Skip to content

proxy: kboot: hand a live post-M4 ANS session to Linux as boot= does - #403

Open
DjDeveloperr wants to merge 3 commits into
mainfrom
djdev/kboot-ans-linux-handoff
Open

DjDeveloperr wants to merge 3 commits into
mainfrom
djdev/kboot-ans-linux-handoff

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

What: A proxy kboot (linux.py: P_KBOOT_PREPARE_DT, then P_KBOOT_BOOT) on a live post-M4 ANS session now hands that session to Linux, as boot= already does. Without it the tree says ANS is off and nvme_shutdown() powers it off, and Linux loses its root. A tree that relies on the live handoff can no longer be booted after the handoff was dropped (found by Ryan).
Tested: Host only at 2e811c7: 65 pytest cases pass with gcc and with clang, Stage 1 and ESP Stage 2 build. Nothing has been booted at this head. The first version of this change (ecbe6ba, before #410) booted on J773g with macOS 27.2 firmware: nvme-apple adopted the live session and mounted the NVMe root.
Risk: two-way door · proxy kboot only, on Macs with a T8132-type ANS and non-secure registers (M4, M4 Pro/Max, M5 and Neo). boot=, M1 to M3 and T8152 are unchanged.
Not yet: a proxy prepare and Linux boot that adopts ANS, and the prepare, then chainload control, on an M4 mini; the same boot on a Neo, including stock handback. The refused-boot retry is covered by the host test only.

Details
  • nvme_keep_for_kboot() uses the condition nvme_shutdown() acts on for boot= (nvme_initialized && nvme_type == NVME_T8132 && !nvme_secure_regs), not a chip list.
  • The request lasts for one handoff. It is cleared once the Linux branch of nvme_shutdown() ran, on a failed P_KBOOT_PREPARE_DT or P_KBOOT_BOOT, and on P_VECTOR, P_NVME_INIT and P_NVME_SHUTDOWN.
  • kboot_prepare_dt() records whether the tree relies on the live handoff. kboot_boot() refuses such a tree once the request is gone (kboot: ANS handoff changed; prepare the device tree again), before it touches hardware, as it already does for a display handoff that changed. A tree that does not rely on it can still be retried.
Evidence

At 2e811c7 (base dfe97a4), CC=gcc and CC=clang:

  • test_nvme_adoption.py test_nvme_poisoned_io.py test_kboot_prepared_dt.py test_t8140_display_refusal_contract.py: 65 passed each.
  • test_smp_handoff_gate.py test_m4_ans_fdt.py test_ctxr_exec_window.py test_t6040_hibernate_layout.py test_usb_dma_reserve.py: 18 passed each.
  • With src/kboot.c from 069e349, the new test_live_ans_tree_is_not_booted_without_its_handoff fails: the second P_KBOOT_BOOT is accepted. The chainload control passes with and without the fix.
  • clang-format --dry-run --Werror src/kboot.c src/nvme.c src/nvme.h src/proxy.c: clean.
  • make USE_CLANG=1 BUILDSTD=1 RELEASE=1 CHAINLOADING=1 BUILTIN_LOGO=aurora: 95616 B headroom; with ESP_STAGE2=1: 78728 B.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

How this interacts with #410

#410 as it stands today: no conflict. #410 changes how nvme_shutdown() hands a session on to another aura stage, live or off. It explicitly leaves the Linux handoff (nvme_keep_running_for_linux) alone, and that runs before #410's branch. This PR only sets that flag, and only for a proxy kboot (P_KBOOT_PREPARE_DT). So a stage-to-stage chainload still follows #410's rules, and a kboot to Linux still hands Linux the live session.

The receivers differ. Ryan's failure (aura#406) is a receiving aura stage faulting in pcie_init() on a live T8132 session. Here the receiver is Linux: nvme-apple adopts a live ANS, as with boot= on the J713's daily boot. It can't cold-start a T8132 ANS (no apple,sart-entries restore), so this path needs the session live.

Evidence (J773g, T8132, 27.2): this keep is in images built from 1a08e86 + ecbe6ba. On the proxy kboot path, the chainloaded image starts ANS from off, then hands it to Linux live.

  • Linux adopts it every time today (6 boots), including the PMGR-policy kernel (linux#2588) and the 27.2 dcpext0 display kernel.
  • No resets.
  • One separate miss: an image that also carried kboot: gpu: hand the M4 (T8132) GPU to Linux on the 27.2 firmware #379 failed P_NVME_INIT from off once (CSTS 0x6). That stopped before the kboot, so nothing was handed on. It's being followed up separately.

The coming rework of #410. If it drops T8132 out of nvme_post_m4_keeps_live(), this PR has to stop keying on that predicate. Otherwise T8132 kboots would go back to "ANS will be off" and Linux would lose its root.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

#410 is merged now, and on main nvme_post_m4_keeps_live() is T6040/T6041 only (src/nvme.c:484-487). So on main nvme_keep_for_kboot() does nothing on T8132, and that is the chip the J773g evidence is from. A T8132 proxy kboot on main reaches the power-off branch at nvme.c:1034 (main) and passes SART entries in the tree. Linux can't cold-start that ANS. The PR needs the Linux-handoff predicate you described in your earlier comment before it can go in.

  • Predicate: "as boot= does" would be keep && nvme_initialized && nvme_post_m4(). payload.c:571-574 sets nvme_keep_running_for_linux for a boot= handoff on every chip, and nvme_shutdown() acts on it only where nvme_type == NVME_T8132 && !nvme_secure_regs (nvme.c:984 on main). That would also make T8140/T6050/T8142 proxy kboots hand ANS to Linux live, as boot= already does there. If that is not intended, a separate T8132-inclusive predicate is the alternative.
  • src/proxy.c:441,458: the flag is cleared only when kboot_prepare_dt() or kboot_boot() fails. If a host prepares a tree and then chainloads, or shuts NVMe down and starts it again, or leaves the proxy for a next stage, nvme_keep_running_for_linux is still set. The next nvme_shutdown() then takes the Linux branch for an aura stage, and nvme_sart_entries() reports not off. payload.c clears it on its failure path (payload.c:647-648), but nothing clears it in nvme_init() or nvme_shutdown(). Clearing it once the Linux branch has run, or on nvme_init(), would bound it to one handoff.
  • No harness case covers the proxy path. In test_nvme_adoption.py, a case could cover prepare_dt on a keeps-live chip, then entries reported as not off, then the Linux branch in nvme_shutdown(), plus a case where the flag is gone if no boot follows.

After the rebase, the row to run is a proxy kboot on the J773g. It should show kboot: keeping ... and nvme: leaving controller and RTKit running for Linux adoption, then nvme-apple adopting the session and an NVMe root.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Blockers: 2.

Building on the comment above. Its three points still stand at d496c7e: the predicate is a no-op on T8132 now that main's nvme_post_m4_keeps_live() is T6040/T6041 only (src/nvme.c:484-487 on main), the flag outlives a prepare that is not followed by a boot, and no test covers it. Two more:

  1. src/nvme.c:951-955: when this is rebased onto a Linux-handoff predicate, don't make it another chip list. The question kboot asks is "will Linux be able to adopt this controller, and can it not cold-start it". That is a property of the controller this stage brought up (post-M4 ANS with no SART restore in Linux), so key it on what nvme_shutdown() already acts on for boot= (the controller type and nvme_secure_regs), so that the proxy path and boot= cannot drift apart again. If T8140/T6050/T8142 should keep powering off on a proxy kboot while boot= hands them over live, say why in the commit; otherwise the two Linux entry points behave differently on the same Mac.
  2. Commit d496c7e carries a Co-Authored-By: Claude ... trailer. Commits should carry only the human author and Signed-off-by; drop the trailer. The PR body ends with a "Generated with" line; replace it with an Assisted-by: LLM (...) last line.

The hardware evidence is from ecbe6ba on a pre-#305/#410 base; this head has not been booted, and after #410 it would not even select the live branch on the J773g.

HW row: J773g (T8132, 27.2 firmware), rebased head, proxy kboot via linux.py, default command line: kboot: keeping ..., nvme: leaving controller and RTKit running for Linux adoption, no ANS will be off, nvme-apple adopts and mounts the NVMe root; then a prepare_dt followed by chainload, which must take the stage-to-stage branch. Plus one T6040/T6041 proxy kboot showing no change. 0 AVC / 0 failed units / 0 new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr
DjDeveloperr force-pushed the djdev/kboot-ans-linux-handoff branch from d496c7e to 63c1d74 Compare November 21, 2026 20:44
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Rebased cleanly onto main (07e90bb14, post-#410) at 63c1d7409 and addressed all review points:

  1. Controller-property predicate (no chip list): nvme_keep_for_kboot() now checks nvme_initialized && nvme_type == NVME_T8132 && !nvme_secure_regs, matching the exact condition nvme_shutdown() already acts on for payload.c's boot= so the two Linux entry points cannot drift apart (covers T8132 as well as T6040/T6041/T8140/T6050/T8142 identically to boot=).
  2. Bounded to one handoff: nvme_keep_running_for_linux is now cleared when the Linux handoff branch in nvme_shutdown() completes, as well as in src/proxy.c on P_VECTOR (chainload), P_NVME_INIT, P_NVME_SHUTDOWN, and failed P_KBOOT_PREPARE_DT / P_KBOOT_BOOT.
  3. Host test coverage: Added cases 37 & 38 to tests/python/test_nvme_adoption.py covering nvme_keep_for_kboot(true) -> nvme_sart_entries() reporting off == false -> nvme_shutdown() Linux branch + flag reset, and aborted prepare_dt -> stage-to-stage power-off.
  4. Attribution: Dropped Co-Authored-By from the commit and updated the PR body footer to Assisted-by: LLM (...).

Local checks: clang-format --dry-run --Werror, test_nvme_adoption / test_nvme_poisoned_io / test_m4_ans_fdt, and full clang release ESP_STAGE2=1 build all pass.

Assisted-by: LLM (Gemini:4 Neon)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Re-checked at 63c1d74 (the real commit under the trailing github-actions "gfya" commit).

  • Fixed: nvme_keep_for_kboot() (src/nvme.c:1004-1008) now uses the same condition the boot= branch of nvme_shutdown() acts on (src/nvme.c:1029). That condition comes from the ADT (nvme-secure-bar / nvme-secure-reg-layout), so there is no chip list. M1-M3 and T8152 are unaffected.
  • Fixed: the flag is bounded to one handoff. It is cleared in the Linux branch (src/nvme.c:1040), on P_VECTOR, P_NVME_INIT and P_NVME_SHUTDOWN, and on a failed prepare or boot (src/proxy.c:111, 443, 461, 661, 665). The boot= failure path in payload.c still behaves the same.
  • Fixed: cases 37 and 38 cover both paths. test_nvme_adoption.py passes here.
  • Note for the rows: because the predicate covers the whole controller type, a proxy kboot on T6040/T6041, T8140, T6050 and T8142 now also hands ANS to Linux live, as boot= does there. The M4 Pro row will therefore show a change, not "no change".
  • Please drop the "gfya" commit before merge.

Still missing (nothing has been booted at this head yet):

  • J773g (T8132, 27.2), proxy kboot via linux.py, default command line. Pass: kboot: keeping this stage's ANS session running for Linux to adopt and nvme: leaving controller and RTKit running for Linux adoption, no "ANS will be off", nvme-apple adopts and mounts the NVMe root.
  • J773g again: prepare_dt followed by a chainload, which takes the stage-to-stage branch.
  • One T6040/T6041 and one T8140 proxy kboot showing the live Linux handoff and the NVMe root mounted.
  • All rows: 0 failed units and 0 new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

When a proxy kboot (P_KBOOT_PREPARE_DT, then P_KBOOT_BOOT) runs on a
post-M4 ANS controller that Linux adopts live (NVME_T8132 with non-secure
registers), kboot_prepare_dt() builds the tree before the next-stage
nvme_shutdown(). Because nvme_keep_running_for_linux was never set on the
proxy path, nvme_sart_entries() described ANS as powered off and
nvme_shutdown() powered T8132 ANS off on main (post-#410), breaking
Linux's NVMe adoption.

Make a proxy kboot use the same Linux-handoff condition that
nvme_shutdown() already acts on for payload.c's boot= (nvme_initialized &&
nvme_type == NVME_T8132 && !nvme_secure_regs), without introducing a chip
list. Bound nvme_keep_running_for_linux to a single handoff by clearing
it once the Linux branch in nvme_shutdown() runs and on failed
P_KBOOT_PREPARE_DT / P_KBOOT_BOOT, P_VECTOR (chainload), P_NVME_INIT, and
P_NVME_SHUTDOWN.

Add host unit test coverage in tests/python/test_nvme_adoption.py for both
the prepare_dt -> Linux-handoff -> cleared path and the aborted
prepare_dt -> stage-to-stage power-off path.

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr
DjDeveloperr force-pushed the djdev/kboot-ans-linux-handoff branch from 6d21ac7 to e234040 Compare November 22, 2026 13:25
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

@RyanTheTide Dropped the trailing "gfya" bot commit and rebased cleanly onto main (dff1235d8) at exact HEAD e234040a9953b2cbc13b74016dc0e897524611cb (identical patch to 63c1d74099c2, Stage 1 clang build, clang-format, test_nvme_adoption, and test_nvme_poisoned_io all pass).

Remaining: J773g proxy kboot (linux.py), J773g prepare_dt → chainload, and T6040/T6041 + T8140 proxy kboot rows at this head.

Assisted-by: LLM (Gemini:4 Neon)

@DjDeveloperr
DjDeveloperr marked this pull request as ready for review November 30, 2026 20:44
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 30, 2026 20:44
@github-actions github-actions Bot added merge-conflict Conflicts with the base branch (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks required sections (bot) labels Nov 30, 2026
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Merge readiness at 2e811c74: not ready yet

Check Detail
CI at head ok 25 checks passed
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok in the PR body at 2e811c74
Conflicts ok none
PR text ok Risk: two-way · proxy kboot only, on Macs with a T8132-type ANS and non-secure registers (M4, M4 Pro/Max, M5 and Neo). boot=, M1 to M3 and T8152 are unchanged.

Areas: none matched in CODEOWNERS

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: REQUEST CHANGES at e234040a

Blockers:

  1. Branch is CONFLICTING with main. Rebase/merge current main so the PR is MERGEABLE and full CI executes cleanly.
  2. Missing exact-head proxy kboot hardware verification. Post a live proxy kboot (P_KBOOT_PREPARE_DT -> P_KBOOT_BOOT) hardware row on a post-M4 Mac confirming live ANS handoff to Linux at the rebased head.

Checked:

  • Metadata and diff summary (+63/-2, 4 files), CONFLICTING against main.
Evidence
  • e234040a conflicts with current main and still lacks live proxy kboot hardware verification.

@aurora-silicon-review
aurora-silicon-review Bot dismissed their stale review December 1, 2026 04:56

Dismissed under the 12-01 merge bar: this review's blockers were not shown failures (CI/rows/rebase/design or re-run asks). Follow-ups, not blocking: Only metadata checked; follow-ups: rebase, post-M4 proxy kboot ANS handoff row

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Forward-merged main dfe97a4 as 069e349. The two proxy conflicts keep the raw-vector display refusal and the failed-kboot error reply alongside the ANS flag cleanup. The boot-refusal fixture now checks that cleanup runs on refusal. Ran the NVMe adoption, poisoned I/O, kboot DT and display-refusal pytest files together (63 passed). J773g still needs a live proxy prepare → Linux boot proving ANS adoption, plus the prepare → chainload control.

@github-actions github-actions Bot removed the merge-conflict Conflicts with the base branch (bot) label Dec 3, 2026

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

A retry can boot a prepared tree that says ANS stays live after the proxy has cleared the live handoff request. After successful PREPARE_DT, let the first BOOT return S_ERROR because a secondary callback is still pending. That branch leaves dt_ready set, but the proxy clears the NVMe flag. Once the callback completes, a second BOOT without PREPARE_DT accepts the old tree and normal shutdown can power ANS off. I reproduced the accepted stale-tree retry with the exact prepared-DT host fixture and a controllable pending-callback stub. Clearing the handoff request needs to invalidate the associated prepared tree, or the retry must retain the handoff state it describes.

A proxy P_KBOOT_PREPARE_DT on a live post-M4 ANS session builds a tree
that says ANS stays running, and asks nvme_shutdown() to leave it so. A
refused P_KBOOT_BOOT (a secondary callback is still pending, say) drops
that request but left the prepared tree bootable: a second P_KBOOT_BOOT
without a new preparation was accepted, nvme_shutdown() powered ANS off,
and Linux got a tree that says it is running, without the SART entries
to start it. P_NVME_INIT and P_NVME_SHUTDOWN between the preparation and
the boot did the same.

Record with the tree that it relies on the handoff, and refuse it in
kboot_boot() once the request is gone, as for a display handoff that
changed: the host prepares the tree again. A tree that does not rely on
it can still be retried, and boot= is unchanged.

The host test runs the proxy's own request handlers: prepare, refused
boot, retry, and prepare followed by a chainload as the control.

Reported-by: Ryan Murray <ryan@aurorasilicon.org>
Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Fixed the retry Ryan found. New head: 2e811c7493e723f67b2a1b69833782745ebf9e37.

What happened: PREPARE_DT on a live ANS session built a tree that says ANS stays running. The first BOOT was refused because a secondary callback was pending, and the proxy dropped the live handoff request but left the tree bootable. A second BOOT without a new PREPARE_DT was accepted, and nvme_shutdown() then powered ANS off under a tree that says it is running. P_NVME_INIT or P_NVME_SHUTDOWN between the two did the same.

Fix (10 lines in kboot.c): the tree records that it relies on the live handoff, and kboot_boot() refuses it once the request is gone, before it touches hardware, next to the same check for the display handoff. The host has to prepare again. A tree that does not rely on ANS staying live can still be retried as before.

Tests: the new host test runs the proxy's own PREPARE_DT, BOOT, VECTOR, NVME_INIT and NVME_SHUTDOWN handlers. Without the fix it fails at the second BOOT; with it, it passes. The control (prepare, then chainload, also after a refused boot) powers ANS off and passes with and without the fix. NVMe adoption, poisoned I/O, kboot DT and display refusal: 65 passed, with gcc and with clang. Five other files that use this code: 18 passed. clang-format is clean; Stage 1 and ESP Stage 2 build.

Not yet: nothing has been booted at this head. The proxy prepare and Linux boot, and the prepare and chainload control, are still needed on hardware. The pending-callback retry itself is host-tested only.

@github-actions github-actions Bot added blast:m1 Macs affected, from Merge risk (bot) blast:m3 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) blast:neo Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) and removed needs-hw-row No hardware row at the PR head (bot) needs-template PR body lacks required sections (bot) labels Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blast:m1 Macs affected, from Merge risk (bot) blast:m3 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) blast:neo Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants