linux-mediatek.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/25] iommu: Make default_domain's mandatory
@ 2023-05-16  0:00 ` Jason Gunthorpe
  2023-05-16  0:00   ` [PATCH v2 01/25] iommu: Add iommu_ops->identity_domain Jason Gunthorpe
                     ` (27 more replies)
  0 siblings, 28 replies; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

[ There was alot of unexpected complication after rc1 with this series,
several new patches were needed ]

It has been a long time coming, this series completes the default_domain
transition and makes it so that the core IOMMU code will always have a
non-NULL default_domain for every driver on every
platform. set_platform_dma_ops() turned out to be a bad idea, and so
completely remove it.

This is achieved by changing each driver to either:

1 - Convert the existing (or deleted) ops->detach_dev() into an
    op->attach_dev() of an IDENTITY domain.

    This is based on the theory that the ARM32 HW is able to function when
    the iommu is turned off as so the turned off state is an IDENTITY
    translation.

2 - Use a new PLATFORM domain type. This is a hack to accommodate drivers
    that we don't really know WTF they do. S390 is legitimately using this
    to switch to it's platform dma_ops implementation, which is where the
    name comes from.

3 - Do #1 and force the default domain to be IDENTITY, this corrects
    the tegra-smmu case where even an ARM64 system would have a NULL
    default_domain.

Using this we can apply the rules:

a) ARM_DMA_USE_IOMMU mode always uses either the driver's
   ops->default_domain, ops->def_domain_type(), or an IDENTITY domain.
   All ARM32 drivers provide one of these three options.

b) dma-iommu.c mode uses either the driver's ops->default_domain,
   ops->def_domain_type or the usual DMA API policy logic based on the
   command line/etc to pick IDENTITY/DMA domain types

c) All other arch's (PPC/S390) use ops->default_domain always.

See the patch "Require a default_domain for all iommu drivers" for a
per-driver breakdown.

The conversion broadly teaches a bunch of ARM32 drivers that they can do
IDENTITY domains. There is some educated guessing involved that these are
actual IDENTITY domains. If this turns out to be wrong the driver can be
trivially changed to use a BLOCKING domain type instead. Further, the
domain type only matters for drivers using ARM64's dma-iommu.c mode as it
will select IDENTITY based on the command line and expect IDENTITY to
work. For ARM32 and other arch cases it is purely documentation.

Finally, based on all the analysis in this series, we can purge
IOMMU_DOMAIN_UNMANAGED/DMA constants from most of the drivers. This
greatly simplifies understanding the driver contract to the core
code. IOMMU drivers should not be involved in policy for how the DMA API
works, that should be a core core decision.

The main gain from this work is to remove alot of ARM_DMA_USE_IOMMU
specific code and behaviors from drivers. All that remains in iommu
drivers after this series is the calls to arm_iommu_create_mapping().

This is a step toward removing ARM_DMA_USE_IOMMU.

The IDENTITY domains added to the ARM64 supporting drivers can be tested
by booting in ARM64 mode and enabling CONFIG_IOMMU_DEFAULT_PASSTHROUGH. If
the system still boots then most likely the implementation is an IDENTITY
domain. If not we can trivially change it to BLOCKING or at worst PLATFORM
if there is no detail what is going on in the HW.

I think this is pretty safe for the ARM32 drivers as they don't really
change, the code that was in detach_dev continues to be called in the same
places it was called before.

This follows the prior series:

https://lore.kernel.org/r/0-v5-1b99ae392328+44574-iommu_err_unwind_jgg@nvidia.com

This is on github: https://github.com/jgunthorpe/linux/commits/iommu_all_defdom

v2:
 - FSL is an IDENTITY domain
 - Delete terga-gart instead of trying to carry it
 - Use the policy determination from iommu_get_default_domain_type() to
   drive the arm_iommu mode
 - Reorganize and introduce new patches to do the above:
    * Split the ops->identity_domain to an independent earlier patch
    * Remove the UNMANAGED return from def_domain_type in mtk_v1 earlier
      so the new iommu_get_default_domain_type() can work
    * Make the driver's def_domain_type have higher policy priority than
      untrusted
    * Merge the set_platfom_dma_ops hunk from mtk_v1 along with rockchip
      into the patch that forced IDENTITY on ARM32
 - Revise sun50i to be cleaner and have a non-NULL internal domain
 - Reword logging in exynos
 - Remove the gdev from the group alloc path, instead add a new
   function __iommu_group_domain_alloc() that takes in the group
   and uses the first device. Split this to its own patch
 - New patch to make iommufd's mock selftest into a real driver
 - New patch to fix power's partial iommu driver
v1: https://lore.kernel.org/r/0-v1-21cc72fcfb22+a7a-iommu_all_defdom_jgg@nvidia.com

Jason Gunthorpe (25):
  iommu: Add iommu_ops->identity_domain
  iommu: Add IOMMU_DOMAIN_PLATFORM
  powerpc/iommu: Setup a default domain and remove set_platform_dma_ops
  iommu: Add IOMMU_DOMAIN_PLATFORM for S390
  iommu/tegra-gart: Remove tegra-gart
  iommu/mtk_iommu_v1: Implement an IDENTITY domain
  iommu: Reorganize iommu_get_default_domain_type() to respect
    def_domain_type()
  iommu: Allow an IDENTITY domain as the default_domain in ARM32
  iommu/fsl_pamu: Implement an IDENTITY domain
  iommu/exynos: Implement an IDENTITY domain
  iommu/tegra-smmu: Implement an IDENTITY domain
  iommu/tegra-smmu: Support DMA domains in tegra
  iommu/omap: Implement an IDENTITY domain
  iommu/msm: Implement an IDENTITY domain
  iommufd/selftest: Make the mock iommu driver into a real driver
  iommu: Remove ops->set_platform_dma_ops()
  iommu/qcom_iommu: Add an IOMMU_IDENTITIY_DOMAIN
  iommu/ipmmu: Add an IOMMU_IDENTITIY_DOMAIN
  iommu/mtk_iommu: Add an IOMMU_IDENTITIY_DOMAIN
  iommu/sun50i: Add an IOMMU_IDENTITIY_DOMAIN
  iommu: Require a default_domain for all iommu drivers
  iommu: Add __iommu_group_domain_alloc()
  iommu: Add ops->domain_alloc_paging()
  iommu: Convert simple drivers with DOMAIN_DMA to domain_alloc_paging()
  iommu: Convert remaining simple drivers to domain_alloc_paging()

 arch/arm/configs/multi_v7_defconfig     |   1 -
 arch/arm/configs/tegra_defconfig        |   1 -
 arch/powerpc/kernel/iommu.c             |  38 ++-
 drivers/iommu/Kconfig                   |  11 -
 drivers/iommu/Makefile                  |   1 -
 drivers/iommu/arm/arm-smmu/qcom_iommu.c |  45 ++-
 drivers/iommu/exynos-iommu.c            |  73 +++--
 drivers/iommu/fsl_pamu_domain.c         |  39 ++-
 drivers/iommu/iommu-priv.h              |  16 +
 drivers/iommu/iommu.c                   | 263 +++++++++++------
 drivers/iommu/iommufd/iommufd_private.h |   5 +-
 drivers/iommu/iommufd/main.c            |   8 +-
 drivers/iommu/iommufd/selftest.c        | 141 ++++-----
 drivers/iommu/ipmmu-vmsa.c              |  50 +++-
 drivers/iommu/msm_iommu.c               |  30 +-
 drivers/iommu/mtk_iommu.c               |  30 +-
 drivers/iommu/mtk_iommu_v1.c            |  28 +-
 drivers/iommu/omap-iommu.c              |  28 +-
 drivers/iommu/rockchip-iommu.c          |  26 +-
 drivers/iommu/s390-iommu.c              |  28 +-
 drivers/iommu/sprd-iommu.c              |   7 +-
 drivers/iommu/sun50i-iommu.c            |  35 ++-
 drivers/iommu/tegra-gart.c              | 371 ------------------------
 drivers/iommu/tegra-smmu.c              |  50 +++-
 drivers/memory/tegra/mc.c               |  34 ---
 drivers/memory/tegra/tegra20.c          |  28 --
 include/linux/iommu.h                   |  16 +-
 include/soc/tegra/mc.h                  |  26 --
 28 files changed, 622 insertions(+), 807 deletions(-)
 create mode 100644 drivers/iommu/iommu-priv.h
 delete mode 100644 drivers/iommu/tegra-gart.c


base-commit: 0b355ade2baf262f213da274411c0e05d8232a21
-- 
2.40.1



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

* [PATCH v2 01/25] iommu: Add iommu_ops->identity_domain
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-05-16  0:00   ` [PATCH v2 02/25] iommu: Add IOMMU_DOMAIN_PLATFORM Jason Gunthorpe
                     ` (26 subsequent siblings)
  27 siblings, 0 replies; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

This allows a driver to set a global static to an IDENTITY domain and
the core code will automatically use it whenever an IDENTITY domain
is requested.

By making it always available it means the IDENTITY can be used in error
handling paths to force the iommu driver into a known state. Devices
implementing global static identity domains should avoid failing their
attach_dev ops.

Convert rockchip to use the new mechanism.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/iommu.c          | 3 +++
 drivers/iommu/rockchip-iommu.c | 9 +--------
 include/linux/iommu.h          | 3 +++
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 4d7010f2b260a7..e02bc94a6c80cc 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1916,6 +1916,9 @@ static struct iommu_domain *__iommu_domain_alloc(const struct bus_type *bus,
 	if (bus == NULL || bus->iommu_ops == NULL)
 		return NULL;
 
+	if (type == IOMMU_DOMAIN_IDENTITY && bus->iommu_ops->identity_domain)
+		return bus->iommu_ops->identity_domain;
+
 	domain = bus->iommu_ops->domain_alloc(type);
 	if (!domain)
 		return NULL;
diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index ea5a3088bb7e8a..ebce56d6e9c634 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -1017,13 +1017,8 @@ static int rk_iommu_identity_attach(struct iommu_domain *identity_domain,
 	return 0;
 }
 
-static void rk_iommu_identity_free(struct iommu_domain *domain)
-{
-}
-
 static struct iommu_domain_ops rk_identity_ops = {
 	.attach_dev = rk_iommu_identity_attach,
-	.free = rk_iommu_identity_free,
 };
 
 static struct iommu_domain rk_identity_domain = {
@@ -1087,9 +1082,6 @@ static struct iommu_domain *rk_iommu_domain_alloc(unsigned type)
 {
 	struct rk_iommu_domain *rk_domain;
 
-	if (type == IOMMU_DOMAIN_IDENTITY)
-		return &rk_identity_domain;
-
 	if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA)
 		return NULL;
 
@@ -1214,6 +1206,7 @@ static int rk_iommu_of_xlate(struct device *dev,
 }
 
 static const struct iommu_ops rk_iommu_ops = {
+	.identity_domain = &rk_identity_domain,
 	.domain_alloc = rk_iommu_domain_alloc,
 	.probe_device = rk_iommu_probe_device,
 	.release_device = rk_iommu_release_device,
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index e8c9a7da106096..2823b0b23e6cb5 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -248,6 +248,8 @@ struct iommu_iotlb_gather {
  *                    will be blocked by the hardware.
  * @pgsize_bitmap: bitmap of all possible supported page sizes
  * @owner: Driver module providing these ops
+ * @identity_domain: An always available, always attachable identity
+ *                   translation.
  */
 struct iommu_ops {
 	bool (*capable)(struct device *dev, enum iommu_cap);
@@ -281,6 +283,7 @@ struct iommu_ops {
 	const struct iommu_domain_ops *default_domain_ops;
 	unsigned long pgsize_bitmap;
 	struct module *owner;
+	struct iommu_domain *identity_domain;
 };
 
 /**
-- 
2.40.1



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

* [PATCH v2 02/25] iommu: Add IOMMU_DOMAIN_PLATFORM
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
  2023-05-16  0:00   ` [PATCH v2 01/25] iommu: Add iommu_ops->identity_domain Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-05-16  0:00   ` [PATCH v2 03/25] powerpc/iommu: Setup a default domain and remove set_platform_dma_ops Jason Gunthorpe
                     ` (25 subsequent siblings)
  27 siblings, 0 replies; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

This is used when the iommu driver is taking control of the dma_ops,
currently only on S390 and power spapr. It is designed to preserve the
original ops->detach_dev() semantic that these S390 was built around.

Provide an opaque domain type and a 'default_domain' ops value that allows
the driver to trivially force any single domain as the default domain.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/iommu.c | 14 +++++++++++++-
 include/linux/iommu.h |  6 ++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index e02bc94a6c80cc..3a72859747bae0 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1644,6 +1644,17 @@ iommu_group_alloc_default_domain(struct iommu_group *group, int req_type)
 
 	lockdep_assert_held(&group->mutex);
 
+	/*
+	 * Allow legacy drivers to specify the domain that will be the default
+	 * domain. This should always be either an IDENTITY or PLATFORM domain.
+	 * Do not use in new drivers.
+	 */
+	if (bus->iommu_ops->default_domain) {
+		if (req_type)
+			return ERR_PTR(-EINVAL);
+		return bus->iommu_ops->default_domain;
+	}
+
 	if (req_type)
 		return __iommu_group_alloc_default_domain(bus, group, req_type);
 
@@ -1952,7 +1963,8 @@ void iommu_domain_free(struct iommu_domain *domain)
 	if (domain->type == IOMMU_DOMAIN_SVA)
 		mmdrop(domain->mm);
 	iommu_put_dma_cookie(domain);
-	domain->ops->free(domain);
+	if (domain->ops->free)
+		domain->ops->free(domain);
 }
 EXPORT_SYMBOL_GPL(iommu_domain_free);
 
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 2823b0b23e6cb5..ddd284f8e5b768 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -64,6 +64,7 @@ struct iommu_domain_geometry {
 #define __IOMMU_DOMAIN_DMA_FQ	(1U << 3)  /* DMA-API uses flush queue    */
 
 #define __IOMMU_DOMAIN_SVA	(1U << 4)  /* Shared process address space */
+#define __IOMMU_DOMAIN_PLATFORM	(1U << 5)
 
 /*
  * This are the possible domain-types
@@ -80,6 +81,8 @@ struct iommu_domain_geometry {
  *				  invalidation.
  *	IOMMU_DOMAIN_SVA	- DMA addresses are shared process addresses
  *				  represented by mm_struct's.
+ *	IOMMU_DOMAIN_PLATFORM	- Legacy domain for drivers that do their own
+ *				  dma_api stuff. Do not use in new drivers.
  */
 #define IOMMU_DOMAIN_BLOCKED	(0U)
 #define IOMMU_DOMAIN_IDENTITY	(__IOMMU_DOMAIN_PT)
@@ -90,6 +93,7 @@ struct iommu_domain_geometry {
 				 __IOMMU_DOMAIN_DMA_API |	\
 				 __IOMMU_DOMAIN_DMA_FQ)
 #define IOMMU_DOMAIN_SVA	(__IOMMU_DOMAIN_SVA)
+#define IOMMU_DOMAIN_PLATFORM	(__IOMMU_DOMAIN_PLATFORM)
 
 struct iommu_domain {
 	unsigned type;
@@ -250,6 +254,7 @@ struct iommu_iotlb_gather {
  * @owner: Driver module providing these ops
  * @identity_domain: An always available, always attachable identity
  *                   translation.
+ * @default_domain: If not NULL this will always be set as the default domain.
  */
 struct iommu_ops {
 	bool (*capable)(struct device *dev, enum iommu_cap);
@@ -284,6 +289,7 @@ struct iommu_ops {
 	unsigned long pgsize_bitmap;
 	struct module *owner;
 	struct iommu_domain *identity_domain;
+	struct iommu_domain *default_domain;
 };
 
 /**
-- 
2.40.1



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

* [PATCH v2 03/25] powerpc/iommu: Setup a default domain and remove set_platform_dma_ops
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
  2023-05-16  0:00   ` [PATCH v2 01/25] iommu: Add iommu_ops->identity_domain Jason Gunthorpe
  2023-05-16  0:00   ` [PATCH v2 02/25] iommu: Add IOMMU_DOMAIN_PLATFORM Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-05-16  0:00   ` [PATCH v2 04/25] iommu: Add IOMMU_DOMAIN_PLATFORM for S390 Jason Gunthorpe
                     ` (24 subsequent siblings)
  27 siblings, 0 replies; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

POWER is using the set_platform_dma_ops() callback to hook up its private
dma_ops, but this is buired under some indirection and is weirdly
happening for a BLOCKED domain as well.

For better documentation create a PLATFORM domain to manage the dma_ops,
since that is what it is for, and make the BLOCKED domain an alias for
it. BLOCKED is required for VFIO.

Also removes the leaky allocation of the BLOCKED domain by using a global
static.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 arch/powerpc/kernel/iommu.c | 38 +++++++++++++++++--------------------
 1 file changed, 17 insertions(+), 21 deletions(-)

diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c
index 0089dd49b4cbf7..db32355ba9aebc 100644
--- a/arch/powerpc/kernel/iommu.c
+++ b/arch/powerpc/kernel/iommu.c
@@ -1280,7 +1280,7 @@ struct iommu_table_group_ops spapr_tce_table_group_ops = {
 /*
  * A simple iommu_ops to allow less cruft in generic VFIO code.
  */
-static int spapr_tce_blocking_iommu_attach_dev(struct iommu_domain *dom,
+static int spapr_tce_platform_iommu_attach_dev(struct iommu_domain *dom,
 					       struct device *dev)
 {
 	struct iommu_group *grp = iommu_group_get(dev);
@@ -1297,17 +1297,22 @@ static int spapr_tce_blocking_iommu_attach_dev(struct iommu_domain *dom,
 	return ret;
 }
 
-static void spapr_tce_blocking_iommu_set_platform_dma(struct device *dev)
-{
-	struct iommu_group *grp = iommu_group_get(dev);
-	struct iommu_table_group *table_group;
+static const struct iommu_domain_ops spapr_tce_platform_domain_ops = {
+	.attach_dev = spapr_tce_platform_iommu_attach_dev,
+};
 
-	table_group = iommu_group_get_iommudata(grp);
-	table_group->ops->release_ownership(table_group);
-}
+static struct iommu_domain spapr_tce_platform_domain = {
+	.type = IOMMU_DOMAIN_PLATFORM,
+	.ops = &spapr_tce_platform_domain_ops,
+};
 
-static const struct iommu_domain_ops spapr_tce_blocking_domain_ops = {
-	.attach_dev = spapr_tce_blocking_iommu_attach_dev,
+static struct iommu_domain spapr_tce_blocked_domain = {
+	.type = IOMMU_DOMAIN_BLOCKED,
+	/*
+	 * FIXME: SPAPR mixes blocked and platform behaviors, the blocked domain
+	 * also sets the dma_api ops
+	 */
+	.ops = &spapr_tce_platform_domain_ops,
 };
 
 static bool spapr_tce_iommu_capable(struct device *dev, enum iommu_cap cap)
@@ -1324,18 +1329,9 @@ static bool spapr_tce_iommu_capable(struct device *dev, enum iommu_cap cap)
 
 static struct iommu_domain *spapr_tce_iommu_domain_alloc(unsigned int type)
 {
-	struct iommu_domain *dom;
-
 	if (type != IOMMU_DOMAIN_BLOCKED)
 		return NULL;
-
-	dom = kzalloc(sizeof(*dom), GFP_KERNEL);
-	if (!dom)
-		return NULL;
-
-	dom->ops = &spapr_tce_blocking_domain_ops;
-
-	return dom;
+	return &spapr_tce_blocked_domain;
 }
 
 static struct iommu_device *spapr_tce_iommu_probe_device(struct device *dev)
@@ -1371,12 +1367,12 @@ static struct iommu_group *spapr_tce_iommu_device_group(struct device *dev)
 }
 
 static const struct iommu_ops spapr_tce_iommu_ops = {
+	.default_domain = &spapr_tce_platform_domain,
 	.capable = spapr_tce_iommu_capable,
 	.domain_alloc = spapr_tce_iommu_domain_alloc,
 	.probe_device = spapr_tce_iommu_probe_device,
 	.release_device = spapr_tce_iommu_release_device,
 	.device_group = spapr_tce_iommu_device_group,
-	.set_platform_dma_ops = spapr_tce_blocking_iommu_set_platform_dma,
 };
 
 static struct attribute *spapr_tce_iommu_attrs[] = {
-- 
2.40.1



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

* [PATCH v2 04/25] iommu: Add IOMMU_DOMAIN_PLATFORM for S390
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (2 preceding siblings ...)
  2023-05-16  0:00   ` [PATCH v2 03/25] powerpc/iommu: Setup a default domain and remove set_platform_dma_ops Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-06-01 18:25     ` Robin Murphy
  2023-05-16  0:00   ` [PATCH v2 05/25] iommu/tegra-gart: Remove tegra-gart Jason Gunthorpe
                     ` (23 subsequent siblings)
  27 siblings, 1 reply; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

The PLATFORM domain will be set as the default domain and attached as
normal during probe. The driver will ignore the initial attach from a NULL
domain to the PLATFORM domain.

After this, the PLATFORM domain's attach_dev will be called whenever we
detach from an UNMANAGED domain (eg for VFIO). This is the same time the
original design would have called op->detach_dev().

This is temporary until the S390 dma-iommu.c conversion is merged.

Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/s390-iommu.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c
index fbf59a8db29b11..f0c867c57a5b9b 100644
--- a/drivers/iommu/s390-iommu.c
+++ b/drivers/iommu/s390-iommu.c
@@ -142,14 +142,31 @@ static int s390_iommu_attach_device(struct iommu_domain *domain,
 	return 0;
 }
 
-static void s390_iommu_set_platform_dma(struct device *dev)
+/*
+ * Switch control over the IOMMU to S390's internal dma_api ops
+ */
+static int s390_iommu_platform_attach(struct iommu_domain *platform_domain,
+				      struct device *dev)
 {
 	struct zpci_dev *zdev = to_zpci_dev(dev);
 
+	if (!zdev->s390_domain)
+		return 0;
+
 	__s390_iommu_detach_device(zdev);
 	zpci_dma_init_device(zdev);
+	return 0;
 }
 
+static struct iommu_domain_ops s390_iommu_platform_ops = {
+	.attach_dev = s390_iommu_platform_attach,
+};
+
+static struct iommu_domain s390_iommu_platform_domain = {
+	.type = IOMMU_DOMAIN_PLATFORM,
+	.ops = &s390_iommu_platform_ops,
+};
+
 static void s390_iommu_get_resv_regions(struct device *dev,
 					struct list_head *list)
 {
@@ -428,12 +445,12 @@ void zpci_destroy_iommu(struct zpci_dev *zdev)
 }
 
 static const struct iommu_ops s390_iommu_ops = {
+	.default_domain = &s390_iommu_platform_domain,
 	.capable = s390_iommu_capable,
 	.domain_alloc = s390_domain_alloc,
 	.probe_device = s390_iommu_probe_device,
 	.release_device = s390_iommu_release_device,
 	.device_group = generic_device_group,
-	.set_platform_dma_ops = s390_iommu_set_platform_dma,
 	.pgsize_bitmap = SZ_4K,
 	.get_resv_regions = s390_iommu_get_resv_regions,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-- 
2.40.1



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

* [PATCH v2 05/25] iommu/tegra-gart: Remove tegra-gart
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (3 preceding siblings ...)
  2023-05-16  0:00   ` [PATCH v2 04/25] iommu: Add IOMMU_DOMAIN_PLATFORM for S390 Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-06-01 16:51     ` Thierry Reding
  2023-05-16  0:00   ` [PATCH v2 06/25] iommu/mtk_iommu_v1: Implement an IDENTITY domain Jason Gunthorpe
                     ` (22 subsequent siblings)
  27 siblings, 1 reply; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

Thierry says this is not used anymore, and doesn't think it ever will
be. The HW it supports is about 10 years old now and newer HW uses
different IOMMU drivers.

As this is the only driver with a GART approach, and it doesn't really
meet the driver expectations from the IOMMU core, let's just remove it
so we don't have to think about how to make it fit in.

It has a number of identified problems:
 - The assignment of iommu_groups doesn't match the HW behavior

 - It claims to have an UNMANAGED domain but it is really an IDENTITY
   domain with a translation aperture. This is inconsistent with the core
   expectation for security sensitive operations

 - It doesn't implement a SW page table under struct iommu_domain so
   * It can't accept a map until the domain is attached
   * It forgets about all maps after the domain is detached
   * It doesn't clear the HW of maps once the domain is detached
     (made worse by having the wrong groups)

Cc: Thierry Reding <treding@nvidia.com>
Cc: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 arch/arm/configs/multi_v7_defconfig |   1 -
 arch/arm/configs/tegra_defconfig    |   1 -
 drivers/iommu/Kconfig               |  11 -
 drivers/iommu/Makefile              |   1 -
 drivers/iommu/tegra-gart.c          | 371 ----------------------------
 drivers/memory/tegra/mc.c           |  34 ---
 drivers/memory/tegra/tegra20.c      |  28 ---
 include/soc/tegra/mc.h              |  26 --
 8 files changed, 473 deletions(-)
 delete mode 100644 drivers/iommu/tegra-gart.c

diff --git a/arch/arm/configs/multi_v7_defconfig b/arch/arm/configs/multi_v7_defconfig
index 871fffe92187bf..daba1afdbd1100 100644
--- a/arch/arm/configs/multi_v7_defconfig
+++ b/arch/arm/configs/multi_v7_defconfig
@@ -1063,7 +1063,6 @@ CONFIG_BCM2835_MBOX=y
 CONFIG_QCOM_APCS_IPC=y
 CONFIG_QCOM_IPCC=y
 CONFIG_ROCKCHIP_IOMMU=y
-CONFIG_TEGRA_IOMMU_GART=y
 CONFIG_TEGRA_IOMMU_SMMU=y
 CONFIG_EXYNOS_IOMMU=y
 CONFIG_QCOM_IOMMU=y
diff --git a/arch/arm/configs/tegra_defconfig b/arch/arm/configs/tegra_defconfig
index f32047e24b633e..ad31b9322911ce 100644
--- a/arch/arm/configs/tegra_defconfig
+++ b/arch/arm/configs/tegra_defconfig
@@ -293,7 +293,6 @@ CONFIG_CHROME_PLATFORMS=y
 CONFIG_CROS_EC=y
 CONFIG_CROS_EC_I2C=m
 CONFIG_CROS_EC_SPI=m
-CONFIG_TEGRA_IOMMU_GART=y
 CONFIG_TEGRA_IOMMU_SMMU=y
 CONFIG_ARCH_TEGRA_2x_SOC=y
 CONFIG_ARCH_TEGRA_3x_SOC=y
diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index db98c3f86e8c8b..79e5b69c6b7647 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -235,17 +235,6 @@ config SUN50I_IOMMU
 	help
 	  Support for the IOMMU introduced in the Allwinner H6 SoCs.
 
-config TEGRA_IOMMU_GART
-	bool "Tegra GART IOMMU Support"
-	depends on ARCH_TEGRA_2x_SOC
-	depends on TEGRA_MC
-	select IOMMU_API
-	help
-	  Enables support for remapping discontiguous physical memory
-	  shared with the operating system into contiguous I/O virtual
-	  space through the GART (Graphics Address Relocation Table)
-	  hardware included on Tegra SoCs.
-
 config TEGRA_IOMMU_SMMU
 	bool "NVIDIA Tegra SMMU Support"
 	depends on ARCH_TEGRA
diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile
index 769e43d780ce89..95ad9dbfbda022 100644
--- a/drivers/iommu/Makefile
+++ b/drivers/iommu/Makefile
@@ -20,7 +20,6 @@ obj-$(CONFIG_OMAP_IOMMU) += omap-iommu.o
 obj-$(CONFIG_OMAP_IOMMU_DEBUG) += omap-iommu-debug.o
 obj-$(CONFIG_ROCKCHIP_IOMMU) += rockchip-iommu.o
 obj-$(CONFIG_SUN50I_IOMMU) += sun50i-iommu.o
-obj-$(CONFIG_TEGRA_IOMMU_GART) += tegra-gart.o
 obj-$(CONFIG_TEGRA_IOMMU_SMMU) += tegra-smmu.o
 obj-$(CONFIG_EXYNOS_IOMMU) += exynos-iommu.o
 obj-$(CONFIG_FSL_PAMU) += fsl_pamu.o fsl_pamu_domain.o
diff --git a/drivers/iommu/tegra-gart.c b/drivers/iommu/tegra-gart.c
deleted file mode 100644
index a482ff838b5331..00000000000000
--- a/drivers/iommu/tegra-gart.c
+++ /dev/null
@@ -1,371 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- * IOMMU API for Graphics Address Relocation Table on Tegra20
- *
- * Copyright (c) 2010-2012, NVIDIA CORPORATION.  All rights reserved.
- *
- * Author: Hiroshi DOYU <hdoyu@nvidia.com>
- */
-
-#define dev_fmt(fmt)	"gart: " fmt
-
-#include <linux/io.h>
-#include <linux/iommu.h>
-#include <linux/moduleparam.h>
-#include <linux/platform_device.h>
-#include <linux/slab.h>
-#include <linux/spinlock.h>
-#include <linux/vmalloc.h>
-
-#include <soc/tegra/mc.h>
-
-#define GART_REG_BASE		0x24
-#define GART_CONFIG		(0x24 - GART_REG_BASE)
-#define GART_ENTRY_ADDR		(0x28 - GART_REG_BASE)
-#define GART_ENTRY_DATA		(0x2c - GART_REG_BASE)
-
-#define GART_ENTRY_PHYS_ADDR_VALID	BIT(31)
-
-#define GART_PAGE_SHIFT		12
-#define GART_PAGE_SIZE		(1 << GART_PAGE_SHIFT)
-#define GART_PAGE_MASK		GENMASK(30, GART_PAGE_SHIFT)
-
-/* bitmap of the page sizes currently supported */
-#define GART_IOMMU_PGSIZES	(GART_PAGE_SIZE)
-
-struct gart_device {
-	void __iomem		*regs;
-	u32			*savedata;
-	unsigned long		iovmm_base;	/* offset to vmm_area start */
-	unsigned long		iovmm_end;	/* offset to vmm_area end */
-	spinlock_t		pte_lock;	/* for pagetable */
-	spinlock_t		dom_lock;	/* for active domain */
-	unsigned int		active_devices;	/* number of active devices */
-	struct iommu_domain	*active_domain;	/* current active domain */
-	struct iommu_device	iommu;		/* IOMMU Core handle */
-	struct device		*dev;
-};
-
-static struct gart_device *gart_handle; /* unique for a system */
-
-static bool gart_debug;
-
-/*
- * Any interaction between any block on PPSB and a block on APB or AHB
- * must have these read-back to ensure the APB/AHB bus transaction is
- * complete before initiating activity on the PPSB block.
- */
-#define FLUSH_GART_REGS(gart)	readl_relaxed((gart)->regs + GART_CONFIG)
-
-#define for_each_gart_pte(gart, iova)					\
-	for (iova = gart->iovmm_base;					\
-	     iova < gart->iovmm_end;					\
-	     iova += GART_PAGE_SIZE)
-
-static inline void gart_set_pte(struct gart_device *gart,
-				unsigned long iova, unsigned long pte)
-{
-	writel_relaxed(iova, gart->regs + GART_ENTRY_ADDR);
-	writel_relaxed(pte, gart->regs + GART_ENTRY_DATA);
-}
-
-static inline unsigned long gart_read_pte(struct gart_device *gart,
-					  unsigned long iova)
-{
-	unsigned long pte;
-
-	writel_relaxed(iova, gart->regs + GART_ENTRY_ADDR);
-	pte = readl_relaxed(gart->regs + GART_ENTRY_DATA);
-
-	return pte;
-}
-
-static void do_gart_setup(struct gart_device *gart, const u32 *data)
-{
-	unsigned long iova;
-
-	for_each_gart_pte(gart, iova)
-		gart_set_pte(gart, iova, data ? *(data++) : 0);
-
-	writel_relaxed(1, gart->regs + GART_CONFIG);
-	FLUSH_GART_REGS(gart);
-}
-
-static inline bool gart_iova_range_invalid(struct gart_device *gart,
-					   unsigned long iova, size_t bytes)
-{
-	return unlikely(iova < gart->iovmm_base || bytes != GART_PAGE_SIZE ||
-			iova + bytes > gart->iovmm_end);
-}
-
-static inline bool gart_pte_valid(struct gart_device *gart, unsigned long iova)
-{
-	return !!(gart_read_pte(gart, iova) & GART_ENTRY_PHYS_ADDR_VALID);
-}
-
-static int gart_iommu_attach_dev(struct iommu_domain *domain,
-				 struct device *dev)
-{
-	struct gart_device *gart = gart_handle;
-	int ret = 0;
-
-	spin_lock(&gart->dom_lock);
-
-	if (gart->active_domain && gart->active_domain != domain) {
-		ret = -EINVAL;
-	} else if (dev_iommu_priv_get(dev) != domain) {
-		dev_iommu_priv_set(dev, domain);
-		gart->active_domain = domain;
-		gart->active_devices++;
-	}
-
-	spin_unlock(&gart->dom_lock);
-
-	return ret;
-}
-
-static void gart_iommu_set_platform_dma(struct device *dev)
-{
-	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
-	struct gart_device *gart = gart_handle;
-
-	spin_lock(&gart->dom_lock);
-
-	if (dev_iommu_priv_get(dev) == domain) {
-		dev_iommu_priv_set(dev, NULL);
-
-		if (--gart->active_devices == 0)
-			gart->active_domain = NULL;
-	}
-
-	spin_unlock(&gart->dom_lock);
-}
-
-static struct iommu_domain *gart_iommu_domain_alloc(unsigned type)
-{
-	struct iommu_domain *domain;
-
-	if (type != IOMMU_DOMAIN_UNMANAGED)
-		return NULL;
-
-	domain = kzalloc(sizeof(*domain), GFP_KERNEL);
-	if (domain) {
-		domain->geometry.aperture_start = gart_handle->iovmm_base;
-		domain->geometry.aperture_end = gart_handle->iovmm_end - 1;
-		domain->geometry.force_aperture = true;
-	}
-
-	return domain;
-}
-
-static void gart_iommu_domain_free(struct iommu_domain *domain)
-{
-	WARN_ON(gart_handle->active_domain == domain);
-	kfree(domain);
-}
-
-static inline int __gart_iommu_map(struct gart_device *gart, unsigned long iova,
-				   unsigned long pa)
-{
-	if (unlikely(gart_debug && gart_pte_valid(gart, iova))) {
-		dev_err(gart->dev, "Page entry is in-use\n");
-		return -EINVAL;
-	}
-
-	gart_set_pte(gart, iova, GART_ENTRY_PHYS_ADDR_VALID | pa);
-
-	return 0;
-}
-
-static int gart_iommu_map(struct iommu_domain *domain, unsigned long iova,
-			  phys_addr_t pa, size_t bytes, int prot, gfp_t gfp)
-{
-	struct gart_device *gart = gart_handle;
-	int ret;
-
-	if (gart_iova_range_invalid(gart, iova, bytes))
-		return -EINVAL;
-
-	spin_lock(&gart->pte_lock);
-	ret = __gart_iommu_map(gart, iova, (unsigned long)pa);
-	spin_unlock(&gart->pte_lock);
-
-	return ret;
-}
-
-static inline int __gart_iommu_unmap(struct gart_device *gart,
-				     unsigned long iova)
-{
-	if (unlikely(gart_debug && !gart_pte_valid(gart, iova))) {
-		dev_err(gart->dev, "Page entry is invalid\n");
-		return -EINVAL;
-	}
-
-	gart_set_pte(gart, iova, 0);
-
-	return 0;
-}
-
-static size_t gart_iommu_unmap(struct iommu_domain *domain, unsigned long iova,
-			       size_t bytes, struct iommu_iotlb_gather *gather)
-{
-	struct gart_device *gart = gart_handle;
-	int err;
-
-	if (gart_iova_range_invalid(gart, iova, bytes))
-		return 0;
-
-	spin_lock(&gart->pte_lock);
-	err = __gart_iommu_unmap(gart, iova);
-	spin_unlock(&gart->pte_lock);
-
-	return err ? 0 : bytes;
-}
-
-static phys_addr_t gart_iommu_iova_to_phys(struct iommu_domain *domain,
-					   dma_addr_t iova)
-{
-	struct gart_device *gart = gart_handle;
-	unsigned long pte;
-
-	if (gart_iova_range_invalid(gart, iova, GART_PAGE_SIZE))
-		return -EINVAL;
-
-	spin_lock(&gart->pte_lock);
-	pte = gart_read_pte(gart, iova);
-	spin_unlock(&gart->pte_lock);
-
-	return pte & GART_PAGE_MASK;
-}
-
-static struct iommu_device *gart_iommu_probe_device(struct device *dev)
-{
-	if (!dev_iommu_fwspec_get(dev))
-		return ERR_PTR(-ENODEV);
-
-	return &gart_handle->iommu;
-}
-
-static int gart_iommu_of_xlate(struct device *dev,
-			       struct of_phandle_args *args)
-{
-	return 0;
-}
-
-static void gart_iommu_sync_map(struct iommu_domain *domain, unsigned long iova,
-				size_t size)
-{
-	FLUSH_GART_REGS(gart_handle);
-}
-
-static void gart_iommu_sync(struct iommu_domain *domain,
-			    struct iommu_iotlb_gather *gather)
-{
-	size_t length = gather->end - gather->start + 1;
-
-	gart_iommu_sync_map(domain, gather->start, length);
-}
-
-static const struct iommu_ops gart_iommu_ops = {
-	.domain_alloc	= gart_iommu_domain_alloc,
-	.probe_device	= gart_iommu_probe_device,
-	.device_group	= generic_device_group,
-	.set_platform_dma_ops = gart_iommu_set_platform_dma,
-	.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,
-		.map		= gart_iommu_map,
-		.unmap		= gart_iommu_unmap,
-		.iova_to_phys	= gart_iommu_iova_to_phys,
-		.iotlb_sync_map	= gart_iommu_sync_map,
-		.iotlb_sync	= gart_iommu_sync,
-		.free		= gart_iommu_domain_free,
-	}
-};
-
-int tegra_gart_suspend(struct gart_device *gart)
-{
-	u32 *data = gart->savedata;
-	unsigned long iova;
-
-	/*
-	 * All GART users shall be suspended at this point. Disable
-	 * address translation to trap all GART accesses as invalid
-	 * memory accesses.
-	 */
-	writel_relaxed(0, gart->regs + GART_CONFIG);
-	FLUSH_GART_REGS(gart);
-
-	for_each_gart_pte(gart, iova)
-		*(data++) = gart_read_pte(gart, iova);
-
-	return 0;
-}
-
-int tegra_gart_resume(struct gart_device *gart)
-{
-	do_gart_setup(gart, gart->savedata);
-
-	return 0;
-}
-
-struct gart_device *tegra_gart_probe(struct device *dev, struct tegra_mc *mc)
-{
-	struct gart_device *gart;
-	struct resource *res;
-	int err;
-
-	BUILD_BUG_ON(PAGE_SHIFT != GART_PAGE_SHIFT);
-
-	/* the GART memory aperture is required */
-	res = platform_get_resource(to_platform_device(dev), IORESOURCE_MEM, 1);
-	if (!res) {
-		dev_err(dev, "Memory aperture resource unavailable\n");
-		return ERR_PTR(-ENXIO);
-	}
-
-	gart = kzalloc(sizeof(*gart), GFP_KERNEL);
-	if (!gart)
-		return ERR_PTR(-ENOMEM);
-
-	gart_handle = gart;
-
-	gart->dev = dev;
-	gart->regs = mc->regs + GART_REG_BASE;
-	gart->iovmm_base = res->start;
-	gart->iovmm_end = res->end + 1;
-	spin_lock_init(&gart->pte_lock);
-	spin_lock_init(&gart->dom_lock);
-
-	do_gart_setup(gart, NULL);
-
-	err = iommu_device_sysfs_add(&gart->iommu, dev, NULL, "gart");
-	if (err)
-		goto free_gart;
-
-	err = iommu_device_register(&gart->iommu, &gart_iommu_ops, dev);
-	if (err)
-		goto remove_sysfs;
-
-	gart->savedata = vmalloc(resource_size(res) / GART_PAGE_SIZE *
-				 sizeof(u32));
-	if (!gart->savedata) {
-		err = -ENOMEM;
-		goto unregister_iommu;
-	}
-
-	return gart;
-
-unregister_iommu:
-	iommu_device_unregister(&gart->iommu);
-remove_sysfs:
-	iommu_device_sysfs_remove(&gart->iommu);
-free_gart:
-	kfree(gart);
-
-	return ERR_PTR(err);
-}
-
-module_param(gart_debug, bool, 0644);
-MODULE_PARM_DESC(gart_debug, "Enable GART debugging");
diff --git a/drivers/memory/tegra/mc.c b/drivers/memory/tegra/mc.c
index 9082b6c3763dcc..e4d75c96bacec8 100644
--- a/drivers/memory/tegra/mc.c
+++ b/drivers/memory/tegra/mc.c
@@ -918,35 +918,6 @@ static int tegra_mc_probe(struct platform_device *pdev)
 		}
 	}
 
-	if (IS_ENABLED(CONFIG_TEGRA_IOMMU_GART) && !mc->soc->smmu) {
-		mc->gart = tegra_gart_probe(&pdev->dev, mc);
-		if (IS_ERR(mc->gart)) {
-			dev_err(&pdev->dev, "failed to probe GART: %ld\n",
-				PTR_ERR(mc->gart));
-			mc->gart = NULL;
-		}
-	}
-
-	return 0;
-}
-
-static int __maybe_unused tegra_mc_suspend(struct device *dev)
-{
-	struct tegra_mc *mc = dev_get_drvdata(dev);
-
-	if (mc->soc->ops && mc->soc->ops->suspend)
-		return mc->soc->ops->suspend(mc);
-
-	return 0;
-}
-
-static int __maybe_unused tegra_mc_resume(struct device *dev)
-{
-	struct tegra_mc *mc = dev_get_drvdata(dev);
-
-	if (mc->soc->ops && mc->soc->ops->resume)
-		return mc->soc->ops->resume(mc);
-
 	return 0;
 }
 
@@ -959,15 +930,10 @@ static void tegra_mc_sync_state(struct device *dev)
 		icc_sync_state(dev);
 }
 
-static const struct dev_pm_ops tegra_mc_pm_ops = {
-	SET_SYSTEM_SLEEP_PM_OPS(tegra_mc_suspend, tegra_mc_resume)
-};
-
 static struct platform_driver tegra_mc_driver = {
 	.driver = {
 		.name = "tegra-mc",
 		.of_match_table = tegra_mc_of_match,
-		.pm = &tegra_mc_pm_ops,
 		.suppress_bind_attrs = true,
 		.sync_state = tegra_mc_sync_state,
 	},
diff --git a/drivers/memory/tegra/tegra20.c b/drivers/memory/tegra/tegra20.c
index fcd7738fcb536c..6f367f743587db 100644
--- a/drivers/memory/tegra/tegra20.c
+++ b/drivers/memory/tegra/tegra20.c
@@ -687,32 +687,6 @@ static int tegra20_mc_probe(struct tegra_mc *mc)
 	return 0;
 }
 
-static int tegra20_mc_suspend(struct tegra_mc *mc)
-{
-	int err;
-
-	if (IS_ENABLED(CONFIG_TEGRA_IOMMU_GART) && mc->gart) {
-		err = tegra_gart_suspend(mc->gart);
-		if (err < 0)
-			return err;
-	}
-
-	return 0;
-}
-
-static int tegra20_mc_resume(struct tegra_mc *mc)
-{
-	int err;
-
-	if (IS_ENABLED(CONFIG_TEGRA_IOMMU_GART) && mc->gart) {
-		err = tegra_gart_resume(mc->gart);
-		if (err < 0)
-			return err;
-	}
-
-	return 0;
-}
-
 static irqreturn_t tegra20_mc_handle_irq(int irq, void *data)
 {
 	struct tegra_mc *mc = data;
@@ -788,8 +762,6 @@ static irqreturn_t tegra20_mc_handle_irq(int irq, void *data)
 
 static const struct tegra_mc_ops tegra20_mc_ops = {
 	.probe = tegra20_mc_probe,
-	.suspend = tegra20_mc_suspend,
-	.resume = tegra20_mc_resume,
 	.handle_irq = tegra20_mc_handle_irq,
 };
 
diff --git a/include/soc/tegra/mc.h b/include/soc/tegra/mc.h
index 51a2263e1bc59d..a46f9d290682f1 100644
--- a/include/soc/tegra/mc.h
+++ b/include/soc/tegra/mc.h
@@ -93,7 +93,6 @@ struct tegra_smmu_soc {
 
 struct tegra_mc;
 struct tegra_smmu;
-struct gart_device;
 
 #ifdef CONFIG_TEGRA_IOMMU_SMMU
 struct tegra_smmu *tegra_smmu_probe(struct device *dev,
@@ -113,28 +112,6 @@ static inline void tegra_smmu_remove(struct tegra_smmu *smmu)
 }
 #endif
 
-#ifdef CONFIG_TEGRA_IOMMU_GART
-struct gart_device *tegra_gart_probe(struct device *dev, struct tegra_mc *mc);
-int tegra_gart_suspend(struct gart_device *gart);
-int tegra_gart_resume(struct gart_device *gart);
-#else
-static inline struct gart_device *
-tegra_gart_probe(struct device *dev, struct tegra_mc *mc)
-{
-	return ERR_PTR(-ENODEV);
-}
-
-static inline int tegra_gart_suspend(struct gart_device *gart)
-{
-	return -ENODEV;
-}
-
-static inline int tegra_gart_resume(struct gart_device *gart)
-{
-	return -ENODEV;
-}
-#endif
-
 struct tegra_mc_reset {
 	const char *name;
 	unsigned long id;
@@ -177,8 +154,6 @@ struct tegra_mc_ops {
 	 */
 	int (*probe)(struct tegra_mc *mc);
 	void (*remove)(struct tegra_mc *mc);
-	int (*suspend)(struct tegra_mc *mc);
-	int (*resume)(struct tegra_mc *mc);
 	irqreturn_t (*handle_irq)(int irq, void *data);
 	int (*probe_device)(struct tegra_mc *mc, struct device *dev);
 };
@@ -216,7 +191,6 @@ struct tegra_mc_soc {
 struct tegra_mc {
 	struct device *dev;
 	struct tegra_smmu *smmu;
-	struct gart_device *gart;
 	void __iomem *regs;
 	void __iomem *bcast_ch_regs;
 	void __iomem **ch_regs;
-- 
2.40.1



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

* [PATCH v2 06/25] iommu/mtk_iommu_v1: Implement an IDENTITY domain
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (4 preceding siblings ...)
  2023-05-16  0:00   ` [PATCH v2 05/25] iommu/tegra-gart: Remove tegra-gart Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-05-16  0:00   ` [PATCH v2 07/25] iommu: Reorganize iommu_get_default_domain_type() to respect def_domain_type() Jason Gunthorpe
                     ` (21 subsequent siblings)
  27 siblings, 0 replies; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

What mtk does during mtk_iommu_v1_set_platform_dma() is actually putting
the iommu into identity mode. Make this available as a proper IDENTITY
domain.

The mtk_iommu_v1_def_domain_type() from
commit 8bbe13f52cb7 ("iommu/mediatek-v1: Add def_domain_type") explains
this was needed to allow probe_finalize() to be called, but now the
IDENTITY domain will do the same job so change the returned
def_domain_type.

mkt_v1 is the only driver that returns IOMMU_DOMAIN_UNMANAGED from
def_domain_type().  This allows the next patch to enforce an IDENTITY
domain policy for this driver.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/mtk_iommu_v1.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c
index 8a0a5e5d049f4a..cc3e7d53d33ad9 100644
--- a/drivers/iommu/mtk_iommu_v1.c
+++ b/drivers/iommu/mtk_iommu_v1.c
@@ -319,11 +319,27 @@ static int mtk_iommu_v1_attach_device(struct iommu_domain *domain, struct device
 	return 0;
 }
 
-static void mtk_iommu_v1_set_platform_dma(struct device *dev)
+static int mtk_iommu_v1_identity_attach(struct iommu_domain *identity_domain,
+					struct device *dev)
 {
 	struct mtk_iommu_v1_data *data = dev_iommu_priv_get(dev);
 
 	mtk_iommu_v1_config(data, dev, false);
+	return 0;
+}
+
+static struct iommu_domain_ops mtk_iommu_v1_identity_ops = {
+	.attach_dev = mtk_iommu_v1_identity_attach,
+};
+
+static struct iommu_domain mtk_iommu_v1_identity_domain = {
+	.type = IOMMU_DOMAIN_IDENTITY,
+	.ops = &mtk_iommu_v1_identity_ops,
+};
+
+static void mtk_iommu_v1_set_platform_dma(struct device *dev)
+{
+	mtk_iommu_v1_identity_attach(&mtk_iommu_v1_identity_domain, dev);
 }
 
 static int mtk_iommu_v1_map(struct iommu_domain *domain, unsigned long iova,
@@ -443,7 +459,7 @@ static int mtk_iommu_v1_create_mapping(struct device *dev, struct of_phandle_arg
 
 static int mtk_iommu_v1_def_domain_type(struct device *dev)
 {
-	return IOMMU_DOMAIN_UNMANAGED;
+	return IOMMU_DOMAIN_IDENTITY;
 }
 
 static struct iommu_device *mtk_iommu_v1_probe_device(struct device *dev)
@@ -578,6 +594,7 @@ static int mtk_iommu_v1_hw_init(const struct mtk_iommu_v1_data *data)
 }
 
 static const struct iommu_ops mtk_iommu_v1_ops = {
+	.identity_domain = &mtk_iommu_v1_identity_domain,
 	.domain_alloc	= mtk_iommu_v1_domain_alloc,
 	.probe_device	= mtk_iommu_v1_probe_device,
 	.probe_finalize = mtk_iommu_v1_probe_finalize,
-- 
2.40.1



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

* [PATCH v2 07/25] iommu: Reorganize iommu_get_default_domain_type() to respect def_domain_type()
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (5 preceding siblings ...)
  2023-05-16  0:00   ` [PATCH v2 06/25] iommu/mtk_iommu_v1: Implement an IDENTITY domain Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-05-16  0:00   ` [PATCH v2 08/25] iommu: Allow an IDENTITY domain as the default_domain in ARM32 Jason Gunthorpe
                     ` (20 subsequent siblings)
  27 siblings, 0 replies; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

Except for dart every driver returns 0 or IDENTITY from def_domain_type().

The drivers that return IDENTITY have some kind of good reason, typically
that quirky hardware really can't support anything other than IDENTITY.

Arrange things so that if the driver says it needs IDENTITY then
iommu_get_default_domain_type() either fails or returns IDENTITY.  It will
never reject the driver's override to IDENTITY.

The only real functional difference is that the PCI untrusted flag is now
ignored for quirky HW instead of overriding the IOMMU driver.

This makes the next patch cleaner that wants to force IDENTITY always for
ARM_IOMMU because there is no support for DMA.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/iommu.c | 66 +++++++++++++++++++++----------------------
 1 file changed, 33 insertions(+), 33 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 3a72859747bae0..8ba90571449cec 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1608,19 +1608,6 @@ struct iommu_group *fsl_mc_device_group(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(fsl_mc_device_group);
 
-static int iommu_get_def_domain_type(struct device *dev)
-{
-	const struct iommu_ops *ops = dev_iommu_ops(dev);
-
-	if (dev_is_pci(dev) && to_pci_dev(dev)->untrusted)
-		return IOMMU_DOMAIN_DMA;
-
-	if (ops->def_domain_type)
-		return ops->def_domain_type(dev);
-
-	return 0;
-}
-
 static struct iommu_domain *
 __iommu_group_alloc_default_domain(const struct bus_type *bus,
 				   struct iommu_group *group, int req_type)
@@ -1761,36 +1748,49 @@ static int iommu_bus_notifier(struct notifier_block *nb,
 static int iommu_get_default_domain_type(struct iommu_group *group,
 					 int target_type)
 {
+	const struct iommu_ops *ops = dev_iommu_ops(
+		list_first_entry(&group->devices, struct group_device, list)
+			->dev);
 	int best_type = target_type;
 	struct group_device *gdev;
 	struct device *last_dev;
+	int type;
 
 	lockdep_assert_held(&group->mutex);
-
 	for_each_group_device(group, gdev) {
-		unsigned int type = iommu_get_def_domain_type(gdev->dev);
-
-		if (best_type && type && best_type != type) {
-			if (target_type) {
-				dev_err_ratelimited(
-					gdev->dev,
-					"Device cannot be in %s domain\n",
-					iommu_domain_type_str(target_type));
-				return -1;
-			}
-
-			dev_warn(
-				gdev->dev,
-				"Device needs domain type %s, but device %s in the same iommu group requires type %s - using default\n",
-				iommu_domain_type_str(type), dev_name(last_dev),
-				iommu_domain_type_str(best_type));
-			return 0;
+		type = best_type;
+		if (ops->def_domain_type) {
+			type = ops->def_domain_type(gdev->dev);
+			if (best_type && type && best_type != type)
+				goto err;
 		}
-		if (!best_type)
-			best_type = type;
+
+		if (dev_is_pci(gdev->dev) && to_pci_dev(gdev->dev)->untrusted) {
+			type = IOMMU_DOMAIN_DMA;
+			if (best_type && type && best_type != type)
+				goto err;
+		}
+		best_type = type;
 		last_dev = gdev->dev;
 	}
 	return best_type;
+
+err:
+	if (target_type) {
+		dev_err_ratelimited(
+			gdev->dev,
+			"Device cannot be in %s domain - it is forcing %s\n",
+			iommu_domain_type_str(target_type),
+			iommu_domain_type_str(type));
+		return -1;
+	}
+
+	dev_warn(
+		gdev->dev,
+		"Device needs domain type %s, but device %s in the same iommu group requires type %s - using default\n",
+		iommu_domain_type_str(type), dev_name(last_dev),
+		iommu_domain_type_str(best_type));
+	return 0;
 }
 
 static void iommu_group_do_probe_finalize(struct device *dev)
-- 
2.40.1



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

* [PATCH v2 08/25] iommu: Allow an IDENTITY domain as the default_domain in ARM32
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (6 preceding siblings ...)
  2023-05-16  0:00   ` [PATCH v2 07/25] iommu: Reorganize iommu_get_default_domain_type() to respect def_domain_type() Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-06-01 18:57     ` Robin Murphy
  2023-05-16  0:00   ` [PATCH v2 09/25] iommu/fsl_pamu: Implement an IDENTITY domain Jason Gunthorpe
                     ` (19 subsequent siblings)
  27 siblings, 1 reply; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

Even though dma-iommu.c and CONFIG_ARM_DMA_USE_IOMMU do approximately the
same stuff, the way they relate to the IOMMU core is quiet different.

dma-iommu.c expects the core code to setup an UNMANAGED domain (of type
IOMMU_DOMAIN_DMA) and then configures itself to use that domain. This
becomes the default_domain for the group.

ARM_DMA_USE_IOMMU does not use the default_domain, instead it directly
allocates an UNMANAGED domain and operates it just like an external
driver. In this case group->default_domain is NULL.

If the driver provides a global static identity_domain then automatically
use it as the default_domain when in ARM_DMA_USE_IOMMU mode.

This allows drivers that implemented default_domain == NULL as an IDENTITY
translation to trivially get a properly labeled non-NULL default_domain on
ARM32 configs.

With this arrangment when ARM_DMA_USE_IOMMU wants to disconnect from the
device the normal detach_domain flow will restore the IDENTITY domain as
the default domain. Overall this makes attach_dev() of the IDENTITY domain
called in the same places as detach_dev().

This effectively migrates these drivers to default_domain mode. For
drivers that support ARM64 they will gain support for the IDENTITY
translation mode for the dma_api and behave in a uniform way.

Drivers use this by setting ops->identity_domain to a static singleton
iommu_domain that implements the identity attach. If the core detects
ARM_DMA_USE_IOMMU mode then it automatically attaches the IDENTITY domain
during probe.

Drivers can continue to prevent the use of DMA translation by returning
IOMMU_DOMAIN_IDENTITY from def_domain_type, this will completely prevent
IOMMU_DMA from running but will not impact ARM_DMA_USE_IOMMU.

This allows removing the set_platform_dma_ops() from every remaining
driver.

Remove the set_platform_dma_ops from rockchip and mkt_v1 as all it does
is set an existing global static identity domain. mkt_v1 does not support
IOMMU_DOMAIN_DMA and it does not compile on ARM64 so this transformation
is safe.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/iommu.c          | 40 +++++++++++++++++++++++++++++-----
 drivers/iommu/mtk_iommu_v1.c   | 12 ----------
 drivers/iommu/rockchip-iommu.c | 10 ---------
 3 files changed, 35 insertions(+), 27 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 8ba90571449cec..bed7cb6e5ee65b 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1757,18 +1757,48 @@ static int iommu_get_default_domain_type(struct iommu_group *group,
 	int type;
 
 	lockdep_assert_held(&group->mutex);
+
+	/*
+	 * ARM32 drivers supporting CONFIG_ARM_DMA_USE_IOMMU can declare an
+	 * identity_domain and it will automatically become their default
+	 * domain. Later on ARM_DMA_USE_IOMMU will install its UNMANAGED domain.
+	 * Override the selection to IDENTITY if we are sure the driver supports
+	 * it.
+	 */
+	if (IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU) && ops->identity_domain) {
+		type = IOMMU_DOMAIN_IDENTITY;
+		if (best_type && type && best_type != type)
+			goto err;
+		best_type = target_type = IOMMU_DOMAIN_IDENTITY;
+	}
+
 	for_each_group_device(group, gdev) {
 		type = best_type;
 		if (ops->def_domain_type) {
 			type = ops->def_domain_type(gdev->dev);
-			if (best_type && type && best_type != type)
+			if (best_type && type && best_type != type) {
+				/* Stick with the last driver override we saw */
+				best_type = type;
 				goto err;
+			}
 		}
 
 		if (dev_is_pci(gdev->dev) && to_pci_dev(gdev->dev)->untrusted) {
-			type = IOMMU_DOMAIN_DMA;
-			if (best_type && type && best_type != type)
-				goto err;
+			/*
+			 * We don't have any way for the iommu core code to
+			 * force arm_iommu to activate so we can't enforce
+			 * trusted. Log it and keep going with the IDENTITY
+			 * default domain.
+			 */
+			if (IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU)) {
+				dev_warn(
+					gdev->dev,
+					"PCI device is untrusted but ARM32 does not support secure IOMMU operation, continuing anyway.\n");
+			} else {
+				type = IOMMU_DOMAIN_DMA;
+				if (best_type && type && best_type != type)
+					goto err;
+			}
 		}
 		best_type = type;
 		last_dev = gdev->dev;
@@ -1790,7 +1820,7 @@ static int iommu_get_default_domain_type(struct iommu_group *group,
 		"Device needs domain type %s, but device %s in the same iommu group requires type %s - using default\n",
 		iommu_domain_type_str(type), dev_name(last_dev),
 		iommu_domain_type_str(best_type));
-	return 0;
+	return best_type;
 }
 
 static void iommu_group_do_probe_finalize(struct device *dev)
diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c
index cc3e7d53d33ad9..7c0c1d50df5f75 100644
--- a/drivers/iommu/mtk_iommu_v1.c
+++ b/drivers/iommu/mtk_iommu_v1.c
@@ -337,11 +337,6 @@ static struct iommu_domain mtk_iommu_v1_identity_domain = {
 	.ops = &mtk_iommu_v1_identity_ops,
 };
 
-static void mtk_iommu_v1_set_platform_dma(struct device *dev)
-{
-	mtk_iommu_v1_identity_attach(&mtk_iommu_v1_identity_domain, dev);
-}
-
 static int mtk_iommu_v1_map(struct iommu_domain *domain, unsigned long iova,
 			    phys_addr_t paddr, size_t pgsize, size_t pgcount,
 			    int prot, gfp_t gfp, size_t *mapped)
@@ -457,11 +452,6 @@ static int mtk_iommu_v1_create_mapping(struct device *dev, struct of_phandle_arg
 	return 0;
 }
 
-static int mtk_iommu_v1_def_domain_type(struct device *dev)
-{
-	return IOMMU_DOMAIN_IDENTITY;
-}
-
 static struct iommu_device *mtk_iommu_v1_probe_device(struct device *dev)
 {
 	struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
@@ -599,10 +589,8 @@ static const struct iommu_ops mtk_iommu_v1_ops = {
 	.probe_device	= mtk_iommu_v1_probe_device,
 	.probe_finalize = mtk_iommu_v1_probe_finalize,
 	.release_device	= mtk_iommu_v1_release_device,
-	.def_domain_type = mtk_iommu_v1_def_domain_type,
 	.device_group	= generic_device_group,
 	.pgsize_bitmap	= MT2701_IOMMU_PAGE_SIZE,
-	.set_platform_dma_ops = mtk_iommu_v1_set_platform_dma,
 	.owner          = THIS_MODULE,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= mtk_iommu_v1_attach_device,
diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index ebce56d6e9c634..9e1296a856ac4c 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -1026,13 +1026,6 @@ static struct iommu_domain rk_identity_domain = {
 	.ops = &rk_identity_ops,
 };
 
-#ifdef CONFIG_ARM
-static void rk_iommu_set_platform_dma(struct device *dev)
-{
-	WARN_ON(rk_iommu_identity_attach(&rk_identity_domain, dev));
-}
-#endif
-
 static int rk_iommu_attach_device(struct iommu_domain *domain,
 		struct device *dev)
 {
@@ -1211,9 +1204,6 @@ static const struct iommu_ops rk_iommu_ops = {
 	.probe_device = rk_iommu_probe_device,
 	.release_device = rk_iommu_release_device,
 	.device_group = rk_iommu_device_group,
-#ifdef CONFIG_ARM
-	.set_platform_dma_ops = rk_iommu_set_platform_dma,
-#endif
 	.pgsize_bitmap = RK_IOMMU_PGSIZE_BITMAP,
 	.of_xlate = rk_iommu_of_xlate,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-- 
2.40.1



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

* [PATCH v2 09/25] iommu/fsl_pamu: Implement an IDENTITY domain
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (7 preceding siblings ...)
  2023-05-16  0:00   ` [PATCH v2 08/25] iommu: Allow an IDENTITY domain as the default_domain in ARM32 Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-06-01 19:37     ` Robin Murphy
  2023-05-16  0:00   ` [PATCH v2 10/25] iommu/exynos: " Jason Gunthorpe
                     ` (18 subsequent siblings)
  27 siblings, 1 reply; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

Robin was able to check the documentation and what fsl_pamu has
historically called detach_dev() is really putting the IOMMU into an
IDENTITY mode.

Move to the new core support for ARM_DMA_USE_IOMMU by defining
ops->identity_domain. This is a ppc driver without any dma_ops, so ensure
the identity translation is the default domain.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/fsl_pamu_domain.c | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index bce37229709965..ca4f5ebf028783 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -283,15 +283,21 @@ static int fsl_pamu_attach_device(struct iommu_domain *domain,
 	return ret;
 }
 
-static void fsl_pamu_set_platform_dma(struct device *dev)
+static int fsl_pamu_identity_attach(struct iommu_domain *platform_domain,
+				    struct device *dev)
 {
 	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
-	struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
+	struct fsl_dma_domain *dma_domain;
 	const u32 *prop;
 	int len;
 	struct pci_dev *pdev = NULL;
 	struct pci_controller *pci_ctl;
 
+	if (domain == platform_domain || !domain)
+		return 0;
+
+	dma_domain = to_fsl_dma_domain(domain);
+
 	/*
 	 * Use LIODN of the PCI controller while detaching a
 	 * PCI device.
@@ -312,8 +318,18 @@ static void fsl_pamu_set_platform_dma(struct device *dev)
 		detach_device(dev, dma_domain);
 	else
 		pr_debug("missing fsl,liodn property at %pOF\n", dev->of_node);
+	return 0;
 }
 
+static struct iommu_domain_ops fsl_pamu_identity_ops = {
+	.attach_dev = fsl_pamu_identity_attach,
+};
+
+static struct iommu_domain fsl_pamu_identity_domain = {
+	.type = IOMMU_DOMAIN_IDENTITY,
+	.ops = &fsl_pamu_identity_ops,
+};
+
 /* Set the domain stash attribute */
 int fsl_pamu_configure_l1_stash(struct iommu_domain *domain, u32 cpu)
 {
@@ -447,12 +463,22 @@ static struct iommu_device *fsl_pamu_probe_device(struct device *dev)
 	return &pamu_iommu;
 }
 
+static int fsl_pamu_def_domain_type(struct device *dev)
+{
+	/*
+	 * This platform does not use dma_ops at all so the normally the iommu
+	 * must be in identity mode
+	 */
+	return IOMMU_DOMAIN_IDENTITY;
+}
+
 static const struct iommu_ops fsl_pamu_ops = {
+	.identity_domain = &fsl_pamu_identity_domain,
+	.def_domain_type = &fsl_pamu_def_domain_type,
 	.capable	= fsl_pamu_capable,
 	.domain_alloc	= fsl_pamu_domain_alloc,
 	.probe_device	= fsl_pamu_probe_device,
 	.device_group   = fsl_pamu_device_group,
-	.set_platform_dma_ops = fsl_pamu_set_platform_dma,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= fsl_pamu_attach_device,
 		.iova_to_phys	= fsl_pamu_iova_to_phys,
-- 
2.40.1



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

* [PATCH v2 10/25] iommu/exynos: Implement an IDENTITY domain
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (8 preceding siblings ...)
  2023-05-16  0:00   ` [PATCH v2 09/25] iommu/fsl_pamu: Implement an IDENTITY domain Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-05-17 22:41     ` Marek Szyprowski
  2023-05-16  0:00   ` [PATCH v2 11/25] iommu/tegra-smmu: " Jason Gunthorpe
                     ` (17 subsequent siblings)
  27 siblings, 1 reply; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

What exynos calls exynos_iommu_detach_device is actually putting the iommu
into identity mode.

Move to the new core support for ARM_DMA_USE_IOMMU by defining
ops->identity_domain.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/exynos-iommu.c | 66 +++++++++++++++++-------------------
 1 file changed, 32 insertions(+), 34 deletions(-)

diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c
index c275fe71c4db32..5e12b85dfe8705 100644
--- a/drivers/iommu/exynos-iommu.c
+++ b/drivers/iommu/exynos-iommu.c
@@ -24,6 +24,7 @@
 
 typedef u32 sysmmu_iova_t;
 typedef u32 sysmmu_pte_t;
+static struct iommu_domain exynos_identity_domain;
 
 /* We do not consider super section mapping (16MB) */
 #define SECT_ORDER 20
@@ -829,7 +830,7 @@ static int __maybe_unused exynos_sysmmu_suspend(struct device *dev)
 		struct exynos_iommu_owner *owner = dev_iommu_priv_get(master);
 
 		mutex_lock(&owner->rpm_lock);
-		if (data->domain) {
+		if (&data->domain->domain != &exynos_identity_domain) {
 			dev_dbg(data->sysmmu, "saving state\n");
 			__sysmmu_disable(data);
 		}
@@ -847,7 +848,7 @@ static int __maybe_unused exynos_sysmmu_resume(struct device *dev)
 		struct exynos_iommu_owner *owner = dev_iommu_priv_get(master);
 
 		mutex_lock(&owner->rpm_lock);
-		if (data->domain) {
+		if (&data->domain->domain != &exynos_identity_domain) {
 			dev_dbg(data->sysmmu, "restoring state\n");
 			__sysmmu_enable(data);
 		}
@@ -980,17 +981,20 @@ static void exynos_iommu_domain_free(struct iommu_domain *iommu_domain)
 	kfree(domain);
 }
 
-static void exynos_iommu_detach_device(struct iommu_domain *iommu_domain,
-				    struct device *dev)
+static int exynos_iommu_identity_attach(struct iommu_domain *identity_domain,
+					struct device *dev)
 {
-	struct exynos_iommu_domain *domain = to_exynos_domain(iommu_domain);
 	struct exynos_iommu_owner *owner = dev_iommu_priv_get(dev);
-	phys_addr_t pagetable = virt_to_phys(domain->pgtable);
+	struct exynos_iommu_domain *domain;
+	phys_addr_t pagetable;
 	struct sysmmu_drvdata *data, *next;
 	unsigned long flags;
 
-	if (!has_sysmmu(dev) || owner->domain != iommu_domain)
-		return;
+	if (owner->domain == identity_domain)
+		return 0;
+
+	domain = to_exynos_domain(owner->domain);
+	pagetable = virt_to_phys(domain->pgtable);
 
 	mutex_lock(&owner->rpm_lock);
 
@@ -1009,15 +1013,25 @@ static void exynos_iommu_detach_device(struct iommu_domain *iommu_domain,
 		list_del_init(&data->domain_node);
 		spin_unlock(&data->lock);
 	}
-	owner->domain = NULL;
+	owner->domain = identity_domain;
 	spin_unlock_irqrestore(&domain->lock, flags);
 
 	mutex_unlock(&owner->rpm_lock);
 
-	dev_dbg(dev, "%s: Detached IOMMU with pgtable %pa\n", __func__,
-		&pagetable);
+	dev_dbg(dev, "%s: Restored IOMMU to IDENTITY from pgtable %pa\n",
+		__func__, &pagetable);
+	return 0;
 }
 
+static struct iommu_domain_ops exynos_identity_ops = {
+	.attach_dev = exynos_iommu_identity_attach,
+};
+
+static struct iommu_domain exynos_identity_domain = {
+	.type = IOMMU_DOMAIN_IDENTITY,
+	.ops = &exynos_identity_ops,
+};
+
 static int exynos_iommu_attach_device(struct iommu_domain *iommu_domain,
 				   struct device *dev)
 {
@@ -1026,12 +1040,11 @@ static int exynos_iommu_attach_device(struct iommu_domain *iommu_domain,
 	struct sysmmu_drvdata *data;
 	phys_addr_t pagetable = virt_to_phys(domain->pgtable);
 	unsigned long flags;
+	int err;
 
-	if (!has_sysmmu(dev))
-		return -ENODEV;
-
-	if (owner->domain)
-		exynos_iommu_detach_device(owner->domain, dev);
+	err = exynos_iommu_identity_attach(&exynos_identity_domain, dev);
+	if (err)
+		return err;
 
 	mutex_lock(&owner->rpm_lock);
 
@@ -1407,26 +1420,12 @@ static struct iommu_device *exynos_iommu_probe_device(struct device *dev)
 	return &data->iommu;
 }
 
-static void exynos_iommu_set_platform_dma(struct device *dev)
-{
-	struct exynos_iommu_owner *owner = dev_iommu_priv_get(dev);
-
-	if (owner->domain) {
-		struct iommu_group *group = iommu_group_get(dev);
-
-		if (group) {
-			exynos_iommu_detach_device(owner->domain, dev);
-			iommu_group_put(group);
-		}
-	}
-}
-
 static void exynos_iommu_release_device(struct device *dev)
 {
 	struct exynos_iommu_owner *owner = dev_iommu_priv_get(dev);
 	struct sysmmu_drvdata *data;
 
-	exynos_iommu_set_platform_dma(dev);
+	WARN_ON(exynos_iommu_identity_attach(&exynos_identity_domain, dev));
 
 	list_for_each_entry(data, &owner->controllers, owner_node)
 		device_link_del(data->link);
@@ -1457,6 +1456,7 @@ static int exynos_iommu_of_xlate(struct device *dev,
 
 		INIT_LIST_HEAD(&owner->controllers);
 		mutex_init(&owner->rpm_lock);
+		owner->domain = &exynos_identity_domain;
 		dev_iommu_priv_set(dev, owner);
 	}
 
@@ -1471,11 +1471,9 @@ static int exynos_iommu_of_xlate(struct device *dev,
 }
 
 static const struct iommu_ops exynos_iommu_ops = {
+	.identity_domain = &exynos_identity_domain,
 	.domain_alloc = exynos_iommu_domain_alloc,
 	.device_group = generic_device_group,
-#ifdef CONFIG_ARM
-	.set_platform_dma_ops = exynos_iommu_set_platform_dma,
-#endif
 	.probe_device = exynos_iommu_probe_device,
 	.release_device = exynos_iommu_release_device,
 	.pgsize_bitmap = SECT_SIZE | LPAGE_SIZE | SPAGE_SIZE,
-- 
2.40.1



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

* [PATCH v2 11/25] iommu/tegra-smmu: Implement an IDENTITY domain
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (9 preceding siblings ...)
  2023-05-16  0:00   ` [PATCH v2 10/25] iommu/exynos: " Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-05-16  0:00   ` [PATCH v2 12/25] iommu/tegra-smmu: Support DMA domains in tegra Jason Gunthorpe
                     ` (16 subsequent siblings)
  27 siblings, 0 replies; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

What tegra-smmu does during tegra_smmu_set_platform_dma() is actually
putting the iommu into identity mode.

Move to the new core support for ARM_DMA_USE_IOMMU by defining
ops->identity_domain.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/tegra-smmu.c | 37 ++++++++++++++++++++++++++++++++-----
 1 file changed, 32 insertions(+), 5 deletions(-)

diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
index 1cbf063ccf147a..f63f1d4f0bd10f 100644
--- a/drivers/iommu/tegra-smmu.c
+++ b/drivers/iommu/tegra-smmu.c
@@ -511,23 +511,39 @@ static int tegra_smmu_attach_dev(struct iommu_domain *domain,
 	return err;
 }
 
-static void tegra_smmu_set_platform_dma(struct device *dev)
+static int tegra_smmu_identity_attach(struct iommu_domain *identity_domain,
+				      struct device *dev)
 {
 	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
 	struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
-	struct tegra_smmu_as *as = to_smmu_as(domain);
-	struct tegra_smmu *smmu = as->smmu;
+	struct tegra_smmu_as *as;
+	struct tegra_smmu *smmu;
 	unsigned int index;
 
 	if (!fwspec)
-		return;
+		return -ENODEV;
 
+	if (domain == identity_domain || !domain)
+		return 0;
+
+	as = to_smmu_as(domain);
+	smmu = as->smmu;
 	for (index = 0; index < fwspec->num_ids; index++) {
 		tegra_smmu_disable(smmu, fwspec->ids[index], as->id);
 		tegra_smmu_as_unprepare(smmu, as);
 	}
+	return 0;
 }
 
+static struct iommu_domain_ops tegra_smmu_identity_ops = {
+	.attach_dev = tegra_smmu_identity_attach,
+};
+
+static struct iommu_domain tegra_smmu_identity_domain = {
+	.type = IOMMU_DOMAIN_IDENTITY,
+	.ops = &tegra_smmu_identity_ops,
+};
+
 static void tegra_smmu_set_pde(struct tegra_smmu_as *as, unsigned long iova,
 			       u32 value)
 {
@@ -962,11 +978,22 @@ static int tegra_smmu_of_xlate(struct device *dev,
 	return iommu_fwspec_add_ids(dev, &id, 1);
 }
 
+static int tegra_smmu_def_domain_type(struct device *dev)
+{
+	/*
+	 * FIXME: For now we want to run all translation in IDENTITY mode, due
+	 * to some device quirks. Better would be to just quirk the troubled
+	 * devices.
+	 */
+	return IOMMU_DOMAIN_IDENTITY;
+}
+
 static const struct iommu_ops tegra_smmu_ops = {
+	.identity_domain = &tegra_smmu_identity_domain,
+	.def_domain_type = &tegra_smmu_def_domain_type,
 	.domain_alloc = tegra_smmu_domain_alloc,
 	.probe_device = tegra_smmu_probe_device,
 	.device_group = tegra_smmu_device_group,
-	.set_platform_dma_ops = tegra_smmu_set_platform_dma,
 	.of_xlate = tegra_smmu_of_xlate,
 	.pgsize_bitmap = SZ_4K,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-- 
2.40.1



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

* [PATCH v2 12/25] iommu/tegra-smmu: Support DMA domains in tegra
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (10 preceding siblings ...)
  2023-05-16  0:00   ` [PATCH v2 11/25] iommu/tegra-smmu: " Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-05-16  0:00   ` [PATCH v2 13/25] iommu/omap: Implement an IDENTITY domain Jason Gunthorpe
                     ` (15 subsequent siblings)
  27 siblings, 0 replies; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

All ARM64 iommu drivers should support IOMMU_DOMAIN_DMA to enable
dma-iommu.c.

tegra is blocking dma-iommu usage, and also default_domain's, because it
wants an identity translation. This is needed for some device quirk. The
correct way to do this is to support IDENTITY domains and use
ops->def_domain_type() to return IOMMU_DOMAIN_IDENTITY for only the quirky
devices.

Add support for IOMMU_DOMAIN_DMA and force IOMMU_DOMAIN_IDENTITY mode for
everything so no behavior changes.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/tegra-smmu.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
index f63f1d4f0bd10f..6cba034905edbf 100644
--- a/drivers/iommu/tegra-smmu.c
+++ b/drivers/iommu/tegra-smmu.c
@@ -276,7 +276,7 @@ static struct iommu_domain *tegra_smmu_domain_alloc(unsigned type)
 {
 	struct tegra_smmu_as *as;
 
-	if (type != IOMMU_DOMAIN_UNMANAGED)
+	if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA)
 		return NULL;
 
 	as = kzalloc(sizeof(*as), GFP_KERNEL);
@@ -989,6 +989,12 @@ static int tegra_smmu_def_domain_type(struct device *dev)
 }
 
 static const struct iommu_ops tegra_smmu_ops = {
+	/*
+	 * FIXME: For now we want to run all translation in IDENTITY mode,
+	 * better would be to have a def_domain_type op do this for just the
+	 * quirky device.
+	 */
+	.default_domain = &tegra_smmu_identity_domain,
 	.identity_domain = &tegra_smmu_identity_domain,
 	.def_domain_type = &tegra_smmu_def_domain_type,
 	.domain_alloc = tegra_smmu_domain_alloc,
-- 
2.40.1



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

* [PATCH v2 13/25] iommu/omap: Implement an IDENTITY domain
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (11 preceding siblings ...)
  2023-05-16  0:00   ` [PATCH v2 12/25] iommu/tegra-smmu: Support DMA domains in tegra Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-05-16  0:00   ` [PATCH v2 14/25] iommu/msm: " Jason Gunthorpe
                     ` (14 subsequent siblings)
  27 siblings, 0 replies; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

What omap does during omap_iommu_set_platform_dma() is actually putting
the iommu into identity mode.

Move to the new core support for ARM_DMA_USE_IOMMU by defining
ops->identity_domain.

This driver does not support IOMMU_DOMAIN_DMA, however it cannot be
compiled on ARM64 either. Most likely it is fine to support dma-iommu.c

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/omap-iommu.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
index 537e402f9bba97..34340ef15241bc 100644
--- a/drivers/iommu/omap-iommu.c
+++ b/drivers/iommu/omap-iommu.c
@@ -1555,16 +1555,31 @@ static void _omap_iommu_detach_dev(struct omap_iommu_domain *omap_domain,
 	omap_domain->dev = NULL;
 }
 
-static void omap_iommu_set_platform_dma(struct device *dev)
+static int omap_iommu_identity_attach(struct iommu_domain *identity_domain,
+				      struct device *dev)
 {
 	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
-	struct omap_iommu_domain *omap_domain = to_omap_domain(domain);
+	struct omap_iommu_domain *omap_domain;
 
+	if (domain == identity_domain || !domain)
+		return 0;
+
+	omap_domain = to_omap_domain(domain);
 	spin_lock(&omap_domain->lock);
 	_omap_iommu_detach_dev(omap_domain, dev);
 	spin_unlock(&omap_domain->lock);
+	return 0;
 }
 
+static struct iommu_domain_ops omap_iommu_identity_ops = {
+	.attach_dev = omap_iommu_identity_attach,
+};
+
+static struct iommu_domain omap_iommu_identity_domain = {
+	.type = IOMMU_DOMAIN_IDENTITY,
+	.ops = &omap_iommu_identity_ops,
+};
+
 static struct iommu_domain *omap_iommu_domain_alloc(unsigned type)
 {
 	struct omap_iommu_domain *omap_domain;
@@ -1732,11 +1747,11 @@ static struct iommu_group *omap_iommu_device_group(struct device *dev)
 }
 
 static const struct iommu_ops omap_iommu_ops = {
+	.identity_domain = &omap_iommu_identity_domain,
 	.domain_alloc	= omap_iommu_domain_alloc,
 	.probe_device	= omap_iommu_probe_device,
 	.release_device	= omap_iommu_release_device,
 	.device_group	= omap_iommu_device_group,
-	.set_platform_dma_ops = omap_iommu_set_platform_dma,
 	.pgsize_bitmap	= OMAP_IOMMU_PGSIZES,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= omap_iommu_attach_dev,
-- 
2.40.1



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

* [PATCH v2 14/25] iommu/msm: Implement an IDENTITY domain
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (12 preceding siblings ...)
  2023-05-16  0:00   ` [PATCH v2 13/25] iommu/omap: Implement an IDENTITY domain Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-05-16  0:00   ` [PATCH v2 15/25] iommufd/selftest: Make the mock iommu driver into a real driver Jason Gunthorpe
                     ` (13 subsequent siblings)
  27 siblings, 0 replies; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

What msm does during omap_iommu_set_platform_dma() is actually putting the
iommu into identity mode.

Move to the new core support for ARM_DMA_USE_IOMMU by defining
ops->identity_domain.

This driver does not support IOMMU_DOMAIN_DMA, however it cannot be
compiled on ARM64 either. Most likely it is fine to support dma-iommu.c

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/msm_iommu.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c
index 79d89bad5132b7..26ed81cfeee897 100644
--- a/drivers/iommu/msm_iommu.c
+++ b/drivers/iommu/msm_iommu.c
@@ -443,15 +443,20 @@ static int msm_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)
 	return ret;
 }
 
-static void msm_iommu_set_platform_dma(struct device *dev)
+static int msm_iommu_identity_attach(struct iommu_domain *identity_domain,
+				     struct device *dev)
 {
 	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
-	struct msm_priv *priv = to_msm_priv(domain);
+	struct msm_priv *priv;
 	unsigned long flags;
 	struct msm_iommu_dev *iommu;
 	struct msm_iommu_ctx_dev *master;
-	int ret;
+	int ret = 0;
 
+	if (domain == identity_domain || !domain)
+		return 0;
+
+	priv = to_msm_priv(domain);
 	free_io_pgtable_ops(priv->iop);
 
 	spin_lock_irqsave(&msm_iommu_lock, flags);
@@ -468,8 +473,18 @@ static void msm_iommu_set_platform_dma(struct device *dev)
 	}
 fail:
 	spin_unlock_irqrestore(&msm_iommu_lock, flags);
+	return ret;
 }
 
+static struct iommu_domain_ops msm_iommu_identity_ops = {
+	.attach_dev = msm_iommu_identity_attach,
+};
+
+static struct iommu_domain msm_iommu_identity_domain = {
+	.type = IOMMU_DOMAIN_IDENTITY,
+	.ops = &msm_iommu_identity_ops,
+};
+
 static int msm_iommu_map(struct iommu_domain *domain, unsigned long iova,
 			 phys_addr_t pa, size_t pgsize, size_t pgcount,
 			 int prot, gfp_t gfp, size_t *mapped)
@@ -675,10 +690,10 @@ irqreturn_t msm_iommu_fault_handler(int irq, void *dev_id)
 }
 
 static struct iommu_ops msm_iommu_ops = {
+	.identity_domain = &msm_iommu_identity_domain,
 	.domain_alloc = msm_iommu_domain_alloc,
 	.probe_device = msm_iommu_probe_device,
 	.device_group = generic_device_group,
-	.set_platform_dma_ops = msm_iommu_set_platform_dma,
 	.pgsize_bitmap = MSM_IOMMU_PGSIZES,
 	.of_xlate = qcom_iommu_of_xlate,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-- 
2.40.1



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

* [PATCH v2 15/25] iommufd/selftest: Make the mock iommu driver into a real driver
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (13 preceding siblings ...)
  2023-05-16  0:00   ` [PATCH v2 14/25] iommu/msm: " Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-05-16  0:00   ` [PATCH v2 16/25] iommu: Remove ops->set_platform_dma_ops() Jason Gunthorpe
                     ` (12 subsequent siblings)
  27 siblings, 0 replies; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

I've avoided doing this because there is no way to make this happen
without an intrusion into the core code. Up till now this has avoided
needing the core code's probe path with some hackery - but now that
default domains are becoming mandatory it is unavoidable. The core probe
path must be run to set the default_domain, only it can do it. Without
a default domain iommufd can't use the group.

Make it so that iommufd selftest can create a real iommu driver and bind
it only to is own private bus. Add iommu_device_register_bus() as a core
code helper to make this possible. It simply sets the right pointers and
registers the notifier block. The mock driver then works like any normal
driver should, with probe triggered by the bus ops

When the bus->iommu_ops stuff is fully unwound we can probably do better
here and remove this special case.

Remove set_platform_dma_ops from selftest and make it use a BLOCKED
default domain.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/iommu-priv.h              |  16 +++
 drivers/iommu/iommu.c                   |  43 ++++++++
 drivers/iommu/iommufd/iommufd_private.h |   5 +-
 drivers/iommu/iommufd/main.c            |   8 +-
 drivers/iommu/iommufd/selftest.c        | 141 +++++++++++++-----------
 5 files changed, 144 insertions(+), 69 deletions(-)
 create mode 100644 drivers/iommu/iommu-priv.h

diff --git a/drivers/iommu/iommu-priv.h b/drivers/iommu/iommu-priv.h
new file mode 100644
index 00000000000000..1cbc04b9cf7297
--- /dev/null
+++ b/drivers/iommu/iommu-priv.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES.
+ */
+#ifndef __IOMMU_PRIV_H
+#define __IOMMU_PRIV_H
+
+#include <linux/iommu.h>
+
+int iommu_device_register_bus(struct iommu_device *iommu,
+			      const struct iommu_ops *ops, struct bus_type *bus,
+			      struct notifier_block *nb);
+void iommu_device_unregister_bus(struct iommu_device *iommu,
+				 struct bus_type *bus,
+				 struct notifier_block *nb);
+
+#endif
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index bed7cb6e5ee65b..f9f11ad918f673 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -36,6 +36,7 @@
 #include "dma-iommu.h"
 
 #include "iommu-sva.h"
+#include "iommu-priv.h"
 
 static struct kset *iommu_group_kset;
 static DEFINE_IDA(iommu_group_ida);
@@ -287,6 +288,48 @@ void iommu_device_unregister(struct iommu_device *iommu)
 }
 EXPORT_SYMBOL_GPL(iommu_device_unregister);
 
+#if IS_ENABLED(CONFIG_IOMMUFD_TEST)
+void iommu_device_unregister_bus(struct iommu_device *iommu,
+				 struct bus_type *bus,
+				 struct notifier_block *nb)
+{
+	bus_unregister_notifier(bus, nb);
+	iommu_device_unregister(iommu);
+}
+EXPORT_SYMBOL_GPL(iommu_device_unregister_bus);
+
+/*
+ * Register an iommu driver against a single bus. This is only used by iommufd
+ * selftest to create a mock iommu driver. The caller must provide
+ * some memory to hold a notifier_block.
+ */
+int iommu_device_register_bus(struct iommu_device *iommu,
+			      const struct iommu_ops *ops, struct bus_type *bus,
+			      struct notifier_block *nb)
+{
+	int err;
+
+	iommu->ops = ops;
+	nb->notifier_call = iommu_bus_notifier;
+	err = bus_register_notifier(bus, nb);
+	if (err)
+		return err;
+
+	spin_lock(&iommu_device_lock);
+	list_add_tail(&iommu->list, &iommu_device_list);
+	spin_unlock(&iommu_device_lock);
+
+	bus->iommu_ops = ops;
+	err = bus_iommu_probe(bus);
+	if (err) {
+		iommu_device_unregister_bus(iommu, bus, nb);
+		return err;
+	}
+	return 0;
+}
+EXPORT_SYMBOL_GPL(iommu_device_register_bus);
+#endif
+
 static struct dev_iommu *dev_iommu_get(struct device *dev)
 {
 	struct dev_iommu *param = dev->iommu;
diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h
index b38e67d1988bdb..368f66c63a239a 100644
--- a/drivers/iommu/iommufd/iommufd_private.h
+++ b/drivers/iommu/iommufd/iommufd_private.h
@@ -303,7 +303,7 @@ extern size_t iommufd_test_memory_limit;
 void iommufd_test_syz_conv_iova_id(struct iommufd_ucmd *ucmd,
 				   unsigned int ioas_id, u64 *iova, u32 *flags);
 bool iommufd_should_fail(void);
-void __init iommufd_test_init(void);
+int __init iommufd_test_init(void);
 void iommufd_test_exit(void);
 bool iommufd_selftest_is_mock_dev(struct device *dev);
 #else
@@ -316,8 +316,9 @@ static inline bool iommufd_should_fail(void)
 {
 	return false;
 }
-static inline void __init iommufd_test_init(void)
+static inline int __init iommufd_test_init(void)
 {
+	return 0;
 }
 static inline void iommufd_test_exit(void)
 {
diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c
index 3fbe636c3d8a69..042d45cc0b1c0d 100644
--- a/drivers/iommu/iommufd/main.c
+++ b/drivers/iommu/iommufd/main.c
@@ -437,8 +437,14 @@ static int __init iommufd_init(void)
 		if (ret)
 			goto err_misc;
 	}
-	iommufd_test_init();
+	ret = iommufd_test_init();
+	if (ret)
+		goto err_vfio_misc;
 	return 0;
+
+err_vfio_misc:
+	if (IS_ENABLED(CONFIG_IOMMUFD_VFIO_CONTAINER))
+		misc_deregister(&vfio_misc_dev);
 err_misc:
 	misc_deregister(&iommu_misc_dev);
 	return ret;
diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c
index 74c2076105d486..5433c9c545526d 100644
--- a/drivers/iommu/iommufd/selftest.c
+++ b/drivers/iommu/iommufd/selftest.c
@@ -9,14 +9,17 @@
 #include <linux/file.h>
 #include <linux/anon_inodes.h>
 #include <linux/fault-inject.h>
+#include <linux/platform_device.h>
 #include <uapi/linux/iommufd.h>
 
+#include "../iommu-priv.h"
 #include "io_pagetable.h"
 #include "iommufd_private.h"
 #include "iommufd_test.h"
 
 static DECLARE_FAULT_ATTR(fail_iommufd);
 static struct dentry *dbgfs_root;
+static struct platform_device *selftest_iommu_dev;
 
 size_t iommufd_test_memory_limit = 65536;
 
@@ -108,10 +111,6 @@ struct selftest_obj {
 	};
 };
 
-static void mock_domain_blocking_free(struct iommu_domain *domain)
-{
-}
-
 static int mock_domain_nop_attach(struct iommu_domain *domain,
 				  struct device *dev)
 {
@@ -119,7 +118,6 @@ static int mock_domain_nop_attach(struct iommu_domain *domain,
 }
 
 static const struct iommu_domain_ops mock_blocking_ops = {
-	.free = mock_domain_blocking_free,
 	.attach_dev = mock_domain_nop_attach,
 };
 
@@ -268,20 +266,26 @@ static bool mock_domain_capable(struct device *dev, enum iommu_cap cap)
 	return cap == IOMMU_CAP_CACHE_COHERENCY;
 }
 
-static void mock_domain_set_plaform_dma_ops(struct device *dev)
+static struct iommu_device mock_iommu_device = {
+};
+
+static struct iommu_device *mock_probe_device(struct device *dev)
 {
-	/*
-	 * mock doesn't setup default domains because we can't hook into the
-	 * normal probe path
-	 */
+	return &mock_iommu_device;
 }
 
 static const struct iommu_ops mock_ops = {
+	/*
+	 * IOMMU_DOMAIN_BLOCKED cannot be returned from def_domain_type()
+	 * because it is zero.
+	 */
+	.default_domain = &mock_blocking_domain,
 	.owner = THIS_MODULE,
 	.pgsize_bitmap = MOCK_IO_PAGE_SIZE,
 	.domain_alloc = mock_domain_alloc,
 	.capable = mock_domain_capable,
-	.set_platform_dma_ops = mock_domain_set_plaform_dma_ops,
+	.device_group = generic_device_group,
+	.probe_device = mock_probe_device,
 	.default_domain_ops =
 		&(struct iommu_domain_ops){
 			.free = mock_domain_free,
@@ -292,10 +296,6 @@ static const struct iommu_ops mock_ops = {
 		},
 };
 
-static struct iommu_device mock_iommu_device = {
-	.ops = &mock_ops,
-};
-
 static inline struct iommufd_hw_pagetable *
 get_md_pagetable(struct iommufd_ucmd *ucmd, u32 mockpt_id,
 		 struct mock_iommu_domain **mock)
@@ -316,22 +316,29 @@ get_md_pagetable(struct iommufd_ucmd *ucmd, u32 mockpt_id,
 	return hwpt;
 }
 
-static struct bus_type iommufd_mock_bus_type = {
-	.name = "iommufd_mock",
-	.iommu_ops = &mock_ops,
+struct mock_bus_type {
+	struct bus_type bus;
+	struct notifier_block nb;
 };
 
+static struct mock_bus_type iommufd_mock_bus_type = {
+	.bus = {
+		.name = "iommufd_mock",
+	},
+};
+
+static atomic_t mock_dev_num;
+
 static void mock_dev_release(struct device *dev)
 {
 	struct mock_dev *mdev = container_of(dev, struct mock_dev, dev);
 
+	atomic_dec(&mock_dev_num);
 	kfree(mdev);
 }
 
 static struct mock_dev *mock_dev_create(void)
 {
-	struct iommu_group *iommu_group;
-	struct dev_iommu *dev_iommu;
 	struct mock_dev *mdev;
 	int rc;
 
@@ -341,51 +348,18 @@ static struct mock_dev *mock_dev_create(void)
 
 	device_initialize(&mdev->dev);
 	mdev->dev.release = mock_dev_release;
-	mdev->dev.bus = &iommufd_mock_bus_type;
-
-	iommu_group = iommu_group_alloc();
-	if (IS_ERR(iommu_group)) {
-		rc = PTR_ERR(iommu_group);
-		goto err_put;
-	}
+	mdev->dev.bus = &iommufd_mock_bus_type.bus;
 
 	rc = dev_set_name(&mdev->dev, "iommufd_mock%u",
-			  iommu_group_id(iommu_group));
+			  atomic_inc_return(&mock_dev_num));
 	if (rc)
-		goto err_group;
-
-	/*
-	 * The iommu core has no way to associate a single device with an iommu
-	 * driver (heck currently it can't even support two iommu_drivers
-	 * registering). Hack it together with an open coded dev_iommu_get().
-	 * Notice that the normal notifier triggered iommu release process also
-	 * does not work here because this bus is not in iommu_buses.
-	 */
-	mdev->dev.iommu = kzalloc(sizeof(*dev_iommu), GFP_KERNEL);
-	if (!mdev->dev.iommu) {
-		rc = -ENOMEM;
-		goto err_group;
-	}
-	mutex_init(&mdev->dev.iommu->lock);
-	mdev->dev.iommu->iommu_dev = &mock_iommu_device;
+		goto err_put;
 
 	rc = device_add(&mdev->dev);
 	if (rc)
-		goto err_dev_iommu;
-
-	rc = iommu_group_add_device(iommu_group, &mdev->dev);
-	if (rc)
-		goto err_del;
-	iommu_group_put(iommu_group);
+		goto err_put;
 	return mdev;
 
-err_del:
-	device_del(&mdev->dev);
-err_dev_iommu:
-	kfree(mdev->dev.iommu);
-	mdev->dev.iommu = NULL;
-err_group:
-	iommu_group_put(iommu_group);
 err_put:
 	put_device(&mdev->dev);
 	return ERR_PTR(rc);
@@ -393,11 +367,7 @@ static struct mock_dev *mock_dev_create(void)
 
 static void mock_dev_destroy(struct mock_dev *mdev)
 {
-	iommu_group_remove_device(&mdev->dev);
-	device_del(&mdev->dev);
-	kfree(mdev->dev.iommu);
-	mdev->dev.iommu = NULL;
-	put_device(&mdev->dev);
+	device_unregister(&mdev->dev);
 }
 
 bool iommufd_selftest_is_mock_dev(struct device *dev)
@@ -443,9 +413,14 @@ static int iommufd_test_mock_domain(struct iommufd_ucmd *ucmd,
 	/* Userspace must destroy the device_id to destroy the object */
 	cmd->mock_domain.out_hwpt_id = pt_id;
 	cmd->mock_domain.out_stdev_id = sobj->obj.id;
+	rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
+	if (rc)
+		goto out_detach;
 	iommufd_object_finalize(ucmd->ictx, &sobj->obj);
-	return iommufd_ucmd_respond(ucmd, sizeof(*cmd));
+	return 0;
 
+out_detach:
+	iommufd_device_detach(idev);
 out_unbind:
 	iommufd_device_unbind(idev);
 out_mdev:
@@ -992,15 +967,49 @@ bool iommufd_should_fail(void)
 	return should_fail(&fail_iommufd, 1);
 }
 
-void __init iommufd_test_init(void)
+int __init iommufd_test_init(void)
 {
+	struct platform_device_info pdevinfo = {
+		.name = "iommufd_selftest_iommu",
+	};
+	int rc;
+
 	dbgfs_root =
 		fault_create_debugfs_attr("fail_iommufd", NULL, &fail_iommufd);
-	WARN_ON(bus_register(&iommufd_mock_bus_type));
+
+	selftest_iommu_dev = platform_device_register_full(&pdevinfo);
+	if (IS_ERR(selftest_iommu_dev)) {
+		rc = PTR_ERR(selftest_iommu_dev);
+		goto err_dbgfs;
+	}
+
+	rc = bus_register(&iommufd_mock_bus_type.bus);
+	if (rc)
+		goto err_platform;
+
+	mock_iommu_device.dev = &selftest_iommu_dev->dev;
+	rc = iommu_device_register_bus(&mock_iommu_device, &mock_ops,
+				  &iommufd_mock_bus_type.bus,
+				  &iommufd_mock_bus_type.nb);
+	if (rc)
+		goto err_bus;
+	return 0;
+
+err_bus:
+	bus_unregister(&iommufd_mock_bus_type.bus);
+err_platform:
+	platform_device_del(selftest_iommu_dev);
+err_dbgfs:
+	debugfs_remove_recursive(dbgfs_root);
+	return rc;
 }
 
 void iommufd_test_exit(void)
 {
+	iommu_device_unregister_bus(&mock_iommu_device,
+				    &iommufd_mock_bus_type.bus,
+				    &iommufd_mock_bus_type.nb);
+	bus_unregister(&iommufd_mock_bus_type.bus);
+	platform_device_del(selftest_iommu_dev);
 	debugfs_remove_recursive(dbgfs_root);
-	bus_unregister(&iommufd_mock_bus_type);
 }
-- 
2.40.1



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

* [PATCH v2 16/25] iommu: Remove ops->set_platform_dma_ops()
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (14 preceding siblings ...)
  2023-05-16  0:00   ` [PATCH v2 15/25] iommufd/selftest: Make the mock iommu driver into a real driver Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-05-16  0:00   ` [PATCH v2 17/25] iommu/qcom_iommu: Add an IOMMU_IDENTITIY_DOMAIN Jason Gunthorpe
                     ` (11 subsequent siblings)
  27 siblings, 0 replies; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

All drivers are now using IDENTITY or PLATFORM domains for what this did,
we can remove it now. It is no longer possible to attach to a NULL domain.

Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/iommu.c | 30 +++++-------------------------
 include/linux/iommu.h |  4 ----
 2 files changed, 5 insertions(+), 29 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index f9f11ad918f673..af8b91d15462f3 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -2259,21 +2259,8 @@ static int __iommu_group_set_domain_internal(struct iommu_group *group,
 	if (group->domain == new_domain)
 		return 0;
 
-	/*
-	 * New drivers should support default domains, so set_platform_dma()
-	 * op will never be called. Otherwise the NULL domain represents some
-	 * platform specific behavior.
-	 */
-	if (!new_domain) {
-		for_each_group_device(group, gdev) {
-			const struct iommu_ops *ops = dev_iommu_ops(gdev->dev);
-
-			if (!WARN_ON(!ops->set_platform_dma_ops))
-				ops->set_platform_dma_ops(gdev->dev);
-		}
-		group->domain = NULL;
-		return 0;
-	}
+	if (WARN_ON(!new_domain))
+		return -EINVAL;
 
 	/*
 	 * Changing the domain is done by calling attach_dev() on the new
@@ -2309,19 +2296,15 @@ static int __iommu_group_set_domain_internal(struct iommu_group *group,
 	 */
 	last_gdev = gdev;
 	for_each_group_device(group, gdev) {
-		const struct iommu_ops *ops = dev_iommu_ops(gdev->dev);
-
 		/*
-		 * If set_platform_dma_ops is not present a NULL domain can
-		 * happen only for first probe, in which case we leave
-		 * group->domain as NULL and let release clean everything up.
+		 * A NULL domain can happen only for first probe, in which case
+		 * we leave group->domain as NULL and let release clean
+		 * everything up.
 		 */
 		if (group->domain)
 			WARN_ON(__iommu_device_set_domain(
 				group, gdev->dev, group->domain,
 				IOMMU_SET_DOMAIN_MUST_SUCCEED));
-		else if (ops->set_platform_dma_ops)
-			ops->set_platform_dma_ops(gdev->dev);
 		if (gdev == last_gdev)
 			break;
 	}
@@ -2935,9 +2918,6 @@ static int iommu_setup_default_domain(struct iommu_group *group,
 	/*
 	 * There are still some drivers which don't support default domains, so
 	 * we ignore the failure and leave group->default_domain NULL.
-	 *
-	 * We assume that the iommu driver starts up the device in
-	 * 'set_platform_dma_ops' mode if it does not support default domains.
 	 */
 	dom = iommu_group_alloc_default_domain(group, req_type);
 	if (!dom) {
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index ddd284f8e5b768..387746f8273c99 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -231,9 +231,6 @@ struct iommu_iotlb_gather {
  * @release_device: Remove device from iommu driver handling
  * @probe_finalize: Do final setup work after the device is added to an IOMMU
  *                  group and attached to the groups domain
- * @set_platform_dma_ops: Returning control back to the platform DMA ops. This op
- *                        is to support old IOMMU drivers, new drivers should use
- *                        default domains, and the common IOMMU DMA ops.
  * @device_group: find iommu group for a particular device
  * @get_resv_regions: Request list of reserved regions for a device
  * @of_xlate: add OF master IDs to iommu grouping
@@ -265,7 +262,6 @@ struct iommu_ops {
 	struct iommu_device *(*probe_device)(struct device *dev);
 	void (*release_device)(struct device *dev);
 	void (*probe_finalize)(struct device *dev);
-	void (*set_platform_dma_ops)(struct device *dev);
 	struct iommu_group *(*device_group)(struct device *dev);
 
 	/* Request/Free a list of reserved regions for a device */
-- 
2.40.1



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

* [PATCH v2 17/25] iommu/qcom_iommu: Add an IOMMU_IDENTITIY_DOMAIN
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (15 preceding siblings ...)
  2023-05-16  0:00   ` [PATCH v2 16/25] iommu: Remove ops->set_platform_dma_ops() Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-05-16  0:00   ` [PATCH v2 18/25] iommu/ipmmu: " Jason Gunthorpe
                     ` (10 subsequent siblings)
  27 siblings, 0 replies; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

This brings back the ops->detach_dev() code that commit
1b932ceddd19 ("iommu: Remove detach_dev callbacks") deleted and turns it
into an IDENTITY domain.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/arm/arm-smmu/qcom_iommu.c | 39 +++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
index a503ed758ec302..9d7b9d8b4386d4 100644
--- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c
+++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
@@ -387,6 +387,44 @@ static int qcom_iommu_attach_dev(struct iommu_domain *domain, struct device *dev
 	return 0;
 }
 
+static int qcom_iommu_identity_attach(struct iommu_domain *identity_domain,
+				      struct device *dev)
+{
+	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
+	struct qcom_iommu_domain *qcom_domain;
+	struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
+	struct qcom_iommu_dev *qcom_iommu = to_iommu(dev);
+	unsigned int i;
+
+	if (domain == identity_domain || !domain)
+		return 0;
+
+	qcom_domain = to_qcom_iommu_domain(domain);
+	if (WARN_ON(!qcom_domain->iommu))
+		return -EINVAL;
+
+	pm_runtime_get_sync(qcom_iommu->dev);
+	for (i = 0; i < fwspec->num_ids; i++) {
+		struct qcom_iommu_ctx *ctx = to_ctx(qcom_domain, fwspec->ids[i]);
+
+		/* Disable the context bank: */
+		iommu_writel(ctx, ARM_SMMU_CB_SCTLR, 0);
+
+		ctx->domain = NULL;
+	}
+	pm_runtime_put_sync(qcom_iommu->dev);
+	return 0;
+}
+
+static struct iommu_domain_ops qcom_iommu_identity_ops = {
+	.attach_dev = qcom_iommu_identity_attach,
+};
+
+static struct iommu_domain qcom_iommu_identity_domain = {
+	.type = IOMMU_DOMAIN_IDENTITY,
+	.ops = &qcom_iommu_identity_ops,
+};
+
 static int qcom_iommu_map(struct iommu_domain *domain, unsigned long iova,
 			  phys_addr_t paddr, size_t pgsize, size_t pgcount,
 			  int prot, gfp_t gfp, size_t *mapped)
@@ -553,6 +591,7 @@ static int qcom_iommu_of_xlate(struct device *dev, struct of_phandle_args *args)
 }
 
 static const struct iommu_ops qcom_iommu_ops = {
+	.identity_domain = &qcom_iommu_identity_domain,
 	.capable	= qcom_iommu_capable,
 	.domain_alloc	= qcom_iommu_domain_alloc,
 	.probe_device	= qcom_iommu_probe_device,
-- 
2.40.1



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

* [PATCH v2 18/25] iommu/ipmmu: Add an IOMMU_IDENTITIY_DOMAIN
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (16 preceding siblings ...)
  2023-05-16  0:00   ` [PATCH v2 17/25] iommu/qcom_iommu: Add an IOMMU_IDENTITIY_DOMAIN Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-05-16  0:00   ` [PATCH v2 19/25] iommu/mtk_iommu: " Jason Gunthorpe
                     ` (9 subsequent siblings)
  27 siblings, 0 replies; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

This brings back the ops->detach_dev() code that commit
1b932ceddd19 ("iommu: Remove detach_dev callbacks") deleted and turns it
into an IDENTITY domain.

Also reverts commit 584d334b1393 ("iommu/ipmmu-vmsa: Remove
ipmmu_utlb_disable()")

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/ipmmu-vmsa.c | 43 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c
index 9f64c5c9f5b90a..de958e411a92e0 100644
--- a/drivers/iommu/ipmmu-vmsa.c
+++ b/drivers/iommu/ipmmu-vmsa.c
@@ -298,6 +298,18 @@ static void ipmmu_utlb_enable(struct ipmmu_vmsa_domain *domain,
 	mmu->utlb_ctx[utlb] = domain->context_id;
 }
 
+/*
+ * Disable MMU translation for the microTLB.
+ */
+static void ipmmu_utlb_disable(struct ipmmu_vmsa_domain *domain,
+			       unsigned int utlb)
+{
+	struct ipmmu_vmsa_device *mmu = domain->mmu;
+
+	ipmmu_imuctr_write(mmu, utlb, 0);
+	mmu->utlb_ctx[utlb] = IPMMU_CTX_INVALID;
+}
+
 static void ipmmu_tlb_flush_all(void *cookie)
 {
 	struct ipmmu_vmsa_domain *domain = cookie;
@@ -630,6 +642,36 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain,
 	return 0;
 }
 
+static int ipmmu_iommu_identity_attach(struct iommu_domain *identity_domain,
+				       struct device *dev)
+{
+	struct iommu_domain *io_domain = iommu_get_domain_for_dev(dev);
+	struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
+	struct ipmmu_vmsa_domain *domain;
+	unsigned int i;
+
+	if (io_domain == identity_domain || !io_domain)
+		return 0;
+
+	domain = to_vmsa_domain(io_domain);
+	for (i = 0; i < fwspec->num_ids; ++i)
+		ipmmu_utlb_disable(domain, fwspec->ids[i]);
+
+	/*
+	 * TODO: Optimize by disabling the context when no device is attached.
+	 */
+	return 0;
+}
+
+static struct iommu_domain_ops ipmmu_iommu_identity_ops = {
+	.attach_dev = ipmmu_iommu_identity_attach,
+};
+
+static struct iommu_domain ipmmu_iommu_identity_domain = {
+	.type = IOMMU_DOMAIN_IDENTITY,
+	.ops = &ipmmu_iommu_identity_ops,
+};
+
 static int ipmmu_map(struct iommu_domain *io_domain, unsigned long iova,
 		     phys_addr_t paddr, size_t pgsize, size_t pgcount,
 		     int prot, gfp_t gfp, size_t *mapped)
@@ -848,6 +890,7 @@ static struct iommu_group *ipmmu_find_group(struct device *dev)
 }
 
 static const struct iommu_ops ipmmu_ops = {
+	.identity_domain = &ipmmu_iommu_identity_domain,
 	.domain_alloc = ipmmu_domain_alloc,
 	.probe_device = ipmmu_probe_device,
 	.release_device = ipmmu_release_device,
-- 
2.40.1



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

* [PATCH v2 19/25] iommu/mtk_iommu: Add an IOMMU_IDENTITIY_DOMAIN
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (17 preceding siblings ...)
  2023-05-16  0:00   ` [PATCH v2 18/25] iommu/ipmmu: " Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-05-16  0:00   ` [PATCH v2 20/25] iommu/sun50i: " Jason Gunthorpe
                     ` (8 subsequent siblings)
  27 siblings, 0 replies; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

This brings back the ops->detach_dev() code that commit
1b932ceddd19 ("iommu: Remove detach_dev callbacks") deleted and turns it
into an IDENTITY domain.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/mtk_iommu.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
index aecc7d154f28ee..e4b9f728002403 100644
--- a/drivers/iommu/mtk_iommu.c
+++ b/drivers/iommu/mtk_iommu.c
@@ -753,6 +753,28 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain,
 	return ret;
 }
 
+static int mtk_iommu_identity_attach(struct iommu_domain *identity_domain,
+				     struct device *dev)
+{
+	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
+	struct mtk_iommu_data *data = dev_iommu_priv_get(dev);
+
+	if (domain == identity_domain || !domain)
+		return 0;
+
+	mtk_iommu_config(data, dev, false, 0);
+	return 0;
+}
+
+static struct iommu_domain_ops mtk_iommu_identity_ops = {
+	.attach_dev = mtk_iommu_identity_attach,
+};
+
+static struct iommu_domain mtk_iommu_identity_domain = {
+	.type = IOMMU_DOMAIN_IDENTITY,
+	.ops = &mtk_iommu_identity_ops,
+};
+
 static int mtk_iommu_map(struct iommu_domain *domain, unsigned long iova,
 			 phys_addr_t paddr, size_t pgsize, size_t pgcount,
 			 int prot, gfp_t gfp, size_t *mapped)
@@ -971,6 +993,7 @@ static void mtk_iommu_get_resv_regions(struct device *dev,
 }
 
 static const struct iommu_ops mtk_iommu_ops = {
+	.identity_domain = &mtk_iommu_identity_domain,
 	.domain_alloc	= mtk_iommu_domain_alloc,
 	.probe_device	= mtk_iommu_probe_device,
 	.release_device	= mtk_iommu_release_device,
-- 
2.40.1



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

* [PATCH v2 20/25] iommu/sun50i: Add an IOMMU_IDENTITIY_DOMAIN
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (18 preceding siblings ...)
  2023-05-16  0:00   ` [PATCH v2 19/25] iommu/mtk_iommu: " Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-05-16  0:00   ` [PATCH v2 21/25] iommu: Require a default_domain for all iommu drivers Jason Gunthorpe
                     ` (7 subsequent siblings)
  27 siblings, 0 replies; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

Prior to commit 1b932ceddd19 ("iommu: Remove detach_dev callbacks") the
sun50i_iommu_detach_device() function was being called by
ops->detach_dev().

This is an IDENTITY domain so convert sun50i_iommu_detach_device() into
sun50i_iommu_identity_attach() and a full IDENTITY domain and thus hook it
back up the same was as the old ops->detach_dev().

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/sun50i-iommu.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c
index 74c5cb93e90027..0bf08b120cf105 100644
--- a/drivers/iommu/sun50i-iommu.c
+++ b/drivers/iommu/sun50i-iommu.c
@@ -757,21 +757,32 @@ static void sun50i_iommu_detach_domain(struct sun50i_iommu *iommu,
 	iommu->domain = NULL;
 }
 
-static void sun50i_iommu_detach_device(struct iommu_domain *domain,
-				       struct device *dev)
+static int sun50i_iommu_identity_attach(struct iommu_domain *identity_domain,
+					struct device *dev)
 {
-	struct sun50i_iommu_domain *sun50i_domain = to_sun50i_domain(domain);
 	struct sun50i_iommu *iommu = dev_iommu_priv_get(dev);
+	struct sun50i_iommu_domain *sun50i_domain;
 
 	dev_dbg(dev, "Detaching from IOMMU domain\n");
 
-	if (iommu->domain != domain)
-		return;
+	if (iommu->domain == identity_domain)
+		return 0;
 
+	sun50i_domain = to_sun50i_domain(iommu->domain);
 	if (refcount_dec_and_test(&sun50i_domain->refcnt))
 		sun50i_iommu_detach_domain(iommu, sun50i_domain);
+	return 0;
 }
 
+static struct iommu_domain_ops sun50i_iommu_identity_ops = {
+	.attach_dev = sun50i_iommu_identity_attach,
+};
+
+static struct iommu_domain sun50i_iommu_identity_domain = {
+	.type = IOMMU_DOMAIN_IDENTITY,
+	.ops = &sun50i_iommu_identity_ops,
+};
+
 static int sun50i_iommu_attach_device(struct iommu_domain *domain,
 				      struct device *dev)
 {
@@ -789,8 +800,7 @@ static int sun50i_iommu_attach_device(struct iommu_domain *domain,
 	if (iommu->domain == domain)
 		return 0;
 
-	if (iommu->domain)
-		sun50i_iommu_detach_device(iommu->domain, dev);
+	sun50i_iommu_identity_attach(&sun50i_iommu_identity_domain, dev);
 
 	sun50i_iommu_attach_domain(iommu, sun50i_domain);
 
@@ -827,6 +837,7 @@ static int sun50i_iommu_of_xlate(struct device *dev,
 }
 
 static const struct iommu_ops sun50i_iommu_ops = {
+	.identity_domain = &sun50i_iommu_identity_domain,
 	.pgsize_bitmap	= SZ_4K,
 	.device_group	= sun50i_iommu_device_group,
 	.domain_alloc	= sun50i_iommu_domain_alloc,
@@ -985,6 +996,7 @@ static int sun50i_iommu_probe(struct platform_device *pdev)
 	if (!iommu)
 		return -ENOMEM;
 	spin_lock_init(&iommu->iommu_lock);
+	iommu->domain = &sun50i_iommu_identity_domain;
 	platform_set_drvdata(pdev, iommu);
 	iommu->dev = &pdev->dev;
 
-- 
2.40.1



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

* [PATCH v2 21/25] iommu: Require a default_domain for all iommu drivers
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (19 preceding siblings ...)
  2023-05-16  0:00   ` [PATCH v2 20/25] iommu/sun50i: " Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-05-16  0:00   ` [PATCH v2 22/25] iommu: Add __iommu_group_domain_alloc() Jason Gunthorpe
                     ` (6 subsequent siblings)
  27 siblings, 0 replies; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

At this point every iommu driver will cause a default_domain to be
selected, so we can finally remove this gap from the core code.

The following table explains what each driver supports and what the
resulting default_domain will be:

                                        ops->defaut_domain
                    IDENTITY   DMA  PLATFORM    v      ARM32          dma-iommu  ARCH
amd/iommu.c             Y       Y                       N/A             either
apple-dart.c            Y       Y                       N/A             either
arm-smmu.c              Y       Y                       IDENTITY        either
qcom_iommu.c            G       Y                       IDENTITY        either
arm-smmu-v3.c           Y       Y                       N/A             either
exynos-iommu.c          G       Y                       IDENTITY        either
fsl_pamu_domain.c       Y                               N/A             N/A     PLATFORM
intel/iommu.c           Y       Y                       N/A             either
ipmmu-vmsa.c            G       Y                       IDENTITY        either
msm_iommu.c             G                               IDENTITY        N/A
mtk_iommu.c             G       Y                       IDENTITY        either
mtk_iommu_v1.c          G                               IDENTITY        N/A
omap-iommu.c            G                               IDENTITY        N/A
rockchip-iommu.c        G       Y                       IDENTITY        either
s390-iommu.c                            Y       Y       N/A             N/A     PLATFORM
sprd-iommu.c                    Y                       N/A             DMA
sun50i-iommu.c          G       Y                       IDENTITY        either
tegra-smmu.c            G       Y                       IDENTITY        IDENTITY
virtio-iommu.c          Y       Y                       N/A             either
spapr                                   Y       Y       N/A             N/A     PLATFORM
 * G means ops->identity_domain is used
 * N/A means the driver will not compile in this configuration

ARM32 drivers select an IDENTITY default domain through either the
ops->identity_domain or directly requesting an IDENTIY domain through
alloc_domain().

In ARM64 mode tegra-smmu will still block the use of dma-iommu.c and
forces an IDENTITY domain.

S390 uses a PLATFORM domain to represent when the dma_ops are set to the
s390 iommu code.

fsl_pamu uses an IDENTITY domain.

POWER SPAPR uses PLATFORM and blocking to enable its weird VFIO mode.

The x86 drivers continue unchanged.

After this patch group->default_domain is only NULL for a short period
during bus iommu probing while all the groups are constituted. Otherwise
it is always !NULL.

This completes changing the iommu subsystem driver contract to a system
where the current iommu_domain always represents some form of translation
and the driver is continuously asserting a definable translation mode.

It resolves the confusion that the original ops->detach_dev() caused
around what translation, exactly, is the IOMMU performing after
detach. There were at least three different answers to that question in
the tree, they are all now clearly named with domain types.

Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/iommu.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index af8b91d15462f3..15cdfca4011ef2 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1805,10 +1805,12 @@ static int iommu_get_default_domain_type(struct iommu_group *group,
 	 * ARM32 drivers supporting CONFIG_ARM_DMA_USE_IOMMU can declare an
 	 * identity_domain and it will automatically become their default
 	 * domain. Later on ARM_DMA_USE_IOMMU will install its UNMANAGED domain.
-	 * Override the selection to IDENTITY if we are sure the driver supports
-	 * it.
+	 * Override the selection to IDENTITY.
 	 */
-	if (IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU) && ops->identity_domain) {
+	if (IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU)) {
+		static_assert(!(IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU) &&
+				IS_ENABLED(CONFIG_IOMMU_DMA)));
+
 		type = IOMMU_DOMAIN_IDENTITY;
 		if (best_type && type && best_type != type)
 			goto err;
@@ -2915,18 +2917,9 @@ static int iommu_setup_default_domain(struct iommu_group *group,
 	if (req_type < 0)
 		return -EINVAL;
 
-	/*
-	 * There are still some drivers which don't support default domains, so
-	 * we ignore the failure and leave group->default_domain NULL.
-	 */
 	dom = iommu_group_alloc_default_domain(group, req_type);
-	if (!dom) {
-		/* Once in default_domain mode we never leave */
-		if (group->default_domain)
-			return -ENODEV;
-		group->default_domain = NULL;
-		return 0;
-	}
+	if (!dom)
+		return -ENODEV;
 
 	if (group->default_domain == dom)
 		return 0;
-- 
2.40.1



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

* [PATCH v2 22/25] iommu: Add __iommu_group_domain_alloc()
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (20 preceding siblings ...)
  2023-05-16  0:00   ` [PATCH v2 21/25] iommu: Require a default_domain for all iommu drivers Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-05-16  0:00   ` [PATCH v2 23/25] iommu: Add ops->domain_alloc_paging() Jason Gunthorpe
                     ` (5 subsequent siblings)
  27 siblings, 0 replies; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

Allocate a domain from a group. Automatically obtains the iommu_ops to use
from the device list of the group. Convert the internal callers to use it.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/iommu.c | 66 ++++++++++++++++++++++++-------------------
 1 file changed, 37 insertions(+), 29 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 15cdfca4011ef2..c4cac1dcf80610 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -94,8 +94,8 @@ static const char * const iommu_group_resv_type_string[] = {
 static int iommu_bus_notifier(struct notifier_block *nb,
 			      unsigned long action, void *data);
 static void iommu_release_device(struct device *dev);
-static struct iommu_domain *__iommu_domain_alloc(const struct bus_type *bus,
-						 unsigned type);
+static struct iommu_domain *
+__iommu_group_domain_alloc(struct iommu_group *group, unsigned int type);
 static int __iommu_attach_device(struct iommu_domain *domain,
 				 struct device *dev);
 static int __iommu_attach_group(struct iommu_domain *domain,
@@ -1652,12 +1652,11 @@ struct iommu_group *fsl_mc_device_group(struct device *dev)
 EXPORT_SYMBOL_GPL(fsl_mc_device_group);
 
 static struct iommu_domain *
-__iommu_group_alloc_default_domain(const struct bus_type *bus,
-				   struct iommu_group *group, int req_type)
+__iommu_group_alloc_default_domain(struct iommu_group *group, int req_type)
 {
 	if (group->default_domain && group->default_domain->type == req_type)
 		return group->default_domain;
-	return __iommu_domain_alloc(bus, req_type);
+	return __iommu_group_domain_alloc(group, req_type);
 }
 
 /*
@@ -1667,9 +1666,10 @@ __iommu_group_alloc_default_domain(const struct bus_type *bus,
 static struct iommu_domain *
 iommu_group_alloc_default_domain(struct iommu_group *group, int req_type)
 {
-	const struct bus_type *bus =
+	struct device *dev =
 		list_first_entry(&group->devices, struct group_device, list)
-			->dev->bus;
+			->dev;
+	const struct iommu_ops *ops = dev_iommu_ops(dev);
 	struct iommu_domain *dom;
 
 	lockdep_assert_held(&group->mutex);
@@ -1679,24 +1679,24 @@ iommu_group_alloc_default_domain(struct iommu_group *group, int req_type)
 	 * domain. This should always be either an IDENTITY or PLATFORM domain.
 	 * Do not use in new drivers.
 	 */
-	if (bus->iommu_ops->default_domain) {
+	if (ops->default_domain) {
 		if (req_type)
 			return ERR_PTR(-EINVAL);
-		return bus->iommu_ops->default_domain;
+		return ops->default_domain;
 	}
 
 	if (req_type)
-		return __iommu_group_alloc_default_domain(bus, group, req_type);
+		return __iommu_group_alloc_default_domain(group, req_type);
 
 	/* The driver gave no guidance on what type to use, try the default */
-	dom = __iommu_group_alloc_default_domain(bus, group, iommu_def_domain_type);
+	dom = __iommu_group_alloc_default_domain(group, iommu_def_domain_type);
 	if (dom)
 		return dom;
 
 	/* Otherwise IDENTITY and DMA_FQ defaults will try DMA */
 	if (iommu_def_domain_type == IOMMU_DOMAIN_DMA)
 		return NULL;
-	dom = __iommu_group_alloc_default_domain(bus, group, IOMMU_DOMAIN_DMA);
+	dom = __iommu_group_alloc_default_domain(group, IOMMU_DOMAIN_DMA);
 	if (!dom)
 		return NULL;
 
@@ -1994,18 +1994,15 @@ void iommu_set_fault_handler(struct iommu_domain *domain,
 }
 EXPORT_SYMBOL_GPL(iommu_set_fault_handler);
 
-static struct iommu_domain *__iommu_domain_alloc(const struct bus_type *bus,
-						 unsigned type)
+static struct iommu_domain *__iommu_domain_alloc(const struct iommu_ops *ops,
+						 unsigned int type)
 {
 	struct iommu_domain *domain;
 
-	if (bus == NULL || bus->iommu_ops == NULL)
-		return NULL;
+	if (type == IOMMU_DOMAIN_IDENTITY && ops->identity_domain)
+		return ops->identity_domain;
 
-	if (type == IOMMU_DOMAIN_IDENTITY && bus->iommu_ops->identity_domain)
-		return bus->iommu_ops->identity_domain;
-
-	domain = bus->iommu_ops->domain_alloc(type);
+	domain = ops->domain_alloc(type);
 	if (!domain)
 		return NULL;
 
@@ -2015,10 +2012,10 @@ static struct iommu_domain *__iommu_domain_alloc(const struct bus_type *bus,
 	 * may override this later
 	 */
 	if (!domain->pgsize_bitmap)
-		domain->pgsize_bitmap = bus->iommu_ops->pgsize_bitmap;
+		domain->pgsize_bitmap = ops->pgsize_bitmap;
 
 	if (!domain->ops)
-		domain->ops = bus->iommu_ops->default_domain_ops;
+		domain->ops = ops->default_domain_ops;
 
 	if (iommu_is_dma_domain(domain) && iommu_get_dma_cookie(domain)) {
 		iommu_domain_free(domain);
@@ -2027,9 +2024,23 @@ static struct iommu_domain *__iommu_domain_alloc(const struct bus_type *bus,
 	return domain;
 }
 
+static struct iommu_domain *
+__iommu_group_domain_alloc(struct iommu_group *group, unsigned int type)
+{
+	struct device *dev =
+		list_first_entry(&group->devices, struct group_device, list)
+			->dev;
+
+	lockdep_assert_held(&group->mutex);
+
+	return __iommu_domain_alloc(dev_iommu_ops(dev), type);
+}
+
 struct iommu_domain *iommu_domain_alloc(const struct bus_type *bus)
 {
-	return __iommu_domain_alloc(bus, IOMMU_DOMAIN_UNMANAGED);
+	if (bus == NULL || bus->iommu_ops == NULL)
+		return NULL;
+	return __iommu_domain_alloc(bus->iommu_ops, IOMMU_DOMAIN_UNMANAGED);
 }
 EXPORT_SYMBOL_GPL(iommu_domain_alloc);
 
@@ -3138,21 +3149,18 @@ void iommu_device_unuse_default_domain(struct device *dev)
 
 static int __iommu_group_alloc_blocking_domain(struct iommu_group *group)
 {
-	struct group_device *dev =
-		list_first_entry(&group->devices, struct group_device, list);
-
 	if (group->blocking_domain)
 		return 0;
 
 	group->blocking_domain =
-		__iommu_domain_alloc(dev->dev->bus, IOMMU_DOMAIN_BLOCKED);
+		__iommu_group_domain_alloc(group, IOMMU_DOMAIN_BLOCKED);
 	if (!group->blocking_domain) {
 		/*
 		 * For drivers that do not yet understand IOMMU_DOMAIN_BLOCKED
 		 * create an empty domain instead.
 		 */
-		group->blocking_domain = __iommu_domain_alloc(
-			dev->dev->bus, IOMMU_DOMAIN_UNMANAGED);
+		group->blocking_domain = __iommu_group_domain_alloc(
+			group, IOMMU_DOMAIN_UNMANAGED);
 		if (!group->blocking_domain)
 			return -EINVAL;
 	}
-- 
2.40.1



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

* [PATCH v2 23/25] iommu: Add ops->domain_alloc_paging()
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (21 preceding siblings ...)
  2023-05-16  0:00   ` [PATCH v2 22/25] iommu: Add __iommu_group_domain_alloc() Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-06-01 19:17     ` Robin Murphy
  2023-05-16  0:00   ` [PATCH v2 24/25] iommu: Convert simple drivers with DOMAIN_DMA to domain_alloc_paging() Jason Gunthorpe
                     ` (4 subsequent siblings)
  27 siblings, 1 reply; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

This callback requests the driver to create only a __IOMMU_DOMAIN_PAGING
domain, so it saves a few lines in a lot of drivers needlessly checking
the type.

More critically, this allows us to sweep out all the
IOMMU_DOMAIN_UNMANAGED and IOMMU_DOMAIN_DMA checks from a lot of the
drivers, simplifying what is going on in the code and ultimately removing
the now-unused special cases in drivers where they did not support
IOMMU_DOMAIN_DMA.

domain_alloc_paging() should return a struct iommu_domain that is
functionally compatible with ARM_DMA_USE_IOMMU, dma-iommu.c and iommufd.

Be forwards looking and pass in a 'struct device *' argument. We can
provide this when allocating the default_domain. No drivers will look at
this.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/iommu.c | 18 +++++++++++++++---
 include/linux/iommu.h |  3 +++
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index c4cac1dcf80610..15aa51c356bd74 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1995,14 +1995,25 @@ void iommu_set_fault_handler(struct iommu_domain *domain,
 EXPORT_SYMBOL_GPL(iommu_set_fault_handler);
 
 static struct iommu_domain *__iommu_domain_alloc(const struct iommu_ops *ops,
+						 struct device *dev,
 						 unsigned int type)
 {
 	struct iommu_domain *domain;
 
 	if (type == IOMMU_DOMAIN_IDENTITY && ops->identity_domain)
 		return ops->identity_domain;
+	else if ((type == IOMMU_DOMAIN_UNMANAGED || type == IOMMU_DOMAIN_DMA) &&
+		 ops->domain_alloc_paging) {
+		/*
+		 * For now exclude DMA_FQ since it is still a driver policy
+		 * decision through domain_alloc() if we can use FQ mode.
+		 */
+		domain = ops->domain_alloc_paging(dev);
+	} else if (ops->domain_alloc)
+		domain = ops->domain_alloc(type);
+	else
+		return NULL;
 
-	domain = ops->domain_alloc(type);
 	if (!domain)
 		return NULL;
 
@@ -2033,14 +2044,15 @@ __iommu_group_domain_alloc(struct iommu_group *group, unsigned int type)
 
 	lockdep_assert_held(&group->mutex);
 
-	return __iommu_domain_alloc(dev_iommu_ops(dev), type);
+	return __iommu_domain_alloc(dev_iommu_ops(dev), dev, type);
 }
 
 struct iommu_domain *iommu_domain_alloc(const struct bus_type *bus)
 {
 	if (bus == NULL || bus->iommu_ops == NULL)
 		return NULL;
-	return __iommu_domain_alloc(bus->iommu_ops, IOMMU_DOMAIN_UNMANAGED);
+	return __iommu_domain_alloc(bus->iommu_ops, NULL,
+				    IOMMU_DOMAIN_UNMANAGED);
 }
 EXPORT_SYMBOL_GPL(iommu_domain_alloc);
 
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 387746f8273c99..18b0df42cc80d1 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -227,6 +227,8 @@ struct iommu_iotlb_gather {
  * struct iommu_ops - iommu ops and capabilities
  * @capable: check capability
  * @domain_alloc: allocate iommu domain
+ * @domain_alloc_paging: Allocate an iommu_domain that can be used for
+ *                       UNMANAGED, DMA, and DMA_FQ domain types.
  * @probe_device: Add device to iommu driver handling
  * @release_device: Remove device from iommu driver handling
  * @probe_finalize: Do final setup work after the device is added to an IOMMU
@@ -258,6 +260,7 @@ struct iommu_ops {
 
 	/* Domain allocation and freeing by the iommu driver */
 	struct iommu_domain *(*domain_alloc)(unsigned iommu_domain_type);
+	struct iommu_domain *(*domain_alloc_paging)(struct device *dev);
 
 	struct iommu_device *(*probe_device)(struct device *dev);
 	void (*release_device)(struct device *dev);
-- 
2.40.1



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

* [PATCH v2 24/25] iommu: Convert simple drivers with DOMAIN_DMA to domain_alloc_paging()
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (22 preceding siblings ...)
  2023-05-16  0:00   ` [PATCH v2 23/25] iommu: Add ops->domain_alloc_paging() Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-05-16  0:00   ` [PATCH v2 25/25] iommu: Convert remaining simple drivers " Jason Gunthorpe
                     ` (3 subsequent siblings)
  27 siblings, 0 replies; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

These drivers are all trivially converted since the function is only
called if the domain type is going to be
IOMMU_DOMAIN_UNMANAGED/DMA.

Tested-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/arm/arm-smmu/qcom_iommu.c | 6 ++----
 drivers/iommu/exynos-iommu.c            | 7 ++-----
 drivers/iommu/ipmmu-vmsa.c              | 7 ++-----
 drivers/iommu/mtk_iommu.c               | 7 ++-----
 drivers/iommu/rockchip-iommu.c          | 7 ++-----
 drivers/iommu/sprd-iommu.c              | 7 ++-----
 drivers/iommu/sun50i-iommu.c            | 9 +++------
 drivers/iommu/tegra-smmu.c              | 7 ++-----
 8 files changed, 17 insertions(+), 40 deletions(-)

diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
index 9d7b9d8b4386d4..a2140fdc65ed58 100644
--- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c
+++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
@@ -319,12 +319,10 @@ static int qcom_iommu_init_domain(struct iommu_domain *domain,
 	return ret;
 }
 
-static struct iommu_domain *qcom_iommu_domain_alloc(unsigned type)
+static struct iommu_domain *qcom_iommu_domain_alloc_paging(struct device *dev)
 {
 	struct qcom_iommu_domain *qcom_domain;
 
-	if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA)
-		return NULL;
 	/*
 	 * Allocate the domain and initialise some of its data structures.
 	 * We can't really do anything meaningful until we've added a
@@ -593,7 +591,7 @@ static int qcom_iommu_of_xlate(struct device *dev, struct of_phandle_args *args)
 static const struct iommu_ops qcom_iommu_ops = {
 	.identity_domain = &qcom_iommu_identity_domain,
 	.capable	= qcom_iommu_capable,
-	.domain_alloc	= qcom_iommu_domain_alloc,
+	.domain_alloc_paging = qcom_iommu_domain_alloc_paging,
 	.probe_device	= qcom_iommu_probe_device,
 	.device_group	= generic_device_group,
 	.of_xlate	= qcom_iommu_of_xlate,
diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c
index 5e12b85dfe8705..d6dead2ed10c11 100644
--- a/drivers/iommu/exynos-iommu.c
+++ b/drivers/iommu/exynos-iommu.c
@@ -887,7 +887,7 @@ static inline void exynos_iommu_set_pte(sysmmu_pte_t *ent, sysmmu_pte_t val)
 				   DMA_TO_DEVICE);
 }
 
-static struct iommu_domain *exynos_iommu_domain_alloc(unsigned type)
+static struct iommu_domain *exynos_iommu_domain_alloc_paging(struct device *dev)
 {
 	struct exynos_iommu_domain *domain;
 	dma_addr_t handle;
@@ -896,9 +896,6 @@ static struct iommu_domain *exynos_iommu_domain_alloc(unsigned type)
 	/* Check if correct PTE offsets are initialized */
 	BUG_ON(PG_ENT_SHIFT < 0 || !dma_dev);
 
-	if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED)
-		return NULL;
-
 	domain = kzalloc(sizeof(*domain), GFP_KERNEL);
 	if (!domain)
 		return NULL;
@@ -1472,7 +1469,7 @@ static int exynos_iommu_of_xlate(struct device *dev,
 
 static const struct iommu_ops exynos_iommu_ops = {
 	.identity_domain = &exynos_identity_domain,
-	.domain_alloc = exynos_iommu_domain_alloc,
+	.domain_alloc_paging = exynos_iommu_domain_alloc_paging,
 	.device_group = generic_device_group,
 	.probe_device = exynos_iommu_probe_device,
 	.release_device = exynos_iommu_release_device,
diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c
index de958e411a92e0..27d36347e0fced 100644
--- a/drivers/iommu/ipmmu-vmsa.c
+++ b/drivers/iommu/ipmmu-vmsa.c
@@ -566,13 +566,10 @@ static irqreturn_t ipmmu_irq(int irq, void *dev)
  * IOMMU Operations
  */
 
-static struct iommu_domain *ipmmu_domain_alloc(unsigned type)
+static struct iommu_domain *ipmmu_domain_alloc_paging(struct device *dev)
 {
 	struct ipmmu_vmsa_domain *domain;
 
-	if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA)
-		return NULL;
-
 	domain = kzalloc(sizeof(*domain), GFP_KERNEL);
 	if (!domain)
 		return NULL;
@@ -891,7 +888,7 @@ static struct iommu_group *ipmmu_find_group(struct device *dev)
 
 static const struct iommu_ops ipmmu_ops = {
 	.identity_domain = &ipmmu_iommu_identity_domain,
-	.domain_alloc = ipmmu_domain_alloc,
+	.domain_alloc_paging = ipmmu_domain_alloc_paging,
 	.probe_device = ipmmu_probe_device,
 	.release_device = ipmmu_release_device,
 	.probe_finalize = ipmmu_probe_finalize,
diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
index e4b9f728002403..e0bb10adc62967 100644
--- a/drivers/iommu/mtk_iommu.c
+++ b/drivers/iommu/mtk_iommu.c
@@ -667,13 +667,10 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom,
 	return 0;
 }
 
-static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type)
+static struct iommu_domain *mtk_iommu_domain_alloc_paging(struct device *dev)
 {
 	struct mtk_iommu_domain *dom;
 
-	if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED)
-		return NULL;
-
 	dom = kzalloc(sizeof(*dom), GFP_KERNEL);
 	if (!dom)
 		return NULL;
@@ -994,7 +991,7 @@ static void mtk_iommu_get_resv_regions(struct device *dev,
 
 static const struct iommu_ops mtk_iommu_ops = {
 	.identity_domain = &mtk_iommu_identity_domain,
-	.domain_alloc	= mtk_iommu_domain_alloc,
+	.domain_alloc_paging = mtk_iommu_domain_alloc_paging,
 	.probe_device	= mtk_iommu_probe_device,
 	.release_device	= mtk_iommu_release_device,
 	.device_group	= mtk_iommu_device_group,
diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index 9e1296a856ac4c..24a2a09fea5503 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -1071,13 +1071,10 @@ static int rk_iommu_attach_device(struct iommu_domain *domain,
 	return ret;
 }
 
-static struct iommu_domain *rk_iommu_domain_alloc(unsigned type)
+static struct iommu_domain *rk_iommu_domain_alloc_paging(struct device *dev)
 {
 	struct rk_iommu_domain *rk_domain;
 
-	if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA)
-		return NULL;
-
 	if (!dma_dev)
 		return NULL;
 
@@ -1200,7 +1197,7 @@ static int rk_iommu_of_xlate(struct device *dev,
 
 static const struct iommu_ops rk_iommu_ops = {
 	.identity_domain = &rk_identity_domain,
-	.domain_alloc = rk_iommu_domain_alloc,
+	.domain_alloc_paging = rk_iommu_domain_alloc_paging,
 	.probe_device = rk_iommu_probe_device,
 	.release_device = rk_iommu_release_device,
 	.device_group = rk_iommu_device_group,
diff --git a/drivers/iommu/sprd-iommu.c b/drivers/iommu/sprd-iommu.c
index 39e34fdeccda78..af68b3a2c123ab 100644
--- a/drivers/iommu/sprd-iommu.c
+++ b/drivers/iommu/sprd-iommu.c
@@ -133,13 +133,10 @@ sprd_iommu_pgt_size(struct iommu_domain *domain)
 		SPRD_IOMMU_PAGE_SHIFT) * sizeof(u32);
 }
 
-static struct iommu_domain *sprd_iommu_domain_alloc(unsigned int domain_type)
+static struct iommu_domain *sprd_iommu_domain_alloc_paging(struct device *dev)
 {
 	struct sprd_iommu_domain *dom;
 
-	if (domain_type != IOMMU_DOMAIN_DMA && domain_type != IOMMU_DOMAIN_UNMANAGED)
-		return NULL;
-
 	dom = kzalloc(sizeof(*dom), GFP_KERNEL);
 	if (!dom)
 		return NULL;
@@ -419,7 +416,7 @@ static int sprd_iommu_of_xlate(struct device *dev, struct of_phandle_args *args)
 
 
 static const struct iommu_ops sprd_iommu_ops = {
-	.domain_alloc	= sprd_iommu_domain_alloc,
+	.domain_alloc_paging = sprd_iommu_domain_alloc_paging,
 	.probe_device	= sprd_iommu_probe_device,
 	.device_group	= sprd_iommu_device_group,
 	.of_xlate	= sprd_iommu_of_xlate,
diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c
index 0bf08b120cf105..056832a367c2af 100644
--- a/drivers/iommu/sun50i-iommu.c
+++ b/drivers/iommu/sun50i-iommu.c
@@ -667,14 +667,11 @@ static phys_addr_t sun50i_iommu_iova_to_phys(struct iommu_domain *domain,
 		sun50i_iova_get_page_offset(iova);
 }
 
-static struct iommu_domain *sun50i_iommu_domain_alloc(unsigned type)
+static struct iommu_domain *
+sun50i_iommu_domain_alloc_paging(struct device *paging)
 {
 	struct sun50i_iommu_domain *sun50i_domain;
 
-	if (type != IOMMU_DOMAIN_DMA &&
-	    type != IOMMU_DOMAIN_UNMANAGED)
-		return NULL;
-
 	sun50i_domain = kzalloc(sizeof(*sun50i_domain), GFP_KERNEL);
 	if (!sun50i_domain)
 		return NULL;
@@ -840,7 +837,7 @@ static const struct iommu_ops sun50i_iommu_ops = {
 	.identity_domain = &sun50i_iommu_identity_domain,
 	.pgsize_bitmap	= SZ_4K,
 	.device_group	= sun50i_iommu_device_group,
-	.domain_alloc	= sun50i_iommu_domain_alloc,
+	.domain_alloc_paging = sun50i_iommu_domain_alloc_paging,
 	.of_xlate	= sun50i_iommu_of_xlate,
 	.probe_device	= sun50i_iommu_probe_device,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
index 6cba034905edbf..69c40c191ce4f0 100644
--- a/drivers/iommu/tegra-smmu.c
+++ b/drivers/iommu/tegra-smmu.c
@@ -272,13 +272,10 @@ static void tegra_smmu_free_asid(struct tegra_smmu *smmu, unsigned int id)
 	clear_bit(id, smmu->asids);
 }
 
-static struct iommu_domain *tegra_smmu_domain_alloc(unsigned type)
+static struct iommu_domain *tegra_smmu_domain_alloc_paging(struct device *dev)
 {
 	struct tegra_smmu_as *as;
 
-	if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA)
-		return NULL;
-
 	as = kzalloc(sizeof(*as), GFP_KERNEL);
 	if (!as)
 		return NULL;
@@ -997,7 +994,7 @@ static const struct iommu_ops tegra_smmu_ops = {
 	.default_domain = &tegra_smmu_identity_domain,
 	.identity_domain = &tegra_smmu_identity_domain,
 	.def_domain_type = &tegra_smmu_def_domain_type,
-	.domain_alloc = tegra_smmu_domain_alloc,
+	.domain_alloc_paging = tegra_smmu_domain_alloc_paging,
 	.probe_device = tegra_smmu_probe_device,
 	.device_group = tegra_smmu_device_group,
 	.of_xlate = tegra_smmu_of_xlate,
-- 
2.40.1



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

* [PATCH v2 25/25] iommu: Convert remaining simple drivers to domain_alloc_paging()
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (23 preceding siblings ...)
  2023-05-16  0:00   ` [PATCH v2 24/25] iommu: Convert simple drivers with DOMAIN_DMA to domain_alloc_paging() Jason Gunthorpe
@ 2023-05-16  0:00   ` Jason Gunthorpe
  2023-06-01 19:47     ` Robin Murphy
  2023-05-17 22:42   ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Marek Szyprowski
                     ` (2 subsequent siblings)
  27 siblings, 1 reply; 42+ messages in thread
From: Jason Gunthorpe @ 2023-05-16  0:00 UTC (permalink / raw)
  To: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

These drivers don't support IOMMU_DOMAIN_DMA, so this commit effectively
allows them to support that mode.

The prior work to require default_domains makes this safe because every
one of these drivers is either compilation incompatible with dma-iommu.c,
or already establishing a default_domain. In both cases alloc_domain()
will never be called with IOMMU_DOMAIN_DMA for these drivers so it is safe
to drop the test.

Removing these tests clarifies that the domain allocation path is only
about the functionality of a paging domain and has nothing to do with
policy of how the paging domain is used for UNMANAGED/DMA/DMA_FQ.

Tested-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/fsl_pamu_domain.c | 7 ++-----
 drivers/iommu/msm_iommu.c       | 7 ++-----
 drivers/iommu/mtk_iommu_v1.c    | 7 ++-----
 drivers/iommu/omap-iommu.c      | 7 ++-----
 drivers/iommu/s390-iommu.c      | 7 ++-----
 5 files changed, 10 insertions(+), 25 deletions(-)

diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index ca4f5ebf028783..8d5d6a3acf9dfd 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -192,13 +192,10 @@ static void fsl_pamu_domain_free(struct iommu_domain *domain)
 	kmem_cache_free(fsl_pamu_domain_cache, dma_domain);
 }
 
-static struct iommu_domain *fsl_pamu_domain_alloc(unsigned type)
+static struct iommu_domain *fsl_pamu_domain_alloc_paging(struct device *dev)
 {
 	struct fsl_dma_domain *dma_domain;
 
-	if (type != IOMMU_DOMAIN_UNMANAGED)
-		return NULL;
-
 	dma_domain = kmem_cache_zalloc(fsl_pamu_domain_cache, GFP_KERNEL);
 	if (!dma_domain)
 		return NULL;
@@ -476,7 +473,7 @@ static const struct iommu_ops fsl_pamu_ops = {
 	.identity_domain = &fsl_pamu_identity_domain,
 	.def_domain_type = &fsl_pamu_def_domain_type,
 	.capable	= fsl_pamu_capable,
-	.domain_alloc	= fsl_pamu_domain_alloc,
+	.domain_alloc_paging = fsl_pamu_domain_alloc_paging,
 	.probe_device	= fsl_pamu_probe_device,
 	.device_group   = fsl_pamu_device_group,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c
index 26ed81cfeee897..a163cee0b7242d 100644
--- a/drivers/iommu/msm_iommu.c
+++ b/drivers/iommu/msm_iommu.c
@@ -302,13 +302,10 @@ static void __program_context(void __iomem *base, int ctx,
 	SET_M(base, ctx, 1);
 }
 
-static struct iommu_domain *msm_iommu_domain_alloc(unsigned type)
+static struct iommu_domain *msm_iommu_domain_alloc_paging(struct device *dev)
 {
 	struct msm_priv *priv;
 
-	if (type != IOMMU_DOMAIN_UNMANAGED)
-		return NULL;
-
 	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
 	if (!priv)
 		goto fail_nomem;
@@ -691,7 +688,7 @@ irqreturn_t msm_iommu_fault_handler(int irq, void *dev_id)
 
 static struct iommu_ops msm_iommu_ops = {
 	.identity_domain = &msm_iommu_identity_domain,
-	.domain_alloc = msm_iommu_domain_alloc,
+	.domain_alloc_paging = msm_iommu_domain_alloc_paging,
 	.probe_device = msm_iommu_probe_device,
 	.device_group = generic_device_group,
 	.pgsize_bitmap = MSM_IOMMU_PGSIZES,
diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c
index 7c0c1d50df5f75..67e044c1a7d93b 100644
--- a/drivers/iommu/mtk_iommu_v1.c
+++ b/drivers/iommu/mtk_iommu_v1.c
@@ -270,13 +270,10 @@ static int mtk_iommu_v1_domain_finalise(struct mtk_iommu_v1_data *data)
 	return 0;
 }
 
-static struct iommu_domain *mtk_iommu_v1_domain_alloc(unsigned type)
+static struct iommu_domain *mtk_iommu_v1_domain_alloc_paging(struct device *dev)
 {
 	struct mtk_iommu_v1_domain *dom;
 
-	if (type != IOMMU_DOMAIN_UNMANAGED)
-		return NULL;
-
 	dom = kzalloc(sizeof(*dom), GFP_KERNEL);
 	if (!dom)
 		return NULL;
@@ -585,7 +582,7 @@ static int mtk_iommu_v1_hw_init(const struct mtk_iommu_v1_data *data)
 
 static const struct iommu_ops mtk_iommu_v1_ops = {
 	.identity_domain = &mtk_iommu_v1_identity_domain,
-	.domain_alloc	= mtk_iommu_v1_domain_alloc,
+	.domain_alloc_paging = mtk_iommu_v1_domain_alloc_paging,
 	.probe_device	= mtk_iommu_v1_probe_device,
 	.probe_finalize = mtk_iommu_v1_probe_finalize,
 	.release_device	= mtk_iommu_v1_release_device,
diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
index 34340ef15241bc..fcf99bd195b32e 100644
--- a/drivers/iommu/omap-iommu.c
+++ b/drivers/iommu/omap-iommu.c
@@ -1580,13 +1580,10 @@ static struct iommu_domain omap_iommu_identity_domain = {
 	.ops = &omap_iommu_identity_ops,
 };
 
-static struct iommu_domain *omap_iommu_domain_alloc(unsigned type)
+static struct iommu_domain *omap_iommu_domain_alloc_paging(struct device *dev)
 {
 	struct omap_iommu_domain *omap_domain;
 
-	if (type != IOMMU_DOMAIN_UNMANAGED)
-		return NULL;
-
 	omap_domain = kzalloc(sizeof(*omap_domain), GFP_KERNEL);
 	if (!omap_domain)
 		return NULL;
@@ -1748,7 +1745,7 @@ static struct iommu_group *omap_iommu_device_group(struct device *dev)
 
 static const struct iommu_ops omap_iommu_ops = {
 	.identity_domain = &omap_iommu_identity_domain,
-	.domain_alloc	= omap_iommu_domain_alloc,
+	.domain_alloc_paging = omap_iommu_domain_alloc_paging,
 	.probe_device	= omap_iommu_probe_device,
 	.release_device	= omap_iommu_release_device,
 	.device_group	= omap_iommu_device_group,
diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c
index f0c867c57a5b9b..5695ad71d60e24 100644
--- a/drivers/iommu/s390-iommu.c
+++ b/drivers/iommu/s390-iommu.c
@@ -39,13 +39,10 @@ static bool s390_iommu_capable(struct device *dev, enum iommu_cap cap)
 	}
 }
 
-static struct iommu_domain *s390_domain_alloc(unsigned domain_type)
+static struct iommu_domain *s390_domain_alloc_paging(struct device *dev)
 {
 	struct s390_domain *s390_domain;
 
-	if (domain_type != IOMMU_DOMAIN_UNMANAGED)
-		return NULL;
-
 	s390_domain = kzalloc(sizeof(*s390_domain), GFP_KERNEL);
 	if (!s390_domain)
 		return NULL;
@@ -447,7 +444,7 @@ void zpci_destroy_iommu(struct zpci_dev *zdev)
 static const struct iommu_ops s390_iommu_ops = {
 	.default_domain = &s390_iommu_platform_domain,
 	.capable = s390_iommu_capable,
-	.domain_alloc = s390_domain_alloc,
+	.domain_alloc_paging = s390_domain_alloc_paging,
 	.probe_device = s390_iommu_probe_device,
 	.release_device = s390_iommu_release_device,
 	.device_group = generic_device_group,
-- 
2.40.1



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

* Re: [PATCH v2 10/25] iommu/exynos: Implement an IDENTITY domain
  2023-05-16  0:00   ` [PATCH v2 10/25] iommu/exynos: " Jason Gunthorpe
@ 2023-05-17 22:41     ` Marek Szyprowski
  0 siblings, 0 replies; 42+ messages in thread
From: Marek Szyprowski @ 2023-05-17 22:41 UTC (permalink / raw)
  To: Jason Gunthorpe, Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Matthias Brugger, Matthew Rosato, Michael Ellerman,
	Nicholas Piggin, Orson Zhai, Rob Clark, Robin Murphy,
	Samuel Holland, Thierry Reding, Krishna Reddy, Chen-Yu Tsai,
	Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

On 16.05.2023 02:00, Jason Gunthorpe wrote:
> What exynos calls exynos_iommu_detach_device is actually putting the iommu
> into identity mode.
>
> Move to the new core support for ARM_DMA_USE_IOMMU by defining
> ops->identity_domain.
>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

Acked-by: Marek Szyprowski

> ---
>   drivers/iommu/exynos-iommu.c | 66 +++++++++++++++++-------------------
>   1 file changed, 32 insertions(+), 34 deletions(-)
>
> diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c
> index c275fe71c4db32..5e12b85dfe8705 100644
> --- a/drivers/iommu/exynos-iommu.c
> +++ b/drivers/iommu/exynos-iommu.c
> @@ -24,6 +24,7 @@
>   
>   typedef u32 sysmmu_iova_t;
>   typedef u32 sysmmu_pte_t;
> +static struct iommu_domain exynos_identity_domain;
>   
>   /* We do not consider super section mapping (16MB) */
>   #define SECT_ORDER 20
> @@ -829,7 +830,7 @@ static int __maybe_unused exynos_sysmmu_suspend(struct device *dev)
>   		struct exynos_iommu_owner *owner = dev_iommu_priv_get(master);
>   
>   		mutex_lock(&owner->rpm_lock);
> -		if (data->domain) {
> +		if (&data->domain->domain != &exynos_identity_domain) {
>   			dev_dbg(data->sysmmu, "saving state\n");
>   			__sysmmu_disable(data);
>   		}
> @@ -847,7 +848,7 @@ static int __maybe_unused exynos_sysmmu_resume(struct device *dev)
>   		struct exynos_iommu_owner *owner = dev_iommu_priv_get(master);
>   
>   		mutex_lock(&owner->rpm_lock);
> -		if (data->domain) {
> +		if (&data->domain->domain != &exynos_identity_domain) {
>   			dev_dbg(data->sysmmu, "restoring state\n");
>   			__sysmmu_enable(data);
>   		}
> @@ -980,17 +981,20 @@ static void exynos_iommu_domain_free(struct iommu_domain *iommu_domain)
>   	kfree(domain);
>   }
>   
> -static void exynos_iommu_detach_device(struct iommu_domain *iommu_domain,
> -				    struct device *dev)
> +static int exynos_iommu_identity_attach(struct iommu_domain *identity_domain,
> +					struct device *dev)
>   {
> -	struct exynos_iommu_domain *domain = to_exynos_domain(iommu_domain);
>   	struct exynos_iommu_owner *owner = dev_iommu_priv_get(dev);
> -	phys_addr_t pagetable = virt_to_phys(domain->pgtable);
> +	struct exynos_iommu_domain *domain;
> +	phys_addr_t pagetable;
>   	struct sysmmu_drvdata *data, *next;
>   	unsigned long flags;
>   
> -	if (!has_sysmmu(dev) || owner->domain != iommu_domain)
> -		return;
> +	if (owner->domain == identity_domain)
> +		return 0;
> +
> +	domain = to_exynos_domain(owner->domain);
> +	pagetable = virt_to_phys(domain->pgtable);
>   
>   	mutex_lock(&owner->rpm_lock);
>   
> @@ -1009,15 +1013,25 @@ static void exynos_iommu_detach_device(struct iommu_domain *iommu_domain,
>   		list_del_init(&data->domain_node);
>   		spin_unlock(&data->lock);
>   	}
> -	owner->domain = NULL;
> +	owner->domain = identity_domain;
>   	spin_unlock_irqrestore(&domain->lock, flags);
>   
>   	mutex_unlock(&owner->rpm_lock);
>   
> -	dev_dbg(dev, "%s: Detached IOMMU with pgtable %pa\n", __func__,
> -		&pagetable);
> +	dev_dbg(dev, "%s: Restored IOMMU to IDENTITY from pgtable %pa\n",
> +		__func__, &pagetable);
> +	return 0;
>   }
>   
> +static struct iommu_domain_ops exynos_identity_ops = {
> +	.attach_dev = exynos_iommu_identity_attach,
> +};
> +
> +static struct iommu_domain exynos_identity_domain = {
> +	.type = IOMMU_DOMAIN_IDENTITY,
> +	.ops = &exynos_identity_ops,
> +};
> +
>   static int exynos_iommu_attach_device(struct iommu_domain *iommu_domain,
>   				   struct device *dev)
>   {
> @@ -1026,12 +1040,11 @@ static int exynos_iommu_attach_device(struct iommu_domain *iommu_domain,
>   	struct sysmmu_drvdata *data;
>   	phys_addr_t pagetable = virt_to_phys(domain->pgtable);
>   	unsigned long flags;
> +	int err;
>   
> -	if (!has_sysmmu(dev))
> -		return -ENODEV;
> -
> -	if (owner->domain)
> -		exynos_iommu_detach_device(owner->domain, dev);
> +	err = exynos_iommu_identity_attach(&exynos_identity_domain, dev);
> +	if (err)
> +		return err;
>   
>   	mutex_lock(&owner->rpm_lock);
>   
> @@ -1407,26 +1420,12 @@ static struct iommu_device *exynos_iommu_probe_device(struct device *dev)
>   	return &data->iommu;
>   }
>   
> -static void exynos_iommu_set_platform_dma(struct device *dev)
> -{
> -	struct exynos_iommu_owner *owner = dev_iommu_priv_get(dev);
> -
> -	if (owner->domain) {
> -		struct iommu_group *group = iommu_group_get(dev);
> -
> -		if (group) {
> -			exynos_iommu_detach_device(owner->domain, dev);
> -			iommu_group_put(group);
> -		}
> -	}
> -}
> -
>   static void exynos_iommu_release_device(struct device *dev)
>   {
>   	struct exynos_iommu_owner *owner = dev_iommu_priv_get(dev);
>   	struct sysmmu_drvdata *data;
>   
> -	exynos_iommu_set_platform_dma(dev);
> +	WARN_ON(exynos_iommu_identity_attach(&exynos_identity_domain, dev));
>   
>   	list_for_each_entry(data, &owner->controllers, owner_node)
>   		device_link_del(data->link);
> @@ -1457,6 +1456,7 @@ static int exynos_iommu_of_xlate(struct device *dev,
>   
>   		INIT_LIST_HEAD(&owner->controllers);
>   		mutex_init(&owner->rpm_lock);
> +		owner->domain = &exynos_identity_domain;
>   		dev_iommu_priv_set(dev, owner);
>   	}
>   
> @@ -1471,11 +1471,9 @@ static int exynos_iommu_of_xlate(struct device *dev,
>   }
>   
>   static const struct iommu_ops exynos_iommu_ops = {
> +	.identity_domain = &exynos_identity_domain,
>   	.domain_alloc = exynos_iommu_domain_alloc,
>   	.device_group = generic_device_group,
> -#ifdef CONFIG_ARM
> -	.set_platform_dma_ops = exynos_iommu_set_platform_dma,
> -#endif
>   	.probe_device = exynos_iommu_probe_device,
>   	.release_device = exynos_iommu_release_device,
>   	.pgsize_bitmap = SECT_SIZE | LPAGE_SIZE | SPAGE_SIZE,

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland



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

* Re: [PATCH v2 00/25] iommu: Make default_domain's mandatory
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (24 preceding siblings ...)
  2023-05-16  0:00   ` [PATCH v2 25/25] iommu: Convert remaining simple drivers " Jason Gunthorpe
@ 2023-05-17 22:42   ` Marek Szyprowski
  2023-05-17 23:32   ` Nicolin Chen
  2023-05-18 10:56   ` Steven Price
  27 siblings, 0 replies; 42+ messages in thread
From: Marek Szyprowski @ 2023-05-17 22:42 UTC (permalink / raw)
  To: Jason Gunthorpe, Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Matthias Brugger, Matthew Rosato, Michael Ellerman,
	Nicholas Piggin, Orson Zhai, Rob Clark, Robin Murphy,
	Samuel Holland, Thierry Reding, Krishna Reddy, Chen-Yu Tsai,
	Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

On 16.05.2023 02:00, Jason Gunthorpe wrote:
> [ There was alot of unexpected complication after rc1 with this series,
> several new patches were needed ]
>
> It has been a long time coming, this series completes the default_domain
> transition and makes it so that the core IOMMU code will always have a
> non-NULL default_domain for every driver on every
> platform. set_platform_dma_ops() turned out to be a bad idea, and so
> completely remove it.
>
> This is achieved by changing each driver to either:
>
> 1 - Convert the existing (or deleted) ops->detach_dev() into an
>      op->attach_dev() of an IDENTITY domain.
>
>      This is based on the theory that the ARM32 HW is able to function when
>      the iommu is turned off as so the turned off state is an IDENTITY
>      translation.
>
> 2 - Use a new PLATFORM domain type. This is a hack to accommodate drivers
>      that we don't really know WTF they do. S390 is legitimately using this
>      to switch to it's platform dma_ops implementation, which is where the
>      name comes from.
>
> 3 - Do #1 and force the default domain to be IDENTITY, this corrects
>      the tegra-smmu case where even an ARM64 system would have a NULL
>      default_domain.
>
> Using this we can apply the rules:
>
> a) ARM_DMA_USE_IOMMU mode always uses either the driver's
>     ops->default_domain, ops->def_domain_type(), or an IDENTITY domain.
>     All ARM32 drivers provide one of these three options.
>
> b) dma-iommu.c mode uses either the driver's ops->default_domain,
>     ops->def_domain_type or the usual DMA API policy logic based on the
>     command line/etc to pick IDENTITY/DMA domain types
>
> c) All other arch's (PPC/S390) use ops->default_domain always.
>
> See the patch "Require a default_domain for all iommu drivers" for a
> per-driver breakdown.
>
> The conversion broadly teaches a bunch of ARM32 drivers that they can do
> IDENTITY domains. There is some educated guessing involved that these are
> actual IDENTITY domains. If this turns out to be wrong the driver can be
> trivially changed to use a BLOCKING domain type instead. Further, the
> domain type only matters for drivers using ARM64's dma-iommu.c mode as it
> will select IDENTITY based on the command line and expect IDENTITY to
> work. For ARM32 and other arch cases it is purely documentation.
>
> Finally, based on all the analysis in this series, we can purge
> IOMMU_DOMAIN_UNMANAGED/DMA constants from most of the drivers. This
> greatly simplifies understanding the driver contract to the core
> code. IOMMU drivers should not be involved in policy for how the DMA API
> works, that should be a core core decision.
>
> The main gain from this work is to remove alot of ARM_DMA_USE_IOMMU
> specific code and behaviors from drivers. All that remains in iommu
> drivers after this series is the calls to arm_iommu_create_mapping().
>
> This is a step toward removing ARM_DMA_USE_IOMMU.
>
> The IDENTITY domains added to the ARM64 supporting drivers can be tested
> by booting in ARM64 mode and enabling CONFIG_IOMMU_DEFAULT_PASSTHROUGH. If
> the system still boots then most likely the implementation is an IDENTITY
> domain. If not we can trivially change it to BLOCKING or at worst PLATFORM
> if there is no detail what is going on in the HW.
>
> I think this is pretty safe for the ARM32 drivers as they don't really
> change, the code that was in detach_dev continues to be called in the same
> places it was called before.

Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>

Works fine on ARM 32bit Exynos based boards.

> This follows the prior series:
>
> https://lore.kernel.org/r/0-v5-1b99ae392328+44574-iommu_err_unwind_jgg@nvidia.com
>
> This is on github: https://protect2.fireeye.com/v1/url?k=773809ed-1645e36e-773982a2-74fe48600158-bd3a7b89de1f2061&q=1&e=7f176af7-9cf3-429b-a0ce-8812c59dfb5c&u=https%3A%2F%2Fgithub.com%2Fjgunthorpe%2Flinux%2Fcommits%2Fiommu_all_defdom
>
> v2:
>   - FSL is an IDENTITY domain
>   - Delete terga-gart instead of trying to carry it
>   - Use the policy determination from iommu_get_default_domain_type() to
>     drive the arm_iommu mode
>   - Reorganize and introduce new patches to do the above:
>      * Split the ops->identity_domain to an independent earlier patch
>      * Remove the UNMANAGED return from def_domain_type in mtk_v1 earlier
>        so the new iommu_get_default_domain_type() can work
>      * Make the driver's def_domain_type have higher policy priority than
>        untrusted
>      * Merge the set_platfom_dma_ops hunk from mtk_v1 along with rockchip
>        into the patch that forced IDENTITY on ARM32
>   - Revise sun50i to be cleaner and have a non-NULL internal domain
>   - Reword logging in exynos
>   - Remove the gdev from the group alloc path, instead add a new
>     function __iommu_group_domain_alloc() that takes in the group
>     and uses the first device. Split this to its own patch
>   - New patch to make iommufd's mock selftest into a real driver
>   - New patch to fix power's partial iommu driver
> v1: https://lore.kernel.org/r/0-v1-21cc72fcfb22+a7a-iommu_all_defdom_jgg@nvidia.com
>
> Jason Gunthorpe (25):
>    iommu: Add iommu_ops->identity_domain
>    iommu: Add IOMMU_DOMAIN_PLATFORM
>    powerpc/iommu: Setup a default domain and remove set_platform_dma_ops
>    iommu: Add IOMMU_DOMAIN_PLATFORM for S390
>    iommu/tegra-gart: Remove tegra-gart
>    iommu/mtk_iommu_v1: Implement an IDENTITY domain
>    iommu: Reorganize iommu_get_default_domain_type() to respect
>      def_domain_type()
>    iommu: Allow an IDENTITY domain as the default_domain in ARM32
>    iommu/fsl_pamu: Implement an IDENTITY domain
>    iommu/exynos: Implement an IDENTITY domain
>    iommu/tegra-smmu: Implement an IDENTITY domain
>    iommu/tegra-smmu: Support DMA domains in tegra
>    iommu/omap: Implement an IDENTITY domain
>    iommu/msm: Implement an IDENTITY domain
>    iommufd/selftest: Make the mock iommu driver into a real driver
>    iommu: Remove ops->set_platform_dma_ops()
>    iommu/qcom_iommu: Add an IOMMU_IDENTITIY_DOMAIN
>    iommu/ipmmu: Add an IOMMU_IDENTITIY_DOMAIN
>    iommu/mtk_iommu: Add an IOMMU_IDENTITIY_DOMAIN
>    iommu/sun50i: Add an IOMMU_IDENTITIY_DOMAIN
>    iommu: Require a default_domain for all iommu drivers
>    iommu: Add __iommu_group_domain_alloc()
>    iommu: Add ops->domain_alloc_paging()
>    iommu: Convert simple drivers with DOMAIN_DMA to domain_alloc_paging()
>    iommu: Convert remaining simple drivers to domain_alloc_paging()
>
>   arch/arm/configs/multi_v7_defconfig     |   1 -
>   arch/arm/configs/tegra_defconfig        |   1 -
>   arch/powerpc/kernel/iommu.c             |  38 ++-
>   drivers/iommu/Kconfig                   |  11 -
>   drivers/iommu/Makefile                  |   1 -
>   drivers/iommu/arm/arm-smmu/qcom_iommu.c |  45 ++-
>   drivers/iommu/exynos-iommu.c            |  73 +++--
>   drivers/iommu/fsl_pamu_domain.c         |  39 ++-
>   drivers/iommu/iommu-priv.h              |  16 +
>   drivers/iommu/iommu.c                   | 263 +++++++++++------
>   drivers/iommu/iommufd/iommufd_private.h |   5 +-
>   drivers/iommu/iommufd/main.c            |   8 +-
>   drivers/iommu/iommufd/selftest.c        | 141 ++++-----
>   drivers/iommu/ipmmu-vmsa.c              |  50 +++-
>   drivers/iommu/msm_iommu.c               |  30 +-
>   drivers/iommu/mtk_iommu.c               |  30 +-
>   drivers/iommu/mtk_iommu_v1.c            |  28 +-
>   drivers/iommu/omap-iommu.c              |  28 +-
>   drivers/iommu/rockchip-iommu.c          |  26 +-
>   drivers/iommu/s390-iommu.c              |  28 +-
>   drivers/iommu/sprd-iommu.c              |   7 +-
>   drivers/iommu/sun50i-iommu.c            |  35 ++-
>   drivers/iommu/tegra-gart.c              | 371 ------------------------
>   drivers/iommu/tegra-smmu.c              |  50 +++-
>   drivers/memory/tegra/mc.c               |  34 ---
>   drivers/memory/tegra/tegra20.c          |  28 --
>   include/linux/iommu.h                   |  16 +-
>   include/soc/tegra/mc.h                  |  26 --
>   28 files changed, 622 insertions(+), 807 deletions(-)
>   create mode 100644 drivers/iommu/iommu-priv.h
>   delete mode 100644 drivers/iommu/tegra-gart.c
>
>
> base-commit: 0b355ade2baf262f213da274411c0e05d8232a21

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland



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

* Re: [PATCH v2 00/25] iommu: Make default_domain's mandatory
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (25 preceding siblings ...)
  2023-05-17 22:42   ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Marek Szyprowski
@ 2023-05-17 23:32   ` Nicolin Chen
  2023-05-18 10:56   ` Steven Price
  27 siblings, 0 replies; 42+ messages in thread
From: Nicolin Chen @ 2023-05-17 23:32 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang, Lu Baolu,
	Dmitry Osipenko, Niklas Schnelle, Steven Price, Thierry Reding

On Mon, May 15, 2023 at 09:00:33PM -0300, Jason Gunthorpe wrote:
 
> This is on github: https://github.com/jgunthorpe/linux/commits/iommu_all_defdom

Ran some VFIO-passthrough sanity on x86 and ARM64, using this
branch. It should cover partially this series. So, if I may:

Tested-by: Nicolin Chen <nicolinc@nvidia.com>

Thanks
Nic

> v2:
>  - FSL is an IDENTITY domain
>  - Delete terga-gart instead of trying to carry it
>  - Use the policy determination from iommu_get_default_domain_type() to
>    drive the arm_iommu mode
>  - Reorganize and introduce new patches to do the above:
>     * Split the ops->identity_domain to an independent earlier patch
>     * Remove the UNMANAGED return from def_domain_type in mtk_v1 earlier
>       so the new iommu_get_default_domain_type() can work
>     * Make the driver's def_domain_type have higher policy priority than
>       untrusted
>     * Merge the set_platfom_dma_ops hunk from mtk_v1 along with rockchip
>       into the patch that forced IDENTITY on ARM32
>  - Revise sun50i to be cleaner and have a non-NULL internal domain
>  - Reword logging in exynos
>  - Remove the gdev from the group alloc path, instead add a new
>    function __iommu_group_domain_alloc() that takes in the group
>    and uses the first device. Split this to its own patch
>  - New patch to make iommufd's mock selftest into a real driver
>  - New patch to fix power's partial iommu driver


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

* Re: [PATCH v2 00/25] iommu: Make default_domain's mandatory
  2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
                     ` (26 preceding siblings ...)
  2023-05-17 23:32   ` Nicolin Chen
@ 2023-05-18 10:56   ` Steven Price
  27 siblings, 0 replies; 42+ messages in thread
From: Steven Price @ 2023-05-18 10:56 UTC (permalink / raw)
  To: Jason Gunthorpe, Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Thierry Reding, Krishna Reddy,
	Chen-Yu Tsai, Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle, Thierry Reding

On 16/05/2023 01:00, Jason Gunthorpe wrote:
> This is on github: https://github.com/jgunthorpe/linux/commits/iommu_all_defdom

Tested-by: Steven Price <steven.price@arm.com>

Works fine on my Firefly-RK3288.

Thanks,

Steve



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

* Re: [PATCH v2 05/25] iommu/tegra-gart: Remove tegra-gart
  2023-05-16  0:00   ` [PATCH v2 05/25] iommu/tegra-gart: Remove tegra-gart Jason Gunthorpe
@ 2023-06-01 16:51     ` Thierry Reding
  0 siblings, 0 replies; 42+ messages in thread
From: Thierry Reding @ 2023-06-01 16:51 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Robin Murphy, Samuel Holland, Krishna Reddy, Chen-Yu Tsai,
	Will Deacon, Yong Wu, Chunyan Zhang, Lu Baolu, Dmitry Osipenko,
	Nicolin Chen, Niklas Schnelle, Steven Price, Thierry Reding

[-- Attachment #1: Type: text/plain, Size: 2170 bytes --]

On Mon, May 15, 2023 at 09:00:38PM -0300, Jason Gunthorpe wrote:
> Thierry says this is not used anymore, and doesn't think it ever will
> be. The HW it supports is about 10 years old now and newer HW uses
> different IOMMU drivers.
> 
> As this is the only driver with a GART approach, and it doesn't really
> meet the driver expectations from the IOMMU core, let's just remove it
> so we don't have to think about how to make it fit in.
> 
> It has a number of identified problems:
>  - The assignment of iommu_groups doesn't match the HW behavior
> 
>  - It claims to have an UNMANAGED domain but it is really an IDENTITY
>    domain with a translation aperture. This is inconsistent with the core
>    expectation for security sensitive operations
> 
>  - It doesn't implement a SW page table under struct iommu_domain so
>    * It can't accept a map until the domain is attached
>    * It forgets about all maps after the domain is detached
>    * It doesn't clear the HW of maps once the domain is detached
>      (made worse by having the wrong groups)
> 
> Cc: Thierry Reding <treding@nvidia.com>
> Cc: Dmitry Osipenko <digetx@gmail.com>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  arch/arm/configs/multi_v7_defconfig |   1 -
>  arch/arm/configs/tegra_defconfig    |   1 -
>  drivers/iommu/Kconfig               |  11 -
>  drivers/iommu/Makefile              |   1 -
>  drivers/iommu/tegra-gart.c          | 371 ----------------------------
>  drivers/memory/tegra/mc.c           |  34 ---
>  drivers/memory/tegra/tegra20.c      |  28 ---
>  include/soc/tegra/mc.h              |  26 --
>  8 files changed, 473 deletions(-)
>  delete mode 100644 drivers/iommu/tegra-gart.c

To clarify, I think this hardware could very well be used again, but I
don't think it makes sense to use it in the context of the IOMMU
subsystem. If anybody wants to make use of this on Tegra20, it probably
makes more sense to move the GART programming into whatever driver ends
up using it instead of jumping through all these hoops just to make it
work like something it isn't.

Acked-by: Thierry Reding <treding@nvidia.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 04/25] iommu: Add IOMMU_DOMAIN_PLATFORM for S390
  2023-05-16  0:00   ` [PATCH v2 04/25] iommu: Add IOMMU_DOMAIN_PLATFORM for S390 Jason Gunthorpe
@ 2023-06-01 18:25     ` Robin Murphy
  2023-06-01 19:58       ` Jason Gunthorpe
  0 siblings, 1 reply; 42+ messages in thread
From: Robin Murphy @ 2023-06-01 18:25 UTC (permalink / raw)
  To: Jason Gunthorpe, Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Samuel Holland, Thierry Reding, Krishna Reddy, Chen-Yu Tsai,
	Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

On 2023-05-16 01:00, Jason Gunthorpe wrote:
> The PLATFORM domain will be set as the default domain and attached as
> normal during probe. The driver will ignore the initial attach from a NULL
> domain to the PLATFORM domain.
> 
> After this, the PLATFORM domain's attach_dev will be called whenever we
> detach from an UNMANAGED domain (eg for VFIO). This is the same time the
> original design would have called op->detach_dev().
> 
> This is temporary until the S390 dma-iommu.c conversion is merged.

If we do need a stopgap here, can we please just call the current 
situation an identity domain? It's true enough in the sense that the 
IOMMU API is not offering any translation or guarantee of isolation, so 
the semantics of an identity domain - from the point of view of anything 
inside the IOMMU API that would be looking - are no weaker or less 
useful than a "platform" domain whose semantics are intentionally unknown.

Then similarly for patch #3 - since we already know s390 is temporary, 
it seems an anathema to introduce a whole domain type with its own weird 
ops->default_domain mechanism solely for POWER to not actually use 
domains with.

In terms of reasoning, I don't see that IOMMU_DOMAIN_PLATFORM is any 
more useful than a NULL default domain, it just renames the problem, and 
gives us more code to maintain for the privilege. As I say, though, we 
don't actually need to juggle the semantic of a "we don't know what's 
happening here" domain around any further, since it works out that a 
"we're not influencing anything here" domain actually suffices for what 
we want to reason about, and those are already well-defined. Sure, the 
platform DMA ops *might* be doing more, but that's beyond the scope of 
the IOMMU API either way. At that point, lo and behold, s390 and POWER 
now look just like ARM and the core code only needs a single special 
case for arch-specific default identity domains, lovely!

Thanks,
Robin.

> Tested-by: Heiko Stuebner <heiko@sntech.de>
> Tested-by: Niklas Schnelle <schnelle@linux.ibm.com>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>   drivers/iommu/s390-iommu.c | 21 +++++++++++++++++++--
>   1 file changed, 19 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c
> index fbf59a8db29b11..f0c867c57a5b9b 100644
> --- a/drivers/iommu/s390-iommu.c
> +++ b/drivers/iommu/s390-iommu.c
> @@ -142,14 +142,31 @@ static int s390_iommu_attach_device(struct iommu_domain *domain,
>   	return 0;
>   }
>   
> -static void s390_iommu_set_platform_dma(struct device *dev)
> +/*
> + * Switch control over the IOMMU to S390's internal dma_api ops
> + */
> +static int s390_iommu_platform_attach(struct iommu_domain *platform_domain,
> +				      struct device *dev)
>   {
>   	struct zpci_dev *zdev = to_zpci_dev(dev);
>   
> +	if (!zdev->s390_domain)
> +		return 0;
> +
>   	__s390_iommu_detach_device(zdev);
>   	zpci_dma_init_device(zdev);
> +	return 0;
>   }
>   
> +static struct iommu_domain_ops s390_iommu_platform_ops = {
> +	.attach_dev = s390_iommu_platform_attach,
> +};
> +
> +static struct iommu_domain s390_iommu_platform_domain = {
> +	.type = IOMMU_DOMAIN_PLATFORM,
> +	.ops = &s390_iommu_platform_ops,
> +};
> +
>   static void s390_iommu_get_resv_regions(struct device *dev,
>   					struct list_head *list)
>   {
> @@ -428,12 +445,12 @@ void zpci_destroy_iommu(struct zpci_dev *zdev)
>   }
>   
>   static const struct iommu_ops s390_iommu_ops = {
> +	.default_domain = &s390_iommu_platform_domain,
>   	.capable = s390_iommu_capable,
>   	.domain_alloc = s390_domain_alloc,
>   	.probe_device = s390_iommu_probe_device,
>   	.release_device = s390_iommu_release_device,
>   	.device_group = generic_device_group,
> -	.set_platform_dma_ops = s390_iommu_set_platform_dma,
>   	.pgsize_bitmap = SZ_4K,
>   	.get_resv_regions = s390_iommu_get_resv_regions,
>   	.default_domain_ops = &(const struct iommu_domain_ops) {


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

* Re: [PATCH v2 08/25] iommu: Allow an IDENTITY domain as the default_domain in ARM32
  2023-05-16  0:00   ` [PATCH v2 08/25] iommu: Allow an IDENTITY domain as the default_domain in ARM32 Jason Gunthorpe
@ 2023-06-01 18:57     ` Robin Murphy
  0 siblings, 0 replies; 42+ messages in thread
From: Robin Murphy @ 2023-06-01 18:57 UTC (permalink / raw)
  To: Jason Gunthorpe, Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Samuel Holland, Thierry Reding, Krishna Reddy, Chen-Yu Tsai,
	Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

On 2023-05-16 01:00, Jason Gunthorpe wrote:
> Even though dma-iommu.c and CONFIG_ARM_DMA_USE_IOMMU do approximately the
> same stuff, the way they relate to the IOMMU core is quiet different.
> 
> dma-iommu.c expects the core code to setup an UNMANAGED domain (of type
> IOMMU_DOMAIN_DMA) and then configures itself to use that domain. This
> becomes the default_domain for the group.
> 
> ARM_DMA_USE_IOMMU does not use the default_domain, instead it directly
> allocates an UNMANAGED domain and operates it just like an external
> driver. In this case group->default_domain is NULL.
> 
> If the driver provides a global static identity_domain then automatically
> use it as the default_domain when in ARM_DMA_USE_IOMMU mode.
> 
> This allows drivers that implemented default_domain == NULL as an IDENTITY
> translation to trivially get a properly labeled non-NULL default_domain on
> ARM32 configs.
> 
> With this arrangment when ARM_DMA_USE_IOMMU wants to disconnect from the
> device the normal detach_domain flow will restore the IDENTITY domain as
> the default domain. Overall this makes attach_dev() of the IDENTITY domain
> called in the same places as detach_dev().
> 
> This effectively migrates these drivers to default_domain mode. For
> drivers that support ARM64 they will gain support for the IDENTITY
> translation mode for the dma_api and behave in a uniform way.
> 
> Drivers use this by setting ops->identity_domain to a static singleton
> iommu_domain that implements the identity attach. If the core detects
> ARM_DMA_USE_IOMMU mode then it automatically attaches the IDENTITY domain
> during probe.
> 
> Drivers can continue to prevent the use of DMA translation by returning
> IOMMU_DOMAIN_IDENTITY from def_domain_type, this will completely prevent
> IOMMU_DMA from running but will not impact ARM_DMA_USE_IOMMU.
> 
> This allows removing the set_platform_dma_ops() from every remaining
> driver.
> 
> Remove the set_platform_dma_ops from rockchip and mkt_v1 as all it does
> is set an existing global static identity domain. mkt_v1 does not support
> IOMMU_DOMAIN_DMA and it does not compile on ARM64 so this transformation
> is safe.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>   drivers/iommu/iommu.c          | 40 +++++++++++++++++++++++++++++-----
>   drivers/iommu/mtk_iommu_v1.c   | 12 ----------
>   drivers/iommu/rockchip-iommu.c | 10 ---------
>   3 files changed, 35 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index 8ba90571449cec..bed7cb6e5ee65b 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -1757,18 +1757,48 @@ static int iommu_get_default_domain_type(struct iommu_group *group,
>   	int type;
>   
>   	lockdep_assert_held(&group->mutex);
> +
> +	/*
> +	 * ARM32 drivers supporting CONFIG_ARM_DMA_USE_IOMMU can declare an
> +	 * identity_domain and it will automatically become their default
> +	 * domain. Later on ARM_DMA_USE_IOMMU will install its UNMANAGED domain.
> +	 * Override the selection to IDENTITY if we are sure the driver supports
> +	 * it.
> +	 */
> +	if (IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU) && ops->identity_domain) {

If I cared about arm-smmu on 32-bit, I'd bring that up again, but 
honestly I'm not sure that I do... I think it might end up working after 
patch #21, and it's currently still broken for lack of .set_platform_dma 
anyway, so meh.

> +		type = IOMMU_DOMAIN_IDENTITY;
> +		if (best_type && type && best_type != type)
> +			goto err;
> +		best_type = target_type = IOMMU_DOMAIN_IDENTITY;
> +	}
> +
>   	for_each_group_device(group, gdev) {
>   		type = best_type;
>   		if (ops->def_domain_type) {
>   			type = ops->def_domain_type(gdev->dev);
> -			if (best_type && type && best_type != type)
> +			if (best_type && type && best_type != type) {
> +				/* Stick with the last driver override we saw */
> +				best_type = type;
>   				goto err;
> +			}
>   		}
>   
>   		if (dev_is_pci(gdev->dev) && to_pci_dev(gdev->dev)->untrusted) {
> -			type = IOMMU_DOMAIN_DMA;
> -			if (best_type && type && best_type != type)
> -				goto err;
> +			/*
> +			 * We don't have any way for the iommu core code to
> +			 * force arm_iommu to activate so we can't enforce
> +			 * trusted. Log it and keep going with the IDENTITY
> +			 * default domain.
> +			 */
> +			if (IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU)) {
> +				dev_warn(
> +					gdev->dev,
> +					"PCI device is untrusted but ARM32 does not support secure IOMMU operation, continuing anyway.\n");

To within experimental error, this is dead code. The ARM DMA ops don't 
even understand groups, so already have the much bigger problem of being 
broken for any non-trivial PCI setup anyway. That's if you could even 
find a 32-bit SoC with both PCI(e) and a relevant IOMMU. None of those 
will have Thunderbolt, and I expect even fewer would be using the 
"external-facing" DT property (which is likely newer than they are) for 
any other reason.

Thanks,
Robin.

> +			} else {
> +				type = IOMMU_DOMAIN_DMA;
> +				if (best_type && type && best_type != type)
> +					goto err;
> +			}
>   		}
>   		best_type = type;
>   		last_dev = gdev->dev;
> @@ -1790,7 +1820,7 @@ static int iommu_get_default_domain_type(struct iommu_group *group,
>   		"Device needs domain type %s, but device %s in the same iommu group requires type %s - using default\n",
>   		iommu_domain_type_str(type), dev_name(last_dev),
>   		iommu_domain_type_str(best_type));
> -	return 0;
> +	return best_type;
>   }
>   
>   static void iommu_group_do_probe_finalize(struct device *dev)
> diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c
> index cc3e7d53d33ad9..7c0c1d50df5f75 100644
> --- a/drivers/iommu/mtk_iommu_v1.c
> +++ b/drivers/iommu/mtk_iommu_v1.c
> @@ -337,11 +337,6 @@ static struct iommu_domain mtk_iommu_v1_identity_domain = {
>   	.ops = &mtk_iommu_v1_identity_ops,
>   };
>   
> -static void mtk_iommu_v1_set_platform_dma(struct device *dev)
> -{
> -	mtk_iommu_v1_identity_attach(&mtk_iommu_v1_identity_domain, dev);
> -}
> -
>   static int mtk_iommu_v1_map(struct iommu_domain *domain, unsigned long iova,
>   			    phys_addr_t paddr, size_t pgsize, size_t pgcount,
>   			    int prot, gfp_t gfp, size_t *mapped)
> @@ -457,11 +452,6 @@ static int mtk_iommu_v1_create_mapping(struct device *dev, struct of_phandle_arg
>   	return 0;
>   }
>   
> -static int mtk_iommu_v1_def_domain_type(struct device *dev)
> -{
> -	return IOMMU_DOMAIN_IDENTITY;
> -}
> -
>   static struct iommu_device *mtk_iommu_v1_probe_device(struct device *dev)
>   {
>   	struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
> @@ -599,10 +589,8 @@ static const struct iommu_ops mtk_iommu_v1_ops = {
>   	.probe_device	= mtk_iommu_v1_probe_device,
>   	.probe_finalize = mtk_iommu_v1_probe_finalize,
>   	.release_device	= mtk_iommu_v1_release_device,
> -	.def_domain_type = mtk_iommu_v1_def_domain_type,
>   	.device_group	= generic_device_group,
>   	.pgsize_bitmap	= MT2701_IOMMU_PAGE_SIZE,
> -	.set_platform_dma_ops = mtk_iommu_v1_set_platform_dma,
>   	.owner          = THIS_MODULE,
>   	.default_domain_ops = &(const struct iommu_domain_ops) {
>   		.attach_dev	= mtk_iommu_v1_attach_device,
> diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
> index ebce56d6e9c634..9e1296a856ac4c 100644
> --- a/drivers/iommu/rockchip-iommu.c
> +++ b/drivers/iommu/rockchip-iommu.c
> @@ -1026,13 +1026,6 @@ static struct iommu_domain rk_identity_domain = {
>   	.ops = &rk_identity_ops,
>   };
>   
> -#ifdef CONFIG_ARM
> -static void rk_iommu_set_platform_dma(struct device *dev)
> -{
> -	WARN_ON(rk_iommu_identity_attach(&rk_identity_domain, dev));
> -}
> -#endif
> -
>   static int rk_iommu_attach_device(struct iommu_domain *domain,
>   		struct device *dev)
>   {
> @@ -1211,9 +1204,6 @@ static const struct iommu_ops rk_iommu_ops = {
>   	.probe_device = rk_iommu_probe_device,
>   	.release_device = rk_iommu_release_device,
>   	.device_group = rk_iommu_device_group,
> -#ifdef CONFIG_ARM
> -	.set_platform_dma_ops = rk_iommu_set_platform_dma,
> -#endif
>   	.pgsize_bitmap = RK_IOMMU_PGSIZE_BITMAP,
>   	.of_xlate = rk_iommu_of_xlate,
>   	.default_domain_ops = &(const struct iommu_domain_ops) {


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

* Re: [PATCH v2 23/25] iommu: Add ops->domain_alloc_paging()
  2023-05-16  0:00   ` [PATCH v2 23/25] iommu: Add ops->domain_alloc_paging() Jason Gunthorpe
@ 2023-06-01 19:17     ` Robin Murphy
  2023-06-01 20:47       ` Jason Gunthorpe
  0 siblings, 1 reply; 42+ messages in thread
From: Robin Murphy @ 2023-06-01 19:17 UTC (permalink / raw)
  To: Jason Gunthorpe, Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Samuel Holland, Thierry Reding, Krishna Reddy, Chen-Yu Tsai,
	Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

On 2023-05-16 01:00, Jason Gunthorpe wrote:
> This callback requests the driver to create only a __IOMMU_DOMAIN_PAGING
> domain, so it saves a few lines in a lot of drivers needlessly checking
> the type.
> 
> More critically, this allows us to sweep out all the
> IOMMU_DOMAIN_UNMANAGED and IOMMU_DOMAIN_DMA checks from a lot of the
> drivers, simplifying what is going on in the code and ultimately removing
> the now-unused special cases in drivers where they did not support
> IOMMU_DOMAIN_DMA.
> 
> domain_alloc_paging() should return a struct iommu_domain that is
> functionally compatible with ARM_DMA_USE_IOMMU, dma-iommu.c and iommufd.
> 
> Be forwards looking and pass in a 'struct device *' argument. We can
> provide this when allocating the default_domain. No drivers will look at
> this.

As mentioned before, we already know we're going to need additional 
flags (and possibly data) to cover the existing set_pgtable_quirks 
use-case plus new stuff like the proposed dirty-tracking enable, so I'd 
be inclined to either add an extensible structure argument now to avoid 
future churn, or just not bother adding the device argument either until 
drivers can actually use it.

> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>   drivers/iommu/iommu.c | 18 +++++++++++++++---
>   include/linux/iommu.h |  3 +++
>   2 files changed, 18 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index c4cac1dcf80610..15aa51c356bd74 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -1995,14 +1995,25 @@ void iommu_set_fault_handler(struct iommu_domain *domain,
>   EXPORT_SYMBOL_GPL(iommu_set_fault_handler);
>   
>   static struct iommu_domain *__iommu_domain_alloc(const struct iommu_ops *ops,
> +						 struct device *dev,
>   						 unsigned int type)
>   {
>   	struct iommu_domain *domain;
>   
>   	if (type == IOMMU_DOMAIN_IDENTITY && ops->identity_domain)
>   		return ops->identity_domain;
> +	else if ((type == IOMMU_DOMAIN_UNMANAGED || type == IOMMU_DOMAIN_DMA) &&
> +		 ops->domain_alloc_paging) {
> +		/*
> +		 * For now exclude DMA_FQ since it is still a driver policy
> +		 * decision through domain_alloc() if we can use FQ mode.
> +		 */

That's sorted now, so the type test can neatly collapse down to "type & 
__IOMMU_DOMAIN_PAGING".

Thanks,
Robin.

> +		domain = ops->domain_alloc_paging(dev);
> +	} else if (ops->domain_alloc)
> +		domain = ops->domain_alloc(type);
> +	else
> +		return NULL;
>   
> -	domain = ops->domain_alloc(type);
>   	if (!domain)
>   		return NULL;
>   
> @@ -2033,14 +2044,15 @@ __iommu_group_domain_alloc(struct iommu_group *group, unsigned int type)
>   
>   	lockdep_assert_held(&group->mutex);
>   
> -	return __iommu_domain_alloc(dev_iommu_ops(dev), type);
> +	return __iommu_domain_alloc(dev_iommu_ops(dev), dev, type);
>   }
>   
>   struct iommu_domain *iommu_domain_alloc(const struct bus_type *bus)
>   {
>   	if (bus == NULL || bus->iommu_ops == NULL)
>   		return NULL;
> -	return __iommu_domain_alloc(bus->iommu_ops, IOMMU_DOMAIN_UNMANAGED);
> +	return __iommu_domain_alloc(bus->iommu_ops, NULL,
> +				    IOMMU_DOMAIN_UNMANAGED);
>   }
>   EXPORT_SYMBOL_GPL(iommu_domain_alloc);
>   
> diff --git a/include/linux/iommu.h b/include/linux/iommu.h
> index 387746f8273c99..18b0df42cc80d1 100644
> --- a/include/linux/iommu.h
> +++ b/include/linux/iommu.h
> @@ -227,6 +227,8 @@ struct iommu_iotlb_gather {
>    * struct iommu_ops - iommu ops and capabilities
>    * @capable: check capability
>    * @domain_alloc: allocate iommu domain
> + * @domain_alloc_paging: Allocate an iommu_domain that can be used for
> + *                       UNMANAGED, DMA, and DMA_FQ domain types.
>    * @probe_device: Add device to iommu driver handling
>    * @release_device: Remove device from iommu driver handling
>    * @probe_finalize: Do final setup work after the device is added to an IOMMU
> @@ -258,6 +260,7 @@ struct iommu_ops {
>   
>   	/* Domain allocation and freeing by the iommu driver */
>   	struct iommu_domain *(*domain_alloc)(unsigned iommu_domain_type);
> +	struct iommu_domain *(*domain_alloc_paging)(struct device *dev);
>   
>   	struct iommu_device *(*probe_device)(struct device *dev);
>   	void (*release_device)(struct device *dev);


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

* Re: [PATCH v2 09/25] iommu/fsl_pamu: Implement an IDENTITY domain
  2023-05-16  0:00   ` [PATCH v2 09/25] iommu/fsl_pamu: Implement an IDENTITY domain Jason Gunthorpe
@ 2023-06-01 19:37     ` Robin Murphy
  2023-06-01 19:46       ` Jason Gunthorpe
  0 siblings, 1 reply; 42+ messages in thread
From: Robin Murphy @ 2023-06-01 19:37 UTC (permalink / raw)
  To: Jason Gunthorpe, Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Samuel Holland, Thierry Reding, Krishna Reddy, Chen-Yu Tsai,
	Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

On 2023-05-16 01:00, Jason Gunthorpe wrote:
> Robin was able to check the documentation and what fsl_pamu has
> historically called detach_dev() is really putting the IOMMU into an
> IDENTITY mode.

Unfortunately it was the other way around - it's the call to 
fsl_setup_liodns() from fsl_pamu_probe() which leaves everything in 
bypass by default (the PAACE_ATM_NO_XLATE part, IIRC), whereas the 
detach_device() call here ends up disabling the given device's LIODN 
altogether. There doesn't appear to have ever been any code anywhere for 
putting things *back* into bypass after using a VFIO domain, so as-is 
these default domains would probably break all DMA :(

Thanks,
Robin.

> Move to the new core support for ARM_DMA_USE_IOMMU by defining
> ops->identity_domain. This is a ppc driver without any dma_ops, so ensure
> the identity translation is the default domain.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>   drivers/iommu/fsl_pamu_domain.c | 32 +++++++++++++++++++++++++++++---
>   1 file changed, 29 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
> index bce37229709965..ca4f5ebf028783 100644
> --- a/drivers/iommu/fsl_pamu_domain.c
> +++ b/drivers/iommu/fsl_pamu_domain.c
> @@ -283,15 +283,21 @@ static int fsl_pamu_attach_device(struct iommu_domain *domain,
>   	return ret;
>   }
>   
> -static void fsl_pamu_set_platform_dma(struct device *dev)
> +static int fsl_pamu_identity_attach(struct iommu_domain *platform_domain,
> +				    struct device *dev)
>   {
>   	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
> -	struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
> +	struct fsl_dma_domain *dma_domain;
>   	const u32 *prop;
>   	int len;
>   	struct pci_dev *pdev = NULL;
>   	struct pci_controller *pci_ctl;
>   
> +	if (domain == platform_domain || !domain)
> +		return 0;
> +
> +	dma_domain = to_fsl_dma_domain(domain);
> +
>   	/*
>   	 * Use LIODN of the PCI controller while detaching a
>   	 * PCI device.
> @@ -312,8 +318,18 @@ static void fsl_pamu_set_platform_dma(struct device *dev)
>   		detach_device(dev, dma_domain);
>   	else
>   		pr_debug("missing fsl,liodn property at %pOF\n", dev->of_node);
> +	return 0;
>   }
>   
> +static struct iommu_domain_ops fsl_pamu_identity_ops = {
> +	.attach_dev = fsl_pamu_identity_attach,
> +};
> +
> +static struct iommu_domain fsl_pamu_identity_domain = {
> +	.type = IOMMU_DOMAIN_IDENTITY,
> +	.ops = &fsl_pamu_identity_ops,
> +};
> +
>   /* Set the domain stash attribute */
>   int fsl_pamu_configure_l1_stash(struct iommu_domain *domain, u32 cpu)
>   {
> @@ -447,12 +463,22 @@ static struct iommu_device *fsl_pamu_probe_device(struct device *dev)
>   	return &pamu_iommu;
>   }
>   
> +static int fsl_pamu_def_domain_type(struct device *dev)
> +{
> +	/*
> +	 * This platform does not use dma_ops at all so the normally the iommu
> +	 * must be in identity mode
> +	 */
> +	return IOMMU_DOMAIN_IDENTITY;
> +}
> +
>   static const struct iommu_ops fsl_pamu_ops = {
> +	.identity_domain = &fsl_pamu_identity_domain,
> +	.def_domain_type = &fsl_pamu_def_domain_type,
>   	.capable	= fsl_pamu_capable,
>   	.domain_alloc	= fsl_pamu_domain_alloc,
>   	.probe_device	= fsl_pamu_probe_device,
>   	.device_group   = fsl_pamu_device_group,
> -	.set_platform_dma_ops = fsl_pamu_set_platform_dma,
>   	.default_domain_ops = &(const struct iommu_domain_ops) {
>   		.attach_dev	= fsl_pamu_attach_device,
>   		.iova_to_phys	= fsl_pamu_iova_to_phys,


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

* Re: [PATCH v2 09/25] iommu/fsl_pamu: Implement an IDENTITY domain
  2023-06-01 19:37     ` Robin Murphy
@ 2023-06-01 19:46       ` Jason Gunthorpe
  2023-06-01 19:53         ` Robin Murphy
  0 siblings, 1 reply; 42+ messages in thread
From: Jason Gunthorpe @ 2023-06-01 19:46 UTC (permalink / raw)
  To: Robin Murphy
  Cc: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Samuel Holland, Thierry Reding, Krishna Reddy, Chen-Yu Tsai,
	Will Deacon, Yong Wu, Chunyan Zhang, Lu Baolu, Dmitry Osipenko,
	Nicolin Chen, Niklas Schnelle, Steven Price, Thierry Reding

On Thu, Jun 01, 2023 at 08:37:45PM +0100, Robin Murphy wrote:
> On 2023-05-16 01:00, Jason Gunthorpe wrote:
> > Robin was able to check the documentation and what fsl_pamu has
> > historically called detach_dev() is really putting the IOMMU into an
> > IDENTITY mode.
> 
> Unfortunately it was the other way around - it's the call to
> fsl_setup_liodns() from fsl_pamu_probe() which leaves everything in bypass
> by default (the PAACE_ATM_NO_XLATE part, IIRC), whereas the detach_device()
> call here ends up disabling the given device's LIODN altogether

Er, I see.. Let me think about it, you convinced me to change it from
PLATFORM, so maybe we should go back to that if it is all wonky.

> There doesn't appear to have ever been any code anywhere for putting
> things *back* into bypass after using a VFIO domain, so as-is these
> default domains would probably break all DMA :(

Sounds like it just never worked right.

ie going to VFIO mode was always a one way trip and you can't go back
to a kernel driver.

I don't think this patch makes it worse because we call the identity
attach_dev in all the same places we called detach_dev in the first
place.

We add an extra call at the start of time, but that call is NOP'd
by this:

> >	if (domain == platform_domain || !domain)
> > +		return 0;
> > +

(bah, and the variable name needs updating too)

Honestly, I don't really want to fix FSL since it seems abandoned, so
either this patch or going back to PLATFORM seems like the best option.

Jason


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

* Re: [PATCH v2 25/25] iommu: Convert remaining simple drivers to domain_alloc_paging()
  2023-05-16  0:00   ` [PATCH v2 25/25] iommu: Convert remaining simple drivers " Jason Gunthorpe
@ 2023-06-01 19:47     ` Robin Murphy
  2023-06-01 20:37       ` Jason Gunthorpe
  0 siblings, 1 reply; 42+ messages in thread
From: Robin Murphy @ 2023-06-01 19:47 UTC (permalink / raw)
  To: Jason Gunthorpe, Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Samuel Holland, Thierry Reding, Krishna Reddy, Chen-Yu Tsai,
	Will Deacon, Yong Wu, Chunyan Zhang
  Cc: Lu Baolu, Dmitry Osipenko, Nicolin Chen, Niklas Schnelle,
	Steven Price, Thierry Reding

On 2023-05-16 01:00, Jason Gunthorpe wrote:
> These drivers don't support IOMMU_DOMAIN_DMA, so this commit effectively
> allows them to support that mode.
> 
> The prior work to require default_domains makes this safe because every
> one of these drivers is either compilation incompatible with dma-iommu.c,
> or already establishing a default_domain. In both cases alloc_domain()
> will never be called with IOMMU_DOMAIN_DMA for these drivers so it is safe
> to drop the test.
> 
> Removing these tests clarifies that the domain allocation path is only
> about the functionality of a paging domain and has nothing to do with
> policy of how the paging domain is used for UNMANAGED/DMA/DMA_FQ.
> 
> Tested-by: Niklas Schnelle <schnelle@linux.ibm.com>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>   drivers/iommu/fsl_pamu_domain.c | 7 ++-----
>   drivers/iommu/msm_iommu.c       | 7 ++-----
>   drivers/iommu/mtk_iommu_v1.c    | 7 ++-----
>   drivers/iommu/omap-iommu.c      | 7 ++-----
>   drivers/iommu/s390-iommu.c      | 7 ++-----
>   5 files changed, 10 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
> index ca4f5ebf028783..8d5d6a3acf9dfd 100644
> --- a/drivers/iommu/fsl_pamu_domain.c
> +++ b/drivers/iommu/fsl_pamu_domain.c
> @@ -192,13 +192,10 @@ static void fsl_pamu_domain_free(struct iommu_domain *domain)
>   	kmem_cache_free(fsl_pamu_domain_cache, dma_domain);
>   }
>   
> -static struct iommu_domain *fsl_pamu_domain_alloc(unsigned type)
> +static struct iommu_domain *fsl_pamu_domain_alloc_paging(struct device *dev)

This isn't a paging domain - it doesn't support map/unmap, and AFAICT 
all it has ever been intended to do is "isolate" accesses to within an 
aperture which is never set to anything less than the entire physical 
address space :/

I hate to imagine what the VFIO userspace applications looked like...

Thanks,
Robin.

>   {
>   	struct fsl_dma_domain *dma_domain;
>   
> -	if (type != IOMMU_DOMAIN_UNMANAGED)
> -		return NULL;
> -
>   	dma_domain = kmem_cache_zalloc(fsl_pamu_domain_cache, GFP_KERNEL);
>   	if (!dma_domain)
>   		return NULL;
> @@ -476,7 +473,7 @@ static const struct iommu_ops fsl_pamu_ops = {
>   	.identity_domain = &fsl_pamu_identity_domain,
>   	.def_domain_type = &fsl_pamu_def_domain_type,
>   	.capable	= fsl_pamu_capable,
> -	.domain_alloc	= fsl_pamu_domain_alloc,
> +	.domain_alloc_paging = fsl_pamu_domain_alloc_paging,
>   	.probe_device	= fsl_pamu_probe_device,
>   	.device_group   = fsl_pamu_device_group,
>   	.default_domain_ops = &(const struct iommu_domain_ops) {
> diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c
> index 26ed81cfeee897..a163cee0b7242d 100644
> --- a/drivers/iommu/msm_iommu.c
> +++ b/drivers/iommu/msm_iommu.c
> @@ -302,13 +302,10 @@ static void __program_context(void __iomem *base, int ctx,
>   	SET_M(base, ctx, 1);
>   }
>   
> -static struct iommu_domain *msm_iommu_domain_alloc(unsigned type)
> +static struct iommu_domain *msm_iommu_domain_alloc_paging(struct device *dev)
>   {
>   	struct msm_priv *priv;
>   
> -	if (type != IOMMU_DOMAIN_UNMANAGED)
> -		return NULL;
> -
>   	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
>   	if (!priv)
>   		goto fail_nomem;
> @@ -691,7 +688,7 @@ irqreturn_t msm_iommu_fault_handler(int irq, void *dev_id)
>   
>   static struct iommu_ops msm_iommu_ops = {
>   	.identity_domain = &msm_iommu_identity_domain,
> -	.domain_alloc = msm_iommu_domain_alloc,
> +	.domain_alloc_paging = msm_iommu_domain_alloc_paging,
>   	.probe_device = msm_iommu_probe_device,
>   	.device_group = generic_device_group,
>   	.pgsize_bitmap = MSM_IOMMU_PGSIZES,
> diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c
> index 7c0c1d50df5f75..67e044c1a7d93b 100644
> --- a/drivers/iommu/mtk_iommu_v1.c
> +++ b/drivers/iommu/mtk_iommu_v1.c
> @@ -270,13 +270,10 @@ static int mtk_iommu_v1_domain_finalise(struct mtk_iommu_v1_data *data)
>   	return 0;
>   }
>   
> -static struct iommu_domain *mtk_iommu_v1_domain_alloc(unsigned type)
> +static struct iommu_domain *mtk_iommu_v1_domain_alloc_paging(struct device *dev)
>   {
>   	struct mtk_iommu_v1_domain *dom;
>   
> -	if (type != IOMMU_DOMAIN_UNMANAGED)
> -		return NULL;
> -
>   	dom = kzalloc(sizeof(*dom), GFP_KERNEL);
>   	if (!dom)
>   		return NULL;
> @@ -585,7 +582,7 @@ static int mtk_iommu_v1_hw_init(const struct mtk_iommu_v1_data *data)
>   
>   static const struct iommu_ops mtk_iommu_v1_ops = {
>   	.identity_domain = &mtk_iommu_v1_identity_domain,
> -	.domain_alloc	= mtk_iommu_v1_domain_alloc,
> +	.domain_alloc_paging = mtk_iommu_v1_domain_alloc_paging,
>   	.probe_device	= mtk_iommu_v1_probe_device,
>   	.probe_finalize = mtk_iommu_v1_probe_finalize,
>   	.release_device	= mtk_iommu_v1_release_device,
> diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c
> index 34340ef15241bc..fcf99bd195b32e 100644
> --- a/drivers/iommu/omap-iommu.c
> +++ b/drivers/iommu/omap-iommu.c
> @@ -1580,13 +1580,10 @@ static struct iommu_domain omap_iommu_identity_domain = {
>   	.ops = &omap_iommu_identity_ops,
>   };
>   
> -static struct iommu_domain *omap_iommu_domain_alloc(unsigned type)
> +static struct iommu_domain *omap_iommu_domain_alloc_paging(struct device *dev)
>   {
>   	struct omap_iommu_domain *omap_domain;
>   
> -	if (type != IOMMU_DOMAIN_UNMANAGED)
> -		return NULL;
> -
>   	omap_domain = kzalloc(sizeof(*omap_domain), GFP_KERNEL);
>   	if (!omap_domain)
>   		return NULL;
> @@ -1748,7 +1745,7 @@ static struct iommu_group *omap_iommu_device_group(struct device *dev)
>   
>   static const struct iommu_ops omap_iommu_ops = {
>   	.identity_domain = &omap_iommu_identity_domain,
> -	.domain_alloc	= omap_iommu_domain_alloc,
> +	.domain_alloc_paging = omap_iommu_domain_alloc_paging,
>   	.probe_device	= omap_iommu_probe_device,
>   	.release_device	= omap_iommu_release_device,
>   	.device_group	= omap_iommu_device_group,
> diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c
> index f0c867c57a5b9b..5695ad71d60e24 100644
> --- a/drivers/iommu/s390-iommu.c
> +++ b/drivers/iommu/s390-iommu.c
> @@ -39,13 +39,10 @@ static bool s390_iommu_capable(struct device *dev, enum iommu_cap cap)
>   	}
>   }
>   
> -static struct iommu_domain *s390_domain_alloc(unsigned domain_type)
> +static struct iommu_domain *s390_domain_alloc_paging(struct device *dev)
>   {
>   	struct s390_domain *s390_domain;
>   
> -	if (domain_type != IOMMU_DOMAIN_UNMANAGED)
> -		return NULL;
> -
>   	s390_domain = kzalloc(sizeof(*s390_domain), GFP_KERNEL);
>   	if (!s390_domain)
>   		return NULL;
> @@ -447,7 +444,7 @@ void zpci_destroy_iommu(struct zpci_dev *zdev)
>   static const struct iommu_ops s390_iommu_ops = {
>   	.default_domain = &s390_iommu_platform_domain,
>   	.capable = s390_iommu_capable,
> -	.domain_alloc = s390_domain_alloc,
> +	.domain_alloc_paging = s390_domain_alloc_paging,
>   	.probe_device = s390_iommu_probe_device,
>   	.release_device = s390_iommu_release_device,
>   	.device_group = generic_device_group,


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

* Re: [PATCH v2 09/25] iommu/fsl_pamu: Implement an IDENTITY domain
  2023-06-01 19:46       ` Jason Gunthorpe
@ 2023-06-01 19:53         ` Robin Murphy
  2023-06-01 20:17           ` Jason Gunthorpe
  0 siblings, 1 reply; 42+ messages in thread
From: Robin Murphy @ 2023-06-01 19:53 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Samuel Holland, Thierry Reding, Krishna Reddy, Chen-Yu Tsai,
	Will Deacon, Yong Wu, Chunyan Zhang, Lu Baolu, Dmitry Osipenko,
	Nicolin Chen, Niklas Schnelle, Steven Price, Thierry Reding

On 2023-06-01 20:46, Jason Gunthorpe wrote:
> On Thu, Jun 01, 2023 at 08:37:45PM +0100, Robin Murphy wrote:
>> On 2023-05-16 01:00, Jason Gunthorpe wrote:
>>> Robin was able to check the documentation and what fsl_pamu has
>>> historically called detach_dev() is really putting the IOMMU into an
>>> IDENTITY mode.
>>
>> Unfortunately it was the other way around - it's the call to
>> fsl_setup_liodns() from fsl_pamu_probe() which leaves everything in bypass
>> by default (the PAACE_ATM_NO_XLATE part, IIRC), whereas the detach_device()
>> call here ends up disabling the given device's LIODN altogether
> 
> Er, I see.. Let me think about it, you convinced me to change it from
> PLATFORM, so maybe we should go back to that if it is all wonky.

FWIW I was thinking more along the lines of a token nominal identity 
domain where attach does nothing at all...

>> There doesn't appear to have ever been any code anywhere for putting
>> things *back* into bypass after using a VFIO domain, so as-is these
>> default domains would probably break all DMA :(
> 
> Sounds like it just never worked right.
> 
> ie going to VFIO mode was always a one way trip and you can't go back
> to a kernel driver.

...on the assumption that doing so wouldn't really be any less broken 
than it always has been :)

Thanks,
Robin.

> I don't think this patch makes it worse because we call the identity
> attach_dev in all the same places we called detach_dev in the first
> place.
> 
> We add an extra call at the start of time, but that call is NOP'd
> by this:
> 
>>> 	if (domain == platform_domain || !domain)
>>> +		return 0;
>>> +
> 
> (bah, and the variable name needs updating too)
> 
> Honestly, I don't really want to fix FSL since it seems abandoned, so
> either this patch or going back to PLATFORM seems like the best option.
> 
> Jason


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

* Re: [PATCH v2 04/25] iommu: Add IOMMU_DOMAIN_PLATFORM for S390
  2023-06-01 18:25     ` Robin Murphy
@ 2023-06-01 19:58       ` Jason Gunthorpe
  0 siblings, 0 replies; 42+ messages in thread
From: Jason Gunthorpe @ 2023-06-01 19:58 UTC (permalink / raw)
  To: Robin Murphy
  Cc: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Samuel Holland, Thierry Reding, Krishna Reddy, Chen-Yu Tsai,
	Will Deacon, Yong Wu, Chunyan Zhang, Lu Baolu, Dmitry Osipenko,
	Nicolin Chen, Niklas Schnelle, Steven Price, Thierry Reding

On Thu, Jun 01, 2023 at 07:25:32PM +0100, Robin Murphy wrote:
> On 2023-05-16 01:00, Jason Gunthorpe wrote:
> > The PLATFORM domain will be set as the default domain and attached as
> > normal during probe. The driver will ignore the initial attach from a NULL
> > domain to the PLATFORM domain.
> > 
> > After this, the PLATFORM domain's attach_dev will be called whenever we
> > detach from an UNMANAGED domain (eg for VFIO). This is the same time the
> > original design would have called op->detach_dev().
> > 
> > This is temporary until the S390 dma-iommu.c conversion is merged.
> 
> If we do need a stopgap here, can we please just call the current situation
> an identity domain? 

I really rather wouldn't lie, especially since we need something for
PPC more permanently. I definately don't want to call PPC IDENTITY.

> Then similarly for patch #3 - since we already know s390 is temporary, it
> seems an anathema to introduce a whole domain type with its own weird
> ops->default_domain mechanism solely for POWER to not actually use domains
> with.

A main point of this entire series is to remove the NULL default
domain, so power's weirdness has to be accomodated somehow.
 
> In terms of reasoning, I don't see that IOMMU_DOMAIN_PLATFORM is any more
> useful than a NULL default domain, it just renames the problem

Yes! Renaming is the whole point.

We are giving actuall meaningful names to all the things that drivers
did with NULL. The ones that actually implemented IDENTITY correctly
gets to be called IDENTITY, everyone else needs to get labeled
something else.

Then we can tell what is correct and what needs fixing at a glance.

That is the *whole point*.

> and gives us more code to maintain for the privilege.

The PLATFORM bit is only 3 lines of core code. Let's not overstate the
cost of a label please.

> As I say, though, we don't actually need to juggle the semantic of a
> "we don't know what's happening here" domain around any further,
> since it works out that a "we're not influencing anything here"
> domain actually suffices for what we want to reason about, and those
> are already well-defined. Sure, the platform DMA ops *might* be
> doing more, but that's beyond the scope of the IOMMU API either
> way. At that point, lo and behold, s390 and POWER now look just like
> ARM and the core code only needs a single special case for
> arch-specific default identity domains, lovely!

I'm really against mis-labeling things.

That is totally the wrong direction for this series. The point is to
label things correctly. Labeling something that is not an IDENTITY
operation as IDENTITY is just repeating the whole mistake of an
ill-defined NULL all over again.

Labels need to be correct, labels are cheap to add, so lets not be
afraid to use proper labels to actually describe the underlying
behavior.

If you don't like PLATFORM we can choose PRIVATE, OPAQUE or some other
label, but not IDENTITY.

Jason


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

* Re: [PATCH v2 09/25] iommu/fsl_pamu: Implement an IDENTITY domain
  2023-06-01 19:53         ` Robin Murphy
@ 2023-06-01 20:17           ` Jason Gunthorpe
  0 siblings, 0 replies; 42+ messages in thread
From: Jason Gunthorpe @ 2023-06-01 20:17 UTC (permalink / raw)
  To: Robin Murphy
  Cc: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Samuel Holland, Thierry Reding, Krishna Reddy, Chen-Yu Tsai,
	Will Deacon, Yong Wu, Chunyan Zhang, Lu Baolu, Dmitry Osipenko,
	Nicolin Chen, Niklas Schnelle, Steven Price, Thierry Reding

On Thu, Jun 01, 2023 at 08:53:41PM +0100, Robin Murphy wrote:
> On 2023-06-01 20:46, Jason Gunthorpe wrote:
> > On Thu, Jun 01, 2023 at 08:37:45PM +0100, Robin Murphy wrote:
> > > On 2023-05-16 01:00, Jason Gunthorpe wrote:
> > > > Robin was able to check the documentation and what fsl_pamu has
> > > > historically called detach_dev() is really putting the IOMMU into an
> > > > IDENTITY mode.
> > > 
> > > Unfortunately it was the other way around - it's the call to
> > > fsl_setup_liodns() from fsl_pamu_probe() which leaves everything in bypass
> > > by default (the PAACE_ATM_NO_XLATE part, IIRC), whereas the detach_device()
> > > call here ends up disabling the given device's LIODN altogether
> > 
> > Er, I see.. Let me think about it, you convinced me to change it from
> > PLATFORM, so maybe we should go back to that if it is all wonky.
> 
> FWIW I was thinking more along the lines of a token nominal identity domain
> where attach does nothing at all...

I'm worried that would create security problems for VFIO.. At least
the driver currently wipes out the VFIO installed translation which
sounds like the right thing to do.

So, I think my first patch was right, we should label this
PLATFORM/PRIVATE/whatever and just leave it as is with some comments
explaining this thread. Based on the same rational as my prior email
that we should label things correctly and this detach_dev is doing
BLOCKING.

Jason


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

* Re: [PATCH v2 25/25] iommu: Convert remaining simple drivers to domain_alloc_paging()
  2023-06-01 19:47     ` Robin Murphy
@ 2023-06-01 20:37       ` Jason Gunthorpe
  0 siblings, 0 replies; 42+ messages in thread
From: Jason Gunthorpe @ 2023-06-01 20:37 UTC (permalink / raw)
  To: Robin Murphy
  Cc: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Nicholas Piggin, Michael Ellerman, Orson Zhai, Rob Clark,
	Samuel Holland, Thierry Reding, Krishna Reddy, Chen-Yu Tsai,
	Will Deacon, Yong Wu, Chunyan Zhang, Lu Baolu, Dmitry Osipenko,
	Nicolin Chen, Niklas Schnelle, Steven Price, Thierry Reding

On Thu, Jun 01, 2023 at 08:47:28PM +0100, Robin Murphy wrote:
> On 2023-05-16 01:00, Jason Gunthorpe wrote:
> > These drivers don't support IOMMU_DOMAIN_DMA, so this commit effectively
> > allows them to support that mode.
> > 
> > The prior work to require default_domains makes this safe because every
> > one of these drivers is either compilation incompatible with dma-iommu.c,
> > or already establishing a default_domain. In both cases alloc_domain()
> > will never be called with IOMMU_DOMAIN_DMA for these drivers so it is safe
> > to drop the test.
> > 
> > Removing these tests clarifies that the domain allocation path is only
> > about the functionality of a paging domain and has nothing to do with
> > policy of how the paging domain is used for UNMANAGED/DMA/DMA_FQ.
> > 
> > Tested-by: Niklas Schnelle <schnelle@linux.ibm.com>
> > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> > ---
> >   drivers/iommu/fsl_pamu_domain.c | 7 ++-----
> >   drivers/iommu/msm_iommu.c       | 7 ++-----
> >   drivers/iommu/mtk_iommu_v1.c    | 7 ++-----
> >   drivers/iommu/omap-iommu.c      | 7 ++-----
> >   drivers/iommu/s390-iommu.c      | 7 ++-----
> >   5 files changed, 10 insertions(+), 25 deletions(-)
> > 
> > diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
> > index ca4f5ebf028783..8d5d6a3acf9dfd 100644
> > --- a/drivers/iommu/fsl_pamu_domain.c
> > +++ b/drivers/iommu/fsl_pamu_domain.c
> > @@ -192,13 +192,10 @@ static void fsl_pamu_domain_free(struct iommu_domain *domain)
> >   	kmem_cache_free(fsl_pamu_domain_cache, dma_domain);
> >   }
> > -static struct iommu_domain *fsl_pamu_domain_alloc(unsigned type)
> > +static struct iommu_domain *fsl_pamu_domain_alloc_paging(struct device *dev)
> 
> This isn't a paging domain - it doesn't support map/unmap, and AFAICT all it
> has ever been intended to do is "isolate" accesses to within an aperture
> which is never set to anything less than the entire physical address space
> :/

Uh.. Yes, I missed that.. Yikes

I'll drop that hunk

It would be horrifying if this driver was ever used with VFIO, we
should definitely block that as it doesn't meet VFIO's security model..

It kind of looks like all this is to support
drivers/soc/fsl/qbman/qman_portal.c which does call
iommu_domain_alloc()?

It looks like the only point is to call fsl_pamu_configure_l1_stash()

Thanks,
Jason


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

* Re: [PATCH v2 23/25] iommu: Add ops->domain_alloc_paging()
  2023-06-01 19:17     ` Robin Murphy
@ 2023-06-01 20:47       ` Jason Gunthorpe
  0 siblings, 0 replies; 42+ messages in thread
From: Jason Gunthorpe @ 2023-06-01 20:47 UTC (permalink / raw)
  To: Robin Murphy
  Cc: Andy Gross, Alim Akhtar, Bjorn Andersson,
	AngeloGioacchino Del Regno, Baolin Wang, Christophe Leroy,
	Gerald Schaefer, Heiko Stuebner, iommu, Jernej Skrabec,
	Jonathan Hunter, Joerg Roedel, Kevin Tian, Konrad Dybcio,
	Krzysztof Kozlowski, linux-arm-kernel, linux-arm-msm,
	linux-mediatek, linux-rockchip, linux-s390, linux-samsung-soc,
	linux-sunxi, linux-tegra, Russell King, linuxppc-dev,
	Marek Szyprowski, Matthias Brugger, Matthew Rosato,
	Michael Ellerman, Nicholas Piggin, Orson Zhai, Rob Clark,
	Samuel Holland, Thierry Reding, Krishna Reddy, Chen-Yu Tsai,
	Will Deacon, Yong Wu, Chunyan Zhang, Lu Baolu, Dmitry Osipenko,
	Nicolin Chen, Niklas Schnelle, Steven Price, Thierry Reding

On Thu, Jun 01, 2023 at 08:17:56PM +0100, Robin Murphy wrote:
> On 2023-05-16 01:00, Jason Gunthorpe wrote:
> > This callback requests the driver to create only a __IOMMU_DOMAIN_PAGING
> > domain, so it saves a few lines in a lot of drivers needlessly checking
> > the type.
> > 
> > More critically, this allows us to sweep out all the
> > IOMMU_DOMAIN_UNMANAGED and IOMMU_DOMAIN_DMA checks from a lot of the
> > drivers, simplifying what is going on in the code and ultimately removing
> > the now-unused special cases in drivers where they did not support
> > IOMMU_DOMAIN_DMA.
> > 
> > domain_alloc_paging() should return a struct iommu_domain that is
> > functionally compatible with ARM_DMA_USE_IOMMU, dma-iommu.c and iommufd.
> > 
> > Be forwards looking and pass in a 'struct device *' argument. We can
> > provide this when allocating the default_domain. No drivers will look at
> > this.
> 
> As mentioned before, we already know we're going to need additional flags
> (and possibly data) to cover the existing set_pgtable_quirks use-case plus
> new stuff like the proposed dirty-tracking enable, so I'd be inclined to
> either add an extensible structure argument now to avoid future
> churn,

I think I said this doesn't really work out because you still have to
go into every driver and code up a 'does not support' check and fail
if any new extension is added. Basically the same churn as adding a
function argument.

Adding more ops is a possible smoother way to support this. Keep
alloc_paging() for these simple drivers and we can add an op with a
big signature and structure or whatever for the fewer fully featured
drivers.

This way the core code can do the 'do not support' checks in one place
based on the set ops and we keep boiler plate code out of alot of
drivers.

> or just not bother adding the device argument either until drivers
> can actually use it.

I debated this, I figured we'd use it pretty quickly, but certainly it
can be taken out.

> > @@ -1995,14 +1995,25 @@ void iommu_set_fault_handler(struct iommu_domain *domain,
> >   EXPORT_SYMBOL_GPL(iommu_set_fault_handler);
> >   static struct iommu_domain *__iommu_domain_alloc(const struct iommu_ops *ops,
> > +						 struct device *dev,
> >   						 unsigned int type)
> >   {
> >   	struct iommu_domain *domain;
> >   	if (type == IOMMU_DOMAIN_IDENTITY && ops->identity_domain)
> >   		return ops->identity_domain;
> > +	else if ((type == IOMMU_DOMAIN_UNMANAGED || type == IOMMU_DOMAIN_DMA) &&
> > +		 ops->domain_alloc_paging) {
> > +		/*
> > +		 * For now exclude DMA_FQ since it is still a driver policy
> > +		 * decision through domain_alloc() if we can use FQ mode.
> > +		 */
> 
> That's sorted now, so the type test can neatly collapse down to "type &
> __IOMMU_DOMAIN_PAGING".

Thanks, I rebase it on Joerg's tree with that series and fix it up

Jason


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

end of thread, other threads:[~2023-06-01 20:47 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20230516000132eucas1p2d20a1c49d4711fda942a3c3a842384e6@eucas1p2.samsung.com>
2023-05-16  0:00 ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Jason Gunthorpe
2023-05-16  0:00   ` [PATCH v2 01/25] iommu: Add iommu_ops->identity_domain Jason Gunthorpe
2023-05-16  0:00   ` [PATCH v2 02/25] iommu: Add IOMMU_DOMAIN_PLATFORM Jason Gunthorpe
2023-05-16  0:00   ` [PATCH v2 03/25] powerpc/iommu: Setup a default domain and remove set_platform_dma_ops Jason Gunthorpe
2023-05-16  0:00   ` [PATCH v2 04/25] iommu: Add IOMMU_DOMAIN_PLATFORM for S390 Jason Gunthorpe
2023-06-01 18:25     ` Robin Murphy
2023-06-01 19:58       ` Jason Gunthorpe
2023-05-16  0:00   ` [PATCH v2 05/25] iommu/tegra-gart: Remove tegra-gart Jason Gunthorpe
2023-06-01 16:51     ` Thierry Reding
2023-05-16  0:00   ` [PATCH v2 06/25] iommu/mtk_iommu_v1: Implement an IDENTITY domain Jason Gunthorpe
2023-05-16  0:00   ` [PATCH v2 07/25] iommu: Reorganize iommu_get_default_domain_type() to respect def_domain_type() Jason Gunthorpe
2023-05-16  0:00   ` [PATCH v2 08/25] iommu: Allow an IDENTITY domain as the default_domain in ARM32 Jason Gunthorpe
2023-06-01 18:57     ` Robin Murphy
2023-05-16  0:00   ` [PATCH v2 09/25] iommu/fsl_pamu: Implement an IDENTITY domain Jason Gunthorpe
2023-06-01 19:37     ` Robin Murphy
2023-06-01 19:46       ` Jason Gunthorpe
2023-06-01 19:53         ` Robin Murphy
2023-06-01 20:17           ` Jason Gunthorpe
2023-05-16  0:00   ` [PATCH v2 10/25] iommu/exynos: " Jason Gunthorpe
2023-05-17 22:41     ` Marek Szyprowski
2023-05-16  0:00   ` [PATCH v2 11/25] iommu/tegra-smmu: " Jason Gunthorpe
2023-05-16  0:00   ` [PATCH v2 12/25] iommu/tegra-smmu: Support DMA domains in tegra Jason Gunthorpe
2023-05-16  0:00   ` [PATCH v2 13/25] iommu/omap: Implement an IDENTITY domain Jason Gunthorpe
2023-05-16  0:00   ` [PATCH v2 14/25] iommu/msm: " Jason Gunthorpe
2023-05-16  0:00   ` [PATCH v2 15/25] iommufd/selftest: Make the mock iommu driver into a real driver Jason Gunthorpe
2023-05-16  0:00   ` [PATCH v2 16/25] iommu: Remove ops->set_platform_dma_ops() Jason Gunthorpe
2023-05-16  0:00   ` [PATCH v2 17/25] iommu/qcom_iommu: Add an IOMMU_IDENTITIY_DOMAIN Jason Gunthorpe
2023-05-16  0:00   ` [PATCH v2 18/25] iommu/ipmmu: " Jason Gunthorpe
2023-05-16  0:00   ` [PATCH v2 19/25] iommu/mtk_iommu: " Jason Gunthorpe
2023-05-16  0:00   ` [PATCH v2 20/25] iommu/sun50i: " Jason Gunthorpe
2023-05-16  0:00   ` [PATCH v2 21/25] iommu: Require a default_domain for all iommu drivers Jason Gunthorpe
2023-05-16  0:00   ` [PATCH v2 22/25] iommu: Add __iommu_group_domain_alloc() Jason Gunthorpe
2023-05-16  0:00   ` [PATCH v2 23/25] iommu: Add ops->domain_alloc_paging() Jason Gunthorpe
2023-06-01 19:17     ` Robin Murphy
2023-06-01 20:47       ` Jason Gunthorpe
2023-05-16  0:00   ` [PATCH v2 24/25] iommu: Convert simple drivers with DOMAIN_DMA to domain_alloc_paging() Jason Gunthorpe
2023-05-16  0:00   ` [PATCH v2 25/25] iommu: Convert remaining simple drivers " Jason Gunthorpe
2023-06-01 19:47     ` Robin Murphy
2023-06-01 20:37       ` Jason Gunthorpe
2023-05-17 22:42   ` [PATCH v2 00/25] iommu: Make default_domain's mandatory Marek Szyprowski
2023-05-17 23:32   ` Nicolin Chen
2023-05-18 10:56   ` Steven Price

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).