Skip to contentSkip to conversation

RAS: Correctable Errors Collector thing

RFC PATCH New Borislav Petkov 1 participant 4 messages Jun 12, 2014

Subsystems (2)
lore
Share & tools
lore

Borislav Petkov

author maintainer
#0 lore raw

cover RAS: Correctable Errors Collector thing

From: Borislav Petkov <[email protected]>

Hi all,

so here's v2 with the feedback from last time addressed (... hopefully). This is ontop of Gong's extlog stuff which is currently a moving target but I've based this stuff on it as we're starting slowly to relocate generic RAS stuff into drivers/ras/.

A couple of points I was thinking about which we should talk about:

* This version automatically removes the oldest element from the array when it gets full. With 512 PFNs max size, I think we should be ok.

* If CEC (let's call this thing that) can perform all RAS actions needed/required, we should not forward correctable errors to userspace because it simply doesn't need to. Unless there is something more we want to do in userspace... we could make it configurable, dunno. This version simply collects the errors and does the soft offlining, thus issuing to dmesg something like this:

[  520.872376] RAS: Soft-offlining pfn: 0xdead
[  520.874384] soft offline: 0xdead page already poisoned

I'm not sure what we want to do with this info - we need to think about it more but we're flexible there so... :-)

My main reasoning behind not forwarding each single correctable error is that we don't want to upset the user unnecessarily and cause those expensive support calls.

* Concerning policy and at which error count we should soft-offline a page and whether we should make it configurable or not and what the interface would be: we still don't know and we probably need to talk about it too. Right now, using 10 bits for that count feels right. The count gets decayed anyway.

But, do we need to run it on lotsa live systems and hear feedback? Definitely.

* As to why we're putting this in the kernel and enabling it by default:
a userspace daemon is much more fragile than doing this in the kernel. And regardless of distro, everyone gets this.

Constructive feedback is, as always, appreciated.

Thanks.

Borislav Petkov (3):
MCE, CE: Corrected errors collecting thing
MCE, CE: Wire in the CE collector
MCE, CE: Add debugging glue

 arch/x86/kernel/cpu/mcheck/mce.c |  87 ++++++++++-
 drivers/ras/Kconfig              |  11 ++
 drivers/ras/Makefile             |   3 +-
 drivers/ras/ce.c                 | 309 +++++++++++++++++++++++++++++++++++++++
 include/linux/ras.h              |   2 +
 5 files changed, 403 insertions(+), 9 deletions(-)
 create mode 100644 drivers/ras/ce.c
Signature · 1 line
2.0.0
author maintainer
#1 lore raw

RFC PATCH 1/3 MCE, CE: Corrected errors collecting thing

From: Borislav Petkov <[email protected]>

A simple data structure for collecting correctable errors.

---
 drivers/ras/Kconfig  |  11 ++
 drivers/ras/Makefile |   3 +-
 drivers/ras/ce.c     | 283 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/ras.h  |   2 +
 4 files changed, 298 insertions(+), 1 deletion(-)
 create mode 100644 drivers/ras/ce.c
drivers/ras/Kconfig +11 -0
index f9da613052c2..c6977b943506 100644
@@ -1,2 +1,13 @@
 config RAS
 	bool
+
+config RAS_CE
+	bool "Correctable Errors Collector"
+	default y if X86_MCE
+	select MEMORY_FAILURE
+	---help---
+	  This is a small cache which collects correctable memory errors per 4K page
+	  PFN and counts their repeated occurrance. Once the counter for a PFN overflows,
+	  we try to soft-offline that page as we take it to mean that it has reached a
+	  relatively high error count and would probably be best if we don't use it
+	  anymore.
drivers/ras/Makefile +2 -1
index d7f73341ced3..7e7f3f9aa948 100644
@@ -1 +1,2 @@
-obj-$(CONFIG_RAS) += ras.o debugfs.o
+obj-$(CONFIG_RAS)	+= ras.o debugfs.o
+obj-$(CONFIG_RAS_CE)	+= ce.o
drivers/ras/ce.c new file +283 -0

283 lines not on this page · raw message

include/linux/ras.h +2 -0
index 2aceeafd6fe5..24e82fb0fe99 100644
@@ -11,4 +11,6 @@ static inline void ras_debugfs_init(void) { return; }
 static inline int ras_add_daemon_trace(void) { return 0; }
 #endif
 
+void __init ce_init(void);
+int ce_add_elem(u64 pfn);
 #endif
Signature · 1 line
2.0.0
author maintainer
#2 lore raw

RFC PATCH 2/3 MCE, CE: Wire in the CE collector

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Add the CE collector to the polling path which collects the correctable errors. Collect only DRAM ECC errors for now.

---
 arch/x86/kernel/cpu/mcheck/mce.c | 64 +++++++++++++++++++++++++++++++++++-----
 1 file changed, 57 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +57 -7
index bb92f38153b2..f908b4cd7448 100644
@@ -36,6 +36,7 @@
 #include <linux/nmi.h>
 #include <linux/cpu.h>
 #include <linux/smp.h>
+#include <linux/ras.h>
 #include <linux/fs.h>
 #include <linux/mm.h>
 #include <linux/debugfs.h>
@@ -577,6 +578,47 @@ static void mce_read_aux(struct mce *m, int i)
 
 DEFINE_PER_CPU(unsigned, mce_poll_count);
 
+static bool dram_ce_error(struct mce *m)
+{
+	struct cpuinfo_x86 *c = &boot_cpu_data;
+
+	if (c->x86_vendor == X86_VENDOR_AMD) {
+		/* ErrCodeExt[20:16] */
+		u8 xec = (m->status >> 16) & 0x1f;
+
+		return (xec == 0x0 || xec == 0x8);
+	} else if (c->x86_vendor == X86_VENDOR_INTEL)
+		/*
+		 * Tony: "You need to look at the low 16 bits of "status"
+		 * (the MCACOD) field and see which is the most significant bit
+		 * set (ignoring bit 12, the "filter" bit).  If the answer is
+		 * bit 7 - then this is a memory error. But you can't just
+		 * blindly check bit 7 because if bit 8 is set, then this is a
+		 * cache error, and if bit 11 is set, then it is a bus/ inter-
+		 * connect error - and either way bit 7 just gives more detail
+		 * on what cache/bus/interconnect error happened."
+		 */
+		return (m->status & 0xef80) == BIT(7);
+	else
+		return false;
+}
+
+static void __log_ce(struct mce *m, enum mcp_flags flags)
+{
+	/*
+	 * Don't get the IP here because it's unlikely to have anything to do
+	 * with the actual error location.
+	 */
+	if ((flags & MCP_DONTLOG) || mca_cfg.dont_log_ce)
+		return;
+
+	if (dram_ce_error(m))
+		ce_add_elem(m->addr >> PAGE_SHIFT);
+	else
+		mce_log(m);
+}
+
+
 /*
  * Poll for corrected events or events that happened before reset.
  * Those are just logged through /dev/mcelog.
@@ -630,12 +672,8 @@ void machine_check_poll(enum mcp_flags flags, mce_banks_t *b)
 
 		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.
-		 */
-		if (!(flags & MCP_DONTLOG) && !mca_cfg.dont_log_ce)
-			mce_log(&m);
+
+		__log_ce(&m, flags);
 
 		/*
 		 * Clear state for this bank.
@@ -2555,5 +2593,17 @@ static int __init mcheck_debugfs_init(void)
 
 	return 0;
 }
-late_initcall(mcheck_debugfs_init);
+#else
+static int __init mcheck_debugfs_init(void) {}
 #endif
+
+static int __init mcheck_late_init(void)
+{
+	if (mcheck_debugfs_init())
+		pr_err("Error creating debugfs nodes!\n");
+
+	ce_init();
+
+	return 0;
+}
+late_initcall(mcheck_late_init);
Signature · 1 line
2.0.0
author maintainer
#3 lore raw

RFC PATCH 3/3 MCE, CE: Add debugging glue

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

For testing purposes only.

---
 arch/x86/kernel/cpu/mcheck/mce.c | 23 ++++++++++++++++++++++-
 drivers/ras/ce.c                 | 28 +++++++++++++++++++++++++++-
 2 files changed, 49 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +22 -1
index f908b4cd7448..fa92c46c0220 100644
@@ -2579,9 +2579,26 @@ static int fake_panic_set(void *data, u64 val)
 DEFINE_SIMPLE_ATTRIBUTE(fake_panic_fops, fake_panic_get,
 			fake_panic_set, "%llu\n");
 
+static u64 cec_pfn;
+
+static int cec_pfn_get(void *data, u64 *val)
+{
+	*val = cec_pfn;
+	return 0;
+}
+
+static int cec_pfn_set(void *data, u64 val)
+{
+	cec_pfn = val;
+
+	return ce_add_elem(val);
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(cec_pfn_ops, cec_pfn_get, cec_pfn_set, "0x%llx\n");
+
 static int __init mcheck_debugfs_init(void)
 {
-	struct dentry *dmce, *ffake_panic;
+	struct dentry *dmce, *ffake_panic, *cec_pfn;
 
 	dmce = mce_get_debugfs_dir();
 	if (!dmce)
@@ -2591,6 +2608,10 @@ static int __init mcheck_debugfs_init(void)
 	if (!ffake_panic)
 		return -ENOMEM;
 
+	cec_pfn = debugfs_create_file("cec_pfn", 0400, dmce, NULL, &cec_pfn_ops);
+	if (!cec_pfn)
+		return -ENOMEM;
+
 	return 0;
 }
 #else
drivers/ras/ce.c +27 -1
index 6b66a587c3ae..4603c0003391 100644
@@ -94,6 +94,25 @@ static struct ce_array {
 
 static DEFINE_MUTEX(ce_mutex);
 
+static void dump_array(struct ce_array *ca)
+{
+	u64 prev = 0;
+	int i;
+
+	pr_info("{ n: %d\n", ca->n);
+	for (i = 0; i < ca->n; i++) {
+		u64 this = PFN(ca->array[i]);
+
+		pr_info(" %03d: [%016llu|%03llx]\n", i, this, FULL_COUNT(ca->array[i]));
+
+		WARN_ON(prev > this);
+
+		prev = this;
+	}
+
+	pr_info("}\n");
+}
+
 /*
  * Decrement decay value. We're using DECAY_BITS bits to denote decay of an
  * element in the array. On insertion and any access, it gets maxed
@@ -180,6 +199,7 @@ static u64 del_lru_elem_unlocked(struct ce_array *ca)
 {
 	unsigned int min = FULL_COUNT_MASK;
 	int i, min_idx = 0;
+	u64 pfn;
 
 	for (i = 0; i < ca->n; i++) {
 		unsigned int this = FULL_COUNT(ca->array[i]);
@@ -189,9 +209,14 @@ static u64 del_lru_elem_unlocked(struct ce_array *ca)
 		}
 	}
 
+	pfn = PFN(ca->array[min_idx]);
+
+	pr_err("%s: Deleting ca[%d]: %016llu|%03x\n",
+		__func__, min_idx, pfn, min);
+
 	__del_elem(ca, min_idx);
 
-	return PFN(ca->array[min_idx]);
+	return pfn;
 }
 
 /*
@@ -266,6 +291,7 @@ int ce_add_elem(u64 pfn)
 	}
 
 unlock:
+	dump_array(ca);
 	mutex_unlock(&ce_mutex);
 
 	return ret;
Signature · 1 line
2.0.0