From: Lu Baolu <baolu.lu@linux.intel.com>
To: Jason Gunthorpe <jgg@ziepe.ca>, Kevin Tian <kevin.tian@intel.com>,
Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
Jean-Philippe Brucker <jean-philippe@linaro.org>,
Nicolin Chen <nicolinc@nvidia.com>, Yi Liu <yi.l.liu@intel.com>,
Jacob Pan <jacob.jun.pan@linux.intel.com>
Cc: iommu@lists.linux.dev, linux-kselftest@vger.kernel.org,
virtualization@lists.linux-foundation.org,
linux-kernel@vger.kernel.org, Lu Baolu <baolu.lu@linux.intel.com>
Subject: [PATCH v2 6/6] iommufd/selftest: Add coverage for IOMMU_TEST_OP_TRIGGER_IOPF
Date: Thu, 26 Oct 2023 10:49:30 +0800 [thread overview]
Message-ID: <20231026024930.382898-7-baolu.lu@linux.intel.com> (raw)
In-Reply-To: <20231026024930.382898-1-baolu.lu@linux.intel.com>
Extend the selftest tool to add coverage of testing IOPF handling. This
would include the following tests:
- Allocating and destroying an IOPF-capable HWPT.
- Attaching/detaching/replacing an IOPF-capable HWPT on a device.
- Triggering an IOPF on the mock device.
- Retrieving and responding to the IOPF through the IOPF FD
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
tools/testing/selftests/iommu/iommufd_utils.h | 66 +++++++++++++++++--
tools/testing/selftests/iommu/iommufd.c | 24 +++++--
.../selftests/iommu/iommufd_fail_nth.c | 2 +-
3 files changed, 81 insertions(+), 11 deletions(-)
diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h
index b75f168fca46..df22c02af997 100644
--- a/tools/testing/selftests/iommu/iommufd_utils.h
+++ b/tools/testing/selftests/iommu/iommufd_utils.h
@@ -103,8 +103,8 @@ static int _test_cmd_mock_domain_replace(int fd, __u32 stdev_id, __u32 pt_id,
pt_id, NULL))
static int _test_cmd_hwpt_alloc(int fd, __u32 device_id, __u32 pt_id,
- __u32 flags, __u32 *hwpt_id, __u32 hwpt_type,
- void *data, size_t data_len)
+ __u32 flags, __u32 *hwpt_id, __u32 *fault_fd,
+ __u32 hwpt_type, void *data, size_t data_len)
{
struct iommu_hwpt_alloc cmd = {
.size = sizeof(cmd),
@@ -122,28 +122,39 @@ static int _test_cmd_hwpt_alloc(int fd, __u32 device_id, __u32 pt_id,
return ret;
if (hwpt_id)
*hwpt_id = cmd.out_hwpt_id;
+ if (fault_fd)
+ *fault_fd = cmd.out_fault_fd;
+
return 0;
}
#define test_cmd_hwpt_alloc(device_id, pt_id, flags, hwpt_id) \
ASSERT_EQ(0, _test_cmd_hwpt_alloc(self->fd, device_id, pt_id, flags, \
- hwpt_id, IOMMU_HWPT_TYPE_DEFAULT, \
+ hwpt_id, NULL, \
+ IOMMU_HWPT_TYPE_DEFAULT, \
NULL, 0))
#define test_err_hwpt_alloc(_errno, device_id, pt_id, flags, hwpt_id) \
EXPECT_ERRNO(_errno, _test_cmd_hwpt_alloc(self->fd, device_id, pt_id, \
- flags, hwpt_id, \
+ flags, hwpt_id, NULL, \
IOMMU_HWPT_TYPE_DEFAULT, \
NULL, 0))
#define test_cmd_hwpt_alloc_nested(device_id, pt_id, flags, hwpt_id, \
hwpt_type, data, data_len) \
ASSERT_EQ(0, _test_cmd_hwpt_alloc(self->fd, device_id, pt_id, flags, \
- hwpt_id, hwpt_type, data, data_len))
+ hwpt_id, NULL, hwpt_type, data, \
+ data_len))
#define test_err_hwpt_alloc_nested(_errno, device_id, pt_id, flags, hwpt_id, \
hwpt_type, data, data_len) \
EXPECT_ERRNO(_errno, \
_test_cmd_hwpt_alloc(self->fd, device_id, pt_id, flags, \
- hwpt_id, hwpt_type, data, data_len))
+ hwpt_id, NULL, hwpt_type, data, \
+ data_len))
+#define test_cmd_hwpt_alloc_nested_iopf(device_id, pt_id, flags, hwpt_id, \
+ fault_fd, hwpt_type, data, data_len) \
+ ASSERT_EQ(0, _test_cmd_hwpt_alloc(self->fd, device_id, pt_id, flags, \
+ hwpt_id, fault_fd, hwpt_type, data, \
+ data_len))
#define test_cmd_hwpt_check_iotlb(hwpt_id, iotlb_id, expected) \
({ \
@@ -551,3 +562,46 @@ static int _test_cmd_unset_dev_data(int fd, __u32 device_id)
#define test_err_unset_dev_data(_errno, device_id) \
EXPECT_ERRNO(_errno, \
_test_cmd_unset_dev_data(self->fd, device_id))
+
+static int _test_cmd_trigger_iopf(int fd, __u32 device_id, __u32 fault_fd, __u32 hwpt_id)
+{
+ struct iommu_test_cmd trigger_iopf_cmd = {
+ .size = sizeof(trigger_iopf_cmd),
+ .op = IOMMU_TEST_OP_TRIGGER_IOPF,
+ .trigger_iopf = {
+ .dev_id = device_id,
+ .pasid = 0x1,
+ .grpid = 0x2,
+ .perm = IOMMU_PGFAULT_PERM_READ | IOMMU_PGFAULT_PERM_WRITE,
+ .addr = 0xdeadbeaf,
+ },
+ };
+ struct iommu_hwpt_page_response response = {
+ .size = sizeof(struct iommu_hwpt_page_response),
+ .hwpt_id = hwpt_id,
+ .dev_id = device_id,
+ .pasid = 0x1,
+ .grpid = 0x2,
+ .code = 0,
+ };
+ struct iommu_hwpt_pgfault fault = {};
+ ssize_t bytes;
+ int ret;
+
+ ret = ioctl(fd, _IOMMU_TEST_CMD(IOMMU_TEST_OP_TRIGGER_IOPF), &trigger_iopf_cmd);
+ if (ret)
+ return ret;
+
+ bytes = read(fault_fd, &fault, sizeof(fault));
+ if (bytes < 0)
+ return bytes;
+
+ bytes = write(fault_fd, &response, sizeof(response));
+ if (bytes < 0)
+ return bytes;
+
+ return 0;
+}
+
+#define test_cmd_trigger_iopf(device_id, fault_fd, hwpt_id) \
+ ASSERT_EQ(0, _test_cmd_trigger_iopf(self->fd, device_id, fault_fd, hwpt_id))
diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c
index 7cf06a4635d8..b30b82a72785 100644
--- a/tools/testing/selftests/iommu/iommufd.c
+++ b/tools/testing/selftests/iommu/iommufd.c
@@ -275,11 +275,12 @@ TEST_F(iommufd_ioas, alloc_hwpt_nested)
.iotlb = IOMMU_TEST_IOTLB_DEFAULT,
};
struct iommu_hwpt_invalidate_selftest inv_reqs[2] = {0};
- uint32_t nested_hwpt_id[2] = {};
+ uint32_t nested_hwpt_id[3] = {};
uint32_t num_inv, driver_error;
uint32_t parent_hwpt_id = 0;
uint32_t parent_hwpt_id_not_work = 0;
uint32_t test_hwpt_id = 0;
+ uint32_t fault_fd;
if (self->device_id) {
/* Negative tests */
@@ -323,7 +324,7 @@ TEST_F(iommufd_ioas, alloc_hwpt_nested)
IOMMU_HWPT_TYPE_SELFTEST,
&data, sizeof(data));
- /* Allocate two nested hwpts sharing one common parent hwpt */
+ /* Allocate nested hwpts sharing one common parent hwpt */
test_cmd_hwpt_alloc_nested(self->device_id, parent_hwpt_id,
0, &nested_hwpt_id[0],
IOMMU_HWPT_TYPE_SELFTEST,
@@ -332,6 +333,11 @@ TEST_F(iommufd_ioas, alloc_hwpt_nested)
0, &nested_hwpt_id[1],
IOMMU_HWPT_TYPE_SELFTEST,
&data, sizeof(data));
+ test_cmd_hwpt_alloc_nested_iopf(self->device_id, parent_hwpt_id,
+ IOMMU_HWPT_ALLOC_IOPF_CAPABLE,
+ &nested_hwpt_id[2], &fault_fd,
+ IOMMU_HWPT_TYPE_SELFTEST,
+ &data, sizeof(data));
test_cmd_hwpt_check_iotlb_all(nested_hwpt_id[0],
IOMMU_TEST_IOTLB_DEFAULT);
test_cmd_hwpt_check_iotlb_all(nested_hwpt_id[1],
@@ -418,10 +424,20 @@ TEST_F(iommufd_ioas, alloc_hwpt_nested)
_test_ioctl_destroy(self->fd, nested_hwpt_id[1]));
test_ioctl_destroy(nested_hwpt_id[0]);
- /* Detach from nested_hwpt_id[1] and destroy it */
- test_cmd_mock_domain_replace(self->stdev_id, parent_hwpt_id);
+ /* Switch from nested_hwpt_id[1] to nested_hwpt_id[2] */
+ test_cmd_mock_domain_replace(self->stdev_id,
+ nested_hwpt_id[2]);
+ EXPECT_ERRNO(EBUSY,
+ _test_ioctl_destroy(self->fd, nested_hwpt_id[2]));
test_ioctl_destroy(nested_hwpt_id[1]);
+ /* Trigger an IOPF on the device */
+ test_cmd_trigger_iopf(self->device_id, fault_fd, nested_hwpt_id[2]);
+
+ /* Detach from nested_hwpt_id[2] and destroy it */
+ test_cmd_mock_domain_replace(self->stdev_id, parent_hwpt_id);
+ test_ioctl_destroy(nested_hwpt_id[2]);
+
/* Detach from the parent hw_pagetable and destroy it */
test_cmd_mock_domain_replace(self->stdev_id, self->ioas_id);
test_ioctl_destroy(parent_hwpt_id);
diff --git a/tools/testing/selftests/iommu/iommufd_fail_nth.c b/tools/testing/selftests/iommu/iommufd_fail_nth.c
index d3f47f262c04..2b7b582c17c4 100644
--- a/tools/testing/selftests/iommu/iommufd_fail_nth.c
+++ b/tools/testing/selftests/iommu/iommufd_fail_nth.c
@@ -615,7 +615,7 @@ TEST_FAIL_NTH(basic_fail_nth, device)
if (_test_cmd_get_hw_info(self->fd, idev_id, &info, sizeof(info)))
return -1;
- if (_test_cmd_hwpt_alloc(self->fd, idev_id, ioas_id, 0, &hwpt_id,
+ if (_test_cmd_hwpt_alloc(self->fd, idev_id, ioas_id, 0, &hwpt_id, NULL,
IOMMU_HWPT_TYPE_DEFAULT, 0, 0))
return -1;
--
2.34.1
next prev parent reply other threads:[~2023-10-26 2:53 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20231204150747eucas1p2365e92a7ac33ba99b801d7c800acaf6a@eucas1p2.samsung.com>
2023-10-26 2:49 ` [PATCH v2 0/6] IOMMUFD: Deliver IO page faults to user space Lu Baolu
2023-10-26 2:49 ` [PATCH v2 1/6] iommu: Add iommu page fault cookie helpers Lu Baolu
2023-12-01 14:38 ` Jason Gunthorpe
2023-12-08 6:24 ` Baolu Lu
2023-10-26 2:49 ` [PATCH v2 2/6] iommufd: Add iommu page fault uapi data Lu Baolu
2023-12-01 15:14 ` Jason Gunthorpe
2023-12-08 6:35 ` Baolu Lu
2023-10-26 2:49 ` [PATCH v2 3/6] iommufd: Initializing and releasing IO page fault data Lu Baolu
2023-12-12 13:10 ` Joel Granados
2023-12-12 14:12 ` Jason Gunthorpe
2023-12-13 2:04 ` Baolu Lu
2023-12-13 2:15 ` Tian, Kevin
2023-12-13 13:19 ` Jason Gunthorpe
2023-10-26 2:49 ` [PATCH v2 4/6] iommufd: Deliver fault messages to user space Lu Baolu
2023-12-01 15:24 ` Jason Gunthorpe
2023-12-08 11:43 ` Baolu Lu
2023-12-07 16:34 ` Joel Granados
2023-12-07 17:17 ` Jason Gunthorpe
2023-12-08 5:47 ` Baolu Lu
2023-12-08 13:41 ` Jason Gunthorpe
2024-01-12 17:46 ` Shameerali Kolothum Thodi
2024-01-15 16:47 ` Jason Gunthorpe
2024-01-15 17:44 ` Shameerali Kolothum Thodi
2024-01-15 17:58 ` Jason Gunthorpe
2023-10-26 2:49 ` [PATCH v2 5/6] iommufd/selftest: Add IOMMU_TEST_OP_TRIGGER_IOPF test support Lu Baolu
2023-10-26 2:49 ` Lu Baolu [this message]
2023-11-02 12:47 ` [PATCH v2 0/6] IOMMUFD: Deliver IO page faults to user space Jason Gunthorpe
2023-11-02 12:47 ` Jason Gunthorpe
2023-11-07 8:35 ` Tian, Kevin
2023-11-07 8:35 ` Tian, Kevin
2023-11-07 17:54 ` Jason Gunthorpe
2023-11-07 17:54 ` Jason Gunthorpe
2023-11-08 8:53 ` Tian, Kevin
2023-11-08 17:39 ` Jason Gunthorpe
[not found] ` <c774e157-9b47-4fb8-80dd-37441c69b43d@linux.intel.com>
2023-11-15 13:58 ` Jason Gunthorpe
2023-11-16 1:42 ` Liu, Jing2
2023-11-21 0:14 ` Jason Gunthorpe
2023-11-29 9:08 ` Shameerali Kolothum Thodi
2023-11-30 3:44 ` Baolu Lu
2023-12-01 14:24 ` Jason Gunthorpe
2023-12-08 5:57 ` Baolu Lu
2023-12-08 13:43 ` Jason Gunthorpe
2023-12-04 15:07 ` Joel Granados
2023-12-04 15:32 ` Jason Gunthorpe
2023-12-08 5:10 ` Baolu Lu
2024-01-12 21:56 ` Joel Granados
2024-01-14 13:13 ` Baolu Lu
2024-01-14 17:18 ` Joel Granados
2024-01-15 1:25 ` Baolu Lu
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=20231026024930.382898-7-baolu.lu@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=iommu@lists.linux.dev \
--cc=jacob.jun.pan@linux.intel.com \
--cc=jean-philippe@linaro.org \
--cc=jgg@ziepe.ca \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=nicolinc@nvidia.com \
--cc=robin.murphy@arm.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=will@kernel.org \
--cc=yi.l.liu@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.