Skip to content

Commit

Permalink
vfio: Require that devices support DMA cache coherence
Browse files Browse the repository at this point in the history
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 <kevin.tian@intel.com>
Acked-by: Alex Williamson <alex.williamson@redhat.com>
Acked-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/4-v3-2cf356649677+a32-intel_no_snoop_jgg@nvidia.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
  • Loading branch information
jgunthorpe authored and joergroedel committed Apr 28, 2022
1 parent f78dc1d commit e8ae0e1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions drivers/vfio/vfio.c
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,13 @@ static int __vfio_register_dev(struct vfio_device *device,

int vfio_register_group_dev(struct vfio_device *device)
{
/*
* VFIO always sets IOMMU_CACHE because we offer no way for userspace to
* restore cache coherency.
*/
if (!iommu_capable(device->dev->bus, IOMMU_CAP_CACHE_COHERENCY))
return -EINVAL;

return __vfio_register_dev(device,
vfio_group_find_or_alloc(device->dev));
}
Expand Down

0 comments on commit e8ae0e1

Please sign in to comment.