[PATCH v7 3/3] x86/mm: add set_direct_map_ro()
Xueyuan Chen
xueyuan.chen21 at gmail.com
Tue Sep 1 08:18:18 PDT 2026
Implement set_direct_map_ro() for x86 with a page-based interface. Clear
_PAGE_RW and _PAGE_DIRTY through the CPA path and let the common CPA
wrapper invalidate stale writable translations before returning.
Co-developed-by: Lance Yang <lance.yang at linux.dev>
Signed-off-by: Lance Yang <lance.yang at linux.dev>
Signed-off-by: Xueyuan Chen <xueyuan.chen21 at gmail.com>
---
arch/x86/include/asm/set_memory.h | 2 ++
arch/x86/mm/pat/set_memory.c | 10 ++++++++++
2 files changed, 12 insertions(+)
diff --git a/arch/x86/include/asm/set_memory.h b/arch/x86/include/asm/set_memory.h
index 39271a5ea925..710164ea8258 100644
--- a/arch/x86/include/asm/set_memory.h
+++ b/arch/x86/include/asm/set_memory.h
@@ -88,6 +88,8 @@ int set_pages_rw(struct page *page, int numpages);
int set_direct_map_invalid_noflush(struct page *page, unsigned int nr);
int set_direct_map_default_noflush(struct page *page, unsigned int nr);
+int set_direct_map_ro(struct page *page, unsigned int nr);
+#define set_direct_map_ro set_direct_map_ro
bool kernel_page_present(struct page *page);
extern int kernel_set_to_readonly;
diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
index a1a061d995b3..7c0cfa7acd17 100644
--- a/arch/x86/mm/pat/set_memory.c
+++ b/arch/x86/mm/pat/set_memory.c
@@ -2666,6 +2666,16 @@ int set_direct_map_default_noflush(struct page *page, unsigned int nr)
return __set_pages_p(page, nr, 0);
}
+int set_direct_map_ro(struct page *page, unsigned int nr)
+{
+ unsigned long addr = (unsigned long)page_address(page);
+
+ /* Direct-map callers are expected to pass pages without aliases. */
+ return change_page_attr_set_clr(&addr, nr, __pgprot(0),
+ __pgprot(_PAGE_RW | _PAGE_DIRTY), 0,
+ CPA_NO_CHECK_ALIAS, NULL);
+}
+
#ifdef CONFIG_DEBUG_PAGEALLOC
void __kernel_map_pages(struct page *page, int numpages, int enable)
{
--
2.47.3
More information about the linux-arm-kernel
mailing list