Skip to content

Commit 6d9500b

Browse files
yiliu1765jgunthorpe
authored andcommitted
iommufd/selftest: Add coverage for reporting max_pasid_log2 via IOMMU_HW_INFO
IOMMU_HW_INFO is extended to report max_pasid_log2, hence add coverage for it. Link: https://patch.msgid.link/r/[email protected] Reviewed-by: Nicolin Chen <[email protected]> Tested-by: Nicolin Chen <[email protected]> Signed-off-by: Yi Liu <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 803f972 commit 6d9500b

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

tools/testing/selftests/iommu/iommufd.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,14 @@ FIXTURE(iommufd_ioas)
342342
uint32_t hwpt_id;
343343
uint32_t device_id;
344344
uint64_t base_iova;
345+
uint32_t device_pasid_id;
345346
};
346347

347348
FIXTURE_VARIANT(iommufd_ioas)
348349
{
349350
unsigned int mock_domains;
350351
unsigned int memory_limit;
352+
bool pasid_capable;
351353
};
352354

353355
FIXTURE_SETUP(iommufd_ioas)
@@ -372,6 +374,12 @@ FIXTURE_SETUP(iommufd_ioas)
372374
IOMMU_TEST_DEV_CACHE_DEFAULT);
373375
self->base_iova = MOCK_APERTURE_START;
374376
}
377+
378+
if (variant->pasid_capable)
379+
test_cmd_mock_domain_flags(self->ioas_id,
380+
MOCK_FLAGS_DEVICE_PASID,
381+
NULL, NULL,
382+
&self->device_pasid_id);
375383
}
376384

377385
FIXTURE_TEARDOWN(iommufd_ioas)
@@ -387,6 +395,7 @@ FIXTURE_VARIANT_ADD(iommufd_ioas, no_domain)
387395
FIXTURE_VARIANT_ADD(iommufd_ioas, mock_domain)
388396
{
389397
.mock_domains = 1,
398+
.pasid_capable = true,
390399
};
391400

392401
FIXTURE_VARIANT_ADD(iommufd_ioas, two_mock_domain)
@@ -752,6 +761,8 @@ TEST_F(iommufd_ioas, get_hw_info)
752761
} buffer_smaller;
753762

754763
if (self->device_id) {
764+
uint8_t max_pasid = 0;
765+
755766
/* Provide a zero-size user_buffer */
756767
test_cmd_get_hw_info(self->device_id, NULL, 0);
757768
/* Provide a user_buffer with exact size */
@@ -766,6 +777,13 @@ TEST_F(iommufd_ioas, get_hw_info)
766777
* the fields within the size range still gets updated.
767778
*/
768779
test_cmd_get_hw_info(self->device_id, &buffer_smaller, sizeof(buffer_smaller));
780+
test_cmd_get_hw_info_pasid(self->device_id, &max_pasid);
781+
ASSERT_EQ(0, max_pasid);
782+
if (variant->pasid_capable) {
783+
test_cmd_get_hw_info_pasid(self->device_pasid_id,
784+
&max_pasid);
785+
ASSERT_EQ(MOCK_PASID_WIDTH, max_pasid);
786+
}
769787
} else {
770788
test_err_get_hw_info(ENOENT, self->device_id,
771789
&buffer_exact, sizeof(buffer_exact));

tools/testing/selftests/iommu/iommufd_fail_nth.c

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

669-
if (_test_cmd_get_hw_info(self->fd, idev_id, &info, sizeof(info), NULL))
669+
if (_test_cmd_get_hw_info(self->fd, idev_id, &info,
670+
sizeof(info), NULL, NULL))
670671
return -1;
671672

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

tools/testing/selftests/iommu/iommufd_utils.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,8 @@ static void teardown_iommufd(int fd, struct __test_metadata *_metadata)
758758

759759
/* @data can be NULL */
760760
static int _test_cmd_get_hw_info(int fd, __u32 device_id, void *data,
761-
size_t data_len, uint32_t *capabilities)
761+
size_t data_len, uint32_t *capabilities,
762+
uint8_t *max_pasid)
762763
{
763764
struct iommu_test_hw_info *info = (struct iommu_test_hw_info *)data;
764765
struct iommu_hw_info cmd = {
@@ -803,6 +804,9 @@ static int _test_cmd_get_hw_info(int fd, __u32 device_id, void *data,
803804
assert(!info->flags);
804805
}
805806

807+
if (max_pasid)
808+
*max_pasid = cmd.out_max_pasid_log2;
809+
806810
if (capabilities)
807811
*capabilities = cmd.out_capabilities;
808812

@@ -811,14 +815,19 @@ static int _test_cmd_get_hw_info(int fd, __u32 device_id, void *data,
811815

812816
#define test_cmd_get_hw_info(device_id, data, data_len) \
813817
ASSERT_EQ(0, _test_cmd_get_hw_info(self->fd, device_id, data, \
814-
data_len, NULL))
818+
data_len, NULL, NULL))
815819

816820
#define test_err_get_hw_info(_errno, device_id, data, data_len) \
817821
EXPECT_ERRNO(_errno, _test_cmd_get_hw_info(self->fd, device_id, data, \
818-
data_len, NULL))
822+
data_len, NULL, NULL))
819823

820824
#define test_cmd_get_hw_capabilities(device_id, caps, mask) \
821-
ASSERT_EQ(0, _test_cmd_get_hw_info(self->fd, device_id, NULL, 0, &caps))
825+
ASSERT_EQ(0, _test_cmd_get_hw_info(self->fd, device_id, NULL, \
826+
0, &caps, NULL))
827+
828+
#define test_cmd_get_hw_info_pasid(device_id, max_pasid) \
829+
ASSERT_EQ(0, _test_cmd_get_hw_info(self->fd, device_id, NULL, \
830+
0, NULL, max_pasid))
822831

823832
static int _test_ioctl_fault_alloc(int fd, __u32 *fault_id, __u32 *fault_fd)
824833
{

0 commit comments

Comments
 (0)