* [PATCH v2 00/35] mm/hugetlb: various fixes (2)
@ 2026-12-03 11:37 David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 02/35] mm/hugetlb: restore the reservation if vma_needs_reservation() fails David Hildenbrand (Arm)
` (18 more replies)
0 siblings, 19 replies; 22+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 11:37 UTC (permalink / raw)
To: Muchun Song, Oscar Salvador, Andrew Morton, Hongfu Li,
Jinmeng Zhou, Mina Almasry, Davidlohr Bueso, Naoya Horiguchi,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Michal Hocko,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Vivek Kasireddy,
Mel Gorman, Hugh Dickins, Baolin Wang, Dave Airlie,
Jason Gunthorpe, Andy Whitcroft, Roman Gushchin, Barry Song,
Andrea Arcangeli, Lorenzo Stoakes, Suren Baghdasaryan,
Shakeel Butt, Pedro Falcato, Jann Horn, Guillaume Morin, Yang Shi,
James Houghton, Rik van Riel, Harry Yoo, Lance Yang,
Axel Rasmussen, Peter Xu, Sasha Levin, Kiryl Shutsemau,
Christian Brauner, Steven Rostedt (Google), Hongbo Li,
Gregory Price, Zi Yan, Joshua Hahn, Rakie Kim, Ying Huang,
Matthew Brost, Byungchul Park, Alistair Popple, Andi Kleen,
David Rientjes, Joern Engel, Aneesh Kumar K.V
Cc: linux-mm, linux-doc, Gerd Hoffmann, linux-kernel, linux-fsdevel,
Johannes Weiner, Chris Mason, Jiaqi Yan, David Hildenbrand (Arm),
Sashiko, stable
Hi,
this is v2 with a bunch more fixes, which I didn't want to send separately
to not cause a mess on the list. Most of the new ones are from Sashiko
reports, and some found while working on them. Chris reported two more.
This is likely the last hugetlb fixes series I'll be sending; I'll
delegate from now on :)
I was able to reproduce and test most of them.
Based on the same base as v1.
- Patch #1: hotfix for v7.4 (already in mm-hotfixes-stable)
- Patch #2 - #6: reservation handling fixes
- Patch #7 - #11: folio allocation and freeing fixes
- Patch #12 - #13: userfaultfd and soft-dirty fixes
- Patch #14 - #25: truncation, hole punching, fallocate() and inode fixes
- Patch #26 - #30: PMD table sharing and VMA lock fixes
- Patch #31 - #33: accounting fixes
- Patch #34: a hugetlb cgroup fix
- Patch #35: a cleanup / hardening patch
I un-RFCed #34 and dropped the controversial VMA-lock optimization fix.
Nothing here is urgent. A lot are low-priority issues, but we might just
fix them in bulk instead of getting random fixes for these things
upstream.
---
Changes in v2:
- Collected tags (thanks!).
- Dropped "mm/hugetlb: use the VMA lock to stabilize flags for PMD sharing".
- "mm/hugetlb_cgroup: charge faults to mm->owner"
- Dropped the RFC label.
- Fall back to current->mm like memcg, and also charge reservations to
the mm of the VMA.
- Minor patch description fixups.
- Added new fixes:
- "mm/hugetlb: restore the reservation if vma_needs_reservation() fails"
- "mm/hugetlb: restore the reservation when racing with another reservation"
- "mm/hugetlb: return the reservation to the subpool on error"
- "mm/hugetlb: report reservations that we actually added from
hugetlb_reserve_pages()"
- "mm/hugetlb: keep HPAGE_RESV_UNMAPPED when forking"
- "mm/hugetlb: wait for deferred frees before failing an allocation"
- "mm/hugetlb_cma: reset hugetlb_cma_size if the arch doesn't support it"
- "hugetlbfs: fix integer overflow when punching holes"
- "hugetlbfs: don't overflow the pseudo VMA address in fallocate()"
- "hugetlbfs: don't overflow the end of the unmap range on 32-bit"
- "hugetlbfs: don't skip private VMAs when unmapping on truncation"
- "mm/hugetlb: serialize private faults with truncation"
- "mm/hugetlb: check EOF for UFFDIO_COPY and UFFDIO_POISON"
- "hugetlbfs: zero all hugetlbfs-specific fields of new inodes"
- "mm/rmap: don't fail unmapping hugetlb folios from private VMAs"
- Reordered the patches by topic.
- Link to v1: https://patch.msgid.link/20261125-hugetlb_fixes_2-v1-0-db27fd2f71a8@kernel.org
To: Muchun Song <muchun.song@linux.dev>
To: Oscar Salvador <osalvador@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
To: Hongfu Li <lihongfu@kylinos.cn>
To: Jinmeng Zhou <jinmengzhou22@gmail.com>
To: Mina Almasry <almasrymina@google.com>
To: Davidlohr Bueso <dave@stgolabs.net>
To: Naoya Horiguchi <nao.horiguchi@gmail.com>
To: "Liam R. Howlett" <liam@infradead.org>
To: Vlastimil Babka <vbabka@kernel.org>
To: Mike Rapoport <rppt@kernel.org>
To: Michal Hocko <mhocko@suse.com>
To: Jonathan Corbet <corbet@lwn.net>
To: Shuah Khan <skhan@linuxfoundation.org>
To: Randy Dunlap <rdunlap@infradead.org>
To: Vivek Kasireddy <vivek.kasireddy@intel.com>
To: Mel Gorman <mgorman@suse.de>
To: Hugh Dickins <hughd@google.com>
To: Baolin Wang <baolin.wang@linux.alibaba.com>
To: Dave Airlie <airlied@redhat.com>
To: Jason Gunthorpe <jgg@ziepe.ca>
To: Andy Whitcroft <apw@canonical.com>
To: Roman Gushchin <roman.gushchin@linux.dev>
To: Barry Song <baohua@kernel.org>
To: Andrea Arcangeli <aarcange@redhat.com>
To: Lorenzo Stoakes <ljs@kernel.org>
To: Suren Baghdasaryan <surenb@google.com>
To: Shakeel Butt <shakeel.butt@linux.dev>
To: Pedro Falcato <pfalcato@suse.de>
To: Jann Horn <jannh@google.com>
To: Guillaume Morin <guillaume@morinfr.org>
To: Yang Shi <shy828301@gmail.com>
To: James Houghton <jthoughton@google.com>
To: Rik van Riel <riel@surriel.com>
To: Harry Yoo <harry@kernel.org>
To: Lance Yang <lance.yang@linux.dev>
To: Axel Rasmussen <axelrasmussen@google.com>
To: Peter Xu <peterx@redhat.com>
To: Sasha Levin <sashal@kernel.org>
To: Kiryl Shutsemau <kas@kernel.org>
To: Christian Brauner <brauner@kernel.org>
To: "Steven Rostedt (Google)" <rostedt@goodmis.org>
To: Hongbo Li <lihongbo22@huawei.com>
To: Gregory Price <gourry@gourry.net>
To: Zi Yan <ziy@nvidia.com>
To: Joshua Hahn <joshua.hahnjy@gmail.com>
To: Rakie Kim <rakie.kim@sk.com>
To: Ying Huang <ying.huang@linux.alibaba.com>
To: Matthew Brost <matthew.brost@intel.com>
To: Byungchul Park <byungchul@sk.com>
To: Alistair Popple <apopple@nvidia.com>
To: Andi Kleen <ak@linux.intel.com>
To: David Rientjes <rientjes@google.com>
To: Joern Engel <joern@lazybastard.org>
To: "Aneesh Kumar K.V" <aneesh.kumar@kernel.org>
Cc: linux-mm@kvack.org
Cc: linux-doc@vger.kernel.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Chris Mason <mason@kernel.org>
Cc: Jiaqi Yan <jiaqiyan@google.com>
---
Chris Mason (8):
mm/hugetlb: fix truncated copy result in UFFDIO_COPY
hugetlbfs: fix deadlock between hole punching and memory failure
hugetlbfs: recheck the vma range after the lock wait
mm/hugetlb: don't zap non-present entries when unmapping a folio
hugetlbfs: seal SHM_HUGETLB files against growth
mm/hugetlb: unshare PMDs of a split VMA if allocating its lock fails
mm/hugetlb_cgroup: track in-use folios per cgroup
mm/hugetlb: resolve protnone faults without a uffd bit
David Hildenbrand (Arm) (27):
mm/hugetlb: charge the copy made at fork to the parent
mm/hugetlb: restore the reservation if vma_needs_reservation() fails
mm/hugetlb: restore the reservation when racing with another reservation
mm/hugetlb: return the reservation to the subpool on error
mm/hugetlb: report reservations that we actually added from hugetlb_reserve_pages()
mm/hugetlb: keep HPAGE_RESV_UNMAPPED when forking
mm/hugetlb: always mark new page cache folios migratable
mm/memfd: mark new hugetlb folios migratable
mm/hugetlb: free surplus folios of other nodes on free
mm/hugetlb: wait for deferred frees before failing an allocation
mm/hugetlb_cma: reset hugetlb_cma_size if the arch doesn't support it
fs/proc/task_mmu: don't clear VM_SOFTDIRTY on hugetlb VMAs
hugetlbfs: fix integer overflow when punching holes
hugetlbfs: don't zero poisoned pages in a hole punch
hugetlbfs: don't overflow the pseudo VMA address in fallocate()
hugetlbfs: don't overflow the end of the unmap range on 32-bit
hugetlbfs: don't skip private VMAs when unmapping on truncation
mm/hugetlb: serialize private faults with truncation
mm/hugetlb: check EOF for UFFDIO_COPY and UFFDIO_POISON
hugetlbfs: zero all hugetlbfs-specific fields of new inodes
mm/rmap: don't fail unmapping hugetlb folios from private VMAs
mm/hugetlb: only check PMD table sharing for PMD-sized folios
mm/migrate: check hugetlb PMD sharing in move_pages()
mm/hugetlb: don't share page tables of a VMA during mprotect()
mm/hugetlb: count migration entries at fork and unmap
mm/hugetlb: stop accounting HugetlbPages once PMD tables were shared
mm/hugetlb_cgroup: charge faults to mm->owner
Documentation/filesystems/proc.rst | 3 +-
Documentation/mm/hugetlbfs_reserv.rst | 4 +-
fs/hugetlbfs/inode.c | 64 ++++---
fs/proc/task_mmu.c | 9 +-
include/linux/hugetlb.h | 22 ++-
include/linux/hugetlb_cgroup.h | 30 +++-
include/linux/leafops.h | 11 ++
mm/hugetlb.c | 330 +++++++++++++++++++++++-----------
mm/hugetlb_cgroup.c | 66 ++++---
mm/hugetlb_cma.c | 1 +
mm/memfd.c | 1 +
mm/mempolicy.c | 2 +-
mm/migrate.c | 23 ++-
mm/rmap.c | 12 +-
mm/vma.c | 2 +-
tools/testing/vma/include/stubs.h | 3 +-
16 files changed, 389 insertions(+), 194 deletions(-)
---
base-commit: c8117bff684306f5c1f959d055cc2b24dd67b1eb
change-id: 20261120-hugetlb_fixes_2-26455c584f4e
Best regards,
--
David Hildenbrand (Arm) <david@kernel.org>
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v2 02/35] mm/hugetlb: restore the reservation if vma_needs_reservation() fails
2026-12-03 11:37 [PATCH v2 00/35] mm/hugetlb: various fixes (2) David Hildenbrand (Arm)
@ 2026-12-03 11:37 ` David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 03/35] mm/hugetlb: restore the reservation when racing with another reservation David Hildenbrand (Arm)
` (17 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 11:37 UTC (permalink / raw)
To: Muchun Song, Oscar Salvador, Andrew Morton, Hongfu Li,
Jinmeng Zhou, Mina Almasry, Davidlohr Bueso, Naoya Horiguchi,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Michal Hocko,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Vivek Kasireddy,
Mel Gorman, Hugh Dickins, Baolin Wang, Dave Airlie,
Jason Gunthorpe, Andy Whitcroft, Roman Gushchin, Barry Song,
Andrea Arcangeli, Lorenzo Stoakes, Suren Baghdasaryan,
Shakeel Butt, Pedro Falcato, Jann Horn, Guillaume Morin, Yang Shi,
James Houghton, Rik van Riel, Harry Yoo, Lance Yang,
Axel Rasmussen, Peter Xu, Sasha Levin, Kiryl Shutsemau,
Christian Brauner, Steven Rostedt (Google), Hongbo Li,
Gregory Price, Zi Yan, Joshua Hahn, Rakie Kim, Ying Huang,
Matthew Brost, Byungchul Park, Alistair Popple, Andi Kleen,
David Rientjes, Joern Engel, Aneesh Kumar K.V
Cc: linux-mm, linux-doc, Gerd Hoffmann, linux-kernel, linux-fsdevel,
Johannes Weiner, Chris Mason, Jiaqi Yan, Sashiko, stable,
David Hildenbrand (Arm)
When we fault in a folio in a shared hugetlb mapping at an index that is
not reserved yet, for example because the mapping was created with
MAP_NORESERVE, alloc_hugetlb_folio() is responsible for performing the
hugetlb reservation for the folio's index in the reserve map.
If something goes wrong before adding the folio to the page cache,
restore_reserve_on_error() will call vma_needs_reservation(), which can
fail to allocate a file_region in corner cases.
In that case, we will leave the reserve map unchanged and free the folio
without HPG_restore_reserve. Consequently, nothing backs the reservation.
The same happens on a min_size= mount if alloc_hugetlb_folio() took the
reservation from the subpool minimum: the folio then has
HPG_restore_reserve, but we clear it when vma_needs_reservation() fails.
When we later try again to allocate+populate the page cache, we will
consume the reservation for that index in the reserve map, although we
never accounted for a reservation. This will underflow resv_huge_pages
and the subpool usage.
Reproduced both cases with fault-injection, failing the file_region
allocation in restore_reserve_on_error() when the first UFFDIO_COPY
attempt into a MAP_SHARED|MAP_NORESERVE mapping fails:
(1) memfd, after the retry:
HugePages_Rsvd: 0 -> 18446744073709551615
(2) hugetlbfs mount with min_size=, after unmounting:
HugePages_Rsvd: 0 -> 18446744073709551615
Let's fix it by setting or keeping HPG_restore_reserve for folios in
shared mappings in this unlikely error case, such that free_huge_folio()
will restore the reservation.
Restructure the code to make it at least a little bit easier to
understand.
This has low urgency, as the file_region allocation is very unlikely to
fail.
Fixes: 846be08578ed ("mm/hugetlb: expand restore_reserve_on_error functionality")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
mm/hugetlb.c | 39 ++++++++++++++++++++-------------------
1 file changed, 20 insertions(+), 19 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index f46c85fc0cd0b..bf2265bc6eb71 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -2730,21 +2730,27 @@ void restore_reserve_on_error(struct hstate *h, struct vm_area_struct *vma,
{
long rc = vma_needs_reservation(h, vma, address);
- if (folio_test_hugetlb_restore_reserve(folio)) {
- if (unlikely(rc < 0))
- /*
- * Rare out of memory condition in reserve map
- * manipulation. Clear hugetlb_restore_reserve so
- * that global reserve count will not be incremented
- * by free_huge_folio. This will make it appear
- * as though the reservation for this folio was
- * consumed. This may prevent the task from
- * faulting in the folio at a later time. This
- * is better than inconsistent global huge page
- * accounting of reserve counts.
- */
+ if (unlikely(rc < 0)) {
+ /*
+ * Rare out of memory condition in reserve map manipulation.
+ *
+ * In shared mappings, the reserve map has the reservation for
+ * this index, so let folio freeing code restore it.
+ *
+ * Otherwise, don't restore the reservation, making it appear
+ * as though it was consumed. This may prevent the task from
+ * faulting in the folio at a later time, but is better than
+ * inconsistent global huge page accounting of reserve counts.
+ */
+ if (vma->vm_flags & VM_MAYSHARE)
+ folio_set_hugetlb_restore_reserve(folio);
+ else
folio_clear_hugetlb_restore_reserve(folio);
- else if (rc)
+ return;
+ }
+
+ if (folio_test_hugetlb_restore_reserve(folio)) {
+ if (rc)
(void)vma_add_reservation(h, vma, address);
else
vma_end_reservation(h, vma, address);
@@ -2769,11 +2775,6 @@ void restore_reserve_on_error(struct hstate *h, struct vm_area_struct *vma,
* on a subsequent allocation.
*/
folio_set_hugetlb_restore_reserve(folio);
- } else if (rc < 0) {
- /*
- * Region cache allocation can fail even if an entry exists.
- * Leave the flag and reserve map unchanged.
- */
} else {
/*
* No reservation present, do nothing
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v2 03/35] mm/hugetlb: restore the reservation when racing with another reservation
2026-12-03 11:37 [PATCH v2 00/35] mm/hugetlb: various fixes (2) David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 02/35] mm/hugetlb: restore the reservation if vma_needs_reservation() fails David Hildenbrand (Arm)
@ 2026-12-03 11:37 ` David Hildenbrand (Arm)
2026-12-04 6:07 ` Muchun Song
2026-12-03 11:37 ` [PATCH v2 04/35] mm/hugetlb: return the reservation to the subpool on error David Hildenbrand (Arm)
` (16 subsequent siblings)
18 siblings, 1 reply; 22+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 11:37 UTC (permalink / raw)
To: Muchun Song, Oscar Salvador, Andrew Morton, Hongfu Li,
Jinmeng Zhou, Mina Almasry, Davidlohr Bueso, Naoya Horiguchi,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Michal Hocko,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Vivek Kasireddy,
Mel Gorman, Hugh Dickins, Baolin Wang, Dave Airlie,
Jason Gunthorpe, Andy Whitcroft, Roman Gushchin, Barry Song,
Andrea Arcangeli, Lorenzo Stoakes, Suren Baghdasaryan,
Shakeel Butt, Pedro Falcato, Jann Horn, Guillaume Morin, Yang Shi,
James Houghton, Rik van Riel, Harry Yoo, Lance Yang,
Axel Rasmussen, Peter Xu, Sasha Levin, Kiryl Shutsemau,
Christian Brauner, Steven Rostedt (Google), Hongbo Li,
Gregory Price, Zi Yan, Joshua Hahn, Rakie Kim, Ying Huang,
Matthew Brost, Byungchul Park, Alistair Popple, Andi Kleen,
David Rientjes, Joern Engel, Aneesh Kumar K.V
Cc: linux-mm, linux-doc, Gerd Hoffmann, linux-kernel, linux-fsdevel,
Johannes Weiner, Chris Mason, Jiaqi Yan, Sashiko, stable,
David Hildenbrand (Arm)
When we fault in a folio in a shared hugetlb mapping at an index that is
not reserved yet, alloc_hugetlb_folio() can race with
hugetlb_reserve_pages() reserving that index, for example, because
another process mmap()s the same file without MAP_NORESERVE.
vma_commit_reservation() will then find the racing reservation in the
reserve map after allocating the folio, and we consume that reservation
instead: we return our subpool charge, drop a global reservation and
uncharge the cgroup reservation of the folio. However, we don't set
HPG_restore_reserve on the folio.
If we then hit an error before the folio gets added to the page cache,
restore_reserve_on_error() assumes that alloc_hugetlb_folio() performed
the reservation in the reserve map and removes it, and free_huge_folio()
doesn't restore the global reservation. The reservation of the racing
mmap() is then gone, and a later fault at that index can fail with
SIGBUS.
Reproduced by artificially delaying alloc_hugetlb_folio() right before
vma_commit_reservation() during a failing UFFDIO_COPY, while another
process mmap()s the same file: once all unreserved huge pages are in
use, that process gets SIGBUS when touching its page.
Let's fix it by setting HPG_restore_reserve, so the error path keeps the
reservation in the reserve map and free_huge_folio() restores the global
reservation. On success, adding the folio to the page cache clears the
flag.
This has low urgency, as it requires an error after racing with another
mapping reserving the same index.
Fixes: 33039678c8da ("mm/hugetlb: handle races in alloc_huge_page and hugetlb_reserve_pages")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
mm/hugetlb.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index bf2265bc6eb71..fbe79ae4c0f3c 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -3222,6 +3222,11 @@ static struct folio *__alloc_hugetlb_folio(struct vm_area_struct *vma,
hugetlb_cgroup_uncharge_folio_rsvd(
hstate_index(h), pages_per_huge_page(h), folio);
spin_unlock_irq(&hugetlb_lock);
+ /*
+ * We consumed that existing reservation and must
+ * restore it when freeing the folio due to errors.
+ */
+ folio_set_hugetlb_restore_reserve(folio);
}
}
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v2 04/35] mm/hugetlb: return the reservation to the subpool on error
2026-12-03 11:37 [PATCH v2 00/35] mm/hugetlb: various fixes (2) David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 02/35] mm/hugetlb: restore the reservation if vma_needs_reservation() fails David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 03/35] mm/hugetlb: restore the reservation when racing with another reservation David Hildenbrand (Arm)
@ 2026-12-03 11:37 ` David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 05/35] mm/hugetlb: report reservations that we actually added from hugetlb_reserve_pages() David Hildenbrand (Arm)
` (15 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 11:37 UTC (permalink / raw)
To: Muchun Song, Oscar Salvador, Andrew Morton, Hongfu Li,
Jinmeng Zhou, Mina Almasry, Davidlohr Bueso, Naoya Horiguchi,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Michal Hocko,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Vivek Kasireddy,
Mel Gorman, Hugh Dickins, Baolin Wang, Dave Airlie,
Jason Gunthorpe, Andy Whitcroft, Roman Gushchin, Barry Song,
Andrea Arcangeli, Lorenzo Stoakes, Suren Baghdasaryan,
Shakeel Butt, Pedro Falcato, Jann Horn, Guillaume Morin, Yang Shi,
James Houghton, Rik van Riel, Harry Yoo, Lance Yang,
Axel Rasmussen, Peter Xu, Sasha Levin, Kiryl Shutsemau,
Christian Brauner, Steven Rostedt (Google), Hongbo Li,
Gregory Price, Zi Yan, Joshua Hahn, Rakie Kim, Ying Huang,
Matthew Brost, Byungchul Park, Alistair Popple, Andi Kleen,
David Rientjes, Joern Engel, Aneesh Kumar K.V
Cc: linux-mm, linux-doc, Gerd Hoffmann, linux-kernel, linux-fsdevel,
Johannes Weiner, Chris Mason, Jiaqi Yan, Sashiko, stable,
David Hildenbrand (Arm)
When we fault in a folio in a shared hugetlb mapping at an index that is
not reserved yet on a min_size= mount, alloc_hugetlb_folio() can take the
reservation from the subpool minimum, and we perform the reservation for
the folio's index in the reserve map.
If something goes wrong before adding the folio to the page cache,
restore_reserve_on_error() is supposed to undo the reservation in the
reserve map, and free_huge_folio() is supposed to return the reservation
to the subpool, like we do for CoW mappings already.
However, as the folio consumed a global reservation, it has
HPG_restore_reserve set. So restore_reserve_on_error() keeps the
reservation in the reserve map, and free_huge_folio() restores the global
reservation instead of returning it to the subpool.
Consequently, the reservation from the subpool minimum is stuck at that
index until truncation. As vma_commit_reservation() does not charge the
hugetlb cgroup reservation, a later fault at that index will consume it
without a cgroup charge.
Reproduced with a failing UFFDIO_COPY on a min_size= mount, followed by
a fault at the same index, inside a hugetlb cgroup:
hugetlb.2MB.rsvd.current: 0 instead of 2097152
Let's fix it by clearing HPG_restore_reserve in shared mappings as well.
On success, adding the folio to the page cache clears the flag.
Note that we have to clear the flag before vma_commit_reservation()
now, such that the race handling can set it again when we raced with
another reservation.
This has low urgency, as it only affects the subpool minimum and the
hugetlb cgroup reservation accounting on min_size= mounts.
Fixes: 1c5ecae3a93f ("hugetlbfs: add minimum size accounting to subpools")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
Documentation/mm/hugetlbfs_reserv.rst | 4 ++--
mm/hugetlb.c | 24 +++++++++++++++---------
2 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/Documentation/mm/hugetlbfs_reserv.rst b/Documentation/mm/hugetlbfs_reserv.rst
index 4711029bd067d..7c13f79603eee 100644
--- a/Documentation/mm/hugetlbfs_reserv.rst
+++ b/Documentation/mm/hugetlbfs_reserv.rst
@@ -257,8 +257,8 @@ compensate. See the section
:ref:`Reservation Map Helper Routines <resv_map_helpers>` for more
information on these routines.
-For CoW mappings, alloc_hugetlb_folio() calls
-folio_clear_hugetlb_restore_reserve() if the reservation came from the subpool.
+alloc_hugetlb_folio() calls folio_clear_hugetlb_restore_reserve() if the
+reservation came from the subpool.
This makes free_huge_folio() return the reservation to the subpool on error.
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index fbe79ae4c0f3c..025aae6d0b72e 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -2722,7 +2722,9 @@ static long vma_del_reservation(struct hstate *h,
* In case 2, simply undo reserve map modifications done by alloc_hugetlb_folio.
*
* For CoW mappings, allocations using a subpool reservation leave the
- * flag clear and the reserve map unchanged. free_huge_folio returns the
+ * flag clear and the reserve map unchanged. The same applies to shared
+ * mappings, except that case 2 removes the reservation from the reserve map,
+ * unless updating the reserve map fails. free_huge_folio returns the
* reservation to the subpool.
*/
void restore_reserve_on_error(struct hstate *h, struct vm_area_struct *vma,
@@ -3200,6 +3202,18 @@ static struct folio *__alloc_hugetlb_folio(struct vm_area_struct *vma,
hugetlb_set_folio_subpool(folio, spool);
+ /*
+ * On error, let folio freeing code return the reservation to the
+ * subpool, unless we consumed a reservation from the reserve map.
+ *
+ * In private mappings, the reserve map might not exist or already
+ * account for another folio at this index. In shared mappings,
+ * restore_reserve_on_error() will remove the reservation we are about
+ * to add to the reserve map, unless updating the reserve map fails.
+ */
+ if (map_chg != MAP_CHG_REUSE)
+ folio_clear_hugetlb_restore_reserve(folio);
+
if (map_chg != MAP_CHG_ENFORCED) {
/* commit() is only needed if the map_chg is not enforced */
retval = vma_commit_reservation(h, vma, addr);
@@ -3230,14 +3244,6 @@ static struct folio *__alloc_hugetlb_folio(struct vm_area_struct *vma,
}
}
- /*
- * Return subpool reservations to the subpool on error. A CoW mapping
- * might not have a reserve map, or it might already account for
- * another folio at this index.
- */
- if (map_chg != MAP_CHG_REUSE && vma_is_cow_mapping(vma))
- folio_clear_hugetlb_restore_reserve(folio);
-
return folio;
out_subpool_put:
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v2 05/35] mm/hugetlb: report reservations that we actually added from hugetlb_reserve_pages()
2026-12-03 11:37 [PATCH v2 00/35] mm/hugetlb: various fixes (2) David Hildenbrand (Arm)
` (2 preceding siblings ...)
2026-12-03 11:37 ` [PATCH v2 04/35] mm/hugetlb: return the reservation to the subpool on error David Hildenbrand (Arm)
@ 2026-12-03 11:37 ` David Hildenbrand (Arm)
2026-12-04 6:08 ` Muchun Song
2026-12-03 11:37 ` [PATCH v2 07/35] mm/hugetlb: always mark new page cache folios migratable David Hildenbrand (Arm)
` (14 subsequent siblings)
18 siblings, 1 reply; 22+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 11:37 UTC (permalink / raw)
To: Muchun Song, Oscar Salvador, Andrew Morton, Hongfu Li,
Jinmeng Zhou, Mina Almasry, Davidlohr Bueso, Naoya Horiguchi,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Michal Hocko,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Vivek Kasireddy,
Mel Gorman, Hugh Dickins, Baolin Wang, Dave Airlie,
Jason Gunthorpe, Andy Whitcroft, Roman Gushchin, Barry Song,
Andrea Arcangeli, Lorenzo Stoakes, Suren Baghdasaryan,
Shakeel Butt, Pedro Falcato, Jann Horn, Guillaume Morin, Yang Shi,
James Houghton, Rik van Riel, Harry Yoo, Lance Yang,
Axel Rasmussen, Peter Xu, Sasha Levin, Kiryl Shutsemau,
Christian Brauner, Steven Rostedt (Google), Hongbo Li,
Gregory Price, Zi Yan, Joshua Hahn, Rakie Kim, Ying Huang,
Matthew Brost, Byungchul Park, Alistair Popple, Andi Kleen,
David Rientjes, Joern Engel, Aneesh Kumar K.V
Cc: linux-mm, linux-doc, Gerd Hoffmann, linux-kernel, linux-fsdevel,
Johannes Weiner, Chris Mason, Jiaqi Yan, Sashiko, stable,
David Hildenbrand (Arm)
memfd_alloc_folio() uses hugetlb_reserve_pages() to reserve the index
of the folio it is about to allocate. If allocating the folio or adding
it to the page cache fails, it undoes that reservation, but only if
hugetlb_reserve_pages() reported that it actually performed the
reservation.
If the index was already reserved, for example through an mmap() of the
same file, memfd_alloc_folio() must not undo that reservation.
However, if hugetlb_reserve_pages() races with another reservation for
the same index, region_add_limited() can reserve fewer pages than
region_chg() counted. hugetlb_reserve_pages() will then hand back the
surplus charges, but still report the number of pages that region_chg()
counted.
Consequently, after racing with hugetlbfs_file_mmap() reserving the same
index, memfd_alloc_folio() will undo the reservation of the mmap() caller
on error, and a later fault at that index can fail with SIGBUS.
Reproduced by artificially delaying hugetlb_reserve_pages() after
region_chg() during IOMMU_IOAS_MAP_FILE of a hugetlb memfd, while another
process mmap()s the memfd, and failing the page cache insertion with
fault injection. Once all unreserved huge pages are in use, the mmap()
caller gets SIGBUS on fault.
Let's fix it by only reporting the reservations that we actually added.
Other callers are not affected, as they only care about error vs.
success, not the actual number of reserved pages.
This has low urgency, as it requires an allocation failure after racing
with an mmap() of the same file.
Fixes: 717cf9357325 ("mm/memfd: reserve hugetlb folios before allocation")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
mm/hugetlb.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 025aae6d0b72e..68d90c7297921 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -6907,9 +6907,9 @@ long hugetlb_change_protection(struct vm_area_struct *vma,
/*
* Update the reservation map for the range [from, to].
*
- * Returns the number of entries that would be added to the reservation map
- * associated with the range [from, to]. This number is greater or equal to
- * zero. -EINVAL or -ENOMEM is returned in case of any errors.
+ * Returns the number of huge pages that we reserved in the range [from, to],
+ * or a negative error code. On a later error, callers must only undo
+ * these reservations, not reservations that already existed in the range.
*/
long hugetlb_reserve_pages(struct inode *inode,
@@ -7052,6 +7052,11 @@ long hugetlb_reserve_pages(struct inode *inode,
rsv_adjust = hugepage_subpool_put_pages(spool,
chg - add);
hugetlb_acct_memory(h, -rsv_adjust);
+ /*
+ * Only report the reservations that we added, such that
+ * callers will not undo the racing reservations.
+ */
+ chg = add;
} else if (h_cg) {
/*
* The file_regions will hold their own reference to
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v2 07/35] mm/hugetlb: always mark new page cache folios migratable
2026-12-03 11:37 [PATCH v2 00/35] mm/hugetlb: various fixes (2) David Hildenbrand (Arm)
` (3 preceding siblings ...)
2026-12-03 11:37 ` [PATCH v2 05/35] mm/hugetlb: report reservations that we actually added from hugetlb_reserve_pages() David Hildenbrand (Arm)
@ 2026-12-03 11:37 ` David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 08/35] mm/memfd: mark new hugetlb " David Hildenbrand (Arm)
` (13 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 11:37 UTC (permalink / raw)
To: Muchun Song, Oscar Salvador, Andrew Morton, Hongfu Li,
Jinmeng Zhou, Mina Almasry, Davidlohr Bueso, Naoya Horiguchi,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Michal Hocko,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Vivek Kasireddy,
Mel Gorman, Hugh Dickins, Baolin Wang, Dave Airlie,
Jason Gunthorpe, Andy Whitcroft, Roman Gushchin, Barry Song,
Andrea Arcangeli, Lorenzo Stoakes, Suren Baghdasaryan,
Shakeel Butt, Pedro Falcato, Jann Horn, Guillaume Morin, Yang Shi,
James Houghton, Rik van Riel, Harry Yoo, Lance Yang,
Axel Rasmussen, Peter Xu, Sasha Levin, Kiryl Shutsemau,
Christian Brauner, Steven Rostedt (Google), Hongbo Li,
Gregory Price, Zi Yan, Joshua Hahn, Rakie Kim, Ying Huang,
Matthew Brost, Byungchul Park, Alistair Popple, Andi Kleen,
David Rientjes, Joern Engel, Aneesh Kumar K.V
Cc: linux-mm, linux-doc, Gerd Hoffmann, linux-kernel, linux-fsdevel,
Johannes Weiner, Chris Mason, Jiaqi Yan, stable,
David Hildenbrand (Arm)
hugetlb_no_page() and hugetlb_mfill_atomic_pte() only set
hugetlb_migratable for a new folio once they installed the PTE.
If they back out after adding the new folio to the page cache, for
example because the PTE changed or is no longer empty, the folio will
stay in the page cache without the migratable flag set.
Later faults will find it as an existing folio and never reset the flag.
Such a folio can never be isolated for migration, which breaks memory
offlining, alloc_contig_range(), longterm pinning and memory failure
handling.
Worse, if the folio is not longterm pinnable, because it resides in
ZONE_MOVABLE or CMA, memfd_pin_folios() and the longterm GUP path retry
forever on -EAGAIN. memfd_pin_folios() cannot even be killed, which will
be fixed independently.
Let's fix it by setting hugetlb folios migratable whenever (1) a new
anon folio gets mapped; or (2) a new folio was added to the page cache,
like hugetlbfs_fallocate() already does.
This has low urgency.
Fixes: cb6acd01e2e4 ("hugetlbfs: fix races and page leaks during migration")
Cc: stable@vger.kernel.org
Reviewed-by: Muchun Song (ByteDance) <muchun.song@linux.dev>
Acked-by: Oscar Salvador (SUSE) <osalvador@kernel.org>
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
mm/hugetlb.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index f64c3293fd109..662cb87fe740a 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -5972,12 +5972,11 @@ static vm_fault_t hugetlb_no_page(struct address_space *mapping,
{
const bool pagecache_folio = vmf->vma->vm_flags & VM_MAYSHARE;
u32 hash = hugetlb_fault_mutex_hash(mapping, vmf->pgoff);
- bool new_folio, new_anon_folio = false;
+ bool folio_locked = true, new_anon_folio = false;
struct vm_area_struct *vma = vmf->vma;
struct mm_struct *mm = vma->vm_mm;
struct hstate *h = hstate_vma(vma);
vm_fault_t ret = VM_FAULT_SIGBUS;
- bool folio_locked = true;
struct folio *folio;
pte_t new_pte;
@@ -5997,7 +5996,6 @@ static vm_fault_t hugetlb_no_page(struct address_space *mapping,
* Use page lock to guard against racing truncation
* before we get page_table_lock.
*/
- new_folio = false;
folio = filemap_lock_hugetlb_folio(h, mapping, vmf->pgoff);
if (IS_ERR(folio)) {
if (!hugetlb_pgoff_valid(mapping, vmf->pgoff, /* partial= */ false))
@@ -6067,7 +6065,6 @@ static vm_fault_t hugetlb_no_page(struct address_space *mapping,
}
folio_zero_user(folio, vmf->real_address);
__folio_mark_uptodate(folio);
- new_folio = true;
if (pagecache_folio) {
int err = hugetlb_add_to_page_cache(folio, mapping,
@@ -6088,6 +6085,7 @@ static vm_fault_t hugetlb_no_page(struct address_space *mapping,
goto out;
}
filemap_invalidate_unlock_shared(mapping);
+ folio_set_hugetlb_migratable(folio);
} else {
new_anon_folio = true;
folio_lock(folio);
@@ -6170,11 +6168,10 @@ static vm_fault_t hugetlb_no_page(struct address_space *mapping,
}
/*
- * Only set hugetlb_migratable in newly allocated pages. Existing pages
- * found in the pagecache may not have hugetlb_migratable if they have
- * been isolated for migration.
+ * We must set hugetlb folios migratable whenever (1) a new anon folio
+ * gets mapped; or (2) a new folio was added to the pagecache.
*/
- if (new_folio)
+ if (new_anon_folio)
folio_set_hugetlb_migratable(folio);
if (folio_locked)
@@ -6668,6 +6665,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte,
if (ret)
goto out_release_nounlock;
folio_in_pagecache = true;
+ folio_set_hugetlb_migratable(folio);
}
ptl = huge_pte_lock(h, dst_mm, dst_pte);
@@ -6716,7 +6714,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte,
/* No need to invalidate - it was non-present before */
update_mmu_cache(dst_vma, dst_addr, dst_pte);
- if (!is_continue)
+ if (!folio_in_pagecache)
folio_set_hugetlb_migratable(folio);
if (vm_shared || is_continue)
folio_unlock(folio);
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v2 08/35] mm/memfd: mark new hugetlb folios migratable
2026-12-03 11:37 [PATCH v2 00/35] mm/hugetlb: various fixes (2) David Hildenbrand (Arm)
` (4 preceding siblings ...)
2026-12-03 11:37 ` [PATCH v2 07/35] mm/hugetlb: always mark new page cache folios migratable David Hildenbrand (Arm)
@ 2026-12-03 11:37 ` David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 09/35] mm/hugetlb: free surplus folios of other nodes on free David Hildenbrand (Arm)
` (12 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 11:37 UTC (permalink / raw)
To: Muchun Song, Oscar Salvador, Andrew Morton, Hongfu Li,
Jinmeng Zhou, Mina Almasry, Davidlohr Bueso, Naoya Horiguchi,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Michal Hocko,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Vivek Kasireddy,
Mel Gorman, Hugh Dickins, Baolin Wang, Dave Airlie,
Jason Gunthorpe, Andy Whitcroft, Roman Gushchin, Barry Song,
Andrea Arcangeli, Lorenzo Stoakes, Suren Baghdasaryan,
Shakeel Butt, Pedro Falcato, Jann Horn, Guillaume Morin, Yang Shi,
James Houghton, Rik van Riel, Harry Yoo, Lance Yang,
Axel Rasmussen, Peter Xu, Sasha Levin, Kiryl Shutsemau,
Christian Brauner, Steven Rostedt (Google), Hongbo Li,
Gregory Price, Zi Yan, Joshua Hahn, Rakie Kim, Ying Huang,
Matthew Brost, Byungchul Park, Alistair Popple, Andi Kleen,
David Rientjes, Joern Engel, Aneesh Kumar K.V
Cc: linux-mm, linux-doc, Gerd Hoffmann, linux-kernel, linux-fsdevel,
Johannes Weiner, Chris Mason, Jiaqi Yan, stable,
David Hildenbrand (Arm)
memfd_alloc_folio() adds a new hugetlb folio to the page cache, but
never sets it migratable, unlike hugetlb_no_page() and
hugetlbfs_fallocate().
Later faults will find it as an existing folio and never set the
migratable flag.
Such a folio can never be isolated for migration, even once it is no
longer pinned, which breaks memory offlining, alloc_contig_range() and
memory failure handling.
Let's fix it by setting the new folio migratable after adding it to the
page cache, like hugetlbfs_fallocate() already does.
This has low urgency.
Fixes: 89c1905d9c14 ("mm/gup: introduce memfd_pin_folios() for pinning memfd folios")
Cc: stable@vger.kernel.org
Reviewed-by: Muchun Song (ByteDance) <muchun.song@linux.dev>
Reviewed-by: Oscar Salvador (SUSE) <osalvador@kernel.org>
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
mm/memfd.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/mm/memfd.c b/mm/memfd.c
index 0e02ca69d27cb..6340e8a7c4355 100644
--- a/mm/memfd.c
+++ b/mm/memfd.c
@@ -152,6 +152,7 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx)
}
hugetlb_set_folio_subpool(folio, subpool_inode(inode));
+ folio_set_hugetlb_migratable(folio);
folio_unlock(folio);
filemap_invalidate_unlock_shared(memfd->f_mapping);
mutex_unlock(&hugetlb_fault_mutex_table[hash]);
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v2 09/35] mm/hugetlb: free surplus folios of other nodes on free
2026-12-03 11:37 [PATCH v2 00/35] mm/hugetlb: various fixes (2) David Hildenbrand (Arm)
` (5 preceding siblings ...)
2026-12-03 11:37 ` [PATCH v2 08/35] mm/memfd: mark new hugetlb " David Hildenbrand (Arm)
@ 2026-12-03 11:37 ` David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 12/35] mm/hugetlb: fix truncated copy result in UFFDIO_COPY David Hildenbrand (Arm)
` (11 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 11:37 UTC (permalink / raw)
To: Muchun Song, Oscar Salvador, Andrew Morton, Hongfu Li,
Jinmeng Zhou, Mina Almasry, Davidlohr Bueso, Naoya Horiguchi,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Michal Hocko,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Vivek Kasireddy,
Mel Gorman, Hugh Dickins, Baolin Wang, Dave Airlie,
Jason Gunthorpe, Andy Whitcroft, Roman Gushchin, Barry Song,
Andrea Arcangeli, Lorenzo Stoakes, Suren Baghdasaryan,
Shakeel Butt, Pedro Falcato, Jann Horn, Guillaume Morin, Yang Shi,
James Houghton, Rik van Riel, Harry Yoo, Lance Yang,
Axel Rasmussen, Peter Xu, Sasha Levin, Kiryl Shutsemau,
Christian Brauner, Steven Rostedt (Google), Hongbo Li,
Gregory Price, Zi Yan, Joshua Hahn, Rakie Kim, Ying Huang,
Matthew Brost, Byungchul Park, Alistair Popple, Andi Kleen,
David Rientjes, Joern Engel, Aneesh Kumar K.V
Cc: linux-mm, linux-doc, Gerd Hoffmann, linux-kernel, linux-fsdevel,
Johannes Weiner, Chris Mason, Jiaqi Yan, stable,
David Hildenbrand (Arm)
Surplus hugetlb folios are accounted per node, but reservations are
global. When free_huge_folio() frees a hugetlb folio whose node doesn't
have any surplus folios, we currently keep it as a free hugetlb folio.
However, we might then have surplus folios on other nodes that are no
longer required for the global reservations.
This can be reproduced with two NUMA nodes, nr_hugepages=1 on node 0 and
nr_overcommit_hugepages=1:
(1) Allocate the single hugetlb folio on node 0 from the pool.
(2) With MPOL_BIND to node 1, mmap(MAP_SHARED) a hugetlb memfd that
needs a single folio. This will reserve + allocate a surplus folio
on node 1.
(3) Free the folio from (1).
(4) With MPOL_BIND to node 0, fault in the folio of the memfd, which
consumes the reservation and allocates node 0's free folio, and
immediately punch a hole, freeing the folio without restoring the
reservation. Node 0 has no surplus folios, so the folio is kept.
The pool ends up with a free surplus folio on node 1 that nobody
reserved:
HugePages_Total: 2
HugePages_Free: 2
HugePages_Rsvd: 0
HugePages_Surp: 1
Let's fix it by freeing a surplus folio of another node when
free_huge_folio() keeps a folio whose node has no surplus folios, using
the same rule as for the folio's own node: the free folios cover all
reservations without it.
With this fix, the surplus folio is already freed in (3), as the two
free folios then exceed the single reservation, and we correctly end up
with a single free folio on node 0 and no surplus folios.
Note that the freed surplus folio might have been required by a task
that was bound to that node. But we don't care about that: reservations
are inherently not NUMA aware, and anybody who needs guarantees on
specific nodes has to preallocate, like QEMU does, for example.
This has low urgency.
Fixes: 7893d1d505d5 ("hugetlb: Try to grow hugetlb pool for MAP_PRIVATE mappings")
Cc: stable@vger.kernel.org
Reported-by: Chris Mason <mason@kernel.org>
Tested-by: Hongfu Li <lihongfu@kylinos.cn>
Reviewed-by: Hongfu Li <lihongfu@kylinos.cn>
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
mm/hugetlb.c | 31 +++++++++++++++++++++++++------
1 file changed, 25 insertions(+), 6 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 662cb87fe740a..5984377160d37 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -142,6 +142,8 @@ static void hugetlb_unmap_range(struct mmu_gather *tlb,
unsigned long end, struct folio *folio,
zap_flags_t zap_flags);
static struct resv_map *vma_resv_map(struct vm_area_struct *vma);
+static struct folio *remove_pool_hugetlb_folio(struct hstate *h,
+ nodemask_t *nodes_allowed, bool acct_surplus);
static inline bool subpool_is_free(struct hugepage_subpool *spool)
{
@@ -1767,6 +1769,7 @@ void free_huge_folio(struct folio *folio)
struct hstate *h = folio_hstate(folio);
int nid = folio_nid(folio);
struct hugepage_subpool *spool = hugetlb_folio_subpool(folio);
+ struct folio *surplus_folio = NULL;
bool restore_reserve;
unsigned long flags;
@@ -1815,19 +1818,35 @@ void free_huge_folio(struct folio *folio)
folio_clear_hugetlb_temporary(folio);
spin_unlock_irqrestore(&hugetlb_lock, flags);
update_and_free_hugetlb_folio(h, folio, true);
+ return;
} else if (h->surplus_huge_pages_node[nid] &&
h->free_huge_pages >= h->resv_huge_pages) {
/* Free this surplus folio that is not required globally. */
remove_hugetlb_folio(h, folio, true);
spin_unlock_irqrestore(&hugetlb_lock, flags);
update_and_free_hugetlb_folio(h, folio, true);
- } else {
- mod_node_page_state(folio_pgdat(folio), NR_HUGETLB,
- -(long)pages_per_huge_page(h));
- arch_clear_hugetlb_flags(folio);
- enqueue_hugetlb_folio(h, folio);
- spin_unlock_irqrestore(&hugetlb_lock, flags);
+ return;
}
+
+ mod_node_page_state(folio_pgdat(folio), NR_HUGETLB,
+ -(long)pages_per_huge_page(h));
+ arch_clear_hugetlb_flags(folio);
+ enqueue_hugetlb_folio(h, folio);
+
+ /*
+ * This is not a surplus folio on this node, but we might have surplus
+ * folios on other nodes that are no longer required, as reservations
+ * are global and surplus folios are per node. So free another folio
+ * instead.
+ */
+ if (h->surplus_huge_pages &&
+ h->free_huge_pages > h->resv_huge_pages)
+ surplus_folio = remove_pool_hugetlb_folio(h, &node_states[N_MEMORY],
+ /* acct_surplus= */ true);
+ spin_unlock_irqrestore(&hugetlb_lock, flags);
+ /* We might be in atomic context, but freeing might need vmemmap pages. */
+ if (surplus_folio)
+ update_and_free_hugetlb_folio(h, surplus_folio, true);
}
/*
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v2 12/35] mm/hugetlb: fix truncated copy result in UFFDIO_COPY
2026-12-03 11:37 [PATCH v2 00/35] mm/hugetlb: various fixes (2) David Hildenbrand (Arm)
` (6 preceding siblings ...)
2026-12-03 11:37 ` [PATCH v2 09/35] mm/hugetlb: free surplus folios of other nodes on free David Hildenbrand (Arm)
@ 2026-12-03 11:37 ` David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 13/35] fs/proc/task_mmu: don't clear VM_SOFTDIRTY on hugetlb VMAs David Hildenbrand (Arm)
` (10 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 11:37 UTC (permalink / raw)
To: Muchun Song, Oscar Salvador, Andrew Morton, Hongfu Li,
Jinmeng Zhou, Mina Almasry, Davidlohr Bueso, Naoya Horiguchi,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Michal Hocko,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Vivek Kasireddy,
Mel Gorman, Hugh Dickins, Baolin Wang, Dave Airlie,
Jason Gunthorpe, Andy Whitcroft, Roman Gushchin, Barry Song,
Andrea Arcangeli, Lorenzo Stoakes, Suren Baghdasaryan,
Shakeel Butt, Pedro Falcato, Jann Horn, Guillaume Morin, Yang Shi,
James Houghton, Rik van Riel, Harry Yoo, Lance Yang,
Axel Rasmussen, Peter Xu, Sasha Levin, Kiryl Shutsemau,
Christian Brauner, Steven Rostedt (Google), Hongbo Li,
Gregory Price, Zi Yan, Joshua Hahn, Rakie Kim, Ying Huang,
Matthew Brost, Byungchul Park, Alistair Popple, Andi Kleen,
David Rientjes, Joern Engel, Aneesh Kumar K.V
Cc: linux-mm, linux-doc, Gerd Hoffmann, linux-kernel, linux-fsdevel,
Johannes Weiner, Chris Mason, Jiaqi Yan, stable,
David Hildenbrand (Arm)
From: Chris Mason <mason@kernel.org>
Folios that span more bytes than can fit into an unsigned integer (e.g.,
16 GiB folios on arm64) are problematic with UFFDIO_COPY: the result
from copy_folio_from_user() can be truncated, possibly indicating
success instead of an error.
We will then continue with the folio that has stale data, and make it
accessible to user space.
For example, if copy_folio_from_user() fails such that the number of
bytes not copied is a multiple of 4 GiB, we'll get an effective ret ==
0.
Let's fix it by simply testing the return value directly.
This has medium urgency, as it's an information leak.
Fixes: 8fb5debc5fcd ("userfaultfd: hugetlbfs: add hugetlb_mcopy_atomic_pte for userfaultfd support")
Cc: stable@vger.kernel.org
Signed-off-by: Chris Mason <mason@kernel.org>
[ david: cleanup code and description ]
Reviewed-by: Muchun Song (ByteDance) <muchun.song@linux.dev>
Reviewed-by: Oscar Salvador (SUSE) <osalvador@kernel.org>
Reviewed-by: Hongfu Li <lihongfu@kylinos.cn>
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
mm/hugetlb.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index d7ced61b4d2d4..0d242ebfb07d2 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -6606,11 +6606,8 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte,
goto out;
}
- ret = copy_folio_from_user(folio, (const void __user *) src_addr,
- false);
-
/* fallback to copy_from_user outside mmap_lock */
- if (unlikely(ret)) {
+ if (unlikely(copy_folio_from_user(folio, (const void __user *)src_addr, false))) {
ret = -ENOENT;
/* Free the allocated folio which may have
* consumed a reservation.
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v2 13/35] fs/proc/task_mmu: don't clear VM_SOFTDIRTY on hugetlb VMAs
2026-12-03 11:37 [PATCH v2 00/35] mm/hugetlb: various fixes (2) David Hildenbrand (Arm)
` (7 preceding siblings ...)
2026-12-03 11:37 ` [PATCH v2 12/35] mm/hugetlb: fix truncated copy result in UFFDIO_COPY David Hildenbrand (Arm)
@ 2026-12-03 11:37 ` David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 15/35] hugetlbfs: don't zero poisoned pages in a hole punch David Hildenbrand (Arm)
` (9 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 11:37 UTC (permalink / raw)
To: Muchun Song, Oscar Salvador, Andrew Morton, Hongfu Li,
Jinmeng Zhou, Mina Almasry, Davidlohr Bueso, Naoya Horiguchi,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Michal Hocko,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Vivek Kasireddy,
Mel Gorman, Hugh Dickins, Baolin Wang, Dave Airlie,
Jason Gunthorpe, Andy Whitcroft, Roman Gushchin, Barry Song,
Andrea Arcangeli, Lorenzo Stoakes, Suren Baghdasaryan,
Shakeel Butt, Pedro Falcato, Jann Horn, Guillaume Morin, Yang Shi,
James Houghton, Rik van Riel, Harry Yoo, Lance Yang,
Axel Rasmussen, Peter Xu, Sasha Levin, Kiryl Shutsemau,
Christian Brauner, Steven Rostedt (Google), Hongbo Li,
Gregory Price, Zi Yan, Joshua Hahn, Rakie Kim, Ying Huang,
Matthew Brost, Byungchul Park, Alistair Popple, Andi Kleen,
David Rientjes, Joern Engel, Aneesh Kumar K.V
Cc: linux-mm, linux-doc, Gerd Hoffmann, linux-kernel, linux-fsdevel,
Johannes Weiner, Chris Mason, Jiaqi Yan, stable,
David Hildenbrand (Arm)
hugetlb does not support soft-dirty tracking: since commit f96f7a40874d
("mm/hugetlb: fix hugetlb not supporting softdirty tracking"),
vma_wants_writenotify() ignores VM_SOFTDIRTY for hugetlb VMAs, and
clear_refs never clears the soft-dirty bits of hugetlb entries.
However, clear_refs still clears VM_SOFTDIRTY on hugetlb VMAs. With
CONFIG_MEM_SOFT_DIRTY, a FOLL_FORCE write to a private hugetlb mapping
without VM_WRITE can then loop in __get_user_pages() until the task is
killed, with the mmap_lock held for reading:
__get_user_pages()
retry:
follow_page_mask()
follow_huge_pmd()
can_follow_write_pmd()
pmd_needs_soft_dirty_wp() is true
returns NULL
faultin_page()
hugetlb_wp()
set_huge_ptep_maybe_writable()
no VM_WRITE: the entry stays as it is
returns 0
goto retry
Let's fix it by not clearing VM_SOFTDIRTY on hugetlb VMAs, so we always
treat hugetlb pages as soft-dirty.
This has low urgency, as the loop can be killed.
Fixes: 052ccfbcc6cd ("mm/hugetlb: support FOLL_FORCE|FOLL_WRITE")
Cc: stable@vger.kernel.org
Reported-by: Chris Mason <mason@kernel.org>
Reviewed-by: Muchun Song (ByteDance) <muchun.song@linux.dev>
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
fs/proc/task_mmu.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index d2a524c6ad4b9..de8eded04e32a 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -1802,6 +1802,9 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
if (type == CLEAR_REFS_SOFT_DIRTY) {
for_each_vma(vmi, vma) {
+ /* hugetlb does not support soft-dirty tracking. */
+ if (vma_is_hugetlb(vma))
+ continue;
if (!(vma->vm_flags & VM_SOFTDIRTY))
continue;
vm_flags_clear(vma, VM_SOFTDIRTY);
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v2 15/35] hugetlbfs: don't zero poisoned pages in a hole punch
2026-12-03 11:37 [PATCH v2 00/35] mm/hugetlb: various fixes (2) David Hildenbrand (Arm)
` (8 preceding siblings ...)
2026-12-03 11:37 ` [PATCH v2 13/35] fs/proc/task_mmu: don't clear VM_SOFTDIRTY on hugetlb VMAs David Hildenbrand (Arm)
@ 2026-12-03 11:37 ` David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 16/35] hugetlbfs: fix deadlock between hole punching and memory failure David Hildenbrand (Arm)
` (8 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 11:37 UTC (permalink / raw)
To: Muchun Song, Oscar Salvador, Andrew Morton, Hongfu Li,
Jinmeng Zhou, Mina Almasry, Davidlohr Bueso, Naoya Horiguchi,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Michal Hocko,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Vivek Kasireddy,
Mel Gorman, Hugh Dickins, Baolin Wang, Dave Airlie,
Jason Gunthorpe, Andy Whitcroft, Roman Gushchin, Barry Song,
Andrea Arcangeli, Lorenzo Stoakes, Suren Baghdasaryan,
Shakeel Butt, Pedro Falcato, Jann Horn, Guillaume Morin, Yang Shi,
James Houghton, Rik van Riel, Harry Yoo, Lance Yang,
Axel Rasmussen, Peter Xu, Sasha Levin, Kiryl Shutsemau,
Christian Brauner, Steven Rostedt (Google), Hongbo Li,
Gregory Price, Zi Yan, Joshua Hahn, Rakie Kim, Ying Huang,
Matthew Brost, Byungchul Park, Alistair Popple, Andi Kleen,
David Rientjes, Joern Engel, Aneesh Kumar K.V
Cc: linux-mm, linux-doc, Gerd Hoffmann, linux-kernel, linux-fsdevel,
Johannes Weiner, Chris Mason, Jiaqi Yan, stable,
David Hildenbrand (Arm)
Since commit 8625147cafaa ("hugetlbfs: don't delete error page from
pagecache"), a poisoned hugetlb folio stays in the page cache, and we
must not access its poisoned pages.
However, hugetlbfs_zero_partial_page() zeroes the partial folio of an
unaligned hole punch without checking for poison, which can cause
issues like machine-checks.
Let's fix it by simply not zeroing poisoned folios. We don't really care
about their content: the folio can no longer be mapped, and read() only
returns data up to the first poisoned page.
Only zeroing the pages that are not poisoned would need more thought, as
we cannot reliably identify the poisoned pages; that is future work.
Note that a folio that gets poisoned concurrently, after we checked it,
can still be zeroed, and sync'ing with memory failure handling is also
left as future work.
This has low urgency, as it requires a hole punch on a poisoned folio.
Fixes: 8625147cafaa ("hugetlbfs: don't delete error page from pagecache")
Cc: stable@vger.kernel.org
Reported-by: Chris Mason <mason@kernel.org>
Reviewed-by: Jiaqi Yan <jiaqiyan@google.com>
Reviewed-by: Muchun Song (ByteDance) <muchun.song@linux.dev>
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
fs/hugetlbfs/inode.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 8ac8925d7ad8b..dd0cc0384a181 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -656,7 +656,8 @@ static void hugetlbfs_zero_partial_page(struct hstate *h,
if (!end)
end = huge_page_size(h);
- folio_zero_segment(folio, (size_t)start, (size_t)end);
+ if (!folio_test_hwpoison(folio))
+ folio_zero_segment(folio, (size_t)start, (size_t)end);
folio_unlock(folio);
folio_put(folio);
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v2 16/35] hugetlbfs: fix deadlock between hole punching and memory failure
2026-12-03 11:37 [PATCH v2 00/35] mm/hugetlb: various fixes (2) David Hildenbrand (Arm)
` (9 preceding siblings ...)
2026-12-03 11:37 ` [PATCH v2 15/35] hugetlbfs: don't zero poisoned pages in a hole punch David Hildenbrand (Arm)
@ 2026-12-03 11:37 ` David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 19/35] hugetlbfs: recheck the vma range after the lock wait David Hildenbrand (Arm)
` (7 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 11:37 UTC (permalink / raw)
To: Muchun Song, Oscar Salvador, Andrew Morton, Hongfu Li,
Jinmeng Zhou, Mina Almasry, Davidlohr Bueso, Naoya Horiguchi,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Michal Hocko,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Vivek Kasireddy,
Mel Gorman, Hugh Dickins, Baolin Wang, Dave Airlie,
Jason Gunthorpe, Andy Whitcroft, Roman Gushchin, Barry Song,
Andrea Arcangeli, Lorenzo Stoakes, Suren Baghdasaryan,
Shakeel Butt, Pedro Falcato, Jann Horn, Guillaume Morin, Yang Shi,
James Houghton, Rik van Riel, Harry Yoo, Lance Yang,
Axel Rasmussen, Peter Xu, Sasha Levin, Kiryl Shutsemau,
Christian Brauner, Steven Rostedt (Google), Hongbo Li,
Gregory Price, Zi Yan, Joshua Hahn, Rakie Kim, Ying Huang,
Matthew Brost, Byungchul Park, Alistair Popple, Andi Kleen,
David Rientjes, Joern Engel, Aneesh Kumar K.V
Cc: linux-mm, linux-doc, Gerd Hoffmann, linux-kernel, linux-fsdevel,
Johannes Weiner, Chris Mason, Jiaqi Yan, stable,
David Hildenbrand (Arm)
From: Chris Mason <mason@kernel.org>
Punching a hole that isn't aligned to the huge page size can deadlock
against memory_failure() on a mapped folio at the edge of the hole.
hugetlbfs_punch_hole() locks and zeroes the partial folios with
i_mmap_rwsem held for write, following the hugetlbfs locking order
documented in mm/rmap.c: i_mmap_rwsem before the folio lock.
However, try_memory_failure_hugetlb() locks the folio first, and then
collects the processes to kill under i_mmap_rwsem:
hugetlbfs_punch_hole() try_memory_failure_hugetlb()
====================== ============================
i_mmap_lock_write()
folio_lock()
hugetlbfs_zero_partial_page() hwpoison_user_mappings()
filemap_lock_hugetlb_folio() collect_procs_file()
waits for the folio lock i_mmap_lock_read()
waits for the writer
In fact, the documentation is outdated: hugetlbfs_punch_hole() is the
*only* one that still takes i_mmap_rwsem before the folio lock. All
other scenarios always take the folio lock before the i_mmap_rwsem.
Only memory failure can deadlock with the hole punch:
* truncation and hole punching of full folios are serialized against it
through the inode lock
* unmap_ref_private() holds the lock of an anon folio, not of a page
cache folio that the hole punch zeroes
* migration only tries to take the i_mmap_rwsem.
There is no need to zero the partial folios under i_mmap_rwsem. The lock
only protects the VMA tree and PMD table sharing, nothing about zeroing;
the inode lock and the folio lock are sufficient.
Let's fix it by only holding i_mmap_rwsem while unmapping the full
folios of the hole.
Update the documented locking order in mm/rmap.c and the function
comment above hugetlb_folio_mapping_lock_write().
hugetlb_folio_mapping_lock_write() could now take the lock
unconditionally, but we leave that for a separate change.
The order of the folio lock and i_mmap_rwsem now matches the one for
other folios, which is nice.
This has low urgency, as the race shouldn't really happen all that often
in practice (never seen).
Fixes: 68d32527d340 ("hugetlbfs: zero partial pages during fallocate hole punch")
Cc: <stable@vger.kernel.org>
Signed-off-by: Chris Mason <mason@kernel.org>
[ david: adjust comment and description ]
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
fs/hugetlbfs/inode.c | 6 ++----
mm/hugetlb.c | 3 +--
mm/rmap.c | 4 ++--
3 files changed, 5 insertions(+), 8 deletions(-)
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index dd0cc0384a181..4290e88f23c5b 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -689,8 +689,6 @@ static long hugetlbfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
return -EPERM;
}
- i_mmap_lock_write(mapping);
-
/* If range starts before first full page, zero partial page. */
if (offset < hole_start)
hugetlbfs_zero_partial_page(h, mapping,
@@ -698,10 +696,12 @@ static long hugetlbfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
/* Unmap users of full pages in the hole. */
if (hole_end > hole_start) {
+ i_mmap_lock_write(mapping);
if (mapping_mapped(mapping))
hugetlb_vmdelete_list(mapping,
hole_start >> PAGE_SHIFT,
hole_end >> PAGE_SHIFT, 0);
+ i_mmap_unlock_write(mapping);
}
/* If range extends beyond last full page, zero partial page. */
@@ -709,8 +709,6 @@ static long hugetlbfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
hugetlbfs_zero_partial_page(h, mapping,
hole_end, offset + len);
- i_mmap_unlock_write(mapping);
-
/* Remove full pages from the file. */
if (hole_end > hole_start)
remove_inode_hugepages(inode, hole_start, hole_end);
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 0d242ebfb07d2..72d912f488fdc 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1878,8 +1878,7 @@ void init_new_hugetlb_folio(struct folio *folio)
* Find and lock address space (mapping) in write mode.
*
* Upon entry, the folio is locked which means that folio_mapping() is
- * stable. Due to locking order, we can only trylock_write. If we can
- * not get the lock, simply return NULL to caller.
+ * stable. If we cannot get the lock immediately, we simply return NULL.
*/
struct address_space *hugetlb_folio_mapping_lock_write(struct folio *folio)
{
diff --git a/mm/rmap.c b/mm/rmap.c
index fe354fa6cc43a..f35b671d26514 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -49,8 +49,8 @@
* hugetlb_fault_mutex (hugetlbfs specific page fault mutex)
* vma_lock (hugetlb specific lock for pmd_sharing)
* mapping->invalidate_lock (when allocating page cache folios)
- * mapping->i_mmap_rwsem (also used for hugetlb pmd sharing)
- * folio_lock
+ * folio_lock
+ * mapping->i_mmap_rwsem (also used for hugetlb pmd sharing)
*/
#include <linux/mm.h>
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v2 19/35] hugetlbfs: recheck the vma range after the lock wait
2026-12-03 11:37 [PATCH v2 00/35] mm/hugetlb: various fixes (2) David Hildenbrand (Arm)
` (10 preceding siblings ...)
2026-12-03 11:37 ` [PATCH v2 16/35] hugetlbfs: fix deadlock between hole punching and memory failure David Hildenbrand (Arm)
@ 2026-12-03 11:37 ` David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 21/35] hugetlbfs: don't skip private VMAs when unmapping on truncation David Hildenbrand (Arm)
` (6 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 11:37 UTC (permalink / raw)
To: Muchun Song, Oscar Salvador, Andrew Morton, Hongfu Li,
Jinmeng Zhou, Mina Almasry, Davidlohr Bueso, Naoya Horiguchi,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Michal Hocko,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Vivek Kasireddy,
Mel Gorman, Hugh Dickins, Baolin Wang, Dave Airlie,
Jason Gunthorpe, Andy Whitcroft, Roman Gushchin, Barry Song,
Andrea Arcangeli, Lorenzo Stoakes, Suren Baghdasaryan,
Shakeel Butt, Pedro Falcato, Jann Horn, Guillaume Morin, Yang Shi,
James Houghton, Rik van Riel, Harry Yoo, Lance Yang,
Axel Rasmussen, Peter Xu, Sasha Levin, Kiryl Shutsemau,
Christian Brauner, Steven Rostedt (Google), Hongbo Li,
Gregory Price, Zi Yan, Joshua Hahn, Rakie Kim, Ying Huang,
Matthew Brost, Byungchul Park, Alistair Popple, Andi Kleen,
David Rientjes, Joern Engel, Aneesh Kumar K.V
Cc: linux-mm, linux-doc, Gerd Hoffmann, linux-kernel, linux-fsdevel,
Johannes Weiner, Chris Mason, Jiaqi Yan, stable,
David Hildenbrand (Arm)
From: Chris Mason <mason@kernel.org>
A hole punch or a truncation of a hugetlb file that races with a split
of a shared vma can lead to a use-after-free read of a page table, and
to an MMU notifier range with end <= start, which trips a WARN_ON_ONCE()
in KVM.
hugetlb_unmap_file_folio() computes the address of the folio in a vma
and walks the page tables to unmap the folio. As free_pgtables() unlinks
a vma from the rmap tree before it frees its page tables, i_mmap_rwsem
does not protect page tables outside of the vma, so walking them can
result in a use-after-free read.
The rmap tree walk guarantees that a found vma spans our folio. However,
when we have to fall back to locking the vma lock first and drop the
i_mmap_rwsem, we don't check whether that is still the case after we
acquired the vma lock and the i_mmap_rwsem. The following is then
possible:
hugetlb_unmap_file_folio() __split_vma(), new_below == 0
========================== =============================
hugetlb_vma_trylock_write() fails
i_mmap_unlock_write()
down_write(&vma_lock->rw_sema)
vma_prepare()
i_mmap_lock_write()
vma->vm_end = addr
vma_complete()
i_mmap_unlock_write()
i_mmap_lock_write()
vma_lock->vma is not NULL
vma_offset_start() >= vma->vm_end
vma_offset_end() == vma->vm_end
hugetlb_vma_maps_pfn(vma, v_start)
unmap_hugepage_range(vma, v_start, v_end)
Similarly, a split with new_below == 1, where the vma keeps the upper
part and vm_start and vm_pgoff move up, or shrinking the vma with
mremap() can leave the vma not covering our folio.
Let's fix it by checking whether the possibly split vma still spans our
folio. Add a VM_WARN_ON_ONCE() to highlight the problem that was
previously missed.
This has medium urgency, as this is triggerable by unprivileged users.
Fixes: 40549ba8f8e0 ("hugetlb: use new vma_lock for pmd sharing synchronization")
Cc: <stable@vger.kernel.org>
Signed-off-by: Chris Mason <mason@kernel.org>
[ david: adjust comment and description ]
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
fs/hugetlbfs/inode.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 9b2c61339f830..db2af960ee7dc 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -439,10 +439,11 @@ static void hugetlb_unmap_file_folio(struct hstate *h,
i_mmap_lock_write(mapping);
vma = vma_lock->vma;
- if (!vma) {
+ if (!vma || vma_start_pgoff(vma) >= end || vma_end_pgoff(vma) <= start) {
/*
- * If lock is no longer attached to vma, then just
- * unlock, drop our reference and retry looking for
+ * If the lock is no longer attached to this vma, or if
+ * the vma changed and no longer covers the folio, then
+ * just unlock, drop our reference and retry looking for
* other vmas.
*/
up_write(&vma_lock->rw_sema);
@@ -456,6 +457,7 @@ static void hugetlb_unmap_file_folio(struct hstate *h,
*/
v_start = vma_offset_start(vma, start);
v_end = vma_offset_end(vma, end);
+ VM_WARN_ON_ONCE(v_start >= v_end);
if (hugetlb_vma_maps_pfn(vma, v_start, pfn))
unmap_hugepage_range(vma, v_start, v_end, NULL,
ZAP_FLAG_DROP_MARKER);
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v2 21/35] hugetlbfs: don't skip private VMAs when unmapping on truncation
2026-12-03 11:37 [PATCH v2 00/35] mm/hugetlb: various fixes (2) David Hildenbrand (Arm)
` (11 preceding siblings ...)
2026-12-03 11:37 ` [PATCH v2 19/35] hugetlbfs: recheck the vma range after the lock wait David Hildenbrand (Arm)
@ 2026-12-03 11:37 ` David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 26/35] mm/rmap: don't fail unmapping hugetlb folios from private VMAs David Hildenbrand (Arm)
` (5 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 11:37 UTC (permalink / raw)
To: Muchun Song, Oscar Salvador, Andrew Morton, Hongfu Li,
Jinmeng Zhou, Mina Almasry, Davidlohr Bueso, Naoya Horiguchi,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Michal Hocko,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Vivek Kasireddy,
Mel Gorman, Hugh Dickins, Baolin Wang, Dave Airlie,
Jason Gunthorpe, Andy Whitcroft, Roman Gushchin, Barry Song,
Andrea Arcangeli, Lorenzo Stoakes, Suren Baghdasaryan,
Shakeel Butt, Pedro Falcato, Jann Horn, Guillaume Morin, Yang Shi,
James Houghton, Rik van Riel, Harry Yoo, Lance Yang,
Axel Rasmussen, Peter Xu, Sasha Levin, Kiryl Shutsemau,
Christian Brauner, Steven Rostedt (Google), Hongbo Li,
Gregory Price, Zi Yan, Joshua Hahn, Rakie Kim, Ying Huang,
Matthew Brost, Byungchul Park, Alistair Popple, Andi Kleen,
David Rientjes, Joern Engel, Aneesh Kumar K.V
Cc: linux-mm, linux-doc, Gerd Hoffmann, linux-kernel, linux-fsdevel,
Johannes Weiner, Chris Mason, Jiaqi Yan, Sashiko, stable,
David Hildenbrand (Arm)
When truncating a file or punching a hole, hugetlb_vmdelete_list() unmaps
the range from all VMAs that map the file. It skips VMAs whose VMA lock it
cannot trylock, which is fine for shared VMAs: remove_inode_hugepages()
unmaps their page cache folios later.
However, private VMAs that own their reservations have a VMA lock as
well, so, for example, a concurrent page fault or MADV_DONTNEED in such a
VMA makes us skip that VMA, and nobody unmaps its anonymous folios or, on
truncation, its uffd-wp markers later.
Consequently, they stay mapped beyond EOF after a truncation, or inside a
punched hole.
We only need the VMA lock here for PMD table sharing, which synchronizes
on the shareable lock. We already hold the i_mmap lock in write mode.
Let's fix it like commit da48afefa78d ("hugetlbfs: fix unmapping folios
from private VMAs") did for hugetlb_unmap_file_folio(): only take the VMA
lock for VMAs with a shareable lock, and always unmap other VMAs only
under i_mmap lock.
This has low urgency, as it requires racing with e.g., a page
fault in the private VMA.
Fixes: bf4916922c60 ("hugetlbfs: extend hugetlb_vma_lock to private VMAs")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
fs/hugetlbfs/inode.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index db2af960ee7dc..5f44236785b5a 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -482,10 +482,16 @@ hugetlb_vmdelete_list(struct address_space *mapping, pgoff_t start,
*/
mapping_rmap_tree_foreach(vma, mapping, start,
end ? end - 1 : ULONG_MAX) {
+ const bool need_vma_lock = __vma_shareable_lock(vma);
unsigned long v_start;
unsigned long v_end;
- if (!hugetlb_vma_trylock_write(vma))
+ /*
+ * We only need additional VMA locking here for PMD table
+ * sharing, which synchronizes on the shareable lock. Other VMAs
+ * never share PMD tables, so we can unmap them without it.
+ */
+ if (need_vma_lock && !hugetlb_vma_trylock_write(vma))
continue;
v_start = vma_offset_start(vma, start);
@@ -493,12 +499,8 @@ hugetlb_vmdelete_list(struct address_space *mapping, pgoff_t start,
unmap_hugepage_range(vma, v_start, v_end, NULL, zap_flags);
- /*
- * Note that vma lock only exists for shared/non-private
- * vmas. Therefore, lock is not held when calling
- * unmap_hugepage_range for private vmas.
- */
- hugetlb_vma_unlock_write(vma);
+ if (need_vma_lock)
+ hugetlb_vma_unlock_write(vma);
}
}
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v2 26/35] mm/rmap: don't fail unmapping hugetlb folios from private VMAs
2026-12-03 11:37 [PATCH v2 00/35] mm/hugetlb: various fixes (2) David Hildenbrand (Arm)
` (12 preceding siblings ...)
2026-12-03 11:37 ` [PATCH v2 21/35] hugetlbfs: don't skip private VMAs when unmapping on truncation David Hildenbrand (Arm)
@ 2026-12-03 11:37 ` David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 27/35] mm/hugetlb: only check PMD table sharing for PMD-sized folios David Hildenbrand (Arm)
` (4 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 11:37 UTC (permalink / raw)
To: Muchun Song, Oscar Salvador, Andrew Morton, Hongfu Li,
Jinmeng Zhou, Mina Almasry, Davidlohr Bueso, Naoya Horiguchi,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Michal Hocko,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Vivek Kasireddy,
Mel Gorman, Hugh Dickins, Baolin Wang, Dave Airlie,
Jason Gunthorpe, Andy Whitcroft, Roman Gushchin, Barry Song,
Andrea Arcangeli, Lorenzo Stoakes, Suren Baghdasaryan,
Shakeel Butt, Pedro Falcato, Jann Horn, Guillaume Morin, Yang Shi,
James Houghton, Rik van Riel, Harry Yoo, Lance Yang,
Axel Rasmussen, Peter Xu, Sasha Levin, Kiryl Shutsemau,
Christian Brauner, Steven Rostedt (Google), Hongbo Li,
Gregory Price, Zi Yan, Joshua Hahn, Rakie Kim, Ying Huang,
Matthew Brost, Byungchul Park, Alistair Popple, Andi Kleen,
David Rientjes, Joern Engel, Aneesh Kumar K.V
Cc: linux-mm, linux-doc, Gerd Hoffmann, linux-kernel, linux-fsdevel,
Johannes Weiner, Chris Mason, Jiaqi Yan, stable,
David Hildenbrand (Arm)
Before unmapping a hugetlb page cache folio, try_to_migrate_one() and
try_to_unmap_poisoned_hugetlb_one() try to unshare the PMD table, which
requires the hugetlb VMA lock in write mode.
As we already hold the i_mmap_rwsem, we can only trylock it, and give up
if that fails.
Since private hugetlb VMAs have a VMA lock as well, the trylock can also
fail on private VMAs, for example while another thread is faulting in
that VMA. PMD table sharing does not apply in private VMAs, so there is
nothing to unshare and we fail for no reason: migration fails more
often, and memory failure might leave a poisoned folio mapped.
Let's fix it by only taking the VMA lock and trying to unshare if PMD
tables can be shared.
Fortunately, we can drop the anon folio checks now.
This has low urgency, as it requires racing with, for example, a page
fault in the private VMA, and migration is usually retried.
Fixes: bf4916922c60 ("hugetlbfs: extend hugetlb_vma_lock to private VMAs")
Cc: stable@vger.kernel.org
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
mm/rmap.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/mm/rmap.c b/mm/rmap.c
index 4193793158bc1..b85ab855a438a 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -2049,7 +2049,7 @@ static bool try_to_unmap_poisoned_hugetlb_one(struct folio *folio,
* acquiring vma_lock BEFORE i_mmap_rwsem. We can only try lock here and
* fail if unsuccessful.
*/
- if (!folio_test_anon(folio)) {
+ if (__vma_shareable_lock(vma)) {
struct mmu_gather tlb;
VM_WARN_ON_ONCE(!(flags & TTU_RMAP_LOCKED));
@@ -2580,8 +2580,6 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma,
PageAnonExclusive(subpage);
if (folio_test_hugetlb(folio)) {
- bool anon = folio_test_anon(folio);
-
/*
* huge_pmd_unshare may unmap an entire PMD page.
* There is no way of knowing exactly which PMDs may
@@ -2601,7 +2599,7 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma,
* i_mmap_rwsem. We can only try lock here and
* fail if unsuccessful.
*/
- if (!anon) {
+ if (__vma_shareable_lock(vma)) {
struct mmu_gather tlb;
VM_BUG_ON(!(flags & TTU_RMAP_LOCKED));
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v2 27/35] mm/hugetlb: only check PMD table sharing for PMD-sized folios
2026-12-03 11:37 [PATCH v2 00/35] mm/hugetlb: various fixes (2) David Hildenbrand (Arm)
` (13 preceding siblings ...)
2026-12-03 11:37 ` [PATCH v2 26/35] mm/rmap: don't fail unmapping hugetlb folios from private VMAs David Hildenbrand (Arm)
@ 2026-12-03 11:37 ` David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 28/35] mm/migrate: check hugetlb PMD sharing in move_pages() David Hildenbrand (Arm)
` (3 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 11:37 UTC (permalink / raw)
To: Muchun Song, Oscar Salvador, Andrew Morton, Hongfu Li,
Jinmeng Zhou, Mina Almasry, Davidlohr Bueso, Naoya Horiguchi,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Michal Hocko,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Vivek Kasireddy,
Mel Gorman, Hugh Dickins, Baolin Wang, Dave Airlie,
Jason Gunthorpe, Andy Whitcroft, Roman Gushchin, Barry Song,
Andrea Arcangeli, Lorenzo Stoakes, Suren Baghdasaryan,
Shakeel Butt, Pedro Falcato, Jann Horn, Guillaume Morin, Yang Shi,
James Houghton, Rik van Riel, Harry Yoo, Lance Yang,
Axel Rasmussen, Peter Xu, Sasha Levin, Kiryl Shutsemau,
Christian Brauner, Steven Rostedt (Google), Hongbo Li,
Gregory Price, Zi Yan, Joshua Hahn, Rakie Kim, Ying Huang,
Matthew Brost, Byungchul Park, Alistair Popple, Andi Kleen,
David Rientjes, Joern Engel, Aneesh Kumar K.V
Cc: linux-mm, linux-doc, Gerd Hoffmann, linux-kernel, linux-fsdevel,
Johannes Weiner, Chris Mason, Jiaqi Yan, stable,
David Hildenbrand (Arm)
hugetlb_pmd_shared() reads "pt_share_count" from the ptdesc of the page
table that maps a hugetlb folio, independent of the folio size, to tell
whether that page table is shared. Only PMD tables have a valid
"pt_share_count"; for other folio sizes, such as 1 GiB folios on x86
that are mapped by a PUD table, we read whatever another user of the
union left behind.
As a result, such folios might be reported as shared in smaps and as not
exclusively mapped in pagemap, and mbind(MPOL_MF_MOVE) and
migrate_pages() might skip them.
Let's fix it by adding hugetlb_folio_maybe_mapped_shared(), which
combines folio_maybe_mapped_shared(), documented to not care about page
table sharing, with a check for PMD table sharing only for PMD-sized
folios, and using it in the affected callers.
This has low urgency.
Fixes: ca1a47cd3f5f ("mm/hugetlb: fix hugetlb_pmd_shared()")
Cc: stable@vger.kernel.org
Reported-by: Chris Mason <mason@kernel.org>
Reviewed-by: Muchun Song (ByteDance) <muchun.song@linux.dev>
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
fs/proc/task_mmu.c | 6 ++----
include/linux/hugetlb.h | 16 ++++++++++++++++
mm/mempolicy.c | 2 +-
3 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index de8eded04e32a..d9ecb94f4daa5 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -1211,8 +1211,7 @@ static int smaps_hugetlb_range(pte_t *pte, unsigned long hmask,
if (folio) {
/* We treat non-present entries as "maybe shared". */
- if (!present || folio_maybe_mapped_shared(folio) ||
- hugetlb_pmd_shared(pte))
+ if (!present || hugetlb_folio_maybe_mapped_shared(folio, pte))
mss->shared_hugetlb += huge_page_size(hstate_vma(vma));
else
mss->private_hugetlb += huge_page_size(hstate_vma(vma));
@@ -2134,8 +2133,7 @@ static int pagemap_hugetlb_range(pte_t *ptep, unsigned long hmask,
if (!folio_test_anon(folio))
flags |= PM_FILE;
- if (!folio_maybe_mapped_shared(folio) &&
- !hugetlb_pmd_shared(ptep))
+ if (!hugetlb_folio_maybe_mapped_shared(folio, ptep))
flags |= PM_MMAP_EXCLUSIVE;
if (huge_pte_uffd(pte))
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 0d5414392d870..49dad5ae57512 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -1386,6 +1386,22 @@ static inline bool hugetlb_pmd_shared(pte_t *pte)
}
#endif
+#ifdef CONFIG_HUGETLB_PAGE
+static inline bool hugetlb_folio_maybe_mapped_shared(struct folio *folio,
+ pte_t *ptep)
+{
+ if (folio_maybe_mapped_shared(folio))
+ return true;
+ return folio_size(folio) == PMD_SIZE && hugetlb_pmd_shared(ptep);
+}
+#else /* !CONFIG_HUGETLB_PAGE */
+static inline bool hugetlb_folio_maybe_mapped_shared(struct folio *folio,
+ pte_t *ptep)
+{
+ return true;
+}
+#endif /* CONFIG_HUGETLB_PAGE */
+
bool want_pmd_share(struct vm_area_struct *vma, unsigned long addr);
#ifndef __HAVE_ARCH_FLUSH_HUGETLB_TLB_RANGE
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 6f800fb961aec..229efcdb2c7db 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -833,7 +833,7 @@ static int queue_folios_hugetlb(pte_t *pte, unsigned long hmask,
* cannot easily detect if a folio is shared.
*/
if ((flags & MPOL_MF_MOVE_ALL) ||
- (!folio_maybe_mapped_shared(folio) && !hugetlb_pmd_shared(pte)))
+ !hugetlb_folio_maybe_mapped_shared(folio, pte))
if (!folio_isolate_hugetlb(folio, qp->pagelist))
qp->nr_failed++;
unlock:
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v2 28/35] mm/migrate: check hugetlb PMD sharing in move_pages()
2026-12-03 11:37 [PATCH v2 00/35] mm/hugetlb: various fixes (2) David Hildenbrand (Arm)
` (14 preceding siblings ...)
2026-12-03 11:37 ` [PATCH v2 27/35] mm/hugetlb: only check PMD table sharing for PMD-sized folios David Hildenbrand (Arm)
@ 2026-12-03 11:37 ` David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 29/35] mm/hugetlb: don't share page tables of a VMA during mprotect() David Hildenbrand (Arm)
` (2 subsequent siblings)
18 siblings, 0 replies; 22+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 11:37 UTC (permalink / raw)
To: Muchun Song, Oscar Salvador, Andrew Morton, Hongfu Li,
Jinmeng Zhou, Mina Almasry, Davidlohr Bueso, Naoya Horiguchi,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Michal Hocko,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Vivek Kasireddy,
Mel Gorman, Hugh Dickins, Baolin Wang, Dave Airlie,
Jason Gunthorpe, Andy Whitcroft, Roman Gushchin, Barry Song,
Andrea Arcangeli, Lorenzo Stoakes, Suren Baghdasaryan,
Shakeel Butt, Pedro Falcato, Jann Horn, Guillaume Morin, Yang Shi,
James Houghton, Rik van Riel, Harry Yoo, Lance Yang,
Axel Rasmussen, Peter Xu, Sasha Levin, Kiryl Shutsemau,
Christian Brauner, Steven Rostedt (Google), Hongbo Li,
Gregory Price, Zi Yan, Joshua Hahn, Rakie Kim, Ying Huang,
Matthew Brost, Byungchul Park, Alistair Popple, Andi Kleen,
David Rientjes, Joern Engel, Aneesh Kumar K.V
Cc: linux-mm, linux-doc, Gerd Hoffmann, linux-kernel, linux-fsdevel,
Johannes Weiner, Chris Mason, Jiaqi Yan, stable,
David Hildenbrand (Arm)
Without MPOL_MF_MOVE_ALL, which requires CAP_SYS_NICE, move_pages(2)
refuses to migrate folios that might be mapped by other processes.
However, folio_maybe_mapped_shared() does not check for page table
sharing. So move_pages(2) with MPOL_MF_MOVE can migrate hugetlb
folios that other processes map.
mbind(2) and migrate_pages(2) already handle PMD table sharing since
commit 73bdf65ea748 ("migrate: hugetlb: check for hugetlb shared PMD in
node migration"), but we missed move_pages(2).
Let's fix it by using hugetlb_folio_maybe_mapped_shared() for hugetlb
folios in move_pages(2). Such folios are now reported with -EACCES in
the status array.
Rework the code to have separate checks for hugetlb vs. !hugetlb.
This has low urgency.
Fixes: e632a938d914 ("mm: migrate: add hugepage migration code to move_pages()")
Cc: <stable@vger.kernel.org>
Reported-by: Chris Mason <mason@kernel.org>
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
mm/migrate.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/mm/migrate.c b/mm/migrate.c
index 0430197fdc04b..194d74152e8e3 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -2279,8 +2279,9 @@ static int do_move_pages_to_node(struct list_head *pagelist, int node)
return err;
}
-static int __add_folio_for_migration(struct folio *folio, int node,
- struct list_head *pagelist, bool migrate_all)
+static int __add_folio_for_migration(struct folio *folio,
+ struct folio_walk *fw, int node, struct list_head *pagelist,
+ bool migrate_all)
{
if (is_zero_folio(folio) || is_huge_zero_folio(folio))
return -EFAULT;
@@ -2291,13 +2292,19 @@ static int __add_folio_for_migration(struct folio *folio, int node,
if (folio_nid(folio) == node)
return 0;
- if (folio_maybe_mapped_shared(folio) && !migrate_all)
- return -EACCES;
-
if (folio_test_hugetlb(folio)) {
+ /* fw->ptep aliases fw->pmdp and fw->pudp. */
+ if (!migrate_all && hugetlb_folio_maybe_mapped_shared(folio, fw->ptep))
+ return -EACCES;
if (folio_isolate_hugetlb(folio, pagelist))
return 1;
- } else if (folio_isolate_lru(folio)) {
+ return -EBUSY;
+ }
+
+ if (!migrate_all && folio_maybe_mapped_shared(folio))
+ return -EACCES;
+
+ if (folio_isolate_lru(folio)) {
list_add_tail(&folio->lru, pagelist);
node_stat_mod_folio(folio,
NR_ISOLATED_ANON + folio_is_file_lru(folio),
@@ -2332,8 +2339,8 @@ static int add_folio_for_migration(struct mm_struct *mm, const void __user *p,
if (vma && vma_migratable(vma)) {
folio = folio_walk_start(&fw, vma, addr, FW_ZEROPAGE);
if (folio) {
- err = __add_folio_for_migration(folio, node, pagelist,
- migrate_all);
+ err = __add_folio_for_migration(folio, &fw, node,
+ pagelist, migrate_all);
folio_walk_end(&fw, vma);
} else {
err = -ENOENT;
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v2 29/35] mm/hugetlb: don't share page tables of a VMA during mprotect()
2026-12-03 11:37 [PATCH v2 00/35] mm/hugetlb: various fixes (2) David Hildenbrand (Arm)
` (15 preceding siblings ...)
2026-12-03 11:37 ` [PATCH v2 28/35] mm/migrate: check hugetlb PMD sharing in move_pages() David Hildenbrand (Arm)
@ 2026-12-03 11:37 ` David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 30/35] mm/hugetlb: unshare PMDs of a split VMA if allocating its lock fails David Hildenbrand (Arm)
2026-12-03 19:11 ` [PATCH v2 00/35] mm/hugetlb: various fixes (2) Andrew Morton
18 siblings, 0 replies; 22+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 11:37 UTC (permalink / raw)
To: Muchun Song, Oscar Salvador, Andrew Morton, Hongfu Li,
Jinmeng Zhou, Mina Almasry, Davidlohr Bueso, Naoya Horiguchi,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Michal Hocko,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Vivek Kasireddy,
Mel Gorman, Hugh Dickins, Baolin Wang, Dave Airlie,
Jason Gunthorpe, Andy Whitcroft, Roman Gushchin, Barry Song,
Andrea Arcangeli, Lorenzo Stoakes, Suren Baghdasaryan,
Shakeel Butt, Pedro Falcato, Jann Horn, Guillaume Morin, Yang Shi,
James Houghton, Rik van Riel, Harry Yoo, Lance Yang,
Axel Rasmussen, Peter Xu, Sasha Levin, Kiryl Shutsemau,
Christian Brauner, Steven Rostedt (Google), Hongbo Li,
Gregory Price, Zi Yan, Joshua Hahn, Rakie Kim, Ying Huang,
Matthew Brost, Byungchul Park, Alistair Popple, Andi Kleen,
David Rientjes, Joern Engel, Aneesh Kumar K.V
Cc: linux-mm, linux-doc, Gerd Hoffmann, linux-kernel, linux-fsdevel,
Johannes Weiner, Chris Mason, Jiaqi Yan, stable,
David Hildenbrand (Arm)
When mprotect() of a shared hugetlb mapping races with a hugetlb fault
in another process that can share the same PMD table, we can end up with
page table entries that don't match the VMA flags, such as writable ones
in a PROT_READ mapping or PROT_NONE ones in accessible VMAs.
huge_pmd_share() takes i_mmap_rwsem and shares a PMD table if the flags
of the two VMAs match, so while that lock is held the entries in a
table have to match the flags of its VMA.
However, mprotect_fixup() stores the new flags without i_mmap_rwsem, and
only hugetlb_change_protection() takes it. A fault in between shares a
table that still has the old entries, and the walk then unshares the
table instead of changing them:
process A process C
VMA is RW, entries are RW VMA is R, PUD is empty
========================= ======================
mprotect_fixup()
VMA flags = R
huge_pmd_share()
i_mmap_lock_read()
flags match, take A's table
i_mmap_unlock_read()
hugetlb_change_protection()
i_mmap_lock_write()
huge_pmd_unshare()
clear A's PUD, return 1
skip the entries
VMA is R, entries are RW
mprotect() changes both the flags and the entries while holding the
mmap lock in write mode.
Let's fix it by only sharing the page tables of another VMA if we can
try-read-lock the mmap lock of its mm. If the trylock fails, we simply
try the next VMA, or allocate our own page table.
A trylock is fine, as we hold i_mmap_rwsem, which is usually taken under
the mmap lock.
This has medium urgency, as it can result in endless page fault loops if
mprotect() races with PMD table sharing and we end up with PROT_NONE
entries in accessible VMAs. If the kernel accesses such memory, for
example in copy_to_user(), the loop happens in the kernel and the task
cannot be killed.
Fixes: 39dde65c9940 ("[PATCH] shared page table for hugetlb page")
Cc: <stable@vger.kernel.org>
Reported-by: Chris Mason <mason@kernel.org>
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
mm/hugetlb.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index a23d36e7b8e93..e529994ee9f73 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -7303,15 +7303,23 @@ pte_t *huge_pmd_share(struct mm_struct *mm, struct vm_area_struct *vma,
if (svma == vma)
continue;
+ /*
+ * Stabilize the svma flags, as mprotect() changes flags
+ * before adjusting page tables.
+ */
+ if (!mmap_read_trylock(svma->vm_mm))
+ continue;
+
saddr = page_table_shareable(svma, vma, addr, idx);
if (saddr) {
spte = hugetlb_walk(svma, saddr,
vma_mmu_pagesize(svma));
- if (spte) {
+ if (spte)
ptdesc_pmd_pts_inc(virt_to_ptdesc(spte));
- break;
- }
}
+ mmap_read_unlock(svma->vm_mm);
+ if (spte)
+ break;
}
if (!spte)
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v2 30/35] mm/hugetlb: unshare PMDs of a split VMA if allocating its lock fails
2026-12-03 11:37 [PATCH v2 00/35] mm/hugetlb: various fixes (2) David Hildenbrand (Arm)
` (16 preceding siblings ...)
2026-12-03 11:37 ` [PATCH v2 29/35] mm/hugetlb: don't share page tables of a VMA during mprotect() David Hildenbrand (Arm)
@ 2026-12-03 11:37 ` David Hildenbrand (Arm)
2026-12-03 19:11 ` [PATCH v2 00/35] mm/hugetlb: various fixes (2) Andrew Morton
18 siblings, 0 replies; 22+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 11:37 UTC (permalink / raw)
To: Muchun Song, Oscar Salvador, Andrew Morton, Hongfu Li,
Jinmeng Zhou, Mina Almasry, Davidlohr Bueso, Naoya Horiguchi,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Michal Hocko,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Vivek Kasireddy,
Mel Gorman, Hugh Dickins, Baolin Wang, Dave Airlie,
Jason Gunthorpe, Andy Whitcroft, Roman Gushchin, Barry Song,
Andrea Arcangeli, Lorenzo Stoakes, Suren Baghdasaryan,
Shakeel Butt, Pedro Falcato, Jann Horn, Guillaume Morin, Yang Shi,
James Houghton, Rik van Riel, Harry Yoo, Lance Yang,
Axel Rasmussen, Peter Xu, Sasha Levin, Kiryl Shutsemau,
Christian Brauner, Steven Rostedt (Google), Hongbo Li,
Gregory Price, Zi Yan, Joshua Hahn, Rakie Kim, Ying Huang,
Matthew Brost, Byungchul Park, Alistair Popple, Andi Kleen,
David Rientjes, Joern Engel, Aneesh Kumar K.V
Cc: linux-mm, linux-doc, Gerd Hoffmann, linux-kernel, linux-fsdevel,
Johannes Weiner, Chris Mason, Jiaqi Yan, stable,
David Hildenbrand (Arm)
From: Chris Mason <mason@kernel.org>
If we split a VMA that has shared PMD page tables mapped, and allocating
the hugetlb VMA lock for the new VMA fails, a fault in the new VMA can
race with a hole punch and access page tables that were already freed.
__split_vma() calls hugetlb_vm_op_open() for the new VMA, which
allocates its hugetlb VMA lock in hugetlb_vma_lock_alloc(). If that
allocation fails, the new VMA is left without a lock.
A VMA that has shared PMD page tables needs the hugetlb VMA lock, since
the lock synchronizes huge_pmd_unshare() with concurrent page table
walks, including faults.
want_pmd_share() and page_table_shareable() prevent new sharing without
the lock, but a split leaves previously shared page tables in place for
the new VMA, and hugetlb_vm_op_open() can't currently return an error if
the allocation fails.
This can, for example, happen for an OOM victim. Then, nothing prevents
a hole punch from unsharing the page table of the new VMA while a fault
in the new VMA is still using it, and the last other sharer from freeing
it:
fault in the new VMA hole punch, then munmap()
==================== =========================
hugetlb_vma_lock_read()
no lock, does nothing
huge_pte_alloc()
pointer into shared table
folio_zero_user()
hugetlb_vma_trylock_write()
no lock, returns 1
huge_pmd_unshare(new VMA)
pud_clear()
last sharer frees the table
huge_pte_lock()
set_huge_pte_at()
Let's fix it by unsharing the PMD page tables of a new VMA that has no
lock. Also, exit hugetlb_split() early if the original VMA has no lock,
as it cannot have shared PMD page tables then.
This has low urgency, as it requires allocating the hugetlb VMA lock to
fail during a split, which is practically only possible for OOM victims,
and a race with a hole punch.
Fixes: 131a79b474e9 ("hugetlb: fix vma lock handling during split vma and range unmapping")
Cc: <stable@vger.kernel.org>
Signed-off-by: Chris Mason <mason@kernel.org>
[ david: return early if the original VMA has no lock, adjust comment
and description ]
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
include/linux/hugetlb.h | 6 ++++--
mm/hugetlb.c | 17 ++++++++++++++++-
mm/vma.c | 2 +-
tools/testing/vma/include/stubs.h | 3 ++-
4 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 49dad5ae57512..aea18895e1459 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -274,7 +274,8 @@ long hugetlb_change_protection(struct vm_area_struct *vma,
unsigned long cp_flags);
void hugetlb_unshare_all_pmds(struct vm_area_struct *vma);
void fixup_hugetlb_reservations(struct vm_area_struct *vma);
-void hugetlb_split(struct vm_area_struct *vma, unsigned long addr);
+void hugetlb_split(struct vm_area_struct *vma, struct vm_area_struct *new,
+ unsigned long addr);
unsigned int arch_hugetlb_cma_order(void);
@@ -457,7 +458,8 @@ static inline void fixup_hugetlb_reservations(struct vm_area_struct *vma)
{
}
-static inline void hugetlb_split(struct vm_area_struct *vma, unsigned long addr) {}
+static inline void hugetlb_split(struct vm_area_struct *vma,
+ struct vm_area_struct *new, unsigned long addr) {}
#endif /* !CONFIG_HUGETLB_PAGE */
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index e529994ee9f73..1c7259d80615e 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -4909,7 +4909,8 @@ static int hugetlb_vm_op_split(struct vm_area_struct *vma, unsigned long addr)
return 0;
}
-void hugetlb_split(struct vm_area_struct *vma, unsigned long addr)
+void hugetlb_split(struct vm_area_struct *vma, struct vm_area_struct *new,
+ unsigned long addr)
{
/*
* PMD sharing is only possible for PUD_SIZE-aligned address ranges
@@ -4920,8 +4921,13 @@ void hugetlb_split(struct vm_area_struct *vma, unsigned long addr)
* walks (except hardware and gup_fast()).
*/
vma_assert_write_locked(vma);
+ vma_assert_write_locked(new);
i_mmap_assert_write_locked(vma->vm_file->f_mapping);
+ /* Shared PMDs require a hugetlb VMA lock. */
+ if (!__vma_shareable_lock(vma))
+ return;
+
if (addr & ~PUD_MASK) {
unsigned long floor = addr & PUD_MASK;
unsigned long ceil = floor + PUD_SIZE;
@@ -4940,6 +4946,15 @@ void hugetlb_split(struct vm_area_struct *vma, unsigned long addr)
hugetlb_unshare_pmds(vma, floor, ceil, /* take_locks = */ false);
}
}
+
+ /*
+ * If we failed to allocate the hugetlb VMA lock, unshare everything
+ * that the new VMA covers.
+ */
+ if (!__vma_shareable_lock(new))
+ hugetlb_unshare_pmds(new, ALIGN(new->vm_start, PUD_SIZE),
+ ALIGN_DOWN(new->vm_end, PUD_SIZE),
+ /* take_locks = */ false);
}
static unsigned long hugetlb_vm_op_pagesize(struct vm_area_struct *vma)
diff --git a/mm/vma.c b/mm/vma.c
index c82e9306b11ac..183bfb8ba4703 100644
--- a/mm/vma.c
+++ b/mm/vma.c
@@ -590,7 +590,7 @@ __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma,
*/
vma_adjust_trans_huge(vma, vma->vm_start, addr, NULL);
if (vma_is_hugetlb(vma))
- hugetlb_split(vma, addr);
+ hugetlb_split(vma, new, addr);
if (new_below) {
vma->vm_start = addr;
diff --git a/tools/testing/vma/include/stubs.h b/tools/testing/vma/include/stubs.h
index 9f5b8e996abf6..6ddecf587d9be 100644
--- a/tools/testing/vma/include/stubs.h
+++ b/tools/testing/vma/include/stubs.h
@@ -466,7 +466,8 @@ static inline void vma_adjust_trans_huge(struct vm_area_struct *vma,
{
}
-static inline void hugetlb_split(struct vm_area_struct *, unsigned long) {}
+static inline void hugetlb_split(struct vm_area_struct *,
+ struct vm_area_struct *, unsigned long) {}
static inline bool vma_supports_mlock(const struct vm_area_struct *vma)
{
--
2.56.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [PATCH v2 00/35] mm/hugetlb: various fixes (2)
2026-12-03 11:37 [PATCH v2 00/35] mm/hugetlb: various fixes (2) David Hildenbrand (Arm)
` (17 preceding siblings ...)
2026-12-03 11:37 ` [PATCH v2 30/35] mm/hugetlb: unshare PMDs of a split VMA if allocating its lock fails David Hildenbrand (Arm)
@ 2026-12-03 19:11 ` Andrew Morton
18 siblings, 0 replies; 22+ messages in thread
From: Andrew Morton @ 2026-12-03 19:11 UTC (permalink / raw)
To: David Hildenbrand (Arm)
Cc: Muchun Song, Oscar Salvador, Hongfu Li, Jinmeng Zhou,
Mina Almasry, Davidlohr Bueso, Naoya Horiguchi, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Michal Hocko, Jonathan Corbet,
Shuah Khan, Randy Dunlap, Vivek Kasireddy, Mel Gorman,
Hugh Dickins, Baolin Wang, Dave Airlie, Jason Gunthorpe,
Andy Whitcroft, Roman Gushchin, Barry Song, Andrea Arcangeli,
Lorenzo Stoakes, Suren Baghdasaryan, Shakeel Butt, Pedro Falcato,
Jann Horn, Guillaume Morin, Yang Shi, James Houghton,
Rik van Riel, Harry Yoo, Lance Yang, Axel Rasmussen, Peter Xu,
Sasha Levin, Kiryl Shutsemau, Christian Brauner,
Steven Rostedt (Google), Hongbo Li, Gregory Price, Zi Yan,
Joshua Hahn, Rakie Kim, Ying Huang, Matthew Brost, Byungchul Park,
Alistair Popple, Andi Kleen, David Rientjes, Joern Engel,
Aneesh Kumar K.V, linux-mm, linux-doc, Gerd Hoffmann,
linux-kernel, linux-fsdevel, Johannes Weiner, Chris Mason,
Jiaqi Yan, Sashiko, stable
On Thu, 03 Dec 2026 12:37:23 +0100 "David Hildenbrand (Arm)" <david@kernel.org> wrote:
> Hi,
>
> this is v2 with a bunch more fixes, which I didn't want to send separately
> to not cause a mess on the list. Most of the new ones are from Sashiko
> reports, and some found while working on them. Chris reported two more.
updated, thanks.
> Changes in v2:
> - Collected tags (thanks!).
> - Dropped "mm/hugetlb: use the VMA lock to stabilize flags for PMD sharing".
> - "mm/hugetlb_cgroup: charge faults to mm->owner"
> - Dropped the RFC label.
> - Fall back to current->mm like memcg, and also charge reservations to
> the mm of the VMA.
> - Minor patch description fixups.
> - Added new fixes:
> - "mm/hugetlb: restore the reservation if vma_needs_reservation() fails"
> - "mm/hugetlb: restore the reservation when racing with another reservation"
> - "mm/hugetlb: return the reservation to the subpool on error"
> - "mm/hugetlb: report reservations that we actually added from
> hugetlb_reserve_pages()"
> - "mm/hugetlb: keep HPAGE_RESV_UNMAPPED when forking"
> - "mm/hugetlb: wait for deferred frees before failing an allocation"
> - "mm/hugetlb_cma: reset hugetlb_cma_size if the arch doesn't support it"
> - "hugetlbfs: fix integer overflow when punching holes"
> - "hugetlbfs: don't overflow the pseudo VMA address in fallocate()"
> - "hugetlbfs: don't overflow the end of the unmap range on 32-bit"
> - "hugetlbfs: don't skip private VMAs when unmapping on truncation"
> - "mm/hugetlb: serialize private faults with truncation"
> - "mm/hugetlb: check EOF for UFFDIO_COPY and UFFDIO_POISON"
> - "hugetlbfs: zero all hugetlbfs-specific fields of new inodes"
> - "mm/rmap: don't fail unmapping hugetlb folios from private VMAs"
Here's how v2 altered mm.git:
Documentation/mm/hugetlbfs_reserv.rst | 4
fs/hugetlbfs/inode.c | 42 +++---
mm/hugetlb.c | 158 +++++++++++++++---------
mm/hugetlb_cgroup.c | 2
mm/hugetlb_cma.c | 1
mm/rmap.c | 8 -
6 files changed, 129 insertions(+), 86 deletions(-)
--- a/Documentation/mm/hugetlbfs_reserv.rst~b
+++ a/Documentation/mm/hugetlbfs_reserv.rst
@@ -257,8 +257,8 @@ compensate. See the section
:ref:`Reservation Map Helper Routines <resv_map_helpers>` for more
information on these routines.
-For CoW mappings, alloc_hugetlb_folio() calls
-folio_clear_hugetlb_restore_reserve() if the reservation came from the subpool.
+alloc_hugetlb_folio() calls folio_clear_hugetlb_restore_reserve() if the
+reservation came from the subpool.
This makes free_huge_folio() return the reservation to the subpool on error.
--- a/fs/hugetlbfs/inode.c~b
+++ a/fs/hugetlbfs/inode.c
@@ -363,15 +363,12 @@ static unsigned long vma_offset_start(st
static unsigned long vma_offset_end(struct vm_area_struct *vma, pgoff_t end)
{
- unsigned long t_end;
+ const pgoff_t nr_pages = end - vma->vm_pgoff;
- if (!end)
+ if (!end || nr_pages >= vma_pages(vma))
return vma->vm_end;
- t_end = ((end - vma->vm_pgoff) << PAGE_SHIFT) + vma->vm_start;
- if (t_end > vma->vm_end)
- t_end = vma->vm_end;
- return t_end;
+ return vma->vm_start + (nr_pages << PAGE_SHIFT);
}
/*
@@ -485,10 +482,16 @@ hugetlb_vmdelete_list(struct address_spa
*/
mapping_rmap_tree_foreach(vma, mapping, start,
end ? end - 1 : ULONG_MAX) {
+ const bool need_vma_lock = __vma_shareable_lock(vma);
unsigned long v_start;
unsigned long v_end;
- if (!hugetlb_vma_trylock_write(vma))
+ /*
+ * We only need additional VMA locking here for PMD table
+ * sharing, which synchronizes on the shareable lock. Other VMAs
+ * never share PMD tables, so we can unmap them without it.
+ */
+ if (need_vma_lock && !hugetlb_vma_trylock_write(vma))
continue;
v_start = vma_offset_start(vma, start);
@@ -496,12 +499,8 @@ hugetlb_vmdelete_list(struct address_spa
unmap_hugepage_range(vma, v_start, v_end, NULL, zap_flags);
- /*
- * Note that vma lock only exists for shared/non-private
- * vmas. Therefore, lock is not held when calling
- * unmap_hugepage_range for private vmas.
- */
- hugetlb_vma_unlock_write(vma);
+ if (need_vma_lock)
+ hugetlb_vma_unlock_write(vma);
}
}
@@ -675,8 +674,12 @@ static long hugetlbfs_punch_hole(struct
/*
* hole_start and hole_end indicate the full pages within the hole.
+ * If rounding up overflows, there are no full pages in the hole.
*/
- hole_start = round_up(offset, hpage_size);
+ if (check_add_overflow(offset, hpage_size - 1, &hole_start))
+ hole_start = offset + len;
+ else
+ hole_start = round_down(hole_start, hpage_size);
hole_end = round_down(offset + len, hpage_size);
inode_lock(inode);
@@ -725,7 +728,6 @@ static long hugetlbfs_fallocate(struct f
struct hstate *h = hstate_inode(inode);
struct vm_area_struct pseudo_vma;
struct mm_struct *mm = current->mm;
- loff_t hpage_size = huge_page_size(h);
unsigned long hpage_shift = huge_page_shift(h);
pgoff_t start, index, end;
int error;
@@ -772,10 +774,11 @@ static long hugetlbfs_fallocate(struct f
for (index = start; index < end; index++) {
/*
* This is supposed to be the vaddr where the page is being
- * faulted in, but we have no vaddr here.
+ * faulted in, but we have no vaddr here. Let the pseudo VMA
+ * map the folio at address 0 to avoid overflows.
*/
+ const unsigned long addr = 0;
struct folio *folio;
- unsigned long addr;
cond_resched();
@@ -788,8 +791,7 @@ static long hugetlbfs_fallocate(struct f
break;
}
- /* addr is the offset within the file (zero based) */
- addr = index * hpage_size;
+ pseudo_vma.vm_pgoff = index << huge_page_order(h);
/* mutex taken here, fault path and hole punch */
hash = hugetlb_fault_mutex_hash(mapping, index);
@@ -903,7 +905,6 @@ static struct inode *hugetlbfs_get_root(
simple_inode_init_ts(inode);
inode->i_op = &hugetlbfs_dir_inode_operations;
inode->i_fop = &simple_dir_operations;
- HUGETLBFS_I(inode)->resv_map = NULL;
/* directory inodes start off with i_nlink == 2 (for "." entry) */
inc_nlink(inode);
lockdep_annotate_inode_mutex_key(inode);
@@ -1205,6 +1206,7 @@ static struct inode *hugetlbfs_alloc_ino
hugetlbfs_inc_free_inodes(sbinfo);
return NULL;
}
+ memset_after(p, 0, vfs_inode);
return &p->vfs_inode;
}
--- a/mm/hugetlb.c~b
+++ a/mm/hugetlb.c
@@ -1220,7 +1220,7 @@ void hugetlb_dup_vma_private(struct vm_a
{
VM_WARN_ON_ONCE_VMA(!vma_is_hugetlb(vma), vma);
/*
- * Clear vm_private_data
+ * Clear vm_private_data, except for HPAGE_RESV_UNMAPPED
* - For shared mappings this is a per-vma semaphore that may be
* allocated in a subsequent call to hugetlb_vm_op_open.
* Before clearing, make sure pointer is not associated with vma
@@ -1229,7 +1229,10 @@ void hugetlb_dup_vma_private(struct vm_a
* been called to allocate a new structure.
* - For MAP_PRIVATE mappings, this is the reserve map which does
* not apply to children. Faults generated by the children are
- * not guaranteed to succeed, even if read-only.
+ * not guaranteed to succeed, even if read-only. But keep
+ * HPAGE_RESV_UNMAPPED: if the reservation owner unmapped folios
+ * from this VMA when its COW fault failed, faults in children must
+ * fail as well.
*/
if (vma->vm_flags & VM_MAYSHARE) {
struct hugetlb_vma_lock *vma_lock = vma->vm_private_data;
@@ -1237,7 +1240,11 @@ void hugetlb_dup_vma_private(struct vm_a
if (vma_lock && vma_lock->vma != vma)
vma->vm_private_data = NULL;
} else {
+ const bool unmapped = is_vma_resv_set(vma, HPAGE_RESV_UNMAPPED);
+
vma->vm_private_data = NULL;
+ if (unmapped)
+ set_vma_resv_flags(vma, HPAGE_RESV_UNMAPPED);
}
}
@@ -2742,7 +2749,9 @@ static long vma_del_reservation(struct h
* In case 2, simply undo reserve map modifications done by alloc_hugetlb_folio.
*
* For CoW mappings, allocations using a subpool reservation leave the
- * flag clear and the reserve map unchanged. free_huge_folio returns the
+ * flag clear and the reserve map unchanged. The same applies to shared
+ * mappings, except that case 2 removes the reservation from the reserve map,
+ * unless updating the reserve map fails. free_huge_folio returns the
* reservation to the subpool.
*/
void restore_reserve_on_error(struct hstate *h, struct vm_area_struct *vma,
@@ -2750,21 +2759,27 @@ void restore_reserve_on_error(struct hst
{
long rc = vma_needs_reservation(h, vma, address);
- if (folio_test_hugetlb_restore_reserve(folio)) {
- if (unlikely(rc < 0))
- /*
- * Rare out of memory condition in reserve map
- * manipulation. Clear hugetlb_restore_reserve so
- * that global reserve count will not be incremented
- * by free_huge_folio. This will make it appear
- * as though the reservation for this folio was
- * consumed. This may prevent the task from
- * faulting in the folio at a later time. This
- * is better than inconsistent global huge page
- * accounting of reserve counts.
- */
+ if (unlikely(rc < 0)) {
+ /*
+ * Rare out of memory condition in reserve map manipulation.
+ *
+ * In shared mappings, the reserve map has the reservation for
+ * this index, so let folio freeing code restore it.
+ *
+ * Otherwise, don't restore the reservation, making it appear
+ * as though it was consumed. This may prevent the task from
+ * faulting in the folio at a later time, but is better than
+ * inconsistent global huge page accounting of reserve counts.
+ */
+ if (vma->vm_flags & VM_MAYSHARE)
+ folio_set_hugetlb_restore_reserve(folio);
+ else
folio_clear_hugetlb_restore_reserve(folio);
- else if (rc)
+ return;
+ }
+
+ if (folio_test_hugetlb_restore_reserve(folio)) {
+ if (rc)
(void)vma_add_reservation(h, vma, address);
else
vma_end_reservation(h, vma, address);
@@ -2789,11 +2804,6 @@ void restore_reserve_on_error(struct hst
* on a subsequent allocation.
*/
folio_set_hugetlb_restore_reserve(folio);
- } else if (rc < 0) {
- /*
- * Region cache allocation can fail even if an entry exists.
- * Leave the flag and reserve map unchanged.
- */
} else {
/*
* No reservation present, do nothing
@@ -3210,6 +3220,9 @@ static struct folio *__alloc_hugetlb_fol
};
folio = hugetlb_alloc_folio(h, &mpoli, memcg_mm, alloc_flags);
+ /* Wait for deferred freeing and retry once before giving up. */
+ if (IS_ERR(folio) && flush_work(&free_hpage_work))
+ folio = hugetlb_alloc_folio(h, &mpoli, memcg_mm, alloc_flags);
mpol_cond_put(mpol);
@@ -3220,6 +3233,18 @@ static struct folio *__alloc_hugetlb_fol
hugetlb_set_folio_subpool(folio, spool);
+ /*
+ * On error, let folio freeing code return the reservation to the
+ * subpool, unless we consumed a reservation from the reserve map.
+ *
+ * In private mappings, the reserve map might not exist or already
+ * account for another folio at this index. In shared mappings,
+ * restore_reserve_on_error() will remove the reservation we are about
+ * to add to the reserve map, unless updating the reserve map fails.
+ */
+ if (map_chg != MAP_CHG_REUSE)
+ folio_clear_hugetlb_restore_reserve(folio);
+
if (map_chg != MAP_CHG_ENFORCED) {
/* commit() is only needed if the map_chg is not enforced */
retval = vma_commit_reservation(h, vma, addr);
@@ -3242,17 +3267,14 @@ static struct folio *__alloc_hugetlb_fol
hugetlb_cgroup_uncharge_folio_rsvd(
hstate_index(h), pages_per_huge_page(h), folio);
spin_unlock_irq(&hugetlb_lock);
+ /*
+ * We consumed that existing reservation and must
+ * restore it when freeing the folio due to errors.
+ */
+ folio_set_hugetlb_restore_reserve(folio);
}
}
- /*
- * Return subpool reservations to the subpool on error. A CoW mapping
- * might not have a reserve map, or it might already account for
- * another folio at this index.
- */
- if (map_chg != MAP_CHG_REUSE && vma_is_cow_mapping(vma))
- folio_clear_hugetlb_restore_reserve(folio);
-
return folio;
out_subpool_put:
@@ -5975,6 +5997,7 @@ static vm_fault_t hugetlb_no_page(struct
const bool pagecache_folio = vmf->vma->vm_flags & VM_MAYSHARE;
u32 hash = hugetlb_fault_mutex_hash(mapping, vmf->pgoff);
bool folio_locked = true, new_anon_folio = false;
+ bool invalidate_locked = false;
struct vm_area_struct *vma = vmf->vma;
struct mm_struct *mm = vma->vm_mm;
struct hstate *h = hstate_vma(vma);
@@ -6034,15 +6057,19 @@ static vm_fault_t hugetlb_no_page(struct
ret = __vmf_anon_prepare(vmf);
if (unlikely(ret))
goto out;
- } else {
- /* Recheck EOF before consuming an inode reservation. */
- filemap_invalidate_lock_shared(mapping);
- if (!hugetlb_pgoff_valid(mapping, vmf->pgoff, /* partial= */ false)) {
- filemap_invalidate_unlock_shared(mapping);
- goto out;
- }
+ ret = VM_FAULT_SIGBUS;
}
+ /*
+ * Recheck EOF and keep truncation out until the folio is in the
+ * page cache, or until we mapped the new anonymous folio:
+ * truncation unmaps or removes it afterwards.
+ */
+ filemap_invalidate_lock_shared(mapping);
+ invalidate_locked = true;
+ if (!hugetlb_pgoff_valid(mapping, vmf->pgoff, /* partial= */ false))
+ goto out;
+
folio = alloc_hugetlb_folio(vma, vmf->address, false);
if (IS_ERR(folio)) {
/*
@@ -6061,8 +6088,6 @@ static vm_fault_t hugetlb_no_page(struct
ret = vmf_error(PTR_ERR(folio));
else
ret = 0;
- if (pagecache_folio)
- filemap_invalidate_unlock_shared(mapping);
goto out;
}
folio_zero_user(folio, vmf->real_address);
@@ -6083,10 +6108,10 @@ static vm_fault_t hugetlb_no_page(struct
folio);
folio_put(folio);
ret = VM_FAULT_SIGBUS;
- filemap_invalidate_unlock_shared(mapping);
goto out;
}
filemap_invalidate_unlock_shared(mapping);
+ invalidate_locked = false;
folio_set_hugetlb_migratable(folio);
} else {
new_anon_folio = true;
@@ -6185,6 +6210,8 @@ static vm_fault_t hugetlb_no_page(struct
*/
spin_unlock(vmf->ptl);
out:
+ if (invalidate_locked)
+ filemap_invalidate_unlock_shared(mapping);
hugetlb_vma_unlock_read(vma);
/*
@@ -6528,13 +6555,31 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_
bool folio_in_pagecache = false;
pte_t dst_ptep;
+ /*
+ * Check EOF and keep truncation out until we mapped the new folio or
+ * installed the poison marker: truncation unmaps or removes it
+ * afterwards.
+ */
+ if (!is_continue) {
+ filemap_invalidate_lock_shared(mapping);
+ if (!hugetlb_pgoff_valid(mapping, idx, /* partial= */ false)) {
+ if (*foliop) {
+ folio_put(*foliop);
+ *foliop = NULL;
+ }
+ ret = -EFAULT;
+ goto out;
+ }
+ }
+
if (uffd_flags_mode_is(flags, MFILL_ATOMIC_POISON)) {
ptl = huge_pte_lock(h, dst_mm, dst_pte);
/* Don't overwrite any existing PTEs (even markers) */
if (!huge_pte_none(huge_ptep_get(dst_mm, dst_addr, dst_pte))) {
spin_unlock(ptl);
- return -EEXIST;
+ ret = -EEXIST;
+ goto out;
}
VM_WARN_ON_ONCE(size == PMD_SIZE && hugetlb_pmd_shared(dst_pte));
@@ -6545,19 +6590,8 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_
update_mmu_cache(dst_vma, dst_addr, dst_pte);
spin_unlock(ptl);
- return 0;
- }
-
- if (alloc_pagecache_folio) {
- filemap_invalidate_lock_shared(mapping);
- if (!hugetlb_pgoff_valid(mapping, idx, /* partial= */ false)) {
- if (*foliop) {
- folio_put(*foliop);
- *foliop = NULL;
- }
- ret = -EFAULT;
- goto out;
- }
+ ret = 0;
+ goto out;
}
if (is_continue) {
@@ -6726,7 +6760,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_
spin_unlock(ptl);
ret = 0;
out:
- if (alloc_pagecache_folio)
+ if (!is_continue)
filemap_invalidate_unlock_shared(mapping);
return ret;
out_release_unlock:
@@ -6912,9 +6946,9 @@ next:
/*
* Update the reservation map for the range [from, to].
*
- * Returns the number of entries that would be added to the reservation map
- * associated with the range [from, to]. This number is greater or equal to
- * zero. -EINVAL or -ENOMEM is returned in case of any errors.
+ * Returns the number of huge pages that we reserved in the range [from, to],
+ * or a negative error code. On a later error, callers must only undo
+ * these reservations, not reservations that already existed in the range.
*/
long hugetlb_reserve_pages(struct inode *inode,
@@ -6987,7 +7021,8 @@ retry:
}
err = hugetlb_cgroup_charge_cgroup_rsvd(hstate_index(h),
- chg * pages_per_huge_page(h), NULL, &h_cg);
+ chg * pages_per_huge_page(h),
+ vma ? vma->vm_mm : NULL, &h_cg);
if (err < 0)
goto out_err;
@@ -7057,6 +7092,11 @@ retry:
rsv_adjust = hugepage_subpool_put_pages(spool,
chg - add);
hugetlb_acct_memory(h, -rsv_adjust);
+ /*
+ * Only report the reservations that we added, such that
+ * callers will not undo the racing reservations.
+ */
+ chg = add;
} else if (h_cg) {
/*
* The file_regions will hold their own reference to
--- a/mm/hugetlb_cgroup.c~b
+++ a/mm/hugetlb_cgroup.c
@@ -287,6 +287,8 @@ static struct hugetlb_cgroup *hugetlb_cg
#ifdef CONFIG_MEMCG
/* Like memcg, charge the owner of the mm we allocate for. */
+ if (!mm)
+ mm = current->mm;
if (mm)
task = rcu_dereference(mm->owner);
#endif
--- a/mm/hugetlb_cma.c~b
+++ a/mm/hugetlb_cma.c
@@ -249,6 +249,7 @@ void __init hugetlb_cma_reserve(void)
order = arch_hugetlb_cma_order();
if (!order) {
pr_warn("hugetlb_cma: the option isn't supported by current arch\n");
+ hugetlb_cma_size = 0;
return;
}
--- a/mm/rmap.c~b
+++ a/mm/rmap.c
@@ -48,7 +48,7 @@
* hugetlbfs PageHuge() take locks in this order:
* hugetlb_fault_mutex (hugetlbfs specific page fault mutex)
* vma_lock (hugetlb specific lock for pmd_sharing)
- * mapping->invalidate_lock (when allocating page cache folios)
+ * mapping->invalidate_lock (when allocating folios)
* folio_lock
* mapping->i_mmap_rwsem (also used for hugetlb pmd sharing)
*/
@@ -2049,7 +2049,7 @@ static bool try_to_unmap_poisoned_hugetl
* acquiring vma_lock BEFORE i_mmap_rwsem. We can only try lock here and
* fail if unsuccessful.
*/
- if (!folio_test_anon(folio)) {
+ if (__vma_shareable_lock(vma)) {
struct mmu_gather tlb;
VM_WARN_ON_ONCE(!(flags & TTU_RMAP_LOCKED));
@@ -2580,8 +2580,6 @@ static bool try_to_migrate_one(struct fo
PageAnonExclusive(subpage);
if (folio_test_hugetlb(folio)) {
- bool anon = folio_test_anon(folio);
-
/*
* huge_pmd_unshare may unmap an entire PMD page.
* There is no way of knowing exactly which PMDs may
@@ -2601,7 +2599,7 @@ static bool try_to_migrate_one(struct fo
* i_mmap_rwsem. We can only try lock here and
* fail if unsuccessful.
*/
- if (!anon) {
+ if (__vma_shareable_lock(vma)) {
struct mmu_gather tlb;
VM_BUG_ON(!(flags & TTU_RMAP_LOCKED));
_
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v2 03/35] mm/hugetlb: restore the reservation when racing with another reservation
2026-12-03 11:37 ` [PATCH v2 03/35] mm/hugetlb: restore the reservation when racing with another reservation David Hildenbrand (Arm)
@ 2026-12-04 6:07 ` Muchun Song
0 siblings, 0 replies; 22+ messages in thread
From: Muchun Song @ 2026-12-04 6:07 UTC (permalink / raw)
To: David Hildenbrand (Arm)
Cc: Muchun Song, Oscar Salvador, Andrew Morton, Hongfu Li,
Jinmeng Zhou, Mina Almasry, Davidlohr Bueso, Naoya Horiguchi,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Michal Hocko,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Vivek Kasireddy,
Mel Gorman, Hugh Dickins, Baolin Wang, Dave Airlie,
Jason Gunthorpe, Andy Whitcroft, Roman Gushchin, Barry Song,
Andrea Arcangeli, Lorenzo Stoakes, Suren Baghdasaryan,
Shakeel Butt, Pedro Falcato, Jann Horn, Guillaume Morin, Yang Shi,
James Houghton, Rik van Riel, Harry Yoo, Lance Yang,
Axel Rasmussen, Peter Xu, Sasha Levin, Kiryl Shutsemau,
Christian Brauner, Steven Rostedt (Google), Hongbo Li,
Gregory Price, Zi Yan, Joshua Hahn, Rakie Kim, Ying Huang,
Matthew Brost, Byungchul Park, Alistair Popple, Andi Kleen,
David Rientjes, Joern Engel, Aneesh Kumar K.V, linux-mm,
linux-doc, Gerd Hoffmann, linux-kernel, linux-fsdevel,
Johannes Weiner, Chris Mason, Jiaqi Yan, Sashiko, stable
> On Dec 3, 2026, at 19:37, David Hildenbrand (Arm) <david@kernel.org> wrote:
>
> When we fault in a folio in a shared hugetlb mapping at an index that is
> not reserved yet, alloc_hugetlb_folio() can race with
> hugetlb_reserve_pages() reserving that index, for example, because
> another process mmap()s the same file without MAP_NORESERVE.
>
> vma_commit_reservation() will then find the racing reservation in the
> reserve map after allocating the folio, and we consume that reservation
> instead: we return our subpool charge, drop a global reservation and
> uncharge the cgroup reservation of the folio. However, we don't set
> HPG_restore_reserve on the folio.
>
> If we then hit an error before the folio gets added to the page cache,
> restore_reserve_on_error() assumes that alloc_hugetlb_folio() performed
> the reservation in the reserve map and removes it, and free_huge_folio()
> doesn't restore the global reservation. The reservation of the racing
> mmap() is then gone, and a later fault at that index can fail with
> SIGBUS.
>
> Reproduced by artificially delaying alloc_hugetlb_folio() right before
> vma_commit_reservation() during a failing UFFDIO_COPY, while another
> process mmap()s the same file: once all unreserved huge pages are in
> use, that process gets SIGBUS when touching its page.
>
> Let's fix it by setting HPG_restore_reserve, so the error path keeps the
> reservation in the reserve map and free_huge_folio() restores the global
> reservation. On success, adding the folio to the page cache clears the
> flag.
>
> This has low urgency, as it requires an error after racing with another
> mapping reserving the same index.
>
> Fixes: 33039678c8da ("mm/hugetlb: handle races in alloc_huge_page and hugetlb_reserve_pages")
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Cc: stable@vger.kernel.org
> Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
Acked-by: Muchun Song (ByteDance) <muchun.song@linux.dev>
Thanks.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v2 05/35] mm/hugetlb: report reservations that we actually added from hugetlb_reserve_pages()
2026-12-03 11:37 ` [PATCH v2 05/35] mm/hugetlb: report reservations that we actually added from hugetlb_reserve_pages() David Hildenbrand (Arm)
@ 2026-12-04 6:08 ` Muchun Song
0 siblings, 0 replies; 22+ messages in thread
From: Muchun Song @ 2026-12-04 6:08 UTC (permalink / raw)
To: David Hildenbrand (Arm)
Cc: Muchun Song, Oscar Salvador, Andrew Morton, Hongfu Li,
Jinmeng Zhou, Mina Almasry, Davidlohr Bueso, Naoya Horiguchi,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Michal Hocko,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Vivek Kasireddy,
Mel Gorman, Hugh Dickins, Baolin Wang, Dave Airlie,
Jason Gunthorpe, Andy Whitcroft, Roman Gushchin, Barry Song,
Andrea Arcangeli, Lorenzo Stoakes, Suren Baghdasaryan,
Shakeel Butt, Pedro Falcato, Jann Horn, Guillaume Morin, Yang Shi,
James Houghton, Rik van Riel, Harry Yoo, Lance Yang,
Axel Rasmussen, Peter Xu, Sasha Levin, Kiryl Shutsemau,
Christian Brauner, Steven Rostedt (Google), Hongbo Li,
Gregory Price, Zi Yan, Joshua Hahn, Rakie Kim, Ying Huang,
Matthew Brost, Byungchul Park, Alistair Popple, Andi Kleen,
David Rientjes, Joern Engel, Aneesh Kumar K.V, linux-mm,
linux-doc, Gerd Hoffmann, linux-kernel, linux-fsdevel,
Johannes Weiner, Chris Mason, Jiaqi Yan, Sashiko, stable
> On Dec 3, 2026, at 19:37, David Hildenbrand (Arm) <david@kernel.org> wrote:
>
> memfd_alloc_folio() uses hugetlb_reserve_pages() to reserve the index
> of the folio it is about to allocate. If allocating the folio or adding
> it to the page cache fails, it undoes that reservation, but only if
> hugetlb_reserve_pages() reported that it actually performed the
> reservation.
>
> If the index was already reserved, for example through an mmap() of the
> same file, memfd_alloc_folio() must not undo that reservation.
>
> However, if hugetlb_reserve_pages() races with another reservation for
> the same index, region_add_limited() can reserve fewer pages than
> region_chg() counted. hugetlb_reserve_pages() will then hand back the
> surplus charges, but still report the number of pages that region_chg()
> counted.
>
> Consequently, after racing with hugetlbfs_file_mmap() reserving the same
> index, memfd_alloc_folio() will undo the reservation of the mmap() caller
> on error, and a later fault at that index can fail with SIGBUS.
>
> Reproduced by artificially delaying hugetlb_reserve_pages() after
> region_chg() during IOMMU_IOAS_MAP_FILE of a hugetlb memfd, while another
> process mmap()s the memfd, and failing the page cache insertion with
> fault injection. Once all unreserved huge pages are in use, the mmap()
> caller gets SIGBUS on fault.
>
> Let's fix it by only reporting the reservations that we actually added.
> Other callers are not affected, as they only care about error vs.
> success, not the actual number of reserved pages.
>
> This has low urgency, as it requires an allocation failure after racing
> with an mmap() of the same file.
>
> Fixes: 717cf9357325 ("mm/memfd: reserve hugetlb folios before allocation")
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Cc: stable@vger.kernel.org
> Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
Acked-by: Muchun Song (ByteDance) <muchun.song@linux.dev>
Thanks.
^ permalink raw reply [flat|nested] 22+ messages in thread
end of thread, other threads:[~2026-12-04 6:09 UTC | newest]
Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 11:37 [PATCH v2 00/35] mm/hugetlb: various fixes (2) David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 02/35] mm/hugetlb: restore the reservation if vma_needs_reservation() fails David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 03/35] mm/hugetlb: restore the reservation when racing with another reservation David Hildenbrand (Arm)
2026-12-04 6:07 ` Muchun Song
2026-12-03 11:37 ` [PATCH v2 04/35] mm/hugetlb: return the reservation to the subpool on error David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 05/35] mm/hugetlb: report reservations that we actually added from hugetlb_reserve_pages() David Hildenbrand (Arm)
2026-12-04 6:08 ` Muchun Song
2026-12-03 11:37 ` [PATCH v2 07/35] mm/hugetlb: always mark new page cache folios migratable David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 08/35] mm/memfd: mark new hugetlb " David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 09/35] mm/hugetlb: free surplus folios of other nodes on free David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 12/35] mm/hugetlb: fix truncated copy result in UFFDIO_COPY David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 13/35] fs/proc/task_mmu: don't clear VM_SOFTDIRTY on hugetlb VMAs David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 15/35] hugetlbfs: don't zero poisoned pages in a hole punch David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 16/35] hugetlbfs: fix deadlock between hole punching and memory failure David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 19/35] hugetlbfs: recheck the vma range after the lock wait David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 21/35] hugetlbfs: don't skip private VMAs when unmapping on truncation David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 26/35] mm/rmap: don't fail unmapping hugetlb folios from private VMAs David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 27/35] mm/hugetlb: only check PMD table sharing for PMD-sized folios David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 28/35] mm/migrate: check hugetlb PMD sharing in move_pages() David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 29/35] mm/hugetlb: don't share page tables of a VMA during mprotect() David Hildenbrand (Arm)
2026-12-03 11:37 ` [PATCH v2 30/35] mm/hugetlb: unshare PMDs of a split VMA if allocating its lock fails David Hildenbrand (Arm)
2026-12-03 19:11 ` [PATCH v2 00/35] mm/hugetlb: various fixes (2) Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox