The micro-VM for AI agents — light enough to embed on your laptop, elastic enough to power an agentic cloud.
BoxLite VMM design
BoxLite is replacing libkrun and libkrunfw with a virtualization stack it owns:
- a Rust VMM in two crates,
boxlite-hypervisorandboxlite-vmm, linked intoboxlite-shim; - a pinned Linux LTS guest kernel, shipped as a file;
boxlite-guestas the guest's PID 1.
This document is the design the VMM milestones build on (#1512). It covers the hypervisor backend interface, the device model, the VM lifecycle and its errors, and the guest boot contract. The libkrun backend remains in use until the new VMM becomes the default in M5.
Diagrams of this design:
- macOS Hypervisor.framework
- Linux KVM
- Windows Hypervisor Platform
- Guest memory
- Linux virtio-fs data flow traces share configuration, FUSE requests, object ownership and cleanup, with observed acceptance results.
BoxLite line references are to commit 42ec1a2a6. External citations name
their project; their revisions are pinned under References.
libkrun/ is the vendored copy at src/deps/libkrun-sys/vendor/libkrun/
(revision a66775c).
This revision includes opt-in Transparent Huge Pages (THP) for Linux guest boot RAM
(boxlite-ai/libkrun#17),
checkpoint vsock and musl fixes
(boxlite-ai/libkrun#18), and
virtio-net unixgram TX handling that keeps the backend open on single-frame
internal errors such as macOS EMSGSIZE so subsequent frames continue to be
delivered (boxlite-ai/libkrun#19).
With bubblewrap enabled, BwrapSandbox passes KRUN_USE_THP=1 to
boxlite-shim after clearing the inherited environment. Only the exact value
1 in the host launcher environment is forwarded; unset or other values are
omitted. KRUN_USE_THP=1 only takes effect on Linux x86_64 (non-TEE) hosts,
and THP backing depends on the host kernel (on managed hosts, pairing it with
transparent_hugepage/defrag=defer or never is recommended).
Scope
- In scope:
- one VM per shim process, on macOS arm64 (Hypervisor.framework, "HVF") and on Linux x86_64 and arm64 (KVM);
- boxes that work as they do on libkrun (M0–M5); the guest boot contract lists what changes underneath;
- room for hot-plug mounts, dynamic resources, memory snapshots, GPUs (M6–M9) and Windows x86_64 hosts on WHP, the Windows Hypervisor Platform (M10).
- Out of scope: more than one VM per process, confidential computing, live migration, Intel Macs, and changes to libkrun.
Decisions
| Decision | Choice | Why | Rejected |
|---|---|---|---|
| Minimum macOS | 15, using HVF's in-kernel GICv3 | hv_gic_create and hv_gic_set_spi exist from macOS 15.0 (hv_gic.h), so no HVF or KVM host needs an emulated interrupt controller, and libkrun already prefers the in-kernel GIC wherever the host has it |
macOS 12 with a userspace GICv3, which libkrun falls back to below macOS 15 (libkrun/src/vmm/src/builder.rs:892-894), at about 3–4 engineer-weeks in M1 |
| SHARED share | virtio-fs in two stages: a FUSE server core for the SHARED share in M2, full passthrough for user volumes in M3 | Every box mounts the SHARED share, and guest file copy stages through it, so the first box already needs virtio-fs | Moving container layout and file copy off the SHARED share first, which changes the guest agent before the first box boots |
| Threads | One thread per vCPU, one virtio worker thread for every device, and a poller on the thread that calls run() |
HVF binds a vCPU to the thread that created it. One worker thread runs every device, as Firecracker and libkrun do, and keeps the threads a per-thread seccomp profile must cover to a fixed few. A slow device, such as a blocking virtio-fs request, stalls the others; the WorkerRuntime seam lets per-device threads replace the shared one without changing the transport, the devices or Vm if M2 measurements show such stalls |
Worker threads per device (Cloud Hypervisor, crosvm), kept behind that seam; an async runtime inside the jailed shim, which complicates per-thread seccomp |
| Guest firmware | None: the VMM writes the kernel and its boot data into guest RAM and starts the boot vCPU at the kernel's entry point, as libkrun, Firecracker and crosvm do | The kernel ships with BoxLite as a file, so firmware and a boot loader would only add a step before it and a second guest program to ship, pin and trust | Firmware boot with edk2 UEFI or Rust Hypervisor Firmware, which cloud-hypervisor offers for disk images that carry their own boot loader (README.md:114-118, :134-137) and which only user-supplied OS images or Secure Boot would need |
macOS 12–14 keep running boxes on libkrun until M5. When M5 removes libkrun,
the support matrix in the root README.md:241 changes from "macOS 12+" to macOS 15.
Architecture
boxlite-shim one jailed process per box
└─ engine adapter (M2) implements Vmm and VmmInstanceImpl (src/boxlite/src/vmm/engine.rs:51-104)
└─ boxlite_vmm::Vm new(config), then run() → VmExit or Error
├─ vcpuN threads Vcpu::run → VcpuExit → chipset dispatch → run again
├─ virtio-worker thread every device's virtqueues and host backends: disk, fs, vsock, net, console
├─ the run() thread one poller: stop requests, vCPU outcomes, device failures
└─ boxlite_hypervisor Vm and Vcpu traits; hvf (macOS arm64), kvm (Linux) or whp (Windows, M10)
guest
└─ pinned LTS kernel → boxlite-guest as PID 1
The two crates split the work as follows:
boxlite-hypervisorowns what differs between hosts: VM and vCPU handles, memory registration, interrupt injection, and decoding exits.boxlite-vmmowns the guest machine: configuration, memory layout, devices, threads, and lifecycle.
KVM memory slots stay in the KVM backend, ARM exception syndromes in the HVF
backend and x86 instruction decoding in the WHP one; boxlite-vmm sees none.
Hypervisor backend interface
The backend is chosen at compile time, because no host has more than one of HVF,
KVM and WHP. M1 adds HvfVm and KvmVm, M10 adds WhpVm, and each implements
the traits in src/hypervisor/src/. boxlite-vmm is written against those
traits, so its tests can drive a mock backend, and M4's fault-injection tests
need no hypervisor.
| Operation | Contract | HVF | KVM | WHP (M10) |
|---|---|---|---|---|
| Create the VM | the backend's constructor | hv_vm_create, one VM per process (hv_vm.h) |
KVM_CREATE_VM on /dev/kvm, then the KVM_SET_TSS_ADDR the KVM API requires on Intel hosts |
WHvCreatePartition; WHvSetPartitionProperty for the vCPU count; then WHvSetupPartition |
| Create the interrupt controller | the backend's constructor | hv_gic_create, after the VM and before any vCPU (hv_gic.h) |
x86_64: KVM_CREATE_IRQCHIP and KVM_CREATE_PIT2, before any vCPU; arm64: a KVM_DEV_TYPE_ARM_VGIC_V3 device with its distributor and redistributor addresses, initialised with KVM_DEV_ARM_VGIC_CTRL_INIT once every vCPU exists |
local APIC emulation, set with WHvSetPartitionProperty before WHvSetupPartition |
| Map guest memory | Vm::map_memory (unsafe) |
hv_vm_map |
KVM_SET_USER_MEMORY_REGION; the backend picks the slot |
WHvMapGpaRange |
| Unmap guest memory | Vm::unmap_memory |
hv_vm_unmap |
the same slot, set to size 0 | WHvUnmapGpaRange |
| Create a vCPU | Vm::create_vcpu, on the thread that will run it |
hv_vcpu_create, which also returns the hv_vcpu_exit_t the vCPU reports its exits in |
KVM_CREATE_VCPU, then mmap of its kvm_run; KVM_ARM_VCPU_INIT on arm64, with secondaries powered off (KVM_ARM_VCPU_POWER_OFF) |
WHvCreateVirtualProcessor |
| Set boot registers | x86_64: X86Vcpu::set_cpu_features, then X86Vcpu::set_boot_registers; arm64 adds its own extension trait |
hv_vcpu_set_reg, hv_vcpu_set_sys_reg |
KVM_SET_ONE_REG on arm64; on x86_64 KVM_SET_CPUID2, then KVM_SET_MSRS, KVM_SET_REGS, KVM_SET_FPU and KVM_SET_SREGS, in Firecracker's order (Firecracker src/vmm/src/arch/x86_64/vcpu.rs:222–301); unlike Firecracker, the VMM leaves the local APIC LINT pins in their KVM reset state, ExtINT on the boot vCPU LINT0, and Linux programs LINT1 itself |
WHvSetVirtualProcessorRegisters |
| Run to the next exit | Vcpu::run → VcpuExit |
hv_vcpu_run |
KVM_RUN |
WHvRunVirtualProcessor |
| Complete pending I/O before stop or state capture | Dispatch exits from Vcpu::complete_pending_io until Ok(IoCompletion::Done) |
Write the read result and advance PC without hv_vcpu_run |
KVM_RUN with immediate_exit set may return more exits from the same instruction |
Finish emulation and update registers/RIP without WHvRunVirtualProcessor |
| Read the exit | the backend decodes it into a VcpuExit |
hv_vcpu_exit_t: the reason and, for an exception, the syndrome and guest address |
kvm_run.exit_reason and its union |
the WHV_RUN_VP_EXIT_CONTEXT that WHvRunVirtualProcessor fills |
| Kick from another thread | VcpuHandle::kick |
hv_vcpus_exit |
set immediate_exit, then signal the vCPU thread |
WHvCancelRunVirtualProcessor |
| Set an interrupt line | Vm::set_irq_line |
hv_gic_set_spi |
KVM_IRQ_LINE |
a userspace IOAPIC, in a crate M10 picks, then WHvRequestInterrupt |
HVF and KVM keep these rules; M10 covers WHP:
- Creation.
- The backend's constructor creates the VM and the host's in-kernel
interrupt controller and timer: a GICv3 on arm64; the PIC, IOAPIC, local
APICs and PIT on x86_64, as libkrun creates them
(
libkrun/src/devices/src/legacy/kvmioapic.rs:19-25). - HVF needs its GIC before any vCPU exists (
hv_gic.h), and so does KVM's x86 irqchip. - KVM on arm64 initialises its GIC only after every vCPU exists, so that
backend initialises it once, in the first
runon any vCPU, before any vCPU enters the guest. - As a result, the VMM creates every vCPU before it runs any.
- The backend's constructor creates the VM and the host's in-kernel
interrupt controller and timer: a GICv3 on arm64; the PIC, IOAPIC, local
APICs and PIT on x86_64, as libkrun creates them
(
- Thread binding. HVF accepts vCPU calls only from the thread that created
the vCPU (
hv_vcpu.h); KVM only recommends it (KVM API). Backend vCPU types are!Send, so the compiler enforces the HVF rule on both hosts. - Kicks.
- A
VcpuHandleisClone + Send + Sync. After a kick,runreturnsVcpuExit::Interrupted. - A kick that lands while the vCPU is outside the guest makes its next
runreturn at once. - Kicking a dropped vCPU does nothing, so a stop can kick every vCPU without tracking which ones already ended.
- A
- Memory lifetime.
map_memoryisunsafe. The caller keeps the host range mapped, backing nothing but that guest region, until both the guest mapping is gone (successfulunmap_memory, or the VM and all its vCPUs dropped) and every host-side user has stopped accessing the range. This includes the virtio workers and in-flight host I/O. A failed unmap can leave the guest mapping in place, and on KVM a live vCPU keeps the VM's mappings alive. Shutdown joins the vCPU threads, shuts down the virtio workers and drains or cancels host I/O before releasing the allocation; workers that do not stop keep the allocation registered, andGuestRamleaks it.- The guest can change that memory at any time. VMM code uses guest-memory access primitives that preserve Rust's aliasing rules, not ordinary Rust references into guest-accessible memory. Conflicting host-side accesses require synchronization or atomic operations. Guest-shared protocols, such as virtqueues, require their specified atomicity and memory ordering; a host mutex does not synchronize with the guest. Raw pointers and volatile accesses alone do not provide these guarantees.
- Both ranges align to the host page size, which is 16 KiB on Apple silicon.
- Interrupt lines. A line is a GIC SPI INTID (32 and up) on arm64 and a GSI on x86_64. Devices set lines from vCPU threads and the virtio worker thread. An edge-triggered interrupt is a set followed by a clear.
- Errors.
boxlite_hypervisor::Errornames the failed operation and its resource (vCPU id, guest address, or line), and keeps the host cause as anio::Error:errnoon KVM, thehv_return_ton HVF.- A host that cannot run VMs reports
io::ErrorKind::Unsupported. Missing access to the hypervisor reportsio::ErrorKind::PermissionDenied. - An exit the backend does not handle becomes
Error::UnhandledExit, never a panic. It carries the backend's description of the exit for diagnostics, so raw exit reasons stay inside the backend, as with Firecracker'sUnhandledKvmExit(String)and hyperlight'sUnknown(String).
The register access that boot needs lives in per-architecture extension
traits, as crosvm's VcpuX86_64: Vcpu does, so neither architecture's types
leak into the other. On x86_64, X86Vm::supported_cpuid returns the host's
CPUID ceiling, and X86Vcpu sets CPUID and MSRs (set_cpu_features), then
registers and segments (set_boot_registers, on the boot vCPU only). arm64
adds its trait with its boot path: PC, X0, PSTATE and MPIDR_EL1, where
MPIDR_EL1 matches each vCPU to its GIC redistributor. M8 extends them to
saving and restoring full vCPU state.
The names come from a survey of nine projects: crosvm, cloud-hypervisor, Firecracker, libkrun, hyperlight, alioth, applevisor, kvm-ioctls and QEMU (links under References).
Vm,Vcpu,runandVcpuExiteach appear in most of them:VmandVcpuin seven,runin six,VcpuExitin five.- Kicks, memory mapping, interrupts and errors have no dominant name, so the
design takes the most common one for each:
- the verb "kick", on a
VcpuHandle; map_memory, as the HVF-capable projects name it;set_irq_line(line, level);- one
Errorwith a variant per operation.
- the verb "kick", on a
Exit contract
The guest reads and writes RAM mapped with map_memory without an exit to the
VMM. An access to an address no mapping covers, such as a device window, is an
MMIO exit.
A process in the guest runs on a vCPU at EL0 (ring 3 on x86_64), and the guest kernel at EL1 (ring 0). The process's system calls and context switches stay inside the guest; only the exits below reach the VMM.
VcpuExit (src/hypervisor/src/exit.rs) is what run returns. MMIO and port
data borrow a per-vCPU buffer inside the backend, as in libkrun and kvm-ioctls.
The VMM handles each exit before it runs that vCPU again. The next run
continues the guest's instruction. Before stopping or saving state, the
VMM releases the borrowed exit and calls complete_pending_io. If it receives
Ok(IoCompletion::Exit(exit)), it handles that exit and releases its borrow
before calling again. For example, KVM can return a second MMIO fragment or the
write phase of a read-modify-write instruction. Ok(IoCompletion::Done) confirms
completion without executing another guest instruction. With no pending I/O,
completion is a no-op. IoCompletion is #[must_use] even after the caller
unwraps the Result.
| Exit | Meaning | HVF | KVM | WHP (M10) |
|---|---|---|---|---|
MmioRead, MmioWrite |
Access to an emulated device | HVF data abort: HV_EXIT_REASON_EXCEPTION with a data-abort syndrome |
KVM_EXIT_MMIO |
WHvRunVpExitReasonMemoryAccess |
IoIn, IoOut (x86_64 only) |
One port access to the 8250 serial, CMOS RTC or i8042; string port I/O is Error::UnhandledExit |
none | KVM_EXIT_IO |
WHvRunVpExitReasonX64IoPortAccess, which also carries the ports of the userspace PIC and PIT (M10) |
Interrupted |
A kick | HV_EXIT_REASON_CANCELED, after hv_vcpus_exit |
KVM_RUN returning EINTR; also EAGAIN, which a waiting secondary vCPU returns once it accepts INIT or SIPI |
WHvRunVpExitReasonCanceled |
CpuOn (arm64 only) |
PSCI CPU_ON: start a powered-off vCPU, with the VMM's answer in a borrowed result |
the HVF backend decodes it from HVC | none: the kernel handles PSCI | none |
Halted |
The vCPU waits for an interrupt | none: with the in-kernel GIC, HVF waits out WFI inside hv_vcpu_run and wakes for the vtimer and for SPIs; a trapped WFI or WFE is a spurious wake the backend steps over |
KVM with the in-kernel irqchip waits in the kernel, and the backend still maps KVM_EXIT_HLT, which only a VM without one returns (as the probe VM in src/boxlite/src/system_check.rs does) |
with local APIC emulation, HLT waits inside WHvRunVirtualProcessor; QEMU handles WHvRunVpExitReasonX64Halt only without it (target/i386/whpx/whpx-all.c:2337-2342) |
Shutdown |
The guest powered off | PSCI SYSTEM_OFF, decoded by the HVF backend |
KVM_EXIT_SYSTEM_EVENT |
the i8042 reset below |
Reset |
The guest reset | PSCI SYSTEM_RESET, decoded by the HVF backend |
a KVM_EXIT_SYSTEM_EVENT reset on arm64; an x86 triple fault (KVM_EXIT_SHUTDOWN) |
the i8042 reset below |
On x86_64 the guest resets through the i8042 port. That reset arrives as an
IoOut, and the VMM's i8042 device sends GuestReset to the event loop,
which ends the VM.
KVM handles PSCI CPU_ON for secondary vCPUs in the kernel; HVF leaves it to
the VMM. The HVF backend returns VcpuExit::CpuOn { target, entry, context_id, result }: the target's MPIDR affinity, its entry address and its X0. The VMM
validates the target and its startup state, sends the entry and context to the
target's owning thread, and writes CpuOnResult into result; the next run
returns it to the guest as the PSCI code, and result starts as
InternalFailure so an unanswered call fails. On arm64 only the boot vCPU
starts at the kernel's entry point, through Arm64Vcpu::set_boot_registers;
each secondary starts powered off until CPU_ON gives it one. An HVF secondary
waits parked, so the stop path's unpark also wakes one the guest never started.
How each host completes an access on the next run:
- HVF. The backend decodes a data abort itself: the syndrome gives the
access size (SAS), direction (WnR), register (SRT) and the load's sign (SSE)
and width (SF), and
physical_addressthe guest address. On the nextrunit writes the register for a read, extended as SSE and SF say, and advances PC by 4, as libkrun does (libkrun/src/hvf/src/lib.rs:554-576,:615-650); HVF leaves the extension to the VMM. Register 31 is XZR, while HVF numbers PC as register 31. - KVM. The kernel completes the access on the next
KVM_RUN, from the data the VMM leaves inkvm_run. - WHP. A memory-access exit carries the instruction bytes, so
whp::emulatordecodes the access. A port-access exit carries the port, size andRAX. On the nextrunthe backend writes the destination register for a read and advances RIP.
Hypervisor.framework can also exit with HV_EXIT_REASON_VTIMER_ACTIVATED
(hv_vcpu_types.h), but not with the in-kernel GIC, which handles the guest's
virtual timer itself: QEMU asserts that this exit never arrives with it
(target/arm/hvf/hvf.c:2580-2581) and notes that HVF then handles vtimer
wake-ups (:2670-2671).
Every Linux boot also raises exceptions that the HVF backend resolves itself,
without a VcpuExit, before it enters the guest again:
- PSCI queries. Linux first calls
PSCI_VERSIONandMIGRATE_INFO_TYPE(drivers/firmware/psci/psci.c:638,:651). The backend answers both in X0, as libkrun does (libkrun/src/hvf/src/lib.rs:526-535), and returnsNOT_SUPPORTEDfor any other call it does not act on, as KVM does (arch/arm64/kvm/psci.c:306-307). - System registers. Linux reads ID registers that HVF does not model, such
as
ID_AA64PFR2_EL1(arch/arm64/kernel/cpuinfo.c:457-472; QEMUtarget/arm/hvf/hvf.c:1145). A trapped ID register reads as zero, as in QEMU (hvf.c:1873-1877) and libkrun (libkrun/src/devices/src/legacy/vcpu.rs:145-150). The backend also emulates the OS lock as QEMU does: a write toOSLAR_EL1sets the lock thatOSLSR_EL1reports, andOSDLR_EL1is a dummy register (hvf.c:1746-1750,:2044-2046,:2056-2058). libkrun ignores writes to both (vcpu.rs:258-260). The other debug registers HVF traps, such asMDCCSR_EL0, read as zero and ignore writes. - WFI and WFE. With the in-kernel GIC neither reaches the VMM on the
hosts tested so far. If one traps, the backend advances PC, as QEMU does
(
hvf.c:2493-2497), and the guest sees a spurious wake.
Device model
Guest memory layout
Two translations stand between a guest access and host memory. The guest
kernel's page tables map a guest virtual address to a guest physical one, and
the host hypervisor's stage-2 translation, EPT or NPT on x86_64, maps that to
the shim's memory from the regions map_memory registers. An address no region
covers is an MMIO exit, except the windows the host's in-kernel interrupt
controller claims.
On arm64 the layout follows Firecracker's, with a PL011 in its serial slot, and
keeps RAM at 0x8000_0000 as libkrun does today.
| Address | Use | Precedent |
|---|---|---|
below 0x3FFF_0000 |
GICv3 redistributors, 128 KiB per vCPU | Firecracker, crosvm, dragonball |
0x3FFF_0000 |
GICv3 distributor, 64 KiB | Firecracker, crosvm, dragonball |
0x4000_1000 |
PL031 RTC, SPI INTID 33 | Firecracker |
0x4000_2000 |
PL011 UART, SPI INTID 32 | Firecracker's serial slot |
0x4000_3000–0x7000_0000 |
virtio-mmio devices, 4 KiB each, with SPIs from INTID 34 | Firecracker's device window; libkrun assigns SPIs in sequence from INTID 32 |
0x7000_0000–0x8000_0000 |
PCI ECAM, reserved for M9 | Firecracker |
0x8000_0000 |
RAM: the kernel Image at its text offset, and the device tree in the last 2 MiB |
libkrun, Firecracker, crosvm, dragonball |
| above RAM | hotplug memory, reserved for M7 | cloud-hypervisor (virtio-mem); libkrun puts shared memory there |
| above the hotplug region | 64-bit PCI BAR window, reserved for M9 | Firecracker and alioth reserve a 64-bit MMIO window |
On x86_64 the layout uses the values most surveyed VMMs share.
| Address or port | Use | Precedent |
|---|---|---|
0x500 |
boot GDT: flat __BOOT_CS (0x10) and __BOOT_DS (0x18) |
Firecracker, which uses selectors 0x8 and 0x10 |
0x7000 |
boot_params (the zero page) |
five of six |
below 0x8FF0 |
boot stack | Firecracker |
0x9000–0xE000 |
identity page tables: PML4, PDPT and one 2 MiB-page directory per GiB of RAM below the hole | Firecracker, which maps 1 GiB |
0x2_0000 |
kernel command line | five of six |
0x9_FC00 |
MP table, 284 bytes plus 20 per vCPU (1564 at 64), inside the reserved [0x9_FC00, 1 MiB) |
Firecracker, libkrun |
0x10_0000 |
bzImage load address; an ELF vmlinux loads where its headers say |
four of six |
below 0xC000_0000, and above 4 GiB |
RAM, split around the 32-bit MMIO hole | Firecracker, cloud-hypervisor, dragonball |
top of the RAM below 0xC000_0000 |
initramfs, in the highest 4 KiB-aligned slot | Firecracker, cloud-hypervisor |
0xC000_0000–0xD000_0000 |
32-bit PCI BAR window, reserved for M9 | Firecracker, cloud-hypervisor and alioth give PCI BARs space in the hole |
0xD000_0000–0xE000_0000 |
virtio-mmio devices, 4 KiB each, with interrupts from GSI 5 | device window: libkrun, crosvm; GSI 5: Firecracker, libkrun, dragonball |
0xE000_0000–0xF000_0000 |
PCI ECAM, reserved for M9 | alioth |
0xFEC0_0000, 0xFEE0_0000 |
IOAPIC and local APIC, both in the kernel on KVM; WHP (M10) emulates only the local APIC | architectural |
| above RAM | hotplug memory (M7), then a 64-bit PCI BAR window (M9) | as on arm64 |
ports 0x3F8, 0x70–0x71, 0x60 and 0x64 |
8250 UART on GSI 4, CMOS RTC with its alarm on GSI 8, i8042 | PC standard |
x86_64 guests boot without ACPI or a device tree, so the command line announces
each virtio-mmio device (virtio_mmio.device=4K@0xd0000000:5), as libkrun does
today. The arguments go at the front of the command line: the kernel hands
everything after a -- to the init program, and the front is always before
any --, so the VMM never parses the caller's text, whose quoted values may
hold --.
Buses
- Which buses. Every host has an MMIO bus; x86_64 adds a port I/O bus.
- Device API. Devices implement
BusDeviceand see offsets from their base:read(&mut self, offset: u64, data: &mut [u8])andwrite(&mut self, offset: u64, data: &[u8]). These are the most common shapes among seven surveyed VMMs:Busin six,BusDevicein four, and offset-based access in all seven. - Registration. Devices register through
chipset::ChipsetBuilder, the one registry of port ranges, MMIO ranges and interrupt lines, as in OpenVMM's chipset builder. Platform code reserves the windows the host serves in the kernel and adds each device by name with the ranges and lines it claims.buildreports every conflict at once, naming the claimant and the owner, or returns an immutableChipsetthat owns the devices. Devices register while the VM is built; M6 and M7 change the guest without adding bus devices. - Composition.
devices::add_allis the one place that names device types: it adds the legacy platform devices, then each configured device in slot order throughadd_slot_device, andvirtio::mmio::add_deviceclaims a window and line, adds the worker slot and builds the transport. Adding a device type is one line inadd_all;Vm::with_devicesandvm.rsstay unchanged. - Dispatch.
Chipset::dispatchserves MMIO and port exits through the buses and returns every other exit to the vCPU loop. An access must lie entirely inside one range, as in Firecracker's bus. Any other access reads0xFF, drops its write and is counted, as on a PC bus with nothing driving it. A claimed read reaches the device zero-filled, so stalekvm_runbytes never leak to the guest. - Locking. A vCPU thread holds a device's lock for one register access and hands queue work to the virtio workers through a kick. A lock that an earlier panic poisoned stops the next access too, as Firecracker and cloud-hypervisor do: the panic was a VMM bug, never guest input.
Virtio-mmio transport
virtio::mmio::MmioTransport is a BusDevice on a 4 KiB window. It owns the
register file, queue configuration, status and interrupt; the device owns the
queues after DRIVER_OK. Control registers take aligned 4-byte accesses, config
space forwards 1/2/4-byte accesses and splits 8-byte accesses. The transport
offers VIRTIO_F_VERSION_1 and masks packed rings, notification data,
notification-config data, ring reset and the admin queue; FEATURES_OK calls
set_features once and fails synchronously if the accepted subset is invalid.
Before DRIVER_OK the transport holds a dense QueueConfig shadow and accepts
queue writes only after FEATURES_OK; QueueReady=0 keeps the configuration.
DRIVER_OK builds the queues, prepares them into the VirtQueues facade, and
moves them into the ActivationContext. After DRIVER_OK every
queue-configuration write is rejected and logged, as Firecracker does;
QueueNotify, InterruptACK and Status stay live, and Status=0 is the only
queue-reconfiguration path. Activation failure leaves DRIVER_OK unset, sets
DEVICE_NEEDS_RESET and raises the configuration interrupt. The transport
drives the device's slot in the virtio workers: it prepares a worker
generation before activation, starts it after, kicks it on QueueNotify and
stops it before Status=0 resets the device. A fatal device error sends
Event::DeviceFailed through Error::VirtioDevice without stopping the
worker slot synchronously.
Interrupts
- No emulated controller. HVF and KVM provide in-kernel interrupt controllers, so the VMM emulates none. WHP (M10) emulates only local APICs.
- Line assignment. The VMM gives each device a line when it builds the machine, and the chipset builder rejects a second claim of a line. It declares virtio-mmio interrupts edge-triggered, as Firecracker, libkrun and dragonball do.
- Virtio interrupts.
MmioInterruptowns the line, the interrupt status bits, the shared device status and the configuration generation. Raising always pulses;InterruptACKclears only the acked bits and pulses again while any remain, so an edge line does not lose a notification that arrived between Linux's read and acknowledgement. - Raising an interrupt. Devices raise their lines from the virtio worker
thread through the VMM's interrupt path, which calls
Vm::set_irq_line. The host's in-kernel controller wakes a vCPU waiting for it, so the VMM wakes no thread. - Naming. Devices hold an
IrqLine, which is notClone, so a device cannot share its line.pulseraises an edge and lowers a line a failed clear left high before raising again;set_levelholds a level, skipping a repeated one; as with OpenVMM'sLineInterrupt, dropping a line held high lowers it. It calls the object-safeIrqChiptrait, which every host VM implements throughVm::set_irq_line. The survey found no dominant name:VirtioInterrupt,InterruptSourceGroupandIrqSendereach appear once or twice.
Devices by milestone
- M1:
- arm64: PL011, PL031 and PSCI;
- x86_64: 8250 serial, CMOS RTC, and the i8042 reset.
- M2:
- the virtio-mmio transport: a 4 KiB register file with aligned 4-byte
control accesses and width-split configuration access, synchronous
FEATURES_OK validation, a dense queue shadow validated at DRIVER_OK,
post-DRIVER_OK queue-write rejection, Status=0 reset, and a
VirtQueuesfacade that validates the dense queue set, applies EVENT_IDX, tracks each deferred chain's head so completion happens exactly once, keepssave/restoreasSnapshotError::Unsupporteduntil M8, processes at most one complete chain per callback, re-enables notifications and schedules pending work through a generation-bound continuation; - virtio-blk, virtio-vsock, virtio-net, virtio-console and virtio-rng;
- reporting-only virtio-balloon: whole-chain validation, raw GPA and aligned
HVA queue-control protection, inward private-anonymous reclaim before
used, unchanged capacity and safe reuse;
Immediatediscards withMADV_DONTNEED, while LinuxLazymarks withMADV_FREEso reclaim follows memory pressure; DarwinMADV_DONTNEEDmay need pressure. Linux x86_64, Linux arm64 and macOS arm64 real guests are all completion gates; arm64 boot dependencies cannot be replaced by unit tests; - the virtio-fs core.
- the virtio-mmio transport: a 4 KiB register file with aligned 4-byte
control accesses and width-split configuration access, synchronous
FEATURES_OK validation, a dense queue shadow validated at DRIVER_OK,
post-DRIVER_OK queue-write rejection, Status=0 reset, and a
- M3: virtio-fs passthrough for user volumes.
- M7: virtio-mem.
- M9: a PCI transport for passed-through devices, VFIO, and virtio-gpu.
Threads
- vCPU threads.
run()spawns one per vCPU, namedvcpuN. Each creates and configures its vCPU and waits at a start gate until the driver allows guest entry. A spawn or setup failure aborts the gate.- Before each guest entry, a vCPU checks the pause and stop state. It waits on a condition variable while parked.
- When the VM is running, idle vCPUs wait inside the host. KVM's in-kernel
irqchip waits out
HLT; with the in-kernel GIC, HVF waits outWFIinsidehv_vcpu_runand wakes the vCPU for its vtimer and for SPIs set from any thread, as an M5 Pro on macOS 27 showed (#2103). QEMU relies on the same: with the in-kernel GIC it arms no wake-up timer of its own (target/arm/hvf/hvf.c:2273-2306). libkrun, written for a userspace GIC, parks until the deadline inCNTV_CVAL_EL0(libkrun/src/hvf/src/lib.rs:705-721).
- Shared virtio execution.
- One lazy
mio::Poll/waker/thread dispatches generation-bound queue kicks and backend events. The device owns the prepared queues and completion. - Common drain handles at most one complete chain, then returns. A durable, coalesced continuation admits backlog next pass after other ready work, even without another guest kick. Balloon has no private scheduler.
- A reclaim syscall may still block. Count bounds are not syscall-time, total CPU or throughput guarantees; stop timeout is Fatal and retains RAM.
- Status=0 closes admission and waits for the old generation before reset. VM exit and Drop stop/join before unmap; after joining, the framework quiesces every device while RAM remains registered. The default is a successful no-op; console drains published TX before the host console worker finishes, and block flushes/syncs its backend.
- Shutdown hook failures are cached separately from join failures, so later hooks
still run and a completed join still permits RAM unmapping.
WorkerRuntimepreserves the future per-device seam without adding a second runtime in M2; shutdown details live with the implementation. Other devices retain their existing reset/drop cleanup; quiesce success does not imply snapshot support or delivery of buffered network traffic.
- One lazy
- The
run()thread.- It waits on one
EventLooppoller for control wakeups, stop requests, vCPU outcomes and device failures. During vCPU setup, the same loop processes control requests and retries kicks. The last ready vCPU wakes the poller; the loop checks terminal events and processes pending pause requests before opening the start gate. TheRECHECKinterval is one second, so the mailbox and terminal queue are revisited even if a wakeup is lost. - The poller is
mio, which uses epoll on Linux and kqueue on macOS and is already inCargo.lockthrough tokio. rust-vmm's event-manager and crosvm'sWaitContextare epoll-only.
- It waits on one
- Stopping. The first terminal event decides the outcome. Sending any
event sets the stop flag before it queues, so the vCPU that sent it, such as
the one that reset the i8042, never enters the guest again; every vCPU
checks the flag before each entry. The
run()thread then:- kicks and unparks every vCPU;
- joins the vCPU threads;
- shuts down the virtio workers and joins the thread;
- finishes the console and returns.
VM lifecycle and errors
M1 implements this public API in boxlite-vmm on Linux x86_64, and the M2
engine adapter calls it from
VmmInstance::enter:
let mut vm = Vm::new(config, console)?;
let control = vm.control(); // Clone for runtime control.
let exit = vm.run()?; // Blocks on the thread that owns the VM.
run returns once: a second call fails with AlreadyRan, since a VM never
restarts. console is a Box<dyn Write + Send> that receives the guest's
serial output through a bounded queue; run waits up to one second for the
sink to take the rest, and bytes it never takes are counted as dropped and
logged.
The driver holds exclusive access to Vm throughout run. VmControl
provides backend-independent runtime controls. External threads use
status(), stop(), request_pause(), wait_paused(timeout), resume(), and
resize_disk() without holding the VM itself. StopHandle::stop uses the
same stop latch.
VmStatus normally moves from Created to Running. A device-less VM
can reserve its first pause in Created. It keeps that status until
run claims the reservation and enters Pausing before releasing the
vCPU start gate. Every vCPU parks before its first guest entry.
During execution, request_pause() posts a command in a single-slot mailbox.
The driver accepts it in Running, enters Pausing, and kicks the vCPUs.
At checkpoint, each vCPU owner dispatches exits from complete_pending_io
until it returns Ok(IoCompletion::Done), then calls notify_guest_stopped. A
terminal exit or error returns immediately without acknowledging the pause. The
checkpoint also skips acknowledgement if a stop arrived during completion.
The driver publishes Paused after one acknowledgement from each vCPU.
resume() uses the same slot and epoch to reopen guest entry and return to
Running. The mailbox lock serializes admission against concurrent clones. A
pure poller wake prompts the driver to check the mailbox. Terminal events use
the same poller and keep their queue priority.
request_pause() posts the request and wakes the driver without waiting.
wait_paused(timeout) observes the reserved, queued, or active epoch and its
timeout leaves the pause in place.
A stop or terminal event moves the VM to Stopping, releases parked vCPUs,
and wakes pending control calls with TerminalOutcome. A stop in Created
lets the first run skip vCPU creation and take the usual cleanup path.
The first terminal event determines the outcome of an active run.
On teardown, the driver joins all scoped vCPUs, shuts down virtio workers,
finishes the console, and publishes Exited. A worker join timeout leaves
the VM in Stopping until drop. The VM owns the RAM mappings until drop,
which also publishes Exited if the VM was never run.
On Linux x86_64, the crate-internal #[cfg(test)] helper
Vm::new_device_less(config) shares KVM preflight, RAM registration, and
kernel and initramfs loading with Vm::new.
It builds an empty chipset and starts no console worker. Configuring disks,
filesystem, vsock, network, virtio console, or hotplug_mib (virtio-mem)
returns Error::Control with ControlReason::UnsupportedDevice before KVM
setup. Its empty disk registry makes resize_disk() return InvalidInput.
runreports how the VM ended, not the box's exit code.- The guest agent writes the box's exit code to
exit.jsonon the SHARED share, and it keeps travelling that way (src/guest/src/service/container.rs:406-488). - libkrun never carried it. It ends the shim with
_exit(libkrun/src/vmm/src/lib.rs:359-372), and BoxLite never sets a code, so the shim exits 0.
- The guest agent writes the box's exit code to
- The VMM never restarts a guest.
- A reset ends the VM just as a power-off does, as with libkrun.
- The guest agent ends every box with
reboot(RESTART), because x86_64 has no ACPI power-off (src/guest/src/service/container.rs:472-485).
- Nothing in the VMM exits the process, and no guest-controlled input can panic it.
- Configuration is validated in
Vm::new.- The checks are vCPU count, memory size and command-line length, against the layout's limits.
- The fields are
vcpu_count(four of six surveyed VMMs) andmemory_mib.memory_mibis BoxLite's ownInstanceSpecname; no VMM name dominates. - The errors for vCPU count and memory size are
InvalidVcpuCountandInvalidMemorySize, as in Firecracker, libkrun and dragonball. M1 names the command-line error with the rest of the boot configuration.
- Errors keep their cause.
boxlite_vmm::Errorwrapsboxlite_hypervisor::Errorand adds configuration, device and guest failures, keeping the chain throughsource().- The adapter (
src/boxlite/src/vmm/native/engine.rs) maps anUnsupportedorPermissionDeniedhost cause toBoxliteError::Unsupported, the configuration bounds (InvalidVcpuCount,InvalidMemorySize,InvalidCommandLine,InvalidDiskCount) toBoxliteError::InvalidArgument, and everything else toBoxliteError::Engine, keeping the cause chain in the message. - It keeps the shim's exit-file format (
src/boxlite/src/vmm/exit_info.rs:80). create_enginereports an engine missing from the build asBoxliteError::Unsupported, so a shim built without thenativefeature fails a native box the same typed way.
- SIGTERM. The shim asks the guest to shut down over gRPC and re-raises the signal to end the process.
Snapshot export
VmControl::export(state_path, memory_path) reserves the control slot for a
paused device-less VM on Linux x86_64. While export is pending or active,
request_pause, resume, and another export are rejected. Vm currently has
no public device-less constructor (Vm::new_device_less is crate-internal for
tests). Once all vCPUs have completed pending I/O and parked, the driver saves
the VM platform state.
If this fails, the driver releases the slot and returns the error without
dispatching vCPU capture. On success, each vCPU saves its state on its owning
thread. The driver collects all replies, including failures, and writes the
platform state and ID-ordered vCPU records only if every capture succeeds.
Following boxlite-hypervisor's capture exclusions, x86 machine state excludes
nested virtualization, Hyper-V SynIC, and guest-debug state. Pausing stops
vCPUs but not KVM's in-kernel timers, so platform capture is non-atomic; PIT
restore loses sub-tick phase and can re-arm one-shot modes (0, 1, and 4).
The state file has a 32-byte little-endian header containing the eight-byte
magic BXLVMST1, u32 version 1, u32 vCPU count, u64 RAM length, and
u64 machine-state length. Postcard encodes the following vCPU and platform
state. The memory file contains raw RAM from offset zero in ram.ranges()
order, skipping [3 GiB, 4 GiB). Its length equals the header's RAM length.
The driver creates both files exclusively with create_new and mode 0600
(subject to the process umask) and writes them synchronously without
interruption by stop requests. Relative paths are resolved against the current
working directory when the export is admitted. The driver handles a stop after
an in-flight platform save_state or file writeout finishes. If stop is requested
during a vCPU's save_state, the driver abandons the capture request so
export() returns TerminalOutcome without waiting, but run() still waits
for the vCPU thread to exit. finish_export releases the control slot and
returns TerminalOutcome if the VM is terminal. The driver skips fsync, and
dropping the files ignores delayed close(2) errors. Ok(()) provides no
guarantee of power-loss durability.
Callers must have exclusive use of both target paths during export. Existing
targets return AlreadyExists and retain their contents. If export fails
after creating a file, boxlite-vmm leaves it in place, even if partially
written. The caller (runtime or runner) is responsible for cleanup, for example
by exporting into a temporary directory and atomically renaming it on success.
Snapshot restore
On Linux x86_64, Vm::from_state(state_path, memory_path) opens the two files
produced by VmControl::export. It validates the v1 header, vCPU and IRQ chip
order, RAM layout, and KVM GPA limit. Each file must end at its declared
payload boundary. The constructor streams the RAM image into anonymous
mappings, creates the host VM, and registers the mappings. A successful
import returns a device-less VM in Created.
Vm::run installs the saved machine state in order.
- The driver calls
restore_before_vcpusto restore the VM clock before it starts the vCPU threads. - Each vCPU owner creates its vCPU, calls
restore_statewith the saved CPU state, and callsnotify_guest_stoppedto notify the guest clock. It then waits at the start gate. - The driver handles queued terminal events first. Once every vCPU is ready,
if the stop latch is clear, the driver calls
restore_after_vcpusto restore the IRQ chips and PIT. Only success opens the gate for guest entry.
A setup failure aborts guest entry. The driver joins every started vCPU and
publishes Exited. A control.request_pause() reservation made in Created keeps
guest entry closed through Paused until control.resume().
On Linux x86_64 with read/write /dev/kvm, make test:integration:vmm:kvm
exercises flat-guest restore, including a 3073 MiB snapshot across the
32-bit MMIO hole. make test:integration:vmm:linux uses VMM_KERNEL for the
Linux restore round trip. make coverage:vmm:kvm and make coverage:vmm:boot
exercise the same restore paths under coverage.
Where the engine plugs in (M2)
Engine choice. The
native-vmmexperimental token gatesAdvancedBoxOptions.engine(src/boxlite/src/runtime/advanced_options.rs), whichinit_box_variablesandprovision_boxpersist asBoxConfig.engine_kind(src/boxlite/src/litebox/config.rs:44);vmm_spawn.rsreads it into theInstanceSpecand theShimController.get_or_createrefuses a box on another engine, and the REST runtime and untrusted imports reject the option likenested_virtualization.The native adapter (
src/boxlite/src/vmm/native/, Linux x86_64, featurenative, registered throughinventorylikekrun/) is strict like libkrun: a request it cannot serve failscreatewithUnsupported(no kernel, a non-ELF kernel, a virtio-fs root, nested virtualization). It converts filesystem shares, the Linux gvproxy endpoint and host Unix RPC/ready sockets into device configuration. It takes its kernel fromInstanceSpec.kernel, preserves disk attach order (vdacontainer,vdbguest root), and defaults toconsole=hvc0. The single filesystem device exports logical shares below its aggregate root; matching mount instructions are sent only for the native engine.Runtime control. The host-only
vmm.sockserves HTTP/1.1 over a serial control thread.POST /v1/resize-diskroutes a target size byblock_idthroughVmControl::resize_disk.POST /v1/mount-controlaccepts directory delivery operations, with a directory descriptor attached when registering a mount.The
box.socklistener forwards guest RPCs, including Mount and Detach.Runtime resize.
LiteBox::resizeconfirms the requested device size, runsresize2fsin the guest, and saves the completed target in box state. Queries read the image capacity, and callers can retry the same target after an uncertain or partial result.File size limits. The VMM bounds guest I/O by virtual disk capacity. The host kernel enforces the shim's configured or inherited
RLIMIT_FSIZEsoft limit.libkrun assumptions outside
krun/.- The jailer stages the shim and its adjacent libkrunfw files together under
<home>/shims/<digest>/. The sandbox receives read-only access to that directory, and libkrun loads the firmware from beside the shim. - The network socket name derives from libkrun's
-krun.socksuffix (src/boxlite/src/net/socket_path.rs:51-59). - The Linux seccomp filter is written for libkrun's threads
(
src/boxlite/src/jailer/seccomp.rs:239-243).
- The jailer stages the shim and its adjacent libkrunfw files together under
Shared shim cache
Installed shim + libkrunfw → content digest → <home>/shims/<digest>/
├─ read-only → Box A shim
└─ read-only → Box B shim
The cache hashes filenames, lengths, and contents in filename order. The runtime can reuse a digest in-process when source file metadata matches and the timestamps were stable before hashing. A cold start copies into a staging directory and renames it into place after writing the completion stamp. Boxes using the same shim and firmware share one published directory.
Guest boot contract
The table compares what the guest gets from libkrun today with what it gets from the new VMM.
| Item | libkrun today | New VMM | Milestone |
|---|---|---|---|
| Kernel | libkrunfw: Linux 6.12 with 32 patches, loaded as a shared library | a pinned LTS kernel file with BoxLite's config: Image on arm64; bzImage or ELF vmlinux on x86_64; the native engine takes it from advanced.kernel until the runtime bundles it |
M1 |
| PID 1 | init.krun, which starts the agent as its child |
boxlite-guest |
M2 |
| Root filesystem | a throwaway virtio-fs root; init.krun then mounts /dev/vdb |
the kernel mounts /dev/vdb (ext4) read-only, and the disk reports itself read-only |
M2 |
| Command line | libkrun's defaults (libkrun/src/vmm/src/vmm_config/kernel_cmdline.rs:7-11), init=/init.krun and KRUN_* variables |
console=hvc0 root=/dev/vdb ro panic=-1 reboot=k init=/boxlite/bin/boxlite-guest, then the agent's environment as quoted "KEY=value" parameters (an entry holding " is skipped), then -- --listen vsock://2695 --notify vsock://2696; on x86_64, one virtio_mmio.device= per device at the front |
M2 |
| Disks | vda is the container disk (qcow2, read-write) and vdb the guest root (raw, read-only); names follow attach order |
unchanged | M2 |
| virtio-fs | one device per share: BoxLiteShared (read-write) and one per volume |
one device, with each share as an export under it | M2 (SHARED), M3 (volumes) |
| vsock | guest CID 3; host box.sock to guest port 2695 for gRPC, guest to host port 2696 as the ready signal (src/shared/src/constants.rs:20-26) |
unchanged | M2 |
| Network | virtio-net to gvproxy in the shim (a stream socket with 4-byte length prefixes on Linux, datagrams with the VFKT handshake on macOS), with 192.168.127.2/24 set by the agent |
unchanged; no TSI | M2 |
| Console | virtio-console hvc0 into console.log, truncated at each boot |
unchanged; M1 first boots on the PL011 or 8250 | M1–M2 |
| Other devices | virtio-rng, and virtio-balloon with free page reporting (libkrun/src/devices/src/virtio/balloon/device.rs:28-30) |
unchanged | M2 |
| Wall clock | PL031 (arm64) or kvm-clock (x86_64) at boot; on macOS, resync over vsock datagram port 123 | the same at boot, with the CMOS RTC registered as rtc0 on x86_64; M2 chooses the resync mechanism |
M1–M2 |
| End of the VM | the agent writes exit.json, syncs and calls reboot(RESTART); libkrun then exits the process |
the same guest steps; run() returns GuestReset |
M2 |
| Start failure | libkrun reports every error as -EINVAL, and the adapter probes the hypervisor for the cause |
typed errors | M2 |
M1 boots only a test initramfs, so its command line names the serial console
(console=ttyAMA0 for the arm64 PL011, console=ttyS0 for the x86 8250) and no
root disk.
As PID 1, boxlite-guest takes on these duties in M2:
- Take over
init.krun's setup (libkrun/init/init.c:504-570,:1290,:1364-1374):- mount devtmpfs on
/dev, proc, sysfs, cgroup2 on/sys/fs/cgroup, devpts, and/dev/shm; - make
/a shared mount; - set
RLIMIT_NPROCandRLIMIT_NOFILE; - set the hostname.
- mount devtmpfs on
- Bring
loup in every box. Today the agent raises it only when networking is enabled (src/guest/src/network.rs:178-192), and boxes without networking still need 127.0.0.1. - Never exit.
- Today the panic hook calls
exit(1)(src/guest/src/main.rs:83-85). As PID 1, that panics a stock kernel. - Fatal paths therefore sync and reset, and
panic=-1turns a kernel panic into a reset.
- Today the panic hook calls
- Keep boot inputs small.
- The kernel caps the command line: 2 KiB on arm64
(
src/boxlite/src/litebox/init/tasks/guest_entrypoint.rs:36-41). - It also caps the number of boot environment entries: 32 under libkrunfw's
CONFIG_INIT_ENV_ARG_LIMIT. - Everything else keeps arriving over gRPC.
- The kernel caps the command line: 2 KiB on arm64
(
These three boot/runtime integration patch groups come from BoxLite's pinned
libkrunfw revision e0647fa7. They are the patches this
boot contract replaces, rather than an inventory of every architecture or
device patch in libkrunfw:
- Init death and reboot: 0001,
Don't panic when init diesand 0002,Ignore run_cmd on orderly reboot. An agent that never exits, pluspanic=-1, replaces them. - vsock datagrams: the 0003–0008 patch series, ending
in
0008-virtio-vsock-support-dgrams.patch. The macOS clock resync uses datagrams; M2 chooses its replacement. - TSI: 0009,
Transparent Socket Impersonation implementationand 0010,allow hijacking sockets. Unused: the network factory always returns gvproxy (src/boxlite/src/net/mod.rs:481-484).
Boot path
No firmware or boot loader runs in the guest. As in libkrun, Firecracker and
crosvm, the VMM is the boot loader: it writes the kernel and its boot data into
guest RAM and starts the boot vCPU at the kernel's entry point, as Linux's boot
protocols require (Documentation/arch/arm64/booting.rst,
Documentation/arch/x86/boot.rst).
| Step | arm64 (HVF, KVM) | x86_64 (KVM, WHP) |
|---|---|---|
| Load the kernel | the Image at its text offset from a 2 MiB aligned base (booting.rst:135-137) |
a bzImage's protected-mode kernel at 1 MiB, or an ELF vmlinux at the addresses its program headers name, 16 MiB by default (arch/x86/Kconfig:2096-2098) |
| Describe the machine | a device tree in the last 2 MiB of RAM: memory, each CPU with the psci enable method, a psci node with the HVC conduit, the GIC, the timer, the apb_pclk clock the PL011 and PL031 name, the PL011, the PL031, each device as virtio,mmio, and the command line as bootargs; Firecracker writes the same nodes, with an ns16550a UART in place of the PL011 (Firecracker src/vmm/src/arch/aarch64/fdt.rs:351–397) |
boot_params at 0x7000: the setup header, which a bzImage carries at offset 0x1f1 and the VMM fills in for a vmlinux, the e820 memory map, and cmd_line_ptr to the command line at 0x2_0000, which names each virtio_mmio.device= (boot.rst:1371-1376); an MP table at 0x9_FC00 that lists each vCPU, the IOAPIC and its interrupt sources |
| CPU state at entry | MMU off, interrupts masked in PSTATE.DAIF, at EL1 (booting.rst:169-176) |
64-bit mode with paging on: identity-mapped page tables and a GDT with flat __BOOT_CS and __BOOT_DS, interrupts off (boot.rst:1394-1402) |
| Boot vCPU registers | PC at the Image's first instruction, X0 at the device tree, X1 to X3 zero (booting.rst:162-165, :423-424) |
RIP at the 64-bit entry, which for a bzImage is the load address plus 0x200; RSI at boot_params (boot.rst:1390-1392, :1401-1402) |
| Other vCPUs | powered off until the kernel calls PSCI CPU_ON (booting.rst:447-453) |
waiting for the boot vCPU's INIT and SIPI to each one the MP table lists; KVM's in-kernel local APIC holds them in KVM_MP_STATE_UNINITIALIZED (KVM_GET_MP_STATE in the KVM API), where KVM_RUN blocks and returns EAGAIN once INIT or SIPI arrives (arch/x86/kvm/x86.c:11487-11518) |
Firecracker sets the same state. On arm64 every vCPU gets PSTATE at EL1h with
DAIF masked, and only vCPU 0 gets PC and X0
(Firecracker src/vmm/src/arch/aarch64/regs.rs:23,
Firecracker src/vmm/src/arch/aarch64/vcpu.rs:338–373).
On x86_64 the boot vCPU gets RIP, RSI pointing at the zero page, long mode, and
identity page tables from 0x9000 (Firecracker src/vmm/src/arch/x86_64/regs.rs:86–107,
Firecracker src/vmm/src/arch/x86_64/regs.rs:247–282).
x86_64 needs the MP table because it boots without ACPI or a device tree:
without the table or an ACPI MADT, Linux turns off the IOAPIC and SMP
(arch/x86/kernel/apic/apic.c:1270-1276, arch/x86/kernel/smpboot.c:1088-1090).
Linux looks for it in low memory, including the last KiB below 640 KiB
(arch/x86/kernel/mpparse.c:612-614), where Firecracker and libkrun write it
(Firecracker src/vmm/src/arch/x86_64/mod.rs:271–272,
libkrun/src/arch/src/x86_64/mod.rs:266-268). Firecracker's table lists each
vCPU, an ISA bus, the IOAPIC and its interrupt sources
(Firecracker src/vmm/src/arch/x86_64/mptable.rs:177–231).
The kernel then boots itself (Linux v6.12):
- Entry. On arm64 the
Imageheader's first two instructions run:efi_signature_nop, a NOP that carries the PE/COFFMZmagic, thenb primary_entry. The kernel keeps X0 as its device tree pointer, turns on its MMU and callsstart_kernel(arch/arm64/kernel/head.S:60-61,:169-170,:521-533,:243). On x86_64 abzImagedecompresses itself from its entry at0x200(arch/x86/boot/compressed/head_64.S:285-288,:477), and the kernel'sstartup_64callsx86_64_start_kernel(arch/x86/kernel/head_64.S:38,:474). - Machine.
start_kernelreads the device tree orboot_paramsand the command line insetup_arch(init/main.c:903,:925). - CPUs and devices.
kernel_init_freeablestarts the other vCPUs insmp_init, then probes drivers indo_basic_setup(init/main.c:1572,:1580). The virtio-mmio probe reads each device's magic value and ID (drivers/virtio/virtio_mmio.c:640,:656), and each read is an MMIO exit to the VMM's device. - Root and init.
prepare_namespacemounts/dev/vdbread-only as/(init/main.c:1593,init/do_mounts.c:60-69), andkernel_initexecutes theinit=program as PID 1 (init/main.c:594-605,:1509). - Agent.
boxlite-guestapplies its sysctl hardening and forks its zygote before any thread (src/guest/src/main.rs:106-120). It then serves gRPC on vsock port 2695, connects to port 2696 to report ready, and waits forGuest.Init(src/guest/src/service/server.rs:107-163).
Room for later milestones
- M6, hot-plug mounts.
- One virtio-fs device serves every export, so a mount added at runtime is a new entry in the fs device's export table, sent to it as a message.
- No bus device, interrupt line or guest rescan is involved.
- The jailed shim still needs access to the new host directory, for example as a descriptor passed from the runtime.
- M7, dynamic resources.
vcpu_countat boot is the maximum. The guest brings CPUs online and offline: PSCICPU_ONandCPU_OFFon arm64, INIT and SIPI on x86_64.- A hotplug region directly above RAM is reserved at boot. virtio-mem adds
and removes blocks in it with
map_memoryandunmap_memory.
- M8, memory snapshots.
- The exit contract already requires pending I/O to finish before vCPU
state is saved (
src/hypervisor/src/exit.rs). - vCPU registers, interrupt-controller state (
hv_gic_state_*on HVF, vgic attributes on KVM) and device state are plain data. They are serialised with serde, as in all four surveyed VMMs that take snapshots. - Device snapshots plan to map the memory file copy-on-write through
map_memory.
- The exit contract already requires pending I/O to finish before vCPU
state is saved (
- M9, GPU.
- BoxLite's own devices stay on virtio-mmio.
- A PCI transport serves only passed-through devices, in the ECAM and BAR windows the layout reserves. On arm64, 32-bit BARs come from the unused part of the device window.
- M9 adds an MSI call to
Vmfor those devices.
- M10, Windows hosts.
boxlite-hypervisorreserves awhpmodule for WHP on Windows x86_64, and the backend table lists its calls. It differs from HVF and KVM in three ways:- WHP emulates only local APICs, so the IOAPIC, PIC and PIT run in userspace
and a raised line ends in
WHvRequestInterrupt. M10 decides which crate owns them. OpenVMM keeps them in its chipset crate, which programs MSI routes into the backend (vmm_core/virt/src/irqcon.rs:24-29). When the guest ends a level-triggered interrupt,WHvRunVpExitReasonX64ApicEoireturns its vector to the WHP backend. InsideVcpu::run, that backend forwards EOI to the userspace IOAPIC through a shared controller or callback, then resumes WHP; it does not return EOI as aVcpuExitto the VMM loop. M10 wires that controller interaction, as QEMU does inside its WHP exit handling (target/i386/whpx/whpx-all.c:2332-2335). - A memory-access exit gives the instruction bytes and the guest address,
not the access width or data. The backend's
emulatordecodes the instruction, as OpenVMM does with itsx86emucrate, soMmioReadandMmioWritekeep their shape. - An unrecoverable guest exception
(
WHvRunVpExitReasonUnrecoverableException) isError::UnhandledExit, and QEMU pauses the VM on it (target/i386/whpx/whpx-all.c:2684-2694). KVM instead reports an x86 triple fault asKVM_EXIT_SHUTDOWN, which the backend maps toReset. M10 decides whether WHP matches KVM.
- WHP emulates only local APICs, so the IOAPIC, PIC and PIT run in userspace
and a raised line ends in
References
The survey behind the names and the layout, the exit contract, the boot path and the M10 notes used these pinned sources:
| Project | Pin | Files |
|---|---|---|
| Firecracker | 68698ad |
src/vmm/src/vstate/, src/vmm/src/arch/*/layout.rs, src/vmm/src/arch/aarch64/regs.rs, src/vmm/src/arch/aarch64/vcpu.rs, src/vmm/src/arch/aarch64/fdt.rs, src/vmm/src/arch/x86_64/regs.rs, src/vmm/src/arch/x86_64/vcpu.rs, src/vmm/src/arch/x86_64/mod.rs, src/vmm/src/arch/x86_64/mptable.rs |
| VIRTIO | 1.4 CS01 |
§2.1 (device status), §2.4 (reset), §2.7 (split queues), §4.2.2 (MMIO register layout) |
| crosvm | 4c88690 |
hypervisor/src/lib.rs, devices/src/bus.rs, aarch64/src/lib.rs |
| OpenVMM | 998904f |
vmm_core/virt_whp/src/, vmm_core/virt/src/irqcon.rs, vm/x86/x86emu/ |
| cloud-hypervisor | c245270 |
hypervisor/src/, vm-device/src/bus.rs, arch/src/*/layout.rs, README.md |
| libkrun | a66775c |
src/hvf/src/lib.rs, src/vmm/src/builder.rs, init/init.c, src/devices/src/legacy/vcpu.rs, src/arch/src/x86_64/mod.rs, src/devices/src/fdt/aarch64.rs |
| alioth | 9d39a5d |
alioth/src/hv/hv.rs, alioth/src/arch/*/layout.rs |
| hyperlight | 398e795 |
src/hyperlight_host/src/hypervisor/virtual_machine/mod.rs |
| kvm-ioctls | 668b30b |
kvm-ioctls/src/ioctls/vcpu.rs, kvm-ioctls/src/ioctls/vm.rs |
| applevisor | e39e718 |
src/vcpu.rs, src/gic.rs |
| dragonball (Kata Containers) | 68b5671 |
src/dragonball/src/vmm.rs, src/dragonball/crates/dbs_boot/ |
| Linux | v6.12 |
Documentation/arch/arm64/booting.rst, Documentation/arch/x86/boot.rst, arch/arm64/kernel/head.S, arch/x86/boot/compressed/head_64.S, arch/x86/kernel/head_64.S, init/main.c, init/do_mounts.c, drivers/virtio/virtio_mmio.c, drivers/firmware/psci/psci.c, arch/arm64/kvm/psci.c, arch/arm64/kernel/cpuinfo.c, arch/x86/kernel/apic/apic.c, arch/x86/kernel/smpboot.c, arch/x86/kernel/mpparse.c, arch/x86/Kconfig |
| QEMU | f8aef8a |
accel/kvm/kvm-all.c, target/arm/hvf/hvf.c, target/i386/whpx/whpx-all.c |
Host APIs:
- HVF: the Hypervisor.framework headers
hv_vcpu.h,hv_vcpu_types.h,hv_vm.handhv_gic.h, in the macOS SDK. - KVM: the KVM API.
- WHP: the Windows Hypervisor Platform API.