Skip to contentSkip to conversation

dma-buf: heaps: Set VM_PFNMAP in mmap for system and cma heaps

PATCH In review John Stultz 3 participants 4 messages Feb 26, 2021 – Mar 2, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dma-buf: heaps: Set VM_PFNMAP in mmap for system and cma heaps

Per discussion and patches here:
https://lore.kernel.org/dri-devel/[email protected]/

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 <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Christian Koenig <[email protected]>
Cc Sumit Semwal <[email protected]>
Cc Liam Mark <[email protected]>
Cc Chris Goldsworthy <[email protected]>
Cc Laura Abbott <[email protected]>
Cc Brian Starkey <[email protected]>
Cc Hridya Valsaraju <[email protected]>
Cc Suren Baghdasaryan <[email protected]>
Cc Sandeep Patil <[email protected]>
Cc Daniel Mentz <[email protected]>
Cc Ørjan Eide <[email protected]>
Cc Robin Murphy <[email protected]>
Cc Ezequiel Garcia <[email protected]>
Cc Simon Ser <[email protected]>
Cc James Jones <[email protected]>
---
 drivers/dma-buf/heaps/cma_heap.c    | 1 +
 drivers/dma-buf/heaps/system_heap.c | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/dma-buf/heaps/cma_heap.c +1 -0
index 364fc2f3e499..34bc3987f942 100644
@@ -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;
 }
drivers/dma-buf/heaps/system_heap.c +3 -1
index 3548b20cb98c..8995e3cbfcaf 100644
@@ -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;
 }
 
Signature · 6 lines
2.25.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 21 lines · John Stultz

Per discussion and patches here:
https://lore.kernel.org/dri-devel/[email protected]/

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 <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Christian Koenig <[email protected]>
Cc Sumit Semwal <[email protected]>
Cc Liam Mark <[email protected]>
Cc Chris Goldsworthy <[email protected]>
Cc Laura Abbott <[email protected]>
Cc Brian Starkey <[email protected]>
Cc Hridya Valsaraju <[email protected]>
Cc Suren Baghdasaryan <[email protected]>
Cc Sandeep Patil <[email protected]>
Cc Daniel Mentz <[email protected]>
Quoted 8 lines
Cc Ørjan Eide <[email protected]>
Cc Robin Murphy <[email protected]>
Cc Ezequiel Garcia <[email protected]>
Cc Simon Ser <[email protected]>
Cc James Jones <[email protected]>

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

Quoted 36 lines
---
 drivers/dma-buf/heaps/cma_heap.c    | 1 +
 drivers/dma-buf/heaps/system_heap.c | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/dma-buf/heaps/cma_heap.c +1 -0
index 364fc2f3e499..34bc3987f942 100644
@@ -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;
 }
drivers/dma-buf/heaps/system_heap.c +3 -2
index 3548b20cb98c..8995e3cbfcaf 100644
@@ -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

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw
Quoted 3 lines · Daniel Vetter

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.

#3 lore raw
Quoted 6 lines · Christoph Hellwig
Quoted 3 lines · Daniel Vetter

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.

Quoted 6 lines

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
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel