Skip to content

kboot: let an OS at EL2 return from its own sleep - #117

Closed
DjDeveloperr wants to merge 1 commit into
mainfrom
feat/t8140-s2r-return
Closed

DjDeveloperr wants to merge 1 commit into
mainfrom
feat/t8140-s2r-return

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

An OS that aura starts at EL2 has no monitor below it, so it powers cores off and suspends the system itself. From M4 on, the Neo's A18 Pro included, iBoot locks every core's reset vector to the boot object, so a wake restarts each core inside aura. On main the boot core then reruns aura's boot flow over the live OS, so Linux can't deep-sleep (the Neo only gets s2idle).

What it enables

When the OS runs at EL2 and resets come back into this image, kboot publishes /chosen/aurora,s2r-mailbox, the physical address of a 32-byte mailbox (magic, boot_mpidr, resume_pa, resumes):

  • On a reset with the mailbox published, the boot core jumps to the resume_pa the OS left, at EL2 with the MMU and caches off and interrupts masked. If the OS left none, it reboots.
  • A secondary comes back through its spin table entry, which still holds the OS's release address, so that path doesn't change.

Once the mailbox is published, the reset paths stop printing, since the OS owns the UART and the display.

There's no option. The CPUs keep spin-table, which every kernel knows, and the property is the whole contract: a kernel that reads it may power its spin-table CPUs off, and one that doesn't ignores it. Whether to deep-sleep stays the OS's choice (mem_sleep on Linux).

What's chip-specific

Only the locked RVBAR. "Resets come back into this image" means a running secondary's RVBAR is locked at an address that reaches this image's vectors: the vectors themselves, a relay this stage installed, an earlier stage's branch here, or the old base a relocated stage forwards from. That's the same address smp_prepare_rvbar() accepted before starting the core. iBoot locks every core's to the same address, the boot core's included. No new hardware is read.

  • From M4 on (A18 Pro, M4, M5 and their variants), any OS at EL2 gets the mailbox.
  • A7 to M3 don't lock RVBAR, so the OS can point it anywhere, and nothing is published.
  • A guest under aura's hypervisor runs at EL1 and gets nothing.

Memory

The feature adds only the 32-byte mailbox, in aura's .data next to the spin tables. That's inside aura's image, which kboot already reserves for every OS because RVBAR and the spin-table release addresses point into it. Nothing new is reserved.

Where it comes from

It's the return path from the T8140 sleep work (feat/s2r-el2-test 5ecf1d8), ported onto main and made generic. Every Linux deep sleep on the Neo since 2026-11-06 ran on that code: hundreds of sleep and wake cycles, including an 8/8 soak. That Stage 2 published the mailbox behind an opt-in chosen.aura,s2r=1 line, on T8140 only, and switched the CPUs' enable-method to aurora,rvbar-spin-table. A kernel without that method leaves the CPU off, so this keeps spin-table and lets the mailbox say it instead. That branch also wrote a diagnostic PMU scratch mark on each return; it stays out. Its PCIe tunables stay out too, because #112 replaces them.

Depends on

Tested

  • Each configuration builds after make clean, with clang 23.1.1 and GNU make 4.4.1: CHAINLOADING=1, plus CI's Stage 1 (RELEASE=1 CHAINLOADING=1 BUILTIN_LOGO=aurora) and ESP Stage 2 (RELEASE=1 CHAINLOADING=1 ESP_STAGE2=1 BUILTIN_LOGO=aurora). The ESP Stage 2 has 17388 B of .text left. clang-format 20.1.8 is clean, and pytest passes (598 passed, 47 skipped).
  • Hardware row on the J700 (MacBook Neo), 2026-11-08: a Stage 2 of this PR and Publish APCIe ANS recovery tables with atomic packed-DT export #112 (1.0.0b9-g7b25e6d1) booting a kernel of the sleep series plus the generic-mailbox change. aura published the mailbox, the CPUs kept spin-table, and the kernel took the parking ops ("spin-table CPUs can park: the boot object brings them back"). 5 of 5 deep sleeps committed and came back, suspend_stats fail 0, boot object resumes 0 → 5, so the boot core returned through the mailbox every time. Wi-Fi, NVMe, audio and the panel were back after every wake, with no crash lines.
    • The debug cable stayed plugged in, and the kernel cuts the debug link at sleep, so the SMC woke each sleep about 2 s in (USB-C and AC events) before the 30 s PMU RTC alarm. The alarm wake itself isn't covered by this row.
    • A first run without the SEP driver loaded (the test boot line masks the service that loads it) refused all five sleeps before the commit, as it should, and brought every device back each time.

🤖 Generated with Claude Code

An OS that aura starts at EL2 has no monitor below it, so it powers cores
off and suspends the system itself. From M4 on, the A18 Pro included,
iBoot locks every core's reset vector to the boot object, so a wake
restarts each core in aura, and the boot core would rerun the boot flow
over the live OS.

When the OS runs at EL2 and a running secondary's locked RVBAR reaches
this image (the address smp_prepare_rvbar() accepted before starting
it), publish /chosen/aurora,s2r-mailbox. On a reset with it published,
the boot core takes the resume address the OS left there, or reboots if
it left none. A secondary needs nothing new: its spin table entry still
holds the OS's release address. Reset paths stop printing once the
mailbox is out, since the OS owns the UART and the display.

The CPUs keep spin-table, which every kernel knows. The property is the
whole contract: a kernel that reads it may power its spin-table CPUs off,
and one that doesn't ignores it. Whether to deep-sleep stays the OS's
choice. Nothing here is chip-specific beyond the locked RVBAR. On A7 to
M3 it isn't locked and nothing is published, and a guest at EL1 gets
nothing.

The mailbox is 32 bytes in aura's .data, inside the image kboot already
reserves, so nothing new is reserved.

Linux reads it in arch/arm64/kernel/cpu_ops.c and
drivers/soc/apple/t8140-sleep.c. The return path is the one every Linux
deep sleep on the Neo since 2026-11-06 ran on, from a Stage 2 built on
1.0.0b5 that set the CPUs' enable method instead.

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

Copy link
Copy Markdown
Contributor Author

This change is already on main. Its one commit landed as 3089662 ("kboot: let an OS at EL2 return from its own sleep") with #144, and the only difference is a clang-format line wrap. main has since extended the same code (a boot-core-only OS, the T8142/T8152 relay case, the CTXR_D window check and the DockChannel wake line). A rebase onto main leaves nothing, so I'm closing this as merged through #144.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant