Repository navigation
soc: apple: sleep: fix APCIe auto-PM teardown and BUSY-latch lowering - #3950
DjDeveloperr merged 1 commit into
Conversation
During repeated T8132 deep-sleep cycles with hardware PS_AUTO_ENABLE active on apcie_sys_st and apcie_phy_sw, an idle auto-gated domain reads PS_ACTUAL = 0 and causes apple_sleep_lower_apcie() to skip PHY/clkgen teardown or race against mid-MMIO auto-gating, and writing PS_TARGET = 0 without first waiting for the domain to wake after clearing PS_AUTO_ENABLE can latch PS_BUSY. Fix all three defects in drivers/soc/apple/sleep.c: - In sleep_ps_wait_on(), wait for FIELD_GET(PS_ACTUAL, val) to reach the full target state rather than merely non-zero. - Mask hardware-owned PS_BUSY in sleep_ps_lower_start() and sleep_ps_lower_finish(), and make sleep_ps_lower() wait for the domain to wake after clearing PS_AUTO_ENABLE before writing PS_TARGET = 0. - In apple_sleep_lower_apcie(), clear PS_AUTO_ENABLE and wait for full power on apcie_sys_st, apcie_sys_gp, and apcie_phy_sw before stopping ports, powering off the PHY/clkgen, and disabling AXI links, then lower each domain in order via sleep_ps_lower_finish(). Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
satchlj
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at 255b646
Blockers:
- Wait for the approved Actions CI runs (
apple-build,host-tests,pr-text,readiness) to complete green at255b646d48d4. - Post an exact-head
255b646d48d4hardware deep-sleep row (and second non-gen4 SoC control row, per merge policy §1/§3 — currently listed under Not yet).
Checked:
- Audited the full 74-line diff in
drivers/soc/apple/sleep.cat255b646d48d4: no code blockers found. sleep_ps_wait_on()pollingFIELD_GET(PS_ACTUAL, val) == target(bounded byPS_OFF_TIMEOUT_US) and masking hardware-ownedPS_BUSY(BIT(11)) insleep_ps_lower_start()/sleep_ps_lower_finish()/sleep_ps_lower()cleanly prevents latchingPS_BUSYwhen lowering an auto-gated domain.- In
apple_sleep_lower_apcie()(non-gen4 path;apcie_gen4untouched), clearingPS_AUTO_ENABLEand waiting for full power onapcie_sys_st,apcie_sys_gp, andapcie_phy_swbeforesleep_apcie_port_stop_once(),sleep_apcie_phy_off(),sleep_apcie_clk_off(), andAPCIE_AXI_EN0/1teardown prevents silent teardown skips and mid-MMIO auto-gating races, then lowers each domain in order viasleep_ps_lower_finish(). - Non-blocking note:
sleep_apcie_port_stop_once()also checkssleep_ps_on(s, s->soc->ps.apcie_gp); ifapcie_gpitself ever usesPS_AUTO_ENABLEon any non-gen4 SoC, it would still be checked via rawPS_ACTUAL != 0.
|
Row:
Note: J413 is a T8112 regression control only; this does not exercise the T6040/T6041 |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Core review at 255b646d48d4: approve. Merge waits on the exact-head T8132 deep-sleep row from your "Not yet" list.
Checked:
- The new
sleep_ps_wait_on()waits forPS_ACTUAL == target, and every wait is bounded byPS_OFF_TIMEOUT_US. A domain that never settles costs at most 5 ms and then takes the old skip path. PS_BUSYis masked in all three write sites, and moving the define up is a plain move.apple_sleep_lower_apcie(): wakingapcie_sys_st,apcie_sys_gpandapcie_phy_swbefore teardown fixes the skipped PHY and clkgen teardown whenapcie_sys_streadsPS_ACTUAL = 0under auto-PM. Thephy_ongate onsleep_apcie_port_stop_once()is safe, because that helper already returns early whenapcie_phy_sworapcie_gpis off.
Notes, not blockers:
- The Risk line says the gen4 path is untouched.
apple_sleep_lower_apcie_gen4()and every othersleep_ps_lower()caller (USB, ATC0, PMP, the macOS-on domains) now also wait for the domain to come up afterPS_AUTO_ENABLEis cleared. That's bounded and looks right, but the blast radius is every deep-sleep SoC, not only non-gen4 APCIe. Please reword the Risk line. sleep_apcie_port_stop_once()still skips the port stop whenapcie_gpitself is auto-gated (PS_ACTUAL = 0), because onlysys_st,sys_gpandphy_sware woken here. If J604 never showsapcie_gpidled at that point, it's fine as is.
Rows:
- Second generation: satchlj's exact-head J413 (T8112) PASS covers it (comment 7353357139).
- We're adding an exact-head J700 (T8140) deep-sleep control from our fleet, because this path runs on every non-gen4 deep-sleep SoC.
- Still needed: your exact-head T8132 multi-cycle deep-sleep row. Once it posts, the frontier merges.
J700 row at exact head
|
| Check | Result |
|---|---|
Two deep sleeps (rtcwake -d rtc0 -m mem -s 30 ×2) |
PASS. suspend_stats success 0 → 1 → 2 with fail unchanged, PM suspend entry (deep) and exit each time, boot object resumes counting up, same boot ID. |
| After each wake | PASS. The three PCIe functions (root port, mt7932 Wi-Fi, mt7932 BT) were present on the same drivers at the same width. Wi-Fi reached its gateway and hci0 came back. The link retrained 5.0 → 2.5 GT/s, the same as the stock -41 deep sleep on this J700. |
| Faults | PASS. 0 SError, unhandled faults, DART faults, pcie-apple or apple-dart errors, co-processor crashes, WARN, BUG or Oops, and 0 failed units after the wakes. |
APCIe lowering, from sleep.c's existing failure lines (the PR adds none) |
PASS. Per cycle, 23 power words were written back and 0 were "not on in time". There was no BUSY-latch-at-commit, deep-path, ANS-not-off, PHY-clock or radio-port-stop line, and no refusal. |
| PMP events (kit gate e) | FAIL by the kit's definition, see below. |
About gate (e). The kit treats any PMP line after a wake as new if it isn't in stock -41's deep-sleep set. Each wake here logged one such line: apple_pmp 300500000.pmp: RTKit: sleep return: ASC control 0x0, setting RUN. It comes right before the usual RTKit: Initializing (protocol version 12). This line is not from this PR:
- A main-based J700 kernel without this PR (the M3 lead's shared-control trial kernel, run three times today) logs the identical line on every wake, for
apple_pmpand also forapple-sioandapple-dcp. - It comes from main's RTKit resume path. Stock -41 only re-initialises.
- There were no PMP error lines.
So the gate fails on a baseline the kit took from the older stock kernel, not on a PMP event caused by #3950.
Stock restored: the return boot ran the configured Stage 2 and stock 7.3.0-41. boot-ctxr.bin is byte-identical to before, no marker is left, the stock and snapshot diffs are empty, and the PMU boot-error count is 00.
|
The exact-head T8132 deep-sleep row ( |
|
Thanks @DjDeveloperr and @satchlj for the review and for running the exact-head J700 (T8140) and J413 (T8112) controls. I also updated the Update from J604 (
To be completely transparent about head isolation:
|
|
PASS J714s (M5 Pro, T6050) linux#3950 head 255b646 in composite2 099704f2 (7.3.0-m5-comp2, vmlinux 1e556b87): 2x rtcwake -d /dev/rtc1 -m mem -s 20 clean deep sleep resumes (20.46s/21.12s, boot_id unchanged, suspend_success 0->2, suspend_fail 0, 14 coprocessors stopped, AUSS 0x3ff->0x300, 0 prepare/APCIe/PCIe/DART/GPU/Oops/WARN/BUG faults), PCIe+NVMe+Wi-Fi+BT+headless Vulkan/GL smoke all pass post-resume, WDT armed, clean stock handback (a70fc871). |
|
Merging at Same diff as the J604 soak kernel. Could the extra guards hide a fault of this diff?
Why a standalone J604 run wouldn't add to this. At this head J604 doesn't enable the What the rows cover. The rewritten non-gen4 body runs only on T8140 and T8132. J700 (T8140) ran it at this exact head, 2/2, without these guards. J413 and J714s cover the shared Merge with main ( |
What: Fix three interacting APCIe auto-PM teardown and
PS_BUSY-latch defects indrivers/soc/apple/sleep.cseen during repeated T8132 deep-sleep cycles with hardwarePS_AUTO_ENABLEactive onapcie_sys_standapcie_phy_sw:sleep_ps_wait_on(), wait forFIELD_GET(PS_ACTUAL, val) == targetrather than merely non-zero.PS_BUSY(BIT(11)) insleep_ps_lower_start()andsleep_ps_lower_finish(), and makesleep_ps_lower()wait viasleep_ps_wait_on()after clearingPS_AUTO_ENABLEbefore writingPS_TARGET = 0so lowering an auto-gated domain does not latchPS_BUSY.apple_sleep_lower_apcie()(non-gen4 path;apcie_gen4early return preserved unchanged), clearPS_AUTO_ENABLEand wait for full power onapcie_sys_st,apcie_sys_gp, andapcie_phy_swbefore stopping ports, powering off the PHY/clkgen, and disabling AXI links, then lower each domain in order viasleep_ps_lower_finish(). This prevents skipped PHY/clkgen teardown whenapcie_sys_stis auto-gated (PS_ACTUAL = 0), mid-MMIO auto-gating races, andPS_BUSYlatches.Tested:
aurora-silicon/linuxmain(bf2931e57045, branchj604-sleep-apcie-autopm-teardown, commit255b646d48d4):scripts/checkpatch.pl --strict:0errors,0warnings,0checks (132lines checked).LLVM=1 W=1:drivers/soc/apple/sleep.o0warnings (2488664bytes).apple-sleep-soc-data16/16passed (0failed).linux-aurora 7.3.0.aurora1-1.1685, commit89d82de1c143):0compiler warnings indrivers/soc/apple/sleep.c, ARM64 QEMU KUnitapple-sleep-soc-data6/6passed (202/202total).sleep.cdiff (89d82de1c143):1.1685(bootb650c46a):1/1deep-sleep suspend/resume wake passed (rc=0,0SErrors,0kernel faults),0PMP events (600 s idle),33.5 Cidle thermal gate,1582.7 fpsProRes decode gate.1.1686(1e959da5e66c, bootb14ae371):10/10deep-sleep (10x 600 s rtcwake -m mem) +10/10s2idle(10x 300 s) soak passed (150.0 mWdeep /799.5 mWs2idlemedian asleep,1.65 sawake,1.35 sWi-Fi recover,10/10AOP IIO sensors + MTP keyboard intact,0SErrors,0L2C/kernel/GPU faults,0resets).Risk: two-way door · all Apple Silicon SoCs with deep sleep enabled (
drivers/soc/apple/sleep.c,+51 / -23lines;apple_sleep_lower_apcie()teardown ordering applies to non-gen4 APCIe whilesleep_ps_lower(),sleep_ps_wait_on(), andPS_BUSYmasking apply to everysleep_ps_lower()caller including gen4 APCIe, USB, ATC0, and PMP) — everysleep_ps_wait_on()wait is bounded byPS_OFF_TIMEOUT_US(5000 us), domains withoutPS_AUTO_ENABLEtake the exact same immediate lowering path withPS_BUSYmasked, and a plain revert restores prior lowering behavior.Not yet:
255b646d48d4(mainbf2931e57045) multi-cycle deep-sleep row on J604 (T8132); second non-gen4 controls are covered by the J413 (T8112) and J700 (T8140) exact-head rows in comments below.Details and verification
Scope (
j604-sleep-apcie-autopm-teardown, head255b646d48d4onmainbf2931e57045)drivers/soc/apple/sleep.c(+51 / -23)Signed-off-by: Dylan Ironside <dylan@dylanironside.io>scripts/checkpatch.pl --strict:0 errors, 0 warnings, 0 checks(132lines checked).LLVM=1 W=1:drivers/soc/apple/sleep.o0warnings (2488664bytes).apple-sleep-soc-data16/16passed (0failed).Mechanism summary
PS_AUTO_ENABLE), idle APCIe domains (apcie_sys_st,apcie_phy_sw,apcie_sys_gp) can reportPS_ACTUAL = 0whilePS_TARGET = 0xf.apple_sleep_lower_apcie()checkedsleep_ps_on()(which checksPS_ACTUAL != 0) before callingsleep_apcie_phy_off()/sleep_apcie_clk_off(), silently skipping PHY/clkgen teardown whenapcie_sys_storapcie_phy_swhappened to be auto-gated, andsleep_ps_lower()wrotePS_TARGET = 0immediately after clearingPS_AUTO_ENABLEwithout waiting forPS_ACTUAL == targetor masking hardware-ownedPS_BUSY.PS_AUTO_ENABLEand waiting for fullPS_ACTUAL == targetonapcie_sys_st,apcie_sys_gp, andapcie_phy_swbefore port stop / PHY / clkgen / AXI teardown, then finishing each lower in order withPS_BUSYmasked, eliminates the skipped teardown andPS_BUSYlatch.