Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796325199; b=TD4Y2WlFEWLkMLtCmNIE29Xw/sXZGTXlsTyZl2ikcqow9fvGHJOWWSQGiASs1QNpqujf 3oof1I2rAh+K6bbqy8mpGKHEqVxteWfVuhrIHLOGc/aadocPZ5Yg7ZpInAZIqLRQzbDy/ 0+iYKxwkf9DwZhFqrh05kMqR6/ZMZBlANU9W5ddMFFYb7Ur0VaQFNUfT2clRFl1La3qH+ h0FrUHsEwHGOpiFO72MkeemJCkAYP8yowbugBH5ITdNk+ViYeLzs3VaucoksV5nMWR/N/ GNrWKEoEGgmkMWe+jrsthKe+cqR1OKemo8KxdDMUZpOA8Qfaz+tIc8Y7WDLGpBVc8kw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796325199; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=vvKcmy8p0CKLP9AuE8UkDvFzRRP66Z1YikKbAWDP/4M=; b=gc4RPKg4BFgbll2CPgOOr4HO4wY5+hUFIqn9uJ7o7rRGaHfzH4Ew/VqNhLm10/nctGPq EjYDbbcMTSQ0e3Ghf+RFPwWjc/jA6IDa/WEK+zFjFCFzFiGQkWIUP8dVwLYYRhxJTiasY cMmRN5WYro8VCuXugLS83QMvyfJThR/ut1WC2ix9MNvm4dCH+1crQTIRNXBnIrKoYhNy2 32QFhLqjXXJmdP5R7poa5XhYSUAiaCfwuQXl+/I0ieHQ2useNAX7z1H1lcodTkuMgQbKq RpMTx5zaKJnfl5fk5/M+om/aRB6qq1CCIO7mJLPbGihQKfabTANe9QcPt+LpJ6b1jRQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b="W/VNpdqm"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE50E606A322 for ; Thu, 3 Dec 2026 19:13:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=W/VNpdqm Received: by smtp.kernel.org (Postfix) with ESMTPSA id 507A91F00934; Thu, 3 Dec 2026 19:13:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796325199; bh=vvKcmy8p0CKLP9AuE8UkDvFzRRP66Z1YikKbAWDP/4M=; h=Date:To:From:In-Reply-To:References:Subject; b=W/VNpdqmm6+qPLWpL0z90oJFBzSXN3irXi4vQ9jHJ2QIhGpH4AKRy+t4qnJD8cT+n Yp67ewBFdVqR6D9crcAn2vElH3r44Cwe/+/N7B+LCGhSh7v9AYzzQVKyS3iT4gAFxL X2veh0cYvxiRXsH2Jkm5UTtM+H6bRfRQy1FfjNgo= Date: Thu, 03 Dec 2026 11:13:18 -0800 To: mm-commits@vger.kernel.org,david@kernel.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261203-hugetlb_fixes_2-v2-6-9bbeabb555d2@kernel.org> References: <20261203-hugetlb_fixes_2-v2-6-9bbeabb555d2@kernel.org> Subject: + mm-hugetlb-keep-hpage_resv_unmapped-when-forking.patch added to mm-unstable branch Message-Id: <20261203191319.507A91F00934@smtp.kernel.org> X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The patch titled Subject: mm/hugetlb: keep HPAGE_RESV_UNMAPPED when forking has been added to the -mm mm-unstable branch. Its filename is mm-hugetlb-keep-hpage_resv_unmapped-when-forking.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-hugetlb-keep-hpage_resv_unmapped-when-forking.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: "David Hildenbrand (Arm)" Subject: mm/hugetlb: keep HPAGE_RESV_UNMAPPED when forking Date: Thu, 03 Dec 2026 12:37:29 +0100 If a COW fault of the owner of a MAP_PRIVATE hugetlb reservation fails to allocate a folio, the owner keeps the folio, and unmap_ref_private() unmaps it from all other private VMAs that map it. We mark these VMAs with HPAGE_RESV_UNMAPPED, such that future faults in them fail instead of looking like the data was lost. However, when a process whose VMA has HPAGE_RESV_UNMAPPED set forks, hugetlb_dup_vma_private() clears vm_private_data of the child's VMA, including HPAGE_RESV_UNMAPPED. Consequently, faults in the grandchild of the original process can map a page cache folio or a new zeroed folio without any signal, silently losing the data. Reproduced by forking a child after writing to a folio in a private mapping, exhausting the pool such that the COW fault of the owner fails, and letting the child fork a grandchild after freeing up the pool again: the child gets SIGBUS when accessing the folio, but the grandchild reads zeroes. Let's fix it by keeping HPAGE_RESV_UNMAPPED when clearing the private data of the child's VMA. This has low urgency, as it requires a failed COW fault due to an exhausted pool, followed by a fork(). No need to CC stable. Link: https://patch.msgid.link/20261203-hugetlb_fixes_2-v2-6-9bbeabb555d2@kernel.org Fixes: 04f2cbe35699 ("hugetlb: guarantee that COW faults for a process that called mmap(MAP_PRIVATE) on hugetlbfs will succeed") Signed-off-by: David Hildenbrand (Arm) Signed-off-by: Andrew Morton Reported-by: Chris Mason Cc: Muchun Song Cc: Oscar Salvador Cc: Hongfu Li Cc: Jinmeng Zhou Cc: Mina Almasry Cc: Davidlohr Bueso Cc: Naoya Horiguchi Cc: Liam R. Howlett Cc: Vlastimil Babka Cc: Mike Rapoport Cc: Michal Hocko Cc: Jonathan Corbet Cc: Shuah Khan Cc: Randy Dunlap Cc: Vivek Kasireddy Cc: Mel Gorman Cc: Hugh Dickins Cc: Baolin Wang Cc: Dave Airlie Cc: Jason Gunthorpe Cc: Andy Whitcroft Cc: Roman Gushchin Cc: Barry Song Cc: Andrea Arcangeli Cc: Lorenzo Stoakes Cc: Suren Baghdasaryan Cc: Shakeel Butt Cc: Pedro Falcato Cc: Jann Horn Cc: Guillaume Morin Cc: Yang Shi Cc: James Houghton Cc: Rik van Riel Cc: Harry Yoo Cc: Lance Yang Cc: Axel Rasmussen Cc: Peter Xu Cc: Sasha Levin Cc: Kiryl Shutsemau Cc: Christian Brauner Cc: Steven Rostedt Cc: Hongbo Li Cc: Gregory Price Cc: Zi Yan Cc: Joshua Hahn Cc: Rakie Kim Cc: Ying Huang Cc: Matthew Brost Cc: Byungchul Park Cc: Alistair Popple Cc: Andi Kleen Cc: David Rientjes Cc: Joern Engel Cc: Aneesh Kumar K.V Cc: Gerd Hoffmann Cc: Johannes Weiner Cc: Jiaqi Yan mm/hugetlb.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) --- a/mm/hugetlb.c~mm-hugetlb-keep-hpage_resv_unmapped-when-forking +++ a/mm/hugetlb.c @@ -1218,7 +1218,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 @@ -1227,7 +1227,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; @@ -1235,7 +1238,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); } } _ Patches currently in -mm which might be from david@kernel.org are mm-mprotect-dont-skip-uffd-marker-install-when-racing-with-pte-table-reclaim.patch mm-userfaultfd-prevent-poison-marker-loss.patch mm-hugetlb-compare-against-persistent-count-when-freeing-lowmem-folios.patch mm-hugetlb-preserve-reservations-when-shrinking-on-highmem.patch mm-hugetlb-account-temporary-folios-separately.patch mm-hugetlb-account-temporary-folios-separately-fix.patch mm-hugetlb-serialize-page-cache-allocations-with-truncation.patch mm-hugetlb-serialize-page-cache-allocations-with-truncation-fix.patch mm-memfd-recheck-the-page-cache-before-allocating-a-hugetlb-folio.patch mm-hugetlb-count-again-if-the-reserve-map-shrank.patch mm-hugetlb-account-restored-reservations-before-freeing-folios.patch mm-hugetlb-delay-anon-folio-rmap-removal-until-after-the-tlb-flush.patch mm-userfaultfd-reject-dax-mappings.patch mm-filemap-avoid-retrying-faults-on-uffd-wp-markers.patch mm-hugetlb-restore-the-reservation-if-vma_needs_reservation-fails.patch mm-hugetlb-restore-the-reservation-when-racing-with-another-reservation.patch mm-hugetlb-return-the-reservation-to-the-subpool-on-error.patch mm-hugetlb-report-reservations-that-we-actually-added-from-hugetlb_reserve_pages.patch mm-hugetlb-keep-hpage_resv_unmapped-when-forking.patch mm-hugetlb-always-mark-new-page-cache-folios-migratable.patch mm-memfd-mark-new-hugetlb-folios-migratable.patch mm-hugetlb-free-surplus-folios-of-other-nodes-on-free.patch mm-hugetlb-wait-for-deferred-frees-before-failing-an-allocation.patch mm-hugetlb_cma-reset-hugetlb_cma_size-if-the-arch-doesnt-support-it.patch fs-proc-task_mmu-dont-clear-vm_softdirty-on-hugetlb-vmas.patch hugetlbfs-fix-integer-overflow-when-punching-holes.patch hugetlbfs-dont-zero-poisoned-pages-in-a-hole-punch.patch hugetlbfs-dont-overflow-the-pseudo-vma-address-in-fallocate.patch hugetlbfs-dont-overflow-the-end-of-the-unmap-range-on-32-bit.patch hugetlbfs-dont-skip-private-vmas-when-unmapping-on-truncation.patch mm-hugetlb-serialize-private-faults-with-truncation.patch mm-hugetlb-check-eof-for-uffdio_copy-and-uffdio_poison.patch hugetlbfs-zero-all-hugetlbfs-specific-fields-of-new-inodes.patch mm-rmap-dont-fail-unmapping-hugetlb-folios-from-private-vmas.patch mm-hugetlb-only-check-pmd-table-sharing-for-pmd-sized-folios.patch mm-migrate-check-hugetlb-pmd-sharing-in-move_pages.patch mm-hugetlb-dont-share-page-tables-of-a-vma-during-mprotect.patch mm-hugetlb-count-migration-entries-at-fork-and-unmap.patch mm-hugetlb-stop-accounting-hugetlbpages-once-pmd-tables-were-shared.patch mm-hugetlb_cgroup-charge-faults-to-mm-owner.patch