Re: [PoC] arm: dma-mapping: direct: Apply dma_pfn_offset only when it is valid
From: Christoph Hellwig
Date: Thu Jan 30 2020 - 11:40:15 EST
On Thu, Jan 30, 2020 at 03:04:37PM +0200, Peter Ujfalusi via iommu wrote:
> On 30/01/2020 9.53, Christoph Hellwig wrote:
> > [skipping the DT bits, as I'm everything but an expert on that..]
> >
> > On Mon, Jan 27, 2020 at 04:00:30PM +0200, Peter Ujfalusi wrote:
> >> I agree on the phys_to_dma(). It should fail for addresses which does
> >> not fall into any of the ranges.
> >> It is just a that we in Linux don't have the concept atm for ranges, we
> >> have only _one_ range which applies to every memory address.
> >
> > what does atm here mean?
>
> struct device have only single dma_pfn_offset, one can not have multiple
> ranges defined. If we have then only the first is taken and the physical
> address and dma address is discarded, only the dma_pfn_offset is stored
> and used.
>
> > We have needed multi-range support for quite a while, as common broadcom
> > SOCs do need it. So patches for that are welcome at least from the
> > DMA layer perspective (kinda similar to your pseudo code earlier)
>
> But do they have dma_pfn_offset != 0?
Well, with that I mean multiple ranges with different offsets. Take
a look at arch/mips/bmips/dma.c:__phys_to_dma() and friends. This
is an existing implementation for mips, but there are arm and arm64
SOCs using the same logic on the market as well, and we'll want to
support them eventually.
> The dma_pfn_offset is _still_ applied to the mask we are trying to set
> (and validate) via dma-direct.
And for the general case that is exactly the right thing to do, we
just need to deal with really odd ZONE_DMA placements like yours.
> > We'll need to find the minimum change to make it work
> > for now without switching ops, even if it isn't the correct one, and
> > then work from there.
>
> Sure, but can we fix the regression by reverting to arm_ops for now only
> if dma_pfn_offset is not 0? It used to work fine in the past at least it
> appeared to work on K2 platforms.
But that will cause yet another regression in what we have just fixed
with using the generic direct ops, at which points it turns into who
screams louder.
For now I'm tempted to throw something like this in, which is a bit
of a hack, but actually 100% matches what various architectures have
historically done:
diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index 6af7ae83c4ad..6ba9ee6e20bd 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -482,6 +482,9 @@ int dma_direct_supported(struct device *dev, u64 mask)
{
u64 min_mask;
+ if (mask >= DMA_BIT_MASK(32))
+ return 1;
+
if (IS_ENABLED(CONFIG_ZONE_DMA))
min_mask = DMA_BIT_MASK(zone_dma_bits);
else