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 48F1D3E8695 for ; Wed, 27 May 2026 09:22:41 +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=1779873764; cv=none; b=X6V7llglg1y0G1xzTAA3kKQg6cGbRTuKUrke5yDu+Ee545gu4HJ/eb4AMEzUiC2AS6EduLNMlRFgRIsYx06qZj9bnVQKkxq9dm0VFWGVuvLMiEYgCmI+lj+dSlE514tnQI0pA1Q2rc/jubNmXggnmUuoRG1IHaVN9yBLZZ0NKBQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779873764; c=relaxed/simple; bh=0/4mKtc+vpsaA5q0UOfnDZ8RHHViummX+gSIRQMd6HM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=U4B0AY+qn8d5kGWWrlSWITFOHIeZ/hvgNMFjE7WvLne62qgZ1I/anDmz0pD53ASrbxnL8aeXkz734wdetK1N4f/WnMiRIaHDCFY42fhCKmQ8upT2IX0/L06TaUKc+HpketNSq/3+rSzcZHwuJWYt/k9bZTVzOCsqJIGFk0sXoVI= 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=Fq0TShGi; 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="Fq0TShGi" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-49056b9f04aso51373025e9.0 for ; Wed, 27 May 2026 02:22:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779873759; x=1780478559; 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=Zvjt27z8kXkbGkzX4jrChRm57mlyR6guk2SEu0CSjpw=; b=Fq0TShGiSPP7jrGfkbWIERD1BxS03DF7dlARGrzjyuWXJhhopejxMZE2LP/PWi8rDr NdqT+Co3scQjZ5Mkb0PyTbW9AlJKdFA8rrYdA0vSTDyC2uHi9B5ySlnUex/00LkRjcCI zcCZt9gTyXQlAQL5F68vuF5kCJSPK8ZE7fH+9Pbhpkx8gLvUf4GCSn590ib+IdMQubDJ phbH9/9WaB1mD+Qnh8/mkhCzV1RD2PSIESL31w4mwKEwnAgOfXSPrZORhm/UMWYVF5Dq vK0Rf3uWV8XLGACPRxSPp/nWAwIbXVxUKRS0KBHW0M9SjgKyw5QARYzLHQNuGYaJClIo Qbug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779873759; x=1780478559; 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=Zvjt27z8kXkbGkzX4jrChRm57mlyR6guk2SEu0CSjpw=; b=kxB0QToVWgYWopYrzPHRan0PNkqS+dpnWL0X+1eboexpjiFgBnvTdXi+1S/7MOTiIT 4oqr5D0KXHbPlupX3Sb2KIfdYn4P7nxt1H8aZu+C1AyJm0Fz2Cqtk4R8RUQMx03DLOlf 19NqXfCChv5vq9GPgGkDnFtHD+smS4cW8WLsNhZYQVMGqJumXh10RzqLpJVveTuejkA2 7EkA+yOVN9f2JJcbYpoqSILp+p28hhonpjsggWQpARSM3/SPsFktNs7xN9DUPzE2pARV U8R8xeasHaerqIKK2d3wFXpDRexoEfEcW8SsBtZTXN8j4N2tek3Hms0kqdDCLkkxT5o8 Cbuw== X-Forwarded-Encrypted: i=1; AFNElJ95KVpCwBUmx+AK5sk0tCjhXc/76JKX0k5jK7NgxemsK8zHkpc9m+1Vt6U+iTc4vw2dVxnlpzAN8bHQmmo=@vger.kernel.org X-Gm-Message-State: AOJu0Yzgxs4Lp4MFvZHo5/yMI+KyNAwhKrnRaFytpRFJ+/Rj4oyj+yOc Y0M8H4BbHyh5ccDpqllqL5vT5r1fcsx5N4jeRkUu7zkdGNVtBWmrLBxB X-Gm-Gg: Acq92OGs8EzTe3EETee7s8H7aT3CEPLBKJYcn6g3qayScXO7OZOtDrwmiXM7fZwrehf /WUqbfaTbVzOSRsvudmgid4c+hgVuhXu1mpxfPOThJZxOmCwAYQqLwHqSE+InbiRxqOdrtBsmwN rUuLaDVW1RLcaCYct1XpsmdNdozufY9w6lsmNoANsCBJRYJzDcQ4vcpfNWu8MLa5aCliAjkAVg4 UofpyG/hvXsqy0u6fMCsn3YJ7Y7qMy6Xo4xQzeEeteY5lZS2D+Tlz+yCR7uBgAxeIS3OoUC6aA2 DfVCPrtwTfIVDUKslPND/LDFRIIL2cxIfcEwfA8RuQXxVRjwU0VxCQtH5nO1lxFm+PUhRlsqIQF RMN0SXHyK42qhTPZPM9hhxDJp5Cx+ApGuAlzo02+mDobShEsYZfpB4+HSjtjlUOSKPS/34QVWon eCz6AETBk305zsD4q9/780ErxsXpnaPBhr5cdb+eRo+mzjXG+fh81z+8enW+IiaeQzwf4W0VKF1 mH+stSXw6Ro/HpMbcGpq3Xv5E1GsDHsm0bOHXA1c3nCyIWTTe3vM/k= X-Received: by 2002:a05:600c:1f90:b0:490:5e2a:dbaf with SMTP id 5b1f17b1804b1-4905e2adc0dmr212138645e9.21.1779873758884; Wed, 27 May 2026 02:22:38 -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-4907e6a1f29sm14599705e9.5.2026.05.27.02.22.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2026 02:22:38 -0700 (PDT) Date: Wed, 27 May 2026 10:22:35 +0100 From: Vishal Moola To: Kevin Brodsky Cc: "David Hildenbrand (Arm)" , Catalin Marinas , Andrew Morton , Alistair Popple , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, will@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> <1be38262-53de-4a27-9841-393e12fc1475@kernel.org> 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: On Wed, May 27, 2026 at 09:34:19AM +0200, Kevin Brodsky wrote: > 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(). If we know for sure we have the head page (which we probably do here), we should use PageTable(page). I included the folio APIs as a defensive way to ensure large order page table users don't break. We only set the type on the head page, and using a folio guarantees we're accessing that head page. This can go away as soon as someone looks at the architectures that allocate large order ptdescs. Also, most (if not all) 'pgtables' don't use ptdescs yet, but they probably should... Anyway, in this particular case, it looks like pgtable is just a name symbolizing 'page table' and not our type 'pgtable_t' anyway so I'm just rambling.