Skip to content

thunderbolt: tb: a router that leaves during the CIO wake is an unplug - #3960

Draft
themartiano wants to merge 1 commit into
aurora-silicon:mainfrom
themartiano:fix/tb-cio-wake-unplug
Draft

themartiano wants to merge 1 commit into
aurora-silicon:mainfrom
themartiano:fix/tb-cio-wake-unplug

Conversation

@themartiano

@themartiano themartiano commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What: After a native CIO sleep the router resume marks the routers that did not come back as unplugged; their tunnels are skipped and retired later, as after a hot unplug. A router that leaves a moment later, while the tunnels are replayed, fails the replay instead: the wake fails and apple_nhi_cio_resume() panics ("Apple CIO: resume failed"). Now, when a replay fails and the host router still answers, the routers behind it that no longer answer are marked unplugged as the router resume would have, and the replay starts over with the rest. A failure with every router answering, a host that does not answer, and the suspend's own unwind still fail as before.

Tested: Host side at the head, on main 30c1870. tools/asahi/tb-cio-sleep-tests.py: 48 cases, 33 negative controls pass (main: 42 and 29). The new cases fail against main's tb-cio-sleep.c (the wake fails: !tb_cio_wake(&tb, &pci_lost)). run-host-tests.py --only cio 5/5, the same as main. arm64 W=1 LLVM 20 build of drivers/thunderbolt/: the same 208 kernel-doc warnings as main, none in tb-cio-sleep.c. checkpatch --strict: clean. No KUnit suite covers these paths (apple-kunit.py plan picks none). Hardware: none. This was found by reading the code; the window was not hit on a Mac. This commit is in our 7.3.0 next4 test kernel (main ba12094 plus this and other open branches; the files it touches are the same on today's main). A row at this head is not yet run.

Risk: two-way · J713, J714s, J716c, and only in an error path that panics today. If it is wrong, a wake that would have panicked carries on with routers marked unplugged.

Other Macs: The code runs only where apple_nhi_cio_bind() sets up a sleep in place: the J713 (T8132) and the J714s and J716c (T6050). On those it changes only what happens after a tunnel replay fails, which today ends in a panic. Every other Mac, the J715 included, does not run it. It can help all three hosts the same way, if the window is ever hit.

Not yet: any hardware evidence. The planned J713 check: a test kernel with a delay before the replay and a dock unplugged in it (expect lost during the CIO wake, the resume completes, a replug works); 20 pulls aimed at the wake; no regression in 10 docked sleeps.

Details
  • A topology failure on a wake can only be the host's (lost children are skipped there), so it stays fatal. On a replay failure the host router is read first; if it does not answer, the wake fails as before. Then each router behind it is read, and only those that do not answer are marked unplugged with tb_sw_set_unplugged(). The replay starts over only if at least one was newly marked, so it ends: each retry needs one more router gone.
  • Not proven: that the window is ever hit; how a real router that just left answers a config read (timeout or error) and how long that takes; that everything behind it (xHCI, PCIe-C) survives. If a router was lost before and its parent leaves in the window, tb_sw_set_unplugged() warns once.
  • Host model cases: dock gone before the first tunnel, dock gone after the first one, dock still answering, host gone, the suspend's unwind, no PCIe tunnel. Negative controls: failing on a router that left, retiring a router that answers, retiring behind a host that does not answer, retiring in the unwind.
  • Does not need thunderbolt: tb: stop waiting for a CIO peer that is gone #3959 (a CIO peer that is gone), which also changes tb-cio-sleep.c: each applies alone to main, and the two merge without conflict. Same story as thunderbolt: tb: stop waiting for a CIO peer that is gone #3959 and iommu/apple-dart: cio: release the clock protection of every removed port DART #3962; best reviewed after them.
Evidence
  • Head 094e3b1, parent 30c1870 (main). Cherry-picked from our branch without conflict; it does not need the other tb-cio-sleep.c PR.
  • python3 tools/asahi/tb-cio-sleep-tests.py: PASS 48 native tunnel replay cases, PASS 33 negative controls (main: 42 and 29).
  • Same test with drivers/thunderbolt/tb-cio-sleep.c taken from main and only the real variant run: fails, Assertion '!tb_cio_wake(&tb, &pci_lost)' failed.
  • tools/asahi/run-host-tests.py --only cio: 5/5, main 5/5.
  • Build: make O=<dir> LLVM=/usr/lib/llvm20/bin/ ARCH=arm64 olddefconfig from our J713 test kernel's config (7.3.0-0.next3), then W=1 drivers/thunderbolt/ (clang 20.1.8). 208 warnings, all kernel-doc in files this does not touch; the list is identical to main's.
  • scripts/checkpatch.pl --strict -g main..HEAD: 0 errors, 0 warnings, 0 checks.
  • scripts/ci/apple-kunit.py plan: no suite for these files.

After a native CIO sleep the router resume marks the routers that did
not come back as unplugged, and their tunnels are skipped and retired
later. A router that leaves a moment after that, while the tunnels are
replayed, fails the replay instead: the wake fails and
apple_nhi_cio_resume() panics.

When a replay fails while the host router still answers, look for the
routers behind it that no longer do, mark them as the router resume
would have, and replay what is left. Host steps, a failure with every
router answering and the suspend's own unwind fail as before.

Found by reading the code. The window is short and was not hit on
hardware. The host test covers it.

Signed-off-by: Eduardo <git@martiano.me>

This branch has not been deployed

No deployments
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.

1 participant