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=1796007133; b=Y77OaXDfwpsDpCIs+ytHTEklf/CW1tX+LyeAZhRymQM9LiQJsjT2Tuq4/L6oJ/6GbHKH Ow41+S//ESW72YzuSYfS3Ld3CVHFkFAN956P7jm5AjKSASgwenHY8uVX1IsRu+kSPRmR7 QoVM+fj1Ksq6ScuPygno14yG5ShJY06EHPzJz2dgXLQbmimmoo83ajLewA34fshfxz5P2 50bzOvmNWiwx9b0qoSL9JYW7PulCPD3PMymb24GsTEVQTq0jOhTND+7vynoVD8uYlNRvG t5Q0R+CzgP11+ekwt8vvQoG/UVRE4BCHN8Y6UOSDDdy6fCDWIljnleZpglmJ9QsvlAA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796007133; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=KlUIKxjLwEC4UdjufphKRuH9INmc9q/l+izgLf3oRUk=; b=WRCxlnLZgjWJgUZjmtA8OKxbOKb/D6X1yJLw7JsFRB5DTJ6WLFdjuB7XNr/LGQ7Z27bv gSyTT3/sa18KrdZTWSqOFFwLeF6/GizH4RtMu0l0HBPTOiC+/jGAhyS7uFuB9pCbFGY9m Rct4ZuD98L8f3IGvD404PdhgrcHyRvdHNFg0jO30HCUlZ3VXazU2ZOWgo2oXXFo0st8vx g9br9TOI791ugOH+JsnvHFsCUSQzXOoh6J4KDveY6mIjWxMVhwNfsNW8YxXN+iSLdeJX6 9s53W6k4ABfZK5/rA7AuhSch3WEhmEFWmAkS9FKgkAZ+RpvnYGKob7y+aGEkq3GwBzw== 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=PVdKb9Xq; 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 BE5A9606A325 for ; Mon, 30 Nov 2026 02:52:13 +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=PVdKb9Xq Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC95E1F000C1; Mon, 30 Nov 2026 02:52:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796007132; bh=KlUIKxjLwEC4UdjufphKRuH9INmc9q/l+izgLf3oRUk=; h=Date:To:From:In-Reply-To:References:Subject; b=PVdKb9XqN5rAmSvhZRhaLkqefq43m6AuRJk0aqoBgMZDIuqSqnNH+C7nbjsSoZNFe v7UXR9c8R9Fvwn7ElP27MlScfIDVRE+x+tXDJE2saP03va6cpeBdHiOLvRzYcGZedI 6q8PX6Ey09/kO2MVVatux7X4WRSG4RdxZ7FtYxSg= Date: Sun, 29 Nov 2026 18:52:12 -0800 To: mm-commits@vger.kernel.org,david@kernel.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261125-hugetlb_fixes_2-v1-10-db27fd2f71a8@kernel.org> References: <20261125-hugetlb_fixes_2-v1-10-db27fd2f71a8@kernel.org> Subject: + mm-hugetlb-only-check-pmd-table-sharing-for-pmd-sized-folios.patch added to mm-new branch Message-Id: <20261130025212.CC95E1F000C1@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: only check PMD table sharing for PMD-sized folios has been added to the -mm mm-new branch. Its filename is mm-hugetlb-only-check-pmd-table-sharing-for-pmd-sized-folios.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-hugetlb-only-check-pmd-table-sharing-for-pmd-sized-folios.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next 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: only check PMD table sharing for PMD-sized folios Date: Wed, 25 Nov 2026 23:33:08 +0100 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. Link: https://patch.msgid.link/20261125-hugetlb_fixes_2-v1-10-db27fd2f71a8@kernel.org Fixes: ca1a47cd3f5f ("mm/hugetlb: fix hugetlb_pmd_shared()") Signed-off-by: David Hildenbrand (Arm) Signed-off-by: Andrew Morton Reported-by: Chris Mason Reviewed-by: Muchun Song (ByteDance) Cc: Oscar Salvador Cc: Jinmeng Zhou Cc: Hongfu Li Cc: Andrea Arcangeli Cc: Mike Kravetz 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: Wanpeng Li Cc: Jason Gunthorpe Cc: luojiajun Cc: Josef Bacik Cc: Daehyeon Ko <4ncienth@gmail.com> Cc: Ackerley Tng Cc: "Oscar Salvador (SUSE)" Cc: Jiaqi Yan Cc: fs/proc/task_mmu.c | 6 ++---- include/linux/hugetlb.h | 16 ++++++++++++++++ mm/mempolicy.c | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) --- a/fs/proc/task_mmu.c~mm-hugetlb-only-check-pmd-table-sharing-for-pmd-sized-folios +++ a/fs/proc/task_mmu.c @@ -1211,8 +1211,7 @@ static int smaps_hugetlb_range(pte_t *pt 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)); @@ -2132,8 +2131,7 @@ static int pagemap_hugetlb_range(pte_t * 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)) --- a/include/linux/hugetlb.h~mm-hugetlb-only-check-pmd-table-sharing-for-pmd-sized-folios +++ a/include/linux/hugetlb.h @@ -1386,6 +1386,22 @@ static inline bool hugetlb_pmd_shared(pt } #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 --- a/mm/mempolicy.c~mm-hugetlb-only-check-pmd-table-sharing-for-pmd-sized-folios +++ a/mm/mempolicy.c @@ -833,7 +833,7 @@ static int queue_folios_hugetlb(pte_t *p * 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: _ Patches currently in -mm which might be from david@kernel.org are mm-hugetlb-charge-the-copy-made-at-fork-to-the-parent.patch 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 uprobes-skip-mappings-not-managed-by-core-mm.patch mm-memory-store-the-pfn-of-cow-pfnmap-mappings-in-the-anon-page-offset.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 hugetlbfs-dont-zero-poisoned-pages-in-a-hole-punch.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 fs-proc-task_mmu-dont-clear-vm_softdirty-on-hugetlb-vmas.patch mm-hugetlb-use-the-vma-lock-to-stabilize-flags-for-pmd-sharing.patch rfc-mm-hugetlb_cgroup-charge-faults-to-mm-owner.patch