<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-toradex.git/mm, branch master</title>
<subtitle>Linux kernel for Apalis and Colibri modules</subtitle>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/'/>
<entry>
<title>Merge tag 'mm-hotfixes-stable-2026-11-17-19-55' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm</title>
<updated>2026-11-18T17:01:16+00:00</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2026-11-18T17:01:16+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=d866d5bafc5e1417032255002e95f8ec3121754b'/>
<id>d866d5bafc5e1417032255002e95f8ec3121754b</id>
<content type='text'>
Pull MM fixes from Andrew Morton:

 - "maple_tree fixes for 7.3" (Liam R. Howlett):

   Fix an RCU reader NULL dereference when the tree is emptied during a
   walk, including /proc/PID/maps racing with munmap(). Add tests and
   make debug WARN and BUG checks report failures properly

 - "mm/kasan: Detect double-free involving kfree_rcu_sheaf()" (Kuniyuki
   Iwashima):

   Detect double-free when an object enters an RCU sheaf. KASAN could
   previously miss it until the object was reused, leading to a later
   free of a live object. Add KUnit tests for the different free orders

 - "mm: Fix page-table teardown during memory hot-remove" (Muchun Song):

   Balance page-table constructors and destructors when hot-remove frees
   tables on x86-64, RISC-V and arm64. This fixes NR_PAGETABLE
   accounting for tables with and without constructors

 - "mm/damon: fix watermark state, kunit pid leak and selftest fake
   pass" (SJ Park):

   Recompute watermark wait state when DAMON schemes are removed, so
   kdamond resumes monitoring. Fix a pid reference leak in KUnit and a
   selftest that reports a skipped run as a pass

 - An XArray iterator could step backwards when a large page-cache entry
   was split, sending filemap_map_pages() outside the PTE page it
   locked. The XArray correction and a filemap bound check prevent
   out-of-bounds accesses and use-after-free. Another XArray fix
   prevents lockless walkers from following a parent pointer into a
   freed node

 - Userfaultfd now validates the whole write-protection range before
   changing any VMA, avoiding partial unprotect without waking blocked
   faults. Failed unmaps now abort queued UFFD_EVENT_UNMAPs; previously
   they could report a nonexistent unmap, leak the userfaultfd context
   and leave later operations returning -EAGAIN. A fork fix clears stale
   uffd PTE bits if the new context is released before its event is
   read

 - Moving the hugetlbfs inode trace event before RCU freeing avoids a
   use-after-free of its superblock. Shmem swapin no longer retries
   forever on reused swap slots containing a mismatched large swap-cache
   folio. Swapoff also avoids a cluster-list loop that can soft-lock
   reclaim and leave swapoff hung

 - Weighted interleave recalculation now uses one node set throughout,
   avoiding a divide-by-zero during memory hotplug. Hwpoison holds the
   folio lock when inspecting its mapping and no longer leaks a folio
   reference; it also updates poison statistics before notifying
   rasdaemon through a trace event

 - Cross-node migration now moves NR_FILE_THPS and NR_KERNEL_FILE_PAGES
   with page-cache folios, preventing per-node and memcg-node accounting
   from retaining stale counts or underflowing after the folios are
   freed

* tag 'mm-hotfixes-stable-2026-11-17-19-55' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: (27 commits)
  xarray: fix index jumping backwards in xas_find()
  userfaultfd: validate the whole range before changing write protection
  maple_tree: update internal warning and bug_on code
  maple_tree: test emptying tree while RCU reading
  maple_tree: fix rcu reader NULL dereference after the tree is emptied
  mm/vma: read anon_vma carefully in validate_mm()
  hugetlbfs: move hugetlbfs_free_inode tracepoint to -&gt;destroy_inode()
  selftests/damon/sysfs_memcg_path_leak: define ksft_skip
  mm/damon/tests/sysfs-kunit: fix leaked pid reference in add_targets test
  mm/damon/core: reset watermark wait state on each iteration
  mm/filemap: stop fault-around when the walk steps back
  mm: memory-failure: update statistics before emitting the trace event
  mm/vma: undo userfaultfd unmap preparation when unmapping fails
  userfaultfd: clear uffd state in child PTEs if uffd is released during fork
  mm/memory-failure: fix folio refcount leak and min_order_for_split() locking
  mm/shmem: fix swapin livelock on a mismatched large swap cache folio
  mm/mempolicy: use one node set for interleave weights
  xarray: clear the new head's parent before freeing the old head
  arm64/mm: fix destructor for unconstructed hotplug page tables
  riscv/mm: fix missing destructor for hotplug PUD tables
  ...
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Pull MM fixes from Andrew Morton:

 - "maple_tree fixes for 7.3" (Liam R. Howlett):

   Fix an RCU reader NULL dereference when the tree is emptied during a
   walk, including /proc/PID/maps racing with munmap(). Add tests and
   make debug WARN and BUG checks report failures properly

 - "mm/kasan: Detect double-free involving kfree_rcu_sheaf()" (Kuniyuki
   Iwashima):

   Detect double-free when an object enters an RCU sheaf. KASAN could
   previously miss it until the object was reused, leading to a later
   free of a live object. Add KUnit tests for the different free orders

 - "mm: Fix page-table teardown during memory hot-remove" (Muchun Song):

   Balance page-table constructors and destructors when hot-remove frees
   tables on x86-64, RISC-V and arm64. This fixes NR_PAGETABLE
   accounting for tables with and without constructors

 - "mm/damon: fix watermark state, kunit pid leak and selftest fake
   pass" (SJ Park):

   Recompute watermark wait state when DAMON schemes are removed, so
   kdamond resumes monitoring. Fix a pid reference leak in KUnit and a
   selftest that reports a skipped run as a pass

 - An XArray iterator could step backwards when a large page-cache entry
   was split, sending filemap_map_pages() outside the PTE page it
   locked. The XArray correction and a filemap bound check prevent
   out-of-bounds accesses and use-after-free. Another XArray fix
   prevents lockless walkers from following a parent pointer into a
   freed node

 - Userfaultfd now validates the whole write-protection range before
   changing any VMA, avoiding partial unprotect without waking blocked
   faults. Failed unmaps now abort queued UFFD_EVENT_UNMAPs; previously
   they could report a nonexistent unmap, leak the userfaultfd context
   and leave later operations returning -EAGAIN. A fork fix clears stale
   uffd PTE bits if the new context is released before its event is
   read

 - Moving the hugetlbfs inode trace event before RCU freeing avoids a
   use-after-free of its superblock. Shmem swapin no longer retries
   forever on reused swap slots containing a mismatched large swap-cache
   folio. Swapoff also avoids a cluster-list loop that can soft-lock
   reclaim and leave swapoff hung

 - Weighted interleave recalculation now uses one node set throughout,
   avoiding a divide-by-zero during memory hotplug. Hwpoison holds the
   folio lock when inspecting its mapping and no longer leaks a folio
   reference; it also updates poison statistics before notifying
   rasdaemon through a trace event

 - Cross-node migration now moves NR_FILE_THPS and NR_KERNEL_FILE_PAGES
   with page-cache folios, preventing per-node and memcg-node accounting
   from retaining stale counts or underflowing after the folios are
   freed

* tag 'mm-hotfixes-stable-2026-11-17-19-55' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: (27 commits)
  xarray: fix index jumping backwards in xas_find()
  userfaultfd: validate the whole range before changing write protection
  maple_tree: update internal warning and bug_on code
  maple_tree: test emptying tree while RCU reading
  maple_tree: fix rcu reader NULL dereference after the tree is emptied
  mm/vma: read anon_vma carefully in validate_mm()
  hugetlbfs: move hugetlbfs_free_inode tracepoint to -&gt;destroy_inode()
  selftests/damon/sysfs_memcg_path_leak: define ksft_skip
  mm/damon/tests/sysfs-kunit: fix leaked pid reference in add_targets test
  mm/damon/core: reset watermark wait state on each iteration
  mm/filemap: stop fault-around when the walk steps back
  mm: memory-failure: update statistics before emitting the trace event
  mm/vma: undo userfaultfd unmap preparation when unmapping fails
  userfaultfd: clear uffd state in child PTEs if uffd is released during fork
  mm/memory-failure: fix folio refcount leak and min_order_for_split() locking
  mm/shmem: fix swapin livelock on a mismatched large swap cache folio
  mm/mempolicy: use one node set for interleave weights
  xarray: clear the new head's parent before freeing the old head
  arm64/mm: fix destructor for unconstructed hotplug page tables
  riscv/mm: fix missing destructor for hotplug PUD tables
  ...
</pre>
</div>
</content>
</entry>
<entry>
<title>Merge tag 'mm-core-7.4-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/mm/core</title>
<updated>2026-11-17T19:51:40+00:00</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2026-11-17T19:51:40+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=63fdb511c27afcebce797e3db580b3534ddfa639'/>
<id>63fdb511c27afcebce797e3db580b3534ddfa639</id>
<content type='text'>
Pull core memory management fixes from David Hildenbrand:
 "The main changes are:

   - Prevent folio refcount overflows with pagecache folios, mostly
     relevant for large folios today. The networking changes for this
     will go through the net tree.

   - Fix out-of-bounds page table accesses with folded PMDs in 3
     scenarios.

   - Fix write-sealing of memfd to detect GUP pins with concurrent
     (un)mapping more reliably, preventing writes through GUP pins after
     write-sealing.

   - Fix lost wakeups when splitting large folios.

   - Fix exposing uninitialized data through MADV_COLLAPSE to user
     space.

  The refcount changes also include a related iommufd fix for properly
  cleaning up when pinning memfd folios fails, which is now easier to
  trigger"

* tag 'mm-core-7.4-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/mm/core:
  mm/gup: limit pagecache folio refcount when grabbing references
  iommufd: fix cleanup when adding memfd folio pins fails
  mm/mmu_gather: flush pending references early before the folio limit
  mm: limit pagecache folio refcount when splicing into pipes
  mm: limit pagecache folio refcount when mapping pages
  mm/huge_memory: prevent losing PG_waiters in __split_folio_to_order()
  mm/rmap: fix PTE table overruns during batched reference checks
  mm/rmap: fix PTE table overruns during batched unmap
  mm/userfaultfd: fix PTE table overruns in UFFDIO_MOVE
  mm/memfd: handle GUP pins more reliably when write-sealing
  mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Pull core memory management fixes from David Hildenbrand:
 "The main changes are:

   - Prevent folio refcount overflows with pagecache folios, mostly
     relevant for large folios today. The networking changes for this
     will go through the net tree.

   - Fix out-of-bounds page table accesses with folded PMDs in 3
     scenarios.

   - Fix write-sealing of memfd to detect GUP pins with concurrent
     (un)mapping more reliably, preventing writes through GUP pins after
     write-sealing.

   - Fix lost wakeups when splitting large folios.

   - Fix exposing uninitialized data through MADV_COLLAPSE to user
     space.

  The refcount changes also include a related iommufd fix for properly
  cleaning up when pinning memfd folios fails, which is now easier to
  trigger"

* tag 'mm-core-7.4-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/mm/core:
  mm/gup: limit pagecache folio refcount when grabbing references
  iommufd: fix cleanup when adding memfd folio pins fails
  mm/mmu_gather: flush pending references early before the folio limit
  mm: limit pagecache folio refcount when splicing into pipes
  mm: limit pagecache folio refcount when mapping pages
  mm/huge_memory: prevent losing PG_waiters in __split_folio_to_order()
  mm/rmap: fix PTE table overruns during batched reference checks
  mm/rmap: fix PTE table overruns during batched unmap
  mm/userfaultfd: fix PTE table overruns in UFFDIO_MOVE
  mm/memfd: handle GUP pins more reliably when write-sealing
  mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE
</pre>
</div>
</content>
</entry>
<entry>
<title>mm/gup: limit pagecache folio refcount when grabbing references</title>
<updated>2026-11-14T15:36:05+00:00</updated>
<author>
<name>David Hildenbrand (Arm)</name>
<email>david@kernel.org</email>
</author>
<published>2026-11-12T22:53:24+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=2d9bcd380585abc436f055fbb618b34f98882004'/>
<id>2d9bcd380585abc436f055fbb618b34f98882004</id>
<content type='text'>
Let's add __folio_ref_count_over_limit() checks in fast and slow GUP
before acquiring additional references or pins.

Keep it simple and use the check for all folio types.

Also propagate try_grab_folio() errors when grabbing additional
references in __get_user_pages() and in memfd_pin_folios(), so hitting
the limit returns -ENOMEM instead of -EFAULT and -EINVAL, respectively.

Keep the existing invalid-refcount warnings.

Fixes: 800d8c63b2e9 ("shmem: add huge pages support")
Fixes: 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS")
Fixes: 793917d997df ("mm/readahead: Add large folio readahead")
Cc: stable@vger.kernel.org
Reviewed-by: Jose A. Perez de Azpillaga &lt;azpijr@gmail.com&gt;
Reviewed-by: Pedro Falcato &lt;pfalcato@suse.de&gt;
Link: https://patch.msgid.link/20261112-refcount_overflow_stable-v4-5-ad3deef0bd23@kernel.org
Signed-off-by: David Hildenbrand (Arm) &lt;david@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Let's add __folio_ref_count_over_limit() checks in fast and slow GUP
before acquiring additional references or pins.

Keep it simple and use the check for all folio types.

Also propagate try_grab_folio() errors when grabbing additional
references in __get_user_pages() and in memfd_pin_folios(), so hitting
the limit returns -ENOMEM instead of -EFAULT and -EINVAL, respectively.

Keep the existing invalid-refcount warnings.

Fixes: 800d8c63b2e9 ("shmem: add huge pages support")
Fixes: 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS")
Fixes: 793917d997df ("mm/readahead: Add large folio readahead")
Cc: stable@vger.kernel.org
Reviewed-by: Jose A. Perez de Azpillaga &lt;azpijr@gmail.com&gt;
Reviewed-by: Pedro Falcato &lt;pfalcato@suse.de&gt;
Link: https://patch.msgid.link/20261112-refcount_overflow_stable-v4-5-ad3deef0bd23@kernel.org
Signed-off-by: David Hildenbrand (Arm) &lt;david@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>mm/mmu_gather: flush pending references early before the folio limit</title>
<updated>2026-11-14T15:36:05+00:00</updated>
<author>
<name>David Hildenbrand (Arm)</name>
<email>david@kernel.org</email>
</author>
<published>2026-11-12T22:53:22+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=317bd7d28b248fd4d4e14614d7c30b17a36ef4d7'/>
<id>317bd7d28b248fd4d4e14614d7c30b17a36ef4d7</id>
<content type='text'>
When a task zaps mappings (e.g., MADV_DONTNEED), it can drop the PT lock
and defer dropping the folio references. In the meantime, page faults
can refault pagecache folios, creating more references for the same
folios. These deferred references can build up over multiple VMAs.

Let's just request a flush after enqueueing folios whose refcount reached
a certain threshold. Start flushing well before new references are refused,
regardless of the caller's privileges.

When returning "true" from __tlb_remove_folio_pages_size(), PTE zapping
will flush the TLB before dropping the PT lock, but drop the references
afterwards. Refaults can still race with that, but flushing early reduces
the risk of letting others hit the limit.

This is a temporary measure until we have something better.

Reported-by: Chris Mason &lt;mason@kernel.org&gt;
Fixes: 800d8c63b2e9 ("shmem: add huge pages support")
Fixes: 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS")
Fixes: 793917d997df ("mm/readahead: Add large folio readahead")
Cc: stable@vger.kernel.org
Reviewed-by: Jose A. Perez de Azpillaga &lt;azpijr@gmail.com&gt;
Reviewed-by: Lance Yang &lt;lance.yang@linux.dev&gt;
Reviewed-by: Pedro Falcato &lt;pfalcato@suse.de&gt;
Link: https://patch.msgid.link/20261112-refcount_overflow_stable-v4-3-ad3deef0bd23@kernel.org
Signed-off-by: David Hildenbrand (Arm) &lt;david@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When a task zaps mappings (e.g., MADV_DONTNEED), it can drop the PT lock
and defer dropping the folio references. In the meantime, page faults
can refault pagecache folios, creating more references for the same
folios. These deferred references can build up over multiple VMAs.

Let's just request a flush after enqueueing folios whose refcount reached
a certain threshold. Start flushing well before new references are refused,
regardless of the caller's privileges.

When returning "true" from __tlb_remove_folio_pages_size(), PTE zapping
will flush the TLB before dropping the PT lock, but drop the references
afterwards. Refaults can still race with that, but flushing early reduces
the risk of letting others hit the limit.

This is a temporary measure until we have something better.

Reported-by: Chris Mason &lt;mason@kernel.org&gt;
Fixes: 800d8c63b2e9 ("shmem: add huge pages support")
Fixes: 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS")
Fixes: 793917d997df ("mm/readahead: Add large folio readahead")
Cc: stable@vger.kernel.org
Reviewed-by: Jose A. Perez de Azpillaga &lt;azpijr@gmail.com&gt;
Reviewed-by: Lance Yang &lt;lance.yang@linux.dev&gt;
Reviewed-by: Pedro Falcato &lt;pfalcato@suse.de&gt;
Link: https://patch.msgid.link/20261112-refcount_overflow_stable-v4-3-ad3deef0bd23@kernel.org
Signed-off-by: David Hildenbrand (Arm) &lt;david@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>mm: limit pagecache folio refcount when splicing into pipes</title>
<updated>2026-11-14T15:36:05+00:00</updated>
<author>
<name>David Hildenbrand (Arm)</name>
<email>david@kernel.org</email>
</author>
<published>2026-11-12T22:53:21+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=c6c9a4c1c9a1669693330205cb9d86fafd3cf235'/>
<id>c6c9a4c1c9a1669693330205cb9d86fafd3cf235</id>
<content type='text'>
Similar to mapping pagecache folios into page tables, let's reject
additional references when splicing folios into a pipe if the refcount
is at its limit.

This will prevent more cases of possible folio refcount overflows with
large pagecache folios.

Introduce folio_get_checked() for checked reference acquisition when
the caller already holds a reference. It warns and fails on a non-positive
refcount and rejects additional references at the limit.

Add __folio_ref_count_over_limit() so folio_get_checked() can reuse the
refcount instead of having to read it a second time.

Use folio_get_checked() in splice_folio_into_pipe() and
fuse_ref_folio(), returning -EFAULT on failure, like we already do for
pipe-buffer duplication. Similarly, make try_get_page() use it instead.

Likely try_get_page() should be renamed (or removed) later, as it doesn't
match the folio_try_get() semantics and is confusing.

If we hit the limit after splicing some data, return the number of bytes
already spliced. Teach the callers to handle errors, and stop
filemap_splice_read() if we only spliced part of a folio, so we don't
skip ahead to the next folio: note that we wouldn't run into this
scenario before as we always spliced the requested range.

The check in try_get_page() also covers pipe-buffer duplication by tee()
and partial pipe-to-pipe splicing.

Note that we deliberately will not fall back to the slow path of copying
the folio, particularly as the folio might have an invalid refcount. If
it is ever really required, we can revisit.

Fixes: 800d8c63b2e9 ("shmem: add huge pages support")
Fixes: 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS")
Fixes: 793917d997df ("mm/readahead: Add large folio readahead")
Cc: stable@vger.kernel.org
Reviewed-by: Jose A. Perez de Azpillaga &lt;azpijr@gmail.com&gt;
Reviewed-by: Pedro Falcato &lt;pfalcato@suse.de&gt;
Link: https://patch.msgid.link/20261112-refcount_overflow_stable-v4-2-ad3deef0bd23@kernel.org
Signed-off-by: David Hildenbrand (Arm) &lt;david@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Similar to mapping pagecache folios into page tables, let's reject
additional references when splicing folios into a pipe if the refcount
is at its limit.

This will prevent more cases of possible folio refcount overflows with
large pagecache folios.

Introduce folio_get_checked() for checked reference acquisition when
the caller already holds a reference. It warns and fails on a non-positive
refcount and rejects additional references at the limit.

Add __folio_ref_count_over_limit() so folio_get_checked() can reuse the
refcount instead of having to read it a second time.

Use folio_get_checked() in splice_folio_into_pipe() and
fuse_ref_folio(), returning -EFAULT on failure, like we already do for
pipe-buffer duplication. Similarly, make try_get_page() use it instead.

Likely try_get_page() should be renamed (or removed) later, as it doesn't
match the folio_try_get() semantics and is confusing.

If we hit the limit after splicing some data, return the number of bytes
already spliced. Teach the callers to handle errors, and stop
filemap_splice_read() if we only spliced part of a folio, so we don't
skip ahead to the next folio: note that we wouldn't run into this
scenario before as we always spliced the requested range.

The check in try_get_page() also covers pipe-buffer duplication by tee()
and partial pipe-to-pipe splicing.

Note that we deliberately will not fall back to the slow path of copying
the folio, particularly as the folio might have an invalid refcount. If
it is ever really required, we can revisit.

Fixes: 800d8c63b2e9 ("shmem: add huge pages support")
Fixes: 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS")
Fixes: 793917d997df ("mm/readahead: Add large folio readahead")
Cc: stable@vger.kernel.org
Reviewed-by: Jose A. Perez de Azpillaga &lt;azpijr@gmail.com&gt;
Reviewed-by: Pedro Falcato &lt;pfalcato@suse.de&gt;
Link: https://patch.msgid.link/20261112-refcount_overflow_stable-v4-2-ad3deef0bd23@kernel.org
Signed-off-by: David Hildenbrand (Arm) &lt;david@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>mm: limit pagecache folio refcount when mapping pages</title>
<updated>2026-11-14T15:35:59+00:00</updated>
<author>
<name>David Hildenbrand (Arm)</name>
<email>david@kernel.org</email>
</author>
<published>2026-11-12T22:53:20+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=26b8f029ce5224dd5c5f45a4bc964a209c259914'/>
<id>26b8f029ce5224dd5c5f45a4bc964a209c259914</id>
<content type='text'>
With large file folios, overflowing the folio mapcount and refcount
became possible more easily. For anon folios it is currently not really
an issue: each large anon folio can only be mapped once into a process; on
4k kernels it would be more processes than usually allowed on a system,
and on 16k or 64k kernels the processes alone would consume hundreds of
GiB. Something to be sorted out at some point, but it's not as urgent.

Being able to overflow the refcount is not really big news, but it's about
time that we do something about it because some modern technology might
find ways to abuse it :)

One of the enablers for that was commit ddc58f27f9ee ("mm: drop tail page
refcounting"), however, file thp support was added later.

File folios can be mapped multiple times into the same process, allowing
for processes to hold many references to the same folio.

As a short-term solution, let's introduce two folio refcount limits:
one for ordinary consumers and one for admins. Leave some headroom
before the refcount goes negative, which we really don't want (having
the mapcount go negative is also not expected).

Start reporting SIGBUS and a ratelimited warning if we run into limits.
When restoring mappings from migration entries, instead zap the pte/pmd
entry. We allow for slightly exceeding the limit to keep things simpler.

During fork(), prefer not copying page table entries over failing fork.
For fault-around, check in next_uptodate_folio() before trying to lock
the folio.

Export folio_ref_count_over_limit_slowpath() using EXPORT_SYMBOL_GPL
right away so modules can use it through try_get_page(), where we will
use it next.

Use has_capability_noaudit(current, CAP_SYS_RESOURCE),
so filesystem credential overrides do not affect access to the admin
reserve, and to not generate auditing messages simply because we access
optional reserves.

Don't grant access to the admin reserve from kernel threads, from
interrupt context, where "current" is just the interrupted task, or with
IRQs disabled, as even unaudited capability checks can take locks.

This is far from ideal, but better than all easy alternatives we can
backport comfortably. For now it fixes the big problem: letting
the refcount (+mapcount) go negative and cause trouble.

This is only a temporary fix. Keep the mapping checks explicit and
separate from reference acquisition: most are expected to disappear when
we rework the underlying refcounting.

Check order 0 folios as well for consistency: each
folio_add_file_rmap*() and folio_dup_file_rmap*() needs a prior check.

Adjust the check in folio_get() to just check for invalid refcounts and
drop folio_ref_zero_or_close_to_overflow(): we really don't want
negative refcounts or negative mapcounts. Convert to VM_WARN_ON_FOLIO as
we touch it.

Also, just document -EHWPOISON for copy_present_ptes() while at it.

Note: When zapping file migration entries, uffd-wp is preserved using PTE
markers, but uffd-rwp protection is lost because there is no corresponding
marker. try_to_unmap() already has the same problem when unmapping file
folios, so we'll happily ignore it.

Reported-by: Chris Mason &lt;mason@kernel.org&gt;
Fixes: 800d8c63b2e9 ("shmem: add huge pages support")
Fixes: 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS")
Fixes: 793917d997df ("mm/readahead: Add large folio readahead")
Cc: stable@vger.kernel.org
Reviewed-by: Jose A. Perez de Azpillaga &lt;azpijr@gmail.com&gt;
Acked-by: Zi Yan &lt;ziy@nvidia.com&gt;
Reviewed-by: Pedro Falcato &lt;pfalcato@suse.de&gt;
Link: https://patch.msgid.link/20261112-refcount_overflow_stable-v4-1-ad3deef0bd23@kernel.org
Signed-off-by: David Hildenbrand (Arm) &lt;david@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
With large file folios, overflowing the folio mapcount and refcount
became possible more easily. For anon folios it is currently not really
an issue: each large anon folio can only be mapped once into a process; on
4k kernels it would be more processes than usually allowed on a system,
and on 16k or 64k kernels the processes alone would consume hundreds of
GiB. Something to be sorted out at some point, but it's not as urgent.

Being able to overflow the refcount is not really big news, but it's about
time that we do something about it because some modern technology might
find ways to abuse it :)

One of the enablers for that was commit ddc58f27f9ee ("mm: drop tail page
refcounting"), however, file thp support was added later.

File folios can be mapped multiple times into the same process, allowing
for processes to hold many references to the same folio.

As a short-term solution, let's introduce two folio refcount limits:
one for ordinary consumers and one for admins. Leave some headroom
before the refcount goes negative, which we really don't want (having
the mapcount go negative is also not expected).

Start reporting SIGBUS and a ratelimited warning if we run into limits.
When restoring mappings from migration entries, instead zap the pte/pmd
entry. We allow for slightly exceeding the limit to keep things simpler.

During fork(), prefer not copying page table entries over failing fork.
For fault-around, check in next_uptodate_folio() before trying to lock
the folio.

Export folio_ref_count_over_limit_slowpath() using EXPORT_SYMBOL_GPL
right away so modules can use it through try_get_page(), where we will
use it next.

Use has_capability_noaudit(current, CAP_SYS_RESOURCE),
so filesystem credential overrides do not affect access to the admin
reserve, and to not generate auditing messages simply because we access
optional reserves.

Don't grant access to the admin reserve from kernel threads, from
interrupt context, where "current" is just the interrupted task, or with
IRQs disabled, as even unaudited capability checks can take locks.

This is far from ideal, but better than all easy alternatives we can
backport comfortably. For now it fixes the big problem: letting
the refcount (+mapcount) go negative and cause trouble.

This is only a temporary fix. Keep the mapping checks explicit and
separate from reference acquisition: most are expected to disappear when
we rework the underlying refcounting.

Check order 0 folios as well for consistency: each
folio_add_file_rmap*() and folio_dup_file_rmap*() needs a prior check.

Adjust the check in folio_get() to just check for invalid refcounts and
drop folio_ref_zero_or_close_to_overflow(): we really don't want
negative refcounts or negative mapcounts. Convert to VM_WARN_ON_FOLIO as
we touch it.

Also, just document -EHWPOISON for copy_present_ptes() while at it.

Note: When zapping file migration entries, uffd-wp is preserved using PTE
markers, but uffd-rwp protection is lost because there is no corresponding
marker. try_to_unmap() already has the same problem when unmapping file
folios, so we'll happily ignore it.

Reported-by: Chris Mason &lt;mason@kernel.org&gt;
Fixes: 800d8c63b2e9 ("shmem: add huge pages support")
Fixes: 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS")
Fixes: 793917d997df ("mm/readahead: Add large folio readahead")
Cc: stable@vger.kernel.org
Reviewed-by: Jose A. Perez de Azpillaga &lt;azpijr@gmail.com&gt;
Acked-by: Zi Yan &lt;ziy@nvidia.com&gt;
Reviewed-by: Pedro Falcato &lt;pfalcato@suse.de&gt;
Link: https://patch.msgid.link/20261112-refcount_overflow_stable-v4-1-ad3deef0bd23@kernel.org
Signed-off-by: David Hildenbrand (Arm) &lt;david@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>mm/huge_memory: prevent losing PG_waiters in __split_folio_to_order()</title>
<updated>2026-11-13T10:14:48+00:00</updated>
<author>
<name>Zi Yan</name>
<email>ziy@nvidia.com</email>
</author>
<published>2026-11-11T03:19:25+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=7183af7f01c839ecef87840a90c0d8c5843f37d7'/>
<id>7183af7f01c839ecef87840a90c0d8c5843f37d7</id>
<content type='text'>
__split_folio_to_order() calls prep_compound_page() on each new head page
to create a compound page after clear_compound_head(). prep_compound_page()
uses non atomic __SetPageHead(). It is mostly OK, since the folio is locked
and frozen and no one else is supposed to modify the folio's flags.

However, code calling migration_entry_wait() can reach the folio by PFN,
then access its flags. It is because softleaf_entry_wait_on_locked() used
by migration_entry_wait() sets PG_waiters concurrently without taking a
reference and the frozen refcount during split cannot block it. Meanwhile,
__SetPageHead() does a plain read and write, so PG_waiters atomically set
by softleaf_entry_wait_on_locked() will be lost if the set happens after
__SetPageHead()'s read and before its write.

One example code interleaving:

CPU0: __split_folio_to_order(new_order&gt;0)  CPU1: do_swap_page()

1. clear_compound_head(new_head)
   new_head-&gt;compound_info = 0
   (page_folio(new_head) == new_head now)

                                           2. migration_entry_wait()
                                             softleaf_to_folio(entry)
                                             page_folio() -&gt; new_head
                                             (not the old head any more)

3. prep_compound_page(new_head, new_order)
     __SetPageHead(new_head)
       tmp = new_head-&gt;flags.f  &lt;-- load; PG_waiters == 0 in tmp

                                           4. folio_set_waiters(new_head)
                                             set_bit(PG_waiters, &amp;flags.f)
                                             enqueue on waitqueue, sleep

5.     new_head-&gt;flags.f = tmp | (1UL &lt;&lt; PG_head)
       &lt;-- store; overwrites step 4, PG_waiters == 0 again

Later, folio_unlock(new_folio) sees no PG_waiters, skips folio_wake_bit(),
and CPU1 can remain blocked indefinitely.

Fix it by setting PG_head along with other flags in new_folio-&gt;flags before
smp_wmb() and clear_compound_head(). The remaining compound page metadata
is set after clear_compound_head(). In that way, after
clear_compound_head() makes new_folio visible, nothing overwrites the
PG_waiters from softleaf_entry_wait_on_locked() by modifying
new_folio-&gt;flags non-atomically.

While at it, use data_race() to suppress the KCSAN issue reported by Ye
Liu's patch (the second Closes) on reading folio-&gt;flags in
__split_folio_to_order().

Suggested-by: Kiryl Shutsemau &lt;kas@kernel.org&gt;
Reported-by: David Hildenbrand &lt;david@kernel.org&gt;
Closes: https://lore.kernel.org/all/DMHE8BEEER1H.2BIY52NXATPIA@nvidia.com/
Reported-by: Ye Liu &lt;ye.liu@linux.dev&gt;
Closes: https://lore.kernel.org/all/20261029-data_race_huge_mem-v1-1-112e331291c1@linux.dev/
Fixes: c010d47f107f6 ("mm: thp: split huge page to any lower order pages")
Cc: stable@vger.kernel.org
Signed-off-by: Zi Yan &lt;ziy@nvidia.com&gt;
Reviewed-by: David Hildenbrand (Arm) &lt;david@kernel.org&gt;
Reviewed-by: Kiryl Shutsemau (Meta) &lt;kas@kernel.org&gt;
Reviewed-by: Baolin Wang &lt;baolin.wang@linux.alibaba.com&gt;
Reviewed-by: Ye Liu &lt;liuye@kylinos.cn&gt;
Link: https://patch.msgid.link/20261110-fix-split_folio_to_order-race-v4-1-cc5042f33408@nvidia.com
Signed-off-by: David Hildenbrand (Arm) &lt;david@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
__split_folio_to_order() calls prep_compound_page() on each new head page
to create a compound page after clear_compound_head(). prep_compound_page()
uses non atomic __SetPageHead(). It is mostly OK, since the folio is locked
and frozen and no one else is supposed to modify the folio's flags.

However, code calling migration_entry_wait() can reach the folio by PFN,
then access its flags. It is because softleaf_entry_wait_on_locked() used
by migration_entry_wait() sets PG_waiters concurrently without taking a
reference and the frozen refcount during split cannot block it. Meanwhile,
__SetPageHead() does a plain read and write, so PG_waiters atomically set
by softleaf_entry_wait_on_locked() will be lost if the set happens after
__SetPageHead()'s read and before its write.

One example code interleaving:

CPU0: __split_folio_to_order(new_order&gt;0)  CPU1: do_swap_page()

1. clear_compound_head(new_head)
   new_head-&gt;compound_info = 0
   (page_folio(new_head) == new_head now)

                                           2. migration_entry_wait()
                                             softleaf_to_folio(entry)
                                             page_folio() -&gt; new_head
                                             (not the old head any more)

3. prep_compound_page(new_head, new_order)
     __SetPageHead(new_head)
       tmp = new_head-&gt;flags.f  &lt;-- load; PG_waiters == 0 in tmp

                                           4. folio_set_waiters(new_head)
                                             set_bit(PG_waiters, &amp;flags.f)
                                             enqueue on waitqueue, sleep

5.     new_head-&gt;flags.f = tmp | (1UL &lt;&lt; PG_head)
       &lt;-- store; overwrites step 4, PG_waiters == 0 again

Later, folio_unlock(new_folio) sees no PG_waiters, skips folio_wake_bit(),
and CPU1 can remain blocked indefinitely.

Fix it by setting PG_head along with other flags in new_folio-&gt;flags before
smp_wmb() and clear_compound_head(). The remaining compound page metadata
is set after clear_compound_head(). In that way, after
clear_compound_head() makes new_folio visible, nothing overwrites the
PG_waiters from softleaf_entry_wait_on_locked() by modifying
new_folio-&gt;flags non-atomically.

While at it, use data_race() to suppress the KCSAN issue reported by Ye
Liu's patch (the second Closes) on reading folio-&gt;flags in
__split_folio_to_order().

Suggested-by: Kiryl Shutsemau &lt;kas@kernel.org&gt;
Reported-by: David Hildenbrand &lt;david@kernel.org&gt;
Closes: https://lore.kernel.org/all/DMHE8BEEER1H.2BIY52NXATPIA@nvidia.com/
Reported-by: Ye Liu &lt;ye.liu@linux.dev&gt;
Closes: https://lore.kernel.org/all/20261029-data_race_huge_mem-v1-1-112e331291c1@linux.dev/
Fixes: c010d47f107f6 ("mm: thp: split huge page to any lower order pages")
Cc: stable@vger.kernel.org
Signed-off-by: Zi Yan &lt;ziy@nvidia.com&gt;
Reviewed-by: David Hildenbrand (Arm) &lt;david@kernel.org&gt;
Reviewed-by: Kiryl Shutsemau (Meta) &lt;kas@kernel.org&gt;
Reviewed-by: Baolin Wang &lt;baolin.wang@linux.alibaba.com&gt;
Reviewed-by: Ye Liu &lt;liuye@kylinos.cn&gt;
Link: https://patch.msgid.link/20261110-fix-split_folio_to_order-race-v4-1-cc5042f33408@nvidia.com
Signed-off-by: David Hildenbrand (Arm) &lt;david@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>mm/rmap: fix PTE table overruns during batched reference checks</title>
<updated>2026-11-13T10:14:48+00:00</updated>
<author>
<name>David Hildenbrand (Arm)</name>
<email>david@kernel.org</email>
</author>
<published>2026-11-11T22:00:01+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=2d9b9352ef885837f246225e9b814a05e9ed2a4a'/>
<id>2d9b9352ef885837f246225e9b814a05e9ed2a4a</id>
<content type='text'>
With a folded PMD, pmd_addr_end() simply returns the supplied end.
folio_referenced_one() can therefore walk past the PTE table when
checking references to a large folio.

Folded PMDs are uncommon, but can occur even on arm64, for example
with 64K pages and a 42-bit virtual address space.

Use pte_table_clamped_end() to clamp the range to the PTE table and
VMA boundaries.

Fixes: 52e054f71840 ("mm: rmap: support batched checks of the references for large folios")
Cc: stable@vger.kernel.org
Reported-by: Chris Mason &lt;mason@kernel.org&gt;
Reviewed-by: Baolin Wang &lt;baolin.wang@linux.alibaba.com&gt;
Link: https://patch.msgid.link/20261111-pte_table_clamped_end-v1-3-2dbe339c487a@kernel.org
Signed-off-by: David Hildenbrand (Arm) &lt;david@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
With a folded PMD, pmd_addr_end() simply returns the supplied end.
folio_referenced_one() can therefore walk past the PTE table when
checking references to a large folio.

Folded PMDs are uncommon, but can occur even on arm64, for example
with 64K pages and a 42-bit virtual address space.

Use pte_table_clamped_end() to clamp the range to the PTE table and
VMA boundaries.

Fixes: 52e054f71840 ("mm: rmap: support batched checks of the references for large folios")
Cc: stable@vger.kernel.org
Reported-by: Chris Mason &lt;mason@kernel.org&gt;
Reviewed-by: Baolin Wang &lt;baolin.wang@linux.alibaba.com&gt;
Link: https://patch.msgid.link/20261111-pte_table_clamped_end-v1-3-2dbe339c487a@kernel.org
Signed-off-by: David Hildenbrand (Arm) &lt;david@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>mm/rmap: fix PTE table overruns during batched unmap</title>
<updated>2026-11-13T10:14:48+00:00</updated>
<author>
<name>David Hildenbrand (Arm)</name>
<email>david@kernel.org</email>
</author>
<published>2026-11-11T22:00:00+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=d8bbf585893c7868234b71d7e7f32484ed0d8458'/>
<id>d8bbf585893c7868234b71d7e7f32484ed0d8458</id>
<content type='text'>
With a folded PMD, pmd_addr_end() simply returns the supplied end.
folio_unmap_pte_batch() can therefore walk past the PTE table when
unmapping a large folio.

Folded PMDs are uncommon, but can occur even on arm64, for example
with 64K pages and a 42-bit virtual address space.

Use pte_table_clamped_end() to clamp the range to the PTE table and
VMA boundaries.

Fixes: 354dffd29575 ("mm: support batched unmap for lazyfree large folios during reclamation")
Cc: stable@vger.kernel.org
Reported-by: Chris Mason &lt;mason@kernel.org&gt;
Reviewed-by: Baolin Wang &lt;baolin.wang@linux.alibaba.com&gt;
Link: https://patch.msgid.link/20261111-pte_table_clamped_end-v1-2-2dbe339c487a@kernel.org
Signed-off-by: David Hildenbrand (Arm) &lt;david@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
With a folded PMD, pmd_addr_end() simply returns the supplied end.
folio_unmap_pte_batch() can therefore walk past the PTE table when
unmapping a large folio.

Folded PMDs are uncommon, but can occur even on arm64, for example
with 64K pages and a 42-bit virtual address space.

Use pte_table_clamped_end() to clamp the range to the PTE table and
VMA boundaries.

Fixes: 354dffd29575 ("mm: support batched unmap for lazyfree large folios during reclamation")
Cc: stable@vger.kernel.org
Reported-by: Chris Mason &lt;mason@kernel.org&gt;
Reviewed-by: Baolin Wang &lt;baolin.wang@linux.alibaba.com&gt;
Link: https://patch.msgid.link/20261111-pte_table_clamped_end-v1-2-2dbe339c487a@kernel.org
Signed-off-by: David Hildenbrand (Arm) &lt;david@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>mm/userfaultfd: fix PTE table overruns in UFFDIO_MOVE</title>
<updated>2026-11-13T10:14:48+00:00</updated>
<author>
<name>David Hildenbrand (Arm)</name>
<email>david@kernel.org</email>
</author>
<published>2026-11-11T21:59:59+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=169169e26ab498e4a3ee07313e986176f4bc52f0'/>
<id>169169e26ab498e4a3ee07313e986176f4bc52f0</id>
<content type='text'>
With a folded PMD, pmd_addr_end() simply returns the supplied end.
move_present_ptes() can therefore walk past the source or destination
PTE table during UFFDIO_MOVE.

pmd_addr_end() is only intended for page table traversal, in patterns
like "next = pmd_addr_end(addr, end);". With folded PMDs, a higher level
has already clamped the range to the PTE table.

Folded PMDs are uncommon, but can occur even on arm64, for example
with 64K pages and a 42-bit virtual address space.

Extract the calculation from folio_pte_range() into
pte_table_clamped_end() and use it to clamp both ranges. This preserves
the wraparound handling from commit f681d4580d5c ("mm: fix address
wraparound when scanning large folio PTEs").

Fixes: 50944692052b ("userfaultfd: opportunistic TLB-flush batching for present pages in MOVE")
Cc: stable@vger.kernel.org
Reported-by: Chris Mason &lt;mason@kernel.org&gt;
Reviewed-by: Baolin Wang &lt;baolin.wang@linux.alibaba.com&gt;
Link: https://patch.msgid.link/20261111-pte_table_clamped_end-v1-1-2dbe339c487a@kernel.org
Reviewed-by: Lokesh Gidra &lt;lokeshgidra@google.com&gt;
Signed-off-by: David Hildenbrand (Arm) &lt;david@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
With a folded PMD, pmd_addr_end() simply returns the supplied end.
move_present_ptes() can therefore walk past the source or destination
PTE table during UFFDIO_MOVE.

pmd_addr_end() is only intended for page table traversal, in patterns
like "next = pmd_addr_end(addr, end);". With folded PMDs, a higher level
has already clamped the range to the PTE table.

Folded PMDs are uncommon, but can occur even on arm64, for example
with 64K pages and a 42-bit virtual address space.

Extract the calculation from folio_pte_range() into
pte_table_clamped_end() and use it to clamp both ranges. This preserves
the wraparound handling from commit f681d4580d5c ("mm: fix address
wraparound when scanning large folio PTEs").

Fixes: 50944692052b ("userfaultfd: opportunistic TLB-flush batching for present pages in MOVE")
Cc: stable@vger.kernel.org
Reported-by: Chris Mason &lt;mason@kernel.org&gt;
Reviewed-by: Baolin Wang &lt;baolin.wang@linux.alibaba.com&gt;
Link: https://patch.msgid.link/20261111-pte_table_clamped_end-v1-1-2dbe339c487a@kernel.org
Reviewed-by: Lokesh Gidra &lt;lokeshgidra@google.com&gt;
Signed-off-by: David Hildenbrand (Arm) &lt;david@kernel.org&gt;
</pre>
</div>
</content>
</entry>
</feed>
