From: Nicolin Chen <nicolinc@nvidia.com>
To: <jgg@nvidia.com>, <robin.murphy@arm.com>, <will@kernel.org>
Cc: <eric.auger@redhat.com>, <kevin.tian@intel.com>,
<baolu.lu@linux.intel.com>, <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>, <kvm@vger.kernel.org>,
<alex.williamson@redhat.com>, <yi.l.liu@intel.com>
Subject: [PATCH v2 06/17] iommu/arm-smmu-v3: Add arm_smmu_set/unset_dev_user_data
Date: Tue, 9 May 2023 20:33:26 -0700 [thread overview]
Message-ID: <9bcf79fe2b93eca097b4ea8eaef43c4c2a4bc8d3.1683688960.git.nicolinc@nvidia.com> (raw)
In-Reply-To: <cover.1683688960.git.nicolinc@nvidia.com>
Implement the new set_dev_user_data and unset_dev_user_data ops, by using
an xarray to store the stream pointer indexed by a given user Stream ID.
This will be used by the user cache invalidation hypercall, to check the
SID field of an ATC_INV command and replace it with the physical SID.
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
---
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 44 +++++++++++++++++++++
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 +
include/uapi/linux/iommufd.h | 10 +++++
3 files changed, 56 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 89daf50be87b..327819663547 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -2746,6 +2746,46 @@ static void arm_smmu_release_device(struct device *dev)
kfree(master);
}
+static int arm_smmu_set_dev_user_data(struct device *dev, const void *user_data)
+{
+ const struct iommu_device_data_arm_smmuv3 *user = user_data;
+ 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 = user->sid;
+ 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 void arm_smmu_unset_dev_user_data(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;
+
+ 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);
+}
+
static struct iommu_group *arm_smmu_device_group(struct device *dev)
{
struct iommu_group *group;
@@ -2873,6 +2913,9 @@ static struct iommu_ops arm_smmu_ops = {
.domain_alloc = arm_smmu_domain_alloc,
.probe_device = arm_smmu_probe_device,
.release_device = arm_smmu_release_device,
+ .set_dev_user_data = arm_smmu_set_dev_user_data,
+ .unset_dev_user_data = arm_smmu_unset_dev_user_data,
+ .dev_user_data_len = sizeof(struct iommu_device_data_arm_smmuv3),
.device_group = arm_smmu_device_group,
.of_xlate = arm_smmu_of_xlate,
.get_resv_regions = arm_smmu_get_resv_regions,
@@ -3108,6 +3151,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 5fa010c6fe20..1951a80af241 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
@@ -676,10 +676,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;
};
diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h
index b1fe4c59ab82..2ecb6240ec69 100644
--- a/include/uapi/linux/iommufd.h
+++ b/include/uapi/linux/iommufd.h
@@ -592,6 +592,16 @@ struct iommu_hw_info {
};
#define IOMMU_DEVICE_GET_HW_INFO _IO(IOMMUFD_TYPE, IOMMUFD_CMD_DEVICE_GET_HW_INFO)
+/**
+ * struct iommu_device_data_arm_smmuv3 - ARM SMMUv3 specific device data
+ * @sid: The Stream ID that is assigned in the user space
+ *
+ * This should be passed via the VFIO_DEVICE_BIND_IOMMUFD ioctl.
+ */
+struct iommu_device_data_arm_smmuv3 {
+ __u32 sid;
+};
+
/**
* enum iommu_hwpt_intel_vtd_invalidate_flags - Flags for Intel VT-d
* stage-1 page table cache
--
2.40.1
next prev parent reply other threads:[~2023-05-10 3:34 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-10 3:33 [PATCH v2 00/17] Add Nested Translation Support for SMMUv3 Nicolin Chen
2023-05-10 3:33 ` [PATCH v2 01/17] vfio: Remove VFIO_TYPE1_NESTING_IOMMU Nicolin Chen
2023-05-10 3:33 ` [PATCH v2 02/17] iommu/dma: Support MSIs through nested domains Nicolin Chen
2023-05-10 3:33 ` [PATCH v2 03/17] iommufd: Add nesting related data structures for ARM SMMUv3 Nicolin Chen
2023-05-10 3:33 ` [PATCH v2 04/17] iommufd/device: Setup MSI on kernel-managed domains Nicolin Chen
2023-05-10 3:33 ` [PATCH v2 05/17] iommu/arm-smmu-v3: Add arm_smmu_hw_info Nicolin Chen
2023-05-10 3:33 ` Nicolin Chen [this message]
2023-05-10 3:33 ` [PATCH v2 07/17] iommu/arm-smmu-v3: Remove ARM_SMMU_DOMAIN_NESTED Nicolin Chen
2023-05-10 3:33 ` [PATCH v2 08/17] iommu/arm-smmu-v3: Unset corresponding STE fields when s2_cfg is NULL Nicolin Chen
2023-05-10 3:33 ` [PATCH v2 09/17] iommu/arm-smmu-v3: Add STRTAB_STE_0_CFG_NESTED for 2-stage translation Nicolin Chen
2023-05-10 3:33 ` [PATCH v2 10/17] iommu/arm-smmu-v3: Allow ARM_SMMU_DOMAIN_S1 stage to access s2_cfg Nicolin Chen
2023-05-10 3:33 ` [PATCH v2 11/17] iommu/arm-smmu-v3: Add s1dss in struct arm_smmu_s1_cfg Nicolin Chen
2023-05-10 3:33 ` [PATCH v2 12/17] iommu/arm-smmu-v3: Pass in user_cfg to arm_smmu_domain_finalise Nicolin Chen
2023-05-10 3:33 ` [PATCH v2 13/17] iommu/arm-smmu-v3: Add arm_smmu_domain_alloc_user Nicolin Chen
2023-05-10 3:33 ` [PATCH v2 14/17] iommu/arm-smmu-v3: Support IOMMU_DOMAIN_NESTED type of allocations Nicolin Chen
2023-05-10 3:33 ` [PATCH v2 15/17] iommu/arm-smmu-v3: Implement arm_smmu_get_msi_mapping_domain Nicolin Chen
2023-05-10 3:33 ` [PATCH v2 16/17] iommu/arm-smmu-v3: Add CMDQ_OP_TLBI_NH_VAA and CMDQ_OP_TLBI_NH_ALL Nicolin Chen
2023-05-10 3:33 ` [PATCH v2 17/17] iommu/arm-smmu-v3: Add arm_smmu_cache_invalidate_user Nicolin Chen
2023-05-10 8:11 ` [PATCH v2 00/17] Add Nested Translation Support for SMMUv3 Tian, Kevin
2023-05-10 8:41 ` Nicolin Chen
2023-05-15 10:00 ` Zhangfei Gao
2023-05-15 15:57 ` Nicolin Chen
2023-05-16 3:12 ` Zhangfei Gao
2023-05-25 23:42 ` Nicolin Chen
2023-05-26 1:58 ` zhangfei gao
2023-05-26 5:10 ` 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=9bcf79fe2b93eca097b4ea8eaef43c4c2a4bc8d3.1683688960.git.nicolinc@nvidia.com \
--to=nicolinc@nvidia.com \
--cc=alex.williamson@redhat.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=kvm@vger.kernel.org \
--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