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=1796325233; b=uyVQ+8jRNRaHGfOQKWxw/dkDv/L/oIT/i7vB9fKXVOhqH9KmXSNxWbkgoIvTsG48Kt7J 0kyW1rYZUieTjXekkW9HFXD1EVH3r/14975zXftQGVP5ZyvxJ1LKgmHjrUi4NzH4pxoR3 B7W6j9FyfxrIOtxpjPcLF1v4NENq63SmqEFzhVcFo9JHChor9Kon1+2+RvFfHcmJ5KqWQ lCdOKq5aK2PlYHffLZRt/Nq49XOtA8o8SXKledi2RYdySS0AE+fnmAHmcYPawL+7H6P/R xNSjOm6oywsCh5aFAk3WZModPFldWVSGsLhyhp/PmzSAyBaZ7xSprNgTSOg5blvpGEA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796325233; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=WA2sH2dNnt1w30zk0mdMMJij04RRtGxeQjvyynjCvj4=; b=AhFcqBmzaKEbUTB0fncNJTnn4+HW0ytttnHIPLuRioRMotKKYvKhTU7ki0+XWDiuJ7Op Mr0HZZbTR3Ik6Bftlyu+YhLbenvOtxraGbbyKyLHJN+PMTdEFDCFHw+oPTkli0Tczn6NF c6tMkIHuUsjHr+XBP6TOJH4ybrwZBXIkMFDsVIpSF35B3A1mSkvt5b8bnlfZr8+BpCc0H 9WFN9J8EzsJ+03DkypmDlvmnlWTh/noPfG8kSK45sNJQl5TocYiycSEPkJGDn8n1CgZcl 0LuFOwCqA6NoWzi85ykDvTSw81RF60dn2Avl2ruDxTQQaOnEpXvfF2k+Ljxf5phFcbA== 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=Ho277KPv; 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 849F8606A334 for ; Thu, 3 Dec 2026 19:13:53 +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=Ho277KPv Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38E811F0092B; Thu, 3 Dec 2026 19:13:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796325233; bh=WA2sH2dNnt1w30zk0mdMMJij04RRtGxeQjvyynjCvj4=; h=Date:To:From:In-Reply-To:References:Subject; b=Ho277KPv5WJNmwlUisEdBfqai6cAESUMaWYzpCM0wy/zL0Z/oivzbZjSB2QWIvmQg oAYDUS9aGwCxmJUSundeaLb323BbmSjhxxqgNV/X5/O1MAe5075ZL9lwr+aU7cNq9h XGXmocU/lVm6aUsReg/gPaz2d74kKYZi1oAL4KHk= Date: Thu, 03 Dec 2026 11:13:52 -0800 To: mm-commits@vger.kernel.org,mason@kernel.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261203-hugetlb_fixes_2-v2-20-9bbeabb555d2@kernel.org> References: <20261203-hugetlb_fixes_2-v2-20-9bbeabb555d2@kernel.org> Subject: + mm-hugetlb-dont-zap-non-present-entries-when-unmapping-a-folio.patch added to mm-unstable branch Message-Id: <20261203191353.38E811F0092B@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: don't zap non-present entries when unmapping a folio has been added to the -mm mm-unstable branch. Its filename is mm-hugetlb-dont-zap-non-present-entries-when-unmapping-a-folio.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-hugetlb-dont-zap-non-present-entries-when-unmapping-a-folio.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: Chris Mason Subject: mm/hugetlb: don't zap non-present entries when unmapping a folio Date: Thu, 03 Dec 2026 12:37:43 +0100 When the owner of a private hugetlb mapping fails to allocate a folio for COW, unmap_ref_private() unmaps the old folio from the forked children, and marks them with HPAGE_RESV_UNMAPPED, so they get a SIGBUS on their next access. hugetlb_unmap_range() is supposed to only unmap that folio, but it clears non-present page table entries unconditionally. A child can silently lose its COWed folio while it is getting migrated, or a hwpoison entry or uffd poison marker, without HPAGE_RESV_UNMAPPED getting set. Consequently, it would not SIGBUS on the next access. Let's fix it by ignoring non-present entries when unmapping a folio. As the folio is locked, migration entries of that folio do not apply. This has low urgency, as it requires a failing COW allocation in the owner racing with migration or memory failure in the child. Let's not CC stable. [david@kernel.org: adjust comment and description] Link: https://patch.msgid.link/20261203-hugetlb_fixes_2-v2-20-9bbeabb555d2@kernel.org Fixes: 8c4894c6bc79 ("hwpoison, hugetlbfs: fix "bad pmd" warning in unmapping hwpoisoned hugepage") Signed-off-by: Chris Mason Signed-off-by: David Hildenbrand (Arm) Signed-off-by: Andrew Morton Reviewed-by: Muchun Song (ByteDance) 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 | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/mm/hugetlb.c~mm-hugetlb-dont-zap-non-present-entries-when-unmapping-a-folio +++ a/mm/hugetlb.c @@ -5455,6 +5455,14 @@ static void hugetlb_unmap_range(struct m */ if (unlikely(!pte_present(pte))) { /* + * If we have a folio provided, we only care about + * present page table entries (folio is locked). + */ + if (folio_provided) { + spin_unlock(ptl); + continue; + } + /* * If the pte was wr-protected by uffd-wp in any of the * swap forms, meanwhile the caller does not want to * drop the uffd-wp bit in this zap, then replace the _ 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-fix-truncated-copy-result-in-uffdio_copy.patch hugetlbfs-fix-deadlock-between-hole-punching-and-memory-failure.patch hugetlbfs-recheck-the-vma-range-after-the-lock-wait.patch mm-hugetlb-dont-zap-non-present-entries-when-unmapping-a-folio.patch hugetlbfs-seal-shm_hugetlb-files-against-growth.patch mm-hugetlb-unshare-pmds-of-a-split-vma-if-allocating-its-lock-fails.patch mm-hugetlb_cgroup-track-in-use-folios-per-cgroup.patch mm-hugetlb-resolve-protnone-faults-without-a-uffd-bit.patch