Repository navigation
arm: apple: keep Linux inside the CTXR executable window - #32
Conversation
A kernel built with CONFIG_ARM64_CTXR_EXECMEM confines its executable code to the physical window in /chosen/aurora,ctxr-exec-window and panics early if its image is outside it. Only a kernel aura loads itself lands there today. Through EFI, the image goes where the allocator or the stub's physical KASLR puts it, and booti leaves it at its load address. efi_load_pe() serves both bootefi and the LoadImage call GRUB makes, so load an arm64 Image from there, at the lowest free 2 MiB boundary in the window, and install LINUX_EFI_LOADED_IMAGE_FIXED_GUID on its handle. The stub then skips physical randomisation and runs the image in place. The EFI memory map stays accurate and other allocations are untouched. booti_setup() does the same search for the aurora_fallback path. It checks that the range is free RAM itself, because booti moves the image before it reserves the memory. A zboot image cannot be placed this way: its decompressor picks the kernel's address from the whole memory map and ignores the protocol. No Aurora kernel is built with EFI_ZBOOT, so refuse it. If the image cannot be placed, print an error and refuse to start it rather than boot a kernel that will panic. With /chosen/aurora,ctxr-exec-enforce set to 0, warn and place it as usual. Nothing changes when the property is absent or malformed. A base of 0 also changes nothing, because the kernel anchors that window on its own image. Signed-off-by: Diljit Singh <[email protected]>
U-Boot can now place the kernel inside the window (aurora-silicon/u-boot#32), so booting through U-Boot and GRUB no longer requires a kernel aura loads itself. Record that, and that a zboot kernel is refused while enforcing. Signed-off-by: Diljit Singh <[email protected]>
A core the window confines can only fetch inside it at EL2, and Linux calls EFI runtime services from any core. U-Boot's runtime code is part of its image, so relocate the image to the top of the window. A kernel that finds runtime code outside it turns runtime services off. Only the image moves. U-Boot's malloc area and EFI stack reserve about 80 MiB, which with a 128 MiB window leaves little or no room for the kernel, and none of that memory is executed once the OS runs. It stays where it would be without a window, at the same addresses. Keep the end of the malloc area in gd, since initr_malloc() can no longer find it from relocaddr. The image's memory is Boot Services Code in the EFI map except for runtime services, so the kernel gets it back for its executable pool at ExitBootServices(). Leave the image where it is if the window isn't in RAM, can't hold it, runs into the rest of U-Boot's memory or has a reservation at its top. Warn when placing a kernel with runtime code outside the window. Nothing changes when the window property is absent. Signed-off-by: Diljit Singh <[email protected]>
An EFI runtime driver's image, or any other EFI_RUNTIME_SERVICES_CODE that an application asks for, is code a confined core may have to run. Ask LMB for the highest address inside the window for it, and fail rather than go below the window when one is enforced. An application that names the address gets that address. Everything else stays out of the window: loader code and data, boot services memory, an initrd and GRUB only run or get read on the unconfined boot core before ExitBootServices(), so they can go anywhere. Signed-off-by: Diljit Singh <[email protected]>
|
Adversarial review and regression run (CTXR lane, 06/11). Not merging yet: the series hasn't booted with a window on our Neo, see the end. Tested
Should fix
Nits
Merge order stays kernel, then this, then aura#77, then aurora-installer#104. Nothing here is unsafe without a window, but the lab Neo can't test it with one: both of its installs have the unpadded 1.7 MB Mach-O Stage 1 enrolled, so |
A kernel placed in the window can be allocated larger than its PE size, because its header's image_size counts too. A relocation failure freed only the PE size, and unloading the image frees what loaded_image reports. Keep the allocated size and use it for both. If installing LINUX_EFI_LOADED_IMAGE_FIXED_GUID fails, free the window pages too. Signed-off-by: Diljit Singh <[email protected]>
Top-down allocations reach the window if it sits high enough, such as board_late_init()'s 2.4 GiB on a small-RAM Mac, or GRUB's heap on an EFI map that shows the window as the largest free range. That can leave no 2 MiB range for the kernel, and the boot is refused. Reserve what's free of the window in LMB when LMB starts, with a flag of its own so that a dump shows it. U-Boot's image and the device tree's reservations are already there by then and stay as they are. The EFI map follows LMB and reports the window as boot services data, which an application can't allocate and the OS gets back at ExitBootServices(). Only three things take from it, each giving up just what it needs: the EFI loader and booti for the kernel, and an allocation of runtime code. Freed pages go back. Nothing changes when the window property is absent. Signed-off-by: Diljit Singh <[email protected]>
systemd-stub loads the kernel in a UKI into loader code pages it allocates and starts it without LoadImage, so it misses the placement in efi_load_pe(). The kernel then lands outside the window, and an enforcing one panics. A kernel is the only loader code that large an application asks for at an address of U-Boot's choosing, so allocate those from the window. efi_load_pe() doesn't come through here, so a UKI's own image stays outside. The EFI stub runs the kernel in place because Apple U-Boot has no RNG, and it logs the placement. Signed-off-by: Diljit Singh <[email protected]>
|
Thanks. Status at 1. Stale. That describes 2. Fixed in 3. Fedora's GRUB isn't a bypass, UKIs were. Fedora 44 and 45 GRUB, with or without shim, call Nits. Both fixed in |
…using The kernel side of the CTXR window has changed. A kernel that finds its image outside the window, or a window it can't use, no longer panics: it keeps its secondary CPUs offline and boots on the boot CPU. It no longer reads aurora,ctxr-exec-enforce, it treats a base of 0 as malformed, and it takes only a page-aligned window that doesn't wrap. Read the window the same way. Drop the enforce property, and take a window only if its base and size are non-zero and 16K aligned, which is the page size of Apple kernels, and it doesn't wrap. U-Boot can't know the kernel's page size before it relocates itself. A 4K-page kernel takes every window this takes. A 64K-page kernel may reject one, and then boots on the boot CPU, as it would with any window it rejects. Stop refusing to start a kernel U-Boot couldn't place. Refusing turned a boot on one CPU into no boot at all, and only some paths did it: a UKI's kernel already fell back silently. Every path now warns the same way, twice and on the console, and carries on: the EFI loader and booti when the window has no room, the EFI loader for a zboot image, the UKI path, and runtime code an application allocates when the window has no room for it. booti_setup() no longer fails for the window, so bootm can no longer turn it into a board reset. Signed-off-by: Diljit Singh <[email protected]>
ctxr_exec_relocate_uboot() ran from reserve_uboot() and guessed how much memory would be reserved below U-Boot's usual place: malloc, the EFI stack, the device tree and 1 MiB. That missed noncached memory and the bloblist, which other boards reserve there. Run it as its own init call after reserve_stacks() instead, when gd->start_addr_sp is final and nothing has used gd->relocaddr yet, and move the image only if the window ends below the bottom of the EFI stack. The image's usual place stays reserved either way. Also leave the image where it is if its new place overlaps what relocate_code() reads while it copies, which is the running image and its relocations, or the device tree U-Boot is using. The copy runs forwards, so a destination above an overlapping source would corrupt it. Signed-off-by: Diljit Singh <[email protected]>
The window LMB sets aside was a static of its own, so lmb_push() and lmb_pop() didn't save it, and a unit test would have run against the board's window. Keep it in struct lmb instead, cleared by lmb_setup(), and set it with lmb_ctxr_window_init(). It only takes effect where the window code or the unit tests are built in, so other boards still compile the hold away. Split lmb_release_ctxr_window_top() into lmb_ctxr_window_top(), which finds the highest aligned range set aside and takes an alignment, and lmb_release_ctxr_window(), so that a caller can check a candidate before giving it up. If giving up a range frees it in LMB but the EFI map can't follow, set it aside again. Add sandbox tests for setting the window aside around what is already reserved, allocations going around it, giving up and setting aside a range with the regions merging back, releases that don't fit, finding the top of it, and a window with no RAM behind part of it. CTXR_EXEC_WINDOW itself stays ARM64 only: it relocates U-Boot and places an arm64 Image, and the LMB part doesn't need it to be tested. Signed-off-by: Diljit Singh <[email protected]>
LMB sets the window aside when it starts, from what the control device tree reserves. The tree an EFI payload gets can reserve more: efi_carve_out_dt_rsv() adds its reservations to the EFI map but not to LMB. Placing the kernel then gives up the window range in LMB, which rewrites that range of the EFI map to conventional memory, and the check in efi_allocate_pages() never sees the reservation. Under QEMU, bootefi with a tree whose /memreserve/ covers the first 8 MiB of the window, which U-Boot's own tree doesn't, loaded the kernel at the window's base, on top of it. Have efi_reserve_memory() take the reservation's pages out of the window's free space with lmb_ctxr_window_claim(), which reserves them in LMB without telling the EFI map, so that the type it was given stays. Kernel placement and runtime code then step around it, and the same boot loads the kernel 8 MiB in. booti still only steps around what U-Boot's own tree reserves: it places the kernel before it reads the tree it boots with. Signed-off-by: Diljit Singh <[email protected]>
booti_setup() gave up a range of the window and booti_start() reserved the image there. When the boot then failed, in bootm_find_images() or a later state, the reservation stayed, and the next booti or EFI kernel went to the next free 2 MiB boundary. Under QEMU, two booti calls with a bad device tree address took 0x40200000 and 0x42e00000 of a 128 MiB window, and a third, valid one found no room for a 43 MiB kernel. Reserve the place in booti_setup() itself, which bootm also calls, and remember it. A successful booti or bootm never returns, so whenever a kernel is placed again, by booti, bootm or the EFI loader, the earlier boot didn't start: give its place back to the window first. booti's own reservation of the image merges with this one, and bootm, which only reserves the load address, now has the moved image reserved too. Signed-off-by: Diljit Singh <[email protected]>
The window took any loader code allocation of 16 MiB or more an application asked for, as a stand-in for systemd-stub loading a UKI's kernel. shim's own PE loader asks for its second stage that way too. Under QEMU, Fedora's shim 16.1 loading a 93 MiB UKI put the UKI itself in the window, left no room for systemd-stub's kernel, which U-Boot then placed outside it without a word, and the kernel booted outside its window. Key on the image asking instead: serve the allocation from the window only if the image its handle describes is a PE with a .linux section, whatever its size. That is the UKI when systemd-boot or U-Boot started it, and also when shim runs it itself, as shim points its own loaded image protocol at the image it starts. A shim loading a UKI no longer puts the UKI in the window, so systemd-stub's kernel goes there. If the window can't take the kernel, say so with the same warning as the other paths before falling back. Signed-off-by: Diljit Singh <[email protected]>
Runtime code from the window was placed at the top of what the window had free, 4 KiB aligned, which is directly below U-Boot's own runtime code. The EFI map then merges the two into one region that starts on a 4 KiB boundary, and a 16K-page kernel turns runtime services off. Under QEMU an application keeping one page of runtime code did exactly that. Allocate runtime code in the window in whole 64 KiB blocks, as UEFI wants for AArch64 runtime memory, so the region stays aligned for a kernel of any page size, merged or not. When such memory is freed, free the 64 KiB block the range ends in too, but not one it starts partway into, which is how efi_alloc_aligned_pages() trims an aligned allocation. If the window has no room, or the caller's limit is below it, the code still goes outside with a warning, as before. If reserving the range the window gave up fails, or the EFI map can't take it, set the range aside again rather than leave it free. Signed-off-by: Diljit Singh <[email protected]>
efi_load_pe() returned the error from a failed TCG2 measurement without freeing the image's pages. For a kernel in the CTXR window that was window space lost until reset. Free them as the relocation failure does, which also sets window pages aside again. Signed-off-by: Diljit Singh <[email protected]>
The section still described the first commit of the series: only the kernel in the window, a kernel that panics, an enforce property, a window with base 0 that the kernel anchors on its image, and nothing keeping other allocations out. Describe what the window holds now: the kernel from the EFI loader, booti and bootm, a UKI's kernel, and U-Boot's image with its runtime code. Say how LMB and the EFI map keep the rest of it free, what U-Boot takes as a window, what happens when the kernel doesn't fit, and what it still misses. Update the Kconfig help the same way. Signed-off-by: Diljit Singh <[email protected]>
A UKI whose kernel is an EFI zboot image got its loader code from the window and the "bytes of loader code at" line, then its decompressor allocated the real kernel with EFI_ALLOCATE_ADDRESS wherever it liked, outside the window, with no warning. Read the Linux header at the start of the UKI's .linux section. For a zboot image, give the warning efi_load_pe() gives for one, and allocate as usual. The UKI path also didn't warn when U-Boot's runtime code is outside the window, which only efi_load_pe() checked. Share that check, and test the 64 KiB region the EFI map gives runtime code rather than the section. Signed-off-by: Diljit Singh <[email protected]>
bootm_load_os() copies a uImage to its load address, booti_setup() then moves an arm64 Image into the CTXR window and reserves that place, and bootm_load_os() goes on to reserve the load address. If the load address is inside the window, LMB holds it and the reservation fails. Under QEMU, a uImage loading at 0x44000000 with the window at [0x40200000, 0x48200000) printed "Moving Image from 0x44000000 to 0x40200000" and then "Unable to allocate memory 0x44000000 for loading OS". The image no longer lives at its load address once it has moved, so skip that reservation when booti_setup() put it in a place in the window. Without the window nothing changes. Signed-off-by: Diljit Singh <[email protected]>
|
Neo (J700) boot through this head ( 🤖 Generated with Claude Code |
The searches for a place in the window compared base + size against the window's end. A huge size from an image header, image_size in a Linux header or text_offset + image_size for booti, wraps that sum and passes the check, and LMB is then asked to give up or free a range that wraps too. Treat a size larger than the window, or than the held region being tested, as no room: in efi_alloc_in_ctxr_window(), booti_setup(), ctxr_exec_place_booti(), lmb_release_ctxr_window(), lmb_ctxr_window_top(), and for runtime code. The LMB tests cover the two LMB functions with such a size. Signed-off-by: Diljit Singh <[email protected]>
Freeing runtime code in the window rounded the end of the range up to a 64 KiB block. That is right for the last block of an allocation, but efi_free_pages(A, 1) on a larger allocation that starts at A freed the whole first block, pages the caller still owned. The EFI map merges neighbouring allocations, and this one with U-Boot's own runtime code, so it can't say where an allocation ends. Keep a small table of runtime code allocations in the window instead: where each still starts, where what was asked for ends, and where its blocks end. Free the blocks a range covers whole, and an allocation's last block only once the range reaches the end of what was asked for. Trimming the end of an aligned allocation, a whole free and a free in pieces then each free exactly the blocks nobody uses. A free in the middle splits the entry. With the table full, runtime code goes outside the window with the usual warning. Signed-off-by: Diljit Singh <[email protected]>
ctxr_exec_relocate_uboot() left U-Boot's image where it was if its new place overlapped the running image, its relocations or the device tree, but not the early global data and the pre-relocation malloc() area. relocate_code() runs on the new stack and global data and doesn't read them, but they are in use right up to it. Leave the image where it is if it would overlap them too, from gd to the end of the early malloc() area, rather than depend on that. Signed-off-by: Diljit Singh <[email protected]>
The check that an LMB test starts with no window popped back to the real LMB and pushed again, so it passed whether or not lmb_setup() clears the window. Set a window in the test LMB instead, push, check it is gone, pop, and check it is back. Add a test of a claim that spans three regions set aside, split by two reservations, and check that it takes each part and leaves the rest. Signed-off-by: Diljit Singh <[email protected]>
The section said U-Boot's image relocates to the top of the window, but ctxr_exec_relocate_uboot() leaves it where it is in several cases. List them, and what follows for runtime services. Say that a zboot kernel in a UKI is warned about too, that systemd-boot installs an entry's devicetree after loading the kernel, as booti reads its tree after placing it, and when freeing part of runtime code in the window keeps a block. Signed-off-by: Diljit Singh <[email protected]>
|
Neo (J700) boot through this head (
Afterwards the Neo went back to the normal path ( 🤖 Generated with Claude Code |
|
Thanks for merging. Two commits landed on the branch after the merge, so they're in #36.
QEMU 61/61, sandbox LMB 14/14. 🤖 Generated with Claude Code |
… window On an M4 booting aura's Mach-O Stage 1, U-Boot at d30213e can place the kernel outside the CTXR executable window, and the secondary CPUs stay parked. aurora-silicon/u-boot#32 keeps it inside. Tested on a fresh 16-inch M4 Pro (J616s) install: 14 cores, Touch ID, external display. Co-Authored-By: Claude Opus 5.5 <[email protected]>
An image with the confined Stage 2 (esp/m1n1/boot-ctxr.bin) boots M4-and-later Macs, whose kernel must run inside the CTXR window. U-Boot before aurora-silicon/u-boot#32 places it wherever its allocator likes, and the kernel then keeps every CPU but the boot CPU offline, as a J616s did on uboot-aurora d30213e. Inspection's new ctxr-uboot check requires such an image's U-Boot to read aurora,ctxr-exec-window; an image without the confined Stage 2 passes it as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
An image with the confined Stage 2 (esp/m1n1/boot-ctxr.bin) boots M4-and-later Macs, whose kernel must run inside the CTXR window. U-Boot before aurora-silicon/u-boot#32 places it wherever its allocator likes, and the kernel then keeps every CPU but the boot CPU offline, as a J616s did on uboot-aurora d30213e. Inspection's new ctxr-uboot check requires such an image's U-Boot to read aurora,ctxr-exec-window; an image without the confined Stage 2 passes it as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
An image with the confined Stage 2 (esp/m1n1/boot-ctxr.bin) boots M4-and-later Macs, whose kernel must run inside the CTXR window. U-Boot before aurora-silicon/u-boot#32 places it wherever its allocator likes, and the kernel then keeps every CPU but the boot CPU offline, as a J616s did on uboot-aurora d30213e. Inspection's new ctxr-uboot check requires such an image's U-Boot to read aurora,ctxr-exec-window; an image without the confined Stage 2 passes it as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged at
7e540a04d0. Two later commits (a revert and a doc note) are in #36.A
CONFIG_ARM64_CTXR_EXECMEMkernel (aurora-silicon/linux#985) confines its executable code to the window in/chosen/aurora,ctxr-exec-window(aurora-silicon/aura#77). If its image is outside the window, or the window is unusable, it keeps the secondary CPUs offline and boots on the boot CPU. It turns EFI runtime services off if any runtime code is outside the window or not aligned to its pages. Through U-Boot and GRUB, the image used to go wherever the EFI allocator or the stub's physical KASLR put it, and U-Boot's runtime code sat at the top of RAM.This PR puts the kernel and U-Boot's runtime code inside the window, on every way U-Boot starts Linux here:
bootefi, GRUB'sLoadImage, systemd-stub UKIs,bootiandbootm.Ryan booted
50d879acon a Neo with a real 128 MiB window, through GRUB, on linux#985 kernelsa1a2ac0andf6b1cbf(report). The commits after50d879achaven't booted on hardware, only under QEMU. sithglan booted an M5 on linux#985 (report) through the aura#77 chain. That report doesn't mention U-Boot and its pool is in one range, where a boot with this PR's runtime code in the window has two, so it isn't counted as a run of this PR. The QEMU results are below, and the list of what to measure on hardware is at the end.Commits
The first six are the original series:
arm: apple: keep Linux inside the CTXR executable windowplaces the kernel.boot: relocate U-Boot's image into the CTXR windowmoves runtime services in.efi_loader: allocate runtime code inside the CTXR windowcovers runtime code an EFI application allocates.efi_loader: free all of a kernel placed in the CTXR windowfixes the failure paths.lmb: set the CTXR window aside until something needs itstops other allocations using it up.efi_loader: keep a kernel a UKI loads itself in the CTXR windowcovers systemd-stub, which skipsLoadImage.The rest answer the review:
boot: ctxr: follow the kernel's window checks and warn instead of refusingmatches linux#985: noaurora,ctxr-exec-enforce, and a window counts only with a non-zero, 16 KiB aligned base and size that don't wrap. U-Boot no longer refuses a kernel it can't place. Every path prints the same warning and starts it.boot: ctxr: place U-Boot's image once the rest of its memory is reservedreplaces the estimate of U-Boot's memory with the real bottom of its stack, and refuses a destination that overlaps the running image or the device tree.lmb: keep the CTXR window in struct lmb and test itmakes the window part of the statelmb_push()saves, and adds sandbox tests.efi_loader: keep device-tree reservations out of the CTXR windowstops a kernel being loaded over a reservation that only the tree handed tobootefihas.boot: ctxr: give back the window place a failed booti tookstops failedbooticalls using up the window.efi_loader: serve only a UKI's kernel from the CTXR windowkeys that path on the image asking having a.linuxsection, not on the size of the request.efi_loader: give runtime code in the CTXR window whole 64 KiB blockskeeps runtime code aligned for any kernel page size.efi_loader: free a PE image's pages when measuring it failscloses a leak.doc: apple: describe the CTXR window support as it is.A second review found these, fixed in:
efi_loader: warn for a UKI's zboot kernel and its runtime code: a UKI whose.linuxis a zboot image got its loader code from the window and a success line, then its decompressor put the kernel elsewhere without a word. The UKI path also didn't say when U-Boot's runtime code is outside the window.boot: bootm: don't reserve a load address the window holds: a uImage that loads inside the window failed withUnable to allocate memory.boot: ctxr: treat an image larger than the window as not fitting: a huge size in an image header wrapped the fit checks.boot: ctxr: keep U-Boot's image clear of the early gd and malloc area.test: lmb: check that lmb_push() saves the CTXR window, which the old test couldn't catch, and a claim over several held regions.doc: apple: say when U-Boot's image stays out of the CTXR window.Revert "efi_loader: free only what runtime code in the CTXR window asked for"anddoc: apple: note what freeing part of CTXR runtime code does, below.efi_loader: free only what runtime code in the CTXR window asked foradded a table of runtime code allocations so that a partial free stayed exact. It is in this merge (7e540a04d0); #36 reverts it and documents the limit, since nothing in the tree frees part of such an allocation.What U-Boot takes as a window
The same as
ctxr_parse_dt()andctxr_window_valid()in linux#985 for a 16K-page kernel: four cells, base and size non-zero and page aligned, no wrap. U-Boot can't know the kernel's page size before it relocates itself, and Apple kernels use 16K pages. A 4K-page kernel takes every window U-Boot takes. A 64K-page kernel may reject one, and then boots on the boot CPU as with any window it rejects. Without a window none of the following happens, so M1 to M3 take the old path.How the kernel gets placed
efi_load_pe(), which servesbootefiand theLoadImagecall GRUB makes, recognises an arm64 Image by its header. It loads it at the lowest free 2 MiB boundary in the window and installsLINUX_EFI_LOADED_IMAGE_FIXED_GUIDon the handle, the stub's existing way for a loader to say "run it where I put it". The EFI map stays accurate and the stub never looks for a new home.booti_setup(), whichbootiandbootmboth call, does the same search and reserves the place itself. Abootiorbootmthat succeeds never returns, so the next kernel placement, bybooti,bootmor the EFI loader, first gives back a place an earlier one took.LoadImage. U-Boot serves loader code from the window when the image asking for it is a PE image with a.linuxsection, whatever the size. That is the UKI when systemd-boot or U-Boot started it, and also when shim runs it itself, since shim points its own loaded image protocol at the image it starts. U-Boot reads the Linux header at the start of.linux: for a zboot image it warns and allocates as usual, since the decompressor puts the real kernel wherever it likes.Physical KASLR is off in this mode. The stub logs
Image placement fixed by loader, or, for a UKI,EFI_RNG_PROTOCOL unavailable, and runs the image in place. Apple U-Boot has noDM_RNG, so it has noEFI_RNG_PROTOCOL. Virtual KASLR still works.When the kernel can't be placed
U-Boot prints, on every path:
and starts the kernel as it would without a window. The kernel then keeps its secondary CPUs offline and boots on the boot CPU. That happens when the window has no room or isn't RAM, for a UKI whose kernel doesn't fit, and for a zboot image, on its own or in a UKI, whose decompressor picks the kernel's address from the whole memory map. A size larger than the window counts as no room, so a huge size in a header can't wrap the checks. Refusing used to turn a boot on one CPU into no boot at all. Because
booti_setup()no longer fails for the window,bootmcan't turn it into a board reset either.bootmalso no longer reserves a load address inside the window once the image has moved out of it.How runtime services get in
A confined core can only fetch inside the window at EL2, and
efi_rts_wqruns on any core. CPU0 isn't confined and EFI applications only run on it beforeExitBootServices(), so only the kernel andEFI_RUNTIME_SERVICES_CODEneed the window.U-Boot's runtime code is inside its image, so the image relocates to the top of the window. That is decided in its own init call after
reserve_stacks(), once every reservation below U-Boot's usual place is made, and only if the window ends below the bottom of the EFI stack. Only the image moves: its malloc area, EFI stack, device tree copy, MMU tables and globals stay where they would be without a window. It also stays where it is if its new place would overlap the running image, its relocations, the device tree in use, or the earlygdand malloc area, if the window is smaller than the image or starts below RAM, or if the device tree reserves the top of the window. Its runtime code is then outside, U-Boot says so when it places a kernel, and Linux turns runtime services off.In the EFI map, the first 64 KiB of the image is
Runtime Codeand the rest isBoot Services Code, so the kernel gets all but 64 KiB back for its pool. The image starts on a 64 KiB boundary and.efi_runtimeis at0x1b0to0xfd8of it.add_u_boot_and_runtime()rounds the section to 64 KiB, so the region stays inside the image if the section grows.Runtime code an EFI application allocates comes from the top of the window too, in whole 64 KiB blocks, as UEFI wants for AArch64. That region ends where U-Boot's begins, and the EFI map merges the two, so the merged region has to stay aligned too. When such memory is freed, U-Boot frees the block the range ends in, but not one it starts partway into, which is how
efi_alloc_aligned_pages()trims an allocation. If the window has no room, or the caller's limit is below it, the code goes outside with a warning, and Linux turns runtime services off.Keeping the window free
When LMB starts, it sets aside what is free of the window, after U-Boot's image and the device tree's reservations, with a flag of its own. Allocations go around it:
board_late_init()allocates about 2.4 GiB top-down, and GRUB builds its heap from the largest free ranges in the EFI map. The EFI map reports the window asBoot Services Data, which an application can't allocate and the OS gets back atExitBootServices().Only kernel placement and runtime code take from it, each the range it needs. Freed pages go back, and so does a range whose reservation fails afterwards.
efi_carve_out_dt_rsv()adds the reservations of the tree an EFI payload gets to the EFI map but not to LMB. Giving up a window range rewrote that part of the EFI map to conventional memory, so the kernel could load on top of such a reservation. Each one now comes out of the window's free space as well.Testing
Builds with no warnings:
apple_m1_defconfig, andqemu_arm64_defconfigwith the option on and off. Sandbox builds with only the warnings it had before. Two builds ofapple_m1_defconfigwith the sameSOURCE_DATE_EPOCHare byte-identical:u-boot-nodtb.binat7791f7a1d6(#36) has sha2566de1f52ad92077f3145e455d6a9ebc31734144fc1097a411b5a0c1c6006abab9.Sandbox unit tests,
ut lib: all 10 existing LMB tests and the 4 new ones pass. The new ones set the window aside around existing reservations, check that allocations go around it, give up a range, set it aside again and see the regions merge back, try releases that don't fit or whose end wraps, find the top of it, set aside a window with no RAM behind part of it, check thatlmb_push()saves and clears it, and take a reservation out of it, including one that spans several held regions. Removing the reset fromlmb_setup(), or the wrap checks from the LMB functions, makes them fail.QEMU
virt(TCG, 2 CPUs, 8 GiB RAM,virtualization=on) booting linux#985 at its final headf6b1cbf1bc1, built withRANDOMIZE_BASE=yand 16K pages, withCONFIG_EFI_RNG_PROTOCOL=yin U-Boot so the stub would randomise if allowed. U-Boot and Linux run at EL2, because that kernel only takes a window at EL2. U-Boot has Apple's malloc size. The window is[0x40200000, +128 MiB).All 61 scenarios pass: the 45 from before, with their expectations moved to the new kernel contract, and 16 new ones.
The 45 changed in these ways:
before-efi,before-grub,before-bootiandbefore-uki44, U-Boot without the option or from before U-Boot moved into the window, now expectdoes not fit window, thenunusable window: keeping the secondary CPUs offline, then init, where they expected a panic.small-*,enforce-absent-efi,not-ram-*andzboot-enforceexpect U-Boot's warning, the kernel outside the window on CPU0, and init, where they expected a refusal. Thesmall-report-*trees still setaurora,ctxr-exec-enforce = <0>, and U-Boot ignores it.base0*andmalformedexpect the kernel'smalformed aurora,ctxr-exec-windowline.before-rt-secondaryneeded the kernel to leave runtime services on with runtime code outside an active window, which the kernel no longer does. It is nowfetch-control, the plugin's negative control: the plugin is told a window 2 MiB short at the top, and has to count the secondary's fetches of U-Boot's runtime code as outside.rt-allocexpects a runtime code request limited to below the window to land below it with a warning, and runtime code in the window to be 64 KiB aligned.executable pool: 84 MiB usable in 2 range(s)andboot verify: ... 0 violation(s): PASS.0x234c00000,does not fit window, secondaries offline, reaches init0x40200000, enforcing, pool 84 MiB in 2 ranges, 0 violationsbytes of loader code at 0x40200000booti0x40200000, pool 84 MiB in 1 rangeThe new scenarios for the review findings, against the first six commits:
bootefiwith a tree that reserves the first 8 MiB of the window, which U-Boot's own doesn't0x40200000, on the reservation0x40a00000, the EFI map showsReservedat0x40200000booticalls fail after placing the image, then a third0x40200000,0x42e00000, thenno free 2 MiB aligned range0x40200000, the third bootsbootifails after placing the image, thenbootefi0x402000000x22bc00000,does not fit window0x40200000[0x4809f000, 0x480b0000), runtime services off[0x48090000, 0x480b0000), runtime services onAnd for the second review, against
bb6e1e3005where that was run:bb6e1e3005.linuxhas a zboot headerbytes of loader code at 0x40200000, no warningbootmof a uImage that loads at0x44000000Unable to allocate memory 0x44000000 for loading OS0x40200000, enforcing, reaches initimage_size, throughbootefibootibooti's ownFailed to allocate memory for the image, back to the promptU-Boot's runtime code is outside it, runtime services offgdand malloc areadevicetreethat reserves the window's startThe zboot UKI uses an Image with a patched zboot header, so it covers U-Boot's detection and warning. A real decompressor hasn't run through this path. That the decompressor allocates with
EFI_ALLOCATE_ADDRESScomes from readingzboot.candrandomalloc.cin the kernel.The Image comes from a build whose own after-build check the shared build VM cut off, and which the host's disk space then kept from being retried. It boots across all of these scenarios, and it is only the test vehicle. The U-Boot builds ran between clean checks of the guest.
On this head, init reads 10 variables through efivarfs on CPU1, with CPU0 offline and the
efi_runtimeworkqueue limited to CPU1, and CPU1 fetches runtime code only from0x480a0000, inside the window. With U-Boot from before it moved into the window, the kernel logsEFI runtime services off.Other scenarios that still pass as before: a window high in a 3 GiB machine after
board_late_init()'s allocations, a 100 MiB initrd through GRUB,bootefi,bootiand a UKI, no property at all, a reservation at the start or the top of the window, a window at the top of RAM, and a window base that isn't 2 MiB aligned.QEMU has no CTXR, so a TCG plugin records which physical pages each vCPU fetches privileged code from. It stands in for the hardware check on the secondary. QEMU proves the allocator paths and the kernel contract. Its plugin only compares addresses, so it can't show that the Neo lets a confined core run U-Boot's runtime code.
On the Neo at
50d879ac, Ryan's report hasreserved exec window [0x10007200000, +128 MiB), enforcing, a pool of 53 MiB in 2 ranges with 74 MiB already reserved,boot verify: 1696 executable mapping(s), 0 violation(s): PASS, all 6 CPUs at EL2 through spin-table, kernel code and data inside the window, and 19 efivars. That is50d879ac, not this head.Known limits
efi_runtime.caccepts aSetVirtualAddressMaponly with exactly one runtime code region. Runtime code an application keeps in the window ends where U-Boot's begins and merges with it in the EFI map, so the call succeeds, but U-Boot doesn't relocate the application's code. Outside the window it is a second region and the call fails. Nothing in the boot chain keeps runtime code.bootiplaces it before it reads the tree it boots with. systemd-boot installs the tree an entry'sdevicetreekey names afterLoadImage: under QEMU the kernel goes to0x40200000, the reservation then lands on it, the stub logsFIRMWARE BUG: Image BSS overlaps adjacent EFI memory regionand moves it out of the window, and it boots on CPU0 with no warning from U-Boot.GetTimereturnsEFI_UNSUPPORTED.apple_m1_defconfighasEFI_RT_VOLATILE_STOREoff, so U-Boot doesn't advertiseSetVariable, and efivarfs mounts read-only.GetVariableworks, 500 of 500 in Ryan's Neo run at50d879ac. None of this comes from the window: the series doesn't touchefi_runtime.c..linuxsection, misses the window with no warning, and the kernel boots on the boot CPU. AnEFI_RNG_PROTOCOLin U-Boot would let the stub move a UKI's kernel to a random address outside it. Neither happens today. The complete fix would be for the kernel's EFI stub to move itself into the window.To measure on hardware
Needs a padded boot object (aurora-installer#104), aura#77 with
aura-ctxr-exec, and a kernel from linux#985. Don't passefi=noruntime.None of this has run on the commits after
50d879ac, so every item stands for this head. "Seen at50d879ac" marks what Ryan's Neo report already shows for that commit.CTXR exec window [...]: Linux image at ...and the address is inside the armedCTXR_D. NoWARNING: CTXR exec windowline and noU-Boot's runtime code is outside it.bdinfoshowsrelocaddrin the last MiB of the window, andsp startandTLB addrnear the top of RAM. There is noout of memory.lmb_dump_allpart ofbdinfo, the window isreserved[n] [<window base>-<relocaddr - 1>], flags: ctxr-window, no-overwritethenreserved[n+1] [<relocaddr>-<window end - 1>], flags: no-overwrite, and no other region starts inside it.kernel_addr_r,ramdisk_addr_randloadaddrare outside it, andlate_init: Failed to set run time variablesdoes not appear.reserved exec window ... enforcing,executable pool: ...andboot verify: ... 0 violation(s): PASS,/proc/iomemshowsKernel codein the window, and no line says it keeps the secondary CPUs offline. Seen at50d879ac.efi=debug, the window atExitBootServicesholdsLoader Codefor the kernel, one 64 KiBRuntime Code,Boot Codefor the rest of U-Boot's image andBoot Datafor the free remainder, and nothing else. The initrd'sLoader Datais outside the window.EFI runtime services offline, and/sys/firmware/efi/efivarslists variables, read-only. Seen at50d879ac, without the per-CPU part that follows. Write each of CPU1 to CPU5 in turn to/sys/devices/virtual/workqueue/efi_runtime/cpumaskand read a variable, with no oops. This is the check QEMU can't do.50d879ac.LoadImage, with a real initramfs and BLS entries.Linux image atin theCTXR exec windowline shows it did.50d879acbooted through GRUB; the report doesn't say which build or whether the entries were BLS.bytes of loader code atwith an address at the window's start, and boots. A kernel larger than the window's free space gets the warning and boots on the boot CPU.50d879ac.aurora_fallbackboots throughbootiinto the window.50d879acran.🤖 Generated with Claude Code