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=1796324406; b=YIViGH1n7aTf2rF4dA2HEf+/Vu4dhDghnj2+6o7h/nb3+5JfKq770K5fDR88wdw+JZc3 cS0BGkRcAbcWRLACbHafdcNjlT0FqnFpN7S11ikVrdZAgSR/XMiZ9fAt5lPWE0DYCKABH zskPp2GaUYLUqhiq5ae7c5IP/aW6HKOLLT5BCFK3XWwtmr9g5ZD1t/WzfIHfYLtUk2aeQ zr3A0QFWHI9zITPCOgtr4J1RAs/dvgJipiDRrsZ7G3W48Ilfz95vT7Xs4K1fHVd/66Ifq v6lVX5vZT3yGDukxEYp7E1qwDXQS2q9cAmpgo7tmbDk4nydFgSGzgKKA673DzbGsHOQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796324406; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=vhZUD7x7zQG9tmJxeveuemp1u0wBNpd0VFDJDuNnwbI=; b=1z6EQZ3ROthmnQhwSKVbE5bqOzaa7ublBVaJ7VXWZALbRbIY2pUPIgwlU/nwQRvou1us AiH9hZ54YN6gcf2aLnViu5uXaTlvfG7+t88aBdhdJ/loEYn67gS2C++SNBwtRQ3AGgfoX wshBOCJBa254B6dVFm4gwaAYR/lLC4Qb8/17qygsZV3jnt0dBxh5LqmZeaw4pRIp2JDsP 6kBAexOsKGtnCTxDFdjOCNQKWCl9vw2Nxjtos4ncXwgpAeVAGtNFg0/aYiGQ7pgT75N2R ROWMwHyPZsBp1jgpCF21amur1Lw/ia2G3FqBO6NTMP4bn2NlMONiL2RbPlNeb7Y0ENA== 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=g1nbSuWV; 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 A753A606A332 for ; Thu, 3 Dec 2026 19:00:06 +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=g1nbSuWV Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D3831F00931; Thu, 3 Dec 2026 19:00:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796324406; bh=vhZUD7x7zQG9tmJxeveuemp1u0wBNpd0VFDJDuNnwbI=; h=Date:To:From:In-Reply-To:References:Subject; b=g1nbSuWVeR5hTjjSNrXLZ3DcrdkCAv1qjzTtAopJ1/W2aegv2ijx1G+sCkO2sqr0A DkgSos9obMP6b8oTPyszvnWLNvgUbnIg4jRZs5+v1bHDUKJGi2d9ql8cx/kzhqg9Ft lsfxnbqSwY0gRIzptmKaIRGTjLw2Yfwvl3LvoBEU= Date: Thu, 03 Dec 2026 11:00:05 -0800 To: mm-commits@vger.kernel.org,mason@kernel.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261125-hugetlb_fixes_2-v1-13-db27fd2f71a8@kernel.org> References: <20261125-hugetlb_fixes_2-v1-13-db27fd2f71a8@kernel.org> Subject: [to-be-updated] mm-hugetlb-unshare-pmds-of-a-split-vma-if-allocating-its-lock-fails.patch removed from -mm tree Message-Id: <20261203190006.5D3831F00931@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 quilt patch titled Subject: mm/hugetlb: unshare PMDs of a split VMA if allocating its lock fails has been removed from the -mm tree. Its filename was mm-hugetlb-unshare-pmds-of-a-split-vma-if-allocating-its-lock-fails.patch This patch was dropped because an updated version will be issued ------------------------------------------------------ From: Chris Mason Subject: mm/hugetlb: unshare PMDs of a split VMA if allocating its lock fails Date: Wed, 25 Nov 2026 23:33:11 +0100 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. [david@kernel.org: return early if the original VMA has no lock, adjust comment and description] Link: https://patch.msgid.link/20261125-hugetlb_fixes_2-v1-13-db27fd2f71a8@kernel.org Fixes: 131a79b474e9 ("hugetlb: fix vma lock handling during split vma and range unmapping") Signed-off-by: Chris Mason Signed-off-by: David Hildenbrand (Arm) Signed-off-by: Andrew Morton Cc: Muchun Song Cc: Oscar Salvador Cc: Jinmeng Zhou Cc: Hongfu Li Cc: Andrea Arcangeli Cc: Naoya Horiguchi Cc: Hugh Dickins Cc: Baolin Wang Cc: Dave Airlie Cc: Vivek Kasireddy Cc: Gerd Hoffmann Cc: Mike Rapoport Cc: Mel Gorman Cc: Dave McCracken Cc: Andy Whitcroft Cc: Adam Litke Cc: Lorenzo Stoakes Cc: Rik van Riel Cc: Liam R. Howlett Cc: Vlastimil Babka Cc: Harry Yoo Cc: Jann Horn Cc: Lance Yang Cc: James Houghton Cc: Yang Shi Cc: Suren Baghdasaryan Cc: Shakeel Butt Cc: Pedro Falcato 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: Wanpeng Li Cc: Andi Kleen Cc: Kenneth W Chen Cc: Michal Hocko Cc: David Rientjes Cc: Joern Engel Cc: Jonathan Corbet Cc: Shuah Khan Cc: Randy Dunlap Cc: Aneesh Kumar K.V Cc: KAMEZAWA Hiroyuki Cc: Kiryl Shutsemau Cc: Sasha Levin Cc: Guillaume Morin Cc: Jason Gunthorpe Cc: luojiajun Cc: Josef Bacik Cc: Daehyeon Ko <4ncienth@gmail.com> Cc: Ackerley Tng Cc: Jiaqi Yan Cc: 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(-) --- a/include/linux/hugetlb.h~mm-hugetlb-unshare-pmds-of-a-split-vma-if-allocating-its-lock-fails +++ a/include/linux/hugetlb.h @@ -274,7 +274,8 @@ long hugetlb_change_protection(struct vm 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_reserva { } -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 */ --- a/mm/hugetlb.c~mm-hugetlb-unshare-pmds-of-a-split-vma-if-allocating-its-lock-fails +++ a/mm/hugetlb.c @@ -4889,7 +4889,8 @@ static int hugetlb_vm_op_split(struct vm 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 @@ -4900,8 +4901,13 @@ void hugetlb_split(struct vm_area_struct * 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; @@ -4920,6 +4926,15 @@ void hugetlb_split(struct vm_area_struct 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) --- a/mm/vma.c~mm-hugetlb-unshare-pmds-of-a-split-vma-if-allocating-its-lock-fails +++ a/mm/vma.c @@ -590,7 +590,7 @@ __split_vma(struct vma_iterator *vmi, st */ 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; --- a/tools/testing/vma/include/stubs.h~mm-hugetlb-unshare-pmds-of-a-split-vma-if-allocating-its-lock-fails +++ a/tools/testing/vma/include/stubs.h @@ -466,7 +466,8 @@ static inline void vma_adjust_trans_huge { } -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) { _ Patches currently in -mm which might be from mason@kernel.org are mm-swap-fix-large-swap-in-across-swap-file-extents.patch hugetlbfs-do-not-grow-a-sealed-file-in-mmap.patch mm-hugetlb-keep-surplus-folios-that-are-reserved.patch mm-hugetlb-fix-reservation-leak-on-min_size=-mounts.patch mm-cachestat-count-each-page-only-once.patch mm-cachestat-restart-the-walk-after-each-entry.patch percpu-queue-the-balance-work-on-an-unbound-workqueue.patch mm-vma-fix-uncharge-after-failed-stack-relocation.patch mm-mremap-apply-the-mmap-offset-limits-on-expansion.patch mm-mremap-respect-guard-gaps-on-in-place-expansion.patch mm-vma-make-brk-mappings-non-executable-under-mdwe.patch kfence-use-a-nofault-store-to-zero-the-guard-page.patch mm-filemap-update-the-folio-order-range-atomically.patch mm-userfaultfd-account-memory-allocated-for-unmap-events.patch mm-userfaultfd-drop-fork-context-reference-outside-event_wqhlock.patch mm-madvise-dont-declare-oom-for-madv_willneed-swapin.patch mm-mprotect-fix-unpaired-notifier-start-at-address-0.patch mm-hmm-refuse-secretmem-vmas-in-hmm_range_fault.patch mm-mglru-count-all-generations-as-evictable.patch mm-mglru-test-pg_lru-before-taking-a-folio-reference.patch mm-mglru-report-root-reclaim-to-memorypressure_level.patch mm-hugetlb_cgroup-track-in-use-folios-per-cgroup.patch hugetlbfs-seal-shm_hugetlb-files-against-growth.patch mm-hugetlb-resolve-protnone-faults-without-a-uffd-bit.patch a.patch