Skip to main content

DmaTarget

Trait DmaTarget 

Source
pub trait DmaTarget: Send + Sync {
    // Required methods
    unsafe fn map_dma(&self, request: DmaMapRequest<'_>) -> 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 (MappingType::Device regions). The mapping type controls whether a region is exposed via GuestMemorySharing (for vhost-user) and whether IOMMU mapping failures are fatal; 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, request: DmaMapRequest<'_>) -> Result<()>

Program an IOMMU mapping.

§Safety

request.host_va always points to backed memory that 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> whose mappings are established eagerly by the mapping manager. The IOMMU mapping will be torn down (via unmap_dma) before the VaMapper releases the VA range.

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§