Skip to main content

Module backend

Module backend 

Source
Expand description

s9vm : hardware backend abstraction (Intel VT-x or AMD-V).

The world registry, the run loop and the device model of s9vm drive a vCPU through the API of Vcpu (VT-x). HwVcpu wraps either that vCPU or an SvmVcpu behind the same method names, so the callers stay written once. The Vmx variant forwards every call unchanged: the Intel path behaves as if the wrapper were not there.

For AMD, exits are converted to the VT-x shape (super::svm_exit) and the few VT-x-only concepts are emulated or made no-ops:

VT-x conceptAMD-V counterpart
load/clear/configure_host (VMCS currency)no-op: a VMCB is plain memory
external-interrupt exitingalways on (INTR intercept)
preemption timeremulated from the TSC on INTR exits (SLICE_DIVISOR)
interrupt-window exitingVINTR intercept + virtual interrupt

Re-exportsยง

use alloc::string::String; ๐Ÿ”’
use core::sync::atomic::AtomicU32; ๐Ÿ”’
use core::sync::atomic::Ordering; ๐Ÿ”’
use crate::s9vm::caps::HwCaps; ๐Ÿ”’
use crate::s9vm::exit; ๐Ÿ”’
use crate::s9vm::exit::ExitReason; ๐Ÿ”’
use crate::s9vm::guest::GuestState; ๐Ÿ”’
use crate::s9vm::msr::MsrModel; ๐Ÿ”’
use crate::s9vm::svm; ๐Ÿ”’
use crate::s9vm::svm_exit; ๐Ÿ”’
use crate::s9vm::svm_vcpu::SvmVcpu; ๐Ÿ”’
use crate::s9vm::svm_vcpu::SvmVcpuError; ๐Ÿ”’
use crate::s9vm::svm_vmcb::exit_code; ๐Ÿ”’
use crate::s9vm::vcpu::ExitInfo; ๐Ÿ”’
use crate::s9vm::vcpu::Vcpu; ๐Ÿ”’
use crate::s9vm::vcpu::VcpuError; ๐Ÿ”’
use crate::s9vm::Backend; ๐Ÿ”’

Structsยง

SvmBackendVcpu
An AMD vCPU plus the state of its emulated preemption timer.

Enumsยง

HwVcpu
A virtual CPU of either backend.

Constantsยง

FALLBACK_TSC_HZ ๐Ÿ”’
TSC frequency assumed when none was published (2 GHz).
SLICE_DIVISOR
Fraction of a second of guest time between two emulated preemption-timer exits on AMD (1 / SLICE_DIVISOR s). VT-xโ€™s default slice is of the same order (roughly 0.1-0.5 s).

Staticsยง

NEXT_ASID ๐Ÿ”’
Next ASID to hand out; wraps within the CPUโ€™s range.

Traitsยง

VcpuOps
The operations the device model needs from a vCPU, whatever the backend.

Functionsยง

allocate_asid ๐Ÿ”’
Allocates a guest ASID in 1..=max_guest_asid.
slice_expired ๐Ÿ”’
True when the emulated slice (1 / SLICE_DIVISOR s of TSC) has elapsed.