Skip to contentSkip to conversation

Add MCE simulation support to qemu/kvm

RFC In review Huang Ying 1 participant 1 message Apr 30, 2009 KVM

lore
Share & tools
lore

Huang Ying

author
#0 lore raw

RFC 2/2 Add MCE simulation support to qemu/kvm

MCE features are detected, initialized and injected via the corresponding KVM ioctl.

---
 kvm-all.c            |   24 ++++++++++++++++++
 kvm.h                |    4 +++
 target-i386/helper.c |    8 +++++-
 target-i386/kvm.c    |   67 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 101 insertions(+), 2 deletions(-)
kvm-all.c +24 -0
@@ -765,6 +765,30 @@ int kvm_has_sync_mmu(void)
     return 0;
 }
 
+int kvm_has_mce(void)
+{
+#ifdef KVM_CAP_MCE
+    KVMState *s = kvm_state;
+    int r;
+
+    r = kvm_ioctl(s, KVM_CHECK_EXTENSION, KVM_CAP_MCE);
+    if (r > 0)
+        return r;
+#endif
+    return 0;
+}
+
+int kvm_get_mce_cap_supported(uint64_t *mce_cap)
+{
+#ifdef KVM_CAP_MCE
+    KVMState *s = kvm_state;
+
+    return kvm_ioctl(s, KVM_X86_GET_MCE_CAP_SUPPORTED, mce_cap);
+#else
+    return -ENOSYS;
+#endif
+}
+
 #ifdef KVM_CAP_SET_GUEST_DEBUG
 struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUState *env,
                                                  target_ulong pc)
kvm.h +4 -0
@@ -47,6 +47,10 @@ int kvm_log_start(target_phys_addr_t phy
 int kvm_log_stop(target_phys_addr_t phys_addr, ram_addr_t size);
 
 int kvm_has_sync_mmu(void);
+int kvm_has_mce(void);
+int kvm_get_mce_cap_supported(uint64_t *mce_cap);
+void kvm_inject_x86_mce(CPUState *cenv, int bank, uint64_t status,
+                        uint64_t mcg_status, uint64_t addr, uint64_t misc);
 
 int kvm_coalesce_mmio_region(target_phys_addr_t start, ram_addr_t size);
 int kvm_uncoalesce_mmio_region(target_phys_addr_t start, ram_addr_t size);
target-i386/helper.c +7 -1
@@ -1440,6 +1440,11 @@ void cpu_inject_x86_mce(CPUState *cenv, 
     unsigned bank_num = mcg_cap & 0xff;
     uint64_t *banks = cenv->mce_banks;
 
+    if (kvm_enabled()) {
+        kvm_inject_x86_mce(cenv, bank, status, mcg_status, addr, misc);
+        return;
+    }
+
     if (bank >= bank_num || !(status & MCI_STATUS_VAL))
         return;
 
@@ -1757,7 +1762,8 @@ CPUX86State *cpu_x86_init(const char *cp
         cpu_x86_close(env);
         return NULL;
     }
-    mce_init(env);
+    if (!kvm_enabled())
+        mce_init(env);
     cpu_reset(env);
 #ifdef CONFIG_KQEMU
     kqemu_init(env);
target-i386/kvm.c +66 -1

91 lines not on this page · raw message