Skip to main content

Module svm

Module svm 

Source
Expand description

s9vm : AMD-V (SVM) hardware layer.

Counterpart of the VT-x activation in super. Provides, for AMD CPUs:

  • detection (detect) through CPUID and VM_CR;
  • per-CPU activation (activate_current_cpu): EFER.SVME, host state-save area (VM_HSAVE_PA) and the host extra-state page used by vmsave/vmload;
  • the world switch vmrun, written in assembly because it must preserve the host general registers, swap the guest ones and bracket the entry with clgi/stgi.

The pure parts live in super::svm_caps (capability decoding) and super::svm_vmcb (VMCB layout, exit decoding), both host-testable.

ยงStatus

Hardware layer of the AMD backend. init_probe only detects and logs: activation is never done implicitly, because setting EFER.SVME changes CPU behavior and must be an explicit decision of the caller. The vCPU that drives vmrun (VMCB setup, FPU/XCR0 switching, injection) is super::svm_vcpu, and the nested page tables are super::mmu::SecondLevel::new_npt.

Not yet done: wiring into the VM life cycle of super::vm (backend selection, device model, exit dispatch) and execution on real hardware.

Re-exportsยง

use core::sync::atomic::AtomicBool; ๐Ÿ”’
use core::sync::atomic::AtomicU32; ๐Ÿ”’
use core::sync::atomic::AtomicU64; ๐Ÿ”’
use core::sync::atomic::Ordering; ๐Ÿ”’
use super::caps::HwCaps; ๐Ÿ”’
use super::svm_caps; ๐Ÿ”’
use super::svm_caps::SvmCaps; ๐Ÿ”’
use super::svm_caps::SvmCapsError; ๐Ÿ”’
use super::InitError; ๐Ÿ”’
use crate::memory::frame::FrameAllocOptions; ๐Ÿ”’
use crate::memory::frame::FramePurpose; ๐Ÿ”’
use crate::memory::frame::PhysFrame; ๐Ÿ”’

Structsยง

GuestGprs
Guest general-purpose registers that vmrun does not keep in the VMCB.

Constantsยง

MAX_CPUS ๐Ÿ”’
Maximum number of tracked CPUs (aligned with percpu::MAX_CPUS).

Staticsยง

ACTIVATED ๐Ÿ”’
CPUs on which SVM is enabled.
ACTIVE_CPUS ๐Ÿ”’
Number of CPUs on which SVM is enabled.
HOST_VMCB ๐Ÿ”’
Per-CPU host extra-state page (vmsave/vmload target), physical address.
HSAVE ๐Ÿ”’
Per-CPU host state-save area (VM_HSAVE_PA), physical address.

Functionsยง

activate_current_cpu
Enables SVM on the current CPU.
active_cpu_count
Number of CPUs on which SVM is enabled.
alloc_zeroed_frame ๐Ÿ”’
Allocates one zeroed 4 KiB frame.
detect
Reads the raw SVM registers and decodes them. No CPU state is modified.
free_frame ๐Ÿ”’
host_vmcb_phys
Physical address of cpuโ€™s host extra-state page (vmsave/vmload), if SVM is activated there. Pass it as host_vmcb_pa to vmrun.
hsave_phys
Physical address of cpuโ€™s host state-save area (VM_HSAVE_PA), if SVM is activated there. The SVM counterpart of the VT-x activation region.
hw_caps
Synthetic HwCaps for an AMD CPU, or None when SVM is unusable.
init_probe
Probes AMD-V and logs the result. Never modifies CPU state.
is_activated
True if SVM is enabled on cpu.
s9vm_svm_vmrun ๐Ÿ”’ โš 
vmrunโš 
Enters the guest described by guest_vmcb_pa and returns on #VMEXIT.