Archive-only list for patches
 help / color / mirror / Atom feed
* [PATCH rc] iommu: Allow ops->default_domain to work when !CONFIG_IOMMU_DMA
@ 2024-01-30 16:12 Jason Gunthorpe
  2024-02-01 12:20 ` Joerg Roedel
  0 siblings, 1 reply; 2+ messages in thread
From: Jason Gunthorpe @ 2024-01-30 16:12 UTC (permalink / raw)
  To: iommu, Joerg Roedel, Robin Murphy, Will Deacon
  Cc: Lu Baolu, Dmitry Baryshkov, Heiko Stuebner, Joerg Roedel,
	Jerry Snitselaar, Marek Szyprowski, Nicolin Chen, Ovidiu Panait,
	patches, Shivaprasad G Bhat, Niklas Schnelle, Steven Price

The ops->default_domain flow used a 0 req_type to select the default
domain and this was enforced by iommu_group_alloc_default_domain().

When !CONFIG_IOMMU_DMA started forcing the old ARM32 drivers into IDENTITY
it also overroad the 0 req_type of the ops->default_domain drivers to
IDENTITY which ends up causing failures during device probe.

Make iommu_group_alloc_default_domain() accept a req_type that matches the
ops->default_domain and have iommu_group_alloc_default_domain() generate a
req_type that matches the default_domain.

This way the req_type always describes what kind of domain should be
attached and ops->default_domain overrides all other mechanisms to choose
the default domain.

Fixes: 2ad56efa80db ("powerpc/iommu: Setup a default domain and remove set_platform_dma_ops")
Fixes: 0f6a90436a57 ("iommu: Do not use IOMMU_DOMAIN_DMA if CONFIG_IOMMU_DMA is not enabled")
Reported-by: Ovidiu Panait <ovidiu.panait@windriver.com>
Closes: https://lore.kernel.org/linux-iommu/20240123165829.630276-1-ovidiu.panait@windriver.com/
Reported-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
Closes: https://lore.kernel.org/linux-iommu/170618452753.3805.4425669653666211728.stgit@ltcd48-lp2.aus.stglab.ibm.com/
Tested-by: Ovidiu Panait <ovidiu.panait@windriver.com>
Tested-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/iommu.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 68e648b5576706..d14413916f93a0 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1799,7 +1799,7 @@ iommu_group_alloc_default_domain(struct iommu_group *group, int req_type)
 	 * domain. Do not use in new drivers.
 	 */
 	if (ops->default_domain) {
-		if (req_type)
+		if (req_type != ops->default_domain->type)
 			return ERR_PTR(-EINVAL);
 		return ops->default_domain;
 	}
@@ -1871,10 +1871,18 @@ static int iommu_get_def_domain_type(struct iommu_group *group,
 	const struct iommu_ops *ops = dev_iommu_ops(dev);
 	int type;
 
-	if (!ops->def_domain_type)
-		return cur_type;
-
-	type = ops->def_domain_type(dev);
+	if (ops->default_domain) {
+		/*
+		 * Drivers that declare a global static default_domain will
+		 * always choose that.
+		 */
+		type = ops->default_domain->type;
+	} else {
+		if (ops->def_domain_type)
+			type = ops->def_domain_type(dev);
+		else
+			return cur_type;
+	}
 	if (!type || cur_type == type)
 		return cur_type;
 	if (!cur_type)

base-commit: 6613476e225e090cc9aad49be7fa504e290dd33d
-- 
2.43.0


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

* Re: [PATCH rc] iommu: Allow ops->default_domain to work when !CONFIG_IOMMU_DMA
  2024-01-30 16:12 [PATCH rc] iommu: Allow ops->default_domain to work when !CONFIG_IOMMU_DMA Jason Gunthorpe
@ 2024-02-01 12:20 ` Joerg Roedel
  0 siblings, 0 replies; 2+ messages in thread
From: Joerg Roedel @ 2024-02-01 12:20 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: iommu, Joerg Roedel, Robin Murphy, Will Deacon, Lu Baolu,
	Dmitry Baryshkov, Heiko Stuebner, Jerry Snitselaar,
	Marek Szyprowski, Nicolin Chen, Ovidiu Panait, patches,
	Shivaprasad G Bhat, Niklas Schnelle, Steven Price

On Tue, Jan 30, 2024 at 12:12:53PM -0400, Jason Gunthorpe wrote:
> The ops->default_domain flow used a 0 req_type to select the default
> domain and this was enforced by iommu_group_alloc_default_domain().
> 
> When !CONFIG_IOMMU_DMA started forcing the old ARM32 drivers into IDENTITY
> it also overroad the 0 req_type of the ops->default_domain drivers to
> IDENTITY which ends up causing failures during device probe.
> 
> Make iommu_group_alloc_default_domain() accept a req_type that matches the
> ops->default_domain and have iommu_group_alloc_default_domain() generate a
> req_type that matches the default_domain.
> 
> This way the req_type always describes what kind of domain should be
> attached and ops->default_domain overrides all other mechanisms to choose
> the default domain.
> 
> Fixes: 2ad56efa80db ("powerpc/iommu: Setup a default domain and remove set_platform_dma_ops")
> Fixes: 0f6a90436a57 ("iommu: Do not use IOMMU_DOMAIN_DMA if CONFIG_IOMMU_DMA is not enabled")
> Reported-by: Ovidiu Panait <ovidiu.panait@windriver.com>
> Closes: https://lore.kernel.org/linux-iommu/20240123165829.630276-1-ovidiu.panait@windriver.com/
> Reported-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
> Closes: https://lore.kernel.org/linux-iommu/170618452753.3805.4425669653666211728.stgit@ltcd48-lp2.aus.stglab.ibm.com/
> Tested-by: Ovidiu Panait <ovidiu.panait@windriver.com>
> Tested-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/iommu/iommu.c | 18 +++++++++++++-----
>  1 file changed, 13 insertions(+), 5 deletions(-)

Applied, thanks.

-- 
Jörg Rödel
jroedel@suse.de

SUSE Software Solutions Germany GmbH
Frankenstraße 146
90461 Nürnberg
Germany
https://www.suse.com/

Geschäftsführer: Ivo Totev, Andrew McDonald, Werner Knoblich
(HRB 36809, AG Nürnberg)

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

end of thread, other threads:[~2024-02-01 12:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-30 16:12 [PATCH rc] iommu: Allow ops->default_domain to work when !CONFIG_IOMMU_DMA Jason Gunthorpe
2024-02-01 12:20 ` Joerg Roedel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox