From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 1C0B9282F27 for ; Wed, 27 May 2026 09:30:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779874249; cv=none; b=rWPRixzEp5UuRnnAqRpyrhKWou0un5JokYPAhAPH+2y1XIpVoUPZkrC10YflFlqEhIni+/HhIGQx7+5KJntZD4pGZps8oup7vSXnkNad6I1g3vEhHhfNYj1Sd88u0YdkazKFQMSc/YrJh1cZAe/YmSxtsH1gtAkth0TzJyEqrTw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779874249; c=relaxed/simple; bh=0SAak8K9NCf6Sa9+7XlmCevRgtTVyup5Bn0awsmHepI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Igh2asJ/fC8Yw3H3CWCbzxsBKir3lB/074jad/C4XQDR3BuncszMb2Gu9yghCh/vA1vekfjpxkWFrsZC3mE+H2YppFLwmcMNb1TikJKZfgC7+H0vGVXRMdBFO4+0TpJe6LH+9rZj+dsxAZrFhOG6wdOw5rNQ90+Mqsbq7Hs9pJs= 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=PTOGabBW; arc=none smtp.client-ip=209.85.128.42 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="PTOGabBW" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-4891e86fabeso19418095e9.1 for ; Wed, 27 May 2026 02:30:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779874246; x=1780479046; 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=UeNp5zNgXhh9w9gen/mqg7KXpKPshnm2ZyOIypYk7Gw=; b=PTOGabBWZ+Rf0VO01BNxmOBUKMRtv5y6801vmOvnFO7hJJ0jf2+znsjjUYcZxvhmyO 2qsMgsqrlLKOWpJSTazji60RZsmZih3DNkCwPfRY4AXQdtT/pZoDTr3hBp0SNGBNmQMH dizKYnwq5f0swdVqv8NN1gkWHl67GhdWVpjt/QW/tNVZwx01Guu/PqEES+V/sFtBfKAG yuLrre29wIvetADpdMmjExpvREeKavwHx6nsQWjt1waMah3YcCTZvvuiI0gORk9GtvgV LN1A0ThyPTNnEJUqSb/kZQ4HAYicINk5qMmvB03gqb47ijv0HXv5pt8h2rfSAaaoE/gy 5hfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779874246; x=1780479046; 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=UeNp5zNgXhh9w9gen/mqg7KXpKPshnm2ZyOIypYk7Gw=; b=FZ2uJk0ZPrSR0AADRZYIoTk1nl9WgcCj0BoT9kf/vZ0F9nOmQqGaYoY0NJaXiPx/L5 uTjuOWTPvy5LSTZD3sS8bYUtIUUuEJ7bFHNLMETteCzX8GpEW/I+S0WAzWhVE9Q0T6OU R5v4yGx3VPs74MHpgSSskKygI6sAIggZhhTCFh/FphoGET9cG95SWsMNJXztvFzrDOKq W8fsEHbyBaM1gxxH9a8aDSyGb69yGQ4bwf/05AWvqXsMyWBwg5UVMF6ZVhycS6CHn1Ch oINSP74he//8vQduFNm7AG324JUsWatZVyhenB5V3pLimQjPuiH+yWvBlaCNxsKPdyL7 Wgog== X-Forwarded-Encrypted: i=1; AFNElJ8ypl/UAyGSwbmHhkSsyrCU1hsAmeE823RxYvdagQ8l9Pn88PTidy5PvOPVXWoJnP6oQvpakfHGeqfZ/HQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwHOLCalHE2YhNFW9VDqbCcKkmKI2ecDgGHPlnHZMgtSA6Nr27q C7KIW89j7uP1kV5DtjmvCVTJ8z+KMOOJ18olZib8GGJrUCmKLRDc3J5yxvWUy1Rz X-Gm-Gg: Acq92OFtcgKECAlM5O8OSSlpJ98YRw/DRDkgKLo2s68Lp5hBdSF7VF1ksWCGM4NfDug kH9zCdQezX2JiISBL8TcHMrczJ2zkTj9FHEtUPREapNV12DeSG185+EGOxJAN49mlMZsJ2Blmfs pIbSwK/i5GUuQz1lS0Gq4rOmdJwzbyQ8TvI/Ut0nbL5EtIHS+SlFl/uNWuGOccE4ddCBwlqrjMT qjTFsk0PIsPgBjLAL4Tah/rr6bHUCdAAigHDX9mTcZ8ykGWbNEIK1iWFYj2XzO244BynxqnibAp 2gXEYlTH7+aMN3v1JVl68/s207LqSmA1uY1iyq4SHRdmwjQpdZsWjoejbg8Cu8WlTuAOv++57oJ zkcAlqgtVFXT2cqlMMRUiQ7jdk0l/alK3QRCI/7FWJq/9/HpUZqsHDfufLzyAuwOYv1LVjMKV19 O178Bwc1/GUJYnMPRkxDB6hnDpm2e0Hx62gaT2D9mik82OQbKq0NCwiEVL8ImYb/WTphEFWxDee H3j9gm+02vWWymkHU+18DYr5Bn8LMVEpA== X-Received: by 2002:a05:600c:8b23:b0:48f:d5b2:7c1a with SMTP id 5b1f17b1804b1-490425aa7a4mr390195565e9.13.1779874246051; Wed, 27 May 2026 02:30:46 -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-49045282201sm427410665e9.8.2026.05.27.02.30.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2026 02:30:45 -0700 (PDT) Date: Wed, 27 May 2026 10:30:43 +0100 From: Vishal Moola To: Kevin Brodsky Cc: 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> 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: <423a2656-e1a3-473e-abeb-5e301c6f7c2a@arm.com> 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. > In the meantime we should probably use the logic above to avoid the BUG > that Alistair reported. Agreed. [1] https://lore.kernel.org/linux-mm/20251113140448.1814860-4-willy@infradead.org/