Repository navigation
smp: install reset-vector relay for locked boot RVBAR on A7-M3 - #664
Conversation
Commit 3530b01 ("chainload: never copy a stage 2 onto a live coprocessor log") keeps Stage 2 staged above the heap on chips with unlocked Apple system registers (M1 to M3) whenever copying Stage 2 to Stage 1's load base would reach a live coprocessor __OS_LOG buffer (for example os-log@80721c000 at +0x178000 on T8103/J313, or the panel DCP log at +0x120000 on M3). Even on those chips, the running boot core's own RVBAR has RVBAR_LOCK set to Stage 1's load base, and writing that locked register takes an SError. With Stage 2 kept at its staged address, smp_point_rvbar_here() saw RVBAR_LOCK pointing at Stage 1's base instead of Stage 2's vectors, did not install a relay there, and refused to publish /chosen/aurora,s2r-mailbox ("CPU 0 RVBAR is locked at 0x..."), disabling deep sleep. Two pieces are needed to forward that retired Stage 1 vector safely: 1. Recognize a retired Aura image via its immutable AURALOAD load header at CHAINLOAD_HDR_OFFSET (0x808) in smp_old_vector_owned(), keeping the STACKBOT tail scan as a fallback for older images without a load header. A Stage 1 that actually ran overwrites its _stack_bot STACKBOT marker with its first stack frame in _start_c, so the 8-byte-aligned STACKBOT scan missed retired Stage 1 images unless a .rodata copy happened to be 8-byte aligned. 2. Extract the locked-RVBAR relay installer from smp_prepare_rvbar() into smp_relay_locked_rvbar(locked, allow_unverified_forward) (also refusing a second distinct locked address so kboot's single smp_rvbar_relay() reservation cannot lose an earlier page), and call it with allow_unverified_forward=false from smp_point_rvbar_here() in builds that reserve smp_rvbar_relay() (!CHAINLOADING || ESP_STAGE2). The retired Stage 1 vector table gets a branch relay (or an absolute veneer via smp_forward_rvbar() when out of branch range, only after smp_old_vector_owned() verifies it), the locked RVBAR register is never written, and kboot_prepare_dt() reserves the relay's 16 KiB page after dt_set_chosen(). Fixes: 3530b01 ("chainload: never copy a stage 2 onto a live coprocessor log") Signed-off-by: Erik Bourget <erik@ebourget.net>
|
Merge readiness at
Areas: none matched in CODEOWNERS Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Reviewed at ffaa715aaf3e. No blocker found, approving. Hardware rows on M2 Pro, M3 Pro and M4 mini are still owed (listed under "Not yet"); kits for them are ready on our side.
What I checked in the code
- Relay page vs
os-log. The relay is one 16 KiB page at the locked reset vector (Stage 1's load base), reserved inkboot_prepare_dt()afterdt_set_chosen().dt_set_s2r_mailbox()is the only caller ofsmp_resets_return_here(), so the relay is always written before the reservation is made. On J313 and M3 theos-logbuffers sit+0x178000and+0x120000above that base, so the two never overlap. - Recognizing a retired Aura image by its
AURALOADheader. A match needs all of these: the address is in RAM, below the inherited top and the firmware RO range, and outside the running image; the four vector slot words (mov x9, '0'..'3', which don't depend on where the image sits) match; and the magic and version are at+0x808. What sits at the locked address is whatever iBoot loaded on this boot, so an image left over from an earlier boot can't be there. A Stage 1 that isn't Aura (m1n1, for example) has no header, falls back to theSTACKBOTscan and is refused as before. - When the relay can't be installed. Every check runs before anything is written and returns -1. The code then falls through to the old
CPU n RVBAR is lockedpath: no mailbox,aurora,s2r-unavailableis set, and the OS stays on s2idle, the same as today. A failed read-back leavesinstalled_relayat 0, so no page is reserved. Stage 1 builds compile the call out, matching the#ifaround the reservation in kboot. - M4/M5/A18 Pro. The early returns in
smp_prepare_rvbar()are unchanged, and the extracted body runs withallow_unverified_forward = true, so this path gets the same decisions as before with two exceptions. (1) It now refuses a second, different locked address. iBoot locks every core to the same address on these chips, so this can't happen in practice, and it closes a gap where the single reservation could lose the first page. (2) TheAURALOADmatch can mark an image as owned where theSTACKBOTscan used to miss it. The relay then gets a branch instead of the absolute veneer, and both reach the same vectors. T8152 has its own function and is untouched. So "unchanged in effect" holds.
Local checks (exact head; GitHub's refs/pull/664/merge tree is 13b6cb754ed8, the same tree as the head, because the base dfe97a4b9783 is main's tip, so one run covers both):
pytest tests/python/test_smp*.py tests/python/test_chainload_run_base.py: 26 passed. The 4 changed test files alone: 8 passed. The same 4 files run against basedfe97a4b: 6 of 8 fail, so they do test the change.- The full CI set (
pytest tests/python tests/test_t8122_gpu_*.py): 1790 passed, 64 skipped. The 5tests/run-*.shscripts all pass. sh tools/stage1_size.sh gcc ARCH=aarch64-linux-gnu- BUILTIN_LOGO=aurora EXTRA_CFLAGS='-Wstack-usage=2048 -Os'(CI's arguments; gcc 16.2.0 here, CI's gcc-stage1-size job is also green): all 5 builds link. esp-stage2 has 78104 B headroom and 3512 B code room.- The ESP Stage 2 builds with clang 23.1.3 (
BUILDSTD=1 RELEASE=1 CHAINLOADING=1 ESP_STAGE2=1 USE_CLANG=1) as1.0.0b19-gffaa715a.
Small things, not blocking
- The header check needs
CHAINLOAD_HDR_VERSIONto match exactly. If a later version bumps it, a newer Stage 2 over an older Stage 1 falls back to theSTACKBOTscan and may quietly lose deep sleep.>= 1(or the magic alone, since the vector slot words are already checked) would keep working across a bump. - The branch path in
smp_relay_locked_rvbar()writes without the armed-CTRR check thatsmp_forward_rvbar()makes. This was already true of the M4+ path, and Stage 1's base isn't in an armed CTRR range on M1 to M3, so the rows will confirm it rather than this needing a change.
|
Note in English instead of Neonish: M1 Air deep sleep doesn't work without this in stage2 at aura head. With this commit, it does work. |
|
J615 (MacBook Air 13" M3, T8122), firmware 27.2, no-regression row at exact head
Afterwards the Mac went back to its production state ( |
|
J414s (
|
|
J473 (Mac mini M2, T8112), firmware 27.2, at exact head
Afterwards the Mac went back to its production state ( |
|
J516s (M3 Pro, T6030, OS firmware
Observed at boot (
Failure (
|
|
The J516s FAIL above wasn't caused by this PR: #664's new code never ran on that boot. What the M3 Pro boot did:
So this cold boot belongs to main, not to #664. Every earlier J516s deep-sleep row booted the installed Stage 2 (b17 One thing seen along the way: in Linux's memblock, the old-base page Fix: none in this PR. Next is a control row on J516s with a plain main |
|
Control row on MacBook Pro 16-inch (M3 Pro, J516s, T6030, OS firmware 27.2) booting
Conclusion: |
|
Correction to the J516s control reading above (
That makes #529's wake-time PCIe replay the prime suspect. It's unproven: we have no serial or DockChannel capture of the wake. Next, an A/B on J516s with the same This doesn't change this PR's status: #664 didn't cause the cold boot. |
|
J773g (Mac mini M4, T8132, OS fw
|
|
Paired A/B deep-sleep wake diagnostic on J516s (
Additional verification from Arm N (
Conclusion: aura#664 is cleared. The J516s deep-wake cold boot on |
What: Install a reset-vector relay at a verified retired Stage 1 Aura image when
smp_point_rvbar_here()finds a core's RVBAR locked on A7–M3, and recognize retired Aura images insmp_old_vector_owned()via their immutableAURALOADheader. Fixes the S2R regression from #554 (3530b019), where keeping Stage 2 staged above a live coprocessor__OS_LOGbuffer left CPU 0's locked RVBAR pointing at Stage 1 and caused Aura to withhold/chosen/aurora,s2r-mailbox.Tested: J313 M1 Air (T8103, OS fw 27.2) at
ffaa715a(Stage 21.0.0b19-gffaa715aunder Stage 11.0.0b19-gdfe97a4b):/chosen/aurora,s2r-mailboxpublished, 16 KiB relay page reservedNOMAPbelowos-log, 2/2 RTC-woken deep sleep cycles (boot object resumes 0 -> 1 -> 2), SEP/GPU/PCIe/Wi-Fi/CPUs 0–7 recovered cleanly (plus 3/3 cycles on Linuxmain5bb2f1eed073at the prior commit0a6a22d9); 26/26 SMP/chainload host tests pass; all 5tools/stage1_size.shGCC builds pass.Risk: two-way door · M1, M2, M3 (new S2R relay path) and M4/M5/A18 Pro (shared
smp_relay_locked_rvbar()extraction, unchanged behavior)Not yet: hardware rows on M2, M3, and M4/M5/A18 Pro.
Details
Commit
3530b019(#554, "chainload: never copy a stage 2 onto a live coprocessor log") keeps Stage 2 staged above the heap on chips with unlocked Apple system registers (M1–M3) whenever copying Stage 2 to Stage 1's load base would overlap a live coprocessor__OS_LOGbuffer (on J313,os-logsits+0x178000above Stage 1's base; on M3, the panel DCP log sits at+0x120000).Because the running boot core's own RVBAR still carries
RVBAR_LOCKpointing at Stage 1's load base (and storing to a locked RVBAR register takes an SError),smp_point_rvbar_here()refused to publish/chosen/aurora,s2r-mailbox(CPU 0 RVBAR is locked at 0x...), disabling deep sleep.Two changes fix this forward without reverting #554 or writing to a locked RVBAR register:
smp_old_vector_owned()): A Stage 1 that actually ran overwrites its_stack_botSTACKBOTmarker with its first stack frame in_start_c, so the 8-byte-alignedSTACKBOTscan missed retired Stage 1 images unless a.rodatacopy happened to land 8-byte aligned (in1.0.0b19-gdfe97a4b,.rodataSTACKBOTwas at0xd3ddb,mod 8 == 3). Check the immutableAURALOADload header (CHAINLOAD_HDR_MAGIC+CHAINLOAD_HDR_VERSION) atCHAINLOAD_HDR_OFFSET(0x808) after matching the four vector slot tags (0x0..0x180), keeping theSTACKBOTscan as a fallback for older images without a load header.smp_point_rvbar_here(): Extract the relay installer fromsmp_prepare_rvbar()intosmp_relay_locked_rvbar(u64 locked, bool allow_unverified_forward)(also refusing a second distinct locked address sokboot_prepare_dt()'s singlesmp_rvbar_relay()reservation cannot lose an earlier page). Call it withallow_unverified_forward = falsefromsmp_point_rvbar_here()under#if !defined(CHAINLOADING) || defined(ESP_STAGE2)(matchingsrc/kboot.c:15738), so:smp_forward_rvbar()) over a verified retired Aura image (smp_old_vector_owned()), never over an unverified page or Mach-O header,kboot's relay reservation never install an unreserved relay,smp_prepare_rvbar()keepsallow_unverified_forward = truewith unchanged M4/M5/A18 Pro behavior, andkboot_prepare_dt()reserves the 16 KiB relay page afterdt_set_chosen().Evidence
1.0.0b19-gdfe97a4b, Stage 21.0.0b19-gdfe97a4b, Linuxmaind6e13deca924):/proc/device-tree/chosen/aurora,s2r-unavailable:CPU 0 RVBAR is locked at 0x8070a4000apple-sleep 23b700000.sleep-controller: no aurora,s2r-mailbox from the boot object: no deep sleep/sys/power/mem_sleep:[s2idle]ffaa715aaf3e(J313 M1 Air, Stage 11.0.0b19-gdfe97a4b, Stage 21.0.0b19-gffaa715a, Linux 7.3.0):/proc/device-tree/chosen/aurora,s2r-mailboxpublished;/sys/power/mem_sleep:s2idle [deep]/sys/kernel/debug/memblock/memory: 16 KiB relay page0x805398000..0x80539bfffreservedNOMAP,0x178000belowos-log(0x805510000..0x80555bfff), Stage 2 at0x8073e0000..0x807807fffrtc1,apple-pmu-rtc) deep sleep cycles:0-7online,/dev/hwrngreturns live entropy, 0 new failed units (only pre-existing J313 speaker protection units).main5bb2f1eed073check (at0a6a22d9, before the 1-line Mach-O header gate): 3/3 consecutive 15 s deep sleep cycles (boot object resumes 0 -> 1 -> 2 -> 3, relay page0x806dd0000..0x806dd3fffreservedNOMAP, SEP/GPU/PCIe/Wi-Fi/CPUs 0–7 recovered cleanly).pytest tests/python/test_smp*.py tests/python/test_chainload_run_base.py): 26/26 passed (including newAURALOADownership, unowned near/far/header EL2 refusal, owned branch/veneer relay, distinct-address guard, and Stage 1 build omission tests).sh tools/stage1_size.sh gcc ARCH=aarch64-linux-gnu- BUILTIN_LOGO=aurora):gcc stage1:_file_vital_end 0x104cd0 of 0x120000; room code 888, data 111408; headroom 111408 Bgcc esp-stage2:_file_vital_end 0x10cee8 of 0x120000; room code 4144, data 78104; headroom 78104 B