Struct hypervisor::kvm::KvmVcpu

source ·
pub struct KvmVcpu {
    kvm: Kvm,
    vm: SafeDescriptor,
    vcpu: File,
    id: usize,
    cap_kvmclock_ctrl: bool,
    run_mmap: Arc<MemoryMapping>,
}
Expand description

A wrapper around using a KVM Vcpu.

Fields§

§kvm: Kvm§vm: SafeDescriptor§vcpu: File§id: usize§cap_kvmclock_ctrl: bool§run_mmap: Arc<MemoryMapping>

Implementations§

source§

impl KvmVcpu

source

pub fn system_event_reset(&self, _event_flags: u64) -> Result<VcpuExit>

Handles a KVM_EXIT_SYSTEM_EVENT with event type KVM_SYSTEM_EVENT_RESET with the given event flags and returns the appropriate VcpuExit value for the run loop to handle.

source

fn xsave_size(&self) -> Result<usize>

Gets the Xsave size by checking the extension KVM_CAP_XSAVE2.

Size should always be >=0. If size is negative, an error occurred. If size <= 4096, XSAVE2 is not supported by the CPU or the kernel. KVM_XSAVE_MAX_SIZE is returned (4096). Otherwise, the size will be returned.

source

pub(crate) fn handle_vm_exit_arch(&self, run: &mut kvm_run) -> Option<VcpuExit>

source§

impl KvmVcpu

source

pub fn get_lapic(&self) -> Result<kvm_lapic_state>

X86 specific call to get the state of the “Local Advanced Programmable Interrupt Controller”.

See the documentation for KVM_GET_LAPIC.

source

pub fn set_lapic(&self, klapic: &kvm_lapic_state) -> Result<()>

X86 specific call to set the state of the “Local Advanced Programmable Interrupt Controller”.

See the documentation for KVM_SET_LAPIC.

source

pub fn get_apic_base(&self) -> Result<u64>

X86 specific call to get the value of the APIC_BASE MSR.

See the documentation for The kvm_run structure, and for KVM_GET_LAPIC.

source

pub fn set_apic_base(&self, apic_base: u64) -> Result<()>

X86 specific call to set the value of the APIC_BASE MSR.

See the documentation for The kvm_run structure, and for KVM_GET_LAPIC.

source

pub fn get_interrupt_bitmap(&self) -> Result<[u64; 4]>

Call to get pending interrupts acknowledged by the APIC but not yet injected into the CPU.

See the documentation for KVM_GET_SREGS.

source

pub fn set_interrupt_bitmap(&self, interrupt_bitmap: [u64; 4]) -> Result<()>

Call to set pending interrupts acknowledged by the APIC but not yet injected into the CPU.

See the documentation for KVM_GET_SREGS.

source§

impl KvmVcpu

source

pub fn get_mp_state(&self) -> Result<kvm_mp_state>

Gets the vcpu’s current “multiprocessing state”.

See the documentation for KVM_GET_MP_STATE. This call can only succeed after a call to Vm::create_irq_chip.

Note that KVM defines the call for both x86 and s390 but we do not expect anyone to run crosvm on s390.

source

pub fn set_mp_state(&self, state: &kvm_mp_state) -> Result<()>

Sets the vcpu’s current “multiprocessing state”.

See the documentation for KVM_SET_MP_STATE. This call can only succeed after a call to Vm::create_irq_chip.

Note that KVM defines the call for both x86 and s390 but we do not expect anyone to run crosvm on s390.

Trait Implementations§

source§

impl AsRawDescriptor for KvmVcpu

source§

fn as_raw_descriptor(&self) -> RawDescriptor

Returns the underlying raw descriptor. Read more
source§

impl Vcpu for KvmVcpu

source§

fn try_clone(&self) -> Result<Self>

Makes a shallow clone of this Vcpu.
source§

fn as_vcpu(&self) -> &dyn Vcpu

Casts this architecture specific trait object to the base trait object Vcpu.
source§

fn id(&self) -> usize

Returns the vcpu id.
source§

fn set_immediate_exit(&self, exit: bool)

Sets the bit that requests an immediate exit.
source§

fn signal_handle(&self) -> VcpuSignalHandle

Returns a handle that can be used to cause this VCPU to exit from run() from a signal handler.
source§

fn on_suspend(&self) -> Result<()>

Signals to the hypervisor that this Vcpu is being paused by userspace.
source§

unsafe fn enable_raw_capability(&self, cap: u32, args: &[u64; 4]) -> Result<()>

Enables a hypervisor-specific extension on this Vcpu. cap is a constant defined by the hypervisor API (e.g., kvm.h). args are the arguments for enabling the feature, if any. Read more
source§

fn run(&mut self) -> Result<VcpuExit>

Runs the VCPU until it exits, returning the reason for the exit.
source§

fn handle_mmio( &self, handle_fn: &mut dyn FnMut(IoParams<'_>) -> Result<()> ) -> Result<()>

Handles an incoming MMIO request from the guest. Read more
source§

fn handle_io(&self, handle_fn: &mut dyn FnMut(IoParams<'_>)) -> Result<()>

Handles an incoming PIO from the guest. Read more
source§

impl VcpuX86_64 for KvmVcpu

source§

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

Use the KVM_INTERRUPT ioctl to inject the specified interrupt vector.

While this ioctl exists on PPC and MIPS as well as x86, the semantics are different and ChromeOS doesn’t support PPC or MIPS.

source§

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

If the VM reports using XSave2, the function will call XSave2.

source§

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

KVM does not support the VcpuExit::Cpuid exit type.

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 inject_nmi(&self) -> Result<()>

Injects a non-maskable interrupt into the VCPU.
source§

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

Gets the VCPU general purpose registers.
source§

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

Sets the VCPU general purpose registers.
source§

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

Gets the VCPU special registers.
source§

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

Sets the VCPU special registers.
source§

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

Gets the VCPU FPU registers.
source§

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

Sets the VCPU FPU registers.
source§

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

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

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

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

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

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

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

Gets the VCPU debug registers.
source§

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

Sets the VCPU debug registers.
source§

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

Gets the VCPU extended control registers.
source§

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

Sets a VCPU extended control register.
source§

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

Gets a single model-specific register’s value.
source§

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

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

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

Sets a single model-specific register’s value.
source§

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

Sets up the data returned by the CPUID instruction.
source§

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

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

fn restore_timekeeping( &self, _host_tsc_reference_moment: u64, _tsc_offset: u64 ) -> Result<()>

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.
source§

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

Gets the guest->host TSC offset. Read more
source§

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

Sets the guest->host TSC offset. Read more
source§

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

Sets the guest TSC exactly to the provided value. Read more
source§

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

Snapshot vCPU state
source§

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

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AsRawDescriptors for T
where T: AsRawDescriptor,

§

fn as_raw_descriptors(&self) -> Vec<i32>

Returns the underlying raw descriptors. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.