2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* Machine check handler.
|
|
|
|
* K8 parts Copyright 2002,2003 Andi Kleen, SuSE Labs.
|
2007-10-23 14:37:23 -06:00
|
|
|
* Rest from unknown author(s).
|
|
|
|
* 2004 Andi Kleen. Rewrote most of it.
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/sched.h>
|
2008-05-20 11:17:02 -06:00
|
|
|
#include <linux/smp_lock.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/rcupdate.h>
|
|
|
|
#include <linux/kallsyms.h>
|
|
|
|
#include <linux/sysdev.h>
|
|
|
|
#include <linux/miscdevice.h>
|
|
|
|
#include <linux/fs.h>
|
2006-01-11 13:17:48 -07:00
|
|
|
#include <linux/capability.h>
|
2005-07-28 22:15:39 -06:00
|
|
|
#include <linux/cpu.h>
|
|
|
|
#include <linux/percpu.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 09:10:36 -06:00
|
|
|
#include <linux/poll.h>
|
|
|
|
#include <linux/thread_info.h>
|
2005-09-12 10:49:24 -06:00
|
|
|
#include <linux/ctype.h>
|
2007-02-13 05:26:23 -07:00
|
|
|
#include <linux/kmod.h>
|
2007-05-08 01:27:03 -06:00
|
|
|
#include <linux/kdebug.h>
|
2007-10-23 14:37:23 -06:00
|
|
|
#include <asm/processor.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <asm/msr.h>
|
|
|
|
#include <asm/mce.h>
|
|
|
|
#include <asm/uaccess.h>
|
2006-01-11 14:46:54 -07:00
|
|
|
#include <asm/smp.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 09:10:36 -06:00
|
|
|
#include <asm/idle.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#define MISC_MCELOG_MINOR 227
|
2008-05-12 07:43:34 -06:00
|
|
|
#define NR_SYSFS_BANKS 6
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-04-07 11:49:57 -06:00
|
|
|
atomic_t mce_entry;
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
static int mce_dont_init;
|
|
|
|
|
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 09:10:37 -06: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)
|
|
|
|
*/
|
2005-04-16 16:20:36 -06:00
|
|
|
static int tolerant = 1;
|
|
|
|
static int banks;
|
2008-05-12 07:43:34 -06:00
|
|
|
static unsigned long bank[NR_SYSFS_BANKS] = { [0 ... NR_SYSFS_BANKS-1] = ~0UL };
|
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 09:10:36 -06:00
|
|
|
static unsigned long notify_user;
|
2005-04-16 16:25:09 -06:00
|
|
|
static int rip_msr;
|
2008-04-22 09:22:21 -06:00
|
|
|
static int mce_bootlog = -1;
|
2007-02-13 05:26:23 -07:00
|
|
|
static atomic_t mce_events;
|
|
|
|
|
|
|
|
static char trigger[128];
|
|
|
|
static char *trigger_argv[2] = { trigger, NULL };
|
2005-04-16 16:20:36 -06: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 09:10:36 -06:00
|
|
|
static DECLARE_WAIT_QUEUE_HEAD(mce_wait);
|
|
|
|
|
2005-04-16 16:20:36 -06: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 05:30:30 -07:00
|
|
|
static struct mce_log mcelog = {
|
2005-04-16 16:20:36 -06:00
|
|
|
MCE_LOG_SIGNATURE,
|
|
|
|
MCE_LOG_LEN,
|
2007-10-23 14:37:23 -06:00
|
|
|
};
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
void mce_log(struct mce *mce)
|
|
|
|
{
|
|
|
|
unsigned next, entry;
|
2007-02-13 05:26:23 -07:00
|
|
|
atomic_inc(&mce_events);
|
2005-04-16 16:20:36 -06:00
|
|
|
mce->finished = 0;
|
2005-09-29 16:01:27 -06:00
|
|
|
wmb();
|
2005-04-16 16:20:36 -06:00
|
|
|
for (;;) {
|
|
|
|
entry = rcu_dereference(mcelog.next);
|
2005-09-12 10:49:24 -06:00
|
|
|
for (;;) {
|
|
|
|
/* When the buffer fills up discard new entries. Assume
|
|
|
|
that the earlier errors are the more interesting. */
|
|
|
|
if (entry >= MCE_LOG_LEN) {
|
2008-01-30 05:30:55 -07:00
|
|
|
set_bit(MCE_OVERFLOW, (unsigned long *)&mcelog.flags);
|
2005-09-12 10:49:24 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Old left over entry. Skip. */
|
|
|
|
if (mcelog.entry[entry].finished) {
|
|
|
|
entry++;
|
|
|
|
continue;
|
|
|
|
}
|
2005-09-29 16:01:27 -06:00
|
|
|
break;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
smp_rmb();
|
|
|
|
next = entry + 1;
|
|
|
|
if (cmpxchg(&mcelog.next, entry, next) == entry)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
memcpy(mcelog.entry + entry, mce, sizeof(struct mce));
|
2005-09-29 16:01:27 -06:00
|
|
|
wmb();
|
2005-04-16 16:20:36 -06:00
|
|
|
mcelog.entry[entry].finished = 1;
|
2005-09-29 16:01:27 -06:00
|
|
|
wmb();
|
2005-04-16 16:20:36 -06: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 09:10:36 -06:00
|
|
|
set_bit(0, ¬ify_user);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void print_mce(struct mce *m)
|
|
|
|
{
|
|
|
|
printk(KERN_EMERG "\n"
|
2006-01-11 14:44:48 -07:00
|
|
|
KERN_EMERG "HARDWARE ERROR\n"
|
2005-04-16 16:20:36 -06:00
|
|
|
KERN_EMERG
|
|
|
|
"CPU %d: Machine Check Exception: %16Lx Bank %d: %016Lx\n",
|
|
|
|
m->cpu, m->mcgstatus, m->bank, m->status);
|
2008-01-30 05:30:56 -07:00
|
|
|
if (m->ip) {
|
2007-10-23 14:37:23 -06:00
|
|
|
printk(KERN_EMERG "RIP%s %02x:<%016Lx> ",
|
2005-04-16 16:20:36 -06:00
|
|
|
!(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
|
2008-01-30 05:30:56 -07:00
|
|
|
m->cs, m->ip);
|
2005-04-16 16:20:36 -06:00
|
|
|
if (m->cs == __KERNEL_CS)
|
2008-01-30 05:30:56 -07:00
|
|
|
print_symbol("{%s}", m->ip);
|
2005-04-16 16:20:36 -06:00
|
|
|
printk("\n");
|
|
|
|
}
|
2007-10-23 14:37:23 -06:00
|
|
|
printk(KERN_EMERG "TSC %Lx ", m->tsc);
|
2005-04-16 16:20:36 -06:00
|
|
|
if (m->addr)
|
|
|
|
printk("ADDR %Lx ", m->addr);
|
|
|
|
if (m->misc)
|
2007-10-23 14:37:23 -06:00
|
|
|
printk("MISC %Lx ", m->misc);
|
2005-04-16 16:20:36 -06:00
|
|
|
printk("\n");
|
2006-01-11 14:44:48 -07:00
|
|
|
printk(KERN_EMERG "This is not a software problem!\n");
|
2007-10-23 14:37:23 -06:00
|
|
|
printk(KERN_EMERG "Run through mcelog --ascii to decode "
|
|
|
|
"and contact your hardware vendor\n");
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void mce_panic(char *msg, struct mce *backup, unsigned long start)
|
2007-10-23 14:37:23 -06:00
|
|
|
{
|
2005-04-16 16:20:36 -06: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 09:10:36 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
oops_begin();
|
|
|
|
for (i = 0; i < MCE_LOG_LEN; i++) {
|
|
|
|
unsigned long tsc = mcelog.entry[i].tsc;
|
2007-10-23 14:37:23 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
if (time_before(tsc, start))
|
|
|
|
continue;
|
2007-10-23 14:37:23 -06:00
|
|
|
print_mce(&mcelog.entry[i]);
|
2005-04-16 16:20:36 -06: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 09:10:36 -06:00
|
|
|
panic(msg);
|
2007-10-23 14:37:23 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
static int mce_available(struct cpuinfo_x86 *c)
|
|
|
|
{
|
2006-03-24 04:15:11 -07:00
|
|
|
return cpu_has(c, X86_FEATURE_MCE) && cpu_has(c, X86_FEATURE_MCA);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2005-04-16 16:25:09 -06:00
|
|
|
static inline void mce_get_rip(struct mce *m, struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
if (regs && (m->mcgstatus & MCG_STATUS_RIPV)) {
|
2008-01-30 05:30:56 -07:00
|
|
|
m->ip = regs->ip;
|
2005-04-16 16:25:09 -06:00
|
|
|
m->cs = regs->cs;
|
|
|
|
} else {
|
2008-01-30 05:30:56 -07:00
|
|
|
m->ip = 0;
|
2005-04-16 16:25:09 -06:00
|
|
|
m->cs = 0;
|
|
|
|
}
|
|
|
|
if (rip_msr) {
|
|
|
|
/* Assume the RIP in the MSR is exact. Is this true? */
|
|
|
|
m->mcgstatus |= MCG_STATUS_EIPV;
|
2008-01-30 05:30:56 -07:00
|
|
|
rdmsrl(rip_msr, m->ip);
|
2005-04-16 16:25:09 -06:00
|
|
|
m->cs = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-23 14:37:23 -06:00
|
|
|
/*
|
2005-04-16 16:20:36 -06:00
|
|
|
* The actual machine check handler
|
|
|
|
*/
|
|
|
|
void do_machine_check(struct pt_regs * regs, long error_code)
|
|
|
|
{
|
|
|
|
struct mce m, panicm;
|
|
|
|
u64 mcestart = 0;
|
|
|
|
int i;
|
|
|
|
int panicm_found = 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 09:10:37 -06: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;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-04-07 11:49:57 -06:00
|
|
|
atomic_inc(&mce_entry);
|
|
|
|
|
2008-01-30 05:31:23 -07:00
|
|
|
if ((regs
|
|
|
|
&& notify_die(DIE_NMI, "machine check", regs, error_code,
|
|
|
|
18, SIGKILL) == NOTIFY_STOP)
|
|
|
|
|| !banks)
|
2006-04-07 11:49:57 -06:00
|
|
|
goto out2;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
memset(&m, 0, sizeof(struct mce));
|
2006-09-26 02:52:37 -06:00
|
|
|
m.cpu = smp_processor_id();
|
2005-04-16 16:20:36 -06:00
|
|
|
rdmsrl(MSR_IA32_MCG_STATUS, m.mcgstatus);
|
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 09:10:37 -06:00
|
|
|
/* if the restart IP is not valid, we're done for */
|
2005-04-16 16:20:36 -06: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 09:10:37 -06:00
|
|
|
no_way_out = 1;
|
2007-10-23 14:37:23 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
rdtscll(mcestart);
|
|
|
|
barrier();
|
|
|
|
|
|
|
|
for (i = 0; i < banks; i++) {
|
2008-05-12 07:43:34 -06:00
|
|
|
if (i < NR_SYSFS_BANKS && !bank[i])
|
2005-04-16 16:20:36 -06:00
|
|
|
continue;
|
2007-10-23 14:37:23 -06:00
|
|
|
|
|
|
|
m.misc = 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
m.addr = 0;
|
|
|
|
m.bank = i;
|
|
|
|
m.tsc = 0;
|
|
|
|
|
|
|
|
rdmsrl(MSR_IA32_MC0_STATUS + i*4, m.status);
|
|
|
|
if ((m.status & MCI_STATUS_VAL) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
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 09:10:37 -06: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;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m.status & MCI_STATUS_MISCV)
|
|
|
|
rdmsrl(MSR_IA32_MC0_MISC + i*4, m.misc);
|
|
|
|
if (m.status & MCI_STATUS_ADDRV)
|
|
|
|
rdmsrl(MSR_IA32_MC0_ADDR + i*4, m.addr);
|
|
|
|
|
2005-04-16 16:25:09 -06:00
|
|
|
mce_get_rip(&m, regs);
|
2005-08-07 10:42:07 -06:00
|
|
|
if (error_code >= 0)
|
2005-04-16 16:20:36 -06:00
|
|
|
rdtscll(m.tsc);
|
2005-08-07 10:42:07 -06:00
|
|
|
if (error_code != -2)
|
|
|
|
mce_log(&m);
|
2005-04-16 16:20:36 -06: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)) {
|
|
|
|
panicm = m;
|
|
|
|
panicm_found = 1;
|
|
|
|
}
|
|
|
|
|
2005-09-13 02:25:16 -06:00
|
|
|
add_taint(TAINT_MACHINE_CHECK);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Never do anything final in the polling timer */
|
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 09:10:36 -06:00
|
|
|
if (!regs)
|
2005-04-16 16:20:36 -06:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* If we didn't find an uncorrectable error, pick
|
|
|
|
the last one (shouldn't happen, just being safe). */
|
|
|
|
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 09:10:37 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have decided that we just CAN'T continue, and the user
|
|
|
|
* has not set tolerant to an insane level, give up and die.
|
|
|
|
*/
|
|
|
|
if (no_way_out && tolerant < 3)
|
2005-04-16 16:20:36 -06: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 09:10:37 -06: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-16 16:20:36 -06: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 09:10:37 -06: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 05:30:56 -07: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 09:10:37 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we know that the error was in user space, send a
|
|
|
|
* SIGBUS. Otherwise, panic if tolerance is low.
|
|
|
|
*
|
|
|
|
* do_exit() takes an awful lot of locks and has a slight
|
|
|
|
* risk of deadlocking.
|
|
|
|
*/
|
|
|
|
if (user_space) {
|
2005-04-16 16:20:36 -06:00
|
|
|
do_exit(SIGBUS);
|
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 09:10:37 -06:00
|
|
|
} else if (panic_on_oops || tolerant < 2) {
|
|
|
|
mce_panic("Uncorrected machine check",
|
|
|
|
&panicm, mcestart);
|
|
|
|
}
|
2005-04-16 16:20:36 -06: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 09:10:36 -06:00
|
|
|
/* notify userspace ASAP */
|
|
|
|
set_thread_flag(TIF_MCE_NOTIFY);
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
out:
|
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 09:10:37 -06:00
|
|
|
/* the last thing we do is clear state */
|
|
|
|
for (i = 0; i < banks; i++)
|
|
|
|
wrmsrl(MSR_IA32_MC0_STATUS+4*i, 0);
|
2005-04-16 16:20:36 -06:00
|
|
|
wrmsrl(MSR_IA32_MCG_STATUS, 0);
|
2006-04-07 11:49:57 -06:00
|
|
|
out2:
|
|
|
|
atomic_dec(&mce_entry);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-09-26 02:52:42 -06:00
|
|
|
#ifdef CONFIG_X86_MCE_INTEL
|
|
|
|
/***
|
|
|
|
* mce_log_therm_throt_event - Logs the thermal throttling event to mcelog
|
2007-10-19 17:25:36 -06:00
|
|
|
* @cpu: The CPU on which the event occurred.
|
2006-09-26 02:52:42 -06: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.
|
|
|
|
*/
|
|
|
|
void mce_log_therm_throt_event(unsigned int cpu, __u64 status)
|
|
|
|
{
|
|
|
|
struct mce m;
|
|
|
|
|
|
|
|
memset(&m, 0, sizeof(m));
|
|
|
|
m.cpu = cpu;
|
|
|
|
m.bank = MCE_THERMAL_BANK;
|
|
|
|
m.status = status;
|
|
|
|
rdtscll(m.tsc);
|
|
|
|
mce_log(&m);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_X86_MCE_INTEL */
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
2007-05-02 11:27:19 -06: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-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
static int check_interval = 5 * 60; /* 5 minutes */
|
2007-05-02 11:27:19 -06:00
|
|
|
static int next_interval; /* in jiffies */
|
2006-11-22 07:55:48 -07:00
|
|
|
static void mcheck_timer(struct work_struct *work);
|
|
|
|
static DECLARE_DELAYED_WORK(mcheck_work, mcheck_timer);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
static void mcheck_check_cpu(void *info)
|
|
|
|
{
|
|
|
|
if (mce_available(¤t_cpu_data))
|
|
|
|
do_machine_check(NULL, 0);
|
|
|
|
}
|
|
|
|
|
2006-11-22 07:55:48 -07:00
|
|
|
static void mcheck_timer(struct work_struct *work)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-05-09 01:39:44 -06:00
|
|
|
on_each_cpu(mcheck_check_cpu, NULL, 1);
|
2005-04-16 16:20:36 -06: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 09:10:36 -06:00
|
|
|
* Alert userspace if needed. If we logged an MCE, reduce the
|
|
|
|
* polling interval, otherwise increase the polling interval.
|
2005-04-16 16:20:36 -06: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 09:10:36 -06:00
|
|
|
if (mce_notify_user()) {
|
|
|
|
next_interval = max(next_interval/2, HZ/100);
|
|
|
|
} else {
|
2007-10-23 14:37:23 -06:00
|
|
|
next_interval = min(next_interval * 2,
|
2007-07-21 09:10:44 -06:00
|
|
|
(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 09:10:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
schedule_delayed_work(&mcheck_work, next_interval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is only called from process context. This is where we do
|
|
|
|
* anything we need to alert userspace about new MCEs. This is called
|
|
|
|
* directly from the poller and also from entry.S and idle, thanks to
|
|
|
|
* TIF_MCE_NOTIFY.
|
|
|
|
*/
|
|
|
|
int mce_notify_user(void)
|
|
|
|
{
|
|
|
|
clear_thread_flag(TIF_MCE_NOTIFY);
|
|
|
|
if (test_and_clear_bit(0, ¬ify_user)) {
|
2007-05-02 11:27:19 -06:00
|
|
|
static unsigned long last_print;
|
|
|
|
unsigned long now = jiffies;
|
|
|
|
|
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 09:10:36 -06:00
|
|
|
wake_up_interruptible(&mce_wait);
|
|
|
|
if (trigger[0])
|
|
|
|
call_usermodehelper(trigger, trigger_argv, NULL,
|
|
|
|
UMH_NO_WAIT);
|
|
|
|
|
2007-05-02 11:27:19 -06:00
|
|
|
if (time_after_eq(now, last_print + (check_interval*HZ))) {
|
|
|
|
last_print = now;
|
|
|
|
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 09:10:36 -06:00
|
|
|
|
|
|
|
return 1;
|
2005-04-16 16:20:36 -06: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 09:10:36 -06:00
|
|
|
return 0;
|
|
|
|
}
|
2007-05-02 11:27:19 -06: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 09:10:36 -06:00
|
|
|
/* see if the idle task needs to notify userspace */
|
|
|
|
static int
|
|
|
|
mce_idle_callback(struct notifier_block *nfb, unsigned long action, void *junk)
|
|
|
|
{
|
|
|
|
/* IDLE_END should be safe - interrupts are back on */
|
|
|
|
if (action == IDLE_END && test_thread_flag(TIF_MCE_NOTIFY))
|
|
|
|
mce_notify_user();
|
|
|
|
|
|
|
|
return NOTIFY_OK;
|
2005-04-16 16:20:36 -06: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 09:10:36 -06:00
|
|
|
static struct notifier_block mce_idle_notifier = {
|
|
|
|
.notifier_call = mce_idle_callback,
|
|
|
|
};
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
static __init int periodic_mcheck_init(void)
|
2007-10-23 14:37:23 -06:00
|
|
|
{
|
2007-05-02 11:27:19 -06:00
|
|
|
next_interval = check_interval * HZ;
|
|
|
|
if (next_interval)
|
2007-07-21 09:10:44 -06:00
|
|
|
schedule_delayed_work(&mcheck_work,
|
|
|
|
round_jiffies_relative(next_interval));
|
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 09:10:36 -06:00
|
|
|
idle_notifier_register(&mce_idle_notifier);
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
2007-10-23 14:37:23 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
__initcall(periodic_mcheck_init);
|
|
|
|
|
|
|
|
|
2007-10-23 14:37:23 -06:00
|
|
|
/*
|
2005-04-16 16:20:36 -06:00
|
|
|
* Initialize Machine Checks for a CPU.
|
|
|
|
*/
|
|
|
|
static void mce_init(void *dummy)
|
|
|
|
{
|
|
|
|
u64 cap;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
rdmsrl(MSR_IA32_MCG_CAP, cap);
|
|
|
|
banks = cap & 0xff;
|
2008-05-12 07:43:34 -06:00
|
|
|
if (banks > MCE_EXTENDED_BANK) {
|
2008-06-06 01:42:36 -06:00
|
|
|
banks = MCE_EXTENDED_BANK;
|
2008-05-12 07:43:34 -06:00
|
|
|
printk(KERN_INFO "MCE: warning: using only %d banks\n",
|
|
|
|
MCE_EXTENDED_BANK);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2005-04-16 16:25:09 -06:00
|
|
|
/* Use accurate RIP reporting if available. */
|
|
|
|
if ((cap & (1<<9)) && ((cap >> 16) & 0xff) >= 9)
|
|
|
|
rip_msr = MSR_IA32_MCG_EIP;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* Log the machine checks left over from the previous reset.
|
|
|
|
This also clears all registers */
|
2005-08-07 10:42:07 -06:00
|
|
|
do_machine_check(NULL, mce_bootlog ? -1 : -2);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
set_in_cr4(X86_CR4_MCE);
|
|
|
|
|
|
|
|
if (cap & MCG_CTL_P)
|
|
|
|
wrmsr(MSR_IA32_MCG_CTL, 0xffffffff, 0xffffffff);
|
|
|
|
|
|
|
|
for (i = 0; i < banks; i++) {
|
2008-06-24 18:12:56 -06:00
|
|
|
if (i < NR_SYSFS_BANKS)
|
|
|
|
wrmsrl(MSR_IA32_MC0_CTL+4*i, bank[i]);
|
|
|
|
else
|
|
|
|
wrmsrl(MSR_IA32_MC0_CTL+4*i, ~0UL);
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
wrmsrl(MSR_IA32_MC0_STATUS+4*i, 0);
|
2007-10-23 14:37:23 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add per CPU specific workarounds here */
|
[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-25 15:54:58 -06:00
|
|
|
static void __cpuinit mce_cpu_quirks(struct cpuinfo_x86 *c)
|
2007-10-23 14:37:23 -06:00
|
|
|
{
|
2005-04-16 16:20:36 -06:00
|
|
|
/* This should be disabled by the BIOS, but isn't always */
|
2008-04-22 09:22:21 -06:00
|
|
|
if (c->x86_vendor == X86_VENDOR_AMD) {
|
|
|
|
if(c->x86 == 15)
|
|
|
|
/* disable GART TBL walk error reporting, which trips off
|
|
|
|
incorrectly with the IOMMU & 3ware & Cerberus. */
|
|
|
|
clear_bit(10, &bank[4]);
|
|
|
|
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. */
|
|
|
|
mce_bootlog = 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2005-11-05 09:25:54 -07:00
|
|
|
|
2007-10-23 14:37:23 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06: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-25 15:54:58 -06:00
|
|
|
static void __cpuinit mce_cpu_features(struct cpuinfo_x86 *c)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
switch (c->x86_vendor) {
|
|
|
|
case X86_VENDOR_INTEL:
|
|
|
|
mce_intel_feature_init(c);
|
|
|
|
break;
|
2005-11-05 09:25:53 -07:00
|
|
|
case X86_VENDOR_AMD:
|
|
|
|
mce_amd_feature_init(c);
|
|
|
|
break;
|
2005-04-16 16:20:36 -06:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-23 14:37:23 -06:00
|
|
|
/*
|
2005-04-16 16:20:36 -06:00
|
|
|
* Called for each booted CPU to set up machine checks.
|
2007-10-23 14:37:23 -06:00
|
|
|
* Must be called with preempt off.
|
2005-04-16 16:20:36 -06: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-25 15:54:58 -06:00
|
|
|
void __cpuinit mcheck_init(struct cpuinfo_x86 *c)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2007-10-23 14:37:23 -06:00
|
|
|
mce_cpu_quirks(c);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
if (mce_dont_init ||
|
|
|
|
!mce_available(c))
|
|
|
|
return;
|
|
|
|
|
|
|
|
mce_init(NULL);
|
|
|
|
mce_cpu_features(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Character device to read and clear the MCE log.
|
|
|
|
*/
|
|
|
|
|
2007-07-21 09:10:35 -06:00
|
|
|
static DEFINE_SPINLOCK(mce_state_lock);
|
|
|
|
static int open_count; /* #times opened */
|
|
|
|
static int open_exclu; /* already open exclusive? */
|
|
|
|
|
|
|
|
static int mce_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
2008-05-20 11:17:02 -06:00
|
|
|
lock_kernel();
|
2007-07-21 09:10:35 -06:00
|
|
|
spin_lock(&mce_state_lock);
|
|
|
|
|
|
|
|
if (open_exclu || (open_count && (file->f_flags & O_EXCL))) {
|
|
|
|
spin_unlock(&mce_state_lock);
|
2008-05-20 11:17:02 -06:00
|
|
|
unlock_kernel();
|
2007-07-21 09:10:35 -06:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (file->f_flags & O_EXCL)
|
|
|
|
open_exclu = 1;
|
|
|
|
open_count++;
|
|
|
|
|
|
|
|
spin_unlock(&mce_state_lock);
|
2008-05-20 11:17:02 -06:00
|
|
|
unlock_kernel();
|
2007-07-21 09:10:35 -06: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 09:10:37 -06:00
|
|
|
return nonseekable_open(inode, file);
|
2007-07-21 09:10:35 -06: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-23 14:37:23 -06:00
|
|
|
static void collect_tscs(void *data)
|
|
|
|
{
|
2005-04-16 16:20:36 -06:00
|
|
|
unsigned long *cpu_tsc = (unsigned long *)data;
|
2007-10-23 14:37:23 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
rdtscll(cpu_tsc[smp_processor_id()]);
|
2007-10-23 14:37:23 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-10-23 14:37:23 -06:00
|
|
|
static ssize_t mce_read(struct file *filp, char __user *ubuf, size_t usize,
|
|
|
|
loff_t *off)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2005-04-16 16:25:10 -06:00
|
|
|
unsigned long *cpu_tsc;
|
2008-01-30 05:31:17 -07:00
|
|
|
static DEFINE_MUTEX(mce_read_mutex);
|
2005-04-16 16:20:36 -06:00
|
|
|
unsigned next;
|
|
|
|
char __user *buf = ubuf;
|
|
|
|
int i, err;
|
|
|
|
|
2008-07-18 19:11:27 -06:00
|
|
|
cpu_tsc = kmalloc(nr_cpu_ids * sizeof(long), GFP_KERNEL);
|
2005-04-16 16:25:10 -06:00
|
|
|
if (!cpu_tsc)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2008-01-30 05:31:17 -07:00
|
|
|
mutex_lock(&mce_read_mutex);
|
2005-04-16 16:20:36 -06:00
|
|
|
next = rcu_dereference(mcelog.next);
|
|
|
|
|
|
|
|
/* Only supports full reads right now */
|
2007-10-23 14:37:23 -06:00
|
|
|
if (*off != 0 || usize < MCE_LOG_LEN*sizeof(struct mce)) {
|
2008-01-30 05:31:17 -07:00
|
|
|
mutex_unlock(&mce_read_mutex);
|
2005-04-16 16:25:10 -06:00
|
|
|
kfree(cpu_tsc);
|
2005-04-16 16:20:36 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = 0;
|
2007-10-23 14:37:23 -06:00
|
|
|
for (i = 0; i < next; i++) {
|
2005-09-12 10:49:24 -06:00
|
|
|
unsigned long start = jiffies;
|
2007-10-23 14:37:23 -06:00
|
|
|
|
2005-09-12 10:49:24 -06:00
|
|
|
while (!mcelog.entry[i].finished) {
|
2007-06-23 18:16:45 -06:00
|
|
|
if (time_after_eq(jiffies, start + 2)) {
|
2005-09-12 10:49:24 -06:00
|
|
|
memset(mcelog.entry + i,0, sizeof(struct mce));
|
2007-06-23 18:16:45 -06:00
|
|
|
goto timeout;
|
2005-09-12 10:49:24 -06:00
|
|
|
}
|
|
|
|
cpu_relax();
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
smp_rmb();
|
|
|
|
err |= copy_to_user(buf, mcelog.entry + i, sizeof(struct mce));
|
2007-10-23 14:37:23 -06:00
|
|
|
buf += sizeof(struct mce);
|
2007-06-23 18:16:45 -06:00
|
|
|
timeout:
|
|
|
|
;
|
2007-10-23 14:37:23 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
memset(mcelog.entry, 0, next * sizeof(struct mce));
|
|
|
|
mcelog.next = 0;
|
|
|
|
|
2005-06-25 15:55:38 -06:00
|
|
|
synchronize_sched();
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-10-23 14:37:23 -06:00
|
|
|
/*
|
|
|
|
* Collect entries that were still getting written before the
|
|
|
|
* synchronize.
|
|
|
|
*/
|
2008-05-09 01:39:44 -06:00
|
|
|
on_each_cpu(collect_tscs, cpu_tsc, 1);
|
2007-10-23 14:37:23 -06: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-16 16:20:36 -06:00
|
|
|
smp_rmb();
|
|
|
|
buf += sizeof(struct mce);
|
|
|
|
memset(&mcelog.entry[i], 0, sizeof(struct mce));
|
|
|
|
}
|
2007-10-23 14:37:23 -06:00
|
|
|
}
|
2008-01-30 05:31:17 -07:00
|
|
|
mutex_unlock(&mce_read_mutex);
|
2005-04-16 16:25:10 -06:00
|
|
|
kfree(cpu_tsc);
|
2007-10-23 14:37:23 -06:00
|
|
|
return err ? -EFAULT : buf - ubuf;
|
2005-04-16 16:20:36 -06: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 09:10:36 -06: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 05:32:59 -07:00
|
|
|
static long mce_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
int __user *p = (int __user *)arg;
|
2007-10-23 14:37:23 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
2007-10-23 14:37:23 -06:00
|
|
|
return -EPERM;
|
2005-04-16 16:20:36 -06:00
|
|
|
switch (cmd) {
|
2007-10-23 14:37:23 -06:00
|
|
|
case MCE_GET_RECORD_LEN:
|
2005-04-16 16:20:36 -06:00
|
|
|
return put_user(sizeof(struct mce), p);
|
|
|
|
case MCE_GET_LOG_LEN:
|
2007-10-23 14:37:23 -06:00
|
|
|
return put_user(MCE_LOG_LEN, p);
|
2005-04-16 16:20:36 -06:00
|
|
|
case MCE_GETCLEAR_FLAGS: {
|
|
|
|
unsigned flags;
|
2007-10-23 14:37:23 -06:00
|
|
|
|
|
|
|
do {
|
2005-04-16 16:20:36 -06:00
|
|
|
flags = mcelog.flags;
|
2007-10-23 14:37:23 -06:00
|
|
|
} while (cmpxchg(&mcelog.flags, flags, 0) != flags);
|
|
|
|
return put_user(flags, p);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
default:
|
2007-10-23 14:37:23 -06:00
|
|
|
return -ENOTTY;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-02-12 01:55:31 -07:00
|
|
|
static const struct file_operations mce_chrdev_ops = {
|
2007-07-21 09:10:35 -06:00
|
|
|
.open = mce_open,
|
|
|
|
.release = mce_release,
|
2005-04-16 16:20:36 -06:00
|
|
|
.read = mce_read,
|
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 09:10:36 -06:00
|
|
|
.poll = mce_poll,
|
2008-01-30 05:32:59 -07:00
|
|
|
.unlocked_ioctl = mce_ioctl,
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct miscdevice mce_log_device = {
|
|
|
|
MISC_MCELOG_MINOR,
|
|
|
|
"mcelog",
|
|
|
|
&mce_chrdev_ops,
|
|
|
|
};
|
|
|
|
|
2007-07-22 03:12:32 -06:00
|
|
|
static unsigned long old_cr4 __initdata;
|
|
|
|
|
|
|
|
void __init stop_mce(void)
|
|
|
|
{
|
|
|
|
old_cr4 = read_cr4();
|
|
|
|
clear_in_cr4(X86_CR4_MCE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __init restart_mce(void)
|
|
|
|
{
|
|
|
|
if (old_cr4 & X86_CR4_MCE)
|
|
|
|
set_in_cr4(X86_CR4_MCE);
|
|
|
|
}
|
|
|
|
|
2007-10-23 14:37:23 -06:00
|
|
|
/*
|
|
|
|
* Old style boot options parsing. Only for compatibility.
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
static int __init mcheck_disable(char *str)
|
|
|
|
{
|
|
|
|
mce_dont_init = 1;
|
2006-03-31 03:30:33 -07:00
|
|
|
return 1;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-10-19 17:25:36 -06:00
|
|
|
/* mce=off disables machine check. Note you can re-enable it later
|
2005-08-07 10:42:07 -06:00
|
|
|
using sysfs.
|
2005-09-12 10:49:24 -06:00
|
|
|
mce=TOLERANCELEVEL (number, see above)
|
2005-11-05 09:25:54 -07:00
|
|
|
mce=bootlog Log MCEs from before booting. Disabled by default on AMD.
|
|
|
|
mce=nobootlog Don't log MCEs from before booting. */
|
2005-04-16 16:20:36 -06:00
|
|
|
static int __init mcheck_enable(char *str)
|
|
|
|
{
|
|
|
|
if (!strcmp(str, "off"))
|
|
|
|
mce_dont_init = 1;
|
2005-11-05 09:25:54 -07:00
|
|
|
else if (!strcmp(str, "bootlog") || !strcmp(str,"nobootlog"))
|
|
|
|
mce_bootlog = str[0] == 'b';
|
2005-09-12 10:49:24 -06:00
|
|
|
else if (isdigit(str[0]))
|
|
|
|
get_option(&str, &tolerant);
|
2005-04-16 16:20:36 -06:00
|
|
|
else
|
2007-10-23 14:37:23 -06:00
|
|
|
printk("mce= argument %s ignored. Please use /sys", str);
|
2006-03-31 03:30:33 -07:00
|
|
|
return 1;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
__setup("nomce", mcheck_disable);
|
2007-10-17 10:04:38 -06:00
|
|
|
__setup("mce=", mcheck_enable);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-10-23 14:37:23 -06:00
|
|
|
/*
|
2005-04-16 16:20:36 -06:00
|
|
|
* Sysfs support
|
2007-10-23 14:37:23 -06:00
|
|
|
*/
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-09-12 10:49:24 -06: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 readded later using
|
|
|
|
CPU hotplug. */
|
2005-04-16 16:20:36 -06:00
|
|
|
static int mce_resume(struct sys_device *dev)
|
|
|
|
{
|
2005-09-12 10:49:24 -06:00
|
|
|
mce_init(NULL);
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reinit MCEs after user configuration changes */
|
2007-10-23 14:37:23 -06:00
|
|
|
static void mce_restart(void)
|
|
|
|
{
|
2007-05-02 11:27:19 -06:00
|
|
|
if (next_interval)
|
2005-04-16 16:20:36 -06:00
|
|
|
cancel_delayed_work(&mcheck_work);
|
|
|
|
/* Timer race is harmless here */
|
2008-05-09 01:39:44 -06:00
|
|
|
on_each_cpu(mce_init, NULL, 1);
|
2007-05-02 11:27:19 -06:00
|
|
|
next_interval = check_interval * HZ;
|
|
|
|
if (next_interval)
|
2007-07-21 09:10:44 -06:00
|
|
|
schedule_delayed_work(&mcheck_work,
|
|
|
|
round_jiffies_relative(next_interval));
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct sysdev_class mce_sysclass = {
|
|
|
|
.resume = mce_resume,
|
2007-12-19 18:09:39 -07:00
|
|
|
.name = "machinecheck",
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
2006-06-26 05:58:50 -06:00
|
|
|
DEFINE_PER_CPU(struct sys_device, device_mce);
|
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-22 14:23:09 -06:00
|
|
|
void (*threshold_cpu_callback)(unsigned long action, unsigned int cpu) __cpuinitdata;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* Why are there no generic functions for this? */
|
|
|
|
#define ACCESSOR(name, var, start) \
|
2008-07-01 10:48:41 -06:00
|
|
|
static ssize_t show_ ## name(struct sys_device *s, \
|
|
|
|
struct sysdev_attribute *attr, \
|
|
|
|
char *buf) { \
|
2007-10-23 14:37:23 -06:00
|
|
|
return sprintf(buf, "%lx\n", (unsigned long)var); \
|
|
|
|
} \
|
2008-07-01 10:48:41 -06:00
|
|
|
static ssize_t set_ ## name(struct sys_device *s, \
|
|
|
|
struct sysdev_attribute *attr, \
|
|
|
|
const char *buf, size_t siz) { \
|
2007-10-23 14:37:23 -06:00
|
|
|
char *end; \
|
|
|
|
unsigned long new = simple_strtoul(buf, &end, 0); \
|
|
|
|
if (end == buf) return -EINVAL; \
|
|
|
|
var = new; \
|
|
|
|
start; \
|
|
|
|
return end-buf; \
|
|
|
|
} \
|
2005-04-16 16:20:36 -06:00
|
|
|
static SYSDEV_ATTR(name, 0644, show_ ## name, set_ ## name);
|
|
|
|
|
2008-05-12 07:43:34 -06:00
|
|
|
/*
|
|
|
|
* TBD should generate these dynamically based on number of available banks.
|
|
|
|
* Have only 6 contol banks in /sysfs until then.
|
|
|
|
*/
|
2005-04-16 16:20:36 -06:00
|
|
|
ACCESSOR(bank0ctl,bank[0],mce_restart())
|
|
|
|
ACCESSOR(bank1ctl,bank[1],mce_restart())
|
|
|
|
ACCESSOR(bank2ctl,bank[2],mce_restart())
|
|
|
|
ACCESSOR(bank3ctl,bank[3],mce_restart())
|
|
|
|
ACCESSOR(bank4ctl,bank[4],mce_restart())
|
2006-01-11 14:43:06 -07:00
|
|
|
ACCESSOR(bank5ctl,bank[5],mce_restart())
|
2007-02-13 05:26:23 -07:00
|
|
|
|
2008-07-01 10:48:41 -06:00
|
|
|
static ssize_t show_trigger(struct sys_device *s, struct sysdev_attribute *attr,
|
|
|
|
char *buf)
|
2007-02-13 05:26:23 -07:00
|
|
|
{
|
|
|
|
strcpy(buf, trigger);
|
|
|
|
strcat(buf, "\n");
|
|
|
|
return strlen(trigger) + 1;
|
|
|
|
}
|
|
|
|
|
2008-07-01 10:48:41 -06:00
|
|
|
static ssize_t set_trigger(struct sys_device *s, struct sysdev_attribute *attr,
|
|
|
|
const char *buf,size_t siz)
|
2007-02-13 05:26:23 -07:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
int len;
|
|
|
|
strncpy(trigger, buf, sizeof(trigger));
|
|
|
|
trigger[sizeof(trigger)-1] = 0;
|
|
|
|
len = strlen(trigger);
|
|
|
|
p = strchr(trigger, '\n');
|
|
|
|
if (*p) *p = 0;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SYSDEV_ATTR(trigger, 0644, show_trigger, set_trigger);
|
2008-07-01 10:48:43 -06:00
|
|
|
static SYSDEV_INT_ATTR(tolerant, 0644, tolerant);
|
2005-04-16 16:20:36 -06:00
|
|
|
ACCESSOR(check_interval,check_interval,mce_restart())
|
2007-02-13 05:26:23 -07:00
|
|
|
static struct sysdev_attribute *mce_attributes[] = {
|
|
|
|
&attr_bank0ctl, &attr_bank1ctl, &attr_bank2ctl,
|
|
|
|
&attr_bank3ctl, &attr_bank4ctl, &attr_bank5ctl,
|
2008-07-01 10:48:43 -06:00
|
|
|
&attr_tolerant.attr, &attr_check_interval, &attr_trigger,
|
2007-02-13 05:26:23 -07:00
|
|
|
NULL
|
|
|
|
};
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-11-14 18:00:44 -07:00
|
|
|
static cpumask_t mce_device_initialized = CPU_MASK_NONE;
|
|
|
|
|
2005-07-28 22:15:39 -06:00
|
|
|
/* Per cpu sysdev init. All of the cpus still share the same ctl bank */
|
|
|
|
static __cpuinit int mce_create_device(unsigned int cpu)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
int err;
|
2006-01-11 14:43:06 -07:00
|
|
|
int i;
|
2007-10-19 12:35:04 -06:00
|
|
|
|
2007-11-06 18:12:58 -07:00
|
|
|
if (!mce_available(&boot_cpu_data))
|
2005-07-28 22:15:39 -06:00
|
|
|
return -EIO;
|
|
|
|
|
2007-10-18 04:05:15 -06:00
|
|
|
memset(&per_cpu(device_mce, cpu).kobj, 0, sizeof(struct kobject));
|
2005-07-28 22:15:39 -06:00
|
|
|
per_cpu(device_mce,cpu).id = cpu;
|
|
|
|
per_cpu(device_mce,cpu).cls = &mce_sysclass;
|
|
|
|
|
|
|
|
err = sysdev_register(&per_cpu(device_mce,cpu));
|
2007-10-18 04:05:15 -06:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
for (i = 0; mce_attributes[i]; i++) {
|
|
|
|
err = sysdev_create_file(&per_cpu(device_mce,cpu),
|
|
|
|
mce_attributes[i]);
|
|
|
|
if (err)
|
|
|
|
goto error;
|
|
|
|
}
|
2007-11-14 18:00:44 -07:00
|
|
|
cpu_set(cpu, mce_device_initialized);
|
2005-07-28 22:15:39 -06:00
|
|
|
|
2007-10-18 04:05:15 -06:00
|
|
|
return 0;
|
|
|
|
error:
|
|
|
|
while (i--) {
|
|
|
|
sysdev_remove_file(&per_cpu(device_mce,cpu),
|
|
|
|
mce_attributes[i]);
|
2005-07-28 22:15:39 -06:00
|
|
|
}
|
2007-10-18 04:05:15 -06:00
|
|
|
sysdev_unregister(&per_cpu(device_mce,cpu));
|
|
|
|
|
2005-07-28 22:15:39 -06:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2008-08-29 06:15:04 -06:00
|
|
|
static __cpuinit void mce_remove_device(unsigned int cpu)
|
2005-07-28 22:15:39 -06:00
|
|
|
{
|
2006-01-11 14:43:06 -07:00
|
|
|
int i;
|
|
|
|
|
2007-11-14 18:00:44 -07:00
|
|
|
if (!cpu_isset(cpu, mce_device_initialized))
|
|
|
|
return;
|
|
|
|
|
2007-02-13 05:26:23 -07:00
|
|
|
for (i = 0; mce_attributes[i]; i++)
|
2006-01-11 14:43:06 -07:00
|
|
|
sysdev_remove_file(&per_cpu(device_mce,cpu),
|
2007-02-13 05:26:23 -07:00
|
|
|
mce_attributes[i]);
|
2005-07-28 22:15:39 -06:00
|
|
|
sysdev_unregister(&per_cpu(device_mce,cpu));
|
2007-11-14 18:00:44 -07:00
|
|
|
cpu_clear(cpu, mce_device_initialized);
|
2005-07-28 22:15:39 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get notified when a cpu comes on/off. Be hotplug friendly. */
|
2008-01-30 05:33:36 -07:00
|
|
|
static int __cpuinit mce_cpu_callback(struct notifier_block *nfb,
|
|
|
|
unsigned long action, void *hcpu)
|
2005-07-28 22:15:39 -06:00
|
|
|
{
|
|
|
|
unsigned int cpu = (unsigned long)hcpu;
|
|
|
|
|
|
|
|
switch (action) {
|
2007-11-14 18:00:44 -07: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-22 14:23:09 -06:00
|
|
|
if (threshold_cpu_callback)
|
|
|
|
threshold_cpu_callback(action, cpu);
|
2005-07-28 22:15:39 -06:00
|
|
|
break;
|
|
|
|
case CPU_DEAD:
|
2007-05-09 03:35:10 -06: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-22 14:23:09 -06:00
|
|
|
if (threshold_cpu_callback)
|
|
|
|
threshold_cpu_callback(action, cpu);
|
2005-07-28 22:15:39 -06:00
|
|
|
mce_remove_device(cpu);
|
|
|
|
break;
|
|
|
|
}
|
2007-11-14 18:00:44 -07:00
|
|
|
return NOTIFY_OK;
|
2005-07-28 22:15:39 -06:00
|
|
|
}
|
|
|
|
|
2008-01-30 05:33:36 -07:00
|
|
|
static struct notifier_block mce_cpu_notifier __cpuinitdata = {
|
2005-07-28 22:15:39 -06:00
|
|
|
.notifier_call = mce_cpu_callback,
|
|
|
|
};
|
|
|
|
|
|
|
|
static __init int mce_init_device(void)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
int i = 0;
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
if (!mce_available(&boot_cpu_data))
|
|
|
|
return -EIO;
|
|
|
|
err = sysdev_class_register(&mce_sysclass);
|
2007-10-18 04:05:15 -06:00
|
|
|
if (err)
|
|
|
|
return err;
|
2005-07-28 22:15:39 -06:00
|
|
|
|
|
|
|
for_each_online_cpu(i) {
|
2007-10-18 04:05:15 -06:00
|
|
|
err = mce_create_device(i);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2005-07-28 22:15:39 -06:00
|
|
|
}
|
|
|
|
|
2006-07-30 04:03:37 -06:00
|
|
|
register_hotcpu_notifier(&mce_cpu_notifier);
|
2005-04-16 16:20:36 -06:00
|
|
|
misc_register(&mce_log_device);
|
|
|
|
return err;
|
|
|
|
}
|
2005-07-28 22:15:39 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
device_initcall(mce_init_device);
|