Skip to content

mm/uffd: Fix missing markers on hugetlb

Peter Xu linux-mm lkml stable 1 version Applied

Status from this message: [merged mm-stable] mm-uffd-detect-pgtable-allocation-failures.patch removed from -mm tree

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 17 repliesApplied 3/3

Patches in v1 All 3 applied

#Subject and filesSizeRepliesApplied
1/3mm/hugetlb: Pre-allocate pgtable pages for uffd wr-protectsmm/hugetlb.c+11 -23 repliesApplied
2/3mm/mprotect: Use long for page accountings and retvalinclude/linux/hugetlb.h include/linux/mm.h mm/hugetlb.c +2 more+19 -195 repliesApplied
3/3mm/uffd: Detect pgtable allocation failuresinclude/linux/userfaultfd_k.h mm/hugetlb.c mm/mempolicy.c +2 more+62 -338 repliesApplied

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchJames HoughtonDavid HildenbrandMike Kravetz
1/3A-b A-b R-b
2/3A-b A-b
3/3A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v1 thread

Cover letter [PATCH 0/3] mm/uffd: Fix missing markers on hugetlb

When James was developing the vma split fix for hugetlb pmd sharing, he found that hugetlb uffd-wp is broken with the test case he developed [1]:

https://lore.kernel.org/r/CADrL8HWSym93=yNpTUdWebOEzUOTR2ffbfUk04XdK6O+PNJNoA@mail.gmail.com

Missing hugetlb pgtable pages caused uffd-wp to lose message when vma split happens to be across a shared huge pmd range in the test.

The issue is pgtable pre-allocation on hugetlb path was overlooked. That was fixed in patch 1.

Meanwhile there's another issue on proper reporting of pgtable allocation failures during UFFDIO_WRITEPROTECT. When pgtable allocation failed during the ioctl(UFFDIO_WRITEPROTECT), we will silent the error so the user cannot detect it (even if extremely rare). This issue can happen not only on hugetlb but also shmem. Anon is not affected because anon doesn't require pgtable allocation during wr-protection. Patch 2 prepares for such a change, then patch 3 allows the error to be reported to the users.

This set only marks patch 1 to copy stable, because it's a real bug to be fixed for all kernels 5.19+.

Patch 2-3 will be an enhancement to process pgtable allocation errors, it should hardly be hit even during heavy workloads in the past of my tests, but it should make the interface clearer. Not copying stable for patch 2-3 due to that. I'll prepare a man page update after patch 2-3 lands.

Tested with:

- James's reproducer above [1] so it'll start to pass with the vma split

    fix:
    https://lore.kernel.org/r/[email protected]

- Faked memory pressures to make sure -ENOMEM returned with either shmem and hugetlbfs
- Some uffd general routines

Peter Xu (3):
mm/hugetlb: Pre-allocate pgtable pages for uffd wr-protects mm/mprotect: Use long for page accountings and retval mm/uffd: Detect pgtable allocation failures

 include/linux/hugetlb.h       |  4 +-
 include/linux/mm.h            |  2 +-
 include/linux/userfaultfd_k.h |  2 +-
 mm/hugetlb.c                  | 21 +++++++--
 mm/mempolicy.c                |  4 +-
 mm/mprotect.c                 | 89 ++++++++++++++++++++++-------------
 mm/userfaultfd.c              | 16 +++++--
 7 files changed, 88 insertions(+), 50 deletions(-)
Signature · 1 line
2.37.3