ppc: add machine check injection HMP command
PATCH 1/4 nmi: add MCE class for implementing machine check injection commands
In reply to Nicholas PigginLike commit 9cb805fd26 ("cpus: Define callback for QEMU "nmi" command") this implements a machine check injection command framework and defines a monitor command for ppc.
--- include/hw/nmi.h | 20 ++++++++++++ include/monitor/hmp-target.h | 1 - include/monitor/hmp.h | 1 + hw/core/nmi.c | 61 ++++++++++++++++++++++++++++++++++++ monitor/hmp-cmds.c | 1 + target/ppc/ppc-qmp-cmds.c | 10 ++++++ hmp-commands.hx | 20 +++++++++++- 7 files changed, 112 insertions(+), 2 deletions(-)
include/hw/nmi.h +20 -0
@@ -42,4 +42,24 @@ struct NMIClass {void nmi_monitor_handle (int cpu_index,Error **errp); + +#define TYPE_MCE "mce" + +#define MCE_CLASS (klass) \ + OBJECT_CLASS_CHECK(MCEClass, (klass), TYPE_MCE) +#define MCE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(MCEClass, (obj), TYPE_MCE) +#define MCE (obj) \ + INTERFACE_CHECK(MCEState, (obj), TYPE_MCE) + +typedef struct MCEState MCEState ; + +typedef struct MCEClass { +InterfaceClass parent_class; + +void (*mce_monitor_handler)(MCEState *n,const QDict *qdict,Error **errp); +}MCEClass ; + +void mce_monitor_handle (const QDict *qdict,Error **errp); +#endif /* NMI_H */
include/monitor/hmp-target.h +0 -1
@@ -46,7 +46,6 @@ CPUState *mon_get_cpu(Monitor *mon);void hmp_info_mem (Monitor *mon,const QDict *qdict);void hmp_info_tlb (Monitor *mon,const QDict *qdict); -void hmp_mce (Monitor *mon,const QDict *qdict);void hmp_info_local_apic (Monitor *mon,const QDict *qdict);void hmp_info_sev (Monitor *mon,const QDict *qdict);void hmp_info_sgx (Monitor *mon,const QDict *qdict);
include/monitor/hmp.h +1 -0
@@ -56,6 +56,7 @@ void hmp_ringbuf_read(Monitor *mon, const QDict *qdict);void hmp_cont (Monitor *mon,const QDict *qdict);void hmp_system_wakeup (Monitor *mon,const QDict *qdict);void hmp_nmi (Monitor *mon,const QDict *qdict); +void hmp_mce (Monitor *mon,const QDict *qdict);void hmp_info_network (Monitor *mon,const QDict *qdict);void hmp_set_link (Monitor *mon,const QDict *qdict);void hmp_balloon (Monitor *mon,const QDict *qdict);
hw/core/nmi.c +61 -0
64 lines not on this page · raw message
monitor/hmp-cmds.c +1 -0
@@ -28,6 +28,7 @@#include "hw/intc/intc.h" #include "qemu/log.h" #include "sysemu/sysemu.h" +#include "hw/nmi.h" bool hmp_handle_error (Monitor *mon,Error *err) {
target/ppc/ppc-qmp-cmds.c +10 -0
@@ -31,6 +31,7 @@#include "qapi/qapi-commands-machine-target.h" #include "cpu-models.h" #include "cpu-qom.h" +#include "hw/nmi.h" static target_long monitor_get_ccr (Monitor *mon,const struct MonitorDef *md,int val)
@@ -91,6 +92,15 @@ void hmp_info_tlb(Monitor *mon, const QDict *qdict)dump_mmu (env1); } +void hmp_mce (Monitor *mon,const QDict *qdict) +{ +Error *err =NULL ; + +mce_monitor_handle (qdict, &err); + +hmp_handle_error (mon, err); +} +const MonitorDef monitor_defs[] = { {"fpscr" , offsetof(CPUPPCState , fpscr) },/* Next instruction pointer */
hmp-commands.hx +19 -1
@@ -1509,12 +1509,30 @@ ERST .cmd = hmp_mce, }, -#endif SRST ``mce`` *cpu* *bank* *status* *mcgstatus* *addr* *misc* Inject an MCE on the given CPU (x86 only). ERST +#endif + +#if defined(TARGET_PPC) + + { + .name = "mce", + .args_type = "cpu_index:i,srr1_mask:l,dsisr:i,dar:l,recovered:i", + .params = "cpu srr1_mask dsisr dar recovered", + .help = "inject a MCE on the given CPU", + .cmd = hmp_mce, + }, + +SRST +``mce`` *cpu* *srr1_mask* *dsisr* *dar* *recovered* + Inject a low-level MCE on the given CPU (PPC only). +ERST + +#endif + #ifdef CONFIG_POSIX { .name = "getfd",
Signature · 1 line
2.42.0
PATCH 3/4 target/ppc: Add machine check interrupt injection helper
In reply to Nicholas PigginThis matches the NMI injection helper function.
--- hw/ppc/spapr_events.c | 3 +-- target/ppc/excp_helper.c | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-)
hw/ppc/spapr_events.c +1 -2
@@ -875,8 +875,7 @@ void spapr_mce_req_event(PowerPCCPU *cpu, bool recovered)if (spapr->fwnmi_machine_check_addr ==-1 ) {/* Non-FWNMI case, deliver it like an architected CPU interrupt. */ - cs->exception_index =POWERPC_EXCP_MCHECK ; -ppc_cpu_do_interrupt (cs); +ppc_cpu_do_machine_check (cs);return ; }
target/ppc/excp_helper.c +7 -0
@@ -2601,6 +2601,13 @@ void ppc_cpu_do_system_reset(CPUState *cs)powerpc_excp (cpu,POWERPC_EXCP_RESET ); } +void ppc_cpu_do_machine_check (CPUState *cs) +{ +PowerPCCPU *cpu =POWERPC_CPU (cs); + +powerpc_excp (cpu,POWERPC_EXCP_MCHECK ); +} +void ppc_cpu_do_fwnmi_machine_check (CPUState *cs,target_ulong vector) {PowerPCCPU *cpu =POWERPC_CPU (cs);
Signature · 1 line
2.42.0
cover ppc: add machine check injection HMP command
I'd like to resurrect this and get it merged, because it's quite useful for testing (has caught several Linux bugs in the past).
IIRC the main concern David had last time it came up was that it should have QMP commands too. Which is valid. But I ended up deciding it wouldn't be nice to expose this low level interface too much, it would be better to use maybe a higher level error injection interface that would be emulated in more detail (e.g., not just a MCE, but would set relevant FIR registers and go through error handling logic).
Since x86 has a low level 'mce' hmp command without qmp equivalent, and since better error injection might take some time, I'd like to just hold nose and take this for now.
Thanks,
Nick
Nicholas Piggin (4):
nmi: add MCE class for implementing machine check injection commands ppc/spapr: Implement mce injection
target/ppc: Add machine check interrupt injection helper ppc/pnv: Implement mce injection
include/hw/nmi.h | 20 ++++++++++++ include/hw/ppc/spapr.h | 3 ++ include/monitor/hmp-target.h | 1 - include/monitor/hmp.h | 1 + target/ppc/cpu.h | 1 + hw/core/nmi.c | 61 ++++++++++++++++++++++++++++++++++++ hw/ppc/pnv.c | 55 ++++++++++++++++++++++++++++++++ hw/ppc/spapr.c | 54 +++++++++++++++++++++++++++++++ hw/ppc/spapr_events.c | 3 +- monitor/hmp-cmds.c | 1 + target/ppc/excp_helper.c | 7 +++++ target/ppc/ppc-qmp-cmds.c | 10 ++++++ hmp-commands.hx | 20 +++++++++++- 13 files changed, 233 insertions(+), 4 deletions(-)
Signature · 1 line
2.42.0
PATCH 4/4 ppc/pnv: Implement mce injection
This implements mce injection for pnv.
--- target/ppc/cpu.h | 1 + hw/ppc/pnv.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+)
target/ppc/cpu.h +1 -0
@@ -1593,6 +1593,7 @@ void ppc_maybe_interrupt(CPUPPCState *env);void ppc_cpu_do_interrupt (CPUState *cpu);bool ppc_cpu_exec_interrupt (CPUState *cpu,int int_req);void ppc_cpu_do_system_reset (CPUState *cs); +void ppc_cpu_do_machine_check (CPUState *cs);void ppc_cpu_do_fwnmi_machine_check (CPUState *cs,target_ulong vector);extern const VMStateDescription vmstate_ppc_cpu;#endif
hw/ppc/pnv.c +55 -0
84 lines not on this page · raw message
Signature · 1 line
2.42.0
PATCH 2/4 ppc/spapr: Implement mce injection
In reply to Nicholas PigginThis implements mce injection for spapr.
(qemu) mce 0 0x200000 0x80 0xdeadbeef 0
Disabling lock debugging due to kernel taint
MCE: CPU0: machine check (Severe) Host SLB Multihit DAR: 00000000deadbeef [Recovered]
MCE: CPU0: machine check (Severe) Host SLB Multihit [Recovered]
MCE: CPU0: PID: 495 Comm: a NIP: [0000000130ee07c8]
MCE: CPU0: Initiator CPU
MCE: CPU0: Unknown
[ 71.567193] MCE: CPU0: NIP: [c0000000000d7f6c] plpar_hcall_norets+0x1c/0x28 [ 71.567249] MCE: CPU0: Initiator CPU [ 71.567308] MCE: CPU0: Unknown
--- include/hw/ppc/spapr.h | 3 +++ hw/ppc/spapr.c | 54 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+)
include/hw/ppc/spapr.h +3 -0
@@ -1015,6 +1015,9 @@ void spapr_init_all_lpcrs(target_ulong value, target_ulong mask);hwaddr spapr_get_rtas_addr (void );bool spapr_memory_hot_unplug_supported (SpaprMachineState *spapr); +void spapr_mce_inject (CPUState *cs,uint64_t srr1_mask,uint32_t dsisr, +uint64_t dar,bool recovered); +void spapr_vof_reset (SpaprMachineState *spapr,void *fdt,Error **errp);void spapr_vof_quiesce (MachineState *ms); bool spapr_vof_setprop(MachineState *ms, const char *path, const char *propname,
hw/ppc/spapr.c +54 -0
84 lines not on this page · raw message
Signature · 1 line
2.42.0
Hello Nick,
Quoted 11 lines · Nicholas Piggin
I'd like to resurrect this and get it merged, because it's quite useful for testing (has caught several Linux bugs in the past).
IIRC the main concern David had last time it came up was that it should have QMP commands too. Which is valid. But I ended up deciding it wouldn't be nice to expose this low level interface too much, it would be better to use maybe a higher level error injection interface that would be emulated in more detail (e.g., not just a MCE, but would set relevant FIR registers and go through error handling logic).
Quoted 3 lines
Since x86 has a low level 'mce' hmp command without qmp equivalent, and since better error injection might take some time, I'd like to just hold nose and take this for now.
I reworked this series some years ago :
https://lore.kernel.org/qemu-devel/[email protected]/
Did you take into account the changes ?
Thanks,
C.
Quoted 24 lines
Thanks,
NickNicholas Piggin (4):
nmi: add MCE class for implementing machine check injection commands ppc/spapr: Implement mce injection
target/ppc: Add machine check interrupt injection helper ppc/pnv: Implement mce injectioninclude/hw/nmi.h | 20 ++++++++++++ include/hw/ppc/spapr.h | 3 ++ include/monitor/hmp-target.h | 1 - include/monitor/hmp.h | 1 + target/ppc/cpu.h | 1 + hw/core/nmi.c | 61 ++++++++++++++++++++++++++++++++++++ hw/ppc/pnv.c | 55 ++++++++++++++++++++++++++++++++ hw/ppc/spapr.c | 54 +++++++++++++++++++++++++++++++ hw/ppc/spapr_events.c | 3 +- monitor/hmp-cmds.c | 1 + target/ppc/excp_helper.c | 7 +++++ target/ppc/ppc-qmp-cmds.c | 10 ++++++ hmp-commands.hx | 20 +++++++++++- 13 files changed, 233 insertions(+), 4 deletions(-)