Skip to content

Commit b25e271

Browse files
jacobpanawilliam
authored andcommitted
vfio: Fix unbalanced vfio_df_close call in no-iommu mode
For devices with no-iommu enabled in IOMMUFD VFIO compat mode, the group open path skips vfio_df_open(), leaving open_count at 0. This causes a warning in vfio_assert_device_open(device) when vfio_df_close() is called during group close. The correct behavior is to skip only the IOMMUFD bind in the device open path for no-iommu devices. Commit 6086efe omitted vfio_df_open(), which was too broad. This patch restores the previous behavior, ensuring the vfio_df_open is called in the group open path. Fixes: 6086efe ("vfio-iommufd: Move noiommu compat validation out of vfio_iommufd_bind()") Suggested-by: Alex Williamson <[email protected]> Suggested-by: Jason Gunthorpe <[email protected]> Signed-off-by: Jacob Pan <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alex Williamson <[email protected]>
1 parent d7b8f8e commit b25e271

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

drivers/vfio/group.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,10 @@ static int vfio_df_group_open(struct vfio_device_file *df)
192192
* implies they expected translation to exist
193193
*/
194194
if (!capable(CAP_SYS_RAWIO) ||
195-
vfio_iommufd_device_has_compat_ioas(device, df->iommufd))
195+
vfio_iommufd_device_has_compat_ioas(device, df->iommufd)) {
196196
ret = -EPERM;
197-
else
198-
ret = 0;
199-
goto out_put_kvm;
197+
goto out_put_kvm;
198+
}
200199
}
201200

202201
ret = vfio_df_open(df);

drivers/vfio/iommufd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ int vfio_df_iommufd_bind(struct vfio_device_file *df)
2525

2626
lockdep_assert_held(&vdev->dev_set->lock);
2727

28+
/* Returns 0 to permit device opening under noiommu mode */
29+
if (vfio_device_is_noiommu(vdev))
30+
return 0;
31+
2832
return vdev->ops->bind_iommufd(vdev, ictx, &df->devid);
2933
}
3034

0 commit comments

Comments
 (0)