The Bit That Reads Execute-Only Pages
matters because the gate is the privileged specification's own load rule in section 4.1.1.6: MXR=0 means loads need R, MXR=1 means loads need R or X, and the module measures exactly that contract on 31 checks with zero mismatches
not here because the traps are synchronous and the run is single-hart on QEMU 8.2.2 TCG: no pipeline, cache, or predictor behavior enters any verdict, so microarchitectural variance cannot move the result
matters because the whole stage is M-mode firmware work: building the Sv39 tables by hand, opening one PMP NAPOT entry, delegating the fault with medeleg bit 13, and mret-ing into S-mode; without that firmware the gate has nothing to measure
matters because the S-mode payload is kernel-shaped: its trap handler takes the delegated fault, records scause, stval, and sepc, and resumes at sepc plus 4; and the trap-and-emulate handler the bit was written for is a kernel's job
not here because nothing is computed: the piece is about a hardware permission record that changes which loads fault, not a procedure
One page at virtual address 0x40000000, mapped execute-only: the flags read valid, executable, accessed, dirty, and no read bit. A page-table entry is the 64-bit word the memory-management unit reads on every access to decide what a virtual page maps to and what may be done with it; this entry may be executed but not read. Two phases, one load instruction. Phase A runs with MXR explicitly clear: the load raises exactly one trap, scause 0xd, the load page fault, with stval holding the faulting address and sepc pointing at the labeled load. t0 was poisoned to zero right before the load; after the handler advanced sepc past the instruction and returned, t0 was still zero. That is the part that makes it a proof rather than a story: the poison proves the load never completed. Phase B sets MXR with one csrs to sstatus: the identical load from the identical address returns the canary, 0xe4ec0d1edeadbeef, and the trap counter never moves past one. The only thing that changed between a fault and a success was one bit.
The natural objection: who marks code execute-only and then reads it? The privileged specification's own commentary answers. Section 4.1.1.6, checked in two copies of the manual this week: MXR was conceived for M-mode routines emulating missing hardware features, misaligned loads and stores being the example. A trap-and-emulate handler has to fetch the very instruction it is about to fake, and if the program's code pages are execute-only, the handler needs a read path that does not relax the page. If you own the pages, the obvious move is to mark them readable too. xv6 does exactly that: its vm.c maps kernel text with read and execute together, so the bit would change nothing there (checked in the tree this week). MXR is useful when the code is not yours to re-mark. It is the emulator's bit.
MXR is bit 19 of sstatus, and the whole mechanism is one CSR write: the hardware's load rule becomes readable or executable instead of readable. The code is the insight here:
__asm__ volatile("csrc sstatus, %0" :: "r"(SSTATUS_MXR)); /* Phase A: gate closed. The ld below faults with scause 0xd. */
__asm__ volatile("csrs sstatus, %0" :: "r"(SSTATUS_MXR)); /* Phase B: one bit. The same ld returns the canary. */
Six lines, two of them the mechanism, taken verbatim from the module. The csrc closes the gate for phase A, the poison proves the load never completes, and the csrs opens it for phase B. The faulting load carries a global label, mxrs_fault_load, so the handler can check that sepc points exactly at the faulting ld, not merely nearby. One CSR instruction is the entire difference between a fault and a canary.
Thirty-one checks, zero mismatches, a checksum over the verdict values identical across three runs, and the raw UART outputs byte-identical. The honest boundaries, stated in the module itself: this verifies QEMU 8.2.2's model of the rule, not silicon; only the supervisor load path was measured, stores through X-only pages are untested, and the spec's rule touches loads only. One sentence to carry away: one bit in sstatus rewrites the load rule from readable to readable or executable, and the manual says it exists so an emulator can read the very instruction words it is about to fake.
Code: src/sstatus-mxr