target/arm: implement FEAT_RNG_TRAP
cover target/arm: implement FEAT_RNG_TRAP
This series implements FEAT_RNG_TRAP in QEMU's AArch64 emulation and enables it on the cortex-max CPU.
FEAT_RNG_TRAP lets EL3 firmware trap MRS reads of RNDR and RNDRRS by setting SCR_EL3.TRNDR=1. When that bit is set, every read is delivered to EL3 as sysreg trap, from any EL (including EL3).
SCR_TRNDR and ID_AA64PFR1_EL1.RNDR_TRAP are already defined, but had no readers and no CPU advertising the feature. With these two patches, EL3 firmware that detects FEAT_RNG_TRAP via ID_AA64PFR1_EL1 and sets SCR_EL3.TRNDR receives the architected trap.
Patch 1 adds the implementation: an .accessfn on the RNDR/RNDRRS ARMCPRegInfo entries that returns CP_ACCESS_TRAP_EL3 whenever SCR_EL3.TRNDR is set, plus a one-line addition to scr_write()'s valid_mask to keep the bit writable when the CPU advertises the feature. It is a no-op on its own because no CPU model yet advertises FEAT_RNG_TRAP.
Patch 2 enables FEAT_RNG_TRAP on cortex-max by setting ID_AA64PFR1_EL1.RNDR_trap=1.
Jason Wright (2):
target/arm: implement FEAT_RNG_TRAP for RNDR/RNDRRS target/arm: advertise FEAT_RNG_TRAP on cortex-max
target/arm/cpu-features.h | 5 +++++ target/arm/helper.c | 16 ++++++++++++++-- target/arm/tcg/cpu64.c | 1 + 3 files changed, 20 insertions(+), 2 deletions(-)
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH 1/2 target/arm: implement FEAT_RNG_TRAP for RNDR/RNDRRS
Add an .accessfn to the RNDR and RNDRRS system registers that traps reads to EL3 when SCR_EL3.TRNDR is set, as required by FEAT_RNG_TRAP. Mark SCR_EL3.TRNDR (bit 40) as a writable field in scr_write() when the CPU advertises the feature. The pseudocode in DDI04387 revision M.b shows the trap firing from El0, EL1, EL2, and EL3, so there is no check of arm_current_el().
--- target/arm/cpu-features.h | 5 +++++ target/arm/helper.c | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-)
target/arm/cpu-features.h +5 -0
@@ -890,6 +890,11 @@ static inline bool isar_feature_aa64_rndr(const ARMISARegisters *id)return FIELD_EX64_IDREG (id,ID_AA64ISAR0 ,RNDR ) !=0 ; } +static inline bool isar_feature_aa64_rng_trap (const ARMISARegisters *id) +{ +return FIELD_EX64_IDREG (id,ID_AA64PFR1 ,RNDR_TRAP ) !=0 ; +} +static inline bool isar_feature_aa64_tlbirange (const ARMISARegisters *id) {return FIELD_EX64_IDREG (id,ID_AA64ISAR0 ,TLB ) ==2 ;
target/arm/helper.c +14 -2
@@ -787,6 +787,9 @@ static void scr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)if (cpu_isar_feature (aa64_mec, cpu)) { valid_mask |=SCR_MECEN ; } +if (cpu_isar_feature (aa64_rng_trap, cpu)) { + valid_mask |=SCR_TRNDR ; + } }else { valid_mask &= ~(SCR_RW |SCR_ST );if (cpu_isar_feature (aa32_ras, cpu)) {
@@ -5294,6 +5297,15 @@ static const ARMCPRegInfo pauth_reginfo[] = { .fieldoffset = offsetof(CPUARMState, keys.apib.hi) }, }; +static CPAccessResult access_rndr (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +if (env->cp15.scr_el3 &SCR_TRNDR ) { +return CP_ACCESS_TRAP_EL3 ; + } +return CP_ACCESS_OK ; +} +static uint64_t rndr_readfn (CPUARMState *env,const ARMCPRegInfo *ri) {Error *err =NULL ;
@@ -5325,11 +5337,11 @@ static const ARMCPRegInfo rndr_reginfo[] = { { .name = "RNDR", .state = ARM_CP_STATE_AA64, .type = ARM_CP_NO_RAW | ARM_CP_SUPPRESS_TB_END | ARM_CP_IO, .opc0 = 3, .opc1 = 3, .crn = 2, .crm = 4, .opc2 = 0, - .access = PL0_R, .readfn = rndr_readfn }, + .access = PL0_R, .accessfn = access_rndr, .readfn = rndr_readfn }, { .name = "RNDRRS", .state = ARM_CP_STATE_AA64, .type = ARM_CP_NO_RAW | ARM_CP_SUPPRESS_TB_END | ARM_CP_IO, .opc0 = 3, .opc1 = 3, .crn = 2, .crm = 4, .opc2 = 1, - .access = PL0_R, .readfn = rndr_readfn }, + .access = PL0_R, .accessfn = access_rndr, .readfn = rndr_readfn }, }; static void dccvap_writefn(CPUARMState *env, const ARMCPRegInfo *ri,
Signature · 1 line
2.50.1 (Apple Git-155)
Re: [PATCH 1/2] target/arm: implement FEAT_RNG_TRAP for RNDR/RNDRRS
I did this myself 9 months ago, but never posted it for some reason.
https://gitlab.com/rth7680/qemu/-/commit/2598d4896e19376fbae3926728ac737e7bbea190
The only difference I have is
target/arm/helper.c static const ARMCPRegInfo pauth_reginfo[] = { · line 5307
Quoted 8 lines
target/arm/helper.c +8
-0+static CPAccessResult access_rndr (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +if (env->cp15.scr_el3 &SCR_TRNDR ) { +return CP_ACCESS_TRAP_EL3 ; + } +return CP_ACCESS_OK ; +}
static CPAccessResult access_rndr(CPUARMState *env, const ARMCPRegInfo *ri,
bool isread)
{
if (env->cp15.scr_el3 & SCR_TRNDR) {
return CP_ACCESS_TRAP_EL3;
}
/*
* Note that FEAT_RNDR_TRAP may be implemented without FEAT_RNDR.
* In that case, if the trap is not enabled, the read undefs.
*/
if (!cpu_isar_feature(aa64_rndr, env_archcpu(env))) {
return CP_ACCESS_UNDEFINED;
}
return CP_ACCESS_OK;
}...
if (cpu_isar_feature(aa64_rndr, cpu) ||
cpu_isar_feature(aa64_rndr_trap, cpu)) {
define_arm_cp_regs(cpu, rndr_reginfo);
}r~
Re: [PATCH 1/2] target/arm: implement FEAT_RNG_TRAP for RNDR/RNDRRS
Quoted 6 lines · Richard Henderson
I did this myself 9 months ago, but never posted it for some reason.
https://gitlab.com/rth7680/qemu/-/commit/2598d4896e19376fbae3926728ac737e7bbea190
static CPAccessResult access_rndr(CPUARMState *env, const ARMCPRegInfo *ri,
bool isread)
Quoted 11 lines
{
if (env->cp15.scr_el3 & SCR_TRNDR) {
return CP_ACCESS_TRAP_EL3;
}
/*
* Note that FEAT_RNDR_TRAP may be implemented without FEAT_RNDR.
* In that case, if the trap is not enabled, the read undefs.
*/
if (!cpu_isar_feature(aa64_rndr, env_archcpu(env))) {
return CP_ACCESS_UNDEFINED;
}Should I pull this into my diff and resubmit? It's definitely the right idea (I didn't think about this possibility).
Quoted 6 lines
if (cpu_isar_feature(aa64_rndr, cpu) ||
cpu_isar_feature(aa64_rndr_trap, cpu)) {
define_arm_cp_regs(cpu, rndr_reginfo);
}Same with this? (adding the || rndr_trap to what is already there).
--Jason Wright
Re: [PATCH 1/2] target/arm: implement FEAT_RNG_TRAP for RNDR/RNDRRS
Quoted 22 lines · Jason L. Wright
Quoted 6 lines · Richard Henderson
I did this myself 9 months ago, but never posted it for some reason.
https://gitlab.com/rth7680/qemu/-/commit/2598d4896e19376fbae3926728ac737e7bbea190
static CPAccessResult access_rndr(CPUARMState *env, const ARMCPRegInfo *ri,
bool isread)Quoted 11 lines
{ if (env->cp15.scr_el3 & SCR_TRNDR) { return CP_ACCESS_TRAP_EL3; } /* * Note that FEAT_RNDR_TRAP may be implemented without FEAT_RNDR. * In that case, if the trap is not enabled, the read undefs. */ if (!cpu_isar_feature(aa64_rndr, env_archcpu(env))) { return CP_ACCESS_UNDEFINED; }Should I pull this into my diff and resubmit? It's definitely the right idea (I didn't think about this possibility).
Quoted 1 line
Quoted 6 lines
Quoted 5 lines
if (cpu_isar_feature(aa64_rndr, cpu) || cpu_isar_feature(aa64_rndr_trap, cpu)) { define_arm_cp_regs(cpu, rndr_reginfo); }Same with this? (adding the ||
rndr_trapto what is already there).
Yes, I think so.
r~
PATCH 2/2 target/arm: advertise FEAT_RNG_TRAP on cortex-max
In reply to Jason WrightSet ID_AA64PFR1.RNDR_TRAP=1 on the max CPU model so guests and firmware detect FEAT_RNG_TRAP, per the Arm Architecture Reference Manual for A-profile architecture (DDI 0487).
--- target/arm/tcg/cpu64.c | 1 + 1 file changed, 1 insertion(+)
target/arm/tcg/cpu64.c +1 -0
@@ -1291,6 +1291,7 @@ void aarch64_max_tcg_initfn(Object *obj) t =FIELD_DP64 (t,ID_AA64PFR1 ,CSV2_FRAC ,0 );/* FEAT_CSV2_3 */ t =FIELD_DP64 (t,ID_AA64PFR1 ,NMI ,1 );/* FEAT_NMI */ t =FIELD_DP64 (t,ID_AA64PFR1 ,GCS ,1 );/* FEAT_GCS */ + t =FIELD_DP64 (t,ID_AA64PFR1 ,RNDR_TRAP ,1 );/* FEAT_RNG_TRAP */ SET_IDREG (isar,ID_AA64PFR1 , t); t =GET_IDREG (isar,ID_AA64MMFR0 );
Signature · 1 line
2.50.1 (Apple Git-155)
v2 cover target/arm: implement FEAT_RNG_TRAP
In reply to Jason WrightImplement FEAT_RNG_TRAP for RNDR/RNDRRS and enable it on cortex-max.
v2:
- access_rndr: return CP_ACCESS_UNDEFINED when FEAT_RNG_TRAP is present but FEAT_RNG is not and the trap is disabled (Richard Henderson)
- Register rndr_reginfo when either FEAT_RNG or FEAT_RNG_TRAP is implemented, not only FEAT_RNG (Richard Henderson)
- Fix document number typo in Patch 1 commit message
Jason Wright (2):
target/arm: implement FEAT_RNG_TRAP for RNDR/RNDRRS target/arm: advertise FEAT_RNG_TRAP on cortex-max
target/arm/cpu-features.h | 5 +++++ target/arm/helper.c | 26 +++++++++++++++++++++++--- target/arm/tcg/cpu64.c | 1 + 3 files changed, 29 insertions(+), 3 deletions(-)
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v2 1/2 target/arm: implement FEAT_RNG_TRAP for RNDR/RNDRRS
Add an .accessfn to the RNDR and RNDRRS system registers that traps reads to EL3 when SCR_EL3.TRNDR is set, as required by FEAT_RNG_TRAP. Mark SCR_EL3.TRNDR (bit 40) as a writable field in scr_write() when the CPU advertises the feature. The pseudocode in DDI0487 revision M.b shows the trap firing from EL0, EL1, EL2, and EL3, so there is no check of arm_current_el().
When FEAT_RNG_TRAP is implemented without FEAT_RNG, an RNDR/RNDRRS read with SCR_EL3.TRNDR=0 should UNDEF rather than succeed; handle that case in access_rndr(). Register the rndr_reginfo CP reg entries whenever either FEAT_RNG or FEAT_RNG_TRAP is implemented, so the accessfn fires even on a FEAT_RNG_TRAP-only CPU.
--- target/arm/cpu-features.h | 5 +++++ target/arm/helper.c | 26 +++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-)
target/arm/cpu-features.h +5 -0
@@ -890,6 +890,11 @@ static inline bool isar_feature_aa64_rndr(const ARMISARegisters *id)return FIELD_EX64_IDREG (id,ID_AA64ISAR0 ,RNDR ) !=0 ; } +static inline bool isar_feature_aa64_rng_trap (const ARMISARegisters *id) +{ +return FIELD_EX64_IDREG (id,ID_AA64PFR1 ,RNDR_TRAP ) !=0 ; +} +static inline bool isar_feature_aa64_tlbirange (const ARMISARegisters *id) {return FIELD_EX64_IDREG (id,ID_AA64ISAR0 ,TLB ) ==2 ;
target/arm/helper.c +23 -3
@@ -787,6 +787,9 @@ static void scr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)if (cpu_isar_feature (aa64_mec, cpu)) { valid_mask |=SCR_MECEN ; } +if (cpu_isar_feature (aa64_rng_trap, cpu)) { + valid_mask |=SCR_TRNDR ; + } }else { valid_mask &= ~(SCR_RW |SCR_ST );if (cpu_isar_feature (aa32_ras, cpu)) {
@@ -5294,6 +5297,22 @@ static const ARMCPRegInfo pauth_reginfo[] = { .fieldoffset = offsetof(CPUARMState, keys.apib.hi) }, }; +static CPAccessResult access_rndr (CPUARMState *env,const ARMCPRegInfo *ri, +bool isread) +{ +if (env->cp15.scr_el3 &SCR_TRNDR ) { +return CP_ACCESS_TRAP_EL3 ; + } +/* +* Note that FEAT_RNG_TRAP may be implemented without FEAT_RNG. +* In that case, if the trap is not enabled, the read undefs. +*/ +if (!cpu_isar_feature (aa64_rndr,env_archcpu (env))) { +return CP_ACCESS_UNDEFINED ; + } +return CP_ACCESS_OK ; +} +static uint64_t rndr_readfn (CPUARMState *env,const ARMCPRegInfo *ri) {Error *err =NULL ;
@@ -5325,11 +5344,11 @@ static const ARMCPRegInfo rndr_reginfo[] = { { .name = "RNDR", .state = ARM_CP_STATE_AA64, .type = ARM_CP_NO_RAW | ARM_CP_SUPPRESS_TB_END | ARM_CP_IO, .opc0 = 3, .opc1 = 3, .crn = 2, .crm = 4, .opc2 = 0, - .access = PL0_R, .readfn = rndr_readfn }, + .access = PL0_R, .accessfn = access_rndr, .readfn = rndr_readfn }, { .name = "RNDRRS", .state = ARM_CP_STATE_AA64, .type = ARM_CP_NO_RAW | ARM_CP_SUPPRESS_TB_END | ARM_CP_IO, .opc0 = 3, .opc1 = 3, .crn = 2, .crm = 4, .opc2 = 1, - .access = PL0_R, .readfn = rndr_readfn }, + .access = PL0_R, .accessfn = access_rndr, .readfn = rndr_readfn }, }; static void dccvap_writefn(CPUARMState *env, const ARMCPRegInfo *ri,
@@ -7423,7 +7442,8 @@ void register_cp_regs_for_features(ARMCPU *cpu)if (cpu_isar_feature (aa64_pauth, cpu)) {define_arm_cp_regs (cpu, pauth_reginfo); } -if (cpu_isar_feature (aa64_rndr, cpu)) { +if (cpu_isar_feature (aa64_rndr, cpu) || +cpu_isar_feature (aa64_rng_trap, cpu)) {define_arm_cp_regs (cpu, rndr_reginfo); }/* Data Cache clean instructions up to PoP */
Signature · 1 line
2.50.1 (Apple Git-155)
Re: [PATCH v2 1/2] target/arm: implement FEAT_RNG_TRAP for RNDR/RNDRRS
Quoted 8 lines · Jason Wright
Add an .accessfn to the RNDR and RNDRRS system registers that traps reads to EL3 when SCR_EL3.TRNDR is set, as required by
FEAT_RNG_TRAP. Mark SCR_EL3.TRNDR (bit 40) as a writable field inscr_write()when the CPU advertises the feature. The pseudocode in DDI0487 revision M.b shows the trap firing from EL0, EL1, EL2, and EL3, so there is no check ofarm_current_el().
Quoted 8 lines
When
FEAT_RNG_TRAPis implemented withoutFEAT_RNG, an RNDR/RNDRRS read with SCR_EL3.TRNDR=0 should UNDEF rather than succeed; handle that case inaccess_rndr(). Register therndr_reginfoCP reg entries whenever eitherFEAT_RNGorFEAT_RNG_TRAPis implemented, so the accessfn fires even on a FEAT_RNG_TRAP-only CPU.Suggested-by Richard Henderson <[email protected]>Signed-off-by Jason Wright <[email protected]>
SCR_EL3.TRNDR = 1 also does one other thing: when it is set, ID_AA64ISAR0_EL1.RNDR reads as 0b0001, regardless of whether FEAT_RNG is implemented. (When TRNDR = 0, ID_AA64ISAR0_EL1.RNDR reports the presence or absence of FEAT_RNG as usual.)
It looks like this patch has missed that bit. We need to give that ID register a readfn so it can at runtime report the different value if necessary, similar to what we do with id_aa64pfr0_read().
thanks
-- PMM
PATCH v2 2/2 target/arm: advertise FEAT_RNG_TRAP on cortex-max
In reply to Jason WrightSet ID_AA64PFR1.RNDR_TRAP=1 on the max CPU model so guests and firmware detect FEAT_RNG_TRAP, per the Arm Architecture Reference Manual for A-profile architecture (DDI 0487).
--- target/arm/tcg/cpu64.c | 1 + 1 file changed, 1 insertion(+)
target/arm/tcg/cpu64.c +1 -0
@@ -1291,6 +1291,7 @@ void aarch64_max_tcg_initfn(Object *obj) t =FIELD_DP64 (t,ID_AA64PFR1 ,CSV2_FRAC ,0 );/* FEAT_CSV2_3 */ t =FIELD_DP64 (t,ID_AA64PFR1 ,NMI ,1 );/* FEAT_NMI */ t =FIELD_DP64 (t,ID_AA64PFR1 ,GCS ,1 );/* FEAT_GCS */ + t =FIELD_DP64 (t,ID_AA64PFR1 ,RNDR_TRAP ,1 );/* FEAT_RNG_TRAP */ SET_IDREG (isar,ID_AA64PFR1 , t); t =GET_IDREG (isar,ID_AA64MMFR0 );
Signature · 1 line
2.50.1 (Apple Git-155)
Re: [PATCH v2 2/2] target/arm: advertise FEAT_RNG_TRAP on cortex-max
Quoted 15 lines · Jason Wright
Set ID_AA64PFR1.RNDR_TRAP=1 on the max CPU model so guests and firmware detect
FEAT_RNG_TRAP, per the Arm Architecture Reference Manual for A-profile architecture (DDI 0487).Signed-off-by Jason Wright <[email protected]>--- target/arm/tcg/cpu64.c | 1 + 1 file changed, 1 insertion(+)target/arm/tcg/cpu64.c +0
-0
target/arm/tcg/cpu64.c void aarch64_max_tcg_initfn(Object *obj) · line 1294
Quoted 4 lines
target/arm/tcg/cpu64.c +1
-0@@ -1291,6 +1291,7 @@ void aarch64_max_tcg_initfn(Object *obj) t =FIELD_DP64 (t,ID_AA64PFR1 ,CSV2_FRAC ,0 );/* FEAT_CSV2_3 */ t =FIELD_DP64 (t,ID_AA64PFR1 ,NMI ,1 );/* FEAT_NMI */ t =FIELD_DP64 (t,ID_AA64PFR1 ,GCS ,1 );/* FEAT_GCS */ + t =FIELD_DP64 (t,ID_AA64PFR1 ,RNDR_TRAP ,1 );/* FEAT_RNG_TRAP */
I think we try to keep these sorted in the order of the fields in the ID register: RNDR_TRAP comes after SME and before CSV2_FRAC.
target/arm/tcg/cpu64.c void aarch64_max_tcg_initfn(Object *obj) · line 1297
Quoted 3 lines
target/arm/tcg/cpu64.c +0
-0SET_IDREG (isar,ID_AA64PFR1 , t); t =GET_IDREG (isar,ID_AA64MMFR0 );
We also need to document that we now support emulation of this feature, by adding a line to docs/system/arm/emulation.rst:
- FEAT_RNG_TRAP (Trapping support for RNDR/RNDRRS)
thanks
-- PMM
v3 cover target/arm: implement FEAT_RNG_TRAP
In reply to Jason WrightImplement FEAT_RNG_TRAP for RNDR/RNDRRS and enable it on cortex-max.
v3:
- helper.c: give ID_AA64ISAR0_EL1 a readfn so that ID_AA64ISAR0_EL1.RNDR reads as 1 whenever SCR_EL3.TRNDR is set, regardless of whether FEAT_RNG is implemented (Peter Maydell)
- cpu64.c: keep the ID_AA64PFR1 fields in register bit-field order; RNDR_TRAP now sits after SME and before CSV2_FRAC (Peter Maydell)
- docs: list FEAT_RNG_TRAP in docs/system/arm/emulation.rst (Peter Maydell)
v2:
- access_rndr: return CP_ACCESS_UNDEFINED when FEAT_RNG_TRAP is present but FEAT_RNG is not and the trap is disabled (Richard Henderson)
- Register rndr_reginfo when either FEAT_RNG or FEAT_RNG_TRAP is implemented, not only FEAT_RNG (Richard Henderson)
- Fix document number typo in Patch 1 commit message
Jason Wright (2):
target/arm: implement FEAT_RNG_TRAP for RNDR/RNDRRS target/arm: advertise FEAT_RNG_TRAP on cortex-max
docs/system/arm/emulation.rst | 1 + target/arm/cpu-features.h | 5 +++ target/arm/helper.c | 58 ++++++++++++++++++++++++++++++++--- target/arm/tcg/cpu64.c | 1 + 4 files changed, 60 insertions(+), 5 deletions(-)
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v3 1/2 target/arm: implement FEAT_RNG_TRAP for RNDR/RNDRRS
Add an .accessfn to the RNDR and RNDRRS system registers that traps reads to EL3 when SCR_EL3.TRNDR is set, as required by FEAT_RNG_TRAP. Mark SCR_EL3.TRNDR (bit 40) as a writable field in scr_write() when the CPU advertises the feature. The pseudocode in DDI0487 revision M.b shows the trap firing from EL0, EL1, EL2, and EL3, so there is no check of arm_current_el().
When FEAT_RNG_TRAP is implemented without FEAT_RNG, an RNDR/RNDRRS read with SCR_EL3.TRNDR=0 should UNDEF rather than succeed; handle that case in access_rndr(). Register the rndr_reginfo CP reg entries whenever either FEAT_RNG or FEAT_RNG_TRAP is implemented, so the accessfn fires even on a FEAT_RNG_TRAP-only CPU.
When SCR_EL3.TRNDR is set, ID_AA64ISAR0_EL1.RNDR reads as 1 regardless of whether FEAT_RNG is implemented; give ID_AA64ISAR0_EL1 a readfn so it reports this at runtime, as we already do for ID_AA64PFR0_EL1.
--- target/arm/cpu-features.h | 5 ++++ target/arm/helper.c | 58 +++++++++++++++++++++++++++++++++++---- 2 files changed, 58 insertions(+), 5 deletions(-)
target/arm/cpu-features.h +5 -0
@@ -908,6 +908,11 @@ static inline bool isar_feature_aa64_rndr(const ARMISARegisters *id)return FIELD_EX64_IDREG (id,ID_AA64ISAR0 ,RNDR ) !=0 ; } +static inline bool isar_feature_aa64_rng_trap (const ARMISARegisters *id) +{ +return FIELD_EX64_IDREG (id,ID_AA64PFR1 ,RNDR_TRAP ) !=0 ; +} +static inline bool isar_feature_aa64_tlbirange (const ARMISARegisters *id) {return FIELD_EX64_IDREG (id,ID_AA64ISAR0 ,TLB ) ==2 ;
target/arm/helper.c +53 -5
100 lines not on this page · raw message
Signature · 1 line
2.50.1 (Apple Git-155)
Re: [PATCH v3 1/2] target/arm: implement FEAT_RNG_TRAP for RNDR/RNDRRS
Quoted 17 lines · Jason Wright
Add an .accessfn to the RNDR and RNDRRS system registers that traps reads to EL3 when SCR_EL3.TRNDR is set, as required by
FEAT_RNG_TRAP. Mark SCR_EL3.TRNDR (bit 40) as a writable field inscr_write()when the CPU advertises the feature. The pseudocode in DDI0487 revision M.b shows the trap firing from EL0, EL1, EL2, and EL3, so there is no check ofarm_current_el().When
FEAT_RNG_TRAPis implemented withoutFEAT_RNG, an RNDR/RNDRRS read with SCR_EL3.TRNDR=0 should UNDEF rather than succeed; handle that case inaccess_rndr(). Register therndr_reginfoCP reg entries whenever eitherFEAT_RNGorFEAT_RNG_TRAPis implemented, so the accessfn fires even on a FEAT_RNG_TRAP-only CPU.When SCR_EL3.TRNDR is set, ID_AA64ISAR0_EL1.RNDR reads as 1 regardless of whether
FEAT_RNGis implemented; giveID_AA64ISAR0_EL1a readfn so it reports this at runtime, as we already do forID_AA64PFR0_EL1.
Quoted 7 lines
Suggested-by Richard Henderson<[email protected]>Suggested-by Peter Maydell<[email protected]>Signed-off-by Jason Wright<[email protected]>--- target/arm/cpu-features.h | 5 ++++ target/arm/helper.c | 58 +++++++++++++++++++++++++++++++++++---- 2 files changed, 58 insertions(+), 5 deletions(-)
r~
PATCH v3 2/2 target/arm: advertise FEAT_RNG_TRAP on cortex-max
In reply to Jason WrightSet ID_AA64PFR1.RNDR_TRAP=1 on the max CPU model so guests and firmware detect FEAT_RNG_TRAP, per the Arm Architecture Reference Manual for A-profile architecture (DDI 0487), and document the feature as emulated in docs/system/arm/emulation.rst.
--- docs/system/arm/emulation.rst | 1 + target/arm/tcg/cpu64.c | 1 + 2 files changed, 2 insertions(+)
docs/system/arm/emulation.rst +1 -0
@@ -135,6 +135,7 @@ the following architecture extensions: - FEAT_RME (Realm Management Extension) (NB: support status in QEMU is experimental) - FEAT_RME_GPC2 (RME Granule Protection Check 2 Extension) - FEAT_RNG (Random number generator) +- FEAT_RNG_TRAP (Trapping support for RNDR/RNDRRS) - FEAT_RPRES (Increased precision of FRECPE and FRSQRTE) - FEAT_S1PIE (Stage 1 permission indirections) - FEAT_S2PIE (Stage 2 permission indirections)
target/arm/tcg/cpu64.c +1 -0
@@ -1292,6 +1292,7 @@ void aarch64_max_tcg_initfn(Object *obj) t =FIELD_DP64 (t,ID_AA64PFR1 ,MTE ,3 );/* FEAT_MTE3 */ t =FIELD_DP64 (t,ID_AA64PFR1 ,RAS_FRAC ,0 );/* FEAT_RASv1p1 + FEAT_DoubleFault */ t =FIELD_DP64 (t,ID_AA64PFR1 ,SME ,2 );/* FEAT_SME2 */ + t =FIELD_DP64 (t,ID_AA64PFR1 ,RNDR_TRAP ,1 );/* FEAT_RNG_TRAP */ t =FIELD_DP64 (t,ID_AA64PFR1 ,CSV2_FRAC ,0 );/* FEAT_CSV2_3 */ t =FIELD_DP64 (t,ID_AA64PFR1 ,NMI ,1 );/* FEAT_NMI */ t =FIELD_DP64 (t,ID_AA64PFR1 ,GCS ,1 );/* FEAT_GCS */
Signature · 1 line
2.50.1 (Apple Git-155)
Re: [PATCH v3 2/2] target/arm: advertise FEAT_RNG_TRAP on cortex-max
Quoted 10 lines · Jason Wright
Set ID_AA64PFR1.RNDR_TRAP=1 on the max CPU model so guests and firmware detect
FEAT_RNG_TRAP, per the Arm Architecture Reference Manual for A-profile architecture (DDI 0487), and document the feature as emulated indocs/system/arm/emulation.rst.Signed-off-by Jason Wright<[email protected]>--- docs/system/arm/emulation.rst | 1 + target/arm/tcg/cpu64.c | 1 + 2 files changed, 2 insertions(+)
r~
Peter Maydell
AppliedQuoted 20 lines · Jason Wright
Implement
FEAT_RNG_TRAPfor RNDR/RNDRRS and enable it on cortex-max.v3:
-helper.c: giveID_AA64ISAR0_EL1a readfn so that ID_AA64ISAR0_EL1.RNDR reads as 1 whenever SCR_EL3.TRNDR is set, regardless of whetherFEAT_RNGis implemented (Peter Maydell)
-cpu64.c: keep theID_AA64PFR1fields in register bit-field order;RNDR_TRAPnow sits after SME and beforeCSV2_FRAC(Peter Maydell)
- docs: listFEAT_RNG_TRAPindocs/system/arm/emulation.rst(Peter Maydell)v2:
-access_rndr: returnCP_ACCESS_UNDEFINEDwhenFEAT_RNG_TRAPis present butFEAT_RNGis not and the trap is disabled (Richard Henderson)
- Registerrndr_reginfowhen eitherFEAT_RNGorFEAT_RNG_TRAPis implemented, not onlyFEAT_RNG(Richard Henderson)
- Fix document number typo in Patch 1 commit message
Quoted 3 lines
Jason Wright (2):
target/arm: implementFEAT_RNG_TRAPfor RNDR/RNDRRS target/arm: advertiseFEAT_RNG_TRAPon cortex-max
Applied to target-arm.next, thanks.
-- PMM