Re: [PATCH can-next v5 7/9] selftests: can: add J1939 TP/ETP multi-frame tests against CAN_RAW
From: netdev-bot+sashiko
Date: Sat Nov 21 2026 - 20:04:07 EST
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The new RX tests in
tools/testing/selftests/net/can/test_j1939_multi.c assume that…
--
selftests: can: add J1939 TP/ETP multi-frame tests against CAN_RAW
This adds TP and ETP round-trip selftests in both directions. A CAN_RAW
socket acts as the transport peer and by default sits on its own vcan
behind the CAN gateway that j1939_lib.sh sets up. The tests check the
control and DT frames the kernel sends and the order of the TX-completion
ACK, and test_j1939_multi.sh is added to TEST_PROGS.
> diff --git a/tools/testing/selftests/net/can/test_j1939_multi.c b/tools/testing/selftests/net/can/test_j1939_multi.c
> new file mode 100644
> index 0000000000000..6edce7493892b
> --- /dev/null
> +++ b/tools/testing/selftests/net/can/test_j1939_multi.c
> @@ -0,0 +1,682 @@
[ ... ]
> +static bool send_dt_burst_ok(int raw, uint8_t prio, pgn_t dt_pgn, uint8_t da,
> + uint8_t sa, unsigned int next, unsigned int count,
> + const uint8_t *payload, size_t size,
> + unsigned int first_seq)
> +{
> + unsigned int i;
> +
> + for (i = 0; i < count; i++) {
> + size_t abs_pkt = (next - 1) + i;
> + uint8_t seq = first_seq + i;
> +
> + if (!send_dt_ok(raw, prio, dt_pgn, da, sa, seq, payload,
> + abs_pkt * J1939_DT_DATA_LEN, size))
> + return false;
> + }
> + return true;
> +}
[ ... ]
> +static bool etp_rx_serve_cts_ok(int raw, const uint8_t *payload, size_t size)
> +{
[ ... ]
> + cm_dat_init(dat, ETP_CMD_DPO);
> + dat[ETP_DPO_PKTS_OFF] = cts_pkts;
> + put_le24(&dat[ETP_DPO_BASE_OFF], next - 1);
> + if (!peer_send_cm_ok(raw, ETP_CM, dat))
> + return false;
> +
> + if (!send_dt_burst_ok(raw, PRIO, ETP_DT, SA_LOCAL, SA_PEER,
> + next, cts_pkts, payload, size,
> + TP_FIRST_PKT))
> + return false;
[Severity: Medium]
Can the DPO and the up to 255 DT frames after it reach the J1939 stack
in a different order than they were sent?
Each raw send() goes through can_send()->netif_rx()->netif_rx_internal().
With RPS off, that queues the frame on the current CPU's backlog:
net/core/dev.c:netif_rx_internal() {
...
ret = enqueue_to_backlog(skb, smp_processor_id(), &qtail);
...
}
The gateway then queues its copy for CANIF while that CPU processes its
backlog. Frames stay in order only inside a single CPU's backlog.
On PREEMPT_RT, use_backlog_threads() always returns true. So netif_rx()
only wakes the per-CPU backlog_napi thread, and send() returns before
the frame has been handled. On non-RT kernels the same thing happens
with thread_backlog_napi, or when softirq work goes to ksoftirqd.
The test thread has no CPU affinity. Suppose it moves to another CPU
between two send() calls, for example after the backlog thread it just
woke preempts it. Then the new CPU can process a later frame before the
earlier frames still queued on the old CPU.
An ETP DT that arrives before the DPO has been handled hits the default
case in j1939_xtp_rx_dat_one() and cancels the session:
net/can/j1939/transport.c:j1939_xtp_rx_dat_one() {
...
case J1939_TP_CMD_CTS:
if (skcb->addr.type != J1939_ETP)
break;
fallthrough;
default:
...
goto out_session_cancel;
...
}
The send_tp_dt_burst_ok() call in tp_serve_cts_ok() has the same
pattern. A TP DT that arrives early fails this check:
if (packet == session->pkt.rx)
session->pkt.rx++;
Then pkt.rx never reaches pkt.last, no EOMA is sent, and the session
times out.
The commit message says:
j1939_lib.sh also turns RPS off on that vcan, so
the peer gets each frame only after the stack has handled its echo
That covers the order between the stack's echo and the peer. It doesn't
cover the order of the peer's own consecutive frames. Nothing in
j1939_lib.sh or in this directory uses taskset or sched_setaffinity, and
that is still true at the end of the series.
Could tp_rx_from_raw and etp_rx_from_raw then fail at random in the
default kselftest run, especially on RT kernels or loaded VMs?
Would pinning the test process to one CPU fix this? That could be
sched_setaffinity() in j1939_test_main() or taskset in j1939_lib.sh.
The per-CPU backlog FIFO would then keep the order.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-j1939-selftests-v5-0-fdf4c242a37e%40pengutronix.de