1113. virtio: what an outside maintainer would fix before it leaves this tree, if it leaves
Raised by a read-only outside review of crates/virtio, read as a stranger to this tree would meet
it. It changes nothing; it lists what the next lanes change, and it puts one question to the
architect first, because every other item depends on its answer. The architect answered it
(Decision 1).
There is no review package for this crate in notes/crate-reviews/, no row in
notes/crate-reviews.md, and no step for it in journey 5. So this review has no settled baseline
to take. The one ruling it takes as settled is the crate name: virtio is ratified as a proper
name (the specification's own) and this review does not reopen it. Everything else below is open.
Reuse: script/crate-review-packet, script/crate-standalone, script/names,
helpers/name_release.py, the template partsfoundry/crate-workflows, and the crates.io API for the
prior-art figures. No new tool.
Goal
A reader who opens crates/virtio can tell in one screen what it is. Today it is the body of one
program (block_driver). It has seven entry points that each drive a device and never return. Six
of them are test roles the QEMU suite spawns, and one is the block server RedoxFS runs on. Whatever
the architect decides about where that code lives, the code that stays is sound on every path a
device or a client can reach. Its layout constants are the kernel's and not a copy of them. Its pure
logic is testable on the host, and its names pass design/naming.md.
Finding status
- P0-1, the crate cannot leave as it stands: Done, #3662. The roles live in
components/src/block_driver_roles.rs(Decision 1, ruled 2026-11-16 UTC, option A). - P0-2, no test runs outside QEMU and no proof exists: Done, #3613.
- P1-3, the ring layout is an unchecked copy of the proved layout: Done, nifeos/moho_abi#3 and
nifeos/nife#4095.
moho_abi::virtual_ioholdsQUEUE_ENTRIES,DESCRIPTOR_TABLE_OFFSET_BYTES,AVAILABLE_RING_OFFSET_BYTES,USED_RING_OFFSET_BYTES,RINGS_END_OFFSET_BYTESandRING_BLOCK_BYTES(names provisional), pinned under the version gate of milestone 1075 (what an outside maintainer would fix before the move) item 11. The kernel, the validator and every virtio driver import them. - P1-4, a client-caused device error kills the block server: Done, #3520.
- P1-5, two
unsafeblocks state an unchecked precondition: Done, #3520. - P1-6, a handshake step the specification requires: Done, #3559, #3574 and
#3628. The driver-side
Versioncheck stays closed on purpose (Decision 3). - P1-7, four completion loops and three submits: Done, #3613.
- P1-8, the receive parser trusts the buffer: Done, #3520.
- P1-9, names against
design/naming.md: Done, #3816 and #3983. Every name the item lists is spelled out, each register, feature bit, descriptor flag and request type keeps the specification's spelling as#[doc(alias)]and in its doc comment's opening, and the public entry points carryName:blocks. All are provisional (maintainer, two-way: the program publishes no name). - P1-10, the documentation describes a different crate: Done, #3613 and #3662.
- P1-11, the manifest does not stand alone: Will not fix. After the fold (#3662) the roles have no manifest of their own, which follows from Decision 1, ruled 2026-11-16 (UTC).
- P2-12,
find_filetrusts the name length: Done, #3613. - P2-13,
disk_size_bytesand the configuration generation: Done, #3520 and #3613. - P2-14, one request in flight on the production path: Done, #3613.
- P2-15, an unused parameter of
run_attack: Done, #3613. - P2-16, an unbounded
complete_block: Done, #3613. - P2-17, the register map unchecked against a second driver: Open. Read against
virtio-drivers0.13 and the virtio 1.2 tables, every constant agrees; the recording-transport test is not built. - Decision 1, fold the roles into
block_driver: Done, #3662 (ruled 2026-11-16 UTC, A). - Decision 2, the ring layout moves to
moho_abi::virtual_io: Done, nifeos/moho_abi#3 and nifeos/nife#4095 (maintainer, provisional, 2026-11-14 UTC). - Decision 3, the kernel checks
Versionand the driver does not: Done, #3628 (maintainer, provisional, 2026-11-15 UTC).
Open decisions
None.
What was checked, and how
The tools run, the sources read and what was not run are in the appendix.
Prior art
The comparison with nearby work is in the appendix.
The items
Each item states what is wrong, where, why it matters, the fix, and the effort (S under a day, M a few days, L a lane of its own). Each also says whether it is a one-way door (a published name, wire format, identity, layout or dependency) or two-way.
P0
1. The crate cannot leave as it stands, and by the standing rules it should not leave as a
crate at all. DONE (#3662 folds the roles into components/src/block_driver_roles.rs).
Cargo.toml lines 12 to 18 names four path dependencies. One of them is user_mode_runtime,
the SDK. The contract-crate ordering (milestone 1017 (the contract crates leave in this order)) has the SDK leaving last, because a crate that
leaves must reference nothing back into this tree. The crate's seven public items
(src/lib.rs lines 198, 246, 297, 321, 352, 872 and 933) are fn(u64) -> ! entry points: five test roles
the QEMU suite spawns, one abandon-and-die role, and one server. They hardcode this tree's
conventions. These include capability slot numbers (:42-45, :910, :923), the DMA window
address (:39), and the kernel image address (:326, :357). They also include the test disk's
file names motd and scratch (:213, :256). Finally, they hardcode a private report protocol
with the kernel test (0xDEAD_..., 0xE4 through 0xEA, 0xE2xx, CRKWRIT1). It has one consumer, components/src/block_driver.rs. The
ruling that a crate gets its own repository only when it would publish on its merits or when more
than one repository consumes it fails on both counts. Why it matters: a repository made for this
crate would be a repository nobody outside could use and that pins the SDK back into nife. The
fix: see Decision 1. Effort: S to fold the roles into the program, L to re-cut a library. One-way:
a repository and a published name.
2. No test can run anywhere but under QEMU, and no proof exists. DONE (the pure logic takes slices or closures, with host tests in tests.rs and Kani harnesses in verification). The crate has zero unit
tests, no Kani harness, and one no_run doctest (:192-197). Its pure logic is find_file
(:399-421), pattern_byte (:232-239), ip_checksum (:606-617), build_dhcp_discover
(:723-796) and parse_dhcp_offer (:821-865). Each reads or writes the fixed DMA_VA through
volatile pointers, so none of it can run on the host. notes/mutation-testing.md records that a
census of this crate measures nothing. Why it matters: every behavior below that this review
found by reading would have been a one-line host test. The fix: route the DMA accesses through a
window value (user_mode_runtime::mapped_window::MappedWindow, which virtual_io_net_transport
already uses, or a &mut [u8] for the parsers), so the parsers and builders take a buffer and a
host test can hand them one. Effort: M. Two-way.
P2: later
The P2 items are in the appendix.
P1: before the tag
The P1 items are in the appendix.
Decisions for the architect
Three decisions, each with the background first, then the recommendation, prior art and a concrete example. Decision 1 is the architect's ruling; the maintainer decides Decisions 2 and 3, provisionally.
Decision 1. Whether crates/virtio leaves this tree, and as what
Background. The crate is the shared body of one program, block_driver: five test roles the DMA
confinement and parity suites spawn (run, run_write, run_write_abandon, run_attack,
run_attack_indirect), one DHCP exerciser (run_net), and the block server RedoxFS runs on
(run_blk_server). It became a crate when a second binary compiled the same file (the aarch64
hello roles, per the comment at components/Cargo.toml lines 106 to 108); that second consumer is gone,
and block_driver.rs is the only caller. It depends on the SDK (user_mode_runtime), which the
contract-crate ordering has leaving last. Two standing rules bear on it. First, a crate gets its own
repository only when it would publish on its merits or when more than one repository consumes it.
Second, a program package leaves as one repository holding its programs and any crate only that
package uses. Two ruled milestones are about to change what a nife virtio driver is. One is a direct
grant for IOMMU-confined virtio-pci functions (1062 step 7), under which the driver sets its own
queues up through the device registers. The other is a startup page that replaces the fixed DMA_VA
(1069). Meanwhile the tree holds six copies of the virtio-mmio handshake and ring constants, and
none of them is in the crate named virtio as a shared thing.
The rule in force, from the architect on 2026-11-16 (UTC). The crate does not leave this tree as a crate. Its
contents fold into the program that owns them, components/src/block_driver.rs (or a module beside
it), and leave later with the drivers package. The ratified name virtio stays reserved for a library,
cut later, that holds what the six copies share. That means the register vocabulary at the
transport seam, the status and feature bits, the handshake, the descriptor and ring accessors at
the validator's fixed layout, the blk request chain and the net header. It has no test role and no
slot convention in it. Whether to cut that library, and when, waits for 1062 step 7, because the
direct grant changes what the shared handshake does. The rules favor the fold (a crate gets
its own repository only when it would publish on its merits or when more than one repository
consumes it), and the fold would win at equal effort.
Prior art. Linux (drivers/virtio/virtio_ring.c shared by every class driver), OpenBSD
(sys/dev/pv/virtio.c under vioblk and vio) and Redox (virtio-core under virtio-blkd,
virtio-netd, virtio-gpud) all put the shared half in one library and the device drivers beside
it. None of them ships test roles as a library. The reuse record already names Redox's
split as the shape nife chose when it refused virtio-drivers.
Concrete example. components/src/block_driver_roles.rs lines 59 to 117 and
components/src/virtual_io_net_transport.rs lines 54 to 87 hold the same handshake constants. The
fold removes a crate boundary that guards nothing, and cutting the library later removes one of
the two copies and the four others with it.
Decision 2. Where the kernel-to-driver ring layout lives
Background. SETUP_QUEUE places a queue's rings at fixed offsets inside the queue's ring block of
the driver's DMA region. The offsets and the queue size are the ones direct_memory_access_validator
proves (LAYOUT_QSIZE, DESC_OFF, AVAIL_OFF, USED_OFF, RING_BLOCK). The kernel aliases
the validator's constants so the layout it runs is the proved one. Every userspace driver spells
the same numbers as literals. ยง46 (thin primitives or whole subsystems; we write everything in between) priced the edge from components to the validator, and the
tree did not take it (milestone 410 (six copies of the shared-frame accessors), per notes/net/the-driver-and-dhcp.md lines 130 to 137). The
validator has no dependencies. moho_abi::virtual_io already carries one DMA-layout fact for drivers, the
word offset at which the kernel writes the region's physical base.
Recommendation. The five layout constants move to moho_abi::virtual_io, which is the contract the driver
already speaks (SETUP_QUEUE's documentation there already describes "the fixed offsets of that
queue's ring block"). The validator and the kernel alias them from there, so the proof still runs on
the layout the kernel runs. Every driver then imports what it already depends on through
user_mode_runtime, and no new edge is taken. The alternative, drivers importing the validator
directly, is the smaller edit and a zero-dependency edge. This review sets it aside only because it
makes a proof crate a contract crate. If neither is wanted, the fallback is a BUGS entry at every
copy, which is what virtual_io_net_transport has today and this crate lacks.
Prior art. Linux puts the ring layout in a UAPI header (include/uapi/linux/virtio_ring.h) that
both the kernel's ring code and every userspace consumer (QEMU, rust-vmm's virtio-bindings)
compile against; the layout is a contract, and the contract has one home. Nife's own moho_abi crate
is the same thing for the system call boundary.
Concrete example. kernel/src/virtual_io.rs lines 497 to 513 alias the validator;
components/src/block_driver_roles.rs lines 93 and 127 to 129 and components/src/virtual_io_net_transport.rs lines 73 to 87 spell 8, 0x000, 0x080,
0x100, 0x200. After the move, each of those is moho_abi::virtual_io::RING_... and a change to the
proved layout is a compile error in every driver.
Decided by the maintainer on 2026-11-14 (UTC), provisional: a two-way door, which the architect may
revisit. The layout values are already the agreement between kernel and driver and do not change;
only the home of their names moves, inside unreleased crates. They stay relevant after the virtio
default ruling of 2026-11-11, because every mediated grant still uses SETUP_QUEUE at the
validator's layout. The five constants and the rings' end, which the validator derives from them,
live in moho_abi::virtual_io beside the DMA-layout fact already there, with spelled-out names,
provisional: QUEUE_ENTRIES, DESCRIPTOR_TABLE_OFFSET_BYTES, AVAILABLE_RING_OFFSET_BYTES,
USED_RING_OFFSET_BYTES, RINGS_END_OFFSET_BYTES and RING_BLOCK_BYTES. The validator, the
kernel and every driver import them. They are on the pinned-value list and under the version gate
of milestone 1075 (what an outside maintainer would fix before the move), its item 11. Item 3 is
the work.
Decision 3. The driver does not check Version; the kernel does
The maintainer ruled this on 2026-11-15 (UTC), provisional: a two-way door, which the architect may revisit.
The rule in force. The driver reads the magic value and never the Version register. The kernel
is the one layer that reads a real Version. It offers only modern devices on either bus: it
refuses any value but 2 in every build, on the mmio scan, and its PCI transport answers 2 for the
same offset. A driver never sees a device whose Version is not 2, so a driver-side check would
test what the kernel already tested. The direct transport (the virtio-pci path of 1062 step 7) has
no such register and answers 0 for any offset it does not name. A driver-side check would need that
transport to invent an answer. The maintainer closes item 6's driver half as not done, on purpose.
Background. A virtio-mmio device reports a version in the register at 0x004. Version 1 is the
legacy layout and version 2 is the modern layout the kernel drives. The virtio specification
commit oasis-tcs/virtio-spec@bb1dd2e1 (2026-06-01) adds mmio version 3. It keeps the version 2
register layout and makes reset asynchronous: the driver polls Status until it reads 0. So
versions other than 2 exist, and the kernel's SUPPORTED_VERSION of 2 refuses version 3 too,
which is the strict choice. Accepting 3 later needs the kernel's reset_to_features_ok to poll
Status the way unregister does after its reset (kernel/src/virtual_io.rs).
Prior art, from memory and not re-read. Linux's virtio_mmio drives version 1 and version 2 with
a layout each and refuses any other; it is one layer that both reads and drives. Redox's
virtio-core is PCI-only and has no such register. Here the kernel owns the register and the
driver sits behind it, so the check lives where the register is read.
Concrete example. A board whose firmware offers a version 1 block device never reaches the driver. The kernel's scan does not offer the slot, so nothing starts a driver for it.
Follow-on
- Milestone 1062. The shared library that holds the name
virtio, ruled 2026-11-16 UTC. Whether and when to cut it waits on milestone 1062 (the device control planes leave the kernel), step 7. - Outstanding. P2-17's recording-transport test, before anyone cuts the library that holds
the name
virtio.
Done when
The checks are in the appendix.
BUGS
- The review did not boot the QEMU suite. The review took the roles' behavior under test from the
entry points and from
notes/virtual-io.md, and did not observe it. MAXIMUM_QUEUES, the boundSETUP_QUEUEputs on a queue index, stays indirect_memory_access_validatorand is not inmoho_abi::virtual_io. A driver learns it only from a refusal. Decision 2 moved the layout and not the bound.- Item 14's figure is the storage benchmark already recorded in
notes/benchmarks.md; nobody ranscript/benchfor this milestone. - The crates.io figures are one API call each at the time of the review; the
virtioname's availability on crates.io rests on a single not-found response. - The six-copy count of the handshake constants comes from a
grepfor the magic value andS_FEATURES_OK; it did not compare every constant in every copy.
Index row
An outside review of crates/virtio before any move. The crate is one program's body and test roles
with a path dependency on the SDK, so the first question is whether it leaves at all. Two decisions
go to the architect (fold or re-cut; where the ring layout lives). The review has two P0 items and
five P2 items. Its nine P1 items cover a client-reachable panic in the block server, an unchecked
unsafe precondition, two skipped handshake steps, a length-blind frame parser, copied layout
constants, duplicated loops and the names.