Enumerate the capabilities from the mock device and test whether it advertises as expected. Include it as part of the iommufd_dirty_tracking suite. Signed-off-by: Joao Martins <joao.m.martins@xxxxxxxxxx> --- drivers/iommu/iommufd/selftest.c | 10 +++++++++- tools/testing/selftests/iommu/iommufd.c | 14 ++++++++++++++ tools/testing/selftests/iommu/iommufd_utils.h | 19 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index 3ec0eb4dfe97..d81a977bf3af 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -275,7 +275,15 @@ static phys_addr_t mock_domain_iova_to_phys(struct iommu_domain *domain, static bool mock_domain_capable(struct device *dev, enum iommu_cap cap) { - return cap == IOMMU_CAP_CACHE_COHERENCY; + switch (cap) { + case IOMMU_CAP_CACHE_COHERENCY: + case IOMMU_CAP_DIRTY: + return true; + default: + break; + } + + return false; } static void mock_domain_set_plaform_dma_ops(struct device *dev) diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index 818e78cd889a..dad1eca3aa09 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -1475,6 +1475,19 @@ TEST_F(iommufd_dirty_tracking, set_dirty) test_ioctl_destroy(hwpt_id); } +TEST_F(iommufd_dirty_tracking, device_dirty_capability) +{ + uint32_t stddev_id; + uint32_t hwpt_id; + + test_cmd_hwpt_alloc(self->idev_id, self->ioas_id, 0, &hwpt_id); + test_cmd_mock_domain(hwpt_id, &stddev_id, NULL, NULL); + test_cmd_get_device_caps(self->idev_id, IOMMUFD_CAP_DIRTY_TRACKING); + + test_ioctl_destroy(stddev_id); + test_ioctl_destroy(hwpt_id); +} + TEST_F(iommufd_dirty_tracking, get_dirty_iova) { uint32_t stddev_id; @@ -1507,6 +1520,7 @@ TEST_F(iommufd_dirty_tracking, get_dirty_iova) test_ioctl_destroy(hwpt_id); } + /* VFIO compatibility IOCTLs */ TEST_F(iommufd, simple_ioctls) diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h index 4d428fbb12e2..e942bc781f34 100644 --- a/tools/testing/selftests/iommu/iommufd_utils.h +++ b/tools/testing/selftests/iommu/iommufd_utils.h @@ -146,6 +146,25 @@ static int _test_cmd_set_dirty(int fd, __u32 hwpt_id, bool enabled) #define test_cmd_set_dirty(hwpt_id, enabled) \ ASSERT_EQ(0, _test_cmd_set_dirty(self->fd, hwpt_id, enabled)) +static int _test_cmd_get_device_caps(int fd, __u32 dev_id, __u64 capability) +{ + struct iommu_device_get_caps cmd = { + .size = sizeof(cmd), + .dev_id = dev_id, + }; + int ret; + + ret = ioctl(fd, IOMMU_DEVICE_GET_CAPS, &cmd); + if (ret) + return ret; + + return cmd.out_caps & capability; +} + +#define test_cmd_get_device_caps(dev_id, expected) \ + ASSERT_EQ(expected, _test_cmd_get_device_caps(self->fd, dev_id, \ + expected)) + static int _test_cmd_get_dirty_iova(int fd, __u32 hwpt_id, size_t length, __u64 iova, size_t page_size, __u64 *bitmap) { -- 2.17.2