diff mbox series

[RFC,6/7] iommufd/selftest: Add test coverage for SIOV virtual device

Message ID 20231009085123.463179-7-yi.l.liu@intel.com (mailing list archive)
State New, archived
Headers show
Series Add SIOV virtual device support | expand

Commit Message

Yi Liu Oct. 9, 2023, 8:51 a.m. UTC
This adds test coverage for SIOV virtual device by passsing a non-zero pasid
to IOMMU_TEST_OP_MOCK_DOMAIN op, and check if the SIOV virtual device (a.k.a
pasid of this device) is attached to the mock domain, then tries to replace
with a new hwpt and other types of hwpts, and check if the attached domain of
this virtual device is correct.

Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
 tools/testing/selftests/iommu/iommufd.c       | 53 ++++++++++++++++++-
 .../selftests/iommu/iommufd_fail_nth.c        | 26 +++++++++
 2 files changed, 77 insertions(+), 2 deletions(-)

Comments

Tian, Kevin Oct. 10, 2023, 8:30 a.m. UTC | #1
> From: Liu, Yi L <yi.l.liu@intel.com>
> Sent: Monday, October 9, 2023 4:51 PM
> 
> @@ -2071,6 +2083,43 @@ TEST_F(iommufd_device_pasid, pasid_attach)
> 
> IOMMU_HWPT_ALLOC_DATA_SELFTEST,
>  					   &data, sizeof(data));
> 
> +		if (variant->pasid) {
> +			uint32_t new_hwpt_id = 0;
> +
> +			ASSERT_EQ(0,
> +				  test_cmd_pasid_check_domain(self->fd,
> +							      self->stdev_id,
> +							      variant->pasid,
> +							      self->hwpt_id,
> +							      &result));
> +			EXPECT_EQ(1, result);
> +			test_cmd_hwpt_alloc(self->device_id, self->ioas_id,
> +					    0, &new_hwpt_id);
> +			test_cmd_mock_domain_replace(self->stdev_id,
> +						     new_hwpt_id);
> +			ASSERT_EQ(0,
> +				  test_cmd_pasid_check_domain(self->fd,
> +							      self->stdev_id,
> +							      variant->pasid,
> +							      new_hwpt_id,
> +							      &result));
> +			EXPECT_EQ(1, result);
> +
> +			/*
> +			 * Detach hwpt from variant->pasid, and check if the
> +			 * variant->pasid has null domain
> +			 */
> +			test_cmd_pasid_detach(variant->pasid);
> +			ASSERT_EQ(0,
> +				  test_cmd_pasid_check_domain(self->fd,
> +							      self->stdev_id,
> +							      variant->pasid,
> +							      0, &result));
> +			EXPECT_EQ(1, result);
> +
> +			test_ioctl_destroy(new_hwpt_id);
> +		}
> +

I wonder whether above better reuses the device attach/replace cases
given default_pasid is hidden inside iommufd_device. this pasid_attach
case is more for testing user pasids on a iommufd_device which hasn't
yet been supported by SIOV device?
Yi Liu Nov. 9, 2023, 7:48 a.m. UTC | #2
On 2023/10/10 16:30, Tian, Kevin wrote:
>> From: Liu, Yi L <yi.l.liu@intel.com>
>> Sent: Monday, October 9, 2023 4:51 PM
>>
>> @@ -2071,6 +2083,43 @@ TEST_F(iommufd_device_pasid, pasid_attach)
>>
>> IOMMU_HWPT_ALLOC_DATA_SELFTEST,
>>   					   &data, sizeof(data));
>>
>> +		if (variant->pasid) {
>> +			uint32_t new_hwpt_id = 0;
>> +
>> +			ASSERT_EQ(0,
>> +				  test_cmd_pasid_check_domain(self->fd,
>> +							      self->stdev_id,
>> +							      variant->pasid,
>> +							      self->hwpt_id,
>> +							      &result));
>> +			EXPECT_EQ(1, result);
>> +			test_cmd_hwpt_alloc(self->device_id, self->ioas_id,
>> +					    0, &new_hwpt_id);
>> +			test_cmd_mock_domain_replace(self->stdev_id,
>> +						     new_hwpt_id);
>> +			ASSERT_EQ(0,
>> +				  test_cmd_pasid_check_domain(self->fd,
>> +							      self->stdev_id,
>> +							      variant->pasid,
>> +							      new_hwpt_id,
>> +							      &result));
>> +			EXPECT_EQ(1, result);
>> +
>> +			/*
>> +			 * Detach hwpt from variant->pasid, and check if the
>> +			 * variant->pasid has null domain
>> +			 */
>> +			test_cmd_pasid_detach(variant->pasid);
>> +			ASSERT_EQ(0,
>> +				  test_cmd_pasid_check_domain(self->fd,
>> +							      self->stdev_id,
>> +							      variant->pasid,
>> +							      0, &result));
>> +			EXPECT_EQ(1, result);
>> +
>> +			test_ioctl_destroy(new_hwpt_id);
>> +		}
>> +
> 
> I wonder whether above better reuses the device attach/replace cases
> given default_pasid is hidden inside iommufd_device. this pasid_attach
> case is more for testing user pasids on a iommufd_device which hasn't
> yet been supported by SIOV device?

perhaps the way how the above code checks the attached domain misled you.
Actually, this is still testing the siov default_pasid. In the variant
setup, the default_pasid is passed to the testing driver when creating
the stdev. That's why the replace test does not require a pasid.

maybe I can let have a new selftest op to check attached domain for a given 
stdev instead of reusing test_cmd_pasid_check_domain().
diff mbox series

Patch

diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c
index 9a1fbba89e96..945ab07a8b84 100644
--- a/tools/testing/selftests/iommu/iommufd.c
+++ b/tools/testing/selftests/iommu/iommufd.c
@@ -2031,14 +2031,20 @@  FIXTURE(iommufd_device_pasid)
 	uint32_t device_id;
 };
 
+FIXTURE_VARIANT(iommufd_device_pasid)
+{
+	uint32_t pasid;
+};
+
 FIXTURE_SETUP(iommufd_device_pasid)
 {
 	self->fd = open("/dev/iommu", O_RDWR);
 	ASSERT_NE(-1, self->fd);
 	test_ioctl_ioas_alloc(&self->ioas_id);
 
-	test_cmd_mock_domain(self->ioas_id, 0, &self->stdev_id,
-			     &self->hwpt_id, &self->device_id);
+	test_cmd_mock_domain(self->ioas_id, variant->pasid,
+			     &self->stdev_id, &self->hwpt_id,
+			     &self->device_id);
 }
 
 FIXTURE_TEARDOWN(iommufd_device_pasid)
@@ -2046,6 +2052,12 @@  FIXTURE_TEARDOWN(iommufd_device_pasid)
 	teardown_iommufd(self->fd, _metadata);
 }
 
+/* For SIOV test */
+FIXTURE_VARIANT_ADD(iommufd_device_pasid, siov_pasid_600)
+{
+	.pasid = 600, //this is the default pasid for the SIOV virtual device
+};
+
 TEST_F(iommufd_device_pasid, pasid_attach)
 {
 	if (self->device_id) {
@@ -2071,6 +2083,43 @@  TEST_F(iommufd_device_pasid, pasid_attach)
 					   IOMMU_HWPT_ALLOC_DATA_SELFTEST,
 					   &data, sizeof(data));
 
+		if (variant->pasid) {
+			uint32_t new_hwpt_id = 0;
+
+			ASSERT_EQ(0,
+				  test_cmd_pasid_check_domain(self->fd,
+							      self->stdev_id,
+							      variant->pasid,
+							      self->hwpt_id,
+							      &result));
+			EXPECT_EQ(1, result);
+			test_cmd_hwpt_alloc(self->device_id, self->ioas_id,
+					    0, &new_hwpt_id);
+			test_cmd_mock_domain_replace(self->stdev_id,
+						     new_hwpt_id);
+			ASSERT_EQ(0,
+				  test_cmd_pasid_check_domain(self->fd,
+							      self->stdev_id,
+							      variant->pasid,
+							      new_hwpt_id,
+							      &result));
+			EXPECT_EQ(1, result);
+
+			/*
+			 * Detach hwpt from variant->pasid, and check if the
+			 * variant->pasid has null domain
+			 */
+			test_cmd_pasid_detach(variant->pasid);
+			ASSERT_EQ(0,
+				  test_cmd_pasid_check_domain(self->fd,
+							      self->stdev_id,
+							      variant->pasid,
+							      0, &result));
+			EXPECT_EQ(1, result);
+
+			test_ioctl_destroy(new_hwpt_id);
+		}
+
 		/*
 		 * Attach ioas to pasid 100, should succeed, domain should
 		 * be valid.
diff --git a/tools/testing/selftests/iommu/iommufd_fail_nth.c b/tools/testing/selftests/iommu/iommufd_fail_nth.c
index 691903c63de0..a5fb45d99869 100644
--- a/tools/testing/selftests/iommu/iommufd_fail_nth.c
+++ b/tools/testing/selftests/iommu/iommufd_fail_nth.c
@@ -644,6 +644,32 @@  TEST_FAIL_NTH(basic_fail_nth, device)
 
 	self->pasid = 0;
 
+	if (_test_ioctl_destroy(self->fd, self->stdev_id))
+		return -1;
+
+	self->pasid = 300;
+	self->stdev_id = 0;
+
+	/* Test for SIOV virtual devices attach */
+	if (_test_cmd_mock_domain(self->fd, ioas_id, self->pasid,
+				  &self->stdev_id, NULL, &idev_id))
+		return -1;
+
+	/* Test for SIOV virtual device replace */
+	if (_test_cmd_mock_domain_replace(self->fd, self->stdev_id,
+					  hwpt_id, NULL))
+		return -1;
+
+	if (_test_cmd_pasid_detach(self->fd, self->stdev_id, self->pasid))
+		return -1;
+
+	self->pasid = 0;
+
+	if (_test_ioctl_destroy(self->fd, self->stdev_id))
+		return -1;
+
+	self->stdev_id = 0;
+
 	return 0;
 }