[PATCH RFC v2 43/54] mm/pageattr: let an architecture allocate the page tables for a split

From: Mike Rapoport (Microsoft)

Date: Thu Nov 26 2026 - 06:21:39 EST


The core allocates the page table for a split with pte_alloc_one_kernel()
and pmd_alloc_one(). s390 cannot use them.

vmem_map_init() write protects the kernel image before the page allocator
is up, so a split at that time has to allocate from memblock.

A fallback to memblock in the core would not be enough. With CMMA, the
decompressor marks all memory as no-DAT, and a page has to be switched back
to DAT before it is used as a page table.

vmem_pte_alloc() and vmem_crst_alloc() do both: they fall back to memblock
and initialize the page.

Memory hot-remove frees the tables of the identity map with
vmem_free_pages(), so a segment table in the identity map has to come from
vmem_crst_alloc() rather than from pmd_alloc_one().

Let an architecture provide arch_cpa_alloc_pgtable() and
arch_cpa_free_pgtable().

There are no users yet. s390 will use them when it switches to the core.

Signed-off-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
---
include/linux/pageattr.h | 6 ++++++
mm/pageattr.c | 6 ++++--
2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/linux/pageattr.h b/include/linux/pageattr.h
index 091408ad328f..1a4e7c5dca98 100644
--- a/include/linux/pageattr.h
+++ b/include/linux/pageattr.h
@@ -111,6 +111,12 @@ static inline int arch_cpa_split_leaf(struct cpa_data *cpa,
}
#endif

+#ifndef arch_cpa_alloc_pgtable
+void *arch_cpa_alloc_pgtable(struct cpa_leaf *leaf);
+
+void arch_cpa_free_pgtable(struct cpa_leaf *leaf, void *table);
+#endif
+
#ifndef cpa_is_direct_map
static inline bool cpa_is_direct_map(unsigned long addr)
{
diff --git a/mm/pageattr.c b/mm/pageattr.c
index 2f357a8c24d2..e05281a2b169 100644
--- a/mm/pageattr.c
+++ b/mm/pageattr.c
@@ -249,7 +249,8 @@ static pte_t *cpa_lookup(struct cpa_data *cpa, unsigned long address,
return leaf->kpte;
}

-static void *arch_cpa_alloc_pgtable(struct cpa_leaf *leaf)
+#ifndef arch_cpa_alloc_pgtable
+void *arch_cpa_alloc_pgtable(struct cpa_leaf *leaf)
{
if (leaf->level == PGTABLE_LEVEL_PMD)
return pte_alloc_one_kernel(&init_mm);
@@ -257,13 +258,14 @@ static void *arch_cpa_alloc_pgtable(struct cpa_leaf *leaf)
return pmd_alloc_one(&init_mm, leaf->addr);
}

-static void arch_cpa_free_pgtable(struct cpa_leaf *leaf, void *table)
+void arch_cpa_free_pgtable(struct cpa_leaf *leaf, void *table)
{
if (leaf->level == PGTABLE_LEVEL_PMD)
pte_free_kernel(&init_mm, table);
else
pmd_free(&init_mm, table);
}
+#endif

static int should_split_large_page(struct cpa_data *cpa, struct cpa_leaf *leaf)
{

--
2.53.0