Skip to main content

KvmMemory

Struct KvmMemory 

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

Guest memory implementation for Linux KVM.

This manages the guest physical address space using mmap’d memory that is registered with KVM via KVM_SET_USER_MEMORY_REGION.

Implementations§

Source§

impl KvmMemory

Source

pub fn new(size: u64) -> Result<Self, HypervisorError>

Creates a new guest memory region.

§Errors

Returns an error if memory allocation fails.

Source

pub fn host_address(&self) -> *mut u8

Returns the host address of the base memory region.

This is used when registering memory with KVM.

Source

pub fn add_region( &self, guest_addr: GuestAddress, size: u64, ) -> Result<*mut u8, HypervisorError>

Adds an additional memory region.

§Errors

Returns an error if the region overlaps with existing regions or memory allocation fails.

Source

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

Adds an externally allocated memory region.

The caller is responsible for ensuring the memory remains valid for the lifetime of this object.

§Safety

The host_addr must point to valid memory of at least size bytes that will remain valid for the lifetime of this KvmMemory.

Source

pub fn attach_vm_fd(&self, vm_fd: RawFd)

Attaches the KVM VM fd for dirty logging.

Source

pub fn register_slot( &self, slot: u32, guest_phys_addr: u64, size: u64, userspace_addr: u64, flags: u32, ) -> Result<(), HypervisorError>

Registers a memory slot for dirty logging.

§Errors

Returns an error if the slot list cannot be updated.

Source

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

Unregisters a memory slot.

§Errors

Returns an error if the slot list cannot be updated.

Source

pub fn set_dirty_tracking_enabled(&self, enabled: bool)

Updates the dirty tracking enabled flag from external callers.

Source

pub fn regions(&self) -> Result<Vec<MemoryRegion>, HypervisorError>

Returns an iterator over all memory regions.

Source

pub fn write_obj<T: Copy>( &self, addr: GuestAddress, val: &T, ) -> Result<(), HypervisorError>

Writes a value to guest memory at the specified address.

Source

pub fn read_obj<T: Copy + Default>( &self, addr: GuestAddress, ) -> Result<T, HypervisorError>

Reads a value from guest memory at the specified address.

Source

pub fn memset( &self, addr: GuestAddress, val: u8, len: usize, ) -> Result<(), HypervisorError>

Fills a range of guest memory with a byte value.

Trait Implementations§

Source§

impl Drop for KvmMemory

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl GuestMemory for KvmMemory

Source§

fn read( &self, addr: GuestAddress, buf: &mut [u8], ) -> Result<(), HypervisorError>

Reads bytes from guest memory. Read more
Source§

fn write(&self, addr: GuestAddress, buf: &[u8]) -> Result<(), HypervisorError>

Writes bytes to guest memory. Read more
Source§

fn get_host_address( &self, addr: GuestAddress, ) -> Result<*mut u8, HypervisorError>

Gets the host virtual address for a guest physical address. Read more
Source§

fn size(&self) -> u64

Returns the total size of guest memory in bytes.
Source§

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

Enables dirty page tracking. Read more
Source§

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

Disables dirty page tracking. Read more
Source§

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

Gets and clears the list of dirty pages since the last call. Read more
Source§

fn dump_all(&self, buf: &mut [u8]) -> Result<(), HypervisorError>

Reads all guest memory into a buffer. Read more
Source§

impl Send for KvmMemory

Source§

impl Sync for KvmMemory

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