Repository navigation
nvme: one STOPPED ANS handoff between boot stages on post-M4 chips - #380
DjDeveloperr wants to merge 9 commits into
Conversation
bd63b83 to
d51aa57
Compare
Post-M4 ANS reaches each boot stage in a different state today: iBoot's live session, a session an older stage handed on running, or off with the SART entries passed on (nvme.sart=). Off is the one that breaks. A whole-APCIe-block power-off takes the shared PHY down with ANS. On T8132 the restart from off is flaky, and after a full re-init XNU panics on the empty port 1's window. T6050 is fine only because it cycles its storage gates alone. Write down the one state every stage leaves ANS in and starts it from: STOPPED. In it ANS stays powered, the controller is off, the firmware has acknowledged SLEEP, its CPU is stopped and ANS alone is reset, and the SART holds iBoot's entries. XNU starts ANS cold from STOPPED (the hypervisor's cold handoff, measured on T8140 and T8132). The note also covers how nvme_init() gets to STOPPED from each state it meets, what each payload gets, the failure modes listed before the code is written, and the end-to-end rows. Signed-off-by: DjDeveloperr <hey@djdev.me> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…es under one Two pieces the post-M4 ANS handoff (docs/post-m4-ans-handoff.md) needs outside the hypervisor build: - pmgr_reset_held() leaves #ifdef SPTM_VIRT. It forces the device on for the reset, then puts its target and auto-enable back. A plain pmgr_reset() refuses an ANS that sits idle under auto-enable. The hypervisor's cold handoff reset ANS this way on T8140 and T8132, and XNU then started it cold. - pmgr_adt_power_enable_under() is the inverse of pmgr_adt_power_disable_under(). It powers on, parents first, the gates of an ADT node that are the named device or depend on it, and leaves a gate that is on already as it is. For ANS under /arm-io/apcie it picks exactly the gates that 1.0.0b13's whole-block power-off took down: on T8132 APCIE_PHY_SW, APCIE_SYS_ST, APCIE_ST and ANS. APCIE_GP and APCIE_SYS_GP stay as iBoot left them. Nothing calls the new function yet. Signed-off-by: DjDeveloperr <hey@djdev.me> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…here
From 1.0.0b13 a post-M4 stage done with ANS powered it off with the
whole APCIe block (pcie_ans_power_off()) and passed its SART entries
on as nvme.sart=. The next stage powered the block back with a full
pcie_init() and warm-started the firmware. On T8132 that restart is
flaky ("ANS stays off until a reboot", hv7). When it works, XNU then
reads the empty port 1's window and panics with an LLC SLVERR (hv3,
hv5). Every stage also met ANS in a different state.
Every SoC with a split-BAR ANS but T6050 now follows one contract
(docs/post-m4-ans-handoff.md). That is T8132, T8140, T6040, T6041 and
T8142.
nvme_shutdown() leaves ANS STOPPED, and never powers anything off:
- the controller gets a normal shutdown if this stage wrote, then
CC.EN=0;
- RTKit is put to SLEEP (IDLE if it won't acknowledge, a plain stop
if neither) and the CPU is stopped;
- the stage's buffers and their SART entries go;
- ANS alone is reset with its gate held on, and any SART entry the
reset takes is written back.
iBoot's SART entries stay in hardware.
nvme_init() reads PMGR's ANS power state before any ANS register, then
takes ANS to STOPPED from whatever it finds:
- A running session gets its controller turned off and a SLEEP, and
is reset. For iBoot's session (no aura queue setup) the one-time
RTKit handshake comes first, since it answers nothing before it. An
older stage's session handed on running is asked directly, woken
if it doesn't answer, and its buffers' SART entries are cleared.
- STOPPED is reset again.
- Off, from an older stage that passed nvme.sart=: ANS's side is
powered back (pcie_ans_power_on()), and iBoot's entries are put
back without that stage's buffers.
Then every stage starts ANS the same way: the mailbox receive side
on, the run bit, the RTKit handshake. This is the start the
hypervisor's cold handoff probed on T8132 and T8140 (HELLO
unprompted).
The rest of the handoff:
- The stage tells the next one with nvme.ans=stopped (payload.c,
chainload.c; secboot passes the line, as it names no address).
nvme.sart= is still produced for T6050 and still accepted from
older stages.
- U-Boot adopts only a running session. Its probe needs RUN and
BOOT_STATUS OK. So payload_run() starts a STOPPED ANS for the
payload, as it did for one passed off
(nvme_post_m4_needs_start()).
- kboot passes apple,sart-entries only for an ANS that will be off,
which on these chips is now only one an older stage powered off.
- nvme_cold_handoff() reuses the same pieces (nvme_session_stop(),
nvme_ans_reset(), the SART classification) and powers back an ANS
that an older stage powered off, instead of failing on it.
T6050 keeps its measured path unchanged: adopt, suspend, idle, storage
gates off, warm start. T8152 and M1-M3 don't change.
nvme_ans_power_off() keeps only T6050's branch. The T8142 clause and
the T8142 adoption went; T8142 is now STOPPED like the others.
test_nvme_adoption models ANS's power and run bit. Its T8142 cases
check the STOPPED cycle: SLEEP then the held reset, no power-off, and
the next start from STOPPED. The other harnesses follow the renames.
Not run on hardware yet. Builds and the host tests pass. The next
commit brings ANS back without touching any root port.
Signed-off-by: DjDeveloperr <hey@djdev.me>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… port
1.0.0b13's whole-block power-off (pcie_init_controller(..., ans_off))
puts the shared APCIe PHY into reset, drops its clock requests and
powers off every gate that depends on ANS. On T8132 that leaves
APCIE_PHY_SW, APCIE_ST, APCIE_SYS_ST and ANS off, with APCIE_GP and
APCIE_SYS_GP on. Its counterpart, pcie_ans_power_on(), was a full
pcie_init(), so it also brought up the GP root ports. They then
differed from what iBoot left. XNU read the empty port 1's window and
panicked with an LLC SLVERR. Port 1 never reaches RUN under aura.
Since the previous commit no stage takes that path. What remains is
bringing back an ANS that an older stage left off:
- pcie_ans_power_on() without a storage gate table now runs
pcie_init_controller() with storage_only:
- only the gates that depend on ANS go back on
(pmgr_adt_power_enable_under());
- the shared PHY comes up as for a full init;
- no root port is touched;
- the controller still reads as not initialized, so kboot's
pcie_init() brings the root ports up for Linux as before.
On real ADTs the gates are ANS, APCIE_ST, APCIE_SYS_ST and
APCIE_PHY_SW on both J773g (T8132) and J700 (T8140); see
test_ans_gates_adt.
- pcie_ans_power_off() refuses on a chip without a storage gate table,
so no caller can take that PHY down again. The ans_off branch and
pmgr_adt_power_disable_under() go.
- T6050's and T8142's storage gate tables are unchanged.
Not run on hardware: on T8132 this is the WIP pcie_ans_power_on_storage()
of the hvtrace branch, with the GP gates left alone too.
Signed-off-by: DjDeveloperr <hey@djdev.me>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… STOPPED Only T8140 started XNU with the cold handoff by default. Elsewhere the runner kept "quiesced" in the guest's iop-ans-nub, so XNU tried to wake iBoot's quiesced session with one INIT. On T8132, T6040, T6041 and T8142 an aura stage that used ANS now leaves it STOPPED: the CPU is stopped and ANS reset. There is no session left to wake there. The cold handoff (sleep) is now the default on those SoCs too. On a STOPPED ANS it only checks: nothing runs, no aura SART entry is left, and ANS is reset and probed. AURA_ANS_COLD=off still gives XNU an untouched iBoot session to wake. T6050 keeps "off" by default. docs/sptm-virt-ans-cold-handoff.md gets the new defaults and a section on an ANS that an older stage powered off. Signed-off-by: DjDeveloperr <hey@djdev.me> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Read from the U-Boot and Linux trees in use: - U-Boot's nvme_apple adopts only a running session (RUN and BOOT_STATUS OK). It doesn't bind the T8142 or T6050 compatibles. It can't start from STOPPED, which is why a stage starts ANS for every payload. - Linux's apple-nvme starts an ANS whose run bit is clear on every post-M4 compatible. On all but T8132 it relies on the bootloader's reset. It turns the mailbox receive side on only for T8140, and it must not get apple,rtkit-handoff for a stopped ANS. None of this is tested on hardware. Also list the functions that implement each part. Signed-off-by: DjDeveloperr <hey@djdev.me> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A post-M4 ANS CPU that was stopped without a reset since it last ran doesn't start again from the run bit: its firmware sends no HELLO, then or later (aura c0a50c0, Ryan Murray, from the J713's 27.2 chain, where U-Boot then gets ANS running). Every start from STOPPED now reads the ASC CPU status first; without the reset state (bit 3) it stops the CPU and resets ANS, its SART entries put back, before the run bit. Then the mailbox's receive side goes on and the start is the warm one, rtkit_boot_warm(), as after a power loss, instead of the cold boot with its wake message: the order that works on the J713. On a J773g mini (27.2, 11-20) Stage 1 1.0.0b13's idle before its chainload timed out ("IOP power transition timed out", aura#305), and neither a warm start, a cold start after an ANS-only reset, nor this order brought that firmware back in the same boot: CPU status 0x62 after the reset, no reset-state bit. Only a SoC reset recovers that case. This change is for the clean STOPPED handoff, not for it. The host model counts the warm starts: iBoot's session gets one cold boot for its handshake, every start from STOPPED one warm start. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: DjDeveloperr <hey@djdev.me>
d51aa57 to
d5eb5f6
Compare
|
Data point from a 13" M4 MacBook Air (J713, T8132) on the 27.2 stub, for the legacy-OFF path. It doesn't test this branch. (Edited 2026-11-21: replaced the first version, which relied on a photo of the panel, with the console log read from the proxy over USB.) Stage 1 is aura main 3d517e6 (dev build), which still hands ANS on powered off with Where it failed. It was the boot after a failed aura-try trial, on the configured c0a50c0 (the trial itself most likely died earlier, in aura#320's MCC init; see below). Console buffer: So the firmware did start, but its IOP power report came later than RTKit's 2 s wait. After the ANS-only reset, the first message read was a stale one (type 0x07), not HELLO. An ESP Stage 2 has no watchdog, so the Mac stayed in the proxy until a host rebooted it over the USB tether. What fixed it on this machine: #394 (main-based, 2 commits). It drains stale ANS messages before the warm start and gives the IOP power report 6 s instead of 2. Its lab form is now the J713's configured Stage 2. On normal boots the IOP power state arrives about 68 ms after HELLO. The slow case looks specific to the state after a watchdog reset. Warm reboots since then pass. Separate T8132 issue we hit on the same night: with aura#320 in the tree, For this PR: the legacy-OFF start on T8132 worked once stale messages were drained and the IOP power wait was long enough. We aren't proposing c0a50c0 itself (it has no PR). The J713 can run this branch as an ESP Stage 2 one-shot once it's ready for hardware: say so here and we'll queue it. Assisted-by: LLM (Claude:Opus 5.5) |
|
Blockers: 4. Main has since taken a different handoff model for these chips, so this branch needs to be re-done against main or closed.
HW row: on current head, rebased: J773g and J713 (T8132), Neo (T8140): b13 Stage 1 -> new Stage 2 -> Linux, new Stage 1 -> old Stage 2, and HV -> macOS, 3 boots each, NVMe up every time with no SLVERR. Plus a T6050 and a T6041 regression boot. All with 0 failed units and 0 new kernel errors. Assisted-by: LLM (Claude:Opus 5.5) |
Revert the automated agent-policy bot commit a90f0c2 that deleted assistant instruction files on this PR branch. The policy workflow has since been updated (aura#475) to stop pushing to PR branches. Signed-off-by: Dj <43033058+DjDeveloperr@users.noreply.github.com>
|
@DjDeveloperr since this was opened, main took a different handoff model for these chips (#305 and #410, 3b835c2), so this branch would need to be redone against main. The review with details is #380 (comment). If nothing here still needs to land, I'll close it after 2026-11-28 03:00 AEDT (24 hours from now). The branch stays, so it can be reopened. If something does still need to land, say so here and I'll leave it open. |
|
Closing as superseded, per #380 (comment) (no objection in 24 hours). The branch stays, so this can be reopened if something here still needs to land. |
Draft: nothing here has run on hardware yet. Owner direction: a minimal, generic post-M4 ANS reset, so that a stage that touches ANS leaves it in a clean state the next stage (or XNU) can start from, instead of today's per-chip power cycles.
What broke (measured on an M4 Mac mini, T8132, 2026-11-19)
nvme_shutdown()withpcie_ans_power_off(). That takes the shared APCIe PHY down and gates everything under ANS: APCIE_PHY_SW, APCIE_ST, APCIE_SYS_ST and ANS were all off afterwards.LLC Bus error (SLVERR)on the empty APCIe port 1.The contract
docs/post-m4-ans-handoff.mddefines one state between stages, STOPPED:The doc also lists the failure modes, written before the code.
nvme_init()starts from any of:nvme.sart=from b13/b8): only the ANS gates powered back on, the shared PHY brought up with no root port, iBoot's SART entries restored.The next stage gets
nvme.ans=stopped.Also included: aura stages clear iBoot's failed-boot count on T8132 (the same commit as #378).
U-Boot and Linux (from reading the code)
boot=already did.apple,sart-entries, which Linux never reads.Host checks
tools/stage1_size.shpasses; Stage 1 headroom 17392 B (16624 on main).test_ans_gates_adtagainst real J773g and J700 ADTs: the legacy repair powers on exactly the four gates measured off.Not yet tested on hardware; open risks, most serious first
E2E plan (3 boots per row, logs kept)
Log lines to look for are in the doc.
Update 11-20: Ryan Murray's start order (d5eb5f6)
lab/j713-ans-reset-main, the J713's working 27.2 chain):rtkit_boot_warm()), instead of the cold boot.-Oz) all build. The host model now counts warm starts.pytest tests/python: 795 passed. The 9 failures aretest_m3_defaults_optoutupdater cases andtest_loadobjs, which fail on main too.🤖 Generated with Claude Code