[PATCH v2 00/31] mm: various (urgent?) fixes, part 3

From: David Hildenbrand (Arm)

Date: Fri Dec 04 2026 - 07:50:33 EST


Hi,

this is actually part 3. I didn't indicate part 2 properly, and it
caused confusion for people monitoring these fixes :)

So, here is another set of fixes for core MM that I will pick up once
reviewed. This time it's mostly shmem, khugepaged and some nasty, nasty
KSM things.

Mostly AI-reported fixes, with some fixes found while redoing some of
them properly.

1 fix has high urgency, 12 have medium urgency and 17 have low urgency.

The last patch is not a fix; for a while I thought it would be one. It's
all confusing. But it's a reasonable locking consistency change in
migration code.

The really critical ones IMHO are:

- "mm/khugepaged: check the VMA before walking page tables when
collapsing" (high)
- "mm/ksm: copy KSM folios at swap-in without VM_MERGEABLE" (medium)
- "mm/ksm: don't convert a shared anon folio into a KSM folio" (medium)
- "mm/memory: don't clear a PUD leaf as bad in a zap" (medium)
- "mm/migrate_device: don't collect KSM folios" (medium)

I might pick these early to send them to Linus before the merge window.
OTOH, the merge window is just around the corner ... and the KSM things
require systems with KSM enabled.

Most fixes are reviewed by now. The following two are still missing review
and are more involved, so I would appreciate some extra careful eyes:

- "mm/ksm: don't convert a shared anon folio into a KSM folio"
- "mm: taint device sections before setting subsections valid"

This is based on mm-core/for-next. I did a bunch of testing (selftests,
some targeted reproducers/tests), but more testing will be highly
appreciated.

Again, thanks to everyone helping out with moving the flood of fixes
forward :)

Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
---
Changes in v2:
- Rebased on top of mm-core/for-next.
- Collected tags (thanks!).
- Dropped "mm/mempolicy: don't wait for mems_allowed_seq in
kmalloc_nolock()".
- "mm/shmem: reject userfaultfd fills during hole punch"
- Drop the comment above __shmem_faults_blocked().
- "mm/khugepaged: don't wait for userfaultfd"
- Clarify in the description that MISSING mode is required as well.
- "mm/khugepaged: check PMD support with the folios locked"
- Also check shmem and drop the outdated comment.
- Update the patch description.
- "mm/migrate_device: don't collect secretmem pages"
- Refuse secretmem VMAs in migrate_vma_setup() instead.
- "mm/ksm: don't convert a shared anon folio into a KSM folio"
- Document that some shared pages might not get merged.
- "mm/migrate: fix KSM oddity by checking expected refcount without
mappings"
- Clarify the description.
- Link to v1: https://patch.msgid.link/20261129-fixes_core_3-v1-0-f66094116801@xxxxxxxxxx

---
Chris Mason (10):
mm/khugepaged: flush file after unlocking folios in collapse_file()
mm/khugepaged: store new folio before adding it to LRU
mm/khugepaged: check PMD support with the folios locked
mm/memory: drop the swap device ref before do_wp_page()
mm/migrate_device: don't collect secretmem pages
mm/mempolicy: check access under exec_update_lock
mm/mempolicy: reject an empty set of allowed nodes
mm/ksm: look up the folio again in cmp_and_merge_page()
mm/ksm: copy KSM folios at swap-in without VM_MERGEABLE
mm/migrate_device: don't collect KSM folios

David Hildenbrand (Arm) (21):
mm/shmem: count only the swapped pages in the requested range
mm/shmem: don't skip parts of a split swap entry when punching holes
mm/shmem: reject userfaultfd fills during hole punch
mm/shmem: fix commit limit bypass with very large shmem sizes
mm/shmem: don't pin inodes with eviction held off in the huge shrinker
mm/shmem: seal the size of SysV and shared anon files
mm/khugepaged: check the VMA before walking page tables when collapsing
mm/khugepaged: check for uffd outside the i_pages lock
mm/khugepaged: don't wait for userfaultfd
mm/khugepaged: stop MADV_COLLAPSE on a fatal signal
mm/huge_memory: split huge zero PMDs on unshare faults
mm/huge_memory: don't map huge PFN entries if the arch restricts PFNs
mm/memory: don't clear a PUD leaf as bad in a zap
mm: consistently check MMF_UNSTABLE when populating in CoW mappings
mm/gup: check for fatal signals in memfd_pin_folios()
mm/migrate_device: mark folios leaving device memory dirty
mm: taint device sections before setting subsections valid
mm/ksm: don't convert a shared anon folio into a KSM folio
mm/ksm: use a migration counter to detect KSM folio migration
mm/migrate: fix KSM oddity by checking expected refcount without mappings
mm/migrate: use consistent folio locking logic

Documentation/admin-guide/mm/ksm.rst | 3 +
include/linux/mm.h | 62 +++++++++------
include/linux/mmzone.h | 9 +++
include/linux/oom.h | 48 +++++++++---
include/linux/shmem_fs.h | 11 +++
ipc/shm.c | 2 +
mm/filemap.c | 9 +++
mm/gup.c | 5 ++
mm/huge_memory.c | 34 ++++++++-
mm/khugepaged.c | 119 ++++++++++++++++++-----------
mm/ksm.c | 143 +++++++++++++++++++++++++++--------
mm/memory.c | 46 +++++++----
mm/memory_hotplug.c | 34 ++-------
mm/mempolicy.c | 30 +++++---
mm/migrate.c | 73 +++++++++---------
mm/migrate_device.c | 30 +++++++-
mm/rmap.c | 6 +-
mm/shmem.c | 96 +++++++++++++++++++----
mm/sparse-vmemmap.c | 39 +++++++---
mm/userfaultfd.c | 37 +++++++++
20 files changed, 611 insertions(+), 225 deletions(-)
---
base-commit: 9ae069c329809d5206bd03470d033bd899970087
change-id: 20261110-fixes_core_3-701ac25d6d72

Best regards,
--
David Hildenbrand (Arm) <david@xxxxxxxxxx>