[Intel-gfx] [PATCH v10 10/22] vfio-iommufd: Move noiommu compat probe out of vfio_iommufd_bind()
Yi Liu
yi.l.liu at intel.com
Wed Apr 26 15:03:09 UTC 2023
into vfio_device_group_open(). This is more consistent with what will
be done in vfio device cdev path.
Reviewed-by: Kevin Tian <kevin.tian at intel.com>
Tested-by: Terrence Xu <terrence.xu at intel.com>
Tested-by: Nicolin Chen <nicolinc at nvidia.com>
Tested-by: Yanting Jiang <yanting.jiang at intel.com>
Signed-off-by: Yi Liu <yi.l.liu at intel.com>
---
drivers/vfio/group.c | 6 ++++++
drivers/vfio/iommufd.c | 32 +++++++++++++++++++-------------
drivers/vfio/vfio.h | 9 +++++++++
3 files changed, 34 insertions(+), 13 deletions(-)
diff --git a/drivers/vfio/group.c b/drivers/vfio/group.c
index 5ed84fdd3aea..7955f7513eaf 100644
--- a/drivers/vfio/group.c
+++ b/drivers/vfio/group.c
@@ -192,6 +192,12 @@ static int vfio_device_group_open(struct vfio_device_file *df)
vfio_device_group_get_kvm_safe(device);
df->iommufd = device->group->iommufd;
+ if (df->iommufd && device->noiommu && device->open_count == 0) {
+ ret = vfio_iommufd_compat_probe_noiommu(device,
+ df->iommufd);
+ if (ret)
+ goto out_put_kvm;
+ }
ret = vfio_device_open(df);
if (ret) {
diff --git a/drivers/vfio/iommufd.c b/drivers/vfio/iommufd.c
index 54ac7be49b80..b0d0024b2980 100644
--- a/drivers/vfio/iommufd.c
+++ b/drivers/vfio/iommufd.c
@@ -10,6 +10,24 @@
MODULE_IMPORT_NS(IOMMUFD);
MODULE_IMPORT_NS(IOMMUFD_VFIO);
+int vfio_iommufd_compat_probe_noiommu(struct vfio_device *device,
+ struct iommufd_ctx *ictx)
+{
+ u32 ioas_id;
+
+ if (!capable(CAP_SYS_RAWIO))
+ return -EPERM;
+
+ /*
+ * Require no compat ioas to be assigned to proceed. The basic
+ * statement is that the user cannot have done something that
+ * implies they expected translation to exist
+ */
+ if (!iommufd_vfio_compat_ioas_get_id(ictx, &ioas_id))
+ return -EPERM;
+ return 0;
+}
+
int vfio_iommufd_bind(struct vfio_device *vdev, struct iommufd_ctx *ictx)
{
u32 ioas_id;
@@ -18,20 +36,8 @@ int vfio_iommufd_bind(struct vfio_device *vdev, struct iommufd_ctx *ictx)
lockdep_assert_held(&vdev->dev_set->lock);
- if (vdev->noiommu) {
- if (!capable(CAP_SYS_RAWIO))
- return -EPERM;
-
- /*
- * Require no compat ioas to be assigned to proceed. The basic
- * statement is that the user cannot have done something that
- * implies they expected translation to exist
- */
- if (!iommufd_vfio_compat_ioas_get_id(ictx, &ioas_id))
- return -EPERM;
-
+ if (vdev->noiommu)
return vfio_iommufd_emulated_bind(vdev, ictx, &device_id);
- }
ret = vdev->ops->bind_iommufd(vdev, ictx, &device_id);
if (ret)
diff --git a/drivers/vfio/vfio.h b/drivers/vfio/vfio.h
index 084227ef6023..c1a4f3920cc5 100644
--- a/drivers/vfio/vfio.h
+++ b/drivers/vfio/vfio.h
@@ -235,9 +235,18 @@ static inline void vfio_container_cleanup(void)
#endif
#if IS_ENABLED(CONFIG_IOMMUFD)
+int vfio_iommufd_compat_probe_noiommu(struct vfio_device *device,
+ struct iommufd_ctx *ictx);
int vfio_iommufd_bind(struct vfio_device *device, struct iommufd_ctx *ictx);
void vfio_iommufd_unbind(struct vfio_device *device);
#else
+static inline int
+vfio_iommufd_compat_probe_noiommu(struct vfio_device *device,
+ struct iommufd_ctx *ictx)
+{
+ return -EOPNOTSUPP;
+}
+
static inline int vfio_iommufd_bind(struct vfio_device *device,
struct iommufd_ctx *ictx)
{
--
2.34.1
More information about the Intel-gfx
mailing list