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>>>>,
caps: KvmVmCaps,
}
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
caps: KvmVmCaps
Implementations§
source§impl KvmVm
impl KvmVm
sourcepub fn init_arch(&self, _cfg: &Config) -> Result<()>
pub fn init_arch(&self, _cfg: &Config) -> Result<()>
Does platform specific initialization for the KvmVm.
sourcepub fn check_capability_arch(&self, c: VmCap) -> Option<bool>
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.
sourcepub fn get_device_params_arch(
&self,
_kind: DeviceKind
) -> Option<kvm_create_device>
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.
sourcepub fn get_pvclock_arch(&self) -> Result<ClockState>
pub fn get_pvclock_arch(&self) -> Result<ClockState>
Arch-specific implementation of Vm::get_pvclock
.
sourcepub fn set_pvclock_arch(&self, state: &ClockState) -> Result<()>
pub fn set_pvclock_arch(&self, state: &ClockState) -> Result<()>
Arch-specific implementation of Vm::set_pvclock
.
sourcepub fn get_pic_state(&self, id: PicSelect) -> Result<kvm_pic_state>
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
.
sourcepub fn set_pic_state(&self, id: PicSelect, state: &kvm_pic_state) -> Result<()>
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
.
sourcepub fn get_ioapic_num_pins(&self) -> Result<usize>
pub fn get_ioapic_num_pins(&self) -> Result<usize>
Retrieves the number of pins for emulated IO-APIC.
sourcepub fn get_ioapic_state(&self) -> Result<kvm_ioapic_state>
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
.
sourcepub fn set_ioapic_state(&self, state: &kvm_ioapic_state) -> Result<()>
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
.
sourcepub fn create_pit(&self) -> Result<()>
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
.
sourcepub fn get_pit_state(&self) -> Result<kvm_pit_state2>
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
.
sourcepub fn set_pit_state(&self, pit_state: &kvm_pit_state2) -> Result<()>
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
.
sourcepub fn set_platform_info_read_access(&self, allow_read: bool) -> Result<()>
pub fn set_platform_info_read_access(&self, allow_read: bool) -> Result<()>
Set MSR_PLATFORM_INFO read access.
sourcepub fn enable_split_irqchip(&self, ioapic_pins: usize) -> Result<()>
pub fn enable_split_irqchip(&self, ioapic_pins: usize) -> Result<()>
Enable support for split-irqchip.
sourcefn get_protected_vm_info(&self) -> Result<KvmProtectedVmInfo>
fn get_protected_vm_info(&self) -> Result<KvmProtectedVmInfo>
Get pKVM hypervisor details, e.g. the firmware size.
Returns Err
if not running under pKVM.
Uses KVM_ENABLE_CAP
internally, but it is only a getter, there should be no side effects
in KVM.
fn set_protected_vm_firmware_gpa(&self, fw_addr: GuestAddress) -> Result<()>
source§impl KvmVm
impl KvmVm
sourcepub fn new(kvm: &Kvm, guest_mem: GuestMemory, cfg: Config) -> Result<KvmVm>
pub fn new(kvm: &Kvm, guest_mem: GuestMemory, cfg: Config) -> Result<KvmVm>
Constructs a new KvmVm
using the given Kvm
instance.
pub fn create_kvm_vcpu(&self, id: usize) -> Result<KvmVcpu>
sourcepub fn create_irq_chip(&self) -> Result<()>
pub fn create_irq_chip(&self) -> Result<()>
Creates an in kernel interrupt controller.
See the documentation on the KVM_CREATE_IRQCHIP ioctl.
sourcepub fn set_irq_line(&self, irq: u32, active: bool) -> Result<()>
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.
sourcepub fn register_irqfd(
&self,
gsi: u32,
evt: &Event,
resample_evt: Option<&Event>
) -> Result<()>
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.
sourcepub fn unregister_irqfd(&self, gsi: u32, evt: &Event) -> Result<()>
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
.
sourcepub fn set_gsi_routing(&self, routes: &[IrqRoute]) -> Result<()>
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
.
fn ioeventfd( &self, evt: &Event, addr: IoEventAddress, datamatch: Datamatch, deassign: bool ) -> Result<()>
sourcepub fn check_raw_capability(&self, capability: KvmCap) -> bool
pub fn check_raw_capability(&self, capability: KvmCap) -> bool
Checks whether a particular KVM-specific capability is available for this VM.
sourceunsafe fn enable_raw_capability(
&self,
capability: KvmCap,
flags: u32,
args: &[u64; 4]
) -> Result<()>
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.
fn handle_inflate( &mut self, guest_address: GuestAddress, size: u64 ) -> Result<()>
fn handle_deflate( &mut self, _guest_address: GuestAddress, _size: u64 ) -> Result<()>
Trait Implementations§
source§impl AsRawDescriptor for KvmVm
impl AsRawDescriptor for KvmVm
source§fn as_raw_descriptor(&self) -> RawDescriptor
fn as_raw_descriptor(&self) -> RawDescriptor
source§impl Vm for KvmVm
impl Vm for KvmVm
source§fn check_capability(&self, c: VmCap) -> bool
fn check_capability(&self, c: VmCap) -> bool
VmCap
is available. Read moresource§fn enable_capability(&self, c: VmCap, _flags: u32) -> Result<bool>
fn enable_capability(&self, c: VmCap, _flags: u32) -> Result<bool>
source§fn get_guest_phys_addr_bits(&self) -> u8
fn get_guest_phys_addr_bits(&self) -> u8
source§fn get_memory(&self) -> &GuestMemory
fn get_memory(&self) -> &GuestMemory
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>
fn add_memory_region( &mut self, guest_addr: GuestAddress, mem: Box<dyn MappedRegion>, read_only: bool, log_dirty_pages: bool, cache: MemCacheType ) -> Result<MemSlot>
source§fn msync_memory_region(
&mut self,
slot: MemSlot,
offset: usize,
size: usize
) -> Result<()>
fn msync_memory_region( &mut self, slot: MemSlot, offset: usize, size: usize ) -> Result<()>
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<()>
fn madvise_pageout_memory_region( &mut self, slot: MemSlot, offset: usize, size: usize ) -> Result<()>
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<()>
fn madvise_remove_memory_region( &mut self, slot: MemSlot, offset: usize, size: usize ) -> Result<()>
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>>
fn remove_memory_region( &mut self, slot: MemSlot ) -> Result<Box<dyn MappedRegion>>
UserMemoryRegion
that was previously added at the given slot.source§fn create_device(&self, kind: DeviceKind) -> Result<SafeDescriptor>
fn create_device(&self, kind: DeviceKind) -> Result<SafeDescriptor>
source§fn get_dirty_log(&self, slot: MemSlot, dirty_log: &mut [u8]) -> Result<()>
fn get_dirty_log(&self, slot: MemSlot, dirty_log: &mut [u8]) -> Result<()>
get_dirty_log
for the memory at
slot
. Only works on VMs that support VmCap::DirtyLog
. Read moresource§fn register_ioevent(
&mut self,
evt: &Event,
addr: IoEventAddress,
datamatch: Datamatch
) -> Result<()>
fn register_ioevent( &mut self, evt: &Event, addr: IoEventAddress, datamatch: Datamatch ) -> Result<()>
source§fn unregister_ioevent(
&mut self,
evt: &Event,
addr: IoEventAddress,
datamatch: Datamatch
) -> Result<()>
fn unregister_ioevent( &mut self, evt: &Event, addr: IoEventAddress, datamatch: Datamatch ) -> Result<()>
register_ioevent
. Read moresource§fn handle_io_events(&self, _addr: IoEventAddress, _data: &[u8]) -> Result<()>
fn handle_io_events(&self, _addr: IoEventAddress, _data: &[u8]) -> Result<()>
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>
fn get_pvclock(&self) -> Result<ClockState>
VmCap::PvClock
.source§fn set_pvclock(&self, state: &ClockState) -> Result<()>
fn set_pvclock(&self, state: &ClockState) -> Result<()>
VmCap::PvClock
.source§fn add_fd_mapping(
&mut self,
slot: u32,
offset: usize,
size: usize,
fd: &dyn AsRawDescriptor,
fd_offset: u64,
prot: Protection
) -> Result<()>
fn add_fd_mapping( &mut self, slot: u32, offset: usize, size: usize, fd: &dyn AsRawDescriptor, fd_offset: u64, prot: Protection ) -> Result<()>
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 moresource§fn remove_mapping(
&mut self,
slot: u32,
offset: usize,
size: usize
) -> Result<()>
fn remove_mapping( &mut self, slot: u32, offset: usize, size: usize ) -> Result<()>
size
-byte mapping starting at offset
.source§fn handle_balloon_event(&mut self, event: BalloonEvent) -> Result<()>
fn handle_balloon_event(&mut self, event: BalloonEvent) -> Result<()>
source§impl VmX86_64 for KvmVm
impl VmX86_64 for KvmVm
source§fn set_tss_addr(&self, addr: GuestAddress) -> Result<()>
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<()>
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
fn get_hypervisor(&self) -> &dyn HypervisorX86_64
HypervisorX86_64
that created this VM.source§fn load_protected_vm_firmware(
&mut self,
fw_addr: GuestAddress,
fw_max_size: u64
) -> Result<()>
fn load_protected_vm_firmware( &mut self, fw_addr: GuestAddress, fw_max_size: u64 ) -> Result<()>
source§fn create_vcpu(&self, id: usize) -> Result<Box<dyn VcpuX86_64>>
fn create_vcpu(&self, id: usize) -> Result<Box<dyn VcpuX86_64>>
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§
§impl<T> AsRawDescriptors for Twhere
T: AsRawDescriptor,
impl<T> AsRawDescriptors for Twhere
T: AsRawDescriptor,
§fn as_raw_descriptors(&self) -> Vec<i32>
fn as_raw_descriptors(&self) -> Vec<i32>
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<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.