Skip to content

mm/memfd: Reserve hugetlb folios before allocation

Vivek Kasireddy dri-devel linux-mm 4 versions – Applied

Status from this message: [merged mm-stable] selftests-udmabuf-add-a-test-to-pin-first-before-writing-to-memfd.patch removed from -mm tree

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest3 patches 2 repliesApplied 3/3
  2. v33 patches 4 repliesSuperseded
  3. v22 patches 4 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v11 patch7 repliesSuperseded

Changes in v4 from the cover letter

- Create a standalone patch to fix the BUG reported by syzbot that can be backported to stable kernels (Andrew)
- Split the changes in memfd_alloc_folio() that add a call to hugetlb_reserve_pages() into a separate patch

Patches in v4 All 3 applied

#Subject and filesSizeRepliesApplied
1/3mm/hugetlb: Make hugetlb_reserve_pages() return nr of entries updatedfs/hugetlbfs/inode.c include/linux/hugetlb.h mm/hugetlb.c+18 -110 repliesApplied
2/3mm/memfd: Reserve hugetlb folios before allocationinclude/linux/hugetlb.h mm/hugetlb.c mm/memfd.c+19 -82 repliesApplied
3/3selftests/udmabuf: Add a test to pin first before writing to memfdtools/testing/selftests/drivers/dma-buf/udmabuf.c+19 -10 repliesApplied

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.

Read the v4 thread

Cover letter [PATCH v4 0/3] mm/memfd: Reserve hugetlb folios before allocation

There are cases when we try to pin a folio but discover that it has not been faulted-in. So, we try to allocate it in memfd_alloc_folio() but the allocation request may not succeed if there are no active reservations in the system at that instant.

Therefore, making a reservation (by calling hugetlb_reserve_pages()) associated with the allocation will ensure that our request would not fail due to lack of reservations. This will also ensure that proper region/subpool accounting is done with our allocation.

-----------------------------

Patchset overview:

Patch 1: Return nr of updated entries from hugetlb_reserve_pages() Patch 2: Make reservation (hugetlb_reserve_pages) in memfd_alloc_folio() Patch 3: New udmabuf selftest to invoke memfd_alloc_folio()

This series is tested by running the new udmabuf selftest introduced in patch #3 along with the other selftests.

Changelog:
v3 -> v4:
- Create a standalone patch to fix the BUG reported by syzbot that can be backported to stable kernels (Andrew)
- Split the changes in memfd_alloc_folio() that add a call to hugetlb_reserve_pages() into a separate patch

v2 -> v3:
- Call hugetlb_unreserve_pages() only if the reservation was actively (and successfully) made from memfd_alloc_folio() (David)

v1 -> v2:
- Replace VM_BUG_ON() with WARN_ON_ONCE() in the function alloc_hugetlb_folio_reserve() (David)
- Move the inline function subpool_inode() from hugetlb.c into the relevant header (hugetlb.h)
- Call hugetlb_unreserve_pages() if the folio cannot be added to the page cache as well
- Added a new udmabuf selftest to exercise the same path as that of syzbot

Cc Gerd Hoffmann <[email protected]>
Cc Steve Sistare <[email protected]>
Cc Muchun Song <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Andrew Morton <[email protected]>

Vivek Kasireddy (3):
mm/hugetlb: Make hugetlb_reserve_pages() return nr of entries updated mm/memfd: Reserve hugetlb folios before allocation selftests/udmabuf: Add a test to pin first before writing to memfd

 fs/hugetlbfs/inode.c                          |  8 +++----
 include/linux/hugetlb.h                       |  7 +++++-
 mm/hugetlb.c                                  | 24 ++++++++++---------
 mm/memfd.c                                    | 17 ++++++++++---
 .../selftests/drivers/dma-buf/udmabuf.c       | 20 +++++++++++++++-
 5 files changed, 56 insertions(+), 20 deletions(-)
Signature · 1 line
2.49.0