Merge tag 'vfio-v6.0-rc1' of https://github.com/awilliam/linux-vfio
[linux-2.6-microblaze.git] / drivers / vfio / vfio.c
index 8e23ca5..7cb56c3 100644 (file)
@@ -554,6 +554,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 (!device_iommu_capable(dev, 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);
@@ -606,13 +616,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 (!device_iommu_capable(device->dev, IOMMU_CAP_CACHE_COHERENCY))
-               return -EINVAL;
-
        return __vfio_register_dev(device,
                vfio_group_find_or_alloc(device->dev));
 }
@@ -1141,7 +1144,7 @@ static struct file *vfio_device_open(struct vfio_device *device)
         * Appears to be missing by lack of need rather than
         * explicitly prevented.  Now there's need.
         */
-       filep->f_mode |= (FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE);
+       filep->f_mode |= (FMODE_PREAD | FMODE_PWRITE);
 
        if (device->group->type == VFIO_NO_IOMMU)
                dev_warn(device->dev, "vfio-noiommu device opened by user "