IommuMemory

Struct IommuMemory 

Source
pub struct IommuMemory<M: GuestMemoryBackend, I: Iommu> { /* private fields */ }
Available on crate feature iommu only.
Expand description

GuestMemory type that consists of an underlying GuestMemoryBackend object plus an Iommu.

The underlying GuestMemoryBackend is basically the physical memory, and the Iommu translates the I/O virtual address space that IommuMemory provides into that underlying physical address space.

Note that this type’s implementation of memory write tracking (“logging”) is specific to what is required by vhost-user:

That is, there are two bitmap levels, one in the underlying GuestMemoryBackend, and one in IommuMemory. The former is used when the IOMMU is disabled, the latter when it is enabled.

If you need a different model (e.g. always use the GuestMemoryBackend bitmaps), you should not use this type.

Implementations§

Source§

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

Source

pub fn new( backend: M, iommu: I, use_iommu: bool, bitmap: <Self as GuestMemory>::Bitmap, ) -> Self

Create a new IommuMemory instance.

Source

pub fn with_replaced_backend(&self, new_backend: M) -> Self

Create a new version of self with the underlying physical memory replaced.

Note that the inner Arc references to the IOMMU and bitmap are cloned, i.e. both the existing and the new IommuMemory object will share the IOMMU and bitmap instances. (The use_iommu flag however is copied, so is independent between the two instances.)

Source

pub fn bitmap(&self) -> &Arc<<Self as GuestMemory>::Bitmap>

Return a reference to the IOVA address space’s dirty bitmap.

This bitmap tracks write accesses done while the IOMMU is enabled.

Source

pub fn set_iommu_enabled(&mut self, enabled: bool)

Enable or disable the IOMMU.

Disabling the IOMMU switches to pass-through mode, where every access is done directly on the underlying physical memory.

Source

pub fn get_iommu_enabled(&self) -> bool

Check whether the IOMMU is enabled.

If the IOMMU is disabled, we operate in pass-through mode, where every access is done directly on the underlying physical memory.

Source

pub fn iommu(&self) -> &Arc<I>

Return a reference to the IOMMU.

Source

pub fn get_backend(&self) -> &M

Return a reference to the underlying physical memory object.

Trait Implementations§

Source§

impl<M: GuestMemoryBackend + Clone, I: Iommu> Clone for IommuMemory<M, I>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<M: GuestMemoryBackend + Debug, I: Iommu> Debug for IommuMemory<M, I>
where <M::R as GuestMemoryRegion>::B: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<M: GuestMemoryBackend + Default, I: Iommu + Default> Default for IommuMemory<M, I>
where <M::R as GuestMemoryRegion>::B: Default,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

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

Source§

type PhysicalMemory = M

Underlying GuestMemoryBackend type.
Source§

type Bitmap = <<M as GuestMemoryBackend>::R as GuestMemoryRegion>::B

Dirty bitmap type for tracking writes to the IOVA address space.
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, ) -> GuestMemoryResult<impl GuestMemorySliceIterator<'a, BS<'a, Self::Bitmap>>>

Returns a VolatileSlice of count bytes starting at addr. Read more
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.

Auto Trait Implementations§

§

impl<M, I> Freeze for IommuMemory<M, I>
where M: Freeze,

§

impl<M, I> RefUnwindSafe for IommuMemory<M, I>

§

impl<M, I> Send for IommuMemory<M, I>
where M: Send, <<M as GuestMemoryBackend>::R as GuestMemoryRegion>::B: Sync + Send,

§

impl<M, I> Sync for IommuMemory<M, I>
where M: Sync, <<M as GuestMemoryBackend>::R as GuestMemoryRegion>::B: Sync + Send,

§

impl<M, I> Unpin for IommuMemory<M, I>
where M: Unpin,

§

impl<M, I> UnwindSafe for IommuMemory<M, I>

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> Bytes<GuestAddress> for T
where T: GuestMemory + ?Sized,

Source§

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

§Examples
  • Write a slice at guestaddress 0x1000. (uses the backend-mmap feature)
gm.write_slice(&[1, 2, 3, 4, 5], start_addr)
    .expect("Could not write slice to guest memory");
Source§

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

§Examples
  • Read a slice of length 16 at guestaddress 0x1000. (uses the backend-mmap feature)
let start_addr = GuestAddress(0x1000);
let mut gm = GuestMemoryMmap::<()>::from_ranges(&vec![(start_addr, 0x400)])
    .expect("Could not create guest memory");
let buf = &mut [0u8; 16];

gm.read_slice(buf, start_addr)
    .expect("Could not read slice from guest memory");
Source§

type E = Error

Associated error codes
Source§

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

Writes a slice into the container at addr. Read more
Source§

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

Reads data from the container at addr into a slice. Read more
Source§

fn read_volatile_from<F>( &self, addr: GuestAddress, src: &mut F, count: usize, ) -> Result<usize, Error>
where F: ReadVolatile,

Reads up to count bytes from src and writes them into the container at addr. Unlike VolatileRead::read_volatile, this function retries on EINTR being returned from the underlying I/O read operation. Read more
Source§

fn read_exact_volatile_from<F>( &self, addr: GuestAddress, src: &mut F, count: usize, ) -> Result<(), Error>
where F: ReadVolatile,

Reads exactly count bytes from an object and writes them into the container at addr. Read more
Source§

fn write_volatile_to<F>( &self, addr: GuestAddress, dst: &mut F, count: usize, ) -> Result<usize, Error>
where F: WriteVolatile,

Reads up to count bytes from the container at addr and writes them into dst. Unlike VolatileWrite::write_volatile, this function retries on EINTR being returned by the underlying I/O write operation. Read more
Source§

fn write_all_volatile_to<F>( &self, addr: GuestAddress, dst: &mut F, count: usize, ) -> Result<(), Error>
where F: WriteVolatile,

Reads exactly count bytes from the container at addr and writes them into an object. Read more
Source§

fn store<O>( &self, val: O, addr: GuestAddress, order: Ordering, ) -> Result<(), Error>
where O: AtomicAccess,

Atomically store a value at the specified address.
Source§

fn load<O>(&self, addr: GuestAddress, order: Ordering) -> Result<O, Error>
where O: AtomicAccess,

Atomically load a value from the specified address.
Source§

fn write_obj<T: ByteValued>(&self, val: T, addr: A) -> Result<(), Self::E>

Writes an object into the container at addr. Read more
Source§

fn read_obj<T: ByteValued>(&self, addr: A) -> Result<T, Self::E>

Reads an object from the container at addr. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.