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=1796325248; b=R/lmOVzOZuZAirXiYy9tnRqYKIhpS45N0NolMjpIFVr9NsdZN4HnfdLRtypInTT3HZ2T fibNpoAThlwen+I3ar0QN5AORsDW3aFqyEbGHhp4jiEeBKLPrARbRLkL9kTsa1kKthBP8 bm/nI37pNd2UePdD2S+OMANSrDh6xW5BSgKtD4kYhSI6+8Sd8VON3s8eZd1F3pGUuo3xp HwtwYLaEctsvMKopvnCjH7cGon4iOzEsvjMRtJSBWCRl9yFGNSDrFYaIX/+H11/5enbjB 5WMdYkJafE+nenOEdIJHX/FsEMItYTxasPqycEsB05pVJbphDZbfnJA6yUacmWVE2kA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796325248; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=Rozx0dGJUDqCzhXvD+eGn6iyrQF0Xm7V73et8qsWMks=; b=wREcTAk4xM1o/MgUseHX9wz5bQNxQz/kHRPiNWutDA1f4tT6nyZIsmtGwyiqcAh/8FFQ wkStaR6F2CzF0kbFCUIQYzIIAKi7vp6paY/Z1yj4vXAUyEiI+xTCj0DhsXV76T7AJ4fNE +2wG5BPLT5WJIxHEMa0NZ3ZlNsR6KpKAjgu4mfQxPyjX425O750yYCKwSD8KAWirlCJye SGMEP4craLjmudWEY2a5EAaqrjnV3WocsuLNCil1eZiNvEtuRBwVerTpmZOHDxo6ZDjK5 58w+Fn53KbOOAIaIJ8hP8Oglh/nqX/I5pYn5cW8I4g3RoIGe1uVblDAc19jlWSC+OnQ== 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=B0fgnxFg; 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 13FE3606A322 for ; Thu, 3 Dec 2026 19:14:08 +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=B0fgnxFg Received: by smtp.kernel.org (Postfix) with ESMTPSA id D170B1F000CE; Thu, 3 Dec 2026 19:14:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796325247; bh=Rozx0dGJUDqCzhXvD+eGn6iyrQF0Xm7V73et8qsWMks=; h=Date:To:From:In-Reply-To:References:Subject; b=B0fgnxFgwG8WoJbf0vv03bZtuDt0UOcI2HcDaTx3S2hjB4RAwykTShjrKMYEFEQUS 2JFPUH53IlgDOiQDIMpaOqAJUZAtaynCzXFrO3iFzbJv5XPokiZ1HdBrpgqI33n7Ri iWRjM4zCLHLYY6SajudeRR+dD6rdyYWo3CKzzrcc= Date: Thu, 03 Dec 2026 11:14:07 -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-26-9bbeabb555d2@kernel.org> References: <20261203-hugetlb_fixes_2-v2-26-9bbeabb555d2@kernel.org> Subject: + mm-rmap-dont-fail-unmapping-hugetlb-folios-from-private-vmas.patch added to mm-unstable branch Message-Id: <20261203191407.D170B1F000CE@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/rmap: don't fail unmapping hugetlb folios from private VMAs has been added to the -mm mm-unstable branch. Its filename is mm-rmap-dont-fail-unmapping-hugetlb-folios-from-private-vmas.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-rmap-dont-fail-unmapping-hugetlb-folios-from-private-vmas.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/rmap: don't fail unmapping hugetlb folios from private VMAs Date: Thu, 03 Dec 2026 12:37:49 +0100 Before unmapping a hugetlb page cache folio, try_to_migrate_one() and try_to_unmap_poisoned_hugetlb_one() try to unshare the PMD table, which requires the hugetlb VMA lock in write mode. As we already hold the i_mmap_rwsem, we can only trylock it, and give up if that fails. Since private hugetlb VMAs have a VMA lock as well, the trylock can also fail on private VMAs, for example while another thread is faulting in that VMA. PMD table sharing does not apply in private VMAs, so there is nothing to unshare and we fail for no reason: migration fails more often, and memory failure might leave a poisoned folio mapped. Let's fix it by only taking the VMA lock and trying to unshare if PMD tables can be shared. Fortunately, we can drop the anon folio checks now. This has low urgency, as it requires racing with, for example, a page fault in the private VMA, and migration is usually retried. Link: https://patch.msgid.link/20261203-hugetlb_fixes_2-v2-26-9bbeabb555d2@kernel.org Fixes: bf4916922c60 ("hugetlbfs: extend hugetlb_vma_lock to private VMAs") Signed-off-by: David Hildenbrand (Arm) Signed-off-by: Andrew Morton 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: Chris Mason Cc: Jiaqi Yan Cc: mm/rmap.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) --- a/mm/rmap.c~mm-rmap-dont-fail-unmapping-hugetlb-folios-from-private-vmas +++ a/mm/rmap.c @@ -2049,7 +2049,7 @@ static bool try_to_unmap_poisoned_hugetl * acquiring vma_lock BEFORE i_mmap_rwsem. We can only try lock here and * fail if unsuccessful. */ - if (!folio_test_anon(folio)) { + if (__vma_shareable_lock(vma)) { struct mmu_gather tlb; VM_WARN_ON_ONCE(!(flags & TTU_RMAP_LOCKED)); @@ -2580,8 +2580,6 @@ static bool try_to_migrate_one(struct fo PageAnonExclusive(subpage); if (folio_test_hugetlb(folio)) { - bool anon = folio_test_anon(folio); - /* * huge_pmd_unshare may unmap an entire PMD page. * There is no way of knowing exactly which PMDs may @@ -2601,7 +2599,7 @@ static bool try_to_migrate_one(struct fo * i_mmap_rwsem. We can only try lock here and * fail if unsuccessful. */ - if (!anon) { + if (__vma_shareable_lock(vma)) { struct mmu_gather tlb; VM_BUG_ON(!(flags & TTU_RMAP_LOCKED)); _ 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