Re: generic DMA bypass flag

From: Christoph Hellwig
Date: Thu Nov 14 2019 - 02:41:10 EST


On Wed, Nov 13, 2019 at 02:45:15PM +0000, Robin Murphy wrote:
> In all honesty, this seems silly. If we can set a per-device flag to say
> "oh, bypass these ops and use some other ops instead", then we can just as
> easily simply give the device the appropriate ops in the first place.
> Because, y'know, the name of the game is "per-device ops".

Except that we can't do it _that_ easily. The problem is that for both
the powerpc and intel case the selection is dynamic. If a device is in
the identify domain with intel-iommu (or the equivalent on powerpc which
doesn't use the normal iommu framework), we still want to use the iommu
to be able to map memory for devices with a too small dma mask using
the iommu instead of using swiotlb bouncing. So to "just" use the
per-device dma ops we'd need:

a) a hook in dma_direct_supported to pick another set of ops for
small dma masks
b) a hook in the IOMMU ops to propagate to the direct ops for full
64-bit masks

I looked into that for powerpc a while ago and it wasn't pretty at all.
Compared to that just checking another flag for the DMA direct calls
is relatively clean and trivial as seens in the diffstat for this series
alone.

> I don't see a great benefit to pulling legacy cruft out into common code
> instead of just working to get rid of it in-place, when said cruft pulls in
> the opposite direction to where we're taking the common code (i.e. it's
> inherently based on the premise of global ops).

I'm not sure what legacy cruft it pull in. I think it actually fits very
much into a mental model of "direct mapping is the default, to be overriden
if needed" which is pretty close to what we have at the moment. Just
with a slightly more complicated processing of the override.