Skip to content

arm64: ctxr-execmem: follow-ups from the Neo run and a second review - #1079

Merged
DjDeveloperr merged 5 commits into
integration/aurorafrom
feat/ctxr-execmem-followup
Nov 7, 2026
Merged

DjDeveloperr merged 5 commits into
integration/aurorafrom
feat/ctxr-execmem-followup

Conversation

@DjDeveloperr

Copy link
Copy Markdown
Contributor

Follow-up to #985, which merged at 273b9e8. These five commits landed on feat/ctxr-execmem after the merge, so they aren't in integration/aurora yet. They answer the rest of Ryan's Neo run and a second independent review.

  • d56b6e6292f mm/execmem: report the window and pool use via sysfs.
    • /sys/kernel/execmem_confine/ gives window_base, window_size, pool_size, pool_free and pool_largest_free, in bytes, so an ENOMEM on a user's Mac is diagnosable. Tools can read the window from there instead of the boot log, which wraps in minutes on the Neo.
    • Also calls both set_memory_nx() and set_memory_rw() on free, where || used to short-circuit.
  • 25e007f8256: skips the crashkernel= reservation, with one warning, while a window is active. kexec is refused then, so the memory was wasted.
  • 590be8c8957: uses the device-tree window unless ctxr_exec_window= matches it exactly. With a smaller command-line window inside the device tree's, only the sub-window was reserved, and the rest of the firmware's window went to the page allocator. EL0 can't execute there on a confined core. Under the simulator, with the enforced window equal to the device tree's 128 MiB, /init hung on CPU2, and 31.7 MiB of user pages landed in the window with maxcpus=1.
  • c6a7e1f3ef7: names the CTXR window in the oops when a kernel fetch outside it faults on a confined core, instead of "execute from non-executable memory" (Ryan's item 3).
  • c3c11153cda: the EL0 backstop checks only a user-executable PFN-mapped page.

Ryan's 6315aea/273b9e8 covered the BPF JIT fill, so the BPF clamp from the same round was dropped.

Tested. Only in QEMU; none of this has booted on hardware.

  • Simulator: small test kernel at c3c11153cda, simulator enforcing on CPU1 and CPU2, guest system files clean before and after. These all pass:
    • good-128m, good-kvm and nowin-kvm
    • bad-cells, bad-small and bad-nvhe
    • cmd-128m and cmd-nobase
    • cmd-inside-dt and cmd-outside-dt: both now simulate the device tree's full window. The command line is ignored, and all 3 CPUs come up and run module, kprobe, BPF and ftrace code.
    • the mismatch control
  • Build: W=1 is clean on the touched objects, and the Image links.

Still open: what takes 74 MiB of the window on the Neo's U-Boot and GRUB path, against 17 MiB on the M5.

🤖 Generated with Claude Code

Nothing reported pool use, so an allocation failure on a user's machine
wasn't diagnosable. Add /sys/kernel/execmem_confine/ with the window base
and size and the pool's size, free and largest free extent. A tool can
read the window from there too.

While here, call both set_memory_nx() and set_memory_rw() on free rather
than letting || short-circuit, and correct the comment: a set_memory_rw()
failure would leave a read-only alias, not an executable one.

Signed-off-by: Diljit Singh <hey@djdev.me>
A CTXR window already makes machine_kexec_prepare() refuse kexec and
crash kernels, because the relocation code runs outside the window. The
crashkernel= reservation then only takes memory a crash kernel can never
use. Skip it with one warning when a window is active, in
arch_reserve_crashkernel(), before reserve_crashkernel_generic() runs.

Signed-off-by: Diljit Singh <hey@djdev.me>
…ne matches it

A command-line window inside the device-tree window reserved only the
sub-window, so the rest of the firmware's window went to the buddy
allocator and EL0 stalled on it on a confined core, with every check
keyed on the sub-window so nothing noticed. The whole firmware window
has to be reserved. Accept a command-line window only when it is
identical to the device-tree one; otherwise warn and use the device-tree
window. A command-line window with no device-tree window (VM bring-up)
is unchanged. Write the entry flag as ctxr_active && is_kernel_in_hyp_mode()
so it plainly can't be set off a non-EL2 path, and drop the now-unused
ctxr_within() helper.

Signed-off-by: Diljit Singh <hey@djdev.me>
An out-of-window kernel fetch on a confined core dies as "execute from
non-executable memory", which sends the reader looking at page
permissions when the real cause is the CTXR window refusing a fetch from
an in-range executable mapping. Add ctxr_exec_fetch_outside_window(),
which walks the kernel page tables for the faulting address and reports
whether its physical page is outside an active window, and say "execute
from outside the CTXR window" when it is. Also refresh the stale
ctxr_stay_el2 comment, which still said the flag was set once.

Signed-off-by: Diljit Singh <hey@djdev.me>
The backstop's PFN-map branch took any follow_pfnmap() PFN and skipped
the user-exec check the folio branch makes, and the comment claimed it
covered struct-page-less mappings in general when follow_pfnmap() only
handles VM_PFNMAP. Confirm a user-executable leaf (pte_user_exec() on
the PFN and pgprot) before comparing, restrict the branch to VM_PFNMAP,
and say plainly that a special VM_MIXEDMAP PTE is left to the hardware
fault, which is the real guarantee; this kill is a diagnostic backstop.
The documentation of the whole-window reservation invariant is tightened
to match the command-line-window fix.

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr
DjDeveloperr merged commit 7aee01a into integration/aurora Nov 7, 2026
1 check passed
RyanTheTide added a commit that referenced this pull request Nov 7, 2026
Brings aurora-wip up to the tested release branch: CTXR execmem
(#985, #1079), KFIX speaker sleep and resume fixes (#1077, #1080),
JPEG v2 (#1072), Jonathan's G17 and USB work (#1073-#1076), brcmfmac
flowring count (#1081), ANE H16 startup restart (#1066) and the
Touch ID per-prompt match (#904).

Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
Assisted-by: LLM
@RyanTheTide
RyanTheTide deleted the feat/ctxr-execmem-followup branch November 7, 2026 12:07
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