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

* Re: [PATCH v1] dma-mapping: normal memory for mmap() on coherent architectures
  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
  2020-10-28 11:39   ` Oded Gabbay
  0 siblings, 2 replies; 9+ messages in thread
From: Christoph Hellwig @ 2019-08-03  6:23 UTC (permalink / raw)
  To: gavinli; +Cc: Gavin Li, iommu, Robin Murphy, Christoph Hellwig

See the discussion at:

https://lists.linuxfoundation.org/pipermail/iommu/2019-August/037716.html

Just curious, what driver do you use that uses dma_mmap_coherent on
x86?
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* Re: [PATCH v1] dma-mapping: normal memory for mmap() on coherent architectures
  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
  1 sibling, 1 reply; 9+ messages in thread
From: Gavin Li @ 2019-08-03  6:35 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: iommu, Robin Murphy, Gavin Li

Ah, seems like it wasn't as simple of a fix as I thought :)

I intended to use dma_mmap_coherent() in the usbfs driver
(drivers/usb/core/devio.c) because its mmap() was broken on arm64 and
all the other noncoherent DMA architectures.

Patch here: https://www.spinics.net/lists/linux-usb/msg183148.html
More info: https://www.spinics.net/lists/linux-usb/msg183180.html

On Fri, Aug 2, 2019 at 11:23 PM Christoph Hellwig <hch@lst.de> wrote:
>
> See the discussion at:
>
> https://lists.linuxfoundation.org/pipermail/iommu/2019-August/037716.html
>
> Just curious, what driver do you use that uses dma_mmap_coherent on
> x86?
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* Re: [PATCH v1] dma-mapping: normal memory for mmap() on coherent architectures
  2019-08-03  6:35   ` Gavin Li
@ 2019-08-03  6:39     ` Christoph Hellwig
  0 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2019-08-03  6:39 UTC (permalink / raw)
  To: Gavin Li; +Cc: Gavin Li, iommu, Robin Murphy, Christoph Hellwig

On Fri, Aug 02, 2019 at 11:35:48PM -0700, Gavin Li wrote:
> Ah, seems like it wasn't as simple of a fix as I thought :)

With our mess of dma flags nothing is ever as simple as it seems..

> I intended to use dma_mmap_coherent() in the usbfs driver
> (drivers/usb/core/devio.c) because its mmap() was broken on arm64 and
> all the other noncoherent DMA architectures.

Good to know, that is the right thing to do!

I'll try to expedite the fix to 5.3-rc + stable backports once we agree
on the details.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* Re: [PATCH v1] dma-mapping: normal memory for mmap() on coherent architectures
  2019-08-03  6:23 ` Christoph Hellwig
  2019-08-03  6:35   ` Gavin Li
@ 2020-10-28 11:39   ` Oded Gabbay
  2020-10-28 17:31     ` Christoph Hellwig
  1 sibling, 1 reply; 9+ messages in thread
From: Oded Gabbay @ 2020-10-28 11:39 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Robin Murphy, Gavin Li, gavinli,
	list@263.net:IOMMU DRIVERS
	<iommu@lists.linux-foundation.org>,
	Joerg Roedel <joro@8bytes.org>,

On Sat, Aug 3, 2019 at 9:26 AM Christoph Hellwig <hch@lst.de> wrote:
>
> See the discussion at:
>
> https://lists.linuxfoundation.org/pipermail/iommu/2019-August/037716.html
>
> Just curious, what driver do you use that uses dma_mmap_coherent on
> x86?
> _______________________________________________
> iommu mailing list
> iommu@lists.linux-foundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/iommu

Hi Christoph,
In the habanalabs driver we have moved to use dma_mmap_coherent (to
match dma_alloc_coherent - see commit
https://lkml.org/lkml/2020/8/29/252)
Since then, we are plagued by the kernel log message that gavin has
mentioned, as we are mostly running in our C/I environment with 5.4.
I wondered if you know if there was any fix to that in the more recent kernels ?
If not, can I help to fix that ?

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

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

* Re: [PATCH v1] dma-mapping: normal memory for mmap() on coherent architectures
  2020-10-28 11:39   ` Oded Gabbay
@ 2020-10-28 17:31     ` Christoph Hellwig
  2020-10-28 17:38       ` Oded Gabbay
  0 siblings, 1 reply; 9+ messages in thread
From: Christoph Hellwig @ 2020-10-28 17:31 UTC (permalink / raw)
  To: Oded Gabbay
  Cc: Robin Murphy, Gavin Li, gavinli, Christoph Hellwig,
	list@263.net:IOMMU DRIVERS
	<iommu@lists.linux-foundation.org>,
	Joerg Roedel <joro@8bytes.org>,

On Wed, Oct 28, 2020 at 01:39:17PM +0200, Oded Gabbay wrote:
> On Sat, Aug 3, 2019 at 9:26 AM Christoph Hellwig <hch@lst.de> wrote:
> >
> > See the discussion at:
> >
> > https://lists.linuxfoundation.org/pipermail/iommu/2019-August/037716.html
> >
> > Just curious, what driver do you use that uses dma_mmap_coherent on
> > x86?
> > _______________________________________________
> > iommu mailing list
> > iommu@lists.linux-foundation.org
> > https://lists.linuxfoundation.org/mailman/listinfo/iommu
> 
> Hi Christoph,
> In the habanalabs driver we have moved to use dma_mmap_coherent (to
> match dma_alloc_coherent - see commit
> https://lkml.org/lkml/2020/8/29/252)
> Since then, we are plagued by the kernel log message that gavin has
> mentioned, as we are mostly running in our C/I environment with 5.4.
> I wondered if you know if there was any fix to that in the more recent kernels ?
> If not, can I help to fix that ?

What are the kernel log messages that gaving has mentioned?
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* Re: [PATCH v1] dma-mapping: normal memory for mmap() on coherent architectures
  2020-10-28 17:31     ` Christoph Hellwig
@ 2020-10-28 17:38       ` Oded Gabbay
  2020-10-28 17:39         ` Christoph Hellwig
  0 siblings, 1 reply; 9+ messages in thread
From: Oded Gabbay @ 2020-10-28 17:38 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Robin Murphy, Gavin Li, gavinli,
	list@263.net:IOMMU DRIVERS
	<iommu@lists.linux-foundation.org>,
	Joerg Roedel <joro@8bytes.org>,

On Wed, Oct 28, 2020 at 7:31 PM Christoph Hellwig <hch@lst.de> wrote:
>
> On Wed, Oct 28, 2020 at 01:39:17PM +0200, Oded Gabbay wrote:
> > On Sat, Aug 3, 2019 at 9:26 AM Christoph Hellwig <hch@lst.de> wrote:
> > >
> > > See the discussion at:
> > >
> > > https://lists.linuxfoundation.org/pipermail/iommu/2019-August/037716.html
> > >
> > > Just curious, what driver do you use that uses dma_mmap_coherent on
> > > x86?
> > > _______________________________________________
> > > iommu mailing list
> > > iommu@lists.linux-foundation.org
> > > https://lists.linuxfoundation.org/mailman/listinfo/iommu
> >
> > Hi Christoph,
> > In the habanalabs driver we have moved to use dma_mmap_coherent (to
> > match dma_alloc_coherent - see commit
> > https://lkml.org/lkml/2020/8/29/252)
> > Since then, we are plagued by the kernel log message that gavin has
> > mentioned, as we are mostly running in our C/I environment with 5.4.
> > I wondered if you know if there was any fix to that in the more recent kernels ?
> > If not, can I help to fix that ?
>
> What are the kernel log messages that gaving has mentioned?

This one:
11:22:43  [Wed Oct 28 11:22:34 2020] x86/PAT: synapse_tests:29265 map
pfn RAM range req uncached-minus for [mem 0xe6236b000-0xe6236bfff],
got write-back

Thousands of the same message with different addresses of course.

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

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

* Re: [PATCH v1] dma-mapping: normal memory for mmap() on coherent architectures
  2020-10-28 17:38       ` Oded Gabbay
@ 2020-10-28 17:39         ` Christoph Hellwig
  2020-10-28 19:33           ` Oded Gabbay
  0 siblings, 1 reply; 9+ messages in thread
From: Christoph Hellwig @ 2020-10-28 17:39 UTC (permalink / raw)
  To: Oded Gabbay
  Cc: Robin Murphy, Gavin Li, gavinli, Christoph Hellwig,
	list@263.net:IOMMU DRIVERS
	<iommu@lists.linux-foundation.org>,
	Joerg Roedel <joro@8bytes.org>,

On Wed, Oct 28, 2020 at 07:38:04PM +0200, Oded Gabbay wrote:
> > > https://lkml.org/lkml/2020/8/29/252)
> > > Since then, we are plagued by the kernel log message that gavin has
> > > mentioned, as we are mostly running in our C/I environment with 5.4.
> > > I wondered if you know if there was any fix to that in the more recent kernels ?
> > > If not, can I help to fix that ?
> >
> > What are the kernel log messages that gaving has mentioned?
> 
> This one:
> 11:22:43  [Wed Oct 28 11:22:34 2020] x86/PAT: synapse_tests:29265 map
> pfn RAM range req uncached-minus for [mem 0xe6236b000-0xe6236bfff],
> got write-back
> 
> Thousands of the same message with different addresses of course.

What kernel version is this on?  And what is the test case?
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* Re: [PATCH v1] dma-mapping: normal memory for mmap() on coherent architectures
  2020-10-28 17:39         ` Christoph Hellwig
@ 2020-10-28 19:33           ` Oded Gabbay
  0 siblings, 0 replies; 9+ messages in thread
From: Oded Gabbay @ 2020-10-28 19:33 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Robin Murphy, Gavin Li, gavinli,
	list@263.net:IOMMU DRIVERS
	<iommu@lists.linux-foundation.org>,
	Joerg Roedel <joro@8bytes.org>,

On Wed, Oct 28, 2020 at 7:39 PM Christoph Hellwig <hch@lst.de> wrote:
>
> On Wed, Oct 28, 2020 at 07:38:04PM +0200, Oded Gabbay wrote:
> > > > https://lkml.org/lkml/2020/8/29/252)
> > > > Since then, we are plagued by the kernel log message that gavin has
> > > > mentioned, as we are mostly running in our C/I environment with 5.4.
> > > > I wondered if you know if there was any fix to that in the more recent kernels ?
> > > > If not, can I help to fix that ?
> > >
> > > What are the kernel log messages that gaving has mentioned?
> >
> > This one:
> > 11:22:43  [Wed Oct 28 11:22:34 2020] x86/PAT: synapse_tests:29265 map
> > pfn RAM range req uncached-minus for [mem 0xe6236b000-0xe6236bfff],
> > got write-back
> >
> > Thousands of the same message with different addresses of course.
>
> What kernel version is this on?  And what is the test case?

ok, so my previous message wasn't accurate. On 5.4 kernel it actually
does NOT happen.
It happens on 4.18 and 4.15 (kernels that are delivered in Ubuntu 18.04).
So I assume it was fixed somewhere between 4.19 to 5.4.
I'll try to dig the code to see where the change is exactly.

Thanks and sorry for the trouble,
Oded
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[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).