pub struct SvmVcpu {}Expand description
An AMD-V virtual CPU.
Fields§
§vmcb_frame: PhysFrame§msrpm: PhysFrame§iopm: PhysFrame§regs: GuestGprs§guest: GuestState§fpu: FpuSwitch§guest_dr: [u64; 4]Guest DR0-DR3, switched around every entry.
seen_gen: u64Flush generation of the ASID this vCPU has already honoured.
msr: MsrModelPer-vCPU shadow of the modelled MSRs (see Self::sync_msr_state).
ncr3: u64Root of the nested page table (nCR3).
asid: u32§flush_by_asid: bool§last_cpu: Option<usize>CPU of the previous entry; a change (or none) forces a TLB flush.
exit: Option<SvmExit>§entered: boolImplementations§
Source§impl SvmVcpu
impl SvmVcpu
Sourcepub fn new(ncr3: u64, asid: u32) -> Result<Self, SvmVcpuError>
pub fn new(ncr3: u64, asid: u32) -> Result<Self, SvmVcpuError>
Creates a vCPU backed by the nested page table rooted at ncr3.
asid is the guest’s TLB tag: non-zero (0 is the host’s) and below the
CPU’s ASID count, otherwise SvmVcpuError::InvalidAsid. It must be
unique among the virtual machines that may run on the same CPU. vCPUs
of one machine may share it together with the NPT: the entry path
flushes whenever a different VMCB was the last one run on the CPU.
fn vmcb_phys(&self) -> u64
fn vmcb(&self) -> &Vmcb
fn vmcb_mut(&mut self) -> &mut Vmcb
Sourcepub fn configure(&mut self, guest: &GuestState)
pub fn configure(&mut self, guest: &GuestState)
Loads a complete guest state: segments, control registers, rip, and
the general registers.
Sourcepub fn nested_cr3(&self) -> u64
pub fn nested_cr3(&self) -> u64
Nested page table root (nCR3) of this vCPU.
Sourcepub fn paging_enabled(&self) -> bool
pub fn paging_enabled(&self) -> bool
True if the guest runs with paging enabled.
Sourcepub fn interruptibility(&self) -> u32
pub fn interruptibility(&self) -> u32
Interrupt-shadow state in the VT-x interruptibility encoding (bit 0 = blocking by STI / MOV SS).
Sourcepub fn sync_msr_state(&mut self)
pub fn sync_msr_state(&mut self)
Pushes the MSR shadows into the VMCB.
Must be called after a replayed wrmsr whose effect is Efer, Pat,
SyscallTargets, SegmentBase or State, before the next entry. Unlike
VT-x, the syscall targets and KERNEL_GS_BASE are real VMCB state here:
the guest’s syscall/swapgs use them natively.
Sourcepub fn diagnostics(&self) -> String
pub fn diagnostics(&self) -> String
One-line dump of the guest state, for logs.
Sourcepub fn guest(&self) -> &GuestState
pub fn guest(&self) -> &GuestState
The guest state as of the last exit.
Sourcepub unsafe fn run(&mut self) -> Result<SvmExit, SvmVcpuError>
pub unsafe fn run(&mut self) -> Result<SvmExit, SvmVcpuError>
Enters the guest and returns on the next #VMEXIT.
Interrupts are disabled for the whole entry, so the vCPU cannot migrate
between CPUs mid-sequence. A host interrupt that arrives during the
guest run causes an INTR exit and is taken once interrupts are
re-enabled when this function returns.
§Safety
SVM must be activated on the current CPU (svm::activate_current_cpu),
and the NPT root given to Self::new must stay valid.
Sourceunsafe fn run_irqs_off(&mut self) -> Result<SvmExit, SvmVcpuError>
unsafe fn run_irqs_off(&mut self) -> Result<SvmExit, SvmVcpuError>
fn read_exit(&mut self) -> SvmExit
Sourcepub fn guest_gpr(&self, register: u8) -> u64
pub fn guest_gpr(&self, register: u8) -> u64
Reads a guest general-purpose register (x86 encoding order: 0 = RAX,
1 = RCX, 2 = RDX, 3 = RBX, 4 = RSP, 5 = RBP, 6 = RSI,
7 = RDI, then 8..=15 = R8..R15). Out-of-range indices read 0.
Sourcepub fn set_guest_gpr(&mut self, register: u8, value: u64)
pub fn set_guest_gpr(&mut self, register: u8, value: u64)
Writes a guest general-purpose register (encoding order, see
Self::guest_gpr). Out-of-range indices are ignored.
Sourcepub fn set_guest_rip(&mut self, rip: u64)
pub fn set_guest_rip(&mut self, rip: u64)
Sets the guest instruction pointer.
Sourcepub fn advance_rip(&mut self, bytes: u64)
pub fn advance_rip(&mut self, bytes: u64)
Advances the guest rip past the instruction that caused an exit.
Sourcepub fn advance_rip_from_exit(&mut self) -> bool
pub fn advance_rip_from_exit(&mut self) -> bool
Advances rip using the CPU-reported NEXT_RIP of the last exit.
Returns false when the CPU did not provide it (no NRIP_SAVE): the
caller must then decode the instruction length itself.
Sourcepub fn request_tlb_flush(&self)
pub fn request_tlb_flush(&self)
Invalidates the guest TLB translations of this vCPU’s ASID on every CPU.
Call it after changing or removing a mapping of the NPT. The flush
generation of the ASID is bumped, so every vCPU sharing it flushes at
its next entry; CPUs currently running a guest with this ASID are kicked
with a reschedule IPI so they exit (the host interrupt makes the guest
leave with an INTR exit) and re-enter through that path.
Sourcefn event_pending(&self) -> bool
fn event_pending(&self) -> bool
True if an event is already queued for the next entry.
Sourcepub fn inject_interrupt(&mut self, vector: u8) -> Result<(), SvmVcpuError>
pub fn inject_interrupt(&mut self, vector: u8) -> Result<(), SvmVcpuError>
Queues an external interrupt for the next entry.
Rejected when the guest cannot take it now (IF clear, interrupt
shadow) or when another event is already queued; the caller should then
arm Self::set_interrupt_window_exiting.
Sourcepub fn inject_nmi(&mut self) -> Result<(), SvmVcpuError>
pub fn inject_nmi(&mut self) -> Result<(), SvmVcpuError>
Queues an NMI for the next entry.
Sourcepub fn inject_exception(
&mut self,
vector: u8,
error_code: Option<u32>,
) -> Result<(), SvmVcpuError>
pub fn inject_exception( &mut self, vector: u8, error_code: Option<u32>, ) -> Result<(), SvmVcpuError>
Queues a hardware exception (with or without error code).
Sourcepub fn set_interrupt_window_exiting(&mut self, enabled: bool)
pub fn set_interrupt_window_exiting(&mut self, enabled: bool)
Arms or disarms the interrupt-window exit: the hardware exits (class
ExitClass::InterruptWindow) as soon as the guest can take an
interrupt. One-shot: it disarms itself when it fires.
Sourcepub fn interrupt_window_armed(&self) -> bool
pub fn interrupt_window_armed(&self) -> bool
True if the interrupt-window exit is armed.
Sourcepub fn guest_xcr0(&self) -> u64
pub fn guest_xcr0(&self) -> u64
XCR0 as seen by the guest.
Sourcepub fn emulate_xsetbv(&mut self) -> Result<(), SvmVcpuError>
pub fn emulate_xsetbv(&mut self) -> Result<(), SvmVcpuError>
Emulates the guest xsetbv that caused the last exit, then advances
rip (xsetbv is always 3 bytes).
Returns SvmVcpuError::InvalidXcr0 without touching any state when
the instruction must fault (wrong XCR index, CPL != 0, invalid value):
the caller injects #GP(0).
Trait Implementations§
Auto Trait Implementations§
impl Forget for SvmVcpu
impl Freeze for SvmVcpu
impl Move for SvmVcpu
impl RefUnwindSafe for SvmVcpu
impl Send for SvmVcpu
impl Sync for SvmVcpu
impl Unpin for SvmVcpu
impl UnsafeUnpin for SvmVcpu
impl UnwindSafe for SvmVcpu
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more