Skip to content

Commit e04b23c

Browse files
jpemartinsjgunthorpe
authored andcommitted
iommufd/selftest: Expand mock_domain with dev_flags
Expand mock_domain test to be able to manipulate the device capabilities. This allows testing with mockdev without dirty tracking support advertised and thus make sure enforce_dirty test does the expected. To avoid breaking IOMMUFD_TEST UABI replicate the mock_domain struct and thus add an input dev_flags at the end. Link: https://lore.kernel.org/r/20231024135109.73787-14-joao.m.martins@oracle.com Signed-off-by: Joao Martins <joao.m.martins@oracle.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent f35f22c commit e04b23c

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

drivers/iommu/iommufd/iommufd_test.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ enum {
1919
IOMMU_TEST_OP_SET_TEMP_MEMORY_LIMIT,
2020
IOMMU_TEST_OP_MOCK_DOMAIN_REPLACE,
2121
IOMMU_TEST_OP_ACCESS_REPLACE_IOAS,
22+
IOMMU_TEST_OP_MOCK_DOMAIN_FLAGS,
2223
};
2324

2425
enum {
@@ -40,6 +41,10 @@ enum {
4041
MOCK_FLAGS_ACCESS_CREATE_NEEDS_PIN_PAGES = 1 << 0,
4142
};
4243

44+
enum {
45+
MOCK_FLAGS_DEVICE_NO_DIRTY = 1 << 0,
46+
};
47+
4348
struct iommu_test_cmd {
4449
__u32 size;
4550
__u32 op;
@@ -56,6 +61,13 @@ struct iommu_test_cmd {
5661
/* out_idev_id is the standard iommufd_bind object */
5762
__u32 out_idev_id;
5863
} mock_domain;
64+
struct {
65+
__u32 out_stdev_id;
66+
__u32 out_hwpt_id;
67+
__u32 out_idev_id;
68+
/* Expand mock_domain to set mock device flags */
69+
__u32 dev_flags;
70+
} mock_domain_flags;
5971
struct {
6072
__u32 pt_id;
6173
} mock_domain_replace;

drivers/iommu/iommufd/selftest.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ enum selftest_obj_type {
9696

9797
struct mock_dev {
9898
struct device dev;
99+
unsigned long flags;
99100
};
100101

101102
struct selftest_obj {
@@ -381,7 +382,7 @@ static void mock_dev_release(struct device *dev)
381382
kfree(mdev);
382383
}
383384

384-
static struct mock_dev *mock_dev_create(void)
385+
static struct mock_dev *mock_dev_create(unsigned long dev_flags)
385386
{
386387
struct mock_dev *mdev;
387388
int rc;
@@ -391,6 +392,7 @@ static struct mock_dev *mock_dev_create(void)
391392
return ERR_PTR(-ENOMEM);
392393

393394
device_initialize(&mdev->dev);
395+
mdev->flags = dev_flags;
394396
mdev->dev.release = mock_dev_release;
395397
mdev->dev.bus = &iommufd_mock_bus_type.bus;
396398

@@ -426,6 +428,7 @@ static int iommufd_test_mock_domain(struct iommufd_ucmd *ucmd,
426428
struct iommufd_device *idev;
427429
struct selftest_obj *sobj;
428430
u32 pt_id = cmd->id;
431+
u32 dev_flags = 0;
429432
u32 idev_id;
430433
int rc;
431434

@@ -436,7 +439,10 @@ static int iommufd_test_mock_domain(struct iommufd_ucmd *ucmd,
436439
sobj->idev.ictx = ucmd->ictx;
437440
sobj->type = TYPE_IDEV;
438441

439-
sobj->idev.mock_dev = mock_dev_create();
442+
if (cmd->op == IOMMU_TEST_OP_MOCK_DOMAIN_FLAGS)
443+
dev_flags = cmd->mock_domain_flags.dev_flags;
444+
445+
sobj->idev.mock_dev = mock_dev_create(dev_flags);
440446
if (IS_ERR(sobj->idev.mock_dev)) {
441447
rc = PTR_ERR(sobj->idev.mock_dev);
442448
goto out_sobj;
@@ -1019,6 +1025,7 @@ int iommufd_test(struct iommufd_ucmd *ucmd)
10191025
cmd->add_reserved.start,
10201026
cmd->add_reserved.length);
10211027
case IOMMU_TEST_OP_MOCK_DOMAIN:
1028+
case IOMMU_TEST_OP_MOCK_DOMAIN_FLAGS:
10221029
return iommufd_test_mock_domain(ucmd, cmd);
10231030
case IOMMU_TEST_OP_MOCK_DOMAIN_REPLACE:
10241031
return iommufd_test_mock_domain_replace(

tools/testing/selftests/iommu/iommufd_utils.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,35 @@ static int _test_cmd_mock_domain(int fd, unsigned int ioas_id, __u32 *stdev_id,
7474
EXPECT_ERRNO(_errno, _test_cmd_mock_domain(self->fd, ioas_id, \
7575
stdev_id, hwpt_id, NULL))
7676

77+
static int _test_cmd_mock_domain_flags(int fd, unsigned int ioas_id,
78+
__u32 stdev_flags, __u32 *stdev_id,
79+
__u32 *hwpt_id, __u32 *idev_id)
80+
{
81+
struct iommu_test_cmd cmd = {
82+
.size = sizeof(cmd),
83+
.op = IOMMU_TEST_OP_MOCK_DOMAIN_FLAGS,
84+
.id = ioas_id,
85+
.mock_domain_flags = { .dev_flags = stdev_flags },
86+
};
87+
int ret;
88+
89+
ret = ioctl(fd, IOMMU_TEST_CMD, &cmd);
90+
if (ret)
91+
return ret;
92+
if (stdev_id)
93+
*stdev_id = cmd.mock_domain_flags.out_stdev_id;
94+
assert(cmd.id != 0);
95+
if (hwpt_id)
96+
*hwpt_id = cmd.mock_domain_flags.out_hwpt_id;
97+
if (idev_id)
98+
*idev_id = cmd.mock_domain_flags.out_idev_id;
99+
return 0;
100+
}
101+
#define test_err_mock_domain_flags(_errno, ioas_id, flags, stdev_id, hwpt_id) \
102+
EXPECT_ERRNO(_errno, \
103+
_test_cmd_mock_domain_flags(self->fd, ioas_id, flags, \
104+
stdev_id, hwpt_id, NULL))
105+
77106
static int _test_cmd_mock_domain_replace(int fd, __u32 stdev_id, __u32 pt_id,
78107
__u32 *hwpt_id)
79108
{

0 commit comments

Comments
 (0)