iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] dma-mapping: normal memory for mmap() on coherent architectures
@ 2019-08-02 18:07 gavinli
  2019-08-03  6:23 ` Christoph Hellwig
  0 siblings, 1 reply; 9+ messages in thread
From: gavinli @ 2019-08-02 18:07 UTC (permalink / raw)
  To: Christoph Hellwig, Marek Szyprowski, Robin Murphy, iommu; +Cc: Gavin Li

From: Gavin Li <git@thegavinli.com>

On x86, calling dma_mmap_coherent() on memory allocated with
dma_alloc_coherent() causes the following warning to be issued:

x86/PAT: ... map pfn RAM range req uncached-minus for [mem 0x77f000000-0x77f210fff], got write-back

This occurs because on x86 dma_alloc_coherent() returns normal kernel
memory pages (with a write-back PAT), but dma_mmap_coherent() tries to
map the same pages into userspace with a uncached-minus PAT, even though
there is no need for the mapping to noncached.

This patch ensures that on DMA coherent architectures/devices, memory is
mapped normally rather than as noncached.

Signed-off-by: Gavin Li <git@thegavinli.com>
---
 include/linux/dma-noncoherent.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/include/linux/dma-noncoherent.h b/include/linux/dma-noncoherent.h
index 9741767e400f..40ff11380ec7 100644
--- a/include/linux/dma-noncoherent.h
+++ b/include/linux/dma-noncoherent.h
@@ -31,7 +31,11 @@ long arch_dma_coherent_to_pfn(struct device *dev, void *cpu_addr,
 pgprot_t arch_dma_mmap_pgprot(struct device *dev, pgprot_t prot,
 		unsigned long attrs);
 #else
-# define arch_dma_mmap_pgprot(dev, prot, attrs)	pgprot_noncached(prot)
+static inline pgprot_t arch_dma_mmap_pgprot(struct device *dev, pgprot_t prot,
+		unsigned long attrs)
+{
+	return dev_is_dma_coherent(dev) ? prot : pgprot_noncached(prot);
+}
 #endif
 
 #ifdef CONFIG_DMA_NONCOHERENT_CACHE_SYNC
-- 
2.22.0

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-10-28 19:33 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-02 18:07 [PATCH v1] dma-mapping: normal memory for mmap() on coherent architectures gavinli
2019-08-03  6:23 ` Christoph Hellwig
2019-08-03  6:35   ` Gavin Li
2019-08-03  6:39     ` Christoph Hellwig
2020-10-28 11:39   ` Oded Gabbay
2020-10-28 17:31     ` Christoph Hellwig
2020-10-28 17:38       ` Oded Gabbay
2020-10-28 17:39         ` Christoph Hellwig
2020-10-28 19:33           ` Oded Gabbay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).