Skip to content

Commit ae36fe7

Browse files
jpemartinsjgunthorpe
authored andcommitted
iommufd/selftest: Test out_capabilities in IOMMU_GET_HW_INFO
Enumerate the capabilities from the mock device and test whether it advertises as expected. Include it as part of the iommufd_dirty_tracking fixture. Link: https://lore.kernel.org/r/20231024135109.73787-18-joao.m.martins@oracle.com Signed-off-by: Joao Martins <joao.m.martins@oracle.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent a9af47e commit ae36fe7

File tree

4 files changed

+45
-11
lines changed

4 files changed

+45
-11
lines changed

drivers/iommu/iommufd/selftest.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,18 @@ static phys_addr_t mock_domain_iova_to_phys(struct iommu_domain *domain,
376376

377377
static bool mock_domain_capable(struct device *dev, enum iommu_cap cap)
378378
{
379-
return cap == IOMMU_CAP_CACHE_COHERENCY;
379+
struct mock_dev *mdev = container_of(dev, struct mock_dev, dev);
380+
381+
switch (cap) {
382+
case IOMMU_CAP_CACHE_COHERENCY:
383+
return true;
384+
case IOMMU_CAP_DIRTY_TRACKING:
385+
return !(mdev->flags & MOCK_FLAGS_DEVICE_NO_DIRTY);
386+
default:
387+
break;
388+
}
389+
390+
return false;
380391
}
381392

382393
static void mock_domain_set_plaform_dma_ops(struct device *dev)

tools/testing/selftests/iommu/iommufd.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,6 +1563,23 @@ TEST_F(iommufd_dirty_tracking, set_dirty_tracking)
15631563
test_ioctl_destroy(hwpt_id);
15641564
}
15651565

1566+
TEST_F(iommufd_dirty_tracking, device_dirty_capability)
1567+
{
1568+
uint32_t caps = 0;
1569+
uint32_t stddev_id;
1570+
uint32_t hwpt_id;
1571+
1572+
test_cmd_hwpt_alloc(self->idev_id, self->ioas_id, 0, &hwpt_id);
1573+
test_cmd_mock_domain(hwpt_id, &stddev_id, NULL, NULL);
1574+
test_cmd_get_hw_capabilities(self->idev_id, caps,
1575+
IOMMU_HW_CAP_DIRTY_TRACKING);
1576+
ASSERT_EQ(IOMMU_HW_CAP_DIRTY_TRACKING,
1577+
caps & IOMMU_HW_CAP_DIRTY_TRACKING);
1578+
1579+
test_ioctl_destroy(stddev_id);
1580+
test_ioctl_destroy(hwpt_id);
1581+
}
1582+
15661583
TEST_F(iommufd_dirty_tracking, get_dirty_bitmap)
15671584
{
15681585
uint32_t stddev_id;

tools/testing/selftests/iommu/iommufd_fail_nth.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ TEST_FAIL_NTH(basic_fail_nth, device)
612612
&idev_id))
613613
return -1;
614614

615-
if (_test_cmd_get_hw_info(self->fd, idev_id, &info, sizeof(info)))
615+
if (_test_cmd_get_hw_info(self->fd, idev_id, &info, sizeof(info), NULL))
616616
return -1;
617617

618618
if (_test_cmd_hwpt_alloc(self->fd, idev_id, ioas_id, 0, &hwpt_id))

tools/testing/selftests/iommu/iommufd_utils.h

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -535,15 +535,16 @@ static void teardown_iommufd(int fd, struct __test_metadata *_metadata)
535535
#endif
536536

537537
/* @data can be NULL */
538-
static int _test_cmd_get_hw_info(int fd, __u32 device_id,
539-
void *data, size_t data_len)
538+
static int _test_cmd_get_hw_info(int fd, __u32 device_id, void *data,
539+
size_t data_len, uint32_t *capabilities)
540540
{
541541
struct iommu_test_hw_info *info = (struct iommu_test_hw_info *)data;
542542
struct iommu_hw_info cmd = {
543543
.size = sizeof(cmd),
544544
.dev_id = device_id,
545545
.data_len = data_len,
546546
.data_uptr = (uint64_t)data,
547+
.out_capabilities = 0,
547548
};
548549
int ret;
549550

@@ -580,14 +581,19 @@ static int _test_cmd_get_hw_info(int fd, __u32 device_id,
580581
assert(!info->flags);
581582
}
582583

584+
if (capabilities)
585+
*capabilities = cmd.out_capabilities;
586+
583587
return 0;
584588
}
585589

586-
#define test_cmd_get_hw_info(device_id, data, data_len) \
587-
ASSERT_EQ(0, _test_cmd_get_hw_info(self->fd, device_id, \
588-
data, data_len))
590+
#define test_cmd_get_hw_info(device_id, data, data_len) \
591+
ASSERT_EQ(0, _test_cmd_get_hw_info(self->fd, device_id, data, \
592+
data_len, NULL))
593+
594+
#define test_err_get_hw_info(_errno, device_id, data, data_len) \
595+
EXPECT_ERRNO(_errno, _test_cmd_get_hw_info(self->fd, device_id, data, \
596+
data_len, NULL))
589597

590-
#define test_err_get_hw_info(_errno, device_id, data, data_len) \
591-
EXPECT_ERRNO(_errno, \
592-
_test_cmd_get_hw_info(self->fd, device_id, \
593-
data, data_len))
598+
#define test_cmd_get_hw_capabilities(device_id, caps, mask) \
599+
ASSERT_EQ(0, _test_cmd_get_hw_info(self->fd, device_id, NULL, 0, &caps))

0 commit comments

Comments
 (0)