dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dma-buf: heaps: Set VM_PFNMAP in mmap for system and cma heaps
@ 2021-02-26  4:09 John Stultz
  2021-02-26  7:36 ` Daniel Vetter
  0 siblings, 1 reply; 3+ messages in thread
From: John Stultz @ 2021-02-26  4:09 UTC (permalink / raw)
  To: lkml
  Cc: dri-devel, Sandeep Patil, Chris Goldsworthy, Ezequiel Garcia,
	Robin Murphy, James Jones, Liam Mark, Jason Gunthorpe,
	Laura Abbott, Hridya Valsaraju, Ørjan Eide, linux-media,
	Suren Baghdasaryan, Christian Koenig, Daniel Mentz

Per discussion and patches here:
  https://lore.kernel.org/dri-devel/20210223105951.912577-1-daniel.vetter@ffwll.ch/

Daniel is planning on making VM_PFNMAP required on dmabufs.

Thus to avoid the warn_on noise, set the VM_PFNMAP in the
system and cma heap's mmap handler.

Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Christian Koenig <christian.koenig@amd.com>
Cc: Sumit Semwal <sumit.semwal@linaro.org>
Cc: Liam Mark <lmark@codeaurora.org>
Cc: Chris Goldsworthy <cgoldswo@codeaurora.org>
Cc: Laura Abbott <labbott@kernel.org>
Cc: Brian Starkey <Brian.Starkey@arm.com>
Cc: Hridya Valsaraju <hridya@google.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Sandeep Patil <sspatil@google.com>
Cc: Daniel Mentz <danielmentz@google.com>
Cc: Ørjan Eide <orjan.eide@arm.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Ezequiel Garcia <ezequiel@collabora.com>
Cc: Simon Ser <contact@emersion.fr>
Cc: James Jones <jajones@nvidia.com>
Cc: linux-media@vger.kernel.org
Cc: dri-devel@lists.freedesktop.org
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 drivers/dma-buf/heaps/cma_heap.c    | 1 +
 drivers/dma-buf/heaps/system_heap.c | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c
index 364fc2f3e499..34bc3987f942 100644
--- a/drivers/dma-buf/heaps/cma_heap.c
+++ b/drivers/dma-buf/heaps/cma_heap.c
@@ -185,6 +185,7 @@ static int cma_heap_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma)
 
 	vma->vm_ops = &dma_heap_vm_ops;
 	vma->vm_private_data = buffer;
+	vma->vm_flags |= VM_PFNMAP;
 
 	return 0;
 }
diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c
index 3548b20cb98c..8995e3cbfcaf 100644
--- a/drivers/dma-buf/heaps/system_heap.c
+++ b/drivers/dma-buf/heaps/system_heap.c
@@ -228,8 +228,10 @@ static int system_heap_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma)
 			return ret;
 		addr += PAGE_SIZE;
 		if (addr >= vma->vm_end)
-			return 0;
+			break;
 	}
+
+	vma->vm_flags |= VM_PFNMAP;
 	return 0;
 }
 
-- 
2.25.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH] dma-buf: heaps: Set VM_PFNMAP in mmap for system and cma heaps
  2021-02-26  4:09 [PATCH] dma-buf: heaps: Set VM_PFNMAP in mmap for system and cma heaps John Stultz
@ 2021-02-26  7:36 ` Daniel Vetter
       [not found]   ` <20210227094436.GA3130571@infradead.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Vetter @ 2021-02-26  7:36 UTC (permalink / raw)
  To: John Stultz
  Cc: Sandeep Patil, dri-devel, Ezequiel Garcia, Robin Murphy,
	James Jones, lkml, Liam Mark, Christian Koenig, Jason Gunthorpe,
	Laura Abbott, Chris Goldsworthy, Hridya Valsaraju,
	Ørjan Eide, open list:DMA BUFFER SHARING FRAMEWORK,
	Suren Baghdasaryan, Daniel Mentz

On Fri, Feb 26, 2021 at 5:09 AM John Stultz <john.stultz@linaro.org> wrote:
>
> Per discussion and patches here:
>   https://lore.kernel.org/dri-devel/20210223105951.912577-1-daniel.vetter@ffwll.ch/
>
> Daniel is planning on making VM_PFNMAP required on dmabufs.
>
> Thus to avoid the warn_on noise, set the VM_PFNMAP in the
> system and cma heap's mmap handler.
>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> Cc: Christian Koenig <christian.koenig@amd.com>
> Cc: Sumit Semwal <sumit.semwal@linaro.org>
> Cc: Liam Mark <lmark@codeaurora.org>
> Cc: Chris Goldsworthy <cgoldswo@codeaurora.org>
> Cc: Laura Abbott <labbott@kernel.org>
> Cc: Brian Starkey <Brian.Starkey@arm.com>
> Cc: Hridya Valsaraju <hridya@google.com>
> Cc: Suren Baghdasaryan <surenb@google.com>
> Cc: Sandeep Patil <sspatil@google.com>
> Cc: Daniel Mentz <danielmentz@google.com>
> Cc: Ørjan Eide <orjan.eide@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Ezequiel Garcia <ezequiel@collabora.com>
> Cc: Simon Ser <contact@emersion.fr>
> Cc: James Jones <jajones@nvidia.com>
> Cc: linux-media@vger.kernel.org
> Cc: dri-devel@lists.freedesktop.org
> Signed-off-by: John Stultz <john.stultz@linaro.org>

System heap uses remap_pfn_range so looks fine, but cma heap inserts
pages, and that's not fine for VM_PFNMAP. You need to use
vm_insert_pfn or remap_pfn_range or one of the related pfn mapping
functions for that too. I think this should splat when you run it.

Also note that remap_pfn_range updates the vma flags already correctly
for you, so you probably don't want to do that.

Also given that both deal with struct page there's a ton of divergence
between these two that doesn't make much sense. Maybe could even share
the code fully, aside from how you allocate the struct pages.
-Daniel

> ---
>  drivers/dma-buf/heaps/cma_heap.c    | 1 +
>  drivers/dma-buf/heaps/system_heap.c | 4 +++-
>  2 files changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c
> index 364fc2f3e499..34bc3987f942 100644
> --- a/drivers/dma-buf/heaps/cma_heap.c
> +++ b/drivers/dma-buf/heaps/cma_heap.c
> @@ -185,6 +185,7 @@ static int cma_heap_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma)
>
>         vma->vm_ops = &dma_heap_vm_ops;
>         vma->vm_private_data = buffer;
> +       vma->vm_flags |= VM_PFNMAP;
>
>         return 0;
>  }
> diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c
> index 3548b20cb98c..8995e3cbfcaf 100644
> --- a/drivers/dma-buf/heaps/system_heap.c
> +++ b/drivers/dma-buf/heaps/system_heap.c
> @@ -228,8 +228,10 @@ static int system_heap_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma)
>                         return ret;
>                 addr += PAGE_SIZE;
>                 if (addr >= vma->vm_end)
> -                       return 0;
> +                       break;
>         }
> +
> +       vma->vm_flags |= VM_PFNMAP;
>         return 0;
>  }
>
> --
> 2.25.1
>


-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH] dma-buf: heaps: Set VM_PFNMAP in mmap for system and cma heaps
       [not found]   ` <20210227094436.GA3130571@infradead.org>
@ 2021-03-02  2:51     ` John Stultz
  0 siblings, 0 replies; 3+ messages in thread
From: John Stultz @ 2021-03-02  2:51 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: dri-devel, Sandeep Patil, Chris Goldsworthy, Ezequiel Garcia,
	Robin Murphy, James Jones, lkml, Liam Mark, Christian Koenig,
	Jason Gunthorpe, Laura Abbott, Hridya Valsaraju, ??rjan Eide,
	open list:DMA BUFFER SHARING FRAMEWORK, Suren Baghdasaryan,
	Daniel Mentz

On Sat, Feb 27, 2021 at 1:44 AM Christoph Hellwig <hch@infradead.org> wrote:
>
> On Fri, Feb 26, 2021 at 08:36:55AM +0100, Daniel Vetter wrote:
> > Also given that both deal with struct page there's a ton of divergence
> > between these two that doesn't make much sense. Maybe could even share
> > the code fully, aside from how you allocate the struct pages.
>
> I've been saying that since the code was first submitted.  Once pages
> are allocated from CMA they should be treated not different from normal
> pages.
>
> Please take a look at how the DMA contigous allocator manages to share
> all code for handling CMA vs alloc_pages pages.

I'll take a look at that! Thanks for the pointer!
-john
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

end of thread, other threads:[~2021-03-02  2:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-26  4:09 [PATCH] dma-buf: heaps: Set VM_PFNMAP in mmap for system and cma heaps John Stultz
2021-02-26  7:36 ` Daniel Vetter
     [not found]   ` <20210227094436.GA3130571@infradead.org>
2021-03-02  2:51     ` John Stultz

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).