Repository navigation
thunderbolt: unregister XDomains when the domain is removed - #1319
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-1and 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 intb_cfg_request(). The same happens when the ACIO platform device is unbound.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.
0-1and0-1.0stay on the thunderbolt bus as dangling devices under the removeddomain0, with nohost 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-1reportshost disconnectedand the bus is empty. All of this happens before the control channel rings are freed. No WARN, BUG or oops.thunderbolt0down/up, M2thunderbolt0down/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 duplicate0-1. Each drop loggedhost disconnected.thunderbolt0down/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.🤖 Generated with Claude Code