Re: [PATCH v4 2/2] dma: add IOMMU static calls with clear default ops

From: Christoph Hellwig
Date: Wed Sep 11 2024 - 04:05:48 EST


On Wed, Sep 11, 2024 at 09:43:05AM +0300, Leon Romanovsky wrote:
> Thanks for the report, I'm looking into it. However, it is unclear to me
> why my patch is causing this issue. The change in dma_supported() should
> produce WARN_ON [1] if new path is taken, otherwise, we return to
> previous behavior.

dma-iommu never implemented .dma_supported and thus claims to support
all dma masks. To restore that behavior we'd need something like the
patch below:

diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
index 7550b5dc5e55df..d23a4d5a6b31a1 100644
--- a/kernel/dma/mapping.c
+++ b/kernel/dma/mapping.c
@@ -841,17 +841,19 @@ 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;
/*
* ->dma_supported sets the bypass flag, so we must always call
* into the method here unless the device is truly direct mapped.
*/
- 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);
+ }
+
+ if (use_dma_iommu(dev))
+ return true;
+ return dma_direct_supported(dev, mask);
}

bool dma_pci_p2pdma_supported(struct device *dev)