Skip to content

Commit 816e51d

Browse files
committed
Merge tag 'vfio-v5.19-rc7' of https://github.com/awilliam/linux-vfio
Pull VFIO fix from Alex Williamson: - Move IOMMU test to unbreak no-iommu support (Jason Gunthorpe) * tag 'vfio-v5.19-rc7' of https://github.com/awilliam/linux-vfio: vfio: Move IOMMU_CAP_CACHE_COHERENCY test to after we know we have a group
2 parents d5b36a4 + afe4e37 commit 816e51d

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

drivers/vfio/vfio.c

Lines changed: 10 additions & 7 deletions
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)