2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Machine check handler.
|
2009-04-08 18:31:17 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* K8 parts Copyright 2002,2003 Andi Kleen, SuSE Labs.
|
2007-10-24 04:37:23 +08:00
|
|
|
* Rest from unknown author(s).
|
|
|
|
* 2004 Andi Kleen. Rewrote most of it.
|
2009-02-12 20:43:23 +08:00
|
|
|
* Copyright 2008 Intel Corporation
|
|
|
|
* Author: Andi Kleen
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2009-04-08 18:31:17 +08:00
|
|
|
#include <linux/thread_info.h>
|
|
|
|
#include <linux/capability.h>
|
|
|
|
#include <linux/miscdevice.h>
|
|
|
|
#include <linux/ratelimit.h>
|
|
|
|
#include <linux/kallsyms.h>
|
|
|
|
#include <linux/rcupdate.h>
|
|
|
|
#include <linux/kobject.h>
|
2009-04-30 15:04:51 +08:00
|
|
|
#include <linux/uaccess.h>
|
2009-04-08 18:31:17 +08:00
|
|
|
#include <linux/kdebug.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/percpu.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/sysdev.h>
|
2005-09-13 00:49:24 +08:00
|
|
|
#include <linux/ctype.h>
|
2009-04-08 18:31:17 +08:00
|
|
|
#include <linux/sched.h>
|
2009-02-18 06:07:13 +08:00
|
|
|
#include <linux/sysfs.h>
|
2009-04-08 18:31:17 +08:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kmod.h>
|
|
|
|
#include <linux/poll.h>
|
|
|
|
#include <linux/cpu.h>
|
2009-04-30 15:04:51 +08:00
|
|
|
#include <linux/smp.h>
|
2009-04-08 18:31:17 +08:00
|
|
|
#include <linux/fs.h>
|
|
|
|
|
2007-10-24 04:37:23 +08:00
|
|
|
#include <asm/processor.h>
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
#include <asm/idle.h>
|
2009-04-08 18:31:17 +08:00
|
|
|
#include <asm/mce.h>
|
|
|
|
#include <asm/msr.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-04-08 18:31:26 +08:00
|
|
|
#include "mce.h"
|
|
|
|
|
2009-04-28 01:25:48 +08:00
|
|
|
/* Handle unconfigured int18 (should never happen) */
|
|
|
|
static void unexpected_machine_check(struct pt_regs *regs, long error_code)
|
|
|
|
{
|
|
|
|
printk(KERN_ERR "CPU#%d: Unexpected int18 (Machine Check).\n",
|
|
|
|
smp_processor_id());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Call the installed machine check handler for this CPU setup. */
|
|
|
|
void (*machine_check_vector)(struct pt_regs *, long error_code) =
|
|
|
|
unexpected_machine_check;
|
2009-04-29 04:50:19 +08:00
|
|
|
|
|
|
|
int mce_disabled;
|
|
|
|
|
x86, mce: use 64bit machine check code on 32bit
The 64bit machine check code is in many ways much better than
the 32bit machine check code: it is more specification compliant,
is cleaner, only has a single code base versus one per CPU,
has better infrastructure for recovery, has a cleaner way to communicate
with user space etc. etc.
Use the 64bit code for 32bit too.
This is the second attempt to do this. There was one a couple of years
ago to unify this code for 32bit and 64bit. Back then this ran into some
trouble with K7s and was reverted.
I believe this time the K7 problems (and some others) are addressed.
I went over the old handlers and was very careful to retain
all quirks.
But of course this needs a lot of testing on old systems. On newer
64bit capable systems I don't expect much problems because they have been
already tested with the 64bit kernel.
I made this a CONFIG for now that still allows to select the old
machine check code. This is mostly to make testing easier,
if someone runs into a problem we can ask them to try
with the CONFIG switched.
The new code is default y for more coverage.
Once there is confidence the 64bit code works well on older hardware
too the CONFIG_X86_OLD_MCE and the associated code can be easily
removed.
This causes a behaviour change for 32bit installations. They now
have to install the mcelog package to be able to log
corrected machine checks.
The 64bit machine check code only handles CPUs which support the
standard Intel machine check architecture described in the IA32 SDM.
The 32bit code has special support for some older CPUs which
have non standard machine check architectures, in particular
WinChip C3 and Intel P5. I made those a separate CONFIG option
and kept them for now. The WinChip variant could be probably
removed without too much pain, it doesn't really do anything
interesting. P5 is also disabled by default (like it
was before) because many motherboards have it miswired, but
according to Alan Cox a few embedded setups use that one.
Forward ported/heavily changed version of old patch, original patch
included review/fixes from Thomas Gleixner, Bert Wesarg.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-04-29 01:07:31 +08:00
|
|
|
#ifdef CONFIG_X86_NEW_MCE
|
2009-04-08 18:31:26 +08:00
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
#define MISC_MCELOG_MINOR 227
|
2009-02-18 06:07:13 +08:00
|
|
|
|
2006-04-08 01:49:57 +08:00
|
|
|
atomic_t mce_entry;
|
|
|
|
|
2009-05-28 03:56:52 +08:00
|
|
|
DEFINE_PER_CPU(unsigned, mce_exception_count);
|
|
|
|
|
x86_64: mcelog tolerant level cleanup
Background:
The MCE handler has several paths that it can take, depending on various
conditions of the MCE status and the value of the 'tolerant' knob. The
exact semantics are not well defined and the code is a bit twisty.
Description:
This patch makes the MCE handler's behavior more clear by documenting the
behavior for various 'tolerant' levels. It also fixes or enhances
several small things in the handler. Specifically:
* If RIPV is set it is not safe to restart, so set the 'no way out'
flag rather than the 'kill it' flag.
* Don't panic() on correctable MCEs.
* If the _OVER bit is set *and* the _UC bit is set (meaning possibly
dropped uncorrected errors), set the 'no way out' flag.
* Use EIPV for testing whether an app can be killed (SIGBUS) rather
than RIPV. According to docs, EIPV indicates that the error is
related to the IP, while RIPV simply means the IP is valid to
restart from.
* Don't clear the MCi_STATUS registers until after the panic() path.
This leaves the status bits set after the panic() so clever BIOSes
can find them (and dumb BIOSes can do nothing).
This patch also calls nonseekable_open() in mce_open (as suggested by akpm).
Result:
Tolerant levels behave almost identically to how they always have, but
not it's well defined. There's a slightly higher chance of panic()ing
when multiple errors happen (a good thing, IMHO). If you take an MBE and
panic(), the error status bits are not cleared.
Alternatives:
None.
Testing:
I used software to inject correctable and uncorrectable errors. With
tolerant = 3, the system usually survives. With tolerant = 2, the system
usually panic()s (PCC) but not always. With tolerant = 1, the system
always panic()s. When the system panic()s, the BIOS is able to detect
that the cause of death was an MC4. I was not able to reproduce the
case of a non-PCC error in userspace, with EIPV, with (tolerant < 3).
That will be rare at best.
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:37 +08:00
|
|
|
/*
|
|
|
|
* Tolerant levels:
|
|
|
|
* 0: always panic on uncorrected errors, log corrected errors
|
|
|
|
* 1: panic or SIGBUS on uncorrected errors, log corrected errors
|
|
|
|
* 2: SIGBUS or log uncorrected errors (if possible), log corrected errors
|
|
|
|
* 3: never panic or SIGBUS, log all errors (for testing only)
|
|
|
|
*/
|
2009-04-08 18:31:17 +08:00
|
|
|
static int tolerant = 1;
|
|
|
|
static int banks;
|
|
|
|
static u64 *bank;
|
|
|
|
static unsigned long notify_user;
|
|
|
|
static int rip_msr;
|
|
|
|
static int mce_bootlog = -1;
|
2007-02-13 20:26:23 +08:00
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
static char trigger[128];
|
|
|
|
static char *trigger_argv[2] = { trigger, NULL };
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-04-28 00:37:43 +08:00
|
|
|
static unsigned long dont_init_banks;
|
|
|
|
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
static DECLARE_WAIT_QUEUE_HEAD(mce_wait);
|
|
|
|
|
2009-02-12 20:49:34 +08:00
|
|
|
/* MCA banks polled by the period polling timer for corrected events */
|
|
|
|
DEFINE_PER_CPU(mce_banks_t, mce_poll_banks) = {
|
|
|
|
[0 ... BITS_TO_LONGS(MAX_NR_BANKS)-1] = ~0UL
|
|
|
|
};
|
|
|
|
|
2009-04-28 00:37:43 +08:00
|
|
|
static inline int skip_bank_init(int i)
|
|
|
|
{
|
|
|
|
return i < BITS_PER_LONG && test_bit(i, &dont_init_banks);
|
|
|
|
}
|
|
|
|
|
2009-02-12 20:43:22 +08:00
|
|
|
/* Do initial initialization of a struct mce */
|
|
|
|
void mce_setup(struct mce *m)
|
|
|
|
{
|
|
|
|
memset(m, 0, sizeof(struct mce));
|
2009-05-28 03:56:56 +08:00
|
|
|
m->cpu = m->extcpu = smp_processor_id();
|
2009-02-12 20:43:22 +08:00
|
|
|
rdtscll(m->tsc);
|
2009-05-28 03:56:56 +08:00
|
|
|
/* We hope get_seconds stays lockless */
|
|
|
|
m->time = get_seconds();
|
|
|
|
m->cpuvendor = boot_cpu_data.x86_vendor;
|
|
|
|
m->cpuid = cpuid_eax(1);
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
m->socketid = cpu_data(m->extcpu).phys_proc_id;
|
|
|
|
#endif
|
|
|
|
m->apicid = cpu_data(m->extcpu).initial_apicid;
|
|
|
|
rdmsrl(MSR_IA32_MCG_CAP, m->mcgcap);
|
2009-02-12 20:43:22 +08:00
|
|
|
}
|
|
|
|
|
2009-04-30 01:31:00 +08:00
|
|
|
DEFINE_PER_CPU(struct mce, injectm);
|
|
|
|
EXPORT_PER_CPU_SYMBOL_GPL(injectm);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Lockless MCE logging infrastructure.
|
|
|
|
* This avoids deadlocks on printk locks without having to break locks. Also
|
|
|
|
* separate MCEs from kernel messages to avoid bogus bug reports.
|
|
|
|
*/
|
|
|
|
|
2008-01-30 20:30:30 +08:00
|
|
|
static struct mce_log mcelog = {
|
2009-05-28 03:56:55 +08:00
|
|
|
.signature = MCE_LOG_SIGNATURE,
|
|
|
|
.len = MCE_LOG_LEN,
|
|
|
|
.recordlen = sizeof(struct mce),
|
2007-10-24 04:37:23 +08:00
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
void mce_log(struct mce *mce)
|
|
|
|
{
|
|
|
|
unsigned next, entry;
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
mce->finished = 0;
|
2005-09-30 06:01:27 +08:00
|
|
|
wmb();
|
2005-04-17 06:20:36 +08:00
|
|
|
for (;;) {
|
|
|
|
entry = rcu_dereference(mcelog.next);
|
2005-09-13 00:49:24 +08:00
|
|
|
for (;;) {
|
2009-04-08 18:31:17 +08:00
|
|
|
/*
|
|
|
|
* When the buffer fills up discard new entries.
|
|
|
|
* Assume that the earlier errors are the more
|
|
|
|
* interesting ones:
|
|
|
|
*/
|
2005-09-13 00:49:24 +08:00
|
|
|
if (entry >= MCE_LOG_LEN) {
|
2009-04-30 15:04:51 +08:00
|
|
|
set_bit(MCE_OVERFLOW,
|
|
|
|
(unsigned long *)&mcelog.flags);
|
2005-09-13 00:49:24 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-04-08 18:31:17 +08:00
|
|
|
/* Old left over entry. Skip: */
|
2005-09-13 00:49:24 +08:00
|
|
|
if (mcelog.entry[entry].finished) {
|
|
|
|
entry++;
|
|
|
|
continue;
|
|
|
|
}
|
2005-09-30 06:01:27 +08:00
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
smp_rmb();
|
|
|
|
next = entry + 1;
|
|
|
|
if (cmpxchg(&mcelog.next, entry, next) == entry)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
memcpy(mcelog.entry + entry, mce, sizeof(struct mce));
|
2005-09-30 06:01:27 +08:00
|
|
|
wmb();
|
2005-04-17 06:20:36 +08:00
|
|
|
mcelog.entry[entry].finished = 1;
|
2005-09-30 06:01:27 +08:00
|
|
|
wmb();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
set_bit(0, ¬ify_user);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void print_mce(struct mce *m)
|
|
|
|
{
|
|
|
|
printk(KERN_EMERG "\n"
|
2006-01-12 05:44:48 +08:00
|
|
|
KERN_EMERG "HARDWARE ERROR\n"
|
2005-04-17 06:20:36 +08:00
|
|
|
KERN_EMERG
|
|
|
|
"CPU %d: Machine Check Exception: %16Lx Bank %d: %016Lx\n",
|
2009-05-28 03:56:56 +08:00
|
|
|
m->extcpu, m->mcgstatus, m->bank, m->status);
|
2008-01-30 20:30:56 +08:00
|
|
|
if (m->ip) {
|
2007-10-24 04:37:23 +08:00
|
|
|
printk(KERN_EMERG "RIP%s %02x:<%016Lx> ",
|
2005-04-17 06:20:36 +08:00
|
|
|
!(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
|
2008-01-30 20:30:56 +08:00
|
|
|
m->cs, m->ip);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (m->cs == __KERNEL_CS)
|
2008-01-30 20:30:56 +08:00
|
|
|
print_symbol("{%s}", m->ip);
|
2005-04-17 06:20:36 +08:00
|
|
|
printk("\n");
|
|
|
|
}
|
2009-02-20 07:44:58 +08:00
|
|
|
printk(KERN_EMERG "TSC %llx ", m->tsc);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (m->addr)
|
2009-02-20 07:44:58 +08:00
|
|
|
printk("ADDR %llx ", m->addr);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (m->misc)
|
2009-02-20 07:44:58 +08:00
|
|
|
printk("MISC %llx ", m->misc);
|
2005-04-17 06:20:36 +08:00
|
|
|
printk("\n");
|
2009-05-28 03:56:56 +08:00
|
|
|
printk(KERN_EMERG "PROCESSOR %u:%x TIME %llu SOCKET %u APIC %x\n",
|
|
|
|
m->cpuvendor, m->cpuid, m->time, m->socketid,
|
|
|
|
m->apicid);
|
2006-01-12 05:44:48 +08:00
|
|
|
printk(KERN_EMERG "This is not a software problem!\n");
|
2007-10-24 04:37:23 +08:00
|
|
|
printk(KERN_EMERG "Run through mcelog --ascii to decode "
|
|
|
|
"and contact your hardware vendor\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-04-28 00:01:31 +08:00
|
|
|
static void mce_panic(char *msg, struct mce *backup, u64 start)
|
2007-10-24 04:37:23 +08:00
|
|
|
{
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
|
2009-04-28 20:25:18 +08:00
|
|
|
bust_spinlocks(1);
|
|
|
|
console_verbose();
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < MCE_LOG_LEN; i++) {
|
2009-04-28 00:01:31 +08:00
|
|
|
u64 tsc = mcelog.entry[i].tsc;
|
2007-10-24 04:37:23 +08:00
|
|
|
|
2009-04-28 00:01:31 +08:00
|
|
|
if ((s64)(tsc - start) < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
2007-10-24 04:37:23 +08:00
|
|
|
print_mce(&mcelog.entry[i]);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (backup && mcelog.entry[i].tsc == backup->tsc)
|
|
|
|
backup = NULL;
|
|
|
|
}
|
|
|
|
if (backup)
|
|
|
|
print_mce(backup);
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
panic(msg);
|
2007-10-24 04:37:23 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-04-30 01:31:00 +08:00
|
|
|
/* Support code for software error injection */
|
|
|
|
|
|
|
|
static int msr_to_offset(u32 msr)
|
|
|
|
{
|
|
|
|
unsigned bank = __get_cpu_var(injectm.bank);
|
|
|
|
if (msr == rip_msr)
|
|
|
|
return offsetof(struct mce, ip);
|
|
|
|
if (msr == MSR_IA32_MC0_STATUS + bank*4)
|
|
|
|
return offsetof(struct mce, status);
|
|
|
|
if (msr == MSR_IA32_MC0_ADDR + bank*4)
|
|
|
|
return offsetof(struct mce, addr);
|
|
|
|
if (msr == MSR_IA32_MC0_MISC + bank*4)
|
|
|
|
return offsetof(struct mce, misc);
|
|
|
|
if (msr == MSR_IA32_MCG_STATUS)
|
|
|
|
return offsetof(struct mce, mcgstatus);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-04-30 01:29:12 +08:00
|
|
|
/* MSR access wrappers used for error injection */
|
|
|
|
static u64 mce_rdmsrl(u32 msr)
|
|
|
|
{
|
|
|
|
u64 v;
|
2009-04-30 01:31:00 +08:00
|
|
|
if (__get_cpu_var(injectm).finished) {
|
|
|
|
int offset = msr_to_offset(msr);
|
|
|
|
if (offset < 0)
|
|
|
|
return 0;
|
|
|
|
return *(u64 *)((char *)&__get_cpu_var(injectm) + offset);
|
|
|
|
}
|
2009-04-30 01:29:12 +08:00
|
|
|
rdmsrl(msr, v);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mce_wrmsrl(u32 msr, u64 v)
|
|
|
|
{
|
2009-04-30 01:31:00 +08:00
|
|
|
if (__get_cpu_var(injectm).finished) {
|
|
|
|
int offset = msr_to_offset(msr);
|
|
|
|
if (offset >= 0)
|
|
|
|
*(u64 *)((char *)&__get_cpu_var(injectm) + offset) = v;
|
|
|
|
return;
|
|
|
|
}
|
2009-04-30 01:29:12 +08:00
|
|
|
wrmsrl(msr, v);
|
|
|
|
}
|
|
|
|
|
2009-02-12 20:49:36 +08:00
|
|
|
int mce_available(struct cpuinfo_x86 *c)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-04-29 04:50:19 +08:00
|
|
|
if (mce_disabled)
|
2009-02-12 20:39:30 +08:00
|
|
|
return 0;
|
2006-03-24 19:15:11 +08:00
|
|
|
return cpu_has(c, X86_FEATURE_MCE) && cpu_has(c, X86_FEATURE_MCA);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:25:09 +08:00
|
|
|
static inline void mce_get_rip(struct mce *m, struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
if (regs && (m->mcgstatus & MCG_STATUS_RIPV)) {
|
2008-01-30 20:30:56 +08:00
|
|
|
m->ip = regs->ip;
|
2005-04-17 06:25:09 +08:00
|
|
|
m->cs = regs->cs;
|
|
|
|
} else {
|
2008-01-30 20:30:56 +08:00
|
|
|
m->ip = 0;
|
2005-04-17 06:25:09 +08:00
|
|
|
m->cs = 0;
|
|
|
|
}
|
|
|
|
if (rip_msr) {
|
|
|
|
/* Assume the RIP in the MSR is exact. Is this true? */
|
|
|
|
m->mcgstatus |= MCG_STATUS_EIPV;
|
2009-04-30 01:29:12 +08:00
|
|
|
m->ip = mce_rdmsrl(rip_msr);
|
2005-04-17 06:25:09 +08:00
|
|
|
m->cs = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-28 03:56:57 +08:00
|
|
|
DEFINE_PER_CPU(unsigned, mce_poll_count);
|
|
|
|
|
2007-10-24 04:37:23 +08:00
|
|
|
/*
|
2009-02-12 20:43:23 +08:00
|
|
|
* Poll for corrected events or events that happened before reset.
|
|
|
|
* Those are just logged through /dev/mcelog.
|
|
|
|
*
|
|
|
|
* This is executed in standard interrupt context.
|
|
|
|
*/
|
2009-02-12 20:49:34 +08:00
|
|
|
void machine_check_poll(enum mcp_flags flags, mce_banks_t *b)
|
2009-02-12 20:43:23 +08:00
|
|
|
{
|
|
|
|
struct mce m;
|
|
|
|
int i;
|
|
|
|
|
2009-05-28 03:56:57 +08:00
|
|
|
__get_cpu_var(mce_poll_count)++;
|
|
|
|
|
2009-02-12 20:43:23 +08:00
|
|
|
mce_setup(&m);
|
|
|
|
|
2009-04-30 01:29:12 +08:00
|
|
|
m.mcgstatus = mce_rdmsrl(MSR_IA32_MCG_STATUS);
|
2009-02-12 20:43:23 +08:00
|
|
|
for (i = 0; i < banks; i++) {
|
2009-02-12 20:49:34 +08:00
|
|
|
if (!bank[i] || !test_bit(i, *b))
|
2009-02-12 20:43:23 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
m.misc = 0;
|
|
|
|
m.addr = 0;
|
|
|
|
m.bank = i;
|
|
|
|
m.tsc = 0;
|
|
|
|
|
|
|
|
barrier();
|
2009-04-30 01:29:12 +08:00
|
|
|
m.status = mce_rdmsrl(MSR_IA32_MC0_STATUS + i*4);
|
2009-02-12 20:43:23 +08:00
|
|
|
if (!(m.status & MCI_STATUS_VAL))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Uncorrected events are handled by the exception handler
|
|
|
|
* when it is enabled. But when the exception is disabled log
|
|
|
|
* everything.
|
|
|
|
*
|
|
|
|
* TBD do the same check for MCI_STATUS_EN here?
|
|
|
|
*/
|
|
|
|
if ((m.status & MCI_STATUS_UC) && !(flags & MCP_UC))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (m.status & MCI_STATUS_MISCV)
|
2009-04-30 01:29:12 +08:00
|
|
|
m.misc = mce_rdmsrl(MSR_IA32_MC0_MISC + i*4);
|
2009-02-12 20:43:23 +08:00
|
|
|
if (m.status & MCI_STATUS_ADDRV)
|
2009-04-30 01:29:12 +08:00
|
|
|
m.addr = mce_rdmsrl(MSR_IA32_MC0_ADDR + i*4);
|
2009-02-12 20:43:23 +08:00
|
|
|
|
|
|
|
if (!(flags & MCP_TIMESTAMP))
|
|
|
|
m.tsc = 0;
|
|
|
|
/*
|
|
|
|
* Don't get the IP here because it's unlikely to
|
|
|
|
* have anything to do with the actual error location.
|
|
|
|
*/
|
2009-04-07 23:06:55 +08:00
|
|
|
if (!(flags & MCP_DONTLOG)) {
|
|
|
|
mce_log(&m);
|
|
|
|
add_taint(TAINT_MACHINE_CHECK);
|
|
|
|
}
|
2009-02-12 20:43:23 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear state for this bank.
|
|
|
|
*/
|
2009-04-30 01:29:12 +08:00
|
|
|
mce_wrmsrl(MSR_IA32_MC0_STATUS+4*i, 0);
|
2009-02-12 20:43:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't clear MCG_STATUS here because it's only defined for
|
|
|
|
* exceptions.
|
|
|
|
*/
|
2009-05-28 03:56:51 +08:00
|
|
|
|
|
|
|
sync_core();
|
2009-02-12 20:43:23 +08:00
|
|
|
}
|
2009-04-30 01:31:00 +08:00
|
|
|
EXPORT_SYMBOL_GPL(machine_check_poll);
|
2009-02-12 20:43:23 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The actual machine check handler. This only handles real
|
|
|
|
* exceptions when something got corrupted coming in through int 18.
|
|
|
|
*
|
|
|
|
* This is executed in NMI context not subject to normal locking rules. This
|
|
|
|
* implies that most kernel services cannot be safely used. Don't even
|
|
|
|
* think about putting a printk in there!
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2009-04-08 18:31:17 +08:00
|
|
|
void do_machine_check(struct pt_regs *regs, long error_code)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct mce m, panicm;
|
2009-04-08 18:31:17 +08:00
|
|
|
int panicm_found = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
u64 mcestart = 0;
|
|
|
|
int i;
|
x86_64: mcelog tolerant level cleanup
Background:
The MCE handler has several paths that it can take, depending on various
conditions of the MCE status and the value of the 'tolerant' knob. The
exact semantics are not well defined and the code is a bit twisty.
Description:
This patch makes the MCE handler's behavior more clear by documenting the
behavior for various 'tolerant' levels. It also fixes or enhances
several small things in the handler. Specifically:
* If RIPV is set it is not safe to restart, so set the 'no way out'
flag rather than the 'kill it' flag.
* Don't panic() on correctable MCEs.
* If the _OVER bit is set *and* the _UC bit is set (meaning possibly
dropped uncorrected errors), set the 'no way out' flag.
* Use EIPV for testing whether an app can be killed (SIGBUS) rather
than RIPV. According to docs, EIPV indicates that the error is
related to the IP, while RIPV simply means the IP is valid to
restart from.
* Don't clear the MCi_STATUS registers until after the panic() path.
This leaves the status bits set after the panic() so clever BIOSes
can find them (and dumb BIOSes can do nothing).
This patch also calls nonseekable_open() in mce_open (as suggested by akpm).
Result:
Tolerant levels behave almost identically to how they always have, but
not it's well defined. There's a slightly higher chance of panic()ing
when multiple errors happen (a good thing, IMHO). If you take an MBE and
panic(), the error status bits are not cleared.
Alternatives:
None.
Testing:
I used software to inject correctable and uncorrectable errors. With
tolerant = 3, the system usually survives. With tolerant = 2, the system
usually panic()s (PCC) but not always. With tolerant = 1, the system
always panic()s. When the system panic()s, the BIOS is able to detect
that the cause of death was an MC4. I was not able to reproduce the
case of a non-PCC error in userspace, with EIPV, with (tolerant < 3).
That will be rare at best.
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:37 +08:00
|
|
|
/*
|
|
|
|
* If no_way_out gets set, there is no safe way to recover from this
|
|
|
|
* MCE. If tolerant is cranked up, we'll try anyway.
|
|
|
|
*/
|
|
|
|
int no_way_out = 0;
|
|
|
|
/*
|
|
|
|
* If kill_it gets set, there might be a way to recover from this
|
|
|
|
* error.
|
|
|
|
*/
|
|
|
|
int kill_it = 0;
|
2009-02-12 20:43:23 +08:00
|
|
|
DECLARE_BITMAP(toclear, MAX_NR_BANKS);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-04-08 01:49:57 +08:00
|
|
|
atomic_inc(&mce_entry);
|
|
|
|
|
2009-05-28 03:56:52 +08:00
|
|
|
__get_cpu_var(mce_exception_count)++;
|
|
|
|
|
2009-02-12 20:43:23 +08:00
|
|
|
if (notify_die(DIE_NMI, "machine check", regs, error_code,
|
2008-01-30 20:31:23 +08:00
|
|
|
18, SIGKILL) == NOTIFY_STOP)
|
2009-05-28 03:56:53 +08:00
|
|
|
goto out;
|
2009-02-12 20:43:23 +08:00
|
|
|
if (!banks)
|
2009-05-28 03:56:53 +08:00
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-02-12 20:43:22 +08:00
|
|
|
mce_setup(&m);
|
|
|
|
|
2009-04-30 01:29:12 +08:00
|
|
|
m.mcgstatus = mce_rdmsrl(MSR_IA32_MCG_STATUS);
|
2009-04-08 18:31:17 +08:00
|
|
|
|
x86_64: mcelog tolerant level cleanup
Background:
The MCE handler has several paths that it can take, depending on various
conditions of the MCE status and the value of the 'tolerant' knob. The
exact semantics are not well defined and the code is a bit twisty.
Description:
This patch makes the MCE handler's behavior more clear by documenting the
behavior for various 'tolerant' levels. It also fixes or enhances
several small things in the handler. Specifically:
* If RIPV is set it is not safe to restart, so set the 'no way out'
flag rather than the 'kill it' flag.
* Don't panic() on correctable MCEs.
* If the _OVER bit is set *and* the _UC bit is set (meaning possibly
dropped uncorrected errors), set the 'no way out' flag.
* Use EIPV for testing whether an app can be killed (SIGBUS) rather
than RIPV. According to docs, EIPV indicates that the error is
related to the IP, while RIPV simply means the IP is valid to
restart from.
* Don't clear the MCi_STATUS registers until after the panic() path.
This leaves the status bits set after the panic() so clever BIOSes
can find them (and dumb BIOSes can do nothing).
This patch also calls nonseekable_open() in mce_open (as suggested by akpm).
Result:
Tolerant levels behave almost identically to how they always have, but
not it's well defined. There's a slightly higher chance of panic()ing
when multiple errors happen (a good thing, IMHO). If you take an MBE and
panic(), the error status bits are not cleared.
Alternatives:
None.
Testing:
I used software to inject correctable and uncorrectable errors. With
tolerant = 3, the system usually survives. With tolerant = 2, the system
usually panic()s (PCC) but not always. With tolerant = 1, the system
always panic()s. When the system panic()s, the BIOS is able to detect
that the cause of death was an MC4. I was not able to reproduce the
case of a non-PCC error in userspace, with EIPV, with (tolerant < 3).
That will be rare at best.
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:37 +08:00
|
|
|
/* if the restart IP is not valid, we're done for */
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!(m.mcgstatus & MCG_STATUS_RIPV))
|
x86_64: mcelog tolerant level cleanup
Background:
The MCE handler has several paths that it can take, depending on various
conditions of the MCE status and the value of the 'tolerant' knob. The
exact semantics are not well defined and the code is a bit twisty.
Description:
This patch makes the MCE handler's behavior more clear by documenting the
behavior for various 'tolerant' levels. It also fixes or enhances
several small things in the handler. Specifically:
* If RIPV is set it is not safe to restart, so set the 'no way out'
flag rather than the 'kill it' flag.
* Don't panic() on correctable MCEs.
* If the _OVER bit is set *and* the _UC bit is set (meaning possibly
dropped uncorrected errors), set the 'no way out' flag.
* Use EIPV for testing whether an app can be killed (SIGBUS) rather
than RIPV. According to docs, EIPV indicates that the error is
related to the IP, while RIPV simply means the IP is valid to
restart from.
* Don't clear the MCi_STATUS registers until after the panic() path.
This leaves the status bits set after the panic() so clever BIOSes
can find them (and dumb BIOSes can do nothing).
This patch also calls nonseekable_open() in mce_open (as suggested by akpm).
Result:
Tolerant levels behave almost identically to how they always have, but
not it's well defined. There's a slightly higher chance of panic()ing
when multiple errors happen (a good thing, IMHO). If you take an MBE and
panic(), the error status bits are not cleared.
Alternatives:
None.
Testing:
I used software to inject correctable and uncorrectable errors. With
tolerant = 3, the system usually survives. With tolerant = 2, the system
usually panic()s (PCC) but not always. With tolerant = 1, the system
always panic()s. When the system panic()s, the BIOS is able to detect
that the cause of death was an MC4. I was not able to reproduce the
case of a non-PCC error in userspace, with EIPV, with (tolerant < 3).
That will be rare at best.
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:37 +08:00
|
|
|
no_way_out = 1;
|
2007-10-24 04:37:23 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
rdtscll(mcestart);
|
|
|
|
barrier();
|
|
|
|
|
|
|
|
for (i = 0; i < banks; i++) {
|
2009-02-12 20:43:23 +08:00
|
|
|
__clear_bit(i, toclear);
|
2009-02-18 06:07:13 +08:00
|
|
|
if (!bank[i])
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
2007-10-24 04:37:23 +08:00
|
|
|
|
|
|
|
m.misc = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
m.addr = 0;
|
|
|
|
m.bank = i;
|
|
|
|
|
2009-04-30 01:29:12 +08:00
|
|
|
m.status = mce_rdmsrl(MSR_IA32_MC0_STATUS + i*4);
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((m.status & MCI_STATUS_VAL) == 0)
|
|
|
|
continue;
|
|
|
|
|
2009-02-12 20:43:23 +08:00
|
|
|
/*
|
|
|
|
* Non uncorrected errors are handled by machine_check_poll
|
|
|
|
* Leave them alone.
|
|
|
|
*/
|
|
|
|
if ((m.status & MCI_STATUS_UC) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set taint even when machine check was not enabled.
|
|
|
|
*/
|
|
|
|
add_taint(TAINT_MACHINE_CHECK);
|
|
|
|
|
|
|
|
__set_bit(i, toclear);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (m.status & MCI_STATUS_EN) {
|
x86_64: mcelog tolerant level cleanup
Background:
The MCE handler has several paths that it can take, depending on various
conditions of the MCE status and the value of the 'tolerant' knob. The
exact semantics are not well defined and the code is a bit twisty.
Description:
This patch makes the MCE handler's behavior more clear by documenting the
behavior for various 'tolerant' levels. It also fixes or enhances
several small things in the handler. Specifically:
* If RIPV is set it is not safe to restart, so set the 'no way out'
flag rather than the 'kill it' flag.
* Don't panic() on correctable MCEs.
* If the _OVER bit is set *and* the _UC bit is set (meaning possibly
dropped uncorrected errors), set the 'no way out' flag.
* Use EIPV for testing whether an app can be killed (SIGBUS) rather
than RIPV. According to docs, EIPV indicates that the error is
related to the IP, while RIPV simply means the IP is valid to
restart from.
* Don't clear the MCi_STATUS registers until after the panic() path.
This leaves the status bits set after the panic() so clever BIOSes
can find them (and dumb BIOSes can do nothing).
This patch also calls nonseekable_open() in mce_open (as suggested by akpm).
Result:
Tolerant levels behave almost identically to how they always have, but
not it's well defined. There's a slightly higher chance of panic()ing
when multiple errors happen (a good thing, IMHO). If you take an MBE and
panic(), the error status bits are not cleared.
Alternatives:
None.
Testing:
I used software to inject correctable and uncorrectable errors. With
tolerant = 3, the system usually survives. With tolerant = 2, the system
usually panic()s (PCC) but not always. With tolerant = 1, the system
always panic()s. When the system panic()s, the BIOS is able to detect
that the cause of death was an MC4. I was not able to reproduce the
case of a non-PCC error in userspace, with EIPV, with (tolerant < 3).
That will be rare at best.
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:37 +08:00
|
|
|
/* if PCC was set, there's no way out */
|
|
|
|
no_way_out |= !!(m.status & MCI_STATUS_PCC);
|
|
|
|
/*
|
|
|
|
* If this error was uncorrectable and there was
|
|
|
|
* an overflow, we're in trouble. If no overflow,
|
|
|
|
* we might get away with just killing a task.
|
|
|
|
*/
|
|
|
|
if (m.status & MCI_STATUS_UC) {
|
|
|
|
if (tolerant < 1 || m.status & MCI_STATUS_OVER)
|
|
|
|
no_way_out = 1;
|
|
|
|
kill_it = 1;
|
|
|
|
}
|
2009-02-12 20:43:23 +08:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Machine check event was not enabled. Clear, but
|
|
|
|
* ignore.
|
|
|
|
*/
|
|
|
|
continue;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m.status & MCI_STATUS_MISCV)
|
2009-04-30 01:29:12 +08:00
|
|
|
m.misc = mce_rdmsrl(MSR_IA32_MC0_MISC + i*4);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (m.status & MCI_STATUS_ADDRV)
|
2009-04-30 01:29:12 +08:00
|
|
|
m.addr = mce_rdmsrl(MSR_IA32_MC0_ADDR + i*4);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-04-17 06:25:09 +08:00
|
|
|
mce_get_rip(&m, regs);
|
2009-02-12 20:43:23 +08:00
|
|
|
mce_log(&m);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
/*
|
|
|
|
* Did this bank cause the exception?
|
|
|
|
*
|
|
|
|
* Assume that the bank with uncorrectable errors did it,
|
|
|
|
* and that there is only a single one:
|
|
|
|
*/
|
|
|
|
if ((m.status & MCI_STATUS_UC) &&
|
|
|
|
(m.status & MCI_STATUS_EN)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
panicm = m;
|
|
|
|
panicm_found = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
/*
|
|
|
|
* If we didn't find an uncorrectable error, pick
|
|
|
|
* the last one (shouldn't happen, just being safe).
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!panicm_found)
|
|
|
|
panicm = m;
|
x86_64: mcelog tolerant level cleanup
Background:
The MCE handler has several paths that it can take, depending on various
conditions of the MCE status and the value of the 'tolerant' knob. The
exact semantics are not well defined and the code is a bit twisty.
Description:
This patch makes the MCE handler's behavior more clear by documenting the
behavior for various 'tolerant' levels. It also fixes or enhances
several small things in the handler. Specifically:
* If RIPV is set it is not safe to restart, so set the 'no way out'
flag rather than the 'kill it' flag.
* Don't panic() on correctable MCEs.
* If the _OVER bit is set *and* the _UC bit is set (meaning possibly
dropped uncorrected errors), set the 'no way out' flag.
* Use EIPV for testing whether an app can be killed (SIGBUS) rather
than RIPV. According to docs, EIPV indicates that the error is
related to the IP, while RIPV simply means the IP is valid to
restart from.
* Don't clear the MCi_STATUS registers until after the panic() path.
This leaves the status bits set after the panic() so clever BIOSes
can find them (and dumb BIOSes can do nothing).
This patch also calls nonseekable_open() in mce_open (as suggested by akpm).
Result:
Tolerant levels behave almost identically to how they always have, but
not it's well defined. There's a slightly higher chance of panic()ing
when multiple errors happen (a good thing, IMHO). If you take an MBE and
panic(), the error status bits are not cleared.
Alternatives:
None.
Testing:
I used software to inject correctable and uncorrectable errors. With
tolerant = 3, the system usually survives. With tolerant = 2, the system
usually panic()s (PCC) but not always. With tolerant = 1, the system
always panic()s. When the system panic()s, the BIOS is able to detect
that the cause of death was an MC4. I was not able to reproduce the
case of a non-PCC error in userspace, with EIPV, with (tolerant < 3).
That will be rare at best.
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:37 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have decided that we just CAN'T continue, and the user
|
2009-04-08 18:31:17 +08:00
|
|
|
* has not set tolerant to an insane level, give up and die.
|
x86_64: mcelog tolerant level cleanup
Background:
The MCE handler has several paths that it can take, depending on various
conditions of the MCE status and the value of the 'tolerant' knob. The
exact semantics are not well defined and the code is a bit twisty.
Description:
This patch makes the MCE handler's behavior more clear by documenting the
behavior for various 'tolerant' levels. It also fixes or enhances
several small things in the handler. Specifically:
* If RIPV is set it is not safe to restart, so set the 'no way out'
flag rather than the 'kill it' flag.
* Don't panic() on correctable MCEs.
* If the _OVER bit is set *and* the _UC bit is set (meaning possibly
dropped uncorrected errors), set the 'no way out' flag.
* Use EIPV for testing whether an app can be killed (SIGBUS) rather
than RIPV. According to docs, EIPV indicates that the error is
related to the IP, while RIPV simply means the IP is valid to
restart from.
* Don't clear the MCi_STATUS registers until after the panic() path.
This leaves the status bits set after the panic() so clever BIOSes
can find them (and dumb BIOSes can do nothing).
This patch also calls nonseekable_open() in mce_open (as suggested by akpm).
Result:
Tolerant levels behave almost identically to how they always have, but
not it's well defined. There's a slightly higher chance of panic()ing
when multiple errors happen (a good thing, IMHO). If you take an MBE and
panic(), the error status bits are not cleared.
Alternatives:
None.
Testing:
I used software to inject correctable and uncorrectable errors. With
tolerant = 3, the system usually survives. With tolerant = 2, the system
usually panic()s (PCC) but not always. With tolerant = 1, the system
always panic()s. When the system panic()s, the BIOS is able to detect
that the cause of death was an MC4. I was not able to reproduce the
case of a non-PCC error in userspace, with EIPV, with (tolerant < 3).
That will be rare at best.
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:37 +08:00
|
|
|
*/
|
|
|
|
if (no_way_out && tolerant < 3)
|
2005-04-17 06:20:36 +08:00
|
|
|
mce_panic("Machine check", &panicm, mcestart);
|
x86_64: mcelog tolerant level cleanup
Background:
The MCE handler has several paths that it can take, depending on various
conditions of the MCE status and the value of the 'tolerant' knob. The
exact semantics are not well defined and the code is a bit twisty.
Description:
This patch makes the MCE handler's behavior more clear by documenting the
behavior for various 'tolerant' levels. It also fixes or enhances
several small things in the handler. Specifically:
* If RIPV is set it is not safe to restart, so set the 'no way out'
flag rather than the 'kill it' flag.
* Don't panic() on correctable MCEs.
* If the _OVER bit is set *and* the _UC bit is set (meaning possibly
dropped uncorrected errors), set the 'no way out' flag.
* Use EIPV for testing whether an app can be killed (SIGBUS) rather
than RIPV. According to docs, EIPV indicates that the error is
related to the IP, while RIPV simply means the IP is valid to
restart from.
* Don't clear the MCi_STATUS registers until after the panic() path.
This leaves the status bits set after the panic() so clever BIOSes
can find them (and dumb BIOSes can do nothing).
This patch also calls nonseekable_open() in mce_open (as suggested by akpm).
Result:
Tolerant levels behave almost identically to how they always have, but
not it's well defined. There's a slightly higher chance of panic()ing
when multiple errors happen (a good thing, IMHO). If you take an MBE and
panic(), the error status bits are not cleared.
Alternatives:
None.
Testing:
I used software to inject correctable and uncorrectable errors. With
tolerant = 3, the system usually survives. With tolerant = 2, the system
usually panic()s (PCC) but not always. With tolerant = 1, the system
always panic()s. When the system panic()s, the BIOS is able to detect
that the cause of death was an MC4. I was not able to reproduce the
case of a non-PCC error in userspace, with EIPV, with (tolerant < 3).
That will be rare at best.
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:37 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the error seems to be unrecoverable, something should be
|
|
|
|
* done. Try to kill as little as possible. If we can kill just
|
|
|
|
* one task, do that. If the user has set the tolerance very
|
|
|
|
* high, don't try to do anything at all.
|
|
|
|
*/
|
|
|
|
if (kill_it && tolerant < 3) {
|
2005-04-17 06:20:36 +08:00
|
|
|
int user_space = 0;
|
|
|
|
|
x86_64: mcelog tolerant level cleanup
Background:
The MCE handler has several paths that it can take, depending on various
conditions of the MCE status and the value of the 'tolerant' knob. The
exact semantics are not well defined and the code is a bit twisty.
Description:
This patch makes the MCE handler's behavior more clear by documenting the
behavior for various 'tolerant' levels. It also fixes or enhances
several small things in the handler. Specifically:
* If RIPV is set it is not safe to restart, so set the 'no way out'
flag rather than the 'kill it' flag.
* Don't panic() on correctable MCEs.
* If the _OVER bit is set *and* the _UC bit is set (meaning possibly
dropped uncorrected errors), set the 'no way out' flag.
* Use EIPV for testing whether an app can be killed (SIGBUS) rather
than RIPV. According to docs, EIPV indicates that the error is
related to the IP, while RIPV simply means the IP is valid to
restart from.
* Don't clear the MCi_STATUS registers until after the panic() path.
This leaves the status bits set after the panic() so clever BIOSes
can find them (and dumb BIOSes can do nothing).
This patch also calls nonseekable_open() in mce_open (as suggested by akpm).
Result:
Tolerant levels behave almost identically to how they always have, but
not it's well defined. There's a slightly higher chance of panic()ing
when multiple errors happen (a good thing, IMHO). If you take an MBE and
panic(), the error status bits are not cleared.
Alternatives:
None.
Testing:
I used software to inject correctable and uncorrectable errors. With
tolerant = 3, the system usually survives. With tolerant = 2, the system
usually panic()s (PCC) but not always. With tolerant = 1, the system
always panic()s. When the system panic()s, the BIOS is able to detect
that the cause of death was an MC4. I was not able to reproduce the
case of a non-PCC error in userspace, with EIPV, with (tolerant < 3).
That will be rare at best.
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:37 +08:00
|
|
|
/*
|
|
|
|
* If the EIPV bit is set, it means the saved IP is the
|
|
|
|
* instruction which caused the MCE.
|
|
|
|
*/
|
|
|
|
if (m.mcgstatus & MCG_STATUS_EIPV)
|
2008-01-30 20:30:56 +08:00
|
|
|
user_space = panicm.ip && (panicm.cs & 3);
|
x86_64: mcelog tolerant level cleanup
Background:
The MCE handler has several paths that it can take, depending on various
conditions of the MCE status and the value of the 'tolerant' knob. The
exact semantics are not well defined and the code is a bit twisty.
Description:
This patch makes the MCE handler's behavior more clear by documenting the
behavior for various 'tolerant' levels. It also fixes or enhances
several small things in the handler. Specifically:
* If RIPV is set it is not safe to restart, so set the 'no way out'
flag rather than the 'kill it' flag.
* Don't panic() on correctable MCEs.
* If the _OVER bit is set *and* the _UC bit is set (meaning possibly
dropped uncorrected errors), set the 'no way out' flag.
* Use EIPV for testing whether an app can be killed (SIGBUS) rather
than RIPV. According to docs, EIPV indicates that the error is
related to the IP, while RIPV simply means the IP is valid to
restart from.
* Don't clear the MCi_STATUS registers until after the panic() path.
This leaves the status bits set after the panic() so clever BIOSes
can find them (and dumb BIOSes can do nothing).
This patch also calls nonseekable_open() in mce_open (as suggested by akpm).
Result:
Tolerant levels behave almost identically to how they always have, but
not it's well defined. There's a slightly higher chance of panic()ing
when multiple errors happen (a good thing, IMHO). If you take an MBE and
panic(), the error status bits are not cleared.
Alternatives:
None.
Testing:
I used software to inject correctable and uncorrectable errors. With
tolerant = 3, the system usually survives. With tolerant = 2, the system
usually panic()s (PCC) but not always. With tolerant = 1, the system
always panic()s. When the system panic()s, the BIOS is able to detect
that the cause of death was an MC4. I was not able to reproduce the
case of a non-PCC error in userspace, with EIPV, with (tolerant < 3).
That will be rare at best.
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:37 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we know that the error was in user space, send a
|
|
|
|
* SIGBUS. Otherwise, panic if tolerance is low.
|
|
|
|
*
|
2009-02-12 20:39:33 +08:00
|
|
|
* force_sig() takes an awful lot of locks and has a slight
|
x86_64: mcelog tolerant level cleanup
Background:
The MCE handler has several paths that it can take, depending on various
conditions of the MCE status and the value of the 'tolerant' knob. The
exact semantics are not well defined and the code is a bit twisty.
Description:
This patch makes the MCE handler's behavior more clear by documenting the
behavior for various 'tolerant' levels. It also fixes or enhances
several small things in the handler. Specifically:
* If RIPV is set it is not safe to restart, so set the 'no way out'
flag rather than the 'kill it' flag.
* Don't panic() on correctable MCEs.
* If the _OVER bit is set *and* the _UC bit is set (meaning possibly
dropped uncorrected errors), set the 'no way out' flag.
* Use EIPV for testing whether an app can be killed (SIGBUS) rather
than RIPV. According to docs, EIPV indicates that the error is
related to the IP, while RIPV simply means the IP is valid to
restart from.
* Don't clear the MCi_STATUS registers until after the panic() path.
This leaves the status bits set after the panic() so clever BIOSes
can find them (and dumb BIOSes can do nothing).
This patch also calls nonseekable_open() in mce_open (as suggested by akpm).
Result:
Tolerant levels behave almost identically to how they always have, but
not it's well defined. There's a slightly higher chance of panic()ing
when multiple errors happen (a good thing, IMHO). If you take an MBE and
panic(), the error status bits are not cleared.
Alternatives:
None.
Testing:
I used software to inject correctable and uncorrectable errors. With
tolerant = 3, the system usually survives. With tolerant = 2, the system
usually panic()s (PCC) but not always. With tolerant = 1, the system
always panic()s. When the system panic()s, the BIOS is able to detect
that the cause of death was an MC4. I was not able to reproduce the
case of a non-PCC error in userspace, with EIPV, with (tolerant < 3).
That will be rare at best.
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:37 +08:00
|
|
|
* risk of deadlocking.
|
|
|
|
*/
|
|
|
|
if (user_space) {
|
2009-02-12 20:39:33 +08:00
|
|
|
force_sig(SIGBUS, current);
|
x86_64: mcelog tolerant level cleanup
Background:
The MCE handler has several paths that it can take, depending on various
conditions of the MCE status and the value of the 'tolerant' knob. The
exact semantics are not well defined and the code is a bit twisty.
Description:
This patch makes the MCE handler's behavior more clear by documenting the
behavior for various 'tolerant' levels. It also fixes or enhances
several small things in the handler. Specifically:
* If RIPV is set it is not safe to restart, so set the 'no way out'
flag rather than the 'kill it' flag.
* Don't panic() on correctable MCEs.
* If the _OVER bit is set *and* the _UC bit is set (meaning possibly
dropped uncorrected errors), set the 'no way out' flag.
* Use EIPV for testing whether an app can be killed (SIGBUS) rather
than RIPV. According to docs, EIPV indicates that the error is
related to the IP, while RIPV simply means the IP is valid to
restart from.
* Don't clear the MCi_STATUS registers until after the panic() path.
This leaves the status bits set after the panic() so clever BIOSes
can find them (and dumb BIOSes can do nothing).
This patch also calls nonseekable_open() in mce_open (as suggested by akpm).
Result:
Tolerant levels behave almost identically to how they always have, but
not it's well defined. There's a slightly higher chance of panic()ing
when multiple errors happen (a good thing, IMHO). If you take an MBE and
panic(), the error status bits are not cleared.
Alternatives:
None.
Testing:
I used software to inject correctable and uncorrectable errors. With
tolerant = 3, the system usually survives. With tolerant = 2, the system
usually panic()s (PCC) but not always. With tolerant = 1, the system
always panic()s. When the system panic()s, the BIOS is able to detect
that the cause of death was an MC4. I was not able to reproduce the
case of a non-PCC error in userspace, with EIPV, with (tolerant < 3).
That will be rare at best.
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:37 +08:00
|
|
|
} else if (panic_on_oops || tolerant < 2) {
|
|
|
|
mce_panic("Uncorrected machine check",
|
|
|
|
&panicm, mcestart);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
/* notify userspace ASAP */
|
|
|
|
set_thread_flag(TIF_MCE_NOTIFY);
|
|
|
|
|
x86_64: mcelog tolerant level cleanup
Background:
The MCE handler has several paths that it can take, depending on various
conditions of the MCE status and the value of the 'tolerant' knob. The
exact semantics are not well defined and the code is a bit twisty.
Description:
This patch makes the MCE handler's behavior more clear by documenting the
behavior for various 'tolerant' levels. It also fixes or enhances
several small things in the handler. Specifically:
* If RIPV is set it is not safe to restart, so set the 'no way out'
flag rather than the 'kill it' flag.
* Don't panic() on correctable MCEs.
* If the _OVER bit is set *and* the _UC bit is set (meaning possibly
dropped uncorrected errors), set the 'no way out' flag.
* Use EIPV for testing whether an app can be killed (SIGBUS) rather
than RIPV. According to docs, EIPV indicates that the error is
related to the IP, while RIPV simply means the IP is valid to
restart from.
* Don't clear the MCi_STATUS registers until after the panic() path.
This leaves the status bits set after the panic() so clever BIOSes
can find them (and dumb BIOSes can do nothing).
This patch also calls nonseekable_open() in mce_open (as suggested by akpm).
Result:
Tolerant levels behave almost identically to how they always have, but
not it's well defined. There's a slightly higher chance of panic()ing
when multiple errors happen (a good thing, IMHO). If you take an MBE and
panic(), the error status bits are not cleared.
Alternatives:
None.
Testing:
I used software to inject correctable and uncorrectable errors. With
tolerant = 3, the system usually survives. With tolerant = 2, the system
usually panic()s (PCC) but not always. With tolerant = 1, the system
always panic()s. When the system panic()s, the BIOS is able to detect
that the cause of death was an MC4. I was not able to reproduce the
case of a non-PCC error in userspace, with EIPV, with (tolerant < 3).
That will be rare at best.
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:37 +08:00
|
|
|
/* the last thing we do is clear state */
|
2009-02-12 20:43:23 +08:00
|
|
|
for (i = 0; i < banks; i++) {
|
|
|
|
if (test_bit(i, toclear))
|
2009-04-30 01:29:12 +08:00
|
|
|
mce_wrmsrl(MSR_IA32_MC0_STATUS+4*i, 0);
|
2009-02-12 20:43:23 +08:00
|
|
|
}
|
2009-04-30 01:29:12 +08:00
|
|
|
mce_wrmsrl(MSR_IA32_MCG_STATUS, 0);
|
2009-05-28 03:56:53 +08:00
|
|
|
out:
|
2006-04-08 01:49:57 +08:00
|
|
|
atomic_dec(&mce_entry);
|
2009-05-28 03:56:51 +08:00
|
|
|
sync_core();
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-04-30 01:31:00 +08:00
|
|
|
EXPORT_SYMBOL_GPL(do_machine_check);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-09-26 16:52:42 +08:00
|
|
|
#ifdef CONFIG_X86_MCE_INTEL
|
|
|
|
/***
|
|
|
|
* mce_log_therm_throt_event - Logs the thermal throttling event to mcelog
|
2007-10-20 07:25:36 +08:00
|
|
|
* @cpu: The CPU on which the event occurred.
|
2006-09-26 16:52:42 +08:00
|
|
|
* @status: Event status information
|
|
|
|
*
|
|
|
|
* This function should be called by the thermal interrupt after the
|
|
|
|
* event has been processed and the decision was made to log the event
|
|
|
|
* further.
|
|
|
|
*
|
|
|
|
* The status parameter will be saved to the 'status' field of 'struct mce'
|
|
|
|
* and historically has been the register value of the
|
|
|
|
* MSR_IA32_THERMAL_STATUS (Intel) msr.
|
|
|
|
*/
|
2009-02-12 20:43:22 +08:00
|
|
|
void mce_log_therm_throt_event(__u64 status)
|
2006-09-26 16:52:42 +08:00
|
|
|
{
|
|
|
|
struct mce m;
|
|
|
|
|
2009-02-12 20:43:22 +08:00
|
|
|
mce_setup(&m);
|
2006-09-26 16:52:42 +08:00
|
|
|
m.bank = MCE_THERMAL_BANK;
|
|
|
|
m.status = status;
|
|
|
|
mce_log(&m);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_X86_MCE_INTEL */
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2007-05-03 01:27:19 +08:00
|
|
|
* Periodic polling timer for "silent" machine check errors. If the
|
|
|
|
* poller finds an MCE, poll 2x faster. When the poller finds no more
|
|
|
|
* errors, poll 2x slower (up to check_interval seconds).
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
static int check_interval = 5 * 60; /* 5 minutes */
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2009-04-09 18:28:22 +08:00
|
|
|
static DEFINE_PER_CPU(int, next_interval); /* in jiffies */
|
2009-02-12 20:39:29 +08:00
|
|
|
static DEFINE_PER_CPU(struct timer_list, mce_timer);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-02-12 20:39:29 +08:00
|
|
|
static void mcheck_timer(unsigned long data)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-02-12 20:39:29 +08:00
|
|
|
struct timer_list *t = &per_cpu(mce_timer, data);
|
2009-04-09 18:28:22 +08:00
|
|
|
int *n;
|
2009-02-12 20:39:29 +08:00
|
|
|
|
|
|
|
WARN_ON(smp_processor_id() != data);
|
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
if (mce_available(¤t_cpu_data)) {
|
2009-02-12 20:49:34 +08:00
|
|
|
machine_check_poll(MCP_TIMESTAMP,
|
|
|
|
&__get_cpu_var(mce_poll_banks));
|
2009-04-08 18:31:17 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
* Alert userspace if needed. If we logged an MCE, reduce the
|
|
|
|
* polling interval, otherwise increase the polling interval.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2009-04-09 18:28:22 +08:00
|
|
|
n = &__get_cpu_var(next_interval);
|
2009-04-30 15:04:51 +08:00
|
|
|
if (mce_notify_user())
|
2009-04-09 18:28:22 +08:00
|
|
|
*n = max(*n/2, HZ/100);
|
2009-04-30 15:04:51 +08:00
|
|
|
else
|
2009-04-09 18:28:22 +08:00
|
|
|
*n = min(*n*2, (int)round_jiffies_relative(check_interval*HZ));
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
|
2009-04-09 18:28:22 +08:00
|
|
|
t->expires = jiffies + *n;
|
2009-02-12 20:39:29 +08:00
|
|
|
add_timer(t);
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
}
|
|
|
|
|
2009-02-12 20:39:28 +08:00
|
|
|
static void mce_do_trigger(struct work_struct *work)
|
|
|
|
{
|
|
|
|
call_usermodehelper(trigger, trigger_argv, NULL, UMH_NO_WAIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DECLARE_WORK(mce_trigger_work, mce_do_trigger);
|
|
|
|
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
/*
|
2009-02-12 20:39:28 +08:00
|
|
|
* Notify the user(s) about new machine check events.
|
|
|
|
* Can be called from interrupt context, but not from machine check/NMI
|
|
|
|
* context.
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
*/
|
|
|
|
int mce_notify_user(void)
|
|
|
|
{
|
2009-02-12 20:49:33 +08:00
|
|
|
/* Not more than two messages every minute */
|
|
|
|
static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2);
|
|
|
|
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
clear_thread_flag(TIF_MCE_NOTIFY);
|
2009-04-08 18:31:17 +08:00
|
|
|
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
if (test_and_clear_bit(0, ¬ify_user)) {
|
|
|
|
wake_up_interruptible(&mce_wait);
|
2009-02-12 20:39:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* There is no risk of missing notifications because
|
|
|
|
* work_pending is always cleared before the function is
|
|
|
|
* executed.
|
|
|
|
*/
|
|
|
|
if (trigger[0] && !work_pending(&mce_trigger_work))
|
|
|
|
schedule_work(&mce_trigger_work);
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
|
2009-02-12 20:49:33 +08:00
|
|
|
if (__ratelimit(&ratelimit))
|
2007-05-03 01:27:19 +08:00
|
|
|
printk(KERN_INFO "Machine check events logged\n");
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
|
|
|
|
return 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2009-04-30 01:31:00 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mce_notify_user);
|
2007-05-03 01:27:19 +08:00
|
|
|
|
2007-10-24 04:37:23 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Initialize Machine Checks for a CPU.
|
|
|
|
*/
|
2009-02-18 06:07:13 +08:00
|
|
|
static int mce_cap_init(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-02-18 06:07:13 +08:00
|
|
|
unsigned b;
|
2009-04-08 18:31:17 +08:00
|
|
|
u64 cap;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
rdmsrl(MSR_IA32_MCG_CAP, cap);
|
2009-04-08 18:31:24 +08:00
|
|
|
|
|
|
|
b = cap & MCG_BANKCNT_MASK;
|
2009-04-08 18:31:27 +08:00
|
|
|
printk(KERN_INFO "mce: CPU supports %d MCE banks\n", b);
|
|
|
|
|
2009-02-18 06:07:13 +08:00
|
|
|
if (b > MAX_NR_BANKS) {
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"MCE: Using only %u machine check banks out of %u\n",
|
|
|
|
MAX_NR_BANKS, b);
|
|
|
|
b = MAX_NR_BANKS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't support asymmetric configurations today */
|
|
|
|
WARN_ON(banks != 0 && b != banks);
|
|
|
|
banks = b;
|
|
|
|
if (!bank) {
|
|
|
|
bank = kmalloc(banks * sizeof(u64), GFP_KERNEL);
|
|
|
|
if (!bank)
|
|
|
|
return -ENOMEM;
|
|
|
|
memset(bank, 0xff, banks * sizeof(u64));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-02-18 06:07:13 +08:00
|
|
|
|
2005-04-17 06:25:09 +08:00
|
|
|
/* Use accurate RIP reporting if available. */
|
2009-04-08 18:31:24 +08:00
|
|
|
if ((cap & MCG_EXT_P) && MCG_EXT_CNT(cap) >= 9)
|
2005-04-17 06:25:09 +08:00
|
|
|
rip_msr = MSR_IA32_MCG_EIP;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-02-18 06:07:13 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-28 03:56:53 +08:00
|
|
|
static void mce_init(void)
|
2009-02-18 06:07:13 +08:00
|
|
|
{
|
2009-04-08 18:31:17 +08:00
|
|
|
mce_banks_t all_banks;
|
2009-02-18 06:07:13 +08:00
|
|
|
u64 cap;
|
|
|
|
int i;
|
|
|
|
|
2009-02-12 20:43:23 +08:00
|
|
|
/*
|
|
|
|
* Log the machine checks left over from the previous reset.
|
|
|
|
*/
|
2009-02-12 20:49:34 +08:00
|
|
|
bitmap_fill(all_banks, MAX_NR_BANKS);
|
2009-04-07 23:06:55 +08:00
|
|
|
machine_check_poll(MCP_UC|(!mce_bootlog ? MCP_DONTLOG : 0), &all_banks);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
set_in_cr4(X86_CR4_MCE);
|
|
|
|
|
2009-02-18 06:07:13 +08:00
|
|
|
rdmsrl(MSR_IA32_MCG_CAP, cap);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (cap & MCG_CTL_P)
|
|
|
|
wrmsr(MSR_IA32_MCG_CTL, 0xffffffff, 0xffffffff);
|
|
|
|
|
|
|
|
for (i = 0; i < banks; i++) {
|
2009-04-28 00:37:43 +08:00
|
|
|
if (skip_bank_init(i))
|
|
|
|
continue;
|
2009-02-18 06:07:13 +08:00
|
|
|
wrmsrl(MSR_IA32_MC0_CTL+4*i, bank[i]);
|
2005-04-17 06:20:36 +08:00
|
|
|
wrmsrl(MSR_IA32_MC0_STATUS+4*i, 0);
|
2007-10-24 04:37:23 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add per CPU specific workarounds here */
|
2009-02-24 06:01:04 +08:00
|
|
|
static void mce_cpu_quirks(struct cpuinfo_x86 *c)
|
2007-10-24 04:37:23 +08:00
|
|
|
{
|
2005-04-17 06:20:36 +08:00
|
|
|
/* This should be disabled by the BIOS, but isn't always */
|
2008-04-22 23:22:21 +08:00
|
|
|
if (c->x86_vendor == X86_VENDOR_AMD) {
|
2009-04-08 18:31:17 +08:00
|
|
|
if (c->x86 == 15 && banks > 4) {
|
|
|
|
/*
|
|
|
|
* disable GART TBL walk error reporting, which
|
|
|
|
* trips off incorrectly with the IOMMU & 3ware
|
|
|
|
* & Cerberus:
|
|
|
|
*/
|
2009-02-18 06:07:13 +08:00
|
|
|
clear_bit(10, (unsigned long *)&bank[4]);
|
2009-04-08 18:31:17 +08:00
|
|
|
}
|
|
|
|
if (c->x86 <= 17 && mce_bootlog < 0) {
|
|
|
|
/*
|
|
|
|
* Lots of broken BIOS around that don't clear them
|
|
|
|
* by default and leave crap in there. Don't log:
|
|
|
|
*/
|
2008-04-22 23:22:21 +08:00
|
|
|
mce_bootlog = 0;
|
2009-04-08 18:31:17 +08:00
|
|
|
}
|
2009-04-28 00:42:48 +08:00
|
|
|
/*
|
|
|
|
* Various K7s with broken bank 0 around. Always disable
|
|
|
|
* by default.
|
|
|
|
*/
|
|
|
|
if (c->x86 == 6)
|
|
|
|
bank[0] = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2005-11-06 00:25:54 +08:00
|
|
|
|
2009-04-28 00:37:43 +08:00
|
|
|
if (c->x86_vendor == X86_VENDOR_INTEL) {
|
|
|
|
/*
|
|
|
|
* SDM documents that on family 6 bank 0 should not be written
|
|
|
|
* because it aliases to another special BIOS controlled
|
|
|
|
* register.
|
|
|
|
* But it's not aliased anymore on model 0x1a+
|
|
|
|
* Don't ignore bank 0 completely because there could be a
|
|
|
|
* valid event later, merely don't write CTL0.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (c->x86 == 6 && c->x86_model < 0x1A)
|
|
|
|
__set_bit(0, &dont_init_banks);
|
|
|
|
}
|
2007-10-24 04:37:23 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
x86, mce: use 64bit machine check code on 32bit
The 64bit machine check code is in many ways much better than
the 32bit machine check code: it is more specification compliant,
is cleaner, only has a single code base versus one per CPU,
has better infrastructure for recovery, has a cleaner way to communicate
with user space etc. etc.
Use the 64bit code for 32bit too.
This is the second attempt to do this. There was one a couple of years
ago to unify this code for 32bit and 64bit. Back then this ran into some
trouble with K7s and was reverted.
I believe this time the K7 problems (and some others) are addressed.
I went over the old handlers and was very careful to retain
all quirks.
But of course this needs a lot of testing on old systems. On newer
64bit capable systems I don't expect much problems because they have been
already tested with the 64bit kernel.
I made this a CONFIG for now that still allows to select the old
machine check code. This is mostly to make testing easier,
if someone runs into a problem we can ask them to try
with the CONFIG switched.
The new code is default y for more coverage.
Once there is confidence the 64bit code works well on older hardware
too the CONFIG_X86_OLD_MCE and the associated code can be easily
removed.
This causes a behaviour change for 32bit installations. They now
have to install the mcelog package to be able to log
corrected machine checks.
The 64bit machine check code only handles CPUs which support the
standard Intel machine check architecture described in the IA32 SDM.
The 32bit code has special support for some older CPUs which
have non standard machine check architectures, in particular
WinChip C3 and Intel P5. I made those a separate CONFIG option
and kept them for now. The WinChip variant could be probably
removed without too much pain, it doesn't really do anything
interesting. P5 is also disabled by default (like it
was before) because many motherboards have it miswired, but
according to Alan Cox a few embedded setups use that one.
Forward ported/heavily changed version of old patch, original patch
included review/fixes from Thomas Gleixner, Bert Wesarg.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-04-29 01:07:31 +08:00
|
|
|
static void __cpuinit mce_ancient_init(struct cpuinfo_x86 *c)
|
|
|
|
{
|
|
|
|
if (c->x86 != 5)
|
|
|
|
return;
|
|
|
|
switch (c->x86_vendor) {
|
|
|
|
case X86_VENDOR_INTEL:
|
|
|
|
if (mce_p5_enabled())
|
|
|
|
intel_p5_mcheck_init(c);
|
|
|
|
break;
|
|
|
|
case X86_VENDOR_CENTAUR:
|
|
|
|
winchip_mcheck_init(c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-21 15:35:51 +08:00
|
|
|
static void mce_cpu_features(struct cpuinfo_x86 *c)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
switch (c->x86_vendor) {
|
|
|
|
case X86_VENDOR_INTEL:
|
|
|
|
mce_intel_feature_init(c);
|
|
|
|
break;
|
2005-11-06 00:25:53 +08:00
|
|
|
case X86_VENDOR_AMD:
|
|
|
|
mce_amd_feature_init(c);
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-12 20:39:29 +08:00
|
|
|
static void mce_init_timer(void)
|
|
|
|
{
|
|
|
|
struct timer_list *t = &__get_cpu_var(mce_timer);
|
2009-04-09 18:28:22 +08:00
|
|
|
int *n = &__get_cpu_var(next_interval);
|
2009-02-12 20:39:29 +08:00
|
|
|
|
2009-04-09 18:28:22 +08:00
|
|
|
*n = check_interval * HZ;
|
|
|
|
if (!*n)
|
2009-02-12 20:39:29 +08:00
|
|
|
return;
|
|
|
|
setup_timer(t, mcheck_timer, smp_processor_id());
|
2009-04-09 18:28:22 +08:00
|
|
|
t->expires = round_jiffies(jiffies + *n);
|
2009-02-12 20:39:29 +08:00
|
|
|
add_timer(t);
|
|
|
|
}
|
|
|
|
|
2007-10-24 04:37:23 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Called for each booted CPU to set up machine checks.
|
2009-04-08 18:31:17 +08:00
|
|
|
* Must be called with preempt off:
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
[PATCH] x86_64: Change init sections for CPU hotplug support
This patch adds __cpuinit and __cpuinitdata sections that need to exist past
boot to support cpu hotplug.
Caveat: This is done *only* for EM64T CPU Hotplug support, on request from
Andi Kleen. Much of the generic hotplug code in kernel, and none of the other
archs that support CPU hotplug today, i386, ia64, ppc64, s390 and parisc dont
mark sections with __cpuinit, but only mark them as __devinit, and
__devinitdata.
If someone is motivated to change generic code, we need to make sure all
existing hotplug code does not break, on other arch's that dont use __cpuinit,
and __cpudevinit.
Signed-off-by: Ashok Raj <ashok.raj@intel.com>
Acked-by: Andi Kleen <ak@muc.de>
Acked-by: Zwane Mwaikambo <zwane@arm.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-26 05:54:58 +08:00
|
|
|
void __cpuinit mcheck_init(struct cpuinfo_x86 *c)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
x86, mce: use 64bit machine check code on 32bit
The 64bit machine check code is in many ways much better than
the 32bit machine check code: it is more specification compliant,
is cleaner, only has a single code base versus one per CPU,
has better infrastructure for recovery, has a cleaner way to communicate
with user space etc. etc.
Use the 64bit code for 32bit too.
This is the second attempt to do this. There was one a couple of years
ago to unify this code for 32bit and 64bit. Back then this ran into some
trouble with K7s and was reverted.
I believe this time the K7 problems (and some others) are addressed.
I went over the old handlers and was very careful to retain
all quirks.
But of course this needs a lot of testing on old systems. On newer
64bit capable systems I don't expect much problems because they have been
already tested with the 64bit kernel.
I made this a CONFIG for now that still allows to select the old
machine check code. This is mostly to make testing easier,
if someone runs into a problem we can ask them to try
with the CONFIG switched.
The new code is default y for more coverage.
Once there is confidence the 64bit code works well on older hardware
too the CONFIG_X86_OLD_MCE and the associated code can be easily
removed.
This causes a behaviour change for 32bit installations. They now
have to install the mcelog package to be able to log
corrected machine checks.
The 64bit machine check code only handles CPUs which support the
standard Intel machine check architecture described in the IA32 SDM.
The 32bit code has special support for some older CPUs which
have non standard machine check architectures, in particular
WinChip C3 and Intel P5. I made those a separate CONFIG option
and kept them for now. The WinChip variant could be probably
removed without too much pain, it doesn't really do anything
interesting. P5 is also disabled by default (like it
was before) because many motherboards have it miswired, but
according to Alan Cox a few embedded setups use that one.
Forward ported/heavily changed version of old patch, original patch
included review/fixes from Thomas Gleixner, Bert Wesarg.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-04-29 01:07:31 +08:00
|
|
|
if (mce_disabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mce_ancient_init(c);
|
|
|
|
|
2009-02-12 20:39:30 +08:00
|
|
|
if (!mce_available(c))
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
2009-02-18 06:07:13 +08:00
|
|
|
if (mce_cap_init() < 0) {
|
2009-04-29 04:50:19 +08:00
|
|
|
mce_disabled = 1;
|
2009-02-18 06:07:13 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
mce_cpu_quirks(c);
|
|
|
|
|
2009-04-28 01:25:48 +08:00
|
|
|
machine_check_vector = do_machine_check;
|
|
|
|
|
2009-05-28 03:56:53 +08:00
|
|
|
mce_init();
|
2005-04-17 06:20:36 +08:00
|
|
|
mce_cpu_features(c);
|
2009-02-12 20:39:29 +08:00
|
|
|
mce_init_timer();
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Character device to read and clear the MCE log.
|
|
|
|
*/
|
|
|
|
|
2007-07-21 23:10:35 +08:00
|
|
|
static DEFINE_SPINLOCK(mce_state_lock);
|
2009-04-08 18:31:17 +08:00
|
|
|
static int open_count; /* #times opened */
|
|
|
|
static int open_exclu; /* already open exclusive? */
|
2007-07-21 23:10:35 +08:00
|
|
|
|
|
|
|
static int mce_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
spin_lock(&mce_state_lock);
|
|
|
|
|
|
|
|
if (open_exclu || (open_count && (file->f_flags & O_EXCL))) {
|
|
|
|
spin_unlock(&mce_state_lock);
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2007-07-21 23:10:35 +08:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (file->f_flags & O_EXCL)
|
|
|
|
open_exclu = 1;
|
|
|
|
open_count++;
|
|
|
|
|
|
|
|
spin_unlock(&mce_state_lock);
|
|
|
|
|
x86_64: mcelog tolerant level cleanup
Background:
The MCE handler has several paths that it can take, depending on various
conditions of the MCE status and the value of the 'tolerant' knob. The
exact semantics are not well defined and the code is a bit twisty.
Description:
This patch makes the MCE handler's behavior more clear by documenting the
behavior for various 'tolerant' levels. It also fixes or enhances
several small things in the handler. Specifically:
* If RIPV is set it is not safe to restart, so set the 'no way out'
flag rather than the 'kill it' flag.
* Don't panic() on correctable MCEs.
* If the _OVER bit is set *and* the _UC bit is set (meaning possibly
dropped uncorrected errors), set the 'no way out' flag.
* Use EIPV for testing whether an app can be killed (SIGBUS) rather
than RIPV. According to docs, EIPV indicates that the error is
related to the IP, while RIPV simply means the IP is valid to
restart from.
* Don't clear the MCi_STATUS registers until after the panic() path.
This leaves the status bits set after the panic() so clever BIOSes
can find them (and dumb BIOSes can do nothing).
This patch also calls nonseekable_open() in mce_open (as suggested by akpm).
Result:
Tolerant levels behave almost identically to how they always have, but
not it's well defined. There's a slightly higher chance of panic()ing
when multiple errors happen (a good thing, IMHO). If you take an MBE and
panic(), the error status bits are not cleared.
Alternatives:
None.
Testing:
I used software to inject correctable and uncorrectable errors. With
tolerant = 3, the system usually survives. With tolerant = 2, the system
usually panic()s (PCC) but not always. With tolerant = 1, the system
always panic()s. When the system panic()s, the BIOS is able to detect
that the cause of death was an MC4. I was not able to reproduce the
case of a non-PCC error in userspace, with EIPV, with (tolerant < 3).
That will be rare at best.
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:37 +08:00
|
|
|
return nonseekable_open(inode, file);
|
2007-07-21 23:10:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mce_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
spin_lock(&mce_state_lock);
|
|
|
|
|
|
|
|
open_count--;
|
|
|
|
open_exclu = 0;
|
|
|
|
|
|
|
|
spin_unlock(&mce_state_lock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-10-24 04:37:23 +08:00
|
|
|
static void collect_tscs(void *data)
|
|
|
|
{
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long *cpu_tsc = (unsigned long *)data;
|
2007-10-24 04:37:23 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
rdtscll(cpu_tsc[smp_processor_id()]);
|
2007-10-24 04:37:23 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
static DEFINE_MUTEX(mce_read_mutex);
|
|
|
|
|
2007-10-24 04:37:23 +08:00
|
|
|
static ssize_t mce_read(struct file *filp, char __user *ubuf, size_t usize,
|
|
|
|
loff_t *off)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-04-08 18:31:17 +08:00
|
|
|
char __user *buf = ubuf;
|
2005-04-17 06:25:10 +08:00
|
|
|
unsigned long *cpu_tsc;
|
2009-02-12 20:39:34 +08:00
|
|
|
unsigned prev, next;
|
2005-04-17 06:20:36 +08:00
|
|
|
int i, err;
|
|
|
|
|
2008-07-19 09:11:27 +08:00
|
|
|
cpu_tsc = kmalloc(nr_cpu_ids * sizeof(long), GFP_KERNEL);
|
2005-04-17 06:25:10 +08:00
|
|
|
if (!cpu_tsc)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2008-01-30 20:31:17 +08:00
|
|
|
mutex_lock(&mce_read_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
next = rcu_dereference(mcelog.next);
|
|
|
|
|
|
|
|
/* Only supports full reads right now */
|
2007-10-24 04:37:23 +08:00
|
|
|
if (*off != 0 || usize < MCE_LOG_LEN*sizeof(struct mce)) {
|
2008-01-30 20:31:17 +08:00
|
|
|
mutex_unlock(&mce_read_mutex);
|
2005-04-17 06:25:10 +08:00
|
|
|
kfree(cpu_tsc);
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = 0;
|
2009-02-12 20:39:34 +08:00
|
|
|
prev = 0;
|
|
|
|
do {
|
|
|
|
for (i = prev; i < next; i++) {
|
|
|
|
unsigned long start = jiffies;
|
|
|
|
|
|
|
|
while (!mcelog.entry[i].finished) {
|
|
|
|
if (time_after_eq(jiffies, start + 2)) {
|
|
|
|
memset(mcelog.entry + i, 0,
|
|
|
|
sizeof(struct mce));
|
|
|
|
goto timeout;
|
|
|
|
}
|
|
|
|
cpu_relax();
|
2005-09-13 00:49:24 +08:00
|
|
|
}
|
2009-02-12 20:39:34 +08:00
|
|
|
smp_rmb();
|
|
|
|
err |= copy_to_user(buf, mcelog.entry + i,
|
|
|
|
sizeof(struct mce));
|
|
|
|
buf += sizeof(struct mce);
|
|
|
|
timeout:
|
|
|
|
;
|
2005-09-13 00:49:24 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-02-12 20:39:34 +08:00
|
|
|
memset(mcelog.entry + prev, 0,
|
|
|
|
(next - prev) * sizeof(struct mce));
|
|
|
|
prev = next;
|
|
|
|
next = cmpxchg(&mcelog.next, prev, 0);
|
|
|
|
} while (next != prev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-06-26 05:55:38 +08:00
|
|
|
synchronize_sched();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-10-24 04:37:23 +08:00
|
|
|
/*
|
|
|
|
* Collect entries that were still getting written before the
|
|
|
|
* synchronize.
|
|
|
|
*/
|
2008-05-09 15:39:44 +08:00
|
|
|
on_each_cpu(collect_tscs, cpu_tsc, 1);
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2007-10-24 04:37:23 +08:00
|
|
|
for (i = next; i < MCE_LOG_LEN; i++) {
|
|
|
|
if (mcelog.entry[i].finished &&
|
|
|
|
mcelog.entry[i].tsc < cpu_tsc[mcelog.entry[i].cpu]) {
|
|
|
|
err |= copy_to_user(buf, mcelog.entry+i,
|
|
|
|
sizeof(struct mce));
|
2005-04-17 06:20:36 +08:00
|
|
|
smp_rmb();
|
|
|
|
buf += sizeof(struct mce);
|
|
|
|
memset(&mcelog.entry[i], 0, sizeof(struct mce));
|
|
|
|
}
|
2007-10-24 04:37:23 +08:00
|
|
|
}
|
2008-01-30 20:31:17 +08:00
|
|
|
mutex_unlock(&mce_read_mutex);
|
2005-04-17 06:25:10 +08:00
|
|
|
kfree(cpu_tsc);
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2007-10-24 04:37:23 +08:00
|
|
|
return err ? -EFAULT : buf - ubuf;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
static unsigned int mce_poll(struct file *file, poll_table *wait)
|
|
|
|
{
|
|
|
|
poll_wait(file, &mce_wait, wait);
|
|
|
|
if (rcu_dereference(mcelog.next))
|
|
|
|
return POLLIN | POLLRDNORM;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-30 20:32:59 +08:00
|
|
|
static long mce_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int __user *p = (int __user *)arg;
|
2007-10-24 04:37:23 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
2007-10-24 04:37:23 +08:00
|
|
|
return -EPERM;
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (cmd) {
|
2007-10-24 04:37:23 +08:00
|
|
|
case MCE_GET_RECORD_LEN:
|
2005-04-17 06:20:36 +08:00
|
|
|
return put_user(sizeof(struct mce), p);
|
|
|
|
case MCE_GET_LOG_LEN:
|
2007-10-24 04:37:23 +08:00
|
|
|
return put_user(MCE_LOG_LEN, p);
|
2005-04-17 06:20:36 +08:00
|
|
|
case MCE_GETCLEAR_FLAGS: {
|
|
|
|
unsigned flags;
|
2007-10-24 04:37:23 +08:00
|
|
|
|
|
|
|
do {
|
2005-04-17 06:20:36 +08:00
|
|
|
flags = mcelog.flags;
|
2007-10-24 04:37:23 +08:00
|
|
|
} while (cmpxchg(&mcelog.flags, flags, 0) != flags);
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2007-10-24 04:37:23 +08:00
|
|
|
return put_user(flags, p);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
default:
|
2007-10-24 04:37:23 +08:00
|
|
|
return -ENOTTY;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-05-26 13:16:14 +08:00
|
|
|
/* Modified in mce-inject.c, so not static or const */
|
2009-04-30 01:31:00 +08:00
|
|
|
struct file_operations mce_chrdev_ops = {
|
2009-04-08 18:31:17 +08:00
|
|
|
.open = mce_open,
|
|
|
|
.release = mce_release,
|
|
|
|
.read = mce_read,
|
|
|
|
.poll = mce_poll,
|
|
|
|
.unlocked_ioctl = mce_ioctl,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
2009-04-30 01:31:00 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mce_chrdev_ops);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static struct miscdevice mce_log_device = {
|
|
|
|
MISC_MCELOG_MINOR,
|
|
|
|
"mcelog",
|
|
|
|
&mce_chrdev_ops,
|
|
|
|
};
|
|
|
|
|
2009-03-26 16:39:20 +08:00
|
|
|
/*
|
|
|
|
* mce=off disables machine check
|
|
|
|
* mce=TOLERANCELEVEL (number, see above)
|
|
|
|
* mce=bootlog Log MCEs from before booting. Disabled by default on AMD.
|
|
|
|
* mce=nobootlog Don't log MCEs from before booting.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
static int __init mcheck_enable(char *str)
|
|
|
|
{
|
x86, mce: use 64bit machine check code on 32bit
The 64bit machine check code is in many ways much better than
the 32bit machine check code: it is more specification compliant,
is cleaner, only has a single code base versus one per CPU,
has better infrastructure for recovery, has a cleaner way to communicate
with user space etc. etc.
Use the 64bit code for 32bit too.
This is the second attempt to do this. There was one a couple of years
ago to unify this code for 32bit and 64bit. Back then this ran into some
trouble with K7s and was reverted.
I believe this time the K7 problems (and some others) are addressed.
I went over the old handlers and was very careful to retain
all quirks.
But of course this needs a lot of testing on old systems. On newer
64bit capable systems I don't expect much problems because they have been
already tested with the 64bit kernel.
I made this a CONFIG for now that still allows to select the old
machine check code. This is mostly to make testing easier,
if someone runs into a problem we can ask them to try
with the CONFIG switched.
The new code is default y for more coverage.
Once there is confidence the 64bit code works well on older hardware
too the CONFIG_X86_OLD_MCE and the associated code can be easily
removed.
This causes a behaviour change for 32bit installations. They now
have to install the mcelog package to be able to log
corrected machine checks.
The 64bit machine check code only handles CPUs which support the
standard Intel machine check architecture described in the IA32 SDM.
The 32bit code has special support for some older CPUs which
have non standard machine check architectures, in particular
WinChip C3 and Intel P5. I made those a separate CONFIG option
and kept them for now. The WinChip variant could be probably
removed without too much pain, it doesn't really do anything
interesting. P5 is also disabled by default (like it
was before) because many motherboards have it miswired, but
according to Alan Cox a few embedded setups use that one.
Forward ported/heavily changed version of old patch, original patch
included review/fixes from Thomas Gleixner, Bert Wesarg.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-04-29 01:07:31 +08:00
|
|
|
if (*str == 0)
|
|
|
|
enable_p5_mce();
|
|
|
|
if (*str == '=')
|
|
|
|
str++;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!strcmp(str, "off"))
|
2009-04-29 04:50:19 +08:00
|
|
|
mce_disabled = 1;
|
2009-03-26 16:39:20 +08:00
|
|
|
else if (!strcmp(str, "bootlog") || !strcmp(str, "nobootlog"))
|
|
|
|
mce_bootlog = (str[0] == 'b');
|
2005-09-13 00:49:24 +08:00
|
|
|
else if (isdigit(str[0]))
|
|
|
|
get_option(&str, &tolerant);
|
2009-03-26 16:39:20 +08:00
|
|
|
else {
|
x86, mce: use 64bit machine check code on 32bit
The 64bit machine check code is in many ways much better than
the 32bit machine check code: it is more specification compliant,
is cleaner, only has a single code base versus one per CPU,
has better infrastructure for recovery, has a cleaner way to communicate
with user space etc. etc.
Use the 64bit code for 32bit too.
This is the second attempt to do this. There was one a couple of years
ago to unify this code for 32bit and 64bit. Back then this ran into some
trouble with K7s and was reverted.
I believe this time the K7 problems (and some others) are addressed.
I went over the old handlers and was very careful to retain
all quirks.
But of course this needs a lot of testing on old systems. On newer
64bit capable systems I don't expect much problems because they have been
already tested with the 64bit kernel.
I made this a CONFIG for now that still allows to select the old
machine check code. This is mostly to make testing easier,
if someone runs into a problem we can ask them to try
with the CONFIG switched.
The new code is default y for more coverage.
Once there is confidence the 64bit code works well on older hardware
too the CONFIG_X86_OLD_MCE and the associated code can be easily
removed.
This causes a behaviour change for 32bit installations. They now
have to install the mcelog package to be able to log
corrected machine checks.
The 64bit machine check code only handles CPUs which support the
standard Intel machine check architecture described in the IA32 SDM.
The 32bit code has special support for some older CPUs which
have non standard machine check architectures, in particular
WinChip C3 and Intel P5. I made those a separate CONFIG option
and kept them for now. The WinChip variant could be probably
removed without too much pain, it doesn't really do anything
interesting. P5 is also disabled by default (like it
was before) because many motherboards have it miswired, but
according to Alan Cox a few embedded setups use that one.
Forward ported/heavily changed version of old patch, original patch
included review/fixes from Thomas Gleixner, Bert Wesarg.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-04-29 01:07:31 +08:00
|
|
|
printk(KERN_INFO "mce argument %s ignored. Please use /sys\n",
|
2009-03-26 16:39:20 +08:00
|
|
|
str);
|
|
|
|
return 0;
|
|
|
|
}
|
2006-03-31 18:30:33 +08:00
|
|
|
return 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
x86, mce: use 64bit machine check code on 32bit
The 64bit machine check code is in many ways much better than
the 32bit machine check code: it is more specification compliant,
is cleaner, only has a single code base versus one per CPU,
has better infrastructure for recovery, has a cleaner way to communicate
with user space etc. etc.
Use the 64bit code for 32bit too.
This is the second attempt to do this. There was one a couple of years
ago to unify this code for 32bit and 64bit. Back then this ran into some
trouble with K7s and was reverted.
I believe this time the K7 problems (and some others) are addressed.
I went over the old handlers and was very careful to retain
all quirks.
But of course this needs a lot of testing on old systems. On newer
64bit capable systems I don't expect much problems because they have been
already tested with the 64bit kernel.
I made this a CONFIG for now that still allows to select the old
machine check code. This is mostly to make testing easier,
if someone runs into a problem we can ask them to try
with the CONFIG switched.
The new code is default y for more coverage.
Once there is confidence the 64bit code works well on older hardware
too the CONFIG_X86_OLD_MCE and the associated code can be easily
removed.
This causes a behaviour change for 32bit installations. They now
have to install the mcelog package to be able to log
corrected machine checks.
The 64bit machine check code only handles CPUs which support the
standard Intel machine check architecture described in the IA32 SDM.
The 32bit code has special support for some older CPUs which
have non standard machine check architectures, in particular
WinChip C3 and Intel P5. I made those a separate CONFIG option
and kept them for now. The WinChip variant could be probably
removed without too much pain, it doesn't really do anything
interesting. P5 is also disabled by default (like it
was before) because many motherboards have it miswired, but
according to Alan Cox a few embedded setups use that one.
Forward ported/heavily changed version of old patch, original patch
included review/fixes from Thomas Gleixner, Bert Wesarg.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-04-29 01:07:31 +08:00
|
|
|
__setup("mce", mcheck_enable);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-10-24 04:37:23 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Sysfs support
|
2007-10-24 04:37:23 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-02-12 20:39:32 +08:00
|
|
|
/*
|
|
|
|
* Disable machine checks on suspend and shutdown. We can't really handle
|
|
|
|
* them later.
|
|
|
|
*/
|
|
|
|
static int mce_disable(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2009-04-28 00:37:43 +08:00
|
|
|
for (i = 0; i < banks; i++) {
|
|
|
|
if (!skip_bank_init(i))
|
|
|
|
wrmsrl(MSR_IA32_MC0_CTL + i*4, 0);
|
|
|
|
}
|
2009-02-12 20:39:32 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mce_suspend(struct sys_device *dev, pm_message_t state)
|
|
|
|
{
|
|
|
|
return mce_disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mce_shutdown(struct sys_device *dev)
|
|
|
|
{
|
|
|
|
return mce_disable();
|
|
|
|
}
|
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
/*
|
|
|
|
* On resume clear all MCE state. Don't want to see leftovers from the BIOS.
|
|
|
|
* Only one CPU is active at this time, the others get re-added later using
|
|
|
|
* CPU hotplug:
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
static int mce_resume(struct sys_device *dev)
|
|
|
|
{
|
2009-05-28 03:56:53 +08:00
|
|
|
mce_init();
|
2009-02-12 20:39:26 +08:00
|
|
|
mce_cpu_features(¤t_cpu_data);
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-12 20:39:29 +08:00
|
|
|
static void mce_cpu_restart(void *data)
|
|
|
|
{
|
|
|
|
del_timer_sync(&__get_cpu_var(mce_timer));
|
|
|
|
if (mce_available(¤t_cpu_data))
|
2009-05-28 03:56:53 +08:00
|
|
|
mce_init();
|
2009-02-12 20:39:29 +08:00
|
|
|
mce_init_timer();
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Reinit MCEs after user configuration changes */
|
2007-10-24 04:37:23 +08:00
|
|
|
static void mce_restart(void)
|
|
|
|
{
|
2009-02-12 20:39:29 +08:00
|
|
|
on_each_cpu(mce_cpu_restart, NULL, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct sysdev_class mce_sysclass = {
|
2009-04-08 18:31:17 +08:00
|
|
|
.suspend = mce_suspend,
|
|
|
|
.shutdown = mce_shutdown,
|
|
|
|
.resume = mce_resume,
|
|
|
|
.name = "machinecheck",
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
DEFINE_PER_CPU(struct sys_device, mce_dev);
|
2009-04-08 18:31:17 +08:00
|
|
|
|
|
|
|
__cpuinitdata
|
|
|
|
void (*threshold_cpu_callback)(unsigned long action, unsigned int cpu);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-02-18 06:07:13 +08:00
|
|
|
static struct sysdev_attribute *bank_attrs;
|
|
|
|
|
|
|
|
static ssize_t show_bank(struct sys_device *s, struct sysdev_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
u64 b = bank[attr - bank_attrs];
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2009-02-20 07:44:58 +08:00
|
|
|
return sprintf(buf, "%llx\n", b);
|
2009-02-18 06:07:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t set_bank(struct sys_device *s, struct sysdev_attribute *attr,
|
2009-04-14 16:26:30 +08:00
|
|
|
const char *buf, size_t size)
|
2009-02-18 06:07:13 +08:00
|
|
|
{
|
2009-04-14 16:26:30 +08:00
|
|
|
u64 new;
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2009-04-14 16:26:30 +08:00
|
|
|
if (strict_strtoull(buf, 0, &new) < 0)
|
2009-02-18 06:07:13 +08:00
|
|
|
return -EINVAL;
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2009-02-18 06:07:13 +08:00
|
|
|
bank[attr - bank_attrs] = new;
|
|
|
|
mce_restart();
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2009-04-14 16:26:30 +08:00
|
|
|
return size;
|
2009-02-18 06:07:13 +08:00
|
|
|
}
|
2007-02-13 20:26:23 +08:00
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
static ssize_t
|
|
|
|
show_trigger(struct sys_device *s, struct sysdev_attribute *attr, char *buf)
|
2007-02-13 20:26:23 +08:00
|
|
|
{
|
|
|
|
strcpy(buf, trigger);
|
|
|
|
strcat(buf, "\n");
|
|
|
|
return strlen(trigger) + 1;
|
|
|
|
}
|
|
|
|
|
2008-07-02 00:48:41 +08:00
|
|
|
static ssize_t set_trigger(struct sys_device *s, struct sysdev_attribute *attr,
|
2009-04-08 18:31:17 +08:00
|
|
|
const char *buf, size_t siz)
|
2007-02-13 20:26:23 +08:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
int len;
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2007-02-13 20:26:23 +08:00
|
|
|
strncpy(trigger, buf, sizeof(trigger));
|
|
|
|
trigger[sizeof(trigger)-1] = 0;
|
|
|
|
len = strlen(trigger);
|
|
|
|
p = strchr(trigger, '\n');
|
2009-04-08 18:31:17 +08:00
|
|
|
|
|
|
|
if (*p)
|
|
|
|
*p = 0;
|
|
|
|
|
2007-02-13 20:26:23 +08:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2009-05-28 03:56:52 +08:00
|
|
|
static ssize_t store_int_with_restart(struct sys_device *s,
|
|
|
|
struct sysdev_attribute *attr,
|
|
|
|
const char *buf, size_t size)
|
|
|
|
{
|
|
|
|
ssize_t ret = sysdev_store_int(s, attr, buf, size);
|
|
|
|
mce_restart();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-02-13 20:26:23 +08:00
|
|
|
static SYSDEV_ATTR(trigger, 0644, show_trigger, set_trigger);
|
2008-07-02 00:48:43 +08:00
|
|
|
static SYSDEV_INT_ATTR(tolerant, 0644, tolerant);
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2009-05-28 03:56:52 +08:00
|
|
|
static struct sysdev_ext_attribute attr_check_interval = {
|
|
|
|
_SYSDEV_ATTR(check_interval, 0644, sysdev_show_int,
|
|
|
|
store_int_with_restart),
|
|
|
|
&check_interval
|
|
|
|
};
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
static struct sysdev_attribute *mce_attrs[] = {
|
2009-05-28 03:56:52 +08:00
|
|
|
&attr_tolerant.attr, &attr_check_interval.attr, &attr_trigger,
|
2007-02-13 20:26:23 +08:00
|
|
|
NULL
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
static cpumask_var_t mce_dev_initialized;
|
2007-11-15 09:00:44 +08:00
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
/* Per cpu sysdev init. All of the cpus still share the same ctrl bank: */
|
2005-07-29 12:15:39 +08:00
|
|
|
static __cpuinit int mce_create_device(unsigned int cpu)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int err;
|
2006-01-12 05:43:06 +08:00
|
|
|
int i;
|
2007-10-20 02:35:04 +08:00
|
|
|
|
2007-11-07 09:12:58 +08:00
|
|
|
if (!mce_available(&boot_cpu_data))
|
2005-07-29 12:15:39 +08:00
|
|
|
return -EIO;
|
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
memset(&per_cpu(mce_dev, cpu).kobj, 0, sizeof(struct kobject));
|
|
|
|
per_cpu(mce_dev, cpu).id = cpu;
|
|
|
|
per_cpu(mce_dev, cpu).cls = &mce_sysclass;
|
2005-07-29 12:15:39 +08:00
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
err = sysdev_register(&per_cpu(mce_dev, cpu));
|
2007-10-18 18:05:15 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
for (i = 0; mce_attrs[i]; i++) {
|
|
|
|
err = sysdev_create_file(&per_cpu(mce_dev, cpu), mce_attrs[i]);
|
2007-10-18 18:05:15 +08:00
|
|
|
if (err)
|
|
|
|
goto error;
|
|
|
|
}
|
2009-02-18 06:07:13 +08:00
|
|
|
for (i = 0; i < banks; i++) {
|
2009-04-08 18:31:17 +08:00
|
|
|
err = sysdev_create_file(&per_cpu(mce_dev, cpu),
|
2009-02-18 06:07:13 +08:00
|
|
|
&bank_attrs[i]);
|
|
|
|
if (err)
|
|
|
|
goto error2;
|
|
|
|
}
|
2009-04-08 18:31:17 +08:00
|
|
|
cpumask_set_cpu(cpu, mce_dev_initialized);
|
2005-07-29 12:15:39 +08:00
|
|
|
|
2007-10-18 18:05:15 +08:00
|
|
|
return 0;
|
2009-02-18 06:07:13 +08:00
|
|
|
error2:
|
2009-04-08 18:31:17 +08:00
|
|
|
while (--i >= 0)
|
|
|
|
sysdev_remove_file(&per_cpu(mce_dev, cpu), &bank_attrs[i]);
|
2007-10-18 18:05:15 +08:00
|
|
|
error:
|
2009-04-08 18:31:17 +08:00
|
|
|
while (--i >= 0)
|
|
|
|
sysdev_remove_file(&per_cpu(mce_dev, cpu), mce_attrs[i]);
|
|
|
|
|
|
|
|
sysdev_unregister(&per_cpu(mce_dev, cpu));
|
2007-10-18 18:05:15 +08:00
|
|
|
|
2005-07-29 12:15:39 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2008-08-29 20:15:04 +08:00
|
|
|
static __cpuinit void mce_remove_device(unsigned int cpu)
|
2005-07-29 12:15:39 +08:00
|
|
|
{
|
2006-01-12 05:43:06 +08:00
|
|
|
int i;
|
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
if (!cpumask_test_cpu(cpu, mce_dev_initialized))
|
2007-11-15 09:00:44 +08:00
|
|
|
return;
|
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
for (i = 0; mce_attrs[i]; i++)
|
|
|
|
sysdev_remove_file(&per_cpu(mce_dev, cpu), mce_attrs[i]);
|
|
|
|
|
2009-02-18 06:07:13 +08:00
|
|
|
for (i = 0; i < banks; i++)
|
2009-04-08 18:31:17 +08:00
|
|
|
sysdev_remove_file(&per_cpu(mce_dev, cpu), &bank_attrs[i]);
|
|
|
|
|
|
|
|
sysdev_unregister(&per_cpu(mce_dev, cpu));
|
|
|
|
cpumask_clear_cpu(cpu, mce_dev_initialized);
|
2005-07-29 12:15:39 +08:00
|
|
|
}
|
|
|
|
|
2009-02-12 20:39:31 +08:00
|
|
|
/* Make sure there are no machine checks on offlined CPUs. */
|
2009-02-24 06:01:04 +08:00
|
|
|
static void mce_disable_cpu(void *h)
|
2009-02-12 20:39:31 +08:00
|
|
|
{
|
2009-02-12 20:49:36 +08:00
|
|
|
unsigned long action = *(unsigned long *)h;
|
2009-04-08 18:31:17 +08:00
|
|
|
int i;
|
2009-02-12 20:39:31 +08:00
|
|
|
|
|
|
|
if (!mce_available(¤t_cpu_data))
|
|
|
|
return;
|
2009-02-12 20:49:36 +08:00
|
|
|
if (!(action & CPU_TASKS_FROZEN))
|
|
|
|
cmci_clear();
|
2009-04-28 00:37:43 +08:00
|
|
|
for (i = 0; i < banks; i++) {
|
|
|
|
if (!skip_bank_init(i))
|
|
|
|
wrmsrl(MSR_IA32_MC0_CTL + i*4, 0);
|
|
|
|
}
|
2009-02-12 20:39:31 +08:00
|
|
|
}
|
|
|
|
|
2009-02-24 06:01:04 +08:00
|
|
|
static void mce_reenable_cpu(void *h)
|
2009-02-12 20:39:31 +08:00
|
|
|
{
|
2009-02-12 20:49:36 +08:00
|
|
|
unsigned long action = *(unsigned long *)h;
|
2009-04-08 18:31:17 +08:00
|
|
|
int i;
|
2009-02-12 20:39:31 +08:00
|
|
|
|
|
|
|
if (!mce_available(¤t_cpu_data))
|
|
|
|
return;
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2009-02-12 20:49:36 +08:00
|
|
|
if (!(action & CPU_TASKS_FROZEN))
|
|
|
|
cmci_reenable();
|
2009-04-28 00:37:43 +08:00
|
|
|
for (i = 0; i < banks; i++) {
|
|
|
|
if (!skip_bank_init(i))
|
|
|
|
wrmsrl(MSR_IA32_MC0_CTL + i*4, bank[i]);
|
|
|
|
}
|
2009-02-12 20:39:31 +08:00
|
|
|
}
|
|
|
|
|
2005-07-29 12:15:39 +08:00
|
|
|
/* Get notified when a cpu comes on/off. Be hotplug friendly. */
|
2009-04-08 18:31:17 +08:00
|
|
|
static int __cpuinit
|
|
|
|
mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
|
2005-07-29 12:15:39 +08:00
|
|
|
{
|
|
|
|
unsigned int cpu = (unsigned long)hcpu;
|
2009-02-12 20:39:29 +08:00
|
|
|
struct timer_list *t = &per_cpu(mce_timer, cpu);
|
2005-07-29 12:15:39 +08:00
|
|
|
|
|
|
|
switch (action) {
|
2007-11-15 09:00:44 +08:00
|
|
|
case CPU_ONLINE:
|
|
|
|
case CPU_ONLINE_FROZEN:
|
|
|
|
mce_create_device(cpu);
|
x86 MCE: Fix CPU hotplug problem with multiple multicore AMD CPUs
During CPU hot-remove the sysfs directory created by
threshold_create_bank(), defined in
arch/x86/kernel/cpu/mcheck/mce_amd_64.c, has to be removed before
its parent directory, created by mce_create_device(), defined in
arch/x86/kernel/cpu/mcheck/mce_64.c . Moreover, when the CPU in
question is hotplugged again, obviously the latter has to be created
before the former. At present, the right ordering is not enforced,
because all of these operations are carried out by CPU hotplug
notifiers which are not appropriately ordered with respect to each
other. This leads to serious problems on systems with two or more
multicore AMD CPUs, among other things during suspend and hibernation.
Fix the problem by placing threshold bank CPU hotplug callbacks in
mce_cpu_callback(), so that they are invoked at the right places,
if defined. Additionally, use kobject_del() to remove the sysfs
directory associated with the kobject created by
kobject_create_and_add() in threshold_create_bank(), to prevent the
kernel from crashing during CPU hotplug operations on systems with
two or more multicore AMD CPUs.
This patch fixes bug #11337.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Andi Kleen <andi@firstfloor.org>
Tested-by: Mark Langsdorf <mark.langsdorf@amd.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2008-08-23 04:23:09 +08:00
|
|
|
if (threshold_cpu_callback)
|
|
|
|
threshold_cpu_callback(action, cpu);
|
2005-07-29 12:15:39 +08:00
|
|
|
break;
|
|
|
|
case CPU_DEAD:
|
2007-05-09 17:35:10 +08:00
|
|
|
case CPU_DEAD_FROZEN:
|
x86 MCE: Fix CPU hotplug problem with multiple multicore AMD CPUs
During CPU hot-remove the sysfs directory created by
threshold_create_bank(), defined in
arch/x86/kernel/cpu/mcheck/mce_amd_64.c, has to be removed before
its parent directory, created by mce_create_device(), defined in
arch/x86/kernel/cpu/mcheck/mce_64.c . Moreover, when the CPU in
question is hotplugged again, obviously the latter has to be created
before the former. At present, the right ordering is not enforced,
because all of these operations are carried out by CPU hotplug
notifiers which are not appropriately ordered with respect to each
other. This leads to serious problems on systems with two or more
multicore AMD CPUs, among other things during suspend and hibernation.
Fix the problem by placing threshold bank CPU hotplug callbacks in
mce_cpu_callback(), so that they are invoked at the right places,
if defined. Additionally, use kobject_del() to remove the sysfs
directory associated with the kobject created by
kobject_create_and_add() in threshold_create_bank(), to prevent the
kernel from crashing during CPU hotplug operations on systems with
two or more multicore AMD CPUs.
This patch fixes bug #11337.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Andi Kleen <andi@firstfloor.org>
Tested-by: Mark Langsdorf <mark.langsdorf@amd.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2008-08-23 04:23:09 +08:00
|
|
|
if (threshold_cpu_callback)
|
|
|
|
threshold_cpu_callback(action, cpu);
|
2005-07-29 12:15:39 +08:00
|
|
|
mce_remove_device(cpu);
|
|
|
|
break;
|
2009-02-12 20:39:29 +08:00
|
|
|
case CPU_DOWN_PREPARE:
|
|
|
|
case CPU_DOWN_PREPARE_FROZEN:
|
|
|
|
del_timer_sync(t);
|
2009-02-12 20:49:36 +08:00
|
|
|
smp_call_function_single(cpu, mce_disable_cpu, &action, 1);
|
2009-02-12 20:39:29 +08:00
|
|
|
break;
|
|
|
|
case CPU_DOWN_FAILED:
|
|
|
|
case CPU_DOWN_FAILED_FROZEN:
|
2009-04-09 18:28:22 +08:00
|
|
|
t->expires = round_jiffies(jiffies +
|
|
|
|
__get_cpu_var(next_interval));
|
2009-02-12 20:39:29 +08:00
|
|
|
add_timer_on(t, cpu);
|
2009-02-12 20:49:36 +08:00
|
|
|
smp_call_function_single(cpu, mce_reenable_cpu, &action, 1);
|
|
|
|
break;
|
|
|
|
case CPU_POST_DEAD:
|
|
|
|
/* intentionally ignoring frozen here */
|
|
|
|
cmci_rediscover(cpu);
|
2009-02-12 20:39:29 +08:00
|
|
|
break;
|
2005-07-29 12:15:39 +08:00
|
|
|
}
|
2007-11-15 09:00:44 +08:00
|
|
|
return NOTIFY_OK;
|
2005-07-29 12:15:39 +08:00
|
|
|
}
|
|
|
|
|
2008-01-30 20:33:36 +08:00
|
|
|
static struct notifier_block mce_cpu_notifier __cpuinitdata = {
|
2005-07-29 12:15:39 +08:00
|
|
|
.notifier_call = mce_cpu_callback,
|
|
|
|
};
|
|
|
|
|
2009-02-18 06:07:13 +08:00
|
|
|
static __init int mce_init_banks(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
bank_attrs = kzalloc(sizeof(struct sysdev_attribute) * banks,
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!bank_attrs)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (i = 0; i < banks; i++) {
|
|
|
|
struct sysdev_attribute *a = &bank_attrs[i];
|
2009-04-08 18:31:17 +08:00
|
|
|
|
|
|
|
a->attr.name = kasprintf(GFP_KERNEL, "bank%d", i);
|
2009-02-18 06:07:13 +08:00
|
|
|
if (!a->attr.name)
|
|
|
|
goto nomem;
|
2009-04-08 18:31:17 +08:00
|
|
|
|
|
|
|
a->attr.mode = 0644;
|
|
|
|
a->show = show_bank;
|
|
|
|
a->store = set_bank;
|
2009-02-18 06:07:13 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nomem:
|
|
|
|
while (--i >= 0)
|
|
|
|
kfree(bank_attrs[i].attr.name);
|
|
|
|
kfree(bank_attrs);
|
|
|
|
bank_attrs = NULL;
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2009-02-18 06:07:13 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2005-07-29 12:15:39 +08:00
|
|
|
static __init int mce_init_device(void)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
int i = 0;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!mce_available(&boot_cpu_data))
|
|
|
|
return -EIO;
|
2009-02-18 06:07:13 +08:00
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
alloc_cpumask_var(&mce_dev_initialized, GFP_KERNEL);
|
2009-03-13 12:19:51 +08:00
|
|
|
|
2009-02-18 06:07:13 +08:00
|
|
|
err = mce_init_banks();
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
err = sysdev_class_register(&mce_sysclass);
|
2007-10-18 18:05:15 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
2005-07-29 12:15:39 +08:00
|
|
|
|
|
|
|
for_each_online_cpu(i) {
|
2007-10-18 18:05:15 +08:00
|
|
|
err = mce_create_device(i);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2005-07-29 12:15:39 +08:00
|
|
|
}
|
|
|
|
|
2006-07-30 18:03:37 +08:00
|
|
|
register_hotcpu_notifier(&mce_cpu_notifier);
|
2005-04-17 06:20:36 +08:00
|
|
|
misc_register(&mce_log_device);
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
|
|
|
}
|
2005-07-29 12:15:39 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
device_initcall(mce_init_device);
|
2009-04-08 18:31:25 +08:00
|
|
|
|
x86, mce: use 64bit machine check code on 32bit
The 64bit machine check code is in many ways much better than
the 32bit machine check code: it is more specification compliant,
is cleaner, only has a single code base versus one per CPU,
has better infrastructure for recovery, has a cleaner way to communicate
with user space etc. etc.
Use the 64bit code for 32bit too.
This is the second attempt to do this. There was one a couple of years
ago to unify this code for 32bit and 64bit. Back then this ran into some
trouble with K7s and was reverted.
I believe this time the K7 problems (and some others) are addressed.
I went over the old handlers and was very careful to retain
all quirks.
But of course this needs a lot of testing on old systems. On newer
64bit capable systems I don't expect much problems because they have been
already tested with the 64bit kernel.
I made this a CONFIG for now that still allows to select the old
machine check code. This is mostly to make testing easier,
if someone runs into a problem we can ask them to try
with the CONFIG switched.
The new code is default y for more coverage.
Once there is confidence the 64bit code works well on older hardware
too the CONFIG_X86_OLD_MCE and the associated code can be easily
removed.
This causes a behaviour change for 32bit installations. They now
have to install the mcelog package to be able to log
corrected machine checks.
The 64bit machine check code only handles CPUs which support the
standard Intel machine check architecture described in the IA32 SDM.
The 32bit code has special support for some older CPUs which
have non standard machine check architectures, in particular
WinChip C3 and Intel P5. I made those a separate CONFIG option
and kept them for now. The WinChip variant could be probably
removed without too much pain, it doesn't really do anything
interesting. P5 is also disabled by default (like it
was before) because many motherboards have it miswired, but
according to Alan Cox a few embedded setups use that one.
Forward ported/heavily changed version of old patch, original patch
included review/fixes from Thomas Gleixner, Bert Wesarg.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-04-29 01:07:31 +08:00
|
|
|
#else /* CONFIG_X86_OLD_MCE: */
|
2009-04-08 18:31:25 +08:00
|
|
|
|
|
|
|
int nr_mce_banks;
|
|
|
|
EXPORT_SYMBOL_GPL(nr_mce_banks); /* non-fatal.o */
|
|
|
|
|
|
|
|
/* This has to be run for each processor */
|
|
|
|
void mcheck_init(struct cpuinfo_x86 *c)
|
|
|
|
{
|
|
|
|
if (mce_disabled == 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (c->x86_vendor) {
|
|
|
|
case X86_VENDOR_AMD:
|
|
|
|
amd_mcheck_init(c);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case X86_VENDOR_INTEL:
|
|
|
|
if (c->x86 == 5)
|
|
|
|
intel_p5_mcheck_init(c);
|
|
|
|
if (c->x86 == 6)
|
|
|
|
intel_p6_mcheck_init(c);
|
|
|
|
if (c->x86 == 15)
|
|
|
|
intel_p4_mcheck_init(c);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case X86_VENDOR_CENTAUR:
|
|
|
|
if (c->x86 == 5)
|
|
|
|
winchip_mcheck_init(c);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-04-08 18:31:27 +08:00
|
|
|
printk(KERN_INFO "mce: CPU supports %d MCE banks\n", nr_mce_banks);
|
2009-04-08 18:31:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __init mcheck_enable(char *str)
|
|
|
|
{
|
|
|
|
mce_disabled = -1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
__setup("mce", mcheck_enable);
|
|
|
|
|
2009-04-29 05:07:25 +08:00
|
|
|
#endif /* CONFIG_X86_OLD_MCE */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Old style boot options parsing. Only for compatibility.
|
|
|
|
*/
|
|
|
|
static int __init mcheck_disable(char *str)
|
|
|
|
{
|
|
|
|
mce_disabled = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("nomce", mcheck_disable);
|