Skip to contentSkip to conversation

Minor nmi cleanups

PATCH Superseded Bandan Das 2 participants 8 messages May 19, 2016 – May 20, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Bandan Das

author
#0 lore raw

cover Minor nmi cleanups

The primary change is a arch specific x86 nmi function which can be called by the core nmi handler.

Bandan Das (4):
target-i386: add a generic x86 nmi handler
nmi: remove x86 specific nmi handling
nmi: add errp function parameter to inject_nmi()
cpus: call the core nmi injection function

 cpus.c                 | 16 +---------------
 hw/core/nmi.c          | 23 ++---------------------
 hw/i386/pc.c           | 20 ++++++++++++++++++++
 hw/watchdog/watchdog.c |  2 +-
 include/hw/nmi.h       |  2 +-
 5 files changed, 25 insertions(+), 38 deletions(-)
Signature · 1 line
2.5.5
author
#2 lore raw

PATCH 2/4 nmi: remove x86 specific nmi handling

nmi_monitor_handle is wired to call the x86 nmi
handler now. So, we can call it here. Note that
this also reverts changes made by commit 33c11879

---
 hw/core/nmi.c | 19 -------------------
 1 file changed, 19 deletions(-)
hw/core/nmi.c +0 -19
index f616a79..cc47025 100644
@@ -20,16 +20,11 @@
  */
 
 #include "qemu/osdep.h"
-#include "qom/cpu.h"
 #include "hw/nmi.h"
 #include "qapi/error.h"
 #include "qapi/qmp/qerror.h"
 #include "monitor/monitor.h"
 
-#if defined(TARGET_I386)
-#include "cpu.h"
-#endif
-
 struct do_nmi_s {
     int cpu_index;
     Error *err;
@@ -80,21 +75,7 @@ void nmi_monitor_handle(int cpu_index, Error **errp)
 
 void inject_nmi(void)
 {
-#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(0, NULL);
-#endif
 }
 
 static const TypeInfo nmi_info = {
Signature · 1 line
2.5.5
author
#1 lore raw

PATCH 1/4 target-i386: add a generic x86 nmi handler

In reply to Bandan Das

Instead of having x86 ifdefs in core nmi code, this change adds a arch specific handler that the nmi common code can call.

---
 hw/i386/pc.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
hw/i386/pc.c +20 -0
index 99437e0..e29ccc8 100644
@@ -67,6 +67,7 @@
 #include "qapi/visitor.h"
 #include "qapi-visit.h"
 #include "qom/cpu.h"
+#include "hw/nmi.h"
 
 /* debug PC/ISA interrupts */
 //#define DEBUG_IRQ
@@ -1963,11 +1964,28 @@ static CPUArchIdList *pc_possible_cpu_arch_ids(MachineState *machine)
     return list;
 }
 
+static void x86_nmi(NMIState *n, int cpu_index, Error **errp)
+{
+    /* cpu index isn't used */
+    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);
+        }
+    }
+}
+
 static void pc_machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
     PCMachineClass *pcmc = PC_MACHINE_CLASS(oc);
     HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
+    NMIClass *nc = NMI_CLASS(oc);
 
     pcmc->get_hotplug_handler = mc->get_hotplug_handler;
     pcmc->pci_enabled = true;
@@ -1993,6 +2011,7 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)
     hc->plug = pc_machine_device_plug_cb;
     hc->unplug_request = pc_machine_device_unplug_request_cb;
     hc->unplug = pc_machine_device_unplug_cb;
+    nc->nmi_monitor_handler = x86_nmi;
 }
 
 static const TypeInfo pc_machine_info = {
@@ -2005,6 +2024,7 @@ static const TypeInfo pc_machine_info = {
     .class_init = pc_machine_class_init,
     .interfaces = (InterfaceInfo[]) {
          { TYPE_HOTPLUG_HANDLER },
+         { TYPE_NMI },
          { }
     },
 };
Signature · 1 line
2.5.5
author
#3 lore raw

PATCH 3/4 nmi: add errp function parameter to inject_nmi()

In reply to Bandan Das

If caller has errp, set it appropriately in case of an error and pass it along.

---
 hw/core/nmi.c          | 4 ++--
 hw/watchdog/watchdog.c | 2 +-
 include/hw/nmi.h       | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
hw/core/nmi.c +2 -2
index cc47025..40324a9 100644
@@ -73,9 +73,9 @@ void nmi_monitor_handle(int cpu_index, Error **errp)
     }
 }
 
-void inject_nmi(void)
+void inject_nmi(Error **errp)
 {
-    nmi_monitor_handle(0, NULL);
+    nmi_monitor_handle(0, errp);
 }
 
 static const TypeInfo nmi_info = {
hw/watchdog/watchdog.c +1 -1
index bbf3646..c3f2c87 100644
@@ -143,7 +143,7 @@ void watchdog_perform_action(void)
     case WDT_NMI:
         qapi_event_send_watchdog(WATCHDOG_EXPIRATION_ACTION_INJECT_NMI,
                                  &error_abort);
-        inject_nmi();
+        inject_nmi(NULL);
         break;
     }
 }
include/hw/nmi.h +1 -1
index f4cec62..63794d9 100644
@@ -45,6 +45,6 @@ typedef struct NMIClass {
 } NMIClass;
 
 void nmi_monitor_handle(int cpu_index, Error **errp);
-void inject_nmi(void);
+void inject_nmi(Error **errp);
 
 #endif /* NMI_H */
Signature · 1 line
2.5.5
author
#4 lore raw

PATCH 4/4 cpus: call the core nmi injection function

In reply to Bandan Das

Now that the common functions are in place, we can call it instead of duplicating code.

---
 cpus.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)
cpus.c +1 -15
index eb34b4f..ead4e3f 100644
@@ -1693,21 +1693,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
+    inject_nmi(errp);
 }
 
 void dump_drift_info(FILE *f, fprintf_function cpu_fprintf)
Signature · 1 line
2.5.5
#5 lore raw

Re: [Qemu-devel] [PATCH 4/4] cpus: call the core nmi injection function

Quoted 8 lines · Bandan Das

void qmp_inject_nmi(Error **errp)
{

cpus.c +0 -6
-#if defined(TARGET_I386)
-    CPUState *cs;
-
-    CPU_FOREACH(cs) {
-        X86CPU *cpu = X86_CPU(cs);
-

cpus.c exit: · line 1696

Quoted 10 lines
cpus.c +1 -9
-        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
+    inject_nmi(errp);

This changes the first argument to nmi_monitor_handle in the !i386 case.
It should just remove the #ifdef, which I think makes the third patch
unnecessary. The first two patches are okay.

Paolo

#6 lore raw

Re: [Qemu-devel] [PATCH 4/4] cpus: call the core nmi injection function

In reply to Bandan Das
Quoted 8 lines · Bandan Das

void qmp_inject_nmi(Error **errp)
{

cpus.c +0 -6
-#if defined(TARGET_I386)
-    CPUState *cs;
-
-    CPU_FOREACH(cs) {
-        X86CPU *cpu = X86_CPU(cs);
-

cpus.c exit: · line 1696

Quoted 10 lines
cpus.c +1 -9
-        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
+    inject_nmi(errp);

This changes the first argument to nmi_monitor_handle in the !i386 case.
It should just remove the #ifdef, which I think makes the third patch
unnecessary. The first two patches are okay.

Paolo

author
#7 lore raw

Re: [Qemu-devel] [PATCH 4/4] cpus: call the core nmi injection function

Quoted 15 lines · Paolo Bonzini
Quoted 14 lines · Bandan Das

void qmp_inject_nmi(Error **errp)
{

cpus.c +0 -12
-#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);
-        }
-    }
Quoted 8 lines

cpus.c exit: · line 1696

Quoted 4 lines
cpus.c +1 -3
-#else
-    nmi_monitor_handle(monitor_get_cpu_index(), errp);
-#endif
+    inject_nmi(errp);

This changes the first argument to nmi_monitor_handle in the !i386 case.
It should just remove the #ifdef, which I think makes the third patch
unnecessary. The first two patches are okay.

Thanks for the review, I have sent a v2.

Quoted 1 line

Paolo