Add a GET_DIRTY_BITMAP case that passes iova = 0 with a zero length and
expects -EINVAL. iova = 0 is the value that lets the zero length wrap
into an accepted range; without the previous patch the request is
accepted and returns success.

The case runs on every variant of the dirty-tracking fixture. Tested on
x86-64 under virtme-ng with CONFIG_IOMMUFD_TEST=y.

Assisted-by: LLM
Signed-off-by: Andrea Parri <[email protected]>
---
 tools/testing/selftests/iommu/iommufd.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/tools/testing/selftests/iommu/iommufd.c 
b/tools/testing/selftests/iommu/iommufd.c
index 47d861b3bdd7b..2b3c9e9c69ca7 100644
--- a/tools/testing/selftests/iommu/iommufd.c
+++ b/tools/testing/selftests/iommu/iommufd.c
@@ -2472,6 +2472,25 @@ TEST_F(iommufd_dirty_tracking, get_dirty_bitmap_overrun)
        test_ioctl_destroy(hwpt_id);
 }
 
+TEST_F(iommufd_dirty_tracking, get_dirty_bitmap_zero_length)
+{
+       uint32_t ioas_id = self->ioas_id;
+       uint32_t hwpt_id;
+
+       test_cmd_hwpt_alloc_iommupt(self->idev_id, ioas_id,
+                                   IOMMU_HWPT_ALLOC_DIRTY_TRACKING,
+                                   MOCK_IOMMUPT_DEFAULT, &hwpt_id);
+       test_cmd_set_dirty_tracking(hwpt_id, true);
+
+       /* Only iova 0 wraps the zero length into an accepted range. */
+       EXPECT_ERRNO(EINVAL,
+                    _test_cmd_get_dirty_bitmap(self->fd, hwpt_id, 0, 0,
+                                               self->page_size, self->bitmap,
+                                               0));
+
+       test_ioctl_destroy(hwpt_id);
+}
+
 /* VFIO compatibility IOCTLs */
 
 TEST_F(iommufd, simple_ioctls)
-- 
2.53.0


Reply via email to