Skip to main content

KvmVm

Struct KvmVm 

Source
pub struct KvmVm { /* private fields */ }
Expand description

Virtual machine implementation for Linux KVM.

This wraps a KVM VM and provides the platform-agnostic interface.

Implementations§

Source§

impl KvmVm

Source

pub fn id(&self) -> u64

Returns the VM ID.

Source

pub fn config(&self) -> &VmConfig

Returns the VM configuration.

Source

pub fn state(&self) -> VmState

Returns the current VM state.

Source

pub fn is_running(&self) -> bool

Returns whether the VM is running.

Source

pub fn add_memory_region( &self, guest_addr: GuestAddress, host_addr: *mut u8, size: u64, read_only: bool, ) -> Result<u32, HypervisorError>

Adds an additional memory region to the VM.

Source

pub fn remove_memory_region(&self, slot: u32) -> Result<(), HypervisorError>

Removes a memory region from the VM.

Source

pub fn set_irq_line(&self, gsi: u32, level: bool) -> Result<(), HypervisorError>

Sets the IRQ line level on the in-kernel irqchip.

For edge-triggered interrupts, call with level=true then level=false. For level-triggered interrupts, keep level=true until acknowledged.

§Arguments
  • gsi - Global System Interrupt number
  • level - true to assert, false to deassert
Source

pub fn trigger_edge_irq(&self, gsi: u32) -> Result<(), HypervisorError>

Triggers an edge-triggered interrupt.

Convenience method that asserts then immediately deasserts the IRQ line.

Source

pub fn register_irqfd( &self, eventfd: RawFd, gsi: u32, resample_fd: Option<RawFd>, ) -> Result<(), HypervisorError>

Registers an eventfd for IRQ injection (IRQFD).

When the eventfd is signaled (write 1 to it), KVM will automatically inject the specified GSI into the guest. This is the most efficient method for interrupt delivery.

§Arguments
  • eventfd - The eventfd file descriptor
  • gsi - The GSI to inject when eventfd is signaled
  • resample_fd - For level-triggered IRQs, optional resample eventfd
Source

pub fn unregister_irqfd( &self, eventfd: RawFd, gsi: u32, ) -> Result<(), HypervisorError>

Unregisters an eventfd for IRQ injection.

Source

pub fn virtio_devices(&self) -> Result<Vec<VirtioDeviceInfo>, HypervisorError>

Returns a copy of the attached VirtIO devices info.

Source

pub fn enable_dirty_tracking(&self) -> Result<(), HypervisorError>

Enables dirty page tracking for all memory regions.

When enabled, KVM tracks which pages have been written to by the guest. Use get_dirty_pages to retrieve and clear the dirty page bitmap.

This is useful for:

  • Live migration: Only transfer modified pages
  • Snapshotting: Track incremental changes
§Errors

Returns an error if dirty logging cannot be enabled.

Source

pub fn disable_dirty_tracking(&self) -> Result<(), HypervisorError>

Disables dirty page tracking for all memory regions.

§Errors

Returns an error if dirty logging cannot be disabled.

Source

pub fn is_dirty_tracking_enabled(&self) -> bool

Returns whether dirty page tracking is enabled.

Source

pub fn get_dirty_pages(&self) -> Result<Vec<DirtyPageInfo>, HypervisorError>

Gets the list of dirty pages across all memory regions.

This retrieves and clears the dirty page bitmap from KVM. Each call returns pages that were written since the last call.

§Errors

Returns an error if dirty tracking is not enabled or if the dirty log cannot be retrieved.

Trait Implementations§

Source§

impl Drop for KvmVm

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl VirtualMachine for KvmVm

Source§

type Vcpu = KvmVcpu

The vCPU type for this VM.
Source§

type Memory = KvmMemory

The guest memory type for this VM.
Source§

fn memory(&self) -> &Self::Memory

Returns a reference to the guest memory.
Source§

fn create_vcpu(&mut self, id: u32) -> Result<Self::Vcpu, HypervisorError>

Creates a new vCPU. Read more
Source§

fn add_virtio_device( &mut self, device: VirtioDeviceConfig, ) -> Result<(), HypervisorError>

Adds a VirtIO device to the VM. Read more
Source§

fn start(&mut self) -> Result<(), HypervisorError>

Starts the VM. Read more
Source§

fn pause(&mut self) -> Result<(), HypervisorError>

Pauses the VM. Read more
Source§

fn resume(&mut self) -> Result<(), HypervisorError>

Resumes a paused VM. Read more
Source§

fn stop(&mut self) -> Result<(), HypervisorError>

Stops the VM. Read more
Source§

fn as_any(&self) -> &dyn Any

Returns the VM as a reference to Any for downcasting. Read more
Source§

fn as_any_mut(&mut self) -> &mut dyn Any

Returns the VM as a mutable reference to Any for downcasting.
Source§

fn vcpu_count(&self) -> u32

Returns the number of vCPUs in the VM.
Source§

fn snapshot_devices(&self) -> Result<Vec<DeviceSnapshot>, HypervisorError>

Gets snapshots of all device states. Read more
Source§

fn restore_devices( &mut self, snapshots: &[DeviceSnapshot], ) -> Result<(), HypervisorError>

Restores device states from snapshots. Read more
Source§

fn is_managed_execution(&self) -> bool

Returns whether this VM uses managed execution. Read more
Source§

impl Send for KvmVm

Source§

impl Sync for KvmVm

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more