target/arm: Implement FEAT_IDTE3
cover target/arm: Implement FEAT_IDTE3
Based-on: [email protected] ("[PATCH 0/6] target/arm: Implement FEAT_FGWTE3")
Not logically related to FEAT_FGWTE3, only patch context.
Allow firmware to hide or modify ID registers exposing features to the hypervisor and operating system.
r~
Richard Henderson (6):
target/arm: Rename isar_feature_aa64_idst
target/arm: Enable writes to SCR_EL3.TID{3,5} target/arm: Implement HCR_EL2.TID3 trap on undefined TID3 registers target/arm: Implement SCR_EL3.TID3
target/arm: Implement SCR_EL3.TID5
target/arm: Enable FEAT_IDTE3 for -cpu max
target/arm/cpregs.h | 8 +++++++ target/arm/cpu-features.h | 7 ++++++- target/arm/cpu.h | 2 ++ target/arm/tcg/helper-defs.h | 1 + target/arm/helper.c | 38 ++++++++++++++++++++++++++++++---- target/arm/tcg/cpu64.c | 2 +- target/arm/tcg/op_helper.c | 23 +++++++++++++++++++- target/arm/tcg/translate-a64.c | 12 +++++++++-- target/arm/tcg/translate.c | 8 +++++++ docs/system/arm/emulation.rst | 1 + 10 files changed, 93 insertions(+), 9 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/6 target/arm: Rename isar_feature_aa64_idst
Rename from isar_feature_aa64_ids to match the feature name: FEAT_IDST.
--- target/arm/cpu-features.h | 2 +- target/arm/tcg/op_helper.c | 2 +- target/arm/tcg/translate-a64.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
target/arm/cpu-features.h +1 -1
@@ -1397,7 +1397,7 @@ static inline bool isar_feature_aa64_fwb(const ARMISARegisters *id)return FIELD_EX64_IDREG (id,ID_AA64MMFR2 ,FWB ) !=0 ; } -static inline bool isar_feature_aa64_ids (const ARMISARegisters *id) +static inline bool isar_feature_aa64_idst (const ARMISARegisters *id) {return FIELD_EX64_IDREG (id,ID_AA64MMFR2 ,IDS ) !=0 ; }
target/arm/tcg/op_helper.c +1 -1
@@ -1135,7 +1135,7 @@ const void *HELPER(access_check_cp_reg)(CPUARMState *env, uint32_t key,break ;case CP_ACCESS_UNDEFINED :/* CP_ACCESS_UNDEFINED is never direct to a specified EL */ -if (cpu_isar_feature (aa64_ids, cpu) && isread && +if (cpu_isar_feature (aa64_idst, cpu) && isread &&arm_cpreg_in_idspace (ri)) {/* * FEAT_IDST says this should be reported as EC_SYSTEMREGISTERTRAP,
target/arm/tcg/translate-a64.c +1 -1
@@ -2675,7 +2675,7 @@ static void gen_sysreg_undef(DisasContext *s, bool isread,*/ uint32_t syndrome; -if (isread &&dc_isar_feature (aa64_ids, s) && +if (isread &&dc_isar_feature (aa64_idst, s) &&arm_cpreg_encoding_in_idspace (op0, op1, op2, crn, crm)) { syndrome =syn_aa64_sysregtrap (op0, op1, op2, crn, crm, rt, isread); }else {
Signature · 1 line
2.43.0
Re: [PATCH 1/6] target/arm: Rename isar_feature_aa64_idst
Quoted 9 lines · Richard Henderson
Rename from
isar_feature_aa64_idsto match the feature name:FEAT_IDST.Signed-off-by Richard Henderson <[email protected]>--- target/arm/cpu-features.h | 2 +- target/arm/tcg/op_helper.c | 2 +- target/arm/tcg/translate-a64.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
thanks
-- PMM
Re: [PATCH 1/6] target/arm: Rename isar_feature_aa64_idst
In reply to Richard HendersonQuoted 8 lines · Richard Henderson
Rename from
isar_feature_aa64_idsto match the feature name:FEAT_IDST.Signed-off-by Richard Henderson <[email protected]>--- target/arm/cpu-features.h | 2 +- target/arm/tcg/op_helper.c | 2 +- target/arm/tcg/translate-a64.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
PATCH 2/6 target/arm: Enable writes to SCR_EL3.TID{3,5}
In reply to Richard Henderson--- target/arm/cpu-features.h | 5 +++++ target/arm/cpu.h | 2 ++ target/arm/helper.c | 3 +++ 3 files changed, 10 insertions(+)
target/arm/cpu-features.h +5 -0
@@ -1402,6 +1402,11 @@ static inline bool isar_feature_aa64_idst(const ARMISARegisters *id)return FIELD_EX64_IDREG (id,ID_AA64MMFR2 ,IDS ) !=0 ; } +static inline bool isar_feature_aa64_idte3 (const ARMISARegisters *id) +{ +return FIELD_EX64_IDREG (id,ID_AA64MMFR2 ,IDS ) >=2 ; +} +static inline bool isar_feature_aa64_half_evt (const ARMISARegisters *id) {return FIELD_EX64_IDREG (id,ID_AA64MMFR2 ,EVT ) >=1 ;
target/arm/cpu.h +2 -0
@@ -1787,6 +1787,8 @@ static inline void xpsr_write(CPUARMState *env, uint32_t val, uint32_t mask)#define SCR_EASE (1ULL << 19)#define SCR_NMEA (1ULL << 20)#define SCR_FIEN (1ULL << 21) +#define SCR_TID3 (1ULL << 22) +#define SCR_TID5 (1ULL << 23)#define SCR_ENSCXT (1ULL << 25)#define SCR_ATA (1ULL << 26)#define SCR_FGTEN (1ULL << 27)
target/arm/helper.c +3 -0
@@ -796,6 +796,9 @@ static void scr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)if (cpu_isar_feature (aa64_rng_trap, cpu)) { valid_mask |=SCR_TRNDR ; } +if (cpu_isar_feature (aa64_idte3, cpu)) { + valid_mask |=SCR_TID5 |SCR_TID3 ; + } }else { valid_mask &= ~(SCR_RW |SCR_ST );if (cpu_isar_feature (aa32_ras, cpu)) {
Signature · 1 line
2.43.0
Re: [PATCH 2/6] target/arm: Enable writes to SCR_EL3.TID{3,5}
Quoted 3 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>---
thanks
-- PMM
PATCH 3/6 target/arm: Implement HCR_EL2.TID3 trap on undefined TID3 registers
In reply to Richard HendersonIt is IMPLEMENTATION DEFINED whether HCR_EL2.TID3 traps on registers within the range which are not explicitly listed. Previously we chose not to honor the TID3 bit.
However, with FEAT_IDTE3 it becomes mandatory to honor SCR_EL3.TID3 on these registers, so we might as well honor HCR_EL2.TID3 too.
--- target/arm/cpregs.h | 8 ++++++++ target/arm/tcg/helper-defs.h | 1 + target/arm/tcg/op_helper.c | 19 +++++++++++++++++++ target/arm/tcg/translate-a64.c | 12 ++++++++++-- target/arm/tcg/translate.c | 8 ++++++++ 5 files changed, 46 insertions(+), 2 deletions(-)
target/arm/cpregs.h +8 -0
@@ -1213,6 +1213,14 @@ static inline bool arm_cpreg_in_idspace(const ARMCPRegInfo *ri) ri->crn, ri->crm); } +/* The TID3 subset of idspace. */ +static inline bool +arm_cpreg_encoding_in_tid3 (uint8_t opc0,uint8_t opc1,uint8_t opc2, +uint8_t crn,uint8_t crm) +{ +return opc0 ==3 && opc1 ==0 && crn ==0 && crm >=2 && crm <8 ; +} +#ifdef CONFIG_USER_ONLY static inline void define_cortex_a72_a57_a53_cp_reginfo (ARMCPU *cpu) { }#else
target/arm/tcg/helper-defs.h +1 -0
@@ -86,6 +86,7 @@ DEF_HELPER_FLAGS_2(check_bxj_trap, TCG_CALL_NO_WG, void, env, i32) DEF_HELPER_4(access_check_cp_reg, cptr, env, i32, i32, i32) DEF_HELPER_FLAGS_2(lookup_cp_reg, TCG_CALL_NO_RWG_SE, cptr, env, i32) +DEF_HELPER_FLAGS_2(tid3_udef_el1, TCG_CALL_NO_WG, noreturn, env, i32) DEF_HELPER_FLAGS_2(tidcp_el0, TCG_CALL_NO_WG, void, env, i32) DEF_HELPER_FLAGS_2(tidcp_el1, TCG_CALL_NO_WG, void, env, i32)DEF_HELPER_3 (set_cp_reg, void, env, cptr, i32)
target/arm/tcg/op_helper.c +19 -0
@@ -1187,6 +1187,25 @@ const void *HELPER(lookup_cp_reg)(CPUARMState *env, uint32_t key)return ri; } +/* Raise an exception for an unimplemented sysreg in TID3 space, from EL1. */ +void HELPER (tid3_udef_el1 )(CPUARMState *env,uint32_t syndrome) +{ +int target_el =1 ; +int excp =EXCP_UDEF ; + +if (arm_hcr_el2_eff (env) &HCR_TID3 ) { + target_el =2 ; + excp =EXCP_HYP_TRAP ; + }else if (is_a64 (env)) { +if (!cpu_isar_feature (aa64_idst,env_archcpu (env))) { + syndrome =syn_uncategorized (); + } + }else { + syndrome =syn_uncategorized (); + } +raise_exception (env, excp, syndrome, target_el); +} +/* * Test for HCR_EL2.TIDCP at EL1. * Since implementation defined registers are rare, and within QEMU
target/arm/tcg/translate-a64.c +10 -2
@@ -2675,9 +2675,17 @@ static void gen_sysreg_undef(DisasContext *s, bool isread,*/ uint32_t syndrome; -if (isread &&dc_isar_feature (aa64_idst, s) && -arm_cpreg_encoding_in_idspace (op0, op1, op2, crn, crm)) { +if (isread &&arm_cpreg_encoding_in_idspace (op0, op1, op2, crn, crm)) { syndrome =syn_aa64_sysregtrap (op0, op1, op2, crn, crm, rt, isread); +if (s->current_el ==1 && +arm_cpreg_encoding_in_tid3 (op0, op1, op2, crn, crm)) { +gen_a64_update_pc (s,0 ); +gen_helper_tid3_udef_el1 (tcg_env,tcg_constant_i32 (syndrome)); +return ; + } +if (!dc_isar_feature (aa64_idst, s)) { + syndrome =syn_uncategorized (); + } }else { syndrome =syn_uncategorized (); }
target/arm/tcg/translate.c +8 -0
@@ -1824,6 +1824,14 @@ static void do_coproc_insn(DisasContext *s, int cpnum, int is64, isread ?"read" :"write" , cpnum, opc1, crn, crm, opc2, s->ns ? "non-secure" : "secure"); } +if (isread + && s->current_el ==1 + && cpnum ==15 + &&arm_cpreg_encoding_in_tid3 (3 , opc1, opc2, crn, crm)) { +gen_set_condexec (s); +gen_update_pc (s,0 ); +gen_helper_tid3_udef_el1 (tcg_env,tcg_constant_i32 (syndrome)); + }unallocated_encoding (s);return ; }
Signature · 1 line
2.43.0
Re: [PATCH 3/6] target/arm: Implement HCR_EL2.TID3 trap on undefined TID3 registers
Quoted 7 lines · Richard Henderson
It is IMPLEMENTATION DEFINED whether HCR_EL2.TID3 traps on registers within the range which are not explicitly listed. Previously we chose not to honor the TID3 bit.
However, with
FEAT_IDTE3it becomes mandatory to honor SCR_EL3.TID3 on these registers
NB that it's mandatory to honour HCR_EL2.TID3 if FEAT_FGT is present, and we already choose to do so for V8. It's only V7 where we don't.
Quoted 1 line
, so we might as well honor HCR_EL2.TID3 too.
I'm not in favour of this, because there's some complicated history behind HCR_EL2.TID3, as outlined in the commit message of 205ca535ab ("target/arm: Correctly honour HCR.TID3 for v7A cores"). I would prefer to leave the trap behaviour as it is now [i.e. "on v7, trap only the specific registers; on v8, take the IMPDEF choice to trap the whole range"], because the wording in the v7A Arm ARM is rather vague. I also have a feeling that I looked at real v7A h/w and it didn't trap these, but I might be misremembering.
thanks
-- PMM
PATCH 4/6 target/arm: Implement SCR_EL3.TID3
In reply to Richard Henderson--- target/arm/helper.c | 18 ++++++++++++++++-- target/arm/tcg/op_helper.c | 4 +++- 2 files changed, 19 insertions(+), 3 deletions(-)
target/arm/helper.c +16 -2
@@ -5894,8 +5894,22 @@ static CPAccessResult access_v7a_tid3(CPUARMState *env, const ARMCPRegInfo *ri,* Any other registers in the TID3 trap space should use access_tid3(), * so that they trap on v8 and above, but not on v7. */ -if ((arm_current_el (env) <2 ) && (arm_hcr_el2_eff (env) &HCR_TID3 )) { -return CP_ACCESS_TRAP_EL2 ; +switch (arm_current_el (env)) { +case 1 : +if (arm_hcr_el2_eff (env) &HCR_TID3 ) { +return CP_ACCESS_TRAP_EL2 ; + } +/* fall through */ +case 2 : +/* Note FEAT_IDTE3 does not trap AArch32 sysregs. */ +if (ri->state ==ARM_CP_STATE_AA64 && (env->cp15.scr_el3 &SCR_TID3 )) { +return CP_ACCESS_TRAP_EL3 ; + } +break ; +case 3 : +break ; +default : +g_assert_not_reached (); }return CP_ACCESS_OK ;
target/arm/tcg/op_helper.c +3 -1
@@ -1197,7 +1197,9 @@ void HELPER(tid3_udef_el1)(CPUARMState *env, uint32_t syndrome) target_el =2 ; excp =EXCP_HYP_TRAP ; }else if (is_a64 (env)) { -if (!cpu_isar_feature (aa64_idst,env_archcpu (env))) { +if (env->cp15.scr_el3 &SCR_TID3 ) { + target_el =3 ; + }else if (!cpu_isar_feature (aa64_idst,env_archcpu (env))) { syndrome =syn_uncategorized (); } }else {
Signature · 1 line
2.43.0
PATCH 5/6 target/arm: Implement SCR_EL3.TID5
In reply to Richard Henderson--- target/arm/helper.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
target/arm/helper.c +15 -2
@@ -5485,8 +5485,21 @@ static const ARMCPRegInfo dcpodp_reg[] = {static CPAccessResult access_tid5 (CPUARMState *env,const ARMCPRegInfo *ri,bool isread) { -if ((arm_current_el (env) <2 ) && (arm_hcr_el2_eff (env) &HCR_TID5 )) { -return CP_ACCESS_TRAP_EL2 ; +switch (arm_current_el (env)) { +case 1 : +if (arm_hcr_el2_eff (env) &HCR_TID5 ) { +return CP_ACCESS_TRAP_EL2 ; + } +/* fall through */ +case 2 : +if (env->cp15.scr_el3 &SCR_TID5 ) { +return CP_ACCESS_TRAP_EL3 ; + } +break ; +case 3 : +break ; +default : +g_assert_not_reached (); }return CP_ACCESS_OK ;
Signature · 1 line
2.43.0
Re: [PATCH 5/6] target/arm: Implement SCR_EL3.TID5
Quoted 5 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/arm/helper.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
thanks
-- PMM
PATCH 6/6 target/arm: Enable FEAT_IDTE3 for -cpu max
In reply to Richard Henderson--- target/arm/tcg/cpu64.c | 2 +- docs/system/arm/emulation.rst | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
target/arm/tcg/cpu64.c +1 -1
@@ -1342,7 +1342,7 @@ void aarch64_max_tcg_initfn(Object *obj) t =FIELD_DP64 (t,ID_AA64MMFR2 ,NV ,2 );/* FEAT_NV2 */ t =FIELD_DP64 (t,ID_AA64MMFR2 ,ST ,1 );/* FEAT_TTST */ t =FIELD_DP64 (t,ID_AA64MMFR2 ,AT ,1 );/* FEAT_LSE2 */ - t =FIELD_DP64 (t,ID_AA64MMFR2 ,IDS ,1 );/* FEAT_IDST */ + t =FIELD_DP64 (t,ID_AA64MMFR2 ,IDS ,2 );/* FEAT_IDST, FEAT_IDTE3 */ t =FIELD_DP64 (t,ID_AA64MMFR2 ,FWB ,1 );/* FEAT_S2FWB */ t =FIELD_DP64 (t,ID_AA64MMFR2 ,TTL ,1 );/* FEAT_TTL */ t =FIELD_DP64 (t,ID_AA64MMFR2 ,BBM ,2 );/* FEAT_BBM at level 2 */
docs/system/arm/emulation.rst +1 -0
@@ -105,6 +105,7 @@ the following architecture extensions: - FEAT_HPMN0 (Setting of MDCR_EL2.HPMN to zero) - FEAT_I8MM (AArch64 Int8 matrix multiplication instructions) - FEAT_IDST (ID space trap handling) +- FEAT_IDTE3 (Trapping ID register accesses to EL3) - FEAT_IESB (Implicit error synchronization event) - FEAT_IVIPT (The IVIPT Extension) - FEAT_JSCVT (JavaScript conversion instructions)
Signature · 1 line
2.43.0
Re: [PATCH 6/6] target/arm: Enable FEAT_IDTE3 for -cpu max
Quoted 2 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>
thanks
-- PMM