Skip to content

soc: apple: sleep, mfd: macsmc: T6050: a port's wake with the lid closed is a dark wake - #2445

Open
axboe wants to merge 4 commits into
aurora-silicon:integration/aurorafrom
axboe:k116s-dark-wake
Open

axboe wants to merge 4 commits into
aurora-silicon:integration/aurorafrom
axboe:k116s-dark-wake

Conversation

@axboe

@axboe axboe commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

The SMC wakes the AP when a charger or a cable comes or goes, and has no mask for it: macOS writes none and leaves such a wake a dark one. On Linux each is a full resume. A charger that drops and renegotiates its contract under the sleep's load woke a K116s five times in six hours with the lid closed, and user space suspended again ten seconds later each time. This is the series mentioned on #2201.

Four commits, on integration/aurora:

  • A port's wake with the lid closed is a dark wake. A wake record of acattach, acdetach or USB-C_plug alone, with the lid reading closed, sets the dark wake as the lid's own closing already does.
  • T6050: tell when the SMC alone woke the AP. apple_sleep_smc_woke_alone() read a wake status that T6050's own wake never fills, so it was always false there and no wake was ever taken as dark. It now uses the status T6050's wake reads.
  • .prepare waits out a command in flight. A dark wake suspends again at once and found a command of the wake still running: -EBUSY, and user space took over. It now takes the mutex.
  • rtkit: echo log words on the saved lane. After the commit the SMC is read on the saved lane, which kept a log word for the ordinary handler without echoing it, and the SMC takes no AP idle notice while one is owed: the notice timed out and the entry panicked. A dark wake's quick re-suspend runs into that, with a syslog record's word or the OSLOG counter. The lane now echoes a word the ordinary handler would answer with its echo and nothing else.

What changes on other boards

  • The second commit makes dark wakes work on every T6050 board with the sleep, so a J714s or J716c woken with the lid closed now goes back to sleep where it resumed fully before.
  • The first and third apply wherever the SMC's saved-context path runs; the fourth on every board whose SMC is read on the saved lane.

Testing

K116s, firmware 27.2, on integration/aurora 0abc2f3 + #2201 and my other K116s commits; the K116s needs #2201 to sleep at all. On this base the series is build-tested only.

Dark wakes Panics
Charger pulled and plugged back, lid closed, no echo 18 3
Dark wakes in a row by RTC alarm, lid open, syslog words echoed about 120 3
Same, syslog words and the OSLOG counter echoed 200 0
The series as posted: charger pulled and plugged back, lid closed 16 0

The rows by RTC alarm use a test switch that makes each alarm wake a dark one; it is not in the series. The captures are in the v2 comment below.

Not fixed here, each seen once

  • A dark wake's re-suspend refused by the internal display coprocessor (-16) 180 ms after the wake's resume ended; the desktop suspended again 9 s later.
  • A sleep entered 18 s after a wake, woken at once with the record wifibt.

Not seen: a wake record of acattach or acdetach (every one was USB-C_plug), MagSafe, and a J714s or J716c.

checkpatch is clean on all four.

…a dark one

The SMC wakes the AP when a charger or a cable comes or goes, and has
no mask for it: macOS writes none, and leaves such a wake a dark one. A
charger that drops and renegotiates its contract under the sleep's load
woke a K116s five times in six hours with the lid closed (wake record
USB-C_plug each time). Every one was a full resume, with user space
suspending again ten seconds later.

Take a wake for acattach, acdetach or USB-C_plug alone as a dark wake
when the lid reads closed, as the lid's own closing already is.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
apple_sleep_smc_woke_alone() reads the wake status the common wake
arming saved, which a SoC with its own wake never fills: on T6050 it
is always false, and no wake is ever taken as a dark one. Use the
status T6050's wake reads at its start: only the SMC's lines latched,
and nothing in the GFX word.

Seen on a K116s, where a wake for USB-C_plug alone with the lid closed
logged SMC.OutboxNotEmpty as the only source and was still a full wake.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for this series, and for the clear write-up of the charger case and the two options for the fourth commit.

On that question, we would prefer the handshake over the timed wait. We avoid sleep or retry loops where a completion or status exists, and two are added in apple_smc_prepare():

  • drivers/mfd/macsmc.c:1496-1499: polls msleep(50) until the SMC has been quiet for SMC_PORT_QUIET_MS (4 s), up to 20 s.
  • drivers/mfd/macsmc.c:1508-1516: retries mutex_trylock() every 20 ms for up to SMC_PREPARE_BUSY_MS.

For the first, giving the saved lane's sleep notice the same reply timeout an atomic command gets (your second option) waits on the SMC's own answer instead of on silence. For the second, .prepare can wait for the command in flight to complete (take the mutex, or wait on the command's completion) instead of polling for it.

The first commit and the T6050 wake-status fix look good to us. If useful, we can run sleep rows on our M1 Pro, M2, M4 Pro and A18 Pro.

A dark wake suspends again as soon as every device has resumed. The
SMC's .prepare then finds a command of the wake still in flight and
refuses with -EBUSY: on a K116s, both dark wakes for a charger plugged
back in ended that way, and user space took over ten seconds later.

Take the mutex and so wait for that command to complete.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
The saved lane keeps a log word for the ordinary handler, which echoes
it after the wake. The SMC takes no AP idle notice while a log word is
owed: when it logs inside the committed part of the entry, the notice
times out and the entry panics, past the last step it can undo.

A dark wake that suspends again within two seconds does that on a
K116s, with either kind of log word:

- A charger plugged back in during a sleep, the SMC still logging its
  contract. 3 of 9 such runs ended in the panic; in the one with the
  lane's packets recorded, eight syslog words had reached it just
  before the notice. In a run with eight such words echoed, the SMC
  answered the notice in 166 us, as it does in every other sleep.

- Dark wakes in a row with no charger: 3 panics in about 120, with the
  syslog words already echoed. The lane held one packet, the OSLOG
  counter:

    macsmc: sleep notice: AP IDLE: -110 after 817327 us
    Kernel panic - not syncing: Apple committed SMC notice failed after
    peer stop: -110

Echo a word on the saved lane when the ordinary handler would answer
it with its echo and nothing else: a syslog record's word and the OSLOG
counter. A syslog record echoed there is not printed, as with the words
the receive path acknowledges ahead of the ordered queue.

With both echoed, 200 dark wakes in a row went back to sleep.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
@axboe

axboe commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Ryan, thanks. v2 is pushed. Neither wait survives, and the timeout I offered as the second option was wrong too: with a serial console on the machine I found the cause.

What happens

After the commit the SMC is read on the saved lane, which keeps a log word for the ordinary handler and does not echo it. The SMC takes no AP idle notice while a log word is owed. A dark wake that suspends again within two seconds has the SMC still logging, so now and then a word lands in the committed part and the notice times out. I saw it with both kinds of log word:

  • Syslog, charger plugged back in. With the AP power ack wait raised to 5 s for the test, so it is not a slow answer:
macsmc: DIAG saved lane AP power ack TIMED OUT: 8 packets since the last dump
macsmc: DIAG   ep 0x02 msg 0x0050000000000006, 8183838 us ago
 (seven more, 0x07 to 0x0d)
macsmc: sleep notice: AP IDLE: -110 after 8168552 us, 8186417 us into the notice (last reply 0xe000)
Kernel panic - not syncing: Apple committed SMC notice failed after peer stop: -110

With eight such words echoed on the lane, in another run, AP IDLE acked in 166 us, which is what every other sleep shows.

  • OSLOG counter, no charger. Dark wakes in a row, syslog words already echoed:
macsmc: DIAG saved lane AP power ack TIMED OUT: 1 packets since the last ack
macsmc: DIAG   ep 0x08 msg 0x0200000000000893, 833101 us ago, echo 0
macsmc: sleep notice: AP IDLE: -110 after 817327 us, 835811 us into the notice (last reply 0x9000)

This is the counter apple_rtkit_oslog_rx() already describes for other firmwares.

v2

  • Commits 1 and 2: unchanged.
  • Commit 3, .prepare: takes the mutex in place of the mutex_trylock() loop. In the 24 re-suspends I logged it for, a command of the wake held the lock each time and it was taken within 1 ms.
  • Commit 4: replaced. The settle wait is gone. apple_rtkit_m5_saved_poll() echoes a word when the ordinary handler would answer it with its echo and nothing else: a syslog record's word and the OSLOG counter. A syslog record echoed there is not printed, as with the words the receive path acknowledges ahead of the ordered queue. This is in rtkit.c, so it reaches every board on the saved lane; I can only test the K116s. The new helper repeats the echo conditions of apple_rtkit_oslog_rx(); say if you want that function built on it instead.

The 5 s reply timeout is not in the series and I withdraw it: it raised the wait for SMC key replies, which were never slow.

Tests (K116s, firmware 27.2)

Dark wakes Panics
Charger pulled and plugged back, lid closed, no echo 9 runs (18) 3
Same, syslog words echoed 3 runs (6) 0
Dark wakes in a row by RTC alarm, lid open, syslog words echoed about 120 3
Same, syslog words and the OSLOG counter echoed 200 0

The rows by RTC alarm use a test switch that makes each alarm wake a dark one and arms the next alarm; it is not in the series. The charger runs had the debug cable in, so the other machine was a second 5 V source on the port next to the charger's.

Without test code and with the syslog echo only: rtcwake -m mem -s 30 3 of 3 on one boot, panel on, Wi-Fi back; three charger runs with the lid closed, no console, no panic. At the v2 head as pushed: rtcwake -m mem -s 30 3 of 3 on one boot, panel on, Wi-Fi back; then, lid closed and no console, the charger pulled and plugged back four times per lid close, twice: 16 dark wakes, each asleep again, no suspend failed.

Seen once each in those runs, not fixed here

  • A dark wake's re-suspend refused by the internal display coprocessor (platform_pm_suspend returns -16), 180 ms after the wake's resume ended, lid closed. systemd reported the sleep failed and the desktop suspended again 9 s later. The settle wait in v1 hid this. Not reproduced in over 300 dark wakes with the lid open; I am still after it.
  • A sleep entered 18 s after a wake, woken at once with the record wifibt.

Yes to the sleep rows on your M1 Pro, M2, M4 Pro and A18 Pro, for commit 1: it changes what a port-only wake with the lid closed does on every board that reports the lid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants