From 4f5ef849c184313a2ba124ff0dd0b1545ddee217 Mon Sep 17 00:00:00 2001 From: Andre Przywara Date: Thu, 26 Jan 2023 15:27:38 +0000 Subject: [PATCH] refactor(cpufeat): enable FEAT_PAN for FEAT_STATE_CHECKED At the moment we only support FEAT_PAN to be either unconditionally compiled in, or to be not supported at all. Add support for runtime detection (ENABLE_FEAT_PAN=2), by splitting is_armv8_1_pan_present() into an ID register reading function and a second function to report the support status. That function considers both build time settings and runtime information (if needed), and is used before we PAN specific setup. Change the FVP platform default to the now supported dynamic option (=2), so the right decision can be made by the code at runtime. Change-Id: I58e5fe8d3c9332820391c7d93a8fb9dba4cf754a Signed-off-by: Andre Przywara --- common/feat_detect.c | 12 +----------- include/arch/aarch64/arch_features.h | 18 +++++++++++++++--- plat/arm/board/fvp/platform.mk | 1 + services/std_svc/sdei/sdei_intr_mgmt.c | 2 +- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/common/feat_detect.c b/common/feat_detect.c index 4b5dcd462..c51da966c 100644 --- a/common/feat_detect.c +++ b/common/feat_detect.c @@ -70,16 +70,6 @@ static void read_feat_csv2_2(void) #endif } -/*********************************************** - * Feature : FEAT_PAN (Privileged Access Never) - **********************************************/ -static void read_feat_pan(void) -{ -#if (ENABLE_FEAT_PAN == FEAT_STATE_ALWAYS) - feat_detect_panic(is_armv8_1_pan_present(), "PAN"); -#endif -} - /******************************************************************************* * Feature : FEAT_RAS (Reliability, Availability, and Serviceability Extension) ******************************************************************************/ @@ -250,7 +240,7 @@ void detect_arch_features(void) read_feat_csv2_2(); /* v8.1 features */ - read_feat_pan(); + check_feature(ENABLE_FEAT_PAN, read_feat_pan_id_field(), "PAN", 1, 3); check_feature(ENABLE_FEAT_VHE, read_feat_vhe_id_field(), "VHE", 1, 1); /* v8.2 features */ diff --git a/include/arch/aarch64/arch_features.h b/include/arch/aarch64/arch_features.h index 1af775876..bdfdc4cce 100644 --- a/include/arch/aarch64/arch_features.h +++ b/include/arch/aarch64/arch_features.h @@ -21,10 +21,22 @@ static inline bool is_armv7_gentimer_present(void) return true; } -static inline bool is_armv8_1_pan_present(void) +static inline unsigned int read_feat_pan_id_field(void) { - return ((read_id_aa64mmfr1_el1() >> ID_AA64MMFR1_EL1_PAN_SHIFT) & - ID_AA64MMFR1_EL1_PAN_MASK) != 0U; + return ISOLATE_FIELD(read_id_aa64mmfr1_el1(), ID_AA64MMFR1_EL1_PAN); +} + +static inline bool is_feat_pan_supported(void) +{ + if (ENABLE_FEAT_PAN == FEAT_STATE_DISABLED) { + return false; + } + + if (ENABLE_FEAT_PAN == FEAT_STATE_ALWAYS) { + return true; + } + + return read_feat_pan_id_field() != 0U; } static inline unsigned int read_feat_vhe_id_field(void) diff --git a/plat/arm/board/fvp/platform.mk b/plat/arm/board/fvp/platform.mk index d5e59cd25..3f1811253 100644 --- a/plat/arm/board/fvp/platform.mk +++ b/plat/arm/board/fvp/platform.mk @@ -470,6 +470,7 @@ ENABLE_FEAT_FGT := 2 ENABLE_FEAT_HCX := 2 ENABLE_FEAT_TCR2 := 2 +ENABLE_FEAT_PAN := 2 ENABLE_FEAT_VHE := 2 ENABLE_MPAM_FOR_LOWER_ELS := 2 diff --git a/services/std_svc/sdei/sdei_intr_mgmt.c b/services/std_svc/sdei/sdei_intr_mgmt.c index 9862e4f8d..3bdf4a2b6 100644 --- a/services/std_svc/sdei/sdei_intr_mgmt.c +++ b/services/std_svc/sdei/sdei_intr_mgmt.c @@ -274,7 +274,7 @@ static void sdei_set_elr_spsr(sdei_entry_t *se, sdei_dispatch_context_t *disp_ct (hcr_el2 & HCR_TGE_BIT) && (hcr_el2 & HCR_E2H_BIT); - if (is_armv8_1_pan_present() && + if (is_feat_pan_supported() && ((client_el == MODE_EL1) || (client_el == MODE_EL2 && el_is_in_host)) && ((client_el_sctlr & SCTLR_SPAN_BIT) == 0U)) {