2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Machine check handler.
|
2009-04-08 18:31:17 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* K8 parts Copyright 2002,2003 Andi Kleen, SuSE Labs.
|
2007-10-24 04:37:23 +08:00
|
|
|
* Rest from unknown author(s).
|
|
|
|
* 2004 Andi Kleen. Rewrote most of it.
|
2009-02-12 20:43:23 +08:00
|
|
|
* Copyright 2008 Intel Corporation
|
|
|
|
* Author: Andi Kleen
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2009-04-08 18:31:17 +08:00
|
|
|
#include <linux/thread_info.h>
|
|
|
|
#include <linux/capability.h>
|
|
|
|
#include <linux/miscdevice.h>
|
2009-05-28 03:56:54 +08:00
|
|
|
#include <linux/interrupt.h>
|
2009-04-08 18:31:17 +08:00
|
|
|
#include <linux/ratelimit.h>
|
|
|
|
#include <linux/kallsyms.h>
|
|
|
|
#include <linux/rcupdate.h>
|
|
|
|
#include <linux/kobject.h>
|
2009-04-30 15:04:51 +08:00
|
|
|
#include <linux/uaccess.h>
|
2009-04-08 18:31:17 +08:00
|
|
|
#include <linux/kdebug.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/percpu.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/sysdev.h>
|
2009-05-28 03:56:55 +08:00
|
|
|
#include <linux/delay.h>
|
2005-09-13 00:49:24 +08:00
|
|
|
#include <linux/ctype.h>
|
2009-04-08 18:31:17 +08:00
|
|
|
#include <linux/sched.h>
|
2009-02-18 06:07:13 +08:00
|
|
|
#include <linux/sysfs.h>
|
2009-04-08 18:31:17 +08:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kmod.h>
|
|
|
|
#include <linux/poll.h>
|
2009-05-28 03:56:55 +08:00
|
|
|
#include <linux/nmi.h>
|
2009-04-08 18:31:17 +08:00
|
|
|
#include <linux/cpu.h>
|
2009-04-30 15:04:51 +08:00
|
|
|
#include <linux/smp.h>
|
2009-04-08 18:31:17 +08:00
|
|
|
#include <linux/fs.h>
|
x86, mce: support action-optional machine checks
Newer Intel CPUs support a new class of machine checks called recoverable
action optional.
Action Optional means that the CPU detected some form of corruption in
the background and tells the OS about using a machine check
exception. The OS can then take appropiate action, like killing the
process with the corrupted data or logging the event properly to disk.
This is done by the new generic high level memory failure handler added
in a earlier patch. The high level handler takes the address with the
failed memory and does the appropiate action, like killing the process.
In this version of the patch the high level handler is stubbed out
with a weak function to not create a direct dependency on the hwpoison
branch.
The high level handler cannot be directly called from the machine check
exception though, because it has to run in a defined process context to
be able to sleep when taking VM locks (it is not expected to sleep for a
long time, just do so in some exceptional cases like lock contention)
Thus the MCE handler has to queue a work item for process context,
trigger process context and then call the high level handler from there.
This patch adds two path to process context: through a per thread kernel
exit notify_user() callback or through a high priority work item.
The first runs when the process exits back to user space, the other when
it goes to sleep and there is no higher priority process.
The machine check handler will schedule both, and whoever runs first
will grab the event. This is done because quick reaction to this
event is critical to avoid a potential more fatal machine check
when the corruption is consumed.
There is a simple lock less ring buffer to queue the corrupted
addresses between the exception handler and the process context handler.
Then in process context it just calls the high level VM code with
the corrupted PFNs.
The code adds the required code to extract the failed address from
the CPU's machine check registers. It doesn't try to handle all
possible cases -- the specification has 6 different ways to specify
memory address -- but only the linear address.
Most of the required checking has been already done earlier in the
mce_severity rule checking engine. Following the Intel
recommendations Action Optional errors are only enabled for known
situations (encoded in MCACODs). The errors are ignored otherwise,
because they are action optional.
v2: Improve comment, disable preemption while processing ring buffer
(reported by Ying Huang)
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-05-28 03:56:59 +08:00
|
|
|
#include <linux/mm.h>
|
2009-07-31 09:41:42 +08:00
|
|
|
#include <linux/debugfs.h>
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2007-10-24 04:37:23 +08:00
|
|
|
#include <asm/processor.h>
|
2009-05-28 03:56:54 +08:00
|
|
|
#include <asm/hw_irq.h>
|
|
|
|
#include <asm/apic.h>
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
#include <asm/idle.h>
|
2009-05-28 03:56:54 +08:00
|
|
|
#include <asm/ipi.h>
|
2009-04-08 18:31:17 +08:00
|
|
|
#include <asm/mce.h>
|
|
|
|
#include <asm/msr.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-05-28 03:56:55 +08:00
|
|
|
#include "mce-internal.h"
|
2009-04-08 18:31:26 +08:00
|
|
|
|
perf_event, x86, mce: Use TRACE_EVENT() for MCE logging
This approach is the first baby step towards solving many of the
structural problems the x86 MCE logging code is having today:
- It has a private ring-buffer implementation that has a number
of limitations and has been historically fragile and buggy.
- It is using a quirky /dev/mcelog ioctl driven ABI that is MCE
specific. /dev/mcelog is not part of any larger logging
framework and hence has remained on the fringes for many years.
- The MCE logging code is still very unclean partly due to its ABI
limitations. Fields are being reused for multiple purposes, and
the whole message structure is limited and x86 specific to begin
with.
All in one, the x86 tree would like to move away from this private
implementation of an event logging facility to a broader framework.
By using perf events we gain the following advantages:
- Multiple user-space agents can access MCE events. We can have an
mcelog daemon running but also a system-wide tracer capturing
important events in flight-recorder mode.
- Sampling support: the kernel and the user-space call-chain of MCE
events can be stored and analyzed as well. This way actual patterns
of bad behavior can be matched to precisely what kind of activity
happened in the kernel (and/or in the app) around that moment in
time.
- Coupling with other hardware and software events: the PMU can track a
number of other anomalies - monitoring software might chose to
monitor those plus the MCE events as well - in one coherent stream of
events.
- Discovery of MCE sources - tracepoints are enumerated and tools can
act upon the existence (or non-existence) of various channels of MCE
information.
- Filtering support: we just subscribe to and act upon the events we
are interested in. Then even on a per event source basis there's
in-kernel filter expressions available that can restrict the amount
of data that hits the event channel.
- Arbitrary deep per cpu buffering of events - we can buffer 32
entries or we can buffer as much as we want, as long as we have
the RAM.
- An NMI-safe ring-buffer implementation - mappable to user-space.
- Built-in support for timestamping of events, PID markers, CPU
markers, etc.
- A rich ABI accessible over system call interface. Per cpu, per task
and per workload monitoring of MCE events can be done this way. The
ABI itself has a nice, meaningful structure.
- Extensible ABI: new fields can be added without breaking tooling.
New tracepoints can be added as the hardware side evolves. There's
various parsers that can be used.
- Lots of scheduling/buffering/batching modes of operandi for MCE
events. poll() support. mmap() support. read() support. You name it.
- Rich tooling support: even without any MCE specific extensions added
the 'perf' tool today offers various views of MCE data: perf report,
perf stat, perf trace can all be used to view logged MCE events and
perhaps correlate them to certain user-space usage patterns. But it
can be used directly as well, for user-space agents and policy action
in mcelog, etc.
With this we hope to achieve significant code cleanup and feature
improvements in the MCE code, and we hope to be able to drop the
/dev/mcelog facility in the end.
This patch is just a plain dumb dump of mce_log() records to
the tracepoints / perf events framework - a first proof of
concept step.
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Cc: Huang Ying <ying.huang@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
LKML-Reference: <4AD42A0D.7050104@jp.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-10-13 15:19:41 +08:00
|
|
|
#define CREATE_TRACE_POINTS
|
|
|
|
#include <trace/events/mce.h>
|
|
|
|
|
2009-06-15 16:20:20 +08:00
|
|
|
int mce_disabled __read_mostly;
|
2009-04-29 04:50:19 +08:00
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
#define MISC_MCELOG_MINOR 227
|
2009-02-18 06:07:13 +08:00
|
|
|
|
2009-05-28 03:56:55 +08:00
|
|
|
#define SPINUNIT 100 /* 100ns */
|
|
|
|
|
2006-04-08 01:49:57 +08:00
|
|
|
atomic_t mce_entry;
|
|
|
|
|
2009-05-28 03:56:52 +08:00
|
|
|
DEFINE_PER_CPU(unsigned, mce_exception_count);
|
|
|
|
|
x86_64: mcelog tolerant level cleanup
Background:
The MCE handler has several paths that it can take, depending on various
conditions of the MCE status and the value of the 'tolerant' knob. The
exact semantics are not well defined and the code is a bit twisty.
Description:
This patch makes the MCE handler's behavior more clear by documenting the
behavior for various 'tolerant' levels. It also fixes or enhances
several small things in the handler. Specifically:
* If RIPV is set it is not safe to restart, so set the 'no way out'
flag rather than the 'kill it' flag.
* Don't panic() on correctable MCEs.
* If the _OVER bit is set *and* the _UC bit is set (meaning possibly
dropped uncorrected errors), set the 'no way out' flag.
* Use EIPV for testing whether an app can be killed (SIGBUS) rather
than RIPV. According to docs, EIPV indicates that the error is
related to the IP, while RIPV simply means the IP is valid to
restart from.
* Don't clear the MCi_STATUS registers until after the panic() path.
This leaves the status bits set after the panic() so clever BIOSes
can find them (and dumb BIOSes can do nothing).
This patch also calls nonseekable_open() in mce_open (as suggested by akpm).
Result:
Tolerant levels behave almost identically to how they always have, but
not it's well defined. There's a slightly higher chance of panic()ing
when multiple errors happen (a good thing, IMHO). If you take an MBE and
panic(), the error status bits are not cleared.
Alternatives:
None.
Testing:
I used software to inject correctable and uncorrectable errors. With
tolerant = 3, the system usually survives. With tolerant = 2, the system
usually panic()s (PCC) but not always. With tolerant = 1, the system
always panic()s. When the system panic()s, the BIOS is able to detect
that the cause of death was an MC4. I was not able to reproduce the
case of a non-PCC error in userspace, with EIPV, with (tolerant < 3).
That will be rare at best.
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:37 +08:00
|
|
|
/*
|
|
|
|
* Tolerant levels:
|
|
|
|
* 0: always panic on uncorrected errors, log corrected errors
|
|
|
|
* 1: panic or SIGBUS on uncorrected errors, log corrected errors
|
|
|
|
* 2: SIGBUS or log uncorrected errors (if possible), log corrected errors
|
|
|
|
* 3: never panic or SIGBUS, log all errors (for testing only)
|
|
|
|
*/
|
2009-06-15 16:20:20 +08:00
|
|
|
static int tolerant __read_mostly = 1;
|
|
|
|
static int banks __read_mostly;
|
|
|
|
static int rip_msr __read_mostly;
|
|
|
|
static int mce_bootlog __read_mostly = -1;
|
|
|
|
static int monarch_timeout __read_mostly = -1;
|
|
|
|
static int mce_panic_timeout __read_mostly;
|
|
|
|
static int mce_dont_log_ce __read_mostly;
|
|
|
|
int mce_cmci_disabled __read_mostly;
|
|
|
|
int mce_ignore_ce __read_mostly;
|
|
|
|
int mce_ser __read_mostly;
|
2007-02-13 20:26:23 +08:00
|
|
|
|
2009-07-09 06:31:43 +08:00
|
|
|
struct mce_bank *mce_banks __read_mostly;
|
|
|
|
|
2009-06-15 16:20:57 +08:00
|
|
|
/* User mode helper program triggered by machine check event */
|
|
|
|
static unsigned long mce_need_notify;
|
|
|
|
static char mce_helper[128];
|
|
|
|
static char *mce_helper_argv[2] = { mce_helper, NULL };
|
2005-04-17 06:20:36 +08:00
|
|
|
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
static DECLARE_WAIT_QUEUE_HEAD(mce_wait);
|
2009-05-28 03:56:55 +08:00
|
|
|
static DEFINE_PER_CPU(struct mce, mces_seen);
|
|
|
|
static int cpu_missing;
|
|
|
|
|
2009-10-07 19:20:38 +08:00
|
|
|
/*
|
|
|
|
* CPU/chipset specific EDAC code can register a notifier call here to print
|
|
|
|
* MCE errors in a human-readable form.
|
|
|
|
*/
|
|
|
|
ATOMIC_NOTIFIER_HEAD(x86_mce_decoder_chain);
|
|
|
|
EXPORT_SYMBOL_GPL(x86_mce_decoder_chain);
|
|
|
|
|
|
|
|
static int default_decode_mce(struct notifier_block *nb, unsigned long val,
|
|
|
|
void *data)
|
2009-10-01 22:14:32 +08:00
|
|
|
{
|
|
|
|
pr_emerg("No human readable MCE decoding support on this CPU type.\n");
|
|
|
|
pr_emerg("Run the message through 'mcelog --ascii' to decode.\n");
|
2009-10-07 19:20:38 +08:00
|
|
|
|
|
|
|
return NOTIFY_STOP;
|
2009-10-01 22:14:32 +08:00
|
|
|
}
|
|
|
|
|
2009-10-07 19:20:38 +08:00
|
|
|
static struct notifier_block mce_dec_nb = {
|
|
|
|
.notifier_call = default_decode_mce,
|
|
|
|
.priority = -1,
|
|
|
|
};
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
|
2009-02-12 20:49:34 +08:00
|
|
|
/* MCA banks polled by the period polling timer for corrected events */
|
|
|
|
DEFINE_PER_CPU(mce_banks_t, mce_poll_banks) = {
|
|
|
|
[0 ... BITS_TO_LONGS(MAX_NR_BANKS)-1] = ~0UL
|
|
|
|
};
|
|
|
|
|
x86, mce: support action-optional machine checks
Newer Intel CPUs support a new class of machine checks called recoverable
action optional.
Action Optional means that the CPU detected some form of corruption in
the background and tells the OS about using a machine check
exception. The OS can then take appropiate action, like killing the
process with the corrupted data or logging the event properly to disk.
This is done by the new generic high level memory failure handler added
in a earlier patch. The high level handler takes the address with the
failed memory and does the appropiate action, like killing the process.
In this version of the patch the high level handler is stubbed out
with a weak function to not create a direct dependency on the hwpoison
branch.
The high level handler cannot be directly called from the machine check
exception though, because it has to run in a defined process context to
be able to sleep when taking VM locks (it is not expected to sleep for a
long time, just do so in some exceptional cases like lock contention)
Thus the MCE handler has to queue a work item for process context,
trigger process context and then call the high level handler from there.
This patch adds two path to process context: through a per thread kernel
exit notify_user() callback or through a high priority work item.
The first runs when the process exits back to user space, the other when
it goes to sleep and there is no higher priority process.
The machine check handler will schedule both, and whoever runs first
will grab the event. This is done because quick reaction to this
event is critical to avoid a potential more fatal machine check
when the corruption is consumed.
There is a simple lock less ring buffer to queue the corrupted
addresses between the exception handler and the process context handler.
Then in process context it just calls the high level VM code with
the corrupted PFNs.
The code adds the required code to extract the failed address from
the CPU's machine check registers. It doesn't try to handle all
possible cases -- the specification has 6 different ways to specify
memory address -- but only the linear address.
Most of the required checking has been already done earlier in the
mce_severity rule checking engine. Following the Intel
recommendations Action Optional errors are only enabled for known
situations (encoded in MCACODs). The errors are ignored otherwise,
because they are action optional.
v2: Improve comment, disable preemption while processing ring buffer
(reported by Ying Huang)
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-05-28 03:56:59 +08:00
|
|
|
static DEFINE_PER_CPU(struct work_struct, mce_work);
|
|
|
|
|
2009-02-12 20:43:22 +08:00
|
|
|
/* Do initial initialization of a struct mce */
|
|
|
|
void mce_setup(struct mce *m)
|
|
|
|
{
|
|
|
|
memset(m, 0, sizeof(struct mce));
|
2009-05-28 03:56:56 +08:00
|
|
|
m->cpu = m->extcpu = smp_processor_id();
|
2009-02-12 20:43:22 +08:00
|
|
|
rdtscll(m->tsc);
|
2009-05-28 03:56:56 +08:00
|
|
|
/* We hope get_seconds stays lockless */
|
|
|
|
m->time = get_seconds();
|
|
|
|
m->cpuvendor = boot_cpu_data.x86_vendor;
|
|
|
|
m->cpuid = cpuid_eax(1);
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
m->socketid = cpu_data(m->extcpu).phys_proc_id;
|
|
|
|
#endif
|
|
|
|
m->apicid = cpu_data(m->extcpu).initial_apicid;
|
|
|
|
rdmsrl(MSR_IA32_MCG_CAP, m->mcgcap);
|
2009-02-12 20:43:22 +08:00
|
|
|
}
|
|
|
|
|
2009-04-30 01:31:00 +08:00
|
|
|
DEFINE_PER_CPU(struct mce, injectm);
|
|
|
|
EXPORT_PER_CPU_SYMBOL_GPL(injectm);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Lockless MCE logging infrastructure.
|
|
|
|
* This avoids deadlocks on printk locks without having to break locks. Also
|
|
|
|
* separate MCEs from kernel messages to avoid bogus bug reports.
|
|
|
|
*/
|
|
|
|
|
2008-01-30 20:30:30 +08:00
|
|
|
static struct mce_log mcelog = {
|
2009-05-28 03:56:55 +08:00
|
|
|
.signature = MCE_LOG_SIGNATURE,
|
|
|
|
.len = MCE_LOG_LEN,
|
|
|
|
.recordlen = sizeof(struct mce),
|
2007-10-24 04:37:23 +08:00
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
void mce_log(struct mce *mce)
|
|
|
|
{
|
|
|
|
unsigned next, entry;
|
2009-04-08 18:31:17 +08:00
|
|
|
|
perf_event, x86, mce: Use TRACE_EVENT() for MCE logging
This approach is the first baby step towards solving many of the
structural problems the x86 MCE logging code is having today:
- It has a private ring-buffer implementation that has a number
of limitations and has been historically fragile and buggy.
- It is using a quirky /dev/mcelog ioctl driven ABI that is MCE
specific. /dev/mcelog is not part of any larger logging
framework and hence has remained on the fringes for many years.
- The MCE logging code is still very unclean partly due to its ABI
limitations. Fields are being reused for multiple purposes, and
the whole message structure is limited and x86 specific to begin
with.
All in one, the x86 tree would like to move away from this private
implementation of an event logging facility to a broader framework.
By using perf events we gain the following advantages:
- Multiple user-space agents can access MCE events. We can have an
mcelog daemon running but also a system-wide tracer capturing
important events in flight-recorder mode.
- Sampling support: the kernel and the user-space call-chain of MCE
events can be stored and analyzed as well. This way actual patterns
of bad behavior can be matched to precisely what kind of activity
happened in the kernel (and/or in the app) around that moment in
time.
- Coupling with other hardware and software events: the PMU can track a
number of other anomalies - monitoring software might chose to
monitor those plus the MCE events as well - in one coherent stream of
events.
- Discovery of MCE sources - tracepoints are enumerated and tools can
act upon the existence (or non-existence) of various channels of MCE
information.
- Filtering support: we just subscribe to and act upon the events we
are interested in. Then even on a per event source basis there's
in-kernel filter expressions available that can restrict the amount
of data that hits the event channel.
- Arbitrary deep per cpu buffering of events - we can buffer 32
entries or we can buffer as much as we want, as long as we have
the RAM.
- An NMI-safe ring-buffer implementation - mappable to user-space.
- Built-in support for timestamping of events, PID markers, CPU
markers, etc.
- A rich ABI accessible over system call interface. Per cpu, per task
and per workload monitoring of MCE events can be done this way. The
ABI itself has a nice, meaningful structure.
- Extensible ABI: new fields can be added without breaking tooling.
New tracepoints can be added as the hardware side evolves. There's
various parsers that can be used.
- Lots of scheduling/buffering/batching modes of operandi for MCE
events. poll() support. mmap() support. read() support. You name it.
- Rich tooling support: even without any MCE specific extensions added
the 'perf' tool today offers various views of MCE data: perf report,
perf stat, perf trace can all be used to view logged MCE events and
perhaps correlate them to certain user-space usage patterns. But it
can be used directly as well, for user-space agents and policy action
in mcelog, etc.
With this we hope to achieve significant code cleanup and feature
improvements in the MCE code, and we hope to be able to drop the
/dev/mcelog facility in the end.
This patch is just a plain dumb dump of mce_log() records to
the tracepoints / perf events framework - a first proof of
concept step.
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Cc: Huang Ying <ying.huang@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
LKML-Reference: <4AD42A0D.7050104@jp.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-10-13 15:19:41 +08:00
|
|
|
/* Emit the trace record: */
|
|
|
|
trace_mce_record(mce);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
mce->finished = 0;
|
2005-09-30 06:01:27 +08:00
|
|
|
wmb();
|
2005-04-17 06:20:36 +08:00
|
|
|
for (;;) {
|
|
|
|
entry = rcu_dereference(mcelog.next);
|
2005-09-13 00:49:24 +08:00
|
|
|
for (;;) {
|
2009-04-08 18:31:17 +08:00
|
|
|
/*
|
|
|
|
* When the buffer fills up discard new entries.
|
|
|
|
* Assume that the earlier errors are the more
|
|
|
|
* interesting ones:
|
|
|
|
*/
|
2005-09-13 00:49:24 +08:00
|
|
|
if (entry >= MCE_LOG_LEN) {
|
2009-04-30 15:04:51 +08:00
|
|
|
set_bit(MCE_OVERFLOW,
|
|
|
|
(unsigned long *)&mcelog.flags);
|
2005-09-13 00:49:24 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-04-08 18:31:17 +08:00
|
|
|
/* Old left over entry. Skip: */
|
2005-09-13 00:49:24 +08:00
|
|
|
if (mcelog.entry[entry].finished) {
|
|
|
|
entry++;
|
|
|
|
continue;
|
|
|
|
}
|
2005-09-30 06:01:27 +08:00
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
smp_rmb();
|
|
|
|
next = entry + 1;
|
|
|
|
if (cmpxchg(&mcelog.next, entry, next) == entry)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
memcpy(mcelog.entry + entry, mce, sizeof(struct mce));
|
2005-09-30 06:01:27 +08:00
|
|
|
wmb();
|
2005-04-17 06:20:36 +08:00
|
|
|
mcelog.entry[entry].finished = 1;
|
2005-09-30 06:01:27 +08:00
|
|
|
wmb();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-05-28 03:56:54 +08:00
|
|
|
mce->finished = 1;
|
2009-06-15 16:20:57 +08:00
|
|
|
set_bit(0, &mce_need_notify);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-06-11 15:04:35 +08:00
|
|
|
static void print_mce(struct mce *m)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-10-01 22:14:32 +08:00
|
|
|
pr_emerg("CPU %d: Machine Check Exception: %16Lx Bank %d: %016Lx\n",
|
2009-05-28 03:56:56 +08:00
|
|
|
m->extcpu, m->mcgstatus, m->bank, m->status);
|
2009-10-01 22:14:32 +08:00
|
|
|
|
2008-01-30 20:30:56 +08:00
|
|
|
if (m->ip) {
|
2009-10-01 22:14:32 +08:00
|
|
|
pr_emerg("RIP%s %02x:<%016Lx> ",
|
|
|
|
!(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
|
|
|
|
m->cs, m->ip);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (m->cs == __KERNEL_CS)
|
2008-01-30 20:30:56 +08:00
|
|
|
print_symbol("{%s}", m->ip);
|
2009-10-01 22:14:32 +08:00
|
|
|
pr_cont("\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-10-01 22:14:32 +08:00
|
|
|
|
|
|
|
pr_emerg("TSC %llx ", m->tsc);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (m->addr)
|
2009-10-01 22:14:32 +08:00
|
|
|
pr_cont("ADDR %llx ", m->addr);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (m->misc)
|
2009-10-01 22:14:32 +08:00
|
|
|
pr_cont("MISC %llx ", m->misc);
|
2009-07-24 19:51:42 +08:00
|
|
|
|
2009-10-01 22:14:32 +08:00
|
|
|
pr_cont("\n");
|
|
|
|
pr_emerg("PROCESSOR %u:%x TIME %llu SOCKET %u APIC %x\n",
|
|
|
|
m->cpuvendor, m->cpuid, m->time, m->socketid, m->apicid);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print out human-readable details about the MCE error,
|
2009-10-07 19:20:38 +08:00
|
|
|
* (if the CPU has an implementation for that)
|
2009-10-01 22:14:32 +08:00
|
|
|
*/
|
2009-10-07 19:20:38 +08:00
|
|
|
atomic_notifier_call_chain(&x86_mce_decoder_chain, 0, m);
|
2009-05-28 03:56:58 +08:00
|
|
|
}
|
|
|
|
|
2009-06-11 15:04:35 +08:00
|
|
|
static void print_mce_head(void)
|
|
|
|
{
|
2009-10-01 22:14:32 +08:00
|
|
|
pr_emerg("\nHARDWARE ERROR\n");
|
2009-06-11 15:04:35 +08:00
|
|
|
}
|
|
|
|
|
2009-05-28 03:56:58 +08:00
|
|
|
static void print_mce_tail(void)
|
|
|
|
{
|
2009-10-01 22:14:32 +08:00
|
|
|
pr_emerg("This is not a software problem!\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-05-28 03:56:55 +08:00
|
|
|
#define PANIC_TIMEOUT 5 /* 5 seconds */
|
|
|
|
|
|
|
|
static atomic_t mce_paniced;
|
|
|
|
|
2009-07-31 09:41:43 +08:00
|
|
|
static int fake_panic;
|
|
|
|
static atomic_t mce_fake_paniced;
|
|
|
|
|
2009-05-28 03:56:55 +08:00
|
|
|
/* Panic in progress. Enable interrupts and wait for final IPI */
|
|
|
|
static void wait_for_panic(void)
|
|
|
|
{
|
|
|
|
long timeout = PANIC_TIMEOUT*USEC_PER_SEC;
|
2009-10-01 22:14:32 +08:00
|
|
|
|
2009-05-28 03:56:55 +08:00
|
|
|
preempt_disable();
|
|
|
|
local_irq_enable();
|
|
|
|
while (timeout-- > 0)
|
|
|
|
udelay(1);
|
2009-05-28 03:56:56 +08:00
|
|
|
if (panic_timeout == 0)
|
|
|
|
panic_timeout = mce_panic_timeout;
|
2009-05-28 03:56:55 +08:00
|
|
|
panic("Panicing machine check CPU died");
|
|
|
|
}
|
|
|
|
|
2009-05-28 03:56:55 +08:00
|
|
|
static void mce_panic(char *msg, struct mce *final, char *exp)
|
2007-10-24 04:37:23 +08:00
|
|
|
{
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
|
2009-07-31 09:41:43 +08:00
|
|
|
if (!fake_panic) {
|
|
|
|
/*
|
|
|
|
* Make sure only one CPU runs in machine check panic
|
|
|
|
*/
|
|
|
|
if (atomic_inc_return(&mce_paniced) > 1)
|
|
|
|
wait_for_panic();
|
|
|
|
barrier();
|
2009-05-28 03:56:55 +08:00
|
|
|
|
2009-07-31 09:41:43 +08:00
|
|
|
bust_spinlocks(1);
|
|
|
|
console_verbose();
|
|
|
|
} else {
|
|
|
|
/* Don't log too much for fake panic */
|
|
|
|
if (atomic_inc_return(&mce_fake_paniced) > 1)
|
|
|
|
return;
|
|
|
|
}
|
2009-06-11 15:04:35 +08:00
|
|
|
print_mce_head();
|
2009-05-28 03:56:54 +08:00
|
|
|
/* First print corrected ones that are still unlogged */
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < MCE_LOG_LEN; i++) {
|
2009-05-28 03:56:54 +08:00
|
|
|
struct mce *m = &mcelog.entry[i];
|
2009-06-11 15:04:35 +08:00
|
|
|
if (!(m->status & MCI_STATUS_VAL))
|
|
|
|
continue;
|
|
|
|
if (!(m->status & MCI_STATUS_UC))
|
|
|
|
print_mce(m);
|
2009-05-28 03:56:54 +08:00
|
|
|
}
|
|
|
|
/* Now print uncorrected but with the final one last */
|
|
|
|
for (i = 0; i < MCE_LOG_LEN; i++) {
|
|
|
|
struct mce *m = &mcelog.entry[i];
|
|
|
|
if (!(m->status & MCI_STATUS_VAL))
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
2009-06-11 15:04:35 +08:00
|
|
|
if (!(m->status & MCI_STATUS_UC))
|
|
|
|
continue;
|
2009-05-28 03:56:54 +08:00
|
|
|
if (!final || memcmp(m, final, sizeof(struct mce)))
|
2009-06-11 15:04:35 +08:00
|
|
|
print_mce(m);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-05-28 03:56:54 +08:00
|
|
|
if (final)
|
2009-06-11 15:04:35 +08:00
|
|
|
print_mce(final);
|
2009-05-28 03:56:55 +08:00
|
|
|
if (cpu_missing)
|
|
|
|
printk(KERN_EMERG "Some CPUs didn't answer in synchronization\n");
|
2009-05-28 03:56:58 +08:00
|
|
|
print_mce_tail();
|
2009-05-28 03:56:55 +08:00
|
|
|
if (exp)
|
|
|
|
printk(KERN_EMERG "Machine check: %s\n", exp);
|
2009-07-31 09:41:43 +08:00
|
|
|
if (!fake_panic) {
|
|
|
|
if (panic_timeout == 0)
|
|
|
|
panic_timeout = mce_panic_timeout;
|
|
|
|
panic(msg);
|
|
|
|
} else
|
|
|
|
printk(KERN_EMERG "Fake kernel panic: %s\n", msg);
|
2007-10-24 04:37:23 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-04-30 01:31:00 +08:00
|
|
|
/* Support code for software error injection */
|
|
|
|
|
|
|
|
static int msr_to_offset(u32 msr)
|
|
|
|
{
|
|
|
|
unsigned bank = __get_cpu_var(injectm.bank);
|
2009-10-01 22:14:32 +08:00
|
|
|
|
2009-04-30 01:31:00 +08:00
|
|
|
if (msr == rip_msr)
|
|
|
|
return offsetof(struct mce, ip);
|
2009-07-09 06:31:44 +08:00
|
|
|
if (msr == MSR_IA32_MCx_STATUS(bank))
|
2009-04-30 01:31:00 +08:00
|
|
|
return offsetof(struct mce, status);
|
2009-07-09 06:31:44 +08:00
|
|
|
if (msr == MSR_IA32_MCx_ADDR(bank))
|
2009-04-30 01:31:00 +08:00
|
|
|
return offsetof(struct mce, addr);
|
2009-07-09 06:31:44 +08:00
|
|
|
if (msr == MSR_IA32_MCx_MISC(bank))
|
2009-04-30 01:31:00 +08:00
|
|
|
return offsetof(struct mce, misc);
|
|
|
|
if (msr == MSR_IA32_MCG_STATUS)
|
|
|
|
return offsetof(struct mce, mcgstatus);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-04-30 01:29:12 +08:00
|
|
|
/* MSR access wrappers used for error injection */
|
|
|
|
static u64 mce_rdmsrl(u32 msr)
|
|
|
|
{
|
|
|
|
u64 v;
|
2009-09-23 23:49:55 +08:00
|
|
|
|
2009-04-30 01:31:00 +08:00
|
|
|
if (__get_cpu_var(injectm).finished) {
|
|
|
|
int offset = msr_to_offset(msr);
|
2009-09-23 23:49:55 +08:00
|
|
|
|
2009-04-30 01:31:00 +08:00
|
|
|
if (offset < 0)
|
|
|
|
return 0;
|
|
|
|
return *(u64 *)((char *)&__get_cpu_var(injectm) + offset);
|
|
|
|
}
|
2009-09-23 23:49:55 +08:00
|
|
|
|
|
|
|
if (rdmsrl_safe(msr, &v)) {
|
|
|
|
WARN_ONCE(1, "mce: Unable to read msr %d!\n", msr);
|
|
|
|
/*
|
|
|
|
* Return zero in case the access faulted. This should
|
|
|
|
* not happen normally but can happen if the CPU does
|
|
|
|
* something weird, or if the code is buggy.
|
|
|
|
*/
|
|
|
|
v = 0;
|
|
|
|
}
|
|
|
|
|
2009-04-30 01:29:12 +08:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mce_wrmsrl(u32 msr, u64 v)
|
|
|
|
{
|
2009-04-30 01:31:00 +08:00
|
|
|
if (__get_cpu_var(injectm).finished) {
|
|
|
|
int offset = msr_to_offset(msr);
|
2009-09-23 23:49:55 +08:00
|
|
|
|
2009-04-30 01:31:00 +08:00
|
|
|
if (offset >= 0)
|
|
|
|
*(u64 *)((char *)&__get_cpu_var(injectm) + offset) = v;
|
|
|
|
return;
|
|
|
|
}
|
2009-04-30 01:29:12 +08:00
|
|
|
wrmsrl(msr, v);
|
|
|
|
}
|
|
|
|
|
x86, mce: support action-optional machine checks
Newer Intel CPUs support a new class of machine checks called recoverable
action optional.
Action Optional means that the CPU detected some form of corruption in
the background and tells the OS about using a machine check
exception. The OS can then take appropiate action, like killing the
process with the corrupted data or logging the event properly to disk.
This is done by the new generic high level memory failure handler added
in a earlier patch. The high level handler takes the address with the
failed memory and does the appropiate action, like killing the process.
In this version of the patch the high level handler is stubbed out
with a weak function to not create a direct dependency on the hwpoison
branch.
The high level handler cannot be directly called from the machine check
exception though, because it has to run in a defined process context to
be able to sleep when taking VM locks (it is not expected to sleep for a
long time, just do so in some exceptional cases like lock contention)
Thus the MCE handler has to queue a work item for process context,
trigger process context and then call the high level handler from there.
This patch adds two path to process context: through a per thread kernel
exit notify_user() callback or through a high priority work item.
The first runs when the process exits back to user space, the other when
it goes to sleep and there is no higher priority process.
The machine check handler will schedule both, and whoever runs first
will grab the event. This is done because quick reaction to this
event is critical to avoid a potential more fatal machine check
when the corruption is consumed.
There is a simple lock less ring buffer to queue the corrupted
addresses between the exception handler and the process context handler.
Then in process context it just calls the high level VM code with
the corrupted PFNs.
The code adds the required code to extract the failed address from
the CPU's machine check registers. It doesn't try to handle all
possible cases -- the specification has 6 different ways to specify
memory address -- but only the linear address.
Most of the required checking has been already done earlier in the
mce_severity rule checking engine. Following the Intel
recommendations Action Optional errors are only enabled for known
situations (encoded in MCACODs). The errors are ignored otherwise,
because they are action optional.
v2: Improve comment, disable preemption while processing ring buffer
(reported by Ying Huang)
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-05-28 03:56:59 +08:00
|
|
|
/*
|
|
|
|
* Simple lockless ring to communicate PFNs from the exception handler with the
|
|
|
|
* process context work function. This is vastly simplified because there's
|
|
|
|
* only a single reader and a single writer.
|
|
|
|
*/
|
|
|
|
#define MCE_RING_SIZE 16 /* we use one entry less */
|
|
|
|
|
|
|
|
struct mce_ring {
|
|
|
|
unsigned short start;
|
|
|
|
unsigned short end;
|
|
|
|
unsigned long ring[MCE_RING_SIZE];
|
|
|
|
};
|
|
|
|
static DEFINE_PER_CPU(struct mce_ring, mce_ring);
|
|
|
|
|
|
|
|
/* Runs with CPU affinity in workqueue */
|
|
|
|
static int mce_ring_empty(void)
|
|
|
|
{
|
|
|
|
struct mce_ring *r = &__get_cpu_var(mce_ring);
|
|
|
|
|
|
|
|
return r->start == r->end;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mce_ring_get(unsigned long *pfn)
|
|
|
|
{
|
|
|
|
struct mce_ring *r;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
*pfn = 0;
|
|
|
|
get_cpu();
|
|
|
|
r = &__get_cpu_var(mce_ring);
|
|
|
|
if (r->start == r->end)
|
|
|
|
goto out;
|
|
|
|
*pfn = r->ring[r->start];
|
|
|
|
r->start = (r->start + 1) % MCE_RING_SIZE;
|
|
|
|
ret = 1;
|
|
|
|
out:
|
|
|
|
put_cpu();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Always runs in MCE context with preempt off */
|
|
|
|
static int mce_ring_add(unsigned long pfn)
|
|
|
|
{
|
|
|
|
struct mce_ring *r = &__get_cpu_var(mce_ring);
|
|
|
|
unsigned next;
|
|
|
|
|
|
|
|
next = (r->end + 1) % MCE_RING_SIZE;
|
|
|
|
if (next == r->start)
|
|
|
|
return -1;
|
|
|
|
r->ring[r->end] = pfn;
|
|
|
|
wmb();
|
|
|
|
r->end = next;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-12 20:49:36 +08:00
|
|
|
int mce_available(struct cpuinfo_x86 *c)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-04-29 04:50:19 +08:00
|
|
|
if (mce_disabled)
|
2009-02-12 20:39:30 +08:00
|
|
|
return 0;
|
2006-03-24 19:15:11 +08:00
|
|
|
return cpu_has(c, X86_FEATURE_MCE) && cpu_has(c, X86_FEATURE_MCA);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
x86, mce: support action-optional machine checks
Newer Intel CPUs support a new class of machine checks called recoverable
action optional.
Action Optional means that the CPU detected some form of corruption in
the background and tells the OS about using a machine check
exception. The OS can then take appropiate action, like killing the
process with the corrupted data or logging the event properly to disk.
This is done by the new generic high level memory failure handler added
in a earlier patch. The high level handler takes the address with the
failed memory and does the appropiate action, like killing the process.
In this version of the patch the high level handler is stubbed out
with a weak function to not create a direct dependency on the hwpoison
branch.
The high level handler cannot be directly called from the machine check
exception though, because it has to run in a defined process context to
be able to sleep when taking VM locks (it is not expected to sleep for a
long time, just do so in some exceptional cases like lock contention)
Thus the MCE handler has to queue a work item for process context,
trigger process context and then call the high level handler from there.
This patch adds two path to process context: through a per thread kernel
exit notify_user() callback or through a high priority work item.
The first runs when the process exits back to user space, the other when
it goes to sleep and there is no higher priority process.
The machine check handler will schedule both, and whoever runs first
will grab the event. This is done because quick reaction to this
event is critical to avoid a potential more fatal machine check
when the corruption is consumed.
There is a simple lock less ring buffer to queue the corrupted
addresses between the exception handler and the process context handler.
Then in process context it just calls the high level VM code with
the corrupted PFNs.
The code adds the required code to extract the failed address from
the CPU's machine check registers. It doesn't try to handle all
possible cases -- the specification has 6 different ways to specify
memory address -- but only the linear address.
Most of the required checking has been already done earlier in the
mce_severity rule checking engine. Following the Intel
recommendations Action Optional errors are only enabled for known
situations (encoded in MCACODs). The errors are ignored otherwise,
because they are action optional.
v2: Improve comment, disable preemption while processing ring buffer
(reported by Ying Huang)
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-05-28 03:56:59 +08:00
|
|
|
static void mce_schedule_work(void)
|
|
|
|
{
|
|
|
|
if (!mce_ring_empty()) {
|
|
|
|
struct work_struct *work = &__get_cpu_var(mce_work);
|
|
|
|
if (!work_pending(work))
|
|
|
|
schedule_work(work);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-28 03:56:51 +08:00
|
|
|
/*
|
|
|
|
* Get the address of the instruction at the time of the machine check
|
|
|
|
* error.
|
|
|
|
*/
|
2005-04-17 06:25:09 +08:00
|
|
|
static inline void mce_get_rip(struct mce *m, struct pt_regs *regs)
|
|
|
|
{
|
2009-05-28 03:56:51 +08:00
|
|
|
|
|
|
|
if (regs && (m->mcgstatus & (MCG_STATUS_RIPV|MCG_STATUS_EIPV))) {
|
2008-01-30 20:30:56 +08:00
|
|
|
m->ip = regs->ip;
|
2005-04-17 06:25:09 +08:00
|
|
|
m->cs = regs->cs;
|
|
|
|
} else {
|
2008-01-30 20:30:56 +08:00
|
|
|
m->ip = 0;
|
2005-04-17 06:25:09 +08:00
|
|
|
m->cs = 0;
|
|
|
|
}
|
2009-05-28 03:56:51 +08:00
|
|
|
if (rip_msr)
|
2009-04-30 01:29:12 +08:00
|
|
|
m->ip = mce_rdmsrl(rip_msr);
|
2005-04-17 06:25:09 +08:00
|
|
|
}
|
|
|
|
|
2009-09-23 23:49:55 +08:00
|
|
|
#ifdef CONFIG_X86_LOCAL_APIC
|
2009-05-28 03:56:54 +08:00
|
|
|
/*
|
|
|
|
* Called after interrupts have been reenabled again
|
|
|
|
* when a MCE happened during an interrupts off region
|
|
|
|
* in the kernel.
|
|
|
|
*/
|
|
|
|
asmlinkage void smp_mce_self_interrupt(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
ack_APIC_irq();
|
|
|
|
exit_idle();
|
|
|
|
irq_enter();
|
2009-05-28 03:56:58 +08:00
|
|
|
mce_notify_irq();
|
x86, mce: support action-optional machine checks
Newer Intel CPUs support a new class of machine checks called recoverable
action optional.
Action Optional means that the CPU detected some form of corruption in
the background and tells the OS about using a machine check
exception. The OS can then take appropiate action, like killing the
process with the corrupted data or logging the event properly to disk.
This is done by the new generic high level memory failure handler added
in a earlier patch. The high level handler takes the address with the
failed memory and does the appropiate action, like killing the process.
In this version of the patch the high level handler is stubbed out
with a weak function to not create a direct dependency on the hwpoison
branch.
The high level handler cannot be directly called from the machine check
exception though, because it has to run in a defined process context to
be able to sleep when taking VM locks (it is not expected to sleep for a
long time, just do so in some exceptional cases like lock contention)
Thus the MCE handler has to queue a work item for process context,
trigger process context and then call the high level handler from there.
This patch adds two path to process context: through a per thread kernel
exit notify_user() callback or through a high priority work item.
The first runs when the process exits back to user space, the other when
it goes to sleep and there is no higher priority process.
The machine check handler will schedule both, and whoever runs first
will grab the event. This is done because quick reaction to this
event is critical to avoid a potential more fatal machine check
when the corruption is consumed.
There is a simple lock less ring buffer to queue the corrupted
addresses between the exception handler and the process context handler.
Then in process context it just calls the high level VM code with
the corrupted PFNs.
The code adds the required code to extract the failed address from
the CPU's machine check registers. It doesn't try to handle all
possible cases -- the specification has 6 different ways to specify
memory address -- but only the linear address.
Most of the required checking has been already done earlier in the
mce_severity rule checking engine. Following the Intel
recommendations Action Optional errors are only enabled for known
situations (encoded in MCACODs). The errors are ignored otherwise,
because they are action optional.
v2: Improve comment, disable preemption while processing ring buffer
(reported by Ying Huang)
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-05-28 03:56:59 +08:00
|
|
|
mce_schedule_work();
|
2009-05-28 03:56:54 +08:00
|
|
|
irq_exit();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void mce_report_event(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
if (regs->flags & (X86_VM_MASK|X86_EFLAGS_IF)) {
|
2009-05-28 03:56:58 +08:00
|
|
|
mce_notify_irq();
|
x86, mce: support action-optional machine checks
Newer Intel CPUs support a new class of machine checks called recoverable
action optional.
Action Optional means that the CPU detected some form of corruption in
the background and tells the OS about using a machine check
exception. The OS can then take appropiate action, like killing the
process with the corrupted data or logging the event properly to disk.
This is done by the new generic high level memory failure handler added
in a earlier patch. The high level handler takes the address with the
failed memory and does the appropiate action, like killing the process.
In this version of the patch the high level handler is stubbed out
with a weak function to not create a direct dependency on the hwpoison
branch.
The high level handler cannot be directly called from the machine check
exception though, because it has to run in a defined process context to
be able to sleep when taking VM locks (it is not expected to sleep for a
long time, just do so in some exceptional cases like lock contention)
Thus the MCE handler has to queue a work item for process context,
trigger process context and then call the high level handler from there.
This patch adds two path to process context: through a per thread kernel
exit notify_user() callback or through a high priority work item.
The first runs when the process exits back to user space, the other when
it goes to sleep and there is no higher priority process.
The machine check handler will schedule both, and whoever runs first
will grab the event. This is done because quick reaction to this
event is critical to avoid a potential more fatal machine check
when the corruption is consumed.
There is a simple lock less ring buffer to queue the corrupted
addresses between the exception handler and the process context handler.
Then in process context it just calls the high level VM code with
the corrupted PFNs.
The code adds the required code to extract the failed address from
the CPU's machine check registers. It doesn't try to handle all
possible cases -- the specification has 6 different ways to specify
memory address -- but only the linear address.
Most of the required checking has been already done earlier in the
mce_severity rule checking engine. Following the Intel
recommendations Action Optional errors are only enabled for known
situations (encoded in MCACODs). The errors are ignored otherwise,
because they are action optional.
v2: Improve comment, disable preemption while processing ring buffer
(reported by Ying Huang)
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-05-28 03:56:59 +08:00
|
|
|
/*
|
|
|
|
* Triggering the work queue here is just an insurance
|
|
|
|
* policy in case the syscall exit notify handler
|
|
|
|
* doesn't run soon enough or ends up running on the
|
|
|
|
* wrong CPU (can happen when audit sleeps)
|
|
|
|
*/
|
|
|
|
mce_schedule_work();
|
2009-05-28 03:56:54 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_X86_LOCAL_APIC
|
|
|
|
/*
|
|
|
|
* Without APIC do not notify. The event will be picked
|
|
|
|
* up eventually.
|
|
|
|
*/
|
|
|
|
if (!cpu_has_apic)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When interrupts are disabled we cannot use
|
|
|
|
* kernel services safely. Trigger an self interrupt
|
|
|
|
* through the APIC to instead do the notification
|
|
|
|
* after interrupts are reenabled again.
|
|
|
|
*/
|
|
|
|
apic->send_IPI_self(MCE_SELF_VECTOR);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for idle afterwards again so that we don't leave the
|
|
|
|
* APIC in a non idle state because the normal APIC writes
|
|
|
|
* cannot exclude us.
|
|
|
|
*/
|
|
|
|
apic_wait_icr_idle();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-05-28 03:56:57 +08:00
|
|
|
DEFINE_PER_CPU(unsigned, mce_poll_count);
|
|
|
|
|
2007-10-24 04:37:23 +08:00
|
|
|
/*
|
2009-02-12 20:43:23 +08:00
|
|
|
* Poll for corrected events or events that happened before reset.
|
|
|
|
* Those are just logged through /dev/mcelog.
|
|
|
|
*
|
|
|
|
* This is executed in standard interrupt context.
|
2009-05-28 03:56:57 +08:00
|
|
|
*
|
|
|
|
* Note: spec recommends to panic for fatal unsignalled
|
|
|
|
* errors here. However this would be quite problematic --
|
|
|
|
* we would need to reimplement the Monarch handling and
|
|
|
|
* it would mess up the exclusion between exception handler
|
|
|
|
* and poll hander -- * so we skip this for now.
|
|
|
|
* These cases should not happen anyways, or only when the CPU
|
|
|
|
* is already totally * confused. In this case it's likely it will
|
|
|
|
* not fully execute the machine check handler either.
|
2009-02-12 20:43:23 +08:00
|
|
|
*/
|
2009-02-12 20:49:34 +08:00
|
|
|
void machine_check_poll(enum mcp_flags flags, mce_banks_t *b)
|
2009-02-12 20:43:23 +08:00
|
|
|
{
|
|
|
|
struct mce m;
|
|
|
|
int i;
|
|
|
|
|
2009-05-28 03:56:57 +08:00
|
|
|
__get_cpu_var(mce_poll_count)++;
|
|
|
|
|
2009-02-12 20:43:23 +08:00
|
|
|
mce_setup(&m);
|
|
|
|
|
2009-04-30 01:29:12 +08:00
|
|
|
m.mcgstatus = mce_rdmsrl(MSR_IA32_MCG_STATUS);
|
2009-02-12 20:43:23 +08:00
|
|
|
for (i = 0; i < banks; i++) {
|
2009-07-09 06:31:43 +08:00
|
|
|
if (!mce_banks[i].ctl || !test_bit(i, *b))
|
2009-02-12 20:43:23 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
m.misc = 0;
|
|
|
|
m.addr = 0;
|
|
|
|
m.bank = i;
|
|
|
|
m.tsc = 0;
|
|
|
|
|
|
|
|
barrier();
|
2009-07-09 06:31:44 +08:00
|
|
|
m.status = mce_rdmsrl(MSR_IA32_MCx_STATUS(i));
|
2009-02-12 20:43:23 +08:00
|
|
|
if (!(m.status & MCI_STATUS_VAL))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
2009-05-28 03:56:57 +08:00
|
|
|
* Uncorrected or signalled events are handled by the exception
|
|
|
|
* handler when it is enabled, so don't process those here.
|
2009-02-12 20:43:23 +08:00
|
|
|
*
|
|
|
|
* TBD do the same check for MCI_STATUS_EN here?
|
|
|
|
*/
|
2009-05-28 03:56:57 +08:00
|
|
|
if (!(flags & MCP_UC) &&
|
|
|
|
(m.status & (mce_ser ? MCI_STATUS_S : MCI_STATUS_UC)))
|
2009-02-12 20:43:23 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (m.status & MCI_STATUS_MISCV)
|
2009-07-09 06:31:44 +08:00
|
|
|
m.misc = mce_rdmsrl(MSR_IA32_MCx_MISC(i));
|
2009-02-12 20:43:23 +08:00
|
|
|
if (m.status & MCI_STATUS_ADDRV)
|
2009-07-09 06:31:44 +08:00
|
|
|
m.addr = mce_rdmsrl(MSR_IA32_MCx_ADDR(i));
|
2009-02-12 20:43:23 +08:00
|
|
|
|
|
|
|
if (!(flags & MCP_TIMESTAMP))
|
|
|
|
m.tsc = 0;
|
|
|
|
/*
|
|
|
|
* Don't get the IP here because it's unlikely to
|
|
|
|
* have anything to do with the actual error location.
|
|
|
|
*/
|
2009-06-11 15:06:07 +08:00
|
|
|
if (!(flags & MCP_DONTLOG) && !mce_dont_log_ce) {
|
2009-04-07 23:06:55 +08:00
|
|
|
mce_log(&m);
|
|
|
|
add_taint(TAINT_MACHINE_CHECK);
|
|
|
|
}
|
2009-02-12 20:43:23 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear state for this bank.
|
|
|
|
*/
|
2009-07-09 06:31:44 +08:00
|
|
|
mce_wrmsrl(MSR_IA32_MCx_STATUS(i), 0);
|
2009-02-12 20:43:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't clear MCG_STATUS here because it's only defined for
|
|
|
|
* exceptions.
|
|
|
|
*/
|
2009-05-28 03:56:51 +08:00
|
|
|
|
|
|
|
sync_core();
|
2009-02-12 20:43:23 +08:00
|
|
|
}
|
2009-04-30 01:31:00 +08:00
|
|
|
EXPORT_SYMBOL_GPL(machine_check_poll);
|
2009-02-12 20:43:23 +08:00
|
|
|
|
2009-05-28 03:56:55 +08:00
|
|
|
/*
|
|
|
|
* Do a quick check if any of the events requires a panic.
|
|
|
|
* This decides if we keep the events around or clear them.
|
|
|
|
*/
|
|
|
|
static int mce_no_way_out(struct mce *m, char **msg)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < banks; i++) {
|
2009-07-09 06:31:44 +08:00
|
|
|
m->status = mce_rdmsrl(MSR_IA32_MCx_STATUS(i));
|
2009-05-28 03:56:55 +08:00
|
|
|
if (mce_severity(m, tolerant, msg) >= MCE_PANIC_SEVERITY)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-28 03:56:55 +08:00
|
|
|
/*
|
|
|
|
* Variable to establish order between CPUs while scanning.
|
|
|
|
* Each CPU spins initially until executing is equal its number.
|
|
|
|
*/
|
|
|
|
static atomic_t mce_executing;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Defines order of CPUs on entry. First CPU becomes Monarch.
|
|
|
|
*/
|
|
|
|
static atomic_t mce_callin;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if a timeout waiting for other CPUs happened.
|
|
|
|
*/
|
|
|
|
static int mce_timed_out(u64 *t)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The others already did panic for some reason.
|
|
|
|
* Bail out like in a timeout.
|
|
|
|
* rmb() to tell the compiler that system_state
|
|
|
|
* might have been modified by someone else.
|
|
|
|
*/
|
|
|
|
rmb();
|
|
|
|
if (atomic_read(&mce_paniced))
|
|
|
|
wait_for_panic();
|
|
|
|
if (!monarch_timeout)
|
|
|
|
goto out;
|
|
|
|
if ((s64)*t < SPINUNIT) {
|
|
|
|
/* CHECKME: Make panic default for 1 too? */
|
|
|
|
if (tolerant < 1)
|
|
|
|
mce_panic("Timeout synchronizing machine check over CPUs",
|
|
|
|
NULL, NULL);
|
|
|
|
cpu_missing = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
*t -= SPINUNIT;
|
|
|
|
out:
|
|
|
|
touch_nmi_watchdog();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The Monarch's reign. The Monarch is the CPU who entered
|
|
|
|
* the machine check handler first. It waits for the others to
|
|
|
|
* raise the exception too and then grades them. When any
|
|
|
|
* error is fatal panic. Only then let the others continue.
|
|
|
|
*
|
|
|
|
* The other CPUs entering the MCE handler will be controlled by the
|
|
|
|
* Monarch. They are called Subjects.
|
|
|
|
*
|
|
|
|
* This way we prevent any potential data corruption in a unrecoverable case
|
|
|
|
* and also makes sure always all CPU's errors are examined.
|
|
|
|
*
|
2009-08-26 15:20:36 +08:00
|
|
|
* Also this detects the case of a machine check event coming from outer
|
2009-05-28 03:56:55 +08:00
|
|
|
* space (not detected by any CPUs) In this case some external agent wants
|
|
|
|
* us to shut down, so panic too.
|
|
|
|
*
|
|
|
|
* The other CPUs might still decide to panic if the handler happens
|
|
|
|
* in a unrecoverable place, but in this case the system is in a semi-stable
|
|
|
|
* state and won't corrupt anything by itself. It's ok to let the others
|
|
|
|
* continue for a bit first.
|
|
|
|
*
|
|
|
|
* All the spin loops have timeouts; when a timeout happens a CPU
|
|
|
|
* typically elects itself to be Monarch.
|
|
|
|
*/
|
|
|
|
static void mce_reign(void)
|
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
struct mce *m = NULL;
|
|
|
|
int global_worst = 0;
|
|
|
|
char *msg = NULL;
|
|
|
|
char *nmsg = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This CPU is the Monarch and the other CPUs have run
|
|
|
|
* through their handlers.
|
|
|
|
* Grade the severity of the errors of all the CPUs.
|
|
|
|
*/
|
|
|
|
for_each_possible_cpu(cpu) {
|
|
|
|
int severity = mce_severity(&per_cpu(mces_seen, cpu), tolerant,
|
|
|
|
&nmsg);
|
|
|
|
if (severity > global_worst) {
|
|
|
|
msg = nmsg;
|
|
|
|
global_worst = severity;
|
|
|
|
m = &per_cpu(mces_seen, cpu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cannot recover? Panic here then.
|
|
|
|
* This dumps all the mces in the log buffer and stops the
|
|
|
|
* other CPUs.
|
|
|
|
*/
|
|
|
|
if (m && global_worst >= MCE_PANIC_SEVERITY && tolerant < 3)
|
2009-05-28 03:56:58 +08:00
|
|
|
mce_panic("Fatal Machine check", m, msg);
|
2009-05-28 03:56:55 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For UC somewhere we let the CPU who detects it handle it.
|
|
|
|
* Also must let continue the others, otherwise the handling
|
|
|
|
* CPU could deadlock on a lock.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* No machine check event found. Must be some external
|
|
|
|
* source or one CPU is hung. Panic.
|
|
|
|
*/
|
2009-08-26 15:20:36 +08:00
|
|
|
if (global_worst <= MCE_KEEP_SEVERITY && tolerant < 3)
|
2009-05-28 03:56:55 +08:00
|
|
|
mce_panic("Machine check from unknown source", NULL, NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now clear all the mces_seen so that they don't reappear on
|
|
|
|
* the next mce.
|
|
|
|
*/
|
|
|
|
for_each_possible_cpu(cpu)
|
|
|
|
memset(&per_cpu(mces_seen, cpu), 0, sizeof(struct mce));
|
|
|
|
}
|
|
|
|
|
|
|
|
static atomic_t global_nwo;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start of Monarch synchronization. This waits until all CPUs have
|
|
|
|
* entered the exception handler and then determines if any of them
|
|
|
|
* saw a fatal event that requires panic. Then it executes them
|
|
|
|
* in the entry order.
|
|
|
|
* TBD double check parallel CPU hotunplug
|
|
|
|
*/
|
2009-06-15 17:18:43 +08:00
|
|
|
static int mce_start(int *no_way_out)
|
2009-05-28 03:56:55 +08:00
|
|
|
{
|
2009-06-15 17:18:43 +08:00
|
|
|
int order;
|
2009-05-28 03:56:55 +08:00
|
|
|
int cpus = num_online_cpus();
|
|
|
|
u64 timeout = (u64)monarch_timeout * NSEC_PER_USEC;
|
|
|
|
|
2009-06-15 17:18:43 +08:00
|
|
|
if (!timeout)
|
|
|
|
return -1;
|
2009-05-28 03:56:55 +08:00
|
|
|
|
2009-06-15 17:18:43 +08:00
|
|
|
atomic_add(*no_way_out, &global_nwo);
|
2009-06-15 15:37:07 +08:00
|
|
|
/*
|
|
|
|
* global_nwo should be updated before mce_callin
|
|
|
|
*/
|
|
|
|
smp_wmb();
|
2009-06-21 14:28:22 +08:00
|
|
|
order = atomic_inc_return(&mce_callin);
|
2009-05-28 03:56:55 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for everyone.
|
|
|
|
*/
|
|
|
|
while (atomic_read(&mce_callin) != cpus) {
|
|
|
|
if (mce_timed_out(&timeout)) {
|
|
|
|
atomic_set(&global_nwo, 0);
|
2009-06-15 17:18:43 +08:00
|
|
|
return -1;
|
2009-05-28 03:56:55 +08:00
|
|
|
}
|
|
|
|
ndelay(SPINUNIT);
|
|
|
|
}
|
|
|
|
|
2009-06-15 15:37:07 +08:00
|
|
|
/*
|
|
|
|
* mce_callin should be read before global_nwo
|
|
|
|
*/
|
|
|
|
smp_rmb();
|
2009-05-28 03:56:55 +08:00
|
|
|
|
2009-06-15 17:18:43 +08:00
|
|
|
if (order == 1) {
|
|
|
|
/*
|
|
|
|
* Monarch: Starts executing now, the others wait.
|
|
|
|
*/
|
2009-05-28 03:56:55 +08:00
|
|
|
atomic_set(&mce_executing, 1);
|
2009-06-15 17:18:43 +08:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Subject: Now start the scanning loop one by one in
|
|
|
|
* the original callin order.
|
|
|
|
* This way when there are any shared banks it will be
|
|
|
|
* only seen by one CPU before cleared, avoiding duplicates.
|
|
|
|
*/
|
|
|
|
while (atomic_read(&mce_executing) < order) {
|
|
|
|
if (mce_timed_out(&timeout)) {
|
|
|
|
atomic_set(&global_nwo, 0);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ndelay(SPINUNIT);
|
|
|
|
}
|
2009-05-28 03:56:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-06-15 17:18:43 +08:00
|
|
|
* Cache the global no_way_out state.
|
2009-05-28 03:56:55 +08:00
|
|
|
*/
|
2009-06-15 17:18:43 +08:00
|
|
|
*no_way_out = atomic_read(&global_nwo);
|
|
|
|
|
|
|
|
return order;
|
2009-05-28 03:56:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Synchronize between CPUs after main scanning loop.
|
|
|
|
* This invokes the bulk of the Monarch processing.
|
|
|
|
*/
|
|
|
|
static int mce_end(int order)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
u64 timeout = (u64)monarch_timeout * NSEC_PER_USEC;
|
|
|
|
|
|
|
|
if (!timeout)
|
|
|
|
goto reset;
|
|
|
|
if (order < 0)
|
|
|
|
goto reset;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allow others to run.
|
|
|
|
*/
|
|
|
|
atomic_inc(&mce_executing);
|
|
|
|
|
|
|
|
if (order == 1) {
|
|
|
|
/* CHECKME: Can this race with a parallel hotplug? */
|
|
|
|
int cpus = num_online_cpus();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Monarch: Wait for everyone to go through their scanning
|
|
|
|
* loops.
|
|
|
|
*/
|
|
|
|
while (atomic_read(&mce_executing) <= cpus) {
|
|
|
|
if (mce_timed_out(&timeout))
|
|
|
|
goto reset;
|
|
|
|
ndelay(SPINUNIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
mce_reign();
|
|
|
|
barrier();
|
|
|
|
ret = 0;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Subject: Wait for Monarch to finish.
|
|
|
|
*/
|
|
|
|
while (atomic_read(&mce_executing) != 0) {
|
|
|
|
if (mce_timed_out(&timeout))
|
|
|
|
goto reset;
|
|
|
|
ndelay(SPINUNIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't reset anything. That's done by the Monarch.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset all global state.
|
|
|
|
*/
|
|
|
|
reset:
|
|
|
|
atomic_set(&global_nwo, 0);
|
|
|
|
atomic_set(&mce_callin, 0);
|
|
|
|
barrier();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Let others run again.
|
|
|
|
*/
|
|
|
|
atomic_set(&mce_executing, 0);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
x86, mce: support action-optional machine checks
Newer Intel CPUs support a new class of machine checks called recoverable
action optional.
Action Optional means that the CPU detected some form of corruption in
the background and tells the OS about using a machine check
exception. The OS can then take appropiate action, like killing the
process with the corrupted data or logging the event properly to disk.
This is done by the new generic high level memory failure handler added
in a earlier patch. The high level handler takes the address with the
failed memory and does the appropiate action, like killing the process.
In this version of the patch the high level handler is stubbed out
with a weak function to not create a direct dependency on the hwpoison
branch.
The high level handler cannot be directly called from the machine check
exception though, because it has to run in a defined process context to
be able to sleep when taking VM locks (it is not expected to sleep for a
long time, just do so in some exceptional cases like lock contention)
Thus the MCE handler has to queue a work item for process context,
trigger process context and then call the high level handler from there.
This patch adds two path to process context: through a per thread kernel
exit notify_user() callback or through a high priority work item.
The first runs when the process exits back to user space, the other when
it goes to sleep and there is no higher priority process.
The machine check handler will schedule both, and whoever runs first
will grab the event. This is done because quick reaction to this
event is critical to avoid a potential more fatal machine check
when the corruption is consumed.
There is a simple lock less ring buffer to queue the corrupted
addresses between the exception handler and the process context handler.
Then in process context it just calls the high level VM code with
the corrupted PFNs.
The code adds the required code to extract the failed address from
the CPU's machine check registers. It doesn't try to handle all
possible cases -- the specification has 6 different ways to specify
memory address -- but only the linear address.
Most of the required checking has been already done earlier in the
mce_severity rule checking engine. Following the Intel
recommendations Action Optional errors are only enabled for known
situations (encoded in MCACODs). The errors are ignored otherwise,
because they are action optional.
v2: Improve comment, disable preemption while processing ring buffer
(reported by Ying Huang)
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-05-28 03:56:59 +08:00
|
|
|
/*
|
|
|
|
* Check if the address reported by the CPU is in a format we can parse.
|
|
|
|
* It would be possible to add code for most other cases, but all would
|
|
|
|
* be somewhat complicated (e.g. segment offset would require an instruction
|
|
|
|
* parser). So only support physical addresses upto page granuality for now.
|
|
|
|
*/
|
|
|
|
static int mce_usable_address(struct mce *m)
|
|
|
|
{
|
|
|
|
if (!(m->status & MCI_STATUS_MISCV) || !(m->status & MCI_STATUS_ADDRV))
|
|
|
|
return 0;
|
|
|
|
if ((m->misc & 0x3f) > PAGE_SHIFT)
|
|
|
|
return 0;
|
|
|
|
if (((m->misc >> 6) & 7) != MCM_ADDR_PHYS)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-05-28 03:56:55 +08:00
|
|
|
static void mce_clear_state(unsigned long *toclear)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < banks; i++) {
|
|
|
|
if (test_bit(i, toclear))
|
2009-07-09 06:31:44 +08:00
|
|
|
mce_wrmsrl(MSR_IA32_MCx_STATUS(i), 0);
|
2009-05-28 03:56:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-12 20:43:23 +08:00
|
|
|
/*
|
|
|
|
* The actual machine check handler. This only handles real
|
|
|
|
* exceptions when something got corrupted coming in through int 18.
|
|
|
|
*
|
|
|
|
* This is executed in NMI context not subject to normal locking rules. This
|
|
|
|
* implies that most kernel services cannot be safely used. Don't even
|
|
|
|
* think about putting a printk in there!
|
2009-05-28 03:56:55 +08:00
|
|
|
*
|
|
|
|
* On Intel systems this is entered on all CPUs in parallel through
|
|
|
|
* MCE broadcast. However some CPUs might be broken beyond repair,
|
|
|
|
* so be always careful when synchronizing with others.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2009-04-08 18:31:17 +08:00
|
|
|
void do_machine_check(struct pt_regs *regs, long error_code)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-05-28 03:56:55 +08:00
|
|
|
struct mce m, *final;
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
2009-05-28 03:56:55 +08:00
|
|
|
int worst = 0;
|
|
|
|
int severity;
|
|
|
|
/*
|
|
|
|
* Establish sequential order between the CPUs entering the machine
|
|
|
|
* check handler.
|
|
|
|
*/
|
2009-06-15 17:18:43 +08:00
|
|
|
int order;
|
x86_64: mcelog tolerant level cleanup
Background:
The MCE handler has several paths that it can take, depending on various
conditions of the MCE status and the value of the 'tolerant' knob. The
exact semantics are not well defined and the code is a bit twisty.
Description:
This patch makes the MCE handler's behavior more clear by documenting the
behavior for various 'tolerant' levels. It also fixes or enhances
several small things in the handler. Specifically:
* If RIPV is set it is not safe to restart, so set the 'no way out'
flag rather than the 'kill it' flag.
* Don't panic() on correctable MCEs.
* If the _OVER bit is set *and* the _UC bit is set (meaning possibly
dropped uncorrected errors), set the 'no way out' flag.
* Use EIPV for testing whether an app can be killed (SIGBUS) rather
than RIPV. According to docs, EIPV indicates that the error is
related to the IP, while RIPV simply means the IP is valid to
restart from.
* Don't clear the MCi_STATUS registers until after the panic() path.
This leaves the status bits set after the panic() so clever BIOSes
can find them (and dumb BIOSes can do nothing).
This patch also calls nonseekable_open() in mce_open (as suggested by akpm).
Result:
Tolerant levels behave almost identically to how they always have, but
not it's well defined. There's a slightly higher chance of panic()ing
when multiple errors happen (a good thing, IMHO). If you take an MBE and
panic(), the error status bits are not cleared.
Alternatives:
None.
Testing:
I used software to inject correctable and uncorrectable errors. With
tolerant = 3, the system usually survives. With tolerant = 2, the system
usually panic()s (PCC) but not always. With tolerant = 1, the system
always panic()s. When the system panic()s, the BIOS is able to detect
that the cause of death was an MC4. I was not able to reproduce the
case of a non-PCC error in userspace, with EIPV, with (tolerant < 3).
That will be rare at best.
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:37 +08:00
|
|
|
/*
|
|
|
|
* If no_way_out gets set, there is no safe way to recover from this
|
|
|
|
* MCE. If tolerant is cranked up, we'll try anyway.
|
|
|
|
*/
|
|
|
|
int no_way_out = 0;
|
|
|
|
/*
|
|
|
|
* If kill_it gets set, there might be a way to recover from this
|
|
|
|
* error.
|
|
|
|
*/
|
|
|
|
int kill_it = 0;
|
2009-02-12 20:43:23 +08:00
|
|
|
DECLARE_BITMAP(toclear, MAX_NR_BANKS);
|
2009-05-28 03:56:55 +08:00
|
|
|
char *msg = "Unknown";
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-04-08 01:49:57 +08:00
|
|
|
atomic_inc(&mce_entry);
|
|
|
|
|
2009-05-28 03:56:52 +08:00
|
|
|
__get_cpu_var(mce_exception_count)++;
|
|
|
|
|
2009-02-12 20:43:23 +08:00
|
|
|
if (notify_die(DIE_NMI, "machine check", regs, error_code,
|
2008-01-30 20:31:23 +08:00
|
|
|
18, SIGKILL) == NOTIFY_STOP)
|
2009-05-28 03:56:53 +08:00
|
|
|
goto out;
|
2009-02-12 20:43:23 +08:00
|
|
|
if (!banks)
|
2009-05-28 03:56:53 +08:00
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-02-12 20:43:22 +08:00
|
|
|
mce_setup(&m);
|
|
|
|
|
2009-04-30 01:29:12 +08:00
|
|
|
m.mcgstatus = mce_rdmsrl(MSR_IA32_MCG_STATUS);
|
2009-05-28 03:56:55 +08:00
|
|
|
final = &__get_cpu_var(mces_seen);
|
|
|
|
*final = m;
|
|
|
|
|
2009-08-26 15:20:36 +08:00
|
|
|
no_way_out = mce_no_way_out(&m, &msg);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
barrier();
|
|
|
|
|
2009-05-28 03:56:57 +08:00
|
|
|
/*
|
|
|
|
* When no restart IP must always kill or panic.
|
|
|
|
*/
|
|
|
|
if (!(m.mcgstatus & MCG_STATUS_RIPV))
|
|
|
|
kill_it = 1;
|
|
|
|
|
2009-05-28 03:56:55 +08:00
|
|
|
/*
|
|
|
|
* Go through all the banks in exclusion of the other CPUs.
|
|
|
|
* This way we don't report duplicated events on shared banks
|
|
|
|
* because the first one to see it will clear it.
|
|
|
|
*/
|
2009-06-15 17:18:43 +08:00
|
|
|
order = mce_start(&no_way_out);
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < banks; i++) {
|
2009-02-12 20:43:23 +08:00
|
|
|
__clear_bit(i, toclear);
|
2009-07-09 06:31:43 +08:00
|
|
|
if (!mce_banks[i].ctl)
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
2007-10-24 04:37:23 +08:00
|
|
|
|
|
|
|
m.misc = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
m.addr = 0;
|
|
|
|
m.bank = i;
|
|
|
|
|
2009-07-09 06:31:44 +08:00
|
|
|
m.status = mce_rdmsrl(MSR_IA32_MCx_STATUS(i));
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((m.status & MCI_STATUS_VAL) == 0)
|
|
|
|
continue;
|
|
|
|
|
2009-02-12 20:43:23 +08:00
|
|
|
/*
|
2009-05-28 03:56:57 +08:00
|
|
|
* Non uncorrected or non signaled errors are handled by
|
|
|
|
* machine_check_poll. Leave them alone, unless this panics.
|
2009-02-12 20:43:23 +08:00
|
|
|
*/
|
2009-05-28 03:56:57 +08:00
|
|
|
if (!(m.status & (mce_ser ? MCI_STATUS_S : MCI_STATUS_UC)) &&
|
|
|
|
!no_way_out)
|
2009-02-12 20:43:23 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set taint even when machine check was not enabled.
|
|
|
|
*/
|
|
|
|
add_taint(TAINT_MACHINE_CHECK);
|
|
|
|
|
2009-05-28 03:56:57 +08:00
|
|
|
severity = mce_severity(&m, tolerant, NULL);
|
2009-02-12 20:43:23 +08:00
|
|
|
|
2009-05-28 03:56:57 +08:00
|
|
|
/*
|
|
|
|
* When machine check was for corrected handler don't touch,
|
|
|
|
* unless we're panicing.
|
|
|
|
*/
|
|
|
|
if (severity == MCE_KEEP_SEVERITY && !no_way_out)
|
|
|
|
continue;
|
|
|
|
__set_bit(i, toclear);
|
|
|
|
if (severity == MCE_NO_SEVERITY) {
|
2009-02-12 20:43:23 +08:00
|
|
|
/*
|
|
|
|
* Machine check event was not enabled. Clear, but
|
|
|
|
* ignore.
|
|
|
|
*/
|
|
|
|
continue;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-05-28 03:56:57 +08:00
|
|
|
/*
|
|
|
|
* Kill on action required.
|
|
|
|
*/
|
|
|
|
if (severity == MCE_AR_SEVERITY)
|
|
|
|
kill_it = 1;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (m.status & MCI_STATUS_MISCV)
|
2009-07-09 06:31:44 +08:00
|
|
|
m.misc = mce_rdmsrl(MSR_IA32_MCx_MISC(i));
|
2005-04-17 06:20:36 +08:00
|
|
|
if (m.status & MCI_STATUS_ADDRV)
|
2009-07-09 06:31:44 +08:00
|
|
|
m.addr = mce_rdmsrl(MSR_IA32_MCx_ADDR(i));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
x86, mce: support action-optional machine checks
Newer Intel CPUs support a new class of machine checks called recoverable
action optional.
Action Optional means that the CPU detected some form of corruption in
the background and tells the OS about using a machine check
exception. The OS can then take appropiate action, like killing the
process with the corrupted data or logging the event properly to disk.
This is done by the new generic high level memory failure handler added
in a earlier patch. The high level handler takes the address with the
failed memory and does the appropiate action, like killing the process.
In this version of the patch the high level handler is stubbed out
with a weak function to not create a direct dependency on the hwpoison
branch.
The high level handler cannot be directly called from the machine check
exception though, because it has to run in a defined process context to
be able to sleep when taking VM locks (it is not expected to sleep for a
long time, just do so in some exceptional cases like lock contention)
Thus the MCE handler has to queue a work item for process context,
trigger process context and then call the high level handler from there.
This patch adds two path to process context: through a per thread kernel
exit notify_user() callback or through a high priority work item.
The first runs when the process exits back to user space, the other when
it goes to sleep and there is no higher priority process.
The machine check handler will schedule both, and whoever runs first
will grab the event. This is done because quick reaction to this
event is critical to avoid a potential more fatal machine check
when the corruption is consumed.
There is a simple lock less ring buffer to queue the corrupted
addresses between the exception handler and the process context handler.
Then in process context it just calls the high level VM code with
the corrupted PFNs.
The code adds the required code to extract the failed address from
the CPU's machine check registers. It doesn't try to handle all
possible cases -- the specification has 6 different ways to specify
memory address -- but only the linear address.
Most of the required checking has been already done earlier in the
mce_severity rule checking engine. Following the Intel
recommendations Action Optional errors are only enabled for known
situations (encoded in MCACODs). The errors are ignored otherwise,
because they are action optional.
v2: Improve comment, disable preemption while processing ring buffer
(reported by Ying Huang)
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-05-28 03:56:59 +08:00
|
|
|
/*
|
|
|
|
* Action optional error. Queue address for later processing.
|
|
|
|
* When the ring overflows we just ignore the AO error.
|
|
|
|
* RED-PEN add some logging mechanism when
|
|
|
|
* usable_address or mce_add_ring fails.
|
|
|
|
* RED-PEN don't ignore overflow for tolerant == 0
|
|
|
|
*/
|
|
|
|
if (severity == MCE_AO_SEVERITY && mce_usable_address(&m))
|
|
|
|
mce_ring_add(m.addr >> PAGE_SHIFT);
|
|
|
|
|
2005-04-17 06:25:09 +08:00
|
|
|
mce_get_rip(&m, regs);
|
2009-02-12 20:43:23 +08:00
|
|
|
mce_log(&m);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-05-28 03:56:55 +08:00
|
|
|
if (severity > worst) {
|
|
|
|
*final = m;
|
|
|
|
worst = severity;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-28 03:56:55 +08:00
|
|
|
if (!no_way_out)
|
|
|
|
mce_clear_state(toclear);
|
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
/*
|
2009-05-28 03:56:55 +08:00
|
|
|
* Do most of the synchronization with other CPUs.
|
|
|
|
* When there's any problem use only local no_way_out state.
|
2009-04-08 18:31:17 +08:00
|
|
|
*/
|
2009-05-28 03:56:55 +08:00
|
|
|
if (mce_end(order) < 0)
|
|
|
|
no_way_out = worst >= MCE_PANIC_SEVERITY;
|
x86_64: mcelog tolerant level cleanup
Background:
The MCE handler has several paths that it can take, depending on various
conditions of the MCE status and the value of the 'tolerant' knob. The
exact semantics are not well defined and the code is a bit twisty.
Description:
This patch makes the MCE handler's behavior more clear by documenting the
behavior for various 'tolerant' levels. It also fixes or enhances
several small things in the handler. Specifically:
* If RIPV is set it is not safe to restart, so set the 'no way out'
flag rather than the 'kill it' flag.
* Don't panic() on correctable MCEs.
* If the _OVER bit is set *and* the _UC bit is set (meaning possibly
dropped uncorrected errors), set the 'no way out' flag.
* Use EIPV for testing whether an app can be killed (SIGBUS) rather
than RIPV. According to docs, EIPV indicates that the error is
related to the IP, while RIPV simply means the IP is valid to
restart from.
* Don't clear the MCi_STATUS registers until after the panic() path.
This leaves the status bits set after the panic() so clever BIOSes
can find them (and dumb BIOSes can do nothing).
This patch also calls nonseekable_open() in mce_open (as suggested by akpm).
Result:
Tolerant levels behave almost identically to how they always have, but
not it's well defined. There's a slightly higher chance of panic()ing
when multiple errors happen (a good thing, IMHO). If you take an MBE and
panic(), the error status bits are not cleared.
Alternatives:
None.
Testing:
I used software to inject correctable and uncorrectable errors. With
tolerant = 3, the system usually survives. With tolerant = 2, the system
usually panic()s (PCC) but not always. With tolerant = 1, the system
always panic()s. When the system panic()s, the BIOS is able to detect
that the cause of death was an MC4. I was not able to reproduce the
case of a non-PCC error in userspace, with EIPV, with (tolerant < 3).
That will be rare at best.
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:37 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have decided that we just CAN'T continue, and the user
|
2009-04-08 18:31:17 +08:00
|
|
|
* has not set tolerant to an insane level, give up and die.
|
2009-05-28 03:56:55 +08:00
|
|
|
*
|
|
|
|
* This is mainly used in the case when the system doesn't
|
|
|
|
* support MCE broadcasting or it has been disabled.
|
x86_64: mcelog tolerant level cleanup
Background:
The MCE handler has several paths that it can take, depending on various
conditions of the MCE status and the value of the 'tolerant' knob. The
exact semantics are not well defined and the code is a bit twisty.
Description:
This patch makes the MCE handler's behavior more clear by documenting the
behavior for various 'tolerant' levels. It also fixes or enhances
several small things in the handler. Specifically:
* If RIPV is set it is not safe to restart, so set the 'no way out'
flag rather than the 'kill it' flag.
* Don't panic() on correctable MCEs.
* If the _OVER bit is set *and* the _UC bit is set (meaning possibly
dropped uncorrected errors), set the 'no way out' flag.
* Use EIPV for testing whether an app can be killed (SIGBUS) rather
than RIPV. According to docs, EIPV indicates that the error is
related to the IP, while RIPV simply means the IP is valid to
restart from.
* Don't clear the MCi_STATUS registers until after the panic() path.
This leaves the status bits set after the panic() so clever BIOSes
can find them (and dumb BIOSes can do nothing).
This patch also calls nonseekable_open() in mce_open (as suggested by akpm).
Result:
Tolerant levels behave almost identically to how they always have, but
not it's well defined. There's a slightly higher chance of panic()ing
when multiple errors happen (a good thing, IMHO). If you take an MBE and
panic(), the error status bits are not cleared.
Alternatives:
None.
Testing:
I used software to inject correctable and uncorrectable errors. With
tolerant = 3, the system usually survives. With tolerant = 2, the system
usually panic()s (PCC) but not always. With tolerant = 1, the system
always panic()s. When the system panic()s, the BIOS is able to detect
that the cause of death was an MC4. I was not able to reproduce the
case of a non-PCC error in userspace, with EIPV, with (tolerant < 3).
That will be rare at best.
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:37 +08:00
|
|
|
*/
|
|
|
|
if (no_way_out && tolerant < 3)
|
2009-05-28 03:56:58 +08:00
|
|
|
mce_panic("Fatal machine check on current CPU", final, msg);
|
x86_64: mcelog tolerant level cleanup
Background:
The MCE handler has several paths that it can take, depending on various
conditions of the MCE status and the value of the 'tolerant' knob. The
exact semantics are not well defined and the code is a bit twisty.
Description:
This patch makes the MCE handler's behavior more clear by documenting the
behavior for various 'tolerant' levels. It also fixes or enhances
several small things in the handler. Specifically:
* If RIPV is set it is not safe to restart, so set the 'no way out'
flag rather than the 'kill it' flag.
* Don't panic() on correctable MCEs.
* If the _OVER bit is set *and* the _UC bit is set (meaning possibly
dropped uncorrected errors), set the 'no way out' flag.
* Use EIPV for testing whether an app can be killed (SIGBUS) rather
than RIPV. According to docs, EIPV indicates that the error is
related to the IP, while RIPV simply means the IP is valid to
restart from.
* Don't clear the MCi_STATUS registers until after the panic() path.
This leaves the status bits set after the panic() so clever BIOSes
can find them (and dumb BIOSes can do nothing).
This patch also calls nonseekable_open() in mce_open (as suggested by akpm).
Result:
Tolerant levels behave almost identically to how they always have, but
not it's well defined. There's a slightly higher chance of panic()ing
when multiple errors happen (a good thing, IMHO). If you take an MBE and
panic(), the error status bits are not cleared.
Alternatives:
None.
Testing:
I used software to inject correctable and uncorrectable errors. With
tolerant = 3, the system usually survives. With tolerant = 2, the system
usually panic()s (PCC) but not always. With tolerant = 1, the system
always panic()s. When the system panic()s, the BIOS is able to detect
that the cause of death was an MC4. I was not able to reproduce the
case of a non-PCC error in userspace, with EIPV, with (tolerant < 3).
That will be rare at best.
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:37 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the error seems to be unrecoverable, something should be
|
|
|
|
* done. Try to kill as little as possible. If we can kill just
|
|
|
|
* one task, do that. If the user has set the tolerance very
|
|
|
|
* high, don't try to do anything at all.
|
|
|
|
*/
|
|
|
|
|
2009-05-28 03:56:57 +08:00
|
|
|
if (kill_it && tolerant < 3)
|
|
|
|
force_sig(SIGBUS, current);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
/* notify userspace ASAP */
|
|
|
|
set_thread_flag(TIF_MCE_NOTIFY);
|
|
|
|
|
2009-05-28 03:56:55 +08:00
|
|
|
if (worst > 0)
|
|
|
|
mce_report_event(regs);
|
2009-04-30 01:29:12 +08:00
|
|
|
mce_wrmsrl(MSR_IA32_MCG_STATUS, 0);
|
2009-05-28 03:56:53 +08:00
|
|
|
out:
|
2006-04-08 01:49:57 +08:00
|
|
|
atomic_dec(&mce_entry);
|
2009-05-28 03:56:51 +08:00
|
|
|
sync_core();
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-04-30 01:31:00 +08:00
|
|
|
EXPORT_SYMBOL_GPL(do_machine_check);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
x86, mce: support action-optional machine checks
Newer Intel CPUs support a new class of machine checks called recoverable
action optional.
Action Optional means that the CPU detected some form of corruption in
the background and tells the OS about using a machine check
exception. The OS can then take appropiate action, like killing the
process with the corrupted data or logging the event properly to disk.
This is done by the new generic high level memory failure handler added
in a earlier patch. The high level handler takes the address with the
failed memory and does the appropiate action, like killing the process.
In this version of the patch the high level handler is stubbed out
with a weak function to not create a direct dependency on the hwpoison
branch.
The high level handler cannot be directly called from the machine check
exception though, because it has to run in a defined process context to
be able to sleep when taking VM locks (it is not expected to sleep for a
long time, just do so in some exceptional cases like lock contention)
Thus the MCE handler has to queue a work item for process context,
trigger process context and then call the high level handler from there.
This patch adds two path to process context: through a per thread kernel
exit notify_user() callback or through a high priority work item.
The first runs when the process exits back to user space, the other when
it goes to sleep and there is no higher priority process.
The machine check handler will schedule both, and whoever runs first
will grab the event. This is done because quick reaction to this
event is critical to avoid a potential more fatal machine check
when the corruption is consumed.
There is a simple lock less ring buffer to queue the corrupted
addresses between the exception handler and the process context handler.
Then in process context it just calls the high level VM code with
the corrupted PFNs.
The code adds the required code to extract the failed address from
the CPU's machine check registers. It doesn't try to handle all
possible cases -- the specification has 6 different ways to specify
memory address -- but only the linear address.
Most of the required checking has been already done earlier in the
mce_severity rule checking engine. Following the Intel
recommendations Action Optional errors are only enabled for known
situations (encoded in MCACODs). The errors are ignored otherwise,
because they are action optional.
v2: Improve comment, disable preemption while processing ring buffer
(reported by Ying Huang)
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-05-28 03:56:59 +08:00
|
|
|
/* dummy to break dependency. actual code is in mm/memory-failure.c */
|
|
|
|
void __attribute__((weak)) memory_failure(unsigned long pfn, int vector)
|
|
|
|
{
|
|
|
|
printk(KERN_ERR "Action optional memory failure at %lx ignored\n", pfn);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called after mce notification in process context. This code
|
|
|
|
* is allowed to sleep. Call the high level VM handler to process
|
|
|
|
* any corrupted pages.
|
|
|
|
* Assume that the work queue code only calls this one at a time
|
|
|
|
* per CPU.
|
|
|
|
* Note we don't disable preemption, so this code might run on the wrong
|
|
|
|
* CPU. In this case the event is picked up by the scheduled work queue.
|
|
|
|
* This is merely a fast path to expedite processing in some common
|
|
|
|
* cases.
|
|
|
|
*/
|
|
|
|
void mce_notify_process(void)
|
|
|
|
{
|
|
|
|
unsigned long pfn;
|
|
|
|
mce_notify_irq();
|
|
|
|
while (mce_ring_get(&pfn))
|
|
|
|
memory_failure(pfn, MCE_VECTOR);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mce_process_work(struct work_struct *dummy)
|
|
|
|
{
|
|
|
|
mce_notify_process();
|
|
|
|
}
|
|
|
|
|
2006-09-26 16:52:42 +08:00
|
|
|
#ifdef CONFIG_X86_MCE_INTEL
|
|
|
|
/***
|
|
|
|
* mce_log_therm_throt_event - Logs the thermal throttling event to mcelog
|
2007-10-20 07:25:36 +08:00
|
|
|
* @cpu: The CPU on which the event occurred.
|
2006-09-26 16:52:42 +08:00
|
|
|
* @status: Event status information
|
|
|
|
*
|
|
|
|
* This function should be called by the thermal interrupt after the
|
|
|
|
* event has been processed and the decision was made to log the event
|
|
|
|
* further.
|
|
|
|
*
|
|
|
|
* The status parameter will be saved to the 'status' field of 'struct mce'
|
|
|
|
* and historically has been the register value of the
|
|
|
|
* MSR_IA32_THERMAL_STATUS (Intel) msr.
|
|
|
|
*/
|
2009-02-12 20:43:22 +08:00
|
|
|
void mce_log_therm_throt_event(__u64 status)
|
2006-09-26 16:52:42 +08:00
|
|
|
{
|
|
|
|
struct mce m;
|
|
|
|
|
2009-02-12 20:43:22 +08:00
|
|
|
mce_setup(&m);
|
2006-09-26 16:52:42 +08:00
|
|
|
m.bank = MCE_THERMAL_BANK;
|
|
|
|
m.status = status;
|
|
|
|
mce_log(&m);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_X86_MCE_INTEL */
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2007-05-03 01:27:19 +08:00
|
|
|
* Periodic polling timer for "silent" machine check errors. If the
|
|
|
|
* poller finds an MCE, poll 2x faster. When the poller finds no more
|
|
|
|
* errors, poll 2x slower (up to check_interval seconds).
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
static int check_interval = 5 * 60; /* 5 minutes */
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2009-06-24 14:13:48 +08:00
|
|
|
static DEFINE_PER_CPU(int, mce_next_interval); /* in jiffies */
|
2009-02-12 20:39:29 +08:00
|
|
|
static DEFINE_PER_CPU(struct timer_list, mce_timer);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-10-16 18:31:32 +08:00
|
|
|
static void mce_start_timer(unsigned long data)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-02-12 20:39:29 +08:00
|
|
|
struct timer_list *t = &per_cpu(mce_timer, data);
|
2009-04-09 18:28:22 +08:00
|
|
|
int *n;
|
2009-02-12 20:39:29 +08:00
|
|
|
|
|
|
|
WARN_ON(smp_processor_id() != data);
|
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
if (mce_available(¤t_cpu_data)) {
|
2009-02-12 20:49:34 +08:00
|
|
|
machine_check_poll(MCP_TIMESTAMP,
|
|
|
|
&__get_cpu_var(mce_poll_banks));
|
2009-04-08 18:31:17 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
* Alert userspace if needed. If we logged an MCE, reduce the
|
|
|
|
* polling interval, otherwise increase the polling interval.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2009-06-24 14:13:48 +08:00
|
|
|
n = &__get_cpu_var(mce_next_interval);
|
2009-05-28 03:56:58 +08:00
|
|
|
if (mce_notify_irq())
|
2009-04-09 18:28:22 +08:00
|
|
|
*n = max(*n/2, HZ/100);
|
2009-04-30 15:04:51 +08:00
|
|
|
else
|
2009-04-09 18:28:22 +08:00
|
|
|
*n = min(*n*2, (int)round_jiffies_relative(check_interval*HZ));
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
|
2009-04-09 18:28:22 +08:00
|
|
|
t->expires = jiffies + *n;
|
2009-06-24 08:21:10 +08:00
|
|
|
add_timer_on(t, smp_processor_id());
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
}
|
|
|
|
|
2009-02-12 20:39:28 +08:00
|
|
|
static void mce_do_trigger(struct work_struct *work)
|
|
|
|
{
|
2009-06-15 16:20:57 +08:00
|
|
|
call_usermodehelper(mce_helper, mce_helper_argv, NULL, UMH_NO_WAIT);
|
2009-02-12 20:39:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static DECLARE_WORK(mce_trigger_work, mce_do_trigger);
|
|
|
|
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
/*
|
2009-02-12 20:39:28 +08:00
|
|
|
* Notify the user(s) about new machine check events.
|
|
|
|
* Can be called from interrupt context, but not from machine check/NMI
|
|
|
|
* context.
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
*/
|
2009-05-28 03:56:58 +08:00
|
|
|
int mce_notify_irq(void)
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
{
|
2009-02-12 20:49:33 +08:00
|
|
|
/* Not more than two messages every minute */
|
|
|
|
static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2);
|
|
|
|
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
clear_thread_flag(TIF_MCE_NOTIFY);
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2009-06-15 16:20:57 +08:00
|
|
|
if (test_and_clear_bit(0, &mce_need_notify)) {
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
wake_up_interruptible(&mce_wait);
|
2009-02-12 20:39:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* There is no risk of missing notifications because
|
|
|
|
* work_pending is always cleared before the function is
|
|
|
|
* executed.
|
|
|
|
*/
|
2009-06-15 16:20:57 +08:00
|
|
|
if (mce_helper[0] && !work_pending(&mce_trigger_work))
|
2009-02-12 20:39:28 +08:00
|
|
|
schedule_work(&mce_trigger_work);
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
|
2009-02-12 20:49:33 +08:00
|
|
|
if (__ratelimit(&ratelimit))
|
2007-05-03 01:27:19 +08:00
|
|
|
printk(KERN_INFO "Machine check events logged\n");
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
|
|
|
|
return 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2009-05-28 03:56:58 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mce_notify_irq);
|
2007-05-03 01:27:19 +08:00
|
|
|
|
2009-07-09 06:31:43 +08:00
|
|
|
static int mce_banks_init(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
mce_banks = kzalloc(banks * sizeof(struct mce_bank), GFP_KERNEL);
|
|
|
|
if (!mce_banks)
|
|
|
|
return -ENOMEM;
|
|
|
|
for (i = 0; i < banks; i++) {
|
|
|
|
struct mce_bank *b = &mce_banks[i];
|
2009-09-23 23:49:55 +08:00
|
|
|
|
2009-07-09 06:31:43 +08:00
|
|
|
b->ctl = -1ULL;
|
|
|
|
b->init = 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-10-24 04:37:23 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Initialize Machine Checks for a CPU.
|
|
|
|
*/
|
2009-10-16 18:31:32 +08:00
|
|
|
static int __cpuinit __mcheck_cpu_cap_init(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-02-18 06:07:13 +08:00
|
|
|
unsigned b;
|
2009-04-08 18:31:17 +08:00
|
|
|
u64 cap;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
rdmsrl(MSR_IA32_MCG_CAP, cap);
|
2009-04-08 18:31:24 +08:00
|
|
|
|
|
|
|
b = cap & MCG_BANKCNT_MASK;
|
2009-10-16 05:21:14 +08:00
|
|
|
if (!banks)
|
|
|
|
printk(KERN_INFO "mce: CPU supports %d MCE banks\n", b);
|
2009-04-08 18:31:27 +08:00
|
|
|
|
2009-02-18 06:07:13 +08:00
|
|
|
if (b > MAX_NR_BANKS) {
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"MCE: Using only %u machine check banks out of %u\n",
|
|
|
|
MAX_NR_BANKS, b);
|
|
|
|
b = MAX_NR_BANKS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't support asymmetric configurations today */
|
|
|
|
WARN_ON(banks != 0 && b != banks);
|
|
|
|
banks = b;
|
2009-07-09 06:31:43 +08:00
|
|
|
if (!mce_banks) {
|
|
|
|
int err = mce_banks_init();
|
2009-09-23 23:49:55 +08:00
|
|
|
|
2009-07-09 06:31:43 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-02-18 06:07:13 +08:00
|
|
|
|
2005-04-17 06:25:09 +08:00
|
|
|
/* Use accurate RIP reporting if available. */
|
2009-04-08 18:31:24 +08:00
|
|
|
if ((cap & MCG_EXT_P) && MCG_EXT_CNT(cap) >= 9)
|
2005-04-17 06:25:09 +08:00
|
|
|
rip_msr = MSR_IA32_MCG_EIP;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-05-28 03:56:57 +08:00
|
|
|
if (cap & MCG_SER_P)
|
|
|
|
mce_ser = 1;
|
|
|
|
|
2009-02-18 06:07:13 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-16 18:31:32 +08:00
|
|
|
static void __mcheck_cpu_init_generic(void)
|
2009-02-18 06:07:13 +08:00
|
|
|
{
|
2009-04-08 18:31:17 +08:00
|
|
|
mce_banks_t all_banks;
|
2009-02-18 06:07:13 +08:00
|
|
|
u64 cap;
|
|
|
|
int i;
|
|
|
|
|
2009-02-12 20:43:23 +08:00
|
|
|
/*
|
|
|
|
* Log the machine checks left over from the previous reset.
|
|
|
|
*/
|
2009-02-12 20:49:34 +08:00
|
|
|
bitmap_fill(all_banks, MAX_NR_BANKS);
|
2009-04-07 23:06:55 +08:00
|
|
|
machine_check_poll(MCP_UC|(!mce_bootlog ? MCP_DONTLOG : 0), &all_banks);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
set_in_cr4(X86_CR4_MCE);
|
|
|
|
|
2009-02-18 06:07:13 +08:00
|
|
|
rdmsrl(MSR_IA32_MCG_CAP, cap);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (cap & MCG_CTL_P)
|
|
|
|
wrmsr(MSR_IA32_MCG_CTL, 0xffffffff, 0xffffffff);
|
|
|
|
|
|
|
|
for (i = 0; i < banks; i++) {
|
2009-07-09 06:31:43 +08:00
|
|
|
struct mce_bank *b = &mce_banks[i];
|
2009-09-23 23:49:55 +08:00
|
|
|
|
2009-07-09 06:31:43 +08:00
|
|
|
if (!b->init)
|
2009-04-28 00:37:43 +08:00
|
|
|
continue;
|
2009-07-09 06:31:44 +08:00
|
|
|
wrmsrl(MSR_IA32_MCx_CTL(i), b->ctl);
|
|
|
|
wrmsrl(MSR_IA32_MCx_STATUS(i), 0);
|
2007-10-24 04:37:23 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add per CPU specific workarounds here */
|
2009-10-16 18:31:32 +08:00
|
|
|
static int __cpuinit __mcheck_cpu_apply_quirks(struct cpuinfo_x86 *c)
|
2007-10-24 04:37:23 +08:00
|
|
|
{
|
2009-08-17 16:19:00 +08:00
|
|
|
if (c->x86_vendor == X86_VENDOR_UNKNOWN) {
|
|
|
|
pr_info("MCE: unknown CPU type - not enabling MCE support.\n");
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* This should be disabled by the BIOS, but isn't always */
|
2008-04-22 23:22:21 +08:00
|
|
|
if (c->x86_vendor == X86_VENDOR_AMD) {
|
2009-04-08 18:31:17 +08:00
|
|
|
if (c->x86 == 15 && banks > 4) {
|
|
|
|
/*
|
|
|
|
* disable GART TBL walk error reporting, which
|
|
|
|
* trips off incorrectly with the IOMMU & 3ware
|
|
|
|
* & Cerberus:
|
|
|
|
*/
|
2009-07-09 06:31:43 +08:00
|
|
|
clear_bit(10, (unsigned long *)&mce_banks[4].ctl);
|
2009-04-08 18:31:17 +08:00
|
|
|
}
|
|
|
|
if (c->x86 <= 17 && mce_bootlog < 0) {
|
|
|
|
/*
|
|
|
|
* Lots of broken BIOS around that don't clear them
|
|
|
|
* by default and leave crap in there. Don't log:
|
|
|
|
*/
|
2008-04-22 23:22:21 +08:00
|
|
|
mce_bootlog = 0;
|
2009-04-08 18:31:17 +08:00
|
|
|
}
|
2009-04-28 00:42:48 +08:00
|
|
|
/*
|
|
|
|
* Various K7s with broken bank 0 around. Always disable
|
|
|
|
* by default.
|
|
|
|
*/
|
2009-06-15 20:52:01 +08:00
|
|
|
if (c->x86 == 6 && banks > 0)
|
2009-07-09 06:31:43 +08:00
|
|
|
mce_banks[0].ctl = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2005-11-06 00:25:54 +08:00
|
|
|
|
2009-04-28 00:37:43 +08:00
|
|
|
if (c->x86_vendor == X86_VENDOR_INTEL) {
|
|
|
|
/*
|
|
|
|
* SDM documents that on family 6 bank 0 should not be written
|
|
|
|
* because it aliases to another special BIOS controlled
|
|
|
|
* register.
|
|
|
|
* But it's not aliased anymore on model 0x1a+
|
|
|
|
* Don't ignore bank 0 completely because there could be a
|
|
|
|
* valid event later, merely don't write CTL0.
|
|
|
|
*/
|
|
|
|
|
2009-07-09 06:31:43 +08:00
|
|
|
if (c->x86 == 6 && c->x86_model < 0x1A && banks > 0)
|
|
|
|
mce_banks[0].init = 0;
|
2009-05-28 03:56:55 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* All newer Intel systems support MCE broadcasting. Enable
|
|
|
|
* synchronization with a one second timeout.
|
|
|
|
*/
|
|
|
|
if ((c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xe)) &&
|
|
|
|
monarch_timeout < 0)
|
|
|
|
monarch_timeout = USEC_PER_SEC;
|
2009-07-29 05:52:54 +08:00
|
|
|
|
2009-08-17 16:19:00 +08:00
|
|
|
/*
|
|
|
|
* There are also broken BIOSes on some Pentium M and
|
|
|
|
* earlier systems:
|
|
|
|
*/
|
|
|
|
if (c->x86 == 6 && c->x86_model <= 13 && mce_bootlog < 0)
|
2009-07-29 05:52:54 +08:00
|
|
|
mce_bootlog = 0;
|
2009-04-28 00:37:43 +08:00
|
|
|
}
|
2009-05-28 03:56:55 +08:00
|
|
|
if (monarch_timeout < 0)
|
|
|
|
monarch_timeout = 0;
|
2009-05-28 03:56:56 +08:00
|
|
|
if (mce_bootlog != 0)
|
|
|
|
mce_panic_timeout = 30;
|
2009-08-17 16:19:00 +08:00
|
|
|
|
|
|
|
return 0;
|
2007-10-24 04:37:23 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-10-16 18:31:32 +08:00
|
|
|
static void __cpuinit __mcheck_cpu_ancient_init(struct cpuinfo_x86 *c)
|
x86, mce: use 64bit machine check code on 32bit
The 64bit machine check code is in many ways much better than
the 32bit machine check code: it is more specification compliant,
is cleaner, only has a single code base versus one per CPU,
has better infrastructure for recovery, has a cleaner way to communicate
with user space etc. etc.
Use the 64bit code for 32bit too.
This is the second attempt to do this. There was one a couple of years
ago to unify this code for 32bit and 64bit. Back then this ran into some
trouble with K7s and was reverted.
I believe this time the K7 problems (and some others) are addressed.
I went over the old handlers and was very careful to retain
all quirks.
But of course this needs a lot of testing on old systems. On newer
64bit capable systems I don't expect much problems because they have been
already tested with the 64bit kernel.
I made this a CONFIG for now that still allows to select the old
machine check code. This is mostly to make testing easier,
if someone runs into a problem we can ask them to try
with the CONFIG switched.
The new code is default y for more coverage.
Once there is confidence the 64bit code works well on older hardware
too the CONFIG_X86_OLD_MCE and the associated code can be easily
removed.
This causes a behaviour change for 32bit installations. They now
have to install the mcelog package to be able to log
corrected machine checks.
The 64bit machine check code only handles CPUs which support the
standard Intel machine check architecture described in the IA32 SDM.
The 32bit code has special support for some older CPUs which
have non standard machine check architectures, in particular
WinChip C3 and Intel P5. I made those a separate CONFIG option
and kept them for now. The WinChip variant could be probably
removed without too much pain, it doesn't really do anything
interesting. P5 is also disabled by default (like it
was before) because many motherboards have it miswired, but
according to Alan Cox a few embedded setups use that one.
Forward ported/heavily changed version of old patch, original patch
included review/fixes from Thomas Gleixner, Bert Wesarg.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-04-29 01:07:31 +08:00
|
|
|
{
|
|
|
|
if (c->x86 != 5)
|
|
|
|
return;
|
|
|
|
switch (c->x86_vendor) {
|
|
|
|
case X86_VENDOR_INTEL:
|
2009-06-15 16:22:49 +08:00
|
|
|
intel_p5_mcheck_init(c);
|
x86, mce: use 64bit machine check code on 32bit
The 64bit machine check code is in many ways much better than
the 32bit machine check code: it is more specification compliant,
is cleaner, only has a single code base versus one per CPU,
has better infrastructure for recovery, has a cleaner way to communicate
with user space etc. etc.
Use the 64bit code for 32bit too.
This is the second attempt to do this. There was one a couple of years
ago to unify this code for 32bit and 64bit. Back then this ran into some
trouble with K7s and was reverted.
I believe this time the K7 problems (and some others) are addressed.
I went over the old handlers and was very careful to retain
all quirks.
But of course this needs a lot of testing on old systems. On newer
64bit capable systems I don't expect much problems because they have been
already tested with the 64bit kernel.
I made this a CONFIG for now that still allows to select the old
machine check code. This is mostly to make testing easier,
if someone runs into a problem we can ask them to try
with the CONFIG switched.
The new code is default y for more coverage.
Once there is confidence the 64bit code works well on older hardware
too the CONFIG_X86_OLD_MCE and the associated code can be easily
removed.
This causes a behaviour change for 32bit installations. They now
have to install the mcelog package to be able to log
corrected machine checks.
The 64bit machine check code only handles CPUs which support the
standard Intel machine check architecture described in the IA32 SDM.
The 32bit code has special support for some older CPUs which
have non standard machine check architectures, in particular
WinChip C3 and Intel P5. I made those a separate CONFIG option
and kept them for now. The WinChip variant could be probably
removed without too much pain, it doesn't really do anything
interesting. P5 is also disabled by default (like it
was before) because many motherboards have it miswired, but
according to Alan Cox a few embedded setups use that one.
Forward ported/heavily changed version of old patch, original patch
included review/fixes from Thomas Gleixner, Bert Wesarg.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-04-29 01:07:31 +08:00
|
|
|
break;
|
|
|
|
case X86_VENDOR_CENTAUR:
|
|
|
|
winchip_mcheck_init(c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-16 18:31:32 +08:00
|
|
|
static void __mcheck_cpu_init_vendor(struct cpuinfo_x86 *c)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
switch (c->x86_vendor) {
|
|
|
|
case X86_VENDOR_INTEL:
|
|
|
|
mce_intel_feature_init(c);
|
|
|
|
break;
|
2005-11-06 00:25:53 +08:00
|
|
|
case X86_VENDOR_AMD:
|
|
|
|
mce_amd_feature_init(c);
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-16 18:31:32 +08:00
|
|
|
static void __mcheck_cpu_init_timer(void)
|
2009-02-12 20:39:29 +08:00
|
|
|
{
|
|
|
|
struct timer_list *t = &__get_cpu_var(mce_timer);
|
2009-06-24 14:13:48 +08:00
|
|
|
int *n = &__get_cpu_var(mce_next_interval);
|
2009-02-12 20:39:29 +08:00
|
|
|
|
2009-06-11 15:06:07 +08:00
|
|
|
if (mce_ignore_ce)
|
|
|
|
return;
|
|
|
|
|
2009-04-09 18:28:22 +08:00
|
|
|
*n = check_interval * HZ;
|
|
|
|
if (!*n)
|
2009-02-12 20:39:29 +08:00
|
|
|
return;
|
2009-10-16 18:31:32 +08:00
|
|
|
setup_timer(t, mce_start_timer, smp_processor_id());
|
2009-04-09 18:28:22 +08:00
|
|
|
t->expires = round_jiffies(jiffies + *n);
|
2009-06-24 08:21:10 +08:00
|
|
|
add_timer_on(t, smp_processor_id());
|
2009-02-12 20:39:29 +08:00
|
|
|
}
|
|
|
|
|
2009-07-09 06:31:42 +08:00
|
|
|
/* Handle unconfigured int18 (should never happen) */
|
|
|
|
static void unexpected_machine_check(struct pt_regs *regs, long error_code)
|
|
|
|
{
|
|
|
|
printk(KERN_ERR "CPU#%d: Unexpected int18 (Machine Check).\n",
|
|
|
|
smp_processor_id());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Call the installed machine check handler for this CPU setup. */
|
|
|
|
void (*machine_check_vector)(struct pt_regs *, long error_code) =
|
|
|
|
unexpected_machine_check;
|
|
|
|
|
2007-10-24 04:37:23 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Called for each booted CPU to set up machine checks.
|
2009-04-08 18:31:17 +08:00
|
|
|
* Must be called with preempt off:
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2009-10-16 18:31:32 +08:00
|
|
|
void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
x86, mce: use 64bit machine check code on 32bit
The 64bit machine check code is in many ways much better than
the 32bit machine check code: it is more specification compliant,
is cleaner, only has a single code base versus one per CPU,
has better infrastructure for recovery, has a cleaner way to communicate
with user space etc. etc.
Use the 64bit code for 32bit too.
This is the second attempt to do this. There was one a couple of years
ago to unify this code for 32bit and 64bit. Back then this ran into some
trouble with K7s and was reverted.
I believe this time the K7 problems (and some others) are addressed.
I went over the old handlers and was very careful to retain
all quirks.
But of course this needs a lot of testing on old systems. On newer
64bit capable systems I don't expect much problems because they have been
already tested with the 64bit kernel.
I made this a CONFIG for now that still allows to select the old
machine check code. This is mostly to make testing easier,
if someone runs into a problem we can ask them to try
with the CONFIG switched.
The new code is default y for more coverage.
Once there is confidence the 64bit code works well on older hardware
too the CONFIG_X86_OLD_MCE and the associated code can be easily
removed.
This causes a behaviour change for 32bit installations. They now
have to install the mcelog package to be able to log
corrected machine checks.
The 64bit machine check code only handles CPUs which support the
standard Intel machine check architecture described in the IA32 SDM.
The 32bit code has special support for some older CPUs which
have non standard machine check architectures, in particular
WinChip C3 and Intel P5. I made those a separate CONFIG option
and kept them for now. The WinChip variant could be probably
removed without too much pain, it doesn't really do anything
interesting. P5 is also disabled by default (like it
was before) because many motherboards have it miswired, but
according to Alan Cox a few embedded setups use that one.
Forward ported/heavily changed version of old patch, original patch
included review/fixes from Thomas Gleixner, Bert Wesarg.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-04-29 01:07:31 +08:00
|
|
|
if (mce_disabled)
|
|
|
|
return;
|
|
|
|
|
2009-10-16 18:31:32 +08:00
|
|
|
__mcheck_cpu_ancient_init(c);
|
x86, mce: use 64bit machine check code on 32bit
The 64bit machine check code is in many ways much better than
the 32bit machine check code: it is more specification compliant,
is cleaner, only has a single code base versus one per CPU,
has better infrastructure for recovery, has a cleaner way to communicate
with user space etc. etc.
Use the 64bit code for 32bit too.
This is the second attempt to do this. There was one a couple of years
ago to unify this code for 32bit and 64bit. Back then this ran into some
trouble with K7s and was reverted.
I believe this time the K7 problems (and some others) are addressed.
I went over the old handlers and was very careful to retain
all quirks.
But of course this needs a lot of testing on old systems. On newer
64bit capable systems I don't expect much problems because they have been
already tested with the 64bit kernel.
I made this a CONFIG for now that still allows to select the old
machine check code. This is mostly to make testing easier,
if someone runs into a problem we can ask them to try
with the CONFIG switched.
The new code is default y for more coverage.
Once there is confidence the 64bit code works well on older hardware
too the CONFIG_X86_OLD_MCE and the associated code can be easily
removed.
This causes a behaviour change for 32bit installations. They now
have to install the mcelog package to be able to log
corrected machine checks.
The 64bit machine check code only handles CPUs which support the
standard Intel machine check architecture described in the IA32 SDM.
The 32bit code has special support for some older CPUs which
have non standard machine check architectures, in particular
WinChip C3 and Intel P5. I made those a separate CONFIG option
and kept them for now. The WinChip variant could be probably
removed without too much pain, it doesn't really do anything
interesting. P5 is also disabled by default (like it
was before) because many motherboards have it miswired, but
according to Alan Cox a few embedded setups use that one.
Forward ported/heavily changed version of old patch, original patch
included review/fixes from Thomas Gleixner, Bert Wesarg.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-04-29 01:07:31 +08:00
|
|
|
|
2009-02-12 20:39:30 +08:00
|
|
|
if (!mce_available(c))
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
2009-10-16 18:31:32 +08:00
|
|
|
if (__mcheck_cpu_cap_init() < 0 || __mcheck_cpu_apply_quirks(c) < 0) {
|
2009-04-29 04:50:19 +08:00
|
|
|
mce_disabled = 1;
|
2009-02-18 06:07:13 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-28 01:25:48 +08:00
|
|
|
machine_check_vector = do_machine_check;
|
|
|
|
|
2009-10-16 18:31:32 +08:00
|
|
|
__mcheck_cpu_init_generic();
|
|
|
|
__mcheck_cpu_init_vendor(c);
|
|
|
|
__mcheck_cpu_init_timer();
|
x86, mce: support action-optional machine checks
Newer Intel CPUs support a new class of machine checks called recoverable
action optional.
Action Optional means that the CPU detected some form of corruption in
the background and tells the OS about using a machine check
exception. The OS can then take appropiate action, like killing the
process with the corrupted data or logging the event properly to disk.
This is done by the new generic high level memory failure handler added
in a earlier patch. The high level handler takes the address with the
failed memory and does the appropiate action, like killing the process.
In this version of the patch the high level handler is stubbed out
with a weak function to not create a direct dependency on the hwpoison
branch.
The high level handler cannot be directly called from the machine check
exception though, because it has to run in a defined process context to
be able to sleep when taking VM locks (it is not expected to sleep for a
long time, just do so in some exceptional cases like lock contention)
Thus the MCE handler has to queue a work item for process context,
trigger process context and then call the high level handler from there.
This patch adds two path to process context: through a per thread kernel
exit notify_user() callback or through a high priority work item.
The first runs when the process exits back to user space, the other when
it goes to sleep and there is no higher priority process.
The machine check handler will schedule both, and whoever runs first
will grab the event. This is done because quick reaction to this
event is critical to avoid a potential more fatal machine check
when the corruption is consumed.
There is a simple lock less ring buffer to queue the corrupted
addresses between the exception handler and the process context handler.
Then in process context it just calls the high level VM code with
the corrupted PFNs.
The code adds the required code to extract the failed address from
the CPU's machine check registers. It doesn't try to handle all
possible cases -- the specification has 6 different ways to specify
memory address -- but only the linear address.
Most of the required checking has been already done earlier in the
mce_severity rule checking engine. Following the Intel
recommendations Action Optional errors are only enabled for known
situations (encoded in MCACODs). The errors are ignored otherwise,
because they are action optional.
v2: Improve comment, disable preemption while processing ring buffer
(reported by Ying Huang)
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-05-28 03:56:59 +08:00
|
|
|
INIT_WORK(&__get_cpu_var(mce_work), mce_process_work);
|
2009-10-07 19:20:38 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Character device to read and clear the MCE log.
|
|
|
|
*/
|
|
|
|
|
2007-07-21 23:10:35 +08:00
|
|
|
static DEFINE_SPINLOCK(mce_state_lock);
|
2009-04-08 18:31:17 +08:00
|
|
|
static int open_count; /* #times opened */
|
|
|
|
static int open_exclu; /* already open exclusive? */
|
2007-07-21 23:10:35 +08:00
|
|
|
|
|
|
|
static int mce_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
spin_lock(&mce_state_lock);
|
|
|
|
|
|
|
|
if (open_exclu || (open_count && (file->f_flags & O_EXCL))) {
|
|
|
|
spin_unlock(&mce_state_lock);
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2007-07-21 23:10:35 +08:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (file->f_flags & O_EXCL)
|
|
|
|
open_exclu = 1;
|
|
|
|
open_count++;
|
|
|
|
|
|
|
|
spin_unlock(&mce_state_lock);
|
|
|
|
|
x86_64: mcelog tolerant level cleanup
Background:
The MCE handler has several paths that it can take, depending on various
conditions of the MCE status and the value of the 'tolerant' knob. The
exact semantics are not well defined and the code is a bit twisty.
Description:
This patch makes the MCE handler's behavior more clear by documenting the
behavior for various 'tolerant' levels. It also fixes or enhances
several small things in the handler. Specifically:
* If RIPV is set it is not safe to restart, so set the 'no way out'
flag rather than the 'kill it' flag.
* Don't panic() on correctable MCEs.
* If the _OVER bit is set *and* the _UC bit is set (meaning possibly
dropped uncorrected errors), set the 'no way out' flag.
* Use EIPV for testing whether an app can be killed (SIGBUS) rather
than RIPV. According to docs, EIPV indicates that the error is
related to the IP, while RIPV simply means the IP is valid to
restart from.
* Don't clear the MCi_STATUS registers until after the panic() path.
This leaves the status bits set after the panic() so clever BIOSes
can find them (and dumb BIOSes can do nothing).
This patch also calls nonseekable_open() in mce_open (as suggested by akpm).
Result:
Tolerant levels behave almost identically to how they always have, but
not it's well defined. There's a slightly higher chance of panic()ing
when multiple errors happen (a good thing, IMHO). If you take an MBE and
panic(), the error status bits are not cleared.
Alternatives:
None.
Testing:
I used software to inject correctable and uncorrectable errors. With
tolerant = 3, the system usually survives. With tolerant = 2, the system
usually panic()s (PCC) but not always. With tolerant = 1, the system
always panic()s. When the system panic()s, the BIOS is able to detect
that the cause of death was an MC4. I was not able to reproduce the
case of a non-PCC error in userspace, with EIPV, with (tolerant < 3).
That will be rare at best.
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:37 +08:00
|
|
|
return nonseekable_open(inode, file);
|
2007-07-21 23:10:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mce_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
spin_lock(&mce_state_lock);
|
|
|
|
|
|
|
|
open_count--;
|
|
|
|
open_exclu = 0;
|
|
|
|
|
|
|
|
spin_unlock(&mce_state_lock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-10-24 04:37:23 +08:00
|
|
|
static void collect_tscs(void *data)
|
|
|
|
{
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long *cpu_tsc = (unsigned long *)data;
|
2007-10-24 04:37:23 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
rdtscll(cpu_tsc[smp_processor_id()]);
|
2007-10-24 04:37:23 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
static DEFINE_MUTEX(mce_read_mutex);
|
|
|
|
|
2007-10-24 04:37:23 +08:00
|
|
|
static ssize_t mce_read(struct file *filp, char __user *ubuf, size_t usize,
|
|
|
|
loff_t *off)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-04-08 18:31:17 +08:00
|
|
|
char __user *buf = ubuf;
|
2005-04-17 06:25:10 +08:00
|
|
|
unsigned long *cpu_tsc;
|
2009-02-12 20:39:34 +08:00
|
|
|
unsigned prev, next;
|
2005-04-17 06:20:36 +08:00
|
|
|
int i, err;
|
|
|
|
|
2008-07-19 09:11:27 +08:00
|
|
|
cpu_tsc = kmalloc(nr_cpu_ids * sizeof(long), GFP_KERNEL);
|
2005-04-17 06:25:10 +08:00
|
|
|
if (!cpu_tsc)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2008-01-30 20:31:17 +08:00
|
|
|
mutex_lock(&mce_read_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
next = rcu_dereference(mcelog.next);
|
|
|
|
|
|
|
|
/* Only supports full reads right now */
|
2007-10-24 04:37:23 +08:00
|
|
|
if (*off != 0 || usize < MCE_LOG_LEN*sizeof(struct mce)) {
|
2008-01-30 20:31:17 +08:00
|
|
|
mutex_unlock(&mce_read_mutex);
|
2005-04-17 06:25:10 +08:00
|
|
|
kfree(cpu_tsc);
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = 0;
|
2009-02-12 20:39:34 +08:00
|
|
|
prev = 0;
|
|
|
|
do {
|
|
|
|
for (i = prev; i < next; i++) {
|
|
|
|
unsigned long start = jiffies;
|
|
|
|
|
|
|
|
while (!mcelog.entry[i].finished) {
|
|
|
|
if (time_after_eq(jiffies, start + 2)) {
|
|
|
|
memset(mcelog.entry + i, 0,
|
|
|
|
sizeof(struct mce));
|
|
|
|
goto timeout;
|
|
|
|
}
|
|
|
|
cpu_relax();
|
2005-09-13 00:49:24 +08:00
|
|
|
}
|
2009-02-12 20:39:34 +08:00
|
|
|
smp_rmb();
|
|
|
|
err |= copy_to_user(buf, mcelog.entry + i,
|
|
|
|
sizeof(struct mce));
|
|
|
|
buf += sizeof(struct mce);
|
|
|
|
timeout:
|
|
|
|
;
|
2005-09-13 00:49:24 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-02-12 20:39:34 +08:00
|
|
|
memset(mcelog.entry + prev, 0,
|
|
|
|
(next - prev) * sizeof(struct mce));
|
|
|
|
prev = next;
|
|
|
|
next = cmpxchg(&mcelog.next, prev, 0);
|
|
|
|
} while (next != prev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-06-26 05:55:38 +08:00
|
|
|
synchronize_sched();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-10-24 04:37:23 +08:00
|
|
|
/*
|
|
|
|
* Collect entries that were still getting written before the
|
|
|
|
* synchronize.
|
|
|
|
*/
|
2008-05-09 15:39:44 +08:00
|
|
|
on_each_cpu(collect_tscs, cpu_tsc, 1);
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2007-10-24 04:37:23 +08:00
|
|
|
for (i = next; i < MCE_LOG_LEN; i++) {
|
|
|
|
if (mcelog.entry[i].finished &&
|
|
|
|
mcelog.entry[i].tsc < cpu_tsc[mcelog.entry[i].cpu]) {
|
|
|
|
err |= copy_to_user(buf, mcelog.entry+i,
|
|
|
|
sizeof(struct mce));
|
2005-04-17 06:20:36 +08:00
|
|
|
smp_rmb();
|
|
|
|
buf += sizeof(struct mce);
|
|
|
|
memset(&mcelog.entry[i], 0, sizeof(struct mce));
|
|
|
|
}
|
2007-10-24 04:37:23 +08:00
|
|
|
}
|
2008-01-30 20:31:17 +08:00
|
|
|
mutex_unlock(&mce_read_mutex);
|
2005-04-17 06:25:10 +08:00
|
|
|
kfree(cpu_tsc);
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2007-10-24 04:37:23 +08:00
|
|
|
return err ? -EFAULT : buf - ubuf;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
x86_64: support poll() on /dev/mcelog
Background:
/dev/mcelog is typically polled manually. This is less than optimal for
situations where accurate accounting of MCEs is important. Calling
poll() on /dev/mcelog does not work.
Description:
This patch adds support for poll() to /dev/mcelog. This results in
immediate wakeup of user apps whenever the poller finds MCEs. Because
the exception handler can not take any locks, it can not call the wakeup
itself. Instead, it uses a thread_info flag (TIF_MCE_NOTIFY) which is
caught at the next return from interrupt or exit from idle, calling the
mce_user_notify() routine. This patch also disables the "fake panic"
path of the mce_panic(), because it results in printk()s in the exception
handler and crashy systems.
This patch also does some small cleanup for essentially unused variables,
and moves the user notification into the body of the poller, so it is
only called once per poll, rather than once per CPU.
Result:
Applications can now poll() on /dev/mcelog. When an error is logged
(whether through the poller or through an exception) the applications are
woken up promptly. This should not affect any previous behaviors. If no
MCEs are being logged, there is no overhead.
Alternatives:
I considered simply supporting poll() through the poller and not using
TIF_MCE_NOTIFY at all. However, the time between an uncorrectable error
happening and the user application being notified is *the*most* critical
window for us. Many uncorrectable errors can be logged to the network if
given a chance.
I also considered doing the MCE poll directly from the idle notifier, but
decided that was overkill.
Testing:
I used an error-injecting DIMM to create lots of correctable DRAM errors
and verified that my user app is woken up in sync with the polling interval.
I also used the northbridge to inject uncorrectable ECC errors, and
verified (printk() to the rescue) that the notify routine is called and the
user app does wake up. I built with PREEMPT on and off, and verified
that my machine survives MCEs.
[wli@holomorphy.com: build fix]
Signed-off-by: Tim Hockin <thockin@google.com>
Signed-off-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-21 23:10:36 +08:00
|
|
|
static unsigned int mce_poll(struct file *file, poll_table *wait)
|
|
|
|
{
|
|
|
|
poll_wait(file, &mce_wait, wait);
|
|
|
|
if (rcu_dereference(mcelog.next))
|
|
|
|
return POLLIN | POLLRDNORM;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-30 20:32:59 +08:00
|
|
|
static long mce_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int __user *p = (int __user *)arg;
|
2007-10-24 04:37:23 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
2007-10-24 04:37:23 +08:00
|
|
|
return -EPERM;
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (cmd) {
|
2007-10-24 04:37:23 +08:00
|
|
|
case MCE_GET_RECORD_LEN:
|
2005-04-17 06:20:36 +08:00
|
|
|
return put_user(sizeof(struct mce), p);
|
|
|
|
case MCE_GET_LOG_LEN:
|
2007-10-24 04:37:23 +08:00
|
|
|
return put_user(MCE_LOG_LEN, p);
|
2005-04-17 06:20:36 +08:00
|
|
|
case MCE_GETCLEAR_FLAGS: {
|
|
|
|
unsigned flags;
|
2007-10-24 04:37:23 +08:00
|
|
|
|
|
|
|
do {
|
2005-04-17 06:20:36 +08:00
|
|
|
flags = mcelog.flags;
|
2007-10-24 04:37:23 +08:00
|
|
|
} while (cmpxchg(&mcelog.flags, flags, 0) != flags);
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2007-10-24 04:37:23 +08:00
|
|
|
return put_user(flags, p);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
default:
|
2007-10-24 04:37:23 +08:00
|
|
|
return -ENOTTY;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-05-26 13:16:14 +08:00
|
|
|
/* Modified in mce-inject.c, so not static or const */
|
2009-04-30 01:31:00 +08:00
|
|
|
struct file_operations mce_chrdev_ops = {
|
2009-04-08 18:31:17 +08:00
|
|
|
.open = mce_open,
|
|
|
|
.release = mce_release,
|
|
|
|
.read = mce_read,
|
|
|
|
.poll = mce_poll,
|
|
|
|
.unlocked_ioctl = mce_ioctl,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
2009-04-30 01:31:00 +08:00
|
|
|
EXPORT_SYMBOL_GPL(mce_chrdev_ops);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static struct miscdevice mce_log_device = {
|
|
|
|
MISC_MCELOG_MINOR,
|
|
|
|
"mcelog",
|
|
|
|
&mce_chrdev_ops,
|
|
|
|
};
|
|
|
|
|
2009-03-26 16:39:20 +08:00
|
|
|
/*
|
2009-06-11 15:06:07 +08:00
|
|
|
* mce=off Disables machine check
|
|
|
|
* mce=no_cmci Disables CMCI
|
|
|
|
* mce=dont_log_ce Clears corrected events silently, no log created for CEs.
|
|
|
|
* mce=ignore_ce Disables polling and CMCI, corrected events are not cleared.
|
2009-05-28 03:56:55 +08:00
|
|
|
* mce=TOLERANCELEVEL[,monarchtimeout] (number, see above)
|
|
|
|
* monarchtimeout is how long to wait for other CPUs on machine
|
|
|
|
* check, or 0 to not wait
|
2009-03-26 16:39:20 +08:00
|
|
|
* mce=bootlog Log MCEs from before booting. Disabled by default on AMD.
|
|
|
|
* mce=nobootlog Don't log MCEs from before booting.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
static int __init mcheck_enable(char *str)
|
|
|
|
{
|
2009-07-29 05:55:09 +08:00
|
|
|
if (*str == 0) {
|
x86, mce: use 64bit machine check code on 32bit
The 64bit machine check code is in many ways much better than
the 32bit machine check code: it is more specification compliant,
is cleaner, only has a single code base versus one per CPU,
has better infrastructure for recovery, has a cleaner way to communicate
with user space etc. etc.
Use the 64bit code for 32bit too.
This is the second attempt to do this. There was one a couple of years
ago to unify this code for 32bit and 64bit. Back then this ran into some
trouble with K7s and was reverted.
I believe this time the K7 problems (and some others) are addressed.
I went over the old handlers and was very careful to retain
all quirks.
But of course this needs a lot of testing on old systems. On newer
64bit capable systems I don't expect much problems because they have been
already tested with the 64bit kernel.
I made this a CONFIG for now that still allows to select the old
machine check code. This is mostly to make testing easier,
if someone runs into a problem we can ask them to try
with the CONFIG switched.
The new code is default y for more coverage.
Once there is confidence the 64bit code works well on older hardware
too the CONFIG_X86_OLD_MCE and the associated code can be easily
removed.
This causes a behaviour change for 32bit installations. They now
have to install the mcelog package to be able to log
corrected machine checks.
The 64bit machine check code only handles CPUs which support the
standard Intel machine check architecture described in the IA32 SDM.
The 32bit code has special support for some older CPUs which
have non standard machine check architectures, in particular
WinChip C3 and Intel P5. I made those a separate CONFIG option
and kept them for now. The WinChip variant could be probably
removed without too much pain, it doesn't really do anything
interesting. P5 is also disabled by default (like it
was before) because many motherboards have it miswired, but
according to Alan Cox a few embedded setups use that one.
Forward ported/heavily changed version of old patch, original patch
included review/fixes from Thomas Gleixner, Bert Wesarg.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-04-29 01:07:31 +08:00
|
|
|
enable_p5_mce();
|
2009-07-29 05:55:09 +08:00
|
|
|
return 1;
|
|
|
|
}
|
x86, mce: use 64bit machine check code on 32bit
The 64bit machine check code is in many ways much better than
the 32bit machine check code: it is more specification compliant,
is cleaner, only has a single code base versus one per CPU,
has better infrastructure for recovery, has a cleaner way to communicate
with user space etc. etc.
Use the 64bit code for 32bit too.
This is the second attempt to do this. There was one a couple of years
ago to unify this code for 32bit and 64bit. Back then this ran into some
trouble with K7s and was reverted.
I believe this time the K7 problems (and some others) are addressed.
I went over the old handlers and was very careful to retain
all quirks.
But of course this needs a lot of testing on old systems. On newer
64bit capable systems I don't expect much problems because they have been
already tested with the 64bit kernel.
I made this a CONFIG for now that still allows to select the old
machine check code. This is mostly to make testing easier,
if someone runs into a problem we can ask them to try
with the CONFIG switched.
The new code is default y for more coverage.
Once there is confidence the 64bit code works well on older hardware
too the CONFIG_X86_OLD_MCE and the associated code can be easily
removed.
This causes a behaviour change for 32bit installations. They now
have to install the mcelog package to be able to log
corrected machine checks.
The 64bit machine check code only handles CPUs which support the
standard Intel machine check architecture described in the IA32 SDM.
The 32bit code has special support for some older CPUs which
have non standard machine check architectures, in particular
WinChip C3 and Intel P5. I made those a separate CONFIG option
and kept them for now. The WinChip variant could be probably
removed without too much pain, it doesn't really do anything
interesting. P5 is also disabled by default (like it
was before) because many motherboards have it miswired, but
according to Alan Cox a few embedded setups use that one.
Forward ported/heavily changed version of old patch, original patch
included review/fixes from Thomas Gleixner, Bert Wesarg.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-04-29 01:07:31 +08:00
|
|
|
if (*str == '=')
|
|
|
|
str++;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!strcmp(str, "off"))
|
2009-04-29 04:50:19 +08:00
|
|
|
mce_disabled = 1;
|
2009-06-11 15:06:07 +08:00
|
|
|
else if (!strcmp(str, "no_cmci"))
|
|
|
|
mce_cmci_disabled = 1;
|
|
|
|
else if (!strcmp(str, "dont_log_ce"))
|
|
|
|
mce_dont_log_ce = 1;
|
|
|
|
else if (!strcmp(str, "ignore_ce"))
|
|
|
|
mce_ignore_ce = 1;
|
2009-03-26 16:39:20 +08:00
|
|
|
else if (!strcmp(str, "bootlog") || !strcmp(str, "nobootlog"))
|
|
|
|
mce_bootlog = (str[0] == 'b');
|
2009-05-28 03:56:55 +08:00
|
|
|
else if (isdigit(str[0])) {
|
2005-09-13 00:49:24 +08:00
|
|
|
get_option(&str, &tolerant);
|
2009-05-28 03:56:55 +08:00
|
|
|
if (*str == ',') {
|
|
|
|
++str;
|
|
|
|
get_option(&str, &monarch_timeout);
|
|
|
|
}
|
|
|
|
} else {
|
x86, mce: use 64bit machine check code on 32bit
The 64bit machine check code is in many ways much better than
the 32bit machine check code: it is more specification compliant,
is cleaner, only has a single code base versus one per CPU,
has better infrastructure for recovery, has a cleaner way to communicate
with user space etc. etc.
Use the 64bit code for 32bit too.
This is the second attempt to do this. There was one a couple of years
ago to unify this code for 32bit and 64bit. Back then this ran into some
trouble with K7s and was reverted.
I believe this time the K7 problems (and some others) are addressed.
I went over the old handlers and was very careful to retain
all quirks.
But of course this needs a lot of testing on old systems. On newer
64bit capable systems I don't expect much problems because they have been
already tested with the 64bit kernel.
I made this a CONFIG for now that still allows to select the old
machine check code. This is mostly to make testing easier,
if someone runs into a problem we can ask them to try
with the CONFIG switched.
The new code is default y for more coverage.
Once there is confidence the 64bit code works well on older hardware
too the CONFIG_X86_OLD_MCE and the associated code can be easily
removed.
This causes a behaviour change for 32bit installations. They now
have to install the mcelog package to be able to log
corrected machine checks.
The 64bit machine check code only handles CPUs which support the
standard Intel machine check architecture described in the IA32 SDM.
The 32bit code has special support for some older CPUs which
have non standard machine check architectures, in particular
WinChip C3 and Intel P5. I made those a separate CONFIG option
and kept them for now. The WinChip variant could be probably
removed without too much pain, it doesn't really do anything
interesting. P5 is also disabled by default (like it
was before) because many motherboards have it miswired, but
according to Alan Cox a few embedded setups use that one.
Forward ported/heavily changed version of old patch, original patch
included review/fixes from Thomas Gleixner, Bert Wesarg.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-04-29 01:07:31 +08:00
|
|
|
printk(KERN_INFO "mce argument %s ignored. Please use /sys\n",
|
2009-03-26 16:39:20 +08:00
|
|
|
str);
|
|
|
|
return 0;
|
|
|
|
}
|
2006-03-31 18:30:33 +08:00
|
|
|
return 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
x86, mce: use 64bit machine check code on 32bit
The 64bit machine check code is in many ways much better than
the 32bit machine check code: it is more specification compliant,
is cleaner, only has a single code base versus one per CPU,
has better infrastructure for recovery, has a cleaner way to communicate
with user space etc. etc.
Use the 64bit code for 32bit too.
This is the second attempt to do this. There was one a couple of years
ago to unify this code for 32bit and 64bit. Back then this ran into some
trouble with K7s and was reverted.
I believe this time the K7 problems (and some others) are addressed.
I went over the old handlers and was very careful to retain
all quirks.
But of course this needs a lot of testing on old systems. On newer
64bit capable systems I don't expect much problems because they have been
already tested with the 64bit kernel.
I made this a CONFIG for now that still allows to select the old
machine check code. This is mostly to make testing easier,
if someone runs into a problem we can ask them to try
with the CONFIG switched.
The new code is default y for more coverage.
Once there is confidence the 64bit code works well on older hardware
too the CONFIG_X86_OLD_MCE and the associated code can be easily
removed.
This causes a behaviour change for 32bit installations. They now
have to install the mcelog package to be able to log
corrected machine checks.
The 64bit machine check code only handles CPUs which support the
standard Intel machine check architecture described in the IA32 SDM.
The 32bit code has special support for some older CPUs which
have non standard machine check architectures, in particular
WinChip C3 and Intel P5. I made those a separate CONFIG option
and kept them for now. The WinChip variant could be probably
removed without too much pain, it doesn't really do anything
interesting. P5 is also disabled by default (like it
was before) because many motherboards have it miswired, but
according to Alan Cox a few embedded setups use that one.
Forward ported/heavily changed version of old patch, original patch
included review/fixes from Thomas Gleixner, Bert Wesarg.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-04-29 01:07:31 +08:00
|
|
|
__setup("mce", mcheck_enable);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-10-16 18:31:33 +08:00
|
|
|
static int __init mcheck_init(void)
|
|
|
|
{
|
|
|
|
atomic_notifier_chain_register(&x86_mce_decoder_chain, &mce_dec_nb);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
early_initcall(mcheck_init);
|
|
|
|
|
2007-10-24 04:37:23 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Sysfs support
|
2007-10-24 04:37:23 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-02-12 20:39:32 +08:00
|
|
|
/*
|
|
|
|
* Disable machine checks on suspend and shutdown. We can't really handle
|
|
|
|
* them later.
|
|
|
|
*/
|
2009-10-16 18:31:32 +08:00
|
|
|
static int mce_disable_error_reporting(void)
|
2009-02-12 20:39:32 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2009-04-28 00:37:43 +08:00
|
|
|
for (i = 0; i < banks; i++) {
|
2009-07-09 06:31:43 +08:00
|
|
|
struct mce_bank *b = &mce_banks[i];
|
2009-09-23 23:49:55 +08:00
|
|
|
|
2009-07-09 06:31:43 +08:00
|
|
|
if (b->init)
|
2009-07-09 06:31:44 +08:00
|
|
|
wrmsrl(MSR_IA32_MCx_CTL(i), 0);
|
2009-04-28 00:37:43 +08:00
|
|
|
}
|
2009-02-12 20:39:32 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mce_suspend(struct sys_device *dev, pm_message_t state)
|
|
|
|
{
|
2009-10-16 18:31:32 +08:00
|
|
|
return mce_disable_error_reporting();
|
2009-02-12 20:39:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mce_shutdown(struct sys_device *dev)
|
|
|
|
{
|
2009-10-16 18:31:32 +08:00
|
|
|
return mce_disable_error_reporting();
|
2009-02-12 20:39:32 +08:00
|
|
|
}
|
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
/*
|
|
|
|
* On resume clear all MCE state. Don't want to see leftovers from the BIOS.
|
|
|
|
* Only one CPU is active at this time, the others get re-added later using
|
|
|
|
* CPU hotplug:
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
static int mce_resume(struct sys_device *dev)
|
|
|
|
{
|
2009-10-16 18:31:32 +08:00
|
|
|
__mcheck_cpu_init_generic();
|
|
|
|
__mcheck_cpu_init_vendor(¤t_cpu_data);
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-12 20:39:29 +08:00
|
|
|
static void mce_cpu_restart(void *data)
|
|
|
|
{
|
|
|
|
del_timer_sync(&__get_cpu_var(mce_timer));
|
2009-06-15 16:18:45 +08:00
|
|
|
if (!mce_available(¤t_cpu_data))
|
|
|
|
return;
|
2009-10-16 18:31:32 +08:00
|
|
|
__mcheck_cpu_init_generic();
|
|
|
|
__mcheck_cpu_init_timer();
|
2009-02-12 20:39:29 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Reinit MCEs after user configuration changes */
|
2007-10-24 04:37:23 +08:00
|
|
|
static void mce_restart(void)
|
|
|
|
{
|
2009-02-12 20:39:29 +08:00
|
|
|
on_each_cpu(mce_cpu_restart, NULL, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-06-15 16:21:36 +08:00
|
|
|
/* Toggle features for corrected errors */
|
|
|
|
static void mce_disable_ce(void *all)
|
|
|
|
{
|
|
|
|
if (!mce_available(¤t_cpu_data))
|
|
|
|
return;
|
|
|
|
if (all)
|
|
|
|
del_timer_sync(&__get_cpu_var(mce_timer));
|
|
|
|
cmci_clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mce_enable_ce(void *all)
|
|
|
|
{
|
|
|
|
if (!mce_available(¤t_cpu_data))
|
|
|
|
return;
|
|
|
|
cmci_reenable();
|
|
|
|
cmci_recheck();
|
|
|
|
if (all)
|
2009-10-16 18:31:32 +08:00
|
|
|
__mcheck_cpu_init_timer();
|
2009-06-15 16:21:36 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static struct sysdev_class mce_sysclass = {
|
2009-04-08 18:31:17 +08:00
|
|
|
.suspend = mce_suspend,
|
|
|
|
.shutdown = mce_shutdown,
|
|
|
|
.resume = mce_resume,
|
|
|
|
.name = "machinecheck",
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
DEFINE_PER_CPU(struct sys_device, mce_dev);
|
2009-04-08 18:31:17 +08:00
|
|
|
|
|
|
|
__cpuinitdata
|
|
|
|
void (*threshold_cpu_callback)(unsigned long action, unsigned int cpu);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-07-09 06:31:43 +08:00
|
|
|
static inline struct mce_bank *attr_to_bank(struct sysdev_attribute *attr)
|
|
|
|
{
|
|
|
|
return container_of(attr, struct mce_bank, attr);
|
|
|
|
}
|
2009-02-18 06:07:13 +08:00
|
|
|
|
|
|
|
static ssize_t show_bank(struct sys_device *s, struct sysdev_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
2009-07-09 06:31:43 +08:00
|
|
|
return sprintf(buf, "%llx\n", attr_to_bank(attr)->ctl);
|
2009-02-18 06:07:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t set_bank(struct sys_device *s, struct sysdev_attribute *attr,
|
2009-04-14 16:26:30 +08:00
|
|
|
const char *buf, size_t size)
|
2009-02-18 06:07:13 +08:00
|
|
|
{
|
2009-04-14 16:26:30 +08:00
|
|
|
u64 new;
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2009-04-14 16:26:30 +08:00
|
|
|
if (strict_strtoull(buf, 0, &new) < 0)
|
2009-02-18 06:07:13 +08:00
|
|
|
return -EINVAL;
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2009-07-09 06:31:43 +08:00
|
|
|
attr_to_bank(attr)->ctl = new;
|
2009-02-18 06:07:13 +08:00
|
|
|
mce_restart();
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2009-04-14 16:26:30 +08:00
|
|
|
return size;
|
2009-02-18 06:07:13 +08:00
|
|
|
}
|
2007-02-13 20:26:23 +08:00
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
static ssize_t
|
|
|
|
show_trigger(struct sys_device *s, struct sysdev_attribute *attr, char *buf)
|
2007-02-13 20:26:23 +08:00
|
|
|
{
|
2009-06-15 16:20:57 +08:00
|
|
|
strcpy(buf, mce_helper);
|
2007-02-13 20:26:23 +08:00
|
|
|
strcat(buf, "\n");
|
2009-06-15 16:20:57 +08:00
|
|
|
return strlen(mce_helper) + 1;
|
2007-02-13 20:26:23 +08:00
|
|
|
}
|
|
|
|
|
2008-07-02 00:48:41 +08:00
|
|
|
static ssize_t set_trigger(struct sys_device *s, struct sysdev_attribute *attr,
|
2009-04-08 18:31:17 +08:00
|
|
|
const char *buf, size_t siz)
|
2007-02-13 20:26:23 +08:00
|
|
|
{
|
|
|
|
char *p;
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2009-06-15 16:20:57 +08:00
|
|
|
strncpy(mce_helper, buf, sizeof(mce_helper));
|
|
|
|
mce_helper[sizeof(mce_helper)-1] = 0;
|
|
|
|
p = strchr(mce_helper, '\n');
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2009-07-16 16:45:11 +08:00
|
|
|
if (p)
|
2009-04-08 18:31:17 +08:00
|
|
|
*p = 0;
|
|
|
|
|
2009-07-16 16:45:11 +08:00
|
|
|
return strlen(mce_helper) + !!p;
|
2007-02-13 20:26:23 +08:00
|
|
|
}
|
|
|
|
|
2009-06-15 16:21:36 +08:00
|
|
|
static ssize_t set_ignore_ce(struct sys_device *s,
|
|
|
|
struct sysdev_attribute *attr,
|
|
|
|
const char *buf, size_t size)
|
|
|
|
{
|
|
|
|
u64 new;
|
|
|
|
|
|
|
|
if (strict_strtoull(buf, 0, &new) < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (mce_ignore_ce ^ !!new) {
|
|
|
|
if (new) {
|
|
|
|
/* disable ce features */
|
|
|
|
on_each_cpu(mce_disable_ce, (void *)1, 1);
|
|
|
|
mce_ignore_ce = 1;
|
|
|
|
} else {
|
|
|
|
/* enable ce features */
|
|
|
|
mce_ignore_ce = 0;
|
|
|
|
on_each_cpu(mce_enable_ce, (void *)1, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t set_cmci_disabled(struct sys_device *s,
|
|
|
|
struct sysdev_attribute *attr,
|
|
|
|
const char *buf, size_t size)
|
|
|
|
{
|
|
|
|
u64 new;
|
|
|
|
|
|
|
|
if (strict_strtoull(buf, 0, &new) < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (mce_cmci_disabled ^ !!new) {
|
|
|
|
if (new) {
|
|
|
|
/* disable cmci */
|
|
|
|
on_each_cpu(mce_disable_ce, NULL, 1);
|
|
|
|
mce_cmci_disabled = 1;
|
|
|
|
} else {
|
|
|
|
/* enable cmci */
|
|
|
|
mce_cmci_disabled = 0;
|
|
|
|
on_each_cpu(mce_enable_ce, NULL, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2009-05-28 03:56:52 +08:00
|
|
|
static ssize_t store_int_with_restart(struct sys_device *s,
|
|
|
|
struct sysdev_attribute *attr,
|
|
|
|
const char *buf, size_t size)
|
|
|
|
{
|
|
|
|
ssize_t ret = sysdev_store_int(s, attr, buf, size);
|
|
|
|
mce_restart();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-02-13 20:26:23 +08:00
|
|
|
static SYSDEV_ATTR(trigger, 0644, show_trigger, set_trigger);
|
2008-07-02 00:48:43 +08:00
|
|
|
static SYSDEV_INT_ATTR(tolerant, 0644, tolerant);
|
2009-05-28 03:56:55 +08:00
|
|
|
static SYSDEV_INT_ATTR(monarch_timeout, 0644, monarch_timeout);
|
2009-06-15 16:21:36 +08:00
|
|
|
static SYSDEV_INT_ATTR(dont_log_ce, 0644, mce_dont_log_ce);
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2009-05-28 03:56:52 +08:00
|
|
|
static struct sysdev_ext_attribute attr_check_interval = {
|
|
|
|
_SYSDEV_ATTR(check_interval, 0644, sysdev_show_int,
|
|
|
|
store_int_with_restart),
|
|
|
|
&check_interval
|
|
|
|
};
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2009-06-15 16:21:36 +08:00
|
|
|
static struct sysdev_ext_attribute attr_ignore_ce = {
|
|
|
|
_SYSDEV_ATTR(ignore_ce, 0644, sysdev_show_int, set_ignore_ce),
|
|
|
|
&mce_ignore_ce
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct sysdev_ext_attribute attr_cmci_disabled = {
|
2009-06-18 05:43:32 +08:00
|
|
|
_SYSDEV_ATTR(cmci_disabled, 0644, sysdev_show_int, set_cmci_disabled),
|
2009-06-15 16:21:36 +08:00
|
|
|
&mce_cmci_disabled
|
|
|
|
};
|
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
static struct sysdev_attribute *mce_attrs[] = {
|
2009-06-15 16:21:36 +08:00
|
|
|
&attr_tolerant.attr,
|
|
|
|
&attr_check_interval.attr,
|
|
|
|
&attr_trigger,
|
2009-05-28 03:56:55 +08:00
|
|
|
&attr_monarch_timeout.attr,
|
2009-06-15 16:21:36 +08:00
|
|
|
&attr_dont_log_ce.attr,
|
|
|
|
&attr_ignore_ce.attr,
|
|
|
|
&attr_cmci_disabled.attr,
|
2007-02-13 20:26:23 +08:00
|
|
|
NULL
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
static cpumask_var_t mce_dev_initialized;
|
2007-11-15 09:00:44 +08:00
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
/* Per cpu sysdev init. All of the cpus still share the same ctrl bank: */
|
2005-07-29 12:15:39 +08:00
|
|
|
static __cpuinit int mce_create_device(unsigned int cpu)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int err;
|
2009-06-18 13:53:24 +08:00
|
|
|
int i, j;
|
2007-10-20 02:35:04 +08:00
|
|
|
|
2007-11-07 09:12:58 +08:00
|
|
|
if (!mce_available(&boot_cpu_data))
|
2005-07-29 12:15:39 +08:00
|
|
|
return -EIO;
|
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
memset(&per_cpu(mce_dev, cpu).kobj, 0, sizeof(struct kobject));
|
|
|
|
per_cpu(mce_dev, cpu).id = cpu;
|
|
|
|
per_cpu(mce_dev, cpu).cls = &mce_sysclass;
|
2005-07-29 12:15:39 +08:00
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
err = sysdev_register(&per_cpu(mce_dev, cpu));
|
2007-10-18 18:05:15 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
for (i = 0; mce_attrs[i]; i++) {
|
|
|
|
err = sysdev_create_file(&per_cpu(mce_dev, cpu), mce_attrs[i]);
|
2007-10-18 18:05:15 +08:00
|
|
|
if (err)
|
|
|
|
goto error;
|
|
|
|
}
|
2009-06-18 13:53:24 +08:00
|
|
|
for (j = 0; j < banks; j++) {
|
2009-04-08 18:31:17 +08:00
|
|
|
err = sysdev_create_file(&per_cpu(mce_dev, cpu),
|
2009-07-09 06:31:43 +08:00
|
|
|
&mce_banks[j].attr);
|
2009-02-18 06:07:13 +08:00
|
|
|
if (err)
|
|
|
|
goto error2;
|
|
|
|
}
|
2009-04-08 18:31:17 +08:00
|
|
|
cpumask_set_cpu(cpu, mce_dev_initialized);
|
2005-07-29 12:15:39 +08:00
|
|
|
|
2007-10-18 18:05:15 +08:00
|
|
|
return 0;
|
2009-02-18 06:07:13 +08:00
|
|
|
error2:
|
2009-06-18 13:53:24 +08:00
|
|
|
while (--j >= 0)
|
2009-07-09 06:31:43 +08:00
|
|
|
sysdev_remove_file(&per_cpu(mce_dev, cpu), &mce_banks[j].attr);
|
2007-10-18 18:05:15 +08:00
|
|
|
error:
|
2009-04-08 18:31:17 +08:00
|
|
|
while (--i >= 0)
|
2009-07-09 06:31:43 +08:00
|
|
|
sysdev_remove_file(&per_cpu(mce_dev, cpu), &mce_banks[i].attr);
|
2009-04-08 18:31:17 +08:00
|
|
|
|
|
|
|
sysdev_unregister(&per_cpu(mce_dev, cpu));
|
2007-10-18 18:05:15 +08:00
|
|
|
|
2005-07-29 12:15:39 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2008-08-29 20:15:04 +08:00
|
|
|
static __cpuinit void mce_remove_device(unsigned int cpu)
|
2005-07-29 12:15:39 +08:00
|
|
|
{
|
2006-01-12 05:43:06 +08:00
|
|
|
int i;
|
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
if (!cpumask_test_cpu(cpu, mce_dev_initialized))
|
2007-11-15 09:00:44 +08:00
|
|
|
return;
|
|
|
|
|
2009-04-08 18:31:17 +08:00
|
|
|
for (i = 0; mce_attrs[i]; i++)
|
|
|
|
sysdev_remove_file(&per_cpu(mce_dev, cpu), mce_attrs[i]);
|
|
|
|
|
2009-02-18 06:07:13 +08:00
|
|
|
for (i = 0; i < banks; i++)
|
2009-07-09 06:31:43 +08:00
|
|
|
sysdev_remove_file(&per_cpu(mce_dev, cpu), &mce_banks[i].attr);
|
2009-04-08 18:31:17 +08:00
|
|
|
|
|
|
|
sysdev_unregister(&per_cpu(mce_dev, cpu));
|
|
|
|
cpumask_clear_cpu(cpu, mce_dev_initialized);
|
2005-07-29 12:15:39 +08:00
|
|
|
}
|
|
|
|
|
2009-02-12 20:39:31 +08:00
|
|
|
/* Make sure there are no machine checks on offlined CPUs. */
|
2009-02-24 06:01:04 +08:00
|
|
|
static void mce_disable_cpu(void *h)
|
2009-02-12 20:39:31 +08:00
|
|
|
{
|
2009-02-12 20:49:36 +08:00
|
|
|
unsigned long action = *(unsigned long *)h;
|
2009-04-08 18:31:17 +08:00
|
|
|
int i;
|
2009-02-12 20:39:31 +08:00
|
|
|
|
|
|
|
if (!mce_available(¤t_cpu_data))
|
|
|
|
return;
|
2009-02-12 20:49:36 +08:00
|
|
|
if (!(action & CPU_TASKS_FROZEN))
|
|
|
|
cmci_clear();
|
2009-04-28 00:37:43 +08:00
|
|
|
for (i = 0; i < banks; i++) {
|
2009-07-09 06:31:43 +08:00
|
|
|
struct mce_bank *b = &mce_banks[i];
|
2009-09-23 23:49:55 +08:00
|
|
|
|
2009-07-09 06:31:43 +08:00
|
|
|
if (b->init)
|
2009-07-09 06:31:44 +08:00
|
|
|
wrmsrl(MSR_IA32_MCx_CTL(i), 0);
|
2009-04-28 00:37:43 +08:00
|
|
|
}
|
2009-02-12 20:39:31 +08:00
|
|
|
}
|
|
|
|
|
2009-02-24 06:01:04 +08:00
|
|
|
static void mce_reenable_cpu(void *h)
|
2009-02-12 20:39:31 +08:00
|
|
|
{
|
2009-02-12 20:49:36 +08:00
|
|
|
unsigned long action = *(unsigned long *)h;
|
2009-04-08 18:31:17 +08:00
|
|
|
int i;
|
2009-02-12 20:39:31 +08:00
|
|
|
|
|
|
|
if (!mce_available(¤t_cpu_data))
|
|
|
|
return;
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2009-02-12 20:49:36 +08:00
|
|
|
if (!(action & CPU_TASKS_FROZEN))
|
|
|
|
cmci_reenable();
|
2009-04-28 00:37:43 +08:00
|
|
|
for (i = 0; i < banks; i++) {
|
2009-07-09 06:31:43 +08:00
|
|
|
struct mce_bank *b = &mce_banks[i];
|
2009-09-23 23:49:55 +08:00
|
|
|
|
2009-07-09 06:31:43 +08:00
|
|
|
if (b->init)
|
2009-07-09 06:31:44 +08:00
|
|
|
wrmsrl(MSR_IA32_MCx_CTL(i), b->ctl);
|
2009-04-28 00:37:43 +08:00
|
|
|
}
|
2009-02-12 20:39:31 +08:00
|
|
|
}
|
|
|
|
|
2005-07-29 12:15:39 +08:00
|
|
|
/* Get notified when a cpu comes on/off. Be hotplug friendly. */
|
2009-04-08 18:31:17 +08:00
|
|
|
static int __cpuinit
|
|
|
|
mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
|
2005-07-29 12:15:39 +08:00
|
|
|
{
|
|
|
|
unsigned int cpu = (unsigned long)hcpu;
|
2009-02-12 20:39:29 +08:00
|
|
|
struct timer_list *t = &per_cpu(mce_timer, cpu);
|
2005-07-29 12:15:39 +08:00
|
|
|
|
|
|
|
switch (action) {
|
2007-11-15 09:00:44 +08:00
|
|
|
case CPU_ONLINE:
|
|
|
|
case CPU_ONLINE_FROZEN:
|
|
|
|
mce_create_device(cpu);
|
x86 MCE: Fix CPU hotplug problem with multiple multicore AMD CPUs
During CPU hot-remove the sysfs directory created by
threshold_create_bank(), defined in
arch/x86/kernel/cpu/mcheck/mce_amd_64.c, has to be removed before
its parent directory, created by mce_create_device(), defined in
arch/x86/kernel/cpu/mcheck/mce_64.c . Moreover, when the CPU in
question is hotplugged again, obviously the latter has to be created
before the former. At present, the right ordering is not enforced,
because all of these operations are carried out by CPU hotplug
notifiers which are not appropriately ordered with respect to each
other. This leads to serious problems on systems with two or more
multicore AMD CPUs, among other things during suspend and hibernation.
Fix the problem by placing threshold bank CPU hotplug callbacks in
mce_cpu_callback(), so that they are invoked at the right places,
if defined. Additionally, use kobject_del() to remove the sysfs
directory associated with the kobject created by
kobject_create_and_add() in threshold_create_bank(), to prevent the
kernel from crashing during CPU hotplug operations on systems with
two or more multicore AMD CPUs.
This patch fixes bug #11337.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Andi Kleen <andi@firstfloor.org>
Tested-by: Mark Langsdorf <mark.langsdorf@amd.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2008-08-23 04:23:09 +08:00
|
|
|
if (threshold_cpu_callback)
|
|
|
|
threshold_cpu_callback(action, cpu);
|
2005-07-29 12:15:39 +08:00
|
|
|
break;
|
|
|
|
case CPU_DEAD:
|
2007-05-09 17:35:10 +08:00
|
|
|
case CPU_DEAD_FROZEN:
|
x86 MCE: Fix CPU hotplug problem with multiple multicore AMD CPUs
During CPU hot-remove the sysfs directory created by
threshold_create_bank(), defined in
arch/x86/kernel/cpu/mcheck/mce_amd_64.c, has to be removed before
its parent directory, created by mce_create_device(), defined in
arch/x86/kernel/cpu/mcheck/mce_64.c . Moreover, when the CPU in
question is hotplugged again, obviously the latter has to be created
before the former. At present, the right ordering is not enforced,
because all of these operations are carried out by CPU hotplug
notifiers which are not appropriately ordered with respect to each
other. This leads to serious problems on systems with two or more
multicore AMD CPUs, among other things during suspend and hibernation.
Fix the problem by placing threshold bank CPU hotplug callbacks in
mce_cpu_callback(), so that they are invoked at the right places,
if defined. Additionally, use kobject_del() to remove the sysfs
directory associated with the kobject created by
kobject_create_and_add() in threshold_create_bank(), to prevent the
kernel from crashing during CPU hotplug operations on systems with
two or more multicore AMD CPUs.
This patch fixes bug #11337.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Andi Kleen <andi@firstfloor.org>
Tested-by: Mark Langsdorf <mark.langsdorf@amd.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2008-08-23 04:23:09 +08:00
|
|
|
if (threshold_cpu_callback)
|
|
|
|
threshold_cpu_callback(action, cpu);
|
2005-07-29 12:15:39 +08:00
|
|
|
mce_remove_device(cpu);
|
|
|
|
break;
|
2009-02-12 20:39:29 +08:00
|
|
|
case CPU_DOWN_PREPARE:
|
|
|
|
case CPU_DOWN_PREPARE_FROZEN:
|
|
|
|
del_timer_sync(t);
|
2009-02-12 20:49:36 +08:00
|
|
|
smp_call_function_single(cpu, mce_disable_cpu, &action, 1);
|
2009-02-12 20:39:29 +08:00
|
|
|
break;
|
|
|
|
case CPU_DOWN_FAILED:
|
|
|
|
case CPU_DOWN_FAILED_FROZEN:
|
2009-04-09 18:28:22 +08:00
|
|
|
t->expires = round_jiffies(jiffies +
|
2009-06-24 14:13:48 +08:00
|
|
|
__get_cpu_var(mce_next_interval));
|
2009-02-12 20:39:29 +08:00
|
|
|
add_timer_on(t, cpu);
|
2009-02-12 20:49:36 +08:00
|
|
|
smp_call_function_single(cpu, mce_reenable_cpu, &action, 1);
|
|
|
|
break;
|
|
|
|
case CPU_POST_DEAD:
|
|
|
|
/* intentionally ignoring frozen here */
|
|
|
|
cmci_rediscover(cpu);
|
2009-02-12 20:39:29 +08:00
|
|
|
break;
|
2005-07-29 12:15:39 +08:00
|
|
|
}
|
2007-11-15 09:00:44 +08:00
|
|
|
return NOTIFY_OK;
|
2005-07-29 12:15:39 +08:00
|
|
|
}
|
|
|
|
|
2008-01-30 20:33:36 +08:00
|
|
|
static struct notifier_block mce_cpu_notifier __cpuinitdata = {
|
2005-07-29 12:15:39 +08:00
|
|
|
.notifier_call = mce_cpu_callback,
|
|
|
|
};
|
|
|
|
|
2009-07-09 06:31:43 +08:00
|
|
|
static __init void mce_init_banks(void)
|
2009-02-18 06:07:13 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < banks; i++) {
|
2009-07-09 06:31:43 +08:00
|
|
|
struct mce_bank *b = &mce_banks[i];
|
|
|
|
struct sysdev_attribute *a = &b->attr;
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2009-07-09 06:31:43 +08:00
|
|
|
a->attr.name = b->attrname;
|
|
|
|
snprintf(b->attrname, ATTR_LEN, "bank%d", i);
|
2009-04-08 18:31:17 +08:00
|
|
|
|
|
|
|
a->attr.mode = 0644;
|
|
|
|
a->show = show_bank;
|
|
|
|
a->store = set_bank;
|
2009-02-18 06:07:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-16 18:31:32 +08:00
|
|
|
static __init int mcheck_init_device(void)
|
2005-07-29 12:15:39 +08:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
int i = 0;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!mce_available(&boot_cpu_data))
|
|
|
|
return -EIO;
|
2009-02-18 06:07:13 +08:00
|
|
|
|
2009-06-18 07:21:33 +08:00
|
|
|
zalloc_cpumask_var(&mce_dev_initialized, GFP_KERNEL);
|
2009-03-13 12:19:51 +08:00
|
|
|
|
2009-07-09 06:31:43 +08:00
|
|
|
mce_init_banks();
|
2009-02-18 06:07:13 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
err = sysdev_class_register(&mce_sysclass);
|
2007-10-18 18:05:15 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
2005-07-29 12:15:39 +08:00
|
|
|
|
|
|
|
for_each_online_cpu(i) {
|
2007-10-18 18:05:15 +08:00
|
|
|
err = mce_create_device(i);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2005-07-29 12:15:39 +08:00
|
|
|
}
|
|
|
|
|
2006-07-30 18:03:37 +08:00
|
|
|
register_hotcpu_notifier(&mce_cpu_notifier);
|
2005-04-17 06:20:36 +08:00
|
|
|
misc_register(&mce_log_device);
|
2009-04-08 18:31:17 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
|
|
|
}
|
2005-07-29 12:15:39 +08:00
|
|
|
|
2009-10-16 18:31:32 +08:00
|
|
|
device_initcall(mcheck_init_device);
|
2009-04-08 18:31:25 +08:00
|
|
|
|
2009-04-29 05:07:25 +08:00
|
|
|
/*
|
|
|
|
* Old style boot options parsing. Only for compatibility.
|
|
|
|
*/
|
|
|
|
static int __init mcheck_disable(char *str)
|
|
|
|
{
|
|
|
|
mce_disabled = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("nomce", mcheck_disable);
|
2009-04-08 18:31:25 +08:00
|
|
|
|
2009-07-31 09:41:42 +08:00
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
struct dentry *mce_get_debugfs_dir(void)
|
2009-04-08 18:31:25 +08:00
|
|
|
{
|
2009-07-31 09:41:42 +08:00
|
|
|
static struct dentry *dmce;
|
2009-04-08 18:31:25 +08:00
|
|
|
|
2009-07-31 09:41:42 +08:00
|
|
|
if (!dmce)
|
|
|
|
dmce = debugfs_create_dir("mce", NULL);
|
2009-04-08 18:31:25 +08:00
|
|
|
|
2009-07-31 09:41:42 +08:00
|
|
|
return dmce;
|
|
|
|
}
|
2009-04-08 18:31:25 +08:00
|
|
|
|
2009-07-31 09:41:43 +08:00
|
|
|
static void mce_reset(void)
|
|
|
|
{
|
|
|
|
cpu_missing = 0;
|
|
|
|
atomic_set(&mce_fake_paniced, 0);
|
|
|
|
atomic_set(&mce_executing, 0);
|
|
|
|
atomic_set(&mce_callin, 0);
|
|
|
|
atomic_set(&global_nwo, 0);
|
|
|
|
}
|
2009-04-08 18:31:25 +08:00
|
|
|
|
2009-07-31 09:41:43 +08:00
|
|
|
static int fake_panic_get(void *data, u64 *val)
|
|
|
|
{
|
|
|
|
*val = fake_panic;
|
|
|
|
return 0;
|
2009-04-08 18:31:25 +08:00
|
|
|
}
|
|
|
|
|
2009-07-31 09:41:43 +08:00
|
|
|
static int fake_panic_set(void *data, u64 val)
|
2009-04-08 18:31:25 +08:00
|
|
|
{
|
2009-07-31 09:41:43 +08:00
|
|
|
mce_reset();
|
|
|
|
fake_panic = val;
|
|
|
|
return 0;
|
2009-04-08 18:31:25 +08:00
|
|
|
}
|
|
|
|
|
2009-07-31 09:41:43 +08:00
|
|
|
DEFINE_SIMPLE_ATTRIBUTE(fake_panic_fops, fake_panic_get,
|
|
|
|
fake_panic_set, "%llu\n");
|
2009-04-29 05:07:25 +08:00
|
|
|
|
2009-10-16 18:31:32 +08:00
|
|
|
static int __init mcheck_debugfs_init(void)
|
2009-04-29 05:07:25 +08:00
|
|
|
{
|
2009-07-31 09:41:43 +08:00
|
|
|
struct dentry *dmce, *ffake_panic;
|
|
|
|
|
|
|
|
dmce = mce_get_debugfs_dir();
|
|
|
|
if (!dmce)
|
|
|
|
return -ENOMEM;
|
|
|
|
ffake_panic = debugfs_create_file("fake_panic", 0444, dmce, NULL,
|
|
|
|
&fake_panic_fops);
|
|
|
|
if (!ffake_panic)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return 0;
|
2009-04-29 05:07:25 +08:00
|
|
|
}
|
2009-10-16 18:31:32 +08:00
|
|
|
late_initcall(mcheck_debugfs_init);
|
2009-07-31 09:41:42 +08:00
|
|
|
#endif
|