pub struct IommuMemory<M: GuestMemoryBackend, I: Iommu> { /* private fields */ }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:
- When the IOMMU is disabled (
IommuMemory::set_iommu_enabled()), writes to memory are tracked by the underlyingGuestMemoryBackendin its bitmap(s). - When it is enabled, they are instead tracked in the
IommuMemory’s dirty bitmap; the offset in the bitmap is calculated from the write’s IOVA.
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>
impl<M: GuestMemoryBackend, I: Iommu> IommuMemory<M, I>
Sourcepub fn new(
backend: M,
iommu: I,
use_iommu: bool,
bitmap: <Self as GuestMemory>::Bitmap,
) -> Self
pub fn new( backend: M, iommu: I, use_iommu: bool, bitmap: <Self as GuestMemory>::Bitmap, ) -> Self
Create a new IommuMemory instance.
Sourcepub fn with_replaced_backend(&self, new_backend: M) -> Self
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.)
Sourcepub fn bitmap(&self) -> &Arc<<Self as GuestMemory>::Bitmap>
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.
Sourcepub fn set_iommu_enabled(&mut self, enabled: bool)
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.
Sourcepub fn get_iommu_enabled(&self) -> bool
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.
Sourcepub fn get_backend(&self) -> &M
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>
impl<M: GuestMemoryBackend + Clone, I: Iommu> Clone for IommuMemory<M, I>
Source§impl<M: GuestMemoryBackend + Debug, I: Iommu> Debug for IommuMemory<M, I>
impl<M: GuestMemoryBackend + Debug, I: Iommu> Debug for IommuMemory<M, I>
Source§impl<M: GuestMemoryBackend + Default, I: Iommu + Default> Default for IommuMemory<M, I>
impl<M: GuestMemoryBackend + Default, I: Iommu + Default> Default for IommuMemory<M, I>
Source§impl<M: GuestMemoryBackend, I: Iommu> GuestMemory for IommuMemory<M, I>
impl<M: GuestMemoryBackend, I: Iommu> GuestMemory for IommuMemory<M, I>
Source§type PhysicalMemory = M
type PhysicalMemory = M
GuestMemoryBackend type.Source§type Bitmap = <<M as GuestMemoryBackend>::R as GuestMemoryRegion>::B
type Bitmap = <<M as GuestMemoryBackend>::R as GuestMemoryRegion>::B
Source§fn check_range(
&self,
addr: GuestAddress,
count: usize,
access: Permissions,
) -> bool
fn check_range( &self, addr: GuestAddress, count: usize, access: Permissions, ) -> bool
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>>>
fn get_slices<'a>( &'a self, addr: GuestAddress, count: usize, access: Permissions, ) -> GuestMemoryResult<impl GuestMemorySliceIterator<'a, BS<'a, Self::Bitmap>>>
Source§fn physical_memory(&self) -> Option<&Self::PhysicalMemory>
fn physical_memory(&self) -> Option<&Self::PhysicalMemory>
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>where
M: RefUnwindSafe,
I: RefUnwindSafe,
<<M as GuestMemoryBackend>::R as GuestMemoryRegion>::B: RefUnwindSafe,
impl<M, I> Send for IommuMemory<M, I>
impl<M, I> Sync for IommuMemory<M, I>
impl<M, I> Unpin for IommuMemory<M, I>where
M: Unpin,
impl<M, I> UnwindSafe for IommuMemory<M, I>where
M: UnwindSafe,
I: RefUnwindSafe,
<<M as GuestMemoryBackend>::R as GuestMemoryRegion>::B: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Bytes<GuestAddress> for Twhere
T: GuestMemory + ?Sized,
impl<T> Bytes<GuestAddress> for Twhere
T: GuestMemory + ?Sized,
Source§fn write_slice(&self, buf: &[u8], addr: GuestAddress) -> Result<(), Error>
fn write_slice(&self, buf: &[u8], addr: GuestAddress) -> Result<(), Error>
§Examples
- Write a slice at guestaddress 0x1000. (uses the
backend-mmapfeature)
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>
fn read_slice(&self, buf: &mut [u8], addr: GuestAddress) -> Result<(), Error>
§Examples
- Read a slice of length 16 at guestaddress 0x1000. (uses the
backend-mmapfeature)
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§fn write(&self, buf: &[u8], addr: GuestAddress) -> Result<usize, Error>
fn write(&self, buf: &[u8], addr: GuestAddress) -> Result<usize, Error>
addr. Read moreSource§fn read(&self, buf: &mut [u8], addr: GuestAddress) -> Result<usize, Error>
fn read(&self, buf: &mut [u8], addr: GuestAddress) -> Result<usize, Error>
addr into a slice. Read moreSource§fn read_volatile_from<F>(
&self,
addr: GuestAddress,
src: &mut F,
count: usize,
) -> Result<usize, Error>where
F: ReadVolatile,
fn read_volatile_from<F>(
&self,
addr: GuestAddress,
src: &mut F,
count: usize,
) -> Result<usize, Error>where
F: ReadVolatile,
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 moreSource§fn read_exact_volatile_from<F>(
&self,
addr: GuestAddress,
src: &mut F,
count: usize,
) -> Result<(), Error>where
F: ReadVolatile,
fn read_exact_volatile_from<F>(
&self,
addr: GuestAddress,
src: &mut F,
count: usize,
) -> Result<(), Error>where
F: ReadVolatile,
Source§fn write_volatile_to<F>(
&self,
addr: GuestAddress,
dst: &mut F,
count: usize,
) -> Result<usize, Error>where
F: WriteVolatile,
fn write_volatile_to<F>(
&self,
addr: GuestAddress,
dst: &mut F,
count: usize,
) -> Result<usize, Error>where
F: WriteVolatile,
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