thunderbolt: Fix tb->lock deadlock during hot-unplug on AMD USB4 routers
Subsystems (2)
PATCH v2 1/1 thunderbolt: Fix tb->lock deadlock during hot-unplug on AMD USB4 routers
From: Juan Martinez <[email protected]>
Commit f1de1fc5f632 ("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers") introduced a deadlock when physically unplugging a Thunderbolt cable on AMD systems.
The problem occurs because tb_handle_hotplug() holds tb->lock while processing the unplug event. When it removes the XDomain services, tbnet_remove() calls tb_xdomain_disable_paths() which eventually calls tb_domain_reset_interface(). That function tries to acquire tb->lock via guard(mutex), but the hotplug worker already holds it, causing a self-deadlock.
The deadlock manifests as a complete network hang because tb_handle_hotplug() holds RTNL while waiting on its own mutex, blocking all network operations system-wide.
The existing code already handles this scenario partially: when xd->is_unplugged is true, tb_disconnect_xdomain_paths() intentionally skips the DMA teardown because the hotplug handler will do it later via __tb_disconnect_xdomain_paths(). However, the reset was still being called unconditionally.
Fix this by:
1. Splitting tb_domain_reset_interface() into a locked inner function __tb_domain_reset_interface_locked() and a locking wrapper
2. Skipping the reset in tb_domain_disconnect_xdomain_paths() when xd->is_unplugged is true (matching the existing teardown skip logic)
3. Calling __tb_domain_reset_interface_locked() from tb_handle_hotplug() after __tb_disconnect_xdomain_paths() where the actual DMA teardown happens and tb->lock is already held
This preserves the reset behavior for normal shutdown paths while avoiding the deadlock during physical cable unplug.
--- drivers/thunderbolt/domain.c | 26 +++++++++++++++++++++----- drivers/thunderbolt/tb.c | 1 + drivers/thunderbolt/tb.h | 1 + 3 files changed, 23 insertions(+), 5 deletions(-)
drivers/thunderbolt/domain.c +21 -5
@@ -788,14 +788,19 @@ int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, transmit_ring, receive_path, receive_ring); } -static void tb_domain_reset_interface (struct tb *tb) +/* +* __tb_domain_reset_interface_locked - Reset host interface (lock held) +* +* Caller must hold tb->lock. Used by hotplug path where lock is already held. +*/ +void __tb_domain_reset_interface_locked (struct tb *tb) {struct tb_nhi *nhi = tb->nhi; -if (!nhi->ops->reset_interface) -return ; +lockdep_assert_held (&tb->lock); -guard (mutex)(&tb->lock); +if (!(nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN )) +return ;/* The reset clears the ring state so stop the control channel */ tb_ctl_stop (tb->ctl);
@@ -803,6 +808,17 @@ static void tb_domain_reset_interface(struct tb *tb)tb_ctl_start (tb->ctl); } +static void tb_domain_reset_interface (struct tb *tb) +{ +struct tb_nhi *nhi = tb->nhi; + +if (!nhi->ops->reset_interface) +return ; + +guard (mutex)(&tb->lock); +__tb_domain_reset_interface_locked (tb); +} +/** * tb_domain_disconnect_xdomain_paths() - Disable DMA paths for XDomain * @tb: Domain disabling the DMA paths
@@ -835,7 +851,7 @@ int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,if (ret)return ret; -if (tb->nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN ) +if (!xd->is_unplugged)tb_domain_reset_interface (tb);return 0 ;
drivers/thunderbolt/tb.c +1 -0
@@ -2489,6 +2489,7 @@ static void tb_handle_hotplug(struct work_struct *work)tb_xdomain_remove (xd); port->xdomain =NULL ;__tb_disconnect_xdomain_paths (tb, xd,-1 ,-1 ,-1 ,-1 ); +__tb_domain_reset_interface_locked (tb);tb_xdomain_put (xd);tb_port_unconfigure_xdomain (port); }else if (tb_port_is_dpout (port) ||tb_port_is_dpin (port)) {
drivers/thunderbolt/tb.h +1 -0
@@ -789,6 +789,7 @@ int tb_domain_disconnect_pcie_paths(struct tb *tb);int tb_domain_approve_xdomain_paths (struct tb *tb,struct tb_xdomain *xd,int transmit_path,int transmit_ring,int receive_path,int receive_ring); +void __tb_domain_reset_interface_locked (struct tb *tb);int tb_domain_disconnect_xdomain_paths (struct tb *tb,struct tb_xdomain *xd,int transmit_path,int transmit_ring,int receive_path,int receive_ring);
Signature · 1 line
2.43.0
Quoted 53 lines · On 8/25/26 16:42, [email protected] wrote:
From: Juan Martinez <[email protected]>
Commit
f1de1fc5f632("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers") introduced a deadlock when physically unplugging a Thunderbolt cable on AMD systems.The problem occurs because
tb_handle_hotplug()holdstb->lockwhile processing the unplug event. When it removes the XDomain services,tbnet_remove()callstb_xdomain_disable_paths()which eventually callstb_domain_reset_interface(). That function tries to acquiretb->lockvia guard(mutex), but the hotplug worker already holds it, causing a self-deadlock.The deadlock manifests as a complete network hang because
tb_handle_hotplug()holds RTNL while waiting on its own mutex, blocking all network operations system-wide.The existing code already handles this scenario partially: when
xd->is_unpluggedis true,tb_disconnect_xdomain_paths()intentionally skips the DMA teardown because the hotplug handler will do it later via__tb_disconnect_xdomain_paths(). However, the reset was still being called unconditionally.Fix this by:
1. Splittingtb_domain_reset_interface()into a locked inner function__tb_domain_reset_interface_locked()and a locking wrapper
2. Skipping the reset intb_domain_disconnect_xdomain_paths()whenxd->is_unplugged is true (matching the existing teardown skip logic)3. Calling
__tb_domain_reset_interface_locked()fromtb_handle_hotplug()after__tb_disconnect_xdomain_paths()where the actual DMA teardown happens andtb->lockis already heldThis preserves the reset behavior for normal shutdown paths while avoiding the deadlock during physical cable unplug.
Fixes f1de1fc5f632 ("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers")Signed-off-by Juan Martinez <[email protected]>--- drivers/thunderbolt/domain.c | 26 +++++++++++++++++++++----- drivers/thunderbolt/tb.c | 1 + drivers/thunderbolt/tb.h | 1 + 3 files changed, 23 insertions(+), 5 deletions(-)drivers/thunderbolt/domain.c +1
-1@@ -788,14 +788,19 @@ int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, transmit_ring, receive_path, receive_ring); } -static void tb_domain_reset_interface (struct tb *tb) +/*
drivers/thunderbolt/domain.c int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, · line 796
Quoted 10 lines
drivers/thunderbolt/domain.c +5
-2+* __tb_domain_reset_interface_locked - Reset host interface (lock held) +* +* Caller must hold tb->lock. Used by hotplug path where lock is already held. +*/ +void __tb_domain_reset_interface_locked (struct tb *tb) {struct tb_nhi *nhi = tb->nhi; -if (!nhi->ops->reset_interface) -return ;
I'm not sure this is correct to move from here to tb_domain_reset_interface() because you still call __tb_domain_reset_interface_locked() from tb_handle_hotplug() which doesn't do this check.
Quoted 59 lines
drivers/thunderbolt/domain.c +15
-2+lockdep_assert_held (&tb->lock); -guard (mutex)(&tb->lock); +if (!(nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN )) +return ;/* The reset clears the ring state so stop the control channel */ tb_ctl_stop (tb->ctl);@@ -803,6 +808,17 @@ static void tb_domain_reset_interface(struct tb *tb)tb_ctl_start (tb->ctl); } +static void tb_domain_reset_interface (struct tb *tb) +{ +struct tb_nhi *nhi = tb->nhi; + +if (!nhi->ops->reset_interface) +return ; + +guard (mutex)(&tb->lock); +__tb_domain_reset_interface_locked (tb); +} +/** * tb_domain_disconnect_xdomain_paths() - Disable DMA paths for XDomain * @tb: Domain disabling the DMA paths @@ -835,7 +851,7 @@ int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,if (ret)return ret; -if (tb->nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN ) +if (!xd->is_unplugged)tb_domain_reset_interface (tb);return 0 ;drivers/thunderbolt/tb.c +1
-0@@ -2489,6 +2489,7 @@ static void tb_handle_hotplug(struct work_struct *work)tb_xdomain_remove (xd); port->xdomain =NULL ;__tb_disconnect_xdomain_paths (tb, xd,-1 ,-1 ,-1 ,-1 ); +__tb_domain_reset_interface_locked (tb);tb_xdomain_put (xd);tb_port_unconfigure_xdomain (port); }else if (tb_port_is_dpout (port) ||tb_port_is_dpin (port)) {drivers/thunderbolt/tb.h +1
-0@@ -789,6 +789,7 @@ int tb_domain_disconnect_pcie_paths(struct tb *tb);int tb_domain_approve_xdomain_paths (struct tb *tb,struct tb_xdomain *xd,int transmit_path,int transmit_ring,int receive_path,int receive_ring); +void __tb_domain_reset_interface_locked (struct tb *tb);int tb_domain_disconnect_xdomain_paths (struct tb *tb,struct tb_xdomain *xd,int transmit_path,int transmit_ring,int receive_path,int receive_ring);
PATCH v3 1/1 thunderbolt: Fix tb->lock deadlock during hot-unplug on AMD USB4 routers
In reply to [email protected]Commit f1de1fc5f632 ("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers") introduced a deadlock when physically unplugging a Thunderbolt cable on AMD systems.
The problem occurs because tb_handle_hotplug() holds tb->lock while processing the unplug event. When it removes the XDomain services, tbnet_remove() calls tb_xdomain_disable_paths() which eventually calls tb_domain_reset_interface(). That function tries to acquire tb->lock via guard(mutex), but the hotplug worker already holds it, causing a self-deadlock.
The deadlock manifests as a complete network hang because tb_handle_hotplug() holds RTNL while waiting on its own mutex, blocking all network operations system-wide.
The existing code already handles this scenario partially: when xd->is_unplugged is true, tb_disconnect_xdomain_paths() intentionally skips the DMA teardown because the hotplug handler will do it later via __tb_disconnect_xdomain_paths(). However, the reset was still being called unconditionally.
Fix this by:
1. Splitting tb_domain_reset_interface() into a locked inner function __tb_domain_reset_interface_locked() and a locking wrapper
2. Skipping the reset in tb_domain_disconnect_xdomain_paths() when xd->is_unplugged is true (matching the existing teardown skip logic)
3. Calling __tb_domain_reset_interface_locked() from tb_handle_hotplug() after __tb_disconnect_xdomain_paths() where the actual DMA teardown happens and tb->lock is already held
This preserves the reset behavior for normal shutdown paths while avoiding the deadlock during physical cable unplug.
--- drivers/thunderbolt/domain.c | 26 +++++++++++++++++++++----- drivers/thunderbolt/tb.c | 1 + drivers/thunderbolt/tb.h | 1 + 3 files changed, 23 insertions(+), 5 deletions(-)
drivers/thunderbolt/domain.c +21 -5
@@ -788,14 +788,19 @@ int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, transmit_ring, receive_path, receive_ring); } -static void tb_domain_reset_interface (struct tb *tb) +/* +* __tb_domain_reset_interface_locked - Reset host interface (lock held) +* +* Caller must hold tb->lock. Used by hotplug path where lock is already held. +*/ +void __tb_domain_reset_interface_locked (struct tb *tb) {struct tb_nhi *nhi = tb->nhi; -if (!nhi->ops->reset_interface) -return ; +lockdep_assert_held (&tb->lock); -guard (mutex)(&tb->lock); +if (!nhi->ops->reset_interface || !(nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN )) +return ;/* The reset clears the ring state so stop the control channel */ tb_ctl_stop (tb->ctl);
@@ -803,6 +808,17 @@ static void tb_domain_reset_interface(struct tb *tb)tb_ctl_start (tb->ctl); } +static void tb_domain_reset_interface (struct tb *tb) +{ +struct tb_nhi *nhi = tb->nhi; + +if (!nhi->ops->reset_interface) +return ; + +guard (mutex)(&tb->lock); +__tb_domain_reset_interface_locked (tb); +} +/** * tb_domain_disconnect_xdomain_paths() - Disable DMA paths for XDomain * @tb: Domain disabling the DMA paths
@@ -835,7 +851,7 @@ int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,if (ret)return ret; -if (tb->nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN ) +if (!xd->is_unplugged)tb_domain_reset_interface (tb);return 0 ;
drivers/thunderbolt/tb.c +1 -0
@@ -2489,6 +2489,7 @@ static void tb_handle_hotplug(struct work_struct *work)tb_xdomain_remove (xd); port->xdomain =NULL ;__tb_disconnect_xdomain_paths (tb, xd,-1 ,-1 ,-1 ,-1 ); +__tb_domain_reset_interface_locked (tb);tb_xdomain_put (xd);tb_port_unconfigure_xdomain (port); }else if (tb_port_is_dpout (port) ||tb_port_is_dpin (port)) {
drivers/thunderbolt/tb.h +1 -0
@@ -789,6 +789,7 @@ int tb_domain_disconnect_pcie_paths(struct tb *tb);int tb_domain_approve_xdomain_paths (struct tb *tb,struct tb_xdomain *xd,int transmit_path,int transmit_ring,int receive_path,int receive_ring); +void __tb_domain_reset_interface_locked (struct tb *tb);int tb_domain_disconnect_xdomain_paths (struct tb *tb,struct tb_xdomain *xd,int transmit_path,int transmit_ring,int receive_path,int receive_ring);
Signature · 1 line
2.43.0
Quoted 70 lines · Juan Martinez
Commit
f1de1fc5f632("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers") introduced a deadlock when physically unplugging a Thunderbolt cable on AMD systems.The problem occurs because
tb_handle_hotplug()holdstb->lockwhile processing the unplug event. When it removes the XDomain services,tbnet_remove()callstb_xdomain_disable_paths()which eventually callstb_domain_reset_interface(). That function tries to acquiretb->lockvia guard(mutex), but the hotplug worker already holds it, causing a self-deadlock.The deadlock manifests as a complete network hang because
tb_handle_hotplug()holds RTNL while waiting on its own mutex, blocking all network operations system-wide.The existing code already handles this scenario partially: when
xd->is_unpluggedis true,tb_disconnect_xdomain_paths()intentionally skips the DMA teardown because the hotplug handler will do it later via__tb_disconnect_xdomain_paths(). However, the reset was still being called unconditionally.Fix this by:
1. Splittingtb_domain_reset_interface()into a locked inner function__tb_domain_reset_interface_locked()and a locking wrapper
2. Skipping the reset intb_domain_disconnect_xdomain_paths()whenxd->is_unplugged is true (matching the existing teardown skip logic)3. Calling
__tb_domain_reset_interface_locked()fromtb_handle_hotplug()after__tb_disconnect_xdomain_paths()where the actual DMA teardown happens andtb->lockis already heldThis preserves the reset behavior for normal shutdown paths while avoiding the deadlock during physical cable unplug.
Fixes f1de1fc5f632 ("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers")Signed-off-by Juan Martinez <[email protected]>--- drivers/thunderbolt/domain.c | 26 +++++++++++++++++++++----- drivers/thunderbolt/tb.c | 1 + drivers/thunderbolt/tb.h | 1 + 3 files changed, 23 insertions(+), 5 deletions(-)drivers/thunderbolt/domain.c +9
-4@@ -788,14 +788,19 @@ int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, transmit_ring, receive_path, receive_ring); } -static void tb_domain_reset_interface (struct tb *tb) +/* +* __tb_domain_reset_interface_locked - Reset host interface (lock held) +* +* Caller must hold tb->lock. Used by hotplug path where lock is already held. +*/ +void __tb_domain_reset_interface_locked (struct tb *tb) {struct tb_nhi *nhi = tb->nhi; -if (!nhi->ops->reset_interface) -return ; +lockdep_assert_held (&tb->lock); -guard (mutex)(&tb->lock); +if (!nhi->ops->reset_interface || !(nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN )) +return ;/* The reset clears the ring state so stop the control channel */ tb_ctl_stop (tb->ctl);
drivers/thunderbolt/domain.c static void tb_domain_reset_interface(struct tb *tb) · line 816
Quoted 9 lines
drivers/thunderbolt/domain.c +6
-0@@ -803,6 +808,17 @@ static void tb_domain_reset_interface(struct tb *tb)tb_ctl_start (tb->ctl); } +static void tb_domain_reset_interface (struct tb *tb) +{ +struct tb_nhi *nhi = tb->nhi; + +if (!nhi->ops->reset_interface) +return ;
Why is this check here? You already have the same check in __tb_domain_reset_interface_locked().
Quoted 41 lines
drivers/thunderbolt/domain.c +6
-1+ +guard (mutex)(&tb->lock); +__tb_domain_reset_interface_locked (tb); +} +/** * tb_domain_disconnect_xdomain_paths() - Disable DMA paths for XDomain * @tb: Domain disabling the DMA paths @@ -835,7 +851,7 @@ int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,if (ret)return ret; -if (tb->nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN ) +if (!xd->is_unplugged)tb_domain_reset_interface (tb);return 0 ;drivers/thunderbolt/tb.c +1
-0@@ -2489,6 +2489,7 @@ static void tb_handle_hotplug(struct work_struct *work)tb_xdomain_remove (xd); port->xdomain =NULL ;__tb_disconnect_xdomain_paths (tb, xd,-1 ,-1 ,-1 ,-1 ); +__tb_domain_reset_interface_locked (tb);tb_xdomain_put (xd);tb_port_unconfigure_xdomain (port); }else if (tb_port_is_dpout (port) ||tb_port_is_dpin (port)) {drivers/thunderbolt/tb.h +1
-0@@ -789,6 +789,7 @@ int tb_domain_disconnect_pcie_paths(struct tb *tb);int tb_domain_approve_xdomain_paths (struct tb *tb,struct tb_xdomain *xd,int transmit_path,int transmit_ring,int receive_path,int receive_ring); +void __tb_domain_reset_interface_locked (struct tb *tb);int tb_domain_disconnect_xdomain_paths (struct tb *tb,struct tb_xdomain *xd,int transmit_path,int transmit_ring,int receive_path,int receive_ring);
PATCH v4 1/1 thunderbolt: Fix tb->lock deadlock during hot-unplug on AMD USB4 routers
In reply to Juan MartinezCommit f1de1fc5f632 ("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers") introduced a deadlock when physically unplugging a Thunderbolt cable on AMD systems.
The problem occurs because tb_handle_hotplug() holds tb->lock while processing the unplug event. When it removes the XDomain services, tbnet_remove() calls tb_xdomain_disable_paths() which eventually calls tb_domain_reset_interface(). That function tries to acquire tb->lock via guard(mutex), but the hotplug worker already holds it, causing a self-deadlock.
The deadlock manifests as a complete network hang because tb_handle_hotplug() holds RTNL while waiting on its own mutex, blocking all network operations system-wide.
The existing code already handles this scenario partially: when xd->is_unplugged is true, tb_disconnect_xdomain_paths() intentionally skips the DMA teardown because the hotplug handler will do it later via __tb_disconnect_xdomain_paths(). However, the reset was still being called unconditionally.
Fix this by:
1. Splitting tb_domain_reset_interface() into a locked inner function __tb_domain_reset_interface_locked() and a locking wrapper
2. Skipping the reset in tb_domain_disconnect_xdomain_paths() when xd->is_unplugged is true (matching the existing teardown skip logic)
3. Calling __tb_domain_reset_interface_locked() from tb_handle_hotplug() after __tb_disconnect_xdomain_paths() where the actual DMA teardown happens and tb->lock is already held
This preserves the reset behavior for normal shutdown paths while avoiding the deadlock during physical cable unplug.
--- drivers/thunderbolt/domain.c | 20 +++++++++++++++++--- drivers/thunderbolt/tb.c | 1 + drivers/thunderbolt/tb.h | 1 + 3 files changed, 19 insertions(+), 3 deletions(-)
drivers/thunderbolt/domain.c +17 -3
@@ -788,14 +788,22 @@ int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, transmit_ring, receive_path, receive_ring); } -static void tb_domain_reset_interface (struct tb *tb) +/* +* __tb_domain_reset_interface_locked - Reset host interface (lock held) +* +* Caller must hold tb->lock. Used by hotplug path where lock is already held. +*/ +void __tb_domain_reset_interface_locked (struct tb *tb) {struct tb_nhi *nhi = tb->nhi; +lockdep_assert_held (&tb->lock); +if (!nhi->ops->reset_interface)return ; -guard (mutex)(&tb->lock); +if (!(nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN )) +return ;/* The reset clears the ring state so stop the control channel */ tb_ctl_stop (tb->ctl);
@@ -803,6 +811,12 @@ static void tb_domain_reset_interface(struct tb *tb)tb_ctl_start (tb->ctl); } +static void tb_domain_reset_interface (struct tb *tb) +{ +guard (mutex)(&tb->lock); +__tb_domain_reset_interface_locked (tb); +} +/** * tb_domain_disconnect_xdomain_paths() - Disable DMA paths for XDomain * @tb: Domain disabling the DMA paths
@@ -835,7 +849,7 @@ int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,if (ret)return ret; -if (tb->nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN ) +if (!xd->is_unplugged)tb_domain_reset_interface (tb);return 0 ;
drivers/thunderbolt/tb.c +1 -0
@@ -2489,6 +2489,7 @@ static void tb_handle_hotplug(struct work_struct *work)tb_xdomain_remove (xd); port->xdomain =NULL ;__tb_disconnect_xdomain_paths (tb, xd,-1 ,-1 ,-1 ,-1 ); +__tb_domain_reset_interface_locked (tb);tb_xdomain_put (xd);tb_port_unconfigure_xdomain (port); }else if (tb_port_is_dpout (port) ||tb_port_is_dpin (port)) {
drivers/thunderbolt/tb.h +1 -0
@@ -789,6 +789,7 @@ int tb_domain_disconnect_pcie_paths(struct tb *tb);int tb_domain_approve_xdomain_paths (struct tb *tb,struct tb_xdomain *xd,int transmit_path,int transmit_ring,int receive_path,int receive_ring); +void __tb_domain_reset_interface_locked (struct tb *tb);int tb_domain_disconnect_xdomain_paths (struct tb *tb,struct tb_xdomain *xd,int transmit_path,int transmit_ring,int receive_path,int receive_ring);
Signature · 1 line
2.43.0
Quoted 30 lines · Juan Martinez
Commit
f1de1fc5f632("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers") introduced a deadlock when physically unplugging a Thunderbolt cable on AMD systems.The problem occurs because
tb_handle_hotplug()holdstb->lockwhile processing the unplug event. When it removes the XDomain services,tbnet_remove()callstb_xdomain_disable_paths()which eventually callstb_domain_reset_interface(). That function tries to acquiretb->lockvia guard(mutex), but the hotplug worker already holds it, causing a self-deadlock.The deadlock manifests as a complete network hang because
tb_handle_hotplug()holds RTNL while waiting on its own mutex, blocking all network operations system-wide.The existing code already handles this scenario partially: when
xd->is_unpluggedis true,tb_disconnect_xdomain_paths()intentionally skips the DMA teardown because the hotplug handler will do it later via__tb_disconnect_xdomain_paths(). However, the reset was still being called unconditionally.Fix this by:
1. Splittingtb_domain_reset_interface()into a locked inner function__tb_domain_reset_interface_locked()and a locking wrapper
2. Skipping the reset intb_domain_disconnect_xdomain_paths()whenxd->is_unplugged is true (matching the existing teardown skip logic)3. Calling
__tb_domain_reset_interface_locked()fromtb_handle_hotplug()after__tb_disconnect_xdomain_paths()where the actual DMA teardown happens andtb->lockis already held
Quoted 5 lines
This preserves the reset behavior for normal shutdown paths while avoiding the deadlock during physical cable unplug.
Fixes f1de1fc5f632 ("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers")Signed-off-by Juan Martinez <[email protected]>
Looks good to me now, thanks for iterating.
Mika,
The quirk this is fixing came in 7.3 cycle. So this patch should also go to -fixes for 7.3 cycle.
Quoted 81 lines
--- drivers/thunderbolt/domain.c | 20 +++++++++++++++++--- drivers/thunderbolt/tb.c | 1 + drivers/thunderbolt/tb.h | 1 + 3 files changed, 19 insertions(+), 3 deletions(-)drivers/thunderbolt/domain.c +17
-3@@ -788,14 +788,22 @@ int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, transmit_ring, receive_path, receive_ring); } -static void tb_domain_reset_interface (struct tb *tb) +/* +* __tb_domain_reset_interface_locked - Reset host interface (lock held) +* +* Caller must hold tb->lock. Used by hotplug path where lock is already held. +*/ +void __tb_domain_reset_interface_locked (struct tb *tb) {struct tb_nhi *nhi = tb->nhi; +lockdep_assert_held (&tb->lock); +if (!nhi->ops->reset_interface)return ; -guard (mutex)(&tb->lock); +if (!(nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN )) +return ;/* The reset clears the ring state so stop the control channel */ tb_ctl_stop (tb->ctl);@@ -803,6 +811,12 @@ static void tb_domain_reset_interface(struct tb *tb)tb_ctl_start (tb->ctl); } +static void tb_domain_reset_interface (struct tb *tb) +{ +guard (mutex)(&tb->lock); +__tb_domain_reset_interface_locked (tb); +} +/** * tb_domain_disconnect_xdomain_paths() - Disable DMA paths for XDomain * @tb: Domain disabling the DMA paths @@ -835,7 +849,7 @@ int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,if (ret)return ret; -if (tb->nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN ) +if (!xd->is_unplugged)tb_domain_reset_interface (tb);return 0 ;drivers/thunderbolt/tb.c +1
-0@@ -2489,6 +2489,7 @@ static void tb_handle_hotplug(struct work_struct *work)tb_xdomain_remove (xd); port->xdomain =NULL ;__tb_disconnect_xdomain_paths (tb, xd,-1 ,-1 ,-1 ,-1 ); +__tb_domain_reset_interface_locked (tb);tb_xdomain_put (xd);tb_port_unconfigure_xdomain (port); }else if (tb_port_is_dpout (port) ||tb_port_is_dpin (port)) {drivers/thunderbolt/tb.h +1
-0@@ -789,6 +789,7 @@ int tb_domain_disconnect_pcie_paths(struct tb *tb);int tb_domain_approve_xdomain_paths (struct tb *tb,struct tb_xdomain *xd,int transmit_path,int transmit_ring,int receive_path,int receive_ring); +void __tb_domain_reset_interface_locked (struct tb *tb);int tb_domain_disconnect_xdomain_paths (struct tb *tb,struct tb_xdomain *xd,int transmit_path,int transmit_ring,int receive_path,int receive_ring);
Hi,
Quoted 84 lines · Juan Martinez
Commit
f1de1fc5f632("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers") introduced a deadlock when physically unplugging a Thunderbolt cable on AMD systems.The problem occurs because
tb_handle_hotplug()holdstb->lockwhile processing the unplug event. When it removes the XDomain services,tbnet_remove()callstb_xdomain_disable_paths()which eventually callstb_domain_reset_interface(). That function tries to acquiretb->lockvia guard(mutex), but the hotplug worker already holds it, causing a self-deadlock.The deadlock manifests as a complete network hang because
tb_handle_hotplug()holds RTNL while waiting on its own mutex, blocking all network operations system-wide.The existing code already handles this scenario partially: when
xd->is_unpluggedis true,tb_disconnect_xdomain_paths()intentionally skips the DMA teardown because the hotplug handler will do it later via__tb_disconnect_xdomain_paths(). However, the reset was still being called unconditionally.Fix this by:
1. Splittingtb_domain_reset_interface()into a locked inner function__tb_domain_reset_interface_locked()and a locking wrapper
2. Skipping the reset intb_domain_disconnect_xdomain_paths()whenxd->is_unpluggedis true (matching the existing teardown skip logic)
3. Calling__tb_domain_reset_interface_locked()fromtb_handle_hotplug()after__tb_disconnect_xdomain_paths()where the actual DMA teardown happens andtb->lockis already heldThis preserves the reset behavior for normal shutdown paths while avoiding the deadlock during physical cable unplug.
Fixes f1de1fc5f632 ("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers")Signed-off-by Juan Martinez <[email protected]>--- drivers/thunderbolt/domain.c | 20 +++++++++++++++++--- drivers/thunderbolt/tb.c | 1 + drivers/thunderbolt/tb.h | 1 + 3 files changed, 19 insertions(+), 3 deletions(-)drivers/thunderbolt/domain.c +16
-2@@ -788,14 +788,22 @@ int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, transmit_ring, receive_path, receive_ring); } -static void tb_domain_reset_interface (struct tb *tb) +/* +* __tb_domain_reset_interface_locked - Reset host interface (lock held) +* +* Caller must hold tb->lock. Used by hotplug path where lock is already held. +*/ +void __tb_domain_reset_interface_locked (struct tb *tb) {struct tb_nhi *nhi = tb->nhi; +lockdep_assert_held (&tb->lock); +if (!nhi->ops->reset_interface)return ; -guard (mutex)(&tb->lock); +if (!(nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN )) +return ;/* The reset clears the ring state so stop the control channel */ tb_ctl_stop (tb->ctl);@@ -803,6 +811,12 @@ static void tb_domain_reset_interface(struct tb *tb)tb_ctl_start (tb->ctl); } +static void tb_domain_reset_interface (struct tb *tb) +{ +guard (mutex)(&tb->lock); +__tb_domain_reset_interface_locked (tb); +} +/** * tb_domain_disconnect_xdomain_paths() - Disable DMA paths for XDomain * @tb: Domain disabling the DMA paths
drivers/thunderbolt/domain.c int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, · line 852
Quoted 5 lines
drivers/thunderbolt/domain.c +1
-1@@ -835,7 +849,7 @@ int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,if (ret)return ret; -if (tb->nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN ) +if (!xd->is_unplugged)
If I read this right, if you unplug a tree (say a router and then after that router there is inter-domain link) with this check the reset does not happen and AMD system still hangs?
Quoted 29 lines
drivers/thunderbolt/domain.c +0
-0tb_domain_reset_interface (tb);return 0 ;drivers/thunderbolt/tb.c +1
-0@@ -2489,6 +2489,7 @@ static void tb_handle_hotplug(struct work_struct *work)tb_xdomain_remove (xd); port->xdomain =NULL ;__tb_disconnect_xdomain_paths (tb, xd,-1 ,-1 ,-1 ,-1 ); +__tb_domain_reset_interface_locked (tb);tb_xdomain_put (xd);tb_port_unconfigure_xdomain (port); }else if (tb_port_is_dpout (port) ||tb_port_is_dpin (port)) {drivers/thunderbolt/tb.h +1
-0@@ -789,6 +789,7 @@ int tb_domain_disconnect_pcie_paths(struct tb *tb);int tb_domain_approve_xdomain_paths (struct tb *tb,struct tb_xdomain *xd,int transmit_path,int transmit_ring,int receive_path,int receive_ring); +void __tb_domain_reset_interface_locked (struct tb *tb);int tb_domain_disconnect_xdomain_paths (struct tb *tb,struct tb_xdomain *xd,int transmit_path,int transmit_ring,int receive_path,int receive_ring);Signature · 1 line
2.43.0
Quoted 90 lines · Mika Westerberg
Hi,
Quoted 87 lines · Juan Martinez
Commit
f1de1fc5f632("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers") introduced a deadlock when physically unplugging a Thunderbolt cable on AMD systems.The problem occurs because
tb_handle_hotplug()holdstb->lockwhile processing the unplug event. When it removes the XDomain services,tbnet_remove()callstb_xdomain_disable_paths()which eventually callstb_domain_reset_interface(). That function tries to acquiretb->lockvia guard(mutex), but the hotplug worker already holds it, causing a self-deadlock.The deadlock manifests as a complete network hang because
tb_handle_hotplug()holds RTNL while waiting on its own mutex, blocking all network operations system-wide.The existing code already handles this scenario partially: when
xd->is_unpluggedis true,tb_disconnect_xdomain_paths()intentionally skips the DMA teardown because the hotplug handler will do it later via__tb_disconnect_xdomain_paths(). However, the reset was still being called unconditionally.Fix this by:
1. Splittingtb_domain_reset_interface()into a locked inner function__tb_domain_reset_interface_locked()and a locking wrapper
2. Skipping the reset intb_domain_disconnect_xdomain_paths()whenxd->is_unplugged is true (matching the existing teardown skip logic)3. Calling
__tb_domain_reset_interface_locked()fromtb_handle_hotplug()after__tb_disconnect_xdomain_paths()where the actual DMA teardown happens andtb->lockis already heldThis preserves the reset behavior for normal shutdown paths while avoiding the deadlock during physical cable unplug.
Fixes f1de1fc5f632 ("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers")Signed-off-by Juan Martinez <[email protected]>--- drivers/thunderbolt/domain.c | 20 +++++++++++++++++--- drivers/thunderbolt/tb.c | 1 + drivers/thunderbolt/tb.h | 1 + 3 files changed, 19 insertions(+), 3 deletions(-)drivers/thunderbolt/domain.c +16
-2@@ -788,14 +788,22 @@ int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, transmit_ring, receive_path, receive_ring); } -static void tb_domain_reset_interface (struct tb *tb) +/* +* __tb_domain_reset_interface_locked - Reset host interface (lock held) +* +* Caller must hold tb->lock. Used by hotplug path where lock is already held. +*/ +void __tb_domain_reset_interface_locked (struct tb *tb) {struct tb_nhi *nhi = tb->nhi; +lockdep_assert_held (&tb->lock); +if (!nhi->ops->reset_interface)return ; -guard (mutex)(&tb->lock); +if (!(nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN )) +return ;/* The reset clears the ring state so stop the control channel */ tb_ctl_stop (tb->ctl);@@ -803,6 +811,12 @@ static void tb_domain_reset_interface(struct tb *tb)tb_ctl_start (tb->ctl); } +static void tb_domain_reset_interface (struct tb *tb) +{ +guard (mutex)(&tb->lock); +__tb_domain_reset_interface_locked (tb); +} +/** * tb_domain_disconnect_xdomain_paths() - Disable DMA paths for XDomain * @tb: Domain disabling the DMA paths @@ -835,7 +849,7 @@ int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,if (ret)return ret;
Quoted 7 lines
drivers/thunderbolt/domain.c int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, · line 852
Quoted 2 lines
drivers/thunderbolt/domain.c +1
-1-if (tb->nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN ) +if (!xd->is_unplugged)If I read this right, if you unplug a tree (say a router and then after that router there is inter-domain link) with this check the reset does not happen and AMD system still hangs?
It should be a different problem. The quirk fixed a problem in the USB4 router (router wasn't functional when problem occurred).
This fixes a deadlock in the kernel that system gets stuck while shutting down.
Quoted 29 lines
Quoted 29 lines
drivers/thunderbolt/domain.c +0
-0tb_domain_reset_interface (tb);return 0 ;drivers/thunderbolt/tb.c +1
-0@@ -2489,6 +2489,7 @@ static void tb_handle_hotplug(struct work_struct *work)tb_xdomain_remove (xd); port->xdomain =NULL ;__tb_disconnect_xdomain_paths (tb, xd,-1 ,-1 ,-1 ,-1 ); +__tb_domain_reset_interface_locked (tb);tb_xdomain_put (xd);tb_port_unconfigure_xdomain (port); }else if (tb_port_is_dpout (port) ||tb_port_is_dpin (port)) {drivers/thunderbolt/tb.h +1
-0@@ -789,6 +789,7 @@ int tb_domain_disconnect_pcie_paths(struct tb *tb);int tb_domain_approve_xdomain_paths (struct tb *tb,struct tb_xdomain *xd,int transmit_path,int transmit_ring,int receive_path,int receive_ring); +void __tb_domain_reset_interface_locked (struct tb *tb);int tb_domain_disconnect_xdomain_paths (struct tb *tb,struct tb_xdomain *xd,int transmit_path,int transmit_ring,int receive_path,int receive_ring);Signature · 1 line
2.43.0
Hi,
Quoted 20 lines · Mario Limonciello
Quoted 10 lines
Quoted 10 lines
drivers/thunderbolt/domain.c +6
-0+static void tb_domain_reset_interface (struct tb *tb) +{ +guard (mutex)(&tb->lock); +__tb_domain_reset_interface_locked (tb); +} +/** * tb_domain_disconnect_xdomain_paths() - Disable DMA paths for XDomain * @tb: Domain disabling the DMA paths @@ -835,7 +849,7 @@ int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,Quoted 9 lines
drivers/thunderbolt/domain.c int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, · line 852
Quoted 4 lines
drivers/thunderbolt/domain.c +1
-1if (ret)return ret; -if (tb->nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN ) +if (!xd->is_unplugged)If I read this right, if you unplug a tree (say a router and then after that router there is inter-domain link) with this check the reset does not happen and AMD system still hangs?
Quoted 5 lines
It should be a different problem. The quirk fixed a problem in the USB4 router (router wasn't functional when problem occurred).
This fixes a deadlock in the kernel that system gets stuck while shutting down.
Right, but now since this checks !xd->is_unplugged and only then does the reset, if you unplug the whole chain including the XDomain connection (i.e. the unplug happens say on host router downstream port) then we mark everything below that with is_unplugged=1 so now this function will skip the quirk and the DMA will get stuck, no?
Because..
Quoted 12 lines
Quoted 12 lines
drivers/thunderbolt/tb.c static void tb_handle_hotplug(struct work_struct *work) · line 2492
Quoted 12 lines
drivers/thunderbolt/domain.c +0
-0tb_domain_reset_interface (tb);return 0 ;drivers/thunderbolt/tb.c +1
-0@@ -2489,6 +2489,7 @@ static void tb_handle_hotplug(struct work_struct *work)tb_xdomain_remove (xd); port->xdomain =NULL ;__tb_disconnect_xdomain_paths (tb, xd,-1 ,-1 ,-1 ,-1 ); +__tb_domain_reset_interface_locked (tb);
... this is not called when the unplug happens elsewhere (like before the XDomain link).
Quoted 38 lines · Mika Westerberg
Hi,
Quoted 20 lines · Mario Limonciello
Quoted 10 lines
Quoted 10 lines
drivers/thunderbolt/domain.c +6
-0+static void tb_domain_reset_interface (struct tb *tb) +{ +guard (mutex)(&tb->lock); +__tb_domain_reset_interface_locked (tb); +} +/** * tb_domain_disconnect_xdomain_paths() - Disable DMA paths for XDomain * @tb: Domain disabling the DMA paths @@ -835,7 +849,7 @@ int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,Quoted 9 lines
drivers/thunderbolt/domain.c int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, · line 852
Quoted 4 lines
drivers/thunderbolt/domain.c +1
-1if (ret)return ret; -if (tb->nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN ) +if (!xd->is_unplugged)If I read this right, if you unplug a tree (say a router and then after that router there is inter-domain link) with this check the reset does not happen and AMD system still hangs?
Quoted 5 lines
It should be a different problem. The quirk fixed a problem in the USB4 router (router wasn't functional when problem occurred).
This fixes a deadlock in the kernel that system gets stuck while shutting down.
Right, but now since this checks !xd->is_unplugged and only then does the reset, if you unplug the whole chain including the XDomain connection (i.e. the unplug happens say on host router downstream port) then we mark everything below that with is_unplugged=1 so now this function will skip the quirk and the DMA will get stuck, no?
Because..
Quoted 1 line
Quoted 14 lines
Quoted 11 lines
Quoted 11 lines
drivers/thunderbolt/tb.c static void tb_handle_hotplug(struct work_struct *work) · line 2492
Quoted 11 lines
drivers/thunderbolt/domain.c +0
-0tb_domain_reset_interface (tb);return 0 ;drivers/thunderbolt/tb.c +1
-0@@ -2489,6 +2489,7 @@ static void tb_handle_hotplug(struct work_struct *work)tb_xdomain_remove (xd); port->xdomain =NULL ;__tb_disconnect_xdomain_paths (tb, xd,-1 ,-1 ,-1 ,-1 ); +__tb_domain_reset_interface_locked (tb);... this is not called when the unplug happens elsewhere (like before the XDomain link).
Ah yeah.
Juan - take a closer look at this, I think you're gonna have to spin it again.
PATCH v5 1/1 thunderbolt: Fix tb->lock deadlock during hot-unplug on AMD USB4 routers
In reply to Mika WesterbergFrom: Juan Martinez <[email protected]>
Commit f1de1fc5f632 ("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers") introduced a deadlock when physically unplugging a Thunderbolt cable on AMD systems.
The problem occurs because tb_handle_hotplug() holds tb->lock while processing the unplug event. When it removes the XDomain services, tbnet_remove() calls tb_xdomain_disable_paths() which eventually calls tb_domain_reset_interface(). That function tries to acquire tb->lock via guard(mutex), but the hotplug worker already holds it, causing a self-deadlock.
The deadlock manifests as a complete network hang because tb_handle_hotplug() holds RTNL while waiting on its own mutex, blocking all network operations system-wide.
The existing code already handles this scenario partially: when xd->is_unplugged is true, tb_disconnect_xdomain_paths() intentionally skips the DMA teardown because the hotplug handler tears down the DMA tunnels itself. However, the reset was still being called unconditionally.
Fix this by splitting tb_domain_reset_interface() into a locked inner function and a locking wrapper. Skip the reset from tb_domain_disconnect_xdomain_paths() when xd->is_unplugged is true, and instead reset the interface after the hotplug handler tears down the DMA tunnel while already holding tb->lock.
Handle both unplug topologies: reset after the direct XDomain teardown, and after invalid DMA tunnels are removed when an upstream router and its downstream XDomain are unplugged together.
This preserves the reset behavior for normal shutdown paths while avoiding the deadlock during physical cable unplug.
---
Notes (v5):
Changes in v5:
- Rebase on the current thunderbolt/next branch.
- Reset the host interface after invalid DMA tunnels are removed, covering XDomains below an unplugged router.
drivers/thunderbolt/domain.c | 20 +++++++++++++++++--- drivers/thunderbolt/tb.c | 10 +++++++++- drivers/thunderbolt/tb.h | 1 + 3 files changed, 27 insertions(+), 4 deletions(-)
drivers/thunderbolt/domain.c +17 -3
@@ -788,14 +788,22 @@ int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, transmit_ring, receive_path, receive_ring); } -static void tb_domain_reset_interface (struct tb *tb) +/* +* __tb_domain_reset_interface_locked - Reset host interface (lock held) +* +* Caller must hold tb->lock. Used by hotplug path where lock is already held. +*/ +void __tb_domain_reset_interface_locked (struct tb *tb) {struct tb_nhi *nhi = tb->nhi; +lockdep_assert_held (&tb->lock); +if (!nhi->ops->reset_interface)return ; -guard (mutex)(&tb->lock); +if (!(nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN )) +return ;/* The reset clears the ring state so stop the control channel */ tb_ctl_stop (tb->ctl);
@@ -803,6 +811,12 @@ static void tb_domain_reset_interface(struct tb *tb)tb_ctl_start (tb->ctl); } +static void tb_domain_reset_interface (struct tb *tb) +{ +guard (mutex)(&tb->lock); +__tb_domain_reset_interface_locked (tb); +} +/** * tb_domain_disconnect_xdomain_paths() - Disable DMA paths for XDomain * @tb: Domain disabling the DMA paths
@@ -835,7 +849,7 @@ int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,if (ret)return ret; -if (tb->nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN ) +if (!xd->is_unplugged)tb_domain_reset_interface (tb);return 0 ;
drivers/thunderbolt/tb.c +9 -1
@@ -1776,12 +1776,19 @@ static void tb_free_invalid_tunnels(struct tb *tb) {struct tb_cm *tcm =tb_priv (tb);struct tb_tunnel *tunnel; +bool reset = false;struct tb_tunnel *n;list_for_each_entry_safe (tunnel, n, &tcm->tunnel_list, list) { -if (tb_tunnel_is_invalid (tunnel)) +if (tb_tunnel_is_invalid (tunnel)) { +if (tb_tunnel_is_dma (tunnel)) + reset = true;tb_deactivate_and_free_tunnel (tunnel); + } } + +if (reset) +__tb_domain_reset_interface_locked (tb); }/*
@@ -2489,6 +2496,7 @@ static void tb_handle_hotplug(struct work_struct *work)tb_xdomain_remove (xd); port->xdomain =NULL ;__tb_disconnect_xdomain_paths (tb, xd,-1 ,-1 ,-1 ,-1 ); +__tb_domain_reset_interface_locked (tb);tb_xdomain_put (xd);tb_port_unconfigure_xdomain (port); }else if (tb_port_is_dpout (port) ||tb_port_is_dpin (port)) {
drivers/thunderbolt/tb.h +1 -0
@@ -792,6 +792,7 @@ int tb_domain_disconnect_pcie_paths(struct tb *tb);int tb_domain_approve_xdomain_paths (struct tb *tb,struct tb_xdomain *xd,int transmit_path,int transmit_ring,int receive_path,int receive_ring); +void __tb_domain_reset_interface_locked (struct tb *tb);int tb_domain_disconnect_xdomain_paths (struct tb *tb,struct tb_xdomain *xd,int transmit_path,int transmit_ring,int receive_path,int receive_ring);
base-commit: 48e989e33b715611438ce4b8d6ff712d4becd84f
Signature · 1 line
2.43.0
Quoted 33 lines · On 8/31/26 11:16, [email protected] wrote:
From: Juan Martinez <[email protected]>
Commit
f1de1fc5f632("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers") introduced a deadlock when physically unplugging a Thunderbolt cable on AMD systems.The problem occurs because
tb_handle_hotplug()holdstb->lockwhile processing the unplug event. When it removes the XDomain services,tbnet_remove()callstb_xdomain_disable_paths()which eventually callstb_domain_reset_interface(). That function tries to acquiretb->lockvia guard(mutex), but the hotplug worker already holds it, causing a self-deadlock.The deadlock manifests as a complete network hang because
tb_handle_hotplug()holds RTNL while waiting on its own mutex, blocking all network operations system-wide.The existing code already handles this scenario partially: when
xd->is_unpluggedis true,tb_disconnect_xdomain_paths()intentionally skips the DMA teardown because the hotplug handler tears down the DMA tunnels itself. However, the reset was still being called unconditionally.Fix this by splitting
tb_domain_reset_interface()into a locked inner function and a locking wrapper. Skip the reset fromtb_domain_disconnect_xdomain_paths()whenxd->is_unpluggedis true, and instead reset the interface after the hotplug handler tears down the DMA tunnel while already holdingtb->lock.Handle both unplug topologies: reset after the direct XDomain teardown, and after invalid DMA tunnels are removed when an upstream router and its downstream XDomain are unplugged together.
Quoted 5 lines
This preserves the reset behavior for normal shutdown paths while avoiding the deadlock during physical cable unplug.
Fixes f1de1fc5f632 ("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers")Signed-off-by Juan Martinez <[email protected]>
BTW -
I did take a look through the Sashiko feedback and the first point doesn't matter because no pre-USB4 hosts take this quirk.
The second point is a side effect of this reset and accepted behavior.
Quoted 111 lines
---
Notes (v5):
Changes in v5:
- Rebase on the current thunderbolt/next branch.
- Reset the host interface after invalid DMA tunnels are removed, covering XDomains below an unplugged router.drivers/thunderbolt/domain.c | 20 +++++++++++++++++--- drivers/thunderbolt/tb.c | 10 +++++++++- drivers/thunderbolt/tb.h | 1 + 3 files changed, 27 insertions(+), 4 deletions(-)drivers/thunderbolt/domain.c +17
-3@@ -788,14 +788,22 @@ int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, transmit_ring, receive_path, receive_ring); } -static void tb_domain_reset_interface (struct tb *tb) +/* +* __tb_domain_reset_interface_locked - Reset host interface (lock held) +* +* Caller must hold tb->lock. Used by hotplug path where lock is already held. +*/ +void __tb_domain_reset_interface_locked (struct tb *tb) {struct tb_nhi *nhi = tb->nhi; +lockdep_assert_held (&tb->lock); +if (!nhi->ops->reset_interface)return ; -guard (mutex)(&tb->lock); +if (!(nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN )) +return ;/* The reset clears the ring state so stop the control channel */ tb_ctl_stop (tb->ctl);@@ -803,6 +811,12 @@ static void tb_domain_reset_interface(struct tb *tb)tb_ctl_start (tb->ctl); } +static void tb_domain_reset_interface (struct tb *tb) +{ +guard (mutex)(&tb->lock); +__tb_domain_reset_interface_locked (tb); +} +/** * tb_domain_disconnect_xdomain_paths() - Disable DMA paths for XDomain * @tb: Domain disabling the DMA paths @@ -835,7 +849,7 @@ int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,if (ret)return ret; -if (tb->nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN ) +if (!xd->is_unplugged)tb_domain_reset_interface (tb);return 0 ;drivers/thunderbolt/tb.c +9
-1@@ -1776,12 +1776,19 @@ static void tb_free_invalid_tunnels(struct tb *tb) {struct tb_cm *tcm =tb_priv (tb);struct tb_tunnel *tunnel; +bool reset = false;struct tb_tunnel *n;list_for_each_entry_safe (tunnel, n, &tcm->tunnel_list, list) { -if (tb_tunnel_is_invalid (tunnel)) +if (tb_tunnel_is_invalid (tunnel)) { +if (tb_tunnel_is_dma (tunnel)) + reset = true;tb_deactivate_and_free_tunnel (tunnel); + } } + +if (reset) +__tb_domain_reset_interface_locked (tb); }/* @@ -2489,6 +2496,7 @@ static void tb_handle_hotplug(struct work_struct *work)tb_xdomain_remove (xd); port->xdomain =NULL ;__tb_disconnect_xdomain_paths (tb, xd,-1 ,-1 ,-1 ,-1 ); +__tb_domain_reset_interface_locked (tb);tb_xdomain_put (xd);tb_port_unconfigure_xdomain (port); }else if (tb_port_is_dpout (port) ||tb_port_is_dpin (port)) {drivers/thunderbolt/tb.h +1
-0@@ -792,6 +792,7 @@ int tb_domain_disconnect_pcie_paths(struct tb *tb);int tb_domain_approve_xdomain_paths (struct tb *tb,struct tb_xdomain *xd,int transmit_path,int transmit_ring,int receive_path,int receive_ring); +void __tb_domain_reset_interface_locked (struct tb *tb);int tb_domain_disconnect_xdomain_paths (struct tb *tb,struct tb_xdomain *xd,int transmit_path,int transmit_ring,int receive_path,int receive_ring);base-commit:
48e989e33b715611438ce4b8d6ff712d4becd84f
Hi,
Quoted 40 lines · Mario Limonciello
Quoted 33 lines · On 8/31/26 11:16, [email protected] wrote:
From: Juan Martinez <[email protected]>
Commit
f1de1fc5f632("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers") introduced a deadlock when physically unplugging a Thunderbolt cable on AMD systems.The problem occurs because
tb_handle_hotplug()holdstb->lockwhile processing the unplug event. When it removes the XDomain services,tbnet_remove()callstb_xdomain_disable_paths()which eventually callstb_domain_reset_interface(). That function tries to acquiretb->lockvia guard(mutex), but the hotplug worker already holds it, causing a self-deadlock.The deadlock manifests as a complete network hang because
tb_handle_hotplug()holds RTNL while waiting on its own mutex, blocking all network operations system-wide.The existing code already handles this scenario partially: when
xd->is_unpluggedis true,tb_disconnect_xdomain_paths()intentionally skips the DMA teardown because the hotplug handler tears down the DMA tunnels itself. However, the reset was still being called unconditionally.Fix this by splitting
tb_domain_reset_interface()into a locked inner function and a locking wrapper. Skip the reset fromtb_domain_disconnect_xdomain_paths()whenxd->is_unpluggedis true, and instead reset the interface after the hotplug handler tears down the DMA tunnel while already holdingtb->lock.Handle both unplug topologies: reset after the direct XDomain teardown, and after invalid DMA tunnels are removed when an upstream router and its downstream XDomain are unplugged together.
Quoted 5 lines
This preserves the reset behavior for normal shutdown paths while avoiding the deadlock during physical cable unplug.
Fixes f1de1fc5f632 ("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers")Signed-off-by Juan Martinez <[email protected]>
Quoted 8 lines
Reviewed-by Mario Limonciello (AMD) <[email protected]>BTW -
I did take a look through the Sashiko feedback and the first point doesn't matter because no pre-USB4 hosts take this quirk.
The second point is a side effect of this reset and accepted behavior.
I did not find Sashiko comments for this last version but started thinking that the way we are doing it now is quite brutal. Say we have this setup:
- Thunderbolt networking for control traffic
- One USB4STREAM for data plane
The data plane comes and goes depending on the needs but what happens now is that after USB4STREAM tears down the tunnels, the whole host interface get reset so that makes the Thunderbolt networking to fail as well.
Is the original hardware hang per-ring? So for example in this case without any fixes the rings for USB4STREAM would hang but the Thunderbolt networking would keep working? I would expect so bot it would be good to confirm.
Because then I think what we can do is to revert the original fix and then handle this all in nhi.c so that we delay the reset until the rings are idle and during that time we hand off "unused" rings (until running out of them). After we find the rings to be idle we block the CM and control channel and do the reset. I don't know how many rings AMD hardware has, though.
I sketched something along those lines (only compile tested) with LLM see below. I wonder if this could work?
drivers/thunderbolt/domain.c +27 -25
@@ -671,6 +671,32 @@ int tb_domain_runtime_resume(struct tb *tb)return 0 ; } +/** +* tb_domain_pause() - Pause the domain +* @tb: Domain to pause +* +* Blocks the connection manager and stops the control channel so that +* the caller can touch the host interface hardware behind its back. +* Takes @tb->lock. +* +* Once done whatever operations needed call tb_domain_unpause(). +*/ +void tb_domain_pause (struct tb *tb) +{ +mutex_lock (&tb->lock); +tb_ctl_stop (tb->ctl); +} + +/** +* tb_domain_unpause() - Resume paused domain +* @tb: Domain to unpause +*/ +void tb_domain_unpause (struct tb *tb) +{ +tb_ctl_start (tb->ctl); +mutex_unlock (&tb->lock); +} +/** * tb_domain_disapprove_switch() - Disapprove switch * @tb: Domain the switch belongs to
@@ -835,21 +861,6 @@ int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, transmit_ring, receive_path, receive_ring); } -static void tb_domain_reset_interface (struct tb *tb) -{ -struct tb_nhi *nhi = tb->nhi; - -if (!nhi->ops->reset_interface) -return ; - -guard (mutex)(&tb->lock); - -/* The reset clears the ring state so stop the control channel */ -tb_ctl_stop (tb->ctl); - nhi->ops->reset_interface (nhi); -tb_ctl_start (tb->ctl); -} -/** * tb_domain_disconnect_xdomain_paths() - Disable DMA paths for XDomain * @tb: Domain disabling the DMA paths
@@ -872,20 +883,11 @@ int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, int transmit_path, int transmit_ring, int receive_path, int receive_ring) { - int ret; - if (!tb->cm_ops->disconnect_xdomain_paths) return -ENOTSUPP; - ret = tb->cm_ops->disconnect_xdomain_paths (tb, xd, transmit_path, +return tb->cm_ops->disconnect_xdomain_paths (tb, xd, transmit_path, transmit_ring, receive_path, receive_ring); -if (ret) -return ret; - -if (tb->nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN ) -tb_domain_reset_interface (tb); - -return 0 ; }static int disconnect_xdomain (struct device *dev,void *data)
drivers/thunderbolt/nhi.c +123 -26
212 lines not on this page · raw message
drivers/thunderbolt/nhi.h +0 -3
@@ -36,7 +36,6 @@ irqreturn_t nhi_msi(int irq, void *data);irqreturn_t ring_msix (int irq,void *data);int nhi_probe (struct tb_nhi *nhi);void nhi_shutdown (struct tb_nhi *nhi); -void nhi_reset_interface (struct tb_nhi *nhi);extern const struct dev_pm_ops nhi_pm_ops;
@@ -55,7 +54,6 @@ extern const struct dev_pm_ops nhi_pm_ops;* @release_ring_irq: NHI specific interrupt release hook * @is_present: Whether the device is currently present on the parent bus * @init_interrupts: NHI specific interrupt initialization hook -* @reset_interface: Resets the host interface */ struct tb_nhi_ops {int (*init)(struct tb_nhi *nhi);
@@ -71,7 +69,6 @@ struct tb_nhi_ops {void (*release_ring_irq)(struct tb_ring *ring);bool (*is_present)(struct tb_nhi *nhi);int (*init_interrupts)(struct tb_nhi *nhi); -void (*reset_interface)(struct tb_nhi *nhi); };/*
drivers/thunderbolt/pci.c +0 -2
@@ -357,7 +357,6 @@ static const struct tb_nhi_ops pci_nhi_default_ops = { .shutdown = nhi_pci_release_irq, .is_present = nhi_pci_is_present, .init_interrupts = nhi_pci_init_msi, - .reset_interface = nhi_reset_interface, };/* Ice Lake specific NHI operations */
@@ -576,7 +575,6 @@ static const struct tb_nhi_ops icl_nhi_ops = { .release_ring_irq = nhi_pci_ring_release_msix, .is_present = nhi_pci_is_present, .init_interrupts = nhi_pci_init_msi, - .reset_interface = nhi_reset_interface, };static int nhi_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id)
drivers/thunderbolt/tb.h +4 -0
@@ -826,6 +826,10 @@ int tb_domain_thaw_noirq(struct tb *tb);void tb_domain_complete (struct tb *tb);int tb_domain_runtime_suspend (struct tb *tb);int tb_domain_runtime_resume (struct tb *tb); +void tb_domain_pause (struct tb *tb); +void tb_domain_unpause (struct tb *tb); +DEFINE_GUARD(tb_domain_paused, struct tb *, tb_domain_pause(_T), + tb_domain_unpause(_T))int tb_domain_disapprove_switch (struct tb *tb,struct tb_switch *sw);int tb_domain_approve_switch (struct tb *tb,struct tb_switch *sw);int tb_domain_approve_switch_key (struct tb *tb,struct tb_switch *sw);
include/linux/thunderbolt.h +4 -0
@@ -537,6 +537,9 @@ void tb_service_properties_changed(struct tb_service *svc);* MSI-X is used. * @hop_count: Number of rings (end point hops) supported by NHI. * @quirks: NHI specific quirks if any +* @dma_hops_used: Bitmap of HopIDs that have been programmed after the +* last host interface reset. Used only with +* %QUIRK_RESET_DMA_ON_TEARDOWN. * @domain_released: Completed when domain has been fully released * @host_reset: Host router was reset on driver load, or forced on system * shutdown/reboot. When set, tb_stop() asserts DPR on connected
@@ -557,6 +560,7 @@ struct tb_nhi {struct work_struct interrupt_work;u32 hop_count;unsigned long quirks; +unsigned long *dma_hops_used;struct completion domain_released;bool host_reset; };
Quoted 67 lines · Mika Westerberg
Hi,
Quoted 40 lines · Mario Limonciello
Quoted 33 lines · On 8/31/26 11:16, [email protected] wrote:
From: Juan Martinez <[email protected]>
Commit
f1de1fc5f632("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers") introduced a deadlock when physically unplugging a Thunderbolt cable on AMD systems.The problem occurs because
tb_handle_hotplug()holdstb->lockwhile processing the unplug event. When it removes the XDomain services,tbnet_remove()callstb_xdomain_disable_paths()which eventually callstb_domain_reset_interface(). That function tries to acquiretb->lockvia guard(mutex), but the hotplug worker already holds it, causing a self-deadlock.The deadlock manifests as a complete network hang because
tb_handle_hotplug()holds RTNL while waiting on its own mutex, blocking all network operations system-wide.The existing code already handles this scenario partially: when
xd->is_unpluggedis true,tb_disconnect_xdomain_paths()intentionally skips the DMA teardown because the hotplug handler tears down the DMA tunnels itself. However, the reset was still being called unconditionally.Fix this by splitting
tb_domain_reset_interface()into a locked inner function and a locking wrapper. Skip the reset fromtb_domain_disconnect_xdomain_paths()whenxd->is_unpluggedis true, and instead reset the interface after the hotplug handler tears down the DMA tunnel while already holdingtb->lock.Handle both unplug topologies: reset after the direct XDomain teardown, and after invalid DMA tunnels are removed when an upstream router and its downstream XDomain are unplugged together.
Quoted 5 lines
This preserves the reset behavior for normal shutdown paths while avoiding the deadlock during physical cable unplug.
Fixes f1de1fc5f632 ("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers")Signed-off-by Juan Martinez <[email protected]>Quoted 8 lines
Reviewed-by Mario Limonciello (AMD) <[email protected]>BTW -
I did take a look through the Sashiko feedback and the first point doesn't matter because no pre-USB4 hosts take this quirk.
The second point is a side effect of this reset and accepted behavior.
I did not find Sashiko comments for this last version but started thinking that the way we are doing it now is quite brutal. Say we have this setup:
- Thunderbolt networking for control traffic
- One USB4STREAM for data planeThe data plane comes and goes depending on the needs but what happens now is that after USB4STREAM tears down the tunnels, the whole host interface get reset so that makes the Thunderbolt networking to fail as well.
Is the original hardware hang per-ring? So for example in this case without any fixes the rings for USB4STREAM would hang but the Thunderbolt networking would keep working? I would expect so bot it would be good to confirm.
Quoted 7 lines
Because then I think what we can do is to revert the original fix and then handle this all in
nhi.cso that we delay the reset until the rings are idle and during that time we hand off "unused" rings (until running out of them). After we find the rings to be idle we block the CM and control channel and do the reset. I don't know how many rings AMD hardware has, though.
IIUC the problem ends up happening while tearing down xdomain. So if a few xdomain tunnels are active you can hit it.
Juan, Sanath, Basavaraj, can you please check and comment?
Quoted 395 lines
I sketched something along those lines (only compile tested) with LLM see below. I wonder if this could work?
drivers/thunderbolt/domain.c +27
-25@@ -671,6 +671,32 @@ int tb_domain_runtime_resume(struct tb *tb)return 0 ; } +/** +* tb_domain_pause() - Pause the domain +* @tb: Domain to pause +* +* Blocks the connection manager and stops the control channel so that +* the caller can touch the host interface hardware behind its back. +* Takes @tb->lock. +* +* Once done whatever operations needed call tb_domain_unpause(). +*/ +void tb_domain_pause (struct tb *tb) +{ +mutex_lock (&tb->lock); +tb_ctl_stop (tb->ctl); +} + +/** +* tb_domain_unpause() - Resume paused domain +* @tb: Domain to unpause +*/ +void tb_domain_unpause (struct tb *tb) +{ +tb_ctl_start (tb->ctl); +mutex_unlock (&tb->lock); +} +/** * tb_domain_disapprove_switch() - Disapprove switch * @tb: Domain the switch belongs to @@ -835,21 +861,6 @@ int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, transmit_ring, receive_path, receive_ring); } -static void tb_domain_reset_interface (struct tb *tb) -{ -struct tb_nhi *nhi = tb->nhi; - -if (!nhi->ops->reset_interface) -return ; - -guard (mutex)(&tb->lock); - -/* The reset clears the ring state so stop the control channel */ -tb_ctl_stop (tb->ctl); - nhi->ops->reset_interface (nhi); -tb_ctl_start (tb->ctl); -} -/** * tb_domain_disconnect_xdomain_paths() - Disable DMA paths for XDomain * @tb: Domain disabling the DMA paths @@ -872,20 +883,11 @@ int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, int transmit_path, int transmit_ring, int receive_path, int receive_ring) { - int ret; - if (!tb->cm_ops->disconnect_xdomain_paths) return -ENOTSUPP; - ret = tb->cm_ops->disconnect_xdomain_paths (tb, xd, transmit_path, +return tb->cm_ops->disconnect_xdomain_paths (tb, xd, transmit_path, transmit_ring, receive_path, receive_ring); -if (ret) -return ret; - -if (tb->nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN ) -tb_domain_reset_interface (tb); - -return 0 ; }static int disconnect_xdomain (struct device *dev,void *data)drivers/thunderbolt/nhi.c +123
-26@@ -523,9 +523,45 @@ irqreturn_t ring_msix(int irq, void *data)return IRQ_HANDLED ; } +static bool ring_is_dma (const struct tb_ring *ring) +{ +return ring->hop >=RING_FIRST_USABLE_HOPID ; +} + +static bool nhi_dma_rings_running (const struct tb_nhi *nhi) +{ +int i; + +lockdep_assert_held (&nhi->lock); + +/* +* Holding nhi->lock is enough here because tb_ring_start() and +* tb_ring_stop() both hold it when they update ring->running. +*/ +for (i =RING_FIRST_USABLE_HOPID ; i < nhi->hop_count; i++) { +if (nhi->tx_rings[i] && nhi->tx_rings[i]->running) +return true; +if (nhi->rx_rings[i] && nhi->rx_rings[i]->running) +return true; + } + +return false; +} + +static bool nhi_avoid_used_dma_rings (const struct tb_nhi *nhi) +{ +lockdep_assert_held (&nhi->lock); + +if (!(nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN )) +return false; + +return nhi_dma_rings_running (nhi); +} +static int nhi_alloc_hop (struct tb_nhi *nhi,struct tb_ring *ring) {unsigned int start_hop =RING_FIRST_USABLE_HOPID ; +bool avoid_used;int ret =0 ;if (nhi->quirks &QUIRK_E2E ) {@@ -539,6 +575,8 @@ static int nhi_alloc_hop(struct tb_nhi *nhi, struct tb_ring *ring)spin_lock_irq (&nhi->lock); + avoid_used =nhi_avoid_used_dma_rings (nhi); +if (ring->hop <0 ) {unsigned int i;@@ -547,6 +585,8 @@ static int nhi_alloc_hop(struct tb_nhi *nhi, struct tb_ring *ring)* range 1 .. hop_count - 1. */ for (i = start_hop; i < nhi->hop_count; i++) { +if (avoid_used &&test_bit (i, nhi->dma_hops_used)) +continue ;if (ring->is_tx) {if (!nhi->tx_rings[i]) { ring->hop = i;@@ -559,6 +599,13 @@ static int nhi_alloc_hop(struct tb_nhi *nhi, struct tb_ring *ring) } } } + +if (ring->hop <0 && avoid_used) { +dev_warn (nhi->dev, +"out of HopIDs that do not need a host interface reset\n" ); + ret = -EBUSY ; + goto err_unlock; + } }if (ring->hop >0 && ring->hop < start_hop) {@@ -583,6 +630,15 @@ static int nhi_alloc_hop(struct tb_nhi *nhi, struct tb_ring *ring) ret = -EBUSY ; goto err_unlock; } +/* Automatic allocation above already skips the used HopIDs */ +if (avoid_used &&ring_is_dma (ring) && +test_bit (ring->hop, nhi->dma_hops_used)) { +dev_warn (nhi->dev, +"hop %d needs a host interface reset before reuse\n" , + ring->hop); + ret = -EBUSY ; + goto err_unlock; + }if (ring->is_tx) nhi->tx_rings[ring->hop] = ring;@@ -710,6 +766,62 @@ struct tb_ring *tb_ring_alloc_rx(struct tb_nhi *nhi, int hop, int size, }EXPORT_SYMBOL_GPL (tb_ring_alloc_rx); +/** +* nhi_reset_interface() - Reset the host interface +* @nhi: Host interface to reset +* +* Brings the registers in the memory BAR back to their default state and +* clears the End-to-End Flow Control state. The caller is responsible for +* stopping the control channel over the reset because it clears the ring +* state as well. +*/ +static void nhi_reset_interface (struct tb_nhi *nhi) +{ +u32 val; + + val =ioread32 (nhi->iobase +REG_CAPS ); +/* Only v1 host interfaces implement the reset */ +if (FIELD_GET (REG_CAPS_VERSION_MASK , val) >=REG_CAPS_VERSION_2 ) +return ; + +dev_dbg (nhi->dev,"issuing host interface reset\n" ); + +iowrite32 (REG_HOST_INTERFACE_RESET_RST , + nhi->iobase +REG_HOST_INTERFACE_RESET ); +/* Wait for tHIReset (10 ms) to complete */ +usleep_range (10000 ,20000 ); +} + +static void nhi_reset_quirk (struct tb_ring *ring) +{ +struct tb_nhi *nhi = ring->nhi; +struct tb *tb =dev_get_drvdata (nhi->dev); + +if (!(nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN )) +return ; +if (!ring_is_dma (ring)) +return ; + + scoped_guard(spinlock_irq, &nhi->lock) { +if (nhi->going_away) +return ; +if (bitmap_empty (nhi->dma_hops_used, nhi->hop_count)) +return ; +/* +* If any of the DMA rings are still running we cannot +* do the reset. +*/ +if (nhi_dma_rings_running (nhi)) +return ; + +bitmap_zero (nhi->dma_hops_used, nhi->hop_count); + } + +/* CM must be blocked before host interface reset can be done */ + scoped_guard(tb_domain_paused, tb) +nhi_reset_interface (nhi); +} +/** * tb_ring_start() - enable a ring * @ring: Ring to start @@ -721,6 +833,8 @@ void tb_ring_start(struct tb_ring *ring)u16 frame_size;u32 flags; +nhi_reset_quirk (ring); +spin_lock_irq (&ring->nhi->lock);spin_lock (&ring->lock);if (ring->nhi->going_away)@@ -781,6 +895,8 @@ void tb_ring_start(struct tb_ring *ring)if (!(ring->flags &RING_FLAG_NO_INTERRUPT ))ring_interrupt_active (ring, true); ring->running = true; +if (ring->nhi->dma_hops_used &&ring_is_dma (ring)) +__set_bit (ring->hop, ring->nhi->dma_hops_used); err:spin_unlock (&ring->lock);spin_unlock_irq (&ring->nhi->lock);@@ -1241,32 +1357,6 @@ static void nhi_reset(struct tb_nhi *nhi)dev_warn (nhi->dev,"timeout resetting host router\n" ); } -/** -* nhi_reset_interface() - Reset the host interface -* @nhi: Host interface to reset -* -* Brings the registers in the memory BAR back to their default state and -* clears the End-to-End Flow Control state. The caller is responsible for -* stopping the control channel over the reset because it clears the ring -* state as well. -*/ -void nhi_reset_interface (struct tb_nhi *nhi) -{ -u32 val; - - val =ioread32 (nhi->iobase +REG_CAPS ); -/* Only v1 host interfaces implement the reset */ -if (FIELD_GET (REG_CAPS_VERSION_MASK , val) >=REG_CAPS_VERSION_2 ) -return ; - -dev_dbg (nhi->dev,"issuing host interface reset\n" ); - -iowrite32 (REG_HOST_INTERFACE_RESET_RST , - nhi->iobase +REG_HOST_INTERFACE_RESET ); -/* Wait for tHIReset (10 ms) to complete */ -usleep_range (10000 ,20000 ); -} -static struct tb *nhi_select_cm (struct tb_nhi *nhi) {bool linked = false;@@ -1331,6 +1421,13 @@ int nhi_probe(struct tb_nhi *nhi)if (!nhi->tx_rings || !nhi->rx_rings || !nhi->interrupt_mask)return -ENOMEM ; +if (nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN ) { + nhi->dma_hops_used =devm_bitmap_zalloc (dev, nhi->hop_count, +GFP_KERNEL ); +if (!nhi->dma_hops_used) +return -ENOMEM ; + } +nhi_reset (nhi);/* In case someone left them on. */ drivers/thunderbolt/nhi.h +0
-3@@ -36,7 +36,6 @@ irqreturn_t nhi_msi(int irq, void *data);irqreturn_t ring_msix (int irq,void *data);int nhi_probe (struct tb_nhi *nhi);void nhi_shutdown (struct tb_nhi *nhi); -void nhi_reset_interface (struct tb_nhi *nhi);extern const struct dev_pm_ops nhi_pm_ops;@@ -55,7 +54,6 @@ extern const struct dev_pm_ops nhi_pm_ops;* @release_ring_irq: NHI specific interrupt release hook * @is_present: Whether the device is currently present on the parent bus * @init_interrupts: NHI specific interrupt initialization hook -* @reset_interface: Resets the host interface */ struct tb_nhi_ops {int (*init)(struct tb_nhi *nhi);@@ -71,7 +69,6 @@ struct tb_nhi_ops {void (*release_ring_irq)(struct tb_ring *ring);bool (*is_present)(struct tb_nhi *nhi);int (*init_interrupts)(struct tb_nhi *nhi); -void (*reset_interface)(struct tb_nhi *nhi); };/* drivers/thunderbolt/pci.c +0
-2@@ -357,7 +357,6 @@ static const struct tb_nhi_ops pci_nhi_default_ops = { .shutdown = nhi_pci_release_irq, .is_present = nhi_pci_is_present, .init_interrupts = nhi_pci_init_msi, - .reset_interface = nhi_reset_interface, };/* Ice Lake specific NHI operations */ @@ -576,7 +575,6 @@ static const struct tb_nhi_ops icl_nhi_ops = { .release_ring_irq = nhi_pci_ring_release_msix, .is_present = nhi_pci_is_present, .init_interrupts = nhi_pci_init_msi, - .reset_interface = nhi_reset_interface, };static int nhi_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id)drivers/thunderbolt/tb.h +4
-0@@ -826,6 +826,10 @@ int tb_domain_thaw_noirq(struct tb *tb);void tb_domain_complete (struct tb *tb);int tb_domain_runtime_suspend (struct tb *tb);int tb_domain_runtime_resume (struct tb *tb); +void tb_domain_pause (struct tb *tb); +void tb_domain_unpause (struct tb *tb); +DEFINE_GUARD(tb_domain_paused, struct tb *, tb_domain_pause(_T), + tb_domain_unpause(_T))int tb_domain_disapprove_switch (struct tb *tb,struct tb_switch *sw);int tb_domain_approve_switch (struct tb *tb,struct tb_switch *sw);int tb_domain_approve_switch_key (struct tb *tb,struct tb_switch *sw);include/linux/thunderbolt.h +4
-0@@ -537,6 +537,9 @@ void tb_service_properties_changed(struct tb_service *svc);* MSI-X is used. * @hop_count: Number of rings (end point hops) supported by NHI. * @quirks: NHI specific quirks if any +* @dma_hops_used: Bitmap of HopIDs that have been programmed after the +* last host interface reset. Used only with +* %QUIRK_RESET_DMA_ON_TEARDOWN. * @domain_released: Completed when domain has been fully released * @host_reset: Host router was reset on driver load, or forced on system * shutdown/reboot. When set, tb_stop() asserts DPR on connected @@ -557,6 +560,7 @@ struct tb_nhi {struct work_struct interrupt_work;u32 hop_count;unsigned long quirks; +unsigned long *dma_hops_used;struct completion domain_released;bool host_reset; };
Quoted 59 lines · Mario Limonciello
Quoted 58 lines · Mika Westerberg
Hi,
Quoted 40 lines · Mario Limonciello
Quoted 33 lines · On 8/31/26 11:16, [email protected] wrote:
From: Juan Martinez <[email protected]>
Commit
f1de1fc5f632("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers") introduced a deadlock when physically unplugging a Thunderbolt cable on AMD systems.The problem occurs because
tb_handle_hotplug()holdstb->lockwhile processing the unplug event. When it removes the XDomain services,tbnet_remove()callstb_xdomain_disable_paths()which eventually callstb_domain_reset_interface(). That function tries to acquiretb->lockvia guard(mutex), but the hotplug worker already holds it, causing a self-deadlock.The deadlock manifests as a complete network hang because
tb_handle_hotplug()holds RTNL while waiting on its own mutex, blocking all network operations system-wide.The existing code already handles this scenario partially: when
xd->is_unpluggedis true,tb_disconnect_xdomain_paths()intentionally skips the DMA teardown because the hotplug handler tears down the DMA tunnels itself. However, the reset was still being called unconditionally.Fix this by splitting
tb_domain_reset_interface()into a locked inner function and a locking wrapper. Skip the reset fromtb_domain_disconnect_xdomain_paths()whenxd->is_unpluggedis true, and instead reset the interface after the hotplug handler tears down the DMA tunnel while already holdingtb->lock.Handle both unplug topologies: reset after the direct XDomain teardown, and after invalid DMA tunnels are removed when an upstream router and its downstream XDomain are unplugged together.
Quoted 5 lines
This preserves the reset behavior for normal shutdown paths while avoiding the deadlock during physical cable unplug.
Fixes f1de1fc5f632 ("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers")Signed-off-by Juan Martinez <[email protected]>Quoted 8 lines
Reviewed-by Mario Limonciello (AMD) <[email protected]>BTW -
I did take a look through the Sashiko feedback and the first point doesn't matter because no pre-USB4 hosts take this quirk.
The second point is a side effect of this reset and accepted behavior.
I did not find Sashiko comments for this last version but started thinking that the way we are doing it now is quite brutal. Say we have this setup:
- Thunderbolt networking for control traffic
- One USB4STREAM for data plane
Quoted 8 lines
Quoted 8 lines
The data plane comes and goes depending on the needs but what happens now is that after USB4STREAM tears down the tunnels, the whole host interface get reset so that makes the Thunderbolt networking to fail as well.
Is the original hardware hang per-ring? So for example in this case without any fixes the rings for USB4STREAM would hang but the Thunderbolt networking would keep working? I would expect so bot it would be good to confirm.
Yes, the hang is per ring. Only the reset is host interface wide, which is exactly the asymmetry you are pointing at.
Quoted 8 lines
Quoted 8 lines
Because then I think what we can do is to revert the original fix and then handle this all in
nhi.cso that we delay the reset until the rings are idle and during that time we hand off "unused" rings (until running out of them). After we find the rings to be idle we block the CM and control channel and do the reset. I don't know how many rings AMD hardware has, though.
REG_CAPS reports hop_count = 3, so HopID 0 for the control channel and two usable DMA HopIDs.
Quoted 7 lines
IIUC the problem ends up happening while tearing down xdomain. So if a few xdomain tunnels are active you can hit it.
Juan, Sanath, Basavaraj, can you please check and comment?
Quoted 3 lines
I sketched something along those lines (only compile tested) with LLM see below. I wonder if this could work?
We ported it and ran it on two hosts connected back to back. It does what you want - networking survives a second tunnel teardown - with three findings.
1) Every reset is preceded by:
thunderbolt 0000:c6:00.6: dangling request in request_queue
WARNING: ctl.c:761 at tb_ctl_stop+0x7c/0xf0 [thunderbolt]
Workqueue: events_long tbnet_connected_work [thunderbolt_net]
tb_domain_pause+0x25/0x40 [thunderbolt]
tb_ring_start+0x325/0x4a0 [thunderbolt]
tbnet_connected_work+0xd9/0x3b0 [thunderbolt_net] 8 out of 8 cycles. tb_ring_start() runs from service driver context while the XDomain exchange still has control requests outstanding.
2) With two DMA HopIDs and tbnet holding one, the second tunnel gets -EBUSY from the second iteration on and stays that way until the last DMA ring stops. Unplug and replug recovers it, so it is more a consequence of the hop count than a bug, but tbnet has to go down to get the tunnel back.
3) tb_domain_pause() takes tb->lock from tb_ring_start(), while unplug holds tb->lock across tbnet_remove() -> stop_login() -> cancel_work_sync(&net->connected_work) and connected_work waits for tb->lock. That is the same deadlock in a different place.
The variant below keeps your bitmap but moves the reset into a per-NHI work item scheduled from tb_ring_stop() when the last DMA ring stops, so nothing takes tb->lock or sleeps in a service driver callback, and tb_domain_pause()/unpause() are not needed. On the same two hosts:
- 8 x ifdown/ifup: 8/8 up, 8 resets, 0 WARNINGs (was 8 of 8).
- tbnet + second tunnel: same behaviour as yours, and the reset now happens by itself as soon as tbnet goes down.
- 3 x disconnect/reconnect: 3/3 up, 0 WARNINGs, no hung tasks.
static void nhi_reset_work(struct work_struct *work)
{
struct tb_nhi *nhi = container_of(work, struct tb_nhi, reset_work);
struct tb *tb = dev_get_drvdata(nhi->dev);
guard(mutex)(&tb->lock);
scoped_guard(spinlock_irq, &nhi->lock) {
if (nhi->going_away)
return;
if (bitmap_empty(nhi->dma_hops_used, nhi->hop_count))
return;
if (nhi_dma_rings_running(nhi))
return;
}
tb_ctl_stop(tb->ctl);
nhi_reset_interface(nhi);
tb_ctl_start(tb->ctl);
scoped_guard(spinlock_irq, &nhi->lock)
bitmap_zero(nhi->dma_hops_used, nhi->hop_count);
}and schedule it from tb_ring_stop() once the last DMA ring is gone:
ring->running = false;
if (ring->nhi->dma_hops_used && ring_is_dma(ring) &&
!nhi_dma_rings_running(ring->nhi))
needs_reset = true;
err:
spin_unlock(&ring->lock);
spin_unlock_irq(&ring->nhi->lock);
if (needs_reset)
schedule_work(&ring->nhi->reset_work);Plus INIT_WORK() in nhi_probe(), cancel_work_sync() in nhi_shutdown(), and tb_domain_pause()/tb_domain_unpause() dropped. The rest of your sketch is unchanged. I can post it as a proper patch if you want to look at it in full.
Quoted 372 lines
Quoted 371 lines
drivers/thunderbolt/domain.c +26
-23@@ -671,6 +671,32 @@ int tb_domain_runtime_resume(struct tb *tb)return 0 ; } +/** +* tb_domain_pause() - Pause the domain +* @tb: Domain to pause +* +* Blocks the connection manager and stops the control channel so that +* the caller can touch the host interface hardware behind its back. +* Takes @tb->lock. +* +* Once done whatever operations needed call tb_domain_unpause(). +*/ +void tb_domain_pause(struct tb *tb) +{ +mutex_lock (&tb->lock); +tb_ctl_stop (tb->ctl); +} + +/** +* tb_domain_unpause() - Resume paused domain +* @tb: Domain to unpause +*/ +void tb_domain_unpause (struct tb *tb) +{ +tb_ctl_start (tb->ctl); +mutex_unlock (&tb->lock); +} +/** * tb_domain_disapprove_switch() - Disapprove switch * @tb: Domain the switch belongs to @@ -835,21 +861,6 @@ int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, transmit_ring, receive_path, receive_ring); } -static void tb_domain_reset_interface(struct tb *tb) -{ -struct tb_nhi *nhi = tb->nhi; - -if (!nhi->ops->reset_interface) -return ; - -guard (mutex)(&tb->lock); - -/* The reset clears the ring state so stop the control channel */ -tb_ctl_stop (tb->ctl); - nhi->ops->reset_interface (nhi); -tb_ctl_start (tb->ctl); -} -/** * tb_domain_disconnect_xdomain_paths() - Disable DMA paths for XDomain * @tb: Domain disabling the DMA paths @@ -872,20 +883,11 @@ int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, int transmit_path, int transmit_ring, int receive_path, int receive_ring) { - int ret; - if (!tb->cm_ops->disconnect_xdomain_paths) return -ENOTSUPP; - ret = tb->cm_ops->disconnect_xdomain_paths(tb, xd, transmit_path, + return tb->cm_ops->disconnect_xdomain_paths(tb, xd, transmit_path, transmit_ring, receive_path, receive_ring); -if (ret) -return ret; - -if (tb->nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN ) -tb_domain_reset_interface (tb); - -return 0 ; }static int disconnect_xdomain (struct device *dev,void *data)drivers/thunderbolt/nhi.c +118
-25@@ -523,9 +523,45 @@ irqreturn_t ring_msix(int irq, void *data)return IRQ_HANDLED ; } +static bool ring_is_dma(const struct tb_ring *ring) +{ +return ring->hop >=RING_FIRST_USABLE_HOPID ; +} + +static bool nhi_dma_rings_running (const struct tb_nhi *nhi) +{ +int i; + +lockdep_assert_held (&nhi->lock); + +/* +* Holding nhi->lock is enough here because tb_ring_start() and +* tb_ring_stop() both hold it when they update ring->running. +*/ +for (i =RING_FIRST_USABLE_HOPID ; i < nhi->hop_count; i++) { +if (nhi->tx_rings[i] && nhi->tx_rings[i]->running) +return true; +if (nhi->rx_rings[i] && nhi->rx_rings[i]->running) +return true; + } + +return false; +} + +static bool nhi_avoid_used_dma_rings (const struct tb_nhi *nhi) +{ +lockdep_assert_held (&nhi->lock); + +if (!(nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN )) +return false; + +return nhi_dma_rings_running (nhi); +} +static int nhi_alloc_hop (struct tb_nhi *nhi,struct tb_ring *ring) {unsigned int start_hop =RING_FIRST_USABLE_HOPID ; +bool avoid_used;int ret =0 ;if (nhi->quirks &QUIRK_E2E ) {@@ -539,6 +575,8 @@ static int nhi_alloc_hop(struct tb_nhi *nhi, struct tb_ring *ring)spin_lock_irq(&nhi->lock); + avoid_used = nhi_avoid_used_dma_rings(nhi); +if (ring->hop < 0) { unsigned int i; @@ -547,6 +585,8 @@ static int nhi_alloc_hop(struct tb_nhi *nhi, struct tb_ring *ring) * range 1 .. hop_count - 1. */ for (i = start_hop; i < nhi->hop_count; i++) { +if (avoid_used &&test_bit (i, nhi->dma_hops_used)) +continue ;if (ring->is_tx) {if (!nhi->tx_rings[i]) { ring->hop = i;@@ -559,6 +599,13 @@ static int nhi_alloc_hop(struct tb_nhi *nhi, struct tb_ring *ring) } } } + +if (ring->hop <0 && avoid_used) { +dev_warn (nhi->dev, +"out of HopIDs that do not need a host interface reset\n" ); + ret = -EBUSY ; + goto err_unlock; + } }if (ring->hop >0 && ring->hop < start_hop) {@@ -583,6 +630,15 @@ static int nhi_alloc_hop(struct tb_nhi *nhi, struct tb_ring *ring) ret = -EBUSY ; goto err_unlock; } +/* Automatic allocation above already skips the used HopIDs */ +if (avoid_used &&ring_is_dma (ring) && +test_bit (ring->hop, nhi->dma_hops_used)) { +dev_warn (nhi->dev, +"hop %d needs a host interface reset before reuse\n" , + ring->hop); + ret = -EBUSY ; + goto err_unlock; + }if (ring->is_tx) nhi->tx_rings[ring->hop] = ring;@@ -710,6 +766,62 @@ struct tb_ring *tb_ring_alloc_rx(struct tb_nhi *nhi, int hop, int size, }EXPORT_SYMBOL_GPL (tb_ring_alloc_rx); +/** +* nhi_reset_interface() - Reset the host interface +* @nhi: Host interface to reset +* +* Brings the registers in the memory BAR back to their default state and +* clears the End-to-End Flow Control state. The caller is responsible for +* stopping the control channel over the reset because it clears the ring +* state as well. +*/ +static void nhi_reset_interface(struct tb_nhi *nhi) +{ +u32 val; + + val =ioread32 (nhi->iobase +REG_CAPS ); +/* Only v1 host interfaces implement the reset */ +if (FIELD_GET (REG_CAPS_VERSION_MASK , val) >=REG_CAPS_VERSION_2 ) +return ; + +dev_dbg (nhi->dev,"issuing host interface reset\n" ); + +iowrite32 (REG_HOST_INTERFACE_RESET_RST , + nhi->iobase +REG_HOST_INTERFACE_RESET ); +/* Wait for tHIReset (10 ms) to complete */ +usleep_range (10000 ,20000 ); +} + +static void nhi_reset_quirk (struct tb_ring *ring) +{ +struct tb_nhi *nhi = ring->nhi; +struct tb *tb =dev_get_drvdata (nhi->dev); + +if (!(nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN )) +return ; +if (!ring_is_dma (ring)) +return ; + + scoped_guard(spinlock_irq, &nhi->lock) { +if (nhi->going_away) +return ; +if (bitmap_empty (nhi->dma_hops_used, nhi->hop_count)) +return ; +/* +* If any of the DMA rings are still running we cannot +* do the reset. +*/ +if (nhi_dma_rings_running (nhi)) +return ; + +bitmap_zero (nhi->dma_hops_used, nhi->hop_count); + } + +/* CM must be blocked before host interface reset can be done */ + scoped_guard(tb_domain_paused, tb) +nhi_reset_interface (nhi); +} +/** * tb_ring_start() - enable a ring * @ring: Ring to start @@ -721,6 +833,8 @@ void tb_ring_start(struct tb_ring *ring)u16 frame_size;u32 flags; +nhi_reset_quirk (ring); +spin_lock_irq (&ring->nhi->lock);spin_lock (&ring->lock);if (ring->nhi->going_away)@@ -781,6 +895,8 @@ void tb_ring_start(struct tb_ring *ring)if (!(ring->flags &RING_FLAG_NO_INTERRUPT ))ring_interrupt_active (ring, true); ring->running = true; +if (ring->nhi->dma_hops_used &&ring_is_dma (ring)) +__set_bit (ring->hop, ring->nhi->dma_hops_used); err:spin_unlock (&ring->lock);spin_unlock_irq (&ring->nhi->lock);@@ -1241,32 +1357,6 @@ static void nhi_reset(struct tb_nhi *nhi)dev_warn (nhi->dev,"timeout resetting host router\n" ); } -/** -* nhi_reset_interface() - Reset the host interface -* @nhi: Host interface to reset -* -* Brings the registers in the memory BAR back to their default state and -* clears the End-to-End Flow Control state. The caller is responsible for -* stopping the control channel over the reset because it clears the ring -* state as well. -*/ -void nhi_reset_interface(struct tb_nhi *nhi) -{ -u32 val; - - val =ioread32 (nhi->iobase +REG_CAPS ); -/* Only v1 host interfaces implement the reset */ -if (FIELD_GET (REG_CAPS_VERSION_MASK , val) >=REG_CAPS_VERSION_2 ) -return ; - -dev_dbg (nhi->dev,"issuing host interface reset\n" ); - -iowrite32 (REG_HOST_INTERFACE_RESET_RST , - nhi->iobase +REG_HOST_INTERFACE_RESET ); -/* Wait for tHIReset (10 ms) to complete */ -usleep_range (10000 ,20000 ); -} -static struct tb *nhi_select_cm(struct tb_nhi *nhi) { bool linked = false; @@ -1331,6 +1421,13 @@ int nhi_probe(struct tb_nhi *nhi)if (!nhi->tx_rings || !nhi->rx_rings || !nhi->interrupt_mask)return -ENOMEM ; + if (nhi->quirks & QUIRK_RESET_DMA_ON_TEARDOWN) { + nhi->dma_hops_used =devm_bitmap_zalloc (dev, nhi->hop_count, +GFP_KERNEL ); +if (!nhi->dma_hops_used) +return -ENOMEM ; + } +nhi_reset (nhi);/* In case someone left them on. */ drivers/thunderbolt/nhi.h +0
-1@@ -36,7 +36,6 @@ irqreturn_t nhi_msi(int irq, void *data);irqreturn_t ring_msix (int irq,void *data);int nhi_probe (struct tb_nhi *nhi);void nhi_shutdown (struct tb_nhi *nhi); -void nhi_reset_interface (struct tb_nhi *nhi);extern const struct dev_pm_ops nhi_pm_ops; @@ -55,7 +54,6 @@ extern const struct dev_pm_ops nhi_pm_ops; * @release_ring_irq: NHI specific interrupt release hook* @is_present: Whether the device is currently present on the parent bus
* @init_interrupts: NHI specific interrupt initialization hook
- * @reset_interface: Resets the host interface
*/struct tb_nhi_ops { int (*init)(struct tb_nhi *nhi);drivers/thunderbolt/nhi.h +0
-1@@ -71,7 +69,6 @@ struct tb_nhi_ops {void (*release_ring_irq)(struct tb_ring *ring);bool (*is_present)(struct tb_nhi *nhi);int (*init_interrupts)(struct tb_nhi *nhi); -void (*reset_interface)(struct tb_nhi *nhi); };/* drivers/thunderbolt/pci.c +0
-2@@ -357,7 +357,6 @@ static const struct tb_nhi_ops pci_nhi_default_ops = { .shutdown = nhi_pci_release_irq, .is_present = nhi_pci_is_present, .init_interrupts = nhi_pci_init_msi, - .reset_interface = nhi_reset_interface, };/* Ice Lake specific NHI operations */ @@ -576,7 +575,6 @@ static const struct tb_nhi_ops icl_nhi_ops = { .release_ring_irq = nhi_pci_ring_release_msix, .is_present = nhi_pci_is_present, .init_interrupts = nhi_pci_init_msi, - .reset_interface = nhi_reset_interface, };static int nhi_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id)drivers/thunderbolt/tb.h +4
-0@@ -826,6 +826,10 @@ int tb_domain_thaw_noirq(struct tb *tb);void tb_domain_complete (struct tb *tb);int tb_domain_runtime_suspend (struct tb *tb);int tb_domain_runtime_resume (struct tb *tb); +void tb_domain_pause (struct tb *tb); +void tb_domain_unpause (struct tb *tb); +DEFINE_GUARD(tb_domain_paused, struct tb *, tb_domain_pause(_T), + tb_domain_unpause(_T))int tb_domain_disapprove_switch (struct tb *tb,struct tb_switch *sw);int tb_domain_approve_switch (struct tb *tb,struct tb_switch *sw);int tb_domain_approve_switch_key (struct tb *tb,struct tb_switch *sw);include/linux/thunderbolt.h +4
-0@@ -537,6 +537,9 @@ void tb_service_properties_changed(struct tb_service *svc);* MSI-X is used. * @hop_count: Number of rings (end point hops) supported by NHI. * @quirks: NHI specific quirks if any +* @dma_hops_used: Bitmap of HopIDs that have been programmed after the +* last host interface reset. Used only with +* %QUIRK_RESET_DMA_ON_TEARDOWN. * @domain_released: Completed when domain has been fully released * @host_reset: Host router was reset on driver load, or forced on system * shutdown/reboot. When set, tb_stop() asserts DPR on connected @@ -557,6 +560,7 @@ struct tb_nhi {struct work_struct interrupt_work;u32 hop_count;unsigned long quirks; +unsigned long *dma_hops_used;struct completion domain_released;bool host_reset; };
Quoted 82 lines · Sanath
Quoted 59 lines · Mario Limonciello
Quoted 58 lines · Mika Westerberg
Hi,
Quoted 40 lines · Mario Limonciello
Quoted 33 lines · On 8/31/26 11:16, [email protected] wrote:
From: Juan Martinez <[email protected]>
Commit
f1de1fc5f632("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers") introduced a deadlock when physically unplugging a Thunderbolt cable on AMD systems.The problem occurs because
tb_handle_hotplug()holdstb->lockwhile processing the unplug event. When it removes the XDomain services,tbnet_remove()callstb_xdomain_disable_paths()which eventually callstb_domain_reset_interface(). That function tries to acquiretb->lockvia guard(mutex), but the hotplug worker already holds it, causing a self-deadlock.The deadlock manifests as a complete network hang because
tb_handle_hotplug()holds RTNL while waiting on its own mutex, blocking all network operations system-wide.The existing code already handles this scenario partially: when
xd->is_unpluggedis true,tb_disconnect_xdomain_paths()intentionally skips the DMA teardown because the hotplug handler tears down the DMA tunnels itself. However, the reset was still being called unconditionally.Fix this by splitting
tb_domain_reset_interface()into a locked inner function and a locking wrapper. Skip the reset fromtb_domain_disconnect_xdomain_paths()whenxd->is_unpluggedis true, and instead reset the interface after the hotplug handler tears down the DMA tunnel while already holdingtb->lock.Handle both unplug topologies: reset after the direct XDomain teardown, and after invalid DMA tunnels are removed when an upstream router and its downstream XDomain are unplugged together.
Quoted 5 lines
This preserves the reset behavior for normal shutdown paths while avoiding the deadlock during physical cable unplug.
Fixes f1de1fc5f632 ("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers")Signed-off-by Juan Martinez <[email protected]>Quoted 8 lines
Reviewed-by Mario Limonciello (AMD) <[email protected]>BTW -
I did take a look through the Sashiko feedback and the first point doesn't matter because no pre-USB4 hosts take this quirk.
The second point is a side effect of this reset and accepted behavior.
I did not find Sashiko comments for this last version but started thinking that the way we are doing it now is quite brutal. Say we have this setup:
- Thunderbolt networking for control traffic
- One USB4STREAM for data planeQuoted 8 lines
Quoted 8 lines
The data plane comes and goes depending on the needs but what happens now is that after USB4STREAM tears down the tunnels, the whole host interface get reset so that makes the Thunderbolt networking to fail as well.
Is the original hardware hang per-ring? So for example in this case without any fixes the rings for USB4STREAM would hang but the Thunderbolt networking would keep working? I would expect so bot it would be good to confirm.
Yes, the hang is per ring. Only the reset is host interface wide, which is exactly the asymmetry you are pointing at.
Quoted 8 lines
Quoted 8 lines
Because then I think what we can do is to revert the original fix and then handle this all in
nhi.cso that we delay the reset until the rings are idle and during that time we hand off "unused" rings (until running out of them). After we find the rings to be idle we block the CM and control channel and do the reset. I don't know how many rings AMD hardware has, though.
REG_CAPSreportshop_count= 3, so HopID 0 for the control channel and two usable DMA HopIDs.Quoted 1 line
Quoted 8 lines
Quoted 6 lines
IIUC the problem ends up happening while tearing down xdomain. So if a few xdomain tunnels are active you can hit it.
Juan, Sanath, Basavaraj, can you please check and comment?
Quoted 3 lines
I sketched something along those lines (only compile tested) with LLM see below. I wonder if this could work?
We ported it and ran it on two hosts connected back to back. It does what you want - networking survives a second tunnel teardown - with three findings.
Does it still help with the hang though? I would think that we can still hang the router from doing a stress on the first tunnel teardown/creation. Could you make a script and confirm while networking is running?
Quoted 446 lines
1) Every reset is preceded by:
thunderbolt 0000:c6:00.6: dangling request in
request_queue
WARNING: ctl.c:761 attb_ctl_stop+0x7c/0xf0[thunderbolt]
Workqueue:events_longtbnet_connected_work[thunderbolt_net]
tb_domain_pause+0x25/0x40[thunderbolt]tb_ring_start+0x325/0x4a0[thunderbolt]tbnet_connected_work+0xd9/0x3b0[thunderbolt_net]8 out of 8 cycles.
tb_ring_start()runs from service driver context while the XDomain exchange still has control requests outstanding.2) With two DMA HopIDs and tbnet holding one, the second tunnel gets
-EBUSYfrom the second iteration on and stays that way until the last DMA ring stops. Unplug and replug recovers it, so it is more a consequence of the hop count than a bug, but tbnet has to go down to get the tunnel back.3)
tb_domain_pause()takestb->lockfromtb_ring_start(), while unplug holdstb->lock across tbnet_remove() -> stop_login() -> cancel_work_sync(&net->connected_work) and connected_work waits for tb->lock. That is the same deadlock in a different place.The variant below keeps your bitmap but moves the reset into a per-NHI work item scheduled from
tb_ring_stop()when the last DMA ring stops, so nothing takestb->lockor sleeps in a service driver callback, and tb_domain_pause()/unpause() are not needed. On the same two hosts:- 8 x ifdown/ifup: 8/8 up, 8 resets, 0 WARNINGs (was 8 of 8).
- tbnet + second tunnel: same behaviour as yours, and the reset now happens by itself as soon as tbnet goes down.
- 3 x disconnect/reconnect: 3/3 up, 0 WARNINGs, no hung tasks.static void
nhi_reset_work(struct work_struct *work){ struct tb_nhi *nhi = container_of(work, struct tb_nhi, reset_work); struct tb *tb = dev_get_drvdata(nhi->dev); guard(mutex)(&tb->lock); scoped_guard(spinlock_irq, &nhi->lock) { if (nhi->going_away) return; if (bitmap_empty(nhi->dma_hops_used, nhi->hop_count)) return; if (nhi_dma_rings_running(nhi)) return; } tb_ctl_stop(tb->ctl); nhi_reset_interface(nhi); tb_ctl_start(tb->ctl); scoped_guard(spinlock_irq, &nhi->lock) bitmap_zero(nhi->dma_hops_used, nhi->hop_count); }and schedule it from
tb_ring_stop()once the last DMA ring is gone:ring->running = false; if (ring->nhi->dma_hops_used && ring_is_dma(ring) && !nhi_dma_rings_running(ring->nhi)) needs_reset = true; err: spin_unlock(&ring->lock); spin_unlock_irq(&ring->nhi->lock); if (needs_reset) schedule_work(&ring->nhi->reset_work);Plus
INIT_WORK()innhi_probe(),cancel_work_sync()innhi_shutdown(), and tb_domain_pause()/tb_domain_unpause() dropped. The rest of your sketch is unchanged. I can post it as a proper patch if you want to look at it in full.Quoted 372 lines
Quoted 371 lines
drivers/thunderbolt/domain.c +26
-23@@ -671,6 +671,32 @@ int tb_domain_runtime_resume(struct tb *tb)return 0 ; } +/** +* tb_domain_pause() - Pause the domain +* @tb: Domain to pause +* +* Blocks the connection manager and stops the control channel so that +* the caller can touch the host interface hardware behind its back. +* Takes @tb->lock. +* +* Once done whatever operations needed call tb_domain_unpause(). +*/ +void tb_domain_pause(struct tb *tb) +{ +mutex_lock (&tb->lock); +tb_ctl_stop (tb->ctl); +} + +/** +* tb_domain_unpause() - Resume paused domain +* @tb: Domain to unpause +*/ +void tb_domain_unpause (struct tb *tb) +{ +tb_ctl_start (tb->ctl); +mutex_unlock (&tb->lock); +} +/** * tb_domain_disapprove_switch() - Disapprove switch * @tb: Domain the switch belongs to @@ -835,21 +861,6 @@ int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, transmit_ring, receive_path, receive_ring); } -static void tb_domain_reset_interface(struct tb *tb) -{ -struct tb_nhi *nhi = tb->nhi; - -if (!nhi->ops->reset_interface) -return ; - -guard (mutex)(&tb->lock); - -/* The reset clears the ring state so stop the control channel */ -tb_ctl_stop (tb->ctl); - nhi->ops->reset_interface (nhi); -tb_ctl_start (tb->ctl); -} -/** * tb_domain_disconnect_xdomain_paths() - Disable DMA paths for XDomain * @tb: Domain disabling the DMA paths @@ -872,20 +883,11 @@ int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, int transmit_path, int transmit_ring, int receive_path, int receive_ring) { - int ret; - if (!tb->cm_ops->disconnect_xdomain_paths) return -ENOTSUPP; - ret = tb->cm_ops->disconnect_xdomain_paths(tb, xd, transmit_path, + return tb->cm_ops->disconnect_xdomain_paths(tb, xd, transmit_path, transmit_ring, receive_path, receive_ring); -if (ret) -return ret; - -if (tb->nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN ) -tb_domain_reset_interface (tb); - -return 0 ; }static int disconnect_xdomain (struct device *dev,void *data)drivers/thunderbolt/nhi.c +118
-25@@ -523,9 +523,45 @@ irqreturn_t ring_msix(int irq, void *data)return IRQ_HANDLED ; } +static bool ring_is_dma(const struct tb_ring *ring) +{ +return ring->hop >=RING_FIRST_USABLE_HOPID ; +} + +static bool nhi_dma_rings_running (const struct tb_nhi *nhi) +{ +int i; + +lockdep_assert_held (&nhi->lock); + +/* +* Holding nhi->lock is enough here because tb_ring_start() and +* tb_ring_stop() both hold it when they update ring->running. +*/ +for (i =RING_FIRST_USABLE_HOPID ; i < nhi->hop_count; i++) { +if (nhi->tx_rings[i] && nhi->tx_rings[i]->running) +return true; +if (nhi->rx_rings[i] && nhi->rx_rings[i]->running) +return true; + } + +return false; +} + +static bool nhi_avoid_used_dma_rings (const struct tb_nhi *nhi) +{ +lockdep_assert_held (&nhi->lock); + +if (!(nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN )) +return false; + +return nhi_dma_rings_running (nhi); +} +static int nhi_alloc_hop (struct tb_nhi *nhi,struct tb_ring *ring) {unsigned int start_hop =RING_FIRST_USABLE_HOPID ; +bool avoid_used;int ret =0 ;if (nhi->quirks &QUIRK_E2E ) {@@ -539,6 +575,8 @@ static int nhi_alloc_hop(struct tb_nhi *nhi, struct tb_ring *ring)spin_lock_irq(&nhi->lock); + avoid_used = nhi_avoid_used_dma_rings(nhi); +if (ring->hop < 0) { unsigned int i; @@ -547,6 +585,8 @@ static int nhi_alloc_hop(struct tb_nhi *nhi, struct tb_ring *ring) * range 1 .. hop_count - 1. */ for (i = start_hop; i < nhi->hop_count; i++) { +if (avoid_used &&test_bit (i, nhi->dma_hops_used)) +continue ;if (ring->is_tx) {if (!nhi->tx_rings[i]) { ring->hop = i;@@ -559,6 +599,13 @@ static int nhi_alloc_hop(struct tb_nhi *nhi, struct tb_ring *ring) } } } + +if (ring->hop <0 && avoid_used) { +dev_warn (nhi->dev, +"out of HopIDs that do not need a host interface reset\n" ); + ret = -EBUSY ; + goto err_unlock; + } }if (ring->hop >0 && ring->hop < start_hop) {@@ -583,6 +630,15 @@ static int nhi_alloc_hop(struct tb_nhi *nhi, struct tb_ring *ring) ret = -EBUSY ; goto err_unlock; } +/* Automatic allocation above already skips the used HopIDs */ +if (avoid_used &&ring_is_dma (ring) && +test_bit (ring->hop, nhi->dma_hops_used)) { +dev_warn (nhi->dev, +"hop %d needs a host interface reset before reuse\n" , + ring->hop); + ret = -EBUSY ; + goto err_unlock; + }if (ring->is_tx) nhi->tx_rings[ring->hop] = ring;@@ -710,6 +766,62 @@ struct tb_ring *tb_ring_alloc_rx(struct tb_nhi *nhi, int hop, int size, }EXPORT_SYMBOL_GPL (tb_ring_alloc_rx); +/** +* nhi_reset_interface() - Reset the host interface +* @nhi: Host interface to reset +* +* Brings the registers in the memory BAR back to their default state and +* clears the End-to-End Flow Control state. The caller is responsible for +* stopping the control channel over the reset because it clears the ring +* state as well. +*/ +static void nhi_reset_interface(struct tb_nhi *nhi) +{ +u32 val; + + val =ioread32 (nhi->iobase +REG_CAPS ); +/* Only v1 host interfaces implement the reset */ +if (FIELD_GET (REG_CAPS_VERSION_MASK , val) >=REG_CAPS_VERSION_2 ) +return ; + +dev_dbg (nhi->dev,"issuing host interface reset\n" ); + +iowrite32 (REG_HOST_INTERFACE_RESET_RST , + nhi->iobase +REG_HOST_INTERFACE_RESET ); +/* Wait for tHIReset (10 ms) to complete */ +usleep_range (10000 ,20000 ); +} + +static void nhi_reset_quirk (struct tb_ring *ring) +{ +struct tb_nhi *nhi = ring->nhi; +struct tb *tb =dev_get_drvdata (nhi->dev); + +if (!(nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN )) +return ; +if (!ring_is_dma (ring)) +return ; + + scoped_guard(spinlock_irq, &nhi->lock) { +if (nhi->going_away) +return ; +if (bitmap_empty (nhi->dma_hops_used, nhi->hop_count)) +return ; +/* +* If any of the DMA rings are still running we cannot +* do the reset. +*/ +if (nhi_dma_rings_running (nhi)) +return ; + +bitmap_zero (nhi->dma_hops_used, nhi->hop_count); + } + +/* CM must be blocked before host interface reset can be done */ + scoped_guard(tb_domain_paused, tb) +nhi_reset_interface (nhi); +} +/** * tb_ring_start() - enable a ring * @ring: Ring to start @@ -721,6 +833,8 @@ void tb_ring_start(struct tb_ring *ring)u16 frame_size;u32 flags; +nhi_reset_quirk (ring); +spin_lock_irq (&ring->nhi->lock);spin_lock (&ring->lock);if (ring->nhi->going_away)@@ -781,6 +895,8 @@ void tb_ring_start(struct tb_ring *ring)if (!(ring->flags &RING_FLAG_NO_INTERRUPT ))ring_interrupt_active (ring, true); ring->running = true; +if (ring->nhi->dma_hops_used &&ring_is_dma (ring)) +__set_bit (ring->hop, ring->nhi->dma_hops_used); err:spin_unlock (&ring->lock);spin_unlock_irq (&ring->nhi->lock);@@ -1241,32 +1357,6 @@ static void nhi_reset(struct tb_nhi *nhi)dev_warn (nhi->dev,"timeout resetting host router\n" ); } -/** -* nhi_reset_interface() - Reset the host interface -* @nhi: Host interface to reset -* -* Brings the registers in the memory BAR back to their default state and -* clears the End-to-End Flow Control state. The caller is responsible for -* stopping the control channel over the reset because it clears the ring -* state as well. -*/ -void nhi_reset_interface(struct tb_nhi *nhi) -{ -u32 val; - - val =ioread32 (nhi->iobase +REG_CAPS ); -/* Only v1 host interfaces implement the reset */ -if (FIELD_GET (REG_CAPS_VERSION_MASK , val) >=REG_CAPS_VERSION_2 ) -return ; - -dev_dbg (nhi->dev,"issuing host interface reset\n" ); - -iowrite32 (REG_HOST_INTERFACE_RESET_RST , - nhi->iobase +REG_HOST_INTERFACE_RESET ); -/* Wait for tHIReset (10 ms) to complete */ -usleep_range (10000 ,20000 ); -} -static struct tb *nhi_select_cm(struct tb_nhi *nhi) { bool linked = false; @@ -1331,6 +1421,13 @@ int nhi_probe(struct tb_nhi *nhi)if (!nhi->tx_rings || !nhi->rx_rings || !nhi->interrupt_mask)return -ENOMEM ; + if (nhi->quirks & QUIRK_RESET_DMA_ON_TEARDOWN) { + nhi->dma_hops_used =devm_bitmap_zalloc (dev, nhi->hop_count, +GFP_KERNEL ); +if (!nhi->dma_hops_used) +return -ENOMEM ; + } +nhi_reset (nhi);/* In case someone left them on. */ drivers/thunderbolt/nhi.h +0
-1@@ -36,7 +36,6 @@ irqreturn_t nhi_msi(int irq, void *data);irqreturn_t ring_msix (int irq,void *data);int nhi_probe (struct tb_nhi *nhi);void nhi_shutdown (struct tb_nhi *nhi); -void nhi_reset_interface (struct tb_nhi *nhi);extern const struct dev_pm_ops nhi_pm_ops; @@ -55,7 +54,6 @@ extern const struct dev_pm_ops nhi_pm_ops; * @release_ring_irq: NHI specific interrupt release hook* @is_present: Whether the device is currently present on the parent bus
* @init_interrupts: NHI specific interrupt initialization hook
- * @reset_interface: Resets the host interface*/ struct tb_nhi_ops { int (*init)(struct tb_nhi *nhi);drivers/thunderbolt/nhi.h +0
-1@@ -71,7 +69,6 @@ struct tb_nhi_ops {void (*release_ring_irq)(struct tb_ring *ring);bool (*is_present)(struct tb_nhi *nhi);int (*init_interrupts)(struct tb_nhi *nhi); -void (*reset_interface)(struct tb_nhi *nhi); };/* drivers/thunderbolt/pci.c +0
-2@@ -357,7 +357,6 @@ static const struct tb_nhi_ops pci_nhi_default_ops = { .shutdown = nhi_pci_release_irq, .is_present = nhi_pci_is_present, .init_interrupts = nhi_pci_init_msi, - .reset_interface = nhi_reset_interface, };/* Ice Lake specific NHI operations */ @@ -576,7 +575,6 @@ static const struct tb_nhi_ops icl_nhi_ops = { .release_ring_irq = nhi_pci_ring_release_msix, .is_present = nhi_pci_is_present, .init_interrupts = nhi_pci_init_msi, - .reset_interface = nhi_reset_interface, };static int nhi_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id)drivers/thunderbolt/tb.h +4
-0@@ -826,6 +826,10 @@ int tb_domain_thaw_noirq(struct tb *tb);void tb_domain_complete (struct tb *tb);int tb_domain_runtime_suspend (struct tb *tb);int tb_domain_runtime_resume (struct tb *tb); +void tb_domain_pause (struct tb *tb); +void tb_domain_unpause (struct tb *tb); +DEFINE_GUARD(tb_domain_paused, struct tb *, tb_domain_pause(_T), + tb_domain_unpause(_T))int tb_domain_disapprove_switch (struct tb *tb,struct tb_switch *sw);int tb_domain_approve_switch (struct tb *tb,struct tb_switch *sw);int tb_domain_approve_switch_key (struct tb *tb,struct tb_switch *sw);include/linux/thunderbolt.h +4
-0@@ -537,6 +537,9 @@ void tb_service_properties_changed(struct tb_service *svc);* MSI-X is used. * @hop_count: Number of rings (end point hops) supported by NHI. * @quirks: NHI specific quirks if any +* @dma_hops_used: Bitmap of HopIDs that have been programmed after the +* last host interface reset. Used only with +* %QUIRK_RESET_DMA_ON_TEARDOWN. * @domain_released: Completed when domain has been fully released * @host_reset: Host router was reset on driver load, or forced on system * shutdown/reboot. When set, tb_stop() asserts DPR on connected @@ -557,6 +560,7 @@ struct tb_nhi {struct work_struct interrupt_work;u32 hop_count;unsigned long quirks; +unsigned long *dma_hops_used;struct completion domain_released;bool host_reset; };
Quoted 85 lines · Mario Limonciello
Quoted 84 lines · Sanath
Quoted 59 lines · Mario Limonciello
Quoted 58 lines · Mika Westerberg
Hi,
Quoted 40 lines · Mario Limonciello
Quoted 33 lines · On 8/31/26 11:16, [email protected] wrote:
From: Juan Martinez <[email protected]>
Commit
f1de1fc5f632("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers") introduced a deadlock when physically unplugging a Thunderbolt cable on AMD systems.The problem occurs because
tb_handle_hotplug()holdstb->lockwhile processing the unplug event. When it removes the XDomain services,tbnet_remove()callstb_xdomain_disable_paths()which eventually callstb_domain_reset_interface(). That function tries to acquiretb->lockvia guard(mutex), but the hotplug worker already holds it, causing a self-deadlock.The deadlock manifests as a complete network hang because
tb_handle_hotplug()holds RTNL while waiting on its own mutex, blocking all network operations system-wide.The existing code already handles this scenario partially: when
xd->is_unpluggedis true,tb_disconnect_xdomain_paths()intentionally skips the DMA teardown because the hotplug handler tears down the DMA tunnels itself. However, the reset was still being called unconditionally.Fix this by splitting
tb_domain_reset_interface()into a locked inner function and a locking wrapper. Skip the reset fromtb_domain_disconnect_xdomain_paths()whenxd->is_unpluggedis true, and instead reset the interface after the hotplug handler tears down the DMA tunnel while already holdingtb->lock.Handle both unplug topologies: reset after the direct XDomain teardown, and after invalid DMA tunnels are removed when an upstream router and its downstream XDomain are unplugged together.
Quoted 5 lines
This preserves the reset behavior for normal shutdown paths while avoiding the deadlock during physical cable unplug.
Fixes f1de1fc5f632 ("thunderbolt: Add quirk to reset host interface on DMA path teardown for AMD USB4 routers")Signed-off-by Juan Martinez <[email protected]>Quoted 8 lines
Reviewed-by Mario Limonciello (AMD) <[email protected]>BTW -
I did take a look through the Sashiko feedback and the first point doesn't matter because no pre-USB4 hosts take this quirk.
The second point is a side effect of this reset and accepted behavior.
I did not find Sashiko comments for this last version but started thinking that the way we are doing it now is quite brutal. Say we have this setup:
- Thunderbolt networking for control traffic
- One USB4STREAM for data planeQuoted 8 lines
Quoted 8 lines
The data plane comes and goes depending on the needs but what happens now is that after USB4STREAM tears down the tunnels, the whole host interface get reset so that makes the Thunderbolt networking to fail as well.
Is the original hardware hang per-ring? So for example in this case without any fixes the rings for USB4STREAM would hang but the Thunderbolt networking would keep working? I would expect so bot it would be good to confirm.
Yes, the hang is per ring. Only the reset is host interface wide, which is exactly the asymmetry you are pointing at.
Quoted 8 lines
Quoted 8 lines
Because then I think what we can do is to revert the original fix and then handle this all in
nhi.cso that we delay the reset until the rings are idle and during that time we hand off "unused" rings (until running out of them). After we find the rings to be idle we block the CM and control channel and do the reset. I don't know how many rings AMD hardware has, though.
REG_CAPSreportshop_count= 3, so HopID 0 for the control channel and two usable DMA HopIDs.Quoted 3 lines
IIUC the problem ends up happening while tearing down xdomain. So if a few xdomain tunnels are active you can hit it.
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Juan, Sanath, Basavaraj, can you please check and comment?
Quoted 3 lines
I sketched something along those lines (only compile tested) with LLM see below. I wonder if this could work?
We ported it and ran it on two hosts connected back to back. It does what you want - networking survives a second tunnel teardown - with three findings.
Does it still help with the hang though? I would think that we can still hang the router from doing a stress on the first tunnel teardown/creation. Could you make a script and confirm while networking is running?
Ported it and stressed it on two Strix Halo hosts connected back to back. REG_CAPS reports hop_count = 3 here, so two usable DMA HopIDs. Observations:
- Single tunnel it works: 50 x traffic then link down/up, plus 42 x dma_test create / transfer / teardown. One reset per cycle, no ping loss, no errors, and every ring restart had a reset before it.
- Every reset is preceded by "dangling request in request_queue" and a WARNING from tb_ctl_stop(), 8 of 8 cycles, via tb_domain_pause() <- tb_ring_start() <- tbnet_connected_work().
- Two tunnels: the networking ring is stopped and restarted with no reset in between, because the check only runs in nhi_alloc_hop() and tbnet reuses its rings across a reconnect. 18 such cycles did not hang, so the unsafe reuse is reachable but I cannot say it hangs.
- When the check does fire it takes networking down, reproduced twice:
"RTNETLINK answers: Cannot allocate memory" plus "out of HopIDs that do not need a host interface reset", until the second tunnel stops.
- tb_domain_pause() takes tb->lock from tb_ring_start(), while unplug holds tb->lock across tbnet_remove() -> stop_login() -> cancel_work_sync(&net->connected_work).
Moving the reset into a per-NHI work item scheduled from tb_ring_stop() when the last DMA ring stops removes the warning and the tb->lock inversion, and passes the same tests cleanly. The reuse hole and the lockout still need the reset to key off ring reuse rather than ring allocation.
Mika, Can I respin your patch along those lines and post it as a new version?
Quoted 447 lines
Quoted 446 lines
1) Every reset is preceded by:
thunderbolt 0000:c6:00.6: dangling request in
request_queue
WARNING: ctl.c:761 attb_ctl_stop+0x7c/0xf0[thunderbolt]
Workqueue:events_longtbnet_connected_work[thunderbolt_net]
tb_domain_pause+0x25/0x40[thunderbolt]tb_ring_start+0x325/0x4a0[thunderbolt]tbnet_connected_work+0xd9/0x3b0[thunderbolt_net]8 out of 8 cycles.
tb_ring_start()runs from service driver context while the XDomain exchange still has control requests outstanding.2) With two DMA HopIDs and tbnet holding one, the second tunnel gets
-EBUSYfrom the second iteration on and stays that way until the last DMA ring stops. Unplug and replug recovers it, so it is more a consequence of the hop count than a bug, but tbnet has to go down to get the tunnel back.3)
tb_domain_pause()takestb->lockfromtb_ring_start(), while unplug holdstb->lock across tbnet_remove() -> stop_login() -> cancel_work_sync(&net->connected_work) and connected_work waits for tb->lock. That is the same deadlock in a different place.The variant below keeps your bitmap but moves the reset into a per-NHI work item scheduled from
tb_ring_stop()when the last DMA ring stops, so nothing takestb->lockor sleeps in a service driver callback, and tb_domain_pause()/unpause() are not needed. On the same two hosts:- 8 x ifdown/ifup: 8/8 up, 8 resets, 0 WARNINGs (was 8 of 8).
- tbnet + second tunnel: same behaviour as yours, and the reset now happens by itself as soon as tbnet goes down.
- 3 x disconnect/reconnect: 3/3 up, 0 WARNINGs, no hung tasks.static void
nhi_reset_work(struct work_struct *work){ struct tb_nhi *nhi = container_of(work, struct tb_nhi, reset_work); struct tb *tb = dev_get_drvdata(nhi->dev); guard(mutex)(&tb->lock); scoped_guard(spinlock_irq, &nhi->lock) { if (nhi->going_away) return; if (bitmap_empty(nhi->dma_hops_used, nhi->hop_count)) return; if (nhi_dma_rings_running(nhi)) return; } tb_ctl_stop(tb->ctl); nhi_reset_interface(nhi); tb_ctl_start(tb->ctl); scoped_guard(spinlock_irq, &nhi->lock) bitmap_zero(nhi->dma_hops_used, nhi->hop_count); }and schedule it from
tb_ring_stop()once the last DMA ring is gone:ring->running = false; if (ring->nhi->dma_hops_used && ring_is_dma(ring) && !nhi_dma_rings_running(ring->nhi)) needs_reset = true; err: spin_unlock(&ring->lock); spin_unlock_irq(&ring->nhi->lock); if (needs_reset) schedule_work(&ring->nhi->reset_work);Plus
INIT_WORK()innhi_probe(),cancel_work_sync()innhi_shutdown(), and tb_domain_pause()/tb_domain_unpause() dropped. The rest of your sketch is unchanged. I can post it as a proper patch if you want to look at it in full.Quoted 372 lines
Quoted 371 lines
drivers/thunderbolt/domain.c +26
-23@@ -671,6 +671,32 @@ int tb_domain_runtime_resume(struct tb *tb)return 0 ; } +/** +* tb_domain_pause() - Pause the domain +* @tb: Domain to pause +* +* Blocks the connection manager and stops the control channel so that +* the caller can touch the host interface hardware behind its back. +* Takes @tb->lock. +* +* Once done whatever operations needed call tb_domain_unpause(). +*/ +void tb_domain_pause(struct tb *tb) +{ +mutex_lock (&tb->lock); +tb_ctl_stop (tb->ctl); +} + +/** +* tb_domain_unpause() - Resume paused domain +* @tb: Domain to unpause +*/ +void tb_domain_unpause (struct tb *tb) +{ +tb_ctl_start (tb->ctl); +mutex_unlock (&tb->lock); +} +/** * tb_domain_disapprove_switch() - Disapprove switch * @tb: Domain the switch belongs to @@ -835,21 +861,6 @@ int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, transmit_ring, receive_path, receive_ring); } -static void tb_domain_reset_interface(struct tb *tb) -{ -struct tb_nhi *nhi = tb->nhi; - -if (!nhi->ops->reset_interface) -return ; - -guard (mutex)(&tb->lock); - -/* The reset clears the ring state so stop the control channel */ -tb_ctl_stop (tb->ctl); - nhi->ops->reset_interface (nhi); -tb_ctl_start (tb->ctl); -} -/** * tb_domain_disconnect_xdomain_paths() - Disable DMA paths for XDomain * @tb: Domain disabling the DMA paths @@ -872,20 +883,11 @@ int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, int transmit_path, int transmit_ring, int receive_path, int receive_ring) { - int ret; - if (!tb->cm_ops->disconnect_xdomain_paths) return -ENOTSUPP; - ret = tb->cm_ops->disconnect_xdomain_paths(tb, xd, transmit_path, + return tb->cm_ops->disconnect_xdomain_paths(tb, xd, transmit_path, transmit_ring, receive_path, receive_ring); -if (ret) -return ret; - -if (tb->nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN ) -tb_domain_reset_interface (tb); - -return 0 ; }static int disconnect_xdomain (struct device *dev,void *data)drivers/thunderbolt/nhi.c +118
-25@@ -523,9 +523,45 @@ irqreturn_t ring_msix(int irq, void *data)return IRQ_HANDLED ; } +static bool ring_is_dma(const struct tb_ring *ring) +{ +return ring->hop >=RING_FIRST_USABLE_HOPID ; +} + +static bool nhi_dma_rings_running (const struct tb_nhi *nhi) +{ +int i; + +lockdep_assert_held (&nhi->lock); + +/* +* Holding nhi->lock is enough here because tb_ring_start() and +* tb_ring_stop() both hold it when they update ring->running. +*/ +for (i =RING_FIRST_USABLE_HOPID ; i < nhi->hop_count; i++) { +if (nhi->tx_rings[i] && nhi->tx_rings[i]->running) +return true; +if (nhi->rx_rings[i] && nhi->rx_rings[i]->running) +return true; + } + +return false; +} + +static bool nhi_avoid_used_dma_rings (const struct tb_nhi *nhi) +{ +lockdep_assert_held (&nhi->lock); + +if (!(nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN )) +return false; + +return nhi_dma_rings_running (nhi); +} +static int nhi_alloc_hop (struct tb_nhi *nhi,struct tb_ring *ring) {unsigned int start_hop =RING_FIRST_USABLE_HOPID ; +bool avoid_used;int ret =0 ;if (nhi->quirks &QUIRK_E2E ) {@@ -539,6 +575,8 @@ static int nhi_alloc_hop(struct tb_nhi *nhi, struct tb_ring *ring)spin_lock_irq(&nhi->lock); + avoid_used = nhi_avoid_used_dma_rings(nhi); +if (ring->hop < 0) { unsigned int i; @@ -547,6 +585,8 @@ static int nhi_alloc_hop(struct tb_nhi *nhi, struct tb_ring *ring) * range 1 .. hop_count - 1. */ for (i = start_hop; i < nhi->hop_count; i++) { +if (avoid_used &&test_bit (i, nhi->dma_hops_used)) +continue ;if (ring->is_tx) {if (!nhi->tx_rings[i]) { ring->hop = i;@@ -559,6 +599,13 @@ static int nhi_alloc_hop(struct tb_nhi *nhi, struct tb_ring *ring) } } } + +if (ring->hop <0 && avoid_used) { +dev_warn (nhi->dev, +"out of HopIDs that do not need a host interface reset\n" ); + ret = -EBUSY ; + goto err_unlock; + } }if (ring->hop >0 && ring->hop < start_hop) {@@ -583,6 +630,15 @@ static int nhi_alloc_hop(struct tb_nhi *nhi, struct tb_ring *ring) ret = -EBUSY ; goto err_unlock; } +/* Automatic allocation above already skips the used HopIDs */ +if (avoid_used &&ring_is_dma (ring) && +test_bit (ring->hop, nhi->dma_hops_used)) { +dev_warn (nhi->dev, +"hop %d needs a host interface reset before reuse\n" , + ring->hop); + ret = -EBUSY ; + goto err_unlock; + }if (ring->is_tx) nhi->tx_rings[ring->hop] = ring;@@ -710,6 +766,62 @@ struct tb_ring *tb_ring_alloc_rx(struct tb_nhi *nhi, int hop, int size, }EXPORT_SYMBOL_GPL (tb_ring_alloc_rx); +/** +* nhi_reset_interface() - Reset the host interface +* @nhi: Host interface to reset +* +* Brings the registers in the memory BAR back to their default state and +* clears the End-to-End Flow Control state. The caller is responsible for +* stopping the control channel over the reset because it clears the ring +* state as well. +*/ +static void nhi_reset_interface(struct tb_nhi *nhi) +{ +u32 val; + + val =ioread32 (nhi->iobase +REG_CAPS ); +/* Only v1 host interfaces implement the reset */ +if (FIELD_GET (REG_CAPS_VERSION_MASK , val) >=REG_CAPS_VERSION_2 ) +return ; + +dev_dbg (nhi->dev,"issuing host interface reset\n" ); + +iowrite32 (REG_HOST_INTERFACE_RESET_RST , + nhi->iobase +REG_HOST_INTERFACE_RESET ); +/* Wait for tHIReset (10 ms) to complete */ +usleep_range (10000 ,20000 ); +} + +static void nhi_reset_quirk (struct tb_ring *ring) +{ +struct tb_nhi *nhi = ring->nhi; +struct tb *tb =dev_get_drvdata (nhi->dev); + +if (!(nhi->quirks &QUIRK_RESET_DMA_ON_TEARDOWN )) +return ; +if (!ring_is_dma (ring)) +return ; + + scoped_guard(spinlock_irq, &nhi->lock) { +if (nhi->going_away) +return ; +if (bitmap_empty (nhi->dma_hops_used, nhi->hop_count)) +return ; +/* +* If any of the DMA rings are still running we cannot +* do the reset. +*/ +if (nhi_dma_rings_running (nhi)) +return ; + +bitmap_zero (nhi->dma_hops_used, nhi->hop_count); + } + +/* CM must be blocked before host interface reset can be done */ + scoped_guard(tb_domain_paused, tb) +nhi_reset_interface (nhi); +} +/** * tb_ring_start() - enable a ring * @ring: Ring to start @@ -721,6 +833,8 @@ void tb_ring_start(struct tb_ring *ring)u16 frame_size;u32 flags; +nhi_reset_quirk (ring); +spin_lock_irq (&ring->nhi->lock);spin_lock (&ring->lock);if (ring->nhi->going_away)@@ -781,6 +895,8 @@ void tb_ring_start(struct tb_ring *ring)if (!(ring->flags &RING_FLAG_NO_INTERRUPT ))ring_interrupt_active (ring, true); ring->running = true; +if (ring->nhi->dma_hops_used &&ring_is_dma (ring)) +__set_bit (ring->hop, ring->nhi->dma_hops_used); err:spin_unlock (&ring->lock);spin_unlock_irq (&ring->nhi->lock);@@ -1241,32 +1357,6 @@ static void nhi_reset(struct tb_nhi *nhi)dev_warn (nhi->dev,"timeout resetting host router\n" ); } -/** -* nhi_reset_interface() - Reset the host interface -* @nhi: Host interface to reset -* -* Brings the registers in the memory BAR back to their default state and -* clears the End-to-End Flow Control state. The caller is responsible for -* stopping the control channel over the reset because it clears the ring -* state as well. -*/ -void nhi_reset_interface(struct tb_nhi *nhi) -{ -u32 val; - - val =ioread32 (nhi->iobase +REG_CAPS ); -/* Only v1 host interfaces implement the reset */ -if (FIELD_GET (REG_CAPS_VERSION_MASK , val) >=REG_CAPS_VERSION_2 ) -return ; - -dev_dbg (nhi->dev,"issuing host interface reset\n" ); - -iowrite32 (REG_HOST_INTERFACE_RESET_RST , - nhi->iobase +REG_HOST_INTERFACE_RESET ); -/* Wait for tHIReset (10 ms) to complete */ -usleep_range (10000 ,20000 ); -} -static struct tb *nhi_select_cm(struct tb_nhi *nhi) { bool linked = false; @@ -1331,6 +1421,13 @@ int nhi_probe(struct tb_nhi *nhi)if (!nhi->tx_rings || !nhi->rx_rings || !nhi->interrupt_mask)return -ENOMEM ; + if (nhi->quirks & QUIRK_RESET_DMA_ON_TEARDOWN) { + nhi->dma_hops_used =devm_bitmap_zalloc (dev, nhi->hop_count, +GFP_KERNEL ); +if (!nhi->dma_hops_used) +return -ENOMEM ; + } +nhi_reset (nhi);/* In case someone left them on. */ drivers/thunderbolt/nhi.h +0
-1@@ -36,7 +36,6 @@ irqreturn_t nhi_msi(int irq, void *data);irqreturn_t ring_msix (int irq,void *data);int nhi_probe (struct tb_nhi *nhi);void nhi_shutdown (struct tb_nhi *nhi); -void nhi_reset_interface (struct tb_nhi *nhi);extern const struct dev_pm_ops nhi_pm_ops; @@ -55,7 +54,6 @@ extern const struct dev_pm_ops nhi_pm_ops; * @release_ring_irq: NHI specific interrupt release hook* @is_present: Whether the device is currently present on the parent bus
* @init_interrupts: NHI specific interrupt initialization hook
- * @reset_interface: Resets the host interface*/ struct tb_nhi_ops { int (*init)(struct tb_nhi *nhi);drivers/thunderbolt/nhi.h +0
-1@@ -71,7 +69,6 @@ struct tb_nhi_ops {void (*release_ring_irq)(struct tb_ring *ring);bool (*is_present)(struct tb_nhi *nhi);int (*init_interrupts)(struct tb_nhi *nhi); -void (*reset_interface)(struct tb_nhi *nhi); };/* drivers/thunderbolt/pci.c +0
-2@@ -357,7 +357,6 @@ static const struct tb_nhi_ops pci_nhi_default_ops = { .shutdown = nhi_pci_release_irq, .is_present = nhi_pci_is_present, .init_interrupts = nhi_pci_init_msi, - .reset_interface = nhi_reset_interface, };/* Ice Lake specific NHI operations */ @@ -576,7 +575,6 @@ static const struct tb_nhi_ops icl_nhi_ops = { .release_ring_irq = nhi_pci_ring_release_msix, .is_present = nhi_pci_is_present, .init_interrupts = nhi_pci_init_msi, - .reset_interface = nhi_reset_interface, };static int nhi_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id)drivers/thunderbolt/tb.h +4
-0@@ -826,6 +826,10 @@ int tb_domain_thaw_noirq(struct tb *tb);void tb_domain_complete (struct tb *tb);int tb_domain_runtime_suspend (struct tb *tb);int tb_domain_runtime_resume (struct tb *tb); +void tb_domain_pause (struct tb *tb); +void tb_domain_unpause (struct tb *tb); +DEFINE_GUARD(tb_domain_paused, struct tb *, tb_domain_pause(_T), + tb_domain_unpause(_T))int tb_domain_disapprove_switch (struct tb *tb,struct tb_switch *sw);int tb_domain_approve_switch (struct tb *tb,struct tb_switch *sw);int tb_domain_approve_switch_key (struct tb *tb,struct tb_switch *sw);include/linux/thunderbolt.h +4
-0@@ -537,6 +537,9 @@ void tb_service_properties_changed(struct tb_service *svc);* MSI-X is used. * @hop_count: Number of rings (end point hops) supported by NHI. * @quirks: NHI specific quirks if any +* @dma_hops_used: Bitmap of HopIDs that have been programmed after the +* last host interface reset. Used only with +* %QUIRK_RESET_DMA_ON_TEARDOWN. * @domain_released: Completed when domain has been fully released * @host_reset: Host router was reset on driver load, or forced on system * shutdown/reboot. When set, tb_stop() asserts DPR on connected @@ -557,6 +560,7 @@ struct tb_nhi {struct work_struct interrupt_work;u32 hop_count;unsigned long quirks; +unsigned long *dma_hops_used;struct completion domain_released;bool host_reset; };
Hi,
Quoted 24 lines · Sanath
Ported it and stressed it on two Strix Halo hosts connected back to back.
REG_CAPSreportshop_count= 3 here, so two usable DMA HopIDs. Observations:- Single tunnel it works: 50 x traffic then link down/up, plus 42 x
dma_testcreate / transfer / teardown. One reset per cycle, no ping loss, no errors, and every ring restart had a reset before it.- Every reset is preceded by "dangling request in
request_queue" and a WARNING fromtb_ctl_stop(), 8 of 8 cycles, viatb_domain_pause()<-tb_ring_start()<-tbnet_connected_work().- Two tunnels: the networking ring is stopped and restarted with no reset in between, because the check only runs in
nhi_alloc_hop()and tbnet reuses its rings across a reconnect. 18 such cycles did not hang, so the unsafe reuse is reachable but I cannot say it hangs.- When the check does fire it takes networking down, reproduced twice:
"RTNETLINK answers: Cannot allocate memory" plus "out of HopIDs that do not need a host interface reset", until the second tunnel stops.-
tb_domain_pause()takestb->lockfromtb_ring_start(), while unplug holdstb->lockacrosstbnet_remove()->stop_login()->cancel_work_sync(&net->connected_work).
Quoted 6 lines
Moving the reset into a per-NHI work item scheduled from
tb_ring_stop()when the last DMA ring stops removes the warning and thetb->lockinversion, and passes the same tests cleanly. The reuse hole and the lockout still need the reset to key off ring reuse rather than ring allocation.Mika, Can I respin your patch along those lines and post it as a new version?
Of course. I'm thinking though that should we do the revert for v7.3-rcX now and then do the proper fix for v7.4 with your updated patch?
Quoted 32 lines · Mika Westerberg
Hi,
Quoted 29 lines · Sanath
Ported it and stressed it on two Strix Halo hosts connected back to back.
REG_CAPSreportshop_count= 3 here, so two usable DMA HopIDs. Observations:- Single tunnel it works: 50 x traffic then link down/up, plus 42 x
dma_testcreate / transfer / teardown. One reset per cycle, no ping loss, no errors, and every ring restart had a reset before it.- Every reset is preceded by "dangling request in
request_queue" and a WARNING fromtb_ctl_stop(), 8 of 8 cycles, viatb_domain_pause()<-tb_ring_start()<-tbnet_connected_work().- Two tunnels: the networking ring is stopped and restarted with no reset in between, because the check only runs in
nhi_alloc_hop()and tbnet reuses its rings across a reconnect. 18 such cycles did not hang, so the unsafe reuse is reachable but I cannot say it hangs.- When the check does fire it takes networking down, reproduced twice:
"RTNETLINK answers: Cannot allocate memory" plus "out of HopIDs that do not need a host interface reset", until the second tunnel stops.-
tb_domain_pause()takestb->lockfromtb_ring_start(), while unplug holdstb->lock across tbnet_remove() -> stop_login() -> cancel_work_sync(&net->connected_work).Moving the reset into a per-NHI work item scheduled from
tb_ring_stop()when the last DMA ring stops removes the warning and thetb->lockinversion, and passes the same tests cleanly. The reuse hole and the lockout still need the reset to key off ring reuse rather than ring allocation.
Quoted 4 lines
Quoted 1 line
Mika, Can I respin your patch along those lines and post it as a new version?
Of course. I'm thinking though that should we do the revert for v7.3-rcX now and then do the proper fix for v7.4 with your updated patch?
Yeah; I think that's the right call right now given the timing and risk.
Hi Mika,
Quoted 27 lines · Mika Westerberg
Hi,
On Tue, Sep 15, 2026 at 04:51:00AM +0000, S, Sanath wrote:
Ported it and stressed it on two Strix Halo hosts connected back to back.REG_CAPSreportshop_count= 3 here, so two usable DMA HopIDs. Observations:- Single tunnel it works: 50 x traffic then link down/up, plus 42 x
dma_testcreate / transfer / teardown. One reset per cycle, no ping loss, no errors, and every ring restart had a reset before it.- Every reset is preceded by "dangling request in
request_queue" and a WARNING fromtb_ctl_stop(), 8 of 8 cycles, viatb_domain_pause()<-tb_ring_start()<-tbnet_connected_work().- Two tunnels: the networking ring is stopped and restarted with no reset in between, because the check only runs in
nhi_alloc_hop()and tbnet reuses its rings across a reconnect. 18 such cycles did not hang, so the unsafe reuse is reachable but I cannot say it hangs.- When the check does fire it takes networking down, reproduced twice:
"RTNETLINK answers: Cannot allocate memory" plus "out of HopIDs that do not need a host interface reset", until the second tunnel stops.-
tb_domain_pause()takestb->lockfromtb_ring_start(), while unplug holdstb->lock across tbnet_remove() -> stop_login() -> cancel_work_sync(&net->connected_work).
Quoted 8 lines
Moving the reset into a per-NHI work item scheduled from
tb_ring_stop()when the last DMA ring stops removes the warning and thetb->lockinversion, and passes the same tests cleanly. The reuse hole and the lockout still need the reset to key off ring reuse rather than ring allocation.Mika, Can I respin your patch along those lines and post it as a new version? Of course. I'm thinking though that should we do the revert for v7.3-rcX now and then do the proper fix for v7.4 with your updated patch?
The reworked series is posted here:
https://lore.kernel.org/all/[email protected]/
Thanks,
--
Basavaraj