From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 43A54CA6019 for ; Fri, 9 Oct 2026 14:15:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:To:References:Message-Id: Content-Transfer-Encoding:Cc:Date:In-Reply-To:From:Subject:Mime-Version: Content-Type:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=w5cuFqIfMY4J2ULv+vaz8/5FjRBSv9rJHt5s66GC9Lo=; b=CUF9ypjEnkdHX8QoNwtQlMpyEQ svmm/y8nncrew7z9pTXc4i9FszIvQD/AUm05xmVMsGpOk7VZMpozcL43q1Zu+cf4j9No+sk43pgs0 /Y2mvMJoaxks34w6B1lFHJLRB/v0KOkLxHNV0WqgFDvXw4dM6Kx8ZAzdlQQsU7cASZHM0cLkGwKlz 9ES13X7Ou7XWK5EpvxgKBGofQkb07f2oAb+kgMxsMQyYOYNujpC3ENWxM/96AQqFECHnDinG4SQew GggwB4xsN9u5hcUsWaXossQR8FSf+KQchO8KdlAm2F/xIugrnR8E/JvP75+Xw+YEkqO29OP48+EF0 57ULGPQA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1xFBNS-00000006R7v-2brH; Fri, 09 Oct 2026 14:15:15 +0000 Received: from out-28.mta0.migadu.com ([2001:41d0:1004:224b::1c] helo=mta0.migadu.com) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1xFBNQ-00000006R7H-1M4d for linux-arm-kernel@lists.infradead.org; Fri, 09 Oct 2026 14:15:13 +0000 X-Envelope-To: linux-arm-kernel@lists.infradead.org DKIM-Signature: a=rsa-sha256; bh=D7hfrm3qIlI4+AhECxlB2fjvQpfx6eid9hhS+USFrjU=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1791555308; v=1; x=1792160108; b=GzsHuOSMUowx9yevoszKVng0leiv6kOAe/0oogqTgR86l+317eSxtwiCtPnL1ZVBJlfSxQjQ 9xThI1aXkxB2N9MZBgeAPu2Y7w8ZWJhivbdITUf8vZ/QYa9LMJwsARb83dHIoM8bx3QQgdzKvTd ucVrSjYhkDpGQLcge4OQ6K6w= X-Envelope-To: linux-arm-kernel@lists.infradead.org Received: by smtp.migadu.com with ESMTPS id d5fd037bf9b86533; Fri, 09 Oct 2026 14:15:05 +0000 X-Mizu-Trace-ID: d5fd037bf9b86533 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3901.100.1.1.12\)) Subject: Re: [PATCH 2/4] riscv/mm: fix hotplug page-table destructor handling From: Muchun Song In-Reply-To: <87jynrs8v8.fsf@all.your.base.are.belong.to.us> Date: Fri, 9 Oct 2026 22:14:40 +0800 Cc: Muchun Song , akpm@linux-foundation.org, linux-mm@kvack.org, stable@vger.kernel.org, david@kernel.org, osalvador@suse.de, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, tglx@kernel.org, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, linux-arm-kernel@lists.infradead.org, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, linux-riscv@lists.infradead.org, agordeev@linux.ibm.com, kevin.brodsky@arm.com, bjorn@rivosinc.com, apopple@nvidia.com, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: <0E3A4E15-38DA-400D-95F2-01FFBB36304B@linux.dev> References: <20261008073021.2512665-1-songmuchun@bytedance.com> <20261008073021.2512665-3-songmuchun@bytedance.com> <87jynrs8v8.fsf@all.your.base.are.belong.to.us> To: =?utf-8?B?QmrDtnJuIFTDtnBlbA==?= X-Mailer: Apple Mail (2.3901.100.1.1.12) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261009_071512_505646_54CC3456 X-CRM114-Status: GOOD ( 15.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org > On Oct 9, 2026, at 14:09, Bj=C3=B6rn T=C3=B6pel = wrote: >=20 > Muchun Song writes: >=20 >> RISC-V uses the same memory-hotplug teardown code for the linear map = and >> vmemmap, although their page-table pages are not always allocated in = the >> same way. Late linear-map allocations run page-table constructors, = while >> vmemmap and early allocations may provide constructor-free pages. >>=20 >> The PTE path unconditionally runs the destructor, which is wrong for >> constructor-free vmemmap tables. The PMD path avoids that problem by >> using is_vmemmap as a proxy for constructor state, but that = assumption >> will no longer hold once runtime vmemmap allocations use the normal >> pgalloc helpers. >>=20 >> Page-table constructors record their state in PG_table. Centralize >> page-table freeing and use PageTable() to decide whether the = destructor >> is required. Keep reserved and constructor-free pages on their = existing >> freeing paths. >>=20 >> Fixes: c75a74f4ba19 ("riscv: mm: Add memory hotplugging support") >> Cc: stable@vger.kernel.org >> Assisted-by: LLM >> Signed-off-by: Muchun Song >> --- >> arch/riscv/mm/init.c | 29 ++++++++++++++--------------- >> 1 file changed, 14 insertions(+), 15 deletions(-) >>=20 >> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c >> index 857f9a55039c..429a0b015ec1 100644 >> --- a/arch/riscv/mm/init.c >> +++ b/arch/riscv/mm/init.c >> @@ -1486,10 +1486,19 @@ struct execmem_info __init = *execmem_arch_setup(void) >> #endif /* CONFIG_EXECMEM */ >>=20 >> #ifdef CONFIG_MEMORY_HOTPLUG >> +static void __meminit free_pagetable(struct page *page) >> +{ >> + if (PageReserved(page)) >> + free_reserved_page(page); >> + else if (PageTable(page)) >> + pagetable_dtor_free(page_ptdesc(page)); >> + else >> + pagetable_free(page_ptdesc(page)); >> +} >=20 > Is PageReserved() enought to determine if there's no dtor to run? On Yes. > rv64 your code is correct, but maybe for robustness? >=20 > | if (PageTable(page)) > | pagetable_dtor(page_ptdesc(page)); > |=20 > | if (PageReserved(page)) > | free_reserved_page(page); > | else > | pagetable_free(page_ptdesc(page)); his looks good to me as well. I'll change it in the next version. = Thanks! Muchun >=20 >=20 > Bj=C3=B6rn