From nobody Sat Feb 7 05:57:35 2026 Received: from mail-dy1-f169.google.com (mail-dy1-f169.google.com [74.125.82.169]) (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 C3889292B44 for ; Thu, 5 Feb 2026 01:35:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770255349; cv=none; b=OEZnxc0epJNc3eKMn7CkJhGhPeGWmFvFu1rF8hOhH4A9AQhTxsps16lpZ7Et5G1L47X+YJXu+QTl8QnpdrqKV1kuiBnONkcacO453VuEwK9ILs9DbcMx3fDsOoIBLBRlObaOkKSUjkOkzx+cWHrr2MWhIhmQ1Nju/YtIRA+TJ+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770255349; c=relaxed/simple; bh=a5VJa/3HQljIKgbSk3fzRur4DvUYq94MD1TqWGsXxm0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L6PUCtr5fG2ClmFdq3nfL+1Wnj6OuTkFyBHx1yP3MXbIN6Kql4doB/2lvy7XoydAPoM/Zc4fgryzsuBi+22s9ZxJyRKXVt8vVWsXz4/uqu0RnBceNyxeJEvkJCxQCqXwNQFD1TYhUuLumVJkb7eGgI1P2ModxmWmpbXCL/6leI8= 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=lNkc7bqL; arc=none smtp.client-ip=74.125.82.169 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="lNkc7bqL" Received: by mail-dy1-f169.google.com with SMTP id 5a478bee46e88-2b8397e3e09so589900eec.0 for ; Wed, 04 Feb 2026 17:35:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770255348; x=1770860148; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IW48nM3DmZSMMmpiusrL/Y8AeUwB4gdi5tKxeg6LSPU=; b=lNkc7bqLQYVgWfFF4qm0yYzAD5WimVygohG8cVqygqeRtA3/ghD+s7+HDBVshT9MHp a1BGs4D3yfIgfhIBQl8JmdecowAxcORi+m+rOHLs5sSgaX/xIqvQvSyqi9EoppuU/2G3 UmItM6GmISlvL46c/XfnxH2QWvChqZLisOqhkuXHXv2q7vJUfkAOGewNKSp7BoTGCnlX zeHdW9ZJPNtGd/6mghf3E401p7IJlCnJ1DAHmEmglQZmwacKEhFbjEbop3abwCiR0K7i dzeX4WYclNIHHHWKbJ8ImuA2l0EdnwzDPYzLMzp1jhKrZQL1RBZPPtvRa1ky+gFk+DNZ t4kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770255348; x=1770860148; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=IW48nM3DmZSMMmpiusrL/Y8AeUwB4gdi5tKxeg6LSPU=; b=NICwkFXDVXTz+YrvX7wbrCACqQ7SovQQ56sK/B9dZd5z9fyAwWNIwXQaQfAgQDFGYw 4Jj7UYnCaUzrTpzw0RUy4ZHC5PtiNsT5dFZY7Vs23ahJFLON243XiMF2MsWNVBh4j99G h9OJZOfFKWgHz8PdGhpU7ycrBUrNYhFmjXrwy1ULRlfF1HbSJdcV8iRG3n2tLNuRik4F dI4C17fSo+s6qMeplvopK66c8FTL12ULP4OGo1+H56TM2B6LPjBKQEDLdUTYQv1Oy06j yXm9gpAWkc+0GRiDxLTYmysjzVAJo0TnL1o11EfOQzTvf+ao/fCurOicaSQBMb9VP8ni tHbA== X-Gm-Message-State: AOJu0Yy2wnYTxGWHJSuimgPvz72mTjm+tiyfpHZVcpOEGwuGi6bIXGIU hAXW+sAmKMU55jpiDpGL/O1mH1x1NOu+xHxWvZYUwz17TFZTOTY3qgcQ/sM+gQ== X-Gm-Gg: AZuq6aKNEfFcxRqGfCM2fnratdXurG9bV7n3HJQ8WWeNColQqtJCZIdwY3Rs+WW+NiR 14LUvWLxeEv8SZOQsSOvM1/oN3Nra52LhP1gxDNGElocqNqTg76EGN5t0KgKfKCd0zoayMuLmwT ddrYgSd8xk6dSp/FmiGVLX6ZV+HKWQEcTU35wN5wFlBPTdmiKa2IUDUgOoOa+5r/gxarytL1aXi ihqUDCM4UEftgkGruycmpMYOoOmSYfu2bp6e2jmbbRPRiM0stzeSsrYmNgmLzROoHbtKfwa8vih z/eSJFB9bSDoUI0GK+ji6Viltu8ll2kIRMbxmtok2Q4ZVsE80CmsVzByIxT9keqgQEsGSZ4j9R6 TDmg3lFBIbYYys05o/UIhrWTT6Pf5s+nmcD+dxegWZaRBnQVOLdVRq2IbxL+HTaXmNb9buA9FrN vzhmd342KYzlSZ/cEEWW75PmzRvcIEUyZJOUx9yrU2olQUcRrDDM3Qfw== X-Received: by 2002:a05:7301:2f8c:b0:2ae:533d:19ee with SMTP id 5a478bee46e88-2b8329e39a7mr2414062eec.21.1770255348163; Wed, 04 Feb 2026 17:35:48 -0800 (PST) Received: from fedora (c-67-164-59-41.hsd1.ca.comcast.net. [67.164.59.41]) by smtp.googlemail.com with ESMTPSA id a92af1059eb24-126f4e0f98asm3424982c88.5.2026.02.04.17.35.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Feb 2026 17:35:47 -0800 (PST) From: "Vishal Moola (Oracle)" To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, "Mike Rapoport (Microsoft)" , Dave Hansen Cc: akpm@linux-foundation.org, "Matthew Wilcox (Oracle)" , Andy Lutomirski , Peter Zijlstra , "Vishal Moola (Oracle)" , Dave Hansen Subject: [PATCH v4 1/4] mm: Add address apis for ptdescs Date: Wed, 4 Feb 2026 17:35:24 -0800 Message-ID: <20260205013527.322157-2-vishal.moola@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260205013527.322157-1-vishal.moola@gmail.com> References: <20260205013527.322157-1-vishal.moola@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Architectures frequently only care about the address associated with a page table. The current ptdesc api forced callers to acquire a ptdesc to use them. Add more apis to abstract ptdescs away from architectures that don't need the descriptor. This patch adds pgtable_alloc() and pgtable_free() to operate on the underlying addresses associated with page table descriptors, similar to get_free_pages() and free_pages(). The allocations will be zeroed since theres no reason to want a page table with stale data. Suggested-by: Dave Hansen Signed-off-by: Vishal Moola (Oracle) --- include/linux/mm.h | 4 ++++ mm/memory.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index f8a8fd47399c..3f3000567823 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3419,6 +3419,10 @@ static inline void __pagetable_free(struct ptdesc *p= t) __free_pages(page, compound_order(page)); } =20 +unsigned long pgtable_alloc_addr_noprof(gfp_t gfp, unsigned int order); +#define pgtable_alloc_addr(...) alloc_hooks(pgtable_alloc_addr_noprof(= __VA_ARGS__)) +void pgtable_free_addr(const void *addr); + #ifdef CONFIG_ASYNC_KERNEL_PGTABLE_FREE void pagetable_free_kernel(struct ptdesc *pt); #else diff --git a/mm/memory.c b/mm/memory.c index d6d273eb2189..96c4c4d06aa1 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -7451,6 +7451,40 @@ long copy_folio_from_user(struct folio *dst_folio, } #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */ =20 +/** + * pgtable_alloc_addr - Allocate pagetables to get an address + * @gfp: GFP flags + * @order: desired pagetable order + * + * pgtable_alloc_addr is like pagetable_alloc. This is for callers who onl= y want a + * page table's address, not its ptdesc. + * + * Return: The address associated with the allocated page table, or 0 on + * failure. + */ +unsigned long pgtable_alloc_addr_noprof(gfp_t gfp, unsigned int order) +{ + struct ptdesc *ptdesc =3D pagetable_alloc_noprof(gfp | __GFP_ZERO, order); + + if (!ptdesc) + return 0; + return (unsigned long) ptdesc_address(ptdesc); +} + +/** + * pgtable_free_addr - Free pagetables by address + * @addr: The virtual address from pgtable_alloc() + * + * This function is for callers who have the address but no ptdesc. If you + * have the ptdesc, use pagetable_free() instead. + */ +void pgtable_free_addr(const void *addr) +{ + struct ptdesc *ptdesc =3D virt_to_ptdesc(addr); + + pagetable_free(ptdesc); +} + #if defined(CONFIG_SPLIT_PTE_PTLOCKS) && ALLOC_SPLIT_PTLOCKS =20 static struct kmem_cache *page_ptl_cachep; --=20 2.52.0