From: Nicolin Chen <nicolinc@nvidia.com>
To: <jgg@nvidia.com>, <kevin.tian@intel.com>, <will@kernel.org>
Cc: <joro@8bytes.org>, <suravee.suthikulpanit@amd.com>,
<robin.murphy@arm.com>, <dwmw2@infradead.org>,
<baolu.lu@linux.intel.com>, <shuah@kernel.org>,
<linux-kernel@vger.kernel.org>, <iommu@lists.linux.dev>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kselftest@vger.kernel.org>
Subject: [PATCH v1 06/16] iommufd/selftest: Add IOMMU_VIOMMU_SET/UNSET_VDEV_ID test coverage
Date: Wed, 7 Aug 2024 13:10:47 -0700 [thread overview]
Message-ID: <4e7303c6dc2cd585c3855be9cf9d032f23c66b9e.1723061378.git.nicolinc@nvidia.com> (raw)
In-Reply-To: <cover.1723061377.git.nicolinc@nvidia.com>
A core-managed VIOMMU maintains an xarray to store a list of virtual ids
to mock_devs.
Add test cases to cover the new IOMMU_VIOMMU_SET/UNSET_VDEV_ID ioctls.
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
---
tools/testing/selftests/iommu/iommufd.c | 35 +++++++++++++++-
tools/testing/selftests/iommu/iommufd_utils.h | 42 +++++++++++++++++++
2 files changed, 75 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c
index 5c770e94f299..2c11525ae754 100644
--- a/tools/testing/selftests/iommu/iommufd.c
+++ b/tools/testing/selftests/iommu/iommufd.c
@@ -556,9 +556,15 @@ TEST_F(iommufd_ioas, alloc_hwpt_nested)
TEST_F(iommufd_ioas, viommu_default)
{
+ struct iommu_hwpt_selftest data = {
+ .iotlb = IOMMU_TEST_IOTLB_DEFAULT,
+ };
+ uint32_t nested_hwpt_id = 0, hwpt_id = 0;
uint32_t dev_id = self->device_id;
uint32_t viommu_id = 0;
- uint32_t hwpt_id = 0;
+ uint32_t device2;
+ uint32_t stdev2;
+ uint32_t hwpt2;
if (dev_id) {
/* Negative test -- invalid hwpt */
@@ -575,17 +581,42 @@ TEST_F(iommufd_ioas, viommu_default)
test_cmd_hwpt_alloc(dev_id, self->ioas_id,
IOMMU_HWPT_ALLOC_NEST_PARENT,
&hwpt_id);
+ test_cmd_mock_domain_replace(self->stdev_id, hwpt_id);
+
/* Negative test -- unsupported viommu type */
test_err_viommu_alloc(EOPNOTSUPP, dev_id, hwpt_id,
0xdead, &viommu_id);
- /* Allocate a default type of viommu */
+
+ /* Allocate a default type of viommu and a nested hwpt on top */
test_cmd_viommu_alloc(dev_id, hwpt_id,
IOMMU_VIOMMU_TYPE_DEFAULT, &viommu_id);
+ test_cmd_hwpt_alloc_nested(self->device_id, viommu_id, 0,
+ &nested_hwpt_id,
+ IOMMU_HWPT_DATA_SELFTEST, &data,
+ sizeof(data));
+ test_cmd_mock_domain_replace(self->stdev_id, nested_hwpt_id);
+
+ /* Set vdev_id to 0x99, unset it, and set to 0x88 */
+ test_cmd_viommu_set_vdev_id(viommu_id, dev_id, 0x99);
+ test_err_viommu_set_vdev_id(EBUSY, viommu_id, dev_id, 0x99);
+ test_err_viommu_unset_vdev_id(EINVAL, viommu_id, dev_id, 0x88);
+ test_cmd_viommu_unset_vdev_id(viommu_id, dev_id, 0x99);
+ test_cmd_viommu_set_vdev_id(viommu_id, dev_id, 0x88);
+
+ /* Negative test -- a device attached to a different HWPT */
+ test_cmd_mock_domain(self->ioas_id, &stdev2, &hwpt2, &device2);
+ test_err_viommu_set_vdev_id(EINVAL, viommu_id, device2, 0xaa);
+ test_ioctl_destroy(stdev2);
+
+ test_cmd_mock_domain_replace(self->stdev_id, hwpt_id);
+ test_ioctl_destroy(nested_hwpt_id);
+ test_cmd_mock_domain_replace(self->stdev_id, self->ioas_id);
test_ioctl_destroy(viommu_id);
test_ioctl_destroy(hwpt_id);
} else {
test_err_viommu_alloc(ENOENT, dev_id, hwpt_id,
IOMMU_VIOMMU_TYPE_DEFAULT, &viommu_id);
+ test_err_viommu_set_vdev_id(ENOENT, viommu_id, dev_id, 0x99);
}
}
diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h
index 810783d31ca5..1b494752a87f 100644
--- a/tools/testing/selftests/iommu/iommufd_utils.h
+++ b/tools/testing/selftests/iommu/iommufd_utils.h
@@ -799,3 +799,45 @@ static int _test_cmd_viommu_alloc(int fd, __u32 device_id, __u32 hwpt_id,
EXPECT_ERRNO(_errno, _test_cmd_viommu_alloc(self->fd, device_id, \
hwpt_id, type, 0, \
viommu_id))
+
+static int _test_cmd_viommu_set_vdev_id(int fd, __u32 viommu_id,
+ __u32 idev_id, __u64 vdev_id)
+{
+ struct iommu_viommu_set_vdev_id cmd = {
+ .size = sizeof(cmd),
+ .dev_id = idev_id,
+ .viommu_id = viommu_id,
+ .vdev_id = vdev_id,
+ };
+
+ return ioctl(fd, IOMMU_VIOMMU_SET_VDEV_ID, &cmd);
+}
+
+#define test_cmd_viommu_set_vdev_id(viommu_id, idev_id, vdev_id) \
+ ASSERT_EQ(0, _test_cmd_viommu_set_vdev_id(self->fd, viommu_id, \
+ idev_id, vdev_id))
+#define test_err_viommu_set_vdev_id(_errno, viommu_id, idev_id, vdev_id) \
+ EXPECT_ERRNO(_errno, \
+ _test_cmd_viommu_set_vdev_id(self->fd, viommu_id, \
+ idev_id, vdev_id))
+
+static int _test_cmd_viommu_unset_vdev_id(int fd, __u32 viommu_id,
+ __u32 idev_id, __u64 vdev_id)
+{
+ struct iommu_viommu_unset_vdev_id cmd = {
+ .size = sizeof(cmd),
+ .dev_id = idev_id,
+ .viommu_id = viommu_id,
+ .vdev_id = vdev_id,
+ };
+
+ return ioctl(fd, IOMMU_VIOMMU_UNSET_VDEV_ID, &cmd);
+}
+
+#define test_cmd_viommu_unset_vdev_id(viommu_id, idev_id, vdev_id) \
+ ASSERT_EQ(0, _test_cmd_viommu_unset_vdev_id(self->fd, viommu_id, \
+ idev_id, vdev_id))
+#define test_err_viommu_unset_vdev_id(_errno, viommu_id, idev_id, vdev_id) \
+ EXPECT_ERRNO(_errno, \
+ _test_cmd_viommu_unset_vdev_id(self->fd, viommu_id, \
+ idev_id, vdev_id))
--
2.43.0
next prev parent reply other threads:[~2024-08-07 20:11 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-07 20:10 [PATCH v1 00/16] iommufd: Add VIOMMU infrastructure (Part-1) Nicolin Chen
2024-08-07 20:10 ` [PATCH v1 01/16] iommufd/viommu: Add IOMMUFD_OBJ_VIOMMU and IOMMU_VIOMMU_ALLOC ioctl Nicolin Chen
2024-08-14 16:50 ` Nicolin Chen
2024-08-15 18:11 ` Jason Gunthorpe
2024-08-15 18:20 ` Nicolin Chen
2024-08-15 23:37 ` Jason Gunthorpe
2024-08-15 18:31 ` Jason Gunthorpe
2024-08-07 20:10 ` [PATCH v1 02/16] iommu: Pass in a viommu pointer to domain_alloc_user op Nicolin Chen
2024-08-07 20:10 ` [PATCH v1 03/16] iommufd: Allow pt_id to carry viommu_id for IOMMU_HWPT_ALLOC Nicolin Chen
2024-08-07 20:10 ` [PATCH v1 04/16] iommufd/selftest: Add IOMMU_VIOMMU_ALLOC test coverage Nicolin Chen
2024-08-07 20:10 ` [PATCH v1 05/16] iommufd/viommu: Add IOMMU_VIOMMU_SET/UNSET_VDEV_ID ioctl Nicolin Chen
2024-08-14 17:09 ` Nicolin Chen
2024-08-14 22:02 ` Jason Gunthorpe
2024-08-15 19:08 ` Jason Gunthorpe
2024-08-15 19:46 ` Nicolin Chen
2024-08-15 19:53 ` Nicolin Chen
2024-08-15 23:42 ` Jason Gunthorpe
2024-08-15 23:41 ` Jason Gunthorpe
2024-08-16 0:21 ` Nicolin Chen
2024-08-19 17:33 ` Jason Gunthorpe
2024-08-19 18:10 ` Nicolin Chen
2024-08-19 18:26 ` Jason Gunthorpe
2024-08-07 20:10 ` Nicolin Chen [this message]
2024-08-07 20:10 ` [PATCH v1 07/16] iommufd/viommu: Add cache_invalidate for IOMMU_VIOMMU_TYPE_DEFAULT Nicolin Chen
2024-08-07 20:10 ` [PATCH v1 08/16] iommufd/viommu: Add IOMMU_VIOMMU_INVALIDATE ioctl Nicolin Chen
2024-08-15 23:24 ` Jason Gunthorpe
2024-08-15 23:51 ` Nicolin Chen
2024-08-19 17:30 ` Jason Gunthorpe
2024-08-19 17:49 ` Nicolin Chen
2024-08-19 18:20 ` Jason Gunthorpe
2024-08-19 18:22 ` Nicolin Chen
2024-08-07 20:10 ` [PATCH v1 09/16] iommufd/viommu: Make iommufd_viommu_find_device a public API Nicolin Chen
2024-08-07 20:10 ` [PATCH v1 10/16] iommufd/selftest: Add mock_viommu_invalidate_user op Nicolin Chen
2024-08-07 20:10 ` [PATCH v1 11/16] iommufd/selftest: Add IOMMU_TEST_OP_DEV_CHECK_CACHE test command Nicolin Chen
2024-08-07 20:10 ` [PATCH v1 12/16] iommufd/selftest: Add coverage for IOMMU_VIOMMU_INVALIDATE ioctl Nicolin Chen
2024-08-07 20:10 ` [PATCH v1 13/16] iommufd/viommu: Add iommufd_viommu_to_parent_domain helper Nicolin Chen
2024-08-07 20:10 ` [PATCH v1 14/16] iommu/arm-smmu-v3: Extract an __arm_smmu_cache_invalidate_user helper Nicolin Chen
2024-08-07 20:10 ` [PATCH v1 15/16] iommu/arm-smmu-v3: Add viommu cache invalidation support Nicolin Chen
2024-08-15 23:36 ` Jason Gunthorpe
2024-08-16 0:50 ` Nicolin Chen
2024-08-19 17:36 ` Jason Gunthorpe
2024-08-19 18:19 ` Nicolin Chen
2024-08-19 18:28 ` Jason Gunthorpe
2024-08-19 18:38 ` Nicolin Chen
2024-08-19 18:47 ` Jason Gunthorpe
2024-08-19 18:54 ` Nicolin Chen
2024-08-07 20:10 ` [PATCH v1 16/16] iommu/arm-smmu-v3: Allow ATS for IOMMU_DOMAIN_NESTED Nicolin Chen
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=4e7303c6dc2cd585c3855be9cf9d032f23c66b9e.1723061378.git.nicolinc@nvidia.com \
--to=nicolinc@nvidia.com \
--cc=baolu.lu@linux.intel.com \
--cc=dwmw2@infradead.org \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=robin.murphy@arm.com \
--cc=shuah@kernel.org \
--cc=suravee.suthikulpanit@amd.com \
--cc=will@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox