mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andi Kleen <ak@suse.de>
To: thockin@google.com, ak@suse.de, patches@x86-64.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] [50/58] x86_64: mcelog tolerant level cleanup
Date: Thu, 19 Jul 2007 11:55:37 +0200 (CEST)	[thread overview]
Message-ID: <20070719095537.1295614E06@wotan.suse.de> (raw)
In-Reply-To: <200707191154.642492000@suse.de>


From: Tim Hockin <thockin@google.com>

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: Andi Kleen <ak@suse.de>
Cc: Andi Kleen <ak@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 Documentation/x86_64/boot-options.txt |    8 +-
 Documentation/x86_64/machinecheck     |   14 ++--
 arch/x86_64/kernel/mce.c              |  101 ++++++++++++++++++++++------------
 3 files changed, 80 insertions(+), 43 deletions(-)

Index: linux/Documentation/x86_64/boot-options.txt
===================================================================
--- linux.orig/Documentation/x86_64/boot-options.txt
+++ linux/Documentation/x86_64/boot-options.txt
@@ -14,9 +14,11 @@ Machine check
    mce=nobootlog
 		Disable boot machine check logging.
    mce=tolerancelevel (number)
-		0: always panic, 1: panic if deadlock possible,
-		2: try to avoid panic, 3: never panic or exit (for testing)
-		default is 1
+		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, log corrected errors
+		3: never panic or SIGBUS, log all errors (for testing only)
+		Default is 1
 		Can be also set using sysfs which is preferable.
 
    nomce (for compatibility with i386): same as mce=off
Index: linux/Documentation/x86_64/machinecheck
===================================================================
--- linux.orig/Documentation/x86_64/machinecheck
+++ linux/Documentation/x86_64/machinecheck
@@ -49,12 +49,14 @@ tolerant
 	Since machine check exceptions can happen any time it is sometimes
 	risky for the kernel to kill a process because it defies
 	normal kernel locking rules. The tolerance level configures
-	how hard the kernel tries to recover even at some risk of deadlock.
-
-	0: always panic,
-	1: panic if deadlock possible,
-	2: try to avoid panic,
-   	3: never panic or exit (for testing only)
+	how hard the kernel tries to recover even at some risk of
+	deadlock.  Higher tolerant values trade potentially better uptime
+	with the risk of a crash or even corruption (for tolerant >= 3).
+
+	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, log corrected errors
+	3: never panic or SIGBUS, log all errors (for testing only)
 
 	Default: 1
 
Index: linux/arch/x86_64/kernel/mce.c
===================================================================
--- linux.orig/arch/x86_64/kernel/mce.c
+++ linux/arch/x86_64/kernel/mce.c
@@ -37,8 +37,13 @@ atomic_t mce_entry;
 
 static int mce_dont_init;
 
-/* 0: always panic, 1: panic if deadlock possible, 2: try to avoid panic,
-   3: never panic or exit (for testing only) */
+/*
+ * 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)
+ */
 static int tolerant = 1;
 static int banks;
 static unsigned long bank[NR_BANKS] = { [0 ... NR_BANKS-1] = ~0UL };
@@ -132,9 +137,6 @@ static void mce_panic(char *msg, struct 
 { 
 	int i;
 
-	if (tolerant >= 3)
-		return;
-
 	oops_begin();
 	for (i = 0; i < MCE_LOG_LEN; i++) {
 		unsigned long tsc = mcelog.entry[i].tsc;
@@ -178,11 +180,19 @@ static inline void mce_get_rip(struct mc
 void do_machine_check(struct pt_regs * regs, long error_code)
 {
 	struct mce m, panicm;
-	int nowayout = (tolerant < 1); 
-	int kill_it = 0;
 	u64 mcestart = 0;
 	int i;
 	int panicm_found = 0;
+	/*
+	 * 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;
 
 	atomic_inc(&mce_entry);
 
@@ -194,8 +204,9 @@ void do_machine_check(struct pt_regs * r
 	memset(&m, 0, sizeof(struct mce));
 	m.cpu = smp_processor_id();
 	rdmsrl(MSR_IA32_MCG_STATUS, m.mcgstatus);
+	/* if the restart IP is not valid, we're done for */
 	if (!(m.mcgstatus & MCG_STATUS_RIPV))
-		kill_it = 1;
+		no_way_out = 1;
 	
 	rdtscll(mcestart);
 	barrier();
@@ -214,10 +225,18 @@ void do_machine_check(struct pt_regs * r
 			continue;
 
 		if (m.status & MCI_STATUS_EN) {
-			/* In theory _OVER could be a nowayout too, but
-			   assume any overflowed errors were no fatal. */
-			nowayout |= !!(m.status & MCI_STATUS_PCC);
-			kill_it |= !!(m.status & MCI_STATUS_UC);
+			/* if PCC was set, there's no way out */
+			no_way_out |= !!(m.status & MCI_STATUS_PCC);
+			/*
+			 * If this error was uncorrectable and there was
+			 * an overflow, we're in trouble.  If no overflow,
+			 * we might get away with just killing a task.
+			 */
+			if (m.status & MCI_STATUS_UC) {
+				if (tolerant < 1 || m.status & MCI_STATUS_OVER)
+					no_way_out = 1;
+				kill_it = 1;
+			}
 		}
 
 		if (m.status & MCI_STATUS_MISCV)
@@ -228,7 +247,6 @@ void do_machine_check(struct pt_regs * r
 		mce_get_rip(&m, regs);
 		if (error_code >= 0)
 			rdtscll(m.tsc);
-		wrmsrl(MSR_IA32_MC0_STATUS + i*4, 0);
 		if (error_code != -2)
 			mce_log(&m);
 
@@ -251,37 +269,52 @@ void do_machine_check(struct pt_regs * r
 	   the last one (shouldn't happen, just being safe). */
 	if (!panicm_found)
 		panicm = m;
-	if (nowayout)
+
+	/*
+	 * If we have decided that we just CAN'T continue, and the user
+	 *  has not set tolerant to an insane level, give up and die.
+	 */
+	if (no_way_out && tolerant < 3)
 		mce_panic("Machine check", &panicm, mcestart);
-	if (kill_it) {
+
+	/*
+	 * If the error seems to be unrecoverable, something should be
+	 * done.  Try to kill as little as possible.  If we can kill just
+	 * one task, do that.  If the user has set the tolerance very
+	 * high, don't try to do anything at all.
+	 */
+	if (kill_it && tolerant < 3) {
 		int user_space = 0;
 
-		if (m.mcgstatus & MCG_STATUS_RIPV)
+		/*
+		 * If the EIPV bit is set, it means the saved IP is the
+		 * instruction which caused the MCE.
+		 */
+		if (m.mcgstatus & MCG_STATUS_EIPV)
 			user_space = panicm.rip && (panicm.cs & 3);
-		
-		/* When the machine was in user space and the CPU didn't get
-		   confused it's normally not necessary to panic, unless you 
-		   are paranoid (tolerant == 0)
-
-		   RED-PEN could be more tolerant for MCEs in idle,
-		   but most likely they occur at boot anyways, where
-		   it is best to just halt the machine. */
-		if ((!user_space && (panic_on_oops || tolerant < 2)) ||
-		    (unsigned)current->pid <= 1)
-			mce_panic("Uncorrected machine check", &panicm, mcestart);
-
-		/* do_exit takes an awful lot of locks and has as
-		   slight risk of deadlocking. If you don't want that
-		   don't set tolerant >= 2 */
-		if (tolerant < 3)
+
+		/*
+		 * If we know that the error was in user space, send a
+		 * SIGBUS.  Otherwise, panic if tolerance is low.
+		 *
+		 * do_exit() takes an awful lot of locks and has a slight
+		 * risk of deadlocking.
+		 */
+		if (user_space) {
 			do_exit(SIGBUS);
+		} else if (panic_on_oops || tolerant < 2) {
+			mce_panic("Uncorrected machine check",
+				&panicm, mcestart);
+		}
 	}
 
 	/* notify userspace ASAP */
 	set_thread_flag(TIF_MCE_NOTIFY);
 
  out:
-	/* Last thing done in the machine check exception to clear state. */
+	/* the last thing we do is clear state */
+	for (i = 0; i < banks; i++)
+		wrmsrl(MSR_IA32_MC0_STATUS+4*i, 0);
 	wrmsrl(MSR_IA32_MCG_STATUS, 0);
  out2:
 	atomic_dec(&mce_entry);
@@ -506,7 +539,7 @@ static int mce_open(struct inode *inode,
 
 	spin_unlock(&mce_state_lock);
 
-	return 0;
+	return nonseekable_open(inode, file);
 }
 
 static int mce_release(struct inode *inode, struct file *file)

  parent reply	other threads:[~2007-07-19 10:24 UTC|newest]

Thread overview: 119+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-19  9:54 [PATCH] [0/58] First batch of x86 patches for .23 Andi Kleen
2007-07-19  9:54 ` [PATCH] [1/58] x86: Always flush pages in change_page_attr Andi Kleen
2007-08-06 10:15   ` [patches] " Jan Beulich
2007-08-06 10:36     ` Andi Kleen
2007-08-06 10:49       ` Jan Beulich
2007-07-19  9:54 ` [PATCH] [2/58] x86_64: Tell gcc to only align stack to 8 bytes Andi Kleen
2007-07-19 11:50   ` Serge Belyshev
2007-07-19 12:06     ` Andi Kleen
2007-07-19 14:42   ` Chuck Ebbert
2007-07-19  9:54 ` [PATCH] [3/58] x86_64: asm/ptrace.h needs linux/compiler.h Andi Kleen
2007-07-19  9:54 ` [PATCH] [4/58] x86_64: Don't rely on a unique IO-APIC ID Andi Kleen
2007-07-19  9:54 ` [PATCH] [5/58] x86_64: Report the pending irq if available in smp_affinity Andi Kleen
2007-07-19 10:23   ` Ingo Molnar
2007-07-19  9:54 ` [PATCH] [6/58] x86_64: Use LOCAL_DISTANCE and REMOTE_DISTANCE in x86_64 ACPI code Andi Kleen
2007-07-19  9:54 ` [PATCH] [7/58] x86_64: various cleanups in NUMA scan node Andi Kleen
2007-07-19 17:15   ` Yinghai Lu
2007-07-19 17:21     ` Andi Kleen
2007-07-19 17:38       ` Yinghai Lu
2007-07-19 20:00         ` Andi Kleen
2007-07-19 21:01     ` David Rientjes
2007-07-19  9:54 ` [PATCH] [8/58] x86_64: Use string instruction memcpy/memset on AMD Fam10 Andi Kleen
2007-07-19 16:43   ` Jan Engelhardt
2007-07-19 17:00     ` Yinghai Lu
2007-07-19  9:54 ` [PATCH] [9/58] x86_64: Always use builtin memcpy on gcc 4.3 Andi Kleen
2007-07-21 23:16   ` Oleg Verych
2007-07-21 23:27     ` Andi Kleen
2007-07-22  0:29     ` Denis Vlasenko
2007-07-19  9:54 ` [PATCH] [10/58] i386: Move all simple string operations out of line Andi Kleen
2007-07-19  9:54 ` [PATCH] [11/58] x86: Support __attribute__((__cold__)) in gcc 4.3 Andi Kleen
2007-07-19  9:54 ` [PATCH] [12/58] x86_64: Add vDSO for x86-64 with gettimeofday/clock_gettime/getcpu Andi Kleen
2007-08-21 16:25   ` Daniel Walker
2007-08-21 18:45     ` Andi Kleen
2007-08-21 18:40       ` Andrew Morton
2007-07-19  9:54 ` [PATCH] [13/58] x86: Separate checking of unsynchronized and unstable TSC Andi Kleen
2007-07-19  9:54 ` [PATCH] [14/58] x86_64: Add on_cpu_single Andi Kleen
2007-07-19 11:09   ` Satyam Sharma
2007-07-19 12:07     ` Andi Kleen
2007-07-19  9:54 ` [PATCH] [15/58] i386: Rewrite sched_clock Andi Kleen
2007-07-19 16:51   ` Daniel Walker
2007-07-19 17:13     ` Andi Kleen
2007-07-19 17:15       ` Daniel Walker
2007-07-19 17:22         ` Andi Kleen
2007-07-19 17:31           ` Daniel Walker
2007-07-19 17:38             ` Andi Kleen
2007-07-19 17:43               ` Daniel Walker
2007-07-19 18:00                 ` Andi Kleen
2007-07-19 18:00                   ` Daniel Walker
2007-07-20  3:11     ` Mathieu Desnoyers
2007-07-20  3:47       ` Mathieu Desnoyers
2007-07-20  4:18         ` [PATCH] [15/58] i386: Rewrite sched_clock (cmpxchg8b) Mathieu Desnoyers
2007-07-20  5:07           ` Nick Piggin
2007-07-20  5:47             ` Mathieu Desnoyers
2007-07-20  8:27       ` [PATCH] [15/58] i386: Rewrite sched_clock Andi Kleen
2007-07-20 14:12         ` Mathieu Desnoyers
2007-07-20 14:39           ` Mathieu Desnoyers
2007-07-20 15:14           ` Andi Kleen
2007-07-20 15:22             ` Mathieu Desnoyers
2007-07-20 16:49             ` [PATCH] 80386 and 80486 cmpxchg64 and cmpxchg64_local fallback Mathieu Desnoyers
2007-07-19  9:55 ` [PATCH] [16/58] x86_64: Use new shared sched_clock in x86-64 too Andi Kleen
2007-07-19  9:55 ` [PATCH] [17/58] i386: Add L3 cache support to AMD CPUID4 emulation Andi Kleen
2007-07-20 17:00   ` [patches] " Andreas Herrmann
2007-07-20 17:15   ` Andreas Herrmann
2007-07-19  9:55 ` [PATCH] [18/58] x86_64: remove extra extern declaring about dmi_ioremap Andi Kleen
2007-07-19  9:55 ` [PATCH] [19/58] x86_64: Don't use softirq save locks in smp_call_function Andi Kleen
2007-07-19 12:16   ` Satyam Sharma
2007-07-19 12:19     ` Andi Kleen
2007-07-19  9:55 ` [PATCH] [20/58] x86: Always probe the NMI watchdog Andi Kleen
2007-07-19 10:24   ` Björn Steinbrink
2007-07-19 10:42     ` Andi Kleen
2007-07-19  9:55 ` [PATCH] [21/58] i386: Reserve the right performance counter for the Intel PerfMon " Andi Kleen
2007-07-19 10:21   ` Björn Steinbrink
2007-07-19 10:45     ` Andi Kleen
2007-07-19  9:55 ` [PATCH] [22/58] x86_64: hpet tsc calibration fix broken smi detection logic Andi Kleen
2007-07-19  9:55 ` [PATCH] [23/58] i386: remove pit_interrupt_hook Andi Kleen
2007-07-19  9:55 ` [PATCH] [24/58] x86_64: Untangle asm/hpet.h from asm/timex.h Andi Kleen
2007-07-19  9:55 ` [PATCH] [25/58] x86_64: use generic cmos update Andi Kleen
2007-07-19  9:55 ` [PATCH] [26/58] x86_64: Use generic xtime init Andi Kleen
2007-07-19  9:55 ` [PATCH] [27/58] x86_64: Remove dead code and other janitor work in tsc.c Andi Kleen
2007-07-19  9:55 ` [PATCH] [28/58] x86_64: Fix APIC typo Andi Kleen
2007-07-19  9:55 ` [PATCH] [29/58] x86_64: fiuxp pt_reqs leftovers Andi Kleen
2007-07-19  9:55 ` [PATCH] [30/58] x86: share hpet.h with i386 Andi Kleen
2007-07-19  9:55 ` [PATCH] [31/58] x86_64: apic.c coding style janitor work Andi Kleen
2007-07-19  9:55 ` [PATCH] [32/58] x86_64: time.c white space wreckage cleanup Andi Kleen
2007-07-19  9:55 ` [PATCH] [33/58] x86_64: Avoid too many remote cpu references due to /proc/stat Andi Kleen
2007-07-19 10:21   ` Christoph Hellwig
2007-07-19 10:41     ` Andi Kleen
2007-07-19 10:55       ` Adrian Bunk
2007-07-19  9:55 ` [PATCH] [34/58] x86_64: ia32entry adjustments Andi Kleen
2007-07-19 14:46   ` Jeff Garzik
2007-08-06 10:43     ` Jan Beulich
2007-07-19  9:55 ` [PATCH] [35/58] i386: allow debuggers to access the vsyscall page with compat vDSO Andi Kleen
2007-07-19  9:55 ` [PATCH] [36/58] x86_64: minor exception trace variables cleanup Andi Kleen
2007-07-19  9:55 ` [PATCH] [37/58] x86_64: remove unused variable maxcpus Andi Kleen
2007-07-19  9:55 ` [PATCH] [38/58] i386: smp-alt-once option is only useful with HOTPLUG_CPU Andi Kleen
2007-07-19  9:55 ` [PATCH] [39/58] i386: minor nx handling adjustment Andi Kleen
2007-07-19  9:55 ` [PATCH] [40/58] i386: remapped_pgdat_init() static Andi Kleen
2007-07-19  9:55 ` [PATCH] [41/58] i386: arch/i386/kernel/i8253.c should #include <asm/timer.h> Andi Kleen
2007-07-19  9:55 ` [PATCH] [42/58] i386: timer_irq_works() static again Andi Kleen
2007-07-19  9:55 ` [PATCH] [43/58] x86_64: Quicklist support for x86_64 Andi Kleen
2007-07-19  9:55 ` [PATCH] [44/58] x86_64: extract helper function from e820_register_active_regions Andi Kleen
2007-07-19  9:55 ` [PATCH] [45/58] x86_64: fake pxm-to-node mapping for fake numa Andi Kleen
2007-07-19  9:55 ` [PATCH] [46/58] x86_64: fake apicid_to_node " Andi Kleen
2007-07-19  9:55 ` [PATCH] [47/58] i386: insert unclaimed MMCONFIG resources Andi Kleen
2007-07-19  9:55 ` [PATCH] [48/58] x86_64: O_EXCL on /dev/mcelog Andi Kleen
2007-07-19  9:55 ` [PATCH] [49/58] x86_64: support poll() " Andi Kleen
2007-07-19  9:55 ` Andi Kleen [this message]
2007-07-19  9:55 ` [PATCH] [51/58] i386: fix machine rebooting Andi Kleen
2007-07-19  9:55 ` [PATCH] [52/58] i386: fix section mismatch warnings in mtrr Andi Kleen
2007-07-19  9:55 ` [PATCH] [53/58] x86: PM_TRACE support Andi Kleen
2007-07-19  9:55 ` [PATCH] [54/58] x86: Make Alt-SysRq-p display the debug register contents Andi Kleen
2007-07-19  9:55 ` [PATCH] [55/58] i386: add reference to the arguments Andi Kleen
2007-07-19  9:55 ` [PATCH] [56/58] x86: round_jiffies() for i386 and x86-64 non-critical/corrected MCE polling Andi Kleen
2007-07-19  9:55 ` [PATCH] [57/58] x86_64: check remote IRR bit before migrating level triggered irq Andi Kleen
2007-07-19  9:55 ` [PATCH] [58/58] x86: remove support for the Rise CPU Andi Kleen
2007-07-19 10:45   ` Alan Cox
2007-07-19 10:48     ` Adrian Bunk
2007-07-19 11:13       ` Alan Cox
2007-07-19 12:03         ` Andi Kleen
2007-07-19 14:56           ` Jeff Garzik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070719095537.1295614E06@wotan.suse.de \
    --to=ak@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patches@x86-64.org \
    --cc=thockin@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®