pub struct AxVM<H: AxVMHal, U: AxVCpuHal> { /* private fields */ }Expand description
A Virtual Machine.
Implementations§
Source§impl<H: AxVMHal, U: AxVCpuHal> AxVM<H, U>
impl<H: AxVMHal, U: AxVCpuHal> AxVM<H, U>
Sourcepub fn new(config: AxVMConfig) -> AxResult<AxVMRef<H, U>>
pub fn new(config: AxVMConfig) -> AxResult<AxVMRef<H, U>>
Creates a new VM with the given configuration.
Returns an error if the configuration is invalid.
The VM is not started until boot is called.
Sourcepub fn set_vm_status(&self, status: VMStatus)
pub fn set_vm_status(&self, status: VMStatus)
Sets the VM status.
Sourcepub fn vcpu(&self, vcpu_id: usize) -> Option<AxVCpuRef<U>>
pub fn vcpu(&self, vcpu_id: usize) -> Option<AxVCpuRef<U>>
Retrieves the vCPU corresponding to the given vcpu_id for the VM. Returns None if the vCPU does not exist.
Sourcepub fn vcpu_list(&self) -> &[AxVCpuRef<U>] ⓘ
pub fn vcpu_list(&self) -> &[AxVCpuRef<U>] ⓘ
Returns a reference to the list of vCPUs corresponding to the VM.
Sourcepub fn ept_root(&self) -> HostPhysAddr
pub fn ept_root(&self) -> HostPhysAddr
Returns the base address of the two-stage address translation page table for the VM.
Sourcepub fn with_config<F, R>(&self, f: F) -> Rwhere
F: FnOnce(&mut AxVMConfig) -> R,
pub fn with_config<F, R>(&self, f: F) -> Rwhere
F: FnOnce(&mut AxVMConfig) -> R,
Returns to the VM’s configuration.
Sourcepub fn get_image_load_region(
&self,
image_load_gpa: GuestPhysAddr,
image_size: usize,
) -> AxResult<Vec<&'static mut [u8]>>
pub fn get_image_load_region( &self, image_load_gpa: GuestPhysAddr, image_size: usize, ) -> AxResult<Vec<&'static mut [u8]>>
Returns guest VM image load region in Vec<&'static mut [u8]>,
according to the given image_load_gpa and image_size. Vec<&’static mut u8>` is a series of (HVA) address segments,
which may correspond to non-contiguous physical addresses,
FIXME:
Find a more elegant way to manage potentially non-contiguous physical memory
instead of Vec<&'static mut [u8]>.
Sourcepub fn suspending(&self) -> bool
pub fn suspending(&self) -> bool
Returns if the VM is suspended.
Sourcepub fn shutdown(&self) -> AxResult
pub fn shutdown(&self) -> AxResult
Shuts down the VM by transitioning to Stopping state.
This method sets the VM status to Stopping, which signals all vCPUs to exit. Currently, the “re-init” process of the VM is not implemented. Therefore, a VM can only be booted once. And after the VM is shut down, it cannot be booted again.
Sourcepub fn get_devices(&self) -> &AxVmDevices
pub fn get_devices(&self) -> &AxVmDevices
Returns this VM’s emulated devices.
Sourcepub fn run_vcpu(&self, vcpu_id: usize) -> AxResult<AxVCpuExitReason>
pub fn run_vcpu(&self, vcpu_id: usize) -> AxResult<AxVCpuExitReason>
Sourcepub fn inject_interrupt_to_vcpu(
&self,
targets: CpuMask<TEMP_MAX_VCPU_NUM>,
irq: usize,
) -> AxResult
pub fn inject_interrupt_to_vcpu( &self, targets: CpuMask<TEMP_MAX_VCPU_NUM>, irq: usize, ) -> AxResult
Injects an interrupt to the vCPU.
Sourcepub fn get_vcpu_affinities_pcpu_ids(&self) -> Vec<(usize, Option<usize>, usize)>
pub fn get_vcpu_affinities_pcpu_ids(&self) -> Vec<(usize, Option<usize>, usize)>
Returns vCpu id list and its corresponding pCpu affinity list, as well as its physical id. If the pCpu affinity is None, it means the vCpu will be allocated to any available pCpu randomly. if the pCPU id is not provided, the vCpu’s physical id will be set as vCpu id.
Returns a vector of tuples, each tuple contains:
- The vCpu id.
- The pCpu affinity mask,
Noneif not set. - The physical id of the vCpu, equal to vCpu id if not provided.
Sourcepub fn map_region(
&self,
gpa: GuestPhysAddr,
hpa: HostPhysAddr,
size: usize,
flags: MappingFlags,
) -> AxResult
pub fn map_region( &self, gpa: GuestPhysAddr, hpa: HostPhysAddr, size: usize, flags: MappingFlags, ) -> AxResult
Maps a region of host physical memory to guest physical memory.
Sourcepub fn unmap_region(&self, gpa: GuestPhysAddr, size: usize) -> AxResult
pub fn unmap_region(&self, gpa: GuestPhysAddr, size: usize) -> AxResult
Unmaps a region of guest physical memory.
Sourcepub fn read_from_guest_of<T>(&self, gpa_ptr: GuestPhysAddr) -> AxResult<T>
pub fn read_from_guest_of<T>(&self, gpa_ptr: GuestPhysAddr) -> AxResult<T>
Reads an object of type T from the guest physical address.
Sourcepub fn write_to_guest_of<T>(&self, gpa_ptr: GuestPhysAddr, data: &T) -> AxResult
pub fn write_to_guest_of<T>(&self, gpa_ptr: GuestPhysAddr, data: &T) -> AxResult
Writes an object of type T to the guest physical address.
Sourcepub fn alloc_ivc_channel(
&self,
expected_size: usize,
) -> AxResult<(GuestPhysAddr, usize)>
pub fn alloc_ivc_channel( &self, expected_size: usize, ) -> AxResult<(GuestPhysAddr, usize)>
Sourcepub fn release_ivc_channel(&self, gpa: GuestPhysAddr, size: usize) -> AxResult
pub fn release_ivc_channel(&self, gpa: GuestPhysAddr, size: usize) -> AxResult
Sourcepub fn alloc_memory_region(
&self,
layout: Layout,
gpa: Option<GuestPhysAddr>,
) -> AxResult<&[u8]>
pub fn alloc_memory_region( &self, layout: Layout, gpa: Option<GuestPhysAddr>, ) -> AxResult<&[u8]>
Allocates a new memory region for the VM.
Sourcepub fn memory_regions(&self) -> Vec<VMMemoryRegion>
pub fn memory_regions(&self) -> Vec<VMMemoryRegion>
Returns a list of all memory regions in the VM.
Sourcepub fn map_reserved_memory_region(
&self,
layout: Layout,
gpa: Option<GuestPhysAddr>,
) -> AxResult<&[u8]>
pub fn map_reserved_memory_region( &self, layout: Layout, gpa: Option<GuestPhysAddr>, ) -> AxResult<&[u8]>
Maps a reserved memory region for the VM.