Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <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>

authored by

Jason Gunthorpe and committed by
Joerg Roedel
e8ae0e14 f78dc1da

+7
+7
drivers/vfio/vfio.c
··· 815 815 816 816 int vfio_register_group_dev(struct vfio_device *device) 817 817 { 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 + 818 825 return __vfio_register_dev(device, 819 826 vfio_group_find_or_alloc(device->dev)); 820 827 }