aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2022-07-11 10:02:03 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2022-07-11 10:02:03 -0700
commit816e51dfb5ba47e4f989af656c956a8c0cc686c0 (patch)
tree0e0cd62460265bc12b542add11c424455e2847c5 /drivers
parentfix race between exit_itimers() and /proc/pid/timers (diff)
parentvfio: Move IOMMU_CAP_CACHE_COHERENCY test to after we know we have a group (diff)
downloadlinux-dev-816e51dfb5ba47e4f989af656c956a8c0cc686c0.tar.xz
linux-dev-816e51dfb5ba47e4f989af656c956a8c0cc686c0.zip
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
Diffstat (limited to 'drivers')
-rw-r--r--drivers/vfio/vfio.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
index 61e71c1154be..e60b06f2ac22 100644
--- a/drivers/vfio/vfio.c
+++ b/drivers/vfio/vfio.c
@@ -549,6 +549,16 @@ static struct vfio_group *vfio_group_find_or_alloc(struct device *dev)
if (!iommu_group)
return ERR_PTR(-EINVAL);
+ /*
+ * VFIO always sets IOMMU_CACHE because we offer no way for userspace to
+ * restore cache coherency. It has to be checked here because it is only
+ * valid for cases where we are using iommu groups.
+ */
+ if (!iommu_capable(dev->bus, IOMMU_CAP_CACHE_COHERENCY)) {
+ iommu_group_put(iommu_group);
+ return ERR_PTR(-EINVAL);
+ }
+
group = vfio_group_get_from_iommu(iommu_group);
if (!group)
group = vfio_create_group(iommu_group, VFIO_IOMMU);
@@ -601,13 +611,6 @@ 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));
}