We need to check if the kpkeys_hardened_pgtables feature is going to be enabled very early during boot, to decide how to set up the linear map and how to allocate early page tables. This happens even before boot CPU features are detected.
Implement the arch_supports_kpkeys_early() helper by directly checking if the boot CPU supports POE, if it is called before boot CPU features are detected. It may also be called later, in which case we simply check the POE feature. Signed-off-by: Kevin Brodsky <[email protected]> --- arch/arm64/include/asm/cpufeature.h | 12 ++++++++++++ arch/arm64/include/asm/kpkeys.h | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 4de51f8d92cb..8722e9e62702 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -1078,6 +1078,18 @@ static inline bool cpu_has_lpa2(void) #endif } +static inline bool cpu_has_poe(void) +{ + u64 mmfr3; + + if (!IS_ENABLED(CONFIG_ARM64_POE)) + return false; + + mmfr3 = read_sysreg_s(SYS_ID_AA64MMFR3_EL1); + return cpuid_feature_extract_unsigned_field(mmfr3, + ID_AA64MMFR3_EL1_S1POE_SHIFT); +} + #endif /* __ASSEMBLER__ */ #endif diff --git a/arch/arm64/include/asm/kpkeys.h b/arch/arm64/include/asm/kpkeys.h index 7dad3532cacf..ea915f78936b 100644 --- a/arch/arm64/include/asm/kpkeys.h +++ b/arch/arm64/include/asm/kpkeys.h @@ -21,6 +21,13 @@ static inline bool arch_supports_kpkeys(void) return system_supports_poe(); } +static inline bool arch_supports_kpkeys_early(void) +{ + /* POE is a boot feature */ + return boot_capabilities_finalized() ? + system_supports_poe() : cpu_has_poe(); +} + #ifdef CONFIG_ARM64_POE static inline u64 por_set_kpkeys_context(u64 por, int ctx) -- 2.51.2
