How google/crosvm works
1. What the repository is
- This is the crosvm virtualization stack. The top-level binary in src/ is the VM monitor/orchestrator, while most functionality is split into reusable crates for memory, devices, async I/O, hypervisor backends, and platform-specific integration.
2. Entry point and orchestration layer
- src/main.rs and src/crosvm/* implement the host-facing control plane: CLI/config parsing, VM setup, device selection, and lifecycle management.
- src/sys/linux/* and src/sys/windows/* hold the platform-specific launch paths and host integration logic.
- This layer is the coordinator that wires together hypervisor, memory, kernel loading, device models, sandboxing, and control APIs.
3. Guest boot and machine construction
- kernel_loader, kernel_cmdline, cros_fdt, acpi_tables, x86_64, aarch64, and riscv64 are responsible for preparing guest boot inputs:
- loading kernels / boot images,
- constructing kernel command lines,
- building FDT/ACPI/SMBIOS/boot tables,
- architecture-specific boot metadata.
- On x86, x86_64 also covers boot parameters, GDT/interrupt setup, and platform tables.
- This forms the boundary between host initialization and the guest’s initial boot state.
4. Hypervisor abstraction
- hypervisor is the backend abstraction for VM creation and vCPU execution.
- It supports multiple providers: KVM, WHPX, HAXM, Gunyah, GenieZone, and Halla, with per-arch implementations under hypervisor/src/*.
- kvm_sys, vfio_sys, and virtio_sys are low-level bindgen/syscall crates used by higher layers where direct kernel or device ABI access is required.
- In the diagram, this is the hardware-acceleration boundary: crosvm talks to a hypervisor backend, which in turn talks to the kernel/OS virtualization APIs.
5. Guest memory and address-space management
- vm_memory provides guest RAM mappings, guest-address types, and udmabuf integration.
- resources provides address allocators for guest RAM windows, MMIO ranges, PCI addresses, and related host-side resource planning.
- swap, disk, and some device crates consume these abstractions when they need direct guest memory access or host-backed buffers.
- This subsystem is the shared substrate used by hypervisor, device emulation, and boot image placement.
6. Device model: the main emulation surface
- devices is the largest subsystem and contains the emulated hardware model.
- It includes:
- legacy/platform devices: ACPI, CMOS, PIT, serial, power, TPM, debug console;
- interrupt controllers and irqchips: APIC, IOAPIC, PIC, KVM-backed, WHPX, userspace, and platform-specific variants;
- PCI/PCIe infrastructure: root complex, bridges, hotplug, MSI/MSI-X, configuration space, VFIO passthrough;
- virtio device implementations.
- The core architecture diagram should show devices hanging off the guest buses and interrupt paths, not directly off the CLI.
7. Virtio I/O path
- Most guest-visible modern devices live under devices/src/virtio/*.
- This includes block, net, fs, gpu, input, rng, balloon, console, vsock, pmem, scsi, snd, video, p9, tpm, and vhost/vhost-user adapters.
- The data flow is generally: guest driver → virtqueue descriptors → device backend/worker → host resource or service → completion interrupt back to the guest.
- Shared queue handling lives in devices/src/virtio/queue/*, descriptor_*, and interrupt.rs.
8. Async/event-driven execution
- cros_async is the async runtime and event orchestration layer used by devices and I/O-heavy components.
- It provides executors, timers, polling/event sources, wakers, queueing, and blocking work pools with Linux and Windows implementations.
- base, base_tokio, and io_uring support lower-level event sources, descriptors, wait contexts, tubes, timers, and Linux async I/O integration.
- In the diagram, this is the internal scheduler/event loop that connects device workers to host kernel events and guest-facing queues.
9. Sandboxing and process isolation
- jail implements the Linux process isolation layer using Minijail and seccomp policies.
- The policy files under jail/seccomp/* are per-device and per-arch, which matches crosvm’s process-per-device security model.
- base contains the IPC, descriptor, tube, notifier, and worker-thread primitives used to connect sandboxed child processes back to the main VM process.
- This is an important architectural boundary: trusted orchestration in the parent, restricted device workers in jailed subprocesses.
10. Host/device communication and control plane
- vm_control, crosvm_control, crosvm_cli, and parts of base provide control APIs and IPC plumbing for external clients.
- The host management path is separate from the guest datapath: external tools issue commands to crosvm, which then mutates VM state or forwards actions to device workers.
- tube_transporter, base::tube, and related IPC layers are the main internal transport for this control path.
11. Storage, networking, and filesystem backends
- disk handles raw, qcow2, Android sparse, GPT, and zstd-backed disk images.
- net_util, net_sys, vhost, and vhost-related device code cover tap/slirp networking and vhost acceleration.
- fuse, ext2, and common/audio_streams support specialized storage/filesystem and audio flows where the device model delegates to host-side services or shared-memory backends.
- These are backend libraries rather than the VM orchestrator itself, so they sit behind the virtio devices.
12. Graphics, input, and multimedia stack
- gpu_display, media, media/ffmpeg, media/libvda, android_audio, and win_audio provide platform and codec backends for GPU/audio/video features.
- devices/src/virtio/gpu, .../video, .../snd, and gpu_display connect the guest’s graphics/audio/video queues to host rendering, encoding/decoding, or audio APIs.
- External services and libraries matter here: Wayland/X11/Windows UI surfaces, FFmpeg, ChromeOS libvda, CRAS, and Android AAudio are part of the runtime architecture for those devices.
13. Platform-specific and vendor-specific virtualization paths
- Android and ChromeOS integration live across arch, common, system_api, power_monitor, and README.chromeos.md-related paths.
- Vendor hypervisors and ARM-specific flows are split into aarch64_sys_reg, geniezone, gunyah, halla, and their corresponding device/irqchip support.
- The repo is explicitly multi-platform: Linux is the primary host, but there is substantial Windows support and multiple ARM hypervisor backends.
14. Testing, end-to-end validation, and tooling
- e2e_tests is the guest/VM integration test harness with dedicated guest images, boot flows, and workload benchmarks.
- fuzz covers protocol and parser surfaces such as virtqueues, block/FS, USB descriptors, and QCOW.
- infra, tools, and docs/book contain build/test automation and architecture docs, but they are support systems rather than runtime components.
- For an architecture diagram, these are best shown as validation/tooling around the core VM stack, not in the hot path.
15. Overall data flow to capture in a diagram
- External user/tooling invokes the crosvm binary or control API.
- crosvm constructs guest boot state, allocates memory/resources, and instantiates a hypervisor VM.
- vCPUs run in the hypervisor backend while device models run in-process or in jailed child processes.
- Guest I/O exits through virtio/PCI/MMIO/IRQ paths into device backends, which use async I/O, host services, or external libraries, then signal completion back into the guest.
- The major architectural boundaries are: host control plane vs guest datapath, parent process vs jailed device workers, and device abstractions vs backend-specific implementations.
Main entry points: crosvm VM setup · devices Device model · hypervisor Hypervisor · jail Sandboxing
Components 30
Control Plane
CLI, orchestration, and external control APIs.
- crosvm binary · Top-level VM monitor entry point and process coordinator.
src/main.rs - VM setup · CLI/config parsing, VM construction, device selection, and lifecycle control.
src/crosvm - Control API · External control surface for managing VMs and device state.
vm_control
Guest Boot
Kernel loading and machine-setup inputs.
- Kernel loader · Loads kernels and boot images for guest startup.
kernel_loader - Cmdline · Builds guest kernel command lines.
kernel_cmdline - FDT builder · Constructs device tree overlays and related boot metadata.
cros_fdt - ACPI tables · Builds ACPI/SMBIOS/firmware tables for guests.
acpi_tables - x86 boot · x86-specific boot parameters, GDT, interrupts, and platform tables.
x86_64
Core Substrate
Shared memory, async, IPC, and isolation primitives.
- Guest memory · Guest RAM mappings, address types, and udmabuf integration.
vm_memory - Allocators · Guest RAM, MMIO, PCI, and host-side address allocation.
resources - Async runtime · Executors, timers, polling, blocking work pools, and wakers.
cros_async - IPC base · Descriptors, tubes, wait contexts, worker threads, and host IPC primitives.
base - Sandboxing · Minijail and seccomp-based device worker isolation.
jail
Hypervisor Backends
VM and vCPU providers plus low-level ABI bindings.
- Hypervisor · Backend abstraction for VM creation and vCPU execution.
hypervisor - KVM ABI · Low-level KVM bindings used by the hypervisor layer.
kvm_sys - VFIO ABI · Low-level VFIO bindings for device passthrough and I/O access.
vfio_sys - Virtio ABI · Low-level virtio and vhost ABI definitions.
virtio_sys
Device Model
Emulated hardware, buses, interrupts, and virtio.
- Device model · Emulated hardware, buses, irqchips, PCI, and virtio frontends.
devices
Host Backends
Host-side services for graphics, audio, networking, and storage.
- Display stack · Host display integration for rendering and window-system surfaces.
gpu_display - Media codecs · FFmpeg and libvda-backed audio/video encode and decode support.
media - Network host · Tap and slirp host networking support.
net_util - Disk backends · Raw, qcow2, sparse, GPT, and zstd-backed disk image handling.
disk - FUSE service · Filesystem server and mount-side host service support.
fuse - Ext2 tools · Ext2 filesystem construction and manipulation utilities.
ext2
Platform Layers
Host- and architecture-specific integration paths.
- Linux host · Primary Linux launch path and host integration logic.
src/sys/linux.rs - Windows host · Windows launch path and host integration logic.
src/sys/windows.rs - Arch support · Architecture-specific host helpers and platform hooks.
arch
Connections 33
- crosvm binary → VM setup: starts · The binary delegates VM orchestration to the crosvm control layer.
- VM setup → Kernel loader: loads · Boot pipeline loads guest kernel or boot image.
- VM setup → Cmdline: builds · Constructs guest command line and boot parameters.
- VM setup → FDT builder: assembles · Prepares device-tree-based boot metadata where needed.
- VM setup → ACPI tables: assembles · Prepares ACPI and SMBIOS tables for the guest.
- VM setup → x86 boot: specializes · x86 host/guest boot details are layered in for x86 machines.
- VM setup → Guest memory: allocates · Sets up guest memory mappings and placement.
- VM setup → Allocators: plans · Allocates MMIO, PCI, and other guest resources.
- VM setup → Hypervisor: creates VM · Instantiates the backend VM and vCPU execution context.
- VM setup → Device model: wires devices · Constructs the guest device model and bus topology.
- VM setup → Sandboxing: isolates · Moves selected device workers into sandboxed subprocesses.
- VM setup → Control API: exposes · Publishes control APIs for external clients.
- Hypervisor → KVM ABI: uses · KVM is one backend ABI used for hardware acceleration.
- Hypervisor → VFIO ABI: uses · VFIO is used for device passthrough paths.
- Hypervisor → Virtio ABI: uses · Virtio and vhost ABI support underpin backend integrations.
- Device model → Async runtime: drives · Device workers and I/O paths are event-driven.
- Device model → IPC base: communicates · Uses tubes, descriptors, and IPC primitives for coordination.
- Device model → Guest memory: maps · Devices consume guest memory for DMA and shared buffers.
- Device model → Allocators: reserves · Device placement consumes address allocation results.
- Device model → Display stack: renders via · Graphics devices connect to host display backends.
- Device model → Media codecs: streams via · Video and audio devices delegate to codec/media backends.
- Device model → Network host: networking · Network devices depend on host tap/slirp support.
- Device model → Disk backends: storage · Block and related storage devices rely on disk backends.
- Device model → FUSE service: filesystem · Filesystem-related device paths can delegate to FUSE services.
- Disk backends → Guest memory: shares buffers · Image I/O and guest-facing buffers interact through memory mappings.
- Async runtime → IPC base: builds on · Async runtime sits on top of the lower-level IPC and waiting primitives.
- Sandboxing → IPC base: uses · Sandboxed workers are connected back to the parent process through base IPC.
- Linux host → Sandboxing: launches · Linux path performs process isolation and device worker setup.
- Windows host → Hypervisor: integrates · Windows path coordinates the host VM backend and launch flow.
- Arch support → VM setup: extends · Architecture helpers feed the orchestration and platform setup layer.
- E2E tests → crosvm binary: validates · Integration tests exercise the full crosvm execution path.
- Fuzzing → Device model: hardens · Fuzzing targets cover device and protocol parsing surfaces.
- Docs → VM setup: documents · Architecture docs explain the runtime and control-plane design.