Linux IOMMU Development
 help / color / mirror / Atom feed
* [PATCH] iommu: Do not use IOMMU_DOMAIN_DMA if CONFIG_IOMMU_DMA is not enabled
@ 2023-10-03 16:52 Jason Gunthorpe
  2023-10-03 17:34 ` Dmitry Baryshkov
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jason Gunthorpe @ 2023-10-03 16:52 UTC (permalink / raw)
  To: iommu, Joerg Roedel, Robin Murphy, Dmitry Baryshkov, Will Deacon
  Cc: Lu Baolu, Heiko Stuebner, Joerg Roedel, Jerry Snitselaar,
	Marek Szyprowski, Nicolin Chen, Niklas Schnelle, Steven Price

msm_iommu platforms do not select either CONFIG_IOMMU_DMA or
CONFIG_ARM_DMA_USE_IOMMU so they create a IOMMU_DOMAIN_DMA domain by
default and never populate it. This acts like a BLOCKED domain and breaks
the GPU driver on the platform.

Detect this and force use of IDENTITY instead.

Fixes: 98ac73f99bc4 ("iommu: Require a default_domain for all iommu drivers")
Reported-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Link: https://lore.kernel.org/linux-iommu/CAA8EJprz7VVmBG68U9zLuqPd0UdSRHYoLDJSP6tCj6H6qanuTQ@mail.gmail.com/
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/iommu.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Dmitry, I changed the patch from what I got you to test, probably best if you
can confirm this is OK too. This should fix any other drivers beyond msm that are
doing the same thing. Thanks

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 1ecac2b5c54f4a..21d45e6a5931a1 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1920,6 +1920,18 @@ static int iommu_get_default_domain_type(struct iommu_group *group,
 		}
 	}
 
+	/*
+	 * If the common dma ops are not selected in kconfig then we cannot use
+	 * IOMMU_DOMAIN_DMA at all. Force IDENTITY if nothing else has been
+	 * selected.
+	 */
+	if (!IS_ENABLED(CONFIG_IOMMU_DMA)) {
+		if (WARN_ON(driver_type == IOMMU_DOMAIN_DMA))
+			return -1;
+		if (!driver_type)
+			driver_type = IOMMU_DOMAIN_IDENTITY;
+	}
+
 	if (untrusted) {
 		if (driver_type && driver_type != IOMMU_DOMAIN_DMA) {
 			dev_err_ratelimited(

base-commit: dd5c4a1fe62738b4494deaf387d9a63a7c9f9519
-- 
2.42.0


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

* Re: [PATCH] iommu: Do not use IOMMU_DOMAIN_DMA if CONFIG_IOMMU_DMA is not enabled
  2023-10-03 16:52 [PATCH] iommu: Do not use IOMMU_DOMAIN_DMA if CONFIG_IOMMU_DMA is not enabled Jason Gunthorpe
@ 2023-10-03 17:34 ` Dmitry Baryshkov
  2023-10-03 17:45 ` Jerry Snitselaar
  2023-10-05 11:00 ` Joerg Roedel
  2 siblings, 0 replies; 4+ messages in thread
From: Dmitry Baryshkov @ 2023-10-03 17:34 UTC (permalink / raw)
  To: Jason Gunthorpe, iommu, Joerg Roedel, Robin Murphy, Will Deacon
  Cc: Lu Baolu, Heiko Stuebner, Joerg Roedel, Jerry Snitselaar,
	Marek Szyprowski, Nicolin Chen, Niklas Schnelle, Steven Price

On 03/10/2023 19:52, Jason Gunthorpe wrote:
> msm_iommu platforms do not select either CONFIG_IOMMU_DMA or
> CONFIG_ARM_DMA_USE_IOMMU so they create a IOMMU_DOMAIN_DMA domain by
> default and never populate it. This acts like a BLOCKED domain and breaks
> the GPU driver on the platform.
> 
> Detect this and force use of IDENTITY instead.
> 
> Fixes: 98ac73f99bc4 ("iommu: Require a default_domain for all iommu drivers")
> Reported-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> Link: https://lore.kernel.org/linux-iommu/CAA8EJprz7VVmBG68U9zLuqPd0UdSRHYoLDJSP6tCj6H6qanuTQ@mail.gmail.com/
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>   drivers/iommu/iommu.c | 12 ++++++++++++
>   1 file changed, 12 insertions(+)
> 
> Dmitry, I changed the patch from what I got you to test, probably best if you
> can confirm this is OK too. This should fix any other drivers beyond msm that are
> doing the same thing. Thanks

It still works for me, so:

Tested-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>

Thanks a lot for your help!


-- 
With best wishes
Dmitry


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

* Re: [PATCH] iommu: Do not use IOMMU_DOMAIN_DMA if CONFIG_IOMMU_DMA is not enabled
  2023-10-03 16:52 [PATCH] iommu: Do not use IOMMU_DOMAIN_DMA if CONFIG_IOMMU_DMA is not enabled Jason Gunthorpe
  2023-10-03 17:34 ` Dmitry Baryshkov
@ 2023-10-03 17:45 ` Jerry Snitselaar
  2023-10-05 11:00 ` Joerg Roedel
  2 siblings, 0 replies; 4+ messages in thread
From: Jerry Snitselaar @ 2023-10-03 17:45 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: iommu, Joerg Roedel, Robin Murphy, Dmitry Baryshkov, Will Deacon,
	Lu Baolu, Heiko Stuebner, Joerg Roedel, Marek Szyprowski,
	Nicolin Chen, Niklas Schnelle, Steven Price

On Tue, Oct 03, 2023 at 01:52:36PM -0300, Jason Gunthorpe wrote:
> msm_iommu platforms do not select either CONFIG_IOMMU_DMA or
> CONFIG_ARM_DMA_USE_IOMMU so they create a IOMMU_DOMAIN_DMA domain by
> default and never populate it. This acts like a BLOCKED domain and breaks
> the GPU driver on the platform.
> 
> Detect this and force use of IDENTITY instead.
> 
> Fixes: 98ac73f99bc4 ("iommu: Require a default_domain for all iommu drivers")
> Reported-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> Link: https://lore.kernel.org/linux-iommu/CAA8EJprz7VVmBG68U9zLuqPd0UdSRHYoLDJSP6tCj6H6qanuTQ@mail.gmail.com/
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/iommu/iommu.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> Dmitry, I changed the patch from what I got you to test, probably best if you
> can confirm this is OK too. This should fix any other drivers beyond msm that are
> doing the same thing. Thanks
> 
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index 1ecac2b5c54f4a..21d45e6a5931a1 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -1920,6 +1920,18 @@ static int iommu_get_default_domain_type(struct iommu_group *group,
>  		}
>  	}
>  
> +	/*
> +	 * If the common dma ops are not selected in kconfig then we cannot use
> +	 * IOMMU_DOMAIN_DMA at all. Force IDENTITY if nothing else has been
> +	 * selected.
> +	 */
> +	if (!IS_ENABLED(CONFIG_IOMMU_DMA)) {
> +		if (WARN_ON(driver_type == IOMMU_DOMAIN_DMA))
> +			return -1;
> +		if (!driver_type)
> +			driver_type = IOMMU_DOMAIN_IDENTITY;
> +	}
> +
>  	if (untrusted) {
>  		if (driver_type && driver_type != IOMMU_DOMAIN_DMA) {
>  			dev_err_ratelimited(
> 
> base-commit: dd5c4a1fe62738b4494deaf387d9a63a7c9f9519
> -- 
> 2.42.0
> 

Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>


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

* Re: [PATCH] iommu: Do not use IOMMU_DOMAIN_DMA if CONFIG_IOMMU_DMA is not enabled
  2023-10-03 16:52 [PATCH] iommu: Do not use IOMMU_DOMAIN_DMA if CONFIG_IOMMU_DMA is not enabled Jason Gunthorpe
  2023-10-03 17:34 ` Dmitry Baryshkov
  2023-10-03 17:45 ` Jerry Snitselaar
@ 2023-10-05 11:00 ` Joerg Roedel
  2 siblings, 0 replies; 4+ messages in thread
From: Joerg Roedel @ 2023-10-05 11:00 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: iommu, Joerg Roedel, Robin Murphy, Dmitry Baryshkov, Will Deacon,
	Lu Baolu, Heiko Stuebner, Jerry Snitselaar, Marek Szyprowski,
	Nicolin Chen, Niklas Schnelle, Steven Price

On Tue, Oct 03, 2023 at 01:52:36PM -0300, Jason Gunthorpe wrote:
>  drivers/iommu/iommu.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)

Applied, thanks.

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

SUSE Software Solutions Germany GmbH
Frankenstraße 146
90461 Nürnberg
Germany

(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman


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

end of thread, other threads:[~2023-10-05 11:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-03 16:52 [PATCH] iommu: Do not use IOMMU_DOMAIN_DMA if CONFIG_IOMMU_DMA is not enabled Jason Gunthorpe
2023-10-03 17:34 ` Dmitry Baryshkov
2023-10-03 17:45 ` Jerry Snitselaar
2023-10-05 11:00 ` Joerg Roedel

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