Skip to contentSkip to conversation

x86: extend some of Intel's recent MCE work to also support AMD

PATCH In review Jan Beulich 2 participants 3 messages Jul 15, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: extend some of Intel's recent MCE work to also support AMD

At least the MSR handling for guests can easily be made shared between the two vendors; likely a lot of the other code in mce_intel.c could also be made common. The goal here, however, is to eliminate the annoying guest-tried-to-modify-msr messages that result from enabling the MCE code on the Linux side.

Additionally (in order for not having to make the same change twice to basically identical code) the patch also merges amd_{fam10,k8}_mcheck_init(), enables the former to also be used for Fam11 (I'd suppose that Fam12 would also need to go here, but I have no data to confirm that), and does some minor (mostly coding style for the code moved around) adjustments.

xen/arch/x86/cpu/mcheck/amd_f10.c +3 -32
@@ -82,45 +82,16 @@ amd_f10_handler(struct mc_info *mi, uint
 	return MCA_EXTINFO_LOCAL;
 }
 
-
-extern void k8_machine_check(struct cpu_user_regs *regs, long error_code);
-
 /* AMD Family10 machine check */
 int amd_f10_mcheck_init(struct cpuinfo_x86 *c) 
 { 
-	uint64_t value;
-	uint32_t i;
-	int cpu_nr;
-
-	if (!cpu_has(c, X86_FEATURE_MCA))
+	if (!amd_k8_mcheck_init(c))
 		return 0;
 
-	x86_mce_vector_register(k8_machine_check);
 	x86_mce_callback_register(amd_f10_handler);
-	cpu_nr = smp_processor_id();
-
-	rdmsrl(MSR_IA32_MCG_CAP, value);
-	if (value & MCG_CTL_P)	/* Control register present ? */
-		wrmsrl (MSR_IA32_MCG_CTL, 0xffffffffffffffffULL);
-	nr_mce_banks = value & MCG_CAP_COUNT;
-
-	for (i = 0; i < nr_mce_banks; i++) {
-		switch (i) {
-		case 4: /* Northbridge */
-			/* Enable error reporting of all errors */
-			wrmsrl(MSR_IA32_MC4_CTL, 0xffffffffffffffffULL);
-			wrmsrl(MSR_IA32_MC4_STATUS, 0x0ULL);
-			break;
 
-		default:
-			/* Enable error reporting of all errors */
-			wrmsrl(MSR_IA32_MC0_CTL + 4 * i, 0xffffffffffffffffULL);
-			wrmsrl(MSR_IA32_MC0_STATUS + 4 * i, 0x0ULL);
-			break;
-		}
-	}
+	printk("CPU%i: AMD Family%xh machine check reporting enabled\n",
+	       smp_processor_id(), c->x86);
 
-	set_in_cr4(X86_CR4_MCE);
-	printk("CPU%i: AMD Family10h machine check reporting enabled.\n", cpu_nr);
 	return 1;
 }
xen/arch/x86/cpu/mcheck/amd_k8.c +17 -14
@@ -70,7 +70,7 @@
 
 
 /* Machine Check Handler for AMD K8 family series */
-void k8_machine_check(struct cpu_user_regs *regs, long error_code)
+static void k8_machine_check(struct cpu_user_regs *regs, long error_code)
 {
 	mcheck_cmn_handler(regs, error_code, mca_allbanks);
 }
@@ -78,29 +78,30 @@ void k8_machine_check(struct cpu_user_re
 /* AMD K8 machine check */
 int amd_k8_mcheck_init(struct cpuinfo_x86 *c)
 {
-	uint64_t value;
 	uint32_t i;
-	int cpu_nr;
 
 	/* Check for PPro style MCA; our caller has confirmed MCE support. */
 	if (!cpu_has(c, X86_FEATURE_MCA))
 		return 0;
 
+	mce_cap_init();
 	x86_mce_vector_register(k8_machine_check);
-	cpu_nr = smp_processor_id();
-
-	rdmsrl(MSR_IA32_MCG_CAP, value);
-	if (value & MCG_CTL_P)	/* Control register present ? */
-		wrmsrl (MSR_IA32_MCG_CTL, 0xffffffffffffffffULL);
-	nr_mce_banks = value & MCG_CAP_COUNT;
 
 	for (i = 0; i < nr_mce_banks; i++) {
 		switch (i) {
 		case 4: /* Northbridge */
-			/* Enable error reporting of all errors */
-			wrmsrl(MSR_IA32_MC4_CTL, 0xffffffffffffffffULL);
-			wrmsrl(MSR_IA32_MC4_STATUS, 0x0ULL);
-			break;
+			if (c->x86 == 0xf) {
+				/*
+				 * Enable error reporting of all errors except
+				 * for GART TBL walk error reporting, which
+				 * trips off incorrectly with IOMMU & 3ware &
+				 * Cerberus.
+				 */
+				wrmsrl(MSR_IA32_MC4_CTL, ~(1ULL << 10));
+				wrmsrl(MSR_IA32_MC4_STATUS, 0x0ULL);
+				break;
+			}
+			/* fall through */
 
 		default:
 			/* Enable error reporting of all errors */
@@ -111,7 +112,9 @@ int amd_k8_mcheck_init(struct cpuinfo_x8
 	}
 
 	set_in_cr4(X86_CR4_MCE);
-	printk("CPU%i: AMD K8 machine check reporting enabled.\n", cpu_nr);
+	if (c->x86 < 0x10 || c->x86 > 0x11)
+		printk("CPU%i: AMD K8 machine check reporting enabled\n",
+		       smp_processor_id());
 
 	return 1;
 }
xen/arch/x86/cpu/mcheck/mce.c +268 -13

315 lines not on this page · raw message

xen/arch/x86/cpu/mcheck/mce.h +5 -0
@@ -25,6 +25,11 @@ void intel_mcheck_timer(struct cpuinfo_x
 void mce_intel_feature_init(struct cpuinfo_x86 *c);
 void amd_nonfatal_mcheck_init(struct cpuinfo_x86 *c);
 
+u64 mce_cap_init(void);
+
+int intel_mce_rdmsr(u32 msr, u32 *lo, u32 *hi);
+int intel_mce_wrmsr(u32 msr, u64 value);
+
 int mce_available(struct cpuinfo_x86 *c);
 int mce_firstbank(struct cpuinfo_x86 *c);
 /* Helper functions used for collecting error telemetry */
xen/arch/x86/cpu/mcheck/mce_intel.c +7 -202

269 lines not on this page · raw message

xen/arch/x86/domain.c +1 -2
@@ -493,8 +493,7 @@ int arch_domain_create(struct domain *d,
             goto fail;
 
         /* For Guest vMCE MSRs virtualization */
-        if ( boot_cpu_data.x86_vendor == X86_VENDOR_INTEL )
-            intel_mce_init_msr(d);
+        mce_init_msr(d);
     }
 
     if ( is_hvm_domain(d) )
xen/arch/x86/hvm/hvm.c +3 -4
@@ -43,6 +43,7 @@
 #include <asm/processor.h>
 #include <asm/types.h>
 #include <asm/msr.h>
+#include <asm/traps.h>
 #include <asm/mc146818rtc.h>
 #include <asm/spinlock.h>
 #include <asm/hvm/hvm.h>
@@ -1773,8 +1774,6 @@ void hvm_rdtsc_intercept(struct cpu_user
     regs->edx = (uint32_t)(tsc >> 32);
 }
 
-extern int intel_mce_rdmsr(u32 msr, u32 *lo, u32 *hi);
-extern int intel_mce_wrmsr(u32 msr, u64 value);
 int hvm_msr_read_intercept(struct cpu_user_regs *regs)
 {
     uint32_t ecx = regs->ecx;
@@ -1852,7 +1851,7 @@ int hvm_msr_read_intercept(struct cpu_us
          break;
 
     default:
-        ret = intel_mce_rdmsr(ecx, &lo, &hi);
+        ret = mce_rdmsr(ecx, &lo, &hi);
         if ( ret < 0 )
             goto gp_fault;
         else if ( ret )
@@ -1951,7 +1950,7 @@ int hvm_msr_write_intercept(struct cpu_u
         break;
 
     default:
-        ret = intel_mce_wrmsr(ecx, msr_content);
+        ret = mce_wrmsr(ecx, msr_content);
         if ( ret < 0 )
             goto gp_fault;
         else if ( ret )
xen/arch/x86/traps.c +13 -18
@@ -1681,7 +1681,8 @@ static int emulate_privileged_op(struct 
     unsigned long *reg, eip = regs->eip, res;
     u8 opcode, modrm_reg = 0, modrm_rm = 0, rep_prefix = 0, lock = 0, rex = 0;
     enum { lm_seg_none, lm_seg_fs, lm_seg_gs } lm_ovr = lm_seg_none;
-    unsigned int port, i, data_sel, ar, data, rc, bpmatch = 0;
+    int rc;
+    unsigned int port, i, data_sel, ar, data, bpmatch = 0;
     unsigned int op_bytes, op_default, ad_bytes, ad_default;
 #define rd_ad(reg) (ad_bytes >= sizeof(regs->reg) \
                     ? regs->reg \
@@ -2246,14 +2247,12 @@ static int emulate_privileged_op(struct 
         default:
             if ( wrmsr_hypervisor_regs(regs->ecx, eax, edx) )
                 break;
-            if ( boot_cpu_data.x86_vendor == X86_VENDOR_INTEL )
-            {
-                int rc = intel_mce_wrmsr(regs->ecx, res);
-                if ( rc < 0 )
-                    goto fail;
-                if ( rc )
-                    break;
-            }
+
+            rc = mce_wrmsr(regs->ecx, res);
+            if ( rc < 0 )
+                goto fail;
+            if ( rc )
+                break;
 
             if ( (rdmsr_safe(regs->ecx, l, h) != 0) ||
                  (eax != l) || (edx != h) )
@@ -2335,15 +2334,11 @@ static int emulate_privileged_op(struct 
                 break;
             }
 
-            if ( boot_cpu_data.x86_vendor == X86_VENDOR_INTEL )
-            {
-                int rc = intel_mce_rdmsr(regs->ecx, &l, &h);
-
-                if ( rc < 0 )
-                    goto fail;
-                if ( rc )
-                    goto rdmsr_writeback;
-            }
+            rc = mce_rdmsr(regs->ecx, &l, &h);
+            if ( rc < 0 )
+                goto fail;
+            if ( rc )
+                goto rdmsr_writeback;
 
             /* Everyone can read the MSR space. */
             /* gdprintk(XENLOG_WARNING,"Domain attempted RDMSR %p.\n",
xen/include/asm-x86/traps.h +4 -4
@@ -47,9 +47,9 @@ extern int guest_has_trap_callback(struc
 extern int send_guest_trap(struct domain *d, uint16_t vcpuid,
 				unsigned int trap_nr);
 
-/* Intel vMCE MSRs virtualization */
-extern void intel_mce_init_msr(struct domain *d);
-extern int intel_mce_wrmsr(u32 msr, u64 value);
-extern int intel_mce_rdmsr(u32 msr, u32 *lo, u32 *hi);
+/* Guest vMCE MSRs virtualization */
+extern void mce_init_msr(struct domain *d);
+extern int mce_wrmsr(u32 msr, u64 value);
+extern int mce_rdmsr(u32 msr, u32 *lo, u32 *hi);
 
 #endif /* ASM_TRAP_H */
#1 lore raw

This is one of your patches that seems not to apply. Perhaps try re-sending as an attachment. Your second MCE patch applied okay.

-- Keir

Quoted 14 lines · Jan Beulich

At least the MSR handling for guests can easily be made shared between the two vendors; likely a lot of the other code in mce_intel.c could also be made common. The goal here, however, is to eliminate the annoying guest-tried-to-modify-msr messages that result from enabling the MCE code on the Linux side.

Additionally (in order for not having to make the same change twice to basically identical code) the patch also merges amd_{fam10,k8}_mcheck_init(), enables the former to also be used for Fam11 (I'd suppose that Fam12 would also need to go here, but I have no data to confirm that), and does some minor (mostly coding style for the code moved around) adjustments.

#2 lore raw

Re: [PATCH] x86: extend some of Intel's recent MCE workto also support AMD

Quoted 3 lines
Quoted 1 line
Quoted 1 line

Keir Fraser <[email protected]> 15.07.09 15:36 >>>

This is one of your patches that seems not to apply. Perhaps try re-sending as an attachment. Your second MCE patch applied okay.

Attached.

If only I knew what it is that's wrong with some of them, but not with others...

Jan

At least the MSR handling for guests can easily be made shared between the two vendors; likely a lot of the other code in mce_intel.c could also be made common. The goal here, however, is to eliminate the annoying guest-tried-to-modify-msr messages that result from enabling the MCE code on the Linux side.

Additionally (in order for not having to make the same change twice to basically identical code) the patch also merges amd_{fam10,k8}_mcheck_init(), enables the former to also be used for Fam11 (I'd suppose that Fam12 would also need to go here, but I have no data to confirm that), and does some minor (mostly coding style for the code moved around) adjustments.

xen/arch/x86/cpu/mcheck/amd_f10.c +3 -32
@@ -82,45 +82,16 @@ amd_f10_handler(struct mc_info *mi, uint
 	return MCA_EXTINFO_LOCAL;
 }
 
-
-extern void k8_machine_check(struct cpu_user_regs *regs, long error_code);
-
 /* AMD Family10 machine check */
 int amd_f10_mcheck_init(struct cpuinfo_x86 *c) 
 { 
-	uint64_t value;
-	uint32_t i;
-	int cpu_nr;
-
-	if (!cpu_has(c, X86_FEATURE_MCA))
+	if (!amd_k8_mcheck_init(c))
 		return 0;
 
-	x86_mce_vector_register(k8_machine_check);
 	x86_mce_callback_register(amd_f10_handler);
-	cpu_nr = smp_processor_id();
-
-	rdmsrl(MSR_IA32_MCG_CAP, value);
-	if (value & MCG_CTL_P)	/* Control register present ? */
-		wrmsrl (MSR_IA32_MCG_CTL, 0xffffffffffffffffULL);
-	nr_mce_banks = value & MCG_CAP_COUNT;
-
-	for (i = 0; i < nr_mce_banks; i++) {
-		switch (i) {
-		case 4: /* Northbridge */
-			/* Enable error reporting of all errors */
-			wrmsrl(MSR_IA32_MC4_CTL, 0xffffffffffffffffULL);
-			wrmsrl(MSR_IA32_MC4_STATUS, 0x0ULL);
-			break;
 
-		default:
-			/* Enable error reporting of all errors */
-			wrmsrl(MSR_IA32_MC0_CTL + 4 * i, 0xffffffffffffffffULL);
-			wrmsrl(MSR_IA32_MC0_STATUS + 4 * i, 0x0ULL);
-			break;
-		}
-	}
+	printk("CPU%i: AMD Family%xh machine check reporting enabled\n",
+	       smp_processor_id(), c->x86);
 
-	set_in_cr4(X86_CR4_MCE);
-	printk("CPU%i: AMD Family10h machine check reporting enabled.\n", cpu_nr);
 	return 1;
 }
xen/arch/x86/cpu/mcheck/amd_k8.c +17 -14
@@ -70,7 +70,7 @@
 
 
 /* Machine Check Handler for AMD K8 family series */
-void k8_machine_check(struct cpu_user_regs *regs, long error_code)
+static void k8_machine_check(struct cpu_user_regs *regs, long error_code)
 {
 	mcheck_cmn_handler(regs, error_code, mca_allbanks);
 }
@@ -78,29 +78,30 @@ void k8_machine_check(struct cpu_user_re
 /* AMD K8 machine check */
 int amd_k8_mcheck_init(struct cpuinfo_x86 *c)
 {
-	uint64_t value;
 	uint32_t i;
-	int cpu_nr;
 
 	/* Check for PPro style MCA; our caller has confirmed MCE support. */
 	if (!cpu_has(c, X86_FEATURE_MCA))
 		return 0;
 
+	mce_cap_init();
 	x86_mce_vector_register(k8_machine_check);
-	cpu_nr = smp_processor_id();
-
-	rdmsrl(MSR_IA32_MCG_CAP, value);
-	if (value & MCG_CTL_P)	/* Control register present ? */
-		wrmsrl (MSR_IA32_MCG_CTL, 0xffffffffffffffffULL);
-	nr_mce_banks = value & MCG_CAP_COUNT;
 
 	for (i = 0; i < nr_mce_banks; i++) {
 		switch (i) {
 		case 4: /* Northbridge */
-			/* Enable error reporting of all errors */
-			wrmsrl(MSR_IA32_MC4_CTL, 0xffffffffffffffffULL);
-			wrmsrl(MSR_IA32_MC4_STATUS, 0x0ULL);
-			break;
+			if (c->x86 == 0xf) {
+				/*
+				 * Enable error reporting of all errors except
+				 * for GART TBL walk error reporting, which
+				 * trips off incorrectly with IOMMU & 3ware &
+				 * Cerberus.
+				 */
+				wrmsrl(MSR_IA32_MC4_CTL, ~(1ULL << 10));
+				wrmsrl(MSR_IA32_MC4_STATUS, 0x0ULL);
+				break;
+			}
+			/* fall through */
 
 		default:
 			/* Enable error reporting of all errors */
@@ -111,7 +112,9 @@ int amd_k8_mcheck_init(struct cpuinfo_x8
 	}
 
 	set_in_cr4(X86_CR4_MCE);
-	printk("CPU%i: AMD K8 machine check reporting enabled.\n", cpu_nr);
+	if (c->x86 < 0x10 || c->x86 > 0x11)
+		printk("CPU%i: AMD K8 machine check reporting enabled\n",
+		       smp_processor_id());
 
 	return 1;
 }
xen/arch/x86/cpu/mcheck/mce.c +268 -13

315 lines not on this page · raw message

xen/arch/x86/cpu/mcheck/mce.h +5 -0
@@ -25,6 +25,11 @@ void intel_mcheck_timer(struct cpuinfo_x
 void mce_intel_feature_init(struct cpuinfo_x86 *c);
 void amd_nonfatal_mcheck_init(struct cpuinfo_x86 *c);
 
+u64 mce_cap_init(void);
+
+int intel_mce_rdmsr(u32 msr, u32 *lo, u32 *hi);
+int intel_mce_wrmsr(u32 msr, u64 value);
+
 int mce_available(struct cpuinfo_x86 *c);
 int mce_firstbank(struct cpuinfo_x86 *c);
 /* Helper functions used for collecting error telemetry */
xen/arch/x86/cpu/mcheck/mce_intel.c +7 -202

269 lines not on this page · raw message

xen/arch/x86/domain.c +1 -2
@@ -493,8 +493,7 @@ int arch_domain_create(struct domain *d,
             goto fail;
 
         /* For Guest vMCE MSRs virtualization */
-        if ( boot_cpu_data.x86_vendor == X86_VENDOR_INTEL )
-            intel_mce_init_msr(d);
+        mce_init_msr(d);
     }
 
     if ( is_hvm_domain(d) )
xen/arch/x86/hvm/hvm.c +3 -4
@@ -43,6 +43,7 @@
 #include <asm/processor.h>
 #include <asm/types.h>
 #include <asm/msr.h>
+#include <asm/traps.h>
 #include <asm/mc146818rtc.h>
 #include <asm/spinlock.h>
 #include <asm/hvm/hvm.h>
@@ -1773,8 +1774,6 @@ void hvm_rdtsc_intercept(struct cpu_user
     regs->edx = (uint32_t)(tsc >> 32);
 }
 
-extern int intel_mce_rdmsr(u32 msr, u32 *lo, u32 *hi);
-extern int intel_mce_wrmsr(u32 msr, u64 value);
 int hvm_msr_read_intercept(struct cpu_user_regs *regs)
 {
     uint32_t ecx = regs->ecx;
@@ -1852,7 +1851,7 @@ int hvm_msr_read_intercept(struct cpu_us
          break;
 
     default:
-        ret = intel_mce_rdmsr(ecx, &lo, &hi);
+        ret = mce_rdmsr(ecx, &lo, &hi);
         if ( ret < 0 )
             goto gp_fault;
         else if ( ret )
@@ -1951,7 +1950,7 @@ int hvm_msr_write_intercept(struct cpu_u
         break;
 
     default:
-        ret = intel_mce_wrmsr(ecx, msr_content);
+        ret = mce_wrmsr(ecx, msr_content);
         if ( ret < 0 )
             goto gp_fault;
         else if ( ret )
xen/arch/x86/traps.c +13 -18
@@ -1681,7 +1681,8 @@ static int emulate_privileged_op(struct 
     unsigned long *reg, eip = regs->eip, res;
     u8 opcode, modrm_reg = 0, modrm_rm = 0, rep_prefix = 0, lock = 0, rex = 0;
     enum { lm_seg_none, lm_seg_fs, lm_seg_gs } lm_ovr = lm_seg_none;
-    unsigned int port, i, data_sel, ar, data, rc, bpmatch = 0;
+    int rc;
+    unsigned int port, i, data_sel, ar, data, bpmatch = 0;
     unsigned int op_bytes, op_default, ad_bytes, ad_default;
 #define rd_ad(reg) (ad_bytes >= sizeof(regs->reg) \
                     ? regs->reg \
@@ -2246,14 +2247,12 @@ static int emulate_privileged_op(struct 
         default:
             if ( wrmsr_hypervisor_regs(regs->ecx, eax, edx) )
                 break;
-            if ( boot_cpu_data.x86_vendor == X86_VENDOR_INTEL )
-            {
-                int rc = intel_mce_wrmsr(regs->ecx, res);
-                if ( rc < 0 )
-                    goto fail;
-                if ( rc )
-                    break;
-            }
+
+            rc = mce_wrmsr(regs->ecx, res);
+            if ( rc < 0 )
+                goto fail;
+            if ( rc )
+                break;
 
             if ( (rdmsr_safe(regs->ecx, l, h) != 0) ||
                  (eax != l) || (edx != h) )
@@ -2335,15 +2334,11 @@ static int emulate_privileged_op(struct 
                 break;
             }
 
-            if ( boot_cpu_data.x86_vendor == X86_VENDOR_INTEL )
-            {
-                int rc = intel_mce_rdmsr(regs->ecx, &l, &h);
-
-                if ( rc < 0 )
-                    goto fail;
-                if ( rc )
-                    goto rdmsr_writeback;
-            }
+            rc = mce_rdmsr(regs->ecx, &l, &h);
+            if ( rc < 0 )
+                goto fail;
+            if ( rc )
+                goto rdmsr_writeback;
 
             /* Everyone can read the MSR space. */
             /* gdprintk(XENLOG_WARNING,"Domain attempted RDMSR %p.\n",
xen/include/asm-x86/traps.h +4 -4
@@ -47,9 +47,9 @@ extern int guest_has_trap_callback(struc
 extern int send_guest_trap(struct domain *d, uint16_t vcpuid,
 				unsigned int trap_nr);
 
-/* Intel vMCE MSRs virtualization */
-extern void intel_mce_init_msr(struct domain *d);
-extern int intel_mce_wrmsr(u32 msr, u64 value);
-extern int intel_mce_rdmsr(u32 msr, u32 *lo, u32 *hi);
+/* Guest vMCE MSRs virtualization */
+extern void mce_init_msr(struct domain *d);
+extern int mce_wrmsr(u32 msr, u64 value);
+extern int mce_rdmsr(u32 msr, u32 *lo, u32 *hi);
 
 #endif /* ASM_TRAP_H */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel