vfio-iommufd: Make vfio_iommufd_emulated_bind() return iommufd_access ID
authorYi Liu <yi.l.liu@intel.com>
Mon, 27 Mar 2023 09:33:49 +0000 (02:33 -0700)
committerJason Gunthorpe <jgg@nvidia.com>
Fri, 31 Mar 2023 16:43:32 +0000 (13:43 -0300)
vfio device cdev needs to return iommufd_access ID to userspace if
bind_iommufd succeeds.

Link: https://lore.kernel.org/r/20230327093351.44505-5-yi.l.liu@intel.com
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Tested-by: Terrence Xu <terrence.xu@intel.com>
Tested-by: Nicolin Chen <nicolinc@nvidia.com>
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
Acked-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/iommu/iommufd/device.c
drivers/iommu/iommufd/selftest.c
drivers/vfio/iommufd.c
include/linux/iommufd.h

index ff6fca0ea269b1dfa72dbb6c43678be7c3fc55c0..4b565a5b51dab64634c111316ce613a158eb40c4 100644 (file)
@@ -425,6 +425,7 @@ void iommufd_access_destroy_object(struct iommufd_object *obj)
  * @ictx: iommufd file descriptor
  * @ops: Driver's ops to associate with the access
  * @data: Opaque data to pass into ops functions
+ * @id: Output ID number to return to userspace for this access
  *
  * An iommufd_access allows a driver to read/write to the IOAS without using
  * DMA. The underlying CPU memory can be accessed using the
@@ -434,7 +435,7 @@ void iommufd_access_destroy_object(struct iommufd_object *obj)
  */
 struct iommufd_access *
 iommufd_access_create(struct iommufd_ctx *ictx,
-                     const struct iommufd_access_ops *ops, void *data)
+                     const struct iommufd_access_ops *ops, void *data, u32 *id)
 {
        struct iommufd_access *access;
 
@@ -459,6 +460,7 @@ iommufd_access_create(struct iommufd_ctx *ictx,
        access->ictx = ictx;
        iommufd_ctx_get(ictx);
        iommufd_object_finalize(ictx, &access->obj);
+       *id = access->obj.id;
        return access;
 }
 EXPORT_SYMBOL_NS_GPL(iommufd_access_create, IOMMUFD);
index 1e89e1a8c5f0774564804dbe7e06ae3578259b2b..e6e04dceffe3d48799074b14699b1865acc6f723 100644 (file)
@@ -554,6 +554,7 @@ static int iommufd_test_create_access(struct iommufd_ucmd *ucmd,
        struct iommu_test_cmd *cmd = ucmd->cmd;
        struct selftest_access *staccess;
        struct iommufd_access *access;
+       u32 id;
        int fdno;
        int rc;
 
@@ -575,7 +576,7 @@ static int iommufd_test_create_access(struct iommufd_ucmd *ucmd,
                (flags & MOCK_FLAGS_ACCESS_CREATE_NEEDS_PIN_PAGES) ?
                        &selftest_access_ops_pin :
                        &selftest_access_ops,
-               staccess);
+               staccess, &id);
        if (IS_ERR(access)) {
                rc = PTR_ERR(access);
                goto out_put_fdno;
index 78e2486586d76d340a6df49d8f8a3f862b359aa0..1ee558c0be2560490a92c513c325edab9f8b970b 100644 (file)
@@ -142,7 +142,7 @@ int vfio_iommufd_emulated_bind(struct vfio_device *vdev,
 
        lockdep_assert_held(&vdev->dev_set->lock);
 
-       user = iommufd_access_create(ictx, &vfio_user_ops, vdev);
+       user = iommufd_access_create(ictx, &vfio_user_ops, vdev, out_device_id);
        if (IS_ERR(user))
                return PTR_ERR(user);
        vdev->iommufd_access = user;
index 155d3630aedcd55110dfcd2b09c6684fa8eec989..1129a36a74c44217d03c8b03f94800903b036d9d 100644 (file)
@@ -41,7 +41,7 @@ enum {
 
 struct iommufd_access *
 iommufd_access_create(struct iommufd_ctx *ictx,
-                     const struct iommufd_access_ops *ops, void *data);
+                     const struct iommufd_access_ops *ops, void *data, u32 *id);
 void iommufd_access_destroy(struct iommufd_access *access);
 int iommufd_access_attach(struct iommufd_access *access, u32 ioas_id);