diff mbox

[1/1,V6] qemu: fix improper nmi emulation

Message ID 4E9EEB08.30504@cn.fujitsu.com
State New
Headers show

Commit Message

Lai Jiangshan Oct. 19, 2011, 3:21 p.m. UTC
On 10/19/2011 06:57 PM, Jan Kiszka wrote:

>>>
>>> Looks OK to me.
>>>
>>> Please don't forget to bake a qemu-only patch for those bits that apply
>>> to upstream as well (ie. the user space APIC path).
>>>
>>> Jan
>>>
>>
>> I did forget it.
>> Did you mean we need to add "#ifdef KVM_CAP_IRQCHIP" back?
> 
> No. I meant basically your patch minus the kvm_in_kernel_irqchip code
> paths, applicable against current qemu.git. Those paths will be re-added
> (slightly differently) when upstream gains that support. I'm working on
> a basic version an will incorporate the logic if your qemu patch is
> already available.
> 
> Jan
> 

Patch for qemu.git

From: Lai Jiangshan <laijs@cn.fujitsu.com>

Currently, NMI interrupt is blindly sent to all the vCPUs when NMI
button event happens. This doesn't properly emulate real hardware on
which NMI button event triggers LINT1. Because of this, NMI is sent to
the processor even when LINT1 is masked in LVT. For example, this
causes the problem that kdump initiated by NMI sometimes doesn't work
on KVM, because kdump assumes NMI is masked on CPUs other than CPU0.

With this patch, inject-nmi request is handled as delivering LINT1.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Reported-by: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
---
 hw/apic.c |    7 +++++++
 hw/apic.h |    1 +
 monitor.c |    6 +++++-
 3 files changed, 13 insertions(+), 1 deletions(-)
diff mbox

Patch

diff --git a/hw/apic.c b/hw/apic.c
index 8289eef..c8dc997 100644
--- a/hw/apic.c
+++ b/hw/apic.c
@@ -205,6 +205,13 @@  void apic_deliver_pic_intr(DeviceState *d, int level)
     }
 }
 
+void apic_deliver_nmi(DeviceState *d)
+{
+    APICState *s = DO_UPCAST(APICState, busdev.qdev, d);
+
+    apic_local_deliver(s, APIC_LVT_LINT1);
+}
+
 #define foreach_apic(apic, deliver_bitmask, code) \
 {\
     int __i, __j, __mask;\
diff --git a/hw/apic.h b/hw/apic.h
index a5c910f..a62d83b 100644
--- a/hw/apic.h
+++ b/hw/apic.h
@@ -8,6 +8,7 @@  void apic_deliver_irq(uint8_t dest, uint8_t dest_mode, uint8_t delivery_mode,
                       uint8_t vector_num, uint8_t trigger_mode);
 int apic_accept_pic_intr(DeviceState *s);
 void apic_deliver_pic_intr(DeviceState *s, int level);
+void apic_deliver_nmi(DeviceState *d);
 int apic_get_interrupt(DeviceState *s);
 void apic_reset_irq_delivered(void);
 int apic_get_irq_delivered(void);
diff --git a/monitor.c b/monitor.c
index ffda0fe..144099a 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2501,7 +2501,11 @@  static int do_inject_nmi(Monitor *mon, const QDict *qdict, QObject **ret_data)
     CPUState *env;
 
     for (env = first_cpu; env != NULL; env = env->next_cpu) {
-        cpu_interrupt(env, CPU_INTERRUPT_NMI);
+        if (!env->apic_state) {
+            cpu_interrupt(env, CPU_INTERRUPT_NMI);
+        } else {
+            apic_deliver_nmi(env->apic_state);
+        }
     }
 
     return 0;