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=1796382533; b=NF41YD2rwghWH6gXQRElhxdeQgDxSJXIXGVlVeLgYmhl04eYMmOnS1vC8Rz+SNbrO+JM 5AzGCcftjhVFgeCh7bnFNItFBC7XVYVh2Vj6E2paIOzAQMCRLJiNBJcqOB4QiiH+GPf65 PZ1yZcWPB/12VwJCIFC13GnQhFUgLRScOTLmm/nZGXVI0UtD5XTcsq7GeMDIhlACc8yLF daQW1JHSizmixPNoPMC8qNtSyCTS6xXzXnRYyqqVnG9d/RVaAqRj+cJqhsVv2AKcIGDsF PziaNAw4184298mBnBYAOwGCqZlVCu1JOFI7vtNBi4LxwIjE9IqxFxkrFUyg9MQ5Otg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382533; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=9tOs5sVODzdEUcYnDpMO1Oc/qruLip4aommARjS4EBs=; b=bXPiedv58ROde5kjIhCy1oHSmH1XkUuONx7jvHeaUMHUYa7CtdjtsHHfs6YDPUuQ0qxl jhhNSyHfiy0VaX8P3v3276v8bp2eJFN1byKoxBoR7iytJarQjzOVLbDGb14Vkx21293N2 IrS/4nMGTLdetNFjlabtdtgezCV4psWl/Sbg+AFKAXfsQCfAvf2YX+YcNAolK5jxGqZvx DDxMiYTVaLup6G5ViU74Jbk8RNwhQ7uryM+1fagpzV/iLON+nsDdNx+9THrq3MzL2nMz2 K6jsm4pWEnkZJqKZU//PeSHjPxy6EKUBLVl+O71vdwlFDzsT0ZRSyUgx736+Cbzl3VQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=WBLyd0+7; 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 06684606A335; Fri, 4 Dec 2026 11:08:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=WBLyd0+7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 545891F000C2; Fri, 4 Dec 2026 11:08:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382532; bh=9tOs5sVODzdEUcYnDpMO1Oc/qruLip4aommARjS4EBs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=WBLyd0+7zdUoZDwKhfXaswy+Ey6T0RFqANGDKiyJTvF32qdU1PMjKpZaGwICTdT6G tj6OG5BTGgjnibj3ZH5r5+ZFpsOBTxYL65RFg1uuN+0vN8JZMjc+MKZUCskRwrjJkz oh7MXliQroqZ37Uv6Vfnupx/wddHfgp2yFqBsieE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Muchun Song , Andrew Morton , "Jose A. Perez de Azpillaga" , Kevin Brodsky , Dave Hansen , "David Hildenbrand (Arm)" , Anshuman Khandual , Oscar Salvador , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Catalin Marinas , Will Deacon , Mark Rutland , Alexander Gordeev , Alistair Popple Subject: [PATCH 6.18 493/703] mm: fix missing page-table destructor in pagetable_free() Date: Fri, 4 Dec 2026 19:06:32 +0900 Message-ID: <20261204100640.915945005@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Muchun Song commit 2a700ab992286e1d3893289909ec46569a725257 upstream. Patch series "mm: Fix page-table teardown during memory hot-remove", v3. Memory hot-remove can free page-table pages allocated through paths with different constructor state. Some paths run the page-table constructor, while generic sparse-vmemmap population may not. The x86, RISC-V, and arm64 teardown paths did not handle that distinction consistently, leaving constructor/destructor accounting unbalanced. Make pagetable_free() handle any remaining constructor state before freeing a page-table page. Callers that already ran pagetable_dtor() have cleared that state, so the destructor is not run twice. The RISC-V and arm64 fixes then use this common helper for their memory-hot-remove paths. The architecture fixes depend on the common MM change in patch 1, so this remains a single series. I expect it to go through the MM tree, with review or acks from the relevant architecture maintainers. This patch (of 4): Since commit 49f599666420 ("mm: call ctor/dtor for kernel PTEs"), pte_alloc_one_kernel() runs the page-table constructor for kernel PTE tables. HVO (HugeTLB Vmemmap Optimization) uses pte_alloc_one_kernel() when splitting a PMD. Restoring the vmemmap backing pages does not collapse the PTE table, so a later memory hot-remove eventually frees it through pagetable_free() on x86-64. That releases the page without running the matching destructor and leaves NR_PAGETABLE elevated. Make pagetable_free() the common free-side primitive for page-table pages. It checks PageTable() and runs the destructor only when the constructor state is still present. Callers that explicitly ran pagetable_dtor() have already cleared PageTable(), so they are not destructed twice; pages that never ran a constructor are freed directly. Link: https://lore.kernel.org/20261023063428.3658761-1-songmuchun@bytedance.com Link: https://lore.kernel.org/20261023063428.3658761-2-songmuchun@bytedance.com Fixes: 49f599666420 ("mm: call ctor/dtor for kernel PTEs") Signed-off-by: Muchun Song Signed-off-by: Andrew Morton Reviewed-by: Jose A. Perez de Azpillaga Reviewed-by: Kevin Brodsky Acked-by: Dave Hansen Acked-by: David Hildenbrand (Arm) Reviewed-by: Anshuman Khandual Cc: Oscar Salvador Cc: Paul Walmsley Cc: Palmer Dabbelt Cc: Albert Ou Cc: Alexandre Ghiti Cc: Björn Töpel Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Rutland Cc: Alexander Gordeev Cc: Alistair Popple Cc: # bf9e4e30f353: x86/mm: use pagetable_free() Signed-off-by: Greg Kroah-Hartman --- include/linux/mm.h | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3157,23 +3157,6 @@ static inline void pagetable_free_kernel __pagetable_free(pt); } #endif -/** - * pagetable_free - Free pagetables - * @pt: The page table descriptor - * - * pagetable_free frees the memory of all page tables described by a page - * table descriptor and the memory for the descriptor itself. - */ -static inline void pagetable_free(struct ptdesc *pt) -{ - if (ptdesc_test_kernel(pt)) { - ptdesc_clear_kernel(pt); - pagetable_free_kernel(pt); - } else { - __pagetable_free(pt); - } -} - #if defined(CONFIG_SPLIT_PTE_PTLOCKS) #if ALLOC_SPLIT_PTLOCKS void __init ptlock_cache_init(void); @@ -3266,6 +3249,26 @@ static inline void pagetable_dtor(struct lruvec_stat_sub_folio(folio, NR_PAGETABLE); } +/** + * pagetable_free - Free pagetables + * @pt: The page table descriptor + * + * pagetable_free frees the memory of all page tables described by a page + * table descriptor and the memory for the descriptor itself. + */ +static inline void pagetable_free(struct ptdesc *pt) +{ + if (PageTable(ptdesc_page(pt))) + pagetable_dtor(pt); + + if (ptdesc_test_kernel(pt)) { + ptdesc_clear_kernel(pt); + pagetable_free_kernel(pt); + } else { + __pagetable_free(pt); + } +} + static inline void pagetable_dtor_free(struct ptdesc *ptdesc) { pagetable_dtor(ptdesc);