Skip to content

nvme: start a post-M4 ANS from off once, restart soon when the NVMe session needs a reboot - #266

Draft
IronsideXXVI wants to merge 4 commits into
aurora-silicon:mainfrom
IronsideXXVI:j604-p178-ans-retry
Draft

IronsideXXVI wants to merge 4 commits into
aurora-silicon:mainfrom
IronsideXXVI:j604-p178-ans-retry

Conversation

@IronsideXXVI

@IronsideXXVI IronsideXXVI commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

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-ans2 compatible. 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 on main 6affb8e. 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, on main 6affb8ec):

The branch is now 4 commits, in this order. The review thread has the reasons for each change since the first version.

  1. 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 (no warm, last_mask or hello_usec; the mask only applies to a warm start), and rtkit_boot_internal() keeps main's signature.
  2. tests: run the warm start test on the start chosen at power-on
  3. main: restart soon when the NVMe session needs a reboot
  4. nvme: log the controller's state right after a start from off

Every 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.py cuts out of src/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 onto main with 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):

  • In Stage 1: the start fails, Stage 1 cannot read Stage 2 and waits in the proxy; its boot watchdog (178 s) resets the Mac and the next boot is normal. 7 of 43 boots with Stage 1's host window on, 0 of 19 with it off. Each one costs about 3 minutes.
  • In Stage 2: Stage 2 also starts ANS from off (Stage 1 powers it off before the jump), and 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):

  1. 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's apple,t8132-nvme-ans2 entry does. (The hand-over to the payload's U-Boot this commit also added is removed again by nvme: 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.
  2. 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.
  3. main: restart soon when the NVMe session needs a reboot: with nvme_io_failed() set and no host, the boot watchdog restarts in 20 s instead of 178 s; a host that syncs still disarms it.
  4. 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's apple_wdt finds it running and keeps it fed.
  5. 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.
  6. 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.
  7. 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:

  • On the J604, these 7 commits ran as the ESP Stage 2 (on aura f0f180afe5 with our other J604 patches), 10 reboots in a row, Stage 1 unchanged (2026-11-15):
    • Stage 2 stopped 0 times (2 of 19 before); 0 "ANS start try" and 0 "power cycle" lines in Stage 2, so no retry was needed.
    • The boot held at the end stayed up 288 s with 0 resets: Linux took the re-armed watchdog over.
    • One of the 10 boots stalled 3 minutes in Stage 1, which does not have these commits yet (it is enrolled from Recovery).
    • 10 boots is evidence, not proof: with the old rates, 0 of 10 still happens by luck about 16 % of the time at 1 in 6 and 35 % at 1 in 10. We keep counting on every boot: 0 of 17 would rule out 1 in 6, 0 of 29 rules out 1 in 10, and 0 of 59 rules out 1 in 20.
    • Commit 6's state line was read on 7 of these boots (it was added between boots): the controller was never fatal at Stage 2's entry (CSTS 0x0), and after each start it read RUN=1, CSTS 0x0, BOOT_STATUS 0xde71ce55.
  • What these boots do not show: which commit removes the cause. The fatal status we saw before was already there at Stage 2's entry, left by Stage 1, which still runs without these commits, so the 0 here can be luck rather than commit 2. Commit 2 is a candidate for the controller faulting at all: before it, the SSD's root port ran with the settings meant for the card reader's port. The retry (commits 1, 5 and 7) is what makes a boot heal when the fault does come; a power cycle or cold start on hardware has not been seen yet in these 10 boots.
  • This branch is the same 7 commits rebased onto main (52af355c). The one conflict was in src/nvme.h, where main had added nvme_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 in src/. This rebased form has not run on hardware yet.

Questions for review:

  • main now 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?
  • Commits 1, 5 and 7 touch only the post-M4 start from off (5 and 7 only the T8132). Should they cover the other post-M4 chips?
  • Commit 4 leaves a running watchdog to the next stage on every chip. Wanted everywhere, or only where Stage 2 hands over to Linux?
  • Commit 2 changes the DBI window only on controllers with a gap in their ports. Are there other boards with such a gap?

Tested on the J604 only.

@RyanTheTide

Copy link
Copy Markdown
Contributor

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 (src/nvme.c:484-485 three tries with 3 s waits, :494-526, and the controller-ready power cycles at :798-803). We avoid retry/sleep loops where a handshake or status exists: here the HELLO and CSTS.CFS already tell us what state ANS is in. The cold PMGR reset is also chosen by chip_id == T8132 (:496), while the reason you cite is Linux's per-compatible apple,t8132-nvme-ans2 cold_reset.

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.

@RyanTheTide

Copy link
Copy Markdown
Contributor

One more point, separate from the ANS start: commit "main: arm the boot watchdog in an ESP Stage 2 too" (src/main.c, #if defined(CHAINLOADING) and the re-arm before Vectoring to next stage) now leaves a running 178 s watchdog to U-Boot and the OS on every chip. Anything that waits for a person before apple_wdt probes would be reset mid-wait: a U-Boot or GRUB menu, an initramfs passphrase prompt, or a kernel built with the driver as a late module. Could this be scoped to the case where the next stage is known to feed the watchdog? Or does U-Boot pet it until the kernel's driver takes over? A boot row through a held U-Boot prompt longer than 178 s would show it. The DBI-per-port fix looks right and universal; as a separate PR it can be tested on other controllers quickly, and we can run rows on a few machines.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. 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.
  2. 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 keys cold_reset on), not by chip_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.
  3. 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_not fails (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.
  4. 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.

@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

Thanks Ryan, and thanks for the summary DjDeveloperr. Sorry this sat since yesterday. I agree with all four points. What I'm doing:

  1. The DBI-per-root-port fix (1cc08a7) goes into its own PR on current main. I'll link it here when it's up.
  2. The ANS start gets reworked to read the state once (HELLO, CSTS.CFS, RUN) and act on it once. No fixed tries with 3 s waits and no ready-time power cycles. The cold PMGR-reset start will be selected by the ANS type, the same key Linux uses for cold_reset, not by chip_id. Before pushing it I'll compare it on the J604 against keeping ANS live across stages as nvme: T8132: keep NVMe across warm reboots on the M4 MacBook Air #305 does, and post the boot rows for both.
  3. The Stage 2 watchdog commit comes out of this PR. If it comes back, it will be scoped to a next stage known to feed it, with the test change in the same commit and a boot row through a held U-Boot prompt longer than 178 s.
  4. Rebase on main (the tests/python/test_nvme_adoption.py conflict) with the rework. Commits 3 and 6 stay with the ANS part.

I'm moving this to draft until the reworked ANS part is pushed.

@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

The DBI-per-root-port fix is now on its own in #405.

@IronsideXXVI

IronsideXXVI commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased on main 3efa4a8 so this is no longer in conflict. The Stage 2 watchdog commit (dfb1eff) is dropped as agreed. The test_nvme_adoption.py conflict was main's counting rtkit_boot_warm() stub next to the new rtkit_boot_wait() stub, and both are kept. The DBI commit is still here because the J604 runs used it; it drops out on the next rebase once #405 is in.

test_nvme_ans_restart.py also gets the T6040, T6041 and T8142 defines that main's nvme.c now uses, so it builds again. Nothing else has changed yet. The ANS start rework from my earlier comment (read HELLO and CSTS.CFS, RUN once, act once, cold start keyed by the ANS compatible, no retry loops) is still owed, and this stays a draft until it is in and has J604 numbers next to #305.

Locally on this head: gcc and clang builds, clang-format, tools/stage1_size.sh, tests/run-pmp-boot-data.sh and the workflow's pytest run pass.

@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

On 9293ee1 the Linux side of CI passes here (gcc and clang builds, clang-format, tools/stage1_size.sh with 16264 B headroom in stage1-dev-audit, tests/run-pmp-boot-data.sh, and the workflow's pytest run: 830 passed, 26 skipped), but the runs on the PR are waiting for workflow approval. Could someone approve them so the macOS Pytest jobs run too?

@RyanTheTide

Copy link
Copy Markdown
Contributor

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.

@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

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.

@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

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 cold_reset on (apple,t8132-nvme-ans2) instead of chip_id == T8132. The fixed tries and the ready-time power cycles are gone.

Locally the workflow commands pass on it (clang-format, gcc and clang builds, tools/stage1_size.sh with 16264 B headroom in stage1-dev-audit, tests/run-pmp-boot-data.sh, pytest 830 passed / 26 skipped). The J604 rows against keeping ANS live come next; the runs here need approval again.

@RyanTheTide

Copy link
Copy Markdown
Contributor

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: nvme_ans_cold_reset() (src/nvme.c, the snprintf(compatible, ..., "apple,t%x-nvme-ans2", chip_id) line) builds the compatible from the chip id, so it is still a chip check in practice. Could it read the ANS node's compatible from the ADT (or the payload tree) instead, so a future ANS of the same type is picked up without a new chip id?

We'll look at the J604 rows against keeping ANS live when they are up.

@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

Fair point, building the string from chip_id still makes it a chip check. I'll change nvme_ans_cold_reset() to take the compatible from the ANS node itself (the ADT /arm-io/ans node, or the payload tree's node if the ADT one doesn't name the type) and match the type on that, so a later chip with the same ANS needs no new entry. I'll push it together with the J604 rows and say so here.

@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

Pushed 794168f on top: nvme_ans_cold_reset() no longer touches chip_id. It reads the type from the ANS node: the ADT's /arm-io/ans if its compatible names one, else the ANS node of the payload's device tree (payload_fdt(), new, the tree load_fdt() picked for the machine), and matches that against the types Linux keys cold_reset on (apple,t8132-nvme-ans2 today).

What the J604's ADT node carries: /arm-io/ans has compatible = "iop,ascwrap-v6", role = "ANS2", device_type = "ans" and an empty nvme-secure-bar, and its child iop-ans-nub is iop-nub,rtbuddy-v2. iop,ascwrap-v6 is just the ASC wrapper: /arm-io/aop, /arm-io/dcp and the dcpext nodes have the same string. So on M4 the ADT doesn't name the ANS type, and today the match comes from the payload tree. Stage 2 has picked that tree from its appended DTBs before it starts ANS, so a J604 Stage 2 still gets the cold start. The ADT check is there so a node that does name its type gets picked up without a new entry. If neither node names a listed type, there's no cold start. The test covers both sources and checks that the chip id alone picks nothing.

Locally the workflow commands pass on it: clang-format, gcc and clang builds, tools/stage1_size.sh with 16264 B headroom in stage1-dev-audit, tests/run-pmp-boot-data.sh, pytest 830 passed / 26 skipped. I'll post the J604 rows comparing this with keeping ANS live as soon as the device run is done. The runs here need approval again.

@RyanTheTide

Copy link
Copy Markdown
Contributor

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 cold_reset on settles the selector point. The test case showing that the chip id alone picks nothing is a good addition.

That leaves the J604 rows against keeping ANS live, which we'll look at when they are up.

@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

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).

A (retry) B (794168f)
boots back on Linux 10/10 10/10
NVMe up 10/10 10/10
Stage 2 found ANS off and started it from off 10/10 10/10
retries / power cycles / CFS seen in Stage 2 0 / 0 / 0 0 / 0 / 0
devicetree found before the first ANS start 10/10 10/10
firmware time, mean 9.42 s 9.42 s
nvme0 up after kernel start 0.58-0.63 s 0.58-0.62 s
extra cold resets 0 1 (reboot 10 of 10)

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 nvme: no running ANS session to hand over. It hits a few percent of boots (2 of the last 40 test boots), and it hit once more tonight on A, two minutes after this run ended. One in 10 can't tell the two apart.

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 DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. nvme_hand_over_for_adoption() (src/nvme.c:1011) has no caller. nvme.h declares it and test_nvme_ans_restart.py covers it, but nothing in src/ 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.

  2. 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's pcie_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.

@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

Thanks. On 1: you're right, nothing on this branch calls nvme_hand_over_for_adoption(). The 10 + 10 rows ran on my packaged aura 1.0.0b13 builds (A: the retry build, B: 794168f applied to the same package), and the line I quoted comes from that build, not from this branch. I'll either add the call site here and say exactly which build the rows used, or drop the function and the description line.

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.

@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

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. 4274558e (new commit on top, no force-push) removes nvme_hand_over_for_adoption(), its declaration and its part of test_nvme_ans_restart.py. I also took the hand-over sentence out of the description.

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).

@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

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 83d28415 and force-pushed as 328a1fb9.

What the start from off keeps from #394:

  • nvme_ans_drain() runs after power-on (after the PMGR reset on the cold start) and before the SART entries and the run bit, on both the warm and the cold start.
  • rtkit_boot_warm() waits RTKIT_WARM_TIMEOUT_US (6 s) for the power report. The cold start keeps RTKIT_IOP_POWER_TIMEOUT.
  • main's step lines: couldn't power ANS on, couldn't restore the SART entries, no warm (or cold) handshake with the CPU status, BOOT_STATUS after the handshake. They come before the existing state line.

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 apple,t8132-nvme-ans2, and nothing is retried.

There's one new commit on top. test_nvme_ans_warm_start.py from #394 cut nvme.c from the drain on. It now takes the ANS start block from the cold-reset type list and stubs what that block calls. Its ANS node names no cold-reset type, so all six cases still run the warm start with the same expected lines. The first six commits also got the Assisted-by trailer they were missing; their content is unchanged apart from the rebase.

Local run on 328a1fb9 (Linux): clang-format clean, gcc and clang builds, stage1 size, PMP boot data, and the workflow pytest (832 passed, 26 skipped). Each commit on the branch builds with gcc.

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 328a1fb9. A stays the retry build. The counts follow with the stop location and Stage 2's console for any extra reset.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Re-review of 328a1fb: Blockers: 1.

Our earlier points:

  • Fixed tries with 3 s waits and the ready-time power cycles: resolved. nvme_ans_power_on() (src/nvme.c:666-690) reads RUN and CSTS.CFS once after power-on and acts once. The late CFS path (src/nvme.c:961) runs at most once, because nvme_ans_cold_started guards it.
  • Cold start chosen by chip_id: resolved. nvme_ans_cold_reset() (src/nvme.c:553-569) matches the ANS node's compatible from the ADT, or from the payload tree if the ADT doesn't name it.
  • Stage 2 watchdog left running into the next stage: resolved (the commit is dropped).
  • DBI split: done; pcie: set up each root port's DBI at its own device #405 is merged. This branch still has its own copy as 26e5eb1 (src/pcie.c, +15/-15), and the branch is 40 commits behind main. A rebase onto current main drops it.

New on this head:

  1. All 10 commits now end in an Assisted-by: LLM trailer (for example dce8acc and 328a1fb). Commits should carry only the human Signed-off-by. The disclosure belongs on the last line of the PR body, which currently ends in "Tested on the J604 only."
  2. The series still contains the code it later removes. Commits dce8acc (three tries plus the hand-over), 415cb9f (ready-time power cycles) and 51b67d2 add it, and d064127, ba9489c and 294ef20 take it out again. Their messages describe behaviour the final tree doesn't have, and a bisect can land on the retry loop or on the hand-over with no caller. Please squash those six into one commit that describes the read-once start. That leaves the restart commit (8f4e41b), the state-log commit (af8b5f9) and the test commit as they are.
  3. Nit: rtkit_boot_wait() (src/rtkit.c:867-871) is documented as "A retried start" and takes warm and hello_usec. Its only caller (src/nvme.c:624) passes false, BIT(0), USEC_PER_SEC. Either make it a cold-only helper or change the comment so it matches what it does now.

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 rtkit_init, drain order) changed too. Pass: "ANS started from off" on the warm path, NVMe up, 0 failed units, 0 new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

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 RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

The new head is up: dff2c1cb, 4 commits on main 6affb8ec. The six retry and hand-over commits are now one commit that describes the read-once start, with rtkit_boot_wait() made cold-only in it. The restart and state-log commits are unchanged, my DBI copy is gone, and the Assisted-by line is out of the commits and at the end of the PR body.

The test commit now comes second, right after the commit that moves the code the warm start test cuts out of nvme.c. Every commit builds on its own, and that one test file fails only at commit 1. The PR body has the tree check and the local run.

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.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks. Checked dff2c1c: four commits on 6affb8e, the retry and hand-over history is now one read-once commit, rtkit_boot_wait() is cold-only, your DBI copy is gone, and the commits carry only your Signed-off-by. We'll run the no-regression boot on our M4 Pro (J616s) on dff2c1c and post it here. Pass as before: "ANS started from off" on the warm path, NVMe up, 0 failed units and 0 new kernel errors against main.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

J616s (M4 Pro) row on dff2c1cb, as promised. I merged it onto current main cec4a105 (clean merge; local a5260662, Stage 2 label 1.0.0b15-ga5260662) and built an ESP Stage 2 (ESP_STAGE2=1 RELEASE=1 CHAINLOADING=1, clang). It ran as a one-shot trial: same installed Stage 1, same kernel 7.3.0-aurora-fleet81, the Mac's own DTB/U-Boot tail. Host tests on that tree (CI set): 1079 passed, 25 skipped.

production Stage 2 (b14) this PR's Stage 2
boot ok ok (44 s to ssh)
failed units / AVC / kernel err lines 0 / 0 / 0 0 / 0 / 0
NVMe (3 namespaces, root on nvme0n1) up, 0 NVMe/RTKit error lines up, 0 NVMe/RTKit error lines
s2idle (rtc wake, 15 s) 2/2 2/2
ANS lines in the Stage 2 log Found variable nvme.adopt, ANS buffers reserved same

One limit, so this isn't over-read: on this Mac the installed Stage 1 starts ANS, finds it already running (RUN=1, warm), and hands the live RTKit session to Stage 2. Stage 2 only adopts it (nvme.adopt). So no "ANS started from off" line appears, and nvme_ans_power_on()'s new start-from-off path does not run in an ESP Stage 2 trial here.

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 apple,t8132-nvme-ans2 cold start) that's the M4 Air.

Assisted-by: LLM (Claude:Opus 5.5)

@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

@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 (apple,t8132-nvme-ans2), so the start-from-off row will come from it on dff2c1c. With it I'll say whether the "ANS started from off" line appears, so it's clear which path ran.

@IronsideXXVI IronsideXXVI changed the title T8132: recover a failed ANS start from off, set up each PCIe root port's DBI at its own device, arm the watchdog in an ESP Stage 2 nvme: start a post-M4 ANS from off once, restart soon when the NVMe session needs a reboot Nov 24, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

@IronsideXXVI checking open drafts today. To come out of draft, this still needs:

  • Review changes requested by @DjDeveloperr are still open.
  • Then a test run at the final head on a Mac with the hardware it touches, and mark it ready for review.

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.

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.

3 participants