Struct hypervisor::kvm::KvmVm

source ·
pub struct KvmVm {
    kvm: Kvm,
    vm: SafeDescriptor,
    guest_mem: GuestMemory,
    mem_regions: Arc<Mutex<BTreeMap<MemSlot, Box<dyn MappedRegion>>>>,
    mem_slot_gaps: Arc<Mutex<BinaryHeap<Reverse<MemSlot>>>>,
    cap_kvmclock_ctrl: bool,
}
Expand description

A wrapper around creating and using a KVM VM.

Fields§

§kvm: Kvm§vm: SafeDescriptor§guest_mem: GuestMemory§mem_regions: Arc<Mutex<BTreeMap<MemSlot, Box<dyn MappedRegion>>>>§mem_slot_gaps: Arc<Mutex<BinaryHeap<Reverse<MemSlot>>>>

A min heap of MemSlot numbers that were used and then removed and can now be re-used

§cap_kvmclock_ctrl: bool

Implementations§

source§

impl KvmVm

source

pub fn init_arch(&self, _cfg: &Config) -> Result<()>

Does platform specific initialization for the KvmVm.

source

pub fn is_pkvm(&self) -> bool

Whether running under pKVM.

source

pub fn check_capability_arch(&self, c: VmCap) -> Option<bool>

Checks if a particular VmCap is available, or returns None if arch-independent Vm.check_capability() should handle the check.

source

pub fn get_device_params_arch( &self, _kind: DeviceKind ) -> Option<kvm_create_device>

Returns the params to pass to KVM_CREATE_DEVICE for a kind device on this arch, or None to let the arch-independent KvmVm::create_device handle it.

source

pub fn get_pvclock_arch(&self) -> Result<ClockState>

Arch-specific implementation of Vm::get_pvclock.

source

pub fn set_pvclock_arch(&self, state: &ClockState) -> Result<()>

Arch-specific implementation of Vm::set_pvclock.

source

pub fn get_pic_state(&self, id: PicSelect) -> Result<kvm_pic_state>

Retrieves the state of given interrupt controller by issuing KVM_GET_IRQCHIP ioctl.

Note that this call can only succeed after a call to Vm::create_irq_chip.

source

pub fn set_pic_state(&self, id: PicSelect, state: &kvm_pic_state) -> Result<()>

Sets the state of given interrupt controller by issuing KVM_SET_IRQCHIP ioctl.

Note that this call can only succeed after a call to Vm::create_irq_chip.

source

pub fn get_ioapic_num_pins(&self) -> Result<usize>

Retrieves the number of pins for emulated IO-APIC.

source

pub fn get_ioapic_state(&self) -> Result<kvm_ioapic_state>

Retrieves the state of IOAPIC by issuing KVM_GET_IRQCHIP ioctl.

Note that this call can only succeed after a call to Vm::create_irq_chip.

source

pub fn set_ioapic_state(&self, state: &kvm_ioapic_state) -> Result<()>

Sets the state of IOAPIC by issuing KVM_SET_IRQCHIP ioctl.

Note that this call can only succeed after a call to Vm::create_irq_chip.

source

pub fn create_pit(&self) -> Result<()>

Creates a PIT as per the KVM_CREATE_PIT2 ioctl.

Note that this call can only succeed after a call to Vm::create_irq_chip.

source

pub fn get_pit_state(&self) -> Result<kvm_pit_state2>

Retrieves the state of PIT by issuing KVM_GET_PIT2 ioctl.

Note that this call can only succeed after a call to Vm::create_pit.

source

pub fn set_pit_state(&self, pit_state: &kvm_pit_state2) -> Result<()>

Sets the state of PIT by issuing KVM_SET_PIT2 ioctl.

Note that this call can only succeed after a call to Vm::create_pit.

source

pub fn set_platform_info_read_access(&self, allow_read: bool) -> Result<()>

Set MSR_PLATFORM_INFO read access.

source

pub fn enable_split_irqchip(&self, ioapic_pins: usize) -> Result<()>

Enable support for split-irqchip.

source§

impl KvmVm

source

pub fn new(kvm: &Kvm, guest_mem: GuestMemory, cfg: Config) -> Result<KvmVm>

Constructs a new KvmVm using the given Kvm instance.

source

pub fn create_kvm_vcpu(&self, id: usize) -> Result<KvmVcpu>

source

pub fn create_irq_chip(&self) -> Result<()>

Creates an in kernel interrupt controller.

See the documentation on the KVM_CREATE_IRQCHIP ioctl.

source

pub fn set_irq_line(&self, irq: u32, active: bool) -> Result<()>

Sets the level on the given irq to 1 if active is true, and 0 otherwise.

source

pub fn register_irqfd( &self, gsi: u32, evt: &Event, resample_evt: Option<&Event> ) -> Result<()>

Registers an event that will, when signalled, trigger the gsi irq, and resample_evt ( when not None ) will be triggered when the irqchip is resampled.

source

pub fn unregister_irqfd(&self, gsi: u32, evt: &Event) -> Result<()>

Unregisters an event that was previously registered with register_irqfd.

The evt and gsi pair must be the same as the ones passed into register_irqfd.

source

pub fn set_gsi_routing(&self, routes: &[IrqRoute]) -> Result<()>

Sets the GSI routing table, replacing any table set with previous calls to set_gsi_routing.

source

fn ioeventfd( &self, evt: &Event, addr: IoEventAddress, datamatch: Datamatch, deassign: bool ) -> Result<()>

source

pub fn check_raw_capability(&self, capability: KvmCap) -> bool

Checks whether a particular KVM-specific capability is available for this VM.

source

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

Enables a KVM-specific capability for this VM, with the given arguments.

§Safety

This function is marked as unsafe because args may be interpreted as pointers for some capabilities. The caller must ensure that any pointers passed in the args array are allocated as the kernel expects, and that mutable pointers are owned.

source

fn handle_inflate( &mut self, guest_address: GuestAddress, size: u64 ) -> Result<()>

source

fn handle_deflate( &mut self, _guest_address: GuestAddress, _size: u64 ) -> Result<()>

Trait Implementations§

source§

impl AsRawDescriptor for KvmVm

source§

fn as_raw_descriptor(&self) -> RawDescriptor

Returns the underlying raw descriptor. Read more
source§

impl Vm for KvmVm

source§

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

Makes a shallow clone of this Vm.
source§

fn check_capability(&self, c: VmCap) -> bool

Checks if a particular VmCap is available. Read more
source§

fn enable_capability(&self, c: VmCap, _flags: u32) -> Result<bool>

Enable the VM capabilities.
source§

fn get_guest_phys_addr_bits(&self) -> u8

Get the guest physical address size in bits.
source§

fn get_memory(&self) -> &GuestMemory

Gets the guest-mapped memory for the Vm.
source§

fn add_memory_region( &mut self, guest_addr: GuestAddress, mem: Box<dyn MappedRegion>, read_only: bool, log_dirty_pages: bool, cache: MemCacheType ) -> Result<MemSlot>

Inserts the given MappedRegion into the VM’s address space at guest_addr. Read more
source§

fn msync_memory_region( &mut self, slot: MemSlot, offset: usize, size: usize ) -> Result<()>

Does a synchronous msync of the memory mapped at slot, syncing size bytes starting at offset from the start of the region. offset must be page aligned.
source§

fn madvise_pageout_memory_region( &mut self, slot: MemSlot, offset: usize, size: usize ) -> Result<()>

Gives a MADV_PAGEOUT advice to the memory region mapped at slot, with the address range starting at offset from the start of the region, and with size size. offset must be page aligned.
source§

fn madvise_remove_memory_region( &mut self, slot: MemSlot, offset: usize, size: usize ) -> Result<()>

Gives a MADV_REMOVE advice to the memory region mapped at slot, with the address range starting at offset from the start of the region, and with size size. offset must be page aligned.
source§

fn remove_memory_region( &mut self, slot: MemSlot ) -> Result<Box<dyn MappedRegion>>

Removes and drops the UserMemoryRegion that was previously added at the given slot.
source§

fn create_device(&self, kind: DeviceKind) -> Result<SafeDescriptor>

Creates an emulated device.
source§

fn get_dirty_log(&self, slot: MemSlot, dirty_log: &mut [u8]) -> Result<()>

Gets the bitmap of dirty pages since the last call to get_dirty_log for the memory at slot. Only works on VMs that support VmCap::DirtyLog. Read more
source§

fn register_ioevent( &mut self, evt: &Event, addr: IoEventAddress, datamatch: Datamatch ) -> Result<()>

Registers an event to be signaled whenever a certain address is written to. Read more
source§

fn unregister_ioevent( &mut self, evt: &Event, addr: IoEventAddress, datamatch: Datamatch ) -> Result<()>

Unregisters an event previously registered with register_ioevent. Read more
source§

fn handle_io_events(&self, _addr: IoEventAddress, _data: &[u8]) -> Result<()>

Trigger any matching registered io events based on an MMIO or PIO write at addr. The data slice represents the contents and length of the write, which is used to compare with the registered io events’ Datamatch values. If the hypervisor does in-kernel IO event delivery, this is a no-op.
source§

fn get_pvclock(&self) -> Result<ClockState>

Retrieves the current timestamp of the paravirtual clock as seen by the current guest. Only works on VMs that support VmCap::PvClock.
source§

fn set_pvclock(&self, state: &ClockState) -> Result<()>

Sets the current timestamp of the paravirtual clock as seen by the current guest. Only works on VMs that support VmCap::PvClock.
source§

fn add_fd_mapping( &mut self, slot: u32, offset: usize, size: usize, fd: &dyn AsRawDescriptor, fd_offset: u64, prot: Protection ) -> Result<()>

Maps size bytes starting at fs_offset bytes from within the given fd at offset bytes from the start of the arena with prot protections. offset must be page aligned. Read more
source§

fn remove_mapping( &mut self, slot: u32, offset: usize, size: usize ) -> Result<()>

Remove size-byte mapping starting at offset.
source§

fn handle_balloon_event(&mut self, event: BalloonEvent) -> Result<()>

Events from virtio-balloon that affect the state for guest memory and host memory.
source§

impl VmX86_64 for KvmVm

source§

fn set_tss_addr(&self, addr: GuestAddress) -> Result<()>

Sets the address of the three-page region in the VM’s address space.

See the documentation on the KVM_SET_TSS_ADDR ioctl.

source§

fn set_identity_map_addr(&self, addr: GuestAddress) -> Result<()>

Sets the address of a one-page region in the VM’s address space.

See the documentation on the KVM_SET_IDENTITY_MAP_ADDR ioctl.

source§

fn get_hypervisor(&self) -> &dyn HypervisorX86_64

Gets the HypervisorX86_64 that created this VM.
source§

fn create_vcpu(&self, id: usize) -> Result<Box<dyn VcpuX86_64>>

Create a Vcpu with the specified Vcpu ID.

Auto Trait Implementations§

§

impl RefUnwindSafe for KvmVm

§

impl Send for KvmVm

§

impl Sync for KvmVm

§

impl Unpin for KvmVm

§

impl UnwindSafe for KvmVm

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.