mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-20 06:21:12 -04:00
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>
This commit is contained in:
committed by
Jason Gunthorpe
parent
a9f10bab2e
commit
3a35f7d4a4
@@ -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);
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user