Skip to content

Commit 576ad6e

Browse files
nicolincjgunthorpe
authored andcommitted
iommufd/selftest: Add IOMMU_TEST_OP_DEV_CHECK_CACHE test command
Similar to IOMMU_TEST_OP_MD_CHECK_IOTLB verifying a mock_domain's iotlb, IOMMU_TEST_OP_DEV_CHECK_CACHE will be used to verify a mock_dev's cache. Link: https://patch.msgid.link/r/cd4082079d75427bd67ed90c3c825e15b5720a5f.1730836308.git.nicolinc@nvidia.com Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Signed-off-by: Nicolin Chen <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent d6563aa commit 576ad6e

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

drivers/iommu/iommufd/iommufd_test.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ enum {
2323
IOMMU_TEST_OP_DIRTY,
2424
IOMMU_TEST_OP_MD_CHECK_IOTLB,
2525
IOMMU_TEST_OP_TRIGGER_IOPF,
26+
IOMMU_TEST_OP_DEV_CHECK_CACHE,
2627
};
2728

2829
enum {
@@ -140,6 +141,10 @@ struct iommu_test_cmd {
140141
__u32 perm;
141142
__u64 addr;
142143
} trigger_iopf;
144+
struct {
145+
__u32 id;
146+
__u32 cache;
147+
} check_dev_cache;
143148
};
144149
__u32 last;
145150
};

drivers/iommu/iommufd/selftest.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,24 @@ static int iommufd_test_md_check_iotlb(struct iommufd_ucmd *ucmd,
11251125
return rc;
11261126
}
11271127

1128+
static int iommufd_test_dev_check_cache(struct iommufd_ucmd *ucmd, u32 idev_id,
1129+
unsigned int cache_id, u32 cache)
1130+
{
1131+
struct iommufd_device *idev;
1132+
struct mock_dev *mdev;
1133+
int rc = 0;
1134+
1135+
idev = iommufd_get_device(ucmd, idev_id);
1136+
if (IS_ERR(idev))
1137+
return PTR_ERR(idev);
1138+
mdev = container_of(idev->dev, struct mock_dev, dev);
1139+
1140+
if (cache_id > MOCK_DEV_CACHE_ID_MAX || mdev->cache[cache_id] != cache)
1141+
rc = -EINVAL;
1142+
iommufd_put_object(ucmd->ictx, &idev->obj);
1143+
return rc;
1144+
}
1145+
11281146
struct selftest_access {
11291147
struct iommufd_access *access;
11301148
struct file *file;
@@ -1634,6 +1652,10 @@ int iommufd_test(struct iommufd_ucmd *ucmd)
16341652
return iommufd_test_md_check_iotlb(ucmd, cmd->id,
16351653
cmd->check_iotlb.id,
16361654
cmd->check_iotlb.iotlb);
1655+
case IOMMU_TEST_OP_DEV_CHECK_CACHE:
1656+
return iommufd_test_dev_check_cache(ucmd, cmd->id,
1657+
cmd->check_dev_cache.id,
1658+
cmd->check_dev_cache.cache);
16371659
case IOMMU_TEST_OP_CREATE_ACCESS:
16381660
return iommufd_test_create_access(ucmd, cmd->id,
16391661
cmd->create_access.flags);

tools/testing/selftests/iommu/iommufd.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ FIXTURE_SETUP(iommufd_ioas)
227227
for (i = 0; i != variant->mock_domains; i++) {
228228
test_cmd_mock_domain(self->ioas_id, &self->stdev_id,
229229
&self->hwpt_id, &self->device_id);
230+
test_cmd_dev_check_cache_all(self->device_id,
231+
IOMMU_TEST_DEV_CACHE_DEFAULT);
230232
self->base_iova = MOCK_APERTURE_START;
231233
}
232234
}
@@ -1392,9 +1394,12 @@ FIXTURE_SETUP(iommufd_mock_domain)
13921394

13931395
ASSERT_GE(ARRAY_SIZE(self->hwpt_ids), variant->mock_domains);
13941396

1395-
for (i = 0; i != variant->mock_domains; i++)
1397+
for (i = 0; i != variant->mock_domains; i++) {
13961398
test_cmd_mock_domain(self->ioas_id, &self->stdev_ids[i],
13971399
&self->hwpt_ids[i], &self->idev_ids[i]);
1400+
test_cmd_dev_check_cache_all(self->idev_ids[0],
1401+
IOMMU_TEST_DEV_CACHE_DEFAULT);
1402+
}
13981403
self->hwpt_id = self->hwpt_ids[0];
13991404

14001405
self->mmap_flags = MAP_SHARED | MAP_ANONYMOUS;

tools/testing/selftests/iommu/iommufd_utils.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,30 @@ static int _test_cmd_hwpt_alloc(int fd, __u32 device_id, __u32 pt_id, __u32 ft_i
250250
test_cmd_hwpt_check_iotlb(hwpt_id, i, expected); \
251251
})
252252

253+
#define test_cmd_dev_check_cache(device_id, cache_id, expected) \
254+
({ \
255+
struct iommu_test_cmd test_cmd = { \
256+
.size = sizeof(test_cmd), \
257+
.op = IOMMU_TEST_OP_DEV_CHECK_CACHE, \
258+
.id = device_id, \
259+
.check_dev_cache = { \
260+
.id = cache_id, \
261+
.cache = expected, \
262+
}, \
263+
}; \
264+
ASSERT_EQ(0, ioctl(self->fd, \
265+
_IOMMU_TEST_CMD( \
266+
IOMMU_TEST_OP_DEV_CHECK_CACHE), \
267+
&test_cmd)); \
268+
})
269+
270+
#define test_cmd_dev_check_cache_all(device_id, expected) \
271+
({ \
272+
int c; \
273+
for (c = 0; c < MOCK_DEV_CACHE_NUM; c++) \
274+
test_cmd_dev_check_cache(device_id, c, expected); \
275+
})
276+
253277
static int _test_cmd_hwpt_invalidate(int fd, __u32 hwpt_id, void *reqs,
254278
uint32_t data_type, uint32_t lreq,
255279
uint32_t *nreqs)

0 commit comments

Comments
 (0)