Struct kvm::Vcpu

source ·
pub struct Vcpu {
    pub(crate) vcpu: File,
    pub(crate) run_mmap: MemoryMapping,
}
Expand description

A wrapper around creating and using a VCPU. Vcpu provides all functionality except for running. To run, to_runnable must be called to lock the vcpu to a thread. Then the returned RunnableVcpu can be used for running.

Fields§

§vcpu: File§run_mmap: MemoryMapping

Implementations§

source§

impl Vcpu

source

pub fn new(id: c_ulong, kvm: &Kvm, vm: &Vm) -> Result<Vcpu>

Constructs a new VCPU for vm.

The id argument is the CPU number between [0, max vcpus).

source

pub fn to_runnable(self, signal_num: Option<c_int>) -> Result<RunnableVcpu>

Consumes self and returns a RunnableVcpu. A RunnableVcpu is required to run the guest. Assigns a vcpu to the current thread and stores it in a hash map that can be used by signal handlers to call set_local_immediate_exit(). An optional signal number will be temporarily blocked while assigning the vcpu to the thread and later blocked when RunnableVcpu is destroyed.

Returns an error, EBUSY, if the current thread already contains a Vcpu.

source

pub fn set_data(&self, data: &[u8]) -> Result<()>

Sets the data received by a mmio read, ioport in, or hypercall instruction.

This function should be called after Vcpu::run returns an VcpuExit::IoIn, VcpuExit::MmioRead, or ’VcpuExit::HypervHcall`.

source

pub fn set_immediate_exit(&self, exit: bool)

Sets the bit that requests an immediate exit.

source

pub fn set_local_immediate_exit(exit: bool)

Sets/clears the bit for immediate exit for the vcpu on the current thread.

source

pub fn get_regs(&self) -> Result<kvm_regs>

Gets the VCPU registers.

source

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

Sets the VCPU registers.

source

pub fn get_sregs(&self) -> Result<kvm_sregs>

Gets the VCPU special registers.

source

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

Sets the VCPU special registers.

source

pub fn get_fpu(&self) -> Result<kvm_fpu>

Gets the VCPU FPU registers.

source

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

X86 specific call to setup the FPU

See the documentation for KVM_SET_FPU.

source

pub fn get_debugregs(&self) -> Result<kvm_debugregs>

Gets the VCPU debug registers.

source

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

Sets the VCPU debug registers

source

pub fn get_xcrs(&self) -> Result<kvm_xcrs>

Gets the VCPU extended control registers

source

pub fn set_xcrs(&self, xcrs: &kvm_xcrs) -> Result<()>

Sets the VCPU extended control registers

source

pub fn get_msrs(&self, msr_entries: &mut Vec<kvm_msr_entry>) -> Result<()>

X86 specific call to get the MSRS

See the documentation for KVM_SET_MSRS.

source

pub fn set_msrs(&self, msrs: &kvm_msrs) -> Result<()>

X86 specific call to setup the MSRS

See the documentation for KVM_SET_MSRS.

source

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

X86 specific call to setup the CPUID registers

See the documentation for KVM_SET_CPUID2.

source

pub fn get_hyperv_cpuid(&self) -> Result<CpuId>

X86 specific call to get the system emulated hyper-v CPUID values

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_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.

source

pub fn get_vcpu_events(&self) -> Result<kvm_vcpu_events>

Gets the vcpu’s currently pending exceptions, interrupts, NMIs, etc

See the documentation for KVM_GET_VCPU_EVENTS.

source

pub fn set_vcpu_events(&self, events: &kvm_vcpu_events) -> Result<()>

Sets the vcpu’s currently pending exceptions, interrupts, NMIs, etc

See the documentation for KVM_SET_VCPU_EVENTS.

source

pub unsafe fn kvm_enable_cap(&self, cap: &kvm_enable_cap) -> Result<()>

Enable the specified capability. See documentation for KVM_ENABLE_CAP.

Safety

This function is marked as unsafe because cap may contain values which are interpreted as pointers by the kernel.

source

pub fn set_signal_mask(&self, signals: &[c_int]) -> Result<()>

Specifies set of signals that are blocked during execution of KVM_RUN. Signals that are not blocked will cause KVM_RUN to return with -EINTR.

See the documentation for KVM_SET_SIGNAL_MASK

Trait Implementations§

source§

impl AsRawDescriptor for Vcpu

source§

fn as_raw_descriptor(&self) -> RawDescriptor

Returns the underlying raw descriptor. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Vcpu

§

impl Send for Vcpu

§

impl Sync for Vcpu

§

impl Unpin for Vcpu

§

impl UnwindSafe for Vcpu

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AsRawDescriptors for Twhere T: AsRawDescriptor,

§

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

Returns the underlying raw descriptors. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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 Twhere 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 Twhere 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.