All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6 0/7] Support attaching PASID to the blocked_domain
@ 2024-12-04 12:29 Yi Liu
  2024-12-04 12:29 ` [PATCH v6 1/7] iommu: Prevent pasid attach if no ops->remove_dev_pasid Yi Liu
                   ` (7 more replies)
  0 siblings, 8 replies; 11+ messages in thread
From: Yi Liu @ 2024-12-04 12:29 UTC (permalink / raw)
  To: joro, jgg, kevin.tian, baolu.lu
  Cc: eric.auger, nicolinc, kvm, chao.p.peng, yi.l.liu, iommu,
	zhenzhong.duan, vasant.hegde, will

During the review of iommufd pasid series, Kevin and Jason suggested
attaching PASID to the blocked domain hence replacing the usage of
remove_dev_pasid() op [1]. This makes sense as it makes the PASID path
aligned with the RID path which attaches the RID to the blocked_domain
when it is to be blocked. To do it, it requires passing the old domain
to the iommu driver. This has been done in [2].

This series makes the Intel iommu driver, ARM SMMUv3 driver and AMD iommu
driver support attaching PASID to the blocked domain. And in the end remove
the remove_dev_pasid op from iommu_ops.

[1] https://lore.kernel.org/linux-iommu/20240816130202.GB2032816@nvidia.com/
[2] https://lore.kernel.org/linux-iommu/20241108021406.173972-1-baolu.lu@linux.intel.com/

v6:
 - Add Jason's r-b on patch 01.
 - Rebased on top of 6.13-rc1

v5: https://lore.kernel.org/linux-iommu/20241113134613.7173-1-yi.l.liu@intel.com/
 - Fix an issue spotted by Baolu in patch 01 of v4. The new version lifts the
   group check to be the first check, hence it can ensure a valid iommu_ops
   returned dev_iommu_ops(). Per this changes, it also removes the duplicated
   dev_has_iommu() check as group check can replace it. Due to the changes,
   drop the r-b tags on this patch.
 - Add Baolu's r-b tag.

v4: https://lore.kernel.org/linux-iommu/20241108120427.13562-1-yi.l.liu@intel.com/
 - Remove unnecessary braces in patch 02 (Vasant)
 - Minor tweaks to patch 01 and 03 (Kevin)
 - Add r-b tags from Jason, Vasant, Kevin

v3: https://lore.kernel.org/linux-iommu/20241104132033.14027-1-yi.l.liu@intel.com/
 - Add a patch to check remove_dev_pasid() in iommu_attach_device_pasid()
 - Split patch 01 of v2 into two patches, drop the r-b of this patch due the
   split.
 - Add AMD iommu blocked domain pasid support (Jason)
 - Remove the remove_dev_pasid op as all the iommu drivers that support pasid
   attach have supported attaching pasid to blocked domain.

v2: https://lore.kernel.org/linux-iommu/20241018055824.24880-1-yi.l.liu@intel.com/#t
 - Add Kevin's r-b
 - Adjust the order of patch 03 of v1, it should be the first patch (Baolu)

v1: https://lore.kernel.org/linux-iommu/20240912130653.11028-1-yi.l.liu@intel.com/

Regards,
	Yi Liu

Jason Gunthorpe (1):
  iommu/arm-smmu-v3: Make the blocked domain support PASID

Yi Liu (6):
  iommu: Prevent pasid attach if no ops->remove_dev_pasid
  iommu: Consolidate the ops->remove_dev_pasid usage into a helper
  iommu: Detaching pasid by attaching to the blocked_domain
  iommu/vt-d: Make the blocked domain support PASID
  iommu/amd: Make the blocked domain support PASID
  iommu: Remove the remove_dev_pasid op

 drivers/iommu/amd/iommu.c                   | 10 +++++-
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 12 +++----
 drivers/iommu/intel/iommu.c                 | 15 ++++++---
 drivers/iommu/iommu.c                       | 35 +++++++++++++--------
 include/linux/iommu.h                       |  5 ---
 5 files changed, 48 insertions(+), 29 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v6 1/7] iommu: Prevent pasid attach if no ops->remove_dev_pasid
  2024-12-04 12:29 [PATCH v6 0/7] Support attaching PASID to the blocked_domain Yi Liu
@ 2024-12-04 12:29 ` Yi Liu
  2024-12-05  2:13   ` Baolu Lu
  2024-12-11  8:24   ` Tian, Kevin
  2024-12-04 12:29 ` [PATCH v6 2/7] iommu: Consolidate the ops->remove_dev_pasid usage into a helper Yi Liu
                   ` (6 subsequent siblings)
  7 siblings, 2 replies; 11+ messages in thread
From: Yi Liu @ 2024-12-04 12:29 UTC (permalink / raw)
  To: joro, jgg, kevin.tian, baolu.lu
  Cc: eric.auger, nicolinc, kvm, chao.p.peng, yi.l.liu, iommu,
	zhenzhong.duan, vasant.hegde, will

driver should implement both set_dev_pasid and remove_dev_pasid op, otherwise
it is a problem how to detach pasid. In reality, it is impossible that an
iommu driver implements set_dev_pasid() but no remove_dev_pasid() op. However,
it is better to check it.

Move the group check to be the first as dev_iommu_ops() may fail when there
is no valid group. Also take the chance to remove the dev_has_iommu() check
as it is duplicated to the group check.

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
 drivers/iommu/iommu.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 9bc0c74cca3c..38c3f67e441f 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -3368,16 +3368,19 @@ int iommu_attach_device_pasid(struct iommu_domain *domain,
 	/* Caller must be a probed driver on dev */
 	struct iommu_group *group = dev->iommu_group;
 	struct group_device *device;
+	const struct iommu_ops *ops;
 	int ret;
 
-	if (!domain->ops->set_dev_pasid)
-		return -EOPNOTSUPP;
-
 	if (!group)
 		return -ENODEV;
 
-	if (!dev_has_iommu(dev) || dev_iommu_ops(dev) != domain->owner ||
-	    pasid == IOMMU_NO_PASID)
+	ops = dev_iommu_ops(dev);
+
+	if (!domain->ops->set_dev_pasid ||
+	    !ops->remove_dev_pasid)
+		return -EOPNOTSUPP;
+
+	if (ops != domain->owner || pasid == IOMMU_NO_PASID)
 		return -EINVAL;
 
 	mutex_lock(&group->mutex);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v6 2/7] iommu: Consolidate the ops->remove_dev_pasid usage into a helper
  2024-12-04 12:29 [PATCH v6 0/7] Support attaching PASID to the blocked_domain Yi Liu
  2024-12-04 12:29 ` [PATCH v6 1/7] iommu: Prevent pasid attach if no ops->remove_dev_pasid Yi Liu
@ 2024-12-04 12:29 ` Yi Liu
  2024-12-04 12:29 ` [PATCH v6 3/7] iommu: Detaching pasid by attaching to the blocked_domain Yi Liu
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Yi Liu @ 2024-12-04 12:29 UTC (permalink / raw)
  To: joro, jgg, kevin.tian, baolu.lu
  Cc: eric.auger, nicolinc, kvm, chao.p.peng, yi.l.liu, iommu,
	zhenzhong.duan, vasant.hegde, will

Add a wrapper for the ops->remove_dev_pasid, this consolidates the iommu_ops
fetching and callback invoking. It is also a preparation for starting the
transition from using remove_dev_pasid op to detach pasid to the way using
blocked_domain to detach pasid.

Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
 drivers/iommu/iommu.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 38c3f67e441f..0331dc30eb64 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -3312,6 +3312,14 @@ bool iommu_group_dma_owner_claimed(struct iommu_group *group)
 }
 EXPORT_SYMBOL_GPL(iommu_group_dma_owner_claimed);
 
+static void iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid,
+				   struct iommu_domain *domain)
+{
+	const struct iommu_ops *ops = dev_iommu_ops(dev);
+
+	ops->remove_dev_pasid(dev, pasid, domain);
+}
+
 static int __iommu_set_group_pasid(struct iommu_domain *domain,
 				   struct iommu_group *group, ioasid_t pasid)
 {
@@ -3330,11 +3338,9 @@ static int __iommu_set_group_pasid(struct iommu_domain *domain,
 err_revert:
 	last_gdev = device;
 	for_each_group_device(group, device) {
-		const struct iommu_ops *ops = dev_iommu_ops(device->dev);
-
 		if (device == last_gdev)
 			break;
-		ops->remove_dev_pasid(device->dev, pasid, domain);
+		iommu_remove_dev_pasid(device->dev, pasid, domain);
 	}
 	return ret;
 }
@@ -3344,12 +3350,9 @@ static void __iommu_remove_group_pasid(struct iommu_group *group,
 				       struct iommu_domain *domain)
 {
 	struct group_device *device;
-	const struct iommu_ops *ops;
 
-	for_each_group_device(group, device) {
-		ops = dev_iommu_ops(device->dev);
-		ops->remove_dev_pasid(device->dev, pasid, domain);
-	}
+	for_each_group_device(group, device)
+		iommu_remove_dev_pasid(device->dev, pasid, domain);
 }
 
 /*
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v6 3/7] iommu: Detaching pasid by attaching to the blocked_domain
  2024-12-04 12:29 [PATCH v6 0/7] Support attaching PASID to the blocked_domain Yi Liu
  2024-12-04 12:29 ` [PATCH v6 1/7] iommu: Prevent pasid attach if no ops->remove_dev_pasid Yi Liu
  2024-12-04 12:29 ` [PATCH v6 2/7] iommu: Consolidate the ops->remove_dev_pasid usage into a helper Yi Liu
@ 2024-12-04 12:29 ` Yi Liu
  2024-12-04 12:29 ` [PATCH v6 4/7] iommu/arm-smmu-v3: Make the blocked domain support PASID Yi Liu
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Yi Liu @ 2024-12-04 12:29 UTC (permalink / raw)
  To: joro, jgg, kevin.tian, baolu.lu
  Cc: eric.auger, nicolinc, kvm, chao.p.peng, yi.l.liu, iommu,
	zhenzhong.duan, vasant.hegde, will

The iommu drivers are on the way to detach pasid by attaching to the blocked
domain. However, this cannot be done in one shot. During the transition, iommu
core would select between the remove_dev_pasid op and the blocked domain.

Suggested-by: Kevin Tian <kevin.tian@intel.com>
Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
 drivers/iommu/iommu.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 0331dc30eb64..149ae5300cc4 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -3316,8 +3316,18 @@ static void iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid,
 				   struct iommu_domain *domain)
 {
 	const struct iommu_ops *ops = dev_iommu_ops(dev);
+	struct iommu_domain *blocked_domain = ops->blocked_domain;
+	int ret = 1;
 
-	ops->remove_dev_pasid(dev, pasid, domain);
+	if (blocked_domain && blocked_domain->ops->set_dev_pasid) {
+		ret = blocked_domain->ops->set_dev_pasid(blocked_domain,
+							 dev, pasid, domain);
+	} else {
+		ops->remove_dev_pasid(dev, pasid, domain);
+		ret = 0;
+	}
+
+	WARN_ON(ret);
 }
 
 static int __iommu_set_group_pasid(struct iommu_domain *domain,
@@ -3380,7 +3390,9 @@ int iommu_attach_device_pasid(struct iommu_domain *domain,
 	ops = dev_iommu_ops(dev);
 
 	if (!domain->ops->set_dev_pasid ||
-	    !ops->remove_dev_pasid)
+	    (!ops->remove_dev_pasid &&
+	     (!ops->blocked_domain ||
+	      !ops->blocked_domain->ops->set_dev_pasid)))
 		return -EOPNOTSUPP;
 
 	if (ops != domain->owner || pasid == IOMMU_NO_PASID)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v6 4/7] iommu/arm-smmu-v3: Make the blocked domain support PASID
  2024-12-04 12:29 [PATCH v6 0/7] Support attaching PASID to the blocked_domain Yi Liu
                   ` (2 preceding siblings ...)
  2024-12-04 12:29 ` [PATCH v6 3/7] iommu: Detaching pasid by attaching to the blocked_domain Yi Liu
@ 2024-12-04 12:29 ` Yi Liu
  2024-12-04 12:29 ` [PATCH v6 5/7] iommu/vt-d: " Yi Liu
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Yi Liu @ 2024-12-04 12:29 UTC (permalink / raw)
  To: joro, jgg, kevin.tian, baolu.lu
  Cc: eric.auger, nicolinc, kvm, chao.p.peng, yi.l.liu, iommu,
	zhenzhong.duan, vasant.hegde, will

From: Jason Gunthorpe <jgg@nvidia.com>

The blocked domain is used to park RID to be blocking DMA state. This
can be extended to PASID as well. By this, the remove_dev_pasid() op
of ARM SMMUv3 can be dropped.

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Nicolin Chen <nicolinc@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

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 e4ebd9e12ad4..ff1d9bbf6d94 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -3016,13 +3016,12 @@ int arm_smmu_set_pasid(struct arm_smmu_master *master,
 	return ret;
 }
 
-static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid,
-				      struct iommu_domain *domain)
+static int arm_smmu_blocking_set_dev_pasid(struct iommu_domain *new_domain,
+					   struct device *dev, ioasid_t pasid,
+					   struct iommu_domain *old_domain)
 {
+	struct arm_smmu_domain *smmu_domain = to_smmu_domain(old_domain);
 	struct arm_smmu_master *master = dev_iommu_priv_get(dev);
-	struct arm_smmu_domain *smmu_domain;
-
-	smmu_domain = to_smmu_domain(domain);
 
 	mutex_lock(&arm_smmu_asid_lock);
 	arm_smmu_clear_cd(master, pasid);
@@ -3043,6 +3042,7 @@ static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid,
 		    sid_domain->type == IOMMU_DOMAIN_BLOCKED)
 			sid_domain->ops->attach_dev(sid_domain, dev);
 	}
+	return 0;
 }
 
 static void arm_smmu_attach_dev_ste(struct iommu_domain *domain,
@@ -3124,6 +3124,7 @@ static int arm_smmu_attach_dev_blocked(struct iommu_domain *domain,
 
 static const struct iommu_domain_ops arm_smmu_blocked_ops = {
 	.attach_dev = arm_smmu_attach_dev_blocked,
+	.set_dev_pasid = arm_smmu_blocking_set_dev_pasid,
 };
 
 static struct iommu_domain arm_smmu_blocked_domain = {
@@ -3551,7 +3552,6 @@ static struct iommu_ops arm_smmu_ops = {
 	.device_group		= arm_smmu_device_group,
 	.of_xlate		= arm_smmu_of_xlate,
 	.get_resv_regions	= arm_smmu_get_resv_regions,
-	.remove_dev_pasid	= arm_smmu_remove_dev_pasid,
 	.dev_enable_feat	= arm_smmu_dev_enable_feature,
 	.dev_disable_feat	= arm_smmu_dev_disable_feature,
 	.page_response		= arm_smmu_page_response,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v6 5/7] iommu/vt-d: Make the blocked domain support PASID
  2024-12-04 12:29 [PATCH v6 0/7] Support attaching PASID to the blocked_domain Yi Liu
                   ` (3 preceding siblings ...)
  2024-12-04 12:29 ` [PATCH v6 4/7] iommu/arm-smmu-v3: Make the blocked domain support PASID Yi Liu
@ 2024-12-04 12:29 ` Yi Liu
  2024-12-04 12:29 ` [PATCH v6 6/7] iommu/amd: " Yi Liu
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Yi Liu @ 2024-12-04 12:29 UTC (permalink / raw)
  To: joro, jgg, kevin.tian, baolu.lu
  Cc: eric.auger, nicolinc, kvm, chao.p.peng, yi.l.liu, iommu,
	zhenzhong.duan, vasant.hegde, will

The blocked domain can be extended to park PASID of a device to be the
DMA blocking state. By this the remove_dev_pasid() op is dropped.

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
 drivers/iommu/intel/iommu.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 7d0acb74d5a5..e0c835a9831f 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -3248,10 +3248,15 @@ static int blocking_domain_attach_dev(struct iommu_domain *domain,
 	return 0;
 }
 
+static int blocking_domain_set_dev_pasid(struct iommu_domain *domain,
+					 struct device *dev, ioasid_t pasid,
+					 struct iommu_domain *old);
+
 static struct iommu_domain blocking_domain = {
 	.type = IOMMU_DOMAIN_BLOCKED,
 	.ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= blocking_domain_attach_dev,
+		.set_dev_pasid	= blocking_domain_set_dev_pasid,
 	}
 };
 
@@ -4097,13 +4102,16 @@ void domain_remove_dev_pasid(struct iommu_domain *domain,
 	kfree(dev_pasid);
 }
 
-static void intel_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid,
-					 struct iommu_domain *domain)
+static int blocking_domain_set_dev_pasid(struct iommu_domain *domain,
+					 struct device *dev, ioasid_t pasid,
+					 struct iommu_domain *old)
 {
 	struct device_domain_info *info = dev_iommu_priv_get(dev);
 
 	intel_pasid_tear_down_entry(info->iommu, dev, pasid, false);
-	domain_remove_dev_pasid(domain, dev, pasid);
+	domain_remove_dev_pasid(old, dev, pasid);
+
+	return 0;
 }
 
 struct dev_pasid_info *
@@ -4476,7 +4484,6 @@ const struct iommu_ops intel_iommu_ops = {
 	.dev_disable_feat	= intel_iommu_dev_disable_feat,
 	.is_attach_deferred	= intel_iommu_is_attach_deferred,
 	.def_domain_type	= device_def_domain_type,
-	.remove_dev_pasid	= intel_iommu_remove_dev_pasid,
 	.pgsize_bitmap		= SZ_4K,
 	.page_response		= intel_iommu_page_response,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v6 6/7] iommu/amd: Make the blocked domain support PASID
  2024-12-04 12:29 [PATCH v6 0/7] Support attaching PASID to the blocked_domain Yi Liu
                   ` (4 preceding siblings ...)
  2024-12-04 12:29 ` [PATCH v6 5/7] iommu/vt-d: " Yi Liu
@ 2024-12-04 12:29 ` Yi Liu
  2024-12-04 12:29 ` [PATCH v6 7/7] iommu: Remove the remove_dev_pasid op Yi Liu
  2024-12-18  8:40 ` [PATCH v6 0/7] Support attaching PASID to the blocked_domain Joerg Roedel
  7 siblings, 0 replies; 11+ messages in thread
From: Yi Liu @ 2024-12-04 12:29 UTC (permalink / raw)
  To: joro, jgg, kevin.tian, baolu.lu
  Cc: eric.auger, nicolinc, kvm, chao.p.peng, yi.l.liu, iommu,
	zhenzhong.duan, vasant.hegde, will

The blocked domain can be extended to park PASID of a device to be the
DMA blocking state. By this the remove_dev_pasid() op is dropped.

Remove PASID from old domain and device GCR3 table. No need to attach
PASID to the blocked domain as clearing PASID from GCR3 table will make
sure all DMAs for that PASID are blocked.

Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
 drivers/iommu/amd/iommu.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 3f691e1fd22c..7814ec98cf0c 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -2467,10 +2467,19 @@ static int blocked_domain_attach_device(struct iommu_domain *domain,
 	return 0;
 }
 
+static int blocked_domain_set_dev_pasid(struct iommu_domain *domain,
+					struct device *dev, ioasid_t pasid,
+					struct iommu_domain *old)
+{
+	amd_iommu_remove_dev_pasid(dev, pasid, old);
+	return 0;
+}
+
 static struct iommu_domain blocked_domain = {
 	.type = IOMMU_DOMAIN_BLOCKED,
 	.ops = &(const struct iommu_domain_ops) {
 		.attach_dev     = blocked_domain_attach_device,
+		.set_dev_pasid  = blocked_domain_set_dev_pasid,
 	}
 };
 
@@ -2893,7 +2902,6 @@ const struct iommu_ops amd_iommu_ops = {
 	.def_domain_type = amd_iommu_def_domain_type,
 	.dev_enable_feat = amd_iommu_dev_enable_feature,
 	.dev_disable_feat = amd_iommu_dev_disable_feature,
-	.remove_dev_pasid = amd_iommu_remove_dev_pasid,
 	.page_response = amd_iommu_page_response,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= amd_iommu_attach_device,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v6 7/7] iommu: Remove the remove_dev_pasid op
  2024-12-04 12:29 [PATCH v6 0/7] Support attaching PASID to the blocked_domain Yi Liu
                   ` (5 preceding siblings ...)
  2024-12-04 12:29 ` [PATCH v6 6/7] iommu/amd: " Yi Liu
@ 2024-12-04 12:29 ` Yi Liu
  2024-12-18  8:40 ` [PATCH v6 0/7] Support attaching PASID to the blocked_domain Joerg Roedel
  7 siblings, 0 replies; 11+ messages in thread
From: Yi Liu @ 2024-12-04 12:29 UTC (permalink / raw)
  To: joro, jgg, kevin.tian, baolu.lu
  Cc: eric.auger, nicolinc, kvm, chao.p.peng, yi.l.liu, iommu,
	zhenzhong.duan, vasant.hegde, will

The iommu drivers that supports PASID have supported attaching pasid to the
blocked_domain, hence remove the remove_dev_pasid op from the iommu_ops.

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
 drivers/iommu/iommu.c | 17 ++++-------------
 include/linux/iommu.h |  5 -----
 2 files changed, 4 insertions(+), 18 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 149ae5300cc4..d328d4753eef 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -3317,17 +3317,9 @@ static void iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid,
 {
 	const struct iommu_ops *ops = dev_iommu_ops(dev);
 	struct iommu_domain *blocked_domain = ops->blocked_domain;
-	int ret = 1;
 
-	if (blocked_domain && blocked_domain->ops->set_dev_pasid) {
-		ret = blocked_domain->ops->set_dev_pasid(blocked_domain,
-							 dev, pasid, domain);
-	} else {
-		ops->remove_dev_pasid(dev, pasid, domain);
-		ret = 0;
-	}
-
-	WARN_ON(ret);
+	WARN_ON(blocked_domain->ops->set_dev_pasid(blocked_domain,
+						   dev, pasid, domain));
 }
 
 static int __iommu_set_group_pasid(struct iommu_domain *domain,
@@ -3390,9 +3382,8 @@ int iommu_attach_device_pasid(struct iommu_domain *domain,
 	ops = dev_iommu_ops(dev);
 
 	if (!domain->ops->set_dev_pasid ||
-	    (!ops->remove_dev_pasid &&
-	     (!ops->blocked_domain ||
-	      !ops->blocked_domain->ops->set_dev_pasid)))
+	    !ops->blocked_domain ||
+	    !ops->blocked_domain->ops->set_dev_pasid)
 		return -EOPNOTSUPP;
 
 	if (ops != domain->owner || pasid == IOMMU_NO_PASID)
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 318d27841130..38c65e92ecd0 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -587,9 +587,6 @@ iommu_copy_struct_from_full_user_array(void *kdst, size_t kdst_entry_size,
  *		- IOMMU_DOMAIN_DMA: must use a dma domain
  *		- 0: use the default setting
  * @default_domain_ops: the default ops for domains
- * @remove_dev_pasid: Remove any translation configurations of a specific
- *                    pasid, so that any DMA transactions with this pasid
- *                    will be blocked by the hardware.
  * @viommu_alloc: Allocate an iommufd_viommu on a physical IOMMU instance behind
  *                the @dev, as the set of virtualization resources shared/passed
  *                to user space IOMMU instance. And associate it with a nesting
@@ -647,8 +644,6 @@ struct iommu_ops {
 			      struct iommu_page_response *msg);
 
 	int (*def_domain_type)(struct device *dev);
-	void (*remove_dev_pasid)(struct device *dev, ioasid_t pasid,
-				 struct iommu_domain *domain);
 
 	struct iommufd_viommu *(*viommu_alloc)(
 		struct device *dev, struct iommu_domain *parent_domain,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v6 1/7] iommu: Prevent pasid attach if no ops->remove_dev_pasid
  2024-12-04 12:29 ` [PATCH v6 1/7] iommu: Prevent pasid attach if no ops->remove_dev_pasid Yi Liu
@ 2024-12-05  2:13   ` Baolu Lu
  2024-12-11  8:24   ` Tian, Kevin
  1 sibling, 0 replies; 11+ messages in thread
From: Baolu Lu @ 2024-12-05  2:13 UTC (permalink / raw)
  To: Yi Liu, joro, jgg, kevin.tian
  Cc: eric.auger, nicolinc, kvm, chao.p.peng, iommu, zhenzhong.duan,
	vasant.hegde, will

On 12/4/24 20:29, Yi Liu wrote:
> driver should implement both set_dev_pasid and remove_dev_pasid op, otherwise
> it is a problem how to detach pasid. In reality, it is impossible that an
> iommu driver implements set_dev_pasid() but no remove_dev_pasid() op. However,
> it is better to check it.
> 
> Move the group check to be the first as dev_iommu_ops() may fail when there
> is no valid group. Also take the chance to remove the dev_has_iommu() check
> as it is duplicated to the group check.
> 
> Reviewed-by: Jason Gunthorpe<jgg@nvidia.com>
> Signed-off-by: Yi Liu<yi.l.liu@intel.com>

Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: [PATCH v6 1/7] iommu: Prevent pasid attach if no ops->remove_dev_pasid
  2024-12-04 12:29 ` [PATCH v6 1/7] iommu: Prevent pasid attach if no ops->remove_dev_pasid Yi Liu
  2024-12-05  2:13   ` Baolu Lu
@ 2024-12-11  8:24   ` Tian, Kevin
  1 sibling, 0 replies; 11+ messages in thread
From: Tian, Kevin @ 2024-12-11  8:24 UTC (permalink / raw)
  To: Liu, Yi L, joro@8bytes.org, jgg@nvidia.com,
	baolu.lu@linux.intel.com
  Cc: eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org,
	chao.p.peng@linux.intel.com, iommu@lists.linux.dev,
	Duan, Zhenzhong, vasant.hegde@amd.com, will@kernel.org

> From: Liu, Yi L <yi.l.liu@intel.com>
> Sent: Wednesday, December 4, 2024 8:29 PM
> 
> driver should implement both set_dev_pasid and remove_dev_pasid op,
> otherwise
> it is a problem how to detach pasid. In reality, it is impossible that an
> iommu driver implements set_dev_pasid() but no remove_dev_pasid() op.
> However,
> it is better to check it.
> 
> Move the group check to be the first as dev_iommu_ops() may fail when
> there
> is no valid group. Also take the chance to remove the dev_has_iommu()
> check
> as it is duplicated to the group check.
> 
> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
> Signed-off-by: Yi Liu <yi.l.liu@intel.com>

Reviewed-by: Kevin Tian <kevin.tian@intel.com>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v6 0/7] Support attaching PASID to the blocked_domain
  2024-12-04 12:29 [PATCH v6 0/7] Support attaching PASID to the blocked_domain Yi Liu
                   ` (6 preceding siblings ...)
  2024-12-04 12:29 ` [PATCH v6 7/7] iommu: Remove the remove_dev_pasid op Yi Liu
@ 2024-12-18  8:40 ` Joerg Roedel
  7 siblings, 0 replies; 11+ messages in thread
From: Joerg Roedel @ 2024-12-18  8:40 UTC (permalink / raw)
  To: Yi Liu
  Cc: jgg, kevin.tian, baolu.lu, eric.auger, nicolinc, kvm, chao.p.peng,
	iommu, zhenzhong.duan, vasant.hegde, will

On Wed, Dec 04, 2024 at 04:29:21AM -0800, Yi Liu wrote:
> Jason Gunthorpe (1):
>   iommu/arm-smmu-v3: Make the blocked domain support PASID
> 
> Yi Liu (6):
>   iommu: Prevent pasid attach if no ops->remove_dev_pasid
>   iommu: Consolidate the ops->remove_dev_pasid usage into a helper
>   iommu: Detaching pasid by attaching to the blocked_domain
>   iommu/vt-d: Make the blocked domain support PASID
>   iommu/amd: Make the blocked domain support PASID
>   iommu: Remove the remove_dev_pasid op
> 
>  drivers/iommu/amd/iommu.c                   | 10 +++++-
>  drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 12 +++----
>  drivers/iommu/intel/iommu.c                 | 15 ++++++---
>  drivers/iommu/iommu.c                       | 35 +++++++++++++--------
>  include/linux/iommu.h                       |  5 ---
>  5 files changed, 48 insertions(+), 29 deletions(-)

Applied, thanks.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-12-18  8:40 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-04 12:29 [PATCH v6 0/7] Support attaching PASID to the blocked_domain Yi Liu
2024-12-04 12:29 ` [PATCH v6 1/7] iommu: Prevent pasid attach if no ops->remove_dev_pasid Yi Liu
2024-12-05  2:13   ` Baolu Lu
2024-12-11  8:24   ` Tian, Kevin
2024-12-04 12:29 ` [PATCH v6 2/7] iommu: Consolidate the ops->remove_dev_pasid usage into a helper Yi Liu
2024-12-04 12:29 ` [PATCH v6 3/7] iommu: Detaching pasid by attaching to the blocked_domain Yi Liu
2024-12-04 12:29 ` [PATCH v6 4/7] iommu/arm-smmu-v3: Make the blocked domain support PASID Yi Liu
2024-12-04 12:29 ` [PATCH v6 5/7] iommu/vt-d: " Yi Liu
2024-12-04 12:29 ` [PATCH v6 6/7] iommu/amd: " Yi Liu
2024-12-04 12:29 ` [PATCH v6 7/7] iommu: Remove the remove_dev_pasid op Yi Liu
2024-12-18  8:40 ` [PATCH v6 0/7] Support attaching PASID to the blocked_domain Joerg Roedel

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.