[PATCH RFC v2 30/54] mm/pageattr: introduce arch_cpa_can_split()

From: Mike Rapoport (Microsoft)

Date: Thu Nov 26 2026 - 06:19:55 EST


Currently CPA core presumes that the split of a large mapping is always
possible. After deciding to split a large mapping, core drops the locks,
allocates a new page table and calls arch_cpa_split_leaf().

If an architecture does not support splitting large mappings, the only way
for it to inform the core is to fail arch_cpa_split_leaf().

arch_cpa_split_leaf() only updates the page tables, and normally shouldn't
fail. A failure there means something went terribly wrong, so having it
check if splits are supported at all would mix capability and corner case
checks.

Besides, if an architecture does not support splitting, the locks and
allocation dance would be there for nothing.

Add arch_cpa_can_split() and fail a request that needs a split the
architecture cannot do before the allocation, with a warning.

By default an architecture cannot split large mappings.

An architecture that can split must override both arch_cpa_can_split() and
arch_cpa_split_leaf().

Since x86 can split all large mappings, hardwire its override of
arch_cpa_can_split() to true.

Signed-off-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
---
arch/x86/include/asm/pageattr.h | 7 ++++++-
include/linux/pageattr.h | 8 +++++++-
mm/pageattr.c | 3 +++
3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/pageattr.h b/arch/x86/include/asm/pageattr.h
index dea7141c3713..8a3e2a35211d 100644
--- a/arch/x86/include/asm/pageattr.h
+++ b/arch/x86/include/asm/pageattr.h
@@ -14,7 +14,12 @@ pgprot_t arch_cpa_new_prot(struct cpa_data *cpa, struct cpa_leaf *leaf);

int arch_cpa_split_leaf(struct cpa_data *cpa, struct cpa_leaf *leaf,
void *table);
-#define arch_cpa_split_leaf arch_cpa_split_leaf
+static inline bool arch_cpa_can_split(struct cpa_data *cpa,
+ struct cpa_leaf *leaf)
+{
+ return true;
+}
+#define arch_cpa_can_split arch_cpa_can_split

int arch_cpa_process_fault(struct cpa_data *cpa);
#define arch_cpa_process_fault arch_cpa_process_fault
diff --git a/include/linux/pageattr.h b/include/linux/pageattr.h
index f8b6b17e0b0b..25f04e61ee85 100644
--- a/include/linux/pageattr.h
+++ b/include/linux/pageattr.h
@@ -96,7 +96,13 @@ static inline pgprot_t arch_cpa_new_prot(struct cpa_data *cpa,
}
#endif

-#ifndef arch_cpa_split_leaf
+#ifndef arch_cpa_can_split
+static inline bool arch_cpa_can_split(struct cpa_data *cpa,
+ struct cpa_leaf *leaf)
+{
+ return false;
+}
+
static inline int arch_cpa_split_leaf(struct cpa_data *cpa,
struct cpa_leaf *leaf, void *table)
{
diff --git a/mm/pageattr.c b/mm/pageattr.c
index 6fb89632b679..dcece32ebad2 100644
--- a/mm/pageattr.c
+++ b/mm/pageattr.c
@@ -421,6 +421,9 @@ static int __change_page_attr(struct cpa_data *cpa)
/*
* We have to split the large page:
*/
+ if (WARN_ON_ONCE(!arch_cpa_can_split(cpa, &leaf)))
+ return -EINVAL;
+
ret = split_large_page(cpa, &leaf);
if (!ret)
goto repeat;

--
2.53.0