Skip to content
This repository was archived by the owner on Oct 3, 2024. It is now read-only.

Commit afe4e37

Browse files
jgunthorpeawilliam
authored andcommitted
vfio: Move IOMMU_CAP_CACHE_COHERENCY test to after we know we have a group
The test isn't going to work if a group doesn't exist. Normally this isn't a problem since VFIO isn't going to create a device if there is no group, but the special CONFIG_VFIO_NOIOMMU behavior allows bypassing this prevention. The new cap test effectively forces a group and breaks this config option. Move the cap test to vfio_group_find_or_alloc() which is the earliest time we know we have a group available and thus are not running in noiommu mode. Fixes: e8ae0e1 ("vfio: Require that devices support DMA cache coherence") Reported-by: Xiang Chen <[email protected]> Tested-by: Xiang Chen <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alex Williamson <[email protected]>
1 parent 88084a3 commit afe4e37

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

drivers/vfio/vfio.c

+10-7
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,16 @@ static struct vfio_group *vfio_group_find_or_alloc(struct device *dev)
549549
if (!iommu_group)
550550
return ERR_PTR(-EINVAL);
551551

552+
/*
553+
* VFIO always sets IOMMU_CACHE because we offer no way for userspace to
554+
* restore cache coherency. It has to be checked here because it is only
555+
* valid for cases where we are using iommu groups.
556+
*/
557+
if (!iommu_capable(dev->bus, IOMMU_CAP_CACHE_COHERENCY)) {
558+
iommu_group_put(iommu_group);
559+
return ERR_PTR(-EINVAL);
560+
}
561+
552562
group = vfio_group_get_from_iommu(iommu_group);
553563
if (!group)
554564
group = vfio_create_group(iommu_group, VFIO_IOMMU);
@@ -601,13 +611,6 @@ static int __vfio_register_dev(struct vfio_device *device,
601611

602612
int vfio_register_group_dev(struct vfio_device *device)
603613
{
604-
/*
605-
* VFIO always sets IOMMU_CACHE because we offer no way for userspace to
606-
* restore cache coherency.
607-
*/
608-
if (!iommu_capable(device->dev->bus, IOMMU_CAP_CACHE_COHERENCY))
609-
return -EINVAL;
610-
611614
return __vfio_register_dev(device,
612615
vfio_group_find_or_alloc(device->dev));
613616
}

0 commit comments

Comments
 (0)