]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
udmabuf: use vmf_insert_pfn and VM_PFNMAP for handling mmap
authorVivek Kasireddy <vivek.kasireddy@intel.com>
Mon, 24 Jun 2024 06:36:13 +0000 (23:36 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 12 Jul 2024 22:52:10 +0000 (15:52 -0700)
Add VM_PFNMAP to vm_flags in the mmap handler to ensure that the mappings
would be managed without using struct page.

And, in the vm_fault handler, use vmf_insert_pfn to share the page's pfn
to userspace instead of directly sharing the page (via struct page *).

Link: https://lkml.kernel.org/r/20240624063952.1572359-6-vivek.kasireddy@intel.com
Signed-off-by: Vivek Kasireddy <vivek.kasireddy@intel.com>
Suggested-by: David Hildenbrand <david@redhat.com>
Acked-by: David Hildenbrand <david@redhat.com>
Acked-by: Dave Airlie <airlied@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Hugh Dickins <hughd@google.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: Dongwon Kim <dongwon.kim@intel.com>
Cc: Junxiao Chang <junxiao.chang@intel.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
drivers/dma-buf/udmabuf.c

index c406459996489ce7c7844f5a2687ddd76d4c9113..820c993c86592adc015df6b54cfa1a4c221a50ad 100644 (file)
@@ -35,12 +35,13 @@ static vm_fault_t udmabuf_vm_fault(struct vm_fault *vmf)
        struct vm_area_struct *vma = vmf->vma;
        struct udmabuf *ubuf = vma->vm_private_data;
        pgoff_t pgoff = vmf->pgoff;
+       unsigned long pfn;
 
        if (pgoff >= ubuf->pagecount)
                return VM_FAULT_SIGBUS;
-       vmf->page = ubuf->pages[pgoff];
-       get_page(vmf->page);
-       return 0;
+
+       pfn = page_to_pfn(ubuf->pages[pgoff]);
+       return vmf_insert_pfn(vma, vmf->address, pfn);
 }
 
 static const struct vm_operations_struct udmabuf_vm_ops = {
@@ -56,6 +57,7 @@ static int mmap_udmabuf(struct dma_buf *buf, struct vm_area_struct *vma)
 
        vma->vm_ops = &udmabuf_vm_ops;
        vma->vm_private_data = ubuf;
+       vm_flags_set(vma, VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP);
        return 0;
 }