Skip to content

Commit c154660

Browse files
nicolincjgunthorpe
authored andcommitted
iommufd/selftest: Add IOMMU_TEST_OP_ACCESS_REPLACE_IOAS coverage
Add a new IOMMU_TEST_OP_ACCESS_REPLACE_IOAS to allow replacing the access->ioas, corresponding to the iommufd_access_replace() helper. Then add replace coverage as a part of user_copy test case, which basically repeats the copy test after replacing the old ioas with a new one. Link: https://lore.kernel.org/r/a4897f93d41c34b972213243b8dbf4c3832842e4.1690523699.git.nicolinc@nvidia.com Reviewed-by: Kevin Tian <kevin.tian@intel.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 70c1612 commit c154660

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed

drivers/iommu/iommufd/iommufd_test.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum {
1818
IOMMU_TEST_OP_ACCESS_RW,
1919
IOMMU_TEST_OP_SET_TEMP_MEMORY_LIMIT,
2020
IOMMU_TEST_OP_MOCK_DOMAIN_REPLACE,
21+
IOMMU_TEST_OP_ACCESS_REPLACE_IOAS,
2122
};
2223

2324
enum {
@@ -91,6 +92,9 @@ struct iommu_test_cmd {
9192
struct {
9293
__u32 limit;
9394
} memory_limit;
95+
struct {
96+
__u32 ioas_id;
97+
} access_replace_ioas;
9498
};
9599
__u32 last;
96100
};

drivers/iommu/iommufd/selftest.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,22 @@ static int iommufd_test_create_access(struct iommufd_ucmd *ucmd,
785785
return rc;
786786
}
787787

788+
static int iommufd_test_access_replace_ioas(struct iommufd_ucmd *ucmd,
789+
unsigned int access_id,
790+
unsigned int ioas_id)
791+
{
792+
struct selftest_access *staccess;
793+
int rc;
794+
795+
staccess = iommufd_access_get(access_id);
796+
if (IS_ERR(staccess))
797+
return PTR_ERR(staccess);
798+
799+
rc = iommufd_access_replace(staccess->access, ioas_id);
800+
fput(staccess->file);
801+
return rc;
802+
}
803+
788804
/* Check that the pages in a page array match the pages in the user VA */
789805
static int iommufd_test_check_pages(void __user *uptr, struct page **pages,
790806
size_t npages)
@@ -1000,6 +1016,9 @@ int iommufd_test(struct iommufd_ucmd *ucmd)
10001016
case IOMMU_TEST_OP_CREATE_ACCESS:
10011017
return iommufd_test_create_access(ucmd, cmd->id,
10021018
cmd->create_access.flags);
1019+
case IOMMU_TEST_OP_ACCESS_REPLACE_IOAS:
1020+
return iommufd_test_access_replace_ioas(
1021+
ucmd, cmd->id, cmd->access_replace_ioas.ioas_id);
10031022
case IOMMU_TEST_OP_ACCESS_PAGES:
10041023
return iommufd_test_access_pages(
10051024
ucmd, cmd->id, cmd->access_pages.iova,

tools/testing/selftests/iommu/iommufd.c

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,13 @@ TEST_F(iommufd_mock_domain, user_copy)
12831283
.dst_iova = MOCK_APERTURE_START,
12841284
.length = BUFFER_SIZE,
12851285
};
1286-
unsigned int ioas_id;
1286+
struct iommu_ioas_unmap unmap_cmd = {
1287+
.size = sizeof(unmap_cmd),
1288+
.ioas_id = self->ioas_id,
1289+
.iova = MOCK_APERTURE_START,
1290+
.length = BUFFER_SIZE,
1291+
};
1292+
unsigned int new_ioas_id, ioas_id;
12871293

12881294
/* Pin the pages in an IOAS with no domains then copy to an IOAS with domains */
12891295
test_ioctl_ioas_alloc(&ioas_id);
@@ -1301,11 +1307,30 @@ TEST_F(iommufd_mock_domain, user_copy)
13011307
ASSERT_EQ(0, ioctl(self->fd, IOMMU_IOAS_COPY, &copy_cmd));
13021308
check_mock_iova(buffer, MOCK_APERTURE_START, BUFFER_SIZE);
13031309

1310+
/* Now replace the ioas with a new one */
1311+
test_ioctl_ioas_alloc(&new_ioas_id);
1312+
test_ioctl_ioas_map_id(new_ioas_id, buffer, BUFFER_SIZE,
1313+
&copy_cmd.src_iova);
1314+
test_cmd_access_replace_ioas(access_cmd.id, new_ioas_id);
1315+
1316+
/* Destroy the old ioas and cleanup copied mapping */
1317+
ASSERT_EQ(0, ioctl(self->fd, IOMMU_IOAS_UNMAP, &unmap_cmd));
1318+
test_ioctl_destroy(ioas_id);
1319+
1320+
/* Then run the same test again with the new ioas */
1321+
access_cmd.access_pages.iova = copy_cmd.src_iova;
1322+
ASSERT_EQ(0,
1323+
ioctl(self->fd, _IOMMU_TEST_CMD(IOMMU_TEST_OP_ACCESS_PAGES),
1324+
&access_cmd));
1325+
copy_cmd.src_ioas_id = new_ioas_id;
1326+
ASSERT_EQ(0, ioctl(self->fd, IOMMU_IOAS_COPY, &copy_cmd));
1327+
check_mock_iova(buffer, MOCK_APERTURE_START, BUFFER_SIZE);
1328+
13041329
test_cmd_destroy_access_pages(
13051330
access_cmd.id, access_cmd.access_pages.out_access_pages_id);
13061331
test_cmd_destroy_access(access_cmd.id);
13071332

1308-
test_ioctl_destroy(ioas_id);
1333+
test_ioctl_destroy(new_ioas_id);
13091334
}
13101335

13111336
TEST_F(iommufd_mock_domain, replace)

tools/testing/selftests/iommu/iommufd_utils.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,25 @@ static int _test_cmd_hwpt_alloc(int fd, __u32 device_id, __u32 pt_id,
119119
#define test_cmd_hwpt_alloc(device_id, pt_id, hwpt_id) \
120120
ASSERT_EQ(0, _test_cmd_hwpt_alloc(self->fd, device_id, pt_id, hwpt_id))
121121

122+
static int _test_cmd_access_replace_ioas(int fd, __u32 access_id,
123+
unsigned int ioas_id)
124+
{
125+
struct iommu_test_cmd cmd = {
126+
.size = sizeof(cmd),
127+
.op = IOMMU_TEST_OP_ACCESS_REPLACE_IOAS,
128+
.id = access_id,
129+
.access_replace_ioas = { .ioas_id = ioas_id },
130+
};
131+
int ret;
132+
133+
ret = ioctl(fd, IOMMU_TEST_CMD, &cmd);
134+
if (ret)
135+
return ret;
136+
return 0;
137+
}
138+
#define test_cmd_access_replace_ioas(access_id, ioas_id) \
139+
ASSERT_EQ(0, _test_cmd_access_replace_ioas(self->fd, access_id, ioas_id))
140+
122141
static int _test_cmd_create_access(int fd, unsigned int ioas_id,
123142
__u32 *access_id, unsigned int flags)
124143
{

0 commit comments

Comments
 (0)