Chris Low-level systems developer
← Back to all posts

The Twelve Bits the Walk Never Touches

Relevance by layertest log
ISA

matters because the 44-bit page number at PTE bits 53:10 and the offset pass-through, pa.pgoff equals va.pgoff, are the privileged ISA's own address-formation contract: the proof checks the implementation against that contract on 60,331,824 cases

MICROARCH

not here because the proof checks the address-formation arithmetic in software; no TLB, walk hardware, or cache behavior is exercised, and the formation is identical on any implementation, so microarchitectural variance cannot move the result

FIRMWARE

matters because M-mode firmware builds Sv39 page tables: every leaf entry it writes must carry a page number that forms the correct physical address by exactly this shift-and-OR, before the hardware will walk the table

KERNEL

matters because the kernel turns page-table entries into physical addresses constantly: xv6's walk() always descends to level 0, so every xv6 mapping is exactly the 4 KiB case this lab proves

ALGORITHM

not here because the 44-bit and 12-bit split is the ISA's fixed contract: outside Sv39 the same shift amounts mean nothing, so the proven identity carries no ISA-independent claim

Take a physical page number, say 0x80000, and an offset, say 0xabc. The physical address is 0x80000abc: the page number shifted left by 12, ORed with the offset. A physical page number names which 4 KiB page holds your byte; the offset is the low 12 bits, which pick the byte inside that page. Everything this lab proves hangs on that split.

A Hayabusa Shinkansen bullet train at a platform
The offset rides the walk like an express.

The part that keeps pulling me back is not the arithmetic, it is what the arithmetic refuses to do. A page-table walk never rewrites the low bits of your address. The privileged specification says it plainly in section 4.3.2: the page offset of the physical address equals the page offset of the virtual address. The tables decide which page your data lives on; the offset rides through the whole walk untouched.

It generalizes beautifully, and the invariant is the same at every scale. When the walk finds its leaf one level up, a 2 MiB megapage, the pass-through window grows: the upper page-number bits shift by 21 and the low 21 bits of the virtual address are copied verbatim, with the hardware faulting on a misaligned superpage if the low 9 bits of the page number are not zero. At two levels up, a 1 GiB page, the top bits shift by 30 and 30 bits of your address ride through, the low 18 required zero. Translation replaces the page number and copies everything below it untouched. The bigger the page, the more of your address passes through unchanged.

The code is the insight here:

uint64_t phys_addr_from_ppn(uint64_t ppn, uint64_t offset) {
    return ((ppn & 0xFFFFFFFFFFFULL) << 12) | (offset & 0xFFFULL);
}

Three lines. The shift moves page-number bit k to address bit k plus 12; the masks make the contract explicit, 44 bits for the page number, 12 for the offset, and anything above those widths is never read, so a stray high bit in a caller cannot leak into the address; the OR recombines two disjoint fields, so no carry can cross between them. Your xv6 walk() always descends to level 0, so every mapping it builds is exactly the 4 KiB case this formula covers.

The test is deliberately built nothing like the code it checks. The oracle never shifts a whole field: it walks destination bits 0 through 55 and sets each one individually from a single-bit extraction, so it shares no structure with the implementation and cannot share its bugs. 60,331,824 checks, roughly one for every second in almost two years, zero mismatches, and the checksum 235e187d99433244 identical across three builds. One conversion costs 4.275 nanoseconds, best observed, about the time light takes to cross four feet of a room. The honest boundary: the lab proves the 4 KiB case. The megapage forms above are verified against the spec text, not yet against a differential oracle, so they are the next rung, not a claimed proof.

One sentence to carry away: the page walk replaces the page number and copies everything below it untouched, and the bigger the page, the more of the address rides through.

Related work: crash triage is $250/symptom, fixed price. .

Choose how to get in touch

The project brief is filled in for you.

Compose in Gmail Use my email app