Skip to main content

Module vm

Module vm 

Source
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Β§

GuestModule
One guest module/initrd range recorded for the boot-parameter block.
HostIommuSegment πŸ”’
One host-side mirror segment, collected while the registry lock is held.
LoadedImage
A guest image loaded into a world’s guest memory.
VcpuSlot
Logical vCPU: opaque identifier, APIC id and ABI register block.
VcpuSnapshot
Diagnostic snapshot of one logical vCPU.
World πŸ”’
Registered world: public record + lazy guest memory + logical vCPUs.
WorldMemory
Guest memory of a world.
WorldRecord
Public record of a world.
WorldStats
Cumulative execution counters of a world.
WorldTimingSnapshot
Compact, Copy view of a world’s cumulative timing aggregates.

EnumsΒ§

DiskError
Errors of load_disk.
RunError
vCPU execution errors.
VcpuRegistryError
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_2M is set.
IOMMU_MAX_MAP_BYTES
Maximum bytes covered by one SYS_VMM_MAP_IOMMU request (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 RAX and adds advance bytes to the guest RIP.
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 None if 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_ns for its vCPU tasks.
destroy_vcpu
Destroys a logical vCPU. Returns false if 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 (RUN refused 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 RUN request without waiting for the vCPU task.
request_run_inner πŸ”’
request_run_timeout
Requests execution of a vCPU and waits at most timeout_ns for the end of that RUN.
resume
Resumes a paused world.
run_completion
Diagnostic state of the last RUN of 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 false if 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 false if 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 RUN requests, 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 posted RUN to 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_ns for 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Β§

WorldMap πŸ”’
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.