lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260205013527.322157-2-vishal.moola@gmail.com>
Date: Wed,  4 Feb 2026 17:35:24 -0800
From: "Vishal Moola (Oracle)" <vishal.moola@...il.com>
To: linux-kernel@...r.kernel.org,
	linux-mm@...ck.org,
	x86@...nel.org,
	"Mike Rapoport (Microsoft)" <rppt@...nel.org>,
	Dave Hansen <dave.hansen@...ux.intel.com>
Cc: akpm@...ux-foundation.org,
	"Matthew Wilcox (Oracle)" <willy@...radead.org>,
	Andy Lutomirski <luto@...nel.org>,
	Peter Zijlstra <peterz@...radead.org>,
	"Vishal Moola (Oracle)" <vishal.moola@...il.com>,
	Dave Hansen <dave.hansen@...el.com>
Subject: [PATCH v4 1/4] mm: Add address apis for ptdescs

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 <dave.hansen@...el.com>
Signed-off-by: Vishal Moola (Oracle) <vishal.moola@...il.com>
---
 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 *pt)
 	__free_pages(page, compound_order(page));
 }
 
+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 */
 
+/**
+ * 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 only 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 = 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 = virt_to_ptdesc(addr);
+
+	pagetable_free(ptdesc);
+}
+
 #if defined(CONFIG_SPLIT_PTE_PTLOCKS) && ALLOC_SPLIT_PTLOCKS
 
 static struct kmem_cache *page_ptl_cachep;
-- 
2.52.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ