support reading some CPUID/CNT registers from user-space
v3 cover support reading some CPUID/CNT registers from user-space
Hi,
This expands on the previous version by adding the additional CPUID registers as exposed by the HWCAP_CPUID kernel feature. Most of the work involves judicious use of macros. There is a easily extensible test case that uses the shiny new check-tcg infrastructure ;-)
Alex Bennée (5):
target/arm: support reading of CNT[VCT|FRQ]_EL0 from user-space target/arm: relax permission checks for HWCAP_CPUID registers target/arm: expose CPUID registers to userspace linux-user/elfload: enable HWCAP_CPUID for AArch64 tests/tcg/aarch64: userspace system register test
linux-user/elfload.c | 1 + target/arm/cpu.h | 7 +++ target/arm/helper.c | 80 +++++++++++++++++++------ tests/tcg/aarch64/Makefile.target | 2 +- tests/tcg/aarch64/sysregs.c | 99 +++++++++++++++++++++++++++++++ 5 files changed, 170 insertions(+), 19 deletions(-) create mode 100644 tests/tcg/aarch64/sysregs.c
Signature · 1 line
2.17.1
PATCH v3 1/5 target/arm: support reading of CNT[VCT|FRQ]_EL0 from user-space
Since kernel commit a86bd139f2 (arm64: arch_timer: Enable CNTVCT_EL0 trap..) user-space has been able to read these system registers. As we can't use QEMUTimer's in linux-user mode we just directly call cpu_get_clock().
---
v2
- include CNTFRQ_EL0 for PL0_R only
v3
- use NANOSECONDS_PER_SECOND / GTIMER_SCALE
--- target/arm/helper.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-)
target/arm/helper.c +24 -3
@@ -2166,11 +2166,32 @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = { };#else -/* In user-mode none of the generic timer registers are accessible, -* and their implementation depends on QEMU_CLOCK_VIRTUAL and qdev gpio outputs, -* so instead just don't register any of them. + +/* In user-mode most of the generic timer registers are inaccessible +* however modern kernels (4.12+) allow access to cntvct_el0 */ + +static uint64_t gt_virt_cnt_read (CPUARMState *env,const ARMCPRegInfo *ri) +{ +/* Currently we have no support for QEMUTimer in linux-user so we +* can't call gt_get_countervalue(env), instead we directly +* call the lower level functions. +*/ +return cpu_get_clock () /GTIMER_SCALE ; +} +static const ARMCPRegInfo generic_timer_cp_reginfo[] = { + { .name ="CNTFRQ_EL0" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =3 , .crn =14 , .crm =0 , .opc2 =0 , + .type =ARM_CP_CONST , .access =PL0_R /* no PL1_RW in linux-user */ , + .fieldoffset = offsetof(CPUARMState, cp15.c14_cntfrq), + .resetvalue =NANOSECONDS_PER_SECOND /GTIMER_SCALE , + }, + { .name ="CNTVCT_EL0" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =3 , .crn =14 , .crm =0 , .opc2 =2 , + .access =PL0_R , .type =ARM_CP_NO_RAW |ARM_CP_IO , + .readfn = gt_virt_cnt_read, + },REGINFO_SENTINEL };
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH v3 1/5] target/arm: support reading of CNT[VCT|FRQ]_EL0 from user-space
Quoted 7 lines · Alex Bennée
Since kernel commit
a86bd139f2(arm64:arch_timer: EnableCNTVCT_EL0trap..) user-space has been able to read these system registers. As we can't use QEMUTimer's in linux-user mode we just directly callcpu_get_clock().Signed-off-by Alex Bennée <[email protected]>
Quoted 8 lines
---
v2
- includeCNTFRQ_EL0forPL0_Ronly
v3
- useNANOSECONDS_PER_SECOND/GTIMER_SCALE--- target/arm/helper.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-)
r~
Re: [Qemu-devel] [PATCH v3 1/5] target/arm: support reading of CNT[VCT|FRQ]_EL0 from user-space
In reply to Alex BennéeQuoted 2 lines · Alex Bennée
Since kernel commit
a86bd139f2(arm64:arch_timer: EnableCNTVCT_EL0trap..)
I'd also mention here that this feature became available in v4.12.
Thanks,
Emilio
PATCH v3 2/5 target/arm: relax permission checks for HWCAP_CPUID registers
In reply to Alex BennéeAlthough technically not visible to userspace the kernel does make them visible via trap and emulate. For user mode we can provide the value directly but we need to relax our permission checks to do this.
--- target/arm/helper.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
target/arm/helper.c +13 -1
@@ -5813,7 +5813,19 @@ void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu,if (r->state !=ARM_CP_STATE_AA32 ) {int mask =0 ;switch (r->opc1) { -case 0 :case 1 :case 2 : +case 0 : +#ifdef CONFIG_USER_ONLY +/* Some AArch64 CPU ID/feature are exported to userspace +* by the kernel (see HWCAP_CPUID) */ +if (r->opc0 ==3 && r->crn ==0 && + (r->crm ==0 || + (r->crm >=4 && r->crm <=7 ))) { + mask =PL0_R ; +break ; + } +#endif +/* fall-through */ +case 1 :case 2 :/* min_EL EL1 */ mask =PL1_RW ;break ;
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH v3 2/5] target/arm: relax permission checks for HWCAP_CPUID registers
target/arm/helper.c void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu, · line 5826
Quoted 10 lines · Alex Bennée
target/arm/helper.c +10
-0+#ifdef CONFIG_USER_ONLY +/* Some AArch64 CPU ID/feature are exported to userspace +* by the kernel (see HWCAP_CPUID) */ +if (r->opc0 ==3 && r->crn ==0 && + (r->crm ==0 || + (r->crm >=4 && r->crm <=7 ))) { + mask =PL0_R ; +break ; + } +#endif
Why not just set mask to PL0U_R | PL1_RW?
This mask doesn't affect the actual permissions, just the check.
Then of course merge with the next patch.
r~
Re: [PATCH v3 2/5] target/arm: relax permission checks for HWCAP_CPUID registers
In reply to Alex BennéeQuoted 24 lines · Alex Bennée
Although technically not visible to userspace the kernel does make them visible via trap and emulate. For user mode we can provide the value directly but we need to relax our permission checks to do this.
Signed-off-by Alex Bennée <[email protected]>--- target/arm/helper.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)target/arm/helper.c +6
-1@@ -5813,7 +5813,19 @@ void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu,if (r->state !=ARM_CP_STATE_AA32 ) {int mask =0 ;switch (r->opc1) { -case 0 :case 1 :case 2 : +case 0 : +#ifdef CONFIG_USER_ONLY +/* Some AArch64 CPU ID/feature are exported to userspace +* by the kernel (see HWCAP_CPUID) */ + if (r->opc0 == 3 && r->crn == 0 && + (r->crm == 0 ||
target/arm/helper.c void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu, · line 5831
Quoted 10 lines
target/arm/helper.c +7
-0+ (r->crm >= 4 && r->crm <= 7))) { + mask =PL0_R ; +break ; + } +#endif +/* fall-through */ +case 1 :case 2 :/* min_EL EL1 */ mask =PL1_RW ;break ;
This looks like a rather inelegant place to shove a CONFIG_USER_ONLY special case. Isn't there a cleaner way to do whatever this is trying to achieve?
thanks
-- PMM
Re: [PATCH v3 2/5] target/arm: relax permission checks for HWCAP_CPUID registers
Quoted 31 lines · Peter Maydell
Quoted 30 lines · Alex Bennée
Although technically not visible to userspace the kernel does make them visible via trap and emulate. For user mode we can provide the value directly but we need to relax our permission checks to do this.
Signed-off-by Alex Bennée <[email protected]>--- target/arm/helper.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)target/arm/helper.c +12
-1@@ -5813,7 +5813,19 @@ void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu,if (r->state !=ARM_CP_STATE_AA32 ) {int mask =0 ;switch (r->opc1) { -case 0 :case 1 :case 2 : +case 0 : +#ifdef CONFIG_USER_ONLY +/* Some AArch64 CPU ID/feature are exported to userspace +* by the kernel (see HWCAP_CPUID) */ +if (r->opc0 ==3 && r->crn ==0 && + (r->crm ==0 || + (r->crm >=4 && r->crm <=7 ))) { + mask =PL0_R ; +break ; + } +#endif +/* fall-through */
Quoted 8 lines
target/arm/helper.c void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu, · line 5831
Quoted 4 lines
target/arm/helper.c +1
-0+case 1 :case 2 :/* min_EL EL1 */ mask =PL1_RW ;break ;This looks like a rather inelegant place to shove a
CONFIG_USER_ONLYspecial case. Isn't there a cleaner way to do whatever this is trying to achieve?
Well technically those registers aren't accessible to user space and this is a sanity check to ensure we don't accidentally make them accessible. But it does get in the way of emulating the traps for USER_ONLY.
Quoted 3 lines
thanks
-- PMM
--
Alex Bennée
PATCH v3 3/5 target/arm: expose CPUID registers to userspace
In reply to Alex BennéeA number of CPUID registers are exposed to userspace by modern Linux kernels thanks to the "ARM64 CPU Feature Registers" ABI. For CONFIG_USER_ONLY we don't emulate the kernels trap and emulate but instead just lower the read permission to PL0_R (hidden behind the PL1U_R macro).
The ID_AA64PFR0_EL1 is a little special as the GIC version is hidden from userspace so we can define a ARM_CP_CONST version of the register for usermode.
squash! target/arm: expose CPUID registers to userspace
--- target/arm/cpu.h | 7 +++++++ target/arm/helper.c | 39 +++++++++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 14 deletions(-)
target/arm/cpu.h +7 -0
@@ -1924,6 +1924,13 @@ static inline bool cptype_valid(int cptype)#define PL0_R (0x02 | PL1_R)#define PL0_W (0x01 | PL1_W) +/* for AArch64 HWCAP_CPUID to userspace */ +#ifdef CONFIG_USER_ONLY +#define PL1U_R PL0_R +#else +#define PL1U_R PL1_R +#endif +#define PL3_RW (PL3_R | PL3_W)#define PL2_RW (PL2_R | PL2_W)#define PL1_RW (PL1_R | PL1_W)
target/arm/helper.c +25 -14
@@ -2987,7 +2987,7 @@ static uint64_t mpidr_read(CPUARMState *env, const ARMCPRegInfo *ri)static const ARMCPRegInfo mpidr_cp_reginfo[] = { { .name ="MPIDR" , .state =ARM_CP_STATE_BOTH , .opc0 =3 , .crn =0 , .crm =0 , .opc1 =0 , .opc2 =5 , - .access =PL1_R , .readfn = mpidr_read, .type =ARM_CP_NO_RAW }, + .access =PL1U_R , .readfn = mpidr_read, .type =ARM_CP_NO_RAW },REGINFO_SENTINEL };
@@ -4776,6 +4776,7 @@ static uint64_t id_pfr1_read(CPUARMState *env, const ARMCPRegInfo *ri)return pfr1; } +#ifndef CONFIG_USER_ONLY static uint64_t id_aa64pfr0_read (CPUARMState *env,const ARMCPRegInfo *ri) {ARMCPU *cpu =arm_env_get_cpu (env);
@@ -4786,6 +4787,7 @@ static uint64_t id_aa64pfr0_read(CPUARMState *env, const ARMCPRegInfo *ri) }return pfr0; } +#endif void register_cp_regs_for_features (ARMCPU *cpu) {
@@ -4934,18 +4936,26 @@ void register_cp_regs_for_features(ARMCPU *cpu)* define new registers here. */ ARMCPRegInfo v8_idregs[] = { -/* ID_AA64PFR0_EL1 is not a plain ARM_CP_CONST because we don't -* know the right value for the GIC field until after we -* define these regs. +/* ID_AA64PFR0_EL1 is not a plain ARM_CP_CONST for system +* emulation because we don't know the right value for the +* GIC field until after we define these regs. For +* user-mode HWCAP_CPUID emulation the gic bits are masked +* anyway. */ { .name ="ID_AA64PFR0_EL1" , .state =ARM_CP_STATE_AA64 , .opc0 =3 , .opc1 =0 , .crn =0 , .crm =4 , .opc2 =0 , +#ifndef CONFIG_USER_ONLY .access =PL1_R , .type =ARM_CP_NO_RAW , .readfn = id_aa64pfr0_read, - .writefn = arm_cp_write_ignore }, + .writefn = arm_cp_write_ignore +#else + .access =PL0_R , .type =ARM_CP_CONST , + .resetvalue = cpu->id_aa64pfr0 +#endif + }, { .name ="ID_AA64PFR1_EL1" , .state =ARM_CP_STATE_AA64 , .opc0 =3 , .opc1 =0 , .crn =0 , .crm =4 , .opc2 =1 , - .access =PL1_R , .type =ARM_CP_CONST , + .access =PL1U_R , .type =ARM_CP_CONST , .resetvalue = cpu->id_aa64pfr1}, { .name ="ID_AA64PFR2_EL1_RESERVED" , .state =ARM_CP_STATE_AA64 , .opc0 =3 , .opc1 =0 , .crn =0 , .crm =4 , .opc2 =2 ,
@@ -4973,11 +4983,11 @@ void register_cp_regs_for_features(ARMCPU *cpu) .resetvalue = 0 }, { .name = "ID_AA64DFR0_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 5, .opc2 = 0, - .access = PL1_R, .type = ARM_CP_CONST, + .access = PL1U_R, .type = ARM_CP_CONST, .resetvalue = cpu->id_aa64dfr0 }, { .name = "ID_AA64DFR1_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 5, .opc2 = 1, - .access = PL1_R, .type = ARM_CP_CONST, + .access = PL1U_R, .type = ARM_CP_CONST, .resetvalue = cpu->id_aa64dfr1 }, { .name = "ID_AA64DFR2_EL1_RESERVED", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 5, .opc2 = 2,
@@ -5005,11 +5015,11 @@ void register_cp_regs_for_features(ARMCPU *cpu) .resetvalue = 0 }, { .name = "ID_AA64ISAR0_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 6, .opc2 = 0, - .access = PL1_R, .type = ARM_CP_CONST, + .access = PL1U_R, .type = ARM_CP_CONST, .resetvalue = cpu->id_aa64isar0 }, { .name = "ID_AA64ISAR1_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 6, .opc2 = 1, - .access = PL1_R, .type = ARM_CP_CONST, + .access = PL1U_R, .type = ARM_CP_CONST, .resetvalue = cpu->id_aa64isar1 }, { .name = "ID_AA64ISAR2_EL1_RESERVED", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 6, .opc2 = 2,
@@ -5037,11 +5047,11 @@ void register_cp_regs_for_features(ARMCPU *cpu) .resetvalue = 0 }, { .name = "ID_AA64MMFR0_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 7, .opc2 = 0, - .access = PL1_R, .type = ARM_CP_CONST, + .access = PL1U_R, .type = ARM_CP_CONST, .resetvalue = cpu->id_aa64mmfr0 }, { .name = "ID_AA64MMFR1_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 7, .opc2 = 1, - .access = PL1_R, .type = ARM_CP_CONST, + .access = PL1U_R, .type = ARM_CP_CONST, .resetvalue = cpu->id_aa64mmfr1 }, { .name = "ID_AA64MMFR2_EL1_RESERVED", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 7, .opc2 = 2,
@@ -5335,7 +5345,7 @@ void register_cp_regs_for_features(ARMCPU *cpu)ARMCPRegInfo id_v8_midr_cp_reginfo[] = { { .name ="MIDR_EL1" , .state =ARM_CP_STATE_BOTH , .opc0 =3 , .opc1 =0 , .crn =0 , .crm =0 , .opc2 =0 , - .access =PL1_R , .type =ARM_CP_NO_RAW , .resetvalue = cpu->midr, + .access =PL1U_R , .type =ARM_CP_NO_RAW , .resetvalue = cpu->midr, .fieldoffset = offsetof(CPUARMState, cp15.c0_cpuid), .readfn = midr_read },/* crn = 0 op1 = 0 crm = 0 op2 = 4,7 : AArch32 aliases of MIDR */
@@ -5347,7 +5357,8 @@ void register_cp_regs_for_features(ARMCPU *cpu) .access = PL1_R, .resetvalue = cpu->midr }, { .name = "REVIDR_EL1", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 0, .opc2 = 6, - .access = PL1_R, .type = ARM_CP_CONST, .resetvalue = cpu->revidr }, + .access = PL1U_R, .type = ARM_CP_CONST, + .resetvalue = cpu->revidr },REGINFO_SENTINEL }; ARMCPRegInfo id_cp_reginfo[] = {
Signature · 1 line
2.17.1
Re: [PATCH v3 3/5] target/arm: expose CPUID registers to userspace
Quoted 23 lines · Alex Bennée
A number of CPUID registers are exposed to userspace by modern Linux kernels thanks to the "ARM64 CPU Feature Registers" ABI. For
CONFIG_USER_ONLYwe don't emulate the kernels trap and emulate but instead just lower the read permission toPL0_R(hidden behind thePL1U_Rmacro).The
ID_AA64PFR0_EL1is a little special as the GIC version is hidden from userspace so we can define aARM_CP_CONSTversion of the register for usermode.Signed-off-by Alex Bennée <[email protected]>squash! target/arm: expose CPUID registers to userspace
--- target/arm/cpu.h | 7 +++++++ target/arm/helper.c | 39 +++++++++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 14 deletions(-)target/arm/cpu.h +0
-0
target/arm/cpu.h static inline bool cptype_valid(int cptype) · line 1927
Quoted 4 lines
target/arm/cpu.h +1
-0@@ -1924,6 +1924,13 @@ static inline bool cptype_valid(int cptype)#define PL0_R (0x02 | PL1_R)#define PL0_W (0x01 | PL1_W) +/* for AArch64 HWCAP_CPUID to userspace */
The comment here should define what the semantics of this new #define are.
Quoted 34 lines
target/arm/cpu.h +6
-0+#ifdef CONFIG_USER_ONLY +#define PL1U_R PL0_R +#else +#define PL1U_R PL1_R +#endif +#define PL3_RW (PL3_R | PL3_W)#define PL2_RW (PL2_R | PL2_W)#define PL1_RW (PL1_R | PL1_W)void
register_cp_regs_for_features(ARMCPU *cpu)
{target/arm/cpu.h +9
-4@@ -4934,18 +4936,26 @@ void register_cp_regs_for_features(ARMCPU *cpu)* define new registers here. */ ARMCPRegInfo v8_idregs[] = { -/* ID_AA64PFR0_EL1 is not a plain ARM_CP_CONST because we don't -* know the right value for the GIC field until after we -* define these regs. +/* ID_AA64PFR0_EL1 is not a plain ARM_CP_CONST for system +* emulation because we don't know the right value for the +* GIC field until after we define these regs. For +* user-mode HWCAP_CPUID emulation the gic bits are masked +* anyway. */ { .name ="ID_AA64PFR0_EL1" , .state =ARM_CP_STATE_AA64 , .opc0 =3 , .opc1 =0 , .crn =0 , .crm =4 , .opc2 =0 , +#ifndef CONFIG_USER_ONLY .access =PL1_R , .type =ARM_CP_NO_RAW , .readfn = id_aa64pfr0_read, - .writefn = arm_cp_write_ignore }, + .writefn = arm_cp_write_ignore +#else + .access =PL0_R , .type =ARM_CP_CONST ,
target/arm/cpu.h void register_cp_regs_for_features(ARMCPU *cpu) · line 4961
Quoted 10 lines
target/arm/cpu.h +4
-1+ .resetvalue = cpu->id_aa64pfr0 +#endif + }, { .name = "ID_AA64PFR1_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 4, .opc2 = 1, - .access = PL1_R, .type = ARM_CP_CONST, + .access = PL1U_R, .type = ARM_CP_CONST, .resetvalue = cpu->id_aa64pfr1}, { .name = "ID_AA64PFR2_EL1_RESERVED", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 4, .opc2 = 2,
The spec says that the values revealed to userspace are masked, so only certain fields are shown to userspace and others (reserved, impdef, invisible fields) are masked out and replaced with fixed values. I don't see where in this patchset we're doing that.
Also, in order to correctly reveal the ID regs to linux-user code, we need to set them correctly for what we're emulating, which at the moment we do not if the cpu is 'max' or 'any'. (See the comment in arm_max_initfn().)
Quoted 52 lines
target/arm/cpu.h +7
-7@@ -4973,11 +4983,11 @@ void register_cp_regs_for_features(ARMCPU *cpu) .resetvalue = 0 }, { .name = "ID_AA64DFR0_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 5, .opc2 = 0, - .access = PL1_R, .type = ARM_CP_CONST, + .access = PL1U_R, .type = ARM_CP_CONST, .resetvalue = cpu->id_aa64dfr0 }, { .name = "ID_AA64DFR1_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 5, .opc2 = 1, - .access = PL1_R, .type = ARM_CP_CONST, + .access = PL1U_R, .type = ARM_CP_CONST, .resetvalue = cpu->id_aa64dfr1 }, { .name = "ID_AA64DFR2_EL1_RESERVED", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 5, .opc2 = 2,@@ -5005,11 +5015,11 @@ void register_cp_regs_for_features(ARMCPU *cpu) .resetvalue = 0 }, { .name = "ID_AA64ISAR0_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 6, .opc2 = 0, - .access = PL1_R, .type = ARM_CP_CONST, + .access = PL1U_R, .type = ARM_CP_CONST, .resetvalue = cpu->id_aa64isar0 }, { .name = "ID_AA64ISAR1_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 6, .opc2 = 1, - .access = PL1_R, .type = ARM_CP_CONST, + .access = PL1U_R, .type = ARM_CP_CONST, .resetvalue = cpu->id_aa64isar1 }, { .name = "ID_AA64ISAR2_EL1_RESERVED", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 6, .opc2 = 2,@@ -5037,11 +5047,11 @@ void register_cp_regs_for_features(ARMCPU *cpu) .resetvalue = 0 }, { .name = "ID_AA64MMFR0_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 7, .opc2 = 0, - .access = PL1_R, .type = ARM_CP_CONST, + .access = PL1U_R, .type = ARM_CP_CONST, .resetvalue = cpu->id_aa64mmfr0 }, { .name = "ID_AA64MMFR1_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 7, .opc2 = 1, - .access = PL1_R, .type = ARM_CP_CONST, + .access = PL1U_R, .type = ARM_CP_CONST, .resetvalue = cpu->id_aa64mmfr1 }, { .name = "ID_AA64MMFR2_EL1_RESERVED", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 7, .opc2 = 2,@@ -5335,7 +5345,7 @@ void register_cp_regs_for_features(ARMCPU *cpu)ARMCPRegInfo id_v8_midr_cp_reginfo[] = { { .name ="MIDR_EL1" , .state =ARM_CP_STATE_BOTH , .opc0 =3 , .opc1 =0 , .crn =0 , .crm =0 , .opc2 =0 , - .access =PL1_R , .type =ARM_CP_NO_RAW , .resetvalue = cpu->midr, + .access =PL1U_R , .type =ARM_CP_NO_RAW , .resetvalue = cpu->midr, .fieldoffset = offsetof(CPUARMState, cp15.c0_cpuid), .readfn = midr_read },/* crn = 0 op1 = 0 crm = 0 op2 = 4,7 : AArch32 aliases of MIDR */
target/arm/cpu.h void register_cp_regs_for_features(ARMCPU *cpu) · line 5361
Quoted 6 lines
target/arm/cpu.h +2
-1@@ -5347,7 +5357,8 @@ void register_cp_regs_for_features(ARMCPU *cpu) .access = PL1_R, .resetvalue = cpu->midr }, { .name = "REVIDR_EL1", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 0, .opc2 = 6, - .access = PL1_R, .type = ARM_CP_CONST, .resetvalue = cpu->revidr }, + .access = PL1U_R, .type = ARM_CP_CONST, + .resetvalue = cpu->revidr },
This is a STATE_BOTH register, so just changing the .access value will reveal the aarch32 cpreg to userspace, which is wrong.
Quoted 5 lines
target/arm/cpu.h +0
-1REGINFO_SENTINEL };ARMCPRegInfo id_cp_reginfo[] = { --2.17.1
thanks
-- PMM
PATCH v3 4/5 linux-user/elfload: enable HWCAP_CPUID for AArch64
In reply to Alex BennéeUserspace programs should (in theory) query the ELF HWCAP before probing these registers. Now we have implemented them all make it public.
--- linux-user/elfload.c | 1 + 1 file changed, 1 insertion(+)
linux-user/elfload.c +1 -0
@@ -566,6 +566,7 @@ static uint32_t get_elf_hwcap(void) hwcaps |=ARM_HWCAP_A64_FP ; hwcaps |=ARM_HWCAP_A64_ASIMD ; + hwcaps |=ARM_HWCAP_A64_CPUID ;/* probe for the extra features */ #define GET_FEATURE (feat, hwcap) \
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH v3 4/5] linux-user/elfload: enable HWCAP_CPUID for AArch64
Quoted 8 lines · Alex Bennée
Userspace programs should (in theory) query the ELF HWCAP before probing these registers. Now we have implemented them all make it public.
Signed-off-by Alex Bennée <[email protected]>--- linux-user/elfload.c | 1 + 1 file changed, 1 insertion(+)
r~
PATCH v3 5/5 tests/tcg/aarch64: userspace system register test
In reply to Alex BennéeThis tests a bunch of registers that the kernel allows userspace to read including the CPUID registers.
--- tests/tcg/aarch64/Makefile.target | 2 +- tests/tcg/aarch64/sysregs.c | 99 +++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/aarch64/sysregs.c
tests/tcg/aarch64/Makefile.target +1 -1
@@ -7,7 +7,7 @@ VPATH += $(AARCH64_SRC) # we don't build any of the ARM tests AARCH64_TESTS=$(filter-out $(ARM_TESTS), $(TESTS)) -AARCH64_TESTS+=fcvt +AARCH64_TESTS+=fcvt sysregs TESTS:=$(AARCH64_TESTS) fcvt: LDFLAGS+=-lm
tests/tcg/aarch64/sysregs.c new file +99 -0
99 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v3 5/5] tests/tcg/aarch64: userspace system register test
Quoted 42 lines · Alex Bennée
This tests a bunch of registers that the kernel allows userspace to read including the CPUID registers.
Signed-off-by Alex Bennée <[email protected]>--- tests/tcg/aarch64/Makefile.target | 2 +- tests/tcg/aarch64/sysregs.c | 99 +++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/aarch64/sysregs.ctests/tcg/aarch64/Makefile.target +1
-1@@ -7,7 +7,7 @@ VPATH += $(AARCH64_SRC) # we don't build any of the ARM tests AARCH64_TESTS=$(filter-out $(ARM_TESTS), $(TESTS)) -AARCH64_TESTS+=fcvt +AARCH64_TESTS+=fcvt sysregs TESTS:=$(AARCH64_TESTS) fcvt: LDFLAGS+=-lmtests/tcg/aarch64/sysregs.c new file +13
-0@@ -0,0 +1,99 @@ +/* +* Check emulated system register access for linux-user mode. +* +* See: https://www.kernel.org/doc/Documentation/arm64/cpu-feature-registers.txt +*/ + +#include <asm/hwcap.h> +#include <stdio.h> +#include <sys/auxv.h> +#include <signal.h> +#include <string.h> +#include <stdbool.h> +
<snip>
tests/tcg/aarch64/sysregs.c line 67
Quoted 8 lines
tests/tcg/aarch64/sysregs.c new file +8
-0+ +/* when (getauxval(AT_HWCAP) & HWCAP_CPUID), since 4.11*/ +if (!(getauxval (AT_HWCAP ) &HWCAP_CPUID )) { +printf ("CPUID registers unavailable\n" ); +return 1 ; + }else { +printf ("Checking CPUID registers\n" ); + }
Annoyingly this fails on qemu:debian-arm64-cross as it uses an older set of headers than my desktop cross environment:
aarch64-linux-gnu-gcc (Ubuntu/Linaro 7.3.0-16ubuntu3) 7.3.0
with the libc:
Source: cross-toolchain-base (25ubuntu6)
Version: 2.27-3ubuntu1cross1
Provides: libc6-arm64-dcv1
So I'm thinking an #ifndef HWCAP_CPUID and define it would be acceptable for a test case.
--
Alex Bennée
Re: [Qemu-devel] [PATCH v3 5/5] tests/tcg/aarch64: userspace system register test
In reply to Alex BennéeQuoted 9 lines · Alex Bennée
This tests a bunch of registers that the kernel allows userspace to read including the CPUID registers.
Signed-off-by Alex Bennée <[email protected]>--- tests/tcg/aarch64/Makefile.target | 2 +- tests/tcg/aarch64/sysregs.c | 99 +++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/aarch64/sysregs.c
r~
Quoted 7 lines · Alex Bennée
Hi,
This expands on the previous version by adding the additional CPUID registers as exposed by the
HWCAP_CPUIDkernel feature. Most of the work involves judicious use of macros. There is a easily extensible test case that uses the shiny new check-tcg infrastructure ;-)
Quoted 6 lines
Alex Bennée (5):
target/arm: support reading of CNT[VCT|FRQ]_EL0 from user-space target/arm: relax permission checks forHWCAP_CPUIDregisters target/arm: expose CPUID registers to userspace linux-user/elfload: enableHWCAP_CPUIDfor AArch64 tests/tcg/aarch64: userspace system register test
Patch 1 is a bugfix not very related to the rest, so I've applied it to target-arm.next, and left review comments on 2/3.
thanks
-- PMM