xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86: MCE fixes
@ 2010-02-09 13:26 Jan Beulich
  0 siblings, 0 replies; only message in thread
From: Jan Beulich @ 2010-02-09 13:26 UTC (permalink / raw)
  To: xen-devel

[-- Attachment #1: Type: text/plain, Size: 3395 bytes --]

- fill_vmsr_data() leaked a domain reference; since the caller already
  obtained one, there's no need to obtain another one here
- intel_UCR_handler() could call put_domain() with a NULL pointer
- mcheck_mca_logout() updated a local data structure that wasn't used
  after the update

Signed-off-by: Jan Beulich <jbeulich@novell.com>

--- 2010-02-09.orig/xen/arch/x86/cpu/mcheck/mce.c	2010-02-03 16:15:15.000000000 +0100
+++ 2010-02-09/xen/arch/x86/cpu/mcheck/mce.c	2010-02-09 09:00:50.000000000 +0100
@@ -300,13 +300,15 @@ mctelem_cookie_t mcheck_mca_logout(enum 
 
 	if (mci != NULL && errcnt > 0) {
 		x86_mcinfo_lookup(mic, mci, MC_TYPE_GLOBAL);
-		mig = (struct mcinfo_global *)mic;
-		if (pcc)
-			mcg.mc_flags |= MC_FLAG_UNCORRECTABLE;
+		mig = container_of(mic, struct mcinfo_global, common);
+		if (mic == NULL)
+			;
+		else if (pcc)
+			mig->mc_flags |= MC_FLAG_UNCORRECTABLE;
 		else if (uc)
-			mcg.mc_flags |= MC_FLAG_RECOVERABLE;
+			mig->mc_flags |= MC_FLAG_RECOVERABLE;
 		else
-			mcg.mc_flags |= MC_FLAG_CORRECTABLE;
+			mig->mc_flags |= MC_FLAG_CORRECTABLE;
 	}
 
 
--- 2010-02-09.orig/xen/arch/x86/cpu/mcheck/mce_intel.c	2010-02-03 16:15:15.000000000 +0100
+++ 2010-02-09/xen/arch/x86/cpu/mcheck/mce_intel.c	2010-02-09 09:16:49.000000000 +0100
@@ -225,22 +225,13 @@ static struct bank_entry* alloc_bank_ent
       for vMCE# MSRs virtualization
 */
 
-static int fill_vmsr_data(struct mcinfo_bank *mc_bank, 
+static int fill_vmsr_data(struct mcinfo_bank *mc_bank, struct domain *d,
         uint64_t gstatus) {
-    struct domain *d;
     struct bank_entry *entry;
 
     /* This error bank impacts one domain, we need to fill domain related
      * data for vMCE MSRs virtualization and vMCE# injection */
     if (mc_bank->mc_domid != (uint16_t)~0) {
-        d = get_domain_by_id(mc_bank->mc_domid);
-
-        /* Not impact a valid domain, skip this error of the bank */
-        if (!d) {
-            mce_printk(MCE_QUIET, "MCE: Not found valid impacted DOM\n");
-            return 0;
-        }
-
         /* For HVM guest, Only when first vMCE is consumed by HVM guest successfully,
          * will we generete another node and inject another vMCE
          */
@@ -365,15 +356,18 @@ static void intel_UCR_handler(struct mci
                           if ( mca_ctl_conflict(bank, d) )
                           {
                               /* Guest has different MCE ctl with hypervisor */
-                              put_domain(d);
+                              if ( d )
+                                  put_domain(d);
                               return;
                           }
 
+                          ASSERT(d);
                           gfn =
                               get_gpfn_from_mfn((bank->mc_addr) >> PAGE_SHIFT);
                           bank->mc_addr =  gfn << PAGE_SHIFT |
                                         (bank->mc_addr & (PAGE_SIZE -1 ));
-                          if (fill_vmsr_data(bank, global->mc_gstatus) == -1)
+                          if ( fill_vmsr_data(bank, d,
+                                              global->mc_gstatus) == -1 )
                           {
                               mce_printk(MCE_QUIET, "Fill vMCE# data for DOM%d "
                                       "failed\n", result->owner);




[-- Attachment #2: x86-mce-domain.patch --]
[-- Type: text/plain, Size: 3389 bytes --]

- fill_vmsr_data() leaked a domain reference; since the caller already
  obtained one, there's no need to obtain another one here
- intel_UCR_handler() could call put_domain() with a NULL pointer
- mcheck_mca_logout() updated a local data structure that wasn't used
  after the update

Signed-off-by: Jan Beulich <jbeulich@novell.com>

--- 2010-02-09.orig/xen/arch/x86/cpu/mcheck/mce.c	2010-02-03 16:15:15.000000000 +0100
+++ 2010-02-09/xen/arch/x86/cpu/mcheck/mce.c	2010-02-09 09:00:50.000000000 +0100
@@ -300,13 +300,15 @@ mctelem_cookie_t mcheck_mca_logout(enum 
 
 	if (mci != NULL && errcnt > 0) {
 		x86_mcinfo_lookup(mic, mci, MC_TYPE_GLOBAL);
-		mig = (struct mcinfo_global *)mic;
-		if (pcc)
-			mcg.mc_flags |= MC_FLAG_UNCORRECTABLE;
+		mig = container_of(mic, struct mcinfo_global, common);
+		if (mic == NULL)
+			;
+		else if (pcc)
+			mig->mc_flags |= MC_FLAG_UNCORRECTABLE;
 		else if (uc)
-			mcg.mc_flags |= MC_FLAG_RECOVERABLE;
+			mig->mc_flags |= MC_FLAG_RECOVERABLE;
 		else
-			mcg.mc_flags |= MC_FLAG_CORRECTABLE;
+			mig->mc_flags |= MC_FLAG_CORRECTABLE;
 	}
 
 
--- 2010-02-09.orig/xen/arch/x86/cpu/mcheck/mce_intel.c	2010-02-03 16:15:15.000000000 +0100
+++ 2010-02-09/xen/arch/x86/cpu/mcheck/mce_intel.c	2010-02-09 09:16:49.000000000 +0100
@@ -225,22 +225,13 @@ static struct bank_entry* alloc_bank_ent
       for vMCE# MSRs virtualization
 */
 
-static int fill_vmsr_data(struct mcinfo_bank *mc_bank, 
+static int fill_vmsr_data(struct mcinfo_bank *mc_bank, struct domain *d,
         uint64_t gstatus) {
-    struct domain *d;
     struct bank_entry *entry;
 
     /* This error bank impacts one domain, we need to fill domain related
      * data for vMCE MSRs virtualization and vMCE# injection */
     if (mc_bank->mc_domid != (uint16_t)~0) {
-        d = get_domain_by_id(mc_bank->mc_domid);
-
-        /* Not impact a valid domain, skip this error of the bank */
-        if (!d) {
-            mce_printk(MCE_QUIET, "MCE: Not found valid impacted DOM\n");
-            return 0;
-        }
-
         /* For HVM guest, Only when first vMCE is consumed by HVM guest successfully,
          * will we generete another node and inject another vMCE
          */
@@ -365,15 +356,18 @@ static void intel_UCR_handler(struct mci
                           if ( mca_ctl_conflict(bank, d) )
                           {
                               /* Guest has different MCE ctl with hypervisor */
-                              put_domain(d);
+                              if ( d )
+                                  put_domain(d);
                               return;
                           }
 
+                          ASSERT(d);
                           gfn =
                               get_gpfn_from_mfn((bank->mc_addr) >> PAGE_SHIFT);
                           bank->mc_addr =  gfn << PAGE_SHIFT |
                                         (bank->mc_addr & (PAGE_SIZE -1 ));
-                          if (fill_vmsr_data(bank, global->mc_gstatus) == -1)
+                          if ( fill_vmsr_data(bank, d,
+                                              global->mc_gstatus) == -1 )
                           {
                               mce_printk(MCE_QUIET, "Fill vMCE# data for DOM%d "
                                       "failed\n", result->owner);

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-02-09 13:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-09 13:26 [PATCH] x86: MCE fixes Jan Beulich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).