Skip to content

Commit e8ae0e1

Browse files
jgunthorpejoergroedel
authored andcommitted
vfio: Require that devices support DMA cache coherence
IOMMU_CACHE means that normal DMAs do not require any additional coherency mechanism and is the basic uAPI that VFIO exposes to userspace. For instance VFIO applications like DPDK will not work if additional coherency operations are required. Therefore check IOMMU_CAP_CACHE_COHERENCY like vdpa & usnic do before allowing an IOMMU backed VFIO device to be created. Reviewed-by: Kevin Tian <[email protected]> Acked-by: Alex Williamson <[email protected]> Acked-by: Robin Murphy <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent f78dc1d commit e8ae0e1

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

drivers/vfio/vfio.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,13 @@ static int __vfio_register_dev(struct vfio_device *device,
815815

816816
int vfio_register_group_dev(struct vfio_device *device)
817817
{
818+
/*
819+
* VFIO always sets IOMMU_CACHE because we offer no way for userspace to
820+
* restore cache coherency.
821+
*/
822+
if (!iommu_capable(device->dev->bus, IOMMU_CAP_CACHE_COHERENCY))
823+
return -EINVAL;
824+
818825
return __vfio_register_dev(device,
819826
vfio_group_find_or_alloc(device->dev));
820827
}

0 commit comments

Comments
 (0)