Repository navigation
usb: typec: tipd: close the USB4 session before a reboot or power off - #2101
DjDeveloperr merged 3 commits into
Conversation
On a 14-inch M5 Max with a Studio Display on the Thunderbolt port, a
reboot could hang for minutes. systemd's last step, device_shutdown(),
blocked in the Thunderbolt NHI teardown. A cable event closed the ACIO
session from the CD321x update work after the PCIe-C controller had
begun to shut down, so the PCIe-C reset handshake of the tunnel timed
out ("failed to quiesce PCIe-C before NHI shutdown: -110") and
device_shutdown() waited behind it.
Close the session earlier, while the system still runs and the lanes
carry the handshake. A reboot notifier runs before system_state changes
and before device_shutdown(). For SYS_RESTART, SYS_HALT and
SYS_POWER_OFF it disables the port's interrupt, stops its work, and
sends TYPEC_THUNDERBOLT_SWITCH_OFF to the router. After that no cable
event can reach the router, so the late close never starts.
The notifier logs once before and once after the close, so a reboot log
shows whether the session was closed in order.
Add two KUnit tests: a reboot sends OFF and stops the port's update
work, and any other notifier action leaves the port alone.
Tested: KUnit (cd321x suites on arm64 under qemu): 122 of 122 pass, and
with the OFF call removed the new reboot test fails. On a 14-inch M5 Max
with a Studio Display docked, three plain reboots with this change
returned in 33, 32 and 37 seconds. Each log shows "closing the
USB4/Thunderbolt session before shutdown", the PCIe-C quiesce, "closed
the USB4/Thunderbolt session before shutdown: 0", then "Preparing for
reboot", and the display and Thunderbolt device were back after each
boot. Not tested: kexec.
Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins. |
|
[Joshua's agent] Docked sleep and wake on the same kernel as the three reboots (this change plus an unrelated display brightness commit), 14-inch M5 Max with the Studio Display docked: one s2idle cycle with an RTC alarm passed.
|
cd321x_register_port() now sets reboot_nb up and registers it, so the extracted probe no longer compiled in the typec-probe and probe-mux-pm-dispatch units. Give the fixture's struct cd321x the two new members, give notifier_block a priority, and mock register and unregister. Check that probe registers the notifier with cd321x_reboot_notify and that every case unregisters it.
|
GREEN on 367a01b [Joshua's agent] Reviewed: reboot notifier (priority INT_MAX) on reboot_notifier_list — verified in kernel/reboot.c that this list runs via blocking_notifier_call_chain BEFORE device_shutdown(), so disable_irq and typec_thunderbolt_switch_set sleeping is legal and the session closes while the ACIO is still up — exactly the stated intent. Unregister ordering in cd321x_unregister_port is correct; ret is logged not propagated (right for shutdown). Other actions return NOTIFY_DONE; KUnit pins both paths plus the pm.py selftest mock updates. Note the request described 'before unplug' — the diff is reboot/halt/power-off only; no hot-unplug path is touched, so the block-on-error-path concern does not apply here. |
|
GREEN on 367a01b [Joshua's agent] Reviewed the full diff at that head plus the surrounding core.c/mux.c paths it calls. What I verified in source:
Nits, non-blocking: no KUnit case for reboot with |
|
Thanks. This is a clean fix. It closes the session in Nothing is missing from your side. Because the notifier now runs on every Apple Type-C port, we'll run no-regression rows before it goes on: Optional: one KUnit case for a reboot with |
|
Note 🤖 OpenAI Codex responding on behalf of joshuaswarren
All three reboot runs with a Studio Display passed on the 14-inch M5 Max MacBook Pro. The logs put the USB4 close before reboot prep. The test kernel also had a patch for screen brightness. Those runs don't cover the other Macs or power-off.
|
|
Thanks for the three M5 Max reboot runs with the USB4 close logged before reboot prep. That covers the T6050 side, and you don't owe a power-off row there. The other Macs and power-off are on us: |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Thanks. This is a clean fix, and I agree with Ryan and the two GREENs. The notifier runs from kernel_restart_prepare() (which kernel_kexec() also goes through) before device_shutdown(), so the close can sleep and happens while ACIO is still up. typec_thunderbolt_switch_set() returns 0 for a port without a router, so ports without one stay quiet.
Two things I checked against the tip:
cd321x_stop_work()is safe to run twice, first from the notifier and then from a later unbind: each unregister sits behind its*_registeredflag, and the cancels are idempotent.- integration/aurora has changed
core.candtps6598x.hsince your base: 78ad8ef (#1889, SN201202x idle sleep) and d5d1f33 (the J714s replug). A local three-way merge of both files is clean.cd321x_stop_work()doesn't cancel the new J714sreplug_work, but with the port's IRQ off, a replug that runs after the notifier can't reach the router, so nothing is needed here.
host-tests is green on 367a01b. Approving. I'll update the branch and merge once host-tests is green on the merged head.
Ryan's rows come after the merge, with a revert ready: systemctl reboot x3 and poweroff x1 on the M1 Pro and M4 Pro with a Thunderbolt dock, and on the M2 and A18 Pro with a USB-C hub. The NULL-switch KUnit case stays optional.
e45e3fd
into
aurora-silicon:integration/aurora
|
Thanks for the merge. |
[Joshua's agent] Fixes a plain
systemctl rebootthat hangs on a 14-inch M5 Max MacBook Pro with a Studio Display on the Thunderbolt port. One fix, one file group (drivers/usb/typec/tipd/).Cause
On the hanging boots the last thing the journal shows is a clean
Finished System Reboot, and the machine stays off until a reset. In a photo of the stuck panel from an earlier boot, the WARN trace rantypec_thunderbolt_switch_setfromcd321x_update_work. The late OFF reachesapple_cio_tbt_switch_set, thenapple_cio_stop, which destroys the NHI and waits for the Thunderbolt domain to be released while holdingacio->lock. By then the PCIe-C controller has started to shut down, so the quiesce handshake times out (failed to quiesce PCIe-C before NHI shutdown: -110) anddevice_shutdown()waits behind it.Change
A reboot notifier on every CD321x/SN201202x port. It runs in
kernel_restart_prepare(), beforesystem_statechanges and beforedevice_shutdown(), forSYS_RESTART,SYS_HALTandSYS_POWER_OFF. It disables the port's interrupt, stops its update work, and sendsTYPEC_THUNDERBOLT_SWITCH_OFFto the router. The session closes while the lanes still carry the handshake, and no cable event can reach the router afterwards. It logs once before and once after the close. It does not change the USB role or the mux. A runtime unplug and suspend are unchanged.Tests
cd321x_tbt_reboot_closes_session_test,cd321x_tbt_reboot_other_action_test). With the OFF call removed: 121 of 122 pass and the closes-session test fails. With it: 122 of 122 pass.systemctl rebootcycles on a kernel with this change plus one unrelated display brightness commit, on top of the tree that hung before. The host came back in 33, 32 and 37 seconds. Netconsole, same order in all three (cycle 1 shown):After each boot:
/dev/drihadcard1,card2,renderD128;hyprctl monitorslisted eDP and DP-1 at 5120x2880;thunderbolt 0-1enumerated the Studio Display.Baseline, and what is not proven
Preparing for reboot. Netconsole stops answering insidedevice_shutdown(), so a missing line there would not have shown the cause before this change.t6050-die0.dtsi). It is not tested and not excluded. These cycles show that closing the session first clears the docked hang; they do not show it is the only cause of a failed restart.