various regdef fixes for EL2/EL3 regs
cover various regdef fixes for EL2/EL3 regs
This patchset fixes a number of minor bugs in regdefs for some EL2 and EL3 registers. The most interesting one here is the first -- we weren't resetting SCTLR_EL3 correctly for 64-bit CPUs. The rest are things I discovered by code inspection looking at other registers:
* we weren't migrating ESR_EL2 and ESR_EL3
* we weren't migrating the (RES0) high 32 bits of VTCR_EL2
* unneeded TLB flush on TCR_EL2 writes
I think these should go into 2.6 since they're bug fixes.
thanks
-- PMM
Peter Maydell (4):
target-arm: Correctly reset SCTLR_EL3 for 64-bit CPUs
target-arm: Remove incorrect ALIAS tags from ESR_EL2 and ESR_EL3
target-arm: Make the 64-bit version of VTCR do the migration
target-arm: Avoid unnecessary TLB flush on TCR_EL2 writes
target-arm/helper.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-)
Signature · 1 line
1.9.1
PATCH 1/4 target-arm: Correctly reset SCTLR_EL3 for 64-bit CPUs
The regdef for SCTRL_EL3 was incorrectly marked as being an ARM_CP_ALIAS, with the remark that this was because the 32-bit definition would take care of reset and migration. However the intention for banked registers as documented in the comment in add_cpreg_to_hashtable() is:
* 2) If ARMv8 is enabled then we can count on a 64-bit version
* taking care of the secure bank. This requires that separate
* 32 and 64-bit definitions are provided.
and so it marks the 32-bit secure banked version as an alias. This results in the sctlr_s/sctlr_el[3] field never being reset or migrated for a 64-bit CPU with EL3 enabled.
Fix this by removing the ARM_CP_ALIAS annotation from SCTLR_EL3. Since this means it now needs a real reset value, move the regdef into the same place that we define the 32-bit SCTLR.
--- target-arm/helper.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
target-arm/helper.c +13 -10
@@ -3744,11 +3744,6 @@ static const ARMCPRegInfo el3_cp_reginfo[] = { .access = PL1_RW, .accessfn = access_trap_aa32s_el1, .writefn = vbar_write, .resetvalue = 0, .fieldoffset = offsetof(CPUARMState, cp15.mvbar) }, - { .name = "SCTLR_EL3", .state = ARM_CP_STATE_AA64, - .type = ARM_CP_ALIAS, /* reset handled by AArch32 view */ - .opc0 = 3, .opc1 = 6, .crn = 1, .crm = 0, .opc2 = 0, - .access = PL3_RW, .raw_writefn = raw_write, .writefn = sctlr_write, - .fieldoffset = offsetof(CPUARMState, cp15.sctlr_el[3]) }, { .name = "TTBR0_EL3", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 6, .crn = 2, .crm = 0, .opc2 = 0, .access = PL3_RW, .writefn = vmsa_ttbr_write, .resetvalue = 0,
@@ -4641,12 +4636,20 @@ void register_cp_regs_for_features(ARMCPU *cpu) }if (arm_feature (env,ARM_FEATURE_EL3 )) {define_arm_cp_regs (cpu, el3_cp_reginfo); -ARMCPRegInfo rvbar = { - .name ="RVBAR_EL3" , .state =ARM_CP_STATE_AA64 , - .opc0 =3 , .opc1 =6 , .crn =12 , .crm =0 , .opc2 =1 , - .type =ARM_CP_CONST , .access =PL3_R , .resetvalue = cpu->rvbar +ARMCPRegInfo el3_regs[] = { + { .name ="RVBAR_EL3" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =6 , .crn =12 , .crm =0 , .opc2 =1 , + .type =ARM_CP_CONST , .access =PL3_R , .resetvalue = cpu->rvbar }, + { .name ="SCTLR_EL3" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =6 , .crn =1 , .crm =0 , .opc2 =0 , + .access =PL3_RW , + .raw_writefn = raw_write, .writefn = sctlr_write, + .fieldoffset = offsetof(CPUARMState, cp15.sctlr_el[3]), + .resetvalue = cpu->reset_sctlr }, +REGINFO_SENTINEL }; -define_one_arm_cp_reg (cpu, &rvbar); + +define_arm_cp_regs (cpu, el3_regs); }/* The behaviour of NSACR is sufficiently various that we don't * try to describe it in a single reginfo:
Signature · 1 line
1.9.1
Re: [Qemu-arm] [Qemu-devel] [PATCH 1/4] target-arm: Correctly reset SCTLR_EL3 for 64-bit CPUs
Quoted 14 lines · Peter Maydell
The regdef for
SCTRL_EL3was incorrectly marked as being anARM_CP_ALIAS, with the remark that this was because the 32-bit definition would take care of reset and migration. However the intention for banked registers as documented in the comment inadd_cpreg_to_hashtable()is:* 2) If ARMv8 is enabled then we can count on a 64-bit version
* taking care of the secure bank. This requires that separate
* 32 and 64-bit definitions are provided.and so it marks the 32-bit secure banked version as an alias. This results in the sctlr_s/sctlr_el[3] field never being reset or migrated for a 64-bit CPU with EL3 enabled.
Quoted 5 lines
Fix this by removing the
ARM_CP_ALIASannotation fromSCTLR_EL3. Since this means it now needs a real reset value, move the regdef into the same place that we define the 32-bit SCTLR.Signed-off-by Peter Maydell <[email protected]>
Thanks,
Laurent
Quoted 50 lines
--- target-arm/helper.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)target-arm/helper.c +13
-11@@ -3744,11 +3744,6 @@ static const ARMCPRegInfo el3_cp_reginfo[] = { .access = PL1_RW, .accessfn = access_trap_aa32s_el1, .writefn = vbar_write, .resetvalue = 0, .fieldoffset = offsetof(CPUARMState, cp15.mvbar) }, - { .name = "SCTLR_EL3", .state = ARM_CP_STATE_AA64, - .type = ARM_CP_ALIAS, /* reset handled by AArch32 view */ - .opc0 = 3, .opc1 = 6, .crn = 1, .crm = 0, .opc2 = 0, - .access = PL3_RW, .raw_writefn = raw_write, .writefn = sctlr_write, - .fieldoffset = offsetof(CPUARMState, cp15.sctlr_el[3]) }, { .name = "TTBR0_EL3", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 6, .crn = 2, .crm = 0, .opc2 = 0, .access = PL3_RW, .writefn = vmsa_ttbr_write, .resetvalue = 0,@@ -4641,12 +4636,20 @@ void register_cp_regs_for_features(ARMCPU *cpu) }if (arm_feature (env,ARM_FEATURE_EL3 )) {define_arm_cp_regs (cpu, el3_cp_reginfo); -ARMCPRegInfo rvbar = { - .name ="RVBAR_EL3" , .state =ARM_CP_STATE_AA64 , - .opc0 =3 , .opc1 =6 , .crn =12 , .crm =0 , .opc2 =1 , - .type =ARM_CP_CONST , .access =PL3_R , .resetvalue = cpu->rvbar +ARMCPRegInfo el3_regs[] = { + { .name ="RVBAR_EL3" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =6 , .crn =12 , .crm =0 , .opc2 =1 , + .type =ARM_CP_CONST , .access =PL3_R , .resetvalue = cpu->rvbar }, + { .name ="SCTLR_EL3" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =6 , .crn =1 , .crm =0 , .opc2 =0 , + .access =PL3_RW , + .raw_writefn = raw_write, .writefn = sctlr_write, + .fieldoffset = offsetof(CPUARMState, cp15.sctlr_el[3]), + .resetvalue = cpu->reset_sctlr }, +REGINFO_SENTINEL }; -define_one_arm_cp_reg (cpu, &rvbar); + +define_arm_cp_regs (cpu, el3_regs); }/* The behaviour of NSACR is sufficiently various that we don't * try to describe it in a single reginfo: -- 1.9.1
Re: [Qemu-arm] [PATCH 1/4] target-arm: Correctly reset SCTLR_EL3 for 64-bit CPUs
In reply to Peter MaydellQuoted 14 lines · Peter Maydell
The regdef for
SCTRL_EL3was incorrectly marked as being anARM_CP_ALIAS, with the remark that this was because the 32-bit definition would take care of reset and migration. However the intention for banked registers as documented in the comment inadd_cpreg_to_hashtable()is:* 2) If ARMv8 is enabled then we can count on a 64-bit version
* taking care of the secure bank. This requires that separate
* 32 and 64-bit definitions are provided.and so it marks the 32-bit secure banked version as an alias. This results in the sctlr_s/sctlr_el[3] field never being reset or migrated for a 64-bit CPU with EL3 enabled.
Quoted 5 lines
Fix this by removing the
ARM_CP_ALIASannotation fromSCTLR_EL3. Since this means it now needs a real reset value, move the regdef into the same place that we define the 32-bit SCTLR.Signed-off-by Peter Maydell <[email protected]>
Quoted 46 lines
--- target-arm/helper.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)target-arm/helper.c +13
-10@@ -3744,11 +3744,6 @@ static const ARMCPRegInfo el3_cp_reginfo[] = { .access = PL1_RW, .accessfn = access_trap_aa32s_el1, .writefn = vbar_write, .resetvalue = 0, .fieldoffset = offsetof(CPUARMState, cp15.mvbar) }, - { .name = "SCTLR_EL3", .state = ARM_CP_STATE_AA64, - .type = ARM_CP_ALIAS, /* reset handled by AArch32 view */ - .opc0 = 3, .opc1 = 6, .crn = 1, .crm = 0, .opc2 = 0, - .access = PL3_RW, .raw_writefn = raw_write, .writefn = sctlr_write, - .fieldoffset = offsetof(CPUARMState, cp15.sctlr_el[3]) }, { .name = "TTBR0_EL3", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 6, .crn = 2, .crm = 0, .opc2 = 0, .access = PL3_RW, .writefn = vmsa_ttbr_write, .resetvalue = 0,@@ -4641,12 +4636,20 @@ void register_cp_regs_for_features(ARMCPU *cpu) }if (arm_feature (env,ARM_FEATURE_EL3 )) {define_arm_cp_regs (cpu, el3_cp_reginfo); -ARMCPRegInfo rvbar = { - .name ="RVBAR_EL3" , .state =ARM_CP_STATE_AA64 , - .opc0 =3 , .opc1 =6 , .crn =12 , .crm =0 , .opc2 =1 , - .type =ARM_CP_CONST , .access =PL3_R , .resetvalue = cpu->rvbar +ARMCPRegInfo el3_regs[] = { + { .name ="RVBAR_EL3" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =6 , .crn =12 , .crm =0 , .opc2 =1 , + .type =ARM_CP_CONST , .access =PL3_R , .resetvalue = cpu->rvbar }, + { .name ="SCTLR_EL3" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =6 , .crn =1 , .crm =0 , .opc2 =0 , + .access =PL3_RW , + .raw_writefn = raw_write, .writefn = sctlr_write, + .fieldoffset = offsetof(CPUARMState, cp15.sctlr_el[3]), + .resetvalue = cpu->reset_sctlr }, +REGINFO_SENTINEL }; -define_one_arm_cp_reg (cpu, &rvbar); + +define_arm_cp_regs (cpu, el3_regs); }/* The behaviour of NSACR is sufficiently various that we don't * try to describe it in a single reginfo:
PATCH 2/4 target-arm: Remove incorrect ALIAS tags from ESR_EL2 and ESR_EL3
In reply to Peter MaydellThe regdefs for the ESR_EL2 and ESR_EL3 system registers should not be marked as ARM_CP_ALIAS, because these are the master copies; the DFSR regdef in vmsa_pmsa_cp_reginfo[] is marked as an alias. Remove the ALIAS tags so that these registers are correctly migrated.
--- target-arm/helper.c | 2 -- 1 file changed, 2 deletions(-)
target-arm/helper.c +0 -2
@@ -3509,7 +3509,6 @@ static const ARMCPRegInfo el2_cp_reginfo[] = { .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, elr_el[2]) }, { .name = "ESR_EL2", .state = ARM_CP_STATE_AA64, - .type = ARM_CP_ALIAS, .opc0 = 3, .opc1 = 4, .crn = 5, .crm = 2, .opc2 = 0, .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, cp15.esr_el[2]) }, { .name = "FAR_EL2", .state = ARM_CP_STATE_AA64,
@@ -3759,7 +3758,6 @@ static const ARMCPRegInfo el3_cp_reginfo[] = { .access = PL3_RW, .fieldoffset = offsetof(CPUARMState, elr_el[3]) }, { .name = "ESR_EL3", .state = ARM_CP_STATE_AA64, - .type = ARM_CP_ALIAS, .opc0 = 3, .opc1 = 6, .crn = 5, .crm = 2, .opc2 = 0, .access = PL3_RW, .fieldoffset = offsetof(CPUARMState, cp15.esr_el[3]) }, { .name = "FAR_EL3", .state = ARM_CP_STATE_AA64,
Signature · 1 line
1.9.1
Re: [Qemu-arm] [PATCH 2/4] target-arm: Remove incorrect ALIAS tags from ESR_EL2 and ESR_EL3
Quoted 6 lines · Peter Maydell
The regdefs for the
ESR_EL2andESR_EL3system registers should not be marked asARM_CP_ALIAS, because these are the master copies; the DFSR regdef in vmsa_pmsa_cp_reginfo[] is marked as an alias. Remove the ALIAS tags so that these registers are correctly migrated.Signed-off-by Peter Maydell <[email protected]>
Quoted 24 lines
--- target-arm/helper.c | 2 -- 1 file changed, 2 deletions(-)target-arm/helper.c +0
-2@@ -3509,7 +3509,6 @@ static const ARMCPRegInfo el2_cp_reginfo[] = { .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, elr_el[2]) }, { .name = "ESR_EL2", .state = ARM_CP_STATE_AA64, - .type = ARM_CP_ALIAS, .opc0 = 3, .opc1 = 4, .crn = 5, .crm = 2, .opc2 = 0, .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, cp15.esr_el[2]) }, { .name = "FAR_EL2", .state = ARM_CP_STATE_AA64,@@ -3759,7 +3758,6 @@ static const ARMCPRegInfo el3_cp_reginfo[] = { .access = PL3_RW, .fieldoffset = offsetof(CPUARMState, elr_el[3]) }, { .name = "ESR_EL3", .state = ARM_CP_STATE_AA64, - .type = ARM_CP_ALIAS, .opc0 = 3, .opc1 = 6, .crn = 5, .crm = 2, .opc2 = 0, .access = PL3_RW, .fieldoffset = offsetof(CPUARMState, cp15.esr_el[3]) }, { .name = "FAR_EL3", .state = ARM_CP_STATE_AA64,
PATCH 3/4 target-arm: Make the 64-bit version of VTCR do the migration
In reply to Peter MaydellMove the ALIAS tag from VTCR_EL2 to VTCR so that we migrate the 64-bit version, as is usual. (This has no particular effect now unless the guest wrote to the high RES0 bits of VTCR_EL2.) Add a comment about why it's OK that we don't have the various accessor functions that the EL1 TCR regdefs do.
--- target-arm/helper.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
target-arm/helper.c +5 -1
@@ -3564,11 +3564,15 @@ static const ARMCPRegInfo el2_cp_reginfo[] = { .fieldoffset = offsetof(CPUARMState, cp15.tcr_el[2]) }, { .name = "VTCR", .state = ARM_CP_STATE_AA32, .cp = 15, .opc1 = 4, .crn = 2, .crm = 1, .opc2 = 2, + .type = ARM_CP_ALIAS, .access = PL2_RW, .accessfn = access_el3_aa32ns, .fieldoffset = offsetof(CPUARMState, cp15.vtcr_el2) }, { .name = "VTCR_EL2", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 4, .crn = 2, .crm = 1, .opc2 = 2, - .access = PL2_RW, .type = ARM_CP_ALIAS, + .access = PL2_RW, +/* no .writefn needed as this can't cause an ASID change; +* no .raw_writefn or .resetfn needed as we never use mask/base_mask +*/ .fieldoffset = offsetof(CPUARMState, cp15.vtcr_el2) }, { .name = "VTTBR", .state = ARM_CP_STATE_AA32, .cp = 15, .opc1 = 6, .crm = 2,
Signature · 1 line
1.9.1
Re: [Qemu-arm] [PATCH 3/4] target-arm: Make the 64-bit version of VTCR do the migration
Quoted 7 lines · Peter Maydell
Move the ALIAS tag from
VTCR_EL2to VTCR so that we migrate the 64-bit version, as is usual. (This has no particular effect now unless the guest wrote to the high RES0 bits ofVTCR_EL2.) Add a comment about why it's OK that we don't have the various accessor functions that the EL1 TCR regdefs do.Signed-off-by Peter Maydell <[email protected]>
Quoted 25 lines
--- target-arm/helper.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)target-arm/helper.c +5
-1@@ -3564,11 +3564,15 @@ static const ARMCPRegInfo el2_cp_reginfo[] = { .fieldoffset = offsetof(CPUARMState, cp15.tcr_el[2]) }, { .name = "VTCR", .state = ARM_CP_STATE_AA32, .cp = 15, .opc1 = 4, .crn = 2, .crm = 1, .opc2 = 2, + .type = ARM_CP_ALIAS, .access = PL2_RW, .accessfn = access_el3_aa32ns, .fieldoffset = offsetof(CPUARMState, cp15.vtcr_el2) }, { .name = "VTCR_EL2", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 4, .crn = 2, .crm = 1, .opc2 = 2, - .access = PL2_RW, .type = ARM_CP_ALIAS, + .access = PL2_RW, +/* no .writefn needed as this can't cause an ASID change; +* no .raw_writefn or .resetfn needed as we never use mask/base_mask +*/ .fieldoffset = offsetof(CPUARMState, cp15.vtcr_el2) }, { .name = "VTTBR", .state = ARM_CP_STATE_AA32, .cp = 15, .opc1 = 6, .crm = 2,
PATCH 4/4 target-arm: Avoid unnecessary TLB flush on TCR_EL2 writes
In reply to Peter MaydellThe TCR_EL2 regdef was incorrectly using the vmsa_tcr_el1_write function for writes. Since TCR_EL2 doesn't have the A1 bit that TCR_EL1 does, we don't need to do a tlb_flush() when it is written. Remove the unnecessary .writefn and also the harmless but unneeded .raw_writefn and .resetfn definitions.
--- target-arm/helper.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
target-arm/helper.c +4 -2
@@ -3559,8 +3559,10 @@ static const ARMCPRegInfo el2_cp_reginfo[] = { .resetvalue = 0 }, { .name = "TCR_EL2", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .opc1 = 4, .crn = 2, .crm = 0, .opc2 = 2, - .access = PL2_RW, .writefn = vmsa_tcr_el1_write, - .resetfn = vmsa_ttbcr_reset, .raw_writefn = raw_write, + .access = PL2_RW, +/* no .writefn needed as this can't cause an ASID change; +* no .raw_writefn or .resetfn needed as we never use mask/base_mask +*/ .fieldoffset = offsetof(CPUARMState, cp15.tcr_el[2]) }, { .name = "VTCR", .state = ARM_CP_STATE_AA32, .cp = 15, .opc1 = 4, .crn = 2, .crm = 1, .opc2 = 2,
Signature · 1 line
1.9.1
Re: [Qemu-arm] [PATCH 4/4] target-arm: Avoid unnecessary TLB flush on TCR_EL2 writes
Quoted 5 lines · Peter Maydell
The
TCR_EL2regdef was incorrectly using thevmsa_tcr_el1_writefunction for writes. SinceTCR_EL2doesn't have the A1 bit thatTCR_EL1does, we don't need to do atlb_flush()when it is written. Remove the unnecessary .writefn and also the harmless but unneeded .raw_writefn and .resetfn definitions.
How about TCR_EL3 which doesn't have A1 bit as well?
Kind regards,
Sergey
Quoted 23 lines
Signed-off-by Peter Maydell <[email protected]>--- target-arm/helper.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)target-arm/helper.c +4
-2@@ -3559,8 +3559,10 @@ static const ARMCPRegInfo el2_cp_reginfo[] = { .resetvalue = 0 }, { .name = "TCR_EL2", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .opc1 = 4, .crn = 2, .crm = 0, .opc2 = 2, - .access = PL2_RW, .writefn = vmsa_tcr_el1_write, - .resetfn = vmsa_ttbcr_reset, .raw_writefn = raw_write, + .access = PL2_RW, +/* no .writefn needed as this can't cause an ASID change; +* no .raw_writefn or .resetfn needed as we never use mask/base_mask +*/ .fieldoffset = offsetof(CPUARMState, cp15.tcr_el[2]) }, { .name = "VTCR", .state = ARM_CP_STATE_AA32, .cp = 15, .opc1 = 4, .crn = 2, .crm = 1, .opc2 = 2,
Re: [Qemu-arm] [PATCH 4/4] target-arm: Avoid unnecessary TLB flush on TCR_EL2 writes
Quoted 8 lines · Sergey Fedorov
Quoted 5 lines · Peter Maydell
The
TCR_EL2regdef was incorrectly using thevmsa_tcr_el1_writefunction for writes. SinceTCR_EL2doesn't have the A1 bit thatTCR_EL1does, we don't need to do atlb_flush()when it is written. Remove the unnecessary .writefn and also the harmless but unneeded .raw_writefn and .resetfn definitions.How about
TCR_EL3which doesn't have A1 bit as well?
Yes, that should have this change too I think.
I'll put patches 1-3 into target-arm.next, and respin this one (which then probably doesn't need to go into 2.6.)
thanks
-- PMM