]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iommufd/selftest: Update hw_info coverage for an input data_type
authorNicolin Chen <nicolinc@nvidia.com>
Thu, 10 Jul 2025 05:59:14 +0000 (22:59 -0700)
committerJason Gunthorpe <jgg@nvidia.com>
Fri, 11 Jul 2025 17:34:35 +0000 (14:34 -0300)
Test both IOMMU_HW_INFO_TYPE_DEFAULT and IOMMU_HW_INFO_TYPE_SELFTEST, and
add a negative test for an unsupported type.

Also drop the unused mask in test_cmd_get_hw_capabilities() as checkpatch
is complaining.

Link: https://patch.msgid.link/r/f01a1e50cd7366f217cbf192ad0b2b79e0eb89f0.1752126748.git.nicolinc@nvidia.com
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
Reviewed-by: Pranjal Shrivastava <praan@google.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 0b21c095ca5e09ed15d179a3d2c387fab1473e7f..d59d48022a24af4570636c0d7c93f6f44fbfee85 100644 (file)
@@ -764,19 +764,34 @@ TEST_F(iommufd_ioas, get_hw_info)
                uint8_t max_pasid = 0;
 
                /* Provide a zero-size user_buffer */
-               test_cmd_get_hw_info(self->device_id, NULL, 0);
+               test_cmd_get_hw_info(self->device_id,
+                                    IOMMU_HW_INFO_TYPE_DEFAULT, NULL, 0);
                /* Provide a user_buffer with exact size */
-               test_cmd_get_hw_info(self->device_id, &buffer_exact, sizeof(buffer_exact));
+               test_cmd_get_hw_info(self->device_id,
+                                    IOMMU_HW_INFO_TYPE_DEFAULT, &buffer_exact,
+                                    sizeof(buffer_exact));
+
+               /* Request for a wrong data_type, and a correct one */
+               test_err_get_hw_info(EOPNOTSUPP, self->device_id,
+                                    IOMMU_HW_INFO_TYPE_SELFTEST + 1,
+                                    &buffer_exact, sizeof(buffer_exact));
+               test_cmd_get_hw_info(self->device_id,
+                                    IOMMU_HW_INFO_TYPE_SELFTEST, &buffer_exact,
+                                    sizeof(buffer_exact));
                /*
                 * Provide a user_buffer with size larger than the exact size to check if
                 * kernel zero the trailing bytes.
                 */
-               test_cmd_get_hw_info(self->device_id, &buffer_larger, sizeof(buffer_larger));
+               test_cmd_get_hw_info(self->device_id,
+                                    IOMMU_HW_INFO_TYPE_DEFAULT, &buffer_larger,
+                                    sizeof(buffer_larger));
                /*
                 * Provide a user_buffer with size smaller than the exact size to check if
                 * the fields within the size range still gets updated.
                 */
-               test_cmd_get_hw_info(self->device_id, &buffer_smaller, sizeof(buffer_smaller));
+               test_cmd_get_hw_info(self->device_id,
+                                    IOMMU_HW_INFO_TYPE_DEFAULT,
+                                    &buffer_smaller, sizeof(buffer_smaller));
                test_cmd_get_hw_info_pasid(self->device_id, &max_pasid);
                ASSERT_EQ(0, max_pasid);
                if (variant->pasid_capable) {
@@ -786,9 +801,11 @@ TEST_F(iommufd_ioas, get_hw_info)
                }
        } else {
                test_err_get_hw_info(ENOENT, self->device_id,
-                                    &buffer_exact, sizeof(buffer_exact));
+                                    IOMMU_HW_INFO_TYPE_DEFAULT, &buffer_exact,
+                                    sizeof(buffer_exact));
                test_err_get_hw_info(ENOENT, self->device_id,
-                                    &buffer_larger, sizeof(buffer_larger));
+                                    IOMMU_HW_INFO_TYPE_DEFAULT, &buffer_larger,
+                                    sizeof(buffer_larger));
        }
 }
 
@@ -2175,8 +2192,7 @@ TEST_F(iommufd_dirty_tracking, device_dirty_capability)
 
        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_hw_capabilities(self->idev_id, caps,
-                                    IOMMU_HW_CAP_DIRTY_TRACKING);
+       test_cmd_get_hw_capabilities(self->idev_id, caps);
        ASSERT_EQ(IOMMU_HW_CAP_DIRTY_TRACKING,
                  caps & IOMMU_HW_CAP_DIRTY_TRACKING);
 
index 41c685bbd2522f20f192de3994ac8c3b1c29611e..651fc9f13c0810ba261ae6cc4681cb8fa89d4833 100644 (file)
@@ -667,8 +667,8 @@ TEST_FAIL_NTH(basic_fail_nth, device)
                                        &self->stdev_id, NULL, &idev_id))
                return -1;
 
-       if (_test_cmd_get_hw_info(self->fd, idev_id, &info,
-                                 sizeof(info), NULL, NULL))
+       if (_test_cmd_get_hw_info(self->fd, idev_id, IOMMU_HW_INFO_TYPE_DEFAULT,
+                                 &info, sizeof(info), NULL, NULL))
                return -1;
 
        if (_test_cmd_hwpt_alloc(self->fd, idev_id, ioas_id, 0,
index 4a1b2bade018898dade8c622d0444f2f9b357cd1..5384852ce038cd9b936663350c7b01fcbf827de3 100644 (file)
@@ -761,20 +761,24 @@ static void teardown_iommufd(int fd, struct __test_metadata *_metadata)
 #endif
 
 /* @data can be NULL */
-static int _test_cmd_get_hw_info(int fd, __u32 device_id, void *data,
-                                size_t data_len, uint32_t *capabilities,
-                                uint8_t *max_pasid)
+static int _test_cmd_get_hw_info(int fd, __u32 device_id, __u32 data_type,
+                                void *data, size_t data_len,
+                                uint32_t *capabilities, uint8_t *max_pasid)
 {
        struct iommu_test_hw_info *info = (struct iommu_test_hw_info *)data;
        struct iommu_hw_info cmd = {
                .size = sizeof(cmd),
                .dev_id = device_id,
                .data_len = data_len,
+               .in_data_type = data_type,
                .data_uptr = (uint64_t)data,
                .out_capabilities = 0,
        };
        int ret;
 
+       if (data_type != IOMMU_HW_INFO_TYPE_DEFAULT)
+               cmd.flags |= IOMMU_HW_INFO_FLAG_INPUT_TYPE;
+
        ret = ioctl(fd, IOMMU_GET_HW_INFO, &cmd);
        if (ret)
                return ret;
@@ -817,20 +821,23 @@ static int _test_cmd_get_hw_info(int fd, __u32 device_id, void *data,
        return 0;
 }
 
-#define test_cmd_get_hw_info(device_id, data, data_len)               \
-       ASSERT_EQ(0, _test_cmd_get_hw_info(self->fd, device_id, data, \
-                                          data_len, NULL, NULL))
+#define test_cmd_get_hw_info(device_id, data_type, data, data_len)         \
+       ASSERT_EQ(0, _test_cmd_get_hw_info(self->fd, device_id, data_type, \
+                                          data, data_len, NULL, NULL))
 
-#define test_err_get_hw_info(_errno, device_id, data, data_len)               \
-       EXPECT_ERRNO(_errno, _test_cmd_get_hw_info(self->fd, device_id, data, \
-                                                  data_len, NULL, NULL))
+#define test_err_get_hw_info(_errno, device_id, data_type, data, data_len) \
+       EXPECT_ERRNO(_errno,                                               \
+                    _test_cmd_get_hw_info(self->fd, device_id, data_type, \
+                                          data, data_len, NULL, NULL))
 
-#define test_cmd_get_hw_capabilities(device_id, caps, mask) \
-       ASSERT_EQ(0, _test_cmd_get_hw_info(self->fd, device_id, NULL, \
+#define test_cmd_get_hw_capabilities(device_id, caps)                        \
+       ASSERT_EQ(0, _test_cmd_get_hw_info(self->fd, device_id,              \
+                                          IOMMU_HW_INFO_TYPE_DEFAULT, NULL, \
                                           0, &caps, NULL))
 
-#define test_cmd_get_hw_info_pasid(device_id, max_pasid)              \
-       ASSERT_EQ(0, _test_cmd_get_hw_info(self->fd, device_id, NULL, \
+#define test_cmd_get_hw_info_pasid(device_id, max_pasid)                     \
+       ASSERT_EQ(0, _test_cmd_get_hw_info(self->fd, device_id,              \
+                                          IOMMU_HW_INFO_TYPE_DEFAULT, NULL, \
                                           0, NULL, max_pasid))
 
 static int _test_ioctl_fault_alloc(int fd, __u32 *fault_id, __u32 *fault_fd)