* [PATCH] dma-mapping: reliably inform about DMA support for IOMMU
@ 2024-09-11 10:15 Leon Romanovsky
2024-09-11 12:54 ` Robin Murphy
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Leon Romanovsky @ 2024-09-11 10:15 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Christoph Hellwig,
Marek Szyprowski
Cc: Leon Romanovsky, iommu, linux-kernel, Nícolas F. R. A. Prado
From: Leon Romanovsky <leonro@nvidia.com>
If the DMA IOMMU path is going to be used, the appropriate check should
return that DMA is supported.
Fixes: b5c58b2fdc42 ("dma-mapping: direct calls for dma-iommu")
Closes: https://lore.kernel.org/all/181e06ff-35a3-434f-b505-672f430bd1cb@notapiano
Reported-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> #KernelCI
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
kernel/dma/mapping.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
index 1a7de37bd643..38d7b3239dbb 100644
--- a/kernel/dma/mapping.c
+++ b/kernel/dma/mapping.c
@@ -824,6 +824,9 @@ static int dma_supported(struct device *dev, u64 mask)
if (WARN_ON(ops && use_dma_iommu(dev)))
return false;
+
+ if (use_dma_iommu(dev))
+ return true;
/*
* ->dma_supported sets the bypass flag, so we must always call
* into the method here unless the device is truly direct mapped.
--
2.46.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] dma-mapping: reliably inform about DMA support for IOMMU
2024-09-11 10:15 [PATCH] dma-mapping: reliably inform about DMA support for IOMMU Leon Romanovsky
@ 2024-09-11 12:54 ` Robin Murphy
2024-09-11 12:54 ` Nícolas F. R. A. Prado
2024-09-12 7:29 ` Christoph Hellwig
2 siblings, 0 replies; 5+ messages in thread
From: Robin Murphy @ 2024-09-11 12:54 UTC (permalink / raw)
To: Leon Romanovsky, Joerg Roedel, Will Deacon, Christoph Hellwig,
Marek Szyprowski
Cc: Leon Romanovsky, iommu, linux-kernel, Nícolas F. R. A. Prado
On 2024-09-11 11:15 am, Leon Romanovsky wrote:
> From: Leon Romanovsky <leonro@nvidia.com>
>
> If the DMA IOMMU path is going to be used, the appropriate check should
> return that DMA is supported.
Oof, indeed the significance of what iommu_dma_ops *didn't* implement is
a subtle one...
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
> Fixes: b5c58b2fdc42 ("dma-mapping: direct calls for dma-iommu")
> Closes: https://lore.kernel.org/all/181e06ff-35a3-434f-b505-672f430bd1cb@notapiano
> Reported-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> #KernelCI
> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
> ---
> kernel/dma/mapping.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
> index 1a7de37bd643..38d7b3239dbb 100644
> --- a/kernel/dma/mapping.c
> +++ b/kernel/dma/mapping.c
> @@ -824,6 +824,9 @@ static int dma_supported(struct device *dev, u64 mask)
>
> if (WARN_ON(ops && use_dma_iommu(dev)))
> return false;
> +
> + if (use_dma_iommu(dev))
> + return true;
> /*
> * ->dma_supported sets the bypass flag, so we must always call
> * into the method here unless the device is truly direct mapped.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] dma-mapping: reliably inform about DMA support for IOMMU
2024-09-11 10:15 [PATCH] dma-mapping: reliably inform about DMA support for IOMMU Leon Romanovsky
2024-09-11 12:54 ` Robin Murphy
@ 2024-09-11 12:54 ` Nícolas F. R. A. Prado
2024-09-12 7:29 ` Christoph Hellwig
2 siblings, 0 replies; 5+ messages in thread
From: Nícolas F. R. A. Prado @ 2024-09-11 12:54 UTC (permalink / raw)
To: Leon Romanovsky
Cc: Joerg Roedel, Will Deacon, Robin Murphy, Christoph Hellwig,
Marek Szyprowski, Leon Romanovsky, iommu, linux-kernel
On Wed, Sep 11, 2024 at 01:15:00PM +0300, Leon Romanovsky wrote:
> From: Leon Romanovsky <leonro@nvidia.com>
>
> If the DMA IOMMU path is going to be used, the appropriate check should
> return that DMA is supported.
>
> Fixes: b5c58b2fdc42 ("dma-mapping: direct calls for dma-iommu")
> Closes: https://lore.kernel.org/all/181e06ff-35a3-434f-b505-672f430bd1cb@notapiano
> Reported-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> #KernelCI
> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Thank you for the quick patch. It fixes the reported issue.
Tested-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
Thanks,
Nícolas
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] dma-mapping: reliably inform about DMA support for IOMMU
2024-09-11 10:15 [PATCH] dma-mapping: reliably inform about DMA support for IOMMU Leon Romanovsky
2024-09-11 12:54 ` Robin Murphy
2024-09-11 12:54 ` Nícolas F. R. A. Prado
@ 2024-09-12 7:29 ` Christoph Hellwig
2024-09-12 10:50 ` Leon Romanovsky
2 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2024-09-12 7:29 UTC (permalink / raw)
To: Leon Romanovsky
Cc: Joerg Roedel, Will Deacon, Robin Murphy, Christoph Hellwig,
Marek Szyprowski, Leon Romanovsky, iommu, linux-kernel,
Nícolas F. R. A. Prado
Thanks, I've applied this. I do like the flow of dma_supported even
less with the duplicate condition now. Can I get a quick review for
this incremental cleanup, please?
---
From d311bfe189d12a836b4add55fdb946f37f8697fa Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <hch@lst.de>
Date: Thu, 12 Sep 2024 09:21:18 +0200
Subject: dma-mapping: reflow dma_supported
dma_supported has become too much spaghetti for my taste. Reflow it to
remove the duplicate use_dma_iommu condition and make the main path more
obvious.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
kernel/dma/mapping.c | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
index 022d670f8cad29..cd2a97d362cd24 100644
--- a/kernel/dma/mapping.c
+++ b/kernel/dma/mapping.c
@@ -841,20 +841,23 @@ static int dma_supported(struct device *dev, u64 mask)
{
const struct dma_map_ops *ops = get_dma_ops(dev);
- if (WARN_ON(ops && use_dma_iommu(dev)))
- return false;
-
- if (use_dma_iommu(dev))
+ if (use_dma_iommu(dev)) {
+ if (WARN_ON(ops))
+ return false;
return true;
+ }
+
/*
- * ->dma_supported sets the bypass flag, so we must always call
- * into the method here unless the device is truly direct mapped.
+ * ->dma_supported sets and clears the bypass flag, so ignore it here
+ * and always call into the method if there is one.
*/
- if (!ops)
- return dma_direct_supported(dev, mask);
- if (!ops->dma_supported)
- return 1;
- return ops->dma_supported(dev, mask);
+ if (ops) {
+ if (!ops->dma_supported)
+ return 1;
+ return ops->dma_supported(dev, mask);
+ }
+
+ return dma_direct_supported(dev, mask);
}
bool dma_pci_p2pdma_supported(struct device *dev)
--
2.45.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] dma-mapping: reliably inform about DMA support for IOMMU
2024-09-12 7:29 ` Christoph Hellwig
@ 2024-09-12 10:50 ` Leon Romanovsky
0 siblings, 0 replies; 5+ messages in thread
From: Leon Romanovsky @ 2024-09-12 10:50 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Joerg Roedel, Will Deacon, Robin Murphy, Marek Szyprowski, iommu,
linux-kernel, Nícolas F. R. A. Prado
On Thu, Sep 12, 2024 at 09:29:54AM +0200, Christoph Hellwig wrote:
> Thanks, I've applied this. I do like the flow of dma_supported even
> less with the duplicate condition now. Can I get a quick review for
> this incremental cleanup, please?
>
> ---
> From d311bfe189d12a836b4add55fdb946f37f8697fa Mon Sep 17 00:00:00 2001
> From: Christoph Hellwig <hch@lst.de>
> Date: Thu, 12 Sep 2024 09:21:18 +0200
> Subject: dma-mapping: reflow dma_supported
>
> dma_supported has become too much spaghetti for my taste. Reflow it to
> remove the duplicate use_dma_iommu condition and make the main path more
> obvious.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> kernel/dma/mapping.c | 25 ++++++++++++++-----------
> 1 file changed, 14 insertions(+), 11 deletions(-)
Reviewed-by: Leon Romanovsky <leon@kernel.org>
>
> diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
> index 022d670f8cad29..cd2a97d362cd24 100644
> --- a/kernel/dma/mapping.c
> +++ b/kernel/dma/mapping.c
> @@ -841,20 +841,23 @@ static int dma_supported(struct device *dev, u64 mask)
> {
> const struct dma_map_ops *ops = get_dma_ops(dev);
>
> - if (WARN_ON(ops && use_dma_iommu(dev)))
> - return false;
> -
> - if (use_dma_iommu(dev))
> + if (use_dma_iommu(dev)) {
> + if (WARN_ON(ops))
> + return false;
> return true;
You can write it as "return !WARN_ON(ops);" if you want to be fancy, but
your version is perfectly fine too, so ignore this comment :).
> + }
> +
> /*
> - * ->dma_supported sets the bypass flag, so we must always call
> - * into the method here unless the device is truly direct mapped.
> + * ->dma_supported sets and clears the bypass flag, so ignore it here
> + * and always call into the method if there is one.
> */
> - if (!ops)
> - return dma_direct_supported(dev, mask);
> - if (!ops->dma_supported)
> - return 1;
> - return ops->dma_supported(dev, mask);
> + if (ops) {
> + if (!ops->dma_supported)
> + return 1;
Worth to change it to be "return true;"
> + return ops->dma_supported(dev, mask);
> + }
> +
> + return dma_direct_supported(dev, mask);
> }
>
> bool dma_pci_p2pdma_supported(struct device *dev)
> --
> 2.45.2
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-09-12 10:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-11 10:15 [PATCH] dma-mapping: reliably inform about DMA support for IOMMU Leon Romanovsky
2024-09-11 12:54 ` Robin Murphy
2024-09-11 12:54 ` Nícolas F. R. A. Prado
2024-09-12 7:29 ` Christoph Hellwig
2024-09-12 10:50 ` Leon Romanovsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox