x86: vMCE injection
authorLiu, Jinsong <jinsong.liu@intel.com>
Wed, 26 Sep 2012 10:05:10 +0000 (12:05 +0200)
committerLiu, Jinsong <jinsong.liu@intel.com>
Wed, 26 Sep 2012 10:05:10 +0000 (12:05 +0200)
In our test for win8 guest mce, we find a bug that no matter what
SRAO/SRAR error xen inject to win8 guest, it always reboot.

The root cause is, current Xen vMCE logic inject vMCE# only to vcpu0,
this is not correct for Intel MCE (Under Intel arch, h/w generate MCE#
to all CPUs).

This patch fixes vMCE injection bug, injecting vMCE# to all vcpus on
Intel platforms.

Signed-off-by: Liu, Jinsong <jinsong.liu@intel.com>
- increase flexibility be making new second argument of inject_vmce() a
  VCPU ID rather than just a boolean

Acked-by: Christoph Egger <Christoph.Egger@amd.com> (on just this change)
- fix condition evaluation order in inject_vmce()

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Committed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/cpu/mcheck/mce.h
xen/arch/x86/cpu/mcheck/mce_intel.c
xen/arch/x86/cpu/mcheck/vmce.c

index d9b0647661e8185eda0f09bfa1355af5f40ade06..5b3393485161b2e4fa5cd4781708f22556bcfec3 100644 (file)
@@ -168,7 +168,7 @@ void x86_mcinfo_dump(struct mc_info *mi);
 
 int fill_vmsr_data(struct mcinfo_bank *mc_bank, struct domain *d,
     uint64_t gstatus);
-int inject_vmce(struct domain *d);
+int inject_vmce(struct domain *d, int vcpu);
 
 static inline int mce_vendor_bank_msr(const struct vcpu *v, uint32_t msr)
 {
index 993ec4ce566463892619299e865f80901efd8818..2f7709bd0643fc524e65736680aa597caa153d68 100644 (file)
@@ -359,7 +359,7 @@ static void intel_memerr_dhandler(
                 }
 
                 /* We will inject vMCE to DOMU*/
-                if ( inject_vmce(d) < 0 )
+                if ( inject_vmce(d, -1) < 0 )
                 {
                     mce_printk(MCE_QUIET, "inject vMCE to DOM%d"
                       " failed\n", d->domain_id);
index 4ae2853e61a60ce00ce1a29db99bda3a0b5b6176..1432870e536402df09895c00b15645dab16d431c 100644 (file)
@@ -324,51 +324,39 @@ static int vmce_load_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h)
 HVM_REGISTER_SAVE_RESTORE(VMCE_VCPU, vmce_save_vcpu_ctxt,
                           vmce_load_vcpu_ctxt, 1, HVMSR_PER_VCPU);
 
-int inject_vmce(struct domain *d)
+/*
+ * for Intel MCE, broadcast vMCE to all vcpus
+ * for AMD MCE, only inject vMCE to vcpu0
+ */
+int inject_vmce(struct domain *d, int vcpu)
 {
-    int cpu = smp_processor_id();
+    struct vcpu *v;
 
-    /* PV guest and HVM guest have different vMCE# injection methods. */
-    if ( !test_and_set_bool(d->vcpu[0]->mce_pending) )
+    for_each_vcpu ( d, v )
     {
-        if ( d->is_hvm )
+        if ( vcpu >= 0 && v->vcpu_id != vcpu )
+            continue;
+
+        if ( (is_hvm_domain(d) ||
+              guest_has_trap_callback(d, v->vcpu_id, TRAP_machine_check)) &&
+             !test_and_set_bool(v->mce_pending) )
         {
-            mce_printk(MCE_VERBOSE, "MCE: inject vMCE to HVM DOM %d\n",
-                       d->domain_id);
-            vcpu_kick(d->vcpu[0]);
+            mce_printk(MCE_VERBOSE, "MCE: inject vMCE to d%d:v%d\n",
+                       d->domain_id, v->vcpu_id);
+            vcpu_kick(v);
         }
         else
         {
-            mce_printk(MCE_VERBOSE, "MCE: inject vMCE to PV DOM%d\n",
-                       d->domain_id);
-            if ( guest_has_trap_callback(d, 0, TRAP_machine_check) )
-            {
-                cpumask_copy(d->vcpu[0]->cpu_affinity_tmp,
-                             d->vcpu[0]->cpu_affinity);
-                mce_printk(MCE_VERBOSE, "MCE: CPU%d set affinity, old %d\n",
-                           cpu, d->vcpu[0]->processor);
-                vcpu_set_affinity(d->vcpu[0], cpumask_of(cpu));
-                vcpu_kick(d->vcpu[0]);
-            }
-            else
-            {
-                mce_printk(MCE_VERBOSE,
-                           "MCE: Kill PV guest with No MCE handler\n");
-                domain_crash(d);
-            }
+            mce_printk(MCE_QUIET, "Failed to inject vMCE to d%d:v%d\n",
+                       d->domain_id, v->vcpu_id);
+            return -EBUSY;
         }
+
+        if ( vcpu >= 0 )
+            return 0;
     }
-    else
-    {
-        /* new vMCE comes while first one has not been injected yet,
-         * in this case, inject fail. [We can't lose this vMCE for
-         * the mce node's consistency].
-         */
-        mce_printk(MCE_QUIET, "There's a pending vMCE waiting to be injected "
-                   " to this DOM%d!\n", d->domain_id);
-        return -1;
-    }
-    return 0;
+
+    return v ? -ESRCH : 0;
 }
 
 int fill_vmsr_data(struct mcinfo_bank *mc_bank, struct domain *d,