Skip to content

Commit e1fa664

Browse files
nicolincjgunthorpe
authored andcommitted
iommufd/selftest: Add IOMMU_TEST_OP_MD_CHECK_IOTLB test op
Allow to test whether IOTLB has been invalidated or not. Link: https://lore.kernel.org/r/20240111041015.47920-6-yi.l.liu@intel.com Reviewed-by: Kevin Tian <kevin.tian@intel.com> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Yi Liu <yi.l.liu@intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent ac86912 commit e1fa664

4 files changed

Lines changed: 59 additions & 0 deletions

File tree

drivers/iommu/iommufd/iommufd_test.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ enum {
2121
IOMMU_TEST_OP_ACCESS_REPLACE_IOAS,
2222
IOMMU_TEST_OP_MOCK_DOMAIN_FLAGS,
2323
IOMMU_TEST_OP_DIRTY,
24+
IOMMU_TEST_OP_MD_CHECK_IOTLB,
2425
};
2526

2627
enum {
@@ -121,6 +122,10 @@ struct iommu_test_cmd {
121122
__aligned_u64 uptr;
122123
__aligned_u64 out_nr_dirty;
123124
} dirty;
125+
struct {
126+
__u32 id;
127+
__u32 iotlb;
128+
} check_iotlb;
124129
};
125130
__u32 last;
126131
};

drivers/iommu/iommufd/selftest.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,28 @@ static int iommufd_test_md_check_refs(struct iommufd_ucmd *ucmd,
843843
return 0;
844844
}
845845

846+
static int iommufd_test_md_check_iotlb(struct iommufd_ucmd *ucmd,
847+
u32 mockpt_id, unsigned int iotlb_id,
848+
u32 iotlb)
849+
{
850+
struct mock_iommu_domain_nested *mock_nested;
851+
struct iommufd_hw_pagetable *hwpt;
852+
int rc = 0;
853+
854+
hwpt = get_md_pagetable_nested(ucmd, mockpt_id, &mock_nested);
855+
if (IS_ERR(hwpt))
856+
return PTR_ERR(hwpt);
857+
858+
mock_nested = container_of(hwpt->domain,
859+
struct mock_iommu_domain_nested, domain);
860+
861+
if (iotlb_id > MOCK_NESTED_DOMAIN_IOTLB_ID_MAX ||
862+
mock_nested->iotlb[iotlb_id] != iotlb)
863+
rc = -EINVAL;
864+
iommufd_put_object(ucmd->ictx, &hwpt->obj);
865+
return rc;
866+
}
867+
846868
struct selftest_access {
847869
struct iommufd_access *access;
848870
struct file *file;
@@ -1324,6 +1346,10 @@ int iommufd_test(struct iommufd_ucmd *ucmd)
13241346
return iommufd_test_md_check_refs(
13251347
ucmd, u64_to_user_ptr(cmd->check_refs.uptr),
13261348
cmd->check_refs.length, cmd->check_refs.refs);
1349+
case IOMMU_TEST_OP_MD_CHECK_IOTLB:
1350+
return iommufd_test_md_check_iotlb(ucmd, cmd->id,
1351+
cmd->check_iotlb.id,
1352+
cmd->check_iotlb.iotlb);
13271353
case IOMMU_TEST_OP_CREATE_ACCESS:
13281354
return iommufd_test_create_access(ucmd, cmd->id,
13291355
cmd->create_access.flags);

tools/testing/selftests/iommu/iommufd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ TEST_F(iommufd_ioas, alloc_hwpt_nested)
330330
&nested_hwpt_id[1],
331331
IOMMU_HWPT_DATA_SELFTEST, &data,
332332
sizeof(data));
333+
test_cmd_hwpt_check_iotlb_all(nested_hwpt_id[0],
334+
IOMMU_TEST_IOTLB_DEFAULT);
335+
test_cmd_hwpt_check_iotlb_all(nested_hwpt_id[1],
336+
IOMMU_TEST_IOTLB_DEFAULT);
333337

334338
/* Negative test: a nested hwpt on top of a nested hwpt */
335339
test_err_hwpt_alloc_nested(EINVAL, self->device_id,

tools/testing/selftests/iommu/iommufd_utils.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,30 @@ static int _test_cmd_hwpt_alloc(int fd, __u32 device_id, __u32 pt_id,
195195
_test_cmd_hwpt_alloc(self->fd, device_id, pt_id, flags, \
196196
hwpt_id, data_type, data, data_len))
197197

198+
#define test_cmd_hwpt_check_iotlb(hwpt_id, iotlb_id, expected) \
199+
({ \
200+
struct iommu_test_cmd test_cmd = { \
201+
.size = sizeof(test_cmd), \
202+
.op = IOMMU_TEST_OP_MD_CHECK_IOTLB, \
203+
.id = hwpt_id, \
204+
.check_iotlb = { \
205+
.id = iotlb_id, \
206+
.iotlb = expected, \
207+
}, \
208+
}; \
209+
ASSERT_EQ(0, \
210+
ioctl(self->fd, \
211+
_IOMMU_TEST_CMD(IOMMU_TEST_OP_MD_CHECK_IOTLB), \
212+
&test_cmd)); \
213+
})
214+
215+
#define test_cmd_hwpt_check_iotlb_all(hwpt_id, expected) \
216+
({ \
217+
int i; \
218+
for (i = 0; i < MOCK_NESTED_DOMAIN_IOTLB_NUM; i++) \
219+
test_cmd_hwpt_check_iotlb(hwpt_id, i, expected); \
220+
})
221+
198222
static int _test_cmd_access_replace_ioas(int fd, __u32 access_id,
199223
unsigned int ioas_id)
200224
{

0 commit comments

Comments
 (0)