FAILED: patch "[PATCH] thunderbolt: Don't access a DP tunnel after its DPRX read was" failed to apply to 6.18-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x 419fa32fa5bc2d7fb9d0d15d5630b1c1090808b3
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026100526-spree-unquote-9a23@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 419fa32fa5bc2d7fb9d0d15d5630b1c1090808b3 Mon Sep 17 00:00:00 2001
From: Sven Peter <[email protected]>
Date: Sat, 29 Aug 2026 10:08:36 +0200
Subject: [PATCH] thunderbolt: Don't access a DP tunnel after its DPRX read was
canceled
tb_dp_dprx_work() checks ->dprx_canceled before it takes tb->lock so it misses a tb_dp_dprx_stop() that could not cancel the already running work. It then polls the DPRX capabilities and runs the callback for a tunnel that has already been torn down while the domain is suspending or going away.
This can be hit by cancelling the DPRX read from outside the ordered tb->wq: During suspend tb_disconnect_and_release_dp() does just this and with a later patch tb_stop() will do it as well. The latter in combination with the Apple NHI where the DPRX read never completed is how I hit this.
Check the flag with tb->lock held instead and check it again in tb_dp_tunnel_active() because the callback runs after the lock has been dropped again.
Also clear the flag in tb_dp_dprx_start() so that it only ever describes the work that is currently in flight.
drivers/thunderbolt/tb.c +12 -0
@@ -1912,6 +1912,18 @@ static void tb_dp_tunnel_active(struct tb_tunnel *tunnel, void *data)struct tb *tb = data;mutex_lock (&tb->lock); + +/* +* If the DPRX read was canceled the tunnel is already being torn +* down by whoever canceled it. Do not touch the adapters here +* because the routers may be gone by now. +*/ +if (tunnel->dprx_canceled) { +tb_tunnel_dbg (tunnel,"DPRX read canceled, not activating\n" ); +mutex_unlock (&tb->lock); +return ; + } +if (tb_tunnel_is_active (tunnel)) {int consumed_up, consumed_down, ret;
drivers/thunderbolt/tunnel.c +9 -2
@@ -1093,8 +1093,14 @@ static void tb_dp_dprx_work(struct work_struct *work)struct tb_tunnel *tunnel =container_of (work,typeof (*tunnel), dprx_work.work);struct tb *tb = tunnel->tb; +/* +* The DPRX read can be canceled while this work is waiting for +* tb->lock. Check the flag only once it is held: while the lock is +* held the tunnel cannot be torn down under us and the adapters are +* safe to access. +*/ +mutex_lock (&tb->lock);if (!tunnel->dprx_canceled) { -mutex_lock (&tb->lock);if (tb_dp_is_usb4 (tunnel->src_port->sw) &&tb_dp_wait_dprx (tunnel,TB_DPRX_WAIT_TIMEOUT )) {if (ktime_before (ktime_get (), tunnel->dprx_timeout)) {
@@ -1106,8 +1112,8 @@ static void tb_dp_dprx_work(struct work_struct *work) }else {tb_tunnel_set_active (tunnel, true); } -mutex_unlock (&tb->lock); } +mutex_unlock (&tb->lock); tunnel->callback (tunnel, tunnel->callback_data);tb_tunnel_put (tunnel);
@@ -1124,6 +1130,7 @@ static int tb_dp_dprx_start(struct tb_tunnel *tunnel)tb_domain_get (tunnel->tb); tunnel->dprx_started = true; + tunnel->dprx_canceled = false; tunnel->dprx_timeout =dprx_timeout_to_ktime (dprx_timeout);queue_delayed_work (tunnel->tb->wq, &tunnel->dprx_work,0 );
Sasha Levin
maintainerPATCH 1/1 thunderbolt: Don't access a DP tunnel after its DPRX read was canceled
From: Sven Peter <[email protected]>
[ Upstream commit 419fa32fa5bc2d7fb9d0d15d5630b1c1090808b3 ]
tb_dp_dprx_work() checks ->dprx_canceled before it takes tb->lock so it misses a tb_dp_dprx_stop() that could not cancel the already running work. It then polls the DPRX capabilities and runs the callback for a tunnel that has already been torn down while the domain is suspending or going away.
This can be hit by cancelling the DPRX read from outside the ordered tb->wq: During suspend tb_disconnect_and_release_dp() does just this and with a later patch tb_stop() will do it as well. The latter in combination with the Apple NHI where the DPRX read never completed is how I hit this.
Check the flag with tb->lock held instead and check it again in tb_dp_tunnel_active() because the callback runs after the lock has been dropped again.
Also clear the flag in tb_dp_dprx_start() so that it only ever describes the work that is currently in flight.
--- drivers/thunderbolt/tb.c | 12 ++++++++++++ drivers/thunderbolt/tunnel.c | 11 +++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-)
drivers/thunderbolt/tb.c +12 -0
@@ -1910,6 +1910,18 @@ static void tb_dp_tunnel_active(struct tb_tunnel *tunnel, void *data)struct tb *tb = data;mutex_lock (&tb->lock); + +/* +* If the DPRX read was canceled the tunnel is already being torn +* down by whoever canceled it. Do not touch the adapters here +* because the routers may be gone by now. +*/ +if (tunnel->dprx_canceled) { +tb_tunnel_dbg (tunnel,"DPRX read canceled, not activating\n" ); +mutex_unlock (&tb->lock); +return ; + } +if (tb_tunnel_is_active (tunnel)) {int consumed_up, consumed_down, ret;
drivers/thunderbolt/tunnel.c +9 -2
@@ -1097,8 +1097,14 @@ static void tb_dp_dprx_work(struct work_struct *work)struct tb_tunnel *tunnel =container_of (work,typeof (*tunnel), dprx_work.work);struct tb *tb = tunnel->tb; +/* +* The DPRX read can be canceled while this work is waiting for +* tb->lock. Check the flag only once it is held: while the lock is +* held the tunnel cannot be torn down under us and the adapters are +* safe to access. +*/ +mutex_lock (&tb->lock);if (!tunnel->dprx_canceled) { -mutex_lock (&tb->lock);if (tb_dp_is_usb4 (tunnel->src_port->sw) &&tb_dp_wait_dprx (tunnel,TB_DPRX_WAIT_TIMEOUT )) {if (ktime_before (ktime_get (), tunnel->dprx_timeout)) {
@@ -1110,8 +1116,8 @@ static void tb_dp_dprx_work(struct work_struct *work) }else {tb_tunnel_set_active (tunnel, true); } -mutex_unlock (&tb->lock); } +mutex_unlock (&tb->lock);if (tunnel->callback) tunnel->callback (tunnel, tunnel->callback_data);
@@ -1129,6 +1135,7 @@ static int tb_dp_dprx_start(struct tb_tunnel *tunnel)tb_domain_get (tunnel->tb); tunnel->dprx_started = true; + tunnel->dprx_canceled = false;if (tunnel->callback) { tunnel->dprx_timeout =dprx_timeout_to_ktime (dprx_timeout);
Signature · 1 line
2.53.0