From: Vivek Kasireddy <vivek.kasireddy@intel.com>
To: dri-devel@lists.freedesktop.org, linux-mm@kvack.org
Cc: Vivek Kasireddy <vivek.kasireddy@intel.com>,
David Hildenbrand <david@redhat.com>,
Daniel Vetter <daniel.vetter@ffwll.ch>,
Hugh Dickins <hughd@google.com>, Peter Xu <peterx@redhat.com>,
Jason Gunthorpe <jgg@nvidia.com>,
Gerd Hoffmann <kraxel@redhat.com>,
Dongwon Kim <dongwon.kim@intel.com>,
Junxiao Chang <junxiao.chang@intel.com>,
Dave Airlie <airlied@redhat.com>
Subject: [PATCH v16 5/9] udmabuf: Use vmf_insert_pfn and VM_PFNMAP for handling mmap
Date: Sun, 23 Jun 2024 23:36:13 -0700 [thread overview]
Message-ID: <20240624063952.1572359-6-vivek.kasireddy@intel.com> (raw)
In-Reply-To: <20240624063952.1572359-1-vivek.kasireddy@intel.com>
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 *).
Cc: David Hildenbrand <david@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: Gerd Hoffmann <kraxel@redhat.com>
Cc: Dongwon Kim <dongwon.kim@intel.com>
Cc: Junxiao Chang <junxiao.chang@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>
Signed-off-by: Vivek Kasireddy <vivek.kasireddy@intel.com>
---
drivers/dma-buf/udmabuf.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index c40645999648..820c993c8659 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -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;
}
--
2.45.1
next prev parent reply other threads:[~2024-06-24 7:05 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-24 6:36 [PATCH v16 0/9] mm/gup: Introduce memfd_pin_folios() for pinning memfd folios Vivek Kasireddy
2024-06-24 6:36 ` [PATCH v16 1/9] mm/gup: Introduce unpin_folio/unpin_folios helpers Vivek Kasireddy
2024-06-24 6:36 ` [PATCH v16 2/9] mm/gup: Introduce check_and_migrate_movable_folios() Vivek Kasireddy
2024-06-24 6:36 ` [PATCH v16 3/9] mm/gup: Introduce memfd_pin_folios() for pinning memfd folios Vivek Kasireddy
2024-07-05 20:48 ` SeongJae Park
2024-07-05 21:23 ` Andrew Morton
2024-07-05 22:11 ` Kasireddy, Vivek
2024-07-05 22:55 ` Andrew Morton
2024-07-12 22:32 ` Andrew Morton
2024-07-14 2:30 ` Kasireddy, Vivek
2024-06-24 6:36 ` [PATCH v16 4/9] udmabuf: add CONFIG_MMU dependency Vivek Kasireddy
2024-06-24 6:36 ` Vivek Kasireddy [this message]
2024-06-24 6:36 ` [PATCH v16 6/9] udmabuf: Add back support for mapping hugetlb pages Vivek Kasireddy
2024-06-24 6:36 ` [PATCH v16 7/9] udmabuf: Convert udmabuf driver to use folios Vivek Kasireddy
2024-06-24 6:36 ` [PATCH v16 8/9] udmabuf: Pin the pages using memfd_pin_folios() API Vivek Kasireddy
2024-06-24 6:36 ` [PATCH v16 9/9] selftests/udmabuf: Add tests to verify data after page migration Vivek Kasireddy
2024-06-26 19:13 ` [PATCH v16 0/9] mm/gup: Introduce memfd_pin_folios() for pinning memfd folios Kasireddy, Vivek
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=20240624063952.1572359-6-vivek.kasireddy@intel.com \
--to=vivek.kasireddy@intel.com \
--cc=airlied@redhat.com \
--cc=daniel.vetter@ffwll.ch \
--cc=david@redhat.com \
--cc=dongwon.kim@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=hughd@google.com \
--cc=jgg@nvidia.com \
--cc=junxiao.chang@intel.com \
--cc=kraxel@redhat.com \
--cc=linux-mm@kvack.org \
--cc=peterx@redhat.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