Repository navigation
soc: apple: sleep: refuse a T8132 deep sleep without a PCIe port recovery - #4181
Conversation
apple_dart_set_host_resumes() leaves a DART's restore after a deep sleep to the PCIe host that clocks it. A host that claimed one port's DART and then can't claim the next one's has to give the first one back, or nothing restores it: the DART's own resume skips it for good. Add the opposite call. Nothing uses it yet. Signed-off-by: DjDeveloperr <hey@djdev.me>
The managed radio's recovery has the T8132 port's reset values inside its own function. A host that sets its ports up itself after a deep sleep writes the same ones: move them out, in the same order and with the same values. No functional change. Signed-off-by: DjDeveloperr <hey@djdev.me>
A T8132 host without the managed radio contract, as the J773g's with its Wi-Fi/Bluetooth and Ethernet ports, has nothing that brings its ports back after a deep sleep. apple-sleep can stop them and knows about a host that owns them, but no host says so. The port DARTs, clocked by their ports, are then read by their own noirq resume without a clock: the J773g takes an SError in the resume of iommu@490000000, 15 ms into the wake, and resets. Take the ports over: save what only their registers hold in the noirq suspend, and in the noirq resume write the reset values, the loader's tunables and link limits, the clocks, the RID-to-SID and MSI routes, then the port's DART and the root port's config space, and train the link, each before anything that depends on it. The link's width and speed limits are the ones the loader left. apple-sleep learns about every port that is back, so that the next sleep stops only those. The host takes the ports over only once every port has what its recovery needs, and gives back what it claimed otherwise. A port that doesn't come back is lost until a restart: its endpoint goes back into reset, its functions are marked disconnected, its config space and interrupt stay closed, and the next sleeps neither save over the last good copy nor touch it. The other ports are not affected. Hosts with apple,managed-sids (J713, J715, J604) return from the new probe first and keep their own recovery. Signed-off-by: DjDeveloperr <hey@djdev.me>
…very A T8132 wake leaves the APCIe ports to their host. A board without the managed radio contract, the J773g, has a host that says whether it sets them up again, but nothing asks: when its probe failed, its device tree leaves out what the recovery needs, or no driver is bound, a deep sleep still goes through. The wake then reads the port DARTs without a clock and the machine resets with its unsaved work. Refuse it in .begin, before any device suspends. Suspend-to-idle takes another path and is not affected. Deep sleep shouldn't be the default there either. The host probes after apple-sleep on the J773g (2.95 s and 0.05 s), so start with s2idle as the default and make it deep sleep when the host registers. A default that was chosen with mem_sleep_default=, or that another missing part took away, stays as it is. With the recovery registered, and on every host with apple,managed-sids (J713, J715, J604, J623, J624), deep sleep and its default are as before. The other SoCs don't set the new field. Signed-off-by: DjDeveloperr <hey@djdev.me>
RyanTheTide
left a comment
There was a problem hiding this comment.
Confirmed the modular-host case called out in the description. If apple-sleep starts first, an administrator can explicitly write s2idle to /sys/power/mem_sleep before the PCIe module loads. When the host registers, apcie_default_held remains set and sleep_apcie_ports_default() overwrites that selection with deep. The next ordinary mem suspend then takes the deeper path despite the explicit selection. The exact host fixture passed unchanged. Adding that one sysfs-equivalent store before the late probe failed the assertion that s2idle stays selected.
When the PCIe host registered after apple-sleep, the driver made deep sleep the default again, also over an s2idle that was written to /sys/power/mem_sleep in the meantime. Drop the change of the default and keep the refusal, which is what protects the machine. systemd-sleep tries "freeze" when "mem" fails, so a Mac without the recovery still suspends to idle there. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Right, and the change of the default wasn't needed. |
RyanTheTide
left a comment
There was a problem hiding this comment.
The late-PCIe-probe case is fixed. Registration now updates only recovery ownership, so the selected sleep mode survives probe and removal. The early deep-sleep refusal remains in place. I ran the exact-head host fixture and it passed, including both explicit selections. The J773g hardware row remains pending.
|
Hardware verification receipt at exact head
|
The base branch was changed.
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
The merge of Hosted KUnit, apple-build and host-tests never ran on this head (it was a draft on a branch base), and this merge doesn't wait for their queue (hosted CI override, Dj). Runtime evidence is the J773g row at this head. Its kernel also carried #4164, #4007, #3485, #3486 and #4175. From that row, and the body now says so: with The PR was retargeted to |
What: If #4176's port recovery doesn't register on a T8132 Mac (the PCIe host's probe failed, its device tree leaves something out, or no driver is bound), a deep sleep still goes through, and the wake would probably reset the Mac with its unsaved work. This refuses that sleep before any device suspends. systemd-sleep's default list (
mem standby freeze) should then go on to suspend-to-idle; where sleep.conf names onlySuspendState=mem, it doesn't (seen on the J773g), and the Mac stays up. Stacked on #4176; meant to land before #4007, which makes deep sleep the default on the J773g.Tested: J773g (M4 Mac mini, 27.2) at
2977a1a31237: with the recovery taken out, twomemwrites returned-EBUSYand s2idle worked; with it, one deep sleep in the same boot, Ethernet, display and GPU back (receipt). Host tests andsleep.oW=1 at this head.Risk: two-way · J773g. No change there once the recovery is registered. Without it, a plain
memwrite gets-EBUSYwhilemem_sleepstays atdeep.Not yet: a Mac whose systemd uses the default sleep list, to see it fall back to suspend-to-idle.
Details
Where the check sits.
apple_sleep_begin()indrivers/soc/apple/sleep.c, after the profile check that can already refuse there. It's before the SoC's own.begin, the pins' save, the watchdog andpm_set_suspend_via_firmware(), so the failed sleep has nothing to undo:.endfinds no firmware sleep and returns. The write to/sys/power/stategets-EBUSY. User space is frozen at that point andpcie-applehas no sysfs unbind, so the host can't go away between the check and the commit.What it asks. The question the T8132 wake already asks (
apcie_ports_unowned && !apcie_ports_host_owned), and that the host answers withapple_sleep_apcie_ports_owned()since #4176. The new field in the SoC's data,apcie_ports_host, says that this SoC's wake leaves the ports to their host; onlyt8132_sleep_socsets it, because other SoCs bring their ports back in other ways and no host of theirs makes that call.The default. Not touched: the first version lowered it and gave it back when the host registered, which could replace an s2idle that a user had written meanwhile (Ryan's review). What's in
/sys/power/mem_sleepstays the user's.What doesn't change
apple,managed-sids, soapcie_ports_unownedis false and neither check applies. Their host refuses by itself when the radio can't be recovered..beginreturns before the check.Left as it is. The wake's own clocking of ports without a host (
sleep_apcie_port_clock()) isn't reached any more on T8132. Removing it is a separate change, so that this one doesn't touch the wake.Evidence
Base: #4176 at
40959794. Head:2977a1a31237.t8132-sleep-refuse-tests.pyat this head, with the productionapple_sleep_begin()/apple_sleep_end()and the host'sapple_pcie_t8132_sleep_probe(): PASS. Host before and afterapple-sleep; host gone and back; the probe failing at each port's preparation, at each DART, at both devres steps, with no ports, and with other host data, each in both probe orders; no host driver at all; managed radio; another SoC; no sleep driver; a chosenmem_sleepkept over the host's registration and removal. A refused sleep arms no watchdog, saves no pin, runs no SoC step, sets no firmware sleep, can be repeated, and leaves s2idle working.mem_sleep_current.215ffcc8(this head only removes lines from it):run-host-tests.py --onlyt8132 6/6, radio 5/5, sleep 51/51, dart- 32/32, pcie 8/8, apple-wdt 10/10, sio-engine 1/1;sleep.oandpcie-apple.owithout warnings at W=1 (gcc 16.2.0 and clang, KUnit tests built in). Not rebuilt at this head yet; the J773g row's build does that.checkpatch.pl --strictat215ffcc8:sleep.c0/0/0; the test file 0 errors, 4 warnings, 4 checks (its stub macros, a typedef, MAINTAINERS).Disabling the recovery for the hardware row needs no code: a one-cell
apple,tunable-porton port 2 in the DTB (pci@2,0has none today, and on this host only the recovery reads it) can't be parsed, so the host logsno deep sleep recovery: -EINVALand everything else probes as usual. Read from the code, not tried.