From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4FE323A7F6E for ; Wed, 27 May 2026 07:34:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779867270; cv=none; b=fpULZlri8q7U8KTC927qgQx4e+HRh9WcOLR2smMGHhp3Se/Cc73BvrHOdxr59EyqiwLfjM/6so6eDBNlR/O98gjhvB1Qy0srKZ0I3Ujkh7wgAFRhRxKFOT/nlrAhlVgKp94O7tZUeH71ALrNdjPNl3Vnefl7UqN/oKOu4aI/6i0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779867270; c=relaxed/simple; bh=HVqcxI1GFbCS7c35naKWqhplQ5379bUFtfju52VKNUI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=I1zIhP9whMvDhmLbYsTxEi7M7cXB/SNI7kUWWqKafUPCidInNn3hffLuIskSrLUOD+0z1P4Lq2Uvy6lnXLqAeq/GI5+QnlQ+kyEUopwvCy23WxKDVW1RyJJike1gU3BnMH/liUNq+QgpGgwDTAUf84+SbvNOrgTdvH/UPSwuunM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=lhpGYhy9; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="lhpGYhy9" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BCDA827DC; Wed, 27 May 2026 00:34:19 -0700 (PDT) Received: from [10.57.93.47] (unknown [10.57.93.47]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8928C3F632; Wed, 27 May 2026 00:34:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1779867264; bh=HVqcxI1GFbCS7c35naKWqhplQ5379bUFtfju52VKNUI=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=lhpGYhy9mzLM0aQ1LmEdrgC7rB9SgaM2E0euQSb2IyT0zWRqzHJdbHCQvPWYTWPEz P7TxGZIzx/4bnsXReJ1v8DM+/x5k4r9aS3DnmQY5y6dTDxqa0kFbXyRop06qe/gjVs u16UwYDXRXQBF7Yv8VbCdByU0IIzdtVpVZ2FuHmg= Message-ID: Date: Wed, 27 May 2026 09:34:19 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] arm64: mm: call pagetable dtor when freeing hot-removed page tables To: "David Hildenbrand (Arm)" , Vishal Moola , Catalin Marinas Cc: Andrew Morton , Alistair Popple , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, will@kernel.org References: <20260521032730.2104017-1-apopple@nvidia.com> <20260521153130.d7d5cd060f7522f894252333@linux-foundation.org> <92450154-e1ab-46e4-b23d-eaa59c9cdd3b@arm.com> <1be38262-53de-4a27-9841-393e12fc1475@kernel.org> From: Kevin Brodsky Content-Language: en-GB In-Reply-To: <1be38262-53de-4a27-9841-393e12fc1475@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 26/05/2026 14:31, David Hildenbrand (Arm) wrote: > On 5/26/26 13:54, Kevin Brodsky wrote: >> On 22/05/2026 11:36, Vishal Moola wrote: >>>> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c >>>> index 4c8959153ac4..9d42cbddce27 100644 >>>> --- a/arch/arm64/mm/mmu.c >>>> +++ b/arch/arm64/mm/mmu.c >>>> @@ -1441,6 +1441,9 @@ static void free_hotplug_page_range(struct page *page, size_t size, >>>> >>>> static void free_hotplug_pgtable_page(struct page *page) >>>> { >>>> + if (folio_test_pgtable(page_folio(page))) >>> This should work. >>> >>>> + pagetable_dtor(page_ptdesc(page)); >>>> + >>>> free_hotplug_page_range(page, PAGE_SIZE, NULL); >>> In the case we presumably have a page table page (ptdesc) at this >>> point, we should really be freeing it with pagetable_free() as well. >> Agreed, I think this is the right thing to do, something like: >> >> if (folio_test_pgtable(page_folio(page))) >> pagetable_dtor_free(page_ptdesc(page)); else >> free_hotplug_page_range(page, PAGE_SIZE, NULL); > That code pattern is wrong. > > folio_test_pgtable() shouldn't exist. > > In the future, something is either a pgtable or a folio, not both. > > So check the type against the page, not the folio. In other words use PageTable(page) instead? Interestingly I can see a few calls to folio_test_pgtable() across the kernel but none to PageTable(), maybe just an antipattern then? The ctor/dtor also use __folio_{set,clear}_pgtable(). - Kevin