Skip to main content

AxArchVCpu

Trait AxArchVCpu 

Source
pub trait AxArchVCpu: Sized {
    type CreateConfig;
    type SetupConfig;

    // Required methods
    fn new(
        vm_id: VMId,
        vcpu_id: VCpuId,
        config: Self::CreateConfig,
    ) -> AxResult<Self>;
    fn set_entry(&mut self, entry: GuestPhysAddr) -> AxResult;
    fn set_ept_root(&mut self, ept_root: HostPhysAddr) -> AxResult;
    fn setup(&mut self, config: Self::SetupConfig) -> AxResult;
    fn run(&mut self) -> AxResult<AxVCpuExitReason>;
    fn bind(&mut self) -> AxResult;
    fn unbind(&mut self) -> AxResult;
    fn set_gpr(&mut self, reg: usize, val: usize);
    fn inject_interrupt(&mut self, vector: usize) -> AxResult;
    fn set_return_value(&mut self, val: usize);
}
Expand description

Architecture-specific virtual CPU trait definition.

This trait provides an abstraction layer for implementing virtual CPUs across different hardware architectures (x86_64, ARM64, RISC-V, etc.). Each architecture must implement this trait to provide the necessary low-level virtualization primitives.

Required Associated Types§

Source

type CreateConfig

Architecture-specific configuration for VCpu creation.

This associated type allows each architecture to define its own configuration parameters needed during VCpu initialization.

Source

type SetupConfig

Architecture-specific configuration for VCpu setup.

This associated type allows each architecture to specify additional configuration parameters needed after basic VCpu creation but before execution.

Required Methods§

Source

fn new( vm_id: VMId, vcpu_id: VCpuId, config: Self::CreateConfig, ) -> AxResult<Self>

Creates a new architecture-specific VCpu instance.

Source

fn set_entry(&mut self, entry: GuestPhysAddr) -> AxResult

Sets the guest entry point where VCpu execution will begin.

It’s guaranteed that this function is called only once, before AxArchVCpu::setup being called.

Source

fn set_ept_root(&mut self, ept_root: HostPhysAddr) -> AxResult

Sets the Extended Page Table (EPT) root for memory translation.

The EPT root defines the top-level page table used for guest-to-host physical address translation in hardware virtualization.

Source

fn setup(&mut self, config: Self::SetupConfig) -> AxResult

Completes VCpu initialization and prepares it for execution.

This method performs any final architecture-specific setup needed before the VCpu can be bound and executed.

Source

fn run(&mut self) -> AxResult<AxVCpuExitReason>

Executes the VCpu until a VM exit occurs.

This is the core execution method that transfers control to the guest VCpu and runs until the guest triggers a VM exit condition that requires hypervisor intervention.

Source

fn bind(&mut self) -> AxResult

Binds the VCpu to the current physical CPU for execution.

This method performs any necessary architecture-specific initialization to prepare the VCpu for execution on the current physical CPU.

Source

fn unbind(&mut self) -> AxResult

Unbinds the VCpu from the current physical CPU.

This method performs cleanup and state preservation when moving the VCpu away from the current physical CPU.

Source

fn set_gpr(&mut self, reg: usize, val: usize)

Sets the value of a general-purpose register.

Source

fn inject_interrupt(&mut self, vector: usize) -> AxResult

Inject an interrupt to the VCpu.

It’s guaranteed (for implementors, and required for callers) that this function is called on the physical CPU where the VCpu is running or queueing.

It’s not guaranteed that the VCpu is running or bound to the current physical CPU when this function is called. It means sometimes an irq queue is necessary to buffer the interrupts until the VCpu is running.

Source

fn set_return_value(&mut self, val: usize)

Sets the return value that will be delivered to the guest.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§