Skip to content

Commit 632fda7

Browse files
yiliu1765jgunthorpe
authored andcommitted
vfio-iommufd: Make vfio_iommufd_emulated_bind() return iommufd_access ID
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>
1 parent 4508a53 commit 632fda7

4 files changed

Lines changed: 7 additions & 4 deletions

File tree

drivers/iommu/iommufd/device.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ void iommufd_access_destroy_object(struct iommufd_object *obj)
425425
* @ictx: iommufd file descriptor
426426
* @ops: Driver's ops to associate with the access
427427
* @data: Opaque data to pass into ops functions
428+
* @id: Output ID number to return to userspace for this access
428429
*
429430
* An iommufd_access allows a driver to read/write to the IOAS without using
430431
* DMA. The underlying CPU memory can be accessed using the
@@ -434,7 +435,7 @@ void iommufd_access_destroy_object(struct iommufd_object *obj)
434435
*/
435436
struct iommufd_access *
436437
iommufd_access_create(struct iommufd_ctx *ictx,
437-
const struct iommufd_access_ops *ops, void *data)
438+
const struct iommufd_access_ops *ops, void *data, u32 *id)
438439
{
439440
struct iommufd_access *access;
440441

@@ -459,6 +460,7 @@ iommufd_access_create(struct iommufd_ctx *ictx,
459460
access->ictx = ictx;
460461
iommufd_ctx_get(ictx);
461462
iommufd_object_finalize(ictx, &access->obj);
463+
*id = access->obj.id;
462464
return access;
463465
}
464466
EXPORT_SYMBOL_NS_GPL(iommufd_access_create, IOMMUFD);

drivers/iommu/iommufd/selftest.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ static int iommufd_test_create_access(struct iommufd_ucmd *ucmd,
554554
struct iommu_test_cmd *cmd = ucmd->cmd;
555555
struct selftest_access *staccess;
556556
struct iommufd_access *access;
557+
u32 id;
557558
int fdno;
558559
int rc;
559560

@@ -575,7 +576,7 @@ static int iommufd_test_create_access(struct iommufd_ucmd *ucmd,
575576
(flags & MOCK_FLAGS_ACCESS_CREATE_NEEDS_PIN_PAGES) ?
576577
&selftest_access_ops_pin :
577578
&selftest_access_ops,
578-
staccess);
579+
staccess, &id);
579580
if (IS_ERR(access)) {
580581
rc = PTR_ERR(access);
581582
goto out_put_fdno;

drivers/vfio/iommufd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ int vfio_iommufd_emulated_bind(struct vfio_device *vdev,
142142

143143
lockdep_assert_held(&vdev->dev_set->lock);
144144

145-
user = iommufd_access_create(ictx, &vfio_user_ops, vdev);
145+
user = iommufd_access_create(ictx, &vfio_user_ops, vdev, out_device_id);
146146
if (IS_ERR(user))
147147
return PTR_ERR(user);
148148
vdev->iommufd_access = user;

include/linux/iommufd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ enum {
4141

4242
struct iommufd_access *
4343
iommufd_access_create(struct iommufd_ctx *ictx,
44-
const struct iommufd_access_ops *ops, void *data);
44+
const struct iommufd_access_ops *ops, void *data, u32 *id);
4545
void iommufd_access_destroy(struct iommufd_access *access);
4646
int iommufd_access_attach(struct iommufd_access *access, u32 ioas_id);
4747

0 commit comments

Comments
 (0)