Introducing a new way to review your PRs.

Read the announcement

arcboxlabs / arcbox

Run AI agents on real and isolated machines — own kernel, filesystem, and network — with <100ms boot. Local first, OCI compatible, pure Rust.

View on GitHub

32 documents · Updated Nov 6, 2026

docs / virtio-devices

VirtIO device stack

The VirtIO device stack gives each guest a standard way to use host-backed storage, consoles, networks, shared filesystems, entropy, memory control, and host-guest sockets. The stack joins common queue and guest-memory rules to device-specific services, then presents each device to the VM monitor through VirtIO MMIO and interrupts.

System role

The stack is the device boundary between a guest kernel and ArcBox host services. A guest driver publishes work in a VirtIO queue. The matching host device consumes that work, calls a backing service, writes the result back to guest memory, and signals the guest.

The stack has two broad parts:

  • arcbox-virtio-core defines the device contract, device IDs, status flags, guest-memory access, and split virtqueues.
  • The per-device crates turn queue traffic into host work for block storage, console I/O, Ethernet, FUSE filesystem operations, entropy, memory ballooning, and vsock connections.

The custom Hypervisor.framework monitor uses these Rust device implementations. The Virtualization.framework path instead uses Apple's native VirtIO device objects for the same guest-facing roles. See Virtualization platform for the larger VM model, and VM lifecycle and hypervisor backends for backend selection and VM execution.

Device contract

The VirtioDevice contract gives the monitor one lifecycle and queue interface for all custom VirtIO devices. Each device reports its type and features, accepts the guest's feature choices, exposes device configuration, activates after the guest is ready, resets when requested, and processes queue entries.

The contract keeps device behavior separate from transport behavior. The monitor owns MMIO registers and interrupt state. A device owns the meaning of its request and response buffers. DeviceCtx joins a device to guest RAM and to the interrupt callback that belongs to its MMIO device.

References: virt/…/lib.rs• L34-69 virt/…/lib.rs• L81-101 virt/…/lib.rs• L153-223

Guest memory boundary

Guest queue addresses are guest physical addresses (GPAs), not direct host offsets. GuestMemWriter maps those addresses into the VM's RAM region and rejects ranges outside that region. This boundary lets every device use the same view of guest memory while keeping malformed queue data from reaching unrelated host memory.

Device-owned buffers remain under host control until the device publishes a used-ring entry. That ownership rule lets a device fill a response or read a request before the guest reuses the buffer.

References: virt/…/guest_mem.rs• L7-20 virt/…/guest_mem.rs• L42-72 virt/…/mod.rs• L226-246

VirtIO transport

VirtIO transport moves work through a split virtqueue. The guest publishes descriptor chains in an available ring. The host reads those chains, performs the device operation, and publishes completion entries in a used ring. Feature negotiation controls optional behavior such as interrupt suppression and device-specific offloads.

Split virtqueues

SplitQueue is the shared queue model for the custom VM monitor's live guest memory. It walks descriptor chains, tracks the guest's available position, writes used entries, and decides when the guest needs an interrupt. Its bounded chain walk handles bad or cyclic descriptor links without leaving a host worker in an endless loop.

The queue also defines the notification handshake. A device can suppress needless interrupts with EVENT_IDX, but it must re-check the available ring before it sleeps. This is important for both throughput and progress: a missed notification can leave a guest request waiting forever.

The older VirtQueue model remains for the Virtualization.framework and local simulation paths. It represents queue rings in host-managed structures rather than serving as a second live HV queue protocol.

References: virt/…/split_queue.rs• L1-23 virt/…/split_queue.rs• L105-146 virt/…/split_queue.rs• L214-365 virt/…/queue.rs• L124-170

Queue notifications

The guest starts a device by negotiating features and setting the VirtIO status to DRIVER_OK. It then programs each queue and notifies the monitor when work is available. The monitor turns the selected queue's MMIO state into a QueueConfig, which gives the device its ring addresses, size, readiness, and RAM GPA base.

The normal request path follows this sequence:

  1. The guest writes descriptors and advances the available ring.
  2. The guest writes QUEUE_NOTIFY through the VirtIO MMIO region.
  3. The monitor selects a device path and drains the queue.
  4. The device or its worker performs host work and publishes used entries.
  5. The monitor raises the device's used-ring interrupt when the device asks for one.

This diagram shows the common request path and the host services behind the device layer.

flowchart LR
    G[Guest driver] -->|descriptors and QUEUE_NOTIFY| T[VirtIO MMIO transport]
    T --> M[VM monitor]
    M --> Q[QueueConfig and guest RAM]
    Q --> D[Device implementation or worker]
    D --> S[Host backing service]
    D -->|used ring| Q
    D -->|INT_VRING| M
    M -->|interrupt| G

References: virt/…/dispatch.rs• L17-80 virt/…/dispatch.rs• L88-195 virt/…/dispatch.rs• L197-367

Interrupt delivery

A completion is useful only when the guest can observe it. The monitor records the VirtIO interrupt status and drives the device's level-triggered IRQ. For asynchronous custom-HV workers, the completion path also exits parked vCPUs so a guest waiting in WFI can run its interrupt handler without waiting for another VM exit.

The monitor does not use one generic shortcut for every device. Block I/O has dedicated workers, network TX has a direct hot path, and other queue notifications use the device contract. These choices change where work runs, but not the guest-visible VirtIO queue contract.

References: virt/…/mod.rs• L102-119 virt/…/mod.rs• L393-429 virt/…/dispatch.rs• L245-352 virt/…/blk_worker.rs• L263-280

Device families

Each device family gives a standard guest interface to one host capability. The device-specific crate owns request meaning and host-service policy. The monitor only needs the common VirtIO identity, configuration, queue, and interrupt behavior.

Block storage

The VirtIO block device presents a disk image as a guest block disk. Its request contract covers reads, writes, flushes, device identity, discard, and write-zeroes operations. Sector and byte ranges are checked against the device capacity before host I/O begins, so malformed or overflowing guest values do not become host file offsets. arcbox-virtio-blk/…/request.rs defines this shared wire contract.

Discard is advisory because it can release host storage without changing guest-visible data. Write-zeroes is mandatory because reads from the requested range must return zero. The custom HV setup exposes one request queue per vCPU and sends queue work to block workers so file I/O does not block a vCPU while it runs guest code.

The block device reports capacity and read-only state through VirtIO configuration. The worker completes every request, including malformed or unsupported requests, so one bad descriptor does not strand the guest queue.

References: virt/…/request.rs• L8-21 virt/…/request.rs• L56-150 virt/…/request.rs• L153-204 virt/…/lib.rs• L1-17 virt/…/mod.rs• L19-97 virt/…/setup.rs• L346-377 virt/…/blk_worker.rs• L263-373

Console I/O

The VirtIO console carries guest output to a host console sink and host input back to the guest. Its host sink can be standard I/O, a test buffer, a pseudo-terminal, or a Unix socket. ArcBox uses the socket form for an optional interactive debug console that remains usable before guest networking starts.

The console has separate receive and transmit directions. Guest output is consumed from its TX queue and mirrored to the host sink. Host input is buffered until guest RX descriptors are available, then copied into those descriptors and reported with a used-ring interrupt.

References: virt/…/lib.rs• L1-16 virt/…/device.rs• L100-120 virt/…/device.rs• L244-283 virt/…/console_rx_worker.rs• L1-14

Network connectivity

The VirtIO network device presents an Ethernet NIC with a MAC address, MTU, link state, and optional checksum or segmentation features. A NetBackend moves packets between the device and a host data path. The backend may be a socket-based path, TAP, or an in-process loopback used for tests.

On the custom HV path, the primary NIC connects to the host network datapath used for NAT and guest connectivity. An optional second NIC connects to vmnet for bridge traffic. Guest TX is drained into the host file descriptor. Host RX is injected into guest write buffers by a worker or bridge poll path. Negotiated offload features are passed to the backend so the guest's frame format and the host path agree.

References: virt/…/backend.rs• L7-80 virt/…/mod.rs• L13-49 virt/…/hot_path.rs• L9-20 virt/…/setup.rs• L394-429

Shared filesystem

The VirtIO filesystem device exposes a host directory through the FUSE protocol. The guest sends FUSE requests through request queues. The device passes them to a filesystem request handler and returns FUSE responses through guest buffers. A FUSE session first negotiates protocol version and shared features before normal file operations begin.

The custom HV path pairs each share with an arcbox-fs server and a separate DAX window when DAX is used. The Virtualization.framework path uses Apple's VirtIO-FS device configuration. The guest-facing mount tag identifies the share in both cases. See Guest filesystem sharing for the host directory, mount, performance, and isolation view.

References: virt/…/lib.rs• L1-24 virt/…/virtio_device.rs• L102-181 virt/…/handler.rs• L7-40 virt/…/session.rs• L94-212 virt/…/setup.rs• L276-343

Entropy supply

The VirtIO RNG device supplies random bytes to the guest's hardware random source. The guest can then seed its random pool early in boot. ArcBox includes it in the custom HV device set because a guest service such as dockerd can wait for the random pool when no entropy device is present.

The device has one request queue. The guest gives it writable buffers, and the host fills those buffers with operating-system entropy before completing the requests.

References: virt/…/lib.rs• L1-17 virt/…/lib.rs• L71-127 virt/…/setup.rs• L433-445

Memory ballooning

The VirtIO balloon device lets the host and guest adjust usable memory. The host publishes a target page count. The guest reports its current balloon size and supplies page information through inflate, deflate, and optional free-page reporting queues. The device advises reported guest pages back to the host and completes each queue chain so the guest can continue its memory-management work.

Free-page reporting lets the guest offer pages that are already free without a host target policy. Deflate requests complete without an explicit remap because the host advice keeps the guest mapping valid. Invalid page numbers and ranges are skipped rather than allowed to affect memory outside the guest RAM mapping.

Reclaim results depend on the VM backend and host platform. The custom HV implementation uses host memory advice, while the Virtualization.framework device exposes Apple's target-memory behavior. A target therefore expresses memory pressure or a guest limit; it does not by itself guarantee the same host memory reduction on every platform.

References: virt/…/lib.rs• L1-55 virt/…/lib.rs• L61-101 virt/…/lib.rs• L104-133 virt/…/lib.rs• L247-321 virt/…/lib.rs• L326-420 virt/…/balloon.rs• L63-115

Host-guest sockets

The VirtIO vsock device provides stream sockets between a guest CID and the host CID without requiring guest IP networking. The device handles connection requests, data, credit flow, shutdown, and reset messages. A host-side connection manager tracks active connections and pending host-to-guest operations.

For the custom HV path, host connections use Unix socketpairs. A doorbell wakes the vsock worker when a new connection or host data is ready. The worker injects responses into the guest RX queue and exits parked vCPUs after raising the used-ring interrupt. This path carries agent and control traffic even when the network device is not ready.

References: virt/…/device.rs• L99-154 virt/…/virtio_device.rs• L39-78 virt/…/mod.rs• L31-57 virt/…/vsock_rx_worker.rs• L1-18

VM monitor integration

The VM monitor turns device instances into guest-visible hardware. It allocates a VirtIO MMIO region and an IRQ for each custom device, stores the device behind a common registry, and keeps typed handles for paths that need direct access to a network, console, or vsock device.

Device registration

During custom HV setup, the monitor creates device instances from VM configuration and registers them with DeviceManager. Registration obtains the device ID and feature mask from the instance. It then creates the MMIO state and connects the concrete device to the type-erased registry entry. Later setup binds guest memory, IRQ callbacks, host file descriptors, connection managers, or filesystem handlers as needed.

The builder is the user-facing source of desired device state. It turns block paths, network choices, shared directories, console settings, and vsock settings into VM configuration. Device creation happens when the VMM has the hypervisor and guest-memory context needed to attach them.

References: virt/…/mod.rs• L646-803 virt/…/builder.rs• L193-265 virt/…/builder.rs• L267-333 virt/…/setup.rs• L224-274

Queue path selection

The monitor chooses the least disruptive host path for each queue event. Block notifications ring an I/O worker. Primary and bridge network TX notifications use the concrete network device hot path. Other devices receive the queue snapshot through VirtioDevice::process_queue. Host-to-guest traffic uses device-specific polling or worker paths that consume guest RX buffers.

This split keeps slow host work away from vCPU execution while allowing packet and control paths to use direct queue access. It also means that a change to a device feature or queue format can affect both the common device code and a monitor-owned worker.

References: virt/…/dispatch.rs• L210-257 virt/…/dispatch.rs• L258-352 virt/…/poll.rs• L3-105 virt/…/net_worker.rs• L1-23

Backend device split

The custom HV backend emulates VirtIO devices in Rust and exposes their queues through the monitor. The Virtualization.framework backend configures native Apple devices through arcbox-vz, so its block, network, filesystem, entropy, balloon, socket, and serial devices are framework objects rather than the Rust queue engines described above.

The two backends preserve the same product roles but do not share every host-side behavior. Use the custom device crates to understand HV queue traffic. Use the VZ device configuration modules to understand framework attachment and platform limits. Compare both through VM lifecycle and hypervisor backends when a behavior differs by backend.

References: virt/…/mod.rs• L1-25 virt/…/storage.rs• L9-47 virt/…/network.rs• L60-130 virt/…/filesystem.rs• L190-302

Change checklist

When these files or sections are changed, remember to consider these:

  • When adding or changing a device feature, keep the advertised feature mask, configuration-space values, request parser, and backend capability in agreement. A guest can select a feature from the mask before the request path uses it.
  • When changing block range parsing or sector arithmetic, keep normal I/O and discard/write-zeroes validation within capacity and aligned with both the generic device path and the HV worker path.
  • When adding a queue or changing queue numbering, update the device's queue roles and every monitor path that snapshots or dispatches that index. Check the monitor's maximum queue register space as well.
  • When changing host-to-guest completion code, preserve the full sequence of used-ring publication, VirtIO interrupt status, IRQ assertion, and vCPU wakeup for asynchronous HV workers.
  • When changing a device that uses typed monitor handles, update both the type-erased registry entry and the typed binding used by its hot path.
  • When changing VirtIO-FS setup, keep the mount tag, filesystem handler, and per-share DAX region aligned. A share can fail even when the VirtIO transport itself is healthy.
  • When changing a device supported by both backends, check whether the VZ framework configuration has the same guest-visible role but different host limits or lifecycle rules.

Important failure modes

TriggerConsequenceGuard
A queue address or descriptor points outside guest RAMThe device cannot read or write the request. A malformed queue can stop progress or produce an invalid completion.Keep GPA translation and range checks in GuestMemWriter and shared queue consumers.
A custom HV device is registered without guest memory or its IRQ bindingIts direct host path has no valid RAM or interrupt context and can become a no-op.Bind DeviceCtx only after DeviceManager has guest memory, MMIO state, and the IRQ callback.
An async worker publishes a completion but does not exit parked vCPUsA guest in WFI may not service the interrupt until an unrelated VM exit.Keep the worker completion order: interrupt status, IRQ assertion, then vCPU exit.
A feature is advertised in the device mask but not supported by a worker or backendThe guest can send a request or frame format that the selected host path cannot honor.Treat feature advertisement, config space, generic parser, hot path, and backend setup as one contract.
A block request has an overflowing or out-of-capacity sector rangeThe request is rejected instead of reaching the backing file. If a new path skips the shared checks, it can address the wrong host range or fail differently from the worker.Route normal I/O and discard/write-zeroes ranges through the checked range helpers and keep both block parsers aligned.
A filesystem share has no valid directory, handler, or completed FUSE sessionThe guest cannot mount or use the share even though the VirtIO-FS MMIO device exists.Validate the share and complete the FUSE initialization handshake before normal requests.
The balloon target is treated as guaranteed host reclaim on every backendThe guest limit may change without the expected reduction in host memory use.Interpret ballooning through the selected backend's reclaim semantics.

Key files

FileWhy to read it
virt/…/lib.rsDefines the shared device lifecycle, device IDs, queue configuration, and device context.
virt/…/split_queue.rsExplains the live guest-memory queue model and completion notification rules.
virt/…/guest_mem.rsDefines the GPA-to-host-memory boundary used by custom HV devices.
virt/…/mod.rsShows how the monitor registers devices, binds contexts, and owns typed hot-path handles.
virt/…/dispatch.rsShows how MMIO status, queue notifications, generic processing, workers, and interrupts connect.
virt/…/setup.rsShows the custom HV device set and the host service attached to each family.
virt/…/request.rsDefines block request types and the checked sector-to-byte range contract.
virt/…/mod.rsDescribes block identity, capacity, read-only behavior, and feature choices.
virt/…/hot_path.rsShows the direct network TX and RX relationship with guest queues.
virt/…/session.rsExplains the FUSE session handshake behind shared filesystem requests.
virt/…/mod.rsExplains host-side connection state and host-to-guest pending work.
virt/…/lib.rsDefines balloon targets, queue roles, free-page reporting, and host memory advice.
virt/…/mod.rsShows the native Virtualization.framework device configuration boundary.