Skip to content

nvme: apple: restore the SART after a refused T8122 warm sleep - #3438

Closed
DjDeveloperr wants to merge 2 commits into
mainfrom
fix/nvme-apple-3435
Closed

DjDeveloperr wants to merge 2 commits into
mainfrom
fix/nvme-apple-3435

Conversation

@DjDeveloperr

Copy link
Copy Markdown
Contributor

Refs #3435

What

On J615, a refused late T8122 warm sleep leaves ANS idle with RUN clear. The reset worker then asserts the shared ANS reset and frees the old RTKit buffers. Freeing them removes their SART ranges, and that reads SART MMIO while the reset is asserted and after ANS has acknowledged IDLE. That read is the SError in #3435. Moving the free before the reset would still leave the read behind the firmware's IDLE gate, so this patch keeps the buffers instead:

  • Save the SART gate and entries while ANS is still running, before IDLE. After the idle acks, stop mailbox delivery and drain RX before clearing RUN.
  • On a refusal, pass the reason to reset work. Pulse the PMGR reset, restore the gate (checking the readback) and the saved entries while RUN is still clear, then start a fresh RTKit handshake with the same buffers and syslog geometry.
  • A real firmware wake still takes the existing warm handshake. Other SoCs and sleep paths are unchanged.

The RTKit helper that keeps the buffers across a reinit is the one from #3381 by Oliver Gregory, with one comment changed. This patch uses it only on the refused warm path. Whichever lands second should drop its copy of the helper.

Tested

  • Strict checkpatch: 0 errors, 0 warnings, 0 checks.
  • drivers/nvme/host/apple.o, drivers/soc/apple/rtkit.o and drivers/soc/apple/sart.o build with AArch64 GCC 16.1.1, -Werror and CONFIG_APPLE_SOC_SLEEP=y, with no warnings. Clang 23 context analysis prints the same 14 diagnostics for the base driver and for this patch.
  • No hardware run yet.

J615 test steps

Boot a one-shot kernel built from #3413 plus this patch, with its modules, the J615 DTB, serial or kmsg capture and an external recovery timer. Add these to the command line:

modprobe.blacklist=aurora apple_t8122_display.dcpext=0 apple_sleep.deep=1 apple_sleep.untested_commit=1 apple_sleep.refuse_late=1

Then, as root, on an internal NVMe filesystem with 256 MiB free:

set -euo pipefail
: "${rtc:?set rtc to the PMU RTC with a working alarm, e.g. /dev/rtc1}"
work=$(mktemp -d -p /var/tmp nvme-3435.XXXXXX)
dd if=/dev/urandom of="$work/pre" bs=1M count=128 conv=fsync status=none
digest=$(sha256sum "$work/pre" | cut -d' ' -f1)
boot=$(cat /proc/sys/kernel/random/boot_id)
echo deep > /sys/power/mem_sleep
p=/sys/module/apple_sleep/parameters
echo 1 > "$p/refuse_late"; test "$(cat "$p/refuse_late")" = Y
rtcwake -d "$rtc" -m no -s 15
if echo mem > /sys/power/state; then echo 'sleep was not refused' >&2; exit 1; fi
test "$(cat "$p/refuse_late")" = N
test "$boot" = "$(cat /proc/sys/kernel/random/boot_id)"
test "$digest" = "$(dd if="$work/pre" iflag=direct bs=1M status=none | sha256sum | cut -d' ' -f1)"
dd if="$work/pre" of="$work/post" bs=1M oflag=direct conv=fsync status=none
test "$digest" = "$(dd if="$work/post" iflag=direct bs=1M status=none | sha256sum | cut -d' ' -f1)"

A pass shows test: refused at the last check (refuse_late), the SART early-restore message and ANS: recovered after refused sleep in the kernel log, the same boot ID, a live controller and matching digests. Repeat three times on one boot, setting refuse_late again before each attempt (once it has been used, the next attempt really sleeps). The log must have no SError, RTKit boot, geometry or syslog errors, SART missing or full errors, I/O timeouts or filesystem errors. Also run a dry control with untested_commit=0, which should print "dry run: every check passed".

Risk

The change only affects T8122 when a warm sleep is refused. The early SART save also runs before a warm sleep that succeeds, and on that path the supplier skips its own late save. If the firmware asks for a different buffer size after the restart, the restart fails and I/O is held, instead of the controller being removed.

Not yet

On J615 a late refusal leaves ANS idle with RUN clear. The reset worker
asserts the shared ANS reset and frees the old RTKit buffers. Removing
their DMA ranges reads the SART while reset is asserted. Moving the
read before reset would still expose it to the firmware's IDLE gate.

Save the SART entries and gate while ANS is running. After the idle
acks, stop mailbox delivery before clearing RUN. On a refusal pulse
the reset, restore the gate and entries, and start a fresh handshake
with the same buffers. Keep the syslog geometry too, since firmware
may keep using its pre-sleep addresses without a new request.

Use Oliver Gregory's retaining RTKit reinit from the non-warm ANS
sleep fix in PR #3381. Only the refused warm path uses it here. The
regular T8122 firmware wake still takes the warm handshake.

Fixes: 038447c ("nvme: apple: skip T8122 warm sleep on dry runs and fall back on refused sleeps")
Link: #3435
Link: #3381
Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J516s (M3 Pro, T6030) at a019c98: PASS. Three s2idle cycles plus one NVMe controller reset. Every digest matched. No storage, RTKit, SART or SError errors.

  • Kernel: this head, built on the Mac and booted once with the stock J516s device tree, firmware and command line (build ID ae3293811bc8). Controller: nvme0, APPLE SSD AP0512Z, firmware 591.40.3, apple,t6030-nvme-ans3 at 38dcc0000.
  • Wrote a 128 MiB random file with fsync on the internal NVMe (btrfs). /sys/power/mem_sleep read [s2idle].
  • Ran three rtcwake -d rtc0 -m mem -s 15 cycles on macsmc-rtc. Every cycle went through a full suspend and resume and woke in the same boot; cycle 1 spent 16.9 s between suspend entry and thaw. In each cycle the ANS firmware shut down on suspend and came back through a full RTKit restart on resume. Afterwards the controller was live, and a direct read of the file and an fsynced direct copy both read back the original sha256.
  • One controller reset with I/O quiesced, through sysfs reset_controller. That is the same kernel path as nvme reset; nvme-cli isn't on this image. The controller was live again after 0.14 s, with the same integrity result.
  • Kernel log across the cycles and the reset: no I/O error, timeout, SART, RTKit error or SError lines, and no refused-sleep recovery message. That path is T8122-only, as expected.
  • Each cycle also shows dwc3-apple 702280000.usb: genpd_prepare returns -11 at prepare. It isn't fatal (the PM core skips -EAGAIN), and main shows it too.

The session reset now frees the buffers in its own helper, and
apple_rtkit_reinit() wraps a session reinit that can keep them. The
controls pulled only the old function names, so the generated harness
no longer compiled and every mutation was reported as stale.

Pull the helper and the session reinit too, where the driver has them.
Older revisions still build as before.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Closing in favour of #3445, which fixes #3435 with a smaller change to apple.c only and has J615 refused-sleep rows. The J516s s2idle and NVMe reset row above was for this branch and doesn't carry over.

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.

1 participant