diff options
| author | James Houghton <jthoughton@google.com> | 2026-09-10 02:34:10 +0000 |
|---|---|---|
| committer | Andrew Morton <akpm@linux-foundation.org> | 2026-09-13 21:32:36 -0700 |
| commit | 14b9a9b022bb58dddc9c4d5d1b27d3f14a8456b4 (patch) | |
| tree | d4c13be57485c26dc625cc15bdd7acf03a45a086 /mm | |
| parent | ed14c253d32ca0510f9a230ce08c7fcf00d6b1c0 (diff) | |
| download | linux-next-14b9a9b022bb58dddc9c4d5d1b27d3f14a8456b4.tar.gz linux-next-14b9a9b022bb58dddc9c4d5d1b27d3f14a8456b4.zip | |
mm/khugepaged: never install PMDs in uffd-minor-registered VMAs
Userfaultfd minor faults provides userspace with the ability to manually
install PTEs with UFFDIO_CONTINUE. Right now, MADV_COLLAPSE can map holes
in the VMA when a naturally-aligned THP is present. This is not true for
khugepaged collapse: the PTEs will be retracted, but a PMD will not be
installed.
When MADV_COLLAPSE installs a PMD that mapped holes in the VMA, userspace
is likely to expect UFFDIO_CONTINUE to succeed on the should-be holes.
UFFDIO_CONTINUE will fail and return EEXIST.
This is not inherently a problem, as MADV_COLLAPSE is an explicit
userspace action. But, especially because MADV_COLLAPSE can be invoked by
an external process via process_madvise(), a rogue caller could break a
userfaultfd-minor resolver thread. If khugepaged is later updated to
install PMDs for khugepaged collapsing, that would be a genuine problem.
Userspace cannot generally use MADV_COLLAPSE to resolve userfault minor
faults, as MADV_COLLAPSE will only resolve such faults if a
naturally-aligned THP is present.
The naturally-aligned THP case is the only case where this quirk exists.
Collapsing otherwise requires all PTEs to be present for
userfaultfd-registered VMAs (i.e., max none PTEs is 0), which is correct.
This check is essentially bypassed for naturally-aligned THPs.
khugepaged doesn't actually install PMDs, so it is impossible for the
kernel to silently install mappings that userspace didn't ask for.
Therefore this patch does not need to be backported.
Link: https://lore.kernel.org/20260910023411.514987-1-jthoughton@google.com
Suggested-by: Lance Yang <lance.yang@linux.dev>
Tested-by: Lance Yang <lance.yang@linux.dev>
Signed-off-by: James Houghton <jthoughton@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Barry Song <baohua@kernel.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Kiryl Shutsemau <kas@kernel.org>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Yang Shi <shy828301@gmail.com>
Cc: Zach O'Keefe <zokeefe@google.com>
Cc: Zi Yan <ziy@nvidia.com>
Diffstat (limited to 'mm')
| -rw-r--r-- | mm/khugepaged.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/mm/khugepaged.c b/mm/khugepaged.c index e763900d2e3f..0d8cd44b14c5 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1834,6 +1834,13 @@ static enum scan_result try_collapse_pte_mapped_thp(struct mm_struct *mm, unsign if (userfaultfd_protected(vma)) return SCAN_PTE_UFFD; + /* + * Userfaultfd-minor-registered VMAs should not be collapsed, as + * userspace is expecting to explicitly install PTEs. + */ + if (userfaultfd_minor(vma)) + return SCAN_PTE_UFFD; + folio = filemap_lock_folio(vma->vm_file->f_mapping, linear_page_index(vma, haddr)); if (IS_ERR(folio)) |
