arm: Steps towards EL2 support round 4
v2 cover arm: Steps towards EL2 support round 4
From: "Edgar E. Iglesias" <[email protected]>
Hi,
This is another series with small steps towards EL2 emulation.
Patch 1 is a fix to allow easier testing of EL3-less cores. Patches 2 and on add regs and a few small steps towards 2-stage MMU.
Comments welcome!
Best regards,
Edgar
v1 -> v2:
* Add fix for gracefully handling missing has_el2 CPU props
* Dropped suppress of TTBR1 for S2 (unneeded)
* Comment on vttbr_write TLB flush
* Mark second instance of VTTBR as ALIAS
* Split the active aa32ns_aa64any into separate AA32/AA64 registrations to allow the AA64 one to avoid .access checks
* VTCR does not need TLB flushes
* Various CP_CONST/resetvalue=0 instead of writefns/readfns
* Fix VMPIDR el2 vs el1 typo
* Fix VMPIDR reset value
* Fix spelling of suppress in commit message
Edgar E. Iglesias (8):
hw/cpu/{a15mpcore, a9mpcore}: Handle missing has_el3 CPU props
gracefully
target-arm: Add VTCR_EL2
target-arm: Add VTTBR_EL2
target-arm: Suppress TBI for S2 translations
target-arm: Suppress EPD for S2, EL2 and EL3 translations
target-arm: Add VPIDR_EL2
target-arm: Break out mpidr_read_val()
target-arm: Add VMPIDR_EL2
hw/cpu/a15mpcore.c | 2 +- hw/cpu/a9mpcore.c | 2 +- target-arm/cpu.h | 4 ++ target-arm/helper.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 155 insertions(+), 11 deletions(-)
Signature · 1 line
1.9.1
PATCH v2 1/8 hw/cpu/{a15mpcore, a9mpcore}: Handle missing has_el3 CPU props gracefully
From: "Edgar E. Iglesias" <[email protected]>
Handle missing CPU support for EL3 gracefully.
--- hw/cpu/a15mpcore.c | 2 +- hw/cpu/a9mpcore.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
hw/cpu/a15mpcore.c +1 -1
@@ -64,7 +64,7 @@ static void a15mp_priv_realize(DeviceState *dev, Error **errp)* either all the CPUs have TZ, or none do. */ cpuobj =OBJECT (qemu_get_cpu (0 )); - has_el3 =object_property_find (cpuobj,"has_el3" , &error_abort) && + has_el3 =object_property_find (cpuobj,"has_el3" ,NULL ) &&object_property_get_bool (cpuobj,"has_el3" , &error_abort);qdev_prop_set_bit (gicdev,"has-security-extensions" , has_el3); }
hw/cpu/a9mpcore.c +1 -1
@@ -69,7 +69,7 @@ static void a9mp_priv_realize(DeviceState *dev, Error **errp)* either all the CPUs have TZ, or none do. */ cpuobj =OBJECT (qemu_get_cpu (0 )); - has_el3 =object_property_find (cpuobj,"has_el3" , &error_abort) && + has_el3 =object_property_find (cpuobj,"has_el3" ,NULL ) &&object_property_get_bool (cpuobj,"has_el3" , &error_abort);qdev_prop_set_bit (gicdev,"has-security-extensions" , has_el3);
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH v2 1/8] hw/cpu/{a15mpcore, a9mpcore}: Handle missing has_el3 CPU props gracefully
Quoted 4 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Handle missing CPU support for EL3 gracefully.
What is the use case here? A9 and A15 should be able to not have EL3, but in this case the property should still exist but be set false. No prop should only be the case with a CPU that can't ever support EL3.
Regards,
Peter
Quoted 36 lines
Signed-off-by Edgar E. Iglesias <[email protected]>--- hw/cpu/a15mpcore.c | 2 +- hw/cpu/a9mpcore.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)hw/cpu/a15mpcore.c +1
-1@@ -64,7 +64,7 @@ static void a15mp_priv_realize(DeviceState *dev, Error **errp)* either all the CPUs have TZ, or none do. */ cpuobj =OBJECT (qemu_get_cpu (0 )); - has_el3 =object_property_find (cpuobj,"has_el3" , &error_abort) && + has_el3 =object_property_find (cpuobj,"has_el3" ,NULL ) &&object_property_get_bool (cpuobj,"has_el3" , &error_abort);qdev_prop_set_bit (gicdev,"has-security-extensions" , has_el3); }hw/cpu/a9mpcore.c +1
-2@@ -69,7 +69,7 @@ static void a9mp_priv_realize(DeviceState *dev, Error **errp)* either all the CPUs have TZ, or none do. */ cpuobj =OBJECT (qemu_get_cpu (0 )); - has_el3 =object_property_find (cpuobj,"has_el3" , &error_abort) && + has_el3 =object_property_find (cpuobj,"has_el3" ,NULL ) &&object_property_get_bool (cpuobj,"has_el3" , &error_abort);qdev_prop_set_bit (gicdev,"has-security-extensions" , has_el3); --1.9.1
PATCH v2 2/8 target-arm: Add VTCR_EL2
In reply to Edgar E. IglesiasFrom: "Edgar E. Iglesias" <[email protected]>
--- target-arm/cpu.h | 1 + target-arm/helper.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-)
target-arm/cpu.h +1 -0
@@ -224,6 +224,7 @@ typedef struct CPUARMState { };/* MMU translation table base control. */ TCR tcr_el[4 ]; +TCR vtcr_el2;/* Virtualization Translation Control. */ uint32_t c2_data;/* MPU data cacheable bits. */ uint32_t c2_insn;/* MPU instruction cacheable bits. */ union {/* MMU domain access control register
target-arm/helper.c +41 -2
67 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 3/8 target-arm: Add VTTBR_EL2
In reply to Edgar E. IglesiasFrom: "Edgar E. Iglesias" <[email protected]>
--- target-arm/cpu.h | 1 + target-arm/helper.c | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-)
target-arm/cpu.h +1 -0
@@ -222,6 +222,7 @@ typedef struct CPUARMState { };uint64_t ttbr1_el[4 ]; }; +uint64_t vttbr_el2;/* Virtualization Translation Table Base. */ /* MMU translation table base control. */ TCR tcr_el[4 ];TCR vtcr_el2;/* Virtualization Translation Control. */
target-arm/helper.c +32 -2
@@ -2213,6 +2213,20 @@ static void vmsa_ttbr_write(CPUARMState *env, const ARMCPRegInfo *ri,raw_write (env, ri, value); } +static void vttbr_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +ARMCPU *cpu =arm_env_get_cpu (env); +CPUState *cs =CPU (cpu); + +/* Accesses to VTTBR may change the VMID so we must flush the TLB. */ +if (raw_read (env, ri) != value) { +tlb_flush_by_mmuidx (cs, ARMMMUIdx_S12NSE1, ARMMMUIdx_S12NSE0, + ARMMMUIdx_S2NS,-1 ); +raw_write (env, ri, value); + } +} +static const ARMCPRegInfo vmsa_pmsa_cp_reginfo[] = { { .name ="DFSR" , .cp =15 , .crn =5 , .crm =0 , .opc1 =0 , .opc2 =0 , .access =PL1_RW , .type =ARM_CP_ALIAS ,
@@ -3144,6 +3158,13 @@ static const ARMCPRegInfo el3_no_el2_cp_reginfo[] = { .opc0 = 3, .opc1 = 4, .crn = 2, .crm = 1, .opc2 = 2, .access = PL2_RW, .accessfn = access_el3_aa32ns_aa64any, .type = ARM_CP_CONST, .resetvalue = 0 }, + { .name = "VTTBR", .state = ARM_CP_STATE_AA32, + .cp = 15, .opc1 = 6, .crm = 2, + .access = PL2_RW, .accessfn = access_el3_aa32ns, + .type = ARM_CP_CONST | ARM_CP_64BIT, .resetvalue = 0 }, + { .name = "VTTBR_EL2", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 4, .crn = 2, .crm = 1, .opc2 = 0, + .access = PL2_RW, .type = ARM_CP_CONST, .resetvalue = 0 }, { .name = "SCTLR_EL2", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 0, .opc2 = 0, .access = PL2_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
@@ -3286,6 +3307,16 @@ static const ARMCPRegInfo el2_cp_reginfo[] = { .opc0 = 3, .opc1 = 4, .crn = 2, .crm = 1, .opc2 = 2, .access = PL2_RW, .type = ARM_CP_ALIAS, .fieldoffset = offsetof(CPUARMState, cp15.vtcr_el2) }, + { .name = "VTTBR", .state = ARM_CP_STATE_AA32, + .cp = 15, .opc1 = 6, .crm = 2, + .type = ARM_CP_64BIT | ARM_CP_ALIAS, + .access = PL2_RW, .accessfn = access_el3_aa32ns, + .fieldoffset = offsetof(CPUARMState, cp15.vttbr_el2), + .writefn = vttbr_write }, + { .name = "VTTBR_EL2", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 4, .crn = 2, .crm = 1, .opc2 = 0, + .access = PL2_RW, .writefn = vttbr_write, + .fieldoffset = offsetof(CPUARMState, cp15.vttbr_el2) }, { .name = "SCTLR_EL2", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 0, .opc2 = 0, .access = PL2_RW, .raw_writefn = raw_write, .writefn = sctlr_write,
@@ -5791,8 +5822,7 @@ static inline uint64_t regime_ttbr(CPUARMState *env, ARMMMUIdx mmu_idx, int ttbrn) {if (mmu_idx == ARMMMUIdx_S2NS) { -/* TODO: return VTTBR_EL2 */ -g_assert_not_reached (); +return env->cp15.vttbr_el2; }if (ttbrn ==0 ) {return env->cp15.ttbr0_el[regime_el (env, mmu_idx)];
Signature · 1 line
1.9.1
PATCH v2 4/8 target-arm: Suppress TBI for S2 translations
In reply to Edgar E. IglesiasFrom: "Edgar E. Iglesias" <[email protected]>
Stage-2 MMU translations do not have configurable TBI as the top byte is always 0 (48-bit IPAs).
--- target-arm/helper.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
target-arm/helper.c +3 -1
@@ -6370,7 +6370,9 @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address,if (arm_el_is_aa64 (env, el)) { va_size =64 ;if (el >1 ) { - tbi =extract64 (tcr->raw_tcr,20 ,1 ); +if (mmu_idx != ARMMMUIdx_S2NS) { + tbi =extract64 (tcr->raw_tcr,20 ,1 ); + } }else {if (extract64 (address,55 ,1 )) { tbi =extract64 (tcr->raw_tcr,38 ,1 );
Signature · 1 line
1.9.1
PATCH v2 5/8 target-arm: Suppress EPD for S2, EL2 and EL3 translations
In reply to Edgar E. IglesiasFrom: "Edgar E. Iglesias" <[email protected]>
Stage-2 translations, EL2 and EL3 regimes don't have the EPD control.
--- target-arm/helper.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
target-arm/helper.c +4 -2
@@ -6344,7 +6344,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address,/* Read an LPAE long-descriptor translation table. */ MMUFaultType fault_type = translation_fault;uint32_t level =1 ; -uint32_t epd; +uint32_t epd =0 ;int32_t tsz;uint32_t tg;uint64_t ttbr;
@@ -6438,7 +6438,9 @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address,*/ if (ttbr_select ==0 ) { ttbr =regime_ttbr (env, mmu_idx,0 ); - epd =extract32 (tcr->raw_tcr,7 ,1 ); +if (el <2 ) { + epd =extract32 (tcr->raw_tcr,7 ,1 ); + } tsz = t0sz; tg =extract32 (tcr->raw_tcr,14 ,2 );
Signature · 1 line
1.9.1
PATCH v2 6/8 target-arm: Add VPIDR_EL2
In reply to Edgar E. IglesiasFrom: "Edgar E. Iglesias" <[email protected]>
--- target-arm/cpu.h | 1 + target-arm/helper.c | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-)
target-arm/cpu.h +1 -0
@@ -385,6 +385,7 @@ typedef struct CPUARMState {*/ uint64_t c15_ccnt;uint64_t pmccfiltr_el0;/* Performance Monitor Filter Register */ +uint64_t vpidr_el2;/* Virtualization Processor ID Register */ } cp15;struct {
target-arm/helper.c +41 -1
72 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 7/8 target-arm: Break out mpidr_read_val()
In reply to Edgar E. IglesiasFrom: "Edgar E. Iglesias" <[email protected]>
Break out mpidr_read_val() to allow future sharing of the code that conditionally sets the M and U bits of MPIDR.
No functional changes.
--- target-arm/helper.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
target-arm/helper.c +6 -1
@@ -2457,7 +2457,7 @@ static uint64_t midr_read(CPUARMState *env, const ARMCPRegInfo *ri)return raw_read (env, ri); } -static uint64_t mpidr_read (CPUARMState *env,const ARMCPRegInfo *ri) +static uint64_t mpidr_read_val (CPUARMState *env) {ARMCPU *cpu =ARM_CPU (arm_env_get_cpu (env));uint64_t mpidr = cpu->mp_affinity;
@@ -2475,6 +2475,11 @@ static uint64_t mpidr_read(CPUARMState *env, const ARMCPRegInfo *ri)return mpidr; } +static uint64_t mpidr_read (CPUARMState *env,const ARMCPRegInfo *ri) +{ +return mpidr_read_val (env); +} +static const ARMCPRegInfo mpidr_cp_reginfo[] = { { .name ="MPIDR" , .state =ARM_CP_STATE_BOTH , .opc0 =3 , .crn =0 , .crm =0 , .opc1 =0 , .opc2 =5 ,
Signature · 1 line
1.9.1
PATCH v2 8/8 target-arm: Add VMPIDR_EL2
In reply to Edgar E. IglesiasFrom: "Edgar E. Iglesias" <[email protected]>
--- target-arm/cpu.h | 1 + target-arm/helper.c | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-)
target-arm/cpu.h +1 -0
@@ -386,6 +386,7 @@ typedef struct CPUARMState {uint64_t c15_ccnt;uint64_t pmccfiltr_el0;/* Performance Monitor Filter Register */ uint64_t vpidr_el2;/* Virtualization Processor ID Register */ +uint64_t vmpidr_el2;/* Virtualization Multiprocessor ID Register */ } cp15;struct {
target-arm/helper.c +24 -2
@@ -2477,6 +2477,12 @@ static uint64_t mpidr_read_val(CPUARMState *env)static uint64_t mpidr_read (CPUARMState *env,const ARMCPRegInfo *ri) { +unsigned int cur_el =arm_current_el (env); +bool secure =arm_is_secure (env); + +if (arm_feature (env,ARM_FEATURE_EL2 ) && !secure && cur_el ==1 ) { +return env->cp15.vmpidr_el2; + }return mpidr_read_val (env); }
@@ -4138,6 +4144,7 @@ void register_cp_regs_for_features(ARMCPU *cpu)define_arm_cp_regs (cpu, v8_cp_reginfo); }if (arm_feature (env,ARM_FEATURE_EL2 )) { +uint64_t vmpidr_def =mpidr_read_val (env);ARMCPRegInfo vpidr_regs[] = { { .name ="VPIDR" , .state =ARM_CP_STATE_AA32 , .cp =15 , .opc1 =4 , .crn =0 , .crm =0 , .opc2 =0 ,
@@ -4148,6 +4155,16 @@ void register_cp_regs_for_features(ARMCPU *cpu) .opc0 = 3, .opc1 = 4, .crn = 0, .crm = 0, .opc2 = 0, .access = PL2_RW, .resetvalue = cpu->midr, .fieldoffset = offsetof(CPUARMState, cp15.vpidr_el2) }, + { .name = "VMPIDR", .state = ARM_CP_STATE_AA32, + .cp = 15, .opc1 = 4, .crn = 0, .crm = 0, .opc2 = 5, + .access = PL2_RW, .accessfn = access_el3_aa32ns, + .resetvalue = vmpidr_def, + .fieldoffset = offsetof(CPUARMState, cp15.vmpidr_el2) }, + { .name = "VMPIDR_EL2", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 4, .crn = 0, .crm = 0, .opc2 = 5, + .access = PL2_RW, + .resetvalue = vmpidr_def, + .fieldoffset = offsetof(CPUARMState, cp15.vmpidr_el2) }, REGINFO_SENTINEL };define_arm_cp_regs (cpu, vpidr_regs);
@@ -4166,8 +4183,8 @@ void register_cp_regs_for_features(ARMCPU *cpu)* register the no_el2 reginfos. */ if (arm_feature (env,ARM_FEATURE_EL3 )) { -/* When EL3 exists but not EL2, VPIDR takes the value -* of MIDR_EL1. +/* When EL3 exists but not EL2, VPIDR and VMPIDR take the value +* of MIDR_EL1 and MPIDR_EL1. */ ARMCPRegInfo vpidr_regs[] = { { .name ="VPIDR_EL2" , .state =ARM_CP_STATE_BOTH ,
@@ -4175,6 +4192,11 @@ void register_cp_regs_for_features(ARMCPU *cpu) .access = PL2_RW, .accessfn = access_el3_aa32ns_aa64any, .type = ARM_CP_CONST, .resetvalue = cpu->midr, .fieldoffset = offsetof(CPUARMState, cp15.vpidr_el2) }, + { .name = "VMPIDR_EL2", .state = ARM_CP_STATE_BOTH, + .opc0 = 3, .opc1 = 4, .crn = 0, .crm = 0, .opc2 = 5, + .access = PL2_RW, .accessfn = access_el3_aa32ns_aa64any, + .type = ARM_CP_NO_RAW, + .writefn = arm_cp_write_ignore, .readfn = mpidr_read }, REGINFO_SENTINEL };define_arm_cp_regs (cpu, vpidr_regs);
Signature · 1 line
1.9.1
Peter Maydell
AppliedQuoted 6 lines · Edgar E. Iglesias
From: "Edgar E. Iglesias" <[email protected]>
Hi,
This is another series with small steps towards EL2 emulation.
Quoted 7 lines
Patch 1 is a fix to allow easier testing of EL3-less cores. Patches 2 and on add regs and a few small steps towards 2-stage MMU.
Comments welcome!
Best regards,
Edgar
Thanks, applied to target-arm.next.
-- PMM