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=1796325250; b=bR0wI4daF1nxL7msaXB4VOg00QzAaWSmm4SaofPkOpDh0zvDgdsy5J3s0GwFJ2wc3eLP 4F62Ni3hJ/j2cTDSLllXgdiHNbnhHns1CDDgX9lVfp0qADLt13WvLYDTtCM5BHccbSb3U jMDTTEaY7c8afMgjQQoHs37kqszYoz4k+kyr2Y5jV7BkY9t9p0nDVLXgrc7AXP2f4zRGR GObyCjw0CL9HCMN2BXT2pJYmPXMwMRrxj2PDALoosUyl0mID687ZCNZg77xafI1Dhf9xA hsuV6junU43a6u+59jXlsJfBWOUZoT8nYJaOckwPglplr37BPUHSJs/9soQfj/gms+w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796325250; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=AluT4dXxH5e5z/PMW8iEK328SbeNj7Qe1XgnzqYVMVI=; b=t3eBXSb8jnNKzgJDot6hWeJe7AwXOXlj1Z8TWkpJDwB6AgjwRteY0JvYBsWhw+TzjYof khqk6GU4T65f1w2kWhJFzcxYQsWvNnLzCYNCfvkN9ug+kBQNmMAFbor+mOK5q1MI04k3T bf3D9nA7XwevJC/pncnfElswm3pasXhrWhZxSBymJnejc1cKjhjdtGC5ziwkUvrkMGlVu KFKCMoB01+CJ+uDdo6q59L9HVLx3BYpGnp0reFkw9FyzOqxpBiDR1aQlIfEVNsBjqcCVW SP6pTWBT5u+sO69zM3oGNPHfxQBcnBsbi0mcXGtKwC8vR9WLH7Gn7bfvbtrycYR3o4A== 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=M6ws51k9; 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 6FC18606A335 for ; Thu, 3 Dec 2026 19:14:10 +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=M6ws51k9 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A5C31F000C2; Thu, 3 Dec 2026 19:14:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796325250; bh=AluT4dXxH5e5z/PMW8iEK328SbeNj7Qe1XgnzqYVMVI=; h=Date:To:From:In-Reply-To:References:Subject; b=M6ws51k9mBNCEzarEryI/b7L2Aj6Em5chCOmAHBVQSRl15TfEWbIGEm8ZvSPSS44J V24vxQwAjBg8mMDb6SK7WD/0kBKgmtrSdvwjvlQOSN5miGZVvz+av53TaZWvrGR7Av Syd2EhjlZ2BJT0joqQ4ZnCbWtb93jyhzBHVAiib4= Date: Thu, 03 Dec 2026 11:14:09 -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-27-9bbeabb555d2@kernel.org> References: <20261203-hugetlb_fixes_2-v2-27-9bbeabb555d2@kernel.org> Subject: + mm-hugetlb-only-check-pmd-table-sharing-for-pmd-sized-folios.patch added to mm-unstable branch Message-Id: <20261203191410.3A5C31F000C2@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-unstable 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-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: only check PMD table sharing for PMD-sized folios Date: Thu, 03 Dec 2026 12:37:50 +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/20261203-hugetlb_fixes_2-v2-27-9bbeabb555d2@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: 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 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 @@ -1216,8 +1216,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)); @@ -2140,8 +2139,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-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