disable the decrementer interrupt when a CPU is unplugged
v2 cover disable the decrementer interrupt when a CPU is unplugged
Hello,
When a CPU is stopped with the 'stop-self' RTAS call, its state 'halted' is switched to 1 and, in this case, the MSR is not taken into account anymore in the cpu_has_work() routine. Only the pending hardware interrupts are checked with their LPCR:PECE* enablement bit.
If the DECR timer fires after 'stop-self' is called and before the CPU 'stop' state is reached, the nearly-dead CPU will have some work to do and the guest will crash. This case happens very frequently with the not yet upstream P9 XIVE exploitation mode. In XICS mode, the DECR is occasionally fired but after 'stop' state, so no work is to be done and the guest survives.
I suspect there is a race between the QEMU mainloop triggering the timers and the TCG CPU thread but I could not quite identify the root cause. To be safe, let's disable the decrementer interrupt in the LPCR when the CPU is halted and reenable it when the CPU is restarted. Reseting the MSR is now pointless, so remove this dubious workaround.
Thanks,
C.
Changes in v2:
- used a new routine ppc_cpu_pvr_match() to discriminate CPU versions
- removed the LPCR:PECE* enablement bit when the CPU is initialized if it is a secondary
- included Nikunj's fix to reboot SMP TCG guests
Cédric Le Goater (4):
target/ppc: export ppc_cpu_pvr_match() helper
spapr/rtas: disable the decrementer interrupt when a CPU is unplugged spapr/rtas: fix reboot of a a SMP TCG guest
spapr/rtas: do not reset the MSR in stop-self command
hw/ppc/spapr_cpu_core.c | 12 ++++++++++++ hw/ppc/spapr_rtas.c | 28 +++++++++++++++++++--------- include/hw/ppc/ppc.h | 1 + target/ppc/machine.c | 5 +++-- target/ppc/translate_init.c | 19 +++++++++++++++++-- 5 files changed, 52 insertions(+), 13 deletions(-)
Signature · 1 line
2.13.6
PATCH v2 1/4 target/ppc: export ppc_cpu_pvr_match() helper
It will be used to test the family of a CPU.
--- include/hw/ppc/ppc.h | 1 + target/ppc/machine.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-)
include/hw/ppc/ppc.h +1 -0
@@ -107,4 +107,5 @@ enum {void ppc_booke_timers_init (PowerPCCPU *cpu,uint32_t freq,uint32_t flags);void ppc_cpu_parse_features (const char *cpu_model); +bool ppc_cpu_pvr_match (PowerPCCPU *cpu,uint32_t pvr);#endif
target/ppc/machine.c +3 -2
@@ -4,6 +4,7 @@#include "exec/exec-all.h" #include "hw/hw.h" #include "hw/boards.h" +#include "hw/ppc/ppc.h" #include "sysemu/kvm.h" #include "helper_regs.h" #include "mmu-hash64.h"
@@ -210,7 +211,7 @@ static int cpu_pre_save(void *opaque)* between sufficiently similar PVRs, as determined by the CPU class's * pvr_match() hook. */ -static bool pvr_match (PowerPCCPU *cpu,uint32_t pvr) +bool ppc_cpu_pvr_match (PowerPCCPU *cpu,uint32_t pvr) {PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu);
@@ -247,7 +248,7 @@ static int cpu_post_load(void *opaque, int version_id) } else#endif { -if (!pvr_match (cpu, env->spr[SPR_PVR ])) { +if (!ppc_cpu_pvr_match (cpu, env->spr[SPR_PVR ])) {return -1 ; } }
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v2 1/4] target/ppc: export ppc_cpu_pvr_match() helper
Quoted 3 lines · Cédric Le Goater
It will be used to test the family of a CPU.
Signed-off-by Cédric Le Goater <[email protected]>
I don't think this is useful, see comments on later patches.
Quoted 45 lines
--- include/hw/ppc/ppc.h | 1 + target/ppc/machine.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-)include/hw/ppc/ppc.h +1
-0@@ -107,4 +107,5 @@ enum {void ppc_booke_timers_init (PowerPCCPU *cpu,uint32_t freq,uint32_t flags);void ppc_cpu_parse_features (const char *cpu_model); +bool ppc_cpu_pvr_match (PowerPCCPU *cpu,uint32_t pvr);#endif target/ppc/machine.c +3
-2@@ -4,6 +4,7 @@#include "exec/exec-all.h" #include "hw/hw.h" #include "hw/boards.h" +#include "hw/ppc/ppc.h" #include "sysemu/kvm.h" #include "helper_regs.h" #include "mmu-hash64.h" @@ -210,7 +211,7 @@ static int cpu_pre_save(void *opaque)* between sufficiently similar PVRs, as determined by the CPU class's * pvr_match() hook. */ -static bool pvr_match (PowerPCCPU *cpu,uint32_t pvr) +bool ppc_cpu_pvr_match (PowerPCCPU *cpu,uint32_t pvr) {PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu);@@ -247,7 +248,7 @@ static int cpu_post_load(void *opaque, int version_id) } else#endif { -if (!pvr_match (cpu, env->spr[SPR_PVR ])) { +if (!ppc_cpu_pvr_match (cpu, env->spr[SPR_PVR ])) {return -1 ; } }
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH v2 2/4 spapr/rtas: disable the decrementer interrupt when a CPU is unplugged
In reply to Cédric Le GoaterWhen a CPU is stopped with the 'stop-self' RTAS call, its state 'halted' is switched to 1 and, in this case, the MSR is not taken into account anymore in the cpu_has_work() routine. Only the pending hardware interrupts are checked with their LPCR:PECE* enablement bit.
If the DECR timer fires after 'stop-self' is called and before the CPU 'stop' state is reached, the nearly-dead CPU will have some work to do and the guest will crash. This case happens very frequently with the not yet upstream P9 XIVE exploitation mode. In XICS mode, the DECR is occasionally fired but after 'stop' state, so no work is to be done and the guest survives.
I suspect there is a race between the QEMU mainloop triggering the timers and the TCG CPU thread but I could not quite identify the root cause. To be safe, let's disable the decrementer interrupt in the LPCR when the CPU is halted and reenable it when the CPU is restarted.
---
Changes in v2:
- used a new routine ppc_cpu_pvr_match() to discriminate CPU versions
- removed the LPCR:PECE* enablement bit when the CPU is initialized if it is a secondary
hw/ppc/spapr_rtas.c | 20 ++++++++++++++++++++ target/ppc/translate_init.c | 19 +++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-)
hw/ppc/spapr_rtas.c +20 -0
@@ -46,6 +46,7 @@#include "qemu/cutils.h" #include "trace.h" #include "hw/ppc/fdt.h" +#include "target/ppc/cpu-models.h" static void rtas_display_character(PowerPCCPU *cpu, sPAPRMachineState *spapr, uint32_t token, uint32_t nargs,
@@ -174,6 +175,15 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr,kvm_cpu_synchronize_state (cs); env->msr = (1ULL <<MSR_SF ) | (1ULL <<MSR_ME ); + +/* Enable DECR interrupt */ +if (ppc_cpu_pvr_match (cpu,CPU_POWERPC_LOGICAL_3_00 )) { + env->spr[SPR_LPCR ] |=LPCR_DEE ; + }else { +/* P7 and P8 both have same bit for DECR */ + env->spr[SPR_LPCR ] |=LPCR_P8_PECE3 ; + } + env->nip = start; env->gpr[3 ] = r3; cs->halted =0 ;
@@ -210,6 +220,16 @@ static void rtas_stop_self(PowerPCCPU *cpu, sPAPRMachineState *spapr,* no need to bother with specific bits, we just clear it. */ env->msr =0 ; + +/* Don't let the decremeter run on a CPU being stopped. This could +* deliver an interrupt on a dying CPU and crash the guest. +*/ +if (ppc_cpu_pvr_match (cpu,CPU_POWERPC_LOGICAL_3_00 )) { + env->spr[SPR_LPCR ] &= ~LPCR_DEE ; + }else { +/* P7 and P8 both have same bit for DECR */ + env->spr[SPR_LPCR ] &= ~LPCR_P8_PECE3 ; + } } static inline int sysparm_st(target_ulong addr, target_ulong len,
target/ppc/translate_init.c +17 -2
@@ -8905,6 +8905,7 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp)CPUPPCState *env = &cpu->env;ppc_spr_t *lpcr = &env->spr_cb[SPR_LPCR ];ppc_spr_t *amor = &env->spr_cb[SPR_AMOR ]; +CPUState *cs =CPU (cpu); cpu->vhyp = vhyp;
@@ -8946,8 +8947,15 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) }else { lpcr->default_value &= ~(LPCR_UPRT |LPCR_GTSE ); } - lpcr->default_value |=LPCR_PDEE |LPCR_HDEE |LPCR_EEE |LPCR_DEE | + lpcr->default_value |=LPCR_PDEE |LPCR_HDEE |LPCR_EEE |LPCR_OEE ; + +/* Only let the decremeter wake up the boot CPU. The RTAS +* command start-cpu will enable it on secondaries. +*/ +if (cs == first_cpu) { + lpcr->default_value |=LPCR_DEE ; + }break ;default :/* P7 and P8 has slightly different PECE bits, mostly because P8 adds
@@ -8955,7 +8963,14 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp)* will work as expected for both implementations */ lpcr->default_value |=LPCR_P8_PECE0 |LPCR_P8_PECE1 |LPCR_P8_PECE2 | -LPCR_P8_PECE3 |LPCR_P8_PECE4 ; +LPCR_P8_PECE4 ; + +/* Only let the decremeter wake up the boot CPU. The RTAS +* command start-cpu will enable it on secondaries. +*/ +if (cs == first_cpu) { + lpcr->default_value |=LPCR_P8_PECE3 ; + } }/* We should be followed by a CPU reset but update the active value
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v2 2/4] spapr/rtas: disable the decrementer interrupt when a CPU is unplugged
Quoted 12 lines · Cédric Le Goater
When a CPU is stopped with the 'stop-self' RTAS call, its state 'halted' is switched to 1 and, in this case, the MSR is not taken into account anymore in the
cpu_has_work()routine. Only the pending hardware interrupts are checked with their LPCR:PECE* enablement bit.If the DECR timer fires after 'stop-self' is called and before the CPU 'stop' state is reached, the nearly-dead CPU will have some work to do and the guest will crash. This case happens very frequently with the not yet upstream P9 XIVE exploitation mode. In XICS mode, the DECR is occasionally fired but after 'stop' state, so no work is to be done and the guest survives.
Quoted 6 lines
I suspect there is a race between the QEMU mainloop triggering the timers and the TCG CPU thread but I could not quite identify the root cause. To be safe, let's disable the decrementer interrupt in the LPCR when the CPU is halted and reenable it when the CPU is restarted.
Signed-off-by Cédric Le Goater <[email protected]>
We should disable external interrupts and doorbells too no ? IE, we could clear all of PECE in fact.
Quoted 102 lines
---
Changes in v2:
- used a new routine
ppc_cpu_pvr_match()to discriminate CPU versions
- removed the LPCR:PECE* enablement bit when the CPU is initialized if it is a secondaryhw/ppc/spapr_rtas.c | 20 ++++++++++++++++++++ target/ppc/translate_init.c | 19 +++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-)hw/ppc/spapr_rtas.c +20
-0@@ -46,6 +46,7 @@#include "qemu/cutils.h" #include "trace.h" #include "hw/ppc/fdt.h" +#include "target/ppc/cpu-models.h" static void rtas_display_character(PowerPCCPU *cpu, sPAPRMachineState *spapr, uint32_t token, uint32_t nargs,@@ -174,6 +175,15 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr,kvm_cpu_synchronize_state (cs); env->msr = (1ULL <<MSR_SF ) | (1ULL <<MSR_ME ); + +/* Enable DECR interrupt */ +if (ppc_cpu_pvr_match (cpu,CPU_POWERPC_LOGICAL_3_00 )) { + env->spr[SPR_LPCR ] |=LPCR_DEE ; + }else { +/* P7 and P8 both have same bit for DECR */ + env->spr[SPR_LPCR ] |=LPCR_P8_PECE3 ; + } + env->nip = start; env->gpr[3 ] = r3; cs->halted =0 ;@@ -210,6 +220,16 @@ static void rtas_stop_self(PowerPCCPU *cpu, sPAPRMachineState *spapr,* no need to bother with specific bits, we just clear it. */ env->msr =0 ; + +/* Don't let the decremeter run on a CPU being stopped. This could +* deliver an interrupt on a dying CPU and crash the guest. +*/ +if (ppc_cpu_pvr_match (cpu,CPU_POWERPC_LOGICAL_3_00 )) { + env->spr[SPR_LPCR ] &= ~LPCR_DEE ; + }else { +/* P7 and P8 both have same bit for DECR */ + env->spr[SPR_LPCR ] &= ~LPCR_P8_PECE3 ; + } } static inline int sysparm_st(target_ulong addr, target_ulong len,target/ppc/translate_init.c +17
-2@@ -8905,6 +8905,7 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp)CPUPPCState *env = &cpu->env;ppc_spr_t *lpcr = &env->spr_cb[SPR_LPCR ];ppc_spr_t *amor = &env->spr_cb[SPR_AMOR ]; +CPUState *cs =CPU (cpu); cpu->vhyp = vhyp;@@ -8946,8 +8947,15 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) }else { lpcr->default_value &= ~(LPCR_UPRT |LPCR_GTSE ); } - lpcr->default_value |=LPCR_PDEE |LPCR_HDEE |LPCR_EEE |LPCR_DEE | + lpcr->default_value |=LPCR_PDEE |LPCR_HDEE |LPCR_EEE |LPCR_OEE ; + +/* Only let the decremeter wake up the boot CPU. The RTAS +* command start-cpu will enable it on secondaries. +*/ +if (cs == first_cpu) { + lpcr->default_value |=LPCR_DEE ; + }break ;default :/* P7 and P8 has slightly different PECE bits, mostly because P8 adds @@ -8955,7 +8963,14 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp)* will work as expected for both implementations */ lpcr->default_value |=LPCR_P8_PECE0 |LPCR_P8_PECE1 |LPCR_P8_PECE2 | -LPCR_P8_PECE3 |LPCR_P8_PECE4 ; +LPCR_P8_PECE4 ; + +/* Only let the decremeter wake up the boot CPU. The RTAS +* command start-cpu will enable it on secondaries. +*/ +if (cs == first_cpu) { + lpcr->default_value |=LPCR_P8_PECE3 ; + } }/* We should be followed by a CPU reset but update the active value
Re: [Qemu-devel] [PATCH v2 2/4] spapr/rtas: disable the decrementer interrupt when a CPU is unplugged
Quoted 18 lines · Benjamin Herrenschmidt
Quoted 17 lines · Cédric Le Goater
When a CPU is stopped with the 'stop-self' RTAS call, its state 'halted' is switched to 1 and, in this case, the MSR is not taken into account anymore in the
cpu_has_work()routine. Only the pending hardware interrupts are checked with their LPCR:PECE* enablement bit.If the DECR timer fires after 'stop-self' is called and before the CPU 'stop' state is reached, the nearly-dead CPU will have some work to do and the guest will crash. This case happens very frequently with the not yet upstream P9 XIVE exploitation mode. In XICS mode, the DECR is occasionally fired but after 'stop' state, so no work is to be done and the guest survives.
I suspect there is a race between the QEMU mainloop triggering the timers and the TCG CPU thread but I could not quite identify the root cause. To be safe, let's disable the decrementer interrupt in the LPCR when the CPU is halted and reenable it when the CPU is restarted.
Quoted 4 lines
Quoted 1 line
Signed-off-by Cédric Le Goater <[email protected]>We should disable external interrupts and doorbells too no ? IE, we could clear all of PECE in fact.
and enable them all in 'start-cpu' for secondaries then ?
C.
Quoted 103 lines
Quoted 103 lines
---
Changes in v2:
- used a new routine
ppc_cpu_pvr_match()to discriminate CPU versions
- removed the LPCR:PECE* enablement bit when the CPU is initialized if it is a secondaryhw/ppc/spapr_rtas.c | 20 ++++++++++++++++++++ target/ppc/translate_init.c | 19 +++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-)hw/ppc/spapr_rtas.c +20
-0@@ -46,6 +46,7 @@#include "qemu/cutils.h" #include "trace.h" #include "hw/ppc/fdt.h" +#include "target/ppc/cpu-models.h" static void rtas_display_character(PowerPCCPU *cpu, sPAPRMachineState *spapr, uint32_t token, uint32_t nargs,@@ -174,6 +175,15 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr,kvm_cpu_synchronize_state (cs); env->msr = (1ULL <<MSR_SF ) | (1ULL <<MSR_ME ); + +/* Enable DECR interrupt */ +if (ppc_cpu_pvr_match (cpu,CPU_POWERPC_LOGICAL_3_00 )) { + env->spr[SPR_LPCR ] |=LPCR_DEE ; + }else { +/* P7 and P8 both have same bit for DECR */ + env->spr[SPR_LPCR ] |=LPCR_P8_PECE3 ; + } + env->nip = start; env->gpr[3 ] = r3; cs->halted =0 ;@@ -210,6 +220,16 @@ static void rtas_stop_self(PowerPCCPU *cpu, sPAPRMachineState *spapr,* no need to bother with specific bits, we just clear it. */ env->msr =0 ; + +/* Don't let the decremeter run on a CPU being stopped. This could +* deliver an interrupt on a dying CPU and crash the guest. +*/ +if (ppc_cpu_pvr_match (cpu,CPU_POWERPC_LOGICAL_3_00 )) { + env->spr[SPR_LPCR ] &= ~LPCR_DEE ; + }else { +/* P7 and P8 both have same bit for DECR */ + env->spr[SPR_LPCR ] &= ~LPCR_P8_PECE3 ; + } } static inline int sysparm_st(target_ulong addr, target_ulong len,target/ppc/translate_init.c +17
-2@@ -8905,6 +8905,7 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp)CPUPPCState *env = &cpu->env;ppc_spr_t *lpcr = &env->spr_cb[SPR_LPCR ];ppc_spr_t *amor = &env->spr_cb[SPR_AMOR ]; +CPUState *cs =CPU (cpu); cpu->vhyp = vhyp;@@ -8946,8 +8947,15 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) }else { lpcr->default_value &= ~(LPCR_UPRT |LPCR_GTSE ); } - lpcr->default_value |=LPCR_PDEE |LPCR_HDEE |LPCR_EEE |LPCR_DEE | + lpcr->default_value |=LPCR_PDEE |LPCR_HDEE |LPCR_EEE |LPCR_OEE ; + +/* Only let the decremeter wake up the boot CPU. The RTAS +* command start-cpu will enable it on secondaries. +*/ +if (cs == first_cpu) { + lpcr->default_value |=LPCR_DEE ; + }break ;default :/* P7 and P8 has slightly different PECE bits, mostly because P8 adds @@ -8955,7 +8963,14 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp)* will work as expected for both implementations */ lpcr->default_value |=LPCR_P8_PECE0 |LPCR_P8_PECE1 |LPCR_P8_PECE2 | -LPCR_P8_PECE3 |LPCR_P8_PECE4 ; +LPCR_P8_PECE4 ; + +/* Only let the decremeter wake up the boot CPU. The RTAS +* command start-cpu will enable it on secondaries. +*/ +if (cs == first_cpu) { + lpcr->default_value |=LPCR_P8_PECE3 ; + } }/* We should be followed by a CPU reset but update the active value
Re: [Qemu-devel] [PATCH v2 2/4] spapr/rtas: disable the decrementer interrupt when a CPU is unplugged
In reply to Cédric Le GoaterQuoted 43 lines · Cédric Le Goater
When a CPU is stopped with the 'stop-self' RTAS call, its state 'halted' is switched to 1 and, in this case, the MSR is not taken into account anymore in the
cpu_has_work()routine. Only the pending hardware interrupts are checked with their LPCR:PECE* enablement bit.If the DECR timer fires after 'stop-self' is called and before the CPU 'stop' state is reached, the nearly-dead CPU will have some work to do and the guest will crash. This case happens very frequently with the not yet upstream P9 XIVE exploitation mode. In XICS mode, the DECR is occasionally fired but after 'stop' state, so no work is to be done and the guest survives.
I suspect there is a race between the QEMU mainloop triggering the timers and the TCG CPU thread but I could not quite identify the root cause. To be safe, let's disable the decrementer interrupt in the LPCR when the CPU is halted and reenable it when the CPU is restarted.
Signed-off-by Cédric Le Goater <[email protected]>---
Changes in v2:
- used a new routine
ppc_cpu_pvr_match()to discriminate CPU versions
- removed the LPCR:PECE* enablement bit when the CPU is initialized if it is a secondaryhw/ppc/spapr_rtas.c | 20 ++++++++++++++++++++ target/ppc/translate_init.c | 19 +++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-)hw/ppc/spapr_rtas.c +1
-0@@ -46,6 +46,7 @@#include "qemu/cutils.h" #include "trace.h" #include "hw/ppc/fdt.h" +#include "target/ppc/cpu-models.h" static void rtas_display_character(PowerPCCPU *cpu, sPAPRMachineState *spapr, uint32_t token, uint32_t nargs,
hw/ppc/spapr_rtas.c static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr, · line 180
Quoted 6 lines
hw/ppc/spapr_rtas.c +3
-0@@ -174,6 +175,15 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr,kvm_cpu_synchronize_state (cs); env->msr = (1ULL <<MSR_SF ) | (1ULL <<MSR_ME ); + +/* Enable DECR interrupt */ +if (ppc_cpu_pvr_match (cpu,CPU_POWERPC_LOGICAL_3_00 )) {
Sorry, I didn't reply to your earlier mail in time. Going via the PVR in this way seems bonkers to me - I like it even less than checking the mmu type. After all, classifying a bunch of precise models (PVRs) together by behaviour is kind of exactly what the CPU classes are for, so using object_dynamic_case() (==instance_of) is a better idea here.
hw/ppc/spapr_rtas.c static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr, · line 189
Quoted 9 lines
hw/ppc/spapr_rtas.c +6
-0+ env->spr[SPR_LPCR ] |=LPCR_DEE ; + }else { +/* P7 and P8 both have same bit for DECR */ + env->spr[SPR_LPCR ] |=LPCR_P8_PECE3 ; + } + env->nip = start; env->gpr[3 ] = r3; cs->halted =0 ;
The other option I'm wondering about here is to actually add a "shutdown" (or something) method to the cpu class, which does whatever is necessary to put the vcpu into a quiescent state that won't be woken up unless it's specifically requested.
Quoted 30 lines
hw/ppc/spapr_rtas.c +10
-0@@ -210,6 +220,16 @@ static void rtas_stop_self(PowerPCCPU *cpu, sPAPRMachineState *spapr,* no need to bother with specific bits, we just clear it. */ env->msr =0 ; + +/* Don't let the decremeter run on a CPU being stopped. This could +* deliver an interrupt on a dying CPU and crash the guest. +*/ +if (ppc_cpu_pvr_match (cpu,CPU_POWERPC_LOGICAL_3_00 )) { + env->spr[SPR_LPCR ] &= ~LPCR_DEE ; + }else { +/* P7 and P8 both have same bit for DECR */ + env->spr[SPR_LPCR ] &= ~LPCR_P8_PECE3 ; + } } static inline int sysparm_st(target_ulong addr, target_ulong len,target/ppc/translate_init.c +1
-0@@ -8905,6 +8905,7 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp)CPUPPCState *env = &cpu->env;ppc_spr_t *lpcr = &env->spr_cb[SPR_LPCR ];ppc_spr_t *amor = &env->spr_cb[SPR_AMOR ]; +CPUState *cs =CPU (cpu); cpu->vhyp = vhyp;
target/ppc/translate_init.c void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) · line 8951
Quoted 6 lines
target/ppc/translate_init.c +1
-1@@ -8946,8 +8947,15 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) }else { lpcr->default_value &= ~(LPCR_UPRT |LPCR_GTSE ); } - lpcr->default_value |=LPCR_PDEE |LPCR_HDEE |LPCR_EEE |LPCR_DEE | + lpcr->default_value |=LPCR_PDEE |LPCR_HDEE |LPCR_EEE |LPCR_OEE ;
But I guess we'd also need a "set_papr" method to go with that.
Quoted 26 lines
target/ppc/translate_init.c +15
-1+ +/* Only let the decremeter wake up the boot CPU. The RTAS +* command start-cpu will enable it on secondaries. +*/ +if (cs == first_cpu) { + lpcr->default_value |=LPCR_DEE ; + }break ;default :/* P7 and P8 has slightly different PECE bits, mostly because P8 adds @@ -8955,7 +8963,14 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp)* will work as expected for both implementations */ lpcr->default_value |=LPCR_P8_PECE0 |LPCR_P8_PECE1 |LPCR_P8_PECE2 | -LPCR_P8_PECE3 |LPCR_P8_PECE4 ; +LPCR_P8_PECE4 ; + +/* Only let the decremeter wake up the boot CPU. The RTAS +* command start-cpu will enable it on secondaries. +*/ +if (cs == first_cpu) { + lpcr->default_value |=LPCR_P8_PECE3 ; + } }/* We should be followed by a CPU reset but update the active value
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH v2 2/4] spapr/rtas: disable the decrementer interrupt when a CPU is unplugged
Quoted 46 lines · David Gibson
Quoted 45 lines · Cédric Le Goater
When a CPU is stopped with the 'stop-self' RTAS call, its state 'halted' is switched to 1 and, in this case, the MSR is not taken into account anymore in the
cpu_has_work()routine. Only the pending hardware interrupts are checked with their LPCR:PECE* enablement bit.If the DECR timer fires after 'stop-self' is called and before the CPU 'stop' state is reached, the nearly-dead CPU will have some work to do and the guest will crash. This case happens very frequently with the not yet upstream P9 XIVE exploitation mode. In XICS mode, the DECR is occasionally fired but after 'stop' state, so no work is to be done and the guest survives.
I suspect there is a race between the QEMU mainloop triggering the timers and the TCG CPU thread but I could not quite identify the root cause. To be safe, let's disable the decrementer interrupt in the LPCR when the CPU is halted and reenable it when the CPU is restarted.
Signed-off-by Cédric Le Goater <[email protected]>---
Changes in v2:
- used a new routine
ppc_cpu_pvr_match()to discriminate CPU versions
- removed the LPCR:PECE* enablement bit when the CPU is initialized if it is a secondaryhw/ppc/spapr_rtas.c | 20 ++++++++++++++++++++ target/ppc/translate_init.c | 19 +++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-)hw/ppc/spapr_rtas.c +1
-0@@ -46,6 +46,7 @@#include "qemu/cutils.h" #include "trace.h" #include "hw/ppc/fdt.h" +#include "target/ppc/cpu-models.h" static void rtas_display_character(PowerPCCPU *cpu, sPAPRMachineState *spapr, uint32_t token, uint32_t nargs,@@ -174,6 +175,15 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr,kvm_cpu_synchronize_state (cs);
Quoted 10 lines
hw/ppc/spapr_rtas.c static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr, · line 180
Quoted 4 lines
hw/ppc/spapr_rtas.c +3
-0env->msr = (1ULL <<MSR_SF ) | (1ULL <<MSR_ME ); + +/* Enable DECR interrupt */ +if (ppc_cpu_pvr_match (cpu,CPU_POWERPC_LOGICAL_3_00 )) {Sorry, I didn't reply to your earlier mail in time. Going via the PVR in this way seems bonkers to me - I like it even less than checking the mmu type. After all, classifying a bunch of precise models (PVRs) together by behaviour is kind of exactly what the CPU classes are for, so using
object_dynamic_case()(==instance_of) is a better idea here.
hmm, and which type should I use ? we don't have any TYPE_POWER9* we could use for a object_dynamic_cast(). I don't think so ? I could use the name and strcmp("power9") probably but it looks ugly.
The only thing we have is "CPU_POWERPC_POWER9_BASE" and it only applicates to PVR.
May be I don't understand your idea.
Quoted 10 lines
hw/ppc/spapr_rtas.c static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr, · line 189
Quoted 9 lines
hw/ppc/spapr_rtas.c +6
-0+ env->spr[SPR_LPCR ] |=LPCR_DEE ; + }else { +/* P7 and P8 both have same bit for DECR */ + env->spr[SPR_LPCR ] |=LPCR_P8_PECE3 ; + } + env->nip = start; env->gpr[3 ] = r3; cs->halted =0 ;
Quoted 4 lines
The other option I'm wondering about here is to actually add a "shutdown" (or something) method to the cpu class, which does whatever is necessary to put the vcpu into a quiescent state that won't be woken up unless it's specifically requested.
yes. That is a good idea.
Thanks,
C.
Quoted 66 lines
Quoted 30 lines
hw/ppc/spapr_rtas.c +10
-0@@ -210,6 +220,16 @@ static void rtas_stop_self(PowerPCCPU *cpu, sPAPRMachineState *spapr,* no need to bother with specific bits, we just clear it. */ env->msr =0 ; + +/* Don't let the decremeter run on a CPU being stopped. This could +* deliver an interrupt on a dying CPU and crash the guest. +*/ +if (ppc_cpu_pvr_match (cpu,CPU_POWERPC_LOGICAL_3_00 )) { + env->spr[SPR_LPCR ] &= ~LPCR_DEE ; + }else { +/* P7 and P8 both have same bit for DECR */ + env->spr[SPR_LPCR ] &= ~LPCR_P8_PECE3 ; + } } static inline int sysparm_st(target_ulong addr, target_ulong len,target/ppc/translate_init.c +1
-0@@ -8905,6 +8905,7 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp)CPUPPCState *env = &cpu->env;ppc_spr_t *lpcr = &env->spr_cb[SPR_LPCR ];ppc_spr_t *amor = &env->spr_cb[SPR_AMOR ]; +CPUState *cs =CPU (cpu); cpu->vhyp = vhyp;target/ppc/translate_init.c void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) · line 8951
Quoted 6 lines
target/ppc/translate_init.c +1
-1@@ -8946,8 +8947,15 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) }else { lpcr->default_value &= ~(LPCR_UPRT |LPCR_GTSE ); } - lpcr->default_value |=LPCR_PDEE |LPCR_HDEE |LPCR_EEE |LPCR_DEE | + lpcr->default_value |=LPCR_PDEE |LPCR_HDEE |LPCR_EEE |LPCR_OEE ;But I guess we'd also need a "
set_papr" method to go with that.Quoted 26 lines
target/ppc/translate_init.c +15
-1+ +/* Only let the decremeter wake up the boot CPU. The RTAS +* command start-cpu will enable it on secondaries. +*/ +if (cs == first_cpu) { + lpcr->default_value |=LPCR_DEE ; + }break ;default :/* P7 and P8 has slightly different PECE bits, mostly because P8 adds @@ -8955,7 +8963,14 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp)* will work as expected for both implementations */ lpcr->default_value |=LPCR_P8_PECE0 |LPCR_P8_PECE1 |LPCR_P8_PECE2 | -LPCR_P8_PECE3 |LPCR_P8_PECE4 ; +LPCR_P8_PECE4 ; + +/* Only let the decremeter wake up the boot CPU. The RTAS +* command start-cpu will enable it on secondaries. +*/ +if (cs == first_cpu) { + lpcr->default_value |=LPCR_P8_PECE3 ; + } }/* We should be followed by a CPU reset but update the active value
Re: [Qemu-devel] [PATCH v2 2/4] spapr/rtas: disable the decrementer interrupt when a CPU is unplugged
Quoted 58 lines · Cédric Le Goater
Quoted 46 lines · David Gibson
Quoted 45 lines · Cédric Le Goater
When a CPU is stopped with the 'stop-self' RTAS call, its state 'halted' is switched to 1 and, in this case, the MSR is not taken into account anymore in the
cpu_has_work()routine. Only the pending hardware interrupts are checked with their LPCR:PECE* enablement bit.If the DECR timer fires after 'stop-self' is called and before the CPU 'stop' state is reached, the nearly-dead CPU will have some work to do and the guest will crash. This case happens very frequently with the not yet upstream P9 XIVE exploitation mode. In XICS mode, the DECR is occasionally fired but after 'stop' state, so no work is to be done and the guest survives.
I suspect there is a race between the QEMU mainloop triggering the timers and the TCG CPU thread but I could not quite identify the root cause. To be safe, let's disable the decrementer interrupt in the LPCR when the CPU is halted and reenable it when the CPU is restarted.
Signed-off-by Cédric Le Goater <[email protected]>---
Changes in v2:
- used a new routine
ppc_cpu_pvr_match()to discriminate CPU versions
- removed the LPCR:PECE* enablement bit when the CPU is initialized if it is a secondaryhw/ppc/spapr_rtas.c | 20 ++++++++++++++++++++ target/ppc/translate_init.c | 19 +++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-)hw/ppc/spapr_rtas.c +1
-0@@ -46,6 +46,7 @@#include "qemu/cutils.h" #include "trace.h" #include "hw/ppc/fdt.h" +#include "target/ppc/cpu-models.h" static void rtas_display_character(PowerPCCPU *cpu, sPAPRMachineState *spapr, uint32_t token, uint32_t nargs,@@ -174,6 +175,15 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr,kvm_cpu_synchronize_state (cs);Quoted 10 lines
hw/ppc/spapr_rtas.c static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr, · line 180
Quoted 4 lines
hw/ppc/spapr_rtas.c +3
-0env->msr = (1ULL <<MSR_SF ) | (1ULL <<MSR_ME ); + +/* Enable DECR interrupt */ +if (ppc_cpu_pvr_match (cpu,CPU_POWERPC_LOGICAL_3_00 )) {Sorry, I didn't reply to your earlier mail in time. Going via the PVR in this way seems bonkers to me - I like it even less than checking the mmu type. After all, classifying a bunch of precise models (PVRs) together by behaviour is kind of exactly what the CPU classes are for, so using
object_dynamic_case()(==instance_of) is a better idea here.
Quoted 3 lines
hmm, and which type should I use ? we don't have any TYPE_POWER9* we could use for a
object_dynamic_cast(). I don't think so ? I could use the name andstrcmp("power9")probably but it looks ugly.
Actually there is, but, yeah, it's a lot less obvious than I thought. It's constructed by the POWERPC_FAILY macro and will be "POWER9-family-powerpc64-cpu"
Quoted 4 lines
The only thing we have is "
CPU_POWERPC_POWER9_BASE" and it only applicates to PVR.May be I don't understand your idea.
Urgh, sorry. This got much muckier than I thought it would be. I think maybe it's best to go back to the mmu type test, and later on we can fix up both the previously existing test like that, and the new one to something better.
Quoted 89 lines
Quoted 10 lines
hw/ppc/spapr_rtas.c static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr, · line 189
Quoted 9 lines
hw/ppc/spapr_rtas.c +6
-0+ env->spr[SPR_LPCR ] |=LPCR_DEE ; + }else { +/* P7 and P8 both have same bit for DECR */ + env->spr[SPR_LPCR ] |=LPCR_P8_PECE3 ; + } + env->nip = start; env->gpr[3 ] = r3; cs->halted =0 ;Quoted 4 lines
The other option I'm wondering about here is to actually add a "shutdown" (or something) method to the cpu class, which does whatever is necessary to put the vcpu into a quiescent state that won't be woken up unless it's specifically requested.
yes. That is a good idea.
Thanks,
C.
Quoted 66 lines
Quoted 30 lines
hw/ppc/spapr_rtas.c +10
-0@@ -210,6 +220,16 @@ static void rtas_stop_self(PowerPCCPU *cpu, sPAPRMachineState *spapr,* no need to bother with specific bits, we just clear it. */ env->msr =0 ; + +/* Don't let the decremeter run on a CPU being stopped. This could +* deliver an interrupt on a dying CPU and crash the guest. +*/ +if (ppc_cpu_pvr_match (cpu,CPU_POWERPC_LOGICAL_3_00 )) { + env->spr[SPR_LPCR ] &= ~LPCR_DEE ; + }else { +/* P7 and P8 both have same bit for DECR */ + env->spr[SPR_LPCR ] &= ~LPCR_P8_PECE3 ; + } } static inline int sysparm_st(target_ulong addr, target_ulong len,target/ppc/translate_init.c +1
-0@@ -8905,6 +8905,7 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp)CPUPPCState *env = &cpu->env;ppc_spr_t *lpcr = &env->spr_cb[SPR_LPCR ];ppc_spr_t *amor = &env->spr_cb[SPR_AMOR ]; +CPUState *cs =CPU (cpu); cpu->vhyp = vhyp;target/ppc/translate_init.c void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) · line 8951
Quoted 6 lines
target/ppc/translate_init.c +1
-1@@ -8946,8 +8947,15 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) }else { lpcr->default_value &= ~(LPCR_UPRT |LPCR_GTSE ); } - lpcr->default_value |=LPCR_PDEE |LPCR_HDEE |LPCR_EEE |LPCR_DEE | + lpcr->default_value |=LPCR_PDEE |LPCR_HDEE |LPCR_EEE |LPCR_OEE ;But I guess we'd also need a "
set_papr" method to go with that.Quoted 26 lines
target/ppc/translate_init.c +15
-1+ +/* Only let the decremeter wake up the boot CPU. The RTAS +* command start-cpu will enable it on secondaries. +*/ +if (cs == first_cpu) { + lpcr->default_value |=LPCR_DEE ; + }break ;default :/* P7 and P8 has slightly different PECE bits, mostly because P8 adds @@ -8955,7 +8963,14 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp)* will work as expected for both implementations */ lpcr->default_value |=LPCR_P8_PECE0 |LPCR_P8_PECE1 |LPCR_P8_PECE2 | -LPCR_P8_PECE3 |LPCR_P8_PECE4 ; +LPCR_P8_PECE4 ; + +/* Only let the decremeter wake up the boot CPU. The RTAS +* command start-cpu will enable it on secondaries. +*/ +if (cs == first_cpu) { + lpcr->default_value |=LPCR_P8_PECE3 ; + } }/* We should be followed by a CPU reset but update the active value
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH v2 2/4] spapr/rtas: disable the decrementer interrupt when a CPU is unplugged
Quoted 70 lines · David Gibson
Quoted 58 lines · Cédric Le Goater
Quoted 46 lines · David Gibson
Quoted 45 lines · Cédric Le Goater
When a CPU is stopped with the 'stop-self' RTAS call, its state 'halted' is switched to 1 and, in this case, the MSR is not taken into account anymore in the
cpu_has_work()routine. Only the pending hardware interrupts are checked with their LPCR:PECE* enablement bit.If the DECR timer fires after 'stop-self' is called and before the CPU 'stop' state is reached, the nearly-dead CPU will have some work to do and the guest will crash. This case happens very frequently with the not yet upstream P9 XIVE exploitation mode. In XICS mode, the DECR is occasionally fired but after 'stop' state, so no work is to be done and the guest survives.
I suspect there is a race between the QEMU mainloop triggering the timers and the TCG CPU thread but I could not quite identify the root cause. To be safe, let's disable the decrementer interrupt in the LPCR when the CPU is halted and reenable it when the CPU is restarted.
Signed-off-by Cédric Le Goater <[email protected]>---
Changes in v2:
- used a new routine
ppc_cpu_pvr_match()to discriminate CPU versions
- removed the LPCR:PECE* enablement bit when the CPU is initialized if it is a secondaryhw/ppc/spapr_rtas.c | 20 ++++++++++++++++++++ target/ppc/translate_init.c | 19 +++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-)hw/ppc/spapr_rtas.c +1
-0@@ -46,6 +46,7 @@#include "qemu/cutils.h" #include "trace.h" #include "hw/ppc/fdt.h" +#include "target/ppc/cpu-models.h" static void rtas_display_character(PowerPCCPU *cpu, sPAPRMachineState *spapr, uint32_t token, uint32_t nargs,@@ -174,6 +175,15 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr,kvm_cpu_synchronize_state (cs);Quoted 10 lines
hw/ppc/spapr_rtas.c static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr, · line 180
Quoted 4 lines
hw/ppc/spapr_rtas.c +3
-0env->msr = (1ULL <<MSR_SF ) | (1ULL <<MSR_ME ); + +/* Enable DECR interrupt */ +if (ppc_cpu_pvr_match (cpu,CPU_POWERPC_LOGICAL_3_00 )) {Sorry, I didn't reply to your earlier mail in time. Going via the PVR in this way seems bonkers to me - I like it even less than checking the mmu type. After all, classifying a bunch of precise models (PVRs) together by behaviour is kind of exactly what the CPU classes are for, so using
object_dynamic_case()(==instance_of) is a better idea here.Quoted 3 lines
hmm, and which type should I use ? we don't have any TYPE_POWER9* we could use for a
object_dynamic_cast(). I don't think so ? I could use the name andstrcmp("power9")probably but it looks ugly.Actually there is, but, yeah, it's a lot less obvious than I thought. It's constructed by the
POWERPC_FAILYmacro and will be "POWER9-family-powerpc64-cpu"Quoted 3 lines
The only thing we have is "
CPU_POWERPC_POWER9_BASE" and it only applicates to PVR.
Quoted 6 lines
Quoted 1 line
May be I don't understand your idea.
Urgh, sorry. This got much muckier than I thought it would be. I think maybe it's best to go back to the mmu type test, and later on we can fix up both the previously existing test like that, and the new one to something better.
Given that the bits are the same on all processors, why not just use :
env->spr[SPR_LPCR] |= LPCR_PECE_L_MASK;
and
env->spr[SPR_LPCR] &= ~LPCR_PECE_L_MASK;
Thanks,
C.
Quoted 90 lines
Quoted 89 lines
Quoted 10 lines
hw/ppc/spapr_rtas.c static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr, · line 189
Quoted 9 lines
hw/ppc/spapr_rtas.c +6
-0+ env->spr[SPR_LPCR ] |=LPCR_DEE ; + }else { +/* P7 and P8 both have same bit for DECR */ + env->spr[SPR_LPCR ] |=LPCR_P8_PECE3 ; + } + env->nip = start; env->gpr[3 ] = r3; cs->halted =0 ;Quoted 4 lines
The other option I'm wondering about here is to actually add a "shutdown" (or something) method to the cpu class, which does whatever is necessary to put the vcpu into a quiescent state that won't be woken up unless it's specifically requested.
yes. That is a good idea.
Thanks,
C.
Quoted 66 lines
Quoted 30 lines
hw/ppc/spapr_rtas.c +10
-0@@ -210,6 +220,16 @@ static void rtas_stop_self(PowerPCCPU *cpu, sPAPRMachineState *spapr,* no need to bother with specific bits, we just clear it. */ env->msr =0 ; + +/* Don't let the decremeter run on a CPU being stopped. This could +* deliver an interrupt on a dying CPU and crash the guest. +*/ +if (ppc_cpu_pvr_match (cpu,CPU_POWERPC_LOGICAL_3_00 )) { + env->spr[SPR_LPCR ] &= ~LPCR_DEE ; + }else { +/* P7 and P8 both have same bit for DECR */ + env->spr[SPR_LPCR ] &= ~LPCR_P8_PECE3 ; + } } static inline int sysparm_st(target_ulong addr, target_ulong len,target/ppc/translate_init.c +1
-0@@ -8905,6 +8905,7 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp)CPUPPCState *env = &cpu->env;ppc_spr_t *lpcr = &env->spr_cb[SPR_LPCR ];ppc_spr_t *amor = &env->spr_cb[SPR_AMOR ]; +CPUState *cs =CPU (cpu); cpu->vhyp = vhyp;target/ppc/translate_init.c void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) · line 8951
Quoted 6 lines
target/ppc/translate_init.c +1
-1@@ -8946,8 +8947,15 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) }else { lpcr->default_value &= ~(LPCR_UPRT |LPCR_GTSE ); } - lpcr->default_value |=LPCR_PDEE |LPCR_HDEE |LPCR_EEE |LPCR_DEE | + lpcr->default_value |=LPCR_PDEE |LPCR_HDEE |LPCR_EEE |LPCR_OEE ;But I guess we'd also need a "
set_papr" method to go with that.Quoted 26 lines
target/ppc/translate_init.c +15
-1+ +/* Only let the decremeter wake up the boot CPU. The RTAS +* command start-cpu will enable it on secondaries. +*/ +if (cs == first_cpu) { + lpcr->default_value |=LPCR_DEE ; + }break ;default :/* P7 and P8 has slightly different PECE bits, mostly because P8 adds @@ -8955,7 +8963,14 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp)* will work as expected for both implementations */ lpcr->default_value |=LPCR_P8_PECE0 |LPCR_P8_PECE1 |LPCR_P8_PECE2 | -LPCR_P8_PECE3 |LPCR_P8_PECE4 ; +LPCR_P8_PECE4 ; + +/* Only let the decremeter wake up the boot CPU. The RTAS +* command start-cpu will enable it on secondaries. +*/ +if (cs == first_cpu) { + lpcr->default_value |=LPCR_P8_PECE3 ; + } }/* We should be followed by a CPU reset but update the active value
Re: [Qemu-devel] [PATCH v2 2/4] spapr/rtas: disable the decrementer interrupt when a CPU is unplugged
Quoted 71 lines · Cédric Le Goater
Quoted 70 lines · David Gibson
Quoted 58 lines · Cédric Le Goater
Quoted 46 lines · David Gibson
Quoted 45 lines · Cédric Le Goater
When a CPU is stopped with the 'stop-self' RTAS call, its state 'halted' is switched to 1 and, in this case, the MSR is not taken into account anymore in the
cpu_has_work()routine. Only the pending hardware interrupts are checked with their LPCR:PECE* enablement bit.If the DECR timer fires after 'stop-self' is called and before the CPU 'stop' state is reached, the nearly-dead CPU will have some work to do and the guest will crash. This case happens very frequently with the not yet upstream P9 XIVE exploitation mode. In XICS mode, the DECR is occasionally fired but after 'stop' state, so no work is to be done and the guest survives.
I suspect there is a race between the QEMU mainloop triggering the timers and the TCG CPU thread but I could not quite identify the root cause. To be safe, let's disable the decrementer interrupt in the LPCR when the CPU is halted and reenable it when the CPU is restarted.
Signed-off-by Cédric Le Goater <[email protected]>---
Changes in v2:
- used a new routine
ppc_cpu_pvr_match()to discriminate CPU versions
- removed the LPCR:PECE* enablement bit when the CPU is initialized if it is a secondaryhw/ppc/spapr_rtas.c | 20 ++++++++++++++++++++ target/ppc/translate_init.c | 19 +++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-)hw/ppc/spapr_rtas.c +1
-0@@ -46,6 +46,7 @@#include "qemu/cutils.h" #include "trace.h" #include "hw/ppc/fdt.h" +#include "target/ppc/cpu-models.h" static void rtas_display_character(PowerPCCPU *cpu, sPAPRMachineState *spapr, uint32_t token, uint32_t nargs,@@ -174,6 +175,15 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr,kvm_cpu_synchronize_state (cs);Quoted 10 lines
hw/ppc/spapr_rtas.c static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr, · line 180
Quoted 4 lines
hw/ppc/spapr_rtas.c +3
-0env->msr = (1ULL <<MSR_SF ) | (1ULL <<MSR_ME ); + +/* Enable DECR interrupt */ +if (ppc_cpu_pvr_match (cpu,CPU_POWERPC_LOGICAL_3_00 )) {Sorry, I didn't reply to your earlier mail in time. Going via the PVR in this way seems bonkers to me - I like it even less than checking the mmu type. After all, classifying a bunch of precise models (PVRs) together by behaviour is kind of exactly what the CPU classes are for, so using
object_dynamic_case()(==instance_of) is a better idea here.Quoted 3 lines
hmm, and which type should I use ? we don't have any TYPE_POWER9* we could use for a
object_dynamic_cast(). I don't think so ? I could use the name andstrcmp("power9")probably but it looks ugly.Actually there is, but, yeah, it's a lot less obvious than I thought. It's constructed by the
POWERPC_FAILYmacro and will be "POWER9-family-powerpc64-cpu"Quoted 3 lines
The only thing we have is "
CPU_POWERPC_POWER9_BASE" and it only applicates to PVR.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
May be I don't understand your idea.
Urgh, sorry. This got much muckier than I thought it would be. I think maybe it's best to go back to the mmu type test, and later on we can fix up both the previously existing test like that, and the new one to something better.
Given that the bits are the same on all processors, why not just use :
grummf, P7 reserves bits 47 and 48.
C.
Quoted 102 lines
env->spr[SPR_LPCR] |= LPCR_PECE_L_MASK;and
env->spr[SPR_LPCR] &= ~LPCR_PECE_L_MASK;Thanks,
C.
Quoted 90 lines
Quoted 89 lines
Quoted 10 lines
hw/ppc/spapr_rtas.c static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr, · line 189
Quoted 9 lines
hw/ppc/spapr_rtas.c +6
-0+ env->spr[SPR_LPCR ] |=LPCR_DEE ; + }else { +/* P7 and P8 both have same bit for DECR */ + env->spr[SPR_LPCR ] |=LPCR_P8_PECE3 ; + } + env->nip = start; env->gpr[3 ] = r3; cs->halted =0 ;Quoted 4 lines
The other option I'm wondering about here is to actually add a "shutdown" (or something) method to the cpu class, which does whatever is necessary to put the vcpu into a quiescent state that won't be woken up unless it's specifically requested.
yes. That is a good idea.
Thanks,
C.
Quoted 66 lines
Quoted 30 lines
hw/ppc/spapr_rtas.c +10
-0@@ -210,6 +220,16 @@ static void rtas_stop_self(PowerPCCPU *cpu, sPAPRMachineState *spapr,* no need to bother with specific bits, we just clear it. */ env->msr =0 ; + +/* Don't let the decremeter run on a CPU being stopped. This could +* deliver an interrupt on a dying CPU and crash the guest. +*/ +if (ppc_cpu_pvr_match (cpu,CPU_POWERPC_LOGICAL_3_00 )) { + env->spr[SPR_LPCR ] &= ~LPCR_DEE ; + }else { +/* P7 and P8 both have same bit for DECR */ + env->spr[SPR_LPCR ] &= ~LPCR_P8_PECE3 ; + } } static inline int sysparm_st(target_ulong addr, target_ulong len,target/ppc/translate_init.c +1
-0@@ -8905,6 +8905,7 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp)CPUPPCState *env = &cpu->env;ppc_spr_t *lpcr = &env->spr_cb[SPR_LPCR ];ppc_spr_t *amor = &env->spr_cb[SPR_AMOR ]; +CPUState *cs =CPU (cpu); cpu->vhyp = vhyp;target/ppc/translate_init.c void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) · line 8951
Quoted 6 lines
target/ppc/translate_init.c +1
-1@@ -8946,8 +8947,15 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) }else { lpcr->default_value &= ~(LPCR_UPRT |LPCR_GTSE ); } - lpcr->default_value |=LPCR_PDEE |LPCR_HDEE |LPCR_EEE |LPCR_DEE | + lpcr->default_value |=LPCR_PDEE |LPCR_HDEE |LPCR_EEE |LPCR_OEE ;But I guess we'd also need a "
set_papr" method to go with that.Quoted 26 lines
target/ppc/translate_init.c +15
-1+ +/* Only let the decremeter wake up the boot CPU. The RTAS +* command start-cpu will enable it on secondaries. +*/ +if (cs == first_cpu) { + lpcr->default_value |=LPCR_DEE ; + }break ;default :/* P7 and P8 has slightly different PECE bits, mostly because P8 adds @@ -8955,7 +8963,14 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp)* will work as expected for both implementations */ lpcr->default_value |=LPCR_P8_PECE0 |LPCR_P8_PECE1 |LPCR_P8_PECE2 | -LPCR_P8_PECE3 |LPCR_P8_PECE4 ; +LPCR_P8_PECE4 ; + +/* Only let the decremeter wake up the boot CPU. The RTAS +* command start-cpu will enable it on secondaries. +*/ +if (cs == first_cpu) { + lpcr->default_value |=LPCR_P8_PECE3 ; + } }/* We should be followed by a CPU reset but update the active value
PATCH v2 3/4 spapr/rtas: fix reboot of a SMP TCG guest
In reply to Cédric Le GoaterJust like for hot unplugged CPUs, when a guest is rebooted, the secondary CPUs can be awaken by the decrementer and start entering SLOF at the same time the boot CPU is.
To be safe, let's disable the decrementer interrupt in the LPCR for the secondaries.
Based on previous work from Nikunj A Dadhania <[email protected]>
--- hw/ppc/spapr_cpu_core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
hw/ppc/spapr_cpu_core.c +12 -0
@@ -20,6 +20,7 @@#include "sysemu/numa.h" #include "sysemu/hw_accel.h" #include "qemu/error-report.h" +#include "target/ppc/cpu-models.h" void spapr_cpu_parse_features (sPAPRMachineState *spapr) {
@@ -86,6 +87,17 @@ static void spapr_cpu_reset(void *opaque) cs->halted =1 ; env->spr[SPR_HIOR ] =0 ; + +/* Don't let the decremeter wake up CPUs other than the boot +* CPUs. this can cause issues when rebooting the guest */ +if (cs != first_cpu) { +if (ppc_cpu_pvr_match (cpu,CPU_POWERPC_LOGICAL_3_00 )) { + env->spr[SPR_LPCR ] &= ~LPCR_DEE ; + }else { +/* P7 and P8 both have same bit for DECR */ + env->spr[SPR_LPCR ] &= ~LPCR_P8_PECE3 ; + } + } }static void spapr_cpu_destroy (PowerPCCPU *cpu)
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v2 3/4] spapr/rtas: fix reboot of a SMP TCG guest
Quoted 10 lines · Cédric Le Goater
Just like for hot unplugged CPUs, when a guest is rebooted, the secondary CPUs can be awaken by the decrementer and start entering SLOF at the same time the boot CPU is.
To be safe, let's disable the decrementer interrupt in the LPCR for the secondaries.
Based on previous work from Nikunj A Dadhania <[email protected]>
Signed-off-by Cédric Le Goater <[email protected]>
Quoted 36 lines
--- hw/ppc/spapr_cpu_core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)hw/ppc/spapr_cpu_core.c +12
-0@@ -20,6 +20,7 @@#include "sysemu/numa.h" #include "sysemu/hw_accel.h" #include "qemu/error-report.h" +#include "target/ppc/cpu-models.h" void spapr_cpu_parse_features (sPAPRMachineState *spapr) {@@ -86,6 +87,17 @@ static void spapr_cpu_reset(void *opaque) cs->halted =1 ; env->spr[SPR_HIOR ] =0 ; + +/* Don't let the decremeter wake up CPUs other than the boot +* CPUs. this can cause issues when rebooting the guest */ +if (cs != first_cpu) { +if (ppc_cpu_pvr_match (cpu,CPU_POWERPC_LOGICAL_3_00 )) { + env->spr[SPR_LPCR ] &= ~LPCR_DEE ; + }else { +/* P7 and P8 both have same bit for DECR */ + env->spr[SPR_LPCR ] &= ~LPCR_P8_PECE3 ; + } + } }static void spapr_cpu_destroy (PowerPCCPU *cpu)Signature · 1 line
2.13.6
PATCH v2 4/4 spapr/rtas: do not reset the MSR in stop-self command
In reply to Cédric Le GoaterWhen a CPU is stopped with the 'stop-self' RTAS call, its state 'halted' is switched to 1 and, in this case, the MSR is not taken into account anymore in the cpu_has_work() routine. Only the pending hardware interrupts are checked with their LPCR:PECE* enablement bit.
The CPU is now also protected from the decrementer interrupt by the LPCR:PECE* bits which are disabled in the 'stop-self' RTAS call. Reseting the MSR is pointless.
--- hw/ppc/spapr_rtas.c | 10 ---------- 1 file changed, 10 deletions(-)
hw/ppc/spapr_rtas.c +0 -10
@@ -210,16 +210,6 @@ static void rtas_stop_self(PowerPCCPU *cpu, sPAPRMachineState *spapr, cs->halted =1 ;qemu_cpu_kick (cs); -/* -* While stopping a CPU, the guest calls H_CPPR which -* effectively disables interrupts on XICS level. -* However decrementer interrupts in TCG can still -* wake the CPU up so here we disable interrupts in MSR -* as well. -* As rtas_start_cpu() resets the whole MSR anyway, there is -* no need to bother with specific bits, we just clear it. -*/ - env->msr =0 ;/* Don't let the decremeter run on a CPU being stopped. This could * deliver an interrupt on a dying CPU and crash the guest.
Signature · 1 line
2.13.6