How nxp-imx/imx-xen works
1. What this repo is
This is the Xen hypervisor source tree: a full virtualization stack, not just a kernel. The repo contains the hypervisor itself, the host-side toolstack, guest-facing ABI headers, firmware components for virtual machines, stub domains, documentation, tests, and CI/build automation.
2. Core runtime boundary
The main architectural split is between:
- xen/: privileged hypervisor code running at the highest CPU privilege
- tools/: userspace management daemons, libraries, and CLI tools running in dom0 or the host OS
- xen/include/public/ and tools/include/: the stable interface layer between host tools and guests/hypervisor
This boundary is crossed through hypercalls, shared-memory rings, event channels, grant tables, xenstore, and I/O request protocols.
3. Hypervisor core
The xen/common/ directory holds cross-architecture hypervisor logic: memory management, domains, scheduler, event channels, grant tables, timers, tracing, livepatch, multicall, and decompression support. This is the generic control plane for VMs and host services.
4. Architecture-specific hypervisor code
xen/arch/x86/, xen/arch/arm/, xen/arch/ppc/, and xen/arch/riscv/ contain platform-specific boot, trap, MMU, interrupt, time, SMP, and virtualization plumbing. The architecture split is substantial: boot paths, page-table management, interrupt controllers, and virtualization modes differ per ISA, so the runtime is assembled from common core plus one arch port.
5. Device and virtualization subsystems
xen/drivers/ and arch subtrees implement hardware-facing support such as ACPI, PCI, IOMMU, APIC/GIC, serial consoles, cpufreq, and virtual PCI. These subsystems connect physical hardware and guest-visible virtual devices, especially for device passthrough and emulation.
6. Security and policy
Xen Security Modules live under xen/xsm/, with FLASK/SELinux-style policy support and a dummy backend. This forms a policy enforcement boundary inside the hypervisor, affecting domain creation, resource access, and control operations.
7. Toolstack and management plane
tools/libs/ contains the reusable management libraries:
- libxc for low-level hypervisor control
- libxl for higher-level domain lifecycle and device management
- xenstore, xenevtchn, xengnttab, xenforeignmemory, xenstat, xenmanage, xenhypfs, and related bindings
tools/xl/ is the main CLI frontend built on libxl. In a typical VM lifecycle, xl drives libxl, which talks to the hypervisor, xenstore, and device-model helpers.
8. Xenstore and host daemons
Xenstore is a key coordination service for domain configuration and device state. The repo includes two implementations:
- tools/xenstored/: the C xenstore daemon
- tools/ocaml/xenstored/: the Ocaml-based alternative
Supporting daemons and services include tools/console/, tools/xenconsoled, hotplug scripts under tools/hotplug/, and watchdog/monitoring utilities. These components mediate lifecycle events, backend/frontend device setup, and console I/O.
9. Guest creation, boot, and firmware path
VM boot is supported by several loaders and firmware pieces:
- tools/firmware/hvmloader/ for HVM guests
- tools/firmware/rombios/ and tools/firmware/vgabios/ for legacy BIOS-style guests
- tools/firmware/etherboot/ for network boot paths
- tools/pygrub/ for filesystem-based guest bootloader extraction
- stubdom/ for minimal isolated service domains such as vTPM and device-model support
These are the bridge between Xen’s abstract domain model and the guest’s actual boot environment.
10. I/O and device model data flow
Guest I/O is handled through a mix of paravirtual and emulated paths:
- paravirtual devices use shared rings, grant tables, and event channels
- HVM guests may route I/O through device models and ioreq mechanisms
- passthrough and virtual device support are mediated by IOMMU, backend drivers, and hotplug scripts
The repo’s xen/arch/*/hvm, xen/common/ioreq.c, xen/common/event_*, and tools/hotplug/ areas together define this path.
11. Language bindings and external APIs
tools/python/, tools/golang/xenlight/, tools/ocaml/libs/, and tools/ocaml/xenstored/ provide language-specific bindings and higher-level APIs for automation and orchestration. These are important architectural extension points because many consumers do not talk to Xen directly in C.
12. Build, packaging, and platform support
The repo is heavily build-system driven with configure, Makefile, Config.mk, xen/Rules.mk, tools/Rules.mk, and many per-component Makefiles. There is broad packaging/CI support under automation/, plus distro/container build definitions. This matters architecturally because the tree is a multi-artifact build: hypervisor image, tools, docs, firmware payloads, and tests are all produced separately.
13. Documentation and contracts
docs/ is not incidental; it captures the system’s public contracts: hypercalls, guest ABIs, migration streams, device models, security policy, and platform-specific boot requirements. For an architecture diagram, the most important contract boundaries are the public Xen headers in xen/include/public/ and the documented protocols in docs/.
14. Validation and regression safety
xen/test/, tools/tests/, tools/fuzz/, and static-analysis automation under automation/ and xen/scripts/ form the quality boundary. They validate low-level emulator behavior, policy logic, CPU handling, store semantics, livepatch, and ABI stability across supported architectures.
15. Overall system view
The repository implements a layered virtualization platform:
host firmware/bootloader → Xen hypervisor → dom0 toolstack and service daemons → guest VMs and stub domains.
The central flows are:
- VM lifecycle: CLI/toolstack → xenstore + hypercalls → hypervisor
- Guest I/O: guest ↔ shared memory/event channels/grants ↔ backends/device model
- Policy/control: admin tools → security modules and control APIs → hypervisor
That is the key structure to capture in an architecture diagram.
Main entry points: common Xen core · light libxl · public Public ABI · xl xl CLI
Components 25
Hypervisor
Privileged runtime and architecture ports.
- Xen core · Cross-architecture VM control, scheduling, memory, timers, tracing, and core services.
xen/common - x86 port · x86 boot, traps, HVM/PV handling, MMU, interrupt, and platform-specific virtualization plumbing.
xen/arch/x86 - ARM port · ARM/arm64 boot, MMU, GIC, PSCI, device tree, and virtualization support.
xen/arch/arm - PPC port · PowerPC boot, MMU, exceptions, and platform integration.
xen/arch/ppc - RISC-V port · RISC-V boot, interrupt controller, MMU, SBI, and virtualization plumbing.
xen/arch/riscv - XSM policy · Hypervisor security policy enforcement with FLASK-style authorization and dummy backend.
xen/xsm - Passthrough · IOMMU, PCI, MSI, and device passthrough support inside the hypervisor.
xen/drivers/passthrough - Console drivers · Serial, console, and debug output paths for host and early boot.
xen/drivers/char
Toolstack
Userspace management plane, daemons, libraries, and CLIs.
- libxl · High-level domain lifecycle, device, migration, and orchestration API.
tools/libs/light - libxc · Low-level hypervisor control library used by management tools and bindings.
tools/libs/ctrl - xenstore libs · Client libraries for xenstore and related event/grant/foreign-memory interfaces.
tools/libs/store - xl CLI · Main command-line frontend for domain creation, configuration, and control.
tools/xl - xenstored · C xenstore daemon providing configuration and state coordination.
tools/xenstored - oxenstored · Ocaml xenstore implementation used as an alternative daemon path.
tools/ocaml/xenstored - Hotplug · Host-side scripts and service units for device attach, console, and domain lifecycle events.
tools/hotplug - Bindings · Python, Golang, and Ocaml bindings for automation and orchestration.
tools/python
Boot & firmware
Guest boot loaders, firmware payloads, and isolated service domains.
- HVM loader · Firmware and boot-time setup for HVM guests, including BIOS tables and device init.
tools/firmware/hvmloader - Legacy BIOS · ROM BIOS, VGA BIOS, and network boot payloads for legacy guest boot flows.
tools/firmware/rombios - Stub domains · Minimal service domains such as vTPM and isolated device-model helpers.
stubdom
Contracts
Stable public headers and protocol definitions.
- Public ABI · Guest-facing hypercall, event-channel, grant-table, HVM, and I/O protocol definitions.
xen/include/public - Tool headers · Host-side APIs and compatibility headers shared by libraries, daemons, and tools.
tools/include
Build & quality
Build system, docs, automation, and validation.
- Docs · Architecture, ABI, protocol, and operational documentation.
docs - Build system · Configure, makefiles, per-platform rules, and generated build metadata.
Makefile - Automation · CI pipelines, containers, analysis scripts, fuzzing, and regression automation.
automation - Tests · Hypervisor and toolstack regression tests and emulator-focused validation.
xen/test
Connections 30
- xl CLI → libxl: drives · CLI uses libxl for domain lifecycle and device management.
- libxl → libxc: calls · Higher-level orchestration builds on low-level hypervisor control.
- libxl → xenstore libs: uses · libxl coordinates VM state through xenstore and related tool interfaces.
- xl CLI → xenstored: coordinates · Domain creation and configuration are published through xenstore.
- xenstored → Xen core: control path · Daemon synchronizes guest state that ultimately affects hypervisor-managed domains.
- oxenstored → xenstored: alt impl · Alternative xenstore implementation for the same coordination role.
- Hotplug → xenstored: reacts to · Hotplug and service scripts respond to xenstore and lifecycle events.
- Bindings → libxl: wraps · Language bindings expose higher-level orchestration APIs.
- Bindings → libxc: wraps · Some bindings also expose low-level control interfaces.
- Xen core → Public ABI: ABI · Public headers define the guest and toolstack contract for hypercalls and protocols.
- libxc → Public ABI: ABI · Low-level control library speaks the published Xen ABI.
- xenstore libs → Public ABI: protocols · Tooling consumes xenstore and shared-memory protocol definitions.
- x86 port → Xen core: specializes · x86 contributes architecture-specific implementations to the common hypervisor core.
- ARM port → Xen core: specializes · ARM contributes architecture-specific implementations to the common hypervisor core.
- PPC port → Xen core: specializes · PowerPC contributes architecture-specific implementations to the common hypervisor core.
- RISC-V port → Xen core: specializes · RISC-V contributes architecture-specific implementations to the common hypervisor core.
- XSM policy → Xen core: enforces · Security policy hooks gate domain and resource control operations.
- Passthrough → Xen core: integrates · IOMMU and device passthrough support is part of the hypervisor runtime.
- Console drivers → Xen core: feeds logs · Console and serial drivers provide host-visible output from the hypervisor.
- HVM loader → Public ABI: uses ABI · Guest firmware uses Xen-defined HVM interfaces and tables.
- Legacy BIOS → HVM loader: supports · Legacy BIOS/VGA payloads are composed into the HVM boot path.
- Stub domains → Public ABI: guest ABI · Stub domains communicate through Xen public interfaces and I/O protocols.
- xl CLI → HVM loader: launches · Toolstack selects firmware and boot components for guest startup.
- xl CLI → Stub domains: provisions · Toolstack can create isolated helper domains such as vTPM and device-model helpers.
- Docs → Public ABI: documents · Docs capture the externally visible ABI and protocol contracts.
- Build system → Xen core: builds · Top-level build drives hypervisor artifacts and per-architecture images.
- Build system → libxl: builds · Build system produces management libraries and tools.
- Automation → Tests: runs · CI and automation execute validation suites and analysis.
- Tests → Xen core: validates · Regression tests exercise hypervisor behavior and ABI stability.
- Tests → libxl: validates · Toolstack tests cover lifecycle, parsing, and control flows.