linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] iommu: Convert dart & iommufd to the new domain_alloc_paging()
@ 2023-09-22 17:07 Jason Gunthorpe
  2023-09-22 17:07 ` [PATCH 1/8] iommu: Move IOMMU_DOMAIN_BLOCKED global statics to ops->blocked_domain Jason Gunthorpe
                   ` (7 more replies)
  0 siblings, 8 replies; 21+ messages in thread
From: Jason Gunthorpe @ 2023-09-22 17:07 UTC (permalink / raw)
  To: Alyssa Rosenzweig, asahi, Lu Baolu, Christophe Leroy,
	David Woodhouse, iommu, Joerg Roedel, Kevin Tian,
	linux-arm-kernel, linuxppc-dev, Hector Martin, Michael Ellerman,
	Nicholas Piggin, Robin Murphy, Sven Peter, Will Deacon

Continue converting drivers to the new interface. Introduce
ops->blocked_domain to hold the global static BLOCKED domain and convert
all drivers supporting BLOCKED to use it.

This makes it trivial for dart and iommufd to convert over to
domain_alloc_paging().

There are six drivers remaining:

drivers/iommu/amd/iommu.c:      .domain_alloc = amd_iommu_domain_alloc,
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c:    .domain_alloc           = arm_smmu_domain_alloc,
drivers/iommu/arm/arm-smmu/arm-smmu.c:  .domain_alloc           = arm_smmu_domain_alloc,
drivers/iommu/fsl_pamu_domain.c:        .domain_alloc   = fsl_pamu_domain_alloc,
drivers/iommu/intel/iommu.c:    .domain_alloc           = intel_iommu_domain_alloc,
drivers/iommu/virtio-iommu.c:   .domain_alloc           = viommu_domain_alloc,

The follows the "Make default_domain's mandatory" series

Jason Gunthorpe (8):
  iommu: Move IOMMU_DOMAIN_BLOCKED global statics to ops->blocked_domain
  iommu/vt-d: Update the definition of the blocking domain
  iommu/vt-d: Use ops->blocked_domain
  iommufd: Convert to alloc_domain_paging()
  iommu/dart: Use static global identity domains
  iommu/dart: Move the blocked domain support to a global static
  iommu/dart: Convert to domain_alloc_paging()
  iommu/dart: Call apple_dart_finalize_domain() as part of
    alloc_paging()

 arch/powerpc/kernel/iommu.c      |   9 +--
 drivers/iommu/apple-dart.c       | 124 ++++++++++++++++++++-----------
 drivers/iommu/intel/iommu.c      |   7 +-
 drivers/iommu/iommu.c            |   2 +
 drivers/iommu/iommufd/selftest.c |  11 +--
 include/linux/iommu.h            |   3 +
 6 files changed, 91 insertions(+), 65 deletions(-)


base-commit: 494e0fef6db2e604bca0fc552d92b760b6e25d10
-- 
2.42.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 1/8] iommu: Move IOMMU_DOMAIN_BLOCKED global statics to ops->blocked_domain
  2023-09-22 17:07 [PATCH 0/8] iommu: Convert dart & iommufd to the new domain_alloc_paging() Jason Gunthorpe
@ 2023-09-22 17:07 ` Jason Gunthorpe
  2023-09-25  2:26   ` Baolu Lu
  2023-09-22 17:07 ` [PATCH 2/8] iommu/vt-d: Update the definition of the blocking domain Jason Gunthorpe
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 21+ messages in thread
From: Jason Gunthorpe @ 2023-09-22 17:07 UTC (permalink / raw)
  To: Alyssa Rosenzweig, asahi, Lu Baolu, Christophe Leroy,
	David Woodhouse, iommu, Joerg Roedel, Kevin Tian,
	linux-arm-kernel, linuxppc-dev, Hector Martin, Michael Ellerman,
	Nicholas Piggin, Robin Murphy, Sven Peter, Will Deacon

Following the pattern of identity domains, just assign the BLOCKED domain
global statics to a value in ops. Update the core code to use the global
static directly.

Update powerpc to use the new scheme and remove its empty domain_alloc
callback.

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

diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c
index d6ad3fde85a212..3c1d10be19c4c7 100644
--- a/arch/powerpc/kernel/iommu.c
+++ b/arch/powerpc/kernel/iommu.c
@@ -1327,13 +1327,6 @@ static bool spapr_tce_iommu_capable(struct device *dev, enum iommu_cap cap)
 	return false;
 }
 
-static struct iommu_domain *spapr_tce_iommu_domain_alloc(unsigned int type)
-{
-	if (type != IOMMU_DOMAIN_BLOCKED)
-		return NULL;
-	return &spapr_tce_blocked_domain;
-}
-
 static struct iommu_device *spapr_tce_iommu_probe_device(struct device *dev)
 {
 	struct pci_dev *pdev;
@@ -1368,8 +1361,8 @@ 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,
+	.blocked_domain = &spapr_tce_blocked_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,
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index fe033043be467a..7fa53d28feca87 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -2049,6 +2049,8 @@ static struct iommu_domain *__iommu_domain_alloc(const struct iommu_ops *ops,
 
 	if (alloc_type == IOMMU_DOMAIN_IDENTITY && ops->identity_domain)
 		return ops->identity_domain;
+	else if (alloc_type == IOMMU_DOMAIN_BLOCKED && ops->blocked_domain)
+		return ops->blocked_domain;
 	else if (type & __IOMMU_DOMAIN_PAGING && ops->domain_alloc_paging)
 		domain = ops->domain_alloc_paging(dev);
 	else if (ops->domain_alloc)
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 4f65879df853e4..6f9e0aacc4431a 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -264,6 +264,8 @@ struct iommu_iotlb_gather {
  * @owner: Driver module providing these ops
  * @identity_domain: An always available, always attachable identity
  *                   translation.
+ * @blocked_domain: An always available, always attachable blocking
+ *                  translation.
  * @default_domain: If not NULL this will always be set as the default domain.
  *                  This should be an IDENTITY/BLOCKED/PLATFORM domain.
  *                  Do not use in new drivers.
@@ -302,6 +304,7 @@ struct iommu_ops {
 	unsigned long pgsize_bitmap;
 	struct module *owner;
 	struct iommu_domain *identity_domain;
+	struct iommu_domain *blocked_domain;
 	struct iommu_domain *default_domain;
 };
 
-- 
2.42.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 2/8] iommu/vt-d: Update the definition of the blocking domain
  2023-09-22 17:07 [PATCH 0/8] iommu: Convert dart & iommufd to the new domain_alloc_paging() Jason Gunthorpe
  2023-09-22 17:07 ` [PATCH 1/8] iommu: Move IOMMU_DOMAIN_BLOCKED global statics to ops->blocked_domain Jason Gunthorpe
@ 2023-09-22 17:07 ` Jason Gunthorpe
  2023-09-25  2:27   ` Baolu Lu
  2023-09-22 17:07 ` [PATCH 3/8] iommu/vt-d: Use ops->blocked_domain Jason Gunthorpe
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 21+ messages in thread
From: Jason Gunthorpe @ 2023-09-22 17:07 UTC (permalink / raw)
  To: Alyssa Rosenzweig, asahi, Lu Baolu, Christophe Leroy,
	David Woodhouse, iommu, Joerg Roedel, Kevin Tian,
	linux-arm-kernel, linuxppc-dev, Hector Martin, Michael Ellerman,
	Nicholas Piggin, Robin Murphy, Sven Peter, Will Deacon

The global static should pre-define the type and the NOP free function can
be now left as NULL.

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

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index c8036caad24e7a..0d0cb2534972a2 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -4029,9 +4029,9 @@ static int blocking_domain_attach_dev(struct iommu_domain *domain,
 }
 
 static struct iommu_domain blocking_domain = {
+	.type = IOMMU_DOMAIN_BLOCKED,
 	.ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= blocking_domain_attach_dev,
-		.free		= intel_iommu_domain_free
 	}
 };
 
@@ -4075,7 +4075,7 @@ static struct iommu_domain *intel_iommu_domain_alloc(unsigned type)
 
 static void intel_iommu_domain_free(struct iommu_domain *domain)
 {
-	if (domain != &si_domain->domain && domain != &blocking_domain)
+	if (domain != &si_domain->domain)
 		domain_exit(to_dmar_domain(domain));
 }
 
-- 
2.42.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 3/8] iommu/vt-d: Use ops->blocked_domain
  2023-09-22 17:07 [PATCH 0/8] iommu: Convert dart & iommufd to the new domain_alloc_paging() Jason Gunthorpe
  2023-09-22 17:07 ` [PATCH 1/8] iommu: Move IOMMU_DOMAIN_BLOCKED global statics to ops->blocked_domain Jason Gunthorpe
  2023-09-22 17:07 ` [PATCH 2/8] iommu/vt-d: Update the definition of the blocking domain Jason Gunthorpe
@ 2023-09-22 17:07 ` Jason Gunthorpe
  2023-09-25  2:29   ` Baolu Lu
  2023-09-22 17:07 ` [PATCH 4/8] iommufd: Convert to alloc_domain_paging() Jason Gunthorpe
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 21+ messages in thread
From: Jason Gunthorpe @ 2023-09-22 17:07 UTC (permalink / raw)
  To: Alyssa Rosenzweig, asahi, Lu Baolu, Christophe Leroy,
	David Woodhouse, iommu, Joerg Roedel, Kevin Tian,
	linux-arm-kernel, linuxppc-dev, Hector Martin, Michael Ellerman,
	Nicholas Piggin, Robin Murphy, Sven Peter, Will Deacon

Trivially migrate to the ops->blocked_domain for the existing global
static.

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

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 0d0cb2534972a2..b79188d0c67e95 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -4041,8 +4041,6 @@ static struct iommu_domain *intel_iommu_domain_alloc(unsigned type)
 	struct iommu_domain *domain;
 
 	switch (type) {
-	case IOMMU_DOMAIN_BLOCKED:
-		return &blocking_domain;
 	case IOMMU_DOMAIN_DMA:
 	case IOMMU_DOMAIN_UNMANAGED:
 		dmar_domain = alloc_domain(type);
@@ -4803,6 +4801,7 @@ static void *intel_iommu_hw_info(struct device *dev, u32 *length, u32 *type)
 }
 
 const struct iommu_ops intel_iommu_ops = {
+	.blocked_domain		= &blocking_domain,
 	.capable		= intel_iommu_capable,
 	.hw_info		= intel_iommu_hw_info,
 	.domain_alloc		= intel_iommu_domain_alloc,
-- 
2.42.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 4/8] iommufd: Convert to alloc_domain_paging()
  2023-09-22 17:07 [PATCH 0/8] iommu: Convert dart & iommufd to the new domain_alloc_paging() Jason Gunthorpe
                   ` (2 preceding siblings ...)
  2023-09-22 17:07 ` [PATCH 3/8] iommu/vt-d: Use ops->blocked_domain Jason Gunthorpe
@ 2023-09-22 17:07 ` Jason Gunthorpe
  2023-09-22 17:07 ` [PATCH 5/8] iommu/dart: Use static global identity domains Jason Gunthorpe
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 21+ messages in thread
From: Jason Gunthorpe @ 2023-09-22 17:07 UTC (permalink / raw)
  To: Alyssa Rosenzweig, asahi, Lu Baolu, Christophe Leroy,
	David Woodhouse, iommu, Joerg Roedel, Kevin Tian,
	linux-arm-kernel, linuxppc-dev, Hector Martin, Michael Ellerman,
	Nicholas Piggin, Robin Murphy, Sven Peter, Will Deacon

Move the global static blocked domain to the ops and convert the unmanaged
domain to domain_alloc_paging.

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

diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c
index fb981ba97c4e87..ee607984709102 100644
--- a/drivers/iommu/iommufd/selftest.c
+++ b/drivers/iommu/iommufd/selftest.c
@@ -141,16 +141,10 @@ static void *mock_domain_hw_info(struct device *dev, u32 *length, u32 *type)
 	return info;
 }
 
-static struct iommu_domain *mock_domain_alloc(unsigned int iommu_domain_type)
+static struct iommu_domain *mock_domain_alloc_paging(struct device *dev)
 {
 	struct mock_iommu_domain *mock;
 
-	if (iommu_domain_type == IOMMU_DOMAIN_BLOCKED)
-		return &mock_blocking_domain;
-
-	if (iommu_domain_type != IOMMU_DOMAIN_UNMANAGED)
-		return NULL;
-
 	mock = kzalloc(sizeof(*mock), GFP_KERNEL);
 	if (!mock)
 		return NULL;
@@ -295,10 +289,11 @@ static const struct iommu_ops mock_ops = {
 	 * because it is zero.
 	 */
 	.default_domain = &mock_blocking_domain,
+	.blocked_domain = &mock_blocking_domain,
 	.owner = THIS_MODULE,
 	.pgsize_bitmap = MOCK_IO_PAGE_SIZE,
 	.hw_info = mock_domain_hw_info,
-	.domain_alloc = mock_domain_alloc,
+	.domain_alloc_paging = mock_domain_alloc_paging,
 	.capable = mock_domain_capable,
 	.device_group = generic_device_group,
 	.probe_device = mock_probe_device,
-- 
2.42.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 5/8] iommu/dart: Use static global identity domains
  2023-09-22 17:07 [PATCH 0/8] iommu: Convert dart & iommufd to the new domain_alloc_paging() Jason Gunthorpe
                   ` (3 preceding siblings ...)
  2023-09-22 17:07 ` [PATCH 4/8] iommufd: Convert to alloc_domain_paging() Jason Gunthorpe
@ 2023-09-22 17:07 ` Jason Gunthorpe
  2023-09-26 18:49   ` Janne Grunau
  2023-09-22 17:07 ` [PATCH 6/8] iommu/dart: Move the blocked domain support to a global static Jason Gunthorpe
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 21+ messages in thread
From: Jason Gunthorpe @ 2023-09-22 17:07 UTC (permalink / raw)
  To: Alyssa Rosenzweig, asahi, Lu Baolu, Christophe Leroy,
	David Woodhouse, iommu, Joerg Roedel, Kevin Tian,
	linux-arm-kernel, linuxppc-dev, Hector Martin, Michael Ellerman,
	Nicholas Piggin, Robin Murphy, Sven Peter, Will Deacon

Move to the new static global for identity domains. Move the identity
specific code to apple_dart_attach_dev_identity().

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

diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
index 6bc2ad2207c3da..424f779ccc34df 100644
--- a/drivers/iommu/apple-dart.c
+++ b/drivers/iommu/apple-dart.c
@@ -658,11 +658,7 @@ static int apple_dart_attach_dev(struct iommu_domain *domain,
 	struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
 	struct apple_dart_domain *dart_domain = to_dart_domain(domain);
 
-	if (cfg->stream_maps[0].dart->force_bypass &&
-	    domain->type != IOMMU_DOMAIN_IDENTITY)
-		return -EINVAL;
-	if (!cfg->stream_maps[0].dart->supports_bypass &&
-	    domain->type == IOMMU_DOMAIN_IDENTITY)
+	if (cfg->stream_maps[0].dart->force_bypass)
 		return -EINVAL;
 
 	ret = apple_dart_finalize_domain(domain, cfg);
@@ -683,15 +679,37 @@ static int apple_dart_attach_dev(struct iommu_domain *domain,
 		for_each_stream_map(i, cfg, stream_map)
 			apple_dart_hw_disable_dma(stream_map);
 		break;
-	case IOMMU_DOMAIN_IDENTITY:
-		for_each_stream_map(i, cfg, stream_map)
-			apple_dart_hw_enable_bypass(stream_map);
-		break;
+	default:
+		return -EINVAL;
 	}
 
 	return ret;
 }
 
+static int apple_dart_attach_dev_identity(struct iommu_domain *domain,
+					  struct device *dev)
+{
+	struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
+	struct apple_dart_stream_map *stream_map;
+	int i;
+
+	if (!cfg->stream_maps[0].dart->supports_bypass)
+		return -EINVAL;
+
+	for_each_stream_map(i, cfg, stream_map)
+		apple_dart_hw_enable_bypass(stream_map);
+	return 0;
+}
+
+static const struct iommu_domain_ops apple_dart_identity_ops = {
+	.attach_dev = apple_dart_attach_dev_identity,
+};
+
+static struct iommu_domain apple_dart_identity_domain = {
+	.type = IOMMU_DOMAIN_IDENTITY,
+	.ops = &apple_dart_identity_ops,
+};
+
 static struct iommu_device *apple_dart_probe_device(struct device *dev)
 {
 	struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
@@ -722,7 +740,7 @@ static struct iommu_domain *apple_dart_domain_alloc(unsigned int type)
 	struct apple_dart_domain *dart_domain;
 
 	if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED &&
-	    type != IOMMU_DOMAIN_IDENTITY && type != IOMMU_DOMAIN_BLOCKED)
+	    type != IOMMU_DOMAIN_BLOCKED)
 		return NULL;
 
 	dart_domain = kzalloc(sizeof(*dart_domain), GFP_KERNEL);
@@ -732,7 +750,7 @@ static struct iommu_domain *apple_dart_domain_alloc(unsigned int type)
 	mutex_init(&dart_domain->init_lock);
 
 	/* no need to allocate pgtbl_ops or do any other finalization steps */
-	if (type == IOMMU_DOMAIN_IDENTITY || type == IOMMU_DOMAIN_BLOCKED)
+	if (type == IOMMU_DOMAIN_BLOCKED)
 		dart_domain->finalized = true;
 
 	return &dart_domain->domain;
@@ -947,6 +965,7 @@ static void apple_dart_get_resv_regions(struct device *dev,
 }
 
 static const struct iommu_ops apple_dart_iommu_ops = {
+	.identity_domain = &apple_dart_identity_domain,
 	.domain_alloc = apple_dart_domain_alloc,
 	.probe_device = apple_dart_probe_device,
 	.release_device = apple_dart_release_device,
-- 
2.42.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 6/8] iommu/dart: Move the blocked domain support to a global static
  2023-09-22 17:07 [PATCH 0/8] iommu: Convert dart & iommufd to the new domain_alloc_paging() Jason Gunthorpe
                   ` (4 preceding siblings ...)
  2023-09-22 17:07 ` [PATCH 5/8] iommu/dart: Use static global identity domains Jason Gunthorpe
@ 2023-09-22 17:07 ` Jason Gunthorpe
  2023-09-26 19:05   ` Janne Grunau
  2023-09-22 17:07 ` [PATCH 7/8] iommu/dart: Convert to domain_alloc_paging() Jason Gunthorpe
  2023-09-22 17:07 ` [PATCH 8/8] iommu/dart: Call apple_dart_finalize_domain() as part of alloc_paging() Jason Gunthorpe
  7 siblings, 1 reply; 21+ messages in thread
From: Jason Gunthorpe @ 2023-09-22 17:07 UTC (permalink / raw)
  To: Alyssa Rosenzweig, asahi, Lu Baolu, Christophe Leroy,
	David Woodhouse, iommu, Joerg Roedel, Kevin Tian,
	linux-arm-kernel, linuxppc-dev, Hector Martin, Michael Ellerman,
	Nicholas Piggin, Robin Murphy, Sven Peter, Will Deacon

Move to the new static global for blocked domains. Move the blocked
specific code to apple_dart_attach_dev_blocked().

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

diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
index 424f779ccc34df..376f4c5461e8f7 100644
--- a/drivers/iommu/apple-dart.c
+++ b/drivers/iommu/apple-dart.c
@@ -675,10 +675,6 @@ static int apple_dart_attach_dev(struct iommu_domain *domain,
 		for_each_stream_map(i, cfg, stream_map)
 			apple_dart_setup_translation(dart_domain, stream_map);
 		break;
-	case IOMMU_DOMAIN_BLOCKED:
-		for_each_stream_map(i, cfg, stream_map)
-			apple_dart_hw_disable_dma(stream_map);
-		break;
 	default:
 		return -EINVAL;
 	}
@@ -710,6 +706,30 @@ static struct iommu_domain apple_dart_identity_domain = {
 	.ops = &apple_dart_identity_ops,
 };
 
+static int apple_dart_attach_dev_blocked(struct iommu_domain *domain,
+					 struct device *dev)
+{
+	struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
+	struct apple_dart_stream_map *stream_map;
+	int i;
+
+	if (cfg->stream_maps[0].dart->force_bypass)
+		return -EINVAL;
+
+	for_each_stream_map(i, cfg, stream_map)
+		apple_dart_hw_disable_dma(stream_map);
+	return 0;
+}
+
+static const struct iommu_domain_ops apple_dart_blocked_ops = {
+	.attach_dev = apple_dart_attach_dev_blocked,
+};
+
+static struct iommu_domain apple_dart_blocked_domain = {
+	.type = IOMMU_DOMAIN_BLOCKED,
+	.ops = &apple_dart_blocked_ops,
+};
+
 static struct iommu_device *apple_dart_probe_device(struct device *dev)
 {
 	struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
@@ -739,8 +759,7 @@ static struct iommu_domain *apple_dart_domain_alloc(unsigned int type)
 {
 	struct apple_dart_domain *dart_domain;
 
-	if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED &&
-	    type != IOMMU_DOMAIN_BLOCKED)
+	if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED)
 		return NULL;
 
 	dart_domain = kzalloc(sizeof(*dart_domain), GFP_KERNEL);
@@ -749,10 +768,6 @@ static struct iommu_domain *apple_dart_domain_alloc(unsigned int type)
 
 	mutex_init(&dart_domain->init_lock);
 
-	/* no need to allocate pgtbl_ops or do any other finalization steps */
-	if (type == IOMMU_DOMAIN_BLOCKED)
-		dart_domain->finalized = true;
-
 	return &dart_domain->domain;
 }
 
@@ -966,6 +981,7 @@ static void apple_dart_get_resv_regions(struct device *dev,
 
 static const struct iommu_ops apple_dart_iommu_ops = {
 	.identity_domain = &apple_dart_identity_domain,
+	.blocked_domain = &apple_dart_blocked_domain,
 	.domain_alloc = apple_dart_domain_alloc,
 	.probe_device = apple_dart_probe_device,
 	.release_device = apple_dart_release_device,
-- 
2.42.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 7/8] iommu/dart: Convert to domain_alloc_paging()
  2023-09-22 17:07 [PATCH 0/8] iommu: Convert dart & iommufd to the new domain_alloc_paging() Jason Gunthorpe
                   ` (5 preceding siblings ...)
  2023-09-22 17:07 ` [PATCH 6/8] iommu/dart: Move the blocked domain support to a global static Jason Gunthorpe
@ 2023-09-22 17:07 ` Jason Gunthorpe
  2023-09-26 19:06   ` Janne Grunau
  2023-09-22 17:07 ` [PATCH 8/8] iommu/dart: Call apple_dart_finalize_domain() as part of alloc_paging() Jason Gunthorpe
  7 siblings, 1 reply; 21+ messages in thread
From: Jason Gunthorpe @ 2023-09-22 17:07 UTC (permalink / raw)
  To: Alyssa Rosenzweig, asahi, Lu Baolu, Christophe Leroy,
	David Woodhouse, iommu, Joerg Roedel, Kevin Tian,
	linux-arm-kernel, linuxppc-dev, Hector Martin, Michael Ellerman,
	Nicholas Piggin, Robin Murphy, Sven Peter, Will Deacon

Since the IDENTITY and BLOCKED behaviors were moved to global statics all
that remains is the paging domain. Rename to
apple_dart_attach_dev_paging() and remove the left over cruft.

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

diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
index 376f4c5461e8f7..62efe0aa056f60 100644
--- a/drivers/iommu/apple-dart.c
+++ b/drivers/iommu/apple-dart.c
@@ -650,8 +650,8 @@ static int apple_dart_domain_add_streams(struct apple_dart_domain *domain,
 				      true);
 }
 
-static int apple_dart_attach_dev(struct iommu_domain *domain,
-				 struct device *dev)
+static int apple_dart_attach_dev_paging(struct iommu_domain *domain,
+					struct device *dev)
 {
 	int ret, i;
 	struct apple_dart_stream_map *stream_map;
@@ -665,21 +665,13 @@ static int apple_dart_attach_dev(struct iommu_domain *domain,
 	if (ret)
 		return ret;
 
-	switch (domain->type) {
-	case IOMMU_DOMAIN_DMA:
-	case IOMMU_DOMAIN_UNMANAGED:
-		ret = apple_dart_domain_add_streams(dart_domain, cfg);
-		if (ret)
-			return ret;
+	ret = apple_dart_domain_add_streams(dart_domain, cfg);
+	if (ret)
+		return ret;
 
-		for_each_stream_map(i, cfg, stream_map)
-			apple_dart_setup_translation(dart_domain, stream_map);
-		break;
-	default:
-		return -EINVAL;
-	}
-
-	return ret;
+	for_each_stream_map(i, cfg, stream_map)
+		apple_dart_setup_translation(dart_domain, stream_map);
+	return 0;
 }
 
 static int apple_dart_attach_dev_identity(struct iommu_domain *domain,
@@ -755,13 +747,10 @@ static void apple_dart_release_device(struct device *dev)
 	kfree(cfg);
 }
 
-static struct iommu_domain *apple_dart_domain_alloc(unsigned int type)
+static struct iommu_domain *apple_dart_domain_alloc_paging(struct device *dev)
 {
 	struct apple_dart_domain *dart_domain;
 
-	if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED)
-		return NULL;
-
 	dart_domain = kzalloc(sizeof(*dart_domain), GFP_KERNEL);
 	if (!dart_domain)
 		return NULL;
@@ -982,7 +971,7 @@ static void apple_dart_get_resv_regions(struct device *dev,
 static const struct iommu_ops apple_dart_iommu_ops = {
 	.identity_domain = &apple_dart_identity_domain,
 	.blocked_domain = &apple_dart_blocked_domain,
-	.domain_alloc = apple_dart_domain_alloc,
+	.domain_alloc_paging = apple_dart_domain_alloc_paging,
 	.probe_device = apple_dart_probe_device,
 	.release_device = apple_dart_release_device,
 	.device_group = apple_dart_device_group,
@@ -992,7 +981,7 @@ static const struct iommu_ops apple_dart_iommu_ops = {
 	.pgsize_bitmap = -1UL, /* Restricted during dart probe */
 	.owner = THIS_MODULE,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
-		.attach_dev	= apple_dart_attach_dev,
+		.attach_dev	= apple_dart_attach_dev_paging,
 		.map_pages	= apple_dart_map_pages,
 		.unmap_pages	= apple_dart_unmap_pages,
 		.flush_iotlb_all = apple_dart_flush_iotlb_all,
-- 
2.42.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 8/8] iommu/dart: Call apple_dart_finalize_domain() as part of alloc_paging()
  2023-09-22 17:07 [PATCH 0/8] iommu: Convert dart & iommufd to the new domain_alloc_paging() Jason Gunthorpe
                   ` (6 preceding siblings ...)
  2023-09-22 17:07 ` [PATCH 7/8] iommu/dart: Convert to domain_alloc_paging() Jason Gunthorpe
@ 2023-09-22 17:07 ` Jason Gunthorpe
  2023-09-26 19:07   ` Janne Grunau
  7 siblings, 1 reply; 21+ messages in thread
From: Jason Gunthorpe @ 2023-09-22 17:07 UTC (permalink / raw)
  To: Alyssa Rosenzweig, asahi, Lu Baolu, Christophe Leroy,
	David Woodhouse, iommu, Joerg Roedel, Kevin Tian,
	linux-arm-kernel, linuxppc-dev, Hector Martin, Michael Ellerman,
	Nicholas Piggin, Robin Murphy, Sven Peter, Will Deacon

In many cases the dev argument will now be !NULL so we should use it to
finalize the domain at allocation.

Make apple_dart_finalize_domain() accept the correct type.

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

diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
index 62efe0aa056f60..2c1832e357c7c6 100644
--- a/drivers/iommu/apple-dart.c
+++ b/drivers/iommu/apple-dart.c
@@ -568,10 +568,9 @@ apple_dart_setup_translation(struct apple_dart_domain *domain,
 	stream_map->dart->hw->invalidate_tlb(stream_map);
 }
 
-static int apple_dart_finalize_domain(struct iommu_domain *domain,
+static int apple_dart_finalize_domain(struct apple_dart_domain *dart_domain,
 				      struct apple_dart_master_cfg *cfg)
 {
-	struct apple_dart_domain *dart_domain = to_dart_domain(domain);
 	struct apple_dart *dart = cfg->stream_maps[0].dart;
 	struct io_pgtable_cfg pgtbl_cfg;
 	int ret = 0;
@@ -597,16 +596,17 @@ static int apple_dart_finalize_domain(struct iommu_domain *domain,
 		.iommu_dev = dart->dev,
 	};
 
-	dart_domain->pgtbl_ops =
-		alloc_io_pgtable_ops(dart->hw->fmt, &pgtbl_cfg, domain);
+	dart_domain->pgtbl_ops = alloc_io_pgtable_ops(dart->hw->fmt, &pgtbl_cfg,
+						      &dart_domain->domain);
 	if (!dart_domain->pgtbl_ops) {
 		ret = -ENOMEM;
 		goto done;
 	}
 
-	domain->pgsize_bitmap = pgtbl_cfg.pgsize_bitmap;
-	domain->geometry.aperture_start = 0;
-	domain->geometry.aperture_end = (dma_addr_t)DMA_BIT_MASK(dart->ias);
+	dart_domain->domain.pgsize_bitmap = pgtbl_cfg.pgsize_bitmap;
+	dart_domain->domain.geometry.aperture_start = 0;
+	dart_domain->domain.geometry.aperture_end =
+		(dma_addr_t)DMA_BIT_MASK(dart->ias);
 
 	dart_domain->finalized = true;
 
@@ -661,7 +661,7 @@ static int apple_dart_attach_dev_paging(struct iommu_domain *domain,
 	if (cfg->stream_maps[0].dart->force_bypass)
 		return -EINVAL;
 
-	ret = apple_dart_finalize_domain(domain, cfg);
+	ret = apple_dart_finalize_domain(dart_domain, cfg);
 	if (ret)
 		return ret;
 
@@ -757,6 +757,16 @@ static struct iommu_domain *apple_dart_domain_alloc_paging(struct device *dev)
 
 	mutex_init(&dart_domain->init_lock);
 
+	if (dev) {
+		struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
+		int ret;
+
+		ret = apple_dart_finalize_domain(dart_domain, cfg);
+		if (ret) {
+			kfree(dart_domain);
+			return ERR_PTR(ret);
+		}
+	}
 	return &dart_domain->domain;
 }
 
-- 
2.42.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 1/8] iommu: Move IOMMU_DOMAIN_BLOCKED global statics to ops->blocked_domain
  2023-09-22 17:07 ` [PATCH 1/8] iommu: Move IOMMU_DOMAIN_BLOCKED global statics to ops->blocked_domain Jason Gunthorpe
@ 2023-09-25  2:26   ` Baolu Lu
  0 siblings, 0 replies; 21+ messages in thread
From: Baolu Lu @ 2023-09-25  2:26 UTC (permalink / raw)
  To: Jason Gunthorpe, Alyssa Rosenzweig, asahi, Christophe Leroy,
	David Woodhouse, iommu, Joerg Roedel, Kevin Tian,
	linux-arm-kernel, linuxppc-dev, Hector Martin, Michael Ellerman,
	Nicholas Piggin, Robin Murphy, Sven Peter, Will Deacon
  Cc: baolu.lu

On 9/23/23 1:07 AM, Jason Gunthorpe wrote:
> Following the pattern of identity domains, just assign the BLOCKED domain
> global statics to a value in ops. Update the core code to use the global
> static directly.
> 
> Update powerpc to use the new scheme and remove its empty domain_alloc
> callback.
> 
> Signed-off-by: Jason Gunthorpe<jgg@nvidia.com>
> ---
>   arch/powerpc/kernel/iommu.c | 9 +--------
>   drivers/iommu/iommu.c       | 2 ++
>   include/linux/iommu.h       | 3 +++
>   3 files changed, 6 insertions(+), 8 deletions(-)

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

Best regards,
baolu

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 2/8] iommu/vt-d: Update the definition of the blocking domain
  2023-09-22 17:07 ` [PATCH 2/8] iommu/vt-d: Update the definition of the blocking domain Jason Gunthorpe
@ 2023-09-25  2:27   ` Baolu Lu
  0 siblings, 0 replies; 21+ messages in thread
From: Baolu Lu @ 2023-09-25  2:27 UTC (permalink / raw)
  To: Jason Gunthorpe, Alyssa Rosenzweig, asahi, Christophe Leroy,
	David Woodhouse, iommu, Joerg Roedel, Kevin Tian,
	linux-arm-kernel, linuxppc-dev, Hector Martin, Michael Ellerman,
	Nicholas Piggin, Robin Murphy, Sven Peter, Will Deacon
  Cc: baolu.lu

On 9/23/23 1:07 AM, Jason Gunthorpe wrote:
> The global static should pre-define the type and the NOP free function can
> be now left as NULL.
> 
> Signed-off-by: Jason Gunthorpe<jgg@nvidia.com>
> ---
>   drivers/iommu/intel/iommu.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)

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

Best regards,
baolu

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 3/8] iommu/vt-d: Use ops->blocked_domain
  2023-09-22 17:07 ` [PATCH 3/8] iommu/vt-d: Use ops->blocked_domain Jason Gunthorpe
@ 2023-09-25  2:29   ` Baolu Lu
  2023-09-25 11:41     ` Jason Gunthorpe
  0 siblings, 1 reply; 21+ messages in thread
From: Baolu Lu @ 2023-09-25  2:29 UTC (permalink / raw)
  To: Jason Gunthorpe, Alyssa Rosenzweig, asahi, Christophe Leroy,
	David Woodhouse, iommu, Joerg Roedel, Kevin Tian,
	linux-arm-kernel, linuxppc-dev, Hector Martin, Michael Ellerman,
	Nicholas Piggin, Robin Murphy, Sven Peter, Will Deacon
  Cc: baolu.lu

On 9/23/23 1:07 AM, Jason Gunthorpe wrote:
> Trivially migrate to the ops->blocked_domain for the existing global
> static.
> 
> Signed-off-by: Jason Gunthorpe<jgg@nvidia.com>
> ---
>   drivers/iommu/intel/iommu.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)

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

P.S. We can further do the same thing to the identity domain. I will
clean it up after all patches are landed.

Best regards,
baolu

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 3/8] iommu/vt-d: Use ops->blocked_domain
  2023-09-25  2:29   ` Baolu Lu
@ 2023-09-25 11:41     ` Jason Gunthorpe
  2023-09-26  3:28       ` Baolu Lu
  0 siblings, 1 reply; 21+ messages in thread
From: Jason Gunthorpe @ 2023-09-25 11:41 UTC (permalink / raw)
  To: Baolu Lu
  Cc: Alyssa Rosenzweig, asahi, Christophe Leroy, David Woodhouse,
	iommu, Joerg Roedel, Kevin Tian, linux-arm-kernel, linuxppc-dev,
	Hector Martin, Michael Ellerman, Nicholas Piggin, Robin Murphy,
	Sven Peter, Will Deacon

On Mon, Sep 25, 2023 at 10:29:52AM +0800, Baolu Lu wrote:
> On 9/23/23 1:07 AM, Jason Gunthorpe wrote:
> > Trivially migrate to the ops->blocked_domain for the existing global
> > static.
> > 
> > Signed-off-by: Jason Gunthorpe<jgg@nvidia.com>
> > ---
> >   drivers/iommu/intel/iommu.c | 3 +--
> >   1 file changed, 1 insertion(+), 2 deletions(-)
> 
> Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
> 
> P.S. We can further do the same thing to the identity domain. I will
> clean it up after all patches are landed.

I looked at that, and it is not trivial..

Both the Intel and virtio-iommu drivers create an "identity" domain
out of a paging domain and pass that off as a true "identity"
domain. So neither can set the global static since the determination
is at runtime..

What I was thinking about doing is consolidating that code so that the
core logic is the thing turning a paging domain into an identity
domain.

Jason

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 3/8] iommu/vt-d: Use ops->blocked_domain
  2023-09-25 11:41     ` Jason Gunthorpe
@ 2023-09-26  3:28       ` Baolu Lu
  0 siblings, 0 replies; 21+ messages in thread
From: Baolu Lu @ 2023-09-26  3:28 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: baolu.lu, Alyssa Rosenzweig, asahi, Christophe Leroy,
	David Woodhouse, iommu, Joerg Roedel, Kevin Tian,
	linux-arm-kernel, linuxppc-dev, Hector Martin, Michael Ellerman,
	Nicholas Piggin, Robin Murphy, Sven Peter, Will Deacon

On 9/25/23 7:41 PM, Jason Gunthorpe wrote:
> On Mon, Sep 25, 2023 at 10:29:52AM +0800, Baolu Lu wrote:
>> On 9/23/23 1:07 AM, Jason Gunthorpe wrote:
>>> Trivially migrate to the ops->blocked_domain for the existing global
>>> static.
>>>
>>> Signed-off-by: Jason Gunthorpe<jgg@nvidia.com>
>>> ---
>>>    drivers/iommu/intel/iommu.c | 3 +--
>>>    1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
>>
>> P.S. We can further do the same thing to the identity domain. I will
>> clean it up after all patches are landed.
> 
> I looked at that, and it is not trivial..
> 
> Both the Intel and virtio-iommu drivers create an "identity" domain
> out of a paging domain and pass that off as a true "identity"
> domain. So neither can set the global static since the determination
> is at runtime..

Emm, yes. The early hardware requires a real 1:1 mapped page table. The
recent implementations are no longer needed.

> 
> What I was thinking about doing is consolidating that code so that the
> core logic is the thing turning a paging domain into an identity
> domain.

Yes. It's not trivial. Needs a separated series with some refactoring
efforts.

Best regards,
baolu

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 5/8] iommu/dart: Use static global identity domains
  2023-09-22 17:07 ` [PATCH 5/8] iommu/dart: Use static global identity domains Jason Gunthorpe
@ 2023-09-26 18:49   ` Janne Grunau
  0 siblings, 0 replies; 21+ messages in thread
From: Janne Grunau @ 2023-09-26 18:49 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alyssa Rosenzweig, asahi, Lu Baolu, Christophe Leroy,
	David Woodhouse, iommu, Joerg Roedel, Kevin Tian,
	linux-arm-kernel, linuxppc-dev, Hector Martin, Michael Ellerman,
	Nicholas Piggin, Robin Murphy, Sven Peter, Will Deacon

Hej,

On Fri, Sep 22, 2023 at 02:07:56PM -0300, Jason Gunthorpe wrote:
> Move to the new static global for identity domains. Move the identity
> specific code to apple_dart_attach_dev_identity().
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/iommu/apple-dart.c | 41 ++++++++++++++++++++++++++++----------
>  1 file changed, 30 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
> index 6bc2ad2207c3da..424f779ccc34df 100644
> --- a/drivers/iommu/apple-dart.c
> +++ b/drivers/iommu/apple-dart.c
> @@ -658,11 +658,7 @@ static int apple_dart_attach_dev(struct iommu_domain *domain,
>  	struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
>  	struct apple_dart_domain *dart_domain = to_dart_domain(domain);
>  
> -	if (cfg->stream_maps[0].dart->force_bypass &&
> -	    domain->type != IOMMU_DOMAIN_IDENTITY)
> -		return -EINVAL;
> -	if (!cfg->stream_maps[0].dart->supports_bypass &&
> -	    domain->type == IOMMU_DOMAIN_IDENTITY)
> +	if (cfg->stream_maps[0].dart->force_bypass)
>  		return -EINVAL;
>  
>  	ret = apple_dart_finalize_domain(domain, cfg);
> @@ -683,15 +679,37 @@ static int apple_dart_attach_dev(struct iommu_domain *domain,
>  		for_each_stream_map(i, cfg, stream_map)
>  			apple_dart_hw_disable_dma(stream_map);
>  		break;
> -	case IOMMU_DOMAIN_IDENTITY:
> -		for_each_stream_map(i, cfg, stream_map)
> -			apple_dart_hw_enable_bypass(stream_map);
> -		break;
> +	default:
> +		return -EINVAL;
>  	}
>  
>  	return ret;
>  }
>  
> +static int apple_dart_attach_dev_identity(struct iommu_domain *domain,
> +					  struct device *dev)
> +{
> +	struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
> +	struct apple_dart_stream_map *stream_map;
> +	int i;
> +
> +	if (!cfg->stream_maps[0].dart->supports_bypass)
> +		return -EINVAL;
> +
> +	for_each_stream_map(i, cfg, stream_map)
> +		apple_dart_hw_enable_bypass(stream_map);
> +	return 0;
> +}
> +
> +static const struct iommu_domain_ops apple_dart_identity_ops = {
> +	.attach_dev = apple_dart_attach_dev_identity,
> +};
> +
> +static struct iommu_domain apple_dart_identity_domain = {
> +	.type = IOMMU_DOMAIN_IDENTITY,
> +	.ops = &apple_dart_identity_ops,
> +};
> +
>  static struct iommu_device *apple_dart_probe_device(struct device *dev)
>  {
>  	struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
> @@ -722,7 +740,7 @@ static struct iommu_domain *apple_dart_domain_alloc(unsigned int type)
>  	struct apple_dart_domain *dart_domain;
>  
>  	if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED &&
> -	    type != IOMMU_DOMAIN_IDENTITY && type != IOMMU_DOMAIN_BLOCKED)
> +	    type != IOMMU_DOMAIN_BLOCKED)
>  		return NULL;
>  
>  	dart_domain = kzalloc(sizeof(*dart_domain), GFP_KERNEL);
> @@ -732,7 +750,7 @@ static struct iommu_domain *apple_dart_domain_alloc(unsigned int type)
>  	mutex_init(&dart_domain->init_lock);
>  
>  	/* no need to allocate pgtbl_ops or do any other finalization steps */
> -	if (type == IOMMU_DOMAIN_IDENTITY || type == IOMMU_DOMAIN_BLOCKED)
> +	if (type == IOMMU_DOMAIN_BLOCKED)
>  		dart_domain->finalized = true;
>  
>  	return &dart_domain->domain;
> @@ -947,6 +965,7 @@ static void apple_dart_get_resv_regions(struct device *dev,
>  }
>  
>  static const struct iommu_ops apple_dart_iommu_ops = {
> +	.identity_domain = &apple_dart_identity_domain,
>  	.domain_alloc = apple_dart_domain_alloc,
>  	.probe_device = apple_dart_probe_device,
>  	.release_device = apple_dart_release_device,

Reviewed-by: Janne Grunau <j@jannau.net>

best reagrds,
Janne

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 6/8] iommu/dart: Move the blocked domain support to a global static
  2023-09-22 17:07 ` [PATCH 6/8] iommu/dart: Move the blocked domain support to a global static Jason Gunthorpe
@ 2023-09-26 19:05   ` Janne Grunau
  2023-09-26 19:34     ` Robin Murphy
  2023-09-27 12:59     ` Jason Gunthorpe
  0 siblings, 2 replies; 21+ messages in thread
From: Janne Grunau @ 2023-09-26 19:05 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alyssa Rosenzweig, asahi, Lu Baolu, Christophe Leroy,
	David Woodhouse, iommu, Joerg Roedel, Kevin Tian,
	linux-arm-kernel, linuxppc-dev, Hector Martin, Michael Ellerman,
	Nicholas Piggin, Robin Murphy, Sven Peter, Will Deacon

Hej,

On Fri, Sep 22, 2023 at 02:07:57PM -0300, Jason Gunthorpe wrote:
> Move to the new static global for blocked domains. Move the blocked
> specific code to apple_dart_attach_dev_blocked().
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/iommu/apple-dart.c | 36 ++++++++++++++++++++++++++----------
>  1 file changed, 26 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
> index 424f779ccc34df..376f4c5461e8f7 100644
> --- a/drivers/iommu/apple-dart.c
> +++ b/drivers/iommu/apple-dart.c
> @@ -675,10 +675,6 @@ static int apple_dart_attach_dev(struct iommu_domain *domain,
>  		for_each_stream_map(i, cfg, stream_map)
>  			apple_dart_setup_translation(dart_domain, stream_map);
>  		break;
> -	case IOMMU_DOMAIN_BLOCKED:
> -		for_each_stream_map(i, cfg, stream_map)
> -			apple_dart_hw_disable_dma(stream_map);
> -		break;
>  	default:
>  		return -EINVAL;
>  	}
> @@ -710,6 +706,30 @@ static struct iommu_domain apple_dart_identity_domain = {
>  	.ops = &apple_dart_identity_ops,
>  };
>  
> +static int apple_dart_attach_dev_blocked(struct iommu_domain *domain,
> +					 struct device *dev)
> +{
> +	struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
> +	struct apple_dart_stream_map *stream_map;
> +	int i;
> +
> +	if (cfg->stream_maps[0].dart->force_bypass)
> +		return -EINVAL;

unrelated to this change as this keeps the current behavior but I think
force_bypass should not override IOMMU_DOMAIN_BLOCKED. It is set if the
CPU page size is smaller than dart's page size. Obviously dart can't
translate in that situation but it should be still possible to block it
completely.

How do we manage this? I can write a patch either to the current state
or based on this series.

> +
> +	for_each_stream_map(i, cfg, stream_map)
> +		apple_dart_hw_disable_dma(stream_map);
> +	return 0;
> +}
> +
> +static const struct iommu_domain_ops apple_dart_blocked_ops = {
> +	.attach_dev = apple_dart_attach_dev_blocked,
> +};
> +
> +static struct iommu_domain apple_dart_blocked_domain = {
> +	.type = IOMMU_DOMAIN_BLOCKED,
> +	.ops = &apple_dart_blocked_ops,
> +};
> +
>  static struct iommu_device *apple_dart_probe_device(struct device *dev)
>  {
>  	struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
> @@ -739,8 +759,7 @@ static struct iommu_domain *apple_dart_domain_alloc(unsigned int type)
>  {
>  	struct apple_dart_domain *dart_domain;
>  
> -	if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED &&
> -	    type != IOMMU_DOMAIN_BLOCKED)
> +	if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED)
>  		return NULL;
>  
>  	dart_domain = kzalloc(sizeof(*dart_domain), GFP_KERNEL);
> @@ -749,10 +768,6 @@ static struct iommu_domain *apple_dart_domain_alloc(unsigned int type)
>  
>  	mutex_init(&dart_domain->init_lock);
>  
> -	/* no need to allocate pgtbl_ops or do any other finalization steps */
> -	if (type == IOMMU_DOMAIN_BLOCKED)
> -		dart_domain->finalized = true;
> -
>  	return &dart_domain->domain;
>  }
>  
> @@ -966,6 +981,7 @@ static void apple_dart_get_resv_regions(struct device *dev,
>  
>  static const struct iommu_ops apple_dart_iommu_ops = {
>  	.identity_domain = &apple_dart_identity_domain,
> +	.blocked_domain = &apple_dart_blocked_domain,
>  	.domain_alloc = apple_dart_domain_alloc,
>  	.probe_device = apple_dart_probe_device,
>  	.release_device = apple_dart_release_device,
> -- 
> 2.42.0

Reviewed-by: Janne Grunau <j@jannau.net>

best regards
Janne

ps: I sent the reply to [Patch 4/8] accidentally with an incorrect from
address but the correct Reviewed-by:. I can resend if necessary.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 7/8] iommu/dart: Convert to domain_alloc_paging()
  2023-09-22 17:07 ` [PATCH 7/8] iommu/dart: Convert to domain_alloc_paging() Jason Gunthorpe
@ 2023-09-26 19:06   ` Janne Grunau
  0 siblings, 0 replies; 21+ messages in thread
From: Janne Grunau @ 2023-09-26 19:06 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alyssa Rosenzweig, asahi, Lu Baolu, Christophe Leroy,
	David Woodhouse, iommu, Joerg Roedel, Kevin Tian,
	linux-arm-kernel, linuxppc-dev, Hector Martin, Michael Ellerman,
	Nicholas Piggin, Robin Murphy, Sven Peter, Will Deacon

On Fri, Sep 22, 2023 at 02:07:58PM -0300, Jason Gunthorpe wrote:
> Since the IDENTITY and BLOCKED behaviors were moved to global statics all
> that remains is the paging domain. Rename to
> apple_dart_attach_dev_paging() and remove the left over cruft.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/iommu/apple-dart.c | 33 +++++++++++----------------------
>  1 file changed, 11 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
> index 376f4c5461e8f7..62efe0aa056f60 100644
> --- a/drivers/iommu/apple-dart.c
> +++ b/drivers/iommu/apple-dart.c
> @@ -650,8 +650,8 @@ static int apple_dart_domain_add_streams(struct apple_dart_domain *domain,
>  				      true);
>  }
>  
> -static int apple_dart_attach_dev(struct iommu_domain *domain,
> -				 struct device *dev)
> +static int apple_dart_attach_dev_paging(struct iommu_domain *domain,
> +					struct device *dev)
>  {
>  	int ret, i;
>  	struct apple_dart_stream_map *stream_map;
> @@ -665,21 +665,13 @@ static int apple_dart_attach_dev(struct iommu_domain *domain,
>  	if (ret)
>  		return ret;
>  
> -	switch (domain->type) {
> -	case IOMMU_DOMAIN_DMA:
> -	case IOMMU_DOMAIN_UNMANAGED:
> -		ret = apple_dart_domain_add_streams(dart_domain, cfg);
> -		if (ret)
> -			return ret;
> +	ret = apple_dart_domain_add_streams(dart_domain, cfg);
> +	if (ret)
> +		return ret;
>  
> -		for_each_stream_map(i, cfg, stream_map)
> -			apple_dart_setup_translation(dart_domain, stream_map);
> -		break;
> -	default:
> -		return -EINVAL;
> -	}
> -
> -	return ret;
> +	for_each_stream_map(i, cfg, stream_map)
> +		apple_dart_setup_translation(dart_domain, stream_map);
> +	return 0;
>  }
>  
>  static int apple_dart_attach_dev_identity(struct iommu_domain *domain,
> @@ -755,13 +747,10 @@ static void apple_dart_release_device(struct device *dev)
>  	kfree(cfg);
>  }
>  
> -static struct iommu_domain *apple_dart_domain_alloc(unsigned int type)
> +static struct iommu_domain *apple_dart_domain_alloc_paging(struct device *dev)
>  {
>  	struct apple_dart_domain *dart_domain;
>  
> -	if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED)
> -		return NULL;
> -
>  	dart_domain = kzalloc(sizeof(*dart_domain), GFP_KERNEL);
>  	if (!dart_domain)
>  		return NULL;
> @@ -982,7 +971,7 @@ static void apple_dart_get_resv_regions(struct device *dev,
>  static const struct iommu_ops apple_dart_iommu_ops = {
>  	.identity_domain = &apple_dart_identity_domain,
>  	.blocked_domain = &apple_dart_blocked_domain,
> -	.domain_alloc = apple_dart_domain_alloc,
> +	.domain_alloc_paging = apple_dart_domain_alloc_paging,
>  	.probe_device = apple_dart_probe_device,
>  	.release_device = apple_dart_release_device,
>  	.device_group = apple_dart_device_group,
> @@ -992,7 +981,7 @@ static const struct iommu_ops apple_dart_iommu_ops = {
>  	.pgsize_bitmap = -1UL, /* Restricted during dart probe */
>  	.owner = THIS_MODULE,
>  	.default_domain_ops = &(const struct iommu_domain_ops) {
> -		.attach_dev	= apple_dart_attach_dev,
> +		.attach_dev	= apple_dart_attach_dev_paging,
>  		.map_pages	= apple_dart_map_pages,
>  		.unmap_pages	= apple_dart_unmap_pages,
>  		.flush_iotlb_all = apple_dart_flush_iotlb_all,
> -- 
> 2.42.0

Reviewed-by: Janne Grunau <j@jannau.net>

best regards
Janne

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 8/8] iommu/dart: Call apple_dart_finalize_domain() as part of alloc_paging()
  2023-09-22 17:07 ` [PATCH 8/8] iommu/dart: Call apple_dart_finalize_domain() as part of alloc_paging() Jason Gunthorpe
@ 2023-09-26 19:07   ` Janne Grunau
  0 siblings, 0 replies; 21+ messages in thread
From: Janne Grunau @ 2023-09-26 19:07 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alyssa Rosenzweig, asahi, Lu Baolu, Christophe Leroy,
	David Woodhouse, iommu, Joerg Roedel, Kevin Tian,
	linux-arm-kernel, linuxppc-dev, Hector Martin, Michael Ellerman,
	Nicholas Piggin, Robin Murphy, Sven Peter, Will Deacon

On Fri, Sep 22, 2023 at 02:07:59PM -0300, Jason Gunthorpe wrote:
> In many cases the dev argument will now be !NULL so we should use it to
> finalize the domain at allocation.
> 
> Make apple_dart_finalize_domain() accept the correct type.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/iommu/apple-dart.c | 26 ++++++++++++++++++--------
>  1 file changed, 18 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
> index 62efe0aa056f60..2c1832e357c7c6 100644
> --- a/drivers/iommu/apple-dart.c
> +++ b/drivers/iommu/apple-dart.c
> @@ -568,10 +568,9 @@ apple_dart_setup_translation(struct apple_dart_domain *domain,
>  	stream_map->dart->hw->invalidate_tlb(stream_map);
>  }
>  
> -static int apple_dart_finalize_domain(struct iommu_domain *domain,
> +static int apple_dart_finalize_domain(struct apple_dart_domain *dart_domain,
>  				      struct apple_dart_master_cfg *cfg)
>  {
> -	struct apple_dart_domain *dart_domain = to_dart_domain(domain);
>  	struct apple_dart *dart = cfg->stream_maps[0].dart;
>  	struct io_pgtable_cfg pgtbl_cfg;
>  	int ret = 0;
> @@ -597,16 +596,17 @@ static int apple_dart_finalize_domain(struct iommu_domain *domain,
>  		.iommu_dev = dart->dev,
>  	};
>  
> -	dart_domain->pgtbl_ops =
> -		alloc_io_pgtable_ops(dart->hw->fmt, &pgtbl_cfg, domain);
> +	dart_domain->pgtbl_ops = alloc_io_pgtable_ops(dart->hw->fmt, &pgtbl_cfg,
> +						      &dart_domain->domain);
>  	if (!dart_domain->pgtbl_ops) {
>  		ret = -ENOMEM;
>  		goto done;
>  	}
>  
> -	domain->pgsize_bitmap = pgtbl_cfg.pgsize_bitmap;
> -	domain->geometry.aperture_start = 0;
> -	domain->geometry.aperture_end = (dma_addr_t)DMA_BIT_MASK(dart->ias);
> +	dart_domain->domain.pgsize_bitmap = pgtbl_cfg.pgsize_bitmap;
> +	dart_domain->domain.geometry.aperture_start = 0;
> +	dart_domain->domain.geometry.aperture_end =
> +		(dma_addr_t)DMA_BIT_MASK(dart->ias);
>  
>  	dart_domain->finalized = true;
>  
> @@ -661,7 +661,7 @@ static int apple_dart_attach_dev_paging(struct iommu_domain *domain,
>  	if (cfg->stream_maps[0].dart->force_bypass)
>  		return -EINVAL;
>  
> -	ret = apple_dart_finalize_domain(domain, cfg);
> +	ret = apple_dart_finalize_domain(dart_domain, cfg);
>  	if (ret)
>  		return ret;
>  
> @@ -757,6 +757,16 @@ static struct iommu_domain *apple_dart_domain_alloc_paging(struct device *dev)
>  
>  	mutex_init(&dart_domain->init_lock);
>  
> +	if (dev) {
> +		struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
> +		int ret;
> +
> +		ret = apple_dart_finalize_domain(dart_domain, cfg);
> +		if (ret) {
> +			kfree(dart_domain);
> +			return ERR_PTR(ret);
> +		}
> +	}
>  	return &dart_domain->domain;
>  }
>  
> -- 
> 2.42.0

Reviewed-by: Janne Grunau <j@jannau.net>

best regards

Janne

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 6/8] iommu/dart: Move the blocked domain support to a global static
  2023-09-26 19:05   ` Janne Grunau
@ 2023-09-26 19:34     ` Robin Murphy
  2023-09-26 19:41       ` Robin Murphy
  2023-09-27 12:59     ` Jason Gunthorpe
  1 sibling, 1 reply; 21+ messages in thread
From: Robin Murphy @ 2023-09-26 19:34 UTC (permalink / raw)
  To: Janne Grunau, Jason Gunthorpe
  Cc: Alyssa Rosenzweig, asahi, Lu Baolu, Christophe Leroy,
	David Woodhouse, iommu, Joerg Roedel, Kevin Tian,
	linux-arm-kernel, linuxppc-dev, Hector Martin, Michael Ellerman,
	Nicholas Piggin, Sven Peter, Will Deacon

On 2023-09-26 20:05, Janne Grunau wrote:
> Hej,
> 
> On Fri, Sep 22, 2023 at 02:07:57PM -0300, Jason Gunthorpe wrote:
>> Move to the new static global for blocked domains. Move the blocked
>> specific code to apple_dart_attach_dev_blocked().
>>
>> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
>> ---
>>   drivers/iommu/apple-dart.c | 36 ++++++++++++++++++++++++++----------
>>   1 file changed, 26 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
>> index 424f779ccc34df..376f4c5461e8f7 100644
>> --- a/drivers/iommu/apple-dart.c
>> +++ b/drivers/iommu/apple-dart.c
>> @@ -675,10 +675,6 @@ static int apple_dart_attach_dev(struct iommu_domain *domain,
>>   		for_each_stream_map(i, cfg, stream_map)
>>   			apple_dart_setup_translation(dart_domain, stream_map);
>>   		break;
>> -	case IOMMU_DOMAIN_BLOCKED:
>> -		for_each_stream_map(i, cfg, stream_map)
>> -			apple_dart_hw_disable_dma(stream_map);
>> -		break;
>>   	default:
>>   		return -EINVAL;
>>   	}
>> @@ -710,6 +706,30 @@ static struct iommu_domain apple_dart_identity_domain = {
>>   	.ops = &apple_dart_identity_ops,
>>   };
>>   
>> +static int apple_dart_attach_dev_blocked(struct iommu_domain *domain,
>> +					 struct device *dev)
>> +{
>> +	struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
>> +	struct apple_dart_stream_map *stream_map;
>> +	int i;
>> +
>> +	if (cfg->stream_maps[0].dart->force_bypass)
>> +		return -EINVAL;
> 
> unrelated to this change as this keeps the current behavior but I think
> force_bypass should not override IOMMU_DOMAIN_BLOCKED. It is set if the
> CPU page size is smaller than dart's page size. Obviously dart can't
> translate in that situation but it should be still possible to block it
> completely.
> 
> How do we manage this? I can write a patch either to the current state
> or based on this series.

The series is queued already, so best to send a patch based on 
iommu/core (I guess just removing these lines?). It won't be 
super-useful in practice since the blocking domain is normally only used 
to transition to an unmanaged domain which in the force_bypass situation 
can't be used anyway, but it's still nice on principle not to have 
unnecessary reasons for attach to fail.

Thanks,
Robin.

> 
>> +
>> +	for_each_stream_map(i, cfg, stream_map)
>> +		apple_dart_hw_disable_dma(stream_map);
>> +	return 0;
>> +}
>> +
>> +static const struct iommu_domain_ops apple_dart_blocked_ops = {
>> +	.attach_dev = apple_dart_attach_dev_blocked,
>> +};
>> +
>> +static struct iommu_domain apple_dart_blocked_domain = {
>> +	.type = IOMMU_DOMAIN_BLOCKED,
>> +	.ops = &apple_dart_blocked_ops,
>> +};
>> +
>>   static struct iommu_device *apple_dart_probe_device(struct device *dev)
>>   {
>>   	struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
>> @@ -739,8 +759,7 @@ static struct iommu_domain *apple_dart_domain_alloc(unsigned int type)
>>   {
>>   	struct apple_dart_domain *dart_domain;
>>   
>> -	if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED &&
>> -	    type != IOMMU_DOMAIN_BLOCKED)
>> +	if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED)
>>   		return NULL;
>>   
>>   	dart_domain = kzalloc(sizeof(*dart_domain), GFP_KERNEL);
>> @@ -749,10 +768,6 @@ static struct iommu_domain *apple_dart_domain_alloc(unsigned int type)
>>   
>>   	mutex_init(&dart_domain->init_lock);
>>   
>> -	/* no need to allocate pgtbl_ops or do any other finalization steps */
>> -	if (type == IOMMU_DOMAIN_BLOCKED)
>> -		dart_domain->finalized = true;
>> -
>>   	return &dart_domain->domain;
>>   }
>>   
>> @@ -966,6 +981,7 @@ static void apple_dart_get_resv_regions(struct device *dev,
>>   
>>   static const struct iommu_ops apple_dart_iommu_ops = {
>>   	.identity_domain = &apple_dart_identity_domain,
>> +	.blocked_domain = &apple_dart_blocked_domain,
>>   	.domain_alloc = apple_dart_domain_alloc,
>>   	.probe_device = apple_dart_probe_device,
>>   	.release_device = apple_dart_release_device,
>> -- 
>> 2.42.0
> 
> Reviewed-by: Janne Grunau <j@jannau.net>
> 
> best regards
> Janne
> 
> ps: I sent the reply to [Patch 4/8] accidentally with an incorrect from
> address but the correct Reviewed-by:. I can resend if necessary.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 6/8] iommu/dart: Move the blocked domain support to a global static
  2023-09-26 19:34     ` Robin Murphy
@ 2023-09-26 19:41       ` Robin Murphy
  0 siblings, 0 replies; 21+ messages in thread
From: Robin Murphy @ 2023-09-26 19:41 UTC (permalink / raw)
  To: Janne Grunau, Jason Gunthorpe
  Cc: Alyssa Rosenzweig, asahi, Lu Baolu, Christophe Leroy,
	David Woodhouse, iommu, Joerg Roedel, Kevin Tian,
	linux-arm-kernel, linuxppc-dev, Hector Martin, Michael Ellerman,
	Nicholas Piggin, Sven Peter, Will Deacon

On 2023-09-26 20:34, Robin Murphy wrote:
> On 2023-09-26 20:05, Janne Grunau wrote:
>> Hej,
>>
>> On Fri, Sep 22, 2023 at 02:07:57PM -0300, Jason Gunthorpe wrote:
>>> Move to the new static global for blocked domains. Move the blocked
>>> specific code to apple_dart_attach_dev_blocked().
>>>
>>> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
>>> ---
>>>   drivers/iommu/apple-dart.c | 36 ++++++++++++++++++++++++++----------
>>>   1 file changed, 26 insertions(+), 10 deletions(-)
>>>
>>> diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
>>> index 424f779ccc34df..376f4c5461e8f7 100644
>>> --- a/drivers/iommu/apple-dart.c
>>> +++ b/drivers/iommu/apple-dart.c
>>> @@ -675,10 +675,6 @@ static int apple_dart_attach_dev(struct 
>>> iommu_domain *domain,
>>>           for_each_stream_map(i, cfg, stream_map)
>>>               apple_dart_setup_translation(dart_domain, stream_map);
>>>           break;
>>> -    case IOMMU_DOMAIN_BLOCKED:
>>> -        for_each_stream_map(i, cfg, stream_map)
>>> -            apple_dart_hw_disable_dma(stream_map);
>>> -        break;
>>>       default:
>>>           return -EINVAL;
>>>       }
>>> @@ -710,6 +706,30 @@ static struct iommu_domain 
>>> apple_dart_identity_domain = {
>>>       .ops = &apple_dart_identity_ops,
>>>   };
>>> +static int apple_dart_attach_dev_blocked(struct iommu_domain *domain,
>>> +                     struct device *dev)
>>> +{
>>> +    struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
>>> +    struct apple_dart_stream_map *stream_map;
>>> +    int i;
>>> +
>>> +    if (cfg->stream_maps[0].dart->force_bypass)
>>> +        return -EINVAL;
>>
>> unrelated to this change as this keeps the current behavior but I think
>> force_bypass should not override IOMMU_DOMAIN_BLOCKED. It is set if the
>> CPU page size is smaller than dart's page size. Obviously dart can't
>> translate in that situation but it should be still possible to block it
>> completely.
>>
>> How do we manage this? I can write a patch either to the current state
>> or based on this series.
> 
> The series is queued already, so best to send a patch based on 
> iommu/core (I guess just removing these lines?).

Um, what? This isn't the domain_alloc_paging series itself, Robin you 
fool. Clearly it's time to close the computer and try again tomorrow...

Cheers,
Robin.

> It won't be 
> super-useful in practice since the blocking domain is normally only used 
> to transition to an unmanaged domain which in the force_bypass situation 
> can't be used anyway, but it's still nice on principle not to have 
> unnecessary reasons for attach to fail.
> 
> Thanks,
> Robin.
> 
>>
>>> +
>>> +    for_each_stream_map(i, cfg, stream_map)
>>> +        apple_dart_hw_disable_dma(stream_map);
>>> +    return 0;
>>> +}
>>> +
>>> +static const struct iommu_domain_ops apple_dart_blocked_ops = {
>>> +    .attach_dev = apple_dart_attach_dev_blocked,
>>> +};
>>> +
>>> +static struct iommu_domain apple_dart_blocked_domain = {
>>> +    .type = IOMMU_DOMAIN_BLOCKED,
>>> +    .ops = &apple_dart_blocked_ops,
>>> +};
>>> +
>>>   static struct iommu_device *apple_dart_probe_device(struct device 
>>> *dev)
>>>   {
>>>       struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
>>> @@ -739,8 +759,7 @@ static struct iommu_domain 
>>> *apple_dart_domain_alloc(unsigned int type)
>>>   {
>>>       struct apple_dart_domain *dart_domain;
>>> -    if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED &&
>>> -        type != IOMMU_DOMAIN_BLOCKED)
>>> +    if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED)
>>>           return NULL;
>>>       dart_domain = kzalloc(sizeof(*dart_domain), GFP_KERNEL);
>>> @@ -749,10 +768,6 @@ static struct iommu_domain 
>>> *apple_dart_domain_alloc(unsigned int type)
>>>       mutex_init(&dart_domain->init_lock);
>>> -    /* no need to allocate pgtbl_ops or do any other finalization 
>>> steps */
>>> -    if (type == IOMMU_DOMAIN_BLOCKED)
>>> -        dart_domain->finalized = true;
>>> -
>>>       return &dart_domain->domain;
>>>   }
>>> @@ -966,6 +981,7 @@ static void apple_dart_get_resv_regions(struct 
>>> device *dev,
>>>   static const struct iommu_ops apple_dart_iommu_ops = {
>>>       .identity_domain = &apple_dart_identity_domain,
>>> +    .blocked_domain = &apple_dart_blocked_domain,
>>>       .domain_alloc = apple_dart_domain_alloc,
>>>       .probe_device = apple_dart_probe_device,
>>>       .release_device = apple_dart_release_device,
>>> -- 
>>> 2.42.0
>>
>> Reviewed-by: Janne Grunau <j@jannau.net>
>>
>> best regards
>> Janne
>>
>> ps: I sent the reply to [Patch 4/8] accidentally with an incorrect from
>> address but the correct Reviewed-by:. I can resend if necessary.
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 6/8] iommu/dart: Move the blocked domain support to a global static
  2023-09-26 19:05   ` Janne Grunau
  2023-09-26 19:34     ` Robin Murphy
@ 2023-09-27 12:59     ` Jason Gunthorpe
  1 sibling, 0 replies; 21+ messages in thread
From: Jason Gunthorpe @ 2023-09-27 12:59 UTC (permalink / raw)
  To: Janne Grunau
  Cc: Alyssa Rosenzweig, asahi, Lu Baolu, Christophe Leroy,
	David Woodhouse, iommu, Joerg Roedel, Kevin Tian,
	linux-arm-kernel, linuxppc-dev, Hector Martin, Michael Ellerman,
	Nicholas Piggin, Robin Murphy, Sven Peter, Will Deacon

On Tue, Sep 26, 2023 at 09:05:08PM +0200, Janne Grunau wrote:
> > +static int apple_dart_attach_dev_blocked(struct iommu_domain *domain,
> > +					 struct device *dev)
> > +{
> > +	struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
> > +	struct apple_dart_stream_map *stream_map;
> > +	int i;
> > +
> > +	if (cfg->stream_maps[0].dart->force_bypass)
> > +		return -EINVAL;
> 
> unrelated to this change as this keeps the current behavior but I think
> force_bypass should not override IOMMU_DOMAIN_BLOCKED.

That would be great, dart is the only driver that can fail blocked..

> It is set if the CPU page size is smaller than dart's page
> size. Obviously dart can't translate in that situation but it should
> be still possible to block it completely.

Wonderful, actually it probably shouldn't even support allocating a
paging domain if it can't support PAGE_SIZE mappings?

> How do we manage this? I can write a patch either to the current state
> or based on this series.

Let me just add a patch to this series to remove that test with your
explanation, that will avoid patch ordering troubles.

Thanks,
Jason

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2023-09-27 13:00 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-22 17:07 [PATCH 0/8] iommu: Convert dart & iommufd to the new domain_alloc_paging() Jason Gunthorpe
2023-09-22 17:07 ` [PATCH 1/8] iommu: Move IOMMU_DOMAIN_BLOCKED global statics to ops->blocked_domain Jason Gunthorpe
2023-09-25  2:26   ` Baolu Lu
2023-09-22 17:07 ` [PATCH 2/8] iommu/vt-d: Update the definition of the blocking domain Jason Gunthorpe
2023-09-25  2:27   ` Baolu Lu
2023-09-22 17:07 ` [PATCH 3/8] iommu/vt-d: Use ops->blocked_domain Jason Gunthorpe
2023-09-25  2:29   ` Baolu Lu
2023-09-25 11:41     ` Jason Gunthorpe
2023-09-26  3:28       ` Baolu Lu
2023-09-22 17:07 ` [PATCH 4/8] iommufd: Convert to alloc_domain_paging() Jason Gunthorpe
2023-09-22 17:07 ` [PATCH 5/8] iommu/dart: Use static global identity domains Jason Gunthorpe
2023-09-26 18:49   ` Janne Grunau
2023-09-22 17:07 ` [PATCH 6/8] iommu/dart: Move the blocked domain support to a global static Jason Gunthorpe
2023-09-26 19:05   ` Janne Grunau
2023-09-26 19:34     ` Robin Murphy
2023-09-26 19:41       ` Robin Murphy
2023-09-27 12:59     ` Jason Gunthorpe
2023-09-22 17:07 ` [PATCH 7/8] iommu/dart: Convert to domain_alloc_paging() Jason Gunthorpe
2023-09-26 19:06   ` Janne Grunau
2023-09-22 17:07 ` [PATCH 8/8] iommu/dart: Call apple_dart_finalize_domain() as part of alloc_paging() Jason Gunthorpe
2023-09-26 19:07   ` Janne Grunau

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).