[PATCH RFC v2 31/54] mm/pageattr: introduce cpa_flush_tlb_kernel_range()
From: Mike Rapoport (Microsoft)
Date: Thu Nov 26 2026 - 06:19:59 EST
Many architectures that implement set_memory_*() APIs flush the TLB after a
page table update with flush_tlb_kernel_range() for the range of the
request.
Add cpa_flush_tlb_kernel_range() helper for their arch_cpa_flush() hooks.
When to flush and whether to flush more than the request stays up to the
architecture.
LoongArch, ARM, powerpc, riscv and arm64 will use it when they switch to
the CPA core.
Signed-off-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
---
include/linux/pageattr.h | 1 +
mm/pageattr.c | 8 ++++++++
2 files changed, 9 insertions(+)
diff --git a/include/linux/pageattr.h b/include/linux/pageattr.h
index 25f04e61ee85..091408ad328f 100644
--- a/include/linux/pageattr.h
+++ b/include/linux/pageattr.h
@@ -65,6 +65,7 @@ static inline unsigned long cpa_addr(struct cpa_data *cpa, unsigned long idx)
int cpa_process_fault(struct cpa_data *cpa);
int cpa_change_alias(struct cpa_data *cpa, struct cpa_data *alias);
+void cpa_flush_tlb_kernel_range(struct cpa_data *cpa);
int change_page_attr(struct cpa_data *cpa);
diff --git a/mm/pageattr.c b/mm/pageattr.c
index dcece32ebad2..852e0989dac9 100644
--- a/mm/pageattr.c
+++ b/mm/pageattr.c
@@ -14,6 +14,8 @@
#include <linux/vmalloc.h>
#include <linux/set_memory.h>
+#include <asm/tlbflush.h>
+
/*
* Serialize CPA using cpa_lock so that:
* - concurrent requests don't split or change the same large mapping at the
@@ -482,6 +484,12 @@ int change_page_attr_noflush(struct cpa_data *cpa)
return ret;
}
+void cpa_flush_tlb_kernel_range(struct cpa_data *cpa)
+{
+ flush_tlb_kernel_range(cpa->addr,
+ cpa->addr + cpa->numpages * PAGE_SIZE);
+}
+
int cpa_change_alias(struct cpa_data *cpa, struct cpa_data *alias)
{
int ret;
--
2.53.0