target/arm: Implement FEAT_FGWTE3
v2 cover target/arm: Implement FEAT_FGWTE3
Based-on: [email protected] ("[PATCH 0/7] target/arm: Introduce cpu types max-v8 and max-v9")
Changes for v2:
- Rebase on the max-v9 split.
- Review comment fixups.
- Set fgt for MECID_RL_A_EL3.
r~
Richard Henderson (6):
target/arm: Add FGWTE3_EL3
target/arm: Add FGWTE3_EL3 bit definitions
target/arm: Add FGWTE3 FGT bit definitions
target/arm: Implement FGWTE3 traps
target/arm: Set fgt in cpregs for FGWTE3
target/arm: Enable FEAT_FGWTE3 for -cpu max
target/arm/cpregs.h | 56 +++++++++++++++++++++++++++ target/arm/cpu-features.h | 5 +++ target/arm/cpu.h | 2 +- target/arm/cpregs-gcs.c | 5 ++- target/arm/helper.c | 69 ++++++++++++++++++++++------------ target/arm/tcg/cpu64.c | 1 + target/arm/tcg/op_helper.c | 40 +++++++++++++------- target/arm/tcg/translate-a64.c | 16 +++++++- docs/system/arm/emulation.rst | 1 + 9 files changed, 155 insertions(+), 40 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/6 target/arm: Add FGWTE3_EL3
--- target/arm/cpregs.h | 1 + target/arm/cpu-features.h | 5 +++++ target/arm/cpu.h | 2 +- target/arm/helper.c | 20 ++++++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-)
target/arm/cpregs.h +1 -0
@@ -385,6 +385,7 @@ typedef enum CPAccessResult {/* Indexes into fgt_write[] */ #define FGTREG_HFGWTR 0#define FGTREG_HDFGWTR 1 +#define FGTREG_FGWTE3 2/* Indexes into fgt_exec[] */ #define FGTREG_HFGITR 0
target/arm/cpu-features.h +5 -0
@@ -1467,6 +1467,11 @@ static inline bool isar_feature_aa64_asid2(const ARMISARegisters *id)return FIELD_EX64_IDREG (id,ID_AA64MMFR4 ,ASID2 ) !=0 ; } +static inline bool isar_feature_aa64_fgwte3 (const ARMISARegisters *id) +{ +return FIELD_EX64_IDREG (id,ID_AA64MMFR4 ,FGWTE3 ) !=0 ; +} +/* * Note the E2H0 ID fields is signed, increasingly negative as more * isn't implemented.
target/arm/cpu.h +1 -1
@@ -553,7 +553,7 @@ typedef struct CPUArchState {* FEAT_FGT2 will add more elements to these arrays. */ uint64_t fgt_read[2 ];/* HFGRTR, HDFGRTR */ -uint64_t fgt_write[2 ];/* HFGWTR, HDFGWTR */ +uint64_t fgt_write[3 ];/* HFGWTR, HDFGWTR, FGWTE3 */ uint64_t fgt_exec[1 ];/* HFGITR */ /* RME registers */
target/arm/helper.c +20 -0
@@ -6331,6 +6331,22 @@ static const ARMCPRegInfo fpmr_reginfo[] = { } }; +static void fgwte3_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +/* All bits are W1S and can only be cleared by cpu reset. */ + env->cp15.fgt_write[FGTREG_FGWTE3 ] |= value; +} + +static const ARMCPRegInfo fgwte3_reginfo[] = { + { .name ="FGWTE3_EL3" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =6 , .crn =1 , .crm =1 , .opc2 =5 , + .access =PL3_RW , .resetvalue =0 , + .writefn = fgwte3_write, .raw_writefn = raw_write, + .fieldoffset = offsetof(CPUARMState, cp15.fgt_write[FGTREG_FGWTE3]) + }, +}; +void register_cp_regs_for_features (ARMCPU *cpu) {/* Register all the coprocessor registers based on feature bits */
@@ -7642,6 +7658,10 @@ void register_cp_regs_for_features(ARMCPU *cpu)define_arm_cp_regs (cpu, ccsidr2_reginfo); } +if (cpu_isar_feature (aa64_fgwte3, cpu)) { +define_arm_cp_regs (cpu, fgwte3_reginfo); + } +define_pm_cpregs (cpu);define_gcs_cpregs (cpu); }
Signature · 1 line
2.43.0
PATCH v2 2/6 target/arm: Add FGWTE3_EL3 bit definitions
In reply to Richard Henderson--- target/arm/cpregs.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
target/arm/cpregs.h +24 -0
@@ -689,6 +689,30 @@ FIELD(HDFGWTR_EL2, NBRBCTL, 60, 1) FIELD(HDFGWTR_EL2, NBRBDATA, 61, 1) FIELD(HDFGWTR_EL2, NPMSNEVFR_EL1, 62, 1) +FIELD(FGWTE3_EL3, ACTLR_EL3, 0, 1) +FIELD(FGWTE3_EL3, AFSR0_EL3, 1, 1) +FIELD(FGWTE3_EL3, AFSR1_EL3, 2, 1) +FIELD(FGWTE3_EL3, AMAIR_EL3, 3, 1) +FIELD(FGWTE3_EL3, AMAIR2_EL3, 4, 1) +FIELD(FGWTE3_EL3, GCSCR_EL3, 5, 1) +FIELD(FGWTE3_EL3, GCSPR_EL3, 6, 1) +FIELD(FGWTE3_EL3, GPCCR_EL3, 7, 1) +FIELD(FGWTE3_EL3, GPTBR_EL3, 8, 1) +FIELD(FGWTE3_EL3, MAIR_EL3, 9, 1) +FIELD(FGWTE3_EL3, MAIR2_EL3, 10, 1) +FIELD(FGWTE3_EL3, MDCR_EL3, 11, 1) +FIELD(FGWTE3_EL3, MECID_RL_A_EL3, 12, 1) +FIELD(FGWTE3_EL3, MPAM3_EL3, 13, 1) +FIELD(FGWTE3_EL3, PIR_EL3, 14, 1) +FIELD(FGWTE3_EL3, SCTLR_EL3, 15, 1) +FIELD(FGWTE3_EL3, SCTLR2_EL3, 16, 1) +FIELD(FGWTE3_EL3, SPMROOTCR_EL3, 17, 1) +FIELD(FGWTE3_EL3, TCR_EL3, 18, 1) +FIELD(FGWTE3_EL3, TPIDR_EL3, 19, 1) +FIELD(FGWTE3_EL3, TTBR0_EL3, 20, 1) +FIELD(FGWTE3_EL3, VBAR_EL3, 21, 1) +FIELD(FGWTE3_EL3, GPCBW_EL3, 22, 1) +FIELD (FGT ,NXS ,13 ,1 )/* Honour HCR_EL2.FGTnXS to suppress FGT */ /* Which fine-grained trap bit register to check, if any */FIELD (FGT ,TYPE ,10 ,3 )
Signature · 1 line
2.43.0
PATCH v2 3/6 target/arm: Add FGWTE3 FGT bit definitions
In reply to Richard Henderson--- target/arm/cpregs.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
target/arm/cpregs.h +31 -0
@@ -728,6 +728,9 @@ FIELD(FGT, BITPOS, 0, 6) /* Bit position within the uint64_t */#define DO_BIT (REG ,BITNAME ) \ FGT_##BITNAME = FGT_##REG | R_##REG##_EL2_##BITNAME##_SHIFT +#define DO_EL3_BIT (REG ,BITNAME ) \ + FGT_##BITNAME = FGT_##REG | R_##REG##_EL3_##BITNAME##_SHIFT +/* Some bits have reversed sense, so 0 means trap and 1 means not */ #define DO_REV_BIT (REG ,BITNAME ) \ FGT_##BITNAME = FGT_##REG | FGT_REV | R_##REG##_EL2_##BITNAME##_SHIFT
@@ -787,6 +790,7 @@ typedef enum FGTBit {FGT_HDFGRTR =FGT_RW | (FGTREG_HDFGRTR <<R_FGT_IDX_SHIFT ),FGT_HDFGWTR =FGT_W | (FGTREG_HDFGWTR <<R_FGT_IDX_SHIFT ),FGT_HFGITR =FGT_EXEC | (FGTREG_HFGITR <<R_FGT_IDX_SHIFT ), +FGT_FGWTE3 =FGT_W | (FGTREG_FGWTE3 <<R_FGT_IDX_SHIFT ),/* Trap bits in HFGRTR_EL2 / HFGWTR_EL2, starting from bit 0. */ DO_BIT(HFGRTR, AFSR0_EL1),
@@ -919,10 +923,37 @@ typedef enum FGTBit {DO_REV_BIT (HFGITR ,NGCSPUSHM_EL1 ),DO_REV_BIT (HFGITR ,NGCSEPP ),DO_BIT (HFGITR ,ATS1E1A ), + +/* Trap bits in FGWTE3_EL3, starting from bit 0 */ +DO_EL3_BIT (FGWTE3 ,ACTLR_EL3 ), +DO_EL3_BIT (FGWTE3 ,AFSR0_EL3 ), +DO_EL3_BIT (FGWTE3 ,AFSR1_EL3 ), +DO_EL3_BIT (FGWTE3 ,AMAIR_EL3 ), +DO_EL3_BIT (FGWTE3 ,AMAIR2_EL3 ), +DO_EL3_BIT (FGWTE3 ,GCSCR_EL3 ), +DO_EL3_BIT (FGWTE3 ,GCSPR_EL3 ), +DO_EL3_BIT (FGWTE3 ,GPCCR_EL3 ), +DO_EL3_BIT (FGWTE3 ,GPTBR_EL3 ), +DO_EL3_BIT (FGWTE3 ,MAIR_EL3 ), +DO_EL3_BIT (FGWTE3 ,MAIR2_EL3 ), +DO_EL3_BIT (FGWTE3 ,MDCR_EL3 ), +DO_EL3_BIT (FGWTE3 ,MECID_RL_A_EL3 ), +DO_EL3_BIT (FGWTE3 ,MPAM3_EL3 ), +DO_EL3_BIT (FGWTE3 ,PIR_EL3 ), +DO_EL3_BIT (FGWTE3 ,SCTLR_EL3 ), +DO_EL3_BIT (FGWTE3 ,SCTLR2_EL3 ), +DO_EL3_BIT (FGWTE3 ,SPMROOTCR_EL3 ), +DO_EL3_BIT (FGWTE3 ,TCR_EL3 ), +DO_EL3_BIT (FGWTE3 ,TPIDR_EL3 ), +DO_EL3_BIT (FGWTE3 ,TTBR0_EL3 ), +DO_EL3_BIT (FGWTE3 ,VBAR_EL3 ), +DO_EL3_BIT (FGWTE3 ,GPCBW_EL3 ), } FGTBit;#undef DO_BIT +#undef DO_EL3_BIT#undef DO_REV_BIT +#undef DO_TLBINXS_BITtypedef struct ARMCPRegInfo ARMCPRegInfo ;
Signature · 1 line
2.43.0
PATCH v2 4/6 target/arm: Implement FGWTE3 traps
In reply to Richard Henderson--- target/arm/tcg/op_helper.c | 40 +++++++++++++++++++++++----------- target/arm/tcg/translate-a64.c | 16 +++++++++++++- 2 files changed, 42 insertions(+), 14 deletions(-)
target/arm/tcg/op_helper.c +27 -13
@@ -1066,13 +1066,15 @@ const void *HELPER(access_check_cp_reg)(CPUARMState *env, uint32_t key,* Fine-grained traps also are lower priority than undef-to-EL1, * higher priority than trap-to-EL3, and we don't care about priority * order with other EL2 traps because the syndrome value is the same. +* +* FGWTE3 traps are exclusively traps to EL3 on registers that are +* only accessible to EL3, so there's no possibility of a trap to EL2. +* So we can handle these checks here too. */ -if (arm_fgt_active (env,arm_current_el (env))) { +if (ri->fgt) {uint64_t trapword =0 ;unsigned int idx =FIELD_EX32 (ri->fgt,FGT ,IDX );unsigned int bitpos =FIELD_EX32 (ri->fgt,FGT ,BITPOS ); -bool rev =FIELD_EX32 (ri->fgt,FGT ,REV ); -bool nxs =FIELD_EX32 (ri->fgt,FGT ,NXS );bool trapbit;if (ri->fgt &FGT_EXEC ) {
@@ -1085,19 +1087,31 @@ const void *HELPER(access_check_cp_reg)(CPUARMState *env, uint32_t key,assert (idx <ARRAY_SIZE (env->cp15.fgt_write)); trapword = env->cp15.fgt_write[idx]; } + trapbit =extract64 (trapword, bitpos,1 ); -if (nxs && (arm_hcrx_el2_eff (env) &HCRX_FGTNXS )) { +if ((ri->access & ~PL3_RW ) ==0 ) {/* -* If HCRX_EL2.FGTnXS is 1 then the fine-grained trap for -* TLBI maintenance insns does *not* apply to the nXS variant. +* EL3 cpreg -- must be FGWTE3, and FGWTE3_EL3 can only be +* set from AArch64, and if the feature is enabled. */ - trapbit =0 ; - }else { - trapbit =extract64 (trapword, bitpos,1 ); - } -if (trapbit != rev) { - res =CP_ACCESS_TRAP_EL2 ; - goto fail; +if (trapbit) { + res =CP_ACCESS_TRAP_EL3 ; + goto fail; + } + }else if (arm_fgt_active (env,arm_current_el (env))) { +bool nxs =FIELD_EX32 (ri->fgt,FGT ,NXS ); +bool rev =FIELD_EX32 (ri->fgt,FGT ,REV ); +if (nxs && (arm_hcrx_el2_eff (env) &HCRX_FGTNXS )) { +/* +* If HCRX_EL2.FGTnXS is 1 then the fine-grained trap for +* TLBI maintenance insns does *not* apply to the nXS variant. +*/ + trapbit =0 ; + } +if (trapbit != rev) { + res =CP_ACCESS_TRAP_EL2 ; + goto fail; + } } }
target/arm/tcg/translate-a64.c +15 -1
@@ -2886,6 +2886,7 @@ static void handle_sys(DisasContext *s, bool isread, {uint32_t key =ENCODE_AA64_CP_REG (op0, op1, crn, crm, op2);const ARMCPRegInfo *ri =get_arm_cp_reginfo (s->cp_regs, key); +bool need_helper = false;bool need_exit_tb = false;bool nv_trap_to_el2 = false;bool nv_redirect_reg = false;
@@ -2999,7 +3000,20 @@ static void handle_sys(DisasContext *s, bool isread, ri =redirect_cpreg (s, key, isread); } -if (ri->accessfn || (ri->fgt && s->fgt_active)) { +if (ri->accessfn) { + need_helper = true; + }else if (ri->fgt) { +/* +* EL3-only access means this must be an FGWTE3 trap (which are +* always active); otherwise it's an FGT trap to EL2. +*/ +if ((ri->access & ~PL3_RW ) ==0 ) { + need_helper =dc_isar_feature (aa64_fgwte3, s); + }else { + need_helper = s->fgt_active; + } + } +if (need_helper) {/* Emit code to perform further access permissions checks at * runtime; this may result in an exception. */
Signature · 1 line
2.43.0
PATCH v2 5/6 target/arm: Set fgt in cpregs for FGWTE3
In reply to Richard Henderson--- target/arm/cpregs-gcs.c | 5 +++-- target/arm/helper.c | 49 ++++++++++++++++++++++------------------- 2 files changed, 29 insertions(+), 25 deletions(-)
target/arm/cpregs-gcs.c +3 -2
@@ -97,7 +97,7 @@ static const ARMCPRegInfo gcs_reginfo[] = { .fieldoffset = offsetof(CPUARMState, cp15.gcscr_el[2]) }, { .name = "GCSCR_EL3", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 6, .crn = 2, .crm = 5, .opc2 = 0, - .access = PL3_RW, + .access = PL3_RW, .fgt = FGT_GCSCR_EL3, .fieldoffset = offsetof(CPUARMState, cp15.gcscr_el[3]) }, { .name = "GCSPR_EL0", .state = ARM_CP_STATE_AA64,
@@ -119,7 +119,8 @@ static const ARMCPRegInfo gcs_reginfo[] = { .fieldoffset = offsetof(CPUARMState, cp15.gcspr_el[2]) }, { .name = "GCSPR_EL3", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 6, .crn = 2, .crm = 5, .opc2 = 1, - .access = PL3_RW, .writefn = gcspr_write, + .access = PL3_RW, .fgt = FGT_GCSPR_EL3, + .writefn = gcspr_write, .fieldoffset = offsetof(CPUARMState, cp15.gcspr_el[2]) }, { .name = "GCSPUSHM", .state = ARM_CP_STATE_AA64,
target/arm/helper.c +26 -23
143 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 6/6 target/arm: Enable FEAT_FGWTE3 for -cpu max
In reply to Richard Henderson--- target/arm/tcg/cpu64.c | 1 + docs/system/arm/emulation.rst | 1 + 2 files changed, 2 insertions(+)
target/arm/tcg/cpu64.c +1 -0
@@ -1462,6 +1462,7 @@ void aarch64_max_v9_tcg_initfn(Object *obj) t =GET_IDREG (isar,ID_AA64MMFR4 ); t =FIELD_DP64 (t,ID_AA64MMFR4 ,ASID2 ,1 );/* v9.4: FEAT_ASID2 */ + t =FIELD_DP64 (t,ID_AA64MMFR4 ,FGWTE3 ,1 );/* v9.4: FEAT_FGWTE3 */ SET_IDREG (isar,ID_AA64MMFR4 , t); t =GET_IDREG (isar,ID_AA64ZFR0 );
docs/system/arm/emulation.rst +1 -0
@@ -78,6 +78,7 @@ the following architecture extensions: - FEAT_FAMINMAX (Floating-point maximum and minimum absolute value instructions) - FEAT_FCMA (Floating-point complex number instructions) - FEAT_FGT (Fine-Grained Traps) +- FEAT_FGWTE3 (Fine-Grained Write Trap EL3) - FEAT_FHM (Floating-point half-precision multiplication instructions) - FEAT_FP (Floating Point extensions) - FEAT_FP16 (Half-precision floating-point data processing)
Signature · 1 line
2.43.0
Peter Maydell
AppliedQuoted 11 lines · Richard Henderson
Based-on: [email protected] ("[PATCH 0/7] target/arm: Introduce cpu types max-v8 and max-v9")
Changes for v2:
- Rebase on the max-v9 split.
- Review comment fixups.
- Set fgt forMECID_RL_A_EL3.r~
Quoted 7 lines
Richard Henderson (6):
target/arm: AddFGWTE3_EL3
target/arm: AddFGWTE3_EL3bit definitions
target/arm: Add FGWTE3 FGT bit definitions
target/arm: Implement FGWTE3 traps
target/arm: Set fgt in cpregs for FGWTE3
target/arm: EnableFEAT_FGWTE3for -cpu max
Applied to target-arm.next, thanks.
-- PMM