disable the decrementer interrupt when a CPU is unplugged
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.
Cédric Le Goater (2):
spapr/rtas: disable the decrementer interrupt when a CPU is unplugged spapr/rtas: do not reset the MSR in stop-self command
hw/ppc/spapr_rtas.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
Signature · 1 line
2.13.6
PATCH 1/2 spapr/rtas: disable the decrementer interrupt when a CPU is unplugged
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.
--- hw/ppc/spapr_rtas.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
hw/ppc/spapr_rtas.c +16 -0
@@ -174,6 +174,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 (env->mmu_model ==POWERPC_MMU_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 +219,13 @@ static void rtas_stop_self(PowerPCCPU *cpu, sPAPRMachineState *spapr,* no need to bother with specific bits, we just clear it. */ env->msr =0 ; + +if (env->mmu_model ==POWERPC_MMU_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,
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH 1/2] spapr/rtas: disable the decrementer interrupt when a CPU is unplugged
Quoted 27 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]>--- hw/ppc/spapr_rtas.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)hw/ppc/spapr_rtas.c +0
-0
hw/ppc/spapr_rtas.c static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr, · line 179
Quoted 6 lines
hw/ppc/spapr_rtas.c +3
-0@@ -174,6 +174,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 (env->mmu_model ==POWERPC_MMU_3_00 ) {
Hm. Checking mmu_model doesn't seem right to me. I mean, it'll get the right answer in practice, but the LPCR programming has nothing whatsoever to do with the MMU.
I think explicitly checking if cpu_ is a POWER9 instance with object_dynamic_cast would be a better option.
Quoted 23 lines
hw/ppc/spapr_rtas.c +13
-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 ;@@ -210,6 +219,13 @@ static void rtas_stop_self(PowerPCCPU *cpu, sPAPRMachineState *spapr,* no need to bother with specific bits, we just clear it. */ env->msr =0 ; + +if (env->mmu_model ==POWERPC_MMU_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,
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 1/2] spapr/rtas: disable the decrementer interrupt when a CPU is unplugged
Quoted 6 lines · David Gibson
Hm. Checking
mmu_modeldoesn't seem right to me. I mean, it'll get the right answer in practice, but the LPCR programming has nothing whatsoever to do with the MMU.I think explicitly checking if
cpu_is a POWER9 instance withobject_dynamic_castwould be a better option.
Best is ARCH 300 ... do we hvae arch versions outside of MMU model these days ?
Ben.
Re: [Qemu-devel] [PATCH 1/2] spapr/rtas: disable the decrementer interrupt when a CPU is unplugged
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 6 lines · David Gibson
Hm. Checking
mmu_modeldoesn't seem right to me. I mean, it'll get the right answer in practice, but the LPCR programming has nothing whatsoever to do with the MMU.I think explicitly checking if
cpu_is a POWER9 instance withobject_dynamic_castwould be a better option.Best is ARCH 300 ... do we hvae arch versions outside of MMU model these days ?
Not that I could spot easily. Apart from implicitly in the cpu family.
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 1/2] spapr/rtas: disable the decrementer interrupt when a CPU is unplugged
Quoted 6 lines · David Gibson
Quoted 5 lines · Benjamin Herrenschmidt
Quoted 4 lines · David Gibson
Hm. Checking
mmu_modeldoesn't seem right to me. I mean, it'll get the right answer in practice, but the LPCR programming has nothing whatsoever to do with the MMU.
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
I think explicitly checking if
cpu_is a POWER9 instance withobject_dynamic_castwould be a better option.Best is ARCH 300 ... do we hvae arch versions outside of MMU model these days ?
Not that I could spot easily. Apart from implicitly in the cpu family.
how about :
pcc->pvr_match(pcc, CPU_POWERPC_LOGICAL_3_00);
C.
Re: [Qemu-devel] [PATCH 1/2] spapr/rtas: disable the decrementer interrupt when a CPU is unplugged
In reply to David GibsonQuoted 39 lines · David Gibson
Quoted 27 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]>--- hw/ppc/spapr_rtas.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)hw/ppc/spapr_rtas.c +0
-0hw/ppc/spapr_rtas.c static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr, · line 179
Quoted 6 lines
hw/ppc/spapr_rtas.c +3
-0@@ -174,6 +174,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 (env->mmu_model ==POWERPC_MMU_3_00 ) {Hm. Checking
mmu_modeldoesn't seem right to me. I mean, it'll get the right answer in practice, but the LPCR programming has nothing whatsoever to do with the MMU.
Quoted 2 lines
I think explicitly checking if
cpu_is a POWER9 instance withobject_dynamic_castwould be a better option.
OK. So I guess we should change the switch statement in cpu_ppc_set_papr() also.
C.
Quoted 25 lines
Quoted 24 lines
hw/ppc/spapr_rtas.c +13
-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 ;@@ -210,6 +219,13 @@ static void rtas_stop_self(PowerPCCPU *cpu, sPAPRMachineState *spapr,* no need to bother with specific bits, we just clear it. */ env->msr =0 ; + +if (env->mmu_model ==POWERPC_MMU_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,
Re: [Qemu-devel] [PATCH 1/2] spapr/rtas: disable the decrementer interrupt when a CPU is unplugged
Quoted 40 lines · Cédric Le Goater
Quoted 39 lines · David Gibson
Quoted 27 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]>--- hw/ppc/spapr_rtas.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)hw/ppc/spapr_rtas.c +0
-0hw/ppc/spapr_rtas.c static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr, · line 179
Quoted 6 lines
hw/ppc/spapr_rtas.c +3
-0@@ -174,6 +174,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 (env->mmu_model ==POWERPC_MMU_3_00 ) {Hm. Checking
mmu_modeldoesn't seem right to me. I mean, it'll get the right answer in practice, but the LPCR programming has nothing whatsoever to do with the MMU.
Quoted 5 lines
Quoted 2 lines
I think explicitly checking if
cpu_is a POWER9 instance withobject_dynamic_castwould be a better option.OK. So I guess we should change the switch statement in
cpu_ppc_set_papr()also.
Yeah, I guess so. No rush.
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 2/2 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
@@ -209,16 +209,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 ;if (env->mmu_model ==POWERPC_MMU_3_00 ) { env->spr[SPR_LPCR ] &= ~LPCR_DEE ;
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH 2/2] spapr/rtas: do not reset the MSR in stop-self command
Quoted 10 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.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.
Signed-off-by Cédric Le Goater <[email protected]>
Quoted 25 lines
--- hw/ppc/spapr_rtas.c | 10 ---------- 1 file changed, 10 deletions(-)hw/ppc/spapr_rtas.c +0
-10@@ -209,16 +209,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 ;if (env->mmu_model ==POWERPC_MMU_3_00 ) { env->spr[SPR_LPCR ] &= ~LPCR_DEE ;
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
Quoted 14 lines · Cédric Le Goater
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.
Quoted 4 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.
Moreover, disabling the DECR in the reset path solves the TCG multi cpu reboot case, as reboot path does not call stop-cpu rtas call.
hw/ppc/spapr_cpu_core.c +9 -0
@@ -86,6 +86,15 @@ static void spapr_cpu_reset(void *opaque) cs->halted =1 ; env->spr[SPR_HIOR ] =0 ; +/* Disable DECR for secondary cpus */ +if (cs != first_cpu) { +if (env->mmu_model ==POWERPC_MMU_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)
Regards
Nikunj
Quoted 16 lines · Nikunj A Dadhania
Quoted 14 lines · Cédric Le Goater
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.
Quoted 7 lines
Quoted 4 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.
Moreover, disabling the DECR in the reset path solves the TCG multi cpu reboot case, as reboot path does not call stop-cpu rtas call.
yes. I was going to restart the thread on the topic.
Let's how these two little patches are discussed. Then we/you can resend the missing hunk in reset which is needed to perform a TCG reboot.
Thanks,
C.
Quoted 25 lines
hw/ppc/spapr_cpu_core.c +9
-0@@ -86,6 +86,15 @@ static void spapr_cpu_reset(void *opaque) cs->halted =1 ; env->spr[SPR_HIOR ] =0 ; +/* Disable DECR for secondary cpus */ +if (cs != first_cpu) { +if (env->mmu_model ==POWERPC_MMU_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)Regards
Nikunj
Quoted 16 lines · Nikunj A Dadhania
Quoted 14 lines · Cédric Le Goater
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.
Quoted 7 lines
Quoted 4 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.
Moreover, disabling the DECR in the reset path solves the TCG multi cpu reboot case, as reboot path does not call stop-cpu rtas call.
SHouldn't we do it in set_papr too and only turn it on for the boot CPU and in start-cpu RTAS call ? Same with the other PECEs in fact...
Quoted 24 lines
hw/ppc/spapr_cpu_core.c +9
-0@@ -86,6 +86,15 @@ static void spapr_cpu_reset(void *opaque) cs->halted =1 ; env->spr[SPR_HIOR ] =0 ; +/* Disable DECR for secondary cpus */ +if (cs != first_cpu) { +if (env->mmu_model ==POWERPC_MMU_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)Regards
Nikunj
Quoted 22 lines · Benjamin Herrenschmidt
Quoted 21 lines · Nikunj A Dadhania
Quoted 18 lines · Cédric Le Goater
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.
Quoted 5 lines
Quoted 2 lines
Moreover, disabling the DECR in the reset path solves the TCG multi cpu reboot case, as reboot path does not call stop-cpu rtas call.
SHouldn't we do it in
set_paprtoo and only turn it on for the boot CPU and in start-cpu RTAS call ? Same with the other PECEs in fact...
yes I agree.
In cpu_ppc_set_papr(), we should set the PECE* bits only for the boot CPU and then let the RTAS calls start-cpu and stop-self do the enablement and disablement.
I will respin the patchset.
C.
Quoted 24 lines
Quoted 24 lines
hw/ppc/spapr_cpu_core.c +9
-0@@ -86,6 +86,15 @@ static void spapr_cpu_reset(void *opaque) cs->halted =1 ; env->spr[SPR_HIOR ] =0 ; +/* Disable DECR for secondary cpus */ +if (cs != first_cpu) { +if (env->mmu_model ==POWERPC_MMU_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)Regards
Nikunj
Quoted 22 lines · Benjamin Herrenschmidt
Quoted 21 lines · Nikunj A Dadhania
Quoted 18 lines · Cédric Le Goater
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.
Quoted 5 lines
Quoted 2 lines
Moreover, disabling the DECR in the reset path solves the TCG multi cpu reboot case, as reboot path does not call stop-cpu rtas call.
SHouldn't we do it in
set_paprtoo and only turn it on for the boot CPU and in start-cpu RTAS call ? Same with the other PECEs in fact...
Yes, +1 for that
Regards
Nikunj
Quoted 32 lines · Nikunj A Dadhania
Quoted 14 lines · Cédric Le Goater
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.
Quoted 4 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.
Moreover, disabling the DECR in the reset path solves the TCG multi cpu reboot case, as reboot path does not call stop-cpu rtas call.
hw/ppc/spapr_cpu_core.c +0
-0@@ -86,6 +86,15 @@ static void spapr_cpu_reset(void *opaque) cs->halted =1 ; env->spr[SPR_HIOR ] =0 ;
hw/ppc/spapr_cpu_core.c static void spapr_cpu_reset(void *opaque) · line 98
Quoted 10 lines
hw/ppc/spapr_cpu_core.c +9
-0+/* Disable DECR for secondary cpus */ +if (cs != first_cpu) { +if (env->mmu_model ==POWERPC_MMU_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 ; + } + } }
This seems reasonable.
Quoted 7 lines
hw/ppc/spapr_cpu_core.c +0
-0static void spapr_cpu_destroy (PowerPCCPU *cpu)Regards
Nikunj
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