Vhost-user device backends
Vhost-user device backends let QEMU use ArcBox device services without moving those services into QEMU. QEMU owns the VM transport and guest memory. The daemon speaks the vhost-user socket protocol and serves the guest's filesystem and vsock traffic.
This page is a child of Virtualization platform. Read VM lifecycle and hypervisor backends for backend selection, VirtIO device stack for shared device concepts, and Guest filesystem sharing for the wider file-sharing path.
System role
The vhost-user layer is a boundary between a virtual-machine frontend and a device service. It keeps the guest-visible VirtIO devices consistent when QEMU runs the System VM, including on macOS hosts where QEMU uses software emulation.
The frontend sends device setup messages and queue notifications over a Unix socket. The backend maps the shared guest memory, processes VirtIO rings, and returns completions or interrupts. This lets QEMU provide CPUs, PCI, and interrupt delivery while ArcBox keeps the device data paths.
flowchart LR
Q[QEMU frontend] -- vhost-user control and queue events --> B[ArcBox vhost-user backend]
Q -- shared guest RAM --> B
B --> F[Filesystem service]
B --> V[Vsock connection service]
F --> H[Host directories]
V --> P[Host-facing ArcBox services]
Frontend and backend boundary
QEMU is the vhost-user frontend. The backend is the device service in the daemon process, first defined by virt/…/lib.rs. QEMU keeps the PCI device model, guest CPU, guest RAM ownership, and guest interrupt injection. ArcBox keeps device features, ring work, host I/O, and device state.
The same boundary can serve a compatible virtual-machine frontend. The current product path is the macOS QEMU TCG backend, which uses this layer for virtio-fs and vsock while keeping the guest unchanged.
References: virt/…/lib.rs• L1-25 virt/…/mod.rs• L1-17
Connection lifecycle
Each device has one Unix socket connection to its frontend. The backend starts before QEMU realizes the device because QEMU waits for protocol replies during device setup.
Connection setup
The connection carries framed requests and optional file descriptors. File descriptors arrive with messages such as the guest-memory table and queue notifiers. The backend checks the frame, request type, payload size, and descriptor count before it changes device state.
The setup flow moves through these stages:
- ArcBox creates a socket pair and starts the device backend on one end.
- QEMU inherits the other end and realizes a vhost-user device.
- QEMU and the backend negotiate device and protocol features.
- QEMU sends the guest-memory regions and each vring's layout.
- QEMU sends kick and call notifiers, then enables the rings.
- The backend worker processes guest work until the frontend disconnects.
sequenceDiagram
participant A as ArcBox daemon
participant Q as QEMU
participant G as Guest driver
A->>A: Start backend
Q->>A: Negotiate features
Q->>A: Share guest memory and vring setup
Q->>A: Enable queues
G->>Q: Post buffers and kick queues
Q->>A: Forward queue notifications
A->>Q: Publish used buffers and call notifier
Q->>G: Deliver device interrupt
References: virt/…/connection.rs• L15-64 virt/…/backend.rs• L63-112 virt/…/protocol.rs• L41-74
Control and data paths
The backend separates setup from queue work. A control path handles frontend requests. A worker path waits for queue kicks and device events through macOS kqueue. Both paths share device state so a ring cannot be reconfigured while it is being processed.
Devices register host descriptors or wake signals with the worker. This lets host-side activity wake the same loop that handles guest queue kicks. An error or disconnect ends the device connection instead of leaving QEMU with a silent, non-working device.
References: virt/…/backend.rs• L1-7 virt/…/backend.rs• L385-477 virt/…/event_loop.rs• L1-10 virt/…/event_loop.rs• L258-327
Reset and teardown
A guest reboot or driver reset stops active rings and clears per-device state. Negotiated protocol features stay active for the life of the connection because QEMU does not renegotiate them after every reset. The backend keeps the required call notifier state so masked and unmasked guest interrupt vectors continue to work.
When the frontend goes away, the backend stops its worker, releases queue and guest-memory state, and returns the device to its owner. The vsock backend also ends every host connection. Callers must treat the resulting EOF as a signal to reconnect after the guest starts again.
References: virt/…/backend.rs• L221-239 virt/…/backend.rs• L370-382 virt/…/vring.rs• L306-320 virt/…/device.rs• L230-238
Guest memory and vring handling
The frontend describes guest RAM and vrings to the backend. A vring is the shared VirtIO ring where the guest posts descriptor chains and the device publishes completed chains.
Guest memory mapping
QEMU must provide shareable guest RAM so the backend can map it. The memory table supplies one descriptor for each RAM region. The backend validates the regions and maps them into one address span so the common ArcBox guest-memory writer can address all guest buffers.
The mapping stays alive while any active queue or device holds it. The backend reuses an unchanged table across a guest reset and replaces it when QEMU supplies a new layout. This keeps ring access tied to the current frontend memory contract.
References: virt/…/memory.rs• L1-13 virt/…/memory.rs• L80-169 virt/…/backend.rs• L241-259
Queue configuration
QEMU sends the queue size, ring addresses, starting cursor, kick descriptor, call descriptor, and enabled state. The backend translates the frontend's ring addresses into guest physical addresses and rejects a ring that is outside the described RAM.
Each running ring uses ArcBox's SplitQueue as the single owner of the available-buffer cursor. A device either uses the ring helper to consume chains and publish completions or drives the queue through the device-facing queue view. Event-index negotiation controls when the backend asks QEMU to interrupt the guest.
References: virt/…/vring.rs• L1-13 virt/…/vring.rs• L126-203 virt/…/vring.rs• L322-353 virt/…/backend.rs• L261-325
Queue notifications
macOS QEMU uses non-blocking pipes in place of Linux eventfds. A guest kick reaches the backend through the pipe's read end. A completed queue writes to the current call-notifier pipe so QEMU can inject the guest interrupt.
The call notifier is a shared slot rather than a fixed descriptor. QEMU can replace it when the guest masks or unmasks an interrupt vector, so every notification uses the descriptor currently installed by the frontend.
References: virt/…/vring.rs• L24-67 virt/…/vring.rs• L284-304 virt/…/lib.rs• L27-35
Filesystem backend
The filesystem backend exposes one host directory as one virtio-fs share. It uses the same filesystem service as the hardware-virtualization path, so the guest sees the same mount tags and host access policy across VM backends.
Share lifecycle
FsShare creates one backend for a tag and source directory. The QEMU integration creates one socket pair per configured share and passes the frontend end to a vhost-user-fs-pci device. The guest mounts the tag through its normal virtio-fs driver.
The System VM normally uses the arcbox, users, and private shares. The share has no read-only mode or uid mapping in this path. Filesystem requests run with the daemon's host credentials through the shared filesystem server.
References: virt/…/fs.rs• L1-18 virt/…/fs.rs• L40-102 virt/…/mod.rs• L166-180
Filesystem request path
The guest places a FUSE request in a virtio-fs descriptor chain. The backend passes that request to the filesystem service, copies the reply into the writable descriptors, publishes the used entry, and signals QEMU when the guest needs an interrupt.
The current QEMU configuration uses one request queue per share. There is no DAX window in this backend, so file reads use FUSE requests. FUSE_SYNCFS is reported as unsupported; the guest treats that result as the lack of this optional operation.
References: virt/…/fs.rs• L31-38 virt/…/fs.rs• L155-213 virt/…/virtio_device.rs• L100-129
Vsock backend
The vsock backend gives the guest a VirtIO socket device while the daemon owns the host-side connection service. Host components can dial a guest port through the same abstraction used by the hardware-virtualization backend.
Host-to-guest connections
VhostUserVsock exposes a guest CID and a host connection method. A host dial creates a socket pair, records the guest port in the connection manager, and returns the daemon end to the caller. The backend moves the other end through the guest's vsock RX and TX queues.
This preserves the host-facing service model for agent RPC, Docker, Kubernetes, NFS relay, and SSH authentication relay. A guest reset closes these connections, so callers observe EOF and establish new connections after the guest is ready.
References: virt/…/mod.rs• L1-20 virt/…/mod.rs• L79-105 virt/…/device.rs• L230-238
Vsock queue flow
QEMU owns the vsock transport and its event queue. The backend serves the RX and TX queues. It drains guest-to-host packets first so connection handshakes and credit updates can make room for host-to-guest data.
Host socket readability and connection-manager activity wake the backend worker. If the guest has no RX buffers, the worker waits for a later guest kick instead of spinning. Edge-triggered host watches allow the same data to remain pending until the guest can receive it.
References: virt/…/device.rs• L20-28 virt/…/device.rs• L52-79 virt/…/device.rs• L125-171
QEMU integration
The macOS QEMU backend assembles the frontend and backend as one VM launch. It starts every vhost-user service before QEMU, passes the QEMU socket ends as inherited descriptors, and stops the services when QEMU exits.
Device launch contract
QEMU uses shareable memory, vhost-user-fs-pci for each filesystem tag, and vhost-user-vsock-pci for guest sockets. The queue count and size in the QEMU arguments must match the backend's device contract. The guest therefore keeps the same VirtIO device view across the HV, VZ, and QEMU paths.
The QEMU TCG path also needs the ArcBox QEMU CPU setting that prevents stale translated code when the filesystem backend updates shared guest pages. Without that host-side QEMU support, file contents can be correct while guest code runs an old translation.
References: virt/…/args.rs• L38-50 virt/…/args.rs• L114-134 virt/…/args.rs• L208-245
Backend ownership
The QEMU machine owns the active filesystem and vsock backend handles. Its stop path terminates QEMU first, then stops each filesystem share and the vsock service. This order prevents a backend from waiting for a frontend that no longer exists.
References: virt/…/mod.rs• L39-68 virt/…/mod.rs• L332-371 virt/…/mod.rs• L410-439
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the vhost-user protocol feature set aligned with the requests made by each QEMU device. In particular, vsock needs config reads for its guest CID.
- Keep the QEMU filesystem queue count and queue size aligned with
FsShareand the guest's device arguments. - Preserve the reset contract: protocol features survive a device reset, while guest-memory handles and device-owned connection state do not.
- Update both sides of the guest-memory contract when ring address translation or shared-memory setup changes. QEMU must still pass descriptors for every mapped RAM region.
- Keep host-vsock port handling aligned with the connection manager and every caller that expects EOF on guest reset.
- Keep QEMU's shared-memory and CPU launch requirements aligned with the backend's direct guest-memory writes.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| QEMU uses private RAM without shareable backing | The backend cannot map guest memory and the device cannot start | Use the shared-memory backend required by the QEMU launch contract |
| A ring address or size falls outside the memory table | Queue setup fails instead of serving invalid guest memory | Validate ring ranges and queue limits before creating SplitQueue |
| QEMU replaces a call notifier and the backend keeps the old descriptor | A completion can lose its guest interrupt | Read the current shared call-notifier slot for every signal |
| Reset clears negotiated protocol features | QEMU can wait for a reply during the first queue setup after reboot | Preserve protocol features for the connection lifetime |
| A vhost-user request is unknown or not supported | The connection closes and QEMU stops the device | Add protocol support before enabling a frontend request |
| A guest reset leaves host vsock connections in the manager | Callers can wait on sockets that no longer have a guest peer | Remove all guest connections during reset and reconnect after EOF |
| QEMU TCG runs without the required code-cache behavior | Guest code read from a shared filesystem can execute stale translations | Use the ArcBox QEMU CPU configuration and startup check |
Key files
| File | Why to read it |
|---|---|
| virt/…/lib.rs | Defines the backend boundary and the intended frontend, memory, vring, filesystem, and vsock model |
| virt/…/backend.rs | Shows connection negotiation, control/data path ownership, reset, and teardown |
| virt/…/protocol.rs | Defines the vhost-user request and feature contract |
| virt/…/memory.rs | Explains how frontend-provided guest RAM becomes device-accessible memory |
| virt/…/vring.rs | Shows ring setup, queue ownership, event notifications, and completion signaling |
| virt/…/fs.rs | Connects a host directory and FsServer to a vhost-user filesystem device |
| virt/…/mod.rs | Exposes the host-facing vsock backend lifecycle and dial operation |
| virt/…/device.rs | Shows the RX/TX data flow and host event integration |
| virt/…/mod.rs | Shows how QEMU creates, owns, and stops the backend services |
| virt/…/args.rs | Shows the QEMU device, memory, queue, and CPU launch contract |