Repository navigation
PM: sleep: consume only the dark-wake IRQ before device resume - #3846
Conversation
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
J516s hardware verification for exact head
|
DjDeveloperr
left a comment
There was a problem hiding this comment.
At this head, a second wake IRQ can disappear during dark-wake resume. suspend_enter() reenables IRQs and runs dpm_resume_noirq() and dpm_resume_early() before returning here. If a new wake IRQ reaches pm_system_irq_wakeup() in that window, it can occupy wakeup_irq[1] and increment pm_abort_suspend. pm_wakeup_clear(0) then erases both IRQ slots and zeroes that counter, allowing the dark-wake loop to re-enter sleep despite the new event. Please consume only the wake classified as dark and preserve later events. A dark wake followed by a separate wake IRQ before dpm_resume_early() returns should exit with userspace resumed.
2304766 to
ad97b96
Compare
|
Addressed the second-wake IRQ preservation finding in exact head
Exact-head verification (
|
DjDeveloperr
left a comment
There was a problem hiding this comment.
Review of ad97b966bf34: the new J516s traces close the second-wake finding in both resume phases.
One blocker remains in drivers/base/power/wakeup-test.c. KUnit supports reruns from debugfs on a live kernel. The suite init and exit call pm_wakeup_clear(0), which zeroes the real IRQ buffer and abort counter, and the cases inject synthetic IRQs into the same globals. A rerun concurrent with resume can discard a genuine pending wake or substitute a fake one. Please exercise private test state or scope the suite to the UML environment that produced the 5/5 result.
When a platform dark-wake callback (such as apple-sleep SMC power button or lid dark wake) handles a wake during dpm_resume_noirq() and calls pm_set_dark_wake(), pm_system_irq_wakeup() has already recorded that wake IRQ in wakeup_irq[0] and incremented pm_abort_suspend. Without consuming that handled dark-wake event, the re-suspend loop in suspend_devices_and_enter() sees pm_wakeup_pending() still true on the next iteration, aborts the re-suspend, and wakes the system into userspace with the display off. Simply zeroing wakeup_irq[] and pm_abort_suspend unconditionally would discard a second, real wake IRQ that arrives during dpm_resume_noirq() or dpm_resume_early() (before the loop re-checks pm_dark_wake()). Add pm_wakeup_consume_irq(unsigned int irq_number) to consume only the recorded wake IRQ when it matches wakeup_irq[0]: it promotes any second recorded IRQ from wakeup_irq[1] into wakeup_irq[0] and decrements pm_abort_suspend by one. Call it from suspend_consume_dark_wake() right after dpm_resume_noirq() completes; if another wake IRQ or non-IRQ wakeup source is still pending after consuming the dark wake, clear PM_SUSPEND_FLAG_DARK_WAKE so suspend_devices_and_enter() finishes resuming into userspace. Also clear PM_SUSPEND_FLAG_DARK_WAKE after suspend_enter() returns if an error occurred or a new wake arrived during dpm_resume_early(). Add a KUnit test suite (CONFIG_PM_WAKEUP_KUNIT_TEST) covering single-IRQ consumption, second-IRQ preservation, mismatched-IRQ no-op, non-IRQ wakeup preservation, and zero-IRQ no-op. Signed-off-by: Diljit Singh <hey@djdev.me>
|
Scoped Production files ( Re-verification (
|
ad97b96 to
013942c
Compare
DjDeveloperr
left a comment
There was a problem hiding this comment.
Rechecked 013942c. The UML and built-in KUnit dependencies keep the debugfs rerun off hardware kernels. The wakeup and suspend sources match ad97b96 byte for byte, so the J516s result still covers the runtime change. The five UML cases passed. No blocking code findings. Hosted checks and a second firmware-sleep generation row are still outstanding.
|
J516s (M3 Pro, T6030) hardware row at |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Blocking finding at 013942c in kernel/power/suspend.c, suspend_consume_dark_wake(): the firmware wake record does not identify the first Linux IRQ. Apple sets the dark-wake flag from latched SMC wake bits and a later SMC event. If an unrelated wake IRQ is the only IRQ recorded by Linux while noirq resume is in progress, pm_wakeup_consume_irq(pm_wakeup_irq()) removes that IRQ and its pending count, and the system can go back to sleep. The two-IRQ tests put the SMC IRQ first and miss this case. Pass the SMC IRQ identity when classifying the wake, consume only that IRQ when it is first, and preserve a sole unrelated IRQ. Please cover both a sole unrelated IRQ and an unrelated IRQ recorded before the SMC IRQ.
A firmware dark-wake record from Apple SMC does not prove that the first Linux IRQ recorded in wakeup_irq[0] belongs to SMC. If an unrelated wake IRQ arrived alone during noirq resume, or arrived ahead of the SMC IRQ, calling pm_wakeup_consume_irq(pm_wakeup_irq()) blindly would drop that unrelated wake event and allow the system to re-enter sleep. Track the classified dark-wake IRQ in pm_dark_wake_irq via pm_set_dark_wake_irq() (leaving pm_set_dark_wake() at IRQ 0 so firmware-only wakes never consume an unrelated Linux IRQ) and expose apple_rtkit_rx_irq() so macsmc passes its mailbox RX IRQ through all four Apple dark-wake paths (apple_smc_dark_wake, apple_sleep_lid_closed_wake, apple_sleep_port_wake, and apple_sleep_debug_link_cut_wake). In pm_consume_dark_wake(), atomically read and clear pm_dark_wake_irq and only call pm_wakeup_consume_irq(irq) when irq is nonzero, preserving both a sole unrelated wake IRQ and an unrelated IRQ recorded before the SMC IRQ so dark wake is cancelled and resume continues to user space. Also clear pm_dark_wake_irq on suspend_devices_and_enter() error/late wake paths and in pm_suspend_clear_flags(). Expand pm-wakeup-kunit-test (CONFIG_PM_WAKEUP_KUNIT_TEST, now depending on SUSPEND) to directly test pm_consume_dark_wake() across matching SMC IRQ, firmware-only dark wake, SMC IRQ followed by unrelated IRQ, sole unrelated IRQ, and unrelated IRQ recorded ahead of the SMC IRQ. Signed-off-by: Diljit Singh <hey@djdev.me>
|
Addressed the review finding from pullrequestreview-6143381070 in
Verification at exact head
|
|
J714s (M5 Pro, T6050) tested integration candidate
The retry needs to pass with the PCIe fix in the candidate. The J516s pass still covers the IRQ handling on T6030. |
J516s (M3 Pro, T6030) Shared-Code Control Receipt — PASSCandidate tree: Pass 1 — Clean exact-head kernel (
Pass 2 — Live physical deep-sleep dark-wake & mixed-IRQ verification (
|
satchlj
left a comment
There was a problem hiding this comment.
Verdict: MERGE at 48237685b006ac3d455f143d197e2c2303d9de6f
Blockers: none
Checked: no Apple material, no inappropriate model gating, default command-line compatibility, wakeup.c / suspend.c / macsmc.c / rtkit.c / sleep.c dark-wake IRQ consumption and rollback paths, UML KUnit scoping, hosted CI, exact-head J516s hardware receipts, PR text
Evidence
drivers/base/power/wakeup.c(pm_wakeup_consume_irq()): checksirq_number != 0, matches onlywakeup_irq[0]underwakeup_irq_lock, promoteswakeup_irq[1]towakeup_irq[0], and decrementspm_abort_suspendonce viapm_system_cancel_wakeup()only when consumed. A second recorded IRQ, a mismatched first IRQ, or a non-IRQ wakeup remains pending.kernel/power/suspend.c(pm_consume_dark_wake(),suspend_enter(),suspend_devices_and_enter()): atomically reads/clearspm_dark_wake_irqviaxchg()right afterdpm_resume_noirq()(beforedpm_resume_early()), consumes only a nonzero matching IRQ, and clearsPM_SUSPEND_FLAG_DARK_WAKEif any wake IRQ or non-IRQ wakeup source remains pending.suspend_devices_and_enter()also clears bothPM_SUSPEND_FLAG_DARK_WAKEandpm_dark_wake_irqon error or late wake duringdpm_resume_early(), andpm_suspend_clear_flags()resetspm_dark_wake_irq.drivers/soc/apple/rtkit.c,drivers/mfd/macsmc.c,drivers/soc/apple/sleep.c, and headers:apple_rtkit_rx_irq()guards null pointers and non-positive IRQ numbers; all four Apple dark-wake classifiers propagateapple_smc_wake_irq(smc);!CONFIG_PM_SLEEP,!CONFIG_SUSPEND, and!CONFIG_APPLE_SLEEPstubs match.drivers/base/Kconfig&drivers/base/power/wakeup-test.c:CONFIG_PM_WAKEUP_KUNIT_TESTdepends onKUNIT=y && UMLandPM_SLEEP && SUSPEND(keeping live-global test injection off hardware kernels) and covers single-IRQ, second-IRQ, mismatch, non-IRQ, firmware-only, sole unrelated IRQ, and unrelated-before-SMC cases (10/10 UML KUnit pass).- Hosted CI: all 12 checks passed (
apple-build,host-tests,pr-text,readiness,KUnit plan,KUnit dcp-topology macsmc asahi);MERGEABLEwith zero conflicts. - Hardware rows at exact head
48237685b006: J516s (M3 Pro, T6030) physical deep-sleep RTC control, live dark-wake re-entry (2 firmware entries / 1 thaw), mixed-IRQ cancel (SMC-first, unrelated-first, sole unrelated, spontaneous real-hardware race preservingmacsmc-rtcIRQ 87 and realUSB-C_plug), firmware-only dark wake, and 20/20 soak (#issuecomment-7332608358,#issuecomment-7333683556,#issuecomment-7343839905).
|
J714s (M5 Pro, T6050) exact-head row at
|
|
Merge-tree receipt: exact head
Not merged yet. The J714s exact-head row above is PARTIAL and has a retry queued, and the |
|
Hold: the readiness check counts the hardware row as done, but the J714s (M5 Pro) row at |
|
J714s (M5 Pro, T6050) exact-head Rev 2 row —
|
|
Hold status at |
|
J714s (M5 Pro, T6050) exact-head Mode 2 dark-wake repeat —
|
|
Hold lifted at
Since the row's base |
Summary
When a platform dark-wake callback (such as
apple-sleepSMC power button, lid, port, or debug-link-cut dark wake) handles a wake duringdpm_resume_noirq()and callspm_set_dark_wake_irq(irq),pm_system_irq_wakeup()has already recorded that wake IRQ inwakeup_irq[0]and incrementedpm_abort_suspend.Without consuming that handled dark-wake event, the re-suspend loop in
suspend_devices_and_enter()seespm_wakeup_pending()still true on the next iteration, aborts the re-suspend, and wakes the system into userspace with the display off.Simply zeroing
wakeup_irq[]andpm_abort_suspendunconditionally (or blindly consumingwakeup_irq[0]without matching the classified dark-wake IRQ) would discard a sole unrelated wake IRQ, an unrelated IRQ recorded ahead of the dark-wake IRQ, or a second wake IRQ arriving duringdpm_resume_noirq()ordpm_resume_early().This change:
pm_wakeup_consume_irq(unsigned int irq_number)indrivers/base/power/wakeup.c(with!CONFIG_PM_SLEEPstub ininclude/linux/suspend.h) to consume only a matchingwakeup_irq[0], shift any second recorded IRQ fromwakeup_irq[1]intowakeup_irq[0], and decrementpm_abort_suspendby one.pm_dark_wake_irqviapm_set_dark_wake_irq(unsigned int irq)(leavingpm_set_dark_wake()at IRQ 0 so firmware-only dark wakes never consume an unrelated Linux IRQ) and exposesapple_rtkit_rx_irq()somacsmcpassesapple_smc_wake_irq(smc)through all four Apple dark-wake classifiers (apple_smc_dark_wake,apple_sleep_lid_closed_wake,apple_sleep_port_wake,apple_sleep_debug_link_cut_wake).pm_consume_dark_wake()insuspend_enter()right afterdpm_resume_noirq()to atomically read/clearpm_dark_wake_irqand consume it only when nonzero and matchingwakeup_irq[0]; if any wake IRQ or non-IRQ wakeup source remains pending, clearsPM_SUSPEND_FLAG_DARK_WAKEsosuspend_devices_and_enter()finishes resuming into userspace.PM_SUSPEND_FLAG_DARK_WAKEandpm_dark_wake_irqaftersuspend_enter()returns on error or late wake duringdpm_resume_early(), and clearspm_dark_wake_irqinpm_suspend_clear_flags().CONFIG_PM_WAKEUP_KUNIT_TEST(drivers/base/power/wakeup-test.c, depending onPM_SLEEP && SUSPEND) with 10 UML KUnit subtests covering bothpm_wakeup_consume_irq()andpm_consume_dark_wake(), including matching SMC IRQ, firmware-only dark wake, second-IRQ preservation, sole unrelated wake IRQ, unrelated IRQ recorded ahead of the SMC IRQ, and non-IRQ wakeup preservation.Tested
Tested:
48237685b006on J516s (T6030, M3 Pro) passed three physical deep-sleep cycles with a clean stock handback. A separate instrumented run (modes 1–5) verified dark-only re-entry, mixed-wake cancellation, firmware-only dark wake preservation, and preserved the RTC IRQ during a spontaneous mixed wake. Native UML KUnit (pm-wakeup-kunit-test) passed 10/10, andscripts/checkpatch.pl --strict --ignore FILE_PATH_CHANGESreported 0 errors, 0 warnings, 0 checks. Exact-head test details.The J516s combined sleep-stack soak kernel (
0f829697b087, which carries48237685b006) completed 20/20 physical deep-sleep cycles and 20/20 NVMe readback checks, with zero kernel errors or GPU faults and clean stock handback. Combined soak receipt.Risk: two-way · all firmware-sleep Macs