Expand description
s9vm : registry of virtual worlds and guest memory.
This layer keeps the world registry (opaque identifier, name, owning silo,
state) and owns, for each world, its guest memory: pinned frames, GPA map
(GuestMap) and second-level translation tables (SecondLevelMemory).
Invariants:
- a guest frame is pinned for as long as the world lives (never swapped, never freed);
- destruction order frees the translation tables first, then the guest frames;
- no frame allocation is done while holding the registry lock: memory is taken out of the registry, manipulated, then put back in place.
No policy is decided here: access checks are done by the syscall layer (capabilities).
Re-exportsΒ§
use alloc::boxed::Box;πuse alloc::collections::BTreeMap;πuse alloc::sync::Arc;πuse alloc::vec::Vec;πuse core::sync::atomic::AtomicBool;πuse core::sync::atomic::AtomicU64;πuse core::sync::atomic::Ordering;πuse crate::hardware::iommu::DmaProt;πuse crate::hardware::iommu::Domain as HardwareIommuDomain;πuse crate::hardware::iommu::FaultPolicy;πuse crate::hardware::iommu::MappingKind;πuse crate::hardware::iommu::Sbdf;πuse crate::memory::frame::FrameAllocOptions;πuse crate::memory::frame::FramePurpose;πuse crate::memory::frame::PhysFrame;πuse crate::process::kthread;πuse crate::process::scheduler::ticks;πuse crate::process::sleep_current_task_ticks;πuse crate::process::TaskId;πuse crate::s9vm::apic::LocalApic;πuse crate::s9vm::backend::HwVcpu;πuse crate::s9vm::backend::VcpuOps;πuse crate::s9vm::caps::HwCaps;πuse crate::s9vm::emulate::interrupt_action;πuse crate::s9vm::emulate::interrupt_deliverable;πuse crate::s9vm::emulate::InterruptAction;πuse crate::s9vm::exit::ExitClass;πuse crate::s9vm::exitqueue::ExitQueue;πuse crate::s9vm::guest::FixedBits;πuse crate::s9vm::guest::GuestState;πuse crate::s9vm::image::Image;πuse crate::s9vm::image::Segment;πuse crate::s9vm::iommu::DeviceId;πuse crate::s9vm::iommu::DomainId;πuse crate::s9vm::iommu::IommuError;πuse crate::s9vm::iommu::IommuModel;πuse crate::s9vm::machine::Machine;πuse crate::s9vm::memmap::contiguous_2m_aligned;πuse crate::s9vm::memmap::perms_from_abi;πuse crate::s9vm::memmap::plan_map;πuse crate::s9vm::memmap::GuestMap;πuse crate::s9vm::memmap::MapError;πuse crate::s9vm::memmap::MAX_GPA;πuse crate::s9vm::mmu::Perms as MmuPerms;πuse crate::s9vm::mmu::PAGE_SIZE;πuse crate::s9vm::timing::ExitLatencyHistogram;πuse crate::s9vm::timing::WorldTiming;πuse crate::s9vm::timing::EXIT_LATENCY_BUCKETS;πuse crate::s9vm::vcpu::ExitInfo;πuse crate::s9vm::vcpu::SecondLevelMemory;πuse crate::s9vm::vcpu::VcpuError;πuse crate::s9vm::virtio_blk::VirtioBlk;πuse crate::sync::SpinLock;πuse crate::sync::WaitQueue;πuse strat9_abi::vmm::exit_kind;πuse strat9_abi::vmm::VmmExitEvent;πuse strat9_abi::vmm::VmmRegs;πuse strat9_abi::vmm::VMM_DISK_DEFAULT_BYTES;πuse strat9_abi::vmm::VMM_DISK_MAX_BYTES;πuse strat9_abi::vmm::VMM_DISK_SECTOR_SIZE;πuse strat9_abi::vmm::VMM_IOMMU_MAX_MAP_BYTES;π
StructsΒ§
- Guest
Module - One guest module/initrd range recorded for the boot-parameter block.
- Host
Iommu πSegment - One host-side mirror segment, collected while the registry lock is held.
- Loaded
Image - A guest image loaded into a worldβs guest memory.
- Vcpu
Slot - Logical vCPU: opaque identifier, APIC id and ABI register block.
- Vcpu
Snapshot - Diagnostic snapshot of one logical vCPU.
- World π
- Registered world: public record + lazy guest memory + logical vCPUs.
- World
Memory - Guest memory of a world.
- World
Record - Public record of a world.
- World
Stats - Cumulative execution counters of a world.
- World
Timing Snapshot - Compact,
Copyview of a worldβs cumulative timing aggregates.
EnumsΒ§
- Disk
Error - Errors of
load_disk. - RunError
- vCPU execution errors.
- Vcpu
Registry Error - vCPU layer errors.
- VmError
- Guest memory layer errors.
ConstantsΒ§
- ACPI_
GPA - Conventional guest-physical address of the firmware table image.
- CMDLINE_
MAX - Maximum length of the guest command line stored by
SYS_VMM_SET_CMDLINE. - DEFAULT_
QUOTA_ PAGES - Default guest page quota (1 GiB).
- IOMMU_
LARGE_ πPAGE_ SIZE - Size of a large IOMMU leaf (2 MiB) installed when
REQUIRE_2Mis set. - IOMMU_
MAX_ MAP_ BYTES - Maximum bytes covered by one
SYS_VMM_MAP_IOMMUrequest (1 GiB). - IOMMU_
PAGE_ πSIZE - Granularity of one IOMMU leaf installed by
SYS_VMM_MAP_IOMMU. - MAX_
CONSOLE_ OUTPUT - Maximum bytes of console output kept for the user side.
- MAX_
CONSOLE_ PENDING - Maximum bytes queued for the guest console at once.
- MAX_
FRAME_ SIZE - Maximum size of one injected network frame.
- MAX_
MODULES_ PER_ WORLD - Maximum number of guest modules/initrd ranges per world.
- MAX_
MODULE_ BYTES - Maximum size of one guest module copied through
SYS_VMM_LOAD_MODULE. - MAX_
NETWORK_ OUTPUT_ BYTES - Maximum number of guest-transmitted octets buffered for the network front-end.
- MAX_
NETWORK_ OUTPUT_ FRAMES - Maximum number of guest-transmitted frames buffered for the network front-end.
- MAX_
PENDING_ FRAMES - Maximum frames queued for the guest network device.
- MAX_
RESUMED_ πEXITS - Maximum number of βresumableβ exits handled internally before handing control back to policy (protection against an interrupt storm).
- MAX_
VCPUS_ PER_ WORLD - Maximum number of vCPUs per world (safety bound, before quotas).
- MAX_
WORLDS - Maximum number of simultaneous worlds (safety bound).
- NAME_
MAX - Maximum length of a name.
- RFLAGS_
IF π RFLAGS.IF: the guest is interruptible.- TIMING_
CLASS_ COUNT - Number of exit classes tracked by
WorldTimingSnapshot.
StaticsΒ§
- IOMMU_
BACKEND_ πNOTED - One-shot note when the host backend is not ready (feature disabled, no DMAR, or activation not validated). The software model keeps working.
- IOMMU_
HOST_ πDOMAINS - Host IOMMU domains, one per
(world, PCI function). - NEXT_ID π
- Next identifier (1 = first world; 0 is reserved for the global summary).
- NEXT_
VCPU π - Next vCPU identifier (global, never 0).
- WORLDS π
FunctionsΒ§
- alias_
memory - Maps a GPA range as an alias of an existing range in a world.
- alloc_
guest_ πframe - Allocates a guest RAM frame (zeroed, non-movable, pinned).
- classify_
region π - Classifies one world region for the guest boot-parameter memory map.
- cleanup_
vcpu π - Unloads the hardware context and signals the vCPU taskβs exit.
- clear
- Frees all entries (tests and kernel shutdown).
- cmdline
- Command line recorded for a world, with its authoritative length.
- complete_
exit - Completes an exit that the policy emulated: writes the result value to
the guest
RAXand addsadvancebytes to the guestRIP. - copy_
segment π - Copies the file-backed bytes of one segment and zeroes its BSS.
- count
- Number of worlds.
- cpuid_
policy - Current guest CPU description (CPUID policy) of a world.
- create
- Creates a world. Returns
Noneif the registry is full or if the name is empty. - create_
vcpu - Creates a logical vCPU in a world and the kernel task that drives it.
- create_
vcpu_ detached - Registers a logical vCPU without spawning a kernel task.
- debug_
dump - Logs an engine snapshot (kernel diagnostic).
- debug_
translate - Diagnostic detail for a world: mapped pages and translation of a GPA.
- destroy
- Destroys a world and frees its guest memory.
- destroy_
inner π - destroy_
timeout - Destroys a world, waiting at most
timeout_nsfor its vCPU tasks. - destroy_
vcpu - Destroys a logical vCPU. Returns
falseif it is unknown. - disk_
sectors - Capacity of the worldβs block device, in 512-byte sectors.
- ept_
access_ πname - Names the access type encoded in an EPT-violation qualification.
- event_
from_ πexit - execute_
one_ πrun - Executes a
RUN(at most one guest entry) in the vCPU task. - exit_
count - Number of pending events for a world.
- free_
guest_ πframes - Frees a list of guest frames.
- get
- Returns a record.
- get_
vcpu_ regs - Reads a vCPUβs register block.
- host_
iommu_ πdomain - Returns (creating it on first use) the host VT-d domain of one PCI function assigned to a world.
- inject_
irq - Schedules the injection of an external interrupt into a vCPU.
- inject_
nmi - Schedules the injection of an NMI into a vCPU (delivered at the next
RUN). - iommu_
dma_ πprot - Translates the model permissions into VT-d DMA rights.
- iommu_
domain π - Returns the IOMMU domain of a world, allocating it on first use.
- iommu_
host_ πready - True when the authoritative host backend is ready for mirroring.
- iommu_
map - Maps an IOVA range of a world to the host frames backing its guest memory.
- iommu_
mapped_ entries - Number of leaves installed in the device translation domain of a world.
- iommu_
translate - Translates one device-visible address of a world.
- iommu_
unmap - Removes an IOVA range of a world from its device translation domain.
- is_
paused - True if the world is paused.
- is_
resumable π - True if an exit can be resumed immediately by the kernel.
- list
- Lists the worlds (identifier order).
- load_
disk - Replaces the contents of a worldβs block device with a disk image.
- load_
image - Loads an ELF64 guest image into a worldβs guest memory.
- load_
module - Loads a guest module/initrd blob into a worldβs guest memory.
- locate_
slot π - Finds a world and the index of a vCPU in that world.
- map_
memory - Maps guest memory into a world.
- merged_
percentile π - Upper bound of the bucket that contains the
p-th sample of the union of every per-class histogram, in cycles. - mirror_
host_ πmap - Mirrors model segments into the host VT-d backend.
- mirror_
host_ πunmap - Removes a range from the host mirror of one device.
- modules
- Modules recorded for a world, in insertion order.
- new_
vcpu_ πslot - Creates the registry entry of a vCPU.
- note_
iommu_ πbackend_ unavailable - Records (once) that host mirroring is disabled.
- pause
- Pauses a world (
RUNrefused until resumed). - peek_
exit - Peeks at the oldest pending exit event of a world, without consuming it.
- pending_
irq - Pending deliverable interrupt vector for a vCPU, if any.
- pop_
exit - Dequeues the next event of a world.
- push_
console_ input - Queues console input for a world.
- push_
console_ πoutput - Appends bytes to the bounded console-output queue of a world.
- push_
exit - Queues an event in a worldβs queue.
- push_
network_ frame - Queues a frame for the network device of a world.
- read_
console_ output - Drains console output of a world into
out. - read_
disk - Reads sectors from the worldβs block device into
out. - read_
network_ frame - Pops one frame transmitted by the guest and queued for the network
front-end. Returns
Ok(None)when the queue is empty. - regs_
from_ πguest - release_
host_ πiommu_ domains - Releases every host VT-d domain owned by a world.
- remove_
vcpu π - Removes a vCPU from the registry without waiting for a task.
- request_
run - Requests execution of a vCPU and blocks the caller until the end of
that
RUN(at most one policy exit). - request_
run_ async - Posts a
RUNrequest without waiting for the vCPU task. - request_
run_ πinner - request_
run_ timeout - Requests execution of a vCPU and waits at most
timeout_nsfor the end of thatRUN. - resume
- Resumes a paused world.
- run_
completion - Diagnostic state of the last
RUNof a vCPU. - run_
vcpu - Runs a vCPU until the next βpolicyβ exit and queues the corresponding event in the worldβs queue.
- second_
level_ pointer - Returns the second-level translation pointer (EPTP) of a world.
- set_
cmdline - Stores the guest kernel command line for a world.
- set_
console_ output - Replaces the console-output snapshot of a world.
- set_
cpuid_ policy - Sets the guest CPU description (CPUID policy) of a world.
- set_
state - Updates a worldβs state. Returns
falseif the world is unknown. - set_
vcpu_ count - Updates a worldβs vCPU count.
- set_
vcpu_ regs - Writes a vCPUβs register block.
- stats
- Cumulative execution counters of a world.
- store_
machine - Puts the device model back into its world. Returns
falseif it vanished. - take_
console_ input - Takes the console input queued for a world.
- take_
machine - Takes the device model out of a world.
- timing
- Read-only timing snapshot of a world.
- timing_
snapshot π - Builds a compact snapshot from the two per-world aggregates.
- total_
stats - Cumulative execution counters of every world.
- validate_
iommu_ πrange - Validates the shape of an IOMMU map/unmap request.
- vcpu_
count - Number of logical vCPUs of a world.
- vcpu_
snapshots - Diagnostic snapshot of every vCPU of a world.
- vcpu_
task_ πmain - Body of a vCPUβs kernel task: waits for
RUNrequests, runs the guest until the next policy exit, publishes the event then waits again. - vcpu_
world_ πmut - Finds the world owning a vCPU (excluding closing worlds).
- wait_
exit - Waits until at least one exit event is available in the vCPUβs world, or until the timeout expires.
- wait_
run_ complete - Waits, at most
timeout_ns, for a previously postedRUNto complete. - wait_
vcpu_ πexited - Waits for a vCPUβs kernel task to finish (or for the vCPU to disappear from the registry).
- wait_
vcpu_ πexited_ timeout - Waits at most
timeout_nsfor a vCPUβs kernel task to finish. - write_
acpi - Writes the firmware description tables of a world at
base_gpa. - write_
boot_ info - Writes the guest boot-information page of a world at
gpa. - write_
boot_ params - Writes the guest boot-parameter block at
gpa. - write_
disk - Writes sectors to the worldβs block device from
data.
Type AliasesΒ§
- World
Map π - Global world registry. Registry type: worlds are boxed so that creating or destroying one does not move the (large) World value through the kernel stack. The early bootstrap runs on an 8 KiB stack; a stack-sized move there is a page fault.