Skip to content

thunderbolt: unregister XDomains when the domain is removed - #1319

Merged
RyanTheTide merged 3 commits into
integration/aurorafrom
tbnet/xdomain-domain-remove
Nov 9, 2026
Merged

RyanTheTide merged 3 commits into
integration/aurorafrom
tbnet/xdomain-domain-remove

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Removing a Thunderbolt domain left its XDomains registered. tb_xdomain_remove() only takes an XDomain out of the topology and leaves unregistering it to the caller, and tb_domain_remove() never did that. When the Apple ACIO driver restarts a port, for example after the partner Mac reboots, the old 0-1 and its thunderbolt-net service survived. Adding the new XDomain then failed with a duplicate sysfs name. The stale thunderbolt-net kept answering the partner's ThunderboltIP login through the freed control channel and oopsed in tb_cfg_request(). The same happens when the ACIO platform device is unbound.

  • thunderbolt: Unregister XDomains when the domain is removed. tb_domain_remove() unregisters the unplugged XDomains after the control channel is stopped and the domain workqueue is drained, and before the connection manager is deinitialized. Requests that service drivers send while unbinding fail at once with -ENOTCONN.
  • thunderbolt: Refuse XDomain DMA paths once the XDomain is unplugged. tb_approve_xdomain_paths() takes tb->lock before it looks up any ports, and returns -ENODEV for an unplugged XDomain or a stopped domain whose root switch is gone. Before, thunderbolt-net's connected work could follow a NULL root switch here while the domain was stopping.
  • net: thunderbolt: Unregister the protocol handler before the netdev. tbnet_remove() takes the ThunderboltIP handler off the list first and cancels any pending disconnect work before free_netdev().

Closes #1318

Testing

J616s (T6040) <-> M2 (T8112) over USB4 with thunderbolt-net up on both sides. Test kernel = fleet44 base + this branch on the J616s; the M2 runs fleet44.

  • ACIO unbind with the link up, before and after. fleet44: the domain is removed, but 0-1 and 0-1.0 stay on the thunderbolt bus as dangling devices under the removed domain0, with no host disconnected. A later reconnect never finishes. With this branch: thunderbolt-net logs out (fails at once on the stopped control channel), its rings are freed, 0-1 reports host disconnected and the bus is empty. All of this happens before the control channel rings are freed. No WARN, BUG or oops.
  • 50 rounds rotating J616s thunderbolt0 down/up, M2 thunderbolt0 down/up (remote logout and login) and M2 reboots (17 partner drops). Across the whole boot: 0 oopses, 0 BUGs, 0 WARNs, 0 call traces, 0 duplicate 0-1. Each drop logged host disconnected.
    • Link and ping came back in 40 of 50 rounds.
    • 7 failures came after an M2 thunderbolt0 down/up. In each one a second remote login arrives while the J616s is activating the DMA paths, and every route 0 config read then times out (DMA RX path activation failed: -110). The same control-port timeout already shows up on fleet44 without this branch, and the next partner drop recovered the link every time. It is a separate issue.
    • 3 failures are one M2 reboot whose link never got past bonding (no XDomain on either side), plus the two rounds after it. The next M2 reboot recovered it.
  • J616s FLEET quick suite (non-sleep rows), compared with the fleet44 baseline, run twice: no new kernel errors, WARNs, BUGs or oopses. AVC 0, failed units 0. Media, ANE, BT, Wi-Fi and SD rows unchanged.

🤖 Generated with Claude Code

Since XDomains are removed from the bus without holding tb->lock,
tb_xdomain_remove() only takes an XDomain out of the topology; the
caller unregisters it later with tb_domain_unregister_unplugged_xdomains().
tb_domain_remove() never does that. Stopping the connection manager
removes the root switch, which marks every XDomain unplugged and calls
tb_xdomain_remove(), but the XDomain stays registered on the bus and its
service drivers stay bound.

When the domain is then freed, a bound thunderbolt-net keeps its
protocol handler on the global list with xd->tb pointing at the freed
domain. A host router driver that removes and re-adds its domain when
the link restarts (the Apple ACIO driver does so when the partner
reboots) then gets a new domain with the same index: adding the new
XDomain fails with a duplicate "0-1" sysfs name, and the stale
thunderbolt-net answers the partner's ThunderboltIP login, which now
arrives on the new control channel, through the freed one:

  Unable to handle kernel paging request at virtual address ...
  pc : queued_spin_lock_slowpath+0x18c/0x5d0
  Call trace:
   queued_spin_lock_slowpath+0x18c/0x5d0 (P)
   _raw_spin_lock_irqsave+0x9c/0xa8
   __mutex_unlock_slowpath+0x90/0x338
   mutex_unlock+0x34/0x70
   tb_cfg_request+0x218/0x250 [thunderbolt]
   tb_xdomain_response+0x74/0xb0 [thunderbolt]
   tbnet_login_response+0x9c/0x238 [thunderbolt_net]
   tbnet_handle_packet+0xd0/0x358 [thunderbolt_net]
   tb_xdomain_handle_request+0xf0/0x1f0 [thunderbolt]
   tb_domain_event_cb+0x60/0xa8 [thunderbolt]
   tb_ctl_handle_event+0x38/0x170 [thunderbolt]
   tb_ctl_rx_callback+0x1b8/0x528 [thunderbolt]
   ring_work+0x138/0x280 [thunderbolt]

Unregister the unplugged XDomains in tb_domain_remove() once tb->lock
is dropped and the domain workqueue is drained, before the connection
manager is deinitialized and the domain device goes away. The control
channel is already stopped at that point, so requests the service
drivers send while unbinding (thunderbolt-net's logout) fail with
-ENOTCONN instead of waiting for a timeout.

Fixes: a8937f3 ("thunderbolt: Remove XDomain from the bus without holding tb->lock")
Closes: #1318
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
tbnet_remove() unregisters the network device first and the
ThunderboltIP protocol handler after it. In between, a login or logout
packet from the remote host still reaches tbnet_handle_packet(), which
can queue login, connect or disconnect work for a device that is being
torn down. A logout queues the disconnect work without checking whether
the interface is up, and nothing cancels it after tbnet_stop() has run,
so it can run after free_netdev().

Take the handler off the list first, then unregister the netdev, and
cancel any disconnect work that is still pending before freeing it.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
tb_approve_xdomain_paths() looks up the destination and NHI ports
before it takes tb->lock. A service driver can still ask for paths
while the domain is being stopped: thunderbolt-net enables them from
its connected work, which a ThunderboltIP login queued just before the
control channel was stopped. By then tb_stop() may have removed the
routers and cleared tb->root_switch, so tb_switch_find_port() follows
a NULL pointer, and the XDomain's parent router is a removed switch.

Take tb->lock first and return -ENODEV when the XDomain is unplugged
or the root switch is gone. tb_disconnect_xdomain_paths() already
skips an unplugged XDomain the same way.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide marked this pull request as ready for review November 9, 2026 13:42
@RyanTheTide
RyanTheTide merged commit cb7c720 into integration/aurora Nov 9, 2026
1 check passed
@RyanTheTide
RyanTheTide deleted the tbnet/xdomain-domain-remove branch November 9, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

J616s USB4: ACIO port restart leaves the old XDomain registered; tbnet uses a freed control channel (Oops); control port wedges at boot

1 participant