cpus: Add generic "nmi" monitor command support
v8 cover cpus: Add generic "nmi" monitor command support
This adds an "nmi" monitor command handler per CPUs. x86, s390 and ppc CPUS are supported.
Please comment. Thanks.
Changes:
v8:
* adjusted commit log for s390 patch
* fixed missing "static" in 1/4
v7:
* fixed typenames, function names, copyrights
* s390x QOM'ed for later addition of the NMI interface
* Since none of x86 machines is QOM'ed, postpone migration to new interface for x86
v6:
* back 5 steps and make it an interface again
v5:
* added Error** to the callback
* fixed some comments
v4:
* now it is not nmi() but nmi_monitor_handler() to avoid confusion
v3:
* patches reorganized
* comments from v2 addressed, more details are in individual commit logs
v2:
* moved from machine interface to CPUClass callback
* s390 and x86 moved to target-s390/target-i386
* x86 handler delivers to the current CPU only now
Alexey Kardashevskiy (5):
cpus: Define callback for QEMU "nmi" command
s390x: Convert QEMUMachine to MachineClass
s390x: Migrate to new NMI interface
spapr: Add support for new NMI interface
pc_piix: Migrate to new NMI interface
cpus.c | 31 ++--------------- hmp-commands.hx | 6 ++-- hw/core/Makefile.objs | 1 + hw/core/nmi.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++ hw/i386/pc_piix.c | 42 +++++++++++++++++++++++ hw/ppc/spapr.c | 21 ++++++++++++ hw/s390x/s390-virtio-ccw.c | 49 ++++++++++++++++++--------- hw/s390x/s390-virtio.c | 59 ++++++++++++++++++++++---------- hw/s390x/s390-virtio.h | 3 ++ include/hw/nmi.h | 49 +++++++++++++++++++++++++++ qapi-schema.json | 4 +-- qmp-commands.hx | 3 +- target-ppc/cpu-qom.h | 1 + target-ppc/excp_helper.c | 8 +++++ 14 files changed, 291 insertions(+), 70 deletions(-) create mode 100644 hw/core/nmi.c create mode 100644 include/hw/nmi.h
Signature · 1 line
2.0.0
PATCH v8 1/5 cpus: Define callback for QEMU "nmi" command
This introduces an NMI (Non Maskable Interrupt) interface with a single nmi_monitor_handler() method. A machine or a device can implement it. This searches for an QOM object with this interface and if it is implemented, calls it. The callback implements an action required to cause debug crash dump on in-kernel debugger invocation. The callback returns Error**.
This adds a nmi_monitor_handle() helper which walks through all objects to find the interface. The interface method is called for all found instances.
This adds support for it in qmp_inject_nmi(). Since no architecture supports it at the moment, there is no change in behaviour.
This changes inject-nmi command description for HMP and QMP.
---
Changes:
v8:
* added missing "static" to nmi_children() definition
v7:
* s/NMI/NMIState/
* added copyrighs to new files
* s/an Non/a Non/
* s/nmi()/nmi_monitor_handle()/
v6:
* NMI is an interface again
v5:
* s/given guest's (CPU|VCPU)/default CPU/
* nmi_monitor_handler() now returns Error**
v4:
* s/\<nmi\>/nmi_monitor_handler/
v3:
* actual nmi() enablement moved from last patch to first patch
* changed description for QMP command too
--- cpus.c | 3 +- hmp-commands.hx | 6 ++-- hw/core/Makefile.objs | 1 + hw/core/nmi.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/nmi.h | 49 ++++++++++++++++++++++++++++++ qapi-schema.json | 4 +-- qmp-commands.hx | 3 +- 7 files changed, 141 insertions(+), 9 deletions(-) create mode 100644 hw/core/nmi.c create mode 100644 include/hw/nmi.h
cpus.c +2 -1
@@ -40,6 +40,7 @@#include "qemu/bitmap.h" #include "qemu/seqlock.h" #include "qapi-event.h" +#include "hw/nmi.h" #ifndef _WIN32#include "qemu/compatfd.h"
@@ -1551,7 +1552,7 @@ void qmp_inject_nmi(Error **errp) } }#else -error_set (errp,QERR_UNSUPPORTED ); +nmi_monitor_handle (monitor_get_cpu_index (), errp);#endif }
hmp-commands.hx +2 -4
@@ -832,19 +832,17 @@ The values that can be specified here depend on the machine type, but are the same that can be specified in the @code{-boot} command line option. ETEXI -#if defined(TARGET_I386) || defined(TARGET_S390X) { .name = "nmi", .args_type = "", .params = "", - .help = "inject an NMI on all guest's CPUs", + .help = "inject an NMI", .mhandler.cmd = hmp_inject_nmi, }, -#endif STEXI @item nmi @var{cpu} @findex nmi -Inject an NMI (x86) or RESTART (s390x) on the given CPU. +Inject an NMI on the default CPU (x86/s390) or all CPUs (ppc64). ETEXI
hw/core/Makefile.objs +1 -0
@@ -4,6 +4,7 @@ common-obj-y += fw-path-provider.o # irq.o needed for qdev GPIO handling: common-obj-y += irq.o common-obj-y += hotplug.o +common-obj-y += nmi.o common-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o common-obj-$(CONFIG_XILINX_AXI) += stream.o
hw/core/nmi.c new file +84 -0
84 lines not on this page · raw message
include/hw/nmi.h new file +49 -0
49 lines not on this page · raw message
qapi-schema.json +2 -2
@@ -1186,13 +1186,13 @@ ## # @inject-nmi: # -# Injects an Non-Maskable Interrupt into all guest's VCPUs. +# Injects a Non-Maskable Interrupt into the default CPU (x86/s390) or all CPUs (ppc64). # # Returns: If successful, nothing # # Since: 0.14.0 # -# Notes: Only x86 Virtual Machines support this command. +# Note: prior to 2.1, this command was only supported for x86 and s390 VMs ## { 'command': 'inject-nmi' }
qmp-commands.hx +1 -2
@@ -477,7 +477,7 @@ SQMP inject-nmi ---------- -Inject an NMI on guest's CPUs. +Inject an NMI on the default CPU (x86/s390) or all CPUs (ppc64). Arguments: None.
@@ -487,7 +487,6 @@ Example: <- { "return": {} } Note: inject-nmi fails when the guest doesn't support injecting. - Currently, only x86 (NMI) and s390x (RESTART) guests do. EQMP
Signature · 1 line
2.0.0
PATCH v8 2/5 s390x: Convert QEMUMachine to MachineClass
In reply to Alexey KardashevskiyThis converts s390-virtio and s390-ccw-virtio machines to QOM MachineClass. This brings ability to add interfaces to the machine classes. The first interface for addition will be NMI.
The patch is mechanical so no change in behavior is expected.
--- hw/s390x/s390-virtio-ccw.c | 43 +++++++++++++++++++++++++++---------------- hw/s390x/s390-virtio.c | 44 +++++++++++++++++++++++++++----------------- 2 files changed, 54 insertions(+), 33 deletions(-)
hw/s390x/s390-virtio-ccw.c +27 -16
@@ -18,6 +18,8 @@#include "css.h" #include "virtio-ccw.h" +#define TYPE_S390_CCW_MACHINE "s390-ccw-machine" +void io_subsystem_reset (void ) {DeviceState *css, *sclp, *flic;
@@ -134,24 +136,33 @@ static void ccw_init(MachineState *machine)s390_create_virtio_net (BUS (css_bus),"virtio-net-ccw" ); } -static QEMUMachine ccw_machine = { - .name ="s390-ccw-virtio" , - .alias ="s390-ccw" , - .desc ="VirtIO-ccw based S390 machine" , - .init = ccw_init, - .block_default_type =IF_VIRTIO , - .no_cdrom =1 , - .no_floppy =1 , - .no_serial =1 , - .no_parallel =1 , - .no_sdcard =1 , - .use_sclp =1 , - .max_cpus =255 , +static void ccw_machine_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); + + mc->name ="s390-ccw-virtio" ; + mc->alias ="s390-ccw" ; + mc->desc ="VirtIO-ccw based S390 machine" ; + mc->init = ccw_init; + mc->block_default_type =IF_VIRTIO ; + mc->no_cdrom =1 ; + mc->no_floppy =1 ; + mc->no_serial =1 ; + mc->no_parallel =1 ; + mc->no_sdcard =1 ; + mc->use_sclp =1 , + mc->max_cpus =255 ; +} + +static const TypeInfo ccw_machine_info = { + .name =TYPE_S390_CCW_MACHINE , + .parent =TYPE_MACHINE , + .class_init = ccw_machine_class_init, }; -static void ccw_machine_init (void ) +static void ccw_machine_register_types (void ) { -qemu_register_machine (&ccw_machine); +type_register_static (&ccw_machine_info); } -machine_init (ccw_machine_init) +type_init (ccw_machine_register_types)
hw/s390x/s390-virtio.c +27 -17
58 lines not on this page · raw message
Signature · 1 line
2.0.0
PATCH v8 3/5 s390x: Migrate to new NMI interface
In reply to Alexey KardashevskiyThis implements an NMI interface for s390 and s390-ccw machines.
This removes #ifdef s390 branch in qmp_inject_nmi so new s390's nmi_monitor_handler() callback is going to be used for NMI.
Since nmi_monitor_handler()-calling code is platform independent, CPUState::cpu_index is used instead of S390CPU::env.cpu_num. There should not be any change in behaviour as both @cpu_index and @cpu_num are global CPU numbers.
Note that s390_cpu_restart() already takes care of the specified cpu, so we don't need to schedule via async_run_on_cpu().
Since the only error s390_cpu_restart() can return is ENOSYS, convert it to QERR_UNSUPPORTED.
---
Changes:
v8:
* adjusted commit log
v7:
* since now s390' are QOM'ed, add interface to them and do not create new object
v6:
* supported NMI interface
v5:
* added ENOSYS -> QERR_UNSUPPORTED, qapi/qmp/qerror.h was added for this
v4:
* s/\<nmi\>/nmi_monitor_handler/
v3:
* now contains both old code removal and new code insertion, easier to track changes
--- cpus.c | 14 -------------- hw/s390x/s390-virtio-ccw.c | 6 ++++++ hw/s390x/s390-virtio.c | 15 +++++++++++++++ hw/s390x/s390-virtio.h | 3 +++ 4 files changed, 24 insertions(+), 14 deletions(-)
cpus.c +0 -14
@@ -1537,20 +1537,6 @@ void qmp_inject_nmi(Error **errp) apic_deliver_nmi(cpu->apic_state); } } -#elif defined(TARGET_S390X) -CPUState *cs; -S390CPU *cpu; - -CPU_FOREACH (cs) { - cpu =S390_CPU (cs); -if (cpu->env.cpu_num ==monitor_get_cpu_index ()) { -if (s390_cpu_restart (S390_CPU (cs)) ==-1 ) { -error_set (errp,QERR_UNSUPPORTED ); -return ; - } -break ; - } - }#else nmi_monitor_handle (monitor_get_cpu_index (), errp);#endif
hw/s390x/s390-virtio-ccw.c +6 -0
@@ -139,6 +139,7 @@ static void ccw_init(MachineState *machine)static void ccw_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc); +NMIClass *nc =NMI_CLASS (oc); mc->name ="s390-ccw-virtio" ; mc->alias ="s390-ccw" ;
@@ -152,12 +153,17 @@ static void ccw_machine_class_init(ObjectClass *oc, void *data) mc->no_sdcard =1 ; mc->use_sclp =1 , mc->max_cpus =255 ; + nc->nmi_monitor_handler = s390_nmi; }static const TypeInfo ccw_machine_info = { .name =TYPE_S390_CCW_MACHINE , .parent =TYPE_MACHINE , .class_init = ccw_machine_class_init, + .interfaces = (InterfaceInfo []) { + {TYPE_NMI }, + { } + }, };static void ccw_machine_register_types (void )
hw/s390x/s390-virtio.c +15 -0
@@ -280,9 +280,19 @@ static void s390_init(MachineState *machine)s390_create_virtio_net ((BusState *)s390_bus,"virtio-net-s390" ); } +void s390_nmi (NMIState *n,int cpu_index,Error **errp) +{ +CPUState *cs =qemu_get_cpu (cpu_index); + +if (s390_cpu_restart (S390_CPU (cs))) { +error_set (errp,QERR_UNSUPPORTED ); + } +} +static void s390_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc); +NMIClass *nc =NMI_CLASS (oc); mc->name ="s390-virtio" ; mc->alias ="s390" ;
@@ -297,12 +307,17 @@ static void s390_machine_class_init(ObjectClass *oc, void *data) mc->no_cdrom =1 ; mc->no_sdcard =1 ; mc->is_default =1 ; + nc->nmi_monitor_handler = s390_nmi; }static const TypeInfo s390_machine_info = { .name =TYPE_S390_MACHINE , .parent =TYPE_MACHINE , .class_init = s390_machine_class_init, + .interfaces = (InterfaceInfo []) { + {TYPE_NMI }, + { } + }, };static void s390_machine_register_types (void )
hw/s390x/s390-virtio.h +3 -0
@@ -12,6 +12,8 @@#ifndef HW_S390_VIRTIO_H #define HW_S390_VIRTIO_H 1 +#include "hw/nmi.h" +#define KVM_S390_VIRTIO_NOTIFY 0#define KVM_S390_VIRTIO_RESET 1#define KVM_S390_VIRTIO_SET_STATUS 2
@@ -26,4 +28,5 @@ void s390_init_ipl_dev(const char *kernel_filename,const char *initrd_filename, const char *firmware);void s390_create_virtio_net (BusState *bus,const char *name); +void s390_nmi (NMIState *n,int cpu_index,Error **errp);#endif
Signature · 1 line
2.0.0
PATCH v8 4/5 spapr: Add support for new NMI interface
In reply to Alexey KardashevskiyThis implements an NMI interface POWERPC SPAPR machine. This enables an "nmi" HMP/QMP command supported on SPAPR.
This calls POWERPC_EXCP_RESET (vector 0x100) in the guest to deliver NMI to every CPU. The expected result is XMON (in-kernel debugger) invocation.
---
Changes:
v7:
* s/ppc_cpu_do_nmi/ppc_cpu_do_system_reset/
v6:
* support NMI interface
v4:
* s/\<nmi\>/nmi_monitor_handler/
* added note about XMON into commit log
v3:
* ppc_cpu_do_nmi() is exported from excp_helper.c instead of powerpc_excp()
--- hw/ppc/spapr.c | 21 +++++++++++++++++++++ target-ppc/cpu-qom.h | 1 + target-ppc/excp_helper.c | 8 ++++++++ 3 files changed, 30 insertions(+)
hw/ppc/spapr.c +21 -0
@@ -55,6 +55,7 @@#include "qemu/config-file.h" #include "qemu/error-report.h" #include "trace.h" +#include "hw/nmi.h" #include <libfdt.h>
@@ -1639,10 +1640,28 @@ static void spapr_machine_initfn(Object *obj) spapr_get_kvm_type, spapr_set_kvm_type, NULL); } +static void ppc_cpu_do_nmi_on_cpu (void *arg) +{ +CPUState *cs = arg; + +cpu_synchronize_state (cs); +ppc_cpu_do_system_reset (cs); +} + +static void spapr_nmi (NMIState *n,int cpu_index,Error **errp) +{ +CPUState *cs; + +CPU_FOREACH (cs) { +async_run_on_cpu (cs, ppc_cpu_do_nmi_on_cpu, cs); + } +} +static void spapr_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);FWPathProviderClass *fwc =FW_PATH_PROVIDER_CLASS (oc); +NMIClass *nc =NMI_CLASS (oc); mc->name ="pseries" ; mc->desc ="pSeries Logical Partition (PAPR compliant)" ;
@@ -1656,6 +1675,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) mc->kvm_type = spapr_kvm_type; fwc->get_dev_path = spapr_get_fw_dev_path; + nc->nmi_monitor_handler = spapr_nmi; }static const TypeInfo spapr_machine_info = {
@@ -1666,6 +1686,7 @@ static const TypeInfo spapr_machine_info = { .class_init = spapr_machine_class_init, .interfaces = (InterfaceInfo []) { {TYPE_FW_PATH_PROVIDER }, + {TYPE_NMI }, { } }, };
target-ppc/cpu-qom.h +1 -0
@@ -127,6 +127,7 @@ int ppc64_cpu_write_elf64_qemunote(WriteCoreDumpFunction f,int ppc64_cpu_write_elf64_note (WriteCoreDumpFunction f,CPUState *cs,int cpuid,void *opaque); #ifndef CONFIG_USER_ONLY +void ppc_cpu_do_system_reset(CPUState *cs); extern const struct VMStateDescription vmstate_ppc_cpu; typedef struct PPCTimebase {
target-ppc/excp_helper.c +8 -0
@@ -810,6 +810,14 @@ void ppc_hw_interrupt(CPUPPCState *env) } } } + +void ppc_cpu_do_system_reset (CPUState *cs) +{ +PowerPCCPU *cpu =POWERPC_CPU (cs); +CPUPPCState *env = &cpu->env; + +powerpc_excp (cpu, env->excp_model,POWERPC_EXCP_RESET ); +}#endif /* !CONFIG_USER_ONLY */ #if defined(DEBUG_OP )
Signature · 1 line
2.0.0
PATCH v8 5/5 pc_piix: Migrate to new NMI interface
In reply to Alexey KardashevskiyThis implements an NMI interface for i386 PC machines.
This removes #ifdef I386 branch in qmp_inject_nmi so new i386's nmi() callback is going to be used for NMI.
This changes code to inject NMI on the current CPU instead of injecting it on every CPU. However that does not seem to be an issue.
Since kvm_apic_external_nmi() takes care of preforming operations in the specific CPU thread so no extra measure is required here.
---
Changes:
v6:
* make use of NMI interface
v5:
* make use of NMI interface
v4:
* s/\<nmi\>/nmi_monitor_handler/
v3:
* now contains both old code removal and new code insertion, easier to track changes
* fixed compile for linux-user
--- cpus.c | 14 -------------- hw/i386/pc_piix.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 14 deletions(-)
cpus.c +0 -14
@@ -1525,21 +1525,7 @@ exit:void qmp_inject_nmi (Error **errp) { -#if defined(TARGET_I386 ) -CPUState *cs; - -CPU_FOREACH (cs) { -X86CPU *cpu =X86_CPU (cs); - -if (!cpu->apic_state) { -cpu_interrupt (cs,CPU_INTERRUPT_NMI ); - }else { -apic_deliver_nmi (cpu->apic_state); - } - } -#else nmi_monitor_handle (monitor_get_cpu_index (), errp); -#endif }void dump_drift_info (FILE *f,fprintf_function cpu_fprintf)
hw/i386/pc_piix.c +42 -0
62 lines not on this page · raw message
Signature · 1 line
2.0.0
Il 20/08/2014 14:16, Alexey Kardashevskiy ha scritto:
Quoted 53 lines
This adds an "nmi" monitor command handler per CPUs. x86, s390 and ppc CPUS are supported.
Please comment. Thanks.
Changes:
v8:
* adjusted commit log for s390 patch
* fixed missing "static" in 1/4v7:
* fixed typenames, function names, copyrights
* s390x QOM'ed for later addition of the NMI interface
* Since none of x86 machines is QOM'ed, postpone migration to new interface for x86v6:
* back 5 steps and make it an interface againv5:
* added Error** to the callback
* fixed some commentsv4:
* now it is notnmi()butnmi_monitor_handler()to avoid confusionv3:
* patches reorganized
* comments from v2 addressed, more details are in individual commit logsv2:
* moved from machine interface to CPUClass callback
* s390 and x86 moved to target-s390/target-i386
* x86 handler delivers to the current CPU only nowAlexey Kardashevskiy (5):
cpus: Define callback for QEMU "nmi" command
s390x: Convert QEMUMachine to MachineClass
s390x: Migrate to new NMI interface
spapr: Add support for new NMI interface
pc_piix: Migrate to new NMI interfacecpus.c | 31 ++--------------- hmp-commands.hx | 6 ++-- hw/core/Makefile.objs | 1 + hw/core/nmi.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++ hw/i386/pc_piix.c | 42 +++++++++++++++++++++++ hw/ppc/spapr.c | 21 ++++++++++++ hw/s390x/s390-virtio-ccw.c | 49 ++++++++++++++++++--------- hw/s390x/s390-virtio.c | 59 ++++++++++++++++++++++---------- hw/s390x/s390-virtio.h | 3 ++
Quoted 9 lines
include/hw/nmi.h | 49 +++++++++++++++++++++++++++ qapi-schema.json | 4 +-- qmp-commands.hx | 3 +- target-ppc/cpu-qom.h | 1 + target-ppc/excp_helper.c | 8 +++++ 14 files changed, 291 insertions(+), 70 deletions(-) create mode 100644 hw/core/nmi.c create mode 100644 include/hw/nmi.h
Applying patches 1-4 to uq/master. PC will wait for the QOM machine conversion.
Paolo