Repository navigation
thunderbolt: Apple native CIO deep sleep with a host-to-host peer or no PCIe tunnel (M4 MacBook Air) - #2692
Conversation
…tunnel A deep sleep with a USB4 partner that has no PCIe tunnel behind the router, such as a host-to-host cable to another Mac or a device that tunnels only USB or DisplayPort, was refused at prepare: the native CIO sleep found no PCIe-C tunnel to stop and returned -ENODEV, so the M4 MacBook Air could not sleep with such a cable in. There is then nothing behind the router to stop: prepare, suspend, wake and complete skip the tunnel's steps, and the router, the NHI's DART, the controller and the PHY sleep as with a dock. The T6050 sleep has only run with a dock's tunnel and still refuses without one. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The native CIO sleep keeps the tunnels and routers behind the host router across its power cycle, and refused any topology with an XDomain peer: a host-to-host cable to another Mac kept the M4 MacBook Air out of deep sleep. The host at the other end owns its half of the link, which the power cycle cannot keep. Release the peer as an unplug does, once nothing in the connection manager can refuse the sleep any more: find it by its adapter's downstream route (the adapter's xdomain pointer was not always set when the sleep was prepared), stop it, and unregister it and its services once the domain lock is dropped, as the hotplug handler does, so that thunderbolt_net gives back its rings before the host's are checked. The rescan after the wake, or after a later refusal, finds it again. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
…O sleep The host router's own sleep has only run with a router below it. With a host-to-host peer the lane link to another host stays up across the release; take the root lane adapters down as an unplug would, so the router sleeps with no link, and enable them again when the sleep completes. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
…ative CIO sleep" Not needed: on the M4 MacBook Air the router sleeps and comes back with a host-to-host peer's lane link left up (3/3 deep sleeps without it, after 10/10 with it), and the lanes stayed off through the firmware's lane init at the wake for nothing. This reverts commit e1ce37e. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
Ready for review. It is what the J713 deep sleep needs whenever the USB4 tether, or any XDomain peer, is attached. The tip candidate t3 (integration tip plus the J713 PR heads, but not this PR) cleanly refused all three deep sleeps at NHI prepare with -95, and this series is the fix for that refusal. It has also run inside the lab kernel for #2721: 3/3 deep sleeps with the peer attached and an external monitor, each with "xdomain released for the sleep" and the CIO router asleep and back. Peer return after a wake, from the logs on both ends: when the J713 sleeps, the J616s sees the link drop. Its |
|
Blockers: 2.
Smaller:
Checked and fine:
Still to run: the docked case with a PCIe tunnel, as the body says. |
… in the host tests
The host models had not followed the two changes before this one:
- cio-native-tests: a partner with no PCIe tunnel no longer refuses the
prepare. It now runs a full sleep and wake with nothing behind the
router, and a prepare followed only by complete. The lost-tunnel
mutation follows the NULL check.
- tb-cio-sleep-tests: models the bus's XDomain calls, and covers:
- a peer on the root router, released once, with its services
unregistered outside the domain lock;
- a peer behind a device router (the recursion), and both at once;
- a refusal before the release, which leaves the peer untouched;
- a tunnel's refusal after it, where the release stands.
Four new negative controls check that the peer is marked unplugged,
unregistered, found behind the device router, and cleared from its
port.
The comments said the wake's rescan finds the peer again. Hardware
shows otherwise. After a J713 deep sleep its link to a J616s does not
train back, and both routers stay in lane init until a replug or a
reboot, so the peer is not found again. Say so.
The T6050 sleep still refuses without a PCIe tunnel because it has only
ever run with a dock's tunnel. That is kept fail-closed as before.
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
Both blockers are addressed at c46c72b (one commit on top, no force push).
The reason for keeping T6050 fail-closed without a tunnel is now in c46c72b's commit message. Squash-merging drops the e1ce37e / revert pair from the history. |
|
Re-review at c46c72b: no blockers left.
One thing to keep in mind for #2726: the new prepare comment says a tunnel prepare that fails after the release also leaves the peers released. So a dock plus a host-to-host peer can lose the peer on a refused sleep too, not only after a successful one. That is rare (it needs both a dock tunnel and an XDomain peer) and is now documented and tested, so it's not a blocker. Still to run, as the body says: the docked case with a PCIe tunnel. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Adversarial review at head c46c72bfbc16da25a79e5edcd24a55b5afa923cf.
Blocker
- T6050 regression:
apple_nhi_cio_prepare()destroys live XDomain peers before refusing-ENODEVwhen no PCIe tunnel is present (drivers/thunderbolt/apple-cio-sleep.c:504-533).- On T6050 (
anhi->cio_t6050 == true, J714s / J716c),apple_nhi_cio_prepare()callstb_cio_sleep_prepare(anhi->tb)at line 504 before checkingif (!pcie && anhi->cio_t6050)at line 530. - Previously, with a host-to-host USB4 cable (XDomain peer, no PCIe tunnel),
tb_cio_check_topology()returned-EOPNOTSUPPbefore mutating state, leaving the peer andthunderbolt_netintact. - With this PR,
tb_cio_check_topology()skipsport->xdomain, sotb_cio_sleep_prepare()runstb_cio_release_xdomains()(markingxd->is_unplugged = true, callingtb_xdomain_remove(), clearingport->xdomain, disconnecting DMA paths, callingtb_port_unconfigure_xdomain()) and thentb_domain_unregister_unplugged_xdomains()(unbindingthunderbolt_netand unregistering the XDomain device). apple_nhi_cio_prepare()then hitsif (!pcie && anhi->cio_t6050)at line 530, callstb_cio_sleep_complete()(which does not rescan XDomains), and returns-ENODEVfrom.prepare(). Because.prepare()failed, the PM core aborts suspend and never calls.complete()(apple_nhi_complete()->tb_domain_complete()->tb_complete()->tb_scan_switch()), leavingtcm->resume_cleanup_pendingstale and the live XDomain /thunderbolt_netlink permanently torn down even though the machine never slept.- Fix:
apple_nhi_prepare()already setsacio->pcie_pm_prepared = truebefore callingapple_nhi_cio_prepare()(freezingpcie_tunnel_work), andacio->native_sleepis set at line 501. Look uppcieand enforceif (!pcie && anhi->cio_t6050) { ret = -ENODEV; goto release_cable; }before callingtb_cio_sleep_prepare(anhi->tb)(and cover the T6050 no-PCIe refusal order intools/asahi/cio-native-tests.csotb_cio_sleep_prepare()is asserted not to run). - (Note: the same unrecovered peer teardown also happens on J713 if a later prepare step fails — e.g., PHY, DART, or
apple_pcie_tunnel_cio_prepare()with both a dock and an XDomain peer. Checking fail-fast prerequisites beforetb_cio_sleep_prepare()reduces that window as well.)
- On T6050 (
Non-blocking notes
- Non-null ports & lookup comment in
tb_cio_release_xdomains()(drivers/thunderbolt/tb-cio-sleep.c:40-54):- Adding
if (!tb_port_is_null(port)) continue;avoids computingtb_downstream_route(port)and walking the full router tree viatb_xdomain_find_by_route()for every protocol adapter (NHI, PCIe, USB3, DP IN/OUT). tb_xdomain_find_by_route()(switch_find_xdomain()indrivers/thunderbolt/xdomain.c) only walksport->xdomainpointers in the switch tree rather than searchingtb_bus_type, so the comment"the bus holds it wherever the port keeps it"is inaccurate; usingport->xdomaindirectly withtb_xdomain_get()(matchingtb_handle_hotplug()) is simpler and avoids the O(P²) walk.
- Adding
- Hardware evidence & regression check:
- Host tests CI (
host-tests) is green atc46c72bf. - Once the T6050 refusal-order blocker is fixed, please post a fresh J713 hardware row on the new head SHA (and the docked PCIe-tunnel regression check still listed under
## Still to run).
- Host tests CI (
- PR body / commit hygiene:
- The PR body's
## Changesection still states"the rescan after the wake, or after a later refusal, finds it again", which conflicts with## Still to run, #2726, and the updated comments inc46c72bf. - Squash-merging will also drop the
e1ce37e0/08dace13commit+revert pair cleanly.
- The PR body's
Checklist verification
- Model/board/firmware gating: Pass — no new
of_machine_is_compatible()or board/firmware gates added;anhi->cio_t6050fail-closed rationale is documented in code and commit messages. - Default cmdline / no hacks / safety / clean-room: Pass.
- Attribution: Pass — all 5 commits have human author/committer and
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>only (noCo-Authored-Byor agent trailers); PR body ends withAssisted-by: LLM (Claude:Opus 5.5). - CI: Green (
Host tests/host-tests: SUCCESS).
Assisted-by: LLM (Google:Gemini 4 Neon)
…d them again after a refusal Review found that a prepare refusal could leave a host-to-host peer torn down when the machine never slept. The CM releases XDomain peers (services unbound, paths down) in tb_cio_sleep_prepare(). Two prepare paths then refused afterwards: - T6050 without a PCIe tunnel refused only after that release. A J714s with a host-to-host cable lost its thunderbolt_net link on every refused deep sleep. - Any later refusal (rings still held, PHY, DART, the PCIe port's prepare) left the released peers gone. The PM core calls no complete for a device whose prepare failed, so tb_complete()'s rescan never ran. Fixes: - Find the PCIe tunnel and take the T6050 refusal before the CM closes, so nothing is released. pcie_pm_prepared already holds the tunnel until complete. The reference is now kept from the lookup and put on every error path. - Add tb_cio_sleep_refused(). It completes the transaction, clears the pending resume cleanup, unregisters the released peers outside the lock, and rescans the root router; their links are still up, so the rescan finds them again. It does not rescan while the CM is stopping or before hotplug is active. The NHI's refusal paths after the CM prepare use it. - The release now looks only at lane adapters, and its comment says why it looks the peer up by route. Host tests: - cio-native: T6050 without a tunnel refuses with nothing prepared and no CM call. Every refusal after the CM's prepare goes through the refused path, none before it. Two new negative controls. - tb-cio-sleep: the refused path after a prepare, after the CM's own refusal, and before any release (an ordinary rescan); and no rescan while stopping. Three new negative controls. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
Thanks. The blocker and both notes are addressed at afd6d5b, one commit on top with no force push.
Host tests pass locally:
Next is a fresh J713 hardware row on afd6d5b. It goes through the t5 candidate, and I'm asking for #2692 to be updated to this head there. The docked PCIe-tunnel check is still owed. |
|
J713 (M4 Air) hardware rows at head Kernel: 7.3.0-bj713t5+ = the tip-built J713 default (t4) + this PR at afd6d5b (+ linux#2590, linux#2721 heads). ONE fleet command line, no parameters. Deep sleep = Real deep sleep: PASS (3/3). Every cycle logged Refusal ordering: host tests at afd6d5b pass here: cio-native 33 cases with 17 negative controls, tb-cio-sleep 41 with 27. The T6050 no-tunnel refusal now runs before Finding (should-fix or document): the refused-path recovery does not hold on hardware. A deep sleep refused by a later device (linux#2710 arm: dcpexts without
Both ends then sit in lane-init timeouts until the J713 reboots. So the commit message's line "their links are still up, so the rescan finds them again" is only half true: the peer is found again, then lost. Before this PR, an aborted deep left the peer untouched, because the NHI refused first. Possible levers: release the peers as late as the CM allows (the NHI's suspend instead of prepare, which narrows the window to refusals after it), or find why re-discovery after a never-slept release drops the lane (the J713's adapter reconfigure versus the peer's state). Failing that, document it in #2726. Evidence (our lab, untainted)
Unrelated to this PR but seen on the same boot: the G16 GPU firmware crashes on the first deep wake ( Assisted-by: LLM (Claude:Opus 5.5) |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Adversarial re-review at head afd6d5b766f5b7b20f74826491b8d4e74633441a (interdiff from c46c72bf plus full PR diff).
Blocker from previous review — RESOLVED
- T6050 refusal-order bug (
drivers/thunderbolt/apple-cio-sleep.c:510-519): Fixed and tested.apple_nhi_cio_prepare()now looks uppcie = apple_cio_find_pcie_tunnel(acio)and enforcesif (!pcie && anhi->cio_t6050) { ret = -ENODEV; goto release_cable; }before callingtb_cio_sleep_prepare(anhi->tb).apple_nhi_prepare()setsacio->pcie_pm_prepared = truebeforehand, freezingpcie_tunnel_work/quiesce across prepare, andpcierefcounting is balanced across every error path (release_cm:putspcieonce) and normal completion (apple_nhi_cio_complete()). Covered by the new T6050 no-tunnel test case and negative controls (t6050-refuses-after-release,refused-without-rescan) intools/asahi/cio-native-tests.{c,py}. - Prior non-blocking notes: Addressed (
!tb_port_is_null(port)skip added intb_cio_release_xdomains(), route-lookup comment updated, and PR body no longer claims post-wake peer re-discovery).
Assessment of hardware finding in #issuecomment-7068987112
- Refused-sleep link drop on J713 (when a later device such as
dcp_platform_suspendfails suspend after NHI prepare releases the XDomain peer,tb_complete()re-discovers the peer and both ends lose the link ~100 ms later until replug/reboot):- Bounded, non-blocking edge case: On T6050 (which refuses without a PCIe tunnel),
afd6d5b7now refuses before any XDomain release, so T6050 has zero regression. On J713, XDomain unregistration (tb_domain_unregister_unplugged_xdomains()) must happen in.prepare()before checking NHI rings (it cannot safely move intosuspend_noirq()because unbindingthunderbolt_netcallsdevice_unregister()). The post-reprobeDead End/ lane-init phase 3 stall is the same CIO host-to-host port-recovery class as #2726, and only triggers on an aborted sleep rather than normal deep sleep (which passes 3/3 onafd6d5b7and 10/10 previously). - Follow-up: Please record this refused-sleep case in #2726 and soften the
"finds it again"wording in the PR body (and comments when #2726 lands) so it reflects what hardware showed.
- Bounded, non-blocking edge case: On T6050 (which refuses without a PCIe tunnel),
Non-blocking notes
- Docked PCIe-tunnel regression row: Still listed under
## Still to runand not yet reported onafd6d5b7. Code inspection of the movedapple_cio_find_pcie_tunnel()lookup andpcie_pm_preparedlocking is clean and host tests cover both docked and no-tunnel paths, so not blocking approval, but please run the docked PCIe-tunnel check before/with promotion. - Pre-release
tb_cio_sleep_prepare()failure path: Iftb_cio_sleep_prepare()fails beforetb_cio_release_xdomains(),apple_nhi_cio_prepare()still jumps torelease_cm:->tb_cio_sleep_refused()->tb_scan_switch(tb->root_switch), which runstb_scan_port()(includingtb_switch_alloc()/tb_retimer_scan()) even when no peer was released becausetb_scan_port()only short-circuits onport->remote. Minor and bounded to an already-failed prepare. - Merge hygiene: Recommend squash-merging to drop the
e1ce37e0/08dace13commit+revert pair from history.
Checklist verification
- No model/board/firmware gating: Pass — fail-closed
anhi->cio_t6050rationale is documented in code and commit messages; no board/firmware-version gates. - Default cmdline / no hacks / safety / clean-room: Pass.
- Attribution: Pass — all 6 commits have human author/committer and
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>only (noCo-Authored-Byor agent trailers); PR body ends withAssisted-by: LLM (Claude:Opus 5.5). - CI & Hardware Evidence:
Host tests / host-testsis green atafd6d5b7(run44944726833); fresh J713 hardware row atafd6d5b7passes 3/3 real deep sleeps on the default cmdline with 0 failed units, 0 AVC denials, and 0 oops/DART faults.
Assisted-by: LLM (Google:Gemini 4 Neon)
|
J713-S2R follow-up on the refused-later finding above, row Q (2026-11-22 08:13). This tested one lever, and it did not fix it. Hypothesis. The release ran Test. Candidate 075f1eb keeps PID set on release (host tests 41 + 28 with a new control; not pushed). Lab kernel: this PR at afd6d5b + 075f1eb. The deep sleep is refused by a later device: a 27.2 dcpext without power words refuses at its suspend, as in your R arm. Result: unchanged. Over two refused deep sleeps:
This is the same J713-to-J616s retrain failure as after a real deep sleep (#2726). So the drop is lane-level, in the firmware, and is not caused by the port's PID state. Where that leaves this PR:
I'm documenting this in #2726 and leaving 075f1eb out. The levers still open:
Evidence: traces/power/20261121-j713-s2r/rowQ-x3/ (J713 journal, plus the J616s journal for 08:12:30-08:16:30). |
|
Claude Opus 5.5 on @satchlj's behalf J775c (Mac Studio, M5 Max, T6050) row on
The failure without #2664 is the same one, with the same address, that we saw on |
Problem
The M4 MacBook Air's (J713) native CIO deep sleep was written for a dock with a PCIe tunnel. With anything else on a USB4 port, it refused every deep sleep at prepare:
tb_cio_check_topology()-EOPNOTSUPP;apple_nhi_cio_prepare()-ENODEV.Change
Testing
Review fixes
Still to run
Assisted-by: LLM (Claude:Opus 5.5)