Re: [PATCH net v9 1/4] can: j1939: serialize cancel and rearm of the receive timer

From: Chaosheng Qu

Date: Thu Nov 12 2026 - 22:38:56 EST


Hi,

Replying once for the series rather than per patch.

1/4

The High holds. hrtimer_try_to_cancel() returns -1 while the callback runs
and leaves alone a timer that was requeued from inside it, so an arm that
races the expiry still takes a second reference for a single queued timer.
The list lock does not help, because the running callback sits on the other
side of it.

The three Mediums hold as well. Deactivating on a WAITING_ABORT cancel does
leave the abort rxtimer queued on a DONE session, and that expiry takes the
generic else branch and queues a second RX_ABORT. j1939_tp_rxtimer() reads
session->state before taking the lock, and with try_to_cancel() no longer
waiting, a concurrent cancel can change state underneath it; the callback
then calls __j1939_session_cancel() again, which puts a second abort frame on
the bus and overwrites session->err. And the message is wrong in two places:
before this patch j1939_session_cancel() called j1939_tp_set_rxtimeout(), it
did not hand-roll get + hrtimer_start(), only j1939_tp_rxtimer() did; and it
replaces the 1809c82aa073 workaround without saying so.

The pre-existing txtimer leak is real too: j1939_tp_schedule_txtimer() takes
a reference per hrtimer_start() with no cancel in front, and the do_cts_eoma
path in j1939_xtp_rx_dat_one() calls it that way, so duplicate DAT frames in
one softirq batch leak the same reference.

So 1/4 needs the reference pinned across the whole queued and running
lifetime of the timer, not the queued part alone: a flag owned by
active_session_list_lock, where the clear-to-set transition takes the
reference and the callback drops it, and both armers and the callback test it
under the lock. That also fixes the state check in j1939_tp_rxtimer() and
lets the WAITING_ABORT deactivate go away. It is a rewrite, not another pass
at this hunk, so it will not be a v10 tomorrow. Zihan Xi is working the same
reference-lifetime problem and Oleksij has asked him to sync with Tetsuo; I
will see where that lands before sending and say so in the cover letter.

2/4

The abort code rests on a false premise. J1939_ECU_LOCAL_SRC is set from the
source address alone in j1939_can_recv(), so a second node using our address,
or a raw frame injected on the interface, is delivered to the transmitter
session. It sent no CTS, yet the session is aborted with ECTS_TOO_BIG and
that reason goes out on the bus. Once j1939_xtp_rx_cts_one() bounds the
packet number, pkt.tx_acked cannot exceed pkt.total - 1, so the next version
uses BAD_EDPO_OFFSET for both roles and drops the split. The comment will
name j1939_xtp_rx_cts_one() instead of "4/4", and the "bounds the
receiver-side writer only" wording goes.

4/4

The changelog describes the wrong current behaviour. An oversized
ETP.CM_CTS already ends in ECTS_TOO_BIG: j1939_xtp_rx_cts_one() stores pkt-1
in pkt.tx_acked, j1939_session_tx_dpo() copies it into the DPO, and the local
echo reaches the transmitter branch with session->transmission set. What
changes is that the out-of-range DPO is no longer sent on the bus. The visible
change is the TP case: there is no DPO, so pkt.tx >= pkt.total made
j1939_session_tx_dat() return -ENOBUFS and the session ran until the 1250ms
rxtimer aborted with TIMEOUT or the retry limit ended it with -ENETUNREACH.
That leads the new changelog. The comment and the role split follow 2/4.

3/4

Both nits accepted: WARN_ON_ONCE(!se_skb) and session->err = -EBADMSG instead
of the silent drop, and the comment in j1939_xtp_rx_dpo_one() rewritten as
part of the EDPO patch.

Thanks,
Chaosheng

pw-bot: cr