vfio/region: Skip IOMMU mapping for BARs when dma-buf is unavailable
PATCH 1/1 vfio/region: Skip IOMMU mapping for BARs when dma-buf is unavailable
When the kernel does not support the VFIO_DEVICE_FEATURE_DMA_BUF feature (e.g. old kernel or out-of-tree vGPU driver), vfio_region_create_dma_buf() returns with a warning and no fd is assigned to the BAR RAMBlocks. Later, when the VFIO listener tries to DMA-map these BAR regions, the iommufd backend falls back to IOMMU_IOAS_MAP with a vaddr pointing at device MMIO. The kernel cannot pin device memory and fails with EFAULT on aarch64, producing these warnings:
qemu-kvm: warning: VFIO dma-buf not supported in kernel, using mmap fallback, P2P DMA will not work
qemu-kvm: warning: IOMMU_IOAS_MAP failed: Bad address, PCI BAR?
qemu-kvm: warning: vfio_container_dma_map(0xaaabb9621a90, 0x88400000000, 0x10000, 0xfffe50100000) = -14 (Bad address)
hostdev0: PCI peer-to-peer transactions on BARs are not supported.
memory_region_set_skip_iommu_map() was recently introduced by commit 11b9798c7b52 ("memory: Allow RAM device regions to skip IOMMU mapping") for the Tegra CMDQV case. Use it to mark BAR mmap regions when dma-buf is unavailable so the VFIO listener skips them. This drops the last three messages and covers both the iommufd and legacy Type1 IOMMU backends.
--- hw/vfio/region.c | 3 +++ 1 file changed, 3 insertions(+)
hw/vfio/region.c +3 -0
@@ -362,6 +362,9 @@ static bool vfio_region_create_dma_buf(VFIORegion *region, Error **errp)if (ret == -ENOTTY ) {warn_report_once ("VFIO dma-buf not supported in kernel, " "using mmap fallback, P2P DMA will not work" ); +for (i =0 ; i < region->nr_mmaps; i++) { +memory_region_set_skip_iommu_map (®ion->mmaps[i].mem, true); + }return true; } error_setg_errno(errp, -ret, "%s: dma-buf unavailable, "
Signature · 1 line
2.56.0