[PATCH 05/11] kvm, x86: introduce kvm_inject_x86_mce_on

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

 



Pass a table instead of multiple args.

Note:

kvm_inject_x86_mce(env, bank, status, mcg_status, addr, misc,
                   abort_on_error);

is equal to:

struct kvm_x86_mce mce = {
    .bank = bank,
    .status = status,
    .mcg_status = mcg_status,
    .addr = addr,
    .misc = misc,
};
kvm_inject_x86_mce_on(env, &mce, abort_on_error);

Signed-off-by: Hidetoshi Seto <seto.hidetoshi@xxxxxxxxxxxxxx>
Tested-by: Jin Dongming <jin.dongming@xxxxxxxxxxxxxxxxxx>
---
 qemu-kvm.c |   56 ++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 38 insertions(+), 18 deletions(-)

diff --git a/qemu-kvm.c b/qemu-kvm.c
index 9f248f0..0ba42fc 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -1131,6 +1131,9 @@ static void sigbus_reraise(void)
 }
 
 #if defined(KVM_CAP_MCE) && defined(TARGET_I386)
+static void kvm_inject_x86_mce_on(CPUState *env, struct kvm_x86_mce *mce,
+                                  int abort_on_error);
+
 static int kvm_mce_in_progress(CPUState *env)
 {
     struct kvm_msr_entry msr_mcg_status = {
@@ -1192,17 +1195,27 @@ static void kvm_mce_inj_srao_memscrub(CPUState *env, unsigned long paddr)
 
 static void kvm_mce_inj_srao_broadcast(unsigned long paddr)
 {
+    struct kvm_x86_mce mce_srao_memscrub = {
+        .bank = 9,
+        .status = MCI_STATUS_VAL | MCI_STATUS_UC | MCI_STATUS_EN
+                  | MCI_STATUS_MISCV | MCI_STATUS_ADDRV | MCI_STATUS_S
+                  | 0xc0,
+        .mcg_status = MCG_STATUS_MCIP | MCG_STATUS_RIPV,
+        .addr = paddr,
+        .misc = (MCM_ADDR_PHYS << 6) | 0xc,
+    };
+    struct kvm_x86_mce mce_dummy = {
+        .bank = 1,
+        .status = MCI_STATUS_VAL | MCI_STATUS_UC,
+        .mcg_status = MCG_STATUS_MCIP | MCG_STATUS_RIPV,
+        .addr = 0,
+        .misc = 0,
+    };
     CPUState *cenv;
 
-    kvm_inject_x86_mce(first_cpu, 9,
-                       MCI_STATUS_VAL | MCI_STATUS_UC | MCI_STATUS_EN
-                       | MCI_STATUS_MISCV | MCI_STATUS_ADDRV | MCI_STATUS_S
-                       | 0xc0,
-                       MCG_STATUS_MCIP | MCG_STATUS_RIPV, paddr,
-                       (MCM_ADDR_PHYS << 6) | 0xc, 1);
+    kvm_inject_x86_mce_on(first_cpu, &mce_srao_memscrub, 1);
     for (cenv = first_cpu->next_cpu; cenv != NULL; cenv = cenv->next_cpu)
-        kvm_inject_x86_mce(cenv, 1, MCI_STATUS_VAL | MCI_STATUS_UC,
-                           MCG_STATUS_MCIP | MCG_STATUS_RIPV, 0, 0, 1);
+        kvm_inject_x86_mce_on(cenv, &mce_dummy, 1);
 }
 #endif
 
@@ -1941,6 +1954,22 @@ static void kvm_do_inject_x86_mce(void *_data)
 
     kvm_do_set_mce(data->env, data->mce, data->abort_on_error);
 }
+
+static void kvm_inject_x86_mce_on(CPUState *env, struct kvm_x86_mce *mce,
+                                  int abort_on_error)
+{
+    struct kvm_x86_mce_data data = {
+        .env = env,
+        .mce = mce,
+        .abort_on_error = abort_on_error,
+    };
+
+    if (!env->mcg_cap) {
+        perror("MCE support is not enabled!");
+        return;
+    }
+    on_vcpu(env, kvm_do_inject_x86_mce, &data);
+}
 #endif
 
 void kvm_inject_x86_mce(CPUState *cenv, int bank, uint64_t status,
@@ -1955,17 +1984,8 @@ void kvm_inject_x86_mce(CPUState *cenv, int bank, uint64_t status,
         .addr = addr,
         .misc = misc,
     };
-    struct kvm_x86_mce_data data = {
-        .env = cenv,
-        .mce = &mce,
-        .abort_on_error = abort_on_error,
-    };
 
-    if (!cenv->mcg_cap) {
-        fprintf(stderr, "MCE support is not enabled!\n");
-        return;
-    }
-    on_vcpu(cenv, kvm_do_inject_x86_mce, &data);
+    kvm_inject_x86_mce_on(cenv, &mce, abort_on_error);
 #else
     if (abort_on_error) {
         abort();
-- 
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