roadmap BUILT

256. x86_64 places PCI BARs in a hardcoded window, and on xenon that window is RAM

Built on 2026-09-04. Minted the same day by calef, from design/roadmap/0256-a-bar-window-the-machine-agreed-to.md (written 2026-09-03 by the milestone 247 sweep, out of milestone 165's Follow-on), on the evening xenon proved it from the bench. (Number provisional until the merge queue lands it.)

It stopped being a prediction on 2026-09-04

Milestone 165 wrote this on 2026-09-02, before any x86_64 kernel had met real firmware:

That is the number to read first on xenon's first boot: a machine whose RAM reaches above 0xc000_0000 would have this kernel move most of its bus on top of memory, and the line says so before anything is driven.

Two days later, on xenon's second boot, with #738's local-APIC fix in:

[PANIC] panicked at kernel/src/arch/x86_64/mmu.rs:349:9:
failed to build the kernel page tables: AlreadyMapped mapping pci bar window
0xc0000000..0xc0200000: 0xc0000000 is also claimed by ram above the image
0xb9fbf000..0xc8940000

and one line above it, the census reading exactly what 165 said to read first:

pci : 15 function(s) on the bus, 13 with a BAR outside 0xc0000000..0xc0200000

The prediction, the instrument that would show it, and the machine that confirmed it were all written down before the confirmation arrived. That is the shape this project is supposed to produce, and it is worth stating plainly because the failures get recorded far more often than this does.

The panic is the lucky half and should not be mistaken for the risk. map_everything refused because the window collided with a range the mapper had already claimed, so the machine stopped. Had xenon's RAM ended just below 0xc0000000 instead of at 0xc8940000, nothing would have collided, and place_bars would have relocated thirteen of fifteen functions on top of memory the allocator believes it owns. The failure would have arrived later as corruption somewhere unrelated. The proposal named that outcome a day before the boot: "not a device that fails to enumerate, it is a device writing into RAM the allocator believes it owns."

Why the constant was right and is not

PCI_BAR_PHYS is 0xc000_0000, q35's conventional 32-bit PCI hole. Its doc comment is honest about its evidence, and the evidence names the boundary it does not cross:

confirmed disjoint from RAM, the ECAM window, the HPET and both APICs by reading QEMU's own info mtree on 2026-08-24 with -m 256M

On a 256 MiB machine 0xc000_0000 is empty. xenon has 16 GiB and its low DRAM runs to 0xc894_0000, straight through the window. The constant was checked against the only machine that existed at the time and correct by luck anywhere else. That is the class this tree has now hit three times on one architecture: a constant that is right on emulated machines and has no firmware source. ECAM is the same class and is fine, because ACPI's MCFG names it and the kernel follows the table (PCI_ECAM_PHYS says 0xb0000000 while xenon's MCFG says 0xf0000000, and the kernel took the table's answer). The BAR window's equivalent lives in the PCI host bridge's _CRS, which is AML, which milestone 165 refused and this block does not reopen.

What to build

Take the window from the machine, from two sources that can disagree.

Fail loudly when they disagree rather than falling back to the constant. That is milestone 215's posture for the analogous case, and its reason carries: a silent fallback to the old behavior is the original bug wearing the clothes of a graceful degradation.

And handle the asymmetry that this boot exposed, which the proposal did not name. QEMU hands the kernel unassigned BARs and real firmware hands it placed ones. place_bars relocates everything into the kernel's window unconditionally, which is why the census reads 13 of 15 rather than 0. A BAR firmware has already placed in a window firmware itself chose is a BAR that wants adopting, not moving; only genuinely unassigned BARs need placing. Whether that split belongs in this milestone or in a second one is the lane's call to make and to say out loud.

The measure

pci::bar_census's second number reaching zero on xenon, or the window being one that machine agreed to. Under QEMU the census is the same instrument and is already wired to the boot line, so the work is testable on patagonia and only confirmed at the bench.

It is also one line further into the tour. The boot stopped at the panic! in initialize in kernel/src/arch/x86_64/mmu/kernel_map.rs on 2026-09-04 and everything past it is unseen on real firmware, so the honest expectation is that this milestone buys the next stop rather than the end of the tour.

What was built

The window is derived, and the constant is gone. arch::x86_64::mmu::PCI_BAR_PHYS no longer exists; arch::x86_64::mmu::memory_mapped_io_window answers instead, and the boot tour panics rather than booting if it cannot.

Two sources, exactly as the block asked, and one distinction the block did not anticipate:

And the derived window steps over what the kernel already knows decodes in the hole, which is the part that turned out to matter most. window_in_hole takes the lowest aligned span that collides with none of the framebuffer, the ECAM aperture, both APICs, or VT-d's register file. xenon's framebuffer is at 0xd0000000, byte for byte the floor of its hole. A derivation that took the floor and asked nothing else would have put the first BAR it placed on top of the console the panic prints on. That is not only a prediction about a machine nobody here can boot: the same collision reproduces under OVMF on patagonia, and the boot line there says so.

The asymmetry is handled here rather than deferred, because the measure needs it. The block left that to the lane, and the honest answer is that deriving the window alone does not move the census. Xenon's thirteen misplaced functions would still have been thirteen, and place_bars would then have tried to move all of them into a 2 MiB window, exhausting it on the first BAR that wanted a megabyte. So pci::place_bars grew an adoption arm. A nonzero BAR that overlaps no RAM region is mapped device-typed where it stands (mmu::map_page, after the fine map exists) and left alone. Overlapping RAM is the one refusal and it is the whole safety argument. Whether an address decodes to the bus is the machine's claim, and it made it by writing the BAR. But a device window mapped over memory is a device answering where the frame allocator allocates, which is what this milestone is about.

pci::bar_census's second number therefore means something narrower and better, and the change is stated in its own doc comment. It counted every BAR outside the kernel's window, which was the right question while every one of them was about to be relocated onto a window nobody had checked. Now "outside the window" is ordinary and "outside the window and on top of RAM" is the whole problem. Zero is the passing answer.

What was measured

Path Derived window Functions Census, second number
QEMU q35, PVH, -m 256M 0x10000000..0x10200000 8 0 (was 5 of 8)
QEMU q35, OVMF, bare tour 0x80400000..0x80600000 6 0 (was 3 of 6)
QEMU q35, OVMF, suite devices 0x80400000..0x80600000 8 0 (was 5 of 8)
xenon, real UEFI unconfirmed, see BUGS 15 was 13 of 15

Three measurements are worth stating on their own, because each one settled a design question that would otherwise have been argued:

Five test cases were added to mmu.rs's map_tests, against the xenon fixture that was already there: both ends of the 17 GiB machine's hole and the window stepping over a framebuffer at the floor. An empty hole gives up its floor, a hole with no room answers None rather than squeezing, and the disagreement message names both numbers. script/test passes on all three architectures; script/lint exits 0.

BUGS

Follow-on

Index row

milestone 165 predicted it on 2026-09-02 and xenon confirmed it on 2026-09-04: PCI_BAR_PHYS was q35's hole checked once at -m 256M, and a 16 GiB machine's RAM runs through it. The constant is gone: mmu::memory_mapped_io_window derives the window from the firmware map's first gap above low DRAM and from Intel's TOLUD. It panics naming both numbers when they disagree, and steps over the windows this kernel already knows decode in the hole. Xenon's framebuffer at the hole's exact floor is why. pci::place_bars adopts a BAR firmware already placed instead of moving it, mapping it where it stands unless it overlaps RAM. The census's second number now counts only what can be neither used nor adopted, and reads 0 on every path measured (was 5 of 8 under PVH, 3 of 6 under OVMF, 13 of 15 on xenon). QEMU models TOLUD nowhere, so absence is distinguished from disagreement and the map is the only source under emulation. Unconfirmed on xenon, which needs a bench session with a camera.