target/arm: Add support for FEAT_SSBS
cover target/arm: Add support for FEAT_SSBS
Add support for FEAT_SSBS, Speculative Store Bypass Safe. SSBS is an optional feature in ARMv8.0 and is mandatory in ARMv8.5.
Rebecca Cran (3):
target/arm: Add support for FEAT_SSBS, Speculative Store Bypass Safe target/arm: Enable FEAT_SSBS for "max" AARCH64 CPU target/arm: Set ID_PFR2.SSBS to 1 for "max" 32-bit CPU
target/arm/cpu.c | 4 ++ target/arm/cpu.h | 15 +++++- target/arm/cpu64.c | 5 ++ target/arm/helper-a64.c | 6 +++ target/arm/helper.c | 52 ++++++++++++++++++++ target/arm/internals.h | 6 +++ target/arm/translate-a64.c | 12 +++++ 7 files changed, 99 insertions(+), 1 deletion(-)
Signature · 1 line
2.26.2
PATCH 1/3 target/arm: Add support for FEAT_SSBS, Speculative Store Bypass Safe
Add support for FEAT_SSBS. SSBS (Speculative Store Bypass Safe) is an optional feature in ARMv8.0, and mandatory in ARMv8.5.
--- target/arm/cpu.h | 15 +++++- target/arm/helper-a64.c | 6 +++ target/arm/helper.c | 52 ++++++++++++++++++++ target/arm/internals.h | 6 +++ target/arm/translate-a64.c | 12 +++++ 5 files changed, 90 insertions(+), 1 deletion(-)
target/arm/cpu.h +14 -1
@@ -1201,6 +1201,7 @@ void pmu_init(ARMCPU *cpu);#define SCTLR_TE (1U << 30)/* AArch32 only */ #define SCTLR_EnIB (1U << 30)/* v8.3, AArch64 only */ #define SCTLR_EnIA (1U << 31)/* v8.3, AArch64 only */ +#define SCTLR_DSSBS_32 (1U << 31)/* v8.5, AArch32 only */ #define SCTLR_BT0 (1ULL << 35)/* v8.5-BTI */ #define SCTLR_BT1 (1ULL << 36)/* v8.5-BTI */ #define SCTLR_ITFSB (1ULL << 37)/* v8.5-MemTag */
@@ -1208,7 +1209,7 @@ void pmu_init(ARMCPU *cpu);#define SCTLR_TCF (3ULL << 40)/* v8.5-MemTag */ #define SCTLR_ATA0 (1ULL << 42)/* v8.5-MemTag */ #define SCTLR_ATA (1ULL << 43)/* v8.5-MemTag */ -#define SCTLR_DSSBS (1ULL << 44)/* v8.5 */ +#define SCTLR_DSSBS_64 (1ULL << 44)/* v8.5, AArch64 only */ #define CPTR_TCPAC (1U << 31)#define CPTR_TTA (1U << 20)
@@ -1245,6 +1246,7 @@ void pmu_init(ARMCPU *cpu);#define CPSR_IL (1U << 20)#define CPSR_DIT (1U << 21)#define CPSR_PAN (1U << 22) +#define CPSR_SSBS (1U << 23)#define CPSR_J (1U << 24)#define CPSR_IT_0_1 (3U << 25)#define CPSR_Q (1U << 27)
@@ -1307,6 +1309,7 @@ void pmu_init(ARMCPU *cpu);#define PSTATE_A (1U << 8)#define PSTATE_D (1U << 9)#define PSTATE_BTYPE (3U << 10) +#define PSTATE_SSBS (1U << 12)#define PSTATE_IL (1U << 20)#define PSTATE_SS (1U << 21)#define PSTATE_PAN (1U << 22)
@@ -3883,6 +3886,11 @@ static inline bool isar_feature_aa32_dit(const ARMISARegisters *id)return FIELD_EX32 (id->id_pfr0,ID_PFR0 ,DIT ) !=0 ; } +static inline bool isar_feature_aa32_ssbs (const ARMISARegisters *id) +{ +return FIELD_EX32 (id->id_pfr2,ID_PFR2 ,SSBS ) !=0 ; +} +/* * 64-bit feature tests via id registers. */
@@ -4137,6 +4145,11 @@ static inline bool isar_feature_aa64_dit(const ARMISARegisters *id)return FIELD_EX64 (id->id_aa64pfr0,ID_AA64PFR0 ,DIT ) !=0 ; } +static inline bool isar_feature_aa64_ssbs (const ARMISARegisters *id) +{ +return FIELD_EX64 (id->id_aa64pfr1,ID_AA64PFR1 ,SSBS ) !=0 ; +} +/* * Feature tests for "does this exist in either 32-bit or 64-bit?" */
target/arm/helper-a64.c +6 -0
@@ -960,6 +960,12 @@ static void cpsr_write_from_spsr_elx(CPUARMState *env, val |=CPSR_DIT ; } +/* Move SSBS to the correct location for CPSR */ +if (val &PSTATE_SSBS ) { + val &= ~PSTATE_SSBS ; + val |=CPSR_SSBS ; + } + mask =aarch32_cpsr_valid_mask (env->features, \ &env_archcpu (env)->isar);cpsr_write (env, val, mask, CPSRWriteRaw);
target/arm/helper.c +52 -0
88 lines not on this page · raw message
target/arm/internals.h +6 -0
@@ -1231,6 +1231,9 @@ static inline uint32_t aarch32_cpsr_valid_mask(uint64_t features,if (isar_feature_aa32_dit (id)) { valid |=CPSR_DIT ; } +if (isar_feature_aa32_ssbs (id)) { + valid |=CPSR_SSBS ; + }return valid; }
@@ -1252,6 +1255,9 @@ static inline uint32_t aarch64_pstate_valid_mask(const ARMISARegisters *id)if (isar_feature_aa64_dit (id)) { valid |=PSTATE_DIT ; } +if (isar_feature_aa64_ssbs (id)) { + valid |=PSTATE_SSBS ; + }if (isar_feature_aa64_mte (id)) { valid |=PSTATE_TCO ; }
target/arm/translate-a64.c +12 -0
@@ -1712,6 +1712,18 @@ static void handle_msr_i(DisasContext *s, uint32_t insn,/* There's no need to rebuild hflags because DIT is a nop */ break ; +case 0x19 :/* SSBS */ +if (!dc_isar_feature (aa64_ssbs, s)) { + goto do_unallocated; + } +if (crm &1 ) { +set_pstate_bits (PSTATE_SSBS ); + }else { +clear_pstate_bits (PSTATE_SSBS ); + } +/* Don't need to rebuild hflags since SSBS is a nop */ +break ; +case 0x1e :/* DAIFSet */ t1 =tcg_const_i32 (crm);gen_helper_msr_i_daifset (cpu_env, t1);
Signature · 1 line
2.26.2
Re: [PATCH 1/3] target/arm: Add support for FEAT_SSBS, Speculative Store Bypass Safe
target/arm/helper-a64.c static void cpsr_write_from_spsr_elx(CPUARMState *env, · line 967
Quoted 9 lines · Rebecca Cran
target/arm/helper-a64.c +5
-0@@ -960,6 +960,12 @@ static void cpsr_write_from_spsr_elx(CPUARMState *env, val |=CPSR_DIT ; } +/* Move SSBS to the correct location for CPSR */ +if (val &PSTATE_SSBS ) { + val &= ~PSTATE_SSBS ; + val |=CPSR_SSBS ; + }
Incorrect. SPSR_ELx leaves this at the same position as CPSR: bit 23.
target/arm/helper.c static void take_aarch32_exception(CPUARMState *env, int new_mode, · line 9525
Quoted 9 lines
target/arm/helper.c +8
-0} + +if (cpu_isar_feature (aa32_ssbs,env_archcpu (env))) { +if (env->cp15.sctlr_el[new_el] &SCTLR_DSSBS_32 ) { + env->uncached_cpsr |=CPSR_SSBS ; + }else { + env->uncached_cpsr &= ~CPSR_SSBS ; + } + }
Hoist this so that it can be shared with the HYP branch (hsctlr is mapped to sctlr_el[2] and HYP maps to el=2).
target/arm/helper.c static uint32_t cpsr_read_for_spsr_elx(CPUARMState *env) · line 9854
Quoted 10 lines
target/arm/helper.c +6
-0@@ -9809,6 +9846,13 @@ static uint32_t cpsr_read_for_spsr_elx(CPUARMState *env) ret &= ~CPSR_DIT ; ret |=PSTATE_DIT ; } + +/* Move SSBS to the correct location for SPSR_ELx */ +if (ret &CPSR_SSBS ) { + ret &= ~CPSR_SSBS ; + ret |=PSTATE_SSBS ; + }
Incorrect, like in cpsr_write_from_spsr_elx.
Quoted 9 lines
target/arm/translate-a64.c +1
-0@@ -1712,6 +1712,18 @@ static void handle_msr_i(DisasContext *s, uint32_t insn,/* There's no need to rebuild hflags because DIT is a nop */ break ; +case 0x19 :/* SSBS */
target/arm/translate-a64.c static void handle_msr_i(DisasContext *s, uint32_t insn, · line 1725
Quoted 10 lines
target/arm/translate-a64.c +10
-0+if (!dc_isar_feature (aa64_ssbs, s)) { + goto do_unallocated; + } +if (crm &1 ) { +set_pstate_bits (PSTATE_SSBS ); + }else { +clear_pstate_bits (PSTATE_SSBS ); + } +/* Don't need to rebuild hflags since SSBS is a nop */ +break ;
Put this above DIT (0x1a) to keep the numbers in order.
r~
Re: [PATCH 1/3] target/arm: Add support for FEAT_SSBS, Speculative Store Bypass Safe
Quoted 5 lines · Richard Henderson
Quoted 4 lines · Rebecca Cran
target/arm/helper-a64.c +0
-0@@ -960,6 +960,12 @@ static void cpsr_write_from_spsr_elx(CPUARMState *env, val |=CPSR_DIT ; }
Quoted 7 lines
target/arm/helper-a64.c static void cpsr_write_from_spsr_elx(CPUARMState *env, · line 967
Quoted 5 lines
target/arm/helper-a64.c +5
-0+/* Move SSBS to the correct location for CPSR */ +if (val &PSTATE_SSBS ) { + val &= ~PSTATE_SSBS ; + val |=CPSR_SSBS ; + }Incorrect.
SPSR_ELxleaves this at the same position as CPSR: bit 23.
Okay, I see where I'm going wrong now - SPSR_ELx has different formats for exceptions taken from aarch32 and aarch64 states, which I hadn't fully understood. I'll fix it.
Signature · 1 line
Rebecca Cran
PATCH 2/3 target/arm: Enable FEAT_SSBS for "max" AARCH64 CPU
In reply to Rebecca CranSet ID_AA64PFR1_EL1.SSBS to 2 and ID_PFR2.SSBS to 1.
--- target/arm/cpu64.c | 5 +++++ 1 file changed, 5 insertions(+)
target/arm/cpu64.c +5 -0
@@ -674,6 +674,7 @@ static void aarch64_max_initfn(Object *obj) t = cpu->isar.id_aa64pfr1; t =FIELD_DP64 (t,ID_AA64PFR1 ,BT ,1 ); + t =FIELD_DP64 (t,ID_AA64PFR1 ,SSBS ,2 );/* * Begin with full support for MTE. This will be downgraded to MTE=0 * during realize if the board provides no tag memory, much like
@@ -723,6 +724,10 @@ static void aarch64_max_initfn(Object *obj) u =FIELD_DP32 (u,ID_PFR0 ,DIT ,1 ); cpu->isar.id_pfr0 = u; + u = cpu->isar.id_pfr2; + u =FIELD_DP32 (u,ID_PFR2 ,SSBS ,1 ); + cpu->isar.id_pfr2 = u; + u = cpu->isar.id_mmfr3; u =FIELD_DP32 (u,ID_MMFR3 ,PAN ,2 );/* ATS1E1 */ cpu->isar.id_mmfr3 = u;
Signature · 1 line
2.26.2
Re: [PATCH 2/3] target/arm: Enable FEAT_SSBS for "max" AARCH64 CPU
Quoted 6 lines · Rebecca Cran
Set ID_AA64PFR1_EL1.SSBS to 2 and ID_PFR2.SSBS to 1.
Signed-off-by Rebecca Cran <[email protected]>--- target/arm/cpu64.c | 5 +++++ 1 file changed, 5 insertions(+)
r~
PATCH 3/3 target/arm: Set ID_PFR2.SSBS to 1 for "max" 32-bit CPU
In reply to Rebecca CranEnable FEAT_SSBS for the "max" 32-bit CPU.
--- target/arm/cpu.c | 4 ++++ 1 file changed, 4 insertions(+)
target/arm/cpu.c +4 -0
@@ -2206,6 +2206,10 @@ static void arm_max_initfn(Object *obj) t = cpu->isar.id_pfr0; t =FIELD_DP32 (t,ID_PFR0 ,DIT ,1 ); cpu->isar.id_pfr0 = t; + + t = cpu->isar.id_pfr2; + t =FIELD_DP32 (t,ID_PFR2 ,SSBS ,1 ); + cpu->isar.id_mfr2 = t; }#endif }
Signature · 1 line
2.26.2
Re: [PATCH 3/3] target/arm: Set ID_PFR2.SSBS to 1 for "max" 32-bit CPU
Quoted 6 lines · Rebecca Cran
Enable
FEAT_SSBSfor the "max" 32-bit CPU.Signed-off-by Rebecca Cran <[email protected]>--- target/arm/cpu.c | 4 ++++ 1 file changed, 4 insertions(+)
r~