From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.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 17649378803 for ; Fri, 22 May 2026 09:37:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779442623; cv=none; b=DgErxU5K+a7osB+UKbNvwHKo9DMBIafVFFYohonqbWrMewTx5xNnYJfpf42tRB0SpA4iB2oA4MJkJ+ECc95afsftRD4DE4plWkGpmZL7QZPBukf+HF2XVUuyAXBY77UHpEi5nEgDmblbmXFUpaYPwr9VOpg83ltZk1Z6LtE6nu4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779442623; c=relaxed/simple; bh=5es1f/aFf3W0ucdgZQVEoZjt06b0YUWrgN0lvgFfnDc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=F18XKzvEKzhtulIpYt92FJ814ThATPNOmikdOwKeKAnogEHAQ6OQtJFuTOjxpp3cjx0d486vI5Lhfm10N23Lc36m1hcOPEDVzn6FqedoA+41Anqm2kVdTSvsML2YvYV4tVWiMQlGWekyOU82RjHYzXNN3xgnbwaNzxvDEb8+dh8= 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=gL+/l1At; arc=none smtp.client-ip=209.85.221.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="gL+/l1At" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-459bf19e87bso4245359f8f.1 for ; Fri, 22 May 2026 02:37:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779442620; x=1780047420; 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=XVo/FFXfWI6Siu3pboylHv8St2O3FHDrAkJHWhb+UAc=; b=gL+/l1At3MhbjkRh+hXDv7cRSZCcyBUanaCGkibUFg097SYzNKc+eyFcg4E5JJ8LJU pM81Rpux1M/QzV5AfX0N+ykX8yCUiBLiBD7LaDeIeMHNzmxJuOiup/Mb/O/FO9ywpM1w PqeY8QuWPBczqy4NYOj1INdvtACl+9tTX3NfCBh5CSKQpdyGIhn0qlTkf9q/d7xaFjtk lBb9Hp6Lq7p18YIiAvXn4YswPgQ9i5kdUW5CR/YTkmnECYBUGKSrcT3Yi6wIHc8J9kgb gCcGz1FBzE0j6MAl6hG1xsQ0lsByBVTNfn8iYG4+6BW4Vv2tidv/UO4X1/H5jC1WSex8 rvYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779442620; x=1780047420; 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=XVo/FFXfWI6Siu3pboylHv8St2O3FHDrAkJHWhb+UAc=; b=k6eiBmI8mDje2gFNSvZAuDsG2V7qHpeXkaVDdyXOW6jyd9gkkGb6zuzhnL41zvNT1D yQBjvPSGBiv9OG1c1giZXMe5nonycQp5X5U3B8mCnCvvWxnrnqqlX9hNBOHPT337vIwE 1TqCaK8ouAyExb+OjOmHa0O0Gl+V+u9j7MwjfCPE7DiCmlWwuqu8Yj0hE3H+6+DjwQBL JknhYyZSGe1rYMk97l7krlIbeVxCFGmdqD1s2cWeO060uoSGWYxTWXN24/ZB6hdpJ3F2 WO37aSpb3wNay8EOZ4xZreqHFbENqODPOqFqywxNZYMnictP6yxMobu31smgtYEYGsR6 fD5w== X-Forwarded-Encrypted: i=1; AFNElJ93MscvTKXF9lsPxrfhVVf241z7vKS+Vf/xxMSQG7AqlQvqBRpAoacllBYa6xmiXIYE4glCCFnzHrQJGDE=@vger.kernel.org X-Gm-Message-State: AOJu0YxXDmgyAstO75gZtDZHWvNHmIOiqXZGpPh99M0prNb42hyOCMaM 6W0Rk5YfKEA4mo2fWtormenv5qzBA+Bv0czCFs7WjPQeLcls2Zq5qVxb X-Gm-Gg: Acq92OEDKW66RTYywbiDB5B70BzJBmBLh5pmJY1x9WEZlI7CCzz2Bfqq75AGfjRykBS ZVsnhvMIEXhAvw7dnNXkO9msiwK913qKK7ybtQ8KMM55ZYzS0rL0via8Zq/tykV1Kw8RI+n4S3W b4yR2a6thPEdyvT8E2MZ1i/7fpBiDXa60kT1e/BwGgL43INeEktRXhxYiyw2e7TKVP1TLz7rwPB iIfhMUO8ZJJR1LA+/I8YmPH/3gnj3Ln971z6f+LExSt6WcyUnQoBA7iEyT4T2JhJx1hi8g2c6FT 2Qdl5HqoJNc5HoSMDD/J6LRsqtuJIwjHaO4ZSiRvJzmWEr8H8Sc5rYsoLo4FgwPUx9xmB9d170O xgzzBYt4OzfydY8X3oDuaI9QiR/8q4np1I2cajXGnITplCZi3H6DWSLn5mHestLaK7Wh9cGaTpM 1epV2gyFm6XYyBLtUMYE/1YcYeLH3pQOYibLcRYhnOMUf4BuRHu/FhJNIY3ZJekVzvKSfvLc6nQ 9Q8Gp61L4nEKqz7lgS00jm5OGxX/vXTTmYfGLqA5Q5o X-Received: by 2002:a5d:64e4:0:b0:45d:3a84:709c with SMTP id ffacd0b85a97d-45eb38d45e6mr3805787f8f.31.1779442620182; Fri, 22 May 2026 02:37:00 -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 ffacd0b85a97d-45eb6c9ba2esm2815306f8f.8.2026.05.22.02.36.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 02:36:59 -0700 (PDT) Date: Fri, 22 May 2026 10:36:57 +0100 From: Vishal Moola To: 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, 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> 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 Fri, May 22, 2026 at 08:15:09AM +0100, Catalin Marinas wrote: > On Thu, May 21, 2026 at 03:31:30PM -0700, Andrew Morton wrote: > > On Thu, 21 May 2026 13:27:30 +1000 Alistair Popple wrote: > > > Since 5e8eb9aeeda3 ("arm64: mm: always call PTE/PMD ctor in > > > __create_pgd_mapping()") page-table allocation on ARM64 always > > > calls pagetable_{pte,pmd,pud,p4d}_ctor(). This sets the page_type > > > to PGTY_table, increments NR_PAGETABLE and possible allocates a PTL. > > > However the matching pagetable_dtor() calls were never added. > > > > > > With DEBUG_VM enabled on kernel versions prior to v6.17 without > > > 2dfcd1608f3a9 ("mm/page_alloc: let page freeing clear any set page > > > type") this leads to the following warning when freeing these pages due > > > to page->page_type sharing page->_mapcount: > > > > > > BUG: Bad page state in process ... pfn:284fbb > > > page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x284fbb > > > flags: 0x17fffc000000000(node=0|zone=2|lastcpupid=0x1ffff) > > > page_type: f2(table) > > > page dumped because: nonzero mapcount > > > Call trace: > > > bad_page+0x13c/0x160 > > > __free_frozen_pages+0x6cc/0x860 > > > ___free_pages+0xf4/0x180 > > > free_pages+0x54/0x80 > > > free_hotplug_page_range.part.0+0x58/0x90 > > > free_empty_tables+0x438/0x500 > > > __remove_pgd_mapping.constprop.0+0x60/0xa8 > > > arch_remove_memory+0x48/0x80 > > > try_remove_memory+0x158/0x1d8 > > > offline_and_remove_memory+0x138/0x180 > > > > > > It can also lead to leaking the ptl allocation if ALLOC_SPLIT_PTLOCKS > > > is defined and incorrect NR_PAGETABLE stats. Fix this by calling > > > pagetable_dtor() in free_hotplug_pgtable_page() prior to freeing the > > > page to undo the effects of calling pagetable_*_ctor(). > > > > > > Fixes: 5e8eb9aeeda3 ("arm64: mm: always call PTE/PMD ctor in __create_pgd_mapping()") > > > > 6.16+, so I assume we want cc:stable here. > > > > > arch/arm64/mm/mmu.c | 1 + > > > 1 file changed, 1 insertion(+) > > > > > > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > > > index 8e1d80a7033e..0c24fe650e95 100644 > > > --- a/arch/arm64/mm/mmu.c > > > +++ b/arch/arm64/mm/mmu.c > > > @@ -1422,6 +1422,7 @@ static void free_hotplug_page_range(struct page *page, size_t size, > > > > > > static void free_hotplug_pgtable_page(struct page *page) > > > { > > > + pagetable_dtor(page_ptdesc(page)); > > > free_hotplug_page_range(page, PAGE_SIZE, NULL); > > > } > > > > I'd of course prefer that arm maintainers handle this. But > > 5e8eb9aeeda3 came via myself so convention kinda-dictates that I get to > > fix it. > > That's fine but Sashiko has some points: > > https://sashiko.dev/#/patchset/20260521032730.2104017-1-apopple@nvidia.com > > The __remove_pgd_mapping() path is fine but we also have the > vmemmap_free() path where the constructor was never called. > > We could pass around a bool dtor argument but I wonder whether we could > just check it's a pgtable page: Free_empty_tables() looks like the only way we'd ever get to free_hotplug_pgtable_page(). I'm a little curious why we can't consolidate unmap_hotplug_range() and free_empty_tables(). I.e. just fold unmap_hotplug_range() into the latter. > 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. Its not a big deal that we don't right now, but losing track of the matching allocation/free sites will become a headache when separately allocating from struct page. > } > > > -- > Catalin