notes

NVMe: the first non-virtio disk

The tree spells it non_volatile_memory_express, since calef's ruling of 2026-09-17 (DECISIONS §154) and the rename of 2026-09-18. NVMe stays in this page's prose, because that is the specification's own name and the word the datasheet, the boot output and QEMU's -device nvme all print; what moved is the crate, the kernel module, its NonVolatileMemoryExpress type, and the program. A reader who greps nvme and finds nothing is looking for the expansion.

The storage half of milestone 53 (the board's own peripherals), decided by calef on 2026-08-15: NVMe first. Milestone 55 (Time Machine), whose backup workload needed the sustained sequential write SD media lacks, has the status REMOVED. A real PCIe device driver still compounds toward the machines this project wants to run on. Everything this project drove before this was a QEMU paravirtual device. An NVMe controller is a real device family with a real specification, the same one in the M.2 drive on the desk. QEMU emulates it faithfully enough that the driver written here is the driver the board-side work will reuse.

The shape

The tree's usual split, with the driver in two processes from one program:

How the protocol works, in one sitting

NVMe is a queue machine. The driver owns rings in its own DMA memory; the controller owns nothing in the driver's space except what commands point it at.

  1. Commands are 64-byte entries the driver writes into a submission queue (SQ), then announces by writing the ring's new tail index to that queue's doorbell register in BAR0.
  2. The controller fetches the command (a DMA read of the SQ), does the work (DMA to or from the addresses in the command's PRP fields), and posts a 16-byte entry to the paired completion queue (CQ).
  3. Every completion carries a phase tag that the controller flips each time it laps the ring. The ring starts zeroed, so the first lap writes tag 1, the second tag 0, and so on; the driver knows which tag means "fresh" and needs no shared index and no interrupt to spot a completion. crates/non_volatile_memory_express's CompletionQueue owns that discipline and a Kani harness proves the flip happens exactly at the wrap.
  4. Queue pair 0 (the admin queue) is created by plain register writes (AQA/ASQ/ACQ) while the controller is disabled; every other pair is created by admin commands (CQ first, because an SQ names its CQ at creation). Admin commands and I/O commands are the same wire shape through the same rings, so bring-up itself exercises the transfer machinery.

The driver serves whole 4096-byte filesystem blocks, file_system_contract::blk's unit, and exposes exactly the blk-IPC verbs as methods: read_block, write_block, size_bytes. A block is one to eight logical blocks depending on the namespace's LBA format (QEMU's default is 512-byte LBAs, so eight); IDENTIFY tells the driver the format and IdentifyNamespace::blocks_per does the arithmetic.

The confinement story, which is the interesting part

This is the first DMA device in the tree whose addresses the kernel cannot validate before the device uses them. The virtio drivers run at EL0 behind a VirtualIo capability: the kernel owns the queue addresses and checks every descriptor against the driver's DMA region before ringing the device. NVMe's equivalent of a descriptor is the PRP inside a command the controller fetches from driver-written memory, and nothing kernel-side parses commands on their way past.

What bounds the device instead is the IOMMU alone (milestone 16b (IOMMU-backed driver isolation)). find_and_confine confines the controller's requester id to its DMA run before any process can enable it, so no enabled controller could ever reach other memory. On a machine without an IOMMU nothing bounds it, and nife trusts both processes (§86's ruling: confinement means an IOMMU). All three test boots have an IOMMU denying unlisted requester ids by default. They are aarch64's SMMUv3, riscv64's ratified RISC-V IOMMU, and x86_64's VT-d, confirmed behind this driver 2026-08-25 per the evidence section of §86 (whether an NVMe driver can leave the kernel). That cuts two ways. The confinement is real (an address outside the region faults in hardware). And it is mandatory: an unconfined NVMe controller on these machines cannot fetch its first command, so a boot where someone forgets the confine call fails loudly rather than running unconfined.

Note the flag difference in the runners: the virtio PCI devices need iommu_platform=on or QEMU silently routes their DMA around the IOMMU. The NVMe device model needs no flag, because a real PCI device's DMA always goes through the PCI address space. One less thing to forget, and the reason the runner comment says so at the attach line.

Two processes, and what each holds

The split costs no new system call surface, because NVMe 1.4 section 3.1 already put a page boundary where the authority boundary belongs. The controller registers (CC, CSTS, AQA, ASQ, ACQ) are below offset 1000h and the first doorbell is at 1000h.

What the split withholds from the data plane, stated precisely because it is easy to overclaim. Creating a queue is what names the physical address a ring lives at, in a PRP field of an admin command, and the admin rings' own bases are the ASQ and ACQ registers. A process that can issue no admin command and cannot name those registers cannot choose where any ring lives.

What it does not withhold. The IOMMU keys on the controller's requester id and bounds it to the whole run, admin rings included, because the controller fetches from both halves. So a data plane that computes a PRP backwards from its own base can make the controller overwrite the admin ring. And with CAP.DSTRD = 0 the admin doorbells share the granted page, so it can ring the admin queue without being able to write what that queue holds. Both are denial of service against the controller rather than an escape, and option 4's doorbell validator is what would close them.

§86's option 4 stays addable. Which submission queue the controller is told about is the admin process's choice. Doorbell mediation would put that choice and the doorbell behind a kernel capability, and the data plane would ring through it instead, changing little else.

What x86_64 needed that the other two did not

Wiring the same driver onto q35 (2026-08-25, decisions §86's evidence section) surfaced two bugs that only a real (non-virtio) DMA device with a real PVH boot could have found, both fixed rather than worked around:

Neither is x86_64-only in principle (a real UEFI machine, milestone 87, picks its own BAR addresses too), which is why both fixes check against what is actually true rather than against which architecture is running.

EXAMPLES

Wire the server and move a block through it (this is the boot test, abridged; the full version is system_tests/src/user/non_volatile_memory_express_tests.rs). Every one of these calls crosses a rendezvous to the unprivileged data plane; the caller holds one endpoint and no device:

let disk = non_volatile_memory_express_service::ensure(
    program("non_volatile_memory_express").unwrap(),
)
.expect("an NVMe controller is attached");
// Against the geometry this boot was handed, never a constant: the same line holds for the
// runner's 8 MiB image and for a 256 GB namespace.
assert_eq!(disk.blk(blk::SIZE, 0) as u64, disk.size_bytes);

// SAFETY: a blk request is a CALL, so one side holds the buffer at a time.
unsafe { disk.transfer_block() }.fill(0x5a);
assert_eq!(disk.blk(blk::WRITE, 37), 0);   // eight 512-byte LBAs, one command, one PRP
unsafe { disk.transfer_block() }.fill(0);
assert_eq!(disk.blk(blk::READ, 37), 0);
assert!(unsafe { disk.transfer_block() }.iter().all(|b| *b == 0x5a));

Run the proof of all of it on all three architectures:

script/test            # the boot test runs in every leg; xtask attaches the controller
# The queue mechanics alone, on the host, in milliseconds.
cargo test -p non_volatile_memory_express
# The eight harnesses, ~seconds.
cargo kani -p non_volatile_memory_express

Poke at the controller interactively:

cargo xtask build && NIFE_NVME=target/nife-nvme.img cargo xtask run
# (write the image first: any size a controller will take, e.g. an 8 MiB zero file)

What the test proves, and where

system_tests/src/user/non_volatile_memory_express_tests.rs's a_confined_el0_process_serves_the_block_interface_end_to_end, on all three architectures (§19 (architectural parity is a tenet); x86_64 joined 2026-08-25, decisions §86's evidence section). The controller enumerates over ECAM and comes up confined behind the SMMU (aarch64), the RISC-V IOMMU (riscv64), or VT-d (x86_64). It answers IDENTIFY with the attached disk's exact size. Then an EL0 process serves SIZE, WRITE, READ-back with byte-exact verification. A second block is written with a second pattern so that each block reads back its own (the write landed where it said, not everywhere). There is a refusal of a block outside the namespace, a flush count that moves, and a refusal of an opcode it has no verb for. Every one of those is written against the geometry the boot was handed rather than against the runner's image size, and none of them assumes what the disk held beforehand. So the same test proves the same things on a 256 GB disk (milestone 318 (the NVMe boot test on real geometry)). It asserts the IOMMU was active, because the IOMMU is the whole of what stops a compromised admin process or data plane reaching memory it was not given.

This is not fatal risk 6's experiment, and nothing here should be read as one. Milestone 16b already proved IOMMU-backed isolation against emulated silicon; risk 6's open clause is about a real device at real speed, on xenon, photographed. The boot that takes it, its two preflights and what each outcome means are risk-6-bench-evening.md.

"Confined" means the IOMMU unit that owns the controller is the one translating. Some unit being up is not enough. On a machine with two VT-d units (a client Intel part: one for the GPU, one catch-all), that is a weaker claim; see that page's first night-of condition. A controller the driver refuses fails the test.

The parity note milestone 53 requires: what ships on all three architectures is this driver against QEMU's -device nvme, on the two virt machines and on q35. The VisionFive 2's PLDA XpressRICH root complex is a different host bridge (no pci-host-ecam-generic node, so find_nvme_device truthfully reports nobody home on the board today). Driving it is the board-side follow-up, and this driver is written to need only a working enumeration and a BAR from it.

The direct memory access escape test

non-volatile-memory-express/the-direct-memory-access-escape-test.md carries the test that aims a confined server's controller outside its region, and its attacker role.

The client windows

Each client stages in the transfer window its badge names (milestone 834 (ioping on nife and Linux)). A client maps only its own window, and the server answers one request at a time, so two clients staging at once touch different pages. A badge no client was given is refused before anything is staged.

BUGS