Repository navigation
nvme: start a post-M4 ANS from off once, restart soon when the NVMe session needs a reboot - #266
IronsideXXVI wants to merge 4 commits into
Conversation
|
Thanks for the careful J604 measurements; the stage-by-stage breakdown is very useful. Two parts don't fit how we usually handle this. The ANS start becomes a fixed retry loop ( Could the start read the state first and act on it once (a stopped or fatal ANS goes straight to the PMGR-reset cold start), selected by the ANS type rather than the chip? Keeping ANS live between stages, as #305 does for the J713, may also remove the cold start altogether; it would help to compare the two. The DBI-per-port and watchdog commits look independent and could go in on their own. The branch needs a rebase too. |
|
One more point, separate from the ANS start: commit "main: arm the boot watchdog in an ESP Stage 2 too" ( |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Thanks Dylan. The stage-by-stage J604 numbers and the CSTS/BOOT_STATUS reads are exactly what this needed. Ryan's two comments from 11-19 cover the structure, and I agree with both. There's one new item (3).
What would make it mergeable:
- Split out the DBI-per-root-port fix (commit 2,
src/pcie.c). It's universal and looks right, and on its own it can merge after a few no-regression rows on controllers without a gap. It may also be the real cause of the fatal status, since the SSD's port ran with the card reader port's settings. We'll check the other trees for port gaps on that PR. - The ANS start: read the state once (HELLO,
CSTS.CFS, RUN) and act on it once, instead of the fixed three tries with 3 s waits (src/nvme.c:484-526) and the ready-time power cycles (:798-803). Select the PMGR-reset cold start by the ANS type (the compatible Linux keyscold_reseton), not bychip_id == T8132(:496). Please also compare it with keeping ANS live across stages, as #305 does on the J713; that may remove the cold start altogether. - Commit 4 leaves a running 178 s watchdog to the next stage on every chip. Please scope it to a next stage known to feed it, or show it is fed through a U-Boot prompt held past 178 s. On this head
tests/python/test_wdt_boot_window.py::test_stage1_arms_it_after_disarming_iboot_and_stage2_does_notfails (the macos-15 job; the other Pytest jobs were cancelled after it), because that test pins the current policy. If the policy changes, the test changes in the same commit. - Rebase: the branch conflicts with main in
tests/python/test_nvme_adoption.py.
On your questions: the retry belongs in whichever path starts ANS from off, driven by the state it reads; other post-M4 chips should get it through the ANS-type key, not a chip list; and the watchdog should stay armed only where the next stage is known to pet it. Commits 3 (the 20 s restart on nvme_io_failed() with no host) and 6 (the state log) look fine and can go with the ANS part.
|
Thanks Ryan, and thanks for the summary DjDeveloperr. Sorry this sat since yesterday. I agree with all four points. What I'm doing:
I'm moving this to draft until the reworked ANS part is pushed. |
|
The DBI-per-root-port fix is now on its own in #405. |
|
Rebased on main 3efa4a8 so this is no longer in conflict. The Stage 2 watchdog commit (dfb1eff) is dropped as agreed. The
Locally on this head: gcc and clang builds, clang-format, |
046660c to
9293ee1
Compare
|
On 9293ee1 the Linux side of CI passes here (gcc and clang builds, clang-format, |
|
Thanks for the rebase, for dropping the Stage 2 watchdog commit, and for splitting the DBI fix into #405. #405 looks right to us: each port's DBI comes from its port number, and controllers without a gap come out unchanged by construction. We will post the no-regression boot rows we offered for gap-free controllers there, on our M1 Pro, M2, M4 Pro and A18 Pro, instead of here. We will look at the ANS start again once the read-once rework, keyed on the ANS compatible, is pushed, along with the J604 rows comparing it with keeping ANS live across stages. |
|
Thanks. Agreed on moving the gap-free rows to #405. I'll push the read-once rework keyed on the ANS compatible together with the J604 rows comparing it with keeping ANS live across stages, and ping you here when both are up. |
|
Pushed 9bc9f8b, the read-once rework: with ANS powered and before the firmware runs, the start from off reads RUN and CSTS.CFS once and acts once (a stopped, fatal ANS goes straight to the cold start after a PMGR reset, anything else gets the warm start; no HELLO, or CSTS.CFS when the controller doesn't come ready, gets the cold start once), and the cold start is picked by the ANS type Linux keys Locally the workflow commands pass on it (clang-format, gcc and clang builds, |
|
Thanks for 9bc9f8b. Reading RUN and CSTS.CFS once at power-on and acting once, with the fixed tries and the ready-time power cycles gone, is the shape we hoped for. One small point on the selector: We'll look at the J604 rows against keeping ANS live when they are up. |
|
Fair point, building the string from |
|
Pushed 794168f on top: What the J604's ADT node carries: Locally the workflow commands pass on it: clang-format, gcc and clang builds, |
|
Thanks for 794168f. Taking the type from the ANS node (the ADT's when it names one, else the payload tree's) and matching it against the compatibles Linux keys That leaves the J604 rows against keeping ANS live, which we'll look at when they are up. |
|
J604 rows for 794168f (M4 14", Linux 7.3.0, same kernel on both sides, 10 warm reboots each, back to back tonight). A = the boot stages I run today (the retry + power-cycle ANS start). B = this PR at 794168f (read RUN and CSTS.CFS once at power-on, act once).
The extra reset. On B's 10th reboot the Mac reset twice instead of once. From the USB host it is attached to: Stage 1 handed over, then Stage 2 came up as its USB proxy device (what it falls back to when it has no payload to boot) instead of going on to Linux. It sat there for 30 s until the host restarted it, and the boot after that was normal (NVMe up at 0.58 s). So the stop was in Stage 2, before Linux. I could not read Stage 2's console ring for that boot, so I don't know which line it stopped on, and in particular not whether it was the ANS start. What this shows. Same NVMe bring-up and the same firmware time on both sides. On all 20 boots both versions took the same path: Stage 2 found ANS off and started it from off. There was never a live session to hand over, and A never needed a retry or a power cycle, so on these boots the read-once code and the retry code did the same thing. What it doesn't show. Whether the one extra reset belongs to this PR. This Mac has a known stop of the same shape on the build I run without this PR: Stage 2 ends up in its proxy with no payload, the console ring ending in Next. A longer run, 30 boots each side, tonight or tomorrow, set up so that any extra reset comes with the place it stopped and Stage 2's console. I'll post those rows here. I'm not calling this a pass yet. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Thanks Dylan. 794168f answers most of our 11-20 review:
- The DBI fix is out on its own in #405.
- The start from off reads RUN and CSTS.CFS once and acts once, and the fixed tries and the ready-time power cycles are gone.
- The cold start is picked by the ANS node's compatible, and the test shows the chip id alone picks nothing.
- The Stage 2 watchdog commit is dropped, and the branch is rebased.
I've approved the six workflow runs on 794168f.
Two things on this head:
-
nvme_hand_over_for_adoption()(src/nvme.c:1011) has no caller.nvme.hdeclares it andtest_nvme_ans_restart.pycovers it, but nothing insrc/calls it, on this head or on any earlier commit of the branch. So the hand-over to the payload's U-Boot that the description lists doesn't happen in this build. Your A/B note quotes its "no running ANS session to hand over" line from the build you run, so that build has a call site this branch lacks. Please either add the call site and say which build the 10 + 10 rows used, or drop the function and the description line. -
Main has moved since your rebase. #410 and #412 (in 1.0.0b14) take T8132 out of
nvme_post_m4_keeps_live(), so every stage now powers a T8132 ANS off at the handoff. The reason is that a next aura stage'spcie_init()faults on a live ANS (the J713 console on #406). That makes the "keep ANS live across stages" comparison we asked for moot for stage-to-stage handoffs. The start from off in this PR is now the path every T8132 Stage 2 takes, and your A/B against the retry build is the right comparison. The branch still merges cleanly, and the PR's CI builds the merge with main, so it covers the combination.
Still open, as you said: the 30 boots per side, with the stop location and Stage 2's console for any extra reset. The DBI commit drops out on rebase once #405 is in. Commits 3 and 6 still look fine.
|
Thanks. On 1: you're right, nothing on this branch calls On 2: understood. With #410/#412 the start from off is what every T8132 Stage 2 does, so the 30 + 30 A/B against the retry build is next, with the stop location and Stage 2's console for any extra reset. |
|
On 1, I went with dropping it. Main now powers a T8132 ANS off at every handoff, so handing a running session to the payload isn't a path aura should take. On 2, I haven't rebased, since the branch still merges cleanly and CI builds the merge with main. For the 30 + 30 run, B gets rebuilt from 4274558 without the payload fallback my package carried, on the same base as A. I'll post the counts with the stop location and Stage 2's console for any extra reset. Local run on 4274558 (Linux, merge base 3efa4a8): clang-format clean, gcc and clang builds, stage1 size, PMP boot data, and the workflow pytest (830 passed, 26 skipped). |
4274558 to
328a1fb
Compare
|
Main moved under this one: #394 (stale ANS messages dropped before the run bit, 6 s for the IOP power report, one line per failed step) touches the same start from off, so the branch stopped merging. Rebased onto What the start from off keeps from #394:
The choice itself is unchanged. RUN and CSTS.CFS are read once at power-on, the cold start only happens on an ANS node that names There's one new commit on top. Local run on For the 30 + 30, B is now this head. The 4274558 build has neither the drain nor the 6 s wait, so I'm rebuilding B from |
|
Re-review of 328a1fb: Blockers: 1. Our earlier points:
New on this head:
HW row: the planned J604 30 + 30 on this exact head against the retry build. Pass: no Stage 2 stops on B, and any extra reset reported with its stop location and Stage 2's console. Also one no-regression boot on a post-M4 Mac whose ANS node names no cold-reset type (for example M4 Pro or A18 Pro), because the warm start path (lazy Assisted-by: LLM (Claude:Opus 5.5) |
|
Thanks, all of it taken:
HW: the squash changes the head, so the J604 30 + 30 runs on the new head against the retry build rather than on 328a1fb. I'll post the row with the stop location and Stage 2's console for any extra reset. I don't have a post-M4 Mac whose ANS node names no cold-reset type. Once the new head is up, could someone with an M4 Pro take the one no-regression boot? |
RyanTheTide
left a comment
There was a problem hiding this comment.
Thanks. That covers every point. We can take the no-regression boot on our M4 Pro MacBook Pro (J616s) once the squashed and rebased head is up; leave a note here when it's pushed. Pass: "ANS started from off" on the warm path, NVMe up, 0 failed units and 0 new kernel errors against current main.
Assisted-by: LLM (Claude:Opus 5.5)
A J604 (T8132) Stage 2 that Stage 1 handed a powered-off ANS found the controller fatal after a warm reboot, with its CPU stopped (entry RUN=0 BOOT_STATUS=0x0 CC=0x470000 CSTS=0x2). The warm start got no HELLO and left ANS down, so the inline payload had no disk and the boot stopped in the proxy until a power cycle. Another J604 Stage 2 got the firmware up (BOOT_STATUS 0xde71ce55), and then the controller never came ready, with CC.EN clear and CSTS.CFS set. Linux's apple,t8132-nvme-ans2 entry (cold_reset) resets a stopped ANS through PMGR and boots it cold. nvme_ans_power_on() now reads RUN and CSTS.CFS once, with the block powered and before the firmware runs, and makes one start from that. A stopped ANS with a fatal controller, of a type that takes a cold reset, gets the cold start: ANS reset through PMGR, then the firmware booted cold. Anything else gets the warm start every good boot took, with its 1 s HELLO wait, unchanged. The same state seen later is acted on once, on such a type only: a warm start that fails (no handshake, or no BOOT_STATUS OK after it), or CSTS.CFS when the controller fails to come ready after a warm start from off, undoes that start (CPU stopped, its mail dropped, ANS powered off) and makes the cold start. Nothing else is retried, and a running session is never handed to the payload. Each of these steps logs RUN, CC, CSTS and BOOT_STATUS. The type is read from the ANS node, never from the chip, and matched against the compatibles Linux's apple-nvme driver keys cold_reset on. The ADT's /arm-io/ans does not name the type today: on the J604 it carries "iop,ascwrap-v6", the ASC wrapper AOP and DCP also use. So the type comes from the payload's device tree, which Stage 2 has picked for the machine before it starts ANS (payload_fdt(), new). A stage with neither node naming such a type keeps the warm start only. rtkit_boot_wait() is that cold start: rtkit_boot() with the IOP's receive side turned on, since an idle may have left it off, and the power states waited for a bounded time. test_nvme_ans_restart.py runs nvme_ans_power_on() and the ready-time path through these cases. test_nvme_adoption.py names the type in the payload's tree, as on the J604. Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
test_nvme_ans_warm_start.py cut src/nvme.c from nvme_ans_drain() on. With the start from off chosen at power-on, the drain sits inside the ANS start block, so the test now takes that block from the cold-reset type list on and stubs what it calls. Its ANS node names no cold-reset type, so every case still runs the warm start the test checks, with the same expected lines. Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
A Stage 1 that cannot read its Stage 2 because its NVMe session failed (nvme_io_failed()) cannot recover without a reboot, yet it waits the whole 178 s boot watchdog period for a host. Restart the boot watchdog's count with 20 s instead. It stays the boot watchdog, so a host that syncs in time still disarms it. Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
A J604 Stage 2 parked after a start of ANS from off with CSTS reading the controller fatal status (0x2) and CC.EN clear, read after the failure, with BOOT_STATUS ok. Whether the fatal status was already there before this stage wrote anything to the controller, or came with the enable, decides where the fault is. Log RUN, CC, CSTS and BOOT_STATUS once the firmware reports booted, before any write to CC. Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
328a1fb to
dff2c1c
Compare
|
The new head is up: The test commit now comes second, right after the commit that moves the code the warm start test cuts out of Thanks for taking the M4 Pro boot. Next the J604 runs 30 + 30 on this head against the retry build, and I'll post that row here. |
|
Thanks. Checked dff2c1c: four commits on 6affb8e, the retry and hand-over history is now one read-once commit, Assisted-by: LLM (Claude:Opus 5.5) |
|
J616s (M4 Pro) row on
One limit, so this isn't over-read: on this Mac the installed Stage 1 starts ANS, finds it already running ( What this row shows: the merged Stage 2 does not regress the adopt path on T6040. What it doesn't show: the path the PR changes. That needs a Stage 1 built from this branch, or a boot where Stage 2 itself starts ANS from off. On T8132 (the Assisted-by: LLM (Claude:Opus 5.5) |
|
@RyanTheTide thanks for the J616s row, and for spelling out its limit. Since Stage 1 hands over a warm ANS there, it covers the adopt path and not the start-from-off one. The J604 is T8132 ( |
|
@IronsideXXVI checking open drafts today. To come out of draft, this still needs:
If it's no longer needed, say so here and we'll close it. Otherwise it stays open as a draft until these are done. |
What: On post-M4 chips, start an ANS (SSD controller) that an earlier stage powered off exactly once, choosing warm or cold from RUN and CSTS.CFS read at power-on. The cold start is chosen by the
apple,t8132-nvme-ans2compatible. There is no retry loop and no hand-over. When the NVMe session needs a reboot and no host is attached, the boot watchdog restarts in 20 s instead of 178 s. The controller state is logged right after a start from off. Four commits onmain6affb8e. The DBI split merged separately in #405.Tested: No hardware run on this head (dff2c1c) yet. Local Linux run: clang-format and rustfmt are clean, gcc Stage 1 and ESP Stage 2 build at each of the 4 commits with the same 50 warnings as main, and stage1 size and PMP boot data pass. Workflow pytest gives 838 passed / 26 skipped (gcc) and 837 / 27 (clang) from commit 2 on. Earlier, the first 7-commit version ran on the J604 (M4 MacBook Pro 14") as ESP Stage 2 for 10 reboots in a row: Stage 2 stopped 0 times (2 of 19 before), and the last boot stayed up 288 s with 0 resets.
Risk: two-way · post-M4 Macs that start ANS from off (the cold start is T8132 only). The shorter watchdog restart applies on every chip with
nvme_io_failed()and no host.Not yet: The 30 + 30 J604 A/B on this head, to follow in the thread. 10 boots is evidence, not proof: 0 of 29 would rule out the old 1 in 10 rate. No other post-M4 Mac has run this.
Full description
Current state (head
dff2c1cbce, onmain6affb8ec):The branch is now 4 commits, in this order. The review thread has the reasons for each change since the first version.
nvme: start a post-M4 ANS from off once, from the state read at power-on: the six retry and hand-over commits of the last version (dce8acc, 415cb9f, 51b67d2, d064127, ba9489c, 294ef20) as one commit that describes what the code does:nvme_ans_power_on()reads RUN and CSTS.CFS once after power-on and makes one start from them, the cold start is picked by the ANS node's compatible (apple,t8132-nvme-ans2), and there is no retry loop and no hand-over.rtkit_boot_wait()is now cold-only (nowarm,last_maskorhello_usec; the mask only applies to a warm start), andrtkit_boot_internal()keepsmain's signature.tests: run the warm start test on the start chosen at power-onmain: restart soon when the NVMe session needs a rebootnvme: log the controller's state right after a start from offEvery commit builds on its own. The test commit comes right after commit 1 because commit 1 moves the code that
test_nvme_ans_warm_start.pycuts out ofsrc/nvme.c, so that one test file (6 cases) fails at commit 1 only and passes from commit 2 on.My copy of the DBI split (26e5eb1) is gone: #405 merged the same change (same patch-id). Before the
rtkit_boot_wait()change, the reordered branch had the same tree as the old branch rebased ontomainwith 26e5eb1 dropped (2405d580b8); that change is the only difference after it (ffcd3b9782). The Stage 2 watchdog commit stays dropped. The start from off includes #394: the stale-message drain before the run bit (on both the warm and the cold start), the 6 s wait for the IOP power report, and its line per failed step.Local run on
dff2c1cbce(Linux): clang-format and rustfmt clean; gcc Stage 1 and ESP Stage 2 build at each of the 4 commits with the same 50 warnings as main; stage1 size and PMP boot data pass; workflow pytest 838 passed / 26 skipped (gcc) and 837 / 27 (clang) from commit 2 on. Nothing of this head has run on hardware yet. The J604 rows below were taken on the first 7-commit version; the 30 + 30 A/B on this head follows in the thread.First description (7 commits, 2026-11-15), kept for the rows:
On the MacBook Pro 14" M4 (J604, T8132), a start of the SSD controller (ANS) from off sometimes ends without a usable controller: on our boots, about 1 in 6 to 1 in 10, depending on the stage. What happens next depends on the stage.
Where it shows up (measured, 2026-11-14 and 2026-11-15):
wdt_disable()leaves no watchdog. When that start failed, the Mac parked in Stage 2's proxy until a host reset it: 2 of 19 boots with the window off. Read from a parked Stage 2: BOOT_STATUS 0xde71ce55 (firmware up), CC 0x470000 (EN clear), CSTS 0x2: the start succeeded, then the controller reported its fatal status and never came ready. An earlier Stage 2 logged the same fatal status at its entry, before it wrote anything (RUN=0, CSTS 0x2): it was left by Stage 1, and it appears to survive a power cycle of ANS's PCIe block and a warm firmware start.This change (7 commits):
nvme: retry the post-M4 ANS start from off, and hand a running one over: a failed try is undone completely and ANS is started again, up to three tries; on the T8132 the last one resets ANS through PMGR and boots it cold, as Linux'sapple,t8132-nvme-ans2entry does. (The hand-over to the payload's U-Boot this commit also added is removed again bynvme: drop the unused ANS hand-over for adoption: nothing calls it, and main now powers a T8132 ANS off at every handoff.) The first try is today's start, unchanged.pcie: set up each root port's DBI at its own device: the port loop moved the DBI window on only for ports it set up, so on a controller with a gap (the J604 has bridges 0 and 2, no 1) port 2's tunables, speed cap and width went to device 1, and port 2 kept its reset defaults (Linux read 16 GT/s where the ADT has 5 GT/s). Controllers with no gap are unchanged.main: restart soon when the NVMe session needs a reboot: withnvme_io_failed()set and no host, the boot watchdog restarts in 20 s instead of 178 s; a host that syncs still disarms it.main: arm the boot watchdog in an ESP Stage 2 too: an ESP Stage 2 arms it as Stage 1 does and re-arms it for the full period right before the next stage. Linux'sapple_wdtfinds it running and keeps it fed.nvme: power-cycle a T8132 ANS whose controller fails to come ready: up to two power cycles, with a log line each, as aura does for T6050.nvme: log the controller's state right after a start from off: RUN, CC, CSTS and BOOT_STATUS once the firmware reports booted, before any write to CC.nvme: start a T8132 ANS cold when its controller reports a fatal status: with CSTS.CFS set, skip the warm power cycle (which meets the same status) and go straight to the PMGR-reset cold start of commit 1.Testing:
f0f180afe5with our other J604 patches), 10 reboots in a row, Stage 1 unchanged (2026-11-15):main(52af355c). The one conflict was insrc/nvme.h, wheremainhad addednvme_cold_handoff(); both declarations are kept. Stage 1 (RELEASE=1 CHAINLOADING=1 USE_CLANG=1) and ESP Stage 2 (... ESP_STAGE2=1) build with no warnings insrc/. This rebased form has not run on hardware yet.Questions for review:
mainnow starts a post-M4 ANS that an earlier stage powered off before any payload, and hands ANS over quiesced. Do you want commit 1's retry inside that path, or kept where it is?Tested on the J604 only.