Skip to content

Commit f436f8b

Browse files
author
Ingo Molnar
committed
x86: EDAC: MCE: Fix MCE decoding callback logic
Make decoding of MCEs happen only on AMD hardware by registering a non-default callback only on CPU families which support it. While looking at the interaction of decode_mce() with the other MCE code i also noticed a few other things and made the following cleanups/fixes: - Fixed the mce_decode() weak alias - a weak alias is really not good here, it should be a proper callback. A weak alias will be overriden if a piece of code is built into the kernel - not good, obviously. - The patch initializes the callback on AMD family 10h and 11h. - Added the more correct fallback printk of: No support for human readable MCE decoding on this CPU type. Transcribe the message and run it through 'mcelog --ascii' to decode. On CPUs that dont have a decoder. - Made the surrounding code more readable. Note that the callback allows us to have a default fallback - without having to check the CPU versions during the printout itself. When an EDAC module registers itself, it can install the decode-print function. (there's no unregister needed as this is core code.) version -v2 by Borislav Petkov: - add K8 to the set of supported CPUs - always build in edac_mce_amd since we use an early_initcall now - fix checkpatch warnings Signed-off-by: Borislav Petkov <borislav.petkov@amd.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Andi Kleen <andi@firstfloor.org> LKML-Reference: <20091001141432.GA11410@aftab> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 24e3580 commit f436f8b

4 files changed

Lines changed: 53 additions & 24 deletions

File tree

‎arch/x86/include/asm/mce.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ static inline void winchip_mcheck_init(struct cpuinfo_x86 *c) {}
133133
static inline void enable_p5_mce(void) {}
134134
#endif
135135

136+
extern void (*x86_mce_decode_callback)(struct mce *m);
137+
136138
void mce_setup(struct mce *m);
137139
void mce_log(struct mce *m);
138140
DECLARE_PER_CPU(struct sys_device, mce_dev);

‎arch/x86/kernel/cpu/mcheck/mce.c‎

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ static DECLARE_WAIT_QUEUE_HEAD(mce_wait);
8585
static DEFINE_PER_CPU(struct mce, mces_seen);
8686
static int cpu_missing;
8787

88+
static void default_decode_mce(struct mce *m)
89+
{
90+
pr_emerg("No human readable MCE decoding support on this CPU type.\n");
91+
pr_emerg("Run the message through 'mcelog --ascii' to decode.\n");
92+
}
93+
94+
/*
95+
* CPU/chipset specific EDAC code can register a callback here to print
96+
* MCE errors in a human-readable form:
97+
*/
98+
void (*x86_mce_decode_callback)(struct mce *m) = default_decode_mce;
99+
EXPORT_SYMBOL(x86_mce_decode_callback);
88100

89101
/* MCA banks polled by the period polling timer for corrected events */
90102
DEFINE_PER_CPU(mce_banks_t, mce_poll_banks) = {
@@ -165,46 +177,46 @@ void mce_log(struct mce *mce)
165177
set_bit(0, &mce_need_notify);
166178
}
167179

168-
void __weak decode_mce(struct mce *m)
169-
{
170-
return;
171-
}
172-
173180
static void print_mce(struct mce *m)
174181
{
175-
printk(KERN_EMERG
176-
"CPU %d: Machine Check Exception: %16Lx Bank %d: %016Lx\n",
182+
pr_emerg("CPU %d: Machine Check Exception: %16Lx Bank %d: %016Lx\n",
177183
m->extcpu, m->mcgstatus, m->bank, m->status);
184+
178185
if (m->ip) {
179-
printk(KERN_EMERG "RIP%s %02x:<%016Lx> ",
180-
!(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
181-
m->cs, m->ip);
186+
pr_emerg("RIP%s %02x:<%016Lx> ",
187+
!(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
188+
m->cs, m->ip);
189+
182190
if (m->cs == __KERNEL_CS)
183191
print_symbol("{%s}", m->ip);
184-
printk(KERN_CONT "\n");
192+
pr_cont("\n");
185193
}
186-
printk(KERN_EMERG "TSC %llx ", m->tsc);
194+
195+
pr_emerg("TSC %llx ", m->tsc);
187196
if (m->addr)
188-
printk(KERN_CONT "ADDR %llx ", m->addr);
197+
pr_cont("ADDR %llx ", m->addr);
189198
if (m->misc)
190-
printk(KERN_CONT "MISC %llx ", m->misc);
191-
printk(KERN_CONT "\n");
192-
printk(KERN_EMERG "PROCESSOR %u:%x TIME %llu SOCKET %u APIC %x\n",
193-
m->cpuvendor, m->cpuid, m->time, m->socketid,
194-
m->apicid);
199+
pr_cont("MISC %llx ", m->misc);
200+
201+
pr_cont("\n");
202+
pr_emerg("PROCESSOR %u:%x TIME %llu SOCKET %u APIC %x\n",
203+
m->cpuvendor, m->cpuid, m->time, m->socketid, m->apicid);
195204

196-
decode_mce(m);
205+
/*
206+
* Print out human-readable details about the MCE error,
207+
* (if the CPU has an implementation for that):
208+
*/
209+
x86_mce_decode_callback(m);
197210
}
198211

199212
static void print_mce_head(void)
200213
{
201-
printk(KERN_EMERG "\nHARDWARE ERROR\n");
214+
pr_emerg("\nHARDWARE ERROR\n");
202215
}
203216

204217
static void print_mce_tail(void)
205218
{
206-
printk(KERN_EMERG "This is not a software problem!\n"
207-
"Run through mcelog --ascii to decode and contact your hardware vendor\n");
219+
pr_emerg("This is not a software problem!\n");
208220
}
209221

210222
#define PANIC_TIMEOUT 5 /* 5 seconds */
@@ -218,6 +230,7 @@ static atomic_t mce_fake_paniced;
218230
static void wait_for_panic(void)
219231
{
220232
long timeout = PANIC_TIMEOUT*USEC_PER_SEC;
233+
221234
preempt_disable();
222235
local_irq_enable();
223236
while (timeout-- > 0)
@@ -285,6 +298,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
285298
static int msr_to_offset(u32 msr)
286299
{
287300
unsigned bank = __get_cpu_var(injectm.bank);
301+
288302
if (msr == rip_msr)
289303
return offsetof(struct mce, ip);
290304
if (msr == MSR_IA32_MCx_STATUS(bank))

‎drivers/edac/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ edac_core-objs += edac_pci.o edac_pci_sysfs.o
1818
endif
1919

2020
ifdef CONFIG_CPU_SUP_AMD
21-
edac_core-objs += edac_mce_amd.o
21+
obj-$(CONFIG_X86_MCE) += edac_mce_amd.o
2222
endif
2323

2424
obj-$(CONFIG_EDAC_AMD76X) += amd76x_edac.o

‎drivers/edac/edac_mce_amd.c‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ static inline void amd_decode_err_code(unsigned int ec)
362362
pr_warning("Huh? Unknown MCE error 0x%x\n", ec);
363363
}
364364

365-
void decode_mce(struct mce *m)
365+
static void amd_decode_mce(struct mce *m)
366366
{
367367
struct err_regs regs;
368368
int node, ecc;
@@ -420,3 +420,16 @@ void decode_mce(struct mce *m)
420420

421421
amd_decode_err_code(m->status & 0xffff);
422422
}
423+
424+
static int __init mce_amd_init(void)
425+
{
426+
/*
427+
* We can decode MCEs for Opteron and later CPUs:
428+
*/
429+
if ((boot_cpu_data.x86_vendor == X86_VENDOR_AMD) &&
430+
(boot_cpu_data.x86 >= 0xf))
431+
x86_mce_decode_callback = amd_decode_mce;
432+
433+
return 0;
434+
}
435+
early_initcall(mce_amd_init);

0 commit comments

Comments
 (0)