Skip to main content

Module s9vm

Module s9vm 

Source
Expand description

Bare-metal virtualization s9vm (kernel mechanism). s9vm : bare-metal virtualization system of strat9-os.

ยงPrinciple

Bedrock provides the mechanism (per-CPU VT-x activation, hardware control block, second-level translation, exit reception, event injection), the policy silo (to come) will decide the life cycle of machines, device model, and interrupt routing.

ยงLayout

ModuleContentHost-testable
capsVT-x capability MSR decodingyes
controlfield encoding, control block primitivesyes (compiles)
mmusecond-level translation tablesyes
exitexit decoding and classificationyes
svm_capsAMD-V capability decodingyes
svm_vmcbAMD VMCB layout, exit decodingyes
svm_stateGuestState <-> VMCB translation, permission mapsyes
svmAMD-V activation and vmrun world switchno
svm_vcpuAMD-V vCPU (VMCB, FPU switch, injection)no

ยงInitialization cycle

  1. very early detection (CPUID + MSR), without side effects;
  2. per-CPU activation when the frame allocator is ready (component bootstrap): CR4.VMXE, 4 KiB activation region, activation;
  3. vCPUs will be created later by the policy layer.

The absence of VT-x is never fatal: the kernel boots normally and logs virtualisation inactive.

Re-exportsยง

use core::sync::atomic::AtomicBool; ๐Ÿ”’
use core::sync::atomic::AtomicU32; ๐Ÿ”’
use core::sync::atomic::AtomicU64; ๐Ÿ”’
use core::sync::atomic::AtomicU8; ๐Ÿ”’
use core::sync::atomic::Ordering; ๐Ÿ”’
use caps::CapsError; ๐Ÿ”’
use caps::HwCaps; ๐Ÿ”’
use caps::MsrSnapshot; ๐Ÿ”’

Modulesยง

acpi
s9vm : static ACPI tables presented to guests.
apic
s9vm : pure model of the guest local APIC (xAPIC / x2APIC).
backend
s9vm : hardware backend abstraction (Intel VT-x or AMD-V).
bios
s9vm : pure PC BIOS service model for a real-mode DOS-class guest.
biosrom
s9vm : real-mode BIOS ROM stubs, low-memory layout and demo boot image.
bootinfo
s9vm : guest boot information page.
bootparams
s9vm : guest boot parameters (firmware hand-off block).
bzimage
s9vm : boot-protocol image (โ€œbzImageโ€) parser and load plan.
caps
s9vm : decoding of hardware virtualization capabilities (Intel VT-x).
control
s9vm : processor control block (guest/host state structure).
cpuid
s9vm : guest CPU description (CPUID model).
decode
s9vm : minimal x86-64 instruction decoder for exit emulation.
dma
8237 DMA controller (master and slave register files).
dosboot
s9vm : DOS-class real-mode guest runner.
emulate
s9vm : in-kernel emulation of a minimal guest device set.
exit
s9vm : decoding of hardware exits (VM-exits).
exitqueue
s9vm : bounded exit event queue.
fdc
82077AA-compatible floppy disk controller and 1.44 MiB drive model.
firmware
s9vm : generic guest-firmware images (SeaBIOS and other BIOS ROMs).
fpu
s9vm : host/guest FPU and SIMD state switching around a guest entry.
fwcfg
QEMU fw_cfg firmware-configuration interface (legacy I/O port mode).
guest
s9vm : guest state and validation before entry.
guestcode
s9vm : machine-code payloads used by the host-side smoke tests.
guestprog
s9vm : guest program builder (tiny assembler for in-kernel test payloads).
guestpt
s9vm : guest page tables for a 64-bit guest entry.
hpet
s9vm : pure model of the guest High Precision Event Timer (HPET).
image
s9vm : guest image format and loading plan.
ioapic
s9vm : pure model of the guest I/O APIC.
iommu
s9vm : device address translation (IOMMU model).
keyboard
8042 keyboard controller model (ports 0x60/0x64).
keyfeed
Host keystrokes waiting to be typed into a DOS guest.
launch
s9vm : guest entry/exit trampoline.
linuxboot
s9vm : guest-physical layout of a 64-bit boot-protocol guest.
machine
s9vm : kernel bridge between a vCPU and the pure emulation layer.
memmap
s9vm : guest memory map (GPA).
mmu
s9vm : second-level translation (hardware page tables).
msr
s9vm : modelled guest MSRs (interception policy and shadow state).
pci
s9vm : guest-visible PCI host bridge (pure model).
pic
s9vm : pure model of the guest 8259A programmable interrupt controller.
pit
s9vm : pure model of the Intel 8254/8253 programmable interval timer.
rtc
s9vm : MC146818-compatible CMOS real-time clock model for guests.
selftest
s9vm : hardware smoke test of the engine.
smp
s9vm : guest SMP bring-up model.
svm
s9vm : AMD-V (SVM) hardware layer.
svm_caps
s9vm : decoding of AMD SVM capabilities.
svm_exit
s9vm : translation of AMD #VMEXIT information to the VT-x exit format.
svm_state
s9vm : translation between the VT-x style GuestState and an AMD VMCB.
svm_vcpu
s9vm : AMD-V vCPU.
svm_vmcb
s9vm : AMD VMCB layout, intercepts and #VMEXIT decoding.
system
Chipset system-control ports (0x92 and 0xCF9).
timing
s9vm : pure timing and exit-latency measurement.
tsc
s9vm : time-stamp counter frequency model.
uart
s9vm : 16550A-compatible UART device (pure model, COM1).
vcpu
s9vm : vCPU: state, control block configuration, entry/exit.
vga
Minimal VGA register model (CRTC, sequencer, graphics, attribute, status).
virtio
s9vm : virtio split-queue core (pure).
virtio_blk
s9vm : virtio block device (pure model, MMIO transport).
virtio_console
s9vm : virtio console device (pure model, MMIO transport).
virtio_net
s9vm : virtio network device (pure model, MMIO transport).
vm
s9vm : registry of virtual worlds and guest memory.
zeropage
s9vm : x86 boot-protocol zero page (struct boot_params) builder.

Enumsยง

Backend
Hardware virtualization backend selected at boot.
InitError
Initialization errors.

Constantsยง

CR4_VMXE ๐Ÿ”’
CR4.VMXE bit (hardware extension enable).
MAX_CPUS ๐Ÿ”’
Maximum number of tracked CPUs (aligned with percpu::MAX_CPUS).
S9VM_ENABLED
Global compile/behavior switch.

Staticsยง

ACTIVATED ๐Ÿ”’
CPU whose activation succeeded.
ACTIVE_CPUS ๐Ÿ”’
Number of activated CPUs.
BACKEND ๐Ÿ”’
Selected backend (Backend as u8).
CAPS_VALID ๐Ÿ”’
Capabilities detected once and for all (0 = not detected).
REGIONS ๐Ÿ”’
Per-CPU activation regions (physical address, 0 = not activated).

Functionsยง

activate_current_cpu
Attempts to activate VT-x on the current CPU.
activate_current_cpu_vmx ๐Ÿ”’
Intel VT-x activation of the current CPU (see activate_current_cpu).
activation_region
Physical address of a CPUโ€™s activation region, if activated.
active_cpu_count
Number of CPUs on which VT-x is active.
backend
The hardware virtualization backend in use.
detect
Detects hardware capabilities of the active backend. Does not modify any CPU state.
detect_vmx
Detects Intel VT-x capabilities only. Does not modify any CPU state.
detected
True if the capabilities were detected at boot.
enable_virtualization ๐Ÿ”’ โš 
Executes the hardware activation (vmxon) on a pre-initialized region.
init
Initialization called by the boot component.
init_svm ๐Ÿ”’
AMD-V initialization: detect, activate the boot CPU, select the backend.
publish_tsc_frequency ๐Ÿ”’
Publishes the host TSC frequency in the tsc cache, once.
read_cr4 ๐Ÿ”’
Reads CR4.
read_msr ๐Ÿ”’
Reads an MSR through the architecture layer.
unavailable_reason
Explains why VT-x is unavailable, for logs and diagnostics.
write_cr4 ๐Ÿ”’ โš 
Writes CR4.
write_msr ๐Ÿ”’
Writes an MSR through the architecture layer.