iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: gavinli@thegavinli.com
To: Christoph Hellwig <hch@lst.de>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Robin Murphy <robin.murphy@arm.com>,
	iommu@lists.linux-foundation.org
Cc: Gavin Li <git@thegavinli.com>
Subject: [PATCH v1] dma-mapping: normal memory for mmap() on coherent architectures
Date: Fri,  2 Aug 2019 11:07:58 -0700	[thread overview]
Message-ID: <20190802180758.9691-1-gavinli@thegavinli.com> (raw)

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

             reply	other threads:[~2019-08-02 20:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-02 18:07 gavinli [this message]
2019-08-03  6:23 ` [PATCH v1] dma-mapping: normal memory for mmap() on coherent architectures 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190802180758.9691-1-gavinli@thegavinli.com \
    --to=gavinli@thegavinli.com \
    --cc=git@thegavinli.com \
    --cc=hch@lst.de \
    --cc=iommu@lists.linux-foundation.org \
    --cc=m.szyprowski@samsung.com \
    --cc=robin.murphy@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).