Skip to contentSkip to conversation

iommu: Retire detach_dev callback

PATCH Superseded Lu Baolu 2 participants 6 messages Aug 26, 2022 – Aug 29, 2022

Subsystems (18)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Lu Baolu

author maintainer
#0 lore raw

v2 cover iommu: Retire detach_dev callback

Hi folks,

This is a follow-up series after several discussions on blocking domain. The latest discussion could be found here.

https://lore.kernel.org/linux-iommu/[email protected]/

As .detach_dev equals to setting the blocking domain to the device, this callback is not needed anymore. This replace .detach_dev callback in the IOMMU drivers with a static blocking domain and retires this callback.

With .detach_dev retired, rename .attach_dev to .set_dev as it actually means setting an iommu domain to the device.

This series depends on below series which includes blocking domain
support for VT-d and SMMUv3 drivers.
[1] https://lore.kernel.org/linux-iommu/[email protected]/

This series is available on github:
[2] https://github.com/LuBaolu/intel-iommu/commits/iommu-blocking_domain-v2

Please review and suggest.

Best regards,
baolu

Change log:
v2:
- Replace .detach_dev callback with static block domain ops;
- Rename .attach_dev to .set_dev.

v1:
- https://lore.kernel.org/linux-iommu/[email protected]/

Lu Baolu (3):
iommu: Replace detach_dev with real blocking domains
iommu: Retire detach_dev domain ops
iommu: Rename attach_dev to set_dev

 include/linux/iommu.h                       |  6 ++--
 drivers/iommu/amd/iommu.c                   | 24 ++++++++++++--
 drivers/iommu/apple-dart.c                  | 26 ++++++++++++---
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c |  4 +--
 drivers/iommu/arm/arm-smmu/arm-smmu.c       |  2 +-
 drivers/iommu/arm/arm-smmu/qcom_iommu.c     | 25 +++++++++++++--
 drivers/iommu/exynos-iommu.c                | 25 +++++++++++++--
 drivers/iommu/fsl_pamu_domain.c             | 24 ++++++++++++--
 drivers/iommu/intel/iommu.c                 |  4 +--
 drivers/iommu/iommu.c                       | 35 ++++-----------------
 drivers/iommu/ipmmu-vmsa.c                  | 24 ++++++++++++--
 drivers/iommu/msm_iommu.c                   | 25 +++++++++++++--
 drivers/iommu/mtk_iommu.c                   | 24 ++++++++++++--
 drivers/iommu/mtk_iommu_v1.c                | 24 ++++++++++++--
 drivers/iommu/omap-iommu.c                  | 22 +++++++++++--
 drivers/iommu/rockchip-iommu.c              | 22 +++++++++++--
 drivers/iommu/s390-iommu.c                  | 27 ++++++++++++++--
 drivers/iommu/sprd-iommu.c                  | 25 +++++++++++++--
 drivers/iommu/sun50i-iommu.c                | 25 +++++++++++++--
 drivers/iommu/tegra-gart.c                  | 22 +++++++++++--
 drivers/iommu/tegra-smmu.c                  | 25 +++++++++++++--
 drivers/iommu/virtio-iommu.c                |  2 +-
 22 files changed, 368 insertions(+), 74 deletions(-)
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH v2 1/3 iommu: Replace detach_dev with real blocking domains

From iommu core's point of view, detaching a domain from a device is equal to attaching the group's blocking domain to the device. This repalces all detach_dev callbacks in the IOMMU drivers with a real blocking domain and handles detaching domain through it.

---
 drivers/iommu/amd/iommu.c               | 22 +++++++++++++++++++++-
 drivers/iommu/apple-dart.c              | 24 +++++++++++++++++++++---
 drivers/iommu/arm/arm-smmu/qcom_iommu.c | 23 ++++++++++++++++++++++-
 drivers/iommu/exynos-iommu.c            | 23 ++++++++++++++++++++++-
 drivers/iommu/fsl_pamu_domain.c         | 22 +++++++++++++++++++++-
 drivers/iommu/ipmmu-vmsa.c              | 22 +++++++++++++++++++++-
 drivers/iommu/msm_iommu.c               | 23 ++++++++++++++++++++++-
 drivers/iommu/mtk_iommu.c               | 22 +++++++++++++++++++++-
 drivers/iommu/mtk_iommu_v1.c            | 22 +++++++++++++++++++++-
 drivers/iommu/omap-iommu.c              | 20 +++++++++++++++++++-
 drivers/iommu/rockchip-iommu.c          | 20 +++++++++++++++++++-
 drivers/iommu/s390-iommu.c              | 23 ++++++++++++++++++++++-
 drivers/iommu/sprd-iommu.c              | 23 ++++++++++++++++++++++-
 drivers/iommu/sun50i-iommu.c            | 23 ++++++++++++++++++++++-
 drivers/iommu/tegra-gart.c              | 20 +++++++++++++++++++-
 drivers/iommu/tegra-smmu.c              | 23 ++++++++++++++++++++++-
 16 files changed, 337 insertions(+), 18 deletions(-)
drivers/iommu/amd/iommu.c +21 -1
index 65b8e4fd8217..4cd0438b0a6e 100644
@@ -85,6 +85,8 @@ struct iommu_cmd {
 struct kmem_cache *amd_iommu_irq_cache;
 
 static void detach_device(struct device *dev);
+static void amd_iommu_detach_device(struct iommu_domain *dom,
+				    struct device *dev);
 
 /****************************************************************************
  *
@@ -2064,10 +2066,29 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
 	return NULL;
 }
 
+static int blocking_domain_attach_dev(struct iommu_domain *_domain,
+				      struct device *dev)
+{
+	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
+
+	amd_iommu_detach_device(domain, dev);
+
+	return 0;
+}
+
+static struct iommu_domain blocking_domain = {
+	.ops = &(const struct iommu_domain_ops) {
+		.attach_dev	= blocking_domain_attach_dev
+	}
+};
+
 static struct iommu_domain *amd_iommu_domain_alloc(unsigned type)
 {
 	struct protection_domain *domain;
 
+	if (type == IOMMU_DOMAIN_BLOCKED)
+		return &blocking_domain;
+
 	/*
 	 * Since DTE[Mode]=0 is prohibited on SNP-enabled system,
 	 * default to use IOMMU_DOMAIN_DMA[_FQ].
@@ -2398,7 +2419,6 @@ const struct iommu_ops amd_iommu_ops = {
 	.def_domain_type = amd_iommu_def_domain_type,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= amd_iommu_attach_device,
-		.detach_dev	= amd_iommu_detach_device,
 		.map		= amd_iommu_map,
 		.unmap		= amd_iommu_unmap,
 		.iotlb_sync_map	= amd_iommu_iotlb_sync_map,
drivers/iommu/apple-dart.c +21 -3
index 1b1725759262..5f46cbf04e07 100644
@@ -568,12 +568,31 @@ static void apple_dart_release_device(struct device *dev)
 	kfree(cfg);
 }
 
+static int blocking_domain_attach_dev(struct iommu_domain *_domain,
+				      struct device *dev)
+{
+	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
+
+	apple_dart_detach_dev(domain, dev);
+
+	return 0;
+}
+
+static struct iommu_domain blocking_domain = {
+	.ops = &(const struct iommu_domain_ops) {
+		.attach_dev	= blocking_domain_attach_dev
+	}
+};
+
 static struct iommu_domain *apple_dart_domain_alloc(unsigned int type)
 {
 	struct apple_dart_domain *dart_domain;
 
+	if (type == IOMMU_DOMAIN_BLOCKED)
+		return &blocking_domain;
+
 	if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED &&
-	    type != IOMMU_DOMAIN_IDENTITY && type != IOMMU_DOMAIN_BLOCKED)
+	    type != IOMMU_DOMAIN_IDENTITY)
 		return NULL;
 
 	dart_domain = kzalloc(sizeof(*dart_domain), GFP_KERNEL);
@@ -583,7 +602,7 @@ static struct iommu_domain *apple_dart_domain_alloc(unsigned int type)
 	mutex_init(&dart_domain->init_lock);
 
 	/* no need to allocate pgtbl_ops or do any other finalization steps */
-	if (type == IOMMU_DOMAIN_IDENTITY || type == IOMMU_DOMAIN_BLOCKED)
+	if (type == IOMMU_DOMAIN_IDENTITY)
 		dart_domain->finalized = true;
 
 	return &dart_domain->domain;
@@ -772,7 +791,6 @@ static const struct iommu_ops apple_dart_iommu_ops = {
 	.owner = THIS_MODULE,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= apple_dart_attach_dev,
-		.detach_dev	= apple_dart_detach_dev,
 		.map_pages	= apple_dart_map_pages,
 		.unmap_pages	= apple_dart_unmap_pages,
 		.flush_iotlb_all = apple_dart_flush_iotlb_all,
drivers/iommu/arm/arm-smmu/qcom_iommu.c +22 -1
index 17235116d3bb..59f8a4d3865c 100644
@@ -72,6 +72,9 @@ struct qcom_iommu_domain {
 	struct iommu_fwspec	*fwspec;
 };
 
+static void qcom_iommu_detach_dev(struct iommu_domain *domain,
+				  struct device *dev);
+
 static struct qcom_iommu_domain *to_qcom_iommu_domain(struct iommu_domain *dom)
 {
 	return container_of(dom, struct qcom_iommu_domain, domain);
@@ -319,10 +322,29 @@ static int qcom_iommu_init_domain(struct iommu_domain *domain,
 	return ret;
 }
 
+static int blocking_domain_attach_dev(struct iommu_domain *_domain,
+				      struct device *dev)
+{
+	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
+
+	qcom_iommu_detach_dev(domain, dev);
+
+	return 0;
+}
+
+static struct iommu_domain blocking_domain = {
+	.ops = &(const struct iommu_domain_ops) {
+		.attach_dev	= blocking_domain_attach_dev
+	}
+};
+
 static struct iommu_domain *qcom_iommu_domain_alloc(unsigned type)
 {
 	struct qcom_iommu_domain *qcom_domain;
 
+	if (type == IOMMU_DOMAIN_BLOCKED)
+		return &blocking_domain;
+
 	if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA)
 		return NULL;
 	/*
@@ -586,7 +608,6 @@ static const struct iommu_ops qcom_iommu_ops = {
 	.pgsize_bitmap	= SZ_4K | SZ_64K | SZ_1M | SZ_16M,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= qcom_iommu_attach_dev,
-		.detach_dev	= qcom_iommu_detach_dev,
 		.map		= qcom_iommu_map,
 		.unmap		= qcom_iommu_unmap,
 		.flush_iotlb_all = qcom_iommu_flush_iotlb_all,
drivers/iommu/exynos-iommu.c +22 -1
index 8e18984a0c4f..f2958ec1868c 100644
@@ -174,6 +174,9 @@ static struct kmem_cache *lv2table_kmem_cache;
 static sysmmu_pte_t *zero_lv2_table;
 #define ZERO_LV2LINK mk_lv1ent_page(virt_to_phys(zero_lv2_table))
 
+static void exynos_iommu_detach_device(struct iommu_domain *iommu_domain,
+				       struct device *dev);
+
 static sysmmu_pte_t *section_entry(sysmmu_pte_t *pgtable, sysmmu_iova_t iova)
 {
 	return pgtable + lv1ent_offset(iova);
@@ -818,12 +821,31 @@ static inline void exynos_iommu_set_pte(sysmmu_pte_t *ent, sysmmu_pte_t val)
 				   DMA_TO_DEVICE);
 }
 
+static int blocking_domain_attach_dev(struct iommu_domain *_domain,
+				      struct device *dev)
+{
+	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
+
+	exynos_iommu_detach_device(domain, dev);
+
+	return 0;
+}
+
+static struct iommu_domain blocking_domain = {
+	.ops = &(const struct iommu_domain_ops) {
+		.attach_dev	= blocking_domain_attach_dev
+	}
+};
+
 static struct iommu_domain *exynos_iommu_domain_alloc(unsigned type)
 {
 	struct exynos_iommu_domain *domain;
 	dma_addr_t handle;
 	int i;
 
+	if (type == IOMMU_DOMAIN_BLOCKED)
+		return &blocking_domain;
+
 	/* Check if correct PTE offsets are initialized */
 	BUG_ON(PG_ENT_SHIFT < 0 || !dma_dev);
 
@@ -1406,7 +1428,6 @@ static const struct iommu_ops exynos_iommu_ops = {
 	.of_xlate = exynos_iommu_of_xlate,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= exynos_iommu_attach_device,
-		.detach_dev	= exynos_iommu_detach_device,
 		.map		= exynos_iommu_map,
 		.unmap		= exynos_iommu_unmap,
 		.iova_to_phys	= exynos_iommu_iova_to_phys,
drivers/iommu/fsl_pamu_domain.c +21 -1
index 011f9ab7f743..66a7093c7852 100644
@@ -23,6 +23,8 @@ static struct kmem_cache *iommu_devinfo_cache;
 static DEFINE_SPINLOCK(device_domain_lock);
 
 struct iommu_device pamu_iommu;	/* IOMMU core code handle */
+static void fsl_pamu_detach_device(struct iommu_domain *domain,
+				   struct device *dev);
 
 static struct fsl_dma_domain *to_fsl_dma_domain(struct iommu_domain *dom)
 {
@@ -192,10 +194,29 @@ static void fsl_pamu_domain_free(struct iommu_domain *domain)
 	kmem_cache_free(fsl_pamu_domain_cache, dma_domain);
 }
 
+static int blocking_domain_attach_dev(struct iommu_domain *_domain,
+				      struct device *dev)
+{
+	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
+
+	fsl_pamu_detach_device(domain, dev);
+
+	return 0;
+}
+
+static struct iommu_domain blocking_domain = {
+	.ops = &(const struct iommu_domain_ops) {
+		.attach_dev	= blocking_domain_attach_dev
+	}
+};
+
 static struct iommu_domain *fsl_pamu_domain_alloc(unsigned type)
 {
 	struct fsl_dma_domain *dma_domain;
 
+	if (type == IOMMU_DOMAIN_BLOCKED)
+		return &blocking_domain;
+
 	if (type != IOMMU_DOMAIN_UNMANAGED)
 		return NULL;
 
@@ -454,7 +475,6 @@ static const struct iommu_ops fsl_pamu_ops = {
 	.device_group   = fsl_pamu_device_group,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= fsl_pamu_attach_device,
-		.detach_dev	= fsl_pamu_detach_device,
 		.iova_to_phys	= fsl_pamu_iova_to_phys,
 		.free		= fsl_pamu_domain_free,
 	}
drivers/iommu/ipmmu-vmsa.c +21 -1
index 1d42084d0276..cfb94e77bbab 100644
@@ -79,6 +79,9 @@ struct ipmmu_vmsa_domain {
 	struct mutex mutex;			/* Protects mappings */
 };
 
+static void ipmmu_detach_device(struct iommu_domain *io_domain,
+				struct device *dev);
+
 static struct ipmmu_vmsa_domain *to_vmsa_domain(struct iommu_domain *dom)
 {
 	return container_of(dom, struct ipmmu_vmsa_domain, io_domain);
@@ -566,11 +569,29 @@ static irqreturn_t ipmmu_irq(int irq, void *dev)
 /* -----------------------------------------------------------------------------
  * IOMMU Operations
  */
+static int blocking_domain_attach_dev(struct iommu_domain *_domain,
+				      struct device *dev)
+{
+	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
+
+	ipmmu_detach_device(domain, dev);
+
+	return 0;
+}
+
+static struct iommu_domain blocking_domain = {
+	.ops = &(const struct iommu_domain_ops) {
+		.attach_dev	= blocking_domain_attach_dev
+	}
+};
 
 static struct iommu_domain *ipmmu_domain_alloc(unsigned type)
 {
 	struct ipmmu_vmsa_domain *domain;
 
+	if (type == IOMMU_DOMAIN_BLOCKED)
+		return &blocking_domain;
+
 	if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA)
 		return NULL;
 
@@ -878,7 +899,6 @@ static const struct iommu_ops ipmmu_ops = {
 	.of_xlate = ipmmu_of_xlate,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= ipmmu_attach_device,
-		.detach_dev	= ipmmu_detach_device,
 		.map		= ipmmu_map,
 		.unmap		= ipmmu_unmap,
 		.flush_iotlb_all = ipmmu_flush_iotlb_all,
drivers/iommu/msm_iommu.c +22 -1
index 6a24aa804ea3..f57f2da2d652 100644
@@ -46,6 +46,9 @@ struct msm_priv {
 	spinlock_t		pgtlock; /* pagetable lock */
 };
 
+static void msm_iommu_detach_dev(struct iommu_domain *domain,
+				 struct device *dev);
+
 static struct msm_priv *to_msm_priv(struct iommu_domain *dom)
 {
 	return container_of(dom, struct msm_priv, domain);
@@ -302,10 +305,29 @@ static void __program_context(void __iomem *base, int ctx,
 	SET_M(base, ctx, 1);
 }
 
+static int blocking_domain_attach_dev(struct iommu_domain *_domain,
+				      struct device *dev)
+{
+	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
+
+	msm_iommu_detach_dev(domain, dev);
+
+	return 0;
+}
+
+static struct iommu_domain blocking_domain = {
+	.ops = &(const struct iommu_domain_ops) {
+		.attach_dev	= blocking_domain_attach_dev
+	}
+};
+
 static struct iommu_domain *msm_iommu_domain_alloc(unsigned type)
 {
 	struct msm_priv *priv;
 
+	if (type == IOMMU_DOMAIN_BLOCKED)
+		return &blocking_domain;
+
 	if (type != IOMMU_DOMAIN_UNMANAGED)
 		return NULL;
 
@@ -678,7 +700,6 @@ static struct iommu_ops msm_iommu_ops = {
 	.of_xlate = qcom_iommu_of_xlate,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= msm_iommu_attach_dev,
-		.detach_dev	= msm_iommu_detach_dev,
 		.map		= msm_iommu_map,
 		.unmap		= msm_iommu_unmap,
 		/*
drivers/iommu/mtk_iommu.c +21 -1
index 7e363b1f24df..63360272d504 100644
@@ -264,6 +264,8 @@ static void mtk_iommu_unbind(struct device *dev)
 static const struct iommu_ops mtk_iommu_ops;
 
 static int mtk_iommu_hw_init(const struct mtk_iommu_data *data, unsigned int bankid);
+static void mtk_iommu_detach_device(struct iommu_domain *domain,
+				    struct device *dev);
 
 #define MTK_IOMMU_TLB_ADDR(iova) ({					\
 	dma_addr_t _addr = iova;					\
@@ -622,10 +624,29 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom,
 	return 0;
 }
 
+static int blocking_domain_attach_dev(struct iommu_domain *_domain,
+				      struct device *dev)
+{
+	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
+
+	mtk_iommu_detach_device(domain, dev);
+
+	return 0;
+}
+
+static struct iommu_domain blocking_domain = {
+	.ops = &(const struct iommu_domain_ops) {
+		.attach_dev	= blocking_domain_attach_dev
+	}
+};
+
 static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type)
 {
 	struct mtk_iommu_domain *dom;
 
+	if (type == IOMMU_DOMAIN_BLOCKED)
+		return &blocking_domain;
+
 	if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED)
 		return NULL;
 
@@ -934,7 +955,6 @@ static const struct iommu_ops mtk_iommu_ops = {
 	.owner		= THIS_MODULE,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= mtk_iommu_attach_device,
-		.detach_dev	= mtk_iommu_detach_device,
 		.map		= mtk_iommu_map,
 		.unmap		= mtk_iommu_unmap,
 		.flush_iotlb_all = mtk_iommu_flush_iotlb_all,
drivers/iommu/mtk_iommu_v1.c +21 -1
index 128c7a3f1778..269622023917 100644
@@ -116,6 +116,8 @@ struct mtk_iommu_v1_domain {
 	struct mtk_iommu_v1_data	*data;
 };
 
+static void mtk_iommu_v1_detach_device(struct iommu_domain *domain,
+				       struct device *dev);
 static int mtk_iommu_v1_bind(struct device *dev)
 {
 	struct mtk_iommu_v1_data *data = dev_get_drvdata(dev);
@@ -270,10 +272,29 @@ static int mtk_iommu_v1_domain_finalise(struct mtk_iommu_v1_data *data)
 	return 0;
 }
 
+static int blocking_domain_attach_dev(struct iommu_domain *_domain,
+				      struct device *dev)
+{
+	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
+
+	mtk_iommu_v1_detach_device(domain, dev);
+
+	return 0;
+}
+
+static struct iommu_domain blocking_domain = {
+	.ops = &(const struct iommu_domain_ops) {
+		.attach_dev	= blocking_domain_attach_dev
+	}
+};
+
 static struct iommu_domain *mtk_iommu_v1_domain_alloc(unsigned type)
 {
 	struct mtk_iommu_v1_domain *dom;
 
+	if (type == IOMMU_DOMAIN_BLOCKED)
+		return &blocking_domain;
+
 	if (type != IOMMU_DOMAIN_UNMANAGED)
 		return NULL;
 
@@ -590,7 +611,6 @@ static const struct iommu_ops mtk_iommu_v1_ops = {
 	.owner          = THIS_MODULE,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= mtk_iommu_v1_attach_device,
-		.detach_dev	= mtk_iommu_v1_detach_device,
 		.map		= mtk_iommu_v1_map,
 		.unmap		= mtk_iommu_v1_unmap,
 		.iova_to_phys	= mtk_iommu_v1_iova_to_phys,
drivers/iommu/omap-iommu.c +19 -1
index d9cf2820c02e..ceb88fd96ac0 100644
@@ -1566,10 +1566,29 @@ static void omap_iommu_detach_dev(struct iommu_domain *domain,
 	spin_unlock(&omap_domain->lock);
 }
 
+static int blocking_domain_attach_dev(struct iommu_domain *_domain,
+				      struct device *dev)
+{
+	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
+
+	omap_iommu_detach_dev(domain, dev);
+
+	return 0;
+}
+
+static struct iommu_domain blocking_domain = {
+	.ops = &(const struct iommu_domain_ops) {
+		.attach_dev	= blocking_domain_attach_dev
+	}
+};
+
 static struct iommu_domain *omap_iommu_domain_alloc(unsigned type)
 {
 	struct omap_iommu_domain *omap_domain;
 
+	if (type == IOMMU_DOMAIN_BLOCKED)
+		return &blocking_domain;
+
 	if (type != IOMMU_DOMAIN_UNMANAGED)
 		return NULL;
 
@@ -1740,7 +1759,6 @@ static const struct iommu_ops omap_iommu_ops = {
 	.pgsize_bitmap	= OMAP_IOMMU_PGSIZES,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= omap_iommu_attach_dev,
-		.detach_dev	= omap_iommu_detach_dev,
 		.map		= omap_iommu_map,
 		.unmap		= omap_iommu_unmap,
 		.iova_to_phys	= omap_iommu_iova_to_phys,
drivers/iommu/rockchip-iommu.c +19 -1
index ab57c4b8fade..3a8239ddbb4f 100644
@@ -1059,10 +1059,29 @@ static int rk_iommu_attach_device(struct iommu_domain *domain,
 	return ret;
 }
 
+static int blocking_domain_attach_dev(struct iommu_domain *_domain,
+				      struct device *dev)
+{
+	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
+
+	rk_iommu_detach_device(domain, dev);
+
+	return 0;
+}
+
+static struct iommu_domain blocking_domain = {
+	.ops = &(const struct iommu_domain_ops) {
+		.attach_dev	= blocking_domain_attach_dev
+	}
+};
+
 static struct iommu_domain *rk_iommu_domain_alloc(unsigned type)
 {
 	struct rk_iommu_domain *rk_domain;
 
+	if (type == IOMMU_DOMAIN_BLOCKED)
+		return &blocking_domain;
+
 	if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA)
 		return NULL;
 
@@ -1194,7 +1213,6 @@ static const struct iommu_ops rk_iommu_ops = {
 	.of_xlate = rk_iommu_of_xlate,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= rk_iommu_attach_device,
-		.detach_dev	= rk_iommu_detach_device,
 		.map		= rk_iommu_map,
 		.unmap		= rk_iommu_unmap,
 		.iova_to_phys	= rk_iommu_iova_to_phys,
drivers/iommu/s390-iommu.c +22 -1
index c898bcbbce11..b18c8302a23d 100644
@@ -34,6 +34,9 @@ struct s390_domain_device {
 	struct zpci_dev		*zdev;
 };
 
+static void s390_iommu_detach_device(struct iommu_domain *domain,
+				     struct device *dev);
+
 static struct s390_domain *to_s390_domain(struct iommu_domain *dom)
 {
 	return container_of(dom, struct s390_domain, domain);
@@ -51,10 +54,29 @@ static bool s390_iommu_capable(enum iommu_cap cap)
 	}
 }
 
+static int blocking_domain_attach_dev(struct iommu_domain *_domain,
+				      struct device *dev)
+{
+	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
+
+	s390_iommu_detach_device(domain, dev);
+
+	return 0;
+}
+
+static struct iommu_domain blocking_domain = {
+	.ops = &(const struct iommu_domain_ops) {
+		.attach_dev	= blocking_domain_attach_dev
+	}
+};
+
 static struct iommu_domain *s390_domain_alloc(unsigned domain_type)
 {
 	struct s390_domain *s390_domain;
 
+	if (domain_type == IOMMU_DOMAIN_BLOCKED)
+		return &blocking_domain;
+
 	if (domain_type != IOMMU_DOMAIN_UNMANAGED)
 		return NULL;
 
@@ -378,7 +400,6 @@ static const struct iommu_ops s390_iommu_ops = {
 	.pgsize_bitmap = S390_IOMMU_PGSIZES,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= s390_iommu_attach_device,
-		.detach_dev	= s390_iommu_detach_device,
 		.map		= s390_iommu_map,
 		.unmap		= s390_iommu_unmap,
 		.iova_to_phys	= s390_iommu_iova_to_phys,
drivers/iommu/sprd-iommu.c +22 -1
index 511959c8a14d..46c567c489d7 100644
@@ -82,6 +82,9 @@ struct sprd_iommu_domain {
 
 static const struct iommu_ops sprd_iommu_ops;
 
+static void sprd_iommu_detach_device(struct iommu_domain *domain,
+				     struct device *dev);
+
 static struct sprd_iommu_domain *to_sprd_domain(struct iommu_domain *dom)
 {
 	return container_of(dom, struct sprd_iommu_domain, domain);
@@ -132,10 +135,29 @@ sprd_iommu_pgt_size(struct iommu_domain *domain)
 		SPRD_IOMMU_PAGE_SHIFT) * sizeof(u32);
 }
 
+static int blocking_domain_attach_dev(struct iommu_domain *_domain,
+				      struct device *dev)
+{
+	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
+
+	sprd_iommu_detach_device(domain, dev);
+
+	return 0;
+}
+
+static struct iommu_domain blocking_domain = {
+	.ops = &(const struct iommu_domain_ops) {
+		.attach_dev	= blocking_domain_attach_dev
+	}
+};
+
 static struct iommu_domain *sprd_iommu_domain_alloc(unsigned int domain_type)
 {
 	struct sprd_iommu_domain *dom;
 
+	if (domain_type == IOMMU_DOMAIN_BLOCKED)
+		return &blocking_domain;
+
 	if (domain_type != IOMMU_DOMAIN_DMA && domain_type != IOMMU_DOMAIN_UNMANAGED)
 		return NULL;
 
@@ -413,7 +435,6 @@ static const struct iommu_ops sprd_iommu_ops = {
 	.owner		= THIS_MODULE,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= sprd_iommu_attach_device,
-		.detach_dev	= sprd_iommu_detach_device,
 		.map		= sprd_iommu_map,
 		.unmap		= sprd_iommu_unmap,
 		.iotlb_sync_map	= sprd_iommu_sync_map,
drivers/iommu/sun50i-iommu.c +22 -1
index a84c63518773..1e63e782d23e 100644
@@ -121,6 +121,9 @@ struct sun50i_iommu_domain {
 	struct sun50i_iommu *iommu;
 };
 
+static void sun50i_iommu_detach_device(struct iommu_domain *domain,
+				       struct device *dev);
+
 static struct sun50i_iommu_domain *to_sun50i_domain(struct iommu_domain *domain)
 {
 	return container_of(domain, struct sun50i_iommu_domain, domain);
@@ -596,10 +599,29 @@ static phys_addr_t sun50i_iommu_iova_to_phys(struct iommu_domain *domain,
 		sun50i_iova_get_page_offset(iova);
 }
 
+static int blocking_domain_attach_dev(struct iommu_domain *_domain,
+				      struct device *dev)
+{
+	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
+
+	sun50i_iommu_detach_device(domain, dev);
+
+	return 0;
+}
+
+static struct iommu_domain blocking_domain = {
+	.ops = &(const struct iommu_domain_ops) {
+		.attach_dev	= blocking_domain_attach_dev
+	}
+};
+
 static struct iommu_domain *sun50i_iommu_domain_alloc(unsigned type)
 {
 	struct sun50i_iommu_domain *sun50i_domain;
 
+	if (type == IOMMU_DOMAIN_BLOCKED)
+		return &blocking_domain;
+
 	if (type != IOMMU_DOMAIN_DMA &&
 	    type != IOMMU_DOMAIN_IDENTITY &&
 	    type != IOMMU_DOMAIN_UNMANAGED)
@@ -764,7 +786,6 @@ static const struct iommu_ops sun50i_iommu_ops = {
 	.probe_device	= sun50i_iommu_probe_device,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= sun50i_iommu_attach_device,
-		.detach_dev	= sun50i_iommu_detach_device,
 		.flush_iotlb_all = sun50i_iommu_flush_iotlb_all,
 		.iotlb_sync	= sun50i_iommu_iotlb_sync,
 		.iova_to_phys	= sun50i_iommu_iova_to_phys,
drivers/iommu/tegra-gart.c +19 -1
index e5ca3cf1a949..5d5669f60d23 100644
@@ -141,10 +141,29 @@ static void gart_iommu_detach_dev(struct iommu_domain *domain,
 	spin_unlock(&gart->dom_lock);
 }
 
+static int blocking_domain_attach_dev(struct iommu_domain *_domain,
+				      struct device *dev)
+{
+	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
+
+	gart_iommu_detach_dev(domain, dev);
+
+	return 0;
+}
+
+static struct iommu_domain blocking_domain = {
+	.ops = &(const struct iommu_domain_ops) {
+		.attach_dev	= blocking_domain_attach_dev
+	}
+};
+
 static struct iommu_domain *gart_iommu_domain_alloc(unsigned type)
 {
 	struct iommu_domain *domain;
 
+	if (type == IOMMU_DOMAIN_BLOCKED)
+		return &blocking_domain;
+
 	if (type != IOMMU_DOMAIN_UNMANAGED)
 		return NULL;
 
@@ -274,7 +293,6 @@ static const struct iommu_ops gart_iommu_ops = {
 	.of_xlate	= gart_iommu_of_xlate,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= gart_iommu_attach_dev,
-		.detach_dev	= gart_iommu_detach_dev,
 		.map		= gart_iommu_map,
 		.unmap		= gart_iommu_unmap,
 		.iova_to_phys	= gart_iommu_iova_to_phys,
drivers/iommu/tegra-smmu.c +22 -1
index 2a8de975fe63..54fddb5215a5 100644
@@ -62,6 +62,9 @@ struct tegra_smmu_as {
 	u32 attr;
 };
 
+static void tegra_smmu_detach_dev(struct iommu_domain *domain,
+				  struct device *dev);
+
 static struct tegra_smmu_as *to_smmu_as(struct iommu_domain *dom)
 {
 	return container_of(dom, struct tegra_smmu_as, domain);
@@ -272,10 +275,29 @@ static void tegra_smmu_free_asid(struct tegra_smmu *smmu, unsigned int id)
 	clear_bit(id, smmu->asids);
 }
 
+static int blocking_domain_attach_dev(struct iommu_domain *_domain,
+				      struct device *dev)
+{
+	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
+
+	tegra_smmu_detach_dev(domain, dev);
+
+	return 0;
+}
+
+static struct iommu_domain blocking_domain = {
+	.ops = &(const struct iommu_domain_ops) {
+		.attach_dev	= blocking_domain_attach_dev
+	}
+};
+
 static struct iommu_domain *tegra_smmu_domain_alloc(unsigned type)
 {
 	struct tegra_smmu_as *as;
 
+	if (type == IOMMU_DOMAIN_BLOCKED)
+		return &blocking_domain;
+
 	if (type != IOMMU_DOMAIN_UNMANAGED)
 		return NULL;
 
@@ -969,7 +991,6 @@ static const struct iommu_ops tegra_smmu_ops = {
 	.pgsize_bitmap = SZ_4K,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= tegra_smmu_attach_dev,
-		.detach_dev	= tegra_smmu_detach_dev,
 		.map		= tegra_smmu_map,
 		.unmap		= tegra_smmu_unmap,
 		.iova_to_phys	= tegra_smmu_iova_to_phys,
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH v2 1/3] iommu: Replace detach_dev with real blocking domains

Quoted 4 lines · Lu Baolu

From iommu core's point of view, detaching a domain from a device is equal to attaching the group's blocking domain to the device. This repalces all detach_dev callbacks in the IOMMU drivers with a real blocking domain and handles detaching domain through it.

There is a subtly here, where detach_dev() is not *always* going to a blocking domain. Recall we made this mistaken when building the owner series and it is why the blocking domain was introduced.

The challenge with this work is to be sure that the code you assigned to the blocking domain doesn't actually set an identity domain or set things to use the platform DMA ops.

drivers/iommu/s390-iommu.c static bool s390_iommu_capable(enum iommu_cap cap) · line 65

Quoted 9 lines
drivers/iommu/s390-iommu.c +9 -0
+static int blocking_domain_attach_dev(struct iommu_domain *_domain,
+				      struct device *dev)
+{
+	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
+
+	s390_iommu_detach_device(domain, dev);
+
+	return 0;
+}

For instance, I know that this is returning the group back to the platform DMA ops.

To really make progress on this I would suggest

1) Remove detach_dev from drivers that don't use it. This is any driver that provides a default domain, if a default domain is set then we always use attach_dev(default_domain) and never detach_dev

2) Of those drivers in #1 audit and try to determine if their detach_dev is doing blocking domain behavior and if yes give them a real blocking domain. Otherwise just delete the code.

3) The remaining drivers are not using default_domain. Rename 'detach_dev' to iommu_ops->set_platform_dma(dev) to make it clear that what it is doing is returning control back to the platform DMA ops.

I would do one patch per driver on the blocking domain conversions and get acks from the driver owners. Do as many as can be acked, delete the rest.

Make it clear to driver owners checking that blocking domain must halt all DMA, and it must not be a passthrough or identity behavior.

When last I looked several of the drivers looked like they were setting an identity domain on the detach_dev - eg back to a boot time behavior where the iommu is bypassed. It is really important these not be converted to blocking :) Arguably if they can be found they should be converted to identity domains instead.

Jason

author maintainer
#3 lore raw

Re: [PATCH v2 1/3] iommu: Replace detach_dev with real blocking domains

Quoted 6 lines · Jason Gunthorpe
Quoted 4 lines · Lu Baolu

From iommu core's point of view, detaching a domain from a device is
equal to attaching the group's blocking domain to the device. This repalces all detach_dev callbacks in the IOMMU drivers with a real blocking domain and handles detaching domain through it.

Quoted 7 lines

There is a subtly here, where detach_dev() is not *always* going to a blocking domain. Recall we made this mistaken when building the owner series and it is why the blocking domain was introduced.

The challenge with this work is to be sure that the code you assigned to the blocking domain doesn't actually set an identity domain or set things to use the platform DMA ops.

This looks like a defect in the current IOMMU subsystem.

Quoted 33 lines

drivers/iommu/s390-iommu.c static bool s390_iommu_capable(enum iommu_cap cap) · line 65

Quoted 10 lines
drivers/iommu/s390-iommu.c +9 -0
+static int blocking_domain_attach_dev(struct iommu_domain *_domain,
+				      struct device *dev)
+{
+	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
+
+	s390_iommu_detach_device(domain, dev);
+
+	return 0;
+}

For instance, I know that this is returning the group back to the platform DMA ops.

To really make progress on this I would suggest

1) Remove detach_dev from drivers that don't use it. This is any driver that provides a default domain, if a default domain is set then we always use attach_dev(default_domain) and never detach_dev

2) Of those drivers in #1 audit and try to determine if their detach_dev is doing blocking domain behavior and if yes give them a real blocking domain. Otherwise just delete the code.

3) The remaining drivers are not using default_domain. Rename 'detach_dev' to iommu_ops->set_platform_dma(dev) to make it clear that what it is doing is returning control back to the platform DMA ops.

I would do one patch per driver on the blocking domain conversions and get acks from the driver owners. Do as many as can be acked, delete the rest.

Quoted 8 lines

Make it clear to driver owners checking that blocking domain must halt all DMA, and it must not be a passthrough or identity behavior.

When last I looked several of the drivers looked like they were setting an identity domain on the detach_dev - eg back to a boot time behavior where the iommu is bypassed. It is really important these not be converted to blocking :) Arguably if they can be found they should be converted to identity domains instead.

Above makes sense to me. Thanks! I will spend some time looking into each IOMMU driver and back here after I work through all of them.

Best regards,
baolu

author maintainer
#4 lore raw

PATCH v2 2/3 iommu: Retire detach_dev domain ops

In reply to Lu Baolu

As no IOMMU driver provides detach_dev domain ops callback now, retire this callback and make the detach_dev calls in iommu core through the blocking domain.

---
 include/linux/iommu.h |  2 --
 drivers/iommu/iommu.c | 31 ++++---------------------------
 2 files changed, 4 insertions(+), 29 deletions(-)
include/linux/iommu.h +0 -2
index 266ef281cbd5..1e9fecfb23a7 100644
@@ -274,7 +274,6 @@ struct iommu_ops {
 /**
  * struct iommu_domain_ops - domain specific operations
  * @attach_dev: attach an iommu domain to a device
- * @detach_dev: detach an iommu domain from a device
  * @set_dev_pasid: set an iommu domain to a pasid of device
  * @map: map a physically contiguous memory region to an iommu domain
  * @map_pages: map a physically contiguous set of pages of the same size to
@@ -295,7 +294,6 @@ struct iommu_ops {
  */
 struct iommu_domain_ops {
 	int (*attach_dev)(struct iommu_domain *domain, struct device *dev);
-	void (*detach_dev)(struct iommu_domain *domain, struct device *dev);
 	int (*set_dev_pasid)(struct iommu_domain *domain, struct device *dev,
 			     ioasid_t pasid);
 
drivers/iommu/iommu.c +4 -27
index 9e84f58440dd..ad34e4df1aad 100644
@@ -2047,16 +2047,6 @@ int iommu_deferred_attach(struct device *dev, struct iommu_domain *domain)
 	return 0;
 }
 
-static void __iommu_detach_device(struct iommu_domain *domain,
-				  struct device *dev)
-{
-	if (iommu_is_attach_deferred(dev))
-		return;
-
-	domain->ops->detach_dev(domain, dev);
-	trace_detach_device_from_domain(dev);
-}
-
 void iommu_detach_device(struct iommu_domain *domain, struct device *dev)
 {
 	struct iommu_group *group;
@@ -2149,15 +2139,6 @@ int iommu_attach_group(struct iommu_domain *domain, struct iommu_group *group)
 }
 EXPORT_SYMBOL_GPL(iommu_attach_group);
 
-static int iommu_group_do_detach_device(struct device *dev, void *data)
-{
-	struct iommu_domain *domain = data;
-
-	__iommu_detach_device(domain, dev);
-
-	return 0;
-}
-
 static int __iommu_group_set_domain(struct iommu_group *group,
 				    struct iommu_domain *new_domain)
 {
@@ -2167,17 +2148,13 @@ static int __iommu_group_set_domain(struct iommu_group *group,
 		return 0;
 
 	/*
-	 * New drivers should support default domains and so the detach_dev() op
-	 * will never be called. Otherwise the NULL domain represents some
-	 * platform specific behavior.
+	 * The NULL domain represents some platform specific behavior.
+	 * Attaching the blocking domain instead.
 	 */
 	if (!new_domain) {
-		if (WARN_ON(!group->domain->ops->detach_dev))
+		if (WARN_ON(!group->blocking_domain))
 			return -EINVAL;
-		__iommu_group_for_each_dev(group, group->domain,
-					   iommu_group_do_detach_device);
-		group->domain = NULL;
-		return 0;
+		new_domain = group->blocking_domain;
 	}
 
 	/*
Signature · 1 line
2.25.1
author maintainer
#5 lore raw

PATCH v2 3/3 iommu: Rename attach_dev to set_dev

In reply to Lu Baolu

With the retirement of the detach_dev callback, the naming of attach_dev isn't meaningful anymore. Rename it to set_dev to restore its original meaning, that is, setting an iommu domain to a device. From now on, after the devices are probed, the core only sets various iommu domains to the device, i.e. identity domain, dma domain, blocking domain and etc. Conceptually, there's always an iommu domain setting on the device.

---
 include/linux/iommu.h                       | 4 ++--
 drivers/iommu/amd/iommu.c                   | 4 ++--
 drivers/iommu/apple-dart.c                  | 4 ++--
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 4 ++--
 drivers/iommu/arm/arm-smmu/arm-smmu.c       | 2 +-
 drivers/iommu/arm/arm-smmu/qcom_iommu.c     | 4 ++--
 drivers/iommu/exynos-iommu.c                | 4 ++--
 drivers/iommu/fsl_pamu_domain.c             | 4 ++--
 drivers/iommu/intel/iommu.c                 | 4 ++--
 drivers/iommu/iommu.c                       | 4 ++--
 drivers/iommu/ipmmu-vmsa.c                  | 4 ++--
 drivers/iommu/msm_iommu.c                   | 4 ++--
 drivers/iommu/mtk_iommu.c                   | 4 ++--
 drivers/iommu/mtk_iommu_v1.c                | 4 ++--
 drivers/iommu/omap-iommu.c                  | 4 ++--
 drivers/iommu/rockchip-iommu.c              | 4 ++--
 drivers/iommu/s390-iommu.c                  | 6 +++---
 drivers/iommu/sprd-iommu.c                  | 4 ++--
 drivers/iommu/sun50i-iommu.c                | 4 ++--
 drivers/iommu/tegra-gart.c                  | 4 ++--
 drivers/iommu/tegra-smmu.c                  | 4 ++--
 drivers/iommu/virtio-iommu.c                | 2 +-
 22 files changed, 43 insertions(+), 43 deletions(-)
include/linux/iommu.h +2 -2
index 1e9fecfb23a7..0d3131c7bf11 100644
@@ -273,7 +273,7 @@ struct iommu_ops {
 
 /**
  * struct iommu_domain_ops - domain specific operations
- * @attach_dev: attach an iommu domain to a device
+ * @set_dev: attach an iommu domain to a device
  * @set_dev_pasid: set an iommu domain to a pasid of device
  * @map: map a physically contiguous memory region to an iommu domain
  * @map_pages: map a physically contiguous set of pages of the same size to
@@ -293,7 +293,7 @@ struct iommu_ops {
  * @free: Release the domain after use.
  */
 struct iommu_domain_ops {
-	int (*attach_dev)(struct iommu_domain *domain, struct device *dev);
+	int (*set_dev)(struct iommu_domain *domain, struct device *dev);
 	int (*set_dev_pasid)(struct iommu_domain *domain, struct device *dev,
 			     ioasid_t pasid);
 
drivers/iommu/amd/iommu.c +2 -2
index 4cd0438b0a6e..620ad8d53773 100644
@@ -2078,7 +2078,7 @@ static int blocking_domain_attach_dev(struct iommu_domain *_domain,
 
 static struct iommu_domain blocking_domain = {
 	.ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= blocking_domain_attach_dev
+		.set_dev	= blocking_domain_attach_dev
 	}
 };
 
@@ -2418,7 +2418,7 @@ const struct iommu_ops amd_iommu_ops = {
 	.pgsize_bitmap	= AMD_IOMMU_PGSIZES,
 	.def_domain_type = amd_iommu_def_domain_type,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= amd_iommu_attach_device,
+		.set_dev	= amd_iommu_attach_device,
 		.map		= amd_iommu_map,
 		.unmap		= amd_iommu_unmap,
 		.iotlb_sync_map	= amd_iommu_iotlb_sync_map,
drivers/iommu/apple-dart.c +2 -2
index 5f46cbf04e07..01d7adb6b97a 100644
@@ -580,7 +580,7 @@ static int blocking_domain_attach_dev(struct iommu_domain *_domain,
 
 static struct iommu_domain blocking_domain = {
 	.ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= blocking_domain_attach_dev
+		.set_dev	= blocking_domain_attach_dev
 	}
 };
 
@@ -790,7 +790,7 @@ static const struct iommu_ops apple_dart_iommu_ops = {
 	.pgsize_bitmap = -1UL, /* Restricted during dart probe */
 	.owner = THIS_MODULE,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= apple_dart_attach_dev,
+		.set_dev	= apple_dart_attach_dev,
 		.map_pages	= apple_dart_map_pages,
 		.unmap_pages	= apple_dart_unmap_pages,
 		.flush_iotlb_all = apple_dart_flush_iotlb_all,
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +2 -2
index a3c5b1a1203b..04d625aef897 100644
@@ -2032,7 +2032,7 @@ static int blocking_domain_set_dev_pasid(struct iommu_domain *_domain,
 
 static struct iommu_domain blocking_domain = {
 	.ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= blocking_domain_attach_dev,
+		.set_dev	= blocking_domain_attach_dev,
 		.set_dev_pasid	= blocking_domain_set_dev_pasid
 	}
 };
@@ -2870,7 +2870,7 @@ static struct iommu_ops arm_smmu_ops = {
 	.pgsize_bitmap		= -1UL, /* Restricted during device attach */
 	.owner			= THIS_MODULE,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-		.attach_dev		= arm_smmu_attach_dev,
+		.set_dev		= arm_smmu_attach_dev,
 		.map_pages		= arm_smmu_map_pages,
 		.unmap_pages		= arm_smmu_unmap_pages,
 		.flush_iotlb_all	= arm_smmu_flush_iotlb_all,
drivers/iommu/arm/arm-smmu/arm-smmu.c +1 -1
index dfa82df00342..57e93727b5f5 100644
@@ -1588,7 +1588,7 @@ static struct iommu_ops arm_smmu_ops = {
 	.pgsize_bitmap		= -1UL, /* Restricted during device attach */
 	.owner			= THIS_MODULE,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-		.attach_dev		= arm_smmu_attach_dev,
+		.set_dev		= arm_smmu_attach_dev,
 		.map_pages		= arm_smmu_map_pages,
 		.unmap_pages		= arm_smmu_unmap_pages,
 		.flush_iotlb_all	= arm_smmu_flush_iotlb_all,
drivers/iommu/arm/arm-smmu/qcom_iommu.c +2 -2
index 59f8a4d3865c..a8d2bea55205 100644
@@ -334,7 +334,7 @@ static int blocking_domain_attach_dev(struct iommu_domain *_domain,
 
 static struct iommu_domain blocking_domain = {
 	.ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= blocking_domain_attach_dev
+		.set_dev	= blocking_domain_attach_dev
 	}
 };
 
@@ -607,7 +607,7 @@ static const struct iommu_ops qcom_iommu_ops = {
 	.of_xlate	= qcom_iommu_of_xlate,
 	.pgsize_bitmap	= SZ_4K | SZ_64K | SZ_1M | SZ_16M,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= qcom_iommu_attach_dev,
+		.set_dev	= qcom_iommu_attach_dev,
 		.map		= qcom_iommu_map,
 		.unmap		= qcom_iommu_unmap,
 		.flush_iotlb_all = qcom_iommu_flush_iotlb_all,
drivers/iommu/exynos-iommu.c +2 -2
index f2958ec1868c..d2f5182bc50b 100644
@@ -833,7 +833,7 @@ static int blocking_domain_attach_dev(struct iommu_domain *_domain,
 
 static struct iommu_domain blocking_domain = {
 	.ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= blocking_domain_attach_dev
+		.set_dev	= blocking_domain_attach_dev
 	}
 };
 
@@ -1427,7 +1427,7 @@ static const struct iommu_ops exynos_iommu_ops = {
 	.pgsize_bitmap = SECT_SIZE | LPAGE_SIZE | SPAGE_SIZE,
 	.of_xlate = exynos_iommu_of_xlate,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= exynos_iommu_attach_device,
+		.set_dev	= exynos_iommu_attach_device,
 		.map		= exynos_iommu_map,
 		.unmap		= exynos_iommu_unmap,
 		.iova_to_phys	= exynos_iommu_iova_to_phys,
drivers/iommu/fsl_pamu_domain.c +2 -2
index 66a7093c7852..740e45bce776 100644
@@ -206,7 +206,7 @@ static int blocking_domain_attach_dev(struct iommu_domain *_domain,
 
 static struct iommu_domain blocking_domain = {
 	.ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= blocking_domain_attach_dev
+		.set_dev	= blocking_domain_attach_dev
 	}
 };
 
@@ -474,7 +474,7 @@ static const struct iommu_ops fsl_pamu_ops = {
 	.probe_device	= fsl_pamu_probe_device,
 	.device_group   = fsl_pamu_device_group,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= fsl_pamu_attach_device,
+		.set_dev	= fsl_pamu_attach_device,
 		.iova_to_phys	= fsl_pamu_iova_to_phys,
 		.free		= fsl_pamu_domain_free,
 	}
drivers/iommu/intel/iommu.c +2 -2
index f5ae4f7f916d..28493abd736e 100644
@@ -4154,7 +4154,7 @@ static int blocking_domain_set_dev_pasid(struct iommu_domain *_domain,
 
 static struct iommu_domain blocking_domain = {
 	.ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= blocking_domain_attach_dev,
+		.set_dev	= blocking_domain_attach_dev,
 		.set_dev_pasid	= blocking_domain_set_dev_pasid,
 	}
 };
@@ -4793,7 +4793,7 @@ const struct iommu_ops intel_iommu_ops = {
 	.page_response		= intel_svm_page_response,
 #endif
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-		.attach_dev		= intel_iommu_attach_device,
+		.set_dev		= intel_iommu_attach_device,
 		.map_pages		= intel_iommu_map_pages,
 		.unmap_pages		= intel_iommu_unmap_pages,
 		.iotlb_sync_map		= intel_iommu_iotlb_sync_map,
drivers/iommu/iommu.c +2 -2
index ad34e4df1aad..8cb35ba60501 100644
@@ -2002,10 +2002,10 @@ static int __iommu_attach_device(struct iommu_domain *domain,
 {
 	int ret;
 
-	if (unlikely(domain->ops->attach_dev == NULL))
+	if (unlikely(!domain->ops->set_dev))
 		return -ENODEV;
 
-	ret = domain->ops->attach_dev(domain, dev);
+	ret = domain->ops->set_dev(domain, dev);
 	if (!ret)
 		trace_attach_device_to_domain(dev);
 	return ret;
drivers/iommu/ipmmu-vmsa.c +2 -2
index cfb94e77bbab..4ebd9a15ce07 100644
@@ -581,7 +581,7 @@ static int blocking_domain_attach_dev(struct iommu_domain *_domain,
 
 static struct iommu_domain blocking_domain = {
 	.ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= blocking_domain_attach_dev
+		.set_dev	= blocking_domain_attach_dev
 	}
 };
 
@@ -898,7 +898,7 @@ static const struct iommu_ops ipmmu_ops = {
 	.pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K,
 	.of_xlate = ipmmu_of_xlate,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= ipmmu_attach_device,
+		.set_dev	= ipmmu_attach_device,
 		.map		= ipmmu_map,
 		.unmap		= ipmmu_unmap,
 		.flush_iotlb_all = ipmmu_flush_iotlb_all,
drivers/iommu/msm_iommu.c +2 -2
index f57f2da2d652..a6288a325076 100644
@@ -317,7 +317,7 @@ static int blocking_domain_attach_dev(struct iommu_domain *_domain,
 
 static struct iommu_domain blocking_domain = {
 	.ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= blocking_domain_attach_dev
+		.set_dev	= blocking_domain_attach_dev
 	}
 };
 
@@ -699,7 +699,7 @@ static struct iommu_ops msm_iommu_ops = {
 	.pgsize_bitmap = MSM_IOMMU_PGSIZES,
 	.of_xlate = qcom_iommu_of_xlate,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= msm_iommu_attach_dev,
+		.set_dev	= msm_iommu_attach_dev,
 		.map		= msm_iommu_map,
 		.unmap		= msm_iommu_unmap,
 		/*
drivers/iommu/mtk_iommu.c +2 -2
index 63360272d504..7c02b4fe8314 100644
@@ -636,7 +636,7 @@ static int blocking_domain_attach_dev(struct iommu_domain *_domain,
 
 static struct iommu_domain blocking_domain = {
 	.ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= blocking_domain_attach_dev
+		.set_dev	= blocking_domain_attach_dev
 	}
 };
 
@@ -954,7 +954,7 @@ static const struct iommu_ops mtk_iommu_ops = {
 	.pgsize_bitmap	= SZ_4K | SZ_64K | SZ_1M | SZ_16M,
 	.owner		= THIS_MODULE,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= mtk_iommu_attach_device,
+		.set_dev	= mtk_iommu_attach_device,
 		.map		= mtk_iommu_map,
 		.unmap		= mtk_iommu_unmap,
 		.flush_iotlb_all = mtk_iommu_flush_iotlb_all,
drivers/iommu/mtk_iommu_v1.c +2 -2
index 269622023917..221b3af5fa94 100644
@@ -284,7 +284,7 @@ static int blocking_domain_attach_dev(struct iommu_domain *_domain,
 
 static struct iommu_domain blocking_domain = {
 	.ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= blocking_domain_attach_dev
+		.set_dev	= blocking_domain_attach_dev
 	}
 };
 
@@ -610,7 +610,7 @@ static const struct iommu_ops mtk_iommu_v1_ops = {
 	.pgsize_bitmap	= ~0UL << MT2701_IOMMU_PAGE_SHIFT,
 	.owner          = THIS_MODULE,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= mtk_iommu_v1_attach_device,
+		.set_dev	= mtk_iommu_v1_attach_device,
 		.map		= mtk_iommu_v1_map,
 		.unmap		= mtk_iommu_v1_unmap,
 		.iova_to_phys	= mtk_iommu_v1_iova_to_phys,
drivers/iommu/omap-iommu.c +2 -2
index ceb88fd96ac0..0bb75c0994c8 100644
@@ -1578,7 +1578,7 @@ static int blocking_domain_attach_dev(struct iommu_domain *_domain,
 
 static struct iommu_domain blocking_domain = {
 	.ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= blocking_domain_attach_dev
+		.set_dev	= blocking_domain_attach_dev
 	}
 };
 
@@ -1758,7 +1758,7 @@ static const struct iommu_ops omap_iommu_ops = {
 	.device_group	= omap_iommu_device_group,
 	.pgsize_bitmap	= OMAP_IOMMU_PGSIZES,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= omap_iommu_attach_dev,
+		.set_dev	= omap_iommu_attach_dev,
 		.map		= omap_iommu_map,
 		.unmap		= omap_iommu_unmap,
 		.iova_to_phys	= omap_iommu_iova_to_phys,
drivers/iommu/rockchip-iommu.c +2 -2
index 3a8239ddbb4f..3b0bbc80b4aa 100644
@@ -1071,7 +1071,7 @@ static int blocking_domain_attach_dev(struct iommu_domain *_domain,
 
 static struct iommu_domain blocking_domain = {
 	.ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= blocking_domain_attach_dev
+		.set_dev	= blocking_domain_attach_dev
 	}
 };
 
@@ -1212,7 +1212,7 @@ static const struct iommu_ops rk_iommu_ops = {
 	.pgsize_bitmap = RK_IOMMU_PGSIZE_BITMAP,
 	.of_xlate = rk_iommu_of_xlate,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= rk_iommu_attach_device,
+		.set_dev	= rk_iommu_attach_device,
 		.map		= rk_iommu_map,
 		.unmap		= rk_iommu_unmap,
 		.iova_to_phys	= rk_iommu_iova_to_phys,
drivers/iommu/s390-iommu.c +3 -3
index b18c8302a23d..3b91c0570cbd 100644
@@ -66,7 +66,7 @@ static int blocking_domain_attach_dev(struct iommu_domain *_domain,
 
 static struct iommu_domain blocking_domain = {
 	.ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= blocking_domain_attach_dev
+		.set_dev	= blocking_domain_attach_dev
 	}
 };
 
@@ -221,7 +221,7 @@ static void s390_iommu_release_device(struct device *dev)
 	 * This is a workaround for a scenario where the IOMMU API common code
 	 * "forgets" to call the detach_dev callback: After binding a device
 	 * to vfio-pci and completing the VFIO_SET_IOMMU ioctl (which triggers
-	 * the attach_dev), removing the device via
+	 * the set_dev), removing the device via
 	 * "echo 1 > /sys/bus/pci/devices/.../remove" won't trigger detach_dev,
 	 * only release_device will be called via the BUS_NOTIFY_REMOVED_DEVICE
 	 * notifier.
@@ -399,7 +399,7 @@ static const struct iommu_ops s390_iommu_ops = {
 	.device_group = generic_device_group,
 	.pgsize_bitmap = S390_IOMMU_PGSIZES,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= s390_iommu_attach_device,
+		.set_dev	= s390_iommu_attach_device,
 		.map		= s390_iommu_map,
 		.unmap		= s390_iommu_unmap,
 		.iova_to_phys	= s390_iommu_iova_to_phys,
drivers/iommu/sprd-iommu.c +2 -2
index 46c567c489d7..7629e107c266 100644
@@ -147,7 +147,7 @@ static int blocking_domain_attach_dev(struct iommu_domain *_domain,
 
 static struct iommu_domain blocking_domain = {
 	.ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= blocking_domain_attach_dev
+		.set_dev	= blocking_domain_attach_dev
 	}
 };
 
@@ -434,7 +434,7 @@ static const struct iommu_ops sprd_iommu_ops = {
 	.pgsize_bitmap	= ~0UL << SPRD_IOMMU_PAGE_SHIFT,
 	.owner		= THIS_MODULE,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= sprd_iommu_attach_device,
+		.set_dev	= sprd_iommu_attach_device,
 		.map		= sprd_iommu_map,
 		.unmap		= sprd_iommu_unmap,
 		.iotlb_sync_map	= sprd_iommu_sync_map,
drivers/iommu/sun50i-iommu.c +2 -2
index 1e63e782d23e..289184549238 100644
@@ -611,7 +611,7 @@ static int blocking_domain_attach_dev(struct iommu_domain *_domain,
 
 static struct iommu_domain blocking_domain = {
 	.ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= blocking_domain_attach_dev
+		.set_dev	= blocking_domain_attach_dev
 	}
 };
 
@@ -785,7 +785,7 @@ static const struct iommu_ops sun50i_iommu_ops = {
 	.of_xlate	= sun50i_iommu_of_xlate,
 	.probe_device	= sun50i_iommu_probe_device,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= sun50i_iommu_attach_device,
+		.set_dev	= sun50i_iommu_attach_device,
 		.flush_iotlb_all = sun50i_iommu_flush_iotlb_all,
 		.iotlb_sync	= sun50i_iommu_iotlb_sync,
 		.iova_to_phys	= sun50i_iommu_iova_to_phys,
drivers/iommu/tegra-gart.c +2 -2
index 5d5669f60d23..c5f3d6feed24 100644
@@ -153,7 +153,7 @@ static int blocking_domain_attach_dev(struct iommu_domain *_domain,
 
 static struct iommu_domain blocking_domain = {
 	.ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= blocking_domain_attach_dev
+		.set_dev	= blocking_domain_attach_dev
 	}
 };
 
@@ -292,7 +292,7 @@ static const struct iommu_ops gart_iommu_ops = {
 	.pgsize_bitmap	= GART_IOMMU_PGSIZES,
 	.of_xlate	= gart_iommu_of_xlate,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= gart_iommu_attach_dev,
+		.set_dev	= gart_iommu_attach_dev,
 		.map		= gart_iommu_map,
 		.unmap		= gart_iommu_unmap,
 		.iova_to_phys	= gart_iommu_iova_to_phys,
drivers/iommu/tegra-smmu.c +2 -2
index 54fddb5215a5..9b3e44e36b10 100644
@@ -287,7 +287,7 @@ static int blocking_domain_attach_dev(struct iommu_domain *_domain,
 
 static struct iommu_domain blocking_domain = {
 	.ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= blocking_domain_attach_dev
+		.set_dev	= blocking_domain_attach_dev
 	}
 };
 
@@ -990,7 +990,7 @@ static const struct iommu_ops tegra_smmu_ops = {
 	.of_xlate = tegra_smmu_of_xlate,
 	.pgsize_bitmap = SZ_4K,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= tegra_smmu_attach_dev,
+		.set_dev	= tegra_smmu_attach_dev,
 		.map		= tegra_smmu_map,
 		.unmap		= tegra_smmu_unmap,
 		.iova_to_phys	= tegra_smmu_iova_to_phys,
drivers/iommu/virtio-iommu.c +1 -1
index 08eeafc9529f..24de723f9158 100644
@@ -1016,7 +1016,7 @@ static struct iommu_ops viommu_ops = {
 	.of_xlate		= viommu_of_xlate,
 	.owner			= THIS_MODULE,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-		.attach_dev		= viommu_attach_dev,
+		.set_dev		= viommu_attach_dev,
 		.map_pages		= viommu_map_pages,
 		.unmap_pages		= viommu_unmap_pages,
 		.iova_to_phys		= viommu_iova_to_phys,
Signature · 1 line
2.25.1