# nxp-imx/imx-xen architecture

> Architecture diagram of the GitHub repository nxp-imx/imx-xen, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nxp-imx/imx-xen
- Repository: https://github.com/nxp-imx/imx-xen

## Overview

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: [`xen/common`](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/xen/common) (Xen core), [`tools/libs/light`](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/tools/libs/light) (libxl), [`xen/include/public`](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/xen/include/public) (Public ABI), [`tools/xl`](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/tools/xl) (xl CLI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_hypervisor["Hypervisor"]
  node_n_xen_core["Xen core<br/>hypervisor common"]
  node_n_x86["x86 port<br/>arch port"]
  node_n_arm["ARM port<br/>arch port"]
  node_n_ppc["PPC port<br/>arch port"]
  node_n_riscv["RISC-V port<br/>arch port"]
  node_n_xsm["XSM policy<br/>security module"]
  node_n_passthrough["Passthrough<br/>iommu/drivers"]
  node_n_char["Console drivers<br/>device drivers"]
end

subgraph group_g_tools["Toolstack"]
  node_n_libxl["libxl<br/>management library"]
  node_n_libxc["libxc<br/>control library"]
  node_n_xenstore_lib["xenstore libs<br/>coordination library"]
  node_n_xl["xl CLI<br/>admin cli"]
  node_n_xenstored_c["xenstored<br/>daemon"]
  node_n_xenstored_ocaml["oxenstored<br/>daemon"]
  node_n_hotplug["Hotplug<br/>host scripts"]
  node_n_bindings["Bindings"]
end

subgraph group_g_firmware["Boot & firmware"]
  node_n_hvmloader["HVM loader<br/>firmware loader"]
  node_n_legacy_fw["Legacy BIOS<br/>firmware payloads"]
  node_n_stubdom["Stub domains<br/>isolated domains"]
end

subgraph group_g_contracts["Contracts"]
  node_n_public["Public ABI<br/>stable headers"]
  node_n_tools_include["Tool headers<br/>host headers"]
end

subgraph group_g_support["Build & quality"]
  node_n_docs["Docs"]
  node_n_build["Build system<br/>build infra"]
  node_n_automation["Automation<br/>ci/test infra"]
  node_n_tests["Tests<br/>validation"]
end

node_n_xl -->|"drives"| node_n_libxl
node_n_libxl -->|"calls"| node_n_libxc
node_n_libxl -->|"uses"| node_n_xenstore_lib
node_n_xl -->|"coordinates"| node_n_xenstored_c
node_n_xenstored_c -.->|"control path"| node_n_xen_core
node_n_xenstored_ocaml -.->|"alt impl"| node_n_xenstored_c
node_n_hotplug -->|"reacts to"| node_n_xenstored_c
node_n_bindings -->|"wraps"| node_n_libxl
node_n_bindings -->|"wraps"| node_n_libxc
node_n_xen_core -->|"ABI"| node_n_public
node_n_libxc -->|"ABI"| node_n_public
node_n_xenstore_lib -->|"protocols"| node_n_public
node_n_x86 -->|"specializes"| node_n_xen_core
node_n_arm -->|"specializes"| node_n_xen_core
node_n_ppc -->|"specializes"| node_n_xen_core
node_n_riscv -->|"specializes"| node_n_xen_core
node_n_xsm -->|"enforces"| node_n_xen_core
node_n_passthrough -->|"integrates"| node_n_xen_core
node_n_char -->|"feeds logs"| node_n_xen_core
node_n_hvmloader -->|"uses ABI"| node_n_public
node_n_legacy_fw -->|"supports"| node_n_hvmloader
node_n_stubdom -->|"guest ABI"| node_n_public
node_n_xl -->|"launches"| node_n_hvmloader
node_n_xl -->|"provisions"| node_n_stubdom
node_n_docs -->|"documents"| node_n_public
node_n_build -->|"builds"| node_n_xen_core
node_n_build -->|"builds"| node_n_libxl
node_n_automation -->|"runs"| node_n_tests
node_n_tests -->|"validates"| node_n_xen_core
node_n_tests -->|"validates"| node_n_libxl

click node_n_xen_core "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/xen/common"
click node_n_x86 "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/xen/arch/x86"
click node_n_arm "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/xen/arch/arm"
click node_n_ppc "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/xen/arch/ppc"
click node_n_riscv "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/xen/arch/riscv"
click node_n_xsm "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/xen/xsm"
click node_n_passthrough "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/xen/drivers/passthrough"
click node_n_char "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/xen/drivers/char"
click node_n_libxl "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/tools/libs/light"
click node_n_libxc "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/tools/libs/ctrl"
click node_n_xenstore_lib "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/tools/libs/store"
click node_n_xl "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/tools/xl"
click node_n_xenstored_c "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/tools/xenstored"
click node_n_xenstored_ocaml "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/tools/ocaml/xenstored"
click node_n_hotplug "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/tools/hotplug"
click node_n_bindings "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/tools/python"
click node_n_hvmloader "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/tools/firmware/hvmloader"
click node_n_legacy_fw "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/tools/firmware/rombios"
click node_n_stubdom "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/stubdom"
click node_n_public "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/xen/include/public"
click node_n_tools_include "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/tools/include"
click node_n_docs "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/docs"
click node_n_build "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/Makefile"
click node_n_automation "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/automation"
click node_n_tests "https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/xen/test"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_xen_core,node_n_x86,node_n_arm,node_n_ppc,node_n_riscv,node_n_xsm,node_n_passthrough,node_n_char toneBlue
class node_n_libxl,node_n_libxc,node_n_xenstore_lib,node_n_xl,node_n_xenstored_c,node_n_xenstored_ocaml,node_n_hotplug,node_n_bindings toneAmber
class node_n_hvmloader,node_n_legacy_fw,node_n_stubdom toneMint
class node_n_public,node_n_tools_include toneRose
class node_n_docs,node_n_build,node_n_automation,node_n_tests toneIndigo
```

## Components

### Hypervisor

Privileged runtime and architecture ports.

- [Xen core](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/xen/common): hypervisor common · Cross-architecture VM control, scheduling, memory, timers, tracing, and core services. · `xen/common`
- [x86 port](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/xen/arch/x86): arch port · x86 boot, traps, HVM/PV handling, MMU, interrupt, and platform-specific virtualization plumbing. · `xen/arch/x86`
- [ARM port](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/xen/arch/arm): arch port · ARM/arm64 boot, MMU, GIC, PSCI, device tree, and virtualization support. · `xen/arch/arm`
- [PPC port](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/xen/arch/ppc): arch port · PowerPC boot, MMU, exceptions, and platform integration. · `xen/arch/ppc`
- [RISC-V port](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/xen/arch/riscv): arch port · RISC-V boot, interrupt controller, MMU, SBI, and virtualization plumbing. · `xen/arch/riscv`
- [XSM policy](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/xen/xsm): security module · Hypervisor security policy enforcement with FLASK-style authorization and dummy backend. · `xen/xsm`
- [Passthrough](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/xen/drivers/passthrough): iommu/drivers · IOMMU, PCI, MSI, and device passthrough support inside the hypervisor. · `xen/drivers/passthrough`
- [Console drivers](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/xen/drivers/char): device drivers · Serial, console, and debug output paths for host and early boot. · `xen/drivers/char`

### Toolstack

Userspace management plane, daemons, libraries, and CLIs.

- [libxl](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/tools/libs/light): management library · High-level domain lifecycle, device, migration, and orchestration API. · `tools/libs/light`
- [libxc](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/tools/libs/ctrl): control library · Low-level hypervisor control library used by management tools and bindings. · `tools/libs/ctrl`
- [xenstore libs](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/tools/libs/store): coordination library · Client libraries for xenstore and related event/grant/foreign-memory interfaces. · `tools/libs/store`
- [xl CLI](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/tools/xl): admin cli · Main command-line frontend for domain creation, configuration, and control. · `tools/xl`
- [xenstored](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/tools/xenstored): daemon · C xenstore daemon providing configuration and state coordination. · `tools/xenstored`
- [oxenstored](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/tools/ocaml/xenstored): daemon · Ocaml xenstore implementation used as an alternative daemon path. · `tools/ocaml/xenstored`
- [Hotplug](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/tools/hotplug): host scripts · Host-side scripts and service units for device attach, console, and domain lifecycle events. · `tools/hotplug`
- [Bindings](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/tools/python): language 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](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/tools/firmware/hvmloader): firmware loader · Firmware and boot-time setup for HVM guests, including BIOS tables and device init. · `tools/firmware/hvmloader`
- [Legacy BIOS](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/tools/firmware/rombios): firmware payloads · ROM BIOS, VGA BIOS, and network boot payloads for legacy guest boot flows. · `tools/firmware/rombios`
- [Stub domains](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/stubdom): isolated domains · Minimal service domains such as vTPM and isolated device-model helpers. · `stubdom`

### Contracts

Stable public headers and protocol definitions.

- [Public ABI](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/xen/include/public): stable headers · Guest-facing hypercall, event-channel, grant-table, HVM, and I/O protocol definitions. · `xen/include/public`
- [Tool headers](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/tools/include): host headers · Host-side APIs and compatibility headers shared by libraries, daemons, and tools. · `tools/include`

### Build & quality

Build system, docs, automation, and validation.

- [Docs](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/docs): contracts/docs · Architecture, ABI, protocol, and operational documentation. · `docs`
- [Build system](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/Makefile): build infra · Configure, makefiles, per-platform rules, and generated build metadata. · `Makefile`
- [Automation](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/automation): ci/test infra · CI pipelines, containers, analysis scripts, fuzzing, and regression automation. · `automation`
- [Tests](https://github.com/nxp-imx/imx-xen/tree/lf-6.18.20_2.0.0/xen/test): validation · Hypervisor and toolstack regression tests and emulator-focused validation. · `xen/test`

## Connections

- 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.
