From: Nicolin Chen <nicolinc@nvidia.com>
To: <jgg@nvidia.com>, <kevin.tian@intel.com>
Cc: <robin.murphy@arm.com>, <eric.auger@redhat.com>,
<yi.l.liu@intel.com>, <baolu.lu@linux.intel.com>,
<will@kernel.org>, <joro@8bytes.org>,
<shameerali.kolothum.thodi@huawei.com>,
<jean-philippe@linaro.org>,
<linux-arm-kernel@lists.infradead.org>, <iommu@lists.linux.dev>,
<linux-kernel@vger.kernel.org>
Subject: [PATCH v5 3/4] iommufd/selftest: Add IOMMU_TEST_OP_DEV_CHECK_DATA
Date: Thu, 27 Jul 2023 14:09:42 -0700 [thread overview]
Message-ID: <dad673c2f4b50a046bc8cc48c4cb21e97e2e06ed.1690487690.git.nicolinc@nvidia.com> (raw)
In-Reply-To: <cover.1690487690.git.nicolinc@nvidia.com>
Add mock_domain_set/unset_dev_user_data and iommufd_test_dev_check_data to
allow testing on IOMMUFD_CMD_SET/UNSET_DEV_DATA ioctls from the user space
selftest via IOMMU_TEST_OP_DEV_CHECK_DATA.
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
---
drivers/iommu/iommufd/iommufd_test.h | 15 ++++++++++
drivers/iommu/iommufd/selftest.c | 42 ++++++++++++++++++++++++++++
2 files changed, 57 insertions(+)
diff --git a/drivers/iommu/iommufd/iommufd_test.h b/drivers/iommu/iommufd/iommufd_test.h
index 9768d0c9e347..b191d7417719 100644
--- a/drivers/iommu/iommufd/iommufd_test.h
+++ b/drivers/iommu/iommufd/iommufd_test.h
@@ -22,6 +22,7 @@ enum {
IOMMU_TEST_OP_DEV_ADD_RESERVED,
IOMMU_TEST_OP_DEV_DEL_RESERVED,
IOMMU_TEST_OP_MD_CHECK_IOTLB,
+ IOMMU_TEST_OP_DEV_CHECK_DATA,
};
enum {
@@ -105,6 +106,9 @@ struct iommu_test_cmd {
struct {
__u32 iotlb;
} check_iotlb;
+ struct {
+ __u32 val;
+ } check_dev_data;
};
__u32 last;
};
@@ -119,6 +123,17 @@ struct iommu_test_hw_info {
__u32 test_reg;
};
+#define IOMMU_DEVICE_DATA_SELFTEST 0xdadbeef
+
+/**
+ * struct iommu_test_device_data
+ *
+ * @val: Should be set to IOMMU_DEVICE_DATA_SELFTEST or unset to 0x0
+ */
+struct iommu_test_device_data {
+ __u32 val;
+};
+
/* Should not be equal to any defined value in enum iommu_hwpt_type */
#define IOMMU_HWPT_TYPE_SELFTTEST 0xdead
diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c
index 5f3e1f2a24e7..526ec6066d17 100644
--- a/drivers/iommu/iommufd/selftest.c
+++ b/drivers/iommu/iommufd/selftest.c
@@ -97,6 +97,7 @@ struct mock_dev {
struct device dev;
struct rw_semaphore reserved_rwsem;
struct rb_root_cached reserved_itree;
+ u32 dev_data;
};
struct selftest_obj {
@@ -375,6 +376,23 @@ static void iommufd_test_get_resv_regions(struct device *dev,
up_read(&mdev->reserved_rwsem);
}
+static int mock_domain_set_dev_user_data(struct device *dev,
+ const void *user_data)
+{
+ struct mock_dev *mdev = container_of(dev, struct mock_dev, dev);
+ const struct iommu_test_device_data *data = user_data;
+
+ mdev->dev_data = data->val;
+ return 0;
+}
+
+static void mock_domain_unset_dev_user_data(struct device *dev)
+{
+ struct mock_dev *mdev = container_of(dev, struct mock_dev, dev);
+
+ mdev->dev_data = 0;
+}
+
static const struct iommu_ops mock_ops = {
.owner = THIS_MODULE,
.pgsize_bitmap = MOCK_IO_PAGE_SIZE,
@@ -385,6 +403,9 @@ static const struct iommu_ops mock_ops = {
.capable = mock_domain_capable,
.get_resv_regions = iommufd_test_get_resv_regions,
.set_platform_dma_ops = mock_domain_set_plaform_dma_ops,
+ .set_dev_user_data = mock_domain_set_dev_user_data,
+ .unset_dev_user_data = mock_domain_unset_dev_user_data,
+ .dev_user_data_len = sizeof(struct iommu_test_device_data),
.default_domain_ops =
&(struct iommu_domain_ops){
.free = mock_domain_free,
@@ -833,6 +854,24 @@ static int iommufd_test_md_check_iotlb(struct iommufd_ucmd *ucmd,
return rc;
}
+static int iommufd_test_dev_check_data(struct iommufd_ucmd *ucmd,
+ u32 dev_id, u32 val)
+{
+ struct iommufd_device *idev;
+ struct mock_dev *mdev;
+ int rc = 0;
+
+ idev = iommufd_get_device(ucmd, dev_id);
+ if (IS_ERR(idev))
+ return PTR_ERR(idev);
+ mdev = container_of(idev->dev, struct mock_dev, dev);
+
+ if (mdev->dev_data != val)
+ rc = -EINVAL;
+ iommufd_put_object(&idev->obj);
+ return rc;
+}
+
struct selftest_access {
struct iommufd_access *access;
struct file *file;
@@ -1255,6 +1294,9 @@ int iommufd_test(struct iommufd_ucmd *ucmd)
case IOMMU_TEST_OP_MD_CHECK_IOTLB:
return iommufd_test_md_check_iotlb(ucmd, cmd->id,
cmd->check_iotlb.iotlb);
+ case IOMMU_TEST_OP_DEV_CHECK_DATA:
+ return iommufd_test_dev_check_data(ucmd, cmd->id,
+ cmd->check_dev_data.val);
case IOMMU_TEST_OP_CREATE_ACCESS:
return iommufd_test_create_access(ucmd, cmd->id,
cmd->create_access.flags);
--
2.41.0
next prev parent reply other threads:[~2023-07-27 21:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-27 21:09 [PATCH v5 0/4] Add set_dev_data and unset_dev_data support Nicolin Chen
2023-07-27 21:09 ` [PATCH v5 1/4] iommu: Add set/unset_dev_user_data ops Nicolin Chen
2023-07-27 21:09 ` [PATCH v5 2/4] iommufd: Add IOMMUFD_CMD_SET_DEV_DATA and IOMMUFD_CMD_UNSET_DEV_DATA Nicolin Chen
2023-07-27 21:09 ` Nicolin Chen [this message]
2023-07-27 21:09 ` [PATCH v5 4/4] iommufd/selftest: Add coverage for IOMMU_SET/UNSET_DEV_DATA 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=dad673c2f4b50a046bc8cc48c4cb21e97e2e06ed.1690487690.git.nicolinc@nvidia.com \
--to=nicolinc@nvidia.com \
--cc=baolu.lu@linux.intel.com \
--cc=eric.auger@redhat.com \
--cc=iommu@lists.linux.dev \
--cc=jean-philippe@linaro.org \
--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=robin.murphy@arm.com \
--cc=shameerali.kolothum.thodi@huawei.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®