Skip to content

Commit 5398be2

Browse files
yiliu1765awilliam
authored andcommitted
vfio: Move the IOMMU_CAP_CACHE_COHERENCY check in __vfio_register_dev()
The IOMMU_CAP_CACHE_COHERENCY check only applies to the physical devices that are IOMMU-backed. But it is now in the group code. If want to compile vfio_group infrastructure out, this check needs to be moved out of the group code. Another reason for this change is to fail the device registration for the physical devices that do not have IOMMU if the group code is not compiled as the cdev interface does not support such devices. Suggested-by: Jason Gunthorpe <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Tested-by: Zhenzhong Duan <[email protected]> Tested-by: Yanting Jiang <[email protected]> Signed-off-by: Yi Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alex Williamson <[email protected]>
1 parent b290a05 commit 5398be2

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

drivers/vfio/group.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -682,16 +682,6 @@ static struct vfio_group *vfio_group_find_or_alloc(struct device *dev)
682682
if (!iommu_group)
683683
return ERR_PTR(-EINVAL);
684684

685-
/*
686-
* VFIO always sets IOMMU_CACHE because we offer no way for userspace to
687-
* restore cache coherency. It has to be checked here because it is only
688-
* valid for cases where we are using iommu groups.
689-
*/
690-
if (!device_iommu_capable(dev, IOMMU_CAP_CACHE_COHERENCY)) {
691-
iommu_group_put(iommu_group);
692-
return ERR_PTR(-EINVAL);
693-
}
694-
695685
mutex_lock(&vfio.group_lock);
696686
group = vfio_group_find_from_iommu(iommu_group);
697687
if (group) {

drivers/vfio/vfio_main.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,17 @@ static int __vfio_register_dev(struct vfio_device *device,
292292
if (ret)
293293
return ret;
294294

295+
/*
296+
* VFIO always sets IOMMU_CACHE because we offer no way for userspace to
297+
* restore cache coherency. It has to be checked here because it is only
298+
* valid for cases where we are using iommu groups.
299+
*/
300+
if (type == VFIO_IOMMU && !vfio_device_is_noiommu(device) &&
301+
!device_iommu_capable(device->dev, IOMMU_CAP_CACHE_COHERENCY)) {
302+
ret = -EINVAL;
303+
goto err_out;
304+
}
305+
295306
ret = vfio_device_add(device);
296307
if (ret)
297308
goto err_out;

0 commit comments

Comments
 (0)