Skip to content

Commit 068e140

Browse files
yiliu1765jgunthorpe
authored andcommitted
iommufd/selftest: Add a helper to get test device
There is need to get the selftest device (sobj->type == TYPE_IDEV) in multiple places, so have a helper to for it. Link: https://patch.msgid.link/r/[email protected] Reviewed-by: Nicolin Chen <[email protected]> Signed-off-by: Yi Liu <[email protected]> Tested-by: Nicolin Chen <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 9eb5920 commit 068e140

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

drivers/iommu/iommufd/selftest.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -996,39 +996,49 @@ static int iommufd_test_mock_domain(struct iommufd_ucmd *ucmd,
996996
return rc;
997997
}
998998

999-
/* Replace the mock domain with a manually allocated hw_pagetable */
1000-
static int iommufd_test_mock_domain_replace(struct iommufd_ucmd *ucmd,
1001-
unsigned int device_id, u32 pt_id,
1002-
struct iommu_test_cmd *cmd)
999+
static struct selftest_obj *
1000+
iommufd_test_get_selftest_obj(struct iommufd_ctx *ictx, u32 id)
10031001
{
10041002
struct iommufd_object *dev_obj;
10051003
struct selftest_obj *sobj;
1006-
int rc;
10071004

10081005
/*
10091006
* Prefer to use the OBJ_SELFTEST because the destroy_rwsem will ensure
10101007
* it doesn't race with detach, which is not allowed.
10111008
*/
1012-
dev_obj =
1013-
iommufd_get_object(ucmd->ictx, device_id, IOMMUFD_OBJ_SELFTEST);
1009+
dev_obj = iommufd_get_object(ictx, id, IOMMUFD_OBJ_SELFTEST);
10141010
if (IS_ERR(dev_obj))
1015-
return PTR_ERR(dev_obj);
1011+
return ERR_CAST(dev_obj);
10161012

10171013
sobj = to_selftest_obj(dev_obj);
10181014
if (sobj->type != TYPE_IDEV) {
1019-
rc = -EINVAL;
1020-
goto out_dev_obj;
1015+
iommufd_put_object(ictx, dev_obj);
1016+
return ERR_PTR(-EINVAL);
10211017
}
1018+
return sobj;
1019+
}
1020+
1021+
/* Replace the mock domain with a manually allocated hw_pagetable */
1022+
static int iommufd_test_mock_domain_replace(struct iommufd_ucmd *ucmd,
1023+
unsigned int device_id, u32 pt_id,
1024+
struct iommu_test_cmd *cmd)
1025+
{
1026+
struct selftest_obj *sobj;
1027+
int rc;
1028+
1029+
sobj = iommufd_test_get_selftest_obj(ucmd->ictx, device_id);
1030+
if (IS_ERR(sobj))
1031+
return PTR_ERR(sobj);
10221032

10231033
rc = iommufd_device_replace(sobj->idev.idev, IOMMU_NO_PASID, &pt_id);
10241034
if (rc)
1025-
goto out_dev_obj;
1035+
goto out_sobj;
10261036

10271037
cmd->mock_domain_replace.pt_id = pt_id;
10281038
rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
10291039

1030-
out_dev_obj:
1031-
iommufd_put_object(ucmd->ictx, dev_obj);
1040+
out_sobj:
1041+
iommufd_put_object(ucmd->ictx, &sobj->obj);
10321042
return rc;
10331043
}
10341044

0 commit comments

Comments
 (0)