Skip to content

PCI/ASPM: add sleep L1SS suppression and deferred D0 PM recheck - #3495

Merged
DjDeveloperr merged 3 commits into
mainfrom
feat/pci-aspm-l1ss-sleep-core
Dec 1, 2026
Merged

DjDeveloperr merged 3 commits into
mainfrom
feat/pci-aspm-l1ss-sleep-core

Conversation

@erikwb

@erikwb erikwb commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

What: Add shared PCI/ASPM core sleep L1SS suppression (pcie_aspm_l1ss_sleep_begin_locked(), pcie_aspm_l1ss_sleep_end(), pcie_aspm_l1ss_hw_exec()), IRQ-safe aspm_l1ss_hw_lock serialization across PCI config save/restore/low-power/reset paths, deferred D0 PCI-PM L1.1/L1.2 recheck (aspm_pm_work on system_freezable_wq), and a pci_host_bridge->pm_state_change() hook; integrate drivers/pci/controller/pcie-apple.c with these core interfaces. Part 2 of the split requested on #3221, forward-merged onto main (62675fa56aba, which includes merged part 1 #3494 d95848ae72b4).

Tested: Offline checks pass at merged head a53f57492079 (all 8 PR-modified files byte-identical to a90a2bfab82d..b886f11afb33 against 62675fa56aba, W=1 CONFIG_PCIEASPM=y/n builds 0 warnings/errors, checkpatch.pl --strict clean, all 7 host suites pass, and apple-spmi-nvmem + trusted-keys KUnit suites pass via local QEMU runs); hardware checks at a53f57492079 passed on J313 (T8103 standalone CONFIG_PROVE_LOCKING=y matched pair vs main 62675fa56aba: debug_locks: 1, 0 lockdep/RCU/sleep-in-atomic reports, aspm_l1ss_hw_lock and hib_l1ss_lock exercised across boot, docked deep S2R attempt, and 2x s2idle, Wi-Fi ASPM L1/ClockPM+/L1.1/L1.2 + ISP capture + smoke clean), J716c (T6050, pm_test=devices/platform, Clock PM off unchanged), J713 (T8132, undocked BCM4388 ASPM L1/L1SS + 2x s2idle; one new non-repeating boot-time brcmfmac ring error of unknown cause), and J313 (T8103, Group A PCI/Wi-Fi ASPM L1/ClockPM+/L1SS + 2x deep resume; same Group A boot had an unisolated post-first-resume ISP -19/DART fault where baseline main passed before becoming unreachable on its 2nd cycle, and unmodified main later reproduced that ISP fault on #3506). See Evidence for digests, exact counts, and prior b886f11afb33 rows.

Risk: two-way door · touches shared PCI core PM/ASPM paths (drivers/pci/{pci,pci-driver,probe,pci.h,pcie/aspm}.c, include/linux/pci.h) affecting all Macs, plus drivers/pci/controller/pcie-apple.c.

Revert: git revert -m 1 <merge_commit> on main (reverts the eventual GitHub merge commit cleanly). Kernel driver and host-test changes only; no persistent ESP, Stage 2, DT, or on-disk state is modified.

Not yet: TB5 dock/I225 runtime-PM churn re-run at merged head a53f57492079 on J713 (no TB device attached to J713; verified at byte-identical b886f11afb33); undocked J313 deep-wake isolation of the post-first-S2R ISP -19/DART fault (J313 is currently docked, where apple-dcp refuses deep S2R -16 before sleep on both main 62675fa56aba and a53f57492079; unmodified main already reproduces the fault on #3506; clean isolation requires physically unplugging the J313 dock); real unattended s2idle/deep suspend on J716c (T6050, limited to pm_test=devices/platform because apple-pmu-rtc cannot wake J716c unattended); and untested external Mac families (M2 / M3 / M4 Pro / M5 Pro / Neo, no hardware in local lab).

Details

Forward merge onto main (a53f57492079)

  • Part 1 (#3494, feat/t8103-pcie-l1ss-sleep) landed in main at d95848ae72b4.
  • Forward-merged origin/main (62675fa56aba) into feat/pci-aspm-l1ss-sleep-core (b886f11afb33 -> a53f57492079) with zero conflicts. cmp -s <(git diff a90a2bfab82d..b886f11afb33) <(git diff 62675fa56aba..a53f57492079) confirms all 8 PR-modified files are byte-identical.
  • Verified git merge-tree --write-tree origin/main a53f57492079 against current main (a171afd2123f, including merged #2215) completes conflict-free (ef8f8723a9e9); apple_pcie_hib_links_no_l1_2() calls pci_disable_link_state_locked() in apple_pcie_resume() while aspm_sleep_disable holds L1SS off, and apple_pcie_complete() later runs pcie_aspm_l1ss_sleep_end(), which restores L1SS timing only and respects link->aspm_disable when re-applying ASPM.

PCI/ASPM core (0dd1485a290e)

  • Locking and bitfield safety:
    • Introduces an IRQ-safe leaf spinlock aspm_l1ss_hw_lock (compiled for both CONFIG_PCIEASPM=y and CONFIG_PCIEASPM=n) serialized under the global order pci_rescan_remove_lock -> pci_bus_sem -> aspm_lock -> host hib_l1ss_lock -> aspm_l1ss_hw_lock -> pci_lock.
    • Adds standalone u8 aspm_sleep_disable and u8 aspm_hw_l1ss on struct pcie_link_state (outside the aspm_lock-protected bitfield word) and standalone u8 aspm_pcipm_deferred and u8 aspm_l1ss_resync on struct pci_dev, eliminating unlocked bitfield RMWs in atomic config-restore paths.
  • Atomic-safe save/restore and PM/reset serialization:
    • Wraps pci_save_pcie_state(), pci_restore_pcie_state(), pci_set_low_power_state(), and pci_pm_reset()'s D3hot PMCSR write under aspm_l1ss_hw_lock.
    • Validates all four L1SS config reads before committing in pci_save_aspm_l1ss_state_locked() so D3cold 0xffffffff reads cannot overwrite valid saved timing.
    • Masks suppressed or non-D0 PCI-PM bits before writing in pci_restore_aspm_l1ss_state_locked() and compares both ends against aspm_hw_l1ss so both missing and stale-enabled substates set aspm_l1ss_resync and trigger forced reprogramming.
  • Deferred D0 recheck and error propagation:
    • Adds pci_host_bridge->pm_state_change() and notifies both core ASPM (aspm_pm_work on system_freezable_wq, gated by aspm_pcipm_deferred) and host bridges from pci_pm_default_resume_early(), pci_pm_restore_standard_config() (via pci_pm_notify_resume()), pci_set_full_power_state() / pci_set_low_power_state() refusal on D0, and pci_pm_reset() after returning to D0.
    • In pcie_config_aspm_link_locked(), never writes PCI-PM L1.1/L1.2 enable bits while either end is outside D0, propagates config-access errors through pcie_l1ss_ctl1_update(), pcie_config_aspm_dev(), pcie_config_aspm_l1ss() (child-first unwind on partial failure), and pcie_aspm_l1ss_sleep_end() (unwinding CTL1 child-first on post-L1SS LNKCTL failure, preserving aspm_l1ss_resync across retries, re-arming aspm_sleep_disable on sleep-end error, and clearing aspm_pcipm_deferred on sleep-end error while preserving it on worker error outside sleep suppression).

Apple PCIe integration (b886f11afb33)

  • Routes deep-sleep L1SS teardown, suspend recheck, and restore through pcie_aspm_l1ss_sleep_begin_locked(), pcie_aspm_l1ss_sleep_end(), and pcie_aspm_l1ss_hw_exec(), keeping .prepare()'s bounded hotplug-safe runtime-PM pin/drain loop and running snapshot+teardown atomically under aspm_l1ss_hw_lock.
  • Routes all non-removal restore errors (config errors, D3cold 0xffffffff, double-failed LNKCTL restore, and core L1SS enable errors) through apple_pcie_hib_retain_failed(), retaining recovery records on hib_l1ss_pending (with timing_pending, plus rollback_pending and intended LNKCTL values when LNKCTL restore fails) and scheduling bounded retries via hib_l1ss_work on system_freezable_wq from bridge->pm_state_change().
  • Purges both hib_l1ss and hib_l1ss_pending on BUS_NOTIFY_DEL_DEVICE and cancels hib_l1ss_work before taking pci_lock_rescan_remove() in remove/cleanup paths.
Evidence

Commits (based on main 62675fa56aba)

  • 0dd1485a290e PCI/ASPM: add sleep L1SS suppression and deferred D0 PM recheck
  • b886f11afb33 PCI: apple: serialize sleep L1SS with ASPM core and defer unmanaged PCI-PM
  • a53f57492079 Merge origin/main into feat/pci-aspm-l1ss-sleep-core

Offline build, lint, host tests, and KUnit at a53f57492079

  • cmp -s <(git diff a90a2bfab82d..b886f11afb33) <(git diff 62675fa56aba..a53f57492079) — exit 0 (all 8 PR-modified files byte-identical).
  • make O=_build_aspm_y ARCH=arm64 LLVM=1 W=1 drivers/pci/{pci,pci-driver,probe,pcie/aspm,controller/pcie-apple}.o (defconfig + asahi.config, RUST=n, CONFIG_PCIE_APPLE=m, CONFIG_PCIEASPM=y) — 0 warnings, 0 errors.
  • make O=_build_aspm_n ARCH=arm64 LLVM=1 W=1 drivers/pci/{pci,pci-driver,probe,pcie/aspm,controller/pcie-apple}.o (defconfig + asahi.config, RUST=n, CONFIG_PCIE_APPLE=m, CONFIG_PCIEASPM=n) — 0 warnings, 0 errors.
  • ./scripts/checkpatch.pl --strict --git 62675fa56aba..a53f57492079: 0 errors, 0 warnings, 0 checks (0dd1485a290e: 1065 lines; b886f11afb33: 3180 lines); git diff --check 62675fa56aba..a53f57492079: clean.
  • Host test suites at a53f57492079:
    • python3 tools/asahi/pciec-policy-tests.py: 86/86 PASS (positive + negative mutation controls, ASan+UBSan).
    • python3 tools/asahi/pcie-adopted-clkpm-tests.py: 13 production cases; 2 negative controls PASS.
    • python3 tools/asahi/radio-pm-tests.py, radio-sleep-fence-tests.py, radio-sleep-power-tests.py, radio-sleep-snapshot-tests.py: PASS.
    • python3 tools/asahi/binding-lifetime-tests.py: 3/3 PASS.
  • Local arm64 QEMU KUnit runs at a53f57492079 (./tools/testing/kunit/kunit.py run --arch=arm64 --make_options LLVM=1):
    • drivers/nvmem/apple-spmi-nvmem.kunitconfig: 2/2 passed.
    • security/keys/trusted-keys/tests/.kunitconfig: 8 passed, 1 skipped (trusted_source_after_mark_readonly when built-in).
  • GitHub Actions at a53f57492079: Host tests, MT7932 KUnit, pr-text, apple-build, KUnit ane-boot, KUnit ane-pm, KUnit dcp-fabric, and KUnit dcp-topology passed; the remaining 12 Apple build and KUnit jobs in run 46199770227 (attempt 3) were cancelled before starting steps after sitting queued ~4 h (attempt 1 failed apple-spmi-nvmem and trusted-keys in Install kernel build and QEMU dependencies).

Hardware verification at a53f57492079

  • J313 (M1 MacBook Air, T8103, docked, default cmdline, one-shot aura-try Stage 2 + GRUB trial) standalone CONFIG_PROVE_LOCKING=y matched pair (a53f57492079 vs main 62675fa56aba):
    • Control kernel (main 62675fa56aba, CONFIG_PROVE_LOCKING=y): SHA-256 bc7f227a01d57d447b9f8f544ca7f281e1c2c1ce78f257343c83c13584e54186.
    • Test kernel (a53f57492079 alone, CONFIG_PROVE_LOCKING=y): SHA-256 7ee4d934a0a5e9385eb71d39825451c293c865bcda19a910020c03991aeda272.
    • git diff control test is the 8 PR files only; both booted with identical trial Stage 2 SHA-256 ebf270451dfae099a118f68d98da0d2587ebb69d26affa48dac70a68e7844838 (default boot.bin 1262bc5d… and default kernel untouched).
    • Lockdep across boot, docked deep S2R attempt, and 2x s2idle (30 s): debug_locks: 1, 0 lockdep/RCU/sleep-in-atomic reports, 0 Oops/BUG/WARN/SError on both kernels; test kernel registered aspm_l1ss_hw_lock from boot and hib_l1ss_lock after the first sleep (4 -> 10 -> 11 class entries).
    • PCIe/ASPM & network: Wi-Fi kept ASPM L1, ClockPM+, and L1.1/L1.2 enabled before sleep, after the deep S2R attempt, and after 2x s2idle (wlan0 0% loss at each probe) on both kernels.
    • ISP & smoke: 90-frame ISP capture (v4l2-ctl -d /dev/video0 --stream-mmap=4 --stream-count=90) before and after the sleep attempt completed cleanly (off-0) on both kernels; display, input, network, audio enumeration, GPU compute + render, and AVC smoke all passed; err+ counts identical (20 total, 12 new vs boot baseline).
    • Docked deep S2R note: J313 was docked with a Thunderbolt dock (Ethernet + external display on dcpext), so deep S2R was refused before SoC sleep on both control and test (apple-dcp 271c00000.dcp: PM: failed to suspend: error -16); the post-wake ISP fault did not occur on either, and clean isolation still requires an undocked deep S2R (unmodified main already reproduces the fault on #3506).
  • J716c (16-inch M5 Max, T6050, firmware 27.2, AC, default command line) in batched trial kernel 3545ebecb76f (origin/main b897ccb4e71c + 18 open PR heads; 8/8 PR files blob-identical):
    • Hashes: kernel Image.gz SHA-256 d56efde4c7232208bd29d5c4e5890319e0050595dd4f4b1c3844df6656a08312, t6050-j716c.dtb SHA-256 d2f0db7a5026ae9cc4e1cff61dca38b4d1b363d47e5bad696ef65c7d715517e0, stripped modules SHA-256 9d5782bcf02ea60a225278c9319431f902b495f6beb485d79d127c0fb2fccc92, one-shot aura-try Stage 2 SHA-256 b7d99286395ddd7dadccc6d9593f4bd55391d9e787af97c18b45f58688d9885d (default Stage 2 21edee972e1ff1718c6f41c32b91ee151afdc58cbb69f16f2f6a4d8d4c722170 and default kernel bf2582ab357573db64031f39e7bc9d617eb574c6b221364ff417810bbddf4c87 unchanged).
    • PCIe/ASPM: Clock PM off unchanged on 00:00.0, 01:00.0, 01:00.1, 01:00.2 (ClockPM-, ASPM Disabled, L1SubCtl1 controls clear); 2x pm_test=devices (freeze) + 2x pm_test=devices (mem) + 2x pm_test=platform (freeze) (rc=0, suspend_stats fail=0), wlan0 0% packet loss after each cycle, 0 PCIe/ASPM/AER lines. Real s2idle/deep not run (apple-pmu-rtc alarm cannot wake J716c unattended); CONFIG_PROVE_LOCKING=y not enabled in this kernel.
    • Smoke & dmesg: eDP-1 3456x2234@120 enabled; 4 input devices enumerated; wlan0 3/3 gateway ping 0% loss; AppleJ716 + AppleJ716HPAI with speakerguardd v2 active (no playback outside #3085); Borealis Apple M5 Max (G17C B1) + renderD128 + vkcube --c 180 --wsi wayland clean; 0 failed user units, 0 new failed system units (aurora-peripherals.service also fails on default Stage 2 after warm reboots), 0 LSM denials (capability,landlock,yama, no SELinux/AppArmor), 0 Oops/BUG/fault lines (err+ 40 vs 55 on default boot, none beyond PM: suspend debug and DPMS syslog lines). Redacted dmesg excerpt: [ 1.250760] sn201202x 1-08: port controller ready; [ 5.907044] apple-dcp 392e00000.dcp: RTKit: syslog message: ... fControllerPowerState 0 ...; [ 135.265810] PM: suspend entry (s2idle) / [ 140.691796] PM: suspend exit (pm_test=devices).
  • J713 (M4 MacBook Air, T8132, firmware 27.2, default cmdline + panic=10, no CalDigit TS5 or external monitor attached) in batched trial kernel 76649338a1bc (over J713 daily base 8dbfa2895b93; 7/7 runtime files blob-identical, tools/asahi/pciec-policy-tests.py hunks-present):
    • Hashes: kernel image SHA-256 e8e9fd2813dd6347176d0e4a55a70d1c694bdab75817c3ab83c441c203140491, t8132-j713.dtb SHA-256 ceacf1d413c651396f4c1dfd9fa27b15c710dd849e46c2753fcff0a23a6681c6, one-shot aura-try Stage 2 SHA-256 f7d4e2f7ebbfb423bd71f233f1aef7af0a39091b288a749d25f9250eb80adbfa (default Stage 2 3b2d2f059858d1891b225910864c02d68afb1b42893667e0afa8666491651071 and default kernel 592f7bc8834d8796d5bdb086091e90ac96fc6a17a83769cbadc92b3268604c49 unchanged).
    • PCIe/ASPM: BCM4388 (0000:01:00.0) reports ASPM: default states L1, LnkCtl: ASPM L1 Enabled, L1SubCtl1: PCI-PM_L1.2+ PCI-PM_L1.1+ ASPM_L1.2+ ASPM_L1.1+, runtime active, power/control on; 5x wlan0 down/up -> operstate up, gateway ping 0% loss (rtt min/avg/max 12.951/13.534/14.118 ms); 2x s2idle (rtcwake -d rtc1 -m freeze -s 20) -> wlan0 up, ping 0% loss (14.533 / 13.453 ms), 0 new err+ lines during the two tested s2idle cycles, same ASPM boot lines as default kernel. TB5 runtime-PM churn was not exercised (no Thunderbolt device attached, no NHI PCI class device present).
    • Smoke & dmesg: eDP-1 2560x1664@60 enabled; input enumerated; wlan0 3/3 gateway ping 0% loss; AppleJ713 + AppleJ713HPAI + AppleJack with speakerguardd-v2 active and protected-sink 1 s 440 Hz tone rc 0; Borealis Apple M4 (G16G B0) + glmark2-es2-wayland 5,099; 0 failed system/user units; 0 AppArmor denials (no SELinux); err+ 4 lines = 3 baseline lines plus one new, non-repeating boot-time brcmfmac error of unknown cause ([ 9.238552] brcmfmac 0000:01:00.0: brcmf_pcie_ring_mb_update_rptr: ring 4: r_ptr 0 outside depth 0, 0 occurrences in the previous 8 boots, never repeated across 5x wlan0 down/up or 5 s2idle cycles; no PR in the batch touches brcmfmac). Redacted dmesg excerpt: [ 0.971231] apple-dcp 30ae00000.dcp: AFK[ep:20]: failed to extract init props: -2; [ 2.884802] aurora-g16 302600000.gpu: G16: firmware at READY, starting the backend; [ 9.238552] brcmfmac 0000:01:00.0: brcmf_pcie_ring_mb_update_rptr: ring 4: r_ptr 0 outside depth 0; [ 22.468225] apple-dcp 30ae00000.dcp: v27 idle cache active (mem=51117696 host=1).
  • J313 (M1 MacBook Air, T8103, default cmdline, undocked on battery) in Group A (main ee36fbdcd1c8 + #3085, #3290, #3329, #3333, #3495, #3506, #3546, #3289, #3320; all changed PR files verified byte-identical):
    • Hashes: kernel SHA-256 888c041944da96032a9252504c4d5543b906fd98717234eca5e091150af85798, one-shot aura-try Stage 2 image SHA-256 949dc089ed390b7535dd5ef2a6e99975c3026658e58dbd9d17e9b20d2bbb7d71 (default Stage 2 1262bc5de585fc57e34c36f10560522d4b231be4f9ac7e45066bc4e364f95484 and default kernel 7b4eda418e92d4403c7018894108026bb65ac9fe3958d80028fce549918306f7 unchanged).
    • Results: Wi-Fi link kept ASPM L1, ClockPM+, and L1.1/L1.2 sub-states enabled before and after 2x deep S2R (rtcwake -d rtc1 -m mem -s 30, success 0 -> 2), 16 MB RAM integrity PASS, DPMS off/on x3 PASS, 0 Oops/BUG/WARN, boot smoke pass (eDP-1 connected/enabled, input, wlan0 gateway ping, audio enumerated, Borealis compute/render Apple M1 (G13G B1)), 0 AVC denials (no SELinux), 1 baseline failed unit (speakerguardd-v2-switchtest.service, also present on baseline main ee36fbdcd1c8). Same Group A boot saw an unisolated post-first-S2R ISP capture failure (apple-isp firmware boot -19 / DART translation fault) where baseline main (ee36fbdcd1c8, kernel SHA-256 f750b04aebd30c439edbd3b995c17b3fd9ad805a4561dadc7ecbf78040c89289) captured cleanly after its first deep S2R (and later became unreachable after its second deep S2R; unmodified main later reproduced the ISP fault on #3506).
  • Prior build, host-test, and hardware verification at b886f11afb33 (before forward-merge onto main 62675fa56aba):
    • Build & host tests at b886f11afb33: ARCH=arm64 LLVM=1 W=1 on drivers/pci/{pci,pci-driver,probe,pcie/aspm,controller/pcie-apple}.o + full vmlinux + modules + modpost with CONFIG_PCIE_APPLE=m in both CONFIG_PCIEASPM=y and CONFIG_PCIEASPM=n (0 warnings, 0 errors); tools/asahi/pciec-policy-tests.py (86/86 positive + negative mutation controls, ASan+UBSan), radio-{pm,sleep-fence,sleep-power,sleep-snapshot}-tests.py, and binding-lifetime-tests.py (3/3): all PASS.
    • J313 (M1, T8103): Default cmdline, pcie_aspm policy [default]. Pre-sleep, post-s2idle (rtcwake -d rtc1 -m freeze -s 8), post-deep mux: apple-display-crossbar: replace the T602x selector fields instead of OR-ing them #1, and post-deep drm/apple: release a stale DPTX link before borrowing a Type-C route #2 (rtcwake -d rtc1 -m mem -s 8): 00:00.0 & 01:00.0 keep ASPM L1 Enabled, ClockPM+ (01:00.0), L1SubCtl1: PCI-PM_L1.2+ PCI-PM_L1.1+ ASPM_L1.2+ ASPM_L1.1+, L1SubCtl2: T_PwrOn=6us. Live kprobes: pcie_aspm_l1ss_sleep_begin_locked=4, pcie_aspm_l1ss_sleep_end=2, pcie_aspm_pm_state_change_deferred=7. Wi-Fi gateway ping 0% packet loss after every cycle (2.76-5.14 ms); 0 Oops/BUG/WARNING/SError/L1SS restore warnings.
    • J713 (M4, T8132): Default cmdline, pcie_aspm policy [powersupersave], live BCM4388 (0000:01:00.0 L1SS + ClockPM+) + Intel JHL9480 Thunderbolt 5 dock (0001:00:00.0..0001:02:03.0) + I225 Ethernet (0001:03:00.0). Runtime-PM churn across 0001:02:0{1,2,3}.0 kprobes: pci_pm_runtime_resume=9, pci_pm_runtime_suspend=9, pcie_aspm_pm_state_change_deferred=18, pcie_aspm_pm_work_fn=0. 1x s2idle (rtcwake -d rtc1 -m freeze -s 8) clean; 0 failed units; 0 Oops/BUG/WARNING/SError.
    • J716c (M5 Max, T6050): Default cmdline, pcie_aspm policy [default]. Boot log confirms pci 0000:01:00.0: Clock PM off: the host does not handle CLKREQ#; 00:00.0/01:00.0 keep ASPM Disabled and L1SubCtl1 all -. 2x pm_test=devices cycles (echo devices > /sys/power/pm_test; echo freeze > /sys/power/state, restored to [none]) pass cleanly; Wi-Fi 0% packet loss; 0 PCIe/ASPM/AER/Oops/BUG/WARNING/SError.

Add core PCI/ASPM support for host controllers that must keep L1 PM
Substates disabled across system sleep and defer PCI-PM L1.1/L1.2
re-enable until both ends of a link reach D0.

Introduce pcie_aspm_l1ss_sleep_begin_locked(), pcie_aspm_l1ss_sleep_end(),
and pcie_aspm_l1ss_hw_exec() serialized by an IRQ-safe leaf spinlock
(aspm_l1ss_hw_lock, compiled for both CONFIG_PCIEASPM=y and =n) plus
aspm_lock under CONFIG_PCIEASPM=y. Global lock order is
pci_rescan_remove_lock -> pci_bus_sem -> aspm_lock -> host hib_l1ss_lock ->
aspm_l1ss_hw_lock -> pci_lock.

Store aspm_sleep_disable and aspm_hw_l1ss as standalone u8 fields outside
struct pcie_link_state's aspm_lock bitfield word, and store
aspm_pcipm_deferred and aspm_l1ss_resync as standalone u8 fields on struct
pci_dev, so atomic restore paths never perform unlocked bitfield RMWs.

Wrap pci_save_pcie_state(), pci_restore_pcie_state(),
pci_set_low_power_state(), and pci_pm_reset()'s D3hot PMCSR write under
aspm_l1ss_hw_lock, and validate all four L1SS register reads before
committing in pci_save_aspm_l1ss_state_locked() so a D3cold 0xffffffff
read cannot corrupt saved timing. Have pci_restore_aspm_l1ss_state() mask
suppressed or non-D0 PCI-PM bits before writing and compare both ends
against aspm_hw_l1ss so both missing and stale-enabled substates set
aspm_l1ss_resync and force reprogramming on the next policy pass.

Propagate config-access errors from pcie_config_aspm_dev(),
pcie_config_aspm_l1ss() (unwinding child-first on partial failure), and
pcie_config_aspm_link_locked() through pcie_aspm_l1ss_sleep_end(),
re-arming aspm_sleep_disable and setting aspm_l1ss_resync on error so
callers can retain recovery records and retry cleanly.

Add pci_host_bridge->pm_state_change() and notify both core ASPM and host
bridges from pci_pm_default_resume_early(), pci_pm_runtime_resume(),
pci_set_power_state() on D0 entry, and pci_pm_reset() after returning to
D0, dispatching deferred core ASPM reconciliation via a preallocated
freezable work item on system_freezable_wq.

Signed-off-by: Erik Bourget <[email protected]>
…CI-PM

Switch apple_pcie's sleep L1SS teardown, suspend recheck, and restore to
pcie_aspm_l1ss_sleep_begin_locked(), pcie_aspm_l1ss_sleep_end(), and
pcie_aspm_l1ss_hw_exec() so L1SS/LNKCTL/PMCSR hardware sequences serialize
with pci_rescan_remove_lock, pci_bus_sem, aspm_lock, hib_l1ss_lock, and
aspm_l1ss_hw_lock across both CONFIG_PCIEASPM=y and CONFIG_PCIEASPM=n.

Keep prepare's bounded hotplug-safe runtime-PM pin and drain loop before
walking the bus under pci_lock_rescan_remove(), hold hib_l1ss_lock across
pending-record inspection and drain, and run each link's CTL2/CTL1/LNKCTL
snapshot together with hardware teardown inside pcie_aspm_l1ss_hw_exec().
In apple_pcie_hib_recheck_l1ss_link(), pre-allocate the recovery record
before modifying hardware and retain it whenever L1SS was cleared or core
suppression was armed. Check unmanaged D0 state inside
pcie_aspm_l1ss_hw_exec() so pci_set_low_power_state() and pci_pm_reset()
cannot transition an endpoint out of D0 before PCI-PM L1SS enable bits
are written.

Route all non-removal restore errors (driver config/D3cold errors,
double-failed LNKCTL restore during normal completion, and core-managed
pcie_config_aspm_link_locked() errors returned by
pcie_aspm_l1ss_sleep_end()) through apple_pcie_hib_retain_failed(),
retaining the recovery record in hib_l1ss_pending with timing_pending
set, preserving intended LNKCTL values and rollback_pending when LNKCTL
restore fails, and queueing a bounded worker retry when both ends are in
PCI_D0.

Route deferred unmanaged PCI-PM L1.1/L1.2 restores and timing retries
through a freezable work item (hib_l1ss_work on system_freezable_wq)
scheduled locklessly from bridge->pm_state_change(). Keep
hib_l1ss_pending_cnt elevated while a pending record is active (including
on the worker's retry list) and re-check D0 after splicing retry entries
back into hib_l1ss_pending. Release the sleep-window runtime-PM pins on
complete/rollback/free, purge both hib_l1ss and hib_l1ss_pending on
BUS_NOTIFY_DEL_DEVICE, and cancel hib_l1ss_work before taking
pci_lock_rescan_remove() in remove/cleanup paths.

Extend tools/asahi/pciec-policy-tests.py to cover core-managed and
unmanaged D3hot defer, pci_pm_default_resume_early() notification,
atomic-safe save/restore and D3cold 0xffffffff validation, aspm_hw_l1ss
resync forced reprogramming, core L1SS enable-error unwind and retry,
double-failed LNKCTL restore retention, hotplug during runtime-PM drain,
PMCSR/reset/LNKCTL locking, BUS_NOTIFY_DEL_DEVICE purging, and negative
mutation controls.

Signed-off-by: Erik Bourget <[email protected]>
@erikwb
erikwb requested review from a team and DjDeveloperr as code owners November 28, 2026 06:44
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 28, 2026
@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Merge readiness at a53f5749: not ready yet

Check Detail
CI at head no failing: KUnit ane-boot, KUnit dcp-fabric, KUnit dcp-topology
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok in the PR body at a53f5749
Conflicts ok none
PR text ok Risk: two-way · touches shared PCI core PM/ASPM paths (drivers/pci/{pci,pci-driver,probe,pci.h,pcie/aspm}.c, include/linux/pci.h) affecting all Macs, plus drivers/pci/controller/pcie-apple.c. Revert: git revert -m 1 <merge_commit> on main (reverts the eventual GitHub merge commit cleanly). Kernel driver and host-test changes only; no persistent ESP, Stage 2, DT, or on-disk state is modified.

Areas: area:gpu

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: HOLD at b886f11a

Blockers:

  1. Targets open non-default base branch feat/t8103-pcie-l1ss-sleep (#3494). Retarget to main once #3494 merges so full main CI runs on the final diff.
  2. Missing exact-head hardware sleep/resume row on the merged main base.

Checked:

  • 0dd1485a (PCI/ASPM core sleep L1SS suppression + aspm_l1ss_hw_lock + deferred aspm_pm_work on system_freezable_wq) and b886f11a (pcie-apple.c integration) cleanly implement part 2 of the #3221 split; MERGEABLE against feat/t8103-pcie-l1ss-sleep.
  • Checked for Apple material, tool attribution, and private serials: clean; human Signed-off-by present.
Evidence
  • Head: b886f11a (base: feat/t8103-pcie-l1ss-sleep, mergeable: MERGEABLE, +3042/-297 across 8 files).

Base automatically changed from feat/t8103-pcie-l1ss-sleep to main November 28, 2026 15:58
Forward-merge main (62675fa, including merged #3494) into
feat/pci-aspm-l1ss-sleep-core (b886f11 -> HEAD) with zero conflicts.
All eight PR-modified files under drivers/pci/, include/linux/pci.h,
and tools/asahi/pciec-policy-tests.py remain byte-identical to
a90a2bf..b886f11.

Signed-off-by: Erik Bourget <[email protected]>
@erikwb

erikwb commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Acknowledged the HOLD at b886f11a:

  1. Base branch and main CI: #3494 (feat/t8103-pcie-l1ss-sleep) merged into main (d95848ae72b4) and #3495 was retargeted to main. Forward-merged origin/main (62675fa56aba) into feat/pci-aspm-l1ss-sleep-core (b886f11afb33 -> a53f57492079, no force push) with zero conflicts so full main CI (apple-build-kunit, host-tests) triggers on the final diff. All eight PR-modified files (drivers/pci/{pci,pci-driver,probe,pci.h,pcie/aspm}.c, drivers/pci/controller/pcie-apple.c, include/linux/pci.h, tools/asahi/pciec-policy-tests.py) remain byte-identical to a90a2bfab82d..b886f11afb33.
  2. Offline verification at a53f57492079:
    • make O=_build_aspm_y ARCH=arm64 LLVM=1 W=1 drivers/pci/{pci,pci-driver,probe,pcie/aspm,controller/pcie-apple}.o (defconfig + asahi.config, RUST=n, CONFIG_PCIE_APPLE=m, CONFIG_PCIEASPM=y and =n): 0 warnings, 0 errors.
    • Host suites: pciec-policy-tests.py (86/86), pcie-adopted-clkpm-tests.py (13+2), radio-{pm,sleep-fence,sleep-power,sleep-snapshot}-tests.py, and binding-lifetime-tests.py (3/3): all PASS.
    • ./scripts/checkpatch.pl --strict --git origin/main..a53f57492079 and git diff --check origin/main..a53f57492079: 0 errors, 0 warnings, 0 checks.
  3. Hardware verification at a53f57492079 and PR body format:
    • Folded multi-Mac hardware results at a53f57492079 (note CONFIG_PROVE_LOCKING=y lockdep runtime pass, J713 TB5 runtime-PM churn re-run at a53f57492079, real s2idle on J716c, and J313 Group A post-S2R ISP capture fault isolation remain under **Not yet:**):
      • J716c (T6050, batched trial kernel 3545ebecb76f, 8/8 PR files blob-identical): PASS — Clock PM off unchanged on 00:00.0/01:00.0/01:00.1/01:00.2, 2x freeze + 2x mem pm_test=devices and 2x pm_test=platform clean, wlan0 0% loss after each, 0 PCIe/ASPM/AER lines, 5-item smoke clean, 0 new failed units (aurora-peripherals.service fails on default Stage 2 after warm reboots).
      • J713 (T8132, batched trial kernel 76649338a1bc over J713 daily base 8dbfa2895b93, 7/7 runtime files blob-identical, panic=10): PASS — BCM4388 ASPM L1 + L1.1/L1.2 enabled (runtime active), 5x wlan0 down/up + gateway ping 0% loss, 2x s2idle PASS (wlan0 up, 0 new err+ lines during the two tested s2idle cycles; one new, non-repeating boot-time brcmfmac ring 4 error of unknown cause at 9.238 s, 0 occurrences in the previous 8 boots); TB5 runtime-PM churn not exercised (no TB device attached).
      • J313 (T8103, Group A over main ee36fbdcd1c8, all changed PR files byte-identical): PASS (PCI/Wi-Fi + deep S2R) — Wi-Fi ASPM L1, ClockPM+, L1.1/L1.2 enabled before and after 2x deep S2R (0 -> 2), DPMS x3 PASS, 0 Oops/BUG/WARN (CONFIG_PROVE_LOCKING=y not built/run on J313; same Group A boot hit an unisolated post-first-S2R ISP capture -19/DART fault vs baseline main pass, and baseline main later became unreachable after its second deep S2R, awaiting physical recovery).
    • Updated **Tested:** so hardware results and head SHA appear on the first line and added **Revert:** alongside **What:**, **Risk:**, and **Not yet:**.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH at a53f57492079

Blockers: The base issue is resolved. Keep the lockdep runtime check, live dock regression and isolation of the J313 post-wake ISP fault outstanding. The current grouped test cannot attribute the fault.

Checked: All eight PR-path blobs are identical to the prior review, #3494 has merged and this PR now targets main. The current tests cover undocked J713 wake and grouped J313 wake.

Evidence

Compared the current head, prior review and current PR receipts.

@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Nov 29, 2026
@erikwb

erikwb commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Lockdep run and standalone matched pair on J313 (M1 MacBook Air, T8103), default cmdline, one-shot aura-try Stage 2 + GRUB trial; default boot.bin 1262bc5d… and kernel untouched.

  • Test: PR head a53f57492079 alone, CONFIG_PROVE_LOCKING=y. Kernel SHA-256 7ee4d934a0a5e9385eb71d39825451c293c865bcda19a910020c03991aeda272.
  • Control: main 62675fa56aba (the base merged into the head), same config. Kernel SHA-256 bc7f227a01d57d447b9f8f544ca7f281e1c2c1ce78f257343c83c13584e54186.
  • git diff control test is the 8 PR files only. Both use the same trial Stage 2 ebf270451dfae099a118f68d98da0d2587ebb69d26affa48dac70a68e7844838, byte-identical to the one used for the unmodified-main control on soc: apple: mcc: enable T8103 DCS dynamic clock and power gating #3506.
Check Control (main) Test (a53f5749)
Lockdep across boot, deep S2R attempt and 2x s2idle debug_locks: 1, 0 lockdep/RCU/sleep-in-atomic reports, 0 Oops/BUG/WARN/SError same
PR lock classes seen by lockdep n/a aspm_l1ss_hw_lock from boot; hib_l1ss_lock after the first sleep (4 → 10 → 11 class entries)
Wi-Fi ASPM L1, ClockPM+, L1.1/L1.2 (before / after sleep / after 2x s2idle) enabled at all three points same
wlan0 loss at each probe 0% 0%
ISP capture (90 frames) before and after the sleep attempt both complete, ISP domains back to off-0 same
2x s2idle (30 s) both resume same
Smoke: display, input, network, audio enumeration, GPU compute + render, AVC pass pass
err+ lines at the end 20 total, 12 new vs the boot baseline 20 total, 12 new vs the boot baseline

Lockdep: no report on either kernel. On the test kernel, lockdep registered the PR's L1SS lock classes and the paths ran across both sleep types. That closes the lockdep item.

ISP isolation: not conclusive this time. The J313 is docked (Thunderbolt dock with Ethernet and an external display on dcpext). On both kernels the deep S2R was refused before the SoC slept: apple-dcp 271c00000.dcp: PM: failed to suspend: error -16, PM: Some devices failed to suspend, rtcwake: write error. So neither run reached a real first deep wake, and the post-wake ISP fault did not appear on either. The other identical lines on both kernels come from the dock's display port (DCPDP2XService admission failed: -19, failed to deassert Type-C DPTX HPD: -110). The refusal and the dock lines are the same on main without this PR. The unmodified-main reproduction of the ISP fault on #3506 (#3506 (comment)) still stands. A clean isolation needs an undocked deep S2R, which needs someone to unplug the dock.

Still open: the undocked J313 deep-wake ISP pair, and the live TB5 dock regression on J713 (needs the dock attached there).

Evidence
  • Config: J313 daily config + PROVE_LOCKING (LOCKDEP, DEBUG_LOCK_ALLOC, PROVE_RCU), CONFIG_PCIEASPM=y, CONFIG_PCIE_APPLE=y; the two configs differ only in CONFIG_LOCALVERSION.
  • Commands: rtcwake -d rtc1 -m mem -s 30, rtcwake -d rtc1 -m freeze -s 30 (x2), v4l2-ctl -d /dev/video0 --stream-mmap=4 --stream-count=90, lspci -vv -s 0000:01:00.0, /proc/lockdep_stats, /proc/lockdep.
  • After the runs: default kernel and default boot.bin 1262bc5d… verified, next_entry empty, trial files removed.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at a53f57492079

Converts this App's earlier review at the same head to an approval under the 12-01 merge bar (better than before and doesn't break; block only on a shown failure). No code blocker was found in it. The merge gate (a row on one Mac at this head + fast CI) is tracked by pr-readiness, not held here.

Checked: All eight PR-path blobs are identical to the prior review, #3494 has merged and this PR now targets main. The current tests cover undocked J713 wake and grouped J313 wake.

Follow-ups (not blocking): lockdep runtime check, live dock regression, isolate J313 post-wake ISP fault (reproduces on main per #3506)

@erikwb

erikwb commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Updated the PR body at a53f57492079 to fold in the standalone J313 CONFIG_PROVE_LOCKING=y lockdep matched-pair pass and current verification state:

  • Lockdep closed in PR body: Moved the J313 T8103 standalone CONFIG_PROVE_LOCKING=y matched pair (a53f57492079 vs main 62675fa56aba, debug_locks: 1, 0 lockdep/RCU/sleep-in-atomic reports, aspm_l1ss_hw_lock and hib_l1ss_lock exercised across boot, docked deep S2R attempt, and 2x s2idle) from **Not yet:** into **Tested:** and Evidence, and updated the J313 ISP isolation item to reflect that J313 is currently docked (where apple-dcp refuses deep S2R -16 on both main and a53f57492079, while unmodified main already reproduces the fault on #3506).
  • Offline & KUnit checks at a53f57492079: W=1 builds (CONFIG_PCIEASPM=y and =n, 0 warnings/errors), ./scripts/checkpatch.pl --strict --git 62675fa56aba..a53f57492079 (0 errors/warnings/checks), all 7 host suites (pciec-policy-tests.py, pcie-adopted-clkpm-tests.py, radio-{pm,sleep-fence,sleep-power,sleep-snapshot}-tests.py, binding-lifetime-tests.py), and local arm64 QEMU KUnit runs for drivers/nvmem/apple-spmi-nvmem.kunitconfig (2/2 passed) and security/keys/trusted-keys/tests/.kunitconfig (8 passed, 1 expected built-in skip) all pass.
  • CI status at a53f57492079: Host tests, MT7932 KUnit, pr-text, apple-build, KUnit ane-boot, KUnit ane-pm, KUnit dcp-fabric, and KUnit dcp-topology passed; the remaining 12 Apple build and KUnit jobs in run 46199770227 (attempt 3) were cancelled after sitting queued ~4 h (following runner Install kernel build and QEMU dependencies failures on apple-spmi-nvmem and trusted-keys in attempt 1). git merge-tree --write-tree against current main (a171afd2123f, including merged #2215) is conflict-free (ef8f8723a9e9), so no branch push is needed—only a workflow rerun of Apple build and KUnit on a53f57492079.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed PMCSR and L1SS serialization, deferred D0 rechecks, and restoring saved state through suspend and device removal. Apple build, host tests, PCI-related KUnit, and the J313/J713 rows passed. The three red KUnit jobs stopped in Ubuntu package setup before tests ran.

@DjDeveloperr
DjDeveloperr merged commit 1e04eef into main Dec 1, 2026
61 of 84 checks passed
@DjDeveloperr
DjDeveloperr deleted the feat/pci-aspm-l1ss-sleep-core branch December 1, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants