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
impl KvmVm
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Returns whether the VM is running.
Sourcepub fn add_memory_region(
&self,
guest_addr: GuestAddress,
host_addr: *mut u8,
size: u64,
read_only: bool,
) -> Result<u32, HypervisorError>
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.
Sourcepub fn remove_memory_region(&self, slot: u32) -> Result<(), HypervisorError>
pub fn remove_memory_region(&self, slot: u32) -> Result<(), HypervisorError>
Removes a memory region from the VM.
Sourcepub fn set_irq_line(&self, gsi: u32, level: bool) -> Result<(), HypervisorError>
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 numberlevel- true to assert, false to deassert
Sourcepub fn trigger_edge_irq(&self, gsi: u32) -> Result<(), HypervisorError>
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.
Sourcepub fn register_irqfd(
&self,
eventfd: RawFd,
gsi: u32,
resample_fd: Option<RawFd>,
) -> Result<(), HypervisorError>
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 descriptorgsi- The GSI to inject when eventfd is signaledresample_fd- For level-triggered IRQs, optional resample eventfd
Sourcepub fn unregister_irqfd(
&self,
eventfd: RawFd,
gsi: u32,
) -> Result<(), HypervisorError>
pub fn unregister_irqfd( &self, eventfd: RawFd, gsi: u32, ) -> Result<(), HypervisorError>
Unregisters an eventfd for IRQ injection.
Sourcepub fn virtio_devices(&self) -> Result<Vec<VirtioDeviceInfo>, HypervisorError>
pub fn virtio_devices(&self) -> Result<Vec<VirtioDeviceInfo>, HypervisorError>
Returns a copy of the attached VirtIO devices info.
Sourcepub fn enable_dirty_tracking(&self) -> Result<(), HypervisorError>
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.
Sourcepub fn disable_dirty_tracking(&self) -> Result<(), HypervisorError>
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.
Sourcepub fn is_dirty_tracking_enabled(&self) -> bool
pub fn is_dirty_tracking_enabled(&self) -> bool
Returns whether dirty page tracking is enabled.
Sourcepub fn get_dirty_pages(&self) -> Result<Vec<DirtyPageInfo>, HypervisorError>
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 VirtualMachine for KvmVm
impl VirtualMachine for KvmVm
Source§fn create_vcpu(&mut self, id: u32) -> Result<Self::Vcpu, HypervisorError>
fn create_vcpu(&mut self, id: u32) -> Result<Self::Vcpu, HypervisorError>
Source§fn add_virtio_device(
&mut self,
device: VirtioDeviceConfig,
) -> Result<(), HypervisorError>
fn add_virtio_device( &mut self, device: VirtioDeviceConfig, ) -> Result<(), HypervisorError>
VirtIO device to the VM. Read moreSource§fn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Any for downcasting.