Skip to main content

DmaTarget

Trait DmaTarget 

Source
pub trait DmaTarget: Send + Sync {
    // Required methods
    unsafe fn map_dma(
        &self,
        range: MemoryRange,
        host_va: Option<*const u8>,
        mappable: &Mappable,
        file_offset: u64,
    ) -> Result<()>;
    fn unmap_dma(&self, range: MemoryRange) -> Result<()>;
}
Expand description

A consumer of IOMMU-granularity DMA mapping events.

Unlike PartitionMemoryMap, which maps entire regions by VA pointer for lazy SLAT resolution, this trait receives individual sub-mapping events with the backing fd + offset, suitable for explicit IOMMU programming (VFIO type1, iommufd, etc.).

DMA targets receive notifications for all active sub-mappings, including device BAR memory (regions with dma_target: false). The dma_target flag controls only whether a region is exposed via GuestMemorySharing (for vhost-user); IOMMU consumers need the full GPA→backing map to program identity mappings for all guest-visible memory.

Implementations must be Send + Sync because they are stored behind Arc in the region manager task.

Required Methods§

Source

unsafe fn map_dma( &self, range: MemoryRange, host_va: Option<*const u8>, mappable: &Mappable, file_offset: u64, ) -> Result<()>

Program an IOMMU mapping for range to the backing described by mappable at file_offset.

host_va is the host virtual address of the mapping, provided when the target was registered with needs_va = true. When None, the implementation should use mappable and file_offset directly (e.g., iommufd).

§Safety

When host_va is Some, the pointed-to memory must be backed and must not be unmapped for the duration of the resulting IOMMU mapping. The caller (the crate-internal DmaMapper) guarantees this by holding an Arc<VaMapper> and calling ensure_mapped before each invocation.

Source

fn unmap_dma(&self, range: MemoryRange) -> Result<()>

Remove IOMMU mappings within range.

The region manager may call this with a range that covers multiple prior map_dma calls (e.g., unmapping an entire region at once even though individual sub-mappings were mapped separately). The range will always be aligned to mapping boundaries — it will not bisect any prior mapping. Gaps within the range (unmapped sub-ranges) are expected and must not cause errors.

Implementors§