From: Nicolin Chen <nicolinc@nvidia.com>
To: <jgg@nvidia.com>, <robin.murphy@arm.com>, <kevin.tian@intel.com>
Cc: <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 RFC v1 3/3] iommu/arm-smmu-v3: Implement set_rid_user and unset_rid_user
Date: Wed, 5 Apr 2023 23:25:36 -0700 [thread overview]
Message-ID: <2f00c7faa5c8ddfb4b94e85d3c5af7a0fa8df35d.1680762112.git.nicolinc@nvidia.com> (raw)
In-Reply-To: <cover.1680762112.git.nicolinc@nvidia.com>
Implement the new set_rid_user and unset_rid_user ops, by using an xarray
to store the stream pointer indexed by a given user space Stream ID. This
will be used by user cache invalidation hypercall, to check the SID field
of an ATC_INV command and replace it with the corresponding physical SID.
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
---
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 45 +++++++++++++++++++++
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 +
2 files changed, 47 insertions(+)
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index f2425b0f0cd6..17bb90e78547 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -2843,6 +2843,48 @@ static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid)
arm_smmu_sva_remove_dev_pasid(domain, dev, pasid);
}
+static int arm_smmu_set_rid_user(struct device *dev, u32 rid, u32 rid_base)
+{
+ struct arm_smmu_master *master = dev_iommu_priv_get(dev);
+ struct arm_smmu_stream *stream = &master->streams[0];
+ struct arm_smmu_device *smmu = master->smmu;
+ u32 sid_user = rid_base | rid;
+ int ret = 0;
+
+ if (!sid_user)
+ return -EINVAL;
+
+ ret = xa_alloc(&smmu->streams_user, &sid_user, stream,
+ XA_LIMIT(sid_user, sid_user), GFP_KERNEL_ACCOUNT);
+ if (ret)
+ return ret;
+ stream->id_user = sid_user;
+ return 0;
+}
+
+static int arm_smmu_unset_rid_user(struct device *dev)
+{
+ struct arm_smmu_master *master = dev_iommu_priv_get(dev);
+ struct arm_smmu_stream *stream = &master->streams[0];
+ struct arm_smmu_device *smmu = master->smmu;
+ u32 sid_user = stream->id_user;
+
+ if (!sid_user)
+ return -ENODEV;
+
+ xa_lock(&smmu->streams_user);
+ stream = __xa_erase(&smmu->streams_user, sid_user);
+ if (stream != master->streams) {
+ WARN_ON(__xa_alloc(&smmu->streams_user, &sid_user, stream,
+ XA_LIMIT(sid_user, sid_user),
+ GFP_KERNEL_ACCOUNT));
+ xa_unlock(&smmu->streams_user);
+ return -EINVAL;
+ }
+ xa_unlock(&smmu->streams_user);
+ return 0;
+}
+
static struct iommu_ops arm_smmu_ops = {
.capable = arm_smmu_capable,
.domain_alloc = arm_smmu_domain_alloc,
@@ -2854,6 +2896,8 @@ static struct iommu_ops arm_smmu_ops = {
.remove_dev_pasid = arm_smmu_remove_dev_pasid,
.dev_enable_feat = arm_smmu_dev_enable_feature,
.dev_disable_feat = arm_smmu_dev_disable_feature,
+ .set_rid_user = arm_smmu_set_rid_user,
+ .unset_rid_user = arm_smmu_unset_rid_user,
.page_response = arm_smmu_page_response,
.def_domain_type = arm_smmu_def_domain_type,
.pgsize_bitmap = -1UL, /* Restricted during device attach */
@@ -3082,6 +3126,7 @@ static int arm_smmu_init_structures(struct arm_smmu_device *smmu)
mutex_init(&smmu->streams_mutex);
smmu->streams = RB_ROOT;
+ xa_init_flags(&smmu->streams_user, XA_FLAGS_ALLOC1 | XA_FLAGS_ACCOUNT);
ret = arm_smmu_init_queues(smmu);
if (ret)
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
index 8d772ea8a583..8ccea2e84bbb 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
@@ -674,10 +674,12 @@ struct arm_smmu_device {
struct rb_root streams;
struct mutex streams_mutex;
+ struct xarray streams_user;
};
struct arm_smmu_stream {
u32 id;
+ u32 id_user;
struct arm_smmu_master *master;
struct rb_node node;
};
--
2.40.0
prev parent reply other threads:[~2023-04-06 6:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-06 6:25 [PATCH RFC v1 0/3] Add set_rid_user and unset_rid_user support Nicolin Chen
2023-04-06 6:25 ` [PATCH RFC v1 1/3] iommu: Add set/unset_rid_user ops Nicolin Chen
2023-04-06 6:25 ` [PATCH RFC v1 2/3] iommufd: Add IOMMUFD_CMD_DEVICE_SET_RID and IOMMUFD_CMD_DEVICE_UNSET_RID Nicolin Chen
2023-04-06 6:25 ` Nicolin Chen [this message]
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=2f00c7faa5c8ddfb4b94e85d3c5af7a0fa8df35d.1680762112.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®