Skip to content

sptm_virt: boot a stock-SPTM guest on J613 - #298

Merged
RyanTheTide merged 23 commits into
aurora-silicon:mainfrom
satchlj:j613-stock-sptm-upstream
Dec 2, 2026
Merged

RyanTheTide merged 23 commits into
aurora-silicon:mainfrom
satchlj:j613-stock-sptm-upstream

Conversation

@satchlj

@satchlj satchlj commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

What: Bring up stock SPTM under FEAT_NV2 (SPTM_VIRT) with generic, ADT-driven host support and bounded ANE tracing:

  • proxyclient/aura/sptm_patch.py: replace the single-register APSTS match with a structural 5-instruction AArch64 readiness-poll matcher (_find_apsts_polls(), admitting 1–2 sites and failing closed on 0 or >2), covering builds with distinct primary/secondary register pairs without per-image export tables.
  • src/sptm_virt_s2.c: parse /chosen/lock-regs/amcc for every non-T8142 chip (validating against mcc_plane_info(), skipping empty unpopulated bank children while rejecting partial banks, supporting up to 8 apertures and 640 shadow entries), keeping the host's real AMCC locks untouched.
  • src/smp.c, src/sptm_virt.c, src/sptm_virt_gpu.c, Makefile: guest secondary RVBAR publishing (including powered-off A7–M3 secondaries with RVBAR_LOCK set from iBoot, while refusing to write any running locked core), bounded AURA_ANE_TRACE ring, and optional NO_DISPLAY=1 headless Stage 1 build flag.
  • proxyclient/tools/run_guest_sptm.py: Darwin KIS re-enumeration console tail, USB serial post-entry drain avoidance, and ctrr_stash_off is None guard.

Tested:

  • J613 (M3 MacBook Air 13", macOS 26.6.2 / 25G83 stock SPTM) at 4903a22bcb3f: PASS — both untraced boot and AURA_ANE_TRACE=1 boot reach loginwindow on all 8 cores with 0 panics:
    • Semantic APSTS matcher patches both readiness-poll sites (0x1000f1980c4, 0x1000f1a77c0).
    • Live-ADT AMCC shadow: SPTM-virt[amcc]: lock-regs bank shadowed: 1 bank(s) on 2 aperture(s) x 2 plane(s); host protection unchanged.
    • Secondary RVBAR publishing: cpu0..3, 5..7 unlocked and pointed at the active image (core state 0x0), running cpu4 untouched (locked -> aura, core state 0x2); all 8 cores enter SPTM and XNU (0xfffffe00340a8000) within 0.9 s.
    • AURA_ANE_TRACE=1: hooks all 6 ADT-derived windows including both DAPF slices (ANE trace: hooked ane-dapf 0x2a5468000+0x4, ANE trace: hooked ane-dapf 0x292468000+0x4) and reaches loginwindow cleanly with 0 panics.
  • Host verification (cd7a9b13b03a + 4903a22bcb3f): clang-format --dry-run --Werror, RVBAR unit test suites (test_smp_guest_rvbar.py, test_smp_legacy_rvbar.py, test_smp_load_base_rvbar.py, test_smp_locked_boot_rvbar.py), and SPTM_VIRT=1 CHAINLOADING=1 DEBUGUSB_PROXY=1 NO_DISPLAY=1 EXTRA_CFLAGS=-Oz build all pass.

Risk: two-way · SPTM_VIRT=1 development/trace builds and host launcher only; default Stage 1 boot path is unchanged aside from the opt-in NO_DISPLAY=1 flag and guest secondary RVBAR helper.

Not yet: An additional post-merge hardware row on another SoC (M2 or M4 Pro) showing the /chosen/lock-regs/amcc admission line.

Merge note: Squash-merge this PR (or land via a fresh squashed branch if a merge commit is ever required) so intermediate branch commits prior to cd7a9b13b03a that previously contained the removed 25G83.json file do not enter main history.

@satchlj
satchlj marked this pull request as ready for review November 18, 2026 13:36
@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for the stock-SPTM guest on the J613; the hardware table is very clear.

One structural point. The AMCC shadow gains a second per-chip implementation: sptm_virt_amcc_contract_t8122() (src/sptm_virt_s2.c:469-520) compares the ADT against transcribed apertures (:475 exact_apertures = {0x220000000, 0x222000000}), and sptm_virt_amcc_watch() branches on chip_id == T8122 (:556) next to the existing T8142 plane offsets. We prefer one path selected by hardware properties.

/chosen/lock-regs/amcc already carries aperture-phys-addr, plane-stride and the *-reg-offset values your test checks. Could the watch read those for every chip (refusing on a malformed node, which keeps it fail-closed), instead of matching exact T8122 numbers? The T8142 branch could then move onto the same reader.

We can run guest rows on our M1 Pro, M2, M4 Pro and A18 Pro with the shared reader.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Following up on the AMCC point with a few more items, mainly so the merge is clean:

  1. src/smp.c:259-271 now writes RVBAR in smp_prepare_rvbar() for every core with unlocked sysregs. That runs on the normal boot path of every M1/M2/M3, not only under the stock-SPTM guest. Could this move to the guest-entry path? If it stays general, we can run normal-boot rows on our M1 Pro and M2.
  2. j613_capture_setup() (src/sptm_virt_gpu.c:246) hard-codes the ANE/DART/AIC regs plus two windows (0x292468000, 0x2a5468000) that aren't checked against the ADT. Could the windows come from the ADT nodes, with the mode named by what it traces rather than by board?
  3. The profile and admit check are pinned to 25G83. Our common target is 27.2 (26B123). A property-driven AMCC reader would make this version-independent.
  4. None of the commits has a Signed-off-by. Could you add your own (git commit -s) when you next push?

@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 for the stock-SPTM guest on the J613. The run table is clear, and it's good to see all 8 cores in XNU under stock SPTM.

Ryan's two rounds cover what holds it, and I agree with all of them:

  1. DCO. None of the 11 commits has a Signed-off-by (docs/licensing.md). git rebase --signoff main adds them in one go.

  2. smp_prepare_rvbar() now writes RVBAR on every A7 to M3 boot (src/smp.c:267-271), not only under the stock-SPTM guest, and it returns -1 when the readback differs. Please move the write to the guest-entry path. If it stays general, say so, and we'll run normal-boot rows on the M1 Pro and M2.

  3. Chip and address gates.

    • sptm_virt_amcc_contract_t8122() compares the ADT with transcribed apertures (exact_apertures = {0x220000000, 0x222000000} in src/sptm_virt_s2.c).
    • sptm_virt_amcc_watch() branches on chip_id == T8122.
    • j613_capture_setup() (src/sptm_virt_gpu.c) hard-codes the ANE, DART and AIC windows, plus 0x292468000 and 0x2a5468000.

    /chosen/lock-regs/amcc already carries aperture-phys-addr, plane-stride and the *-reg-offset values. Reading those on every chip, and refusing a malformed node so it stays fail-closed, would replace the T8122 numbers, and the T8142 branch could move onto the same reader.

  4. The profile and the admit check pin 25G83. A property-driven reader would also make the 27.2 (26B123) target work.

The red format-check is base drift in src/sptm_virt_s2r.c. main is clean now, so your next push will pick that up.

@satchlj
satchlj force-pushed the j613-stock-sptm-upstream branch from eb9dfa7 to 1a7a1dd Compare November 20, 2026 14:42
@satchlj

satchlj commented Nov 20, 2026 •

Copy link
Copy Markdown
Member Author

Claude Opus 5.5 on @satchlj's behalf

Thanks @RyanTheTide and @DjDeveloperr. I've addressed every point in a code-only pass. New head: 1a7a1dd4.

None of this rework has run on hardware. The J613 wasn't available, so the run table in the description is from the old head only.

Review point Commit What changed
DCO all 15 Rebased onto current main with --signoff. Every commit has Signed-off-by: Satya Benson. Main's format-check fix comes with the rebase.
RVBAR on every A7–M3 boot 5d439406 smp_prepare_rvbar() and its two harnesses are back to main, byte for byte. The write moved to a new smp_prepare_guest_rvbar(), which only smp_prepare_guest_resets() (the stock-SPTM guest path) calls. It writes an unlocked RVBAR on A7–M3, reads it back, and never writes a locked one. Normal boots no longer change, so the normal-boot rows on M1 Pro and M2 aren't needed.
AMCC chip and address gates feb1ced4 Every chip now uses one reader of /chosen/lock-regs/amcc. It reads aperture-phys-addr, aperture-count and aperture-size, plus plane-count and plane-stride. It also reads the optional cache-status-reg-*, and treats each child node as a bank, taking its five *-reg-offset values. The geometry must also match the MCC driver's planes. A missing or malformed node is refused at admission (sptm_virt_s2_admit) and panics before any hook at guest setup. sptm_virt_amcc_contract_t8122() and the chip_id == T8122 branch are gone. Under this shadow, only the registers the node describes are shadowed.
T8142 branch (not moved) T8142 keeps its plane-offset path (amcc_is_lock, AURA_AMCC_NOLOCK). Its shadow is a per-lock mask over +0xacc/+0xadc/+0xaec that was measured on that machine. Nothing in this PR or in aura's source shows whether T8142's lock-regs banks name those same offsets. Moving it now would be an untested change on M5, and M5 isn't among the offered rows. It can move once someone with an M5 confirms the banks.
j613_capture_setup() 9c9dccc7 Now ane_trace_setup() / SPTM_VIRT_ANE_TRACE (AURA_ANE_TRACE). It hooks every reg window of /arm-io/ane and /arm-io/dart-ane, plus /arm-io/aic reg[0]. A window inside another is traced through the larger one. It refuses a missing node, an empty window or too many windows before installing any hook, and the chip check is gone. On the J613 ADT it hooks the same ANE and AIC windows as before. The two 4-byte windows at 0x292468000 and 0x2a5468000 are dropped for now, because neither this PR nor aura's source names their ADT node. They can come back as ADT-relative entries once one does.
25G83 pin 1a7a1dd4 aura/sptm_export.py selects a clean-room export from aura/sptm_exports/*.json by the SPTM image's sha256, not by SoC, board or OS build. The 25G83 export moved there unchanged. The exact ADT resource and window lists are gone. AURA_J613_RUN is now AURA_SPTM_EXPORT. Supporting 27.2 (26B123) takes one more reviewed export file. That export doesn't exist yet, so 27.2 is not claimed to work.

Validation on the new head (host only):

  • gmake USE_CLANG=1 BUILDSTD=1 CHAINLOADING=1 SPTM_VIRT=1 DEBUGUSB_PROXY=1 NO_DISPLAY=1 EXTRA_CFLAGS=-Oz builds.
  • make format-check (clang-format 20.1.8) and make rustfmt-check are clean.
  • Host pytest: 814 passed, 52 skipped. The only failures are 6 toolchain tests (test_toolchain, test_asm, test_loadobjs), which need an ld.lld that this build host doesn't have.
  • New harnesses compile the production bodies against modeled MMIO, ADT and MCC data:
    • test_smp_guest_rvbar.py
    • test_sptm_amcc_lockregs.py: two geometries are admitted, and 24 malformed or inconsistent nodes are refused.
    • test_sptm_ane_trace.py
    • test_sptm_export.py

Still untested on hardware:

  • J613 (T8122, 25G83): the full guest boot on this head. This covers the RVBAR publish now running in smp_prepare_guest_resets() and the lock-regs reader admitting the real node. The plane-offset locks no longer apply under that shadow, the ANE trace no longer covers the two word windows, and the runner uses the new env names.
  • Other chips: the AMCC change touches every chip except T8142. A stock-SPTM guest is now refused if /chosen/lock-regs/amcc is missing or malformed. Where the node is well-formed, the guest now gets the bank shadow, which no chip other than T8122 had before.

@RyanTheTide, we'd gladly take your offer of guest rows on M1 Pro, M2, M4 Pro and A18 Pro with the shared reader. The useful signal per machine is the SPTM-virt[amcc] admission or refusal line and how far the guest gets. If a node is refused on a chip that booted before, please post that line, since it shows which property failed.

@satchlj

satchlj commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Claude Opus 5.5 on @satchlj's behalf: pushed 92989ea, "sptm_virt_gpu: trace the ANE DART's DAPF slices from the ADT".

ane_trace_setup() now reads every dapf-instance-N property of /arm-io/dart-ane through the existing dapf_t8110_ranges() and hooks each slice at four-byte granularity. A slice that lies inside a reg window is traced through that window. This brings back the two word windows that 9c9dccc dropped: they are DAPF slices 0 and 4. The other three slices fall inside /arm-io/ane reg[3]. A property that is present but malformed or empty, or a slice that isn't whole words, refuses the trace before any hook is installed. No addresses are hard-coded, and nothing is selected by chip or board.

The host test tests/python/test_sptm_ane_trace.py now covers the slice path and its refusals. The USE_CLANG=1 BUILDSTD=1 CHAINLOADING=1 SPTM_VIRT=1 build, format-check, rustfmt-check and the host pytest suite (818 passed) all pass.

This is untested on hardware. The J613 guest boot already queued on rubra will cover it.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for the rework. One reader of /chosen/lock-regs/amcc for every chip, refusing a malformed node at admission, the ANE trace windows taken from the ADT, the export chosen by the SPTM image's hash, and the RVBAR write confined to the guest path cover what we asked. Leaving the T8142 plane-offset shadow where it is until someone with an M5 confirms its lock-regs banks is fine, and the comment says why.

As offered, we will run the guest on our M1 Pro, M2, M4 Pro and A18 Pro at 1a7a1dd and post the SPTM-virt[amcc] admission or refusal line and how far each guest gets. A J613 run on this head is still the main row.

@satchlj

satchlj commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Claude Opus 5.5 on @satchlj's behalf. J613 guest boots at 92989eac: both failed on the host before the guest started. It is a code bug, not a hardware one.

Setup. J613 (MacBook Air M3), macOS 26.6.2 (25G83) stock SPTM/TXM. Built with gmake -j8 USE_CLANG=1 BUILDSTD=1 CHAINLOADING=1 SPTM_VIRT=1 DEBUGUSB_PROXY=1 NO_DISPLAY=1 EXTRA_CFLAGS=-Oz (clean). Two RAM chainloads under the rig lock: run 70 untraced, run 71 with AURA_ANE_TRACE=1, both with AURA_SPTM_EXPORT=1.

What happened, in both runs:

  • The export was selected: SPTM export 25G83: SPTM shipped with macOS 26.6.2 (25G83), measured on a J613.
  • The device tree and boot args were written, and the two APSTS polls were patched.
  • Then patch_sptm() raised TypeError: '<' not supported between instances of 'NoneType' and 'int' from p.write32(sym["sptm_virt_ctrr_stash_off"], sp["ctrr_stash_off"]) (proxyclient/tools/run_guest_sptm.py:625).
  • sptm_export.py:72 returns "ctrr_stash_off": None for every export, and 25G83.json has "ctrr_stash_off": null, so this happens on every export boot.

Suggested fix: restore the guard the earlier head had:

    if sp["ctrr_stash_off"] is not None:
        p.write32(sym["sptm_virt_ctrr_stash_off"], sp["ctrr_stash_off"])
        print(f"SPTM: CTRR stash +0x{sp['ctrr_stash_off']:x}")

DAPF slices: not observed. The ANE trace: hooked … lines are printed by Aura once the guest starts, after patch_sptm(), so run 71 shows none of them, neither slices 0–4 nor the /arm-io/ane reg[3] ones. Whether reading dapf-instance-N is enough on J613 is still open.

Recovery and disk: after each run the installed Linux came back cleanly. Btrfs superblock generations moved only forward: 87754 → 87759 for run 70, and 87760 → 87764 for run 71, on all three superblocks.

I'll rerun both on the next head with the guard.

🤖 Generated with Claude Code

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for the J613 runs and the clear write-up. Bringing the two word windows back as the ANE DART's dapf-instance-N slices, read through dapf_t8110_ranges() with refusal on a malformed property, is the right shape, and it keeps the trace free of fixed addresses.

The ctrr_stash_off guard you suggest (run_guest_sptm.py:625) looks right: the export never sets it, so the write should be skipped when it is None.

We will run our M1 Pro, M2, M4 Pro and A18 Pro guest rows on the head that carries that guard rather than on 1a7a1dd, and post the SPTM-virt[amcc] line and how far each guest gets. The J613 rerun with AURA_ANE_TRACE=1 remains the main row.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Blockers: 3.

  1. The new /chosen/lock-regs/amcc reader refuses every real node we have, including the J613's, so the guest never gets past admission. I checked it against live ADTs:
    • T8122 (J615 ADT, same SoC as the J613): amcc-ctrr-a names its five offsets, but amcc-ctrr-b, -c and -d are empty nodes. src/sptm_virt_s2.c:478-490 treats every child as a bank that must name all five registers, so the node is "malformed".
    • T8132 (2 apertures x 2 planes), T8140/T8152 (1 x 4) and T6040 (4 x 4) all list four populated banks. 2x2x4x5 = 80 already exceeds amcc_lock_shadow[64] (:376, bound check at :497-498).
    • T6041 has 8 apertures, which is more than AMCC_LR_MAX_APERTURES 4 (:389).
      Fix: skip a child that names no *-reg-offset (refuse one that names only some of them), and size the shadow from the largest geometry the ADT can describe. test_sptm_amcc_lockregs.py only models 1 or 2 populated banks. Please add a T8122-shaped case (one populated bank plus three empty ones) and a 2x2x4 case, and both should be admitted.
  2. proxyclient/aura/sptm_exports/25G83.json holds 32-byte instruction sequences, patch offsets and the image UUID, all taken from Apple's SPTM binary. Shipping that in this public tree publishes binary-derived content, and it also turns support into a per-firmware-image table. Either extend sptm_patch.plan()'s pattern scan to find the early-entry readiness wait (main already finds the APSTS sequence that way), or have the loader read exports from a private path given on the command line, with no export files in the repo.
  3. Six commits (69e4ccd, 5d43940, feb1ced, 9c9dccc, 1a7a1dd, 92989ea) carry Co-Authored-By: Claude ... trailers. Please drop them and keep only the human Signed-off-by. Also make the PR body's last line Assisted-by: LLM (<Vendor>:<Model>), not the "Generated with Claude Code" footer.

The ctrr_stash_off crash found in the 92989ea runs is still at head (proxyclient/tools/run_guest_sptm.py:625). The guard proposed in that comment hasn't been pushed yet.

HW row: J613, 25G83 stock SPTM, on the head with the fixes above: SPTM-virt[amcc]: lock-regs bank shadowed admission line, the guest reaches loginwindow (untraced run), and an AURA_ANE_TRACE=1 run shows the ANE trace: hooked ane-dapf lines. Add one other-SoC guest row (M2 or M4 Pro) showing the admission line.

Assisted-by: LLM (Claude:Opus 5.5)

Signed-off-by: Satya Benson <satya@benson.earth>
Signed-off-by: Satya Benson <satya@benson.earth>
Signed-off-by: Satya Benson <satya@benson.earth>
Signed-off-by: Satya Benson <satya@benson.earth>
Signed-off-by: Satya Benson <satya@benson.earth>
Signed-off-by: Satya Benson <satya@benson.earth>
Signed-off-by: Satya Benson <satya@benson.earth>
Signed-off-by: Satya Benson <satya@benson.earth>
Signed-off-by: Satya Benson <satya@benson.earth>
Signed-off-by: Satya Benson <satya@benson.earth>
The macOS CI runners have no gmake on PATH.

Signed-off-by: Satya Benson <satya@benson.earth>
smp_prepare_rvbar() runs on every normal boot. Restore its main
behaviour (A7 to M3 leave the write to smp_start_cpu()) and the two
harnesses that modeled the extra write, and move the publish into
smp_prepare_guest_rvbar(), called only from smp_prepare_guest_resets().
It writes an unlocked RVBAR on A7 to M3, reads it back, and never
writes a locked one.

Signed-off-by: Satya Benson <satya@benson.earth>
Replace sptm_virt_amcc_contract_t8122()'s transcribed apertures and
offsets, and the chip_id == T8122 branch in sptm_virt_amcc_watch(),
with one reader of /chosen/lock-regs/amcc used on every chip: the
apertures (aperture-phys-addr, -count, -size), the plane geometry
(plane-count, plane-stride), the optional cache status
(cache-status-reg-*), and one bank per child from its *-reg-offset
properties. The geometry must also match the MCC driver's planes.

A missing or malformed node is refused at admission
(sptm_virt_s2_admit) and panics before any hook at guest setup, so the
path stays fail-closed. Under the lock-regs shadow, only the described
bank registers are shadowed; the T8142 plane-offset locks no longer
apply there.

T8142 keeps its plane-offset path (amcc_is_lock, AURA_AMCC_NOLOCK):
whether its lock-regs banks name +0xacc/+0xadc/+0xaec has not been
checked on an M5, so moving it now would change that path untested.

Signed-off-by: Satya Benson <satya@benson.earth>
j613_capture_setup() compared transcribed J613 values and hooked a
fixed window list, including two addresses (0x292468000, 0x2a5468000)
no ADT node backed. Replace it with ane_trace_setup(): it hooks every
reg window of /arm-io/ane and /arm-io/dart-ane and /arm-io/aic reg[0],
traces a window that lies inside another through the larger one, and
refuses a missing node, an empty window or too many windows before any
hook. The chip_id check goes; the mode is SPTM_VIRT_ANE_TRACE, named by
what it traces.

On the J613 ADT this hooks the same ANE and AIC windows as before. The
two word windows are no longer traced: their ADT node is not named in
this PR or aura's source, so they come back once one is.

Signed-off-by: Satya Benson <satya@benson.earth>
The J613 profile and admit check were pinned to 25G83 and to
chip == 0x8122, with exact ADT register values. Replace them:

- aura/sptm_export.py loads every aura/sptm_exports/*.json and picks
  the one whose image_sha256 matches the SPTM image given. No SoC,
  board or OS build is matched. The existing 25G83 export moves there
  unchanged; an export for another SPTM build (27.2, 26B123) is one
  more file, once one is reviewed.
- An image with an export is patched only from it, and only with
  AURA_SPTM_EXPORT=1 (was AURA_J613_RUN) or AURA_ANE_TRACE=1 (was
  AURA_J613_TRACE). An incomplete or unreviewed export, or one with
  rows the loader does not apply, is refused on the host before
  anything is placed on the target. Any other image goes to
  sptm_patch.plan(), which refuses images it cannot fully plan.
- The exact ADT resource and window lists go: the ANE trace reads its
  windows from the ADT, and the AMCC shadow reads lock-regs.

Signed-off-by: Satya Benson <satya@benson.earth>
ane_trace_setup() dropped the two four-byte windows j613_capture_setup()
hooked by address. They are slices of the ANE DART's filter: the
dapf-instance-N entries of /arm-io/dart-ane. Read every such property
with dapf_t8110_ranges() and hook each slice at the filter's word
granularity; a slice inside a reg window is traced through it, as
before.

A dapf-instance-N that is present but malformed, empty, or holds a slice
that is not whole words refuses the trace before any hook. A DART with
no such property traces its reg windows only.

On the J613 ADT this restores the two word windows; the other three
slices lie in /arm-io/ane reg[3].

Signed-off-by: Satya Benson <satya@benson.earth>
@satchlj

satchlj commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Claude Opus 5.5 on @satchlj's behalf. Commits rewritten to carry human identity and DCO only (no Co-Authored-By, no Assisted-by in commits); trees byte-identical to the previous head 92989ea (new head 8550bdb).

Conflict: src/sptm_virt.h, flag bit 11. main took it for SPTM_VIRT_SEP
(AURA_SEP_TRACE); this branch used it for SPTM_VIRT_ANE_TRACE. ANE_TRACE
moves to bit 12, and AURA_ANE_TRACE in run_guest_sptm.py moves with it.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor

The 24 h window on Dj's 11-26 merge-main request passed, so as maintainers we merged main (26c1a85b) into the branch as a fast-forward on 4903a22b. Your commits are kept and nothing was force-pushed. New head: 7a0bc989.

The one conflict was a flag-bit collision in src/sptm_virt.h: main took bit 11 for SPTM_VIRT_SEP (AURA_SEP_TRACE), and this branch used bit 11 for SPTM_VIRT_ANE_TRACE. ANE_TRACE moves to bit 12, and AURA_ANE_TRACE in proxyclient/tools/run_guest_sptm.py moves with it (1 << 12). Nothing else uses the raw number. If you pass the flag word by hand anywhere, use 0x1000 now.

Local checks at the new head: clang build (RELEASE=1 CHAINLOADING=1 ESP_STAGE2=1 USE_CLANG=1 BUILDSTD=1) OK, make format-check (clang-format 20.1.8) clean, full pytest 1272 passed. The 2 test_loadobjs failures also fail on main on this host (nm output format). Main itself is still red on stage1-size (DCP log buffer), and that is not caused by this PR.

Because the conflict was in a file this PR touches, the J613 row at 4903a22b doesn't carry over. Please re-run the J613 stock-SPTM boot at 7a0bc989. That row, plus a non-author look at the bit move, is all it needs to merge.

@RyanTheTide
RyanTheTide requested review from a team as code owners November 27, 2026 11:09
@github-actions github-actions Bot added needs-review No approving review from Core or Omarchy Mac yet (bot) and removed merge-conflict Conflicts with the base branch (bot) labels Nov 27, 2026
@satchlj

satchlj commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

Checked the stage1-size failures (gcc, fedora, nix) on 7a0bc989 against main (26c1a85b, run 45941698202): the Stage 1 sizes are byte-for-byte identical, so this PR adds 0 B to Stage 1:

  • gcc stage1: _file_vital_end 0x11d1d8, headroom 3696 B (main 26c1a85b: _file_vital_end 0x11d1d8, headroom 3696 B)
  • nix stage1: _file_vital_end 0x11d010, headroom 3152 B (main 26c1a85b: _file_vital_end 0x11d010, headroom 3152 B)

All SPTM_VIRT objects stay compiled out of Stage 1 and smp_prepare_guest_resets is dropped by --gc-sections when SPTM_VIRT=0. Once main's Stage 1 headroom is back above 4096 B, merging main will clear stage1-size.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Status at 7a0bc989: the code is ready. Thanks for checking Stage 1: it adds 0 B, and the gcc/fedora/nix "Stage 1 room" failures are main's own. Two things are left before merge, both because main was merged into the branch:

  1. @satchlj: one J613 stock-SPTM guest boot at 7a0bc989, the same steps as your earlier row. The forward-merge resolved a src/sptm_virt.h flag-bit collision, so the old row no longer counts.
  2. @DjDeveloperr: a re-approval at 7a0bc989. The forward-merge dismissed yours, and our account made that push, so our approval doesn't satisfy the last-push rule. The only change since your approval is that one-line flag renumbering.
    We'll merge once both are in.

@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: FINISH, then merge at 7a0bc989

Blockers:

  1. Missing exact-head J613 stock-SPTM guest boot row at 7a0bc989 (needed because the forward-merge resolved a src/sptm_virt.h flag-bit collision relative to the previously tested 4903a22b head), plus a second-Mac regression check.

Checked:

  • Code & IP audit: prior Apple-binary pattern export is gone (_find_apsts_polls() uses semantic instruction matching with zero copied binary bytes); src/sptm_virt.h merge resolution at 7a0bc989 is clean.
  • Stage 1 size CI (gcc, fedora, nix): verified byte-identical to main (26c1a85b), adding 0 B to Stage 1; all other 27 CI jobs pass (MERGEABLE on main).
  • Checked for Apple material, tool attribution, private serials, and board gating: clean; human Signed-off-by present.
Evidence
  • Head: 7a0bc989 (base: main, mergeable: MERGEABLE, +1161/-41 across 15 files).

@RyanTheTide

Copy link
Copy Markdown
Contributor

About the App's "second-Mac regression check": a normal-boot row on another Mac wouldn't run any of the changed C:

  • smp_prepare_guest_rvbar() is reached only from smp_prepare_guest_resets(), which exists only in SPTM_VIRT builds and is dropped by --gc-sections when SPTM_VIRT=0.
  • sptm_virt*.c is guest-only.
  • NO_DISPLAY is a new opt-in make flag that changes no default image.
  • Stage 1 is byte-identical to main.

The rest is proxyclient tooling and host tests, and all 27 non-size CI jobs pass. So the J613 stock-SPTM guest boot at 7a0bc989 is the one row that matters, plus Dj's re-approval.

@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: HOLD at 29883b3a — code and clean main forward-merge remain sound; awaiting queued CI (17 jobs) and the exact-head J613 stock-SPTM guest boot row.

Blockers:

  1. Queued CI at 29883b3a (17 jobs, including Stage 1 size check post-#551) must complete green.
  2. Exact-head J613 stock-SPTM guest boot row at 29883b3a (previously requested after the src/sptm_virt.h flag-bit collision resolution at 7a0bc989; note the non-SPTM_VIRT path is dead-stripped so a second-Mac normal-boot row is not needed per the 11-28 maintainer note).

Checked: Clean main forward-merge commit 29883b3a (overlap only in Makefile), MERGEABLE status, and prior code audit at 7a0bc989.

Evidence
  • 29883b3a merges main cleanly (MERGEABLE), preserving the semantic _find_apsts_polls() matcher and src/sptm_virt.h reconciliation unchanged.
  • Note: merge commit 29883b3a has no Signed-off-by: trailer; confirm policy CI passes on the merge commit.

@RyanTheTide

Copy link
Copy Markdown
Contributor

@satchlj #551 (the Stage 1 size fix) has landed, and I merged current main into this branch. The head is now 29883b3a. Hosted CI for that head is queued behind a long Actions backlog.

I checked the forward-merge's src/sptm_virt.h resolution at 29883b3a. The host-config flags are now unique: BIT(0)-BIT(8), then BIT(10)-BIT(12), with bit 9 deliberately left free for the auractl runner. Default images stay byte-identical, and the changed C only exists in SPTM_VIRT builds.

One row is still owed, and only a J613 can run it (our lab has none): a stock-SPTM guest boot on your J613 at 29883b3a, with the same steps as your earlier row. Please post the guest log lines here.

If there's no row by 2026-11-30 14:00 AEDT, I'll merge once CI is green and the App verdict is FINISH, file the J613 row as a known-gap issue, and track it there. That fallback is only acceptable because no default image changes.

@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) and removed ci-failing A check failed at the PR head (bot) labels Nov 29, 2026
Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) and removed ci-failing A check failed at the PR head (bot) labels Nov 30, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

Maintainer disposition at 7d91d3f7.

I merged current main (bf76fa29) into the branch. It's a signed-off merge commit with no conflicts; your commits are kept and nothing was force-pushed. The old head's Pytest failures came from main's own red, which #570 fixed. The new head also moves CI onto current main.

Main's new layout vs. this PR: I checked #609 (RELR packing) and #611 (SMP shared state moved to .bss) against this PR, and neither affects it.

  • sptm_virt_low_floor() places SPTM's window above _end, which includes .bss.
  • run_guest_sptm.py resolves symbols with nm against the run base.
  • smp_prepare_guest_rvbar() takes _vectors_start at runtime and only writes smp_reset_stacks[i]. smp_shared_init() seeds those entries before smp_init().

Local checks at 7d91d3f7:

  • Full host pytest: 1678 passed, 28 skipped.
  • clang builds all succeed: CHAINLOADING=1, +ESP_STAGE2=1, RELEASE=1 CHAINLOADING=1 ESP_STAGE2=1, SPTM_VIRT=1 CHAINLOADING=1, and ESP_STAGE2=1 SPTM_VIRT=1 SPTM_VIRT_ESP=1 AURACTL=1 EXTRA_CFLAGS=-Oz. The last one has an ESP vital margin of 158544 B.
  • Stage 1 and ESP Stage 2 sizes are byte-identical to main: ESP Stage 2 headroom is 10104 B with gcc + GNU ld 2.42 and 109016 B with fedora:44.

The J613 row: the changed C runs only in SPTM_VIRT=1 builds, which are opt-in and ship in no default image.

  • Default RELEASE=1 CHAINLOADING=1 and ESP_STAGE2=1 images contain no sptm_virt or smp_prepare_guest symbols.
  • NO_DISPLAY is opt-in.
  • The rest is proxyclient tooling and host tests.

The 11-30 14:00 deadline has passed with no new row, so as maintainers we accept the J613 stock-SPTM guest boot as a known gap under our merge-then-fix rule.

This PR merges once CI is green and the review App approves at the exact head. It will be a squash merge, as you asked, so the early commits that carried the removed export table stay out of main's history. When it merges we'll open a known-gap issue for the J613 row. You're welcome to post your J613 guest log there (same steps as your 4903a22b row: untraced and AURA_ANE_TRACE=1, now 0x1000), or a fix PR if anything regressed.

@DjDeveloperr, could you re-review at 7d91d3f7? Since your approval, the only changes are maintainer forward-merges of main: the SPTM_VIRT_ANE_TRACE bit 11 -> 12 move you already saw, and this clean merge.

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

Superseded 12-01: not a hold under the merge bar (no shown failure). Provenance-only check, runtime not reviewed; follow-ups: verify squash tree vs e8eb54da, runtime disposition

Verdict: Provenance check passed at 7d91d3f.

Checked: The revised squash message now matches the PR description and includes human sign-offs. The PR diff omits the removed artifact, and 17 hosted checks passed. Verify the final squash tree against reviewed tree e8eb54da. Runtime behavior still needs a separate disposition.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Landing plan (closeout): squash merge at 7d91d3f7 only (gh pr merge --squash --match-head-commit 7d91d3f7…). The squash commit's tree is the PR head's merge with main, so none of the removed SPTM-derived history reaches main. Exact commit message:

sptm_virt: boot a stock-SPTM guest on J613

Run a stock (unmodified) SPTM macOS guest under aura's SPTM_VIRT
hypervisor on the J613. This is an opt-in build only: SPTM_VIRT is not set by
any default, release or distribution build. Squashed, so that intermediate
commits that added and then removed a table derived from the SPTM binary
stay out of main's history.

Signed-off-by: Satya Benson <satya@benson.earth>
Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>

@RyanTheTide

Copy link
Copy Markdown
Contributor

Corrected squash message: the guest's SPTM is a stock image patched at runtime by the structural matcher, not unmodified. Exact message:

sptm_virt: boot a stock-SPTM guest on J613

Bring up a stock SPTM image under FEAT_NV2 (SPTM_VIRT) with generic,
ADT-driven host support. The SPTM image is patched at runtime when it is
loaded: a structural matcher finds its readiness polls, failing closed on
zero or more than two sites. There are no per-image tables. Also: AMCC
lock-region parsing from /chosen/lock-regs/amcc for every non-T8142 chip,
guest secondary RVBAR publishing, a bounded AURA_ANE_TRACE ring, an
optional NO_DISPLAY=1 headless build, and run_guest_sptm.py console fixes.

This is an opt-in build only: SPTM_VIRT is not set by any default, release
or distribution build. Squashed, so that intermediate commits that added and
then removed a table derived from the SPTM binary stay out of main's history.

Signed-off-by: Satya Benson <satya@benson.earth>
Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>

@RyanTheTide

Copy link
Copy Markdown
Contributor

Consolidated review at 7d91d3f7 (closeout, an independent adversarial review by a different model; the full list is here, nothing more will follow). @satchlj, fix the two blockers and #298 merges (by squash). Everything else can be a follow-up.

Blockers

  1. T6050 can no longer boot under SPTM_VIRT (src/sptm_virt_s2.c ~512-528, 614-616, 646-650; src/sptm_virt.c ~353). On main, chips other than T8142 left the AMCC unhooked. Now sptm_virt_load() refuses and sptm_virt_s2_setup() panics unless lock-regs matches mcc_plane_info(), and there's no MCC driver for mcc,t6050. That means every J716c/K116s guest boot is refused, and the lab's K114s HV work uses that path. T6040/T8140 also now depend on the aperture order matching mcc_regs[] (compacted by amcc-enable-mask). Fix: match apertures to /arm-io/mcc reg[amcc-reg-idx+i] by address where there's no MCC driver, or keep main's unhooked behaviour on chips with no proof row.
  2. Accesses that aren't 32-bit reach the real AMCC registers (amcc_hook, ~587-601). The shadow only applies at width == 2, so a 64-bit STR at the lock offset or offset-4, an STP, or a byte/halfword store writes the real lock/limit/enable/write-disable registers. That contradicts "keep the host's real AMCC locks untouched". Fix: refuse (return false, so the guest faults) any access other than 32-bit that overlaps a shadowed register or the cache-status word, with tests for both offsets.

Follow-ups (minor)
3. The shadow table has no cross-core lock (~536-556): two cores missing at once can take the same slot. Pre-fill it at setup (napertures×nplanes×nbanks×5), or take a spinlock.
4. T8142 behaviour change (~599): an unwritten lock read used to pass through to hardware; it now allocates an entry and returns 0.
5. Cache-status reads are always faked and writes are dropped (~588-595): document why that's safe, or fake only until the real value matches.
6. smp.c ~1551-1558: a running secondary with an unlocked, wrong RVBAR is still written. Refuse any running secondary.
7. ANE ring (sptm_virt_gpu.c ~171-172): the full check runs before an unlocked slot reservation, so concurrent cores can overwrite the oldest records (memory-safe, because the index wraps).

Nits: limit the APSTS scan to the executable segment and drop the unused APSTS tuple (the 5-instruction match, the 0/>2 refusal and the expected-word check are sound). NO_DISPLAY is also read from the environment. The ctrr_stash_off is None guard is dead code. The ANE trace window limit of 10 may panic on bigger chips.

Checked and fine: no Apple-derived data in the final diff; nothing reachable without SPTM_VIRT; the ADT bounds and the 640/8 limits are enforced before any write; partial banks are refused; the Python tooling can't mispatch.

If there's no update by 2026-12-02 12:00 AEDT, we'll fix the two blockers ourselves on this branch, with your authorship kept. The J613 row stays a known gap as posted; the fix needs a T6050 (K114s) and a J616s admission row, which our lab will run.

Two fixes from the aurora-silicon#298 closeout review.

A chip with no MCC driver (T6050) has no planes to check
/chosen/lock-regs/amcc against, so the lock-regs path refused every
guest load and panicked in setup. Such a chip is admitted again and its
AMCC left unhooked, as before the lock-regs shadow.

The shadow and the cache-status fake only model 32-bit accesses. A
byte, halfword, 64-bit or pair access that overlaps a shadowed register
went to the real AMCC lock, limit, enable or write-disable registers.
Such an access is now refused, so the guest takes the fault.
@RyanTheTide

Copy link
Copy Markdown
Contributor

Fixed forward as announced, since the 12:00 deadline passed without an update. One commit on top of 7d91d3f7, 00d7e7f0 (fast-forward; your commits and authorship are unchanged):

  1. T6050 boots under SPTM_VIRT again. A chip with no MCC driver (mcc_plane_info(0) fails, as on T6050) is admitted again by sptm_virt_s2_admit(), and sptm_virt_amcc_watch() leaves its AMCC unhooked, as on main. Chips that do have an MCC driver still need a matching /chosen/lock-regs/amcc node.
  2. Accesses that aren't 32-bit no longer reach the real AMCC registers. amcc_hook() now refuses (return false, so the guest faults) any access other than 32-bit that overlaps a shadowed bank register or the faked cache-status register. That covers a 64-bit STR at the lock offset or offset-4, STP/pairs, and byte or halfword stores. The T8142 plane-offset locks get the same check.

Tests: tests/python/test_sptm_amcc_lockregs.py gains the overlap cases (lock, offset-4, pairs, byte, halfword, cache status, the T8142 mask, pass-through elsewhere) and the no-MCC-driver admission case. On main 0745e344 + this branch: gcc normal + ESP_STAGE2 build pass, CI gcc 13.3 size check pass (ESP Stage 2 headroom 4752 B, unchanged), pytest 1818 passed.

Follow-ups 3-7 and the nits stay follow-ups, as in the review. Still open before the squash: one approval at this head, plus the T6050 and J616s admission rows.

@satchlj

satchlj commented Dec 2, 2026

Copy link
Copy Markdown
Member Author

T6050 admission verification at exact head 00d7e7f0 on Apple M5 Max Mac Studio (J775c, Mac17,14, chip_id=0x6050, board_id=0x10, OS FW 27.0 / System FW 27.2, Stage 2 built with USE_CLANG=1 CHAINLOADING=1 ESP_STAGE2=1 SPTM_VIRT=1 SPTM_VIRT_ESP=1 AURACTL=1 DEBUGUSB_PROXY=1 EXTRA_CFLAGS=-Oz, one-shot trial attached over DebugUSB KIS proxy):

  • Boot banner & MCC init:
    • aura 1.0.0b17-g00d7e7f0
    • MCC: Unsupported version:mcc,t6050
  • Live proxy checks against 00d7e7f0 (aura-raw.elf symbols at runtime base 0x10004d94000):
    • mcc_plane_info(0) = -1 (amcc_undriven() == true)
    • sptm_virt_requested() = 1
    • sptm_virt_s2_admit() = 1 (admitted)
    • sptm_virt_place() = 0, managed window [0x1001e000000, 0x10fcf400000)
    • sptm_virt_load(0x1001e004000, 0x1001e100000) (valid rev 2 ver 2 handoff boot_args) = 0:
      SPTM-virt: handoff boot_args rev 2 ver 2 virtBase 0xfffffe001e000000 physBase 0x1001e000000 memSize 0x40000000 top 0x1001e200000
      SPTM-virt: images recorded, entry 0x1001e004000 handoff 0x1001e100000; ready to enter
      
    • sptm_virt_s2_setup() returned cleanly without panic:
      HV: Initializing for 42-bit PA range
      SPTM-virt[guard]: aura image [0x10004d94000, 0x100050fc000) unmapped from the guest
      SPTM-virt[guard]: aura carve-out [0x10010000000, 0x1001e000000) unmapped from the guest
      SPTM-virt[amcc]: no MCC driver for this chip; AMCC left unhooked
      SPTM-virt[s2]: stage 2 deferred to each CPU's XNU entry: identity [0, 0x20000000000), vuart at 0x505200000 irq 1359 -> iodev 1, 52 tables at 0x10010510000 sum 0xe1625b7feaf5542c
      
  • Clean reboot back to default Linux after the checks.
  • Note: this verifies T6050 admission (sptm_virt_s2_admit, sptm_virt_load) and full Stage 2 setup (sptm_virt_s2_setup / sptm_virt_amcc_watch leaving AMCC unhooked); actual guest entry into macOS was not run here (no 27.2 export in this PR).

@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: MERGE at 00d7e7f

This is one round on the fix-forward delta 7d91d3f7..00d7e7f0. It is checked against the two blockers in the consolidated review.

  1. T6050 admission works. amcc_undriven() (mcc_plane_info(0) < 0) admits a chip that has no MCC driver, and sptm_virt_amcc_watch() returns before the lock-regs panic. AMCC stays unhooked, as on main. Chips with an MCC driver keep the lock-regs requirement. Satya's J775c (T6050) row at this exact head shows admit=1, load=0 and a clean sptm_virt_s2_setup() with "AMCC left unhooked".
  2. Accesses that are not 32-bit are refused. amcc_wide_touches_shadow() runs before any shadow or pass-through path. The HV decoder reports a W-register LDP/STP as width 3 and an X-register pair as width 4, so 1 << width covers the full 8 or 16 bytes. A byte, halfword, 64-bit or pair access that overlaps a lock-regs bank register, the cache-status word, or a T8142 nolock offset now returns false (the guest faults). A 32-bit access that does not overlap passes through unchanged.

Checked: I traced the width encoding in src/hv/hv_vm.c (the pair decode and the SPTE_HOOK call). tests/python/test_sptm_amcc_lockregs.py at the head passes 5/5. The same tests against the pre-fix src/sptm_virt_s2.c (7d91d3f) fail 3/5, including test_wide_access_over_shadow_refused and test_chip_without_mcc_driver_stays_unhooked, so the new tests do detect both bugs. CI is green at the head.

Follow-ups (not blocking):

  • amcc_undriven() cannot tell "no driver for this chip" from "a driver whose init failed", so the second case would also be admitted unhooked. A chip_id allowlist would make that case explicit.
  • T6040/T8140 still depend on the lock-regs aperture order matching mcc_regs[]. A mismatch refuses admission; it does not corrupt anything. Matching by address would remove that dependency.
  • Follow-ups 3-7 and the nits from the consolidated review are still open.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging by squash at 00d7e7f00b47, per the 11-30 landing plan. Gate: the App approved this exact head (one round on the fix-forward delta). Row: satchlj's J775c (M5 Max, T6050) admission row at this head. Fast CI: main 0745e344 + this branch passes gcc normal + ESP_STAGE2, the CI gcc 13.3 size check (4752 B) and pytest 1818. The squash message is the agreed one, with one clause added for the T6050 / wide-access fix. The J613 row stays the known gap noted earlier. Revert: git revert <squash sha>.

@RyanTheTide
RyanTheTide merged commit bf936cf into aurora-silicon:main Dec 2, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (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.

3 participants