Virtualization platform
The virtualization platform runs ArcBox workloads in isolated virtual machines. It gives higher layers one VM contract while connecting each request to a monitor, a host hypervisor or external VMM, guest devices, and controlled host services.
System role
The platform separates workload intent from the host mechanism that executes it. A caller describes the guest's resources, boot inputs, disks, networks, and optional services. A VM driver validates that request, selects a VMM, and returns a handle that remains the common control point for identity, observation, shutdown, restore, and supported optional features.
The main system boundaries are:
| Boundary | System responsibility |
|---|---|
| VM driver contract | Gives orchestration one way to create, observe, stop, restore, and recover VMs. |
| VM monitor or VMM adapter | Turns the request into guest memory, CPU execution, boot state, devices, and runtime events. |
| Hypervisor backend | Provides host-side CPU and memory isolation. |
| Device model | Presents guest hardware and carries guest I/O to host services. |
| Host integration | Supplies storage, network paths, file access, control channels, and other resources outside the guest. |
The same contract covers in-process monitors and external VMM processes. This lets workload orchestration choose a backend without changing its VM control model. See VM lifecycle and hypervisor backends for backend choice and lifecycle behavior.
VM monitor
The VM monitor is the control center for a guest. It prepares guest memory and boot inputs, attaches the requested devices, starts execution, observes exits and device work, and applies stop or restore actions.
The monitor presents a small state view to its callers. A guest is running, quiesced after a held checkpoint, or exited with a status. Events report guest-driven changes such as exit or reset, while the handle keeps the durable VM record that recovery uses.
This diagram shows how a VM request becomes guest execution and how guest activity returns to the monitor.
flowchart LR
A[VM request] --> B[VM driver]
B --> C[VM monitor or VMM adapter]
C --> D[Guest memory and boot state]
C --> E[Hypervisor backend]
C --> F[Device model]
F --> G[Host services]
E --> H[Guest execution]
H --> C
G --> F
The driver contract also supports preparing an external VMM before a guest is ready. Preparation can make the process, private area, and guest-initiated listener available in advance. A later boot consumes that prepared VM once, so a plain boot and a prepare-then-boot path have the same external behavior.
References: virt/…/lib.rs• L11-34 virt/…/driver.rs• L26-101 virt/…/capability.rs• L33-103 virt/…/checks.rs• L285-369 virt/…/fake_prepared.rs• L96-118
Hypervisor backends
The backend decides where vCPUs run and how the host supplies guest memory. Linux uses KVM. macOS can use managed execution through Virtualization.framework or manual execution through Hypervisor.framework. External Firecracker execution adds a process and API boundary around a KVM-backed guest.
The backend exposes only the capabilities it can honor. A capability is an optional operation such as guest vsock, checkpoint, staging, balloon control, console output, or diagnostics. The driver claims the backend-wide feature set, and each VM handle also checks whether that VM requested the related device or service.
| Backend shape | Guest execution ownership | Recovery and host boundary |
|---|---|---|
| Managed macOS VMM | The platform framework runs the vCPUs and owns part of the device behavior. | The driver controls the framework VM through the common contract. |
| Manual hypervisor monitor | The monitor runs vCPUs and handles exits, memory access, interrupts, and in-tree devices. | The monitor joins guest requests to host resources directly. |
| External Firecracker VMM | Firecracker runs as a separate process and exposes a control socket. | The driver records the process and its private area so a later process can recover or clean it up. |
Firecracker can run directly against host paths or inside a per-VM jail. In jail mode, the VMM sees only staged boot files and disks inside its private root. The driver records the jail path with the process record because a running jailed process does not reliably reveal that path to a later adopter.
When the process that launched an external VMM is lost, recovery first verifies that a live process belongs to the VM. If its control API answers, the driver rebuilds the full handle and reads back VM state and devices. If the API is unavailable, it keeps a process-only handle that can observe and kill the verified process and can still manage its staged area. This preserves safe cleanup without pretending that unavailable devices work.
References: virt/…/driver.rs• L31-90 virt/…/driver.rs• L183-220 virt/…/capability.rs• L318-375 virt/…/driver.rs• L50-100 virt/…/discover.rs• L29-59 virt/…/adopt.rs• L39-86 virt/…/process_only.rs• L31-126
Device model
The device model gives the guest standard virtual hardware instead of direct access to host resources. VirtIO transports guest queue requests through guest memory and interrupts. Device implementations then map those requests to disks, networks, files, sockets, randomness, console output, or memory targets.
The device set is shaped by both the monitor and the selected backend. A managed framework may provide a device itself. A manual monitor registers an in-tree device and connects its transport to the matching host service. The guest-visible contract stays stable even when the host-side path changes.
| Device family | Guest view | Host-side purpose |
|---|---|---|
| Block | Virtual disks | Reads and writes image files or block devices. |
| Network | Virtual Ethernet interfaces | Carries guest packets to a host network path. |
| Filesystem | A mounted shared directory | Carries file operations across the guest-host boundary. |
| Vsock | Host-guest socket ports | Carries control, readiness, execution, and service traffic without guest IP networking. |
| Console and serial | Boot and operator output | Carries early boot and interactive output. |
| Entropy | Random data source | Supplies guest randomness from the host. |
| Balloon | Guest memory target | Lets the host ask the guest to release usable pages. |
The balloon is an example of a device whose result depends on the host. On Linux, released pages can return to the host through the memory advice path. On macOS, the same current path does not reclaim physical memory, so higher layers keep idle balloon use disabled where reclaim is not available. Block requests also validate guest-provided ranges before host I/O, which keeps malformed requests inside the guest disk boundary.
See VirtIO device stack for transport, queues, and device-specific behavior.
References: virt/…/lib.rs• L16-55 virt/…/lib.rs• L104-180 virt/…/request.rs• L56-150 virt/…/driver.rs• L126-179
Host integration
Host integration makes a virtual device useful while keeping the guest inside its VM boundary. The driver maps guest intent to host paths, host sockets, network attachments, and process controls. Each resource stays tied to the VM lifetime and is released only after guest work no longer uses it.
Guest memory and boot state
Guest RAM is host-backed memory mapped into the guest's physical address space. The monitor uses it for boot data, device queues, and guest I/O. The memory boundary checks addresses and lengths before access so a guest request cannot reach an unmapped host region.
On macOS, the platform can track changed memory in software because Virtualization.framework does not provide KVM-style dirty-page tracking. It records page checksums as a baseline and reports pages whose contents changed. This supports the checkpoint and restore model without changing the common driver contract.
References: virt/…/memory.rs• L62-87 virt/…/memory.rs• L282-429
Private file areas
An external VMM that runs under a jailer receives a private per-VM area. The driver places kernels, root disks, and checkpoint data there before the VMM starts. Read-only data can share storage when safe. Writable disks receive private copies, block devices are represented by device nodes, and handed-over disks move into the area.
The area has two ownership paths. A prepared VM owns cleanup for a process it spawned. An adopted handle owns cleanup when the launching process is gone. A disk that must survive the VM leaves the area before the area is removed. See Guest filesystem sharing for the separate host-directory sharing boundary.
References: virt/…/jail.rs• L23-92 virt/…/jail.rs• L235-274 virt/…/jail.rs• L395-428 virt/…/render.rs• L43-55 virt/…/render.rs• L188-243 virt/…/prepared.rs• L51-115
Guest control channels
Vsock provides direct host-to-guest and guest-to-host channels. The host can dial a guest service. The guest can dial a host listener before or during boot. ArcBox uses this path for readiness, workload execution, file operations, and other control traffic.
The in-VM agent listens on fixed vsock services and reports readiness only after its required listeners are available. It can run commands with piped or terminal I/O, stream output, deliver signals, and report process exit. It also exposes file operations and watches, while the host remains the trusted initiator of those file requests.
The agent keeps guest wall time aligned with the host after startup and after accepted service connections. This matters for restored guests because a snapshot restores the old clock before the first post-restore workload request.
sequenceDiagram
participant H as Host service
participant V as Vsock
participant A as Guest agent
participant P as Guest workload
A-->>H: Ready connection
H->>V: Dial service port
V->>A: Framed command or file request
A->>P: Start or access workload
P-->>A: Output, file result, or exit
A-->>H: Framed result and status
References: virt/…/driver.rs• L126-161 virt/…/capability.rs• L20-30 virt/…/capability.rs• L213-226 virt/…/main.rs• L1-36 virt/…/main.rs• L503-573 virt/…/main.rs• L788-810
Runtime relationships
Workload orchestration asks the VM driver to create or restore a guest. The driver and monitor build the selected backend, attach devices, and return a handle. The handle then reports state and events while optional capability ports provide only the host services that both the backend and VM configuration support.
The durable record connects runtime control to recovery. It identifies the VM, names its driver and runtime area, and records external process details when needed. A later process can use that record to adopt a surviving VMM or remove the private area left by one that is gone.
This diagram shows the common control relationship from workload orchestration to guest services.
sequenceDiagram
participant O as Workload orchestrator
participant D as VM driver
participant M as VM monitor or adapter
participant B as Backend
participant G as Guest
participant S as Host services
O->>D: Boot or restore VM request
D->>M: Validate and prepare request
M->>B: Create isolated guest
M->>G: Load boot state and expose devices
B-->>M: Run guest
G->>M: Device requests and events
M->>S: Use controlled host resources
M-->>O: State and capability results
O->>D: Shutdown or detach
D->>M: Stop guest and release resources
The contract tests protect the relationships that are easy to break across backends. They check that lifecycle state and exit events agree, that capability claims match handle accessors, that prepare then boot matches plain boot, that staged files are usable, and that detach then adopt returns the same VM with its needed boundary information.
References: virt/…/driver.rs• L94-180 virt/…/driver.rs• L359-416 virt/…/checks.rs• L31-90 virt/…/checks.rs• L170-225 virt/…/checks.rs• L480-520 virt/…/checks.rs• L770-843 virt/…/fake_prepared.rs• L248-301
Change checklist
When these files or sections are changed, remember to consider these:
- A backend change must keep driver capability claims aligned with the optional handle accessors and with the prepare, boot, restore, detach, and adopt paths.
- A change to an external VMM record must preserve enough process and jail identity for a later adopter to find the right VM and clean the right private area.
- A change to staged disk or checkpoint names must keep staging, boot rendering, checkpoint restore, and disk handover on the same names.
- A new device or changed device capability must update guest discovery, host attachment, queue completion, and the backend's advertised feature set together.
- A memory or balloon change must keep guest address bounds safe and must distinguish Linux reclaim from macOS memory hints.
- A vsock service change must preserve listener timing, port direction, framed message compatibility, and cleanup when the VM exits.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A backend claims a capability that its handle does not expose | Orchestration reaches an absent or broken service path. | Keep DriverCapabilities and handle accessors in agreement. |
| A jailed VMM is adopted without its recorded jail | Host paths and guest sockets point outside the VM area. | Rebuild the layout from the durable jail record. |
| A VMM API is unavailable during adoption | Device and state operations cannot be restored. | Return a process-only handle that can still observe, kill, detach, and manage staging. |
| A writable disk is hard-linked into a VM area | Guest writes change the caller's source disk. | Use a private copy for writable images and preserve device-node handling for block devices. |
| Guest memory or block ranges exceed their mapped or configured bounds | Host memory or disk access can fail or cross its intended boundary. | Check address, length, sector, and capacity arithmetic before host access. |
| A required vsock listener is not bound before guest dial-out | Boot readiness or a control connection is missed. | Bind prepared listeners before boot and treat VM exit as the end of acceptance. |
| A restored guest keeps snapshot wall time | Workload timestamps and certificate checks can be wrong after restore. | Sync the guest clock before handling post-restore workload traffic. |
Key files
| File | Why to read it |
|---|---|
| virt/…/lib.rs | Defines the platform-neutral VM vocabulary and the boundary between orchestration and adapters. |
| virt/…/driver.rs | Shows the common driver, handle, state, record, and capability model. |
| virt/…/capability.rs | Explains optional services, preparation, staging, checkpointing, adoption, and vsock direction. |
| virt/…/checks.rs | Shows the cross-backend behavior the contract requires. |
| virt/…/driver.rs | Shows how an external Firecracker backend maps the common contract to boot, restore, adopt, and cleanup. |
| virt/…/render.rs | Shows the relationship between VM intent, host paths, and jailed VMM paths. |
| virt/…/jail.rs | Shows the private-area boundary and the resource staging model. |
| virt/…/adopt.rs | Shows how a surviving external VMM is identified and rebuilt after host process loss. |
| virt/…/memory.rs | Shows the macOS guest-memory boundary and software dirty tracking used for snapshots. |
| virt/…/lib.rs | Shows host memory target behavior and the platform difference in page reclaim. |
| virt/…/request.rs | Shows the guest block request boundary and checked disk-range rules. |
| virt/…/main.rs | Shows the guest-side vsock services for readiness, workload control, file operations, and clock sync. |