linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Vishal Moola (Oracle)" <vishal.moola@gmail.com>
To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org,
	"Mike Rapoport (Microsoft)" <rppt@kernel.org>
Cc: akpm@linux-foundation.org,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Andy Lutomirski <luto@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	"Vishal Moola (Oracle)" <vishal.moola@gmail.com>,
	Dave Hansen <dave.hansen@intel.com>
Subject: [PATCH v5 1/4] mm: Add address apis for ptdescs
Date: Wed, 11 Feb 2026 11:52:30 -0800	[thread overview]
Message-ID: <20260211195233.368497-2-vishal.moola@gmail.com> (raw)
In-Reply-To: <20260211195233.368497-1-vishal.moola@gmail.com>

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.

Add pgtable_alloc_addr() and pgtable_free_addr() to operate on the
underlying addresses associated with page table descriptors, similar to
get_free_pages() and free_pages(). Zero the allocations since
theres no reason to want a page table with stale data.

Have pgtable_alloc_addr() return a void pointer. This will simplify code
for callers since they all want pointers.

Suggested-by: Dave Hansen <dave.hansen@intel.com>
Signed-off-by: Vishal Moola (Oracle) <vishal.moola@gmail.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..9b6d3d910990 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));
 }
 
+void *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 1a26947ed8cd..b9653377d647 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -7452,6 +7452,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.
+ */
+void *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 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



  reply	other threads:[~2026-02-11 19:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-11 19:52 [PATCH v5 0/4] Convert 64-bit x86/mm/pat to ptdescs Vishal Moola (Oracle)
2026-02-11 19:52 ` Vishal Moola (Oracle) [this message]
2026-02-11 20:13   ` [PATCH v5 1/4] mm: Add address apis for ptdescs Dave Hansen
2026-02-11 21:54     ` Matthew Wilcox
2026-02-11 22:18     ` Vishal Moola (Oracle)
2026-02-12  0:07       ` Vishal Moola (Oracle)
2026-02-18 20:23         ` Vishal Moola (Oracle)
2026-02-18 20:27           ` Dave Hansen
2026-02-11 19:52 ` [PATCH v5 2/4] x86/mm/pat: Convert pte code to use ptdescs Vishal Moola (Oracle)
2026-02-11 21:55   ` Matthew Wilcox
2026-02-11 22:23     ` Vishal Moola (Oracle)
2026-02-11 23:04       ` Dave Hansen
2026-02-11 19:52 ` [PATCH v5 3/4] x86/mm/pat: Convert pmd " Vishal Moola (Oracle)
2026-02-11 20:07   ` Dave Hansen
2026-02-11 21:45     ` Vishal Moola (Oracle)
2026-02-11 19:52 ` [PATCH v5 4/4] x86/mm/pat: Convert split_large_page() " Vishal Moola (Oracle)
2026-02-11 21:59   ` Matthew Wilcox
2026-02-11 22:38     ` Vishal Moola (Oracle)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260211195233.368497-2-vishal.moola@gmail.com \
    --to=vishal.moola@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=dave.hansen@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rppt@kernel.org \
    --cc=willy@infradead.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox