Repository navigation
nvme: apple: restart ANS cleanly after a refused T8122 warm sleep - #3445
Conversation
The T8122 warm sleep idles ANS (RTKit IDLE) and clears its run bit in
.suspend, and keeps the RTKit session for the restart after the wake.
When the sleep is refused after that (no firmware resume), the resume
falls back to the cold path in the reset work: reset assert,
apple_rtkit_reinit(), deassert, boot. That has two problems after a
warm idle:
- The reinit is the first to free the session's buffers. It does that
through the SART, which on T8122 shares ANS's reset, so it reads a
SART held in reset and takes an asynchronous SError:
Kernel panic - not syncing: Asynchronous SError Interrupt
sart3_get_entry
apple_sart_remove_allowed_region
apple_nvme_sart_dma_destroy
apple_rtkit_reinit
apple_nvme_reset_work_impl
- With that out of the way, ANS doesn't boot ("ANS did not boot",
reset failure -62) and the disk is lost: in IDLE ANS gates its SART,
and the reset drops its entries, as on the M1 class's firmware sleep.
Treat a refused warm sleep as that path already treats a refused
firmware sleep: save the SART's entries and the word that gates it
before the idle (and drop them again if the idle fails), and on the
refusal take the start after a firmware sleep (fw_sleep_restart: SART
power word, SART entries, mailbox enables). Free the session's buffers
before the reset assert, with the SART power word written back first.
A committed warm sleep keeps its warm restart; its SART snapshot is
now taken before the idle instead of in the SART's suspend_late.
Closes: #3435
Signed-off-by: Ryan Murray <[email protected]>
There was a problem hiding this comment.
The refused-sleep path saves the SART table while the old RTKit buffers are still mapped. apple_rtkit_reinit() frees those buffers and removes their live entries, but apple_sart_restore_early() later replays the pre-idle snapshot. For SARTv3 the replay filter selects any saved nonempty entry, so it can restore a DMA mapping for freed memory and leave the hardware table inconsistent with used_entries. Refresh or invalidate the old session entries in the snapshot after teardown with SART powered and before asserting reset. Add a refused-sleep row that verifies that protected boot entries survive and all old session mappings stay absent until a fresh allocation claims them.
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
… them After a refused T8122 warm sleep, ANS comes back from the cold start on its old session's buffers: it reports on (IOP and AP power 0x0 -> 0x20) without asking for any new one. The previous change freed those buffers early and then wrote their SART entries back from the pre-idle snapshot, so ANS kept DMAing into freed memory through entries that used_entries no longer accounted for. Taking the snapshot again after the teardown instead removes the entries, and ANS's DMA is then refused: storage hangs (seen on J615). Keep them instead. While that restart runs, the shmem_destroy callback stashes the torn-down session's buffers, still allocated and still in the SART (and in used_entries), instead of freeing them, so the reinit no longer reads the SART inside the shared reset either; the early reinit and its SART power-word write go. The pre-idle snapshot written back now holds only live entries. The kept buffers are freed (with the SART out of reset) after a later start in which ANS allocates new buffers: the next one with a full handshake, such as after s2idle. If a start fails they stay kept, as ANS's state is unknown; buffers still kept at removal are not freed. Also log each SART entry written back from a snapshot (dev_dbg), with the boot loader's entries marked. Signed-off-by: Ryan Murray <[email protected]>
|
Thanks, the stale snapshot was real, and worse than stale entries: chasing it showed what ANS actually does after this restart. Fixed in b0ced07 (new commit on top, no force push). What ANS does. After a refused warm sleep, ANS comes back from the cold start on its old session's buffers. It reports on (IOP/AP power Fix. Keep them. While that restart runs, the shmem_destroy callback stashes the torn-down session's buffers instead of freeing them: still allocated, still in the SART and in Row you asked for (J615, exact tree, kernel 7.3.0-aurora-m3pr7+):
The M1 firmware-sleep path has the same snapshot/teardown ordering; filed as #3446 (not changed here). |
There was a problem hiding this comment.
Verdict: HOLD at b0ced070.
Blocker: drivers/nvme/host/apple.c:2173 treats any successful shared-memory allocation as proof that ANS has retired every retained mapping. RTKit handles buffer requests per endpoint. If a boot obtains a new crashlog buffer but still uses its old syslog or I/O-report buffer, the aggregate counter changes and the driver removes all of the old mappings while that boot can still use them. The boot-status check establishes that ANS initialized. It supplies no evidence about which endpoint buffers were replaced. Reclaim only replacements whose ownership the protocol establishes, or reclaim after a proven DMA-quiescent boundary. Please cover a partial replacement and a failed restart. Keep every retained allocation tracked so overflow cannot silently leave an unowned live mapping.
Checked: Read the full patch, RTKit allocation and reinit paths, and the J615 receipt. The refusal path now replays live entries, which resolves the original stale-snapshot finding. The receipt exercises zero replacements on refusal and all three replacements on the subsequent s2idle cycle. The partial replacement case remains unverified. Hosted checks and a second-family regression are pending.
The previous change freed the buffers kept from a refused warm sleep after any start in which ANS allocated a new buffer. RTKit hands out buffers per endpoint, so a start that replaces only some of them would have freed others that ANS still uses. Free them instead where the driver already frees its session's own buffers: after ANS acknowledges an RTKit shutdown (AP QUIESCED, IOP SLEEP), with its SART still out of reset. All shutdowns of a running ANS go through apple_nvme_rtkit_shutdown() for that: the cold reset, s2idle's suspend, removal and system shutdown. If the shutdown fails, or ANS isn't running, the buffers stay kept. Track every kept buffer in a list (__GFP_NOFAIL for the small node), so that none can be left mapped without an owner. Signed-off-by: Ryan Murray <[email protected]>
|
Replies to the review of b0ced07. Fixed in b58b626 (new commit on top).
J615 rows at the exact tree (66923b1 + this PR, kernel 7.3.0-aurora-m3pr8+), one boot:
Evidence: |
There was a problem hiding this comment.
Verdict: HOLD at b58b6264.
Blocker: The shutdown acknowledgement fixes the partial-replacement issue, but reclaim also has to retire the saved SART entries. Consider a refused warm sleep (buffers kept), then a successful firmware sleep (the live entries populate saved[] and resume makes replay_valid true), then a normal NVMe reset. apple_nvme_rtkit_shutdown() frees the kept buffers and clears their live entries. apple_sart_remove_allowed_region() leaves saved[] unchanged. The non-firmware reset path then calls apple_sart_replay(), and SARTv3's replay predicate accepts a nonempty saved entry even after used_entries has been cleared. This restores access to reclaimed memory.
Please retire the saved mappings as part of successful removal, or refresh the replay state at the quiescent, SART-live boundary before reset. Preserve protected boot entries and add a regression covering a successful firmware resume followed by reclaim and reset replay. The J615 refusal → s2idle row is useful, but s2idle clears replay_valid in late suspend and therefore does not cover that path.
Checked: Read the patch delta, RTKit shutdown and reinit, the legacy reset sequence, SART entry removal, the replay predicate and the J615 log. The new list removes the fixed-array overflow, and partial replacement alone no longer frees a kept buffer.
After a firmware-driven wake the SART keeps its snapshot for apple_sart_replay() (replay_valid), which a coprocessor's driver calls before it sets the run bit again, e.g. in the NVMe reset that follows a later failure. A region its driver removed in the meantime, freeing the memory behind it, stays in that snapshot, and the replay writes the entry back: the coprocessor can reach freed memory again. With nvme-apple, the buffers kept from a refused T8122 warm sleep and freed after a later shutdown are one case; the session's own buffers, freed by any RTKit shutdown after a wake, are another. Drop a removed region from the snapshot while it is kept for a replay. The bootloader's entries are never removed, so they stay. Before the wake, while the snapshot still waits for it, nothing changes: that wake writes back what was there when it was taken. Add a KUnit case: snapshot, a removal before the wake (kept), wake, removals after it (dropped; a protected entry can't be removed), power loss, replay. Signed-off-by: Ryan Murray <[email protected]>
|
Reply to the review of b58b626. Fixed in 718d688 (new commit on top). Replay of reclaimed regions. Agreed, and it isn't limited to kept buffers. After any firmware wake, the session's own buffers, freed by a later RTKit shutdown, stay in the snapshot that Regression for firmware resume → reclaim → reset replay. The J615 can't complete a firmware resume (the open 60 s post-commit wall), so the sequence is covered in KUnit: Exact-head J615 rows (66923b1 + this PR, kernel 7.3.0-aurora-m3pr9+), unchanged from b58b626:
Evidence: |
There was a problem hiding this comment.
Verdict: MERGE at 718d6882 when hosted checks and landing evidence are recorded.
Checked: Successful SART removal now retires the matching saved mapping when replay is valid. Protected entries, unrelated entries and a snapshot still waiting for its wake are preserved. I compiled the exact helper in a small host fixture and verified those cases, including a matching address with a different length. The recorded arm64 KUnit run passed 79/79, including replay after removal. The J615 log verifies repeated refused entry, shutdown-boundary reclaim, fresh allocations after s2idle and working storage at this head.
This clears the replay finding. The completed firmware-resume sequence is covered by KUnit. Hosted checks and the independent-family J473 regression remain pending.
|
Second-family row: J413 (MacBook Air M2, T8112), same kernel 7.3.0-aurora-m3pr9+ (this head 718d688 on #3413's 66923b1), non-default one-shot on its production Stage 2. Boot: 0 kernel errors, Enforcing, 0 failed units. s2idle 3/3 rc=0; after each: NVMe 256 MiB O_DIRECT read 4.1 GB/s + 64 MiB fsync'd write OK, eDP enabled, Wi-Fi up, 0 errors. The SART shows the normal per-cycle churn (shutdown frees 3 session buffers, the restart allocates 3). Restored: fleet89 saved and running, test kernel removed, 0 failed. (J473 was held by REBOOT-HANG; J413 is the same SoC family.) Evidence: |
Keep .untested = true and .display_no_restart = true on t8122_sleep_soc so /sys/power/mem_sleep remains [s2idle] by default until all T8122 deep-sleep prerequisites (aurora-silicon#3425, aurora-silicon#3504, aurora-silicon#3445, aurora-silicon#3452) have landed and 27.2-firmware T8122 boards (J615) have a matching display sleep path. With .untested and .display_no_restart preserved, default s2idle and apple_sleep.deep=1 dry runs stay intact on both 26.6.2 (J613) and 27.2 (J615), while committed J613 deep sleep runs via apple_sleep.deep=1 apple_sleep.untested_commit=1. Signed-off-by: Satya Benson <[email protected]>
satchlj
left a comment
There was a problem hiding this comment.
Reviewed at exact head 718d6882:
drivers/nvme/host/apple.c: deferring RTKit shmem buffer teardown viashmem_defer/kept_shmemacross a refused T8122 warm sleep and releasing those buffers only after ANS acknowledges shutdown inapple_nvme_rtkit_shutdown()cleanly prevents tearing down buffers ANS still uses or touching the SART during shared reset.shmem_deferis properly cleared on both boot success and reset failure paths.drivers/soc/apple/sart.c:apple_sart_forget_replay()retires non-protected removed entries fromsart->saved[]oncesart->replay_validis set, preventing stale reclaimed mappings from being written back on a subsequentapple_sart_replay().drivers/soc/apple/sart-test.c:sart_test_replay_after_removecovers pre-wake preservation, post-wake retirement, protected-entry immutability, and replay across SART versions.
(Looks like adding the Tested: and Risk: lines to the PR description is all that remains for pr-text / pr-readiness.)
What: On T8122, a warm sleep refused after ANS was idled now restarts ANS the way a refused firmware sleep does. The SART entries and power word are written back, and the old RTKit session's buffers stay kept until ANS acknowledges a clean RTKit shutdown. Before this, the refusal ended in an SError panic or a lost disk. Fixes #3435
Tested: J615 M3 Air 15" at 718d688: forced late refusal 3/3 recovered on the same boot (NVMe read/write + eDP OK), default cmdline boot + s2idle 3/3, 0 failed units. J413 M2 Air at 718d688 (second family, unaffected check): boot + s2idle 3/3, NVMe read + fsync'd write OK, 0 failed units. KUnit sart 79/79 on arm64 QEMU.
Risk: two-way · M3 (T8122) NVMe warm-sleep path; the SART replay change touches every Mac that replays SART entries after a firmware wake (M1, M2), covered by KUnit and the J413 row.
Not yet: a committed T8122 deep sleep that wakes (the J615 on 27.2 firmware doesn't wake from deep yet, a separate open issue); no M1 row.
Fixes #3435.
Problem. On T8122 the warm sleep (
hw->warm_sleep) idles ANS (RTKit IDLE) and clears its run bit in.suspend, and keeps the RTKit session for the restart after the wake. If the sleep is refused after that, there is no firmware resume, soapple_nvme_t8122_warm_resume()falls back to the cold path in the reset work: reset assert,apple_rtkit_reinit(), deassert, boot. After a warm idle that path fails twice:The reinit is the first thing to free the session's buffers. It frees them through
apple_nvme_sart_dma_destroy()→apple_sart_remove_allowed_region()→sart3_get_entry()while the SART is held in the ANS reset (T8122 shares it), and that is an asynchronous SError (Kernel panic - not syncing: Asynchronous SError Interrupt, nvme-reset-wq).With only (1) fixed, ANS doesn't come back:
ANS did not boot,Reset failure status: -62, the disk is gone, and btrfs goes read-only and hangs. What the firmware-sleep start puts back (SART entries, mailbox enables) is needed after this reset; the SART power word itself read 0x1 before and after. The M1 class's firmware sleep (7dfc208) already handles the same thing for a refused sleep.Once restarted, ANS runs on its old session's buffers: it reports on (IOP/AP power
0x0 -> 0x20) without asking for new ones. Freeing them (before or after the boot) either lets it DMA into freed memory or, with their SART entries gone, blocks it and storage hangs.Fix.
apple_sart_save_now()) and the NVMe block's SART power word, dropping them again if the idle fails. On the refusal (!pm_resume_via_firmware()), setfw_sleep_restart, so after the reset the reset work writes back the power word, the SART entries and the mailbox enables.used_entries) instead of freeing them. Nothing touches the SART inside the shared reset, and every entry written back is live.apple_nvme_rtkit_shutdown(). If the shutdown fails or ANS isn't running, they stay kept. Every kept buffer is tracked on a list.apple_sart_replay(), so a later replay can't map reclaimed memory again. This also covers the session's own buffers. KUnitsart_test_replay_after_remove.dev_dbgper SART entry written back from a snapshot (boot entries marked).A committed warm sleep keeps its warm restart. The only change on that path: its SART snapshot is taken just before the idle instead of in the SART's
suspend_late. No SoC, board or firmware gate: everything is under the existingt8122_warm_sleep/hw->warm_sleepstate.Rows. J615 (M3 Air 15", macOS 27.2 firmware). The kernel is this PR's two commits on top of #3413's head 66923b1, which adds the test-only
apple_sleep.refuse_late(kernel 7.3.0-aurora-m3pr7+; the same patch on that base). The first table is from the first commit alone (m3pr4); the current head's rows follow it. DT-only trial with main's J615 DTB, GPU module blacklisted,apple_t8122_display.dcpext=0,apple_sleep.deep=1.refuse_late=1+untested_commit)sart3_get_entry(reset work) → reset9 entries written back after a sleep that didn't happen,ANS boot and NVMe init completed, same boot; after each: eDP enabled, NVMe 4.3-4.9 GB/s O_DIRECT read, write + sync OK,/rw, btrfs device stats 0ANS did not boot, reset failure -62, disk lost (why the SART restore is needed)genpd_prepare -11linesNotes:
received syslog message but no syslog_msg_bufferthree times: ANS logs into its kept syslog buffer, which this RTKit session has no record of. Harmless; the messages are dropped until the next full start.Evidence (lab store):
traces/power/20261128-m3-deepsleep/rows/pr4-summary.txt,pr3drl3/kmsg.log,pr2Drl/.Rows at b0ced07 (m3pr7); the current head 718d688 (m3pr9) repeats them with the same results, see
rows/pr9/:ANS booted successfullythe kept 8/5/7 are freed. Disk OK (5.1 GB/s, write OK). Repeated once more: refuse_late keeps 9/10/11, the next s2idle allocates 5/7/8 and frees 9/10/11.traces/power/20261128-m3-deepsleep/rows/pr7/,pr5drl/,pr6rl/.