target-arm: Implement TLB invalidate inner shareable ops properly
cover target-arm: Implement TLB invalidate inner shareable ops properly
The ARM architecture defines that the "IS" variants of TLB maintenance operations must affect all TLBs in the Inner Shareable domain, which for us means all CPUs. We were incorrectly implementing these to only affect the current CPU, which meant that SMP TCG operation was unstable (especially noticeable on v8).
These patches shove the legacy loosely-decoded wildcard TLB op definitions back from "not-v8" to "not-v7" so we can use the correct strict decode for v7 and v7MP (which is where the IS ops were introduced); this then gives us a place we can insert the correct behaviour.
Without these patches, using Ard's PSCI emulation patches with lots of SMP CPUs tends to result in Oopses, processes crashing with illegal instruction exceptions, etc.
Although we don't support SMP TCG in QEMU 2.1, I've cc'd these to stable because they also affect v7.
Peter Maydell (2):
target-arm: Push legacy wildcard TLB ops back into v6
target-arm: Make *IS TLB maintenance ops affect all CPUs
target-arm/helper.c | 195 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 140 insertions(+), 55 deletions(-)
Signature · 1 line
1.9.1
PATCH 1/2 target-arm: Push legacy wildcard TLB ops back into v6
When we implemented ARMv8 in QEMU we retained our legacy loose wildcarded decoding of the TLB maintenance operations for v7 and earlier CPUs and provided the correct stricter decode for v8. However the loose decode is in fact wrong for v7MP, because it doesn't correctly implement the operations which must apply to every CPU in the Inner Shareable domain.
Move the legacy wildcarding from the not_v8 reginfo array into the not_v7 array, and move the strictly decoded operations from the v8 reginfo to v7 or v7mp arrays as appropriate.
Cache and TLB lockdown legacy wildcarding remains in the not_v8 array for the moment.
--- target-arm/helper.c | 102 ++++++++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 47 deletions(-)
target-arm/helper.c +55 -47
@@ -414,21 +414,6 @@ static const ARMCPRegInfo not_v8_cp_reginfo[] = {*/ { .name = "TLB_LOCKDOWN", .cp = 15, .crn = 10, .crm = CP_ANY, .opc1 = CP_ANY, .opc2 = CP_ANY, .access = PL1_RW, .type = ARM_CP_NOP }, - /* MMU TLB control. Note that the wildcarding means we cover not just - * the unified TLB ops but also the dside/iside/inner-shareable variants. - */ - { .name = "TLBIALL", .cp = 15, .crn = 8, .crm = CP_ANY, - .opc1 = CP_ANY, .opc2 = 0, .access = PL1_W, .writefn = tlbiall_write, - .type = ARM_CP_NO_MIGRATE }, - { .name = "TLBIMVA", .cp = 15, .crn = 8, .crm = CP_ANY, - .opc1 = CP_ANY, .opc2 = 1, .access = PL1_W, .writefn = tlbimva_write, - .type = ARM_CP_NO_MIGRATE }, - { .name = "TLBIASID", .cp = 15, .crn = 8, .crm = CP_ANY, - .opc1 = CP_ANY, .opc2 = 2, .access = PL1_W, .writefn = tlbiasid_write, - .type = ARM_CP_NO_MIGRATE }, - { .name = "TLBIMVAA", .cp = 15, .crn = 8, .crm = CP_ANY, - .opc1 = CP_ANY, .opc2 = 3, .access = PL1_W, .writefn = tlbimvaa_write, - .type = ARM_CP_NO_MIGRATE }, /* Cache maintenance ops; some of this space may be overridden later. */ { .name = "CACHEMAINT", .cp = 15, .crn = 7, .crm = CP_ANY, .opc1 = 0, .opc2 = CP_ANY, .access = PL1_W,
@@ -472,6 +457,21 @@ static const ARMCPRegInfo not_v7_cp_reginfo[] = {*/ { .name = "DBGDIDR", .cp = 14, .crn = 0, .crm = 0, .opc1 = 0, .opc2 = 0, .access = PL0_R, .type = ARM_CP_CONST, .resetvalue = 0 }, + /* MMU TLB control. Note that the wildcarding means we cover not just + * the unified TLB ops but also the dside/iside/inner-shareable variants. + */ + { .name = "TLBIALL", .cp = 15, .crn = 8, .crm = CP_ANY, + .opc1 = CP_ANY, .opc2 = 0, .access = PL1_W, .writefn = tlbiall_write, + .type = ARM_CP_NO_MIGRATE }, + { .name = "TLBIMVA", .cp = 15, .crn = 8, .crm = CP_ANY, + .opc1 = CP_ANY, .opc2 = 1, .access = PL1_W, .writefn = tlbimva_write, + .type = ARM_CP_NO_MIGRATE }, + { .name = "TLBIASID", .cp = 15, .crn = 8, .crm = CP_ANY, + .opc1 = CP_ANY, .opc2 = 2, .access = PL1_W, .writefn = tlbiasid_write, + .type = ARM_CP_NO_MIGRATE }, + { .name = "TLBIMVAA", .cp = 15, .crn = 8, .crm = CP_ANY, + .opc1 = CP_ANY, .opc2 = 3, .access = PL1_W, .writefn = tlbimvaa_write, + .type = ARM_CP_NO_MIGRATE }, REGINFO_SENTINEL };
@@ -890,6 +890,42 @@ static const ARMCPRegInfo v7_cp_reginfo[] = { { .name = "ISR_EL1", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 1, .opc2 = 0, .type = ARM_CP_NO_MIGRATE, .access = PL1_R, .readfn = isr_read }, + /* 32 bit ITLB invalidates */ + { .name = "ITLBIALL", .cp = 15, .opc1 = 0, .crn = 8, .crm = 5, .opc2 = 0, + .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbiall_write }, + { .name = "ITLBIMVA", .cp = 15, .opc1 = 0, .crn = 8, .crm = 5, .opc2 = 1, + .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbimva_write }, + { .name = "ITLBIASID", .cp = 15, .opc1 = 0, .crn = 8, .crm = 5, .opc2 = 2, + .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbiasid_write }, + /* 32 bit DTLB invalidates */ + { .name = "DTLBIALL", .cp = 15, .opc1 = 0, .crn = 8, .crm = 6, .opc2 = 0, + .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbiall_write }, + { .name = "DTLBIMVA", .cp = 15, .opc1 = 0, .crn = 8, .crm = 6, .opc2 = 1, + .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbimva_write }, + { .name = "DTLBIASID", .cp = 15, .opc1 = 0, .crn = 8, .crm = 6, .opc2 = 2, + .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbiasid_write }, + /* 32 bit TLB invalidates */ + { .name = "TLBIALL", .cp = 15, .opc1 = 0, .crn = 8, .crm = 7, .opc2 = 0, + .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbiall_write }, + { .name = "TLBIMVA", .cp = 15, .opc1 = 0, .crn = 8, .crm = 7, .opc2 = 1, + .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbimva_write }, + { .name = "TLBIASID", .cp = 15, .opc1 = 0, .crn = 8, .crm = 7, .opc2 = 2, + .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbiasid_write }, + { .name = "TLBIMVAA", .cp = 15, .opc1 = 0, .crn = 8, .crm = 7, .opc2 = 3, + .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbimvaa_write }, +REGINFO_SENTINEL +}; + +static const ARMCPRegInfo v7mp_cp_reginfo[] = { +/* 32 bit TLB invalidates, Inner Shareable */ + { .name ="TLBIALLIS" , .cp =15 , .opc1 =0 , .crn =8 , .crm =3 , .opc2 =0 , + .type =ARM_CP_NO_MIGRATE , .access =PL1_W , .writefn = tlbiall_write }, + { .name ="TLBIMVAIS" , .cp =15 , .opc1 =0 , .crn =8 , .crm =3 , .opc2 =1 , + .type =ARM_CP_NO_MIGRATE , .access =PL1_W , .writefn = tlbimva_write }, + { .name ="TLBIASIDIS" , .cp =15 , .opc1 =0 , .crn =8 , .crm =3 , .opc2 =2 , + .type =ARM_CP_NO_MIGRATE , .access =PL1_W , .writefn = tlbiasid_write }, + { .name ="TLBIMVAAIS" , .cp =15 , .opc1 =0 , .crn =8 , .crm =3 , .opc2 =3 , + .type =ARM_CP_NO_MIGRATE , .access =PL1_W , .writefn = tlbimvaa_write },REGINFO_SENTINEL };
@@ -2056,42 +2092,11 @@ static const ARMCPRegInfo v8_cp_reginfo[] = { .opc0 = 1, .opc1 = 0, .crn = 7, .crm = 8, .opc2 = 3, .access = PL1_W, .type = ARM_CP_NO_MIGRATE, .writefn = ats_write },#endif -/* 32 bit TLB invalidates, Inner Shareable */ - { .name = "TLBIALLIS", .cp = 15, .opc1 = 0, .crn = 8, .crm = 3, .opc2 = 0, - .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbiall_write }, - { .name = "TLBIMVAIS", .cp = 15, .opc1 = 0, .crn = 8, .crm = 3, .opc2 = 1, - .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbimva_write }, - { .name = "TLBIASIDIS", .cp = 15, .opc1 = 0, .crn = 8, .crm = 3, .opc2 = 2, - .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbiasid_write }, - { .name = "TLBIMVAAIS", .cp = 15, .opc1 = 0, .crn = 8, .crm = 3, .opc2 = 3, - .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbimvaa_write }, +/* TLB invalidate last level of translation table walk */ { .name = "TLBIMVALIS", .cp = 15, .opc1 = 0, .crn = 8, .crm = 3, .opc2 = 5, .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbimva_write }, { .name = "TLBIMVAALIS", .cp = 15, .opc1 = 0, .crn = 8, .crm = 3, .opc2 = 7, .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbimvaa_write }, - /* 32 bit ITLB invalidates */ - { .name = "ITLBIALL", .cp = 15, .opc1 = 0, .crn = 8, .crm = 5, .opc2 = 0, - .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbiall_write }, - { .name = "ITLBIMVA", .cp = 15, .opc1 = 0, .crn = 8, .crm = 5, .opc2 = 1, - .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbimva_write }, - { .name = "ITLBIASID", .cp = 15, .opc1 = 0, .crn = 8, .crm = 5, .opc2 = 2, - .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbiasid_write }, - /* 32 bit DTLB invalidates */ - { .name = "DTLBIALL", .cp = 15, .opc1 = 0, .crn = 8, .crm = 6, .opc2 = 0, - .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbiall_write }, - { .name = "DTLBIMVA", .cp = 15, .opc1 = 0, .crn = 8, .crm = 6, .opc2 = 1, - .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbimva_write }, - { .name = "DTLBIASID", .cp = 15, .opc1 = 0, .crn = 8, .crm = 6, .opc2 = 2, - .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbiasid_write }, - /* 32 bit TLB invalidates */ - { .name = "TLBIALL", .cp = 15, .opc1 = 0, .crn = 8, .crm = 7, .opc2 = 0, - .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbiall_write }, - { .name = "TLBIMVA", .cp = 15, .opc1 = 0, .crn = 8, .crm = 7, .opc2 = 1, - .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbimva_write }, - { .name = "TLBIASID", .cp = 15, .opc1 = 0, .crn = 8, .crm = 7, .opc2 = 2, - .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbiasid_write }, - { .name = "TLBIMVAA", .cp = 15, .opc1 = 0, .crn = 8, .crm = 7, .opc2 = 3, - .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbimvaa_write }, { .name = "TLBIMVAL", .cp = 15, .opc1 = 0, .crn = 8, .crm = 7, .opc2 = 5, .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbimva_write }, { .name = "TLBIMVAAL", .cp = 15, .opc1 = 0, .crn = 8, .crm = 7, .opc2 = 7,
@@ -2434,6 +2439,9 @@ void register_cp_regs_for_features(ARMCPU *cpu)if (arm_feature (env,ARM_FEATURE_V6K )) {define_arm_cp_regs (cpu, v6k_cp_reginfo); } +if (arm_feature (env,ARM_FEATURE_V7MP )) { +define_arm_cp_regs (cpu, v7mp_cp_reginfo); + }if (arm_feature (env,ARM_FEATURE_V7 )) {/* v7 performance monitor control register: same implementor * field as main ID register, and we implement only the cycle
Signature · 1 line
1.9.1
PATCH 2/2 target-arm: Make *IS TLB maintenance ops affect all CPUs
In reply to Peter MaydellThe ARM architecture defines that the "IS" variants of TLB maintenance operations must affect all TLBs in the Inner Shareable domain, which for us means all CPUs. We were incorrectly implementing these to only affect the current CPU, which meant that SMP TCG operation was unstable.
--- target-arm/helper.c | 101 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 89 insertions(+), 12 deletions(-)
target-arm/helper.c +89 -12
@@ -388,6 +388,47 @@ static void tlbimvaa_write(CPUARMState *env, const ARMCPRegInfo *ri,tlb_flush_page (CPU (cpu), value &TARGET_PAGE_MASK ); } +/* IS variants of TLB operations must affect all cores */ +static void tlbiall_is_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +CPUState *other_cs; + +CPU_FOREACH (other_cs) { +tlb_flush (other_cs,1 ); + } +} + +static void tlbiasid_is_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +CPUState *other_cs; + +CPU_FOREACH (other_cs) { +tlb_flush (other_cs, value ==0 ); + } +} + +static void tlbimva_is_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +CPUState *other_cs; + +CPU_FOREACH (other_cs) { +tlb_flush_page (other_cs, value &TARGET_PAGE_MASK ); + } +} + +static void tlbimvaa_is_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +CPUState *other_cs; + +CPU_FOREACH (other_cs) { +tlb_flush_page (other_cs, value &TARGET_PAGE_MASK ); + } +} +static const ARMCPRegInfo cp_reginfo[] = { { .name ="FCSEIDR" , .cp =15 , .crn =13 , .crm =0 , .opc1 =0 , .opc2 =0 , .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.c13_fcse),
@@ -919,13 +960,15 @@ static const ARMCPRegInfo v7_cp_reginfo[] = {static const ARMCPRegInfo v7mp_cp_reginfo[] = {/* 32 bit TLB invalidates, Inner Shareable */ { .name ="TLBIALLIS" , .cp =15 , .opc1 =0 , .crn =8 , .crm =3 , .opc2 =0 , - .type =ARM_CP_NO_MIGRATE , .access =PL1_W , .writefn = tlbiall_write }, + .type =ARM_CP_NO_MIGRATE , .access =PL1_W , .writefn = tlbiall_is_write }, { .name ="TLBIMVAIS" , .cp =15 , .opc1 =0 , .crn =8 , .crm =3 , .opc2 =1 , - .type =ARM_CP_NO_MIGRATE , .access =PL1_W , .writefn = tlbimva_write }, + .type =ARM_CP_NO_MIGRATE , .access =PL1_W , .writefn = tlbimva_is_write }, { .name ="TLBIASIDIS" , .cp =15 , .opc1 =0 , .crn =8 , .crm =3 , .opc2 =2 , - .type =ARM_CP_NO_MIGRATE , .access =PL1_W , .writefn = tlbiasid_write }, + .type =ARM_CP_NO_MIGRATE , .access =PL1_W , + .writefn = tlbiasid_is_write }, { .name ="TLBIMVAAIS" , .cp =15 , .opc1 =0 , .crn =8 , .crm =3 , .opc2 =3 , - .type =ARM_CP_NO_MIGRATE , .access =PL1_W , .writefn = tlbimvaa_write }, + .type =ARM_CP_NO_MIGRATE , .access =PL1_W , + .writefn = tlbimvaa_is_write },REGINFO_SENTINEL };
@@ -1915,6 +1958,39 @@ static void tlbi_aa64_asid_write(CPUARMState *env, const ARMCPRegInfo *ri,tlb_flush (CPU (cpu), asid ==0 ); } +static void tlbi_aa64_va_is_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +CPUState *other_cs; +uint64_t pageaddr =sextract64 (value <<12 ,0 ,56 ); + +CPU_FOREACH (other_cs) { +tlb_flush_page (other_cs, pageaddr); + } +} + +static void tlbi_aa64_vaa_is_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +CPUState *other_cs; +uint64_t pageaddr =sextract64 (value <<12 ,0 ,56 ); + +CPU_FOREACH (other_cs) { +tlb_flush_page (other_cs, pageaddr); + } +} + +static void tlbi_aa64_asid_is_write (CPUARMState *env,const ARMCPRegInfo *ri, +uint64_t value) +{ +CPUState *other_cs; +int asid =extract64 (value,48 ,16 ); + +CPU_FOREACH (other_cs) { +tlb_flush (other_cs, asid ==0 ); + } +} +static CPAccessResult aa64_zva_access (CPUARMState *env,const ARMCPRegInfo *ri) {/* We don't implement EL2, so the only control on DC ZVA is the
@@ -2032,27 +2108,27 @@ static const ARMCPRegInfo v8_cp_reginfo[] = { { .name = "TLBI_VMALLE1IS", .state = ARM_CP_STATE_AA64, .opc0 = 1, .opc1 = 0, .crn = 8, .crm = 3, .opc2 = 0, .access = PL1_W, .type = ARM_CP_NO_MIGRATE, - .writefn = tlbiall_write }, + .writefn = tlbiall_is_write }, { .name = "TLBI_VAE1IS", .state = ARM_CP_STATE_AA64, .opc0 = 1, .opc1 = 0, .crn = 8, .crm = 3, .opc2 = 1, .access = PL1_W, .type = ARM_CP_NO_MIGRATE, - .writefn = tlbi_aa64_va_write }, + .writefn = tlbi_aa64_va_is_write }, { .name = "TLBI_ASIDE1IS", .state = ARM_CP_STATE_AA64, .opc0 = 1, .opc1 = 0, .crn = 8, .crm = 3, .opc2 = 2, .access = PL1_W, .type = ARM_CP_NO_MIGRATE, - .writefn = tlbi_aa64_asid_write }, + .writefn = tlbi_aa64_asid_is_write }, { .name = "TLBI_VAAE1IS", .state = ARM_CP_STATE_AA64, .opc0 = 1, .opc1 = 0, .crn = 8, .crm = 3, .opc2 = 3, .access = PL1_W, .type = ARM_CP_NO_MIGRATE, - .writefn = tlbi_aa64_vaa_write }, + .writefn = tlbi_aa64_vaa_is_write }, { .name = "TLBI_VALE1IS", .state = ARM_CP_STATE_AA64, .opc0 = 1, .opc1 = 0, .crn = 8, .crm = 3, .opc2 = 5, .access = PL1_W, .type = ARM_CP_NO_MIGRATE, - .writefn = tlbi_aa64_va_write }, + .writefn = tlbi_aa64_va_is_write }, { .name = "TLBI_VAALE1IS", .state = ARM_CP_STATE_AA64, .opc0 = 1, .opc1 = 0, .crn = 8, .crm = 3, .opc2 = 7, .access = PL1_W, .type = ARM_CP_NO_MIGRATE, - .writefn = tlbi_aa64_vaa_write }, + .writefn = tlbi_aa64_vaa_is_write }, { .name = "TLBI_VMALLE1", .state = ARM_CP_STATE_AA64, .opc0 = 1, .opc1 = 0, .crn = 8, .crm = 7, .opc2 = 0, .access = PL1_W, .type = ARM_CP_NO_MIGRATE,
@@ -2094,9 +2170,10 @@ static const ARMCPRegInfo v8_cp_reginfo[] = {#endif /* TLB invalidate last level of translation table walk */ { .name = "TLBIMVALIS", .cp = 15, .opc1 = 0, .crn = 8, .crm = 3, .opc2 = 5, - .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbimva_write }, + .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbimva_is_write }, { .name = "TLBIMVAALIS", .cp = 15, .opc1 = 0, .crn = 8, .crm = 3, .opc2 = 7, - .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbimvaa_write }, + .type = ARM_CP_NO_MIGRATE, .access = PL1_W, + .writefn = tlbimvaa_is_write }, { .name = "TLBIMVAL", .cp = 15, .opc1 = 0, .crn = 8, .crm = 7, .opc2 = 5, .type = ARM_CP_NO_MIGRATE, .access = PL1_W, .writefn = tlbimva_write }, { .name = "TLBIMVAAL", .cp = 15, .opc1 = 0, .crn = 8, .crm = 7, .opc2 = 7,
Signature · 1 line
1.9.1