From mboxrd@z Thu Jan 1 00:00:00 1970 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=1794887782; b=Bjru5IBH3F71DSV1po+3S2ppq42Orcv2K/BI3JrB0RPiRoIIrUi/Oy1jLS88RacVtQUC PE3PND058pXYUm/wa/u1ltsBbp+dKXEo0d6a4Mmx2yS7VrYZpFLbQ0uBrv+m2jjEO+mAA VsWl3B9nlZMkk9GIsWQDip30UKCqg7nrQHXHjbOx4uiq8I5kLi8Gw/FWUg9D7vaM/QO7H Frj4RT9sGTqz/wvrTbJ0qU8rJ/pC8IQDjod74MjZgMNEEaUu2ipFwMCK3kxwbrU1uUQiQ ZkkPVEGfuSnjw9p23/xLLqQhku9tuZ2cJXW1pbY77BN7FODFpoEBZDa78KV9ZM1wmuQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794887782; h=Received:DKIM-Signature:Date:To:From:Subject:Message-Id; bh=IlEktLo/CRm51V48308+Sf1VOX62XuWcbN2CluCbQeo=; b=FxvcY1E3+UHFydVV/1x+8YAr7wlNuUFSku0G/gYfEf3tExCpbFMJOCeJZsKldiUX4bEl N9LxKLIZQrEjKPGnJXhesTXGRy9UoLqQVp02smiQ9tnv7gxtBKH9qPQ9dzmepHLF7+mvL G+I/AGneQwg76Gra5L7G+D90B7/GxupiAXh6ypIUjKgI81v+uAmQJxPuRMZRtTFGREfXM vMQagqrycS0na+cK0WanHdzrktKtKfJwAZdrpWGhRJYu7t1sIIDowgsb0dek68mXZg3QS 6BQZWMvTnPsP/gynmmcxMe6E695lVCTOUAxc2TnvgSlU5udJ8AQCijyG9bWpmozZSDw== 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=YvmAvn1W; 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 84DBD606A31C; Tue, 17 Nov 2026 03:56:22 +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=YvmAvn1W Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D53C1F000C4; Tue, 17 Nov 2026 03:56:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1794887782; bh=IlEktLo/CRm51V48308+Sf1VOX62XuWcbN2CluCbQeo=; h=Date:To:From:Subject; b=YvmAvn1W9P/j35BKRTGqYncKtG1UuwvStC728keZdz/AmtoGjeOSrLnFoGRNYFkvH pohDk2uL502l0vlDicI5qjpYvrzLXq6nePstCFA8UPa1vKbuYSswxFlhzSFmaRIqOd 3ppZhVmBKbzuVq4OipZraLpdWUM6y7ju2SMcB5HQ= Date: Mon, 16 Nov 2026 19:56:21 -0800 To: mm-commits@vger.kernel.org,stable@vger.kernel.org,rppt@kernel.org, osalvador@suse.de,osalvador@kernel.org,nao.horiguchi@gmail.com, ljs@kernel.org,linmiaohe@huawei.com,joao.m.martins@oracle.com, jiaqiyan@google.com,david@kernel.org,azpijr@gmail.com, songmuchun@bytedance.com,akpm@linux-foundation.org From: Andrew Morton Subject: + mm-hugetlb_vmemmap-fix-pmd-split-tlb-flush-race.patch added to mm-new branch Message-Id: <20261117035622.0D53C1F000C4@smtp.kernel.org> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The patch titled Subject: mm/hugetlb_vmemmap: fix PMD split TLB flush race has been added to the -mm mm-new branch. Its filename is mm-hugetlb_vmemmap-fix-pmd-split-tlb-flush-race.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-hugetlb_vmemmap-fix-pmd-split-tlb-flush-race.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: Muchun Song Subject: mm/hugetlb_vmemmap: fix PMD split TLB flush race Date: Sat, 14 Nov 2026 19:25:22 +0800 Bulk HVO optimization converts vmemmap PMDs for a list of folios into PTE tables before issuing a single global TLB flush. After publishing a PTE table, a concurrent single-folio optimization can observe it and remap its PTEs before the deferred flush: CPU0 CPU1 hugetlb_vmemmap_optimize_folios() hugetlb_vmemmap_pteify_folio() vmemmap_split_pmd() pmd_populate_kernel() /* TLB flush deferred */ hugetlb_vmemmap_optimize_folio() vmemmap_pmd_entry() /* sees a PTE table */ vmemmap_optimize_pte() set_pte_at() flush_tlb_all() Modern MMUs permit overlapping TLB entries with different mapping granularities only when they translate to the same physical address. In this race, the stale PMD translation still points at the original vmemmap backing range while the new PTE can point at a shared or replacement vmemmap page for the same virtual address. Serialize deferred PMD splitting against PTE remapping with the HVO rwsem. Hold it for write across the split-only pteify batch and its TLB flush, then downgrade it before remapping the folios' vmemmap pages. This guarantees that no PTE remapper can observe a newly split PMD until the stale PMD translations have been invalidated. Link: https://lore.kernel.org/20261114112523.75208-3-songmuchun@bytedance.com Fixes: f4b7e3efaddb ("hugetlb: batch PMD split for bulk vmemmap dedup") Signed-off-by: Muchun Song Signed-off-by: Andrew Morton Reported-by: Sashiko Closes: https://sashiko.dev/#/bug/linux-fbdc3410-a4cf-457e-88e6-684380fbadfe Reviewed-by: Jose A. Perez de Azpillaga Acked-by: Oscar Salvador (SUSE) Cc: Oscar Salvador Cc: Miaohe Lin Cc: David Hildenbrand Cc: Mike Rapoport Cc: Naoya Horiguchi Cc: Joao Martins Cc: Lorenzo Stoakes Cc: Jiaqi Yan Cc: mm/hugetlb_vmemmap.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) --- a/mm/hugetlb_vmemmap.c~mm-hugetlb_vmemmap-fix-pmd-split-tlb-flush-race +++ a/mm/hugetlb_vmemmap.c @@ -311,6 +311,9 @@ static inline int vmemmap_restore_range( * is skipped, the caller must flush TLBs after all pteify operations are complete * before remapping the folio's vmemmap pages. * + * Note: The caller must hold vmemmap_remap_rwsem for write from the first + * pteify operation through the final TLB flush. + * * Return: %0 on success, negative error code otherwise. */ static int vmemmap_pteify_folio(const struct folio *folio, unsigned long flags) @@ -321,6 +324,8 @@ static int vmemmap_pteify_folio(const st .flags = flags, }; + rwsem_assert_held_write(&vmemmap_remap_rwsem); + return vmemmap_remap_range(start, end, &walk); } @@ -400,6 +405,7 @@ static int vmemmap_restore_folio(const s if (ret) return ret; + guard(rwsem_read)(&vmemmap_remap_rwsem); return vmemmap_restore_range(start, end, &vmemmap_pages, flags); } @@ -568,6 +574,7 @@ void hugetlb_vmemmap_optimize_folios(str if (list_empty(folio_list)) return; + down_write(&vmemmap_remap_rwsem); list_for_each_entry(folio, folio_list, lru) { int ret; @@ -592,12 +599,14 @@ void hugetlb_vmemmap_optimize_folios(str break; } - if (!nr_to_optimize) + if (!nr_to_optimize) { + up_write(&vmemmap_remap_rwsem); return; + } flush_tlb_all(); + downgrade_write(&vmemmap_remap_rwsem); - guard(rwsem_read)(&vmemmap_remap_rwsem); list_for_each_entry(folio, folio_list, lru) { int ret; @@ -620,6 +629,7 @@ void hugetlb_vmemmap_optimize_folios(str } flush_tlb_all(); + up_read(&vmemmap_remap_rwsem); free_vmemmap_page_list(&vmemmap_pages); } _ Patches currently in -mm which might be from songmuchun@bytedance.com are powerpc-mm-make-vmemmap_populate_compound_pages-static.patch powerpc-mm-drop-powerpc-vmemmap_can_optimize.patch mm-sparse-vmemmap-drop-vmemmap_can_optimize.patch mm-sparse-vmemmap-drop-pgmap-from-vmemmap-population-apis.patch mm-hugetlb_vmemmap-fix-hwpoison-state-races-during-optimization.patch mm-hugetlb_vmemmap-fix-pmd-split-tlb-flush-race.patch mm-hugetlb_vmemmap-fix-deadlock-during-pmd-split.patch