Skip to content

nvme: T8132: keep NVMe across warm reboots on the M4 MacBook Air - #305

Merged
DjDeveloperr merged 2 commits into
mainfrom
j713/ans-live-handoff
Nov 20, 2026
Merged

DjDeveloperr merged 2 commits into
mainfrom
j713/ans-live-handoff

Conversation

@erikwb

@erikwb erikwb commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

On an M4 MacBook Air (J713, T8132), a warm reboot sometimes leaves Stage 2 without NVMe. The Mac stops in Aura and only a forced restart brings it back. Stage 1 powers ANS off after loading Stage 2, and Stage 2's cold start of ANS intermittently doesn't come up. This is the same failure #275 fixes on T6040/T6041.

Stacked on #275. The first commit is #275 rebased onto main, authorship kept. Its only conflict was the adopt condition, which main now spells nvme_ans_storage_gated(). It resolves as nvme_ans_storage_gated() || nvme_post_m4_keeps_live(), so T6050 and T8142 are unchanged. Please review the last commit here. If #275 merges first, this rebases down to that one commit.

The last commit adds T8132 to nvme_post_m4_keeps_live(). Stage 1 hands its ANS session on running, with only the I/O queue registers cleared, and Stage 2 adopts it. It also keeps the live branch out of the way when a stage asks for a quiesced ANS (nvme_quiesce_for_next), so that path behaves as on main for every chip that hands on live. The T8132 expectation in tests/python/test_nvme_adoption.py changes to match: a live handoff keeps its queues.

Tested on a J713 (Mac16,12), with Stage 1 (enrolled from 1TR) and Stage 2 built from this change on the aura package pin (5dcf62d). Every boot logs nvme: handing the live ANS session on in Stage 1 and nvme: adopting the live post-M4 ANS session in Stage 2, with no cold start. Linux takes the controller over as before, and nvme0n1 and all partitions are present. Nine consecutive warm reboots came up the same way. The nvme_quiesce_for_next gate was added after that run; it doesn't change the J713 boot path. Local builds pass for clang Stage 1 and Stage 2, the SPTM_VIRT ESP variant, and gcc cross Stage 1 and Stage 2. pytest tests/python passes except test_loadobjs, which fails on main too in this environment.

This change was developed and tested by Claude (Anthropic), working with me on the J713.

🤖 Generated with Claude Code

@erikwb

erikwb commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

@RyanTheTide @DjDeveloperr FYI m4's installed from the current installer crash sometimes on wakeup/soft reboot without this

@RyanTheTide

Copy link
Copy Markdown
Contributor

Review note on nvme_post_m4_keeps_live(): with T8132 added, T6040, T6041 and T8132 hand on live here, and T6050 and T8142 do through nvme_ans_storage_gated(). That covers every post-M4 ANS except T8140 and T8152, so the chip list is close to nvme_post_m4() (the ADT's nvme-secure-reg-layout). Two options:

  • If a T8140 or T8152 session survives the same live handoff and adoption, the condition could be nvme_post_m4(). A new M4-or-later SoC then gets the handoff without another entry.
  • If they need the power-off path, a comment saying what differs on them (a measured failure, or a different ANS revision) would record why the list stops there.

This also fixes #267 (J614c, 8 TB, RUN=0 cold start with no HELLO). The reporter's 3/3 cycles and the installed boot are in #275.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for the 9-reboot run. Two small things besides the chip-list question already on this PR:

  1. The rebased first commit (79c5d71, from nvme: T6040/T6041: hand the ANS session on fully live and adopt it #275) has no Signed-off-by. Could it get its author's DCO line, or yours with a note, when you next push?
  2. Since this carries nvme: T6040/T6041: hand the ANS session on fully live and adopt it #275 rebased, it would help to say which one should land. Either nvme: T6040/T6041: hand the ANS session on fully live and adopt it #275 closes in favour of this, or this drops to the T8132 commit after nvme: T6040/T6041: hand the ANS session on fully live and adopt it #275 merges, so the two don't race. If the condition becomes nvme_post_m4(), we can add a warm-reboot row on an M4 Pro (T6040), and on an A18 Pro (T8140) as a check of the chips not yet covered.

hci-kitten and others added 2 commits November 19, 2026 10:36
On J614c (T6041) the ANS firmware answers neither an RTKit power
transition (rtkit_quiesce times out with "IOP power transition timed
out") nor a start after power-off (no HELLO, ASC CPU running, pmgr
domains on), so every handoff since adf5580 leaves Stage 2 without NVMe.

A session left running with the controller enabled is adopted by the
next nvme_init(), as T6050 already does: hand it on with RTKit untouched
and only the I/O queue registers cleared, and let T6040/T6041 take the
T6050 adopt path.

Tested on J614c from the proxy, read-only: init from the iBoot session,
read LBA 0, hand on, adopt, read again, 3/3 cycles with identical data;
and a Stage 2 built with this change, chainloaded raw, booted through to
the installed system.

[erikwb: rebased onto main; the adopt condition, which main now spells
 nvme_ans_storage_gated(), resolves as nvme_ans_storage_gated() ||
 nvme_post_m4_keeps_live(), so T6050 and T8142 are unchanged]
Signed-off-by: Erik Bourget <erik@ebourget.net>
On the M4 MacBook Air (J713, T8132), Stage 1 powers ANS off after
loading Stage 2 and Stage 2 starts it again from off. After a warm
reboot that cold start intermittently gets nowhere, and Stage 2 is
left without NVMe until a forced restart.

Give T8132 the T6040/T6041 handling: Stage 1 hands its ANS session on
running, with only the I/O queue registers cleared, and Stage 2 adopts
it instead of starting ANS from off. A stage that asks for a quiesced
ANS (nvme_quiesce_for_next) still gets one, on every chip that hands
on live.

Tested on a J713 with Stage 1 and Stage 2 built from this change on
1.0.0b13.1: every boot logs "handing the live ANS session on" in
Stage 1 and "adopting the live post-M4 ANS session" in Stage 2, with no
cold start. Linux takes the controller over as before, nvme0n1 and all
partitions are present, and nine consecutive warm reboots came up the
same way.

Signed-off-by: Erik Bourget <erik@ebourget.net>
@erikwb
erikwb force-pushed the j713/ans-live-handoff branch from 2b21d67 to 4935120 Compare November 19, 2026 15:48
@erikwb

erikwb commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. Pushed: the rebased #275 commit now has a rebase note and my Signed-off-by, and the branch is on current main (format-check was failing on main's own s2r file). Let's land this one; #275 can close once it merges, as you suggested there. On the chip list, I kept it and added a comment on why it stops: T8152 keeps its quiesce path because its Linux driver neither adopts a live session nor restarts a stopped ANS, and T8140 keeps the power-off path, which works there, while live adoption by the next stage is untested. If your A18 Pro row shows T8140 survives a live handoff and adoption, I'll add it. An M4 Pro (T6040) warm-reboot row would also help, since only T6041 and T8132 have been run.

@techmore

Copy link
Copy Markdown
Contributor

A data point from a J773g for the warm-reboot NVMe failure this PR addresses: Stage 1's own log of it (the ANS firmware asserts during Stage 1's idle), and where in the code it comes from.

Written by an AI agent from the owner's captures; the owner ran the hardware steps.

Machine

What happens

On some warm reboots the ANS firmware crashes while Stage 1 idles it before the chainload. Stage 1 stops it, powers it off and hands Stage 2 the SART entries as usual. Stage 2 gets no HELLO and parks in the proxy. A reset of the SoC recovers it.

Stage 1, firmware assert (6 captures; N was 3, 8, 8, 8, 21 and 24):

[  3.972928] chainload: image staged at 0x1000e114000 runs its first 0x3d0000 bytes at 0x10003ac0000
[  4.061444] rtkit(nvme): IOP crashed!
[  4.062548] rtkit(nvme): == CRASH INFO ==
[  4.064475] rtkit(nvme):   Message 1: assert failed: [5624]: 3 open cmds - shutdown 0
...
[  4.141207] rtkit(nvme): IOP died during shutdown
[  4.143141] nvme: ANS didn't acknowledge idle, stopping it anyway
[  4.145013] pcie: Initializing t8132 PCIe controller
[  4.248759] nvme: ANS powered off, 9 SART entries kept

The crash is reported 12 to 137 ms after image staged.

Stage 2 after it (all 6, and one more failure whose Stage 1 log was not captured):

nvme: entry RUN=0 BOOT_STATUS=0x0 saved SART entries=9
nvme: entry CC=0x470000 CSTS=0x2 AQA=0x3f003f IOSQ=0x0 IOCQ=0x0 IOQA=0x3f003f
rtkit(nvme): did not receive HELLO
nvme: start failed: RUN=1 CC=0x470000 CSTS=0x2 BOOT_STATUS=0x0
nvme: ANS start try 2 of 3
rtkit(nvme): did not receive HELLO
nvme: ANS start try 3 of 3, cold after a reset
rtkit(nvme): did not receive HELLO
nvme: ANS didn't start from off; it stays down until a reboot

Stage 1, timeout variant (1 capture, after echo b > /proc/sysrq-trigger):

[  4.875973] chainload: image staged at 0x1000e368000 runs its first 0x3d0000 bytes at 0x10003d14000
[  9.878741] rtkit(nvme): IOP power transition timed out
[  9.880687] nvme: ANS didn't acknowledge idle, stopping it anyway
[  9.882561] pcie: Initializing t8132 PCIe controller
[  9.986283] nvme: ANS powered off, 9 SART entries kept

Stage 2 after it: entry RUN=0 BOOT_STATUS=0xde71ce55, CC=0x470000 CSTS=0x0, no HELLO on all three tries.

Numbers

Warm reboots only, one machine. "Plain" means Stage 1 wrote nothing to NVMe. "Trial" means a boot through aura-try: Stage 1 spends the marker (a write and a flush), so nvme_wrote is set and it sends the NVMe normal shutdown before the idle.

Boots How Linux was left Stage 1 Failed
74 (three loops: 45, 19, 10) systemctl reboot or reboot -f plain 3, all the assert
16 sysrq reset plain 1, the timeout
16 alternating systemctl reboot and sysrq reset trial 0
  • Outside the loops: 4 more assert failures, each on a plain reboot that followed a test boot. Plain boots there were not all counted.
  • Outside the loops: 57 more Stage 1 logs of trial boots. None has either failure. In total 73 trial boots, 0 failures.
  • Stage 2's entry reads CC=0x474000 on every trial boot and CC=0x470000 on every plain one. No capture shows a failed start after CC=0x474000.
  • image staged to pcie: Initializing (disable, idle and, on trial boots, the shutdown):
Before the boot Plain Trial
clean reboot 326 to 931 ms (62 boots) 312 to 943 ms (8)
sysrq reset 1201 to 4079 ms (15), and the 5 s timeout 678 to 1016 ms (8)

This supports the missing shutdown as the cause. It does not prove it:

  • At 3 in 74, 16 clean boots in a row happen by chance about half the time. The 73 would happen about 1 time in 20, if the rate were uniform. It may not be: the failures outside the loops cluster after test boots.
  • Trial boots also differ by a write and a flush before the shutdown. We can't separate the two.
  • shutdown 0 in the assert reads as "no shutdown was requested". That is our reading of the text.

Where

Lines on main.

  • src/chainload.c:494: nvme_shutdown() on the chainload path.
  • src/nvme.c:943-947: on a post-M4 ANS it calls nvme_ans_power_off().
  • src/nvme.c:473: if ((nvme_wrote || chip_id == T8142) && !nvme_ctrl_shutdown()). On T8132 a stage that only read skips the shutdown and goes to the disable and the idle. (b13.1 has nvme_wrote alone, src/nvme.c:455.)
  • src/nvme.c:479-482: an unacknowledged idle prints the message and stops the CPU.
  • src/nvme.c:487-488: the function still reports ANS powered off and returns true, so the next stage starts it warm.
  • src/rtkit.c:952 and :963: the two rtkit_idle() failures above.

Proposed fix (untested)

Send the NVMe normal shutdown before the idle on the chainload path whether or not the stage wrote, as line 473 already does for T8142. Separately, an unacknowledged idle should not be handed on as "off, start warm".

We have not run this. Stage 1 on this unit can only be replaced from Recovery with someone at the machine.

This PR would take T8132 off this path by handing ANS on live. This report may still matter for T8140 and for any stage that powers ANS off. #266 saw the same CSTS 0x2 at Stage 2's entry on the J604; its retries ran on every failure here and recovered none.

What we can provide

@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. Ryan's points are settled. The rebased #275 commit has its note and your sign-off, and the comment above nvme_post_m4_keeps_live() (src/nvme.c:455-462) says why T8152 and T8140 stay off the list. That's the reason Ryan asked for, so the list is fine as it stands.

I read the live hand-on in nvme_shutdown(). It runs only when no later stage asked for a quiesced ANS (nvme_quiesce_for_next), it clears only the I/O queue registers, and the next nvme_init() adopts a session only if it reads BOOT_STATUS OK with no fatal status. techmore's J773g captures point the same way: every failure there is on the power-off path that this takes T8132 off.

CI is green on 4935120, and main hasn't touched src/nvme.c or the test since your base. Approving and merging. #275 can close once this is in, as you and Ryan agreed.

One note on the rows: main currently resets every T8132 at boot (#320's MCC check; the fix is #392). So a J713 or J773g warm-reboot row on main's Stage 2 has to wait for #392, and a failure before then isn't caused by this PR. After the merge, with a revert ready:

  • the J713 warm-reboot loop on main plus #392;
  • Ryan's M4 Pro (T6040) warm-reboot row, since only T6041 and T8132 have run, plus the A18 Pro check if T8140 should join the list.

@DjDeveloperr
DjDeveloperr merged commit a5ffc4d into main Nov 20, 2026
16 checks passed
@DjDeveloperr

Copy link
Copy Markdown
Contributor

Merged as a5ffc4d (CI green on 4935120, no base drift). Post-merge verification as in my review: the J713 warm-reboot loop on main plus #392 (main resets every T8132 at boot until #392 lands, so a failure before then isn't this PR), and Ryan's M4 Pro warm-reboot row. A revert is ready if it doesn't hold. #275 can close now, as agreed.

DjDeveloperr added a commit that referenced this pull request Nov 20, 2026
The J713 console on aura#406 shows why the b14 candidate's chainload
reset the Mac. The Stage 2 ran normally, then crashed in its own PCIe
init. It had received nvme.sart= ("ANS is off") while ANS was still
live, so it called pcie_ans_power_on(), which on T8132 is a full
pcie_init(), and took a synchronous external abort. nvme_sart_entries()
reports any T8132 session as off, but nvme_shutdown() had handed that
session on live (T8132 is in nvme_post_m4_keeps_live(), since #305).

Ryan's one-boot probes settle the rest. Reporting the session as live
lets the Stage 2 adopt it, but then kboot's own T8132 pcie_init() (the
radio port) faults the same way. So on T8132 a live handoff to another
aura stage fails in the receiver whatever this stage reports. Dropping
T8132 from nvme_post_m4_keeps_live() (power off, pass nvme.sart=, as
every 1.0.0b13 stage does) passes into the configured Stage 2: root on
NVMe, 0 failed units, PMU counter 0.

The origin rule of the previous commit does not cover this: an
iBoot-loaded Stage 1 receives iBoot's live session and would still hand
it on live. So T8132 leaves nvme_post_m4_keeps_live(), on both sides: a
stage powers it off at the handoff, and a later stage doesn't adopt a
live T8132 session but stops it and starts it from off.

nvme_sart_entries() now also returns nothing for a session that
nvme_shutdown() handed on live, on any chip, so stale entries from an
earlier power-off never reach the next stage beside a live ANS.
T6040/T6041 keep their live handoff (the J616s row passed).

tests: the harness first, then the code. 23 and 26 (a T8132 iBoot
session) now power off and free the queues. 34 (a T8132 session handed
on live by a #305 stage) is cycled from off and goes on off. 35 (T6040,
adopted live, stale entries present) goes on live and reports no
entries. 23 failed before this change; 35 fails without the
nvme_sart_entries() change.

Signed-off-by: Diljit Singh <hey@djdev.me>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
m0d16l14n1 pushed a commit to m0d16l14n1/aura that referenced this pull request Nov 21, 2026
On T6040, T6041 and T8132 (nvme_post_m4_keeps_live()) a stage hands its
ANS session on live at the chainload handoff, whatever its origin. That
covers iBoot's session, which this stage gave its one RTKit handshake,
and a live session an earlier stage handed on, which it adopted. aurora-silicon#305
tested both. It also covers a session this stage started from off,
because the earlier stage had powered ANS off and passed its SART
entries (nvme.sart=, every 1.0.0b11 to 1.0.0b13.1 Stage 1 on these
chips). That case was never tested, and it is the one that fails.

On a J713 a 1.0.0b13 Stage 1 ran a b14 candidate Stage 1 as an aura-try
trial. The candidate started ANS from off with the entries, warm, read
the ESP, and handed the session on live. The Mac reset right at the
handoff, with the configured Stage 2 and with main's own. When the
candidate had no Stage 2 to hand to, it rebooted cleanly. On a J616s,
the same candidate adopted a live session from a 1.0.0b10 Stage 1 and
handed it on live, and that boot passed.

So the origin decides. A session that came running may go on live.
One this stage started from off goes on as it came: powered off, its
SART entries passed on, through the existing post-M4 power-off. Its
earlier stage chose that, and the firmware has just shown it starts
from off. The chip list still says where a live handoff is wanted; the
origin says where it is allowed. The Linux handoff
(nvme_keep_running_for_linux) is unchanged. U-Boot can't start ANS from
off, and kboot already reserves every SART-allowed range and the
retained heap for Linux.

tests: two T8132 cases. One arrives off and must go on off, then start
from off again; it failed before this change. One adopts a live session
and must stay live.

Signed-off-by: Diljit Singh <hey@djdev.me>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants