[PATCH RFC v10 17/22] arm64: kpkeys: Ensure the linear map can be modified
From: Kevin Brodsky
Date: Mon Nov 09 2026 - 11:08:58 EST
When the kpkeys_hardened_pgtables feature is enabled, we need to be
able to modify attributes (specifically the pkey/POIndex) in the
linear map at page granularity.
Add the appropriate check to can_set_direct_map() on the same
principle as rodata_full and other features.
kpkeys_hardened_pgtables currently requires the linear map to be
fully PTE-mapped, so we also need to ensure that force_pte_mapping()
returns true, like for DEBUG_PAGEALLOC.
Both functions can be called very early, before POE is actually
detected, so the early_enabled() helper is used.
Reviewed-by: Yeoreum Yun <yeoreum.yun@xxxxxxx>
Signed-off-by: Kevin Brodsky <kevin.brodsky@xxxxxxx>
---
arch/arm64/mm/mmu.c | 2 +-
arch/arm64/mm/pageattr.c | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index a61ea65bd496..c1e3260bd0db 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -781,7 +781,7 @@ static inline bool force_pte_mapping(void)
const bool bbml3 = system_capabilities_finalized() ?
system_supports_bbml3() : cpu_supports_bbml3();
- if (debug_pagealloc_enabled())
+ if (debug_pagealloc_enabled() || kpkeys_hardened_pgtables_early_enabled())
return true;
if (bbml3)
return false;
diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c
index 7143bb2dfecd..35f3e8ab0baa 100644
--- a/arch/arm64/mm/pageattr.c
+++ b/arch/arm64/mm/pageattr.c
@@ -101,7 +101,8 @@ bool can_set_direct_map(void)
* Realms need to make pages shared/protected at page granularity.
*/
return rodata_full || debug_pagealloc_enabled() ||
- arm64_kfence_can_set_direct_map() || is_realm_world();
+ arm64_kfence_can_set_direct_map() || is_realm_world() ||
+ kpkeys_hardened_pgtables_early_enabled();
}
static int update_range_prot(unsigned long start, unsigned long size,
--
2.56.0