GuestMemory

Trait GuestMemory 

Source
pub trait GuestMemory {
    type PhysicalMemory: GuestMemoryBackend + ?Sized;
    type Bitmap: Bitmap;

    // Required methods
    fn check_range(
        &self,
        addr: GuestAddress,
        count: usize,
        access: Permissions,
    ) -> bool;
    fn get_slices<'a>(
        &'a self,
        addr: GuestAddress,
        count: usize,
        access: Permissions,
    ) -> Result<impl GuestMemorySliceIterator<'a, BS<'a, Self::Bitmap>>>;

    // Provided method
    fn physical_memory(&self) -> Option<&Self::PhysicalMemory> { ... }
}
Expand description

Represents virtual I/O memory.

GuestMemory is generally backed by some “physical” GuestMemoryBackend, which then consists for GuestMemoryRegion objects. However, the mapping from I/O virtual addresses (IOVAs) to physical addresses may be arbitrarily fragmented. Translation is done via an IOMMU.

Note in contrast to GuestMemoryBackend:

  • Any IOVA range may consist of arbitrarily many underlying ranges in physical memory.
  • Accessing an IOVA requires passing the intended access mode, and the IOMMU will check whether the given access mode is permitted for the given IOVA.
  • The translation result for a given IOVA may change over time (i.e. the physical address associated with an IOVA may change).

Required Associated Types§

Source

type PhysicalMemory: GuestMemoryBackend + ?Sized

Underlying GuestMemoryBackend type.

Source

type Bitmap: Bitmap

Dirty bitmap type for tracking writes to the IOVA address space.

Required Methods§

Source

fn check_range( &self, addr: GuestAddress, count: usize, access: Permissions, ) -> bool

Return true if addr..(addr + count) is accessible with access.

Source

fn get_slices<'a>( &'a self, addr: GuestAddress, count: usize, access: Permissions, ) -> Result<impl GuestMemorySliceIterator<'a, BS<'a, Self::Bitmap>>>

Returns a VolatileSlice of count bytes starting at addr.

Note that because of the fragmented nature of virtual memory, it can easily happen that the range [addr, addr + count) is not backed by a continuous region in our own virtual memory, which will make generating the slice impossible.

The iterator’s items are wrapped in Result, i.e. there may be errors reported on individual items. If there is no such error, the cumulative length of all items will be equal to count. Any error will end iteration immediately, i.e. there are no items past the first error.

If count is 0, an empty iterator will be returned.

Provided Methods§

Source

fn physical_memory(&self) -> Option<&Self::PhysicalMemory>

If this virtual memory is just a plain GuestMemoryBackend object underneath without an IOMMU translation layer in between, return that GuestMemoryBackend object.

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§

Source§

impl<M: GuestMemoryBackend + ?Sized> GuestMemory for M

Allow accessing every GuestMemoryBackend via GuestMemory.

GuestMemory is a generalization of GuestMemoryBackend: Every object implementing the former is a subset of an object implementing the latter (there always is an underlying GuestMemoryBackend), with an opaque internal mapping on top, e.g. provided by an IOMMU.

Every GuestMemoryBackend is therefore trivially also an GuestMemory, assuming a complete identity mapping (which we must assume, so that accessing such objects via either trait will yield the same result): Basically, all GuestMemory methods are implemented as trivial wrappers around the same GuestMemoryBackend methods (if available), discarding the access parameter.

Source§

impl<M: GuestMemoryBackend, I: Iommu> GuestMemory for IommuMemory<M, I>

Available on crate feature iommu only.