Skip to content

Commit 7a467e0

Browse files
committed
iommufd/selftest: Return the real idev id from selftest mock_domain
Now that we actually call iommufd_device_bind() we can return the idev_id from that function to userspace for use in other APIs. Link: https://lore.kernel.org/r/18-v8-6659224517ea+532-iommufd_alloc_jgg@nvidia.com Reviewed-by: Kevin Tian <kevin.tian@intel.com> Tested-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 7074d7b commit 7a467e0

File tree

5 files changed

+29
-21
lines changed

5 files changed

+29
-21
lines changed

drivers/iommu/iommufd/iommufd_test.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ struct iommu_test_cmd {
5252
struct {
5353
__u32 out_stdev_id;
5454
__u32 out_hwpt_id;
55+
/* out_idev_id is the standard iommufd_bind object */
56+
__u32 out_idev_id;
5557
} mock_domain;
5658
struct {
5759
__u32 pt_id;

drivers/iommu/iommufd/selftest.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ static int iommufd_test_mock_domain(struct iommufd_ucmd *ucmd,
443443
/* Userspace must destroy the device_id to destroy the object */
444444
cmd->mock_domain.out_hwpt_id = pt_id;
445445
cmd->mock_domain.out_stdev_id = sobj->obj.id;
446+
cmd->mock_domain.out_idev_id = idev_id;
446447
iommufd_object_finalize(ucmd->ictx, &sobj->obj);
447448
return iommufd_ucmd_respond(ucmd, sizeof(*cmd));
448449

tools/testing/selftests/iommu/iommufd.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ FIXTURE_SETUP(iommufd_ioas)
211211

212212
for (i = 0; i != variant->mock_domains; i++) {
213213
test_cmd_mock_domain(self->ioas_id, &self->stdev_id,
214-
&self->hwpt_id);
214+
&self->hwpt_id, NULL);
215215
self->base_iova = MOCK_APERTURE_START;
216216
}
217217
}
@@ -262,7 +262,7 @@ TEST_F(iommufd_ioas, hwpt_attach)
262262
{
263263
/* Create a device attached directly to a hwpt */
264264
if (self->stdev_id) {
265-
test_cmd_mock_domain(self->hwpt_id, NULL, NULL);
265+
test_cmd_mock_domain(self->hwpt_id, NULL, NULL, NULL);
266266
} else {
267267
test_err_mock_domain(ENOENT, self->hwpt_id, NULL, NULL);
268268
}
@@ -681,7 +681,7 @@ TEST_F(iommufd_ioas, access_pin)
681681
_IOMMU_TEST_CMD(IOMMU_TEST_OP_ACCESS_PAGES),
682682
&access_cmd));
683683
test_cmd_mock_domain(self->ioas_id, &mock_stdev_id,
684-
&mock_hwpt_id);
684+
&mock_hwpt_id, NULL);
685685
check_map_cmd.id = mock_hwpt_id;
686686
ASSERT_EQ(0, ioctl(self->fd,
687687
_IOMMU_TEST_CMD(IOMMU_TEST_OP_MD_CHECK_MAP),
@@ -836,7 +836,7 @@ TEST_F(iommufd_ioas, fork_gone)
836836
* If a domain already existed then everything was pinned within
837837
* the fork, so this copies from one domain to another.
838838
*/
839-
test_cmd_mock_domain(self->ioas_id, NULL, NULL);
839+
test_cmd_mock_domain(self->ioas_id, NULL, NULL, NULL);
840840
check_access_rw(_metadata, self->fd, access_id,
841841
MOCK_APERTURE_START, 0);
842842

@@ -885,7 +885,7 @@ TEST_F(iommufd_ioas, fork_present)
885885
ASSERT_EQ(8, read(efd, &tmp, sizeof(tmp)));
886886

887887
/* Read pages from the remote process */
888-
test_cmd_mock_domain(self->ioas_id, NULL, NULL);
888+
test_cmd_mock_domain(self->ioas_id, NULL, NULL, NULL);
889889
check_access_rw(_metadata, self->fd, access_id, MOCK_APERTURE_START, 0);
890890

891891
ASSERT_EQ(0, close(pipefds[1]));
@@ -1033,6 +1033,7 @@ FIXTURE(iommufd_mock_domain)
10331033
uint32_t hwpt_id;
10341034
uint32_t hwpt_ids[2];
10351035
uint32_t stdev_ids[2];
1036+
uint32_t idev_ids[2];
10361037
int mmap_flags;
10371038
size_t mmap_buf_size;
10381039
};
@@ -1055,7 +1056,7 @@ FIXTURE_SETUP(iommufd_mock_domain)
10551056

10561057
for (i = 0; i != variant->mock_domains; i++)
10571058
test_cmd_mock_domain(self->ioas_id, &self->stdev_ids[i],
1058-
&self->hwpt_ids[i]);
1059+
&self->hwpt_ids[i], &self->idev_ids[i]);
10591060
self->hwpt_id = self->hwpt_ids[0];
10601061

10611062
self->mmap_flags = MAP_SHARED | MAP_ANONYMOUS;
@@ -1249,7 +1250,7 @@ TEST_F(iommufd_mock_domain, all_aligns_copy)
12491250
/* Add and destroy a domain while the area exists */
12501251
old_id = self->hwpt_ids[1];
12511252
test_cmd_mock_domain(self->ioas_id, &mock_stdev_id,
1252-
&self->hwpt_ids[1]);
1253+
&self->hwpt_ids[1], NULL);
12531254

12541255
check_mock_iova(buf + start, iova, length);
12551256
check_refs(buf + start / PAGE_SIZE * PAGE_SIZE,
@@ -1458,7 +1459,7 @@ FIXTURE_SETUP(vfio_compat_mock_domain)
14581459

14591460
/* Create what VFIO would consider a group */
14601461
test_ioctl_ioas_alloc(&self->ioas_id);
1461-
test_cmd_mock_domain(self->ioas_id, NULL, NULL);
1462+
test_cmd_mock_domain(self->ioas_id, NULL, NULL, NULL);
14621463

14631464
/* Attach it to the vfio compat */
14641465
vfio_ioas_cmd.ioas_id = self->ioas_id;

tools/testing/selftests/iommu/iommufd_fail_nth.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ TEST_FAIL_NTH(basic_fail_nth, map_domain)
315315

316316
fail_nth_enable();
317317

318-
if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, &hwpt_id))
318+
if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, &hwpt_id, NULL))
319319
return -1;
320320

321321
if (_test_ioctl_ioas_map(self->fd, ioas_id, buffer, 262144, &iova,
@@ -326,7 +326,7 @@ TEST_FAIL_NTH(basic_fail_nth, map_domain)
326326
if (_test_ioctl_destroy(self->fd, stdev_id))
327327
return -1;
328328

329-
if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, &hwpt_id))
329+
if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, &hwpt_id, NULL))
330330
return -1;
331331
return 0;
332332
}
@@ -350,12 +350,13 @@ TEST_FAIL_NTH(basic_fail_nth, map_two_domains)
350350
if (_test_ioctl_set_temp_memory_limit(self->fd, 32))
351351
return -1;
352352

353-
if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, &hwpt_id))
353+
if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, &hwpt_id, NULL))
354354
return -1;
355355

356356
fail_nth_enable();
357357

358-
if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id2, &hwpt_id2))
358+
if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id2, &hwpt_id2,
359+
NULL))
359360
return -1;
360361

361362
if (_test_ioctl_ioas_map(self->fd, ioas_id, buffer, 262144, &iova,
@@ -369,9 +370,10 @@ TEST_FAIL_NTH(basic_fail_nth, map_two_domains)
369370
if (_test_ioctl_destroy(self->fd, stdev_id2))
370371
return -1;
371372

372-
if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, &hwpt_id))
373+
if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, &hwpt_id, NULL))
373374
return -1;
374-
if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id2, &hwpt_id2))
375+
if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id2, &hwpt_id2,
376+
NULL))
375377
return -1;
376378
return 0;
377379
}
@@ -528,7 +530,7 @@ TEST_FAIL_NTH(basic_fail_nth, access_pin_domain)
528530
if (_test_ioctl_set_temp_memory_limit(self->fd, 32))
529531
return -1;
530532

531-
if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, &hwpt_id))
533+
if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, &hwpt_id, NULL))
532534
return -1;
533535

534536
if (_test_ioctl_ioas_map(self->fd, ioas_id, buffer, BUFFER_SIZE, &iova,
@@ -603,7 +605,7 @@ TEST_FAIL_NTH(basic_fail_nth, device)
603605

604606
fail_nth_enable();
605607

606-
if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, NULL))
608+
if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, NULL, NULL))
607609
return -1;
608610

609611
if (_test_cmd_mock_domain_replace(self->fd, stdev_id, ioas_id2, NULL))

tools/testing/selftests/iommu/iommufd_utils.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static unsigned long PAGE_SIZE;
4141
})
4242

4343
static int _test_cmd_mock_domain(int fd, unsigned int ioas_id, __u32 *stdev_id,
44-
__u32 *hwpt_id)
44+
__u32 *hwpt_id, __u32 *idev_id)
4545
{
4646
struct iommu_test_cmd cmd = {
4747
.size = sizeof(cmd),
@@ -59,14 +59,16 @@ static int _test_cmd_mock_domain(int fd, unsigned int ioas_id, __u32 *stdev_id,
5959
assert(cmd.id != 0);
6060
if (hwpt_id)
6161
*hwpt_id = cmd.mock_domain.out_hwpt_id;
62+
if (idev_id)
63+
*idev_id = cmd.mock_domain.out_idev_id;
6264
return 0;
6365
}
64-
#define test_cmd_mock_domain(ioas_id, stdev_id, hwpt_id) \
65-
ASSERT_EQ(0, \
66-
_test_cmd_mock_domain(self->fd, ioas_id, stdev_id, hwpt_id))
66+
#define test_cmd_mock_domain(ioas_id, stdev_id, hwpt_id, idev_id) \
67+
ASSERT_EQ(0, _test_cmd_mock_domain(self->fd, ioas_id, stdev_id, \
68+
hwpt_id, idev_id))
6769
#define test_err_mock_domain(_errno, ioas_id, stdev_id, hwpt_id) \
6870
EXPECT_ERRNO(_errno, _test_cmd_mock_domain(self->fd, ioas_id, \
69-
stdev_id, hwpt_id))
71+
stdev_id, hwpt_id, NULL))
7072

7173
static int _test_cmd_mock_domain_replace(int fd, __u32 stdev_id, __u32 pt_id,
7274
__u32 *hwpt_id)

0 commit comments

Comments
 (0)