ppc: various fixes for 9.2
cover ppc: various fixes for 9.2
Some small last-minute fixes that mostly fix recently added or exposed issues. I'd like to send a PR with them for 9.2 in the next couple of days unless there are objections.
Thanks,
Nick
Glenn Miles (1):
target/ppc: Fix THREAD_SIBLING_FOREACH for mult-socket
Nicholas Piggin (3):
target/ppc: Fix non-maskable interrupt while halted ppc/pnv: Fix direct controls quiesce
ppc/pnv: Add xscom- prefix to pervasive-control region name
target/ppc/cpu.h | 8 ++++++-- hw/ppc/pnv_core.c | 11 +++++++++-- hw/ppc/pnv_nest_pervasive.c | 2 +- hw/ppc/spapr_cpu_core.c | 1 + target/ppc/excp_helper.c | 7 +++++++ 5 files changed, 24 insertions(+), 5 deletions(-)
Signature · 1 line
2.45.2
PATCH 1/4 target/ppc: Fix non-maskable interrupt while halted
The ppc (pnv and spapr) NMI injection code does not go through the asynchronous interrupt path and set a bit in env->pending_interrupts and raise an interrupt request that the cpu_exec() loop can see. Instead it injects the exception directly into registers.
This can lead to cpu_exec() missing that the thread has work to do, if a NMI is injected while it was idle.
Fix this by clearing halted when injecting the interrupt. Probably NMI injection should be reworked to use the interrupt request interface, but this seems to work as a minimal fix.
--- target/ppc/excp_helper.c | 7 +++++++ 1 file changed, 7 insertions(+)
target/ppc/excp_helper.c +7 -0
@@ -2495,10 +2495,16 @@ static void ppc_deliver_interrupt(CPUPPCState *env, int interrupt) } } +/* +* system reset is not delivered via normal irq method, so have to set +* halted = 0 to resume CPU running if it was halted. Possibly we should +* move it over to using PPC_INTERRUPT_RESET rather than async_run_on_cpu. +*/ void ppc_cpu_do_system_reset (CPUState *cs) {PowerPCCPU *cpu =POWERPC_CPU (cs); + cs->halted =0 ;powerpc_excp (cpu,POWERPC_EXCP_RESET ); }
@@ -2520,6 +2526,7 @@ void ppc_cpu_do_fwnmi_machine_check(CPUState *cs, target_ulong vector)/* Anything for nested required here? MSR[HV] bit? */ + cs->halted =0 ;powerpc_set_excp_state (cpu, vector, msr); }
Signature · 1 line
2.45.2
Re: [PATCH 1/4] target/ppc: Fix non-maskable interrupt while halted
Quoted 53 lines · Nicholas Piggin
The ppc (pnv and spapr) NMI injection code does not go through the asynchronous interrupt path and set a bit in
env->pending_interruptsand raise an interrupt request that thecpu_exec()loop can see. Instead it injects the exception directly into registers.This can lead to
cpu_exec()missing that the thread has work to do, if a NMI is injected while it was idle.Fix this by clearing halted when injecting the interrupt. Probably NMI injection should be reworked to use the interrupt request interface,
but this seems to work as a minimal fix.Fixes 3431648272d3 ("spapr: Add support for new NMI interface")Signed-off-by Nicholas Piggin <[email protected]>--- target/ppc/excp_helper.c | 7 +++++++ 1 file changed, 7 insertions(+)target/ppc/excp_helper.c +2
-0@@ -2495,10 +2495,16 @@ static void ppc_deliver_interrupt(CPUPPCState *env, int interrupt) } } +/* +* system reset is not delivered via normal irq method, so have to set
+ * halted = 0 to resume CPU running if it was halted. Possibly we should
+ * move it over to usingPPC_INTERRUPT_RESETrather thanasync_run_on_cpu.
+ */
voidppc_cpu_do_system_reset(CPUState *cs){ PowerPCCPU *cpu = POWERPC_CPU(cs);target/ppc/excp_helper.c +2
-0+ cs->halted =0 ;powerpc_excp (cpu,POWERPC_EXCP_RESET ); }@@ -2520,6 +2526,7 @@ void ppc_cpu_do_fwnmi_machine_check(CPUState *cs, target_ulong vector)/* Anything for nested required here? MSR[HV] bit? */ + cs->halted =0 ;powerpc_set_excp_state (cpu, vector, msr); }
PATCH 2/4 ppc/pnv: Fix direct controls quiesce
In reply to Nicholas Pigginpowernv CPUs have a set of control registers that can stop, start, and do other things to control a thread's execution.
Using this interface to stop a thread puts it into a particular state that can be queried, and is distinguishable from other things that might stop the CPU (e.g., going idle, or being debugged via gdb, or stopped by the monitor).
Add a new flag that can speficially distinguish this state where it is stopped with control registers. This solves some hangs when rebooting powernv machines when skiboot is modified to allow QEMU to use the CPU control facility (that uses controls to bring all secondaries to a known state).
There might still be a bigger issue with how we handle CPU stop requests. Multiple different sources may want to stop a CPU, there may be situations where one of them resumes a CPU before all agree? A stop_request mask or refcount might be a nice way to consolidate all these.
--- target/ppc/cpu.h | 1 + hw/ppc/pnv_core.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-)
target/ppc/cpu.h +1 -0
@@ -1355,6 +1355,7 @@ struct CPUArchState {* special way (such as routing some resume causes to 0x100, i.e. sreset). */ bool resume_as_sreset; +bool quiesced;#endif /* These resources are used only in TCG */
hw/ppc/pnv_core.c +7 -2
@@ -217,8 +217,8 @@ static uint64_t pnv_core_power10_xscom_read(void *opaque, hwaddr addr,case PNV10_XSCOM_EC_CORE_RAS_STATUS :for (i =0 ; i < nr_threads; i++) {PowerPCCPU *cpu = pc->threads[i]; -CPUState *cs =CPU (cpu); -if (cs->stopped) { +CPUPPCState *env = &cpu->env; +if (env->quiesced) { val |=PPC_BIT (0 +8 * i) |PPC_BIT (1 +8 * i); } }
@@ -244,20 +244,25 @@ static void pnv_core_power10_xscom_write(void *opaque, hwaddr addr,for (i =0 ; i < nr_threads; i++) {PowerPCCPU *cpu = pc->threads[i];CPUState *cs =CPU (cpu); +CPUPPCState *env = &cpu->env;if (val &PPC_BIT (7 +8 * i)) {/* stop */ val &= ~PPC_BIT (7 +8 * i);cpu_pause (cs); + env->quiesced = true; }if (val &PPC_BIT (6 +8 * i)) {/* start */ val &= ~PPC_BIT (6 +8 * i); + env->quiesced = false;cpu_resume (cs); }if (val &PPC_BIT (4 +8 * i)) {/* sreset */ val &= ~PPC_BIT (4 +8 * i); + env->quiesced = false;pnv_cpu_do_nmi_resume (cs); }if (val &PPC_BIT (3 +8 * i)) {/* clear maint */ + env->quiesced = false;/* * Hardware has very particular cases for where clear maint * must be used and where start must be used to resume a
Signature · 1 line
2.45.2
Re: [PATCH 2/4] ppc/pnv: Fix direct controls quiesce
Quoted 87 lines · Nicholas Piggin
powernv CPUs have a set of control registers that can stop, start, and
do other things to control a thread's execution.Using this interface to stop a thread puts it into a particular state that can be queried, and is distinguishable from other things that might stop the CPU (e.g., going idle, or being debugged via gdb, or stopped by the monitor).
Add a new flag that can speficially distinguish this state where it is stopped with control registers. This solves some hangs when rebooting powernv machines when skiboot is modified to allow QEMU to use the CPU control facility (that uses controls to bring all secondaries to a known state).
Fixes c8891955086 ("ppc/pnv: Implement POWER10 PC xscom registersfor direct controls")
Signed-off-by Nicholas Piggin <[email protected]>There might still be a bigger issue with how we handle CPU stop requests. Multiple different sources may want to stop a CPU, there may be situations where one of them resumes a CPU before all agree? A
stop_requestmask or refcount might be a nice way to consolidate all these.--- target/ppc/cpu.h | 1 + hw/ppc/pnv_core.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-)target/ppc/cpu.h +0
-0@@ -1355,6 +1355,7 @@ struct CPUArchState {* special way (such as routing some resume causes to 0x100, i.e. sreset).
*/ bool resume_as_sreset;target/ppc/cpu.h +1
-0+bool quiesced;#endif /* These resources are used only in TCG */ hw/ppc/pnv_core.c +2
-2@@ -217,8 +217,8 @@ static uint64_t pnv_core_power10_xscom_read(void *opaque, hwaddr addr, case PNV10_XSCOM_EC_CORE_RAS_STATUS:for (i =0 ; i < nr_threads; i++) {PowerPCCPU *cpu = pc->threads[i]; -CPUState *cs =CPU (cpu); -if (cs->stopped) { +CPUPPCState *env = &cpu->env; +if (env->quiesced) { val |=PPC_BIT (0 +8 * i) |PPC_BIT (1 +8 * i); }}hw/ppc/pnv_core.c +5
-0@@ -244,20 +244,25 @@ static void pnv_core_power10_xscom_write(void *opaque, hwaddr addr, for (i = 0; i < nr_threads; i++) {PowerPCCPU *cpu = pc->threads[i];CPUState *cs =CPU (cpu); +CPUPPCState *env = &cpu->env;if (val &PPC_BIT (7 +8 * i)) {/* stop */ val &= ~PPC_BIT (7 +8 * i);cpu_pause (cs); + env->quiesced = true; }if (val &PPC_BIT (6 +8 * i)) {/* start */ val &= ~PPC_BIT (6 +8 * i); + env->quiesced = false;cpu_resume (cs); }if (val &PPC_BIT (4 +8 * i)) {/* sreset */ val &= ~PPC_BIT (4 +8 * i); + env->quiesced = false;pnv_cpu_do_nmi_resume (cs); }if (val &PPC_BIT (3 +8 * i)) {/* clear maint */ + env->quiesced = false;/* * Hardware has very particular cases for where clear maint
* must be used and where start must be used to
resume a
PATCH 3/4 target/ppc: Fix THREAD_SIBLING_FOREACH for mult-socket
In reply to Nicholas PigginFrom: Glenn Miles <[email protected]>
The THREAD_SIBLING_FOREACH macro wasn't excluding threads from other chips. Add chip_index field to the thread state and add a check for the new field in the macro.
--- target/ppc/cpu.h | 7 +++++-- hw/ppc/pnv_core.c | 2 ++ hw/ppc/spapr_cpu_core.c | 1 + 3 files changed, 8 insertions(+), 2 deletions(-)
target/ppc/cpu.h +5 -2
@@ -1253,6 +1253,7 @@ struct CPUArchState {/* For SMT processors */ bool has_smt_siblings;int core_index; +int chip_index;#if !defined(CONFIG_USER_ONLY )/* MMU context, only relevant for full system emulation */
@@ -1412,8 +1413,10 @@ struct CPUArchState {#define THREAD_SIBLING_FOREACH (cs, cs_sibling) \ CPU_FOREACH(cs_sibling) \ - if (POWERPC_CPU(cs)->env.core_index == \ - POWERPC_CPU(cs_sibling)->env.core_index) + if ((POWERPC_CPU(cs)->env.chip_index == \ + POWERPC_CPU(cs_sibling)->env.chip_index) && \ + (POWERPC_CPU(cs)->env.core_index == \ + POWERPC_CPU(cs_sibling)->env.core_index))#define SET_FIT_PERIOD (a_, b_, c_, d_) \ do { \
hw/ppc/pnv_core.c +2 -0
@@ -322,6 +322,8 @@ static void pnv_core_cpu_realize(PnvCore *pc, PowerPCCPU *cpu, Error **errp, pir_spr->default_value = pir; tir_spr->default_value = tir; + env->chip_index = pc->chip->chip_id; +if (pc->big_core) {/* 2 "small cores" get the same core index for SMT operations */ env->core_index = core_hwid >>1 ;
hw/ppc/spapr_cpu_core.c +1 -0
@@ -313,6 +313,7 @@ static PowerPCCPU *spapr_create_vcpu(SpaprCpuCore *sc, int i, Error **errp)return NULL ; } + env->chip_index = sc->node_id; env->core_index = cc->core_id; cpu->node_id = sc->node_id;
Signature · 1 line
2.45.2
Re: [PATCH 3/4] target/ppc: Fix THREAD_SIBLING_FOREACH for mult-socket
Quoted 71 lines · Nicholas Piggin
From: Glenn Miles <[email protected]>
The
THREAD_SIBLING_FOREACHmacro wasn't excluding threads from other chips. Addchip_indexfield to the thread state and add a check for the new field in the macro.Fixes b769d4c8f4c6 ("target/ppc: Add initial flags and helpers forSMT support")
Signed-off-by Glenn Miles <[email protected]>[npiggin: set chip_index for spapr too]Reviewed-by Nicholas Piggin <[email protected]>Signed-off-by Nicholas Piggin <[email protected]>--- target/ppc/cpu.h | 7 +++++-- hw/ppc/pnv_core.c | 2 ++ hw/ppc/spapr_cpu_core.c | 1 + 3 files changed, 8 insertions(+), 2 deletions(-)target/ppc/cpu.h +5
-2@@ -1253,6 +1253,7 @@ struct CPUArchState {/* For SMT processors */ bool has_smt_siblings;int core_index; +int chip_index;#if !defined(CONFIG_USER_ONLY )/* MMU context, only relevant for full system emulation */ @@ -1412,8 +1413,10 @@ struct CPUArchState {#define THREAD_SIBLING_FOREACH (cs, cs_sibling) \ CPU_FOREACH(cs_sibling) \ - if (POWERPC_CPU(cs)->env.core_index == \ - POWERPC_CPU(cs_sibling)->env.core_index) + if ((POWERPC_CPU(cs)->env.chip_index == \ + POWERPC_CPU(cs_sibling)->env.chip_index) && \ + (POWERPC_CPU(cs)->env.core_index == \ + POWERPC_CPU(cs_sibling)->env.core_index))#define SET_FIT_PERIOD (a_, b_, c_, d_) \ do { \hw/ppc/pnv_core.c +2
-0@@ -322,6 +322,8 @@ static void pnv_core_cpu_realize(PnvCore *pc, PowerPCCPU *cpu, Error **errp, pir_spr->default_value = pir; tir_spr->default_value = tir; + env->chip_index = pc->chip->chip_id; +if (pc->big_core) {/* 2 "small cores" get the same core index for SMT operations */
env->core_index = core_hwid >> 1;hw/ppc/spapr_cpu_core.c +1
-0@@ -313,6 +313,7 @@ static PowerPCCPU *spapr_create_vcpu(SpaprCpuCore *sc, int i, Error **errp)return NULL ; } + env->chip_index = sc->node_id; env->core_index = cc->core_id;cpu->node_id = sc->node_id;
PATCH 4/4 ppc/pnv: Add xscom- prefix to pervasive-control region name
In reply to Nicholas PigginBy convention, xscom regions get a xscom- prefix.
--- hw/ppc/pnv_nest_pervasive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/pnv_nest_pervasive.c +1 -1
@@ -177,7 +177,7 @@ static void pnv_nest_pervasive_realize(DeviceState *dev, Error **errp)pnv_xscom_region_init (&nest_pervasive->xscom_ctrl_regs_mr,OBJECT (nest_pervasive), &pnv_nest_pervasive_control_xscom_ops, - nest_pervasive,"pervasive-control" , + nest_pervasive,"xscom-pervasive-control" ,PNV10_XSCOM_CHIPLET_CTRL_REGS_SIZE ); }
Signature · 1 line
2.45.2
Re: [PATCH 4/4] ppc/pnv: Add xscom- prefix to pervasive-control region name
Quoted 24 lines · Nicholas Piggin
By convention, xscom regions get a xscom- prefix.
Fixes 1adf24708bf7 ("hw/ppc: Add pnv nest pervasive common chipletmodel")
Signed-off-by Nicholas Piggin <[email protected]>--- hw/ppc/pnv_nest_pervasive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/ppc/pnv_nest_pervasive.c +1
-1@@ -177,7 +177,7 @@ static void pnv_nest_pervasive_realize(DeviceState *dev, Error **errp)pnv_xscom_region_init (&nest_pervasive->xscom_ctrl_regs_mr,OBJECT (nest_pervasive), &pnv_nest_pervasive_control_xscom_ops, - nest_pervasive,"pervasive-control" , + nest_pervasive,"xscom-pervasive-control" ,PNV10_XSCOM_CHIPLET_CTRL_REGS_SIZE ); }
Re: [PATCH 4/4] ppc/pnv: Add xscom- prefix to pervasive-control region name
In reply to Nicholas PigginHi,
Quoted 13 lines · Nicholas Piggin
By convention, xscom regions get a xscom- prefix.
Fixes 1adf24708bf7 ("hw/ppc: Add pnv nest pervasive common chiplet model")Signed-off-by Nicholas Piggin <[email protected]>--- hw/ppc/pnv_nest_pervasive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/ppc/pnv_nest_pervasive.c +0
-0
hw/ppc/pnv_nest_pervasive.c static void pnv_nest_pervasive_realize(DeviceState *dev, Error **errp) · line 180
Quoted 5 lines
hw/ppc/pnv_nest_pervasive.c +1
-1@@ -177,7 +177,7 @@ static void pnv_nest_pervasive_realize(DeviceState *dev, Error **errp) pnv_xscom_region_init(&nest_pervasive->xscom_ctrl_regs_mr, OBJECT(nest_pervasive), &pnv_nest_pervasive_control_xscom_ops, - nest_pervasive, "pervasive-control", + nest_pervasive, "xscom-pervasive-control",
Could this break migration stream? Or only RAM regions need to have a stable name? I don't remember, but try be be cautions with such cosmetic change just before the release ;)
Quoted 3 lines
hw/ppc/pnv_nest_pervasive.c +0
-0PNV10_XSCOM_CHIPLET_CTRL_REGS_SIZE); }
Re: [PATCH 4/4] ppc/pnv: Add xscom- prefix to pervasive-control region name
Quoted 11 lines · Philippe Mathieu-Daudé
Hi,
Quoted 8 lines · Nicholas Piggin
By convention, xscom regions get a xscom- prefix.
Fixes 1adf24708bf7 ("hw/ppc: Add pnv nest pervasive common chiplet model")Signed-off-by Nicholas Piggin <[email protected]>--- hw/ppc/pnv_nest_pervasive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines
hw/ppc/pnv_nest_pervasive.c static void pnv_nest_pervasive_realize(DeviceState *dev, Error **errp) · line 180
Quoted 10 lines
hw/ppc/pnv_nest_pervasive.c +1
-1@@ -177,7 +177,7 @@ static void pnv_nest_pervasive_realize(DeviceState *dev, Error **errp) pnv_xscom_region_init(&nest_pervasive->xscom_ctrl_regs_mr, OBJECT(nest_pervasive), &pnv_nest_pervasive_control_xscom_ops, - nest_pervasive, "pervasive-control", + nest_pervasive, "xscom-pervasive-control",Could this break migration stream? Or only RAM regions need to have a stable name? I don't remember, but try be be cautions with such cosmetic change just before the release ;)
Hey Phil,
Thanks for always somehow being across everything :)
For the powernv machine we are okay since we don't support migration at all. It's on the wishlist, but at the moment we have lots of hardware models that don't provide vmstate. So I think we are okay.
Thanks,
Nick
Philippe Mathieu-Daudé
Reviewed-byRe: [PATCH 4/4] ppc/pnv: Add xscom- prefix to pervasive-control region name
Quoted 27 lines · Nicholas Piggin
Quoted 11 lines · Philippe Mathieu-Daudé
Hi,
Quoted 8 lines · Nicholas Piggin
By convention, xscom regions get a xscom- prefix.
Fixes 1adf24708bf7 ("hw/ppc: Add pnv nest pervasive common chiplet model")Signed-off-by Nicholas Piggin <[email protected]>--- hw/ppc/pnv_nest_pervasive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 14 lines
hw/ppc/pnv_nest_pervasive.c static void pnv_nest_pervasive_realize(DeviceState *dev, Error **errp) · line 180
Quoted 10 lines
hw/ppc/pnv_nest_pervasive.c +1
-1@@ -177,7 +177,7 @@ static void pnv_nest_pervasive_realize(DeviceState *dev, Error **errp) pnv_xscom_region_init(&nest_pervasive->xscom_ctrl_regs_mr, OBJECT(nest_pervasive), &pnv_nest_pervasive_control_xscom_ops, - nest_pervasive, "pervasive-control", + nest_pervasive, "xscom-pervasive-control",Could this break migration stream? Or only RAM regions need to have a stable name? I don't remember, but try be be cautions with such cosmetic change just before the release ;)
Quoted 3 lines
Hey Phil,
Thanks for always somehow being across everything :)
;)
Answering myself, I/O regions are migrated within the device state, per field, via DeviceClass::vmsd structure.
IIRC RAM regions are the ones tied to their name, which is built using the object owner, which is why we can't change migrated RAM MR owners.
Quoted 3 lines
For the powernv machine we are okay since we don't support migration at all. It's on the wishlist, but at the moment we have lots of hardware models that don't provide vmstate. So I think we are okay.
Re: [PATCH 4/4] ppc/pnv: Add xscom- prefix to pervasive-control region name
Quoted 28 lines · Philippe Mathieu-Daudé
Quoted 27 lines · Nicholas Piggin
Quoted 25 lines · Philippe Mathieu-Daudé
Hi,
Quoted 13 lines · Nicholas Piggin
By convention, xscom regions get a xscom- prefix.
Fixes 1adf24708bf7 ("hw/ppc: Add pnv nest pervasive common chiplet model")Signed-off-by Nicholas Piggin <[email protected]>--- hw/ppc/pnv_nest_pervasive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/ppc/pnv_nest_pervasive.c +0
-0hw/ppc/pnv_nest_pervasive.c static void pnv_nest_pervasive_realize(DeviceState *dev, Error **errp) · line 180
Quoted 5 lines
hw/ppc/pnv_nest_pervasive.c +1
-1@@ -177,7 +177,7 @@ static void pnv_nest_pervasive_realize(DeviceState *dev, Error **errp) pnv_xscom_region_init(&nest_pervasive->xscom_ctrl_regs_mr, OBJECT(nest_pervasive), &pnv_nest_pervasive_control_xscom_ops, - nest_pervasive, "pervasive-control", + nest_pervasive, "xscom-pervasive-control",Could this break migration stream? Or only RAM regions need to have a stable name? I don't remember, but try be be cautions with such cosmetic change just before the release ;)
Quoted 8 lines
Quoted 3 lines
Hey Phil,
Thanks for always somehow being across everything :)
;)
Answering myself, I/O regions are migrated within the device state, per field, via
DeviceClass::vmsdstructure.
IIUC by default we don't migrate IO regions at all, unless we register something into the VMSD explicitly.
Quoted 4 lines
IIRC RAM regions are the ones tied to their name, which is built using the object owner, which is why we can't change migrated RAM MR owners.
True.
Thanks,
Signature · 1 line
Peter Xu