Trait arch::VcpuArch

source ·
pub trait VcpuArch: Vcpu {
Show 30 methods // Required methods fn set_interrupt_window_requested(&self, requested: bool); fn ready_for_interrupt(&self) -> bool; fn interrupt(&self, irq: u8) -> Result<(), Error>; fn inject_nmi(&self) -> Result<(), Error>; fn get_regs(&self) -> Result<Regs, Error>; fn set_regs(&self, regs: &Regs) -> Result<(), Error>; fn get_sregs(&self) -> Result<Sregs, Error>; fn set_sregs(&self, sregs: &Sregs) -> Result<(), Error>; fn get_fpu(&self) -> Result<Fpu, Error>; fn set_fpu(&self, fpu: &Fpu) -> Result<(), Error>; fn get_debugregs(&self) -> Result<DebugRegs, Error>; fn set_debugregs(&self, debugregs: &DebugRegs) -> Result<(), Error>; fn get_xcrs(&self) -> Result<BTreeMap<u32, u64>, Error>; fn set_xcr(&self, xcr: u32, value: u64) -> Result<(), Error>; fn get_xsave(&self) -> Result<Xsave, Error>; fn set_xsave(&self, xsave: &Xsave) -> Result<(), Error>; fn get_interrupt_state(&self) -> Result<Value, Error>; fn set_interrupt_state(&self, data: Value) -> Result<(), Error>; fn get_msr(&self, msr_index: u32) -> Result<u64, Error>; fn get_all_msrs(&self) -> Result<BTreeMap<u32, u64>, Error>; fn set_msr(&self, msr_index: u32, value: u64) -> Result<(), Error>; fn set_cpuid(&self, cpuid: &CpuId) -> Result<(), Error>; fn set_guest_debug( &self, addrs: &[GuestAddress], enable_singlestep: bool ) -> Result<(), Error>; fn handle_cpuid(&mut self, entry: &CpuIdEntry) -> Result<(), Error>; fn restore_timekeeping( &self, host_tsc_reference_moment: u64, tsc_offset: u64 ) -> Result<(), Error>; // Provided methods fn get_tsc_offset(&self) -> Result<u64, Error> { ... } fn set_tsc_offset(&self, offset: u64) -> Result<(), Error> { ... } fn set_tsc_value(&self, value: u64) -> Result<(), Error> { ... } fn snapshot(&self) -> Result<VcpuSnapshot, Error> { ... } fn restore( &mut self, snapshot: &VcpuSnapshot, host_tsc_reference_moment: u64 ) -> Result<(), Error> { ... }
}
Expand description

A wrapper around creating and using a VCPU on x86_64.

Required Methods§

source

fn set_interrupt_window_requested(&self, requested: bool)

Sets or clears the flag that requests the VCPU to exit when it becomes possible to inject interrupts into the guest.

source

fn ready_for_interrupt(&self) -> bool

Checks if we can inject an interrupt into the VCPU.

source

fn interrupt(&self, irq: u8) -> Result<(), Error>

Injects interrupt vector irq into the VCPU.

This function should only be called when Self::ready_for_interrupt returns true. Otherwise the interrupt injection may fail or the next VCPU run may fail. However, if Self::interrupt returns Ok, the implementation must guarantee that the interrupt isn’t injected in an uninterruptible window (e.g. right after the mov ss instruction).

The caller should avoid calling this function more than 1 time for one VMEXIT, because the hypervisor may behave differently: some hypervisors(e.g. WHPX, KVM) will only try to inject the last irq requested, while some other hypervisors(e.g. HAXM) may try to inject all irqs requested.

source

fn inject_nmi(&self) -> Result<(), Error>

Injects a non-maskable interrupt into the VCPU.

source

fn get_regs(&self) -> Result<Regs, Error>

Gets the VCPU general purpose registers.

source

fn set_regs(&self, regs: &Regs) -> Result<(), Error>

Sets the VCPU general purpose registers.

source

fn get_sregs(&self) -> Result<Sregs, Error>

Gets the VCPU special registers.

source

fn set_sregs(&self, sregs: &Sregs) -> Result<(), Error>

Sets the VCPU special registers.

source

fn get_fpu(&self) -> Result<Fpu, Error>

Gets the VCPU FPU registers.

source

fn set_fpu(&self, fpu: &Fpu) -> Result<(), Error>

Sets the VCPU FPU registers.

source

fn get_debugregs(&self) -> Result<DebugRegs, Error>

Gets the VCPU debug registers.

source

fn set_debugregs(&self, debugregs: &DebugRegs) -> Result<(), Error>

Sets the VCPU debug registers.

source

fn get_xcrs(&self) -> Result<BTreeMap<u32, u64>, Error>

Gets the VCPU extended control registers.

source

fn set_xcr(&self, xcr: u32, value: u64) -> Result<(), Error>

Sets a VCPU extended control register.

source

fn get_xsave(&self) -> Result<Xsave, Error>

Gets the VCPU x87 FPU, MMX, XMM, YMM and MXCSR registers.

source

fn set_xsave(&self, xsave: &Xsave) -> Result<(), Error>

Sets the VCPU x87 FPU, MMX, XMM, YMM and MXCSR registers.

source

fn get_interrupt_state(&self) -> Result<Value, Error>

Gets interrupt state (hypervisor specific) for this VCPU that must be saved/restored for snapshotting.

source

fn set_interrupt_state(&self, data: Value) -> Result<(), Error>

Sets interrupt state (hypervisor specific) for this VCPU. Only used for snapshotting.

source

fn get_msr(&self, msr_index: u32) -> Result<u64, Error>

Gets a single model-specific register’s value.

source

fn get_all_msrs(&self) -> Result<BTreeMap<u32, u64>, Error>

Gets the model-specific registers. Returns all the MSRs for the VCPU.

source

fn set_msr(&self, msr_index: u32, value: u64) -> Result<(), Error>

Sets a single model-specific register’s value.

source

fn set_cpuid(&self, cpuid: &CpuId) -> Result<(), Error>

Sets up the data returned by the CPUID instruction.

source

fn set_guest_debug( &self, addrs: &[GuestAddress], enable_singlestep: bool ) -> Result<(), Error>

Sets up debug registers and configure vcpu for handling guest debug events.

source

fn handle_cpuid(&mut self, entry: &CpuIdEntry) -> Result<(), Error>

This function should be called after Vcpu::run returns VcpuExit::Cpuid, and entry should represent the result of emulating the CPUID instruction. The handle_cpuid function will then set the appropriate registers on the vcpu.

source

fn restore_timekeeping( &self, host_tsc_reference_moment: u64, tsc_offset: u64 ) -> Result<(), Error>

Some hypervisors require special handling to restore timekeeping when a snapshot is restored. They are provided with a host TSC reference moment, guaranteed to be the same across all Vcpus, and the Vcpu’s TSC offset at the moment it was snapshotted.

Provided Methods§

source

fn get_tsc_offset(&self) -> Result<u64, Error>

Gets the guest->host TSC offset.

The default implementation uses VcpuX86_64::get_msr() to read the guest TSC.

source

fn set_tsc_offset(&self, offset: u64) -> Result<(), Error>

Sets the guest->host TSC offset.

The default implementation uses VcpuX86_64::set_tsc_value() to set the TSC value.

It sets TSC_OFFSET (VMCS / CB field) by setting the TSC MSR to the current host TSC value plus the desired offset. We rely on the fact that hypervisors determine the value of TSC_OFFSET by computing TSC_OFFSET = new_tsc_value - _rdtsc() = _rdtsc() + offset - _rdtsc() ~= offset. Note that the ~= is important: this is an approximate operation, because the two _rdtsc() calls are separated by at least a few ticks.

Note: TSC_OFFSET, host TSC, guest TSC, and TSC MSR are all different concepts.

  • When a guest executes rdtsc, the value (guest TSC) returned is host_tsc * TSC_MULTIPLIER + TSC_OFFSET + TSC_ADJUST.
  • The TSC MSR is a special MSR that when written to by the host, will cause TSC_OFFSET to be set accordingly by the hypervisor.
  • When the guest writes to TSC MSR, it actually changes the TSC_ADJUST MSR for the guest. Generally this is only happens if the guest is trying to re-zero or synchronize TSCs.
source

fn set_tsc_value(&self, value: u64) -> Result<(), Error>

Sets the guest TSC exactly to the provided value.

The default implementation sets the guest’s TSC by writing the value to the MSR directly.

See VcpuX86_64::set_tsc_offset() for an explanation of how this value is actually read by the guest after being set.

source

fn snapshot(&self) -> Result<VcpuSnapshot, Error>

Snapshot vCPU state

source

fn restore( &mut self, snapshot: &VcpuSnapshot, host_tsc_reference_moment: u64 ) -> Result<(), Error>

Implementations§

source§

impl dyn VcpuX86_64

source

pub fn is<__T>(&self) -> bool
where __T: VcpuX86_64,

Returns true if the trait object wraps an object of type __T.

source

pub fn downcast<__T>( self: Box<dyn VcpuX86_64> ) -> Result<Box<__T>, Box<dyn VcpuX86_64>>
where __T: VcpuX86_64,

Returns a boxed object from a boxed trait object if the underlying object is of type __T. Returns the original boxed trait if it isn’t.

source

pub fn downcast_rc<__T>( self: Rc<dyn VcpuX86_64> ) -> Result<Rc<__T>, Rc<dyn VcpuX86_64>>
where __T: VcpuX86_64,

Returns an Rc-ed object from an Rc-ed trait object if the underlying object is of type __T. Returns the original Rc-ed trait if it isn’t.

source

pub fn downcast_ref<__T>(&self) -> Option<&__T>
where __T: VcpuX86_64,

Returns a reference to the object within the trait object if it is of type __T, or None if it isn’t.

source

pub fn downcast_mut<__T>(&mut self) -> Option<&mut __T>
where __T: VcpuX86_64,

Returns a mutable reference to the object within the trait object if it is of type __T, or None if it isn’t.

Implementors§