]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iommufd/selftest: Add coverage for viommu data
authorNicolin Chen <nicolinc@nvidia.com>
Thu, 10 Jul 2025 05:59:01 +0000 (22:59 -0700)
committerJason Gunthorpe <jgg@nvidia.com>
Thu, 10 Jul 2025 15:38:51 +0000 (12:38 -0300)
Extend the existing test_cmd/err_viommu_alloc helpers to accept optional
user data. And add a TEST_F for a loopback test.

Link: https://patch.msgid.link/r/8ceb64d30e9953f29270a7d341032ca439317271.1752126748.git.nicolinc@nvidia.com
Reviewed-by: Pranjal Shrivastava <praan@google.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
tools/testing/selftests/iommu/iommufd.c
tools/testing/selftests/iommu/iommufd_fail_nth.c
tools/testing/selftests/iommu/iommufd_utils.h

index 1a8e85afe9aa51f9519172f17f7c3e9b758b30f5..a9dfcce5e1b223b0b26112830bc64328cb614bcb 100644 (file)
@@ -2688,7 +2688,7 @@ FIXTURE_SETUP(iommufd_viommu)
 
                /* Allocate a vIOMMU taking refcount of the parent hwpt */
                test_cmd_viommu_alloc(self->device_id, self->hwpt_id,
-                                     IOMMU_VIOMMU_TYPE_SELFTEST,
+                                     IOMMU_VIOMMU_TYPE_SELFTEST, NULL, 0,
                                      &self->viommu_id);
 
                /* Allocate a regular nested hwpt */
@@ -2727,24 +2727,27 @@ TEST_F(iommufd_viommu, viommu_negative_tests)
        if (self->device_id) {
                /* Negative test -- invalid hwpt (hwpt_id=0) */
                test_err_viommu_alloc(ENOENT, device_id, 0,
-                                     IOMMU_VIOMMU_TYPE_SELFTEST, NULL);
+                                     IOMMU_VIOMMU_TYPE_SELFTEST, NULL, 0,
+                                     NULL);
 
                /* Negative test -- not a nesting parent hwpt */
                test_cmd_hwpt_alloc(device_id, ioas_id, 0, &hwpt_id);
                test_err_viommu_alloc(EINVAL, device_id, hwpt_id,
-                                     IOMMU_VIOMMU_TYPE_SELFTEST, NULL);
+                                     IOMMU_VIOMMU_TYPE_SELFTEST, NULL, 0,
+                                     NULL);
                test_ioctl_destroy(hwpt_id);
 
                /* Negative test -- unsupported viommu type */
                test_err_viommu_alloc(EOPNOTSUPP, device_id, self->hwpt_id,
-                                     0xdead, NULL);
+                                     0xdead, NULL, 0, NULL);
                EXPECT_ERRNO(EBUSY,
                             _test_ioctl_destroy(self->fd, self->hwpt_id));
                EXPECT_ERRNO(EBUSY,
                             _test_ioctl_destroy(self->fd, self->viommu_id));
        } else {
                test_err_viommu_alloc(ENOENT, self->device_id, self->hwpt_id,
-                                     IOMMU_VIOMMU_TYPE_SELFTEST, NULL);
+                                     IOMMU_VIOMMU_TYPE_SELFTEST, NULL, 0,
+                                     NULL);
        }
 }
 
@@ -2791,6 +2794,21 @@ TEST_F(iommufd_viommu, viommu_alloc_nested_iopf)
        }
 }
 
+TEST_F(iommufd_viommu, viommu_alloc_with_data)
+{
+       struct iommu_viommu_selftest data = {
+               .in_data = 0xbeef,
+       };
+
+       if (!self->device_id)
+               SKIP(return, "Skipping test for variant no_viommu");
+
+       test_cmd_viommu_alloc(self->device_id, self->hwpt_id,
+                             IOMMU_VIOMMU_TYPE_SELFTEST, &data, sizeof(data),
+                             &self->viommu_id);
+       ASSERT_EQ(data.out_data, data.in_data);
+}
+
 TEST_F(iommufd_viommu, vdevice_alloc)
 {
        uint32_t viommu_id = self->viommu_id;
@@ -3105,8 +3123,7 @@ TEST_F(iommufd_device_pasid, pasid_attach)
 
        /* Allocate a regular nested hwpt based on viommu */
        test_cmd_viommu_alloc(self->device_id, parent_hwpt_id,
-                             IOMMU_VIOMMU_TYPE_SELFTEST,
-                             &viommu_id);
+                             IOMMU_VIOMMU_TYPE_SELFTEST, NULL, 0, &viommu_id);
        test_cmd_hwpt_alloc_nested(self->device_id, viommu_id,
                                   IOMMU_HWPT_ALLOC_PASID,
                                   &nested_hwpt_id[2],
index e11ec4b121fc37ea13f1032bd926911d09eeb953..f7ccf182210899a4b1d2b87b103e6ebfc414ed84 100644 (file)
@@ -688,8 +688,9 @@ TEST_FAIL_NTH(basic_fail_nth, device)
                                 IOMMU_HWPT_DATA_NONE, 0, 0))
                return -1;
 
-       if (_test_cmd_viommu_alloc(self->fd, idev_id, hwpt_id,
-                                  IOMMU_VIOMMU_TYPE_SELFTEST, 0, &viommu_id))
+       if (_test_cmd_viommu_alloc(self->fd, idev_id, hwpt_id, 0,
+                                  IOMMU_VIOMMU_TYPE_SELFTEST, NULL, 0,
+                                  &viommu_id))
                return -1;
 
        if (_test_cmd_vdevice_alloc(self->fd, viommu_id, idev_id, 0, &vdev_id))
index 72f6636e5d909911e6f06ec397f37c8e7e440c5a..a5d4cbd089bae9336fb000ba151ded4c128ce8e6 100644 (file)
@@ -897,7 +897,8 @@ static int _test_cmd_trigger_iopf(int fd, __u32 device_id, __u32 pasid,
                                            pasid, fault_fd))
 
 static int _test_cmd_viommu_alloc(int fd, __u32 device_id, __u32 hwpt_id,
-                                 __u32 type, __u32 flags, __u32 *viommu_id)
+                                 __u32 flags, __u32 type, void *data,
+                                 __u32 data_len, __u32 *viommu_id)
 {
        struct iommu_viommu_alloc cmd = {
                .size = sizeof(cmd),
@@ -905,6 +906,8 @@ static int _test_cmd_viommu_alloc(int fd, __u32 device_id, __u32 hwpt_id,
                .type = type,
                .dev_id = device_id,
                .hwpt_id = hwpt_id,
+               .data_uptr = (uint64_t)data,
+               .data_len = data_len,
        };
        int ret;
 
@@ -916,13 +919,15 @@ static int _test_cmd_viommu_alloc(int fd, __u32 device_id, __u32 hwpt_id,
        return 0;
 }
 
-#define test_cmd_viommu_alloc(device_id, hwpt_id, type, viommu_id)        \
-       ASSERT_EQ(0, _test_cmd_viommu_alloc(self->fd, device_id, hwpt_id, \
-                                           type, 0, viommu_id))
-#define test_err_viommu_alloc(_errno, device_id, hwpt_id, type, viommu_id) \
-       EXPECT_ERRNO(_errno,                                               \
-                    _test_cmd_viommu_alloc(self->fd, device_id, hwpt_id,  \
-                                           type, 0, viommu_id))
+#define test_cmd_viommu_alloc(device_id, hwpt_id, type, data, data_len,      \
+                             viommu_id)                                     \
+       ASSERT_EQ(0, _test_cmd_viommu_alloc(self->fd, device_id, hwpt_id, 0, \
+                                           type, data, data_len, viommu_id))
+#define test_err_viommu_alloc(_errno, device_id, hwpt_id, type, data,        \
+                             data_len, viommu_id)                           \
+       EXPECT_ERRNO(_errno,                                                 \
+                    _test_cmd_viommu_alloc(self->fd, device_id, hwpt_id, 0, \
+                                           type, data, data_len, viommu_id))
 
 static int _test_cmd_vdevice_alloc(int fd, __u32 viommu_id, __u32 idev_id,
                                   __u64 virt_id, __u32 *vdev_id)