[PATCH 1/2] Add "broadcast" option for mce command.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When the following test case is injected with mce command, maybe user could not
get the expected result.
    DATA
               command cpu bank status             mcg_status  addr   misc
        (qemu) mce     1   1    0xbd00000000000000 0x05        0x1234 0x8c

    Expected Result
           panic type: "Fatal Machine check"

That is because each mce command can only inject the given cpu and could not
inject mce interrupt to other cpus. So user will get the following result:
    panic type: "Fatal machine check on current CPU"

"broadcast" option is used for injecting dummy data into other cpus. Injecting mce
with this option the expected result could be gotten.

Signed-off-by: Jin Dongming <jin.dongming@xxxxxxxxxxxxxxxxxx>
---
 hmp-commands.hx   |    6 ++++++
 monitor.c         |   19 ++++++++++++++++++-
 qemu-kvm.h        |    3 +++
 target-i386/kvm.c |    2 +-
 4 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index ba6de28..3a93837 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1053,9 +1053,15 @@ ETEXI
 
     {
         .name       = "mce",
+#if defined(KVM_CAP_MCE)
+        .args_type  = "cpu_index:i,bank:i,status:l,mcg_status:l,addr:l,misc:l,broadcast:s?",
+        .params     = "cpu bank status mcgstatus addr misc [broadcast|b]",
+        .help       = "inject a MCE on the given CPU [and broadcast to other CPUs]",
+#else
         .args_type  = "cpu_index:i,bank:i,status:l,mcg_status:l,addr:l,misc:l",
         .params     = "cpu bank status mcgstatus addr misc",
         .help       = "inject a MCE on the given CPU",
+#endif
         .mhandler.cmd = do_inject_mce,
     },
 
diff --git a/monitor.c b/monitor.c
index 66d6acd..9d0a98e 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2263,12 +2263,29 @@ static void do_inject_mce(Monitor *mon, const QDict *qdict)
     uint64_t mcg_status = qdict_get_int(qdict, "mcg_status");
     uint64_t addr = qdict_get_int(qdict, "addr");
     uint64_t misc = qdict_get_int(qdict, "misc");
+#if defined(KVM_CAP_MCE)
+    const char *b = qdict_get_try_str(qdict, "broadcast");
+    int broadcast = 0;
 
-    for (cenv = first_cpu; cenv != NULL; cenv = cenv->next_cpu)
+    if (b) {
+        if (!strncmp(b, "broadcast", sizeof("broadcast")) ||
+            !strncmp(b, "b", sizeof("b"))) {
+            broadcast = 1;
+        } else
+            monitor_printf(mon, "Don't do broadcast: option invalid: %s\n", b);
+    }
+#endif
+
+    for (cenv = first_cpu; cenv != NULL; cenv = cenv->next_cpu) {
         if (cenv->cpu_index == cpu_index && cenv->mcg_cap) {
             cpu_inject_x86_mce(cenv, bank, status, mcg_status, addr, misc);
+#if defined(KVM_CAP_MCE)
+            if (broadcast)
+                kvm_mce_broadcast_rest(cenv);
+#endif
             break;
         }
+    } 
 }
 #endif
 
diff --git a/qemu-kvm.h b/qemu-kvm.h
index 0f3fb50..b3986cc 100644
--- a/qemu-kvm.h
+++ b/qemu-kvm.h
@@ -98,6 +98,9 @@ int try_push_interrupts(kvm_context_t kvm);
 
 #if defined(__x86_64__) || defined(__i386__)
 struct kvm_x86_mce;
+#if defined KVM_CAP_MCE
+extern void kvm_mce_broadcast_rest(CPUState *env);
+#endif
 #endif
 
 /*!
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index b7b2430..e3ebbb2 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -1705,7 +1705,7 @@ static void hardware_memory_error(void)
 }
 
 #ifdef KVM_CAP_MCE
-static void kvm_mce_broadcast_rest(CPUState *env)
+void kvm_mce_broadcast_rest(CPUState *env)
 {
     CPUState *cenv;
     int family, model, cpuver = env->cpuid_version;
-- 
1.7.1.1


--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux