From: Yi Liu <yi.l.liu@intel.com>
To: joro@8bytes.org, kevin.tian@intel.com, baolu.lu@linux.intel.com,
jgg@nvidia.com
Cc: yi.l.liu@intel.com, iommu@lists.linux.dev, robin.murphy@arm.com,
nicolinc@nvidia.com, will@kernel.org, vasant.hegde@amd.com
Subject: [PATCH v7 01/13] iommu: Add iommu_attach_device_pasid_handle()
Date: Sat, 15 Feb 2025 19:52:16 -0800 [thread overview]
Message-ID: <20250216035228.23831-2-yi.l.liu@intel.com> (raw)
In-Reply-To: <20250216035228.23831-1-yi.l.liu@intel.com>
The existing iommu_attach_device_pasid() function allows both a valid
handle and a NULL handle, which is not consistent with the RID path where
iommu_attach_group() and iommu_attach_group_handle() coexist. To refine
it, this adds iommu_attach_device_pasid_handle() to cover the case with
valid handle, while let the iommu_attach_device_pasid() only deals with
the case with NULL handle.
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
drivers/dma/idxd/init.c | 2 +-
drivers/iommu/iommu-sva.c | 10 ++++++----
drivers/iommu/iommu.c | 8 ++++----
include/linux/iommu.h | 34 +++++++++++++++++++++++++++++-----
4 files changed, 40 insertions(+), 14 deletions(-)
diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c
index b946f78f85e1..d11a763ef124 100644
--- a/drivers/dma/idxd/init.c
+++ b/drivers/dma/idxd/init.c
@@ -593,7 +593,7 @@ static int idxd_enable_system_pasid(struct idxd_device *idxd)
* DMA domain is owned by the driver, it should support all valid
* types such as DMA-FQ, identity, etc.
*/
- ret = iommu_attach_device_pasid(domain, dev, pasid, NULL);
+ ret = iommu_attach_device_pasid(domain, dev, pasid);
if (ret) {
dev_err(dev, "failed to attach device pasid %d, domain type %d",
pasid, domain->type);
diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c
index 503c5d23c1ea..09d676ddf15e 100644
--- a/drivers/iommu/iommu-sva.c
+++ b/drivers/iommu/iommu-sva.c
@@ -115,8 +115,9 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm
/* Search for an existing domain. */
list_for_each_entry(domain, &mm->iommu_mm->sva_domains, next) {
- ret = iommu_attach_device_pasid(domain, dev, iommu_mm->pasid,
- &handle->handle);
+ ret = iommu_attach_device_pasid_handle(domain, dev,
+ iommu_mm->pasid,
+ &handle->handle);
if (!ret) {
domain->users++;
goto out;
@@ -130,8 +131,9 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm
goto out_free_handle;
}
- ret = iommu_attach_device_pasid(domain, dev, iommu_mm->pasid,
- &handle->handle);
+ ret = iommu_attach_device_pasid_handle(domain, dev,
+ iommu_mm->pasid,
+ &handle->handle);
if (ret)
goto out_free_domain;
domain->users = 1;
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index c3bf8e131a8e..95830f670e18 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -3423,9 +3423,9 @@ static void *iommu_make_pasid_entry(struct iommu_domain *domain,
*
* Return: 0 on success, or an error.
*/
-int iommu_attach_device_pasid(struct iommu_domain *domain,
- struct device *dev, ioasid_t pasid,
- struct iommu_attach_handle *handle)
+int __iommu_attach_device_pasid(struct iommu_domain *domain,
+ struct device *dev, ioasid_t pasid,
+ struct iommu_attach_handle *handle)
{
/* Caller must be a probed driver on dev */
struct iommu_group *group = dev->iommu_group;
@@ -3476,7 +3476,7 @@ int iommu_attach_device_pasid(struct iommu_domain *domain,
mutex_unlock(&group->mutex);
return ret;
}
-EXPORT_SYMBOL_GPL(iommu_attach_device_pasid);
+EXPORT_SYMBOL_GPL(__iommu_attach_device_pasid);
/*
* iommu_detach_device_pasid() - Detach the domain from pasid of device
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 38c65e92ecd0..d795de7bad8f 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -1122,9 +1122,24 @@ bool iommu_group_dma_owner_claimed(struct iommu_group *group);
int iommu_device_claim_dma_owner(struct device *dev, void *owner);
void iommu_device_release_dma_owner(struct device *dev);
-int iommu_attach_device_pasid(struct iommu_domain *domain,
- struct device *dev, ioasid_t pasid,
- struct iommu_attach_handle *handle);
+int __iommu_attach_device_pasid(struct iommu_domain *domain,
+ struct device *dev, ioasid_t pasid,
+ struct iommu_attach_handle *handle);
+
+static inline int iommu_attach_device_pasid(struct iommu_domain *domain,
+ struct device *dev, ioasid_t pasid)
+{
+ return __iommu_attach_device_pasid(domain, dev, pasid, NULL);
+}
+
+static inline int
+iommu_attach_device_pasid_handle(struct iommu_domain *domain,
+ struct device *dev, ioasid_t pasid,
+ struct iommu_attach_handle *handle)
+{
+ return __iommu_attach_device_pasid(domain, dev, pasid, handle);
+}
+
void iommu_detach_device_pasid(struct iommu_domain *domain,
struct device *dev, ioasid_t pasid);
ioasid_t iommu_alloc_global_pasid(struct device *dev);
@@ -1139,6 +1154,8 @@ struct iommu_fault_param {};
struct iommu_iotlb_gather {};
struct iommu_dirty_bitmap {};
struct iommu_dirty_ops {};
+struct iommu_attach_handle {};
+
static inline bool device_iommu_capable(struct device *dev, enum iommu_cap cap)
{
@@ -1451,8 +1468,15 @@ static inline int iommu_device_claim_dma_owner(struct device *dev, void *owner)
}
static inline int iommu_attach_device_pasid(struct iommu_domain *domain,
- struct device *dev, ioasid_t pasid,
- struct iommu_attach_handle *handle)
+ struct device *dev, ioasid_t pasid)
+{
+ return -ENODEV;
+}
+
+static inline int
+iommu_attach_device_pasid_handle(struct iommu_domain *domain,
+ struct device *dev, ioasid_t pasid,
+ struct iommu_attach_handle *handle)
{
return -ENODEV;
}
--
2.34.1
next prev parent reply other threads:[~2025-02-16 3:52 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-16 3:52 [PATCH v7 00/13] iommufd support pasid attach/replace Yi Liu
2025-02-16 3:52 ` Yi Liu [this message]
2025-02-25 9:47 ` [PATCH v7 01/13] iommu: Add iommu_attach_device_pasid_handle() Tian, Kevin
2025-02-16 3:52 ` [PATCH v7 02/13] iommu: Introduce a replace API for device pasid Yi Liu
2025-02-25 9:55 ` Tian, Kevin
2025-02-25 11:35 ` Yi Liu
2025-02-16 3:52 ` [PATCH v7 03/13] iommufd: Pass @pasid through the device attach/replace path Yi Liu
2025-02-16 3:52 ` [PATCH v7 04/13] iommufd/device: Only add reserved_iova in non-pasid path Yi Liu
2025-02-16 3:52 ` [PATCH v7 05/13] iommufd: Mark PASID-compatible domain Yi Liu
2025-02-16 3:52 ` [PATCH v7 06/13] iommufd: Support pasid attach/replace Yi Liu
2025-02-16 3:52 ` [PATCH v7 07/13] iommufd: Enforce PASID-compatible domain for RID Yi Liu
2025-02-16 3:52 ` [PATCH v7 08/13] iommu/vt-d: Add IOMMU_HWPT_ALLOC_PASID support Yi Liu
2025-02-16 3:52 ` [PATCH v7 09/13] iommufd: Allow allocating PASID-compatible domain Yi Liu
2025-02-16 3:52 ` [PATCH v7 10/13] iommufd/selftest: Add set_dev_pasid in mock iommu Yi Liu
2025-02-16 3:52 ` [PATCH v7 11/13] iommufd/selftest: Add a helper to get test device Yi Liu
2025-02-16 3:52 ` [PATCH v7 12/13] iommufd/selftest: Add test ops to test pasid attach/detach Yi Liu
2025-02-16 3:52 ` [PATCH v7 13/13] iommufd/selftest: Add coverage for iommufd " Yi Liu
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=20250216035228.23831-2-yi.l.liu@intel.com \
--to=yi.l.liu@intel.com \
--cc=baolu.lu@linux.intel.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=nicolinc@nvidia.com \
--cc=robin.murphy@arm.com \
--cc=vasant.hegde@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