From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4496D231827 for ; Fri, 29 May 2026 10:16:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780049820; cv=none; b=dEW30usZcSJDRTCKFTPzKbUTE8rulYDTJQzWuujJf3t5TVUy1mGDHDTE1hA2GRwcx3THj1xieOYpDbORezRF3sWTzDibDN7BvMDBGALsqm37Rt4anBGIuqf3CsGaAxEEz40VVr6ZgVNC60snK47EJBroMYCsH7NITvYupv47oqw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780049820; c=relaxed/simple; bh=r9Eqht+11E7yGIevR8TkAEXUN8W2iS/C+q852Oq2lnE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kTWUnVQVGhqLPFibnLIGZMAqxPfaj1/aiI+SaKc0gus98coQQ1yZ+VrUzgW0b5oE00nzNQFAkRK7F3Xrf1PR3QKT69zRg1AX61u1ONhtYM/NL5QpLrBmLek3SiJNMTSJ+KmzYNxSiduArNPHBCh5cKUOKLD3Gd1sJM3qUoAtGuk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kbwrwS63; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kbwrwS63" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4891b0786beso91806235e9.1 for ; Fri, 29 May 2026 03:16:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780049818; x=1780654618; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=PChq7lVk0cZN2Il3vhZJBZZET0uiB5y1SQ5YG4ON0U0=; b=kbwrwS63j+d5ZGdZ1Yr7Lr4VUXOKBKkrfLqcKsPj2B1tb7mnl+PEPkjskZy91PjYke Ko2HkdmibMWajz6TreK53EgfuDhtl025X0eZ+wdKDVZ60GvmQRYq6Dv9oDlLqskKLe31 oCPdEKownsOfDk2IGQ2WPbh+IUVfM8HfkTuzh1UPfiZRbqtBRslEq01avlkTZjYGiOxN K4x9dhTaWDh6sZ/cfEfLagiqFlazI/3grK+laZ24WdwnNajCvyUelD2DRDQdJhDTJcN2 zNZBFYHXwBaVRDCNG9PY28YfiSW2s7CpA7dCbUjPJSoXll+GC8SFIOrrU8cBDe8s6TPY Fzxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780049818; x=1780654618; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PChq7lVk0cZN2Il3vhZJBZZET0uiB5y1SQ5YG4ON0U0=; b=VdzOdOtIsYxCgK5BZcQistfRxAp+g3QO2cXzywKliq+2VOR994FyBgCCnlr1li195K jSAC42pIo0UlCzFhzKWCavUIexLQ1vEL7fuAVxzNHmwhNLXP+nHmuygWE3yx3UTn1NIj rabSQ7OdadX1KgaEDZ5k1axVOZttZxuBDh598no3ECE6IHhTcrwNlMyBPlnWZKiuE4S+ yO27/j48PwaOpMBKwPJs5hqJzBeGW2cjhldNu9oAWWY9WAoF4tgxDkAYE2Q8cdyC8dzu utp52elq9oUcp9ZPp5yXrhfdx5ZHfKh2D0TvZ82aqkm+rQWTNc/tl8ZMz26sQpMGV+3L WEwA== X-Forwarded-Encrypted: i=1; AFNElJ8T8f5PnihTMhE9ZHHFnfNTE6PElK9QIlcni4PUADGUaWdac6NtXLrVOGerH6LMI9rcYY/LFDvE3co1D8g=@vger.kernel.org X-Gm-Message-State: AOJu0YwpPStCTj9xoCtD0ccD2PQrr4FW/BRwyFM64lLAgqjPxCmjHptu Wc80PdCIcey/ALW4f1xeOi3EMXsqT70SnVELMVz+AraPd5Btu3iJ1Evb X-Gm-Gg: Acq92OFZpSRbOoX7qilrvvYXN93L1FHBoycfzy/innHNMZqMg5u1Uyz4NHNsuZztnb6 0PMAeEL/mFAX8V/CH5/uR91fskbZjVQ/J51p23Ez5qqIF2ikazdvC2lGs7yH0jZZg6rlzDs+duO L8Frq48XaTUCMizaWItw3yOPVmVU0mKeo4kch9Rusy0AfCB+r9UEKasdluV7qY5RHoXyohBjpi2 46exX7T8+yzmIPlrFbTKvQR/4C1GqqNxc9VrSxVOoozmbI7vMRGjNAO2pxkcPwsZYC5CuXRqrIv Yti+r8K719BV270SdOYFeowBH/r8Ny2FWqVTWRL3AIfyR+SkcPRuwaKkD89HCkDgwRp0Xzo3+0e ncRk7XfEWMxGIQ87MEz55jnLz9ihsgYgfBjgRH2ipqZ2PYBSh6iUihwhUKNtlwZ+UyuPgJ/WILY /ktDBIQtLvcsN0keanaZWmhc58ojuUu8z/CdAynWKf8QL4E/YVeCoxA8PgEeNmXfeq6Uidn/J82 S4FIOf3qfUH4mW/5gzNaaijHiuv6qLaLi5CartPsPAM X-Received: by 2002:a05:600c:1453:b0:490:50ff:7943 with SMTP id 5b1f17b1804b1-4909c0773a4mr26720375e9.5.1780049817498; Fri, 29 May 2026 03:16:57 -0700 (PDT) Received: from fedora (cpc92878-cmbg18-2-0-cust539.5-4.cable.virginm.net. [86.16.54.28]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4909c13276dsm11265945e9.36.2026.05.29.03.16.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 03:16:56 -0700 (PDT) Date: Fri, 29 May 2026 11:16:54 +0100 From: Vishal Moola To: Kevin Brodsky Cc: Matthew Wilcox , Will Deacon , Catalin Marinas , Andrew Morton , Alistair Popple , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, david@kernel.org Subject: Re: [PATCH] arm64: mm: call pagetable dtor when freeing hot-removed page tables Message-ID: References: <20260521032730.2104017-1-apopple@nvidia.com> <20260521153130.d7d5cd060f7522f894252333@linux-foundation.org> <92450154-e1ab-46e4-b23d-eaa59c9cdd3b@arm.com> <423a2656-e1a3-473e-abeb-5e301c6f7c2a@arm.com> <83d168c1-fed9-4301-8d0e-ffd133df90bb@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <83d168c1-fed9-4301-8d0e-ffd133df90bb@arm.com> On Thu, May 28, 2026 at 10:05:22AM +0200, Kevin Brodsky wrote: > On 27/05/2026 11:30, Vishal Moola wrote: > > On Wed, May 27, 2026 at 09:35:50AM +0200, Kevin Brodsky wrote: > >> On 26/05/2026 17:07, Will Deacon wrote: > >>> On Tue, May 26, 2026 at 01:54:00PM +0200, 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); > >>>> > >>>> > >>>> Strangely enough x86 calls pagetable_free() in both cases. > >>>> > >>>> My series protecting page tables with pkeys has a patch [1] to get > >>>> vmemmap to allocate page tables with pagetable_alloc(). The diff above > >>>> will require pagetable_*_ctor() to be called as well, but I think that's > >>>> the right thing to do anyway. That could be posted as a separate series, > >>>> but I'm hesitant due to the lack of NUMA awareness in pagetable_alloc(). > >>> I agree that calling the ctor()/dtor() functions consistently is the > >>> cleanest approach and that will need something like your patch to call > >>> the constructor from vmemmap_alloc_block_zero(). Trying to elide these > >>> calls for the page-table pages used to map the altmap just feels odd to > >>> me, as there isn't anything particularly special about them afaik. > >> I don't think they're really special either, most likely they just got > >> missed/ignored for the purpose of ctor/dtor like many other kernel page > >> tables (until recently). > >> > >> I'll prepare a series refactoring that code then - that will also > >> require changing most arch implementations of vmemmap_free() to call > >> pagetable_dtor_free(). > > Take a look at Matthew's series[1]. I think thats the ideal approach for > > page table accounting. He hasn't had time to iterate on it though. I > > doubt he'd mind if someone picked it up. > > I recall this series. Are you suggesting that we would no longer need to > call the ctor/dtor for kernel page tables with this approach? That > leaves us with the weird case of ptdesc_set_kernel(), which is called > from *_alloc_one() while ptdesc_clear_kernel() is called from > pagetable_free(), but that's only an optimisation so we can probably > live with it. Pretty much. The ctor/dtor do things that every single page table should be doing, so it makes sense to move them to the allocation/free sites instead. Kernel pagetables are a subset of ptdescs, so keeping those where they are makes sense IMO. > If we go down this route, I would suggest we inline what's left of the > ctor/dtor, i.e. ptlock, in {pte,pmd}_alloc_one() and {pte,pmd}_free(). > This way it is clear that everything applicable to all page tables > (kernel+user) should go directly into pagetable_{alloc,free}. > > Happy to post something along those lines (patch 2/3 of Matthew's series > + removing ctor/dtor completely) if that sounds sensible. Sounds good to me :)