From: Chaosheng Qu <quchaosheng000406@163.com>
To: Robin van der Gracht <robin@protonic.nl>,
Oleksij Rempel <o.rempel@pengutronix.de>,
Oliver Hartkopp <socketcan@hartkopp.net>,
Marc Kleine-Budde <mkl@pengutronix.de>
Cc: kernel@pengutronix.de, linux-can@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH net v7 1/4] can: j1939: arm the abort timer under the session list lock
Date: Sun, 08 Nov 2026 09:34:23 +0800 [thread overview]
Message-ID: <179410166345.60581.16722127854597502548@163.com> (raw)
In-Reply-To: <179410166344.60581.3898011861151549156@163.com>
From 672c37cb66569c9103f28405d455c8777c81c9e0 Mon Sep 17 00:00:00 2001
From: Chaosheng Qu <quchaosheng000406@163.com>
Date: Sun, 8 Nov 2026 09:22:28 +0800
Subject: [PATCH net v7 1/4] can: j1939: arm the abort timer under the session
list lock
j1939_session_cancel() cancels the receive timer while holding
active_session_list_lock. hrtimer_cancel() waits for a callback that is
already running, and j1939_tp_rxtimer() takes the same lock, so a softirq
callback waiting for the lock deadlocks against the CPU that holds it.
Cancel the timer before taking the lock instead.
Cancelling outside the lock opens a second window: the cancel/get/start
sequence is no longer atomic against j1939_tp_set_rxtimeout(), which rearms
the same timer from the receive path without holding the lock. A
concurrent
arm in that window queues a timer whose reference is never dropped, and the
session then never reaches j1939_session_destroy(), keeping both its netdev
and its j1939_priv reference alive. Take the lock for the rearms so both
armers are serialized; hrtimer_start() does not wait for a callback, so it
is safe to call while holding it.
A session that is already in J1939_SESSION_WAITING_ABORT also gets its
timer
back. A second unparsable frame re-enters j1939_session_cancel() after
j1939_session_timers_cancel() has killed the timer, and without a rearmed
timer nothing ever moves that session out of WAITING_ABORT, so
unregistering
the device hangs in unregister_netdevice().
The reference accounting stays balanced: one j1939_session_get() per
hrtimer_start(), dropped by j1939_session_put() in j1939_tp_rxtimer() when
the timer fires.
Signed-off-by: Chaosheng Qu <quchaosheng000406@163.com>
---
net/can/j1939/transport.c | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c
index 8fcfd13e5e6f..590a04c453b5 100644
--- a/net/can/j1939/transport.c
+++ b/net/can/j1939/transport.c
@@ -1161,12 +1161,38 @@ static void __j1939_session_cancel(struct j1939_session *session,
static void j1939_session_cancel(struct j1939_session *session,
enum j1939_xtp_abort err)
{
+ bool abort_sent = false;
+
+ /* Cancel the abort timer before taking the list lock.
+ *
+ * hrtimer_cancel() waits for a callback that is already running, and
+ * j1939_tp_rxtimer() takes the same lock, so cancelling the timer while
+ * holding active_session_list_lock can deadlock: the lock holder waits
+ * for the callback, the callback waits for the lock.
+ */
+ j1939_session_rxtimer_cancel(session);
+
j1939_session_list_lock(session->priv);
if (session->state >= J1939_SESSION_ACTIVE &&
session->state < J1939_SESSION_WAITING_ABORT) {
- j1939_tp_set_rxtimeout(session, J1939_XTP_ABORT_TIMEOUT_MS);
__j1939_session_cancel(session, err);
+ abort_sent = true;
+ }
+
+ /* Re-arm under the lock, whether the abort frame just went out or the
+ * session is already in WAITING_ABORT and only needs its timer back.
+ *
+ * hrtimer_start() does not wait for a running callback, so arming here
+ * cannot deadlock, and taking the lock closes the window against
+ * j1939_tp_set_rxtimeout(), which rearms the same timer from the
+ * receive path without holding it.
+ */
+ if (abort_sent || session->state == J1939_SESSION_WAITING_ABORT) {
+ j1939_session_get(session);
+ hrtimer_start(&session->rxtimer,
+ ms_to_ktime(J1939_XTP_ABORT_TIMEOUT_MS),
+ HRTIMER_MODE_REL_SOFT);
}
j1939_session_list_unlock(session->priv);
--
2.43.0
next prev parent reply other threads:[~2026-11-11 6:30 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-08 1:34 [PATCH net v7 0/4] can: j1939: fix the abort timer and bound EDPO Chaosheng Qu
2026-11-08 1:34 ` [PATCH net v7 4/4] can: j1939: reject a CTS that names more packets than the message has Chaosheng Qu
2026-11-12 21:49 ` netdev-bot+sashiko
2026-11-13 3:11 ` Chaosheng Qu
2026-11-08 1:34 ` Chaosheng Qu [this message]
2026-11-12 21:49 ` [PATCH net v7 1/4] can: j1939: arm the abort timer under the session list lock netdev-bot+sashiko
2026-11-13 3:11 ` Chaosheng Qu
2026-11-08 1:34 ` [PATCH net v7 2/4] can: j1939: validate the EDPO packet number Chaosheng Qu
2026-11-12 21:49 ` netdev-bot+sashiko
2026-11-13 3:11 ` Chaosheng Qu
2026-11-08 1:34 ` [PATCH net v7 3/4] can: j1939: drop the message when the reassembled skb is gone Chaosheng Qu
2026-11-12 21:49 ` netdev-bot+sashiko
2026-11-13 3:11 ` Chaosheng Qu
2026-11-13 7:25 ` Oleksij Rempel
2026-11-13 8:54 ` Chaosheng Qu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179410166345.60581.16722127854597502548@163.com \
--to=quchaosheng000406@163.com \
--cc=kernel@pengutronix.de \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mkl@pengutronix.de \
--cc=o.rempel@pengutronix.de \
--cc=robin@protonic.nl \
--cc=socketcan@hartkopp.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®