Repository navigation
nvme: post-M4: start an ANS running from iBoot again from a reset - #593
Conversation
pmgr_reset_held() is declared in every build but only built with SPTM_VIRT. A Stage 2 needs it to reset an idle ANS, which refuses a plain pmgr_reset(). Build it everywhere, and look the device up with pmgr_find_device_by_name() as pmgr_reset() does, so that a virtual child sharing its parent's name isn't picked. Signed-off-by: František Balázsy <fbalazsy@users.noreply.github.com>
…ails A post-M4 ANS whose CPU was stopped without a reset since it last ran sends no HELLO after the run bit, then or later. A Stage 2 that meets it in nvme_ans_power_on() stops with "ANS didn't start from off; it stays down until a reboot" and parks in the proxy. On a J616s (T6040) the state survived a watchdog reset taken while Linux had ANS stopped for sleep, and every warm reboot after it; only a power-off cleared it. Make that start again from a reset ANS, as XNU starts it: stop the CPU, reset ANS alone through PMGR with its gate held on (pmgr_reset_held()), drop what is left in the mailbox, put the SART entries back, and start it warm (the HELLO the firmware sends unasked), then after another reset cold (INIT, then HELLO). If that fails too, power-cycle ANS and its PCIe block first and do the same once more. A start that granted the firmware buffers isn't retried. Nothing changes when the first start works. J616s, Stage 2 with this change as an aura-try trial behind an installed 1.0.0b13.1 Stage 1, with a test-only hook that idles ANS (acknowledged) and starts it from off again without its power-off or a reset: CPU status 0x6e and "did not receive HELLO"; after the reset 0x6a, HELLO, started in 0.12 s, and the boot went on to Linux. Signed-off-by: František Balázsy <fbalazsy@users.noreply.github.com>
2945f30 ("pmgr: build pmgr_reset_held() outside the SPTM_VIRT build") also changed how pmgr_reset_held() finds its device: virtual entries became skipped. Its existing caller, the T8140 cold handoff, may then pick another entry than before, and that wasn't checked there. Keep the lookup as it was; the change only needs the function built everywhere. Signed-off-by: František Balázsy <fbalazsy@users.noreply.github.com>
rtkit already records a start whose firmware sent no HELLO, for rtkit_boot_or_adopt(). Give callers an accessor, so that they can tell a firmware that never answered from one that answered and then failed a later step of its start. Signed-off-by: František Balázsy <fbalazsy@users.noreply.github.com>
110acee ("nvme: post-M4: start ANS again from a reset when its start from off fails") resets ANS after any failed start from off. A start also fails when the firmware sent HELLO and the endpoint map but its power report didn't come in time, or when BOOT_STATUS didn't turn OK. Such a firmware is running its resume, may be doing NAND work around it, and must not be reset under it. Reset only when the failed start got no HELLO at all (rtkit_no_hello()); any other failure stays on the "stays down" path, as before that commit. The cold start from a reset used rtkit_boot(), whose wait for the power report has no limit: a firmware that says HELLO and never reports would hang the stage. Use rtkit_boot_timed() with the 6 s the warm start gives the same report. The comment no longer says where the sequence was seen: it is the normal RTKit start. Some machines name ANS's PMGR device ANS2, as nvme_ans_sleep_and_reset() notes; the reset now tries both names. The gate listed for /arm-io/ans is not used, since on T8140 it is the virtual APCIE_SYS_ST-V. Worst case added to a boot: the recovery runs only after starts that got no HELLO, each of which waits 1 s, so at most 4 s for the four retried starts, four held resets (a PMGR mode change and 10 us each) and one power cycle of ANS and its PCIe block. The last start then has the limits every start has (1 s for HELLO, 6 s for each power report, 1 s for BOOT_STATUS). There is no loop beyond the five starts. J616s (T6040), this Stage 2 as an aura-try trial behind an installed 1.0.0b13.1 Stage 1, with a test-only hook that idles ANS (acknowledged) and starts it from off again without its power-off or a reset: - warm after reset: CPU status 0x6e, "did not receive HELLO"; after the reset 0x6a, HELLO, started 0.12 s after the reset. - cold after reset (hook also skips the first reset): two starts with no HELLO, then the reset (0x6e -> 0x6a) and the cold start, started 0.12 s after the reset. - without the hook: the first start works and nothing else runs. Each boot went on to Linux with NVMe working. Signed-off-by: František Balázsy <fbalazsy@users.noreply.github.com>
On the J713 (T8132, firmware 27.2) a warm reboot can leave ANS answering HELLO and the endpoint map and then sending nothing more: "timed out waiting for IOP power state 0x20 (last 0)" after 6 s, CPU status 0x6e. The no-HELLO narrowing leaves that start on the "stays down until a reboot" path, so the boot stops in the proxy. rtkit now records, for each boot attempt, whether its IOP power wait gave up on the timeout (not on a receive error) with no message of any kind read during the wait and no crash. Nothing else changes in a failed boot, so DCP and the other RTKit users see the same behaviour as before. nvme asks for more only when it would restart ANS: rtkit_silent_after_power_wait() also requires the mailbox to stay empty for another 0.5 s. It only looks at the mailbox and never reads it, so a late message stays queued and nothing is handled (no buffer granted) on the way to a restart. nvme_ans_silent() treats such a start like one with no HELLO, and nvme_ans_reset_for_start() looks at the mailbox once more just before the stop that would discard it. A firmware that reported any power state, sent any message, or got as far as BOOT_STATUS is still left alone. The retry bounds are unchanged: at most five starts, four resets and one power cycle, now up to 6.5 s each when the firmware stays quiet. Signed-off-by: Erik Bourget <erik@ebourget.net>
rtkit_wait_for_power() checks its deadline after each rtkit_recv(), and only then the state that receive may have changed. A report of the target state handled by the call that reaches the deadline is then turned into a timeout, and the start fails although the IOP answered in time. Check the state first, so a report read within the deadline counts. A wait that ends without one is unchanged. Signed-off-by: Erik Bourget <erik@ebourget.net>
A stage that finds ANS running from iBoot (Stage 1 on the J713) gives it one plain RTKit handshake. The from-off start's resets don't cover it: a firmware that sends no HELLO fails NVMe for the boot, and one that says HELLO and then nothing waits for the IOP power report forever, since rtkit_boot() has no timeout. rtkit_boot_bounded() is rtkit_boot() with the IOP power report bounded. It doesn't wait for the AP power state and leaves the later timeouts as they were, so a handshake that works is unchanged. nvme_ans_boot_running() takes that handshake with the 6 s the other post-M4 starts give the report. A failed start is made again only when the firmware sent no HELLO, or HELLO and then nothing at all (nvme_ans_silent()), the start granted it no buffers, and nothing at all arrives in the mailbox for another 0.5 s (one grace for either case), nor at a last look just before the stop. The mailbox is only looked at, so a late HELLO stays queued and stops the reset. Otherwise ANS is left untouched, as before. nvme_ans_reset_for_start() now stops ANS's CPU right after its last look and only then drains the mailbox (rtkit_stop()), for the from-off resets too: before, the drain came first, and a message sent between the look and the stop was dropped unseen. One sent as the CPU stops is logged; the reset goes on, since the firmware is stopped by then. Without the restart the boot stops with NVMe down, and the reboot that follows resets ANS as well. The restart resets ANS alone and starts it cold, as iBoot starts it, then once more after a power cycle of ANS and its PCIe block, through nvme_ans_reset_for_start() with iBoot's SART entries put back. The cold start asks this stage for new buffers, so nothing iBoot gave the firmware is used after the reset. After a reset a failure keeps the queues and needs a reboot, as for a start from off. The SART snapshot is for the resets only and is dropped once they are done, started or not, so nothing reports ANS as powered off while it runs. A session that started from a reset is handed on as one that came running, like iBoot's (it was started cold, as iBoot's is), so the next stage's handoff is unchanged. M1-M3 and the from-off and adopted paths are unchanged. Worst case added to a boot, with a firmware that stays quiet: about 20 s (the handshake and two cold starts, each 6 s for the report and 0.5 s grace), two resets and one power cycle. NVME_TEST_RUNNING_FALLBACK (test builds only) takes the reset path on a healthy ANS: no handshake, iBoot's session is idled instead, and ANS is reset only once the firmware acknowledged the idle. Signed-off-by: Erik Bourget <erik@ebourget.net>
The host stubs kept cpu_stopped set after a reset's first stop, so a later attempt that drained the mailbox before stopping ANS would have passed. Clear it whenever a fresh RTKit instance is taken. Signed-off-by: Erik Bourget <erik@ebourget.net>
|
Merge readiness at
Areas: none matched in CODEOWNERS Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
There was a problem hiding this comment.
Superseded 12-01: not a hold under the merge bar (no shown failure). Only metadata/CI checked; follow-ups: J713 forced-fallback reset row and Stage 1 warm-reboot rows
Verdict: HOLD at e3303b33
Blockers:
- Missing hardware verification for a one-way-door Stage 1 NVMe reset-recovery change. As noted under
Not yet, no Mac has bootede3303b33yet; Stage 1 enrollment requires the planned J713 hardware rows (NVME_TEST_RUNNING_FALLBACKexercising the reset path on a healthy ANS, followed by real Stage 1 warm-reboot cycles).
Checked:
- Metadata, commits (
02096c6f,7a55e1da,e3303b33,+760/-33, 9 files),MERGEABLEagainstmain. - All CI suites (
build,test,format-check,stage1-size,esp-stage2-size,pr-text,aurora-agent-policy,pr-readiness) passed ate3303b33.
Evidence
- CI is completely green; holding for J713 hardware testing of both the forced fallback reset path and real Stage 1 warm reboots.
|
Verified
|
DjDeveloperr
left a comment
There was a problem hiding this comment.
Reviewed the bounded handshake, reset admission, SART restoration, and queue preservation on failed recovery. The Stage 2 boots and host checks are recorded. Merge still needs the owner-run J713 Stage 1 forced-fallback and normal warm-reboot rows, plus size verification on the current base.
|
Merging at |
|
Follow-up on Enrolled a
|
On the M4 Mac mini (J773g, T8132), 1 boot in 7 the ANS warm start after the Stage 1 hand-off answers HELLO and the endpoint map, then crashes before its IOP power report (CPU status 0x68), and the next stage has no NVMe (aurora-silicon#613). Two gaps: - The crash report is lost. A warm start grants no crash log buffer, so rtkit_crashed() returned at "IOP crashed!". The crash message names the buffer the earlier stage granted; under SART its address is physical. Read the log from it when the whole buffer lies inside one SART entry (the entries the earlier stage set, put back before the start), never anywhere else, and never free it. sart_covers() does the check. - The start isn't retried. Since aurora-silicon#593 a warm start that got HELLO and then nothing is reset and made again (warm, cold, power cycle), but a crash message counted as "answered" and stopped that. A warm start that crashed before reporting power, with no buffer granted by this start (rtkit_crashed_in_warm_start()), now takes the same reset ladder: the firmware isn't resuming, and the session holds no queue or grant. Host tests: the RTKit harness gains a warm start through a SART whose firmware crashes after the endpoint map, with its log inside and outside the SART entry. Link: aurora-silicon#613 Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
What: A post-M4 stage that finds ANS running from iBoot (Stage 1 on the M4 MacBook Air, J713) gets a bounded handshake and the reset recovery a start from off has. Today that stage's one plain
rtkit_boot()fails NVMe for the boot when the firmware sends no HELLO, and waits for the IOP power report forever when it says HELLO and then nothing. Stacked on #449 and onf547c53e(wip/ans-hello-then-silent): review the top three commits (compare).Tested: J716c (M5 Max,
T6050) ate3303b33: one-shotaura-tryStage 2 (ESP_STAGE2=1, installed alongside the default Stage 2, which was not touched) booted the default Linux7.3.0kernel to the desktop with the NVMe root and the RTKit endpoints (SMC, MTP, GPU) up, 1 failed unit (aurora-peripherals.service, also failed on the default boot; 0 new), 0 LSM denials (no SELinux or AppArmor loaded), 0 GPU or MMU faults, 0 Oops/WARN/SError lines, the same 41 kernelerr+lines as the default boot apart from which DCP node prints themd-managerservice line,eDP-13456x2234@120, Wi-Fi 0% loss, andvkcube --c 240 --wsi waylandclean. J713 (M4 Air,T8132, 27.2 firmware, battery, default command line) ate3303b33: one-shotaura-tryStage 2 (ESP_STAGE2=1,1.0.0b17-ge3303b33; default Stage 2 left untouched) booted Linux7.3.0to the desktop with the NVMe root up (nvme: ANS started from off, RTKit v12,IOP power state 0x20, non-regression ofrtkit_wait_for_power()and Stage 2 NVMe paths; Stage 1 stayed at1.0.0b17-gd82fa5dbwithnvme: entry RUN=1, so the running-ANS path was not entered),0failed units (system and user),0AppArmor denials,0Oops/WARN,eDP-12560x1664@60enabled, and kernelerrlines = baseline3. Hosted CI ate3303b33: 19 successful, 11 skipped, 0 failing; local host tests (1526 passed in full run, 52/52 targeted NVMe/RTKit tests passed) andclangRELEASE=1 CHAINLOADING=1builds (ESP_STAGE2=1, Stage 1, and Stage 1 withNVME_TEST_RUNNING_FALLBACK) pass ate3303b33.Risk: one-way door: it ships in Stage 1, which a revert doesn't undo on a Mac that enrolled it · post-M4 Macs whose ANS has the split secure BAR (T8132, T6040, T6041, T6050, T8140, T8142), only when a stage finds ANS running from iBoot and its handshake fails. A handshake that works is unchanged.
Not yet:
J713Stage 1 rows ate3303b33(requires machine-owner Stage 1 / 1TR enrollment): an enrolled Stage 1 built withNVME_TEST_RUNNING_FALLBACK(the reset path on a healthy ANS), then the real Stage 1 with warm reboots. No other post-M4 Mac. The real failure can't be produced on demand.Details
Why. #449 recovers a start from off, which is what Stage 2 does on the J713. Stage 1 there finds ANS running from iBoot (
nvme: entry RUN=1), skips that path and does one plain handshake. Adid not receive HELLOwas seen once on a J713 after a restart from macOS; which stage printed it wasn't captured. With NVMe down, Stage 1 can't load Stage 2 and stops in the proxy until the proxy fallback restarts the Mac, which resets ANS anyway.rtkit: count a power report read just before the wait's deadline.rtkit_wait_for_power()checked its deadline before the state the last receive changed, so a report of the target state read by the call that reached the deadline became a timeout. It now checks the state first. Every RTKit power wait gets this.nvme: post-M4: start an ANS running from iBoot again from a reset.rtkit_boot_bounded()isrtkit_boot()with the IOP power report bounded. It doesn't wait for the AP power state and leaves the later timeouts as they were.nvme_ans_boot_running()takes the handshake with the 6 s the other post-M4 starts give the report. A failed start is made again only when:nvme_ans_silent()),nvme_ans_reset_for_start()with iBoot's SART entries put back. The cold start asks this stage for new buffers, so nothing iBoot gave the firmware is used after the reset.nvme_ans_reset_for_start()now stops ANS's CPU right after its last look and only then drains the mailbox (rtkit_stop()), for nvme: post-M4: start ANS again from a reset when its start from off fails #449's from-off resets too. A message sent as the CPU stops is logged and the reset goes on.NVME_TEST_RUNNING_FALLBACK(test builds only) takes the reset path on a healthy ANS: no handshake, iBoot's session is idled instead, and ANS is reset only once the firmware acknowledged the idle.M1-M3 and the adopted path are unchanged. The from-off start keeps its own retry selection (which failures take the reset path is unchanged), but it shares the two changes above that are not specific to a start from iBoot:
nvme_ans_reset_for_start()stops ANS's CPU before it drains the mailbox, and every RTKit power wait counts a report read at its deadline.Stack. The first five commits are #449's code commits, carried unchanged onto
maine019f3e6, thenf547c53e(restart a start that said HELLO and then nothing, the second J713 signature reported on #449). When #449 lands,maingets merged in here.Evidence
Hosted CI at
e3303b33fef2: 19 successful, 11 skipped, 0 failing (build,ESP stage 2 vital size,format-check,gcc,stage1-sizeacrossgcc/clang-macos/fedora/alarm/nix,Pytestacross ubuntu/macos/arm,pr-text,readiness).J713 (
M4 Air,T8132, firmware 27.2, battery 50% to 43%, default command line) one-shot Stage 2 ate3303b33fef2: default Stage 2 (1.0.0b17-gf547c53e,m1n1/boot-ctxr-272.binSHA-2569a013b9c1b6c89d8766922671fe68418bc7c539c708d0a5c6981f9ff8cb89222) left in place; trial image =ESP_STAGE2=1 RELEASE=1 CHAINLOADING=1aura.binbuilt ate3303b33fef2(SHA-2563e3242dfc4abdfb9df9ba0b38e5b4339300b0e086127f86ce85c9e60df6fa357) followed by the default image's device-tree and U-Boot tail (trial image SHA-2567a0a5f5c0ea736a945a147cb84b5eef5148794ef9dbe3368ff2278cb5101ce91), armed once throughaura-try(spentafter boot)./proc/device-tree/chosen/asahi,m1n1-stage2-versionread1.0.0b17-ge3303b33; Stage 1 remained1.0.0b17-gd82fa5db(nvme: entry RUN=1, so the running-ANS path of this PR was not taken). Stage 2 loggednvme: entry RUN=0 ... saved SART entries=9,rtkit(nvme): booting with version 12,IOP power state 0x20,nvme: ANS started from off,nvme: initialized, and Linux7.3.0mounted the NVMe root filesystem and reached the desktop (0failed units system and user,0AppArmor denials,0Oops/WARN,eDP-12560x1664@60enabled, kernelerrlines = baseline3). Restored: default Stage 2 hash unchanged,aura-tryreturned to its previousspentcontent, trial image removed.J716c (
M5 Max,T6050, firmware 27.2, AC 100%, default command line) one-shot Stage 2 ate3303b33fef2:aura.binSHA-2563e3242dfc4abdfb9df9ba0b38e5b4339300b0e086127f86ce85c9e60df6fa357(ESP_STAGE2=1, built from the head), chained from the default Stage 2 throughaura-trywith the trial watchdog armed, then the default boot tail and the default Linux7.3.0kernel and DTB. The device tree'saurora,trialproperty named the chained trial Stage 2 path (aurora/<dir>/stage2.bin) the device tree'sasahi,m1n1-stage2-versionread1.0.0b17-ge3303b33(the head; the default Stage 2 reads1.0.0b17-g42243c6b), and theaura-trymarker went tospent; the default Stage 2 (SHA-256b0a2f222b5a9151c201f5a89af4e13bae7078942bd14d1b7abcde941f30017b4) was not modified. NVMe: root onnvme0n1p10,nvme0n1p1 to p11 enumerated. RTKit: SMC, MTP and GPU endpoints initialised (protocol version 12). Failed units:aurora-peripherals.service(1, same on the default boot). Kernelerr+: 41 lines on both boots; only difference is themd-managerDCP service line printed for302e00000and306e00000instead of392e00000, and one fewer shutdown watchdog line. 0GPU fault/MMU fault/firmware-timeout/DeviceLost/recovery lines, 0 Oops/BUG/WARN/SError lines. This branch is based onmaine019f3e6, so the trial Stage 2 does not carry the latermaincommits the J716c default Stage 2 has (42243c6b8); it was exercised on the default kernel only.Clean merge check against
origin/main(2a7854a30d16):git merge-tree --write-treesucceeds cleanly (a772b3c4bb5a, 0 conflicts).Host tests at
e3303b33:cd tests/python && python -m pytest -q -p no:cacheprovider .gives 1526 passed, 26 skipped, 2 failed (test_proxyclient/test_aura/test_loadobjs.py::test_tool_output_lines,::test_run_tool, which need proxyclient tools the build host doesn't have and fail on the base too). Targeted re-run (test_nvme_ans_running_restart.py,test_rtkit_iop_power_silent.py,test_nvme_ans_warm_start.py,test_nvme_adoption.py,test_nvme_poisoned_io.py): 52/52 passed.New
tests/python/test_nvme_ans_running_restart.py(17 cases): clean start, BOOT_STATUS failure, no HELLO, HELLO then nothing, after a power cycle, never, cold start answers and fails, reset fails, answered, buffers granted, a message at each look (in the grace, before the reset, at the helper's look, as the CPU stops), and the test build with and without an acknowledged idle. The stubs fail any case that drains the mailbox before the CPU stop; putting the old order back fails 20 tests here and intest_nvme_ans_warm_start.py.test_rtkit_iop_power_silent.pygetspower-on-at-deadline.test_nvme_adoption.pyandtest_nvme_poisoned_io.pytake the new function into their extracted fragments.make format-checkwith clang-format 20.1.8: clean (touched files also clean under clang-format 23.1.5).Builds (clang,
RELEASE=1 CHAINLOADING=1), the same warnings as the base:ESP_STAGE2=0)NVME_TEST_RUNNING_FALLBACKESP_STAGE2=1)aura.bin/aura.macho/aura-boot.macho)