diff --git a/bl31/aarch64/runtime_exceptions.S b/bl31/aarch64/runtime_exceptions.S index 4c1fa1a62..fbf2bcac1 100644 --- a/bl31/aarch64/runtime_exceptions.S +++ b/bl31/aarch64/runtime_exceptions.S @@ -57,8 +57,7 @@ * EL (KFH) or handles it in EL3 (FFH) based on EA routing model. */ .macro sync_and_handle_pending_serror - dsb sy - isb + synchronize_errors mrs x30, ISR_EL1 tbz x30, #ISR_A_SHIFT, 2f #if HANDLE_EA_EL3_FIRST_NS diff --git a/include/arch/aarch32/asm_macros.S b/include/arch/aarch32/asm_macros.S index 83e94caa4..3ba86e956 100644 --- a/include/arch/aarch32/asm_macros.S +++ b/include/arch/aarch32/asm_macros.S @@ -120,6 +120,14 @@ .endm #endif + /* Macro for error synchronization */ + .macro synchronize_errors + /* Complete any stores that may return an abort */ + dsb sy + /* Synchronise the CPU context with the completion of the dsb */ + isb + .endm + #if (ARM_ARCH_MAJOR == 7) /* ARMv7 does not support stl instruction */ .macro stl _reg, _write_lock diff --git a/include/arch/aarch64/asm_macros.S b/include/arch/aarch64/asm_macros.S index 44f892cf2..53c7d0b08 100644 --- a/include/arch/aarch64/asm_macros.S +++ b/include/arch/aarch64/asm_macros.S @@ -301,4 +301,25 @@ msr daifclr, #DAIF_ABT_BIT isb .endm + + /* Macro for error synchronization on exception boundries. + * With FEAT_RAS enabled, it is assumed that FEAT_IESB is also present + * and enabled. + * FEAT_IESB provides an implicit error synchronization event at exception + * entry and exception return, so there is no need for any explicit instruction. + */ + .macro synchronize_errors + /* + * This is a hot path, so we don't want to do some actual FEAT_RAS runtime + * detection here. For ENABLE_FEAT_RAS==2, its not ideal but won't hurt as + * state 2 is mostly used by configurable platforms(fvp/qemu). + */ +#if ENABLE_FEAT_RAS != 1 + /* Complete any stores that may return an abort */ + dsb sy + /* Synchronise the CPU context with the completion of the dsb */ + isb +#endif + .endm + #endif /* ASM_MACROS_S */ diff --git a/include/arch/aarch64/el3_common_macros.S b/include/arch/aarch64/el3_common_macros.S index 9c9c00f1a..b40473a4e 100644 --- a/include/arch/aarch64/el3_common_macros.S +++ b/include/arch/aarch64/el3_common_macros.S @@ -208,6 +208,10 @@ */ mov_imm x0, (SCTLR_RESET_VAL & ~(SCTLR_EE_BIT | SCTLR_WXN_BIT \ | SCTLR_SA_BIT | SCTLR_A_BIT | SCTLR_DSSBS_BIT)) +#if ENABLE_FEAT_RAS == 1 + /* If FEAT_RAS is present assume FEAT_IESB is also present */ + orr x0, x0, #SCTLR_IESB_BIT +#endif msr sctlr_el3, x0 isb .endif /* _init_sctlr */ diff --git a/lib/el3_runtime/aarch64/context.S b/lib/el3_runtime/aarch64/context.S index 894165ae0..631094f73 100644 --- a/lib/el3_runtime/aarch64/context.S +++ b/lib/el3_runtime/aarch64/context.S @@ -649,23 +649,9 @@ sve_not_enabled: 1: #endif /* IMAGE_BL31 && DYNAMIC_WORKAROUND_CVE_2018_3639 */ -/* - * This is a hot path, so we don't want to do some actual FEAT_RAS runtime - * detection here. The "esb" is a cheaper variant, so using "dsb" in the - * ENABLE_FEAT_RAS==2 case is not ideal, but won't hurt. - */ -#if IMAGE_BL31 && ENABLE_FEAT_RAS == 1 - /* ---------------------------------------------------------- - * Issue Error Synchronization Barrier to synchronize SErrors - * before exiting EL3. We're running with EAs unmasked, so - * any synchronized errors would be taken immediately; - * therefore no need to inspect DISR_EL1 register. - * ---------------------------------------------------------- - */ - esb -#else - dsb sy -#endif /* IMAGE_BL31 && ENABLE_FEAT_RAS */ +#if IMAGE_BL31 + synchronize_errors +#endif /* IMAGE_BL31 */ /* ---------------------------------------------------------- * Restore SPSR_EL3, ELR_EL3 and SCR_EL3 prior to ERET