All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yi Liu <yi.l.liu@intel.com>
To: joro@8bytes.org, alex.williamson@redhat.com, jgg@nvidia.com,
	kevin.tian@intel.com, robin.murphy@arm.com,
	baolu.lu@linux.intel.com
Cc: cohuck@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com,
	kvm@vger.kernel.org, mjrosato@linux.ibm.com,
	chao.p.peng@linux.intel.com, yi.l.liu@intel.com,
	yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com,
	shameerali.kolothum.thodi@huawei.com, lulu@redhat.com,
	suravee.suthikulpanit@amd.com, iommu@lists.linux.dev,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	zhenzhong.duan@intel.com, joao.m.martins@oracle.com
Subject: [RFC 5/7] iommufd/selftest: Extend IOMMU_TEST_OP_MOCK_DOMAIN to pass in pasid
Date: Mon,  9 Oct 2023 01:51:21 -0700	[thread overview]
Message-ID: <20231009085123.463179-6-yi.l.liu@intel.com> (raw)
In-Reply-To: <20231009085123.463179-1-yi.l.liu@intel.com>

This extends IOMMU_TEST_OP_MOCK_DOMAIN to accept a pasid from caller.
Hence it is able to cover the iommufd_device_bind_pasid() for SIOV
virtual devices. pasid #0 is selected to mark the physical devices,
non-zero pasid values would be considered as SIOV virtual device bind.
Will add SIOV test cases later.

Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
 drivers/iommu/iommufd/iommufd_test.h          |  2 ++
 drivers/iommu/iommufd/selftest.c              | 10 ++++++--
 tools/testing/selftests/iommu/iommufd.c       | 24 +++++++++----------
 .../selftests/iommu/iommufd_fail_nth.c        | 16 ++++++-------
 tools/testing/selftests/iommu/iommufd_utils.h | 21 +++++++++-------
 5 files changed, 42 insertions(+), 31 deletions(-)

diff --git a/drivers/iommu/iommufd/iommufd_test.h b/drivers/iommu/iommufd/iommufd_test.h
index cf10f250b0d2..64217f33f91a 100644
--- a/drivers/iommu/iommufd/iommufd_test.h
+++ b/drivers/iommu/iommufd/iommufd_test.h
@@ -62,6 +62,8 @@ struct iommu_test_cmd {
 			__aligned_u64 length;
 		} add_reserved;
 		struct {
+			/* #0 is invalid, any non-zero is meaningful */
+			__u32 default_pasid;
 			__u32 out_stdev_id;
 			__u32 out_hwpt_id;
 			/* out_idev_id is the standard iommufd_bind object */
diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c
index 5fb025ab8677..60c6d76c82b4 100644
--- a/drivers/iommu/iommufd/selftest.c
+++ b/drivers/iommu/iommufd/selftest.c
@@ -638,8 +638,14 @@ static int iommufd_test_mock_domain(struct iommufd_ucmd *ucmd,
 		goto out_sobj;
 	}
 
-	idev = iommufd_device_bind(ucmd->ictx, &sobj->idev.mock_dev->dev,
-				   &idev_id);
+	if (!cmd->mock_domain.default_pasid)
+		idev = iommufd_device_bind(ucmd->ictx, &sobj->idev.mock_dev->dev,
+					   &idev_id);
+	else
+		idev = iommufd_device_bind_pasid(ucmd->ictx,
+						 &sobj->idev.mock_dev->dev,
+						 cmd->mock_domain.default_pasid,
+						 &idev_id);
 	if (IS_ERR(idev)) {
 		rc = PTR_ERR(idev);
 		goto out_mdev;
diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c
index be2a95163d10..9a1fbba89e96 100644
--- a/tools/testing/selftests/iommu/iommufd.c
+++ b/tools/testing/selftests/iommu/iommufd.c
@@ -219,7 +219,7 @@ FIXTURE_SETUP(iommufd_ioas)
 	}
 
 	for (i = 0; i != variant->mock_domains; i++) {
-		test_cmd_mock_domain(self->ioas_id, &self->stdev_id,
+		test_cmd_mock_domain(self->ioas_id, 0, &self->stdev_id,
 				     &self->hwpt_id, &self->device_id);
 		self->base_iova = MOCK_APERTURE_START;
 	}
@@ -450,9 +450,9 @@ TEST_F(iommufd_ioas, hwpt_attach)
 {
 	/* Create a device attached directly to a hwpt */
 	if (self->stdev_id) {
-		test_cmd_mock_domain(self->hwpt_id, NULL, NULL, NULL);
+		test_cmd_mock_domain(self->hwpt_id, 0, NULL, NULL, NULL);
 	} else {
-		test_err_mock_domain(ENOENT, self->hwpt_id, NULL, NULL);
+		test_err_mock_domain(ENOENT, self->hwpt_id, 0, NULL, NULL);
 	}
 }
 
@@ -902,7 +902,7 @@ TEST_F(iommufd_ioas, access_pin)
 		ASSERT_EQ(0, ioctl(self->fd,
 				   _IOMMU_TEST_CMD(IOMMU_TEST_OP_ACCESS_PAGES),
 				   &access_cmd));
-		test_cmd_mock_domain(self->ioas_id, &mock_stdev_id,
+		test_cmd_mock_domain(self->ioas_id, 0, &mock_stdev_id,
 				     &mock_hwpt_id, NULL);
 		check_map_cmd.id = mock_hwpt_id;
 		ASSERT_EQ(0, ioctl(self->fd,
@@ -1058,7 +1058,7 @@ TEST_F(iommufd_ioas, fork_gone)
 		 * If a domain already existed then everything was pinned within
 		 * the fork, so this copies from one domain to another.
 		 */
-		test_cmd_mock_domain(self->ioas_id, NULL, NULL, NULL);
+		test_cmd_mock_domain(self->ioas_id, 0, NULL, NULL, NULL);
 		check_access_rw(_metadata, self->fd, access_id,
 				MOCK_APERTURE_START, 0);
 
@@ -1067,7 +1067,7 @@ TEST_F(iommufd_ioas, fork_gone)
 		 * Otherwise we need to actually pin pages which can't happen
 		 * since the fork is gone.
 		 */
-		test_err_mock_domain(EFAULT, self->ioas_id, NULL, NULL);
+		test_err_mock_domain(EFAULT, self->ioas_id, 0, NULL, NULL);
 	}
 
 	test_cmd_destroy_access(access_id);
@@ -1107,7 +1107,7 @@ TEST_F(iommufd_ioas, fork_present)
 	ASSERT_EQ(8, read(efd, &tmp, sizeof(tmp)));
 
 	/* Read pages from the remote process */
-	test_cmd_mock_domain(self->ioas_id, NULL, NULL, NULL);
+	test_cmd_mock_domain(self->ioas_id, 0, NULL, NULL, NULL);
 	check_access_rw(_metadata, self->fd, access_id, MOCK_APERTURE_START, 0);
 
 	ASSERT_EQ(0, close(pipefds[1]));
@@ -1277,7 +1277,7 @@ FIXTURE_SETUP(iommufd_mock_domain)
 	ASSERT_GE(ARRAY_SIZE(self->hwpt_ids), variant->mock_domains);
 
 	for (i = 0; i != variant->mock_domains; i++)
-		test_cmd_mock_domain(self->ioas_id, &self->stdev_ids[i],
+		test_cmd_mock_domain(self->ioas_id, 0, &self->stdev_ids[i],
 				     &self->hwpt_ids[i], &self->idev_ids[i]);
 	self->hwpt_id = self->hwpt_ids[0];
 
@@ -1471,7 +1471,7 @@ TEST_F(iommufd_mock_domain, all_aligns_copy)
 
 			/* Add and destroy a domain while the area exists */
 			old_id = self->hwpt_ids[1];
-			test_cmd_mock_domain(self->ioas_id, &mock_stdev_id,
+			test_cmd_mock_domain(self->ioas_id, 0, &mock_stdev_id,
 					     &self->hwpt_ids[1], NULL);
 
 			check_mock_iova(buf + start, iova, length);
@@ -1609,7 +1609,7 @@ TEST_F(iommufd_mock_domain, alloc_hwpt)
 		test_cmd_mock_domain_replace(self->stdev_ids[i], self->ioas_id);
 		test_ioctl_destroy(hwpt_id[1]);
 
-		test_cmd_mock_domain(hwpt_id[0], &stddev_id, NULL, NULL);
+		test_cmd_mock_domain(hwpt_id[0], 0, &stddev_id, NULL, NULL);
 		test_ioctl_destroy(stddev_id);
 		test_ioctl_destroy(hwpt_id[0]);
 	}
@@ -1756,7 +1756,7 @@ FIXTURE_SETUP(vfio_compat_mock_domain)
 
 	/* Create what VFIO would consider a group */
 	test_ioctl_ioas_alloc(&self->ioas_id);
-	test_cmd_mock_domain(self->ioas_id, NULL, NULL, NULL);
+	test_cmd_mock_domain(self->ioas_id, 0, NULL, NULL, NULL);
 
 	/* Attach it to the vfio compat */
 	vfio_ioas_cmd.ioas_id = self->ioas_id;
@@ -2037,7 +2037,7 @@ FIXTURE_SETUP(iommufd_device_pasid)
 	ASSERT_NE(-1, self->fd);
 	test_ioctl_ioas_alloc(&self->ioas_id);
 
-	test_cmd_mock_domain(self->ioas_id, &self->stdev_id,
+	test_cmd_mock_domain(self->ioas_id, 0, &self->stdev_id,
 			     &self->hwpt_id, &self->device_id);
 }
 
diff --git a/tools/testing/selftests/iommu/iommufd_fail_nth.c b/tools/testing/selftests/iommu/iommufd_fail_nth.c
index f7f4b838c2d1..691903c63de0 100644
--- a/tools/testing/selftests/iommu/iommufd_fail_nth.c
+++ b/tools/testing/selftests/iommu/iommufd_fail_nth.c
@@ -321,7 +321,7 @@ TEST_FAIL_NTH(basic_fail_nth, map_domain)
 
 	fail_nth_enable();
 
-	if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, &hwpt_id, NULL))
+	if (_test_cmd_mock_domain(self->fd, ioas_id, 0, &stdev_id, &hwpt_id, NULL))
 		return -1;
 
 	if (_test_ioctl_ioas_map(self->fd, ioas_id, buffer, 262144, &iova,
@@ -332,7 +332,7 @@ TEST_FAIL_NTH(basic_fail_nth, map_domain)
 	if (_test_ioctl_destroy(self->fd, stdev_id))
 		return -1;
 
-	if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, &hwpt_id, NULL))
+	if (_test_cmd_mock_domain(self->fd, ioas_id, 0, &stdev_id, &hwpt_id, NULL))
 		return -1;
 	return 0;
 }
@@ -356,12 +356,12 @@ TEST_FAIL_NTH(basic_fail_nth, map_two_domains)
 	if (_test_ioctl_set_temp_memory_limit(self->fd, 32))
 		return -1;
 
-	if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, &hwpt_id, NULL))
+	if (_test_cmd_mock_domain(self->fd, ioas_id, 0, &stdev_id, &hwpt_id, NULL))
 		return -1;
 
 	fail_nth_enable();
 
-	if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id2, &hwpt_id2,
+	if (_test_cmd_mock_domain(self->fd, ioas_id, 0, &stdev_id2, &hwpt_id2,
 				  NULL))
 		return -1;
 
@@ -376,9 +376,9 @@ TEST_FAIL_NTH(basic_fail_nth, map_two_domains)
 	if (_test_ioctl_destroy(self->fd, stdev_id2))
 		return -1;
 
-	if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, &hwpt_id, NULL))
+	if (_test_cmd_mock_domain(self->fd, ioas_id, 0, &stdev_id, &hwpt_id, NULL))
 		return -1;
-	if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id2, &hwpt_id2,
+	if (_test_cmd_mock_domain(self->fd, ioas_id, 0, &stdev_id2, &hwpt_id2,
 				  NULL))
 		return -1;
 	return 0;
@@ -536,7 +536,7 @@ TEST_FAIL_NTH(basic_fail_nth, access_pin_domain)
 	if (_test_ioctl_set_temp_memory_limit(self->fd, 32))
 		return -1;
 
-	if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, &hwpt_id, NULL))
+	if (_test_cmd_mock_domain(self->fd, ioas_id, 0, &stdev_id, &hwpt_id, NULL))
 		return -1;
 
 	if (_test_ioctl_ioas_map(self->fd, ioas_id, buffer, BUFFER_SIZE, &iova,
@@ -613,7 +613,7 @@ TEST_FAIL_NTH(basic_fail_nth, device)
 
 	fail_nth_enable();
 
-	if (_test_cmd_mock_domain(self->fd, ioas_id, &self->stdev_id, NULL,
+	if (_test_cmd_mock_domain(self->fd, ioas_id, 0, &self->stdev_id, NULL,
 				  &idev_id))
 		return -1;
 
diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h
index 8339925562f3..bc9080fc9c2f 100644
--- a/tools/testing/selftests/iommu/iommufd_utils.h
+++ b/tools/testing/selftests/iommu/iommufd_utils.h
@@ -44,14 +44,16 @@ static unsigned long PAGE_SIZE;
 				&test_cmd));                                  \
 	})
 
-static int _test_cmd_mock_domain(int fd, unsigned int ioas_id, __u32 *stdev_id,
-				 __u32 *hwpt_id, __u32 *idev_id)
+static int _test_cmd_mock_domain(int fd, unsigned int ioas_id,
+				 unsigned int default_pasid,
+				 __u32 *stdev_id, __u32 *hwpt_id,
+				 __u32 *idev_id)
 {
 	struct iommu_test_cmd cmd = {
 		.size = sizeof(cmd),
 		.op = IOMMU_TEST_OP_MOCK_DOMAIN,
 		.id = ioas_id,
-		.mock_domain = {},
+		.mock_domain = { .default_pasid = default_pasid, },
 	};
 	int ret;
 
@@ -67,12 +69,13 @@ static int _test_cmd_mock_domain(int fd, unsigned int ioas_id, __u32 *stdev_id,
 		*idev_id = cmd.mock_domain.out_idev_id;
 	return 0;
 }
-#define test_cmd_mock_domain(ioas_id, stdev_id, hwpt_id, idev_id)       \
-	ASSERT_EQ(0, _test_cmd_mock_domain(self->fd, ioas_id, stdev_id, \
-					   hwpt_id, idev_id))
-#define test_err_mock_domain(_errno, ioas_id, stdev_id, hwpt_id)      \
-	EXPECT_ERRNO(_errno, _test_cmd_mock_domain(self->fd, ioas_id, \
-						   stdev_id, hwpt_id, NULL))
+#define test_cmd_mock_domain(ioas_id, pasid, stdev_id, hwpt_id, idev_id)   \
+	ASSERT_EQ(0, _test_cmd_mock_domain(self->fd, ioas_id, pasid,       \
+					   stdev_id, hwpt_id, idev_id))
+#define test_err_mock_domain(_errno, ioas_id, pasid, stdev_id, hwpt_id)    \
+	EXPECT_ERRNO(_errno, _test_cmd_mock_domain(self->fd, ioas_id,      \
+						   pasid, stdev_id,        \
+						   hwpt_id, NULL))
 
 static int _test_cmd_mock_domain_replace(int fd, __u32 stdev_id, __u32 pt_id,
 					 __u32 *hwpt_id)
-- 
2.34.1


  parent reply	other threads:[~2023-10-09  8:52 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-09  8:51 [RFC 0/7] Add SIOV virtual device support Yi Liu
2023-10-09  8:51 ` [RFC 1/7] iommufd: Handle unsafe interrupts in a separate function Yi Liu
2023-10-09  8:51 ` [RFC 2/7] iommufd: Introduce iommufd_alloc_device() Yi Liu
2023-10-09  8:51 ` [RFC 3/7] iommufd: Add iommufd_device_bind_pasid() Yi Liu
2023-10-10  8:19   ` Tian, Kevin
2023-11-08  7:45     ` Yi Liu
2023-11-08  8:46       ` Tian, Kevin
2023-11-08  9:03         ` Yi Liu
2023-10-09  8:51 ` [RFC 4/7] iommufd: Support attach/replace for SIOV virtual device {dev, pasid} Yi Liu
2023-10-10  8:24   ` Tian, Kevin
2023-11-09  8:21     ` Yi Liu
2023-10-09  8:51 ` Yi Liu [this message]
2023-10-10  8:25   ` [RFC 5/7] iommufd/selftest: Extend IOMMU_TEST_OP_MOCK_DOMAIN to pass in pasid Tian, Kevin
2023-10-09  8:51 ` [RFC 6/7] iommufd/selftest: Add test coverage for SIOV virtual device Yi Liu
2023-10-10  8:30   ` Tian, Kevin
2023-11-09  7:48     ` Yi Liu
2023-10-09  8:51 ` [RFC 7/7] vfio: Add vfio_register_pasid_iommu_dev() Yi Liu
2023-10-10  8:33   ` Tian, Kevin
2023-11-09  8:20     ` Yi Liu
2023-11-16  5:35   ` Cao, Yahui
2023-11-17  6:31     ` Yi Liu
     [not found]   ` <99115148-d0e3-4920-aed6-669ae45aa2fe@intel.com>
2023-11-17  6:30     ` Yi Liu
2023-10-09 13:21 ` [RFC 0/7] Add SIOV virtual device support Jason Gunthorpe
2023-10-09 23:33   ` Tian, Kevin
2023-11-22  3:59   ` Cao, Yahui

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231009085123.463179-6-yi.l.liu@intel.com \
    --to=yi.l.liu@intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=chao.p.peng@linux.intel.com \
    --cc=cohuck@redhat.com \
    --cc=eric.auger@redhat.com \
    --cc=iommu@lists.linux.dev \
    --cc=jasowang@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=joao.m.martins@oracle.com \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=lulu@redhat.com \
    --cc=mjrosato@linux.ibm.com \
    --cc=nicolinc@nvidia.com \
    --cc=peterx@redhat.com \
    --cc=robin.murphy@arm.com \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=yi.y.sun@linux.intel.com \
    --cc=zhenzhong.duan@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.