Re: [PATCH] dma-mapping: fix page attributes for dma_mmap_*
From: Christoph Hellwig
Date: Thu Aug 01 2019 - 12:35:05 EST
On Thu, Aug 01, 2019 at 05:23:06PM +0100, Will Deacon wrote:
> > - if (!dev_is_dma_coherent(dev) || (attrs & DMA_ATTR_WRITE_COMBINE))
> > - return pgprot_writecombine(prot);
> > - return prot;
> > + return pgprot_writecombine(prot);
> > }
>
> Seems like a sensible cleanup to me:
>
> Acked-by: Will Deacon <will@xxxxxxxxxx>
>
> Although arch_dma_mmap_pgprot() is a bit of a misnomer now that it only
> gets involved in the non-coherent case.
A better name is welcome. My other idea would be to just remove it
entirely and do something like:
#ifndef pgprot_dmacoherent
#define pgprot_dmacoherent pgprot_noncached
#endif
pgprot_t dma_mmap_pgprot(struct device *dev, pgprot_t prot, unsigned long attrs)
{
if (dev_is_dma_coherent(dev) || (attrs & DMA_ATTR_NON_CONSISTENT))
return prot;
#ifdef pgprot_writecombine
if (attrs & DMA_ATTR_WRITE_COMBINE)
return pgprot_writecombine(prot);
#endif
return pgprot_dmacoherent(prot);
}
But my worry is how this interacts with architectures that have an
uncached segment (mips, nios2, microblaze, extensa) where we'd have
the kernel access DMA_ATTR_WRITE_COMBINE mappigns using the uncached
segment, and userspace mmaps using pgprot_writecombine, which could
lead to aliasing issues. But then again mips already supports
DMA_ATTR_WRITE_COMBINE, so this must be ok somehow. I guess I'll
need to field that question to the relevant parties.