Skip to main content

AxVM

Struct AxVM 

Source
pub struct AxVM<H: AxVMHal, U: AxVCpuHal> { /* private fields */ }
Expand description

A Virtual Machine.

Implementations§

Source§

impl<H: AxVMHal, U: AxVCpuHal> AxVM<H, U>

Source

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.

Source

pub fn id(&self) -> usize

Returns the VM id.

Source

pub fn init(&self) -> AxResult

Sets up the VM before booting.

Source

pub fn set_vm_status(&self, status: VMStatus)

Sets the VM status.

Source

pub fn vm_status(&self) -> VMStatus

Returns the current VM status.

Source

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.

Source

pub fn vcpu_num(&self) -> usize

Returns the number of vCPUs corresponding to the VM.

Source

pub fn vcpu_list(&self) -> &[AxVCpuRef<U>]

Returns a reference to the list of vCPUs corresponding to the VM.

Source

pub fn ept_root(&self) -> HostPhysAddr

Returns the base address of the two-stage address translation page table for the VM.

Source

pub fn with_config<F, R>(&self, f: F) -> R
where F: FnOnce(&mut AxVMConfig) -> R,

Returns to the VM’s configuration.

Source

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

Source

pub fn boot(&self) -> AxResult

Boots the VM by transitioning to Running state.

Source

pub fn running(&self) -> bool

Returns if the VM is running.

Source

pub fn stopping(&self) -> bool

Returns if the VM is shutting down (in Stopping state).

Source

pub fn suspending(&self) -> bool

Returns if the VM is suspended.

Source

pub fn stopped(&self) -> bool

Returns if the VM is stopped.

Source

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.

Source

pub fn get_devices(&self) -> &AxVmDevices

Returns this VM’s emulated devices.

Source

pub fn run_vcpu(&self, vcpu_id: usize) -> AxResult<AxVCpuExitReason>

Run a vCPU according to the given vcpu_id.

§Arguments
  • vcpu_id - the id of the vCPU to run.
§Returns
  • AxVCpuExitReason - the exit reason of the vCPU, wrapped in an AxResult.
Source

pub fn inject_interrupt_to_vcpu( &self, targets: CpuMask<TEMP_MAX_VCPU_NUM>, irq: usize, ) -> AxResult

Injects an interrupt to the vCPU.

Source

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, None if not set.
  • The physical id of the vCpu, equal to vCpu id if not provided.
Source

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.

Source

pub fn unmap_region(&self, gpa: GuestPhysAddr, size: usize) -> AxResult

Unmaps a region of guest physical memory.

Source

pub fn read_from_guest_of<T>(&self, gpa_ptr: GuestPhysAddr) -> AxResult<T>

Reads an object of type T from the guest physical address.

Source

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.

Source

pub fn alloc_ivc_channel( &self, expected_size: usize, ) -> AxResult<(GuestPhysAddr, usize)>

Allocates an IVC channel for inter-VM communication region.

§Arguments
  • expected_size - The expected size of the IVC channel in bytes.
§Returns
  • AxResult<(GuestPhysAddr, usize)> - A tuple containing the guest physical address of the allocated IVC channel and its actual size.
Source

pub fn release_ivc_channel(&self, gpa: GuestPhysAddr, size: usize) -> AxResult

Releases an IVC channel for inter-VM communication region.

§Arguments
  • gpa - The guest physical address of the IVC channel to release.
  • size - The size of the IVC channel in bytes.
§Returns
  • AxResult<()> - An empty result indicating success or failure.
Source

pub fn alloc_memory_region( &self, layout: Layout, gpa: Option<GuestPhysAddr>, ) -> AxResult<&[u8]>

Allocates a new memory region for the VM.

Source

pub fn memory_regions(&self) -> Vec<VMMemoryRegion>

Returns a list of all memory regions in the VM.

Source

pub fn map_reserved_memory_region( &self, layout: Layout, gpa: Option<GuestPhysAddr>, ) -> AxResult<&[u8]>

Maps a reserved memory region for the VM.

Trait Implementations§

Source§

impl<H: AxVMHal, U: AxVCpuHal> Drop for AxVM<H, U>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<H, U> !Freeze for AxVM<H, U>

§

impl<H, U> !RefUnwindSafe for AxVM<H, U>

§

impl<H, U> Send for AxVM<H, U>
where H: Send, <H as AxVMHal>::PagingHandler: Send,

§

impl<H, U> Sync for AxVM<H, U>
where H: Send, <H as AxVMHal>::PagingHandler: Send,

§

impl<H, U> Unpin for AxVM<H, U>
where H: Unpin, <H as AxVMHal>::PagingHandler: Unpin,

§

impl<H, U> UnsafeUnpin for AxVM<H, U>

§

impl<H, U> !UnwindSafe for AxVM<H, U>

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
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
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>,

Source§

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>,

Source§

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.