summaryrefslogtreecommitdiff
path: root/mm/gup.c
diff options
context:
space:
mode:
authorSteve Sistare <steven.sistare@oracle.com>2024-10-25 06:11:51 -0700
committerJason Gunthorpe <jgg@nvidia.com>2024-10-28 13:24:23 -0300
commita2ad1b8101a36c927bcbd1317475b9576c352155 (patch)
treed2641b8751555a9f860ca974efd57fb0021d8449 /mm/gup.c
parente2d8fe9148b79ed1cbf0663edc988db7769173dc (diff)
downloadlinux-a2ad1b8101a36c927bcbd1317475b9576c352155.tar.gz
linux-a2ad1b8101a36c927bcbd1317475b9576c352155.tar.bz2
linux-a2ad1b8101a36c927bcbd1317475b9576c352155.zip
mm/gup: Add folio_add_pins()
Export a function that adds pins to an already-pinned huge-page folio. This allows any range of small pages within the folio to be unpinned later. For example, pages pinned via memfd_pin_folios and modified by folio_add_pins could be unpinned via unpin_user_page(s). Link: https://patch.msgid.link/r/1729861919-234514-2-git-send-email-steven.sistare@oracle.com Suggested-by: Jason Gunthorpe <jgg@nvidia.com> Suggested-by: David Hildenbrand <david@redhat.com> Signed-off-by: Steve Sistare <steven.sistare@oracle.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Acked-by: David Hildenbrand <david@redhat.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Diffstat (limited to 'mm/gup.c')
-rw-r--r--mm/gup.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/mm/gup.c b/mm/gup.c
index a82890b46a36..4ac3e567e08e 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -3717,3 +3717,27 @@ err:
return ret;
}
EXPORT_SYMBOL_GPL(memfd_pin_folios);
+
+/**
+ * folio_add_pins() - add pins to an already-pinned folio
+ * @folio: the folio to add more pins to
+ * @pins: number of pins to add
+ *
+ * Try to add more pins to an already-pinned folio. The semantics
+ * of the pin (e.g., FOLL_WRITE) follow any existing pin and cannot
+ * be changed.
+ *
+ * This function is helpful when having obtained a pin on a large folio
+ * using memfd_pin_folios(), but wanting to logically unpin parts
+ * (e.g., individual pages) of the folio later, for example, using
+ * unpin_user_page_range_dirty_lock().
+ *
+ * This is not the right interface to initially pin a folio.
+ */
+int folio_add_pins(struct folio *folio, unsigned int pins)
+{
+ VM_WARN_ON_ONCE(!folio_maybe_dma_pinned(folio));
+
+ return try_grab_folio(folio, pins, FOLL_PIN);
+}
+EXPORT_SYMBOL_GPL(folio_add_pins);