Skip to content

Commit 3a35f7d

Browse files
nicolincjgunthorpe
authored andcommitted
iommufd/selftest: Update hw_info coverage for an input data_type
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>
1 parent a9f10ba commit 3a35f7d

3 files changed

Lines changed: 46 additions & 23 deletions

File tree

tools/testing/selftests/iommu/iommufd.c

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -764,19 +764,34 @@ TEST_F(iommufd_ioas, get_hw_info)
764764
uint8_t max_pasid = 0;
765765

766766
/* Provide a zero-size user_buffer */
767-
test_cmd_get_hw_info(self->device_id, NULL, 0);
767+
test_cmd_get_hw_info(self->device_id,
768+
IOMMU_HW_INFO_TYPE_DEFAULT, NULL, 0);
768769
/* Provide a user_buffer with exact size */
769-
test_cmd_get_hw_info(self->device_id, &buffer_exact, sizeof(buffer_exact));
770+
test_cmd_get_hw_info(self->device_id,
771+
IOMMU_HW_INFO_TYPE_DEFAULT, &buffer_exact,
772+
sizeof(buffer_exact));
773+
774+
/* Request for a wrong data_type, and a correct one */
775+
test_err_get_hw_info(EOPNOTSUPP, self->device_id,
776+
IOMMU_HW_INFO_TYPE_SELFTEST + 1,
777+
&buffer_exact, sizeof(buffer_exact));
778+
test_cmd_get_hw_info(self->device_id,
779+
IOMMU_HW_INFO_TYPE_SELFTEST, &buffer_exact,
780+
sizeof(buffer_exact));
770781
/*
771782
* Provide a user_buffer with size larger than the exact size to check if
772783
* kernel zero the trailing bytes.
773784
*/
774-
test_cmd_get_hw_info(self->device_id, &buffer_larger, sizeof(buffer_larger));
785+
test_cmd_get_hw_info(self->device_id,
786+
IOMMU_HW_INFO_TYPE_DEFAULT, &buffer_larger,
787+
sizeof(buffer_larger));
775788
/*
776789
* Provide a user_buffer with size smaller than the exact size to check if
777790
* the fields within the size range still gets updated.
778791
*/
779-
test_cmd_get_hw_info(self->device_id, &buffer_smaller, sizeof(buffer_smaller));
792+
test_cmd_get_hw_info(self->device_id,
793+
IOMMU_HW_INFO_TYPE_DEFAULT,
794+
&buffer_smaller, sizeof(buffer_smaller));
780795
test_cmd_get_hw_info_pasid(self->device_id, &max_pasid);
781796
ASSERT_EQ(0, max_pasid);
782797
if (variant->pasid_capable) {
@@ -786,9 +801,11 @@ TEST_F(iommufd_ioas, get_hw_info)
786801
}
787802
} else {
788803
test_err_get_hw_info(ENOENT, self->device_id,
789-
&buffer_exact, sizeof(buffer_exact));
804+
IOMMU_HW_INFO_TYPE_DEFAULT, &buffer_exact,
805+
sizeof(buffer_exact));
790806
test_err_get_hw_info(ENOENT, self->device_id,
791-
&buffer_larger, sizeof(buffer_larger));
807+
IOMMU_HW_INFO_TYPE_DEFAULT, &buffer_larger,
808+
sizeof(buffer_larger));
792809
}
793810
}
794811

@@ -2175,8 +2192,7 @@ TEST_F(iommufd_dirty_tracking, device_dirty_capability)
21752192

21762193
test_cmd_hwpt_alloc(self->idev_id, self->ioas_id, 0, &hwpt_id);
21772194
test_cmd_mock_domain(hwpt_id, &stddev_id, NULL, NULL);
2178-
test_cmd_get_hw_capabilities(self->idev_id, caps,
2179-
IOMMU_HW_CAP_DIRTY_TRACKING);
2195+
test_cmd_get_hw_capabilities(self->idev_id, caps);
21802196
ASSERT_EQ(IOMMU_HW_CAP_DIRTY_TRACKING,
21812197
caps & IOMMU_HW_CAP_DIRTY_TRACKING);
21822198

tools/testing/selftests/iommu/iommufd_fail_nth.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,8 @@ TEST_FAIL_NTH(basic_fail_nth, device)
667667
&self->stdev_id, NULL, &idev_id))
668668
return -1;
669669

670-
if (_test_cmd_get_hw_info(self->fd, idev_id, &info,
671-
sizeof(info), NULL, NULL))
670+
if (_test_cmd_get_hw_info(self->fd, idev_id, IOMMU_HW_INFO_TYPE_DEFAULT,
671+
&info, sizeof(info), NULL, NULL))
672672
return -1;
673673

674674
if (_test_cmd_hwpt_alloc(self->fd, idev_id, ioas_id, 0,

tools/testing/selftests/iommu/iommufd_utils.h

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -761,20 +761,24 @@ static void teardown_iommufd(int fd, struct __test_metadata *_metadata)
761761
#endif
762762

763763
/* @data can be NULL */
764-
static int _test_cmd_get_hw_info(int fd, __u32 device_id, void *data,
765-
size_t data_len, uint32_t *capabilities,
766-
uint8_t *max_pasid)
764+
static int _test_cmd_get_hw_info(int fd, __u32 device_id, __u32 data_type,
765+
void *data, size_t data_len,
766+
uint32_t *capabilities, uint8_t *max_pasid)
767767
{
768768
struct iommu_test_hw_info *info = (struct iommu_test_hw_info *)data;
769769
struct iommu_hw_info cmd = {
770770
.size = sizeof(cmd),
771771
.dev_id = device_id,
772772
.data_len = data_len,
773+
.in_data_type = data_type,
773774
.data_uptr = (uint64_t)data,
774775
.out_capabilities = 0,
775776
};
776777
int ret;
777778

779+
if (data_type != IOMMU_HW_INFO_TYPE_DEFAULT)
780+
cmd.flags |= IOMMU_HW_INFO_FLAG_INPUT_TYPE;
781+
778782
ret = ioctl(fd, IOMMU_GET_HW_INFO, &cmd);
779783
if (ret)
780784
return ret;
@@ -817,20 +821,23 @@ static int _test_cmd_get_hw_info(int fd, __u32 device_id, void *data,
817821
return 0;
818822
}
819823

820-
#define test_cmd_get_hw_info(device_id, data, data_len) \
821-
ASSERT_EQ(0, _test_cmd_get_hw_info(self->fd, device_id, data, \
822-
data_len, NULL, NULL))
824+
#define test_cmd_get_hw_info(device_id, data_type, data, data_len) \
825+
ASSERT_EQ(0, _test_cmd_get_hw_info(self->fd, device_id, data_type, \
826+
data, data_len, NULL, NULL))
823827

824-
#define test_err_get_hw_info(_errno, device_id, data, data_len) \
825-
EXPECT_ERRNO(_errno, _test_cmd_get_hw_info(self->fd, device_id, data, \
826-
data_len, NULL, NULL))
828+
#define test_err_get_hw_info(_errno, device_id, data_type, data, data_len) \
829+
EXPECT_ERRNO(_errno, \
830+
_test_cmd_get_hw_info(self->fd, device_id, data_type, \
831+
data, data_len, NULL, NULL))
827832

828-
#define test_cmd_get_hw_capabilities(device_id, caps, mask) \
829-
ASSERT_EQ(0, _test_cmd_get_hw_info(self->fd, device_id, NULL, \
833+
#define test_cmd_get_hw_capabilities(device_id, caps) \
834+
ASSERT_EQ(0, _test_cmd_get_hw_info(self->fd, device_id, \
835+
IOMMU_HW_INFO_TYPE_DEFAULT, NULL, \
830836
0, &caps, NULL))
831837

832-
#define test_cmd_get_hw_info_pasid(device_id, max_pasid) \
833-
ASSERT_EQ(0, _test_cmd_get_hw_info(self->fd, device_id, NULL, \
838+
#define test_cmd_get_hw_info_pasid(device_id, max_pasid) \
839+
ASSERT_EQ(0, _test_cmd_get_hw_info(self->fd, device_id, \
840+
IOMMU_HW_INFO_TYPE_DEFAULT, NULL, \
834841
0, NULL, max_pasid))
835842

836843
static int _test_ioctl_fault_alloc(int fd, __u32 *fault_id, __u32 *fault_fd)

0 commit comments

Comments
 (0)