Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
184c074
build: expose headless Stage 1 option for J613 proxy host
satchlj Nov 17, 2026
fa27578
Prepare fail-closed T8122 stock-SPTM profile and resident ANE capture
satchlj Nov 11, 2026
6677564
run_guest_sptm: do not drain KIS after guest entry
satchlj Nov 17, 2026
ce7c5d9
run_guest_sptm: avoid USB CDC drain after entry
satchlj Nov 17, 2026
9a95dbc
sptm: bind partial J613 clean-room export
satchlj Nov 17, 2026
37364bb
sptm: shadow exact T8122 AMCC contract
satchlj Nov 17, 2026
bdf4820
sptm: admit exact J613 stock path
satchlj Nov 17, 2026
db764e7
j613: boot stock SPTM guest on all cores
satchlj Nov 18, 2026
f528865
ci: format stock SPTM changes and update RVBAR harnesses
satchlj Nov 18, 2026
bb1b562
tests: model host RVBAR addresses in harnesses
satchlj Nov 18, 2026
19bc546
tests: fall back to make when gmake is absent
satchlj Nov 18, 2026
ce3aa7c
smp: publish RVBAR only on the stock-SPTM guest reset path
satchlj Nov 20, 2026
01e86d0
sptm: read the AMCC guest shadow from /chosen/lock-regs/amcc
satchlj Nov 20, 2026
fecefc8
sptm_virt_gpu: take the ANE trace windows from the ADT
satchlj Nov 20, 2026
57c7238
run_guest_sptm: select a clean-room SPTM export by image, not 25G83
satchlj Nov 20, 2026
8550bdb
sptm_virt_gpu: trace the ANE DART's DAPF slices from the ADT
satchlj Nov 20, 2026
33e5742
Merge branch 'main' into j613-stock-sptm-upstream
satchlj Nov 25, 2026
cd7a9b1
sptm_virt: replace 25G83 export with semantic APSTS matcher and live-…
satchlj Nov 25, 2026
4903a22
smp: publish RVBAR for powered-off locked A7-M3 secondaries in guest …
satchlj Nov 25, 2026
7a0bc98
Merge main into sptm-virt J613 stock-SPTM guest
RyanTheTide Nov 27, 2026
29883b3
Merge branch 'main' into j613-stock-sptm-upstream
RyanTheTide Nov 29, 2026
7d91d3f
Merge branch 'main' into j613-stock-sptm-upstream
RyanTheTide Nov 30, 2026
00d7e7f
sptm_virt: keep T6050 booting and refuse wide AMCC shadow accesses
RyanTheTide Dec 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ ifeq ($(BRINGUP),1)
CFG += BRINGUP
endif

# Proxy-only Stage 1 images can run headless. This selects display.c's existing
# NO_DISPLAY path without changing the default or any installed boot image.
ifeq ($(NO_DISPLAY),1)
CFG += NO_DISPLAY
endif

ifeq ($(CHAINLOADING),1)
CFG += CHAINLOADING
CARGO_FLAGS += --features chainload
Expand Down
43 changes: 40 additions & 3 deletions proxyclient/aura/sptm_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,59 @@ def _b(src, dst):
return 0x14000000 | ((dst - src) & 0x3FFFFFF)


def _find_apsts_polls(words):
"""Find the APSTS readiness-poll CBZ instructions in any SPTM build.

Each poll spins on bit 0 of S3_6_C15_C12_4 before setting bit 0 of S3_4_C15_C0_4:
mrs xA, S3_6_C15_C12_4
and xB, xA, #1
cbz xB, .-8
mrs xA, S3_4_C15_C0_4
orr xA, xA, #1
The register pair (xA, xB) differs across builds and across primary/secondary entry
paths in the same image, so match the 5-instruction architectural sequence structurally.
"""
hits = []
for i in range(len(words) - 4):
w0 = words[i]
if (w0 & 0xFFFFFFE0) != 0xD53EFC80:
continue
reg_a = w0 & 0x1F
if reg_a == 31:
continue
w1 = words[i + 1]
if (w1 & 0xFFFFFC00) != 0x92400000 or ((w1 >> 5) & 0x1F) != reg_a:
continue
reg_b = w1 & 0x1F
if reg_b == 31:
continue
if (words[i + 2] == (0xB4FFFFC0 | reg_b) and
words[i + 3] == (0xD53CF080 | reg_a) and
words[i + 4] == (0xB2400000 | (reg_a << 5) | reg_a)):
hits.append(i + 2)
return hits


def plan(image, entry_off):
"""The patches for one SPTM image: a dict with
patches: [(what, offset from entry, mask, expected, replacement)],
ctrr_stash_off: SPTM's CTRR stash offset (aura's sptm_virt_ctrr_stash_off; 0 if it has no
CTXR checks),
mte: (offset from entry, expected words, replacement words) or None.
Raises SptmPatchError if a site is missing or not unique."""
Raises SptmPatchError if a site is missing or outside its expected count."""
words = _words(image)
e = entry_off // 4
out = []

def patch(what, i, new):
out.append((what, 4 * (i - e), 0xFFFFFFFF, words[i], new))

i = _one(words, APSTS, "APSTS poll") + 5
patch("APSTS poll", i, NOP)
apsts = _find_apsts_polls(words)
if not 1 <= len(apsts) <= 2:
raise SptmPatchError(
f"APSTS poll: {len(apsts)} matches in this SPTM, need one or two")
for i in apsts:
patch("APSTS poll", i, NOP)
stash = 0
if CTXR_MARKER in image:
c = _one(words, CTRR, "CTRR check") + 6
Expand Down
75 changes: 60 additions & 15 deletions proxyclient/tools/run_guest_sptm.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
AURA_SAMPLE sample the guest's PC until each core's XNU entry (pre-XNU hangs)
AURA_SAMPLE_HZ=<n> samples per second (default 4)
AURA_SAMPLE_MAX=<n> stop printing after n samples (default 64)
AURA_ANE_TRACE trace the ANE, its DART and the AIC (windows from the ADT) into a
bounded ring, and park when it is full
AURA_XNU_ENTRY patch the guest kernelcache's acct(2) so a root process reaches aura's
control hvc with no kext (the auractl "xnu" entry; aura/auractl_xnu.py)
AURA_XNU_RO_RELAX patch XNU's zalloc_ro_mut RO-zone panic out (tracing only; XNU_QUIRKS)
Expand Down Expand Up @@ -121,6 +123,7 @@
"AURA_S2R_DROP_USB": 1 << 4,
"AURA_XNU_BT": 1 << 5,
"AURA_GPU_TRACE": 1 << 6,
"AURA_ANE_TRACE": 1 << 12,
"AURA_SAMPLE": 1 << 7,
"AURA_S2R_MEM": 1 << 8,
# bit 9 is reserved for AURA_AURACTL in the feat/auractl runner
Expand Down Expand Up @@ -402,6 +405,15 @@ def aura_heap_size(adt):
return (112 if j813 else 128) * 1024 * 1024


def post_entry_drain_needed(iface):
"""A device-side USB serial endpoint can stop accepting OUT as the guest enters."""
if iface.is_kis:
return False
port = iface.devpath or getattr(iface.dev, "port", "") or ""
device = os.path.basename(os.path.realpath(port))
return not device.startswith(("ttyACM", "cu.usbmodem", "tty.usbmodem"))


def parse_args():
ap = argparse.ArgumentParser(description="Boot the stock SPTM as an NV2 guest under aura")
ap.add_argument("--sptm", type=pathlib.Path, required=True, help="sptm.bin (flat Mach-O)")
Expand Down Expand Up @@ -645,8 +657,9 @@ def patch_sptm(p, sym, entry, sp):
print(f"{what}: [0x{pa:x}] 0x{before:08x} -> 0x{p.read32(pa):08x}")
if sp["mte"]:
rewrite_sptm_seq(p, sym, entry, sp["mte"])
p.write32(sym["sptm_virt_ctrr_stash_off"], sp["ctrr_stash_off"])
print(f"SPTM: CTRR stash +0x{sp['ctrr_stash_off']:x}")
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}")


def amcc_status(adt):
Expand Down Expand Up @@ -849,13 +862,18 @@ def configure(p, sym, plan, adt, ctl_cookie=0):


def tail_console(iface, secs, idle):
"""Keep reading the console after the entry call: a serial read error reopens the device,
and the tail stops after secs, or after idle seconds of silence."""
"""Keep reading the console after entry, including across KIS re-enumeration.

Darwin does not reliably revive a pyserial object whose underlying device vanished. Throw
that object away and construct a fresh one on the same physical KIS path instead. Time spent
waiting for the node is not console silence, but it remains bounded by the overall tail window.
"""
import serial

end = time.time() + secs
last = time.time()
dev = iface.dev
serial_cls = type(dev)
buf = b""
print(f"--- tailing console for up to {secs}s (stop after {idle:g}s silent) ---", flush=True)
while time.time() < end:
Expand All @@ -867,21 +885,43 @@ def tail_console(iface, secs, idle):
# loops until full or timeout and discards buffered bytes if the link resets mid-read.
chunk = dev.read(max(1, min(4096, dev.in_waiting)))
except (serial.serialutil.SerialException, OSError) as e:
lost = time.time()
devpath = getattr(iface, "devpath", None)
print(f"--- tail: read error ({e}); reopening ---", flush=True)
try:
dev.close()
except Exception:
pass
for _ in range(100):
try:
dev.open()
print("--- tail: reopened ---", flush=True)
if devpath:
dev = None
while time.time() < end:
if not os.path.exists(devpath):
time.sleep(0.1)
continue
try:
dev = serial_cls(devpath, iface.baudrate)
dev.timeout = min(1, max(0.05, end - time.time()))
iface.dev = dev
gap = time.time() - lost
last += gap
print(f"--- tail: reopened after {gap:.3f}s ---", flush=True)
break
except (serial.serialutil.SerialException, OSError):
time.sleep(0.1)
else:
print("--- tail: device gone ---", flush=True)
break
except (serial.serialutil.SerialException, OSError):
time.sleep(0.2)
else:
print("--- tail: device gone ---", flush=True)
break
for _ in range(100):
try:
dev.open()
print("--- tail: reopened ---", flush=True)
break
except (serial.serialutil.SerialException, OSError):
time.sleep(0.2)
else:
print("--- tail: device gone ---", flush=True)
break
continue
if not chunk:
continue
Expand Down Expand Up @@ -941,7 +981,7 @@ def main():
entry_off = plan_mod.macho_info(images["sptm"]).entry - plan_mod.macho_info(images["sptm"]).virtlo
try:
sp = sptm_patch.plan(images["sptm"], entry_off)
except sptm_patch.SptmPatchError as e:
except (sptm_patch.SptmPatchError, ValueError) as e:
raise SystemExit(f"this SPTM can't be patched: {e}")
print(f"SPTM: {len(sp['patches'])} patch sites found"
+ (", MTE tag-storage sequence found" if sp["mte"] else ""))
Expand Down Expand Up @@ -985,7 +1025,8 @@ def main():
quirk_hide = tuple(quirks["hide"])
if env_on("AURA_KEEP_WIFI"):
quirk_hide = tuple(n for n in quirk_hide if n in port_nodes)
hide = port_nodes + (() if env_on("AURA_KEEP_ANE") else STRIP_NODES) + quirk_hide
keep_ane = env_on("AURA_KEEP_ANE") or env_on("AURA_ANE_TRACE")
hide = port_nodes + (() if keep_ane else STRIP_NODES) + quirk_hide
if not env_on("AURA_KEEP_ERRH"):
hide += (ERROR_HANDLER,)
if env_on("AURA_HIDE_DOCKCHANNEL"):
Expand Down Expand Up @@ -1088,7 +1129,11 @@ def main():
# sptm_virt_enter does not return. Waiting for a reply or a boot banner would eat the guest's
# first console output and reopen the link.
p.request(p.P_CALL, sym["sptm_virt_enter"], no_reply=True)
iface.dev.flush()
# Once a USB target enters the guest it can stop consuming host OUT immediately. The enter
# request is already queued by write(); tcdrain here can then block forever and prevent the
# console tail from reading the guest's first output. Real UARTs retain the drain.
if post_entry_drain_needed(iface):
iface.dev.flush()
secs = env_int("AURA_TAIL_SECS")
if secs > 0:
tail_console(iface, secs, float(os.environ.get("AURA_TAIL_IDLE") or 10))
Expand Down
30 changes: 29 additions & 1 deletion src/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,33 @@ static u64 smp_guest_mpidr(int i)
return (u64)(cpu->reg & 0xffff) | (aff2 << 16);
}

/*
* The stock-SPTM guest's reset contract. A7 to M3 leave RVBAR writable on a powered-off secondary
* core (and writing it clears RVBAR_LOCK, as smp_start_cpu() does); the ordinary SMP path writes
* it only in smp_start_cpu() just before releasing a core, whereas here the guest performs
* CPUSTART itself. Publish this image's vector now and read it back. A running core's locked RVBAR
* is never written (a store to a running locked core takes an SError on T8122); on M4+,
* smp_prepare_rvbar() checks or installs the locked-RVBAR relay.
*/
static int smp_prepare_guest_rvbar(const struct cpu_info *cpu)
{
u64 target = (u64)_vectors_start;
u64 rvbar = read64(cpu->impl_reg);

if (!cpu_features->apple_sysregs_unlocked)
return smp_prepare_rvbar(cpu);
if ((rvbar & RVBAR_ADDR_UNLOCKED) == target && !(rvbar & RVBAR_LOCK))
return 0;
if ((rvbar & RVBAR_LOCK) && (read64(cpu->impl_reg + 0x100) & 0xff))
return (rvbar & RVBAR_ADDR_UNLOCKED) == target ? 0 : -1;
if (target & ~RVBAR_ADDR_UNLOCKED)
return -1;
write64(cpu->impl_reg, target);
sysop("dsb sy");
rvbar = read64(cpu->impl_reg);
return !(rvbar & RVBAR_LOCK) && (rvbar & RVBAR_ADDR_UNLOCKED) == target ? 0 : -1;
}

/*
* Under the virtualized SPTM every core enters the guest through a hardware reset, as natively:
* XNU starts a core with PMGR CPUSTART, and a core that power-gates in idle or sleep comes back
Expand Down Expand Up @@ -1564,7 +1591,8 @@ int smp_prepare_guest_resets(void)
}
smp_reset_stacks[i].mpidr = mpidr;
smp_reset_stacks[i].stack = (u64)cpu_stack(i) + SECONDARY_STACK_SIZE;
rc = smp_prepare_rvbar(cpu);
rc = smp_prepare_guest_rvbar(cpu);
rvbar = read64(cpu->impl_reg);
}
/* A secondary must be powered off here: XNU's CPUSTART only resets a core that is
* off, and one left running (an earlier stage's park loop) never reaches SPTM. */
Expand Down
5 changes: 4 additions & 1 deletion src/sptm_virt.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ __attribute__((used, retain)) int sptm_virt_place(struct sptm_virt_placement *ou
{
struct sptm_virt_layout l;

if (!out)
if (!out || !sptm_virt_requested())
return -1;
memset(out, 0, sizeof(*out));
if (sptm_virt_layout(&l) < 0 || sptm_virt_gl_alloc() < 0)
Expand Down Expand Up @@ -349,6 +349,9 @@ __attribute__((used, retain)) int sptm_virt_load(u64 sptm_entry, u64 handoff)
{
struct sptm_virt_layout l;

/* Direct proxy callers must pass the same exact SoC/ADT contract as the host profile. */
if (!sptm_virt_requested() || !sptm_virt_s2_admit())
return -1;
if (sptm_virt_layout(&l) < 0) {
printf("SPTM-virt: load refused, no valid carve-out layout\n");
return -1;
Expand Down
5 changes: 3 additions & 2 deletions src/sptm_virt.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ struct sptm_virt_placement {
#define SPTM_VIRT_SAMPLE BIT(7) /* sample the guest's PC until its XNU entry */
#define SPTM_VIRT_S2R_MEM BIT(8) /* T6050: also hook the MCC and the coprocessor DARTs */
/* bit 9 is AURA_AURACTL in the feat/auractl runner; left free here so the two never clash */
#define SPTM_VIRT_CTL_DCC BIT(10) /* arm auractl's DCC transport (MDCR_EL2.TDCC) at boot */
#define SPTM_VIRT_SEP BIT(11) /* record the SEP mailbox and its OOL buffers (debug only) */
#define SPTM_VIRT_CTL_DCC BIT(10) /* arm auractl's DCC transport (MDCR_EL2.TDCC) at boot */
#define SPTM_VIRT_SEP BIT(11) /* record the SEP mailbox and its OOL buffers (debug only) */
#define SPTM_VIRT_ANE_TRACE BIT(12) /* bounded ANE, ANE DART and AIC trace from the ADT */
/* sptm_virt_s2r_cp_ansx, with COPROC on T6050 */
#define S2R_CP_ANSX_SART BIT(0) /* sart-ans reg[0-2], first page each */
#define S2R_CP_ANSX_NVME BIT(1) /* the NVMe BAR's first page (reg[9]) */
Expand Down
Loading
Loading