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=1796381085; b=j2hZG5oIh+34JKOxLfVkeTLD7tVHXMOdeEq6RC+fxngSqTEYUNWwjruDMr2vpaSGC8Qr sL1FEOhUg+6srtgbedu8MTb/7axjHHNWW6ftcCRLdlguT4uQd0Yij+DIlLhFILSCGxK1d FYkQZWlo42FlL2Ht1oqojieqcJyh8uLJ06Z8FP6drW7PoAVH/2nU8+636tOR5JZrSbHyt E461Q1aQHSSuo0i9r44OHDIMMc+A0XKB+gihQzf051xNicSD+M54rlKJr+6/jQpFzOVrM 7gR6FdQek8zyJaxRPHxcNHE7xW8cvh9dmziWEgXFrYslIwYzD+BAu22B1ojBNM3FEGQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381085; 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=mGFSqGsbJO8hl08JyvrV0D8h/CvY87ZZt6MP5f/wfJA=; b=XL2rBrBNdVEeelEZAwvVQx1XeGC0JerX6GxGMXhZnTIV3N6alGc6XM8lJd3q+udFrdOS iSTmtCqbrrAXeYF8IAOeTDzSSzlBicPm+7PAXoShq/JYrSLMkm4QXG3TxOznchj/CPw4C oiccay4QoC7U257aDKIu/E+X1VYeOgIsq1TNVDYsWDoO2wPx3z+7BT7QhTlP0jZr09KCm UvJNU05bpBLuf+S3b1kpSkUJ/uvier7X44s/C4/Yl8r4mk5ZlJhZQx/kCKeAUiNKt0Umu bdnLKMnKwc9ECNac0P3RDWtngiow47pU8y1v/F7DK93eqhKpd7Fvu/ljwu0jCaW3LCw== 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=jCo9f0Is; 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 99ABA606A33C; Fri, 4 Dec 2026 10:44:45 +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=jCo9f0Is Received: by smtp.kernel.org (Postfix) with ESMTPSA id E656A1F000C2; Fri, 4 Dec 2026 10:44:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381085; bh=mGFSqGsbJO8hl08JyvrV0D8h/CvY87ZZt6MP5f/wfJA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jCo9f0IsaBRTbSR4n8K6lU/ul2f7w2aNJpxWN1ikPQfx8hVTrMHhARn855atqixmO 6qr0JUsVPnG3jbkIci5J2e2F2Du7KWQgzdOd7zdlGmGD/8j+7VGQeOryKui98i9VNS +mwhWkrrdNs1FPfNSMDv8GJJjBcqUOghyCcz7Afk= 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 7.3 552/742] mm: fix missing page-table destructor in pagetable_free() Date: Fri, 4 Dec 2026 19:06:56 +0900 Message-ID: <20261204100649.818400546@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-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 @@ -3816,23 +3816,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); @@ -3925,6 +3908,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);