Skip to contentSkip to conversation

support for broken memory modules (BadRAM)

PATCH Superseded Stefan Assmann 2 participants 6 messages Jun 21, 2011 – Jun 22, 2011

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover support for broken memory modules (BadRAM)

Following the RFC for the BadRAM feature here's the updated version with spelling fixes, thanks go to Randy Dunlap. Also the code is now less verbose, as requested by Andi Kleen.
v2 with even more spelling fixes suggested by Randy.
Patches are against vanilla 2.6.39.

The idea is to allow the user to specify RAM addresses that shouldn't be touched by the OS, because they are broken in some way. Not all machines have hardware support for hwpoison, ECC RAM, etc, so here's a solution that allows to use bitmasks to mask address patterns with the new "badram" kernel command line parameter.
Memtest86 has an option to generate these patterns since v2.3 so the only thing for the user to do should be:
- run Memtest86
- note down the pattern
- add badram=<pattern> to the kernel command line

The concerning pages are then marked with the hwpoison flag and thus won't be used by the memory managment system.

Link to Ricks original patches and docs:
http://rick.vanrein.org/linux/badram/

Stefan

Stefan Assmann (3):
Add string parsing function get_next_ulong
support for broken memory modules (BadRAM)
Add documentation and credits for BadRAM

 CREDITS                             |    9 +
 Documentation/BadRAM.txt            |  370 +++++++++++++++++++++++++++++++++++
 Documentation/kernel-parameters.txt |    6 +
 include/linux/kernel.h              |    1 +
 lib/cmdline.c                       |   35 ++++
 mm/memory-failure.c                 |  100 ++++++++++
 6 files changed, 521 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/BadRAM.txt
Signature · 8 lines
1.7.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

PATCH v2 1/3 Add string parsing function get_next_ulong

Adding this function to allow easy parsing of unsigned long values from the beginning of strings. Convenience function to parse pointers from the kernel command line.

---
 include/linux/kernel.h |    1 +
 lib/cmdline.c          |   35 +++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 0 deletions(-)
include/linux/kernel.h +1 -0
index 00cec4d..98c1916 100644
@@ -280,6 +280,7 @@ extern int vsscanf(const char *, const char *, va_list)
 
 extern int get_option(char **str, int *pint);
 extern char *get_options(const char *str, int nints, int *ints);
+extern int get_next_ulong(char **str, unsigned long *val, char sep, int base);
 extern unsigned long long memparse(const char *ptr, char **retptr);
 
 extern int core_kernel_text(unsigned long addr);
lib/cmdline.c +35 -0
index f5f3ad8..82a6616 100644
@@ -114,6 +114,41 @@ char *get_options(const char *str, int nints, int *ints)
 }
 
 /**
+ *	get_next_ulong - Parse unsigned long at the beginning of a string
+ *	@strp: (output) String to be parsed
+ *	@val: (output) unsigned long carrying the result
+ *	@sep: character specifying the separator
+ *	@base: number system of the parsed value
+ *
+ *	This function parses an unsigned long value at the beginning of a
+ *	string. The string may begin with a separator or an unsigned long
+ *	value.
+ *	After the function is run val will contain the parsed value and strp
+ *	will point to the character *after* the parsed unsigned long.
+ *
+ *	In the error case 0 is returned, val and *strp stay unaltered.
+ *	Otherwise return 1.
+ */
+int get_next_ulong(char **strp, unsigned long *val, char sep, int base)
+{
+	char *tmp;
+
+	if (!strp || !(*strp))
+		return 0;
+
+	tmp = *strp;
+	if (*tmp == sep)
+		tmp++;
+
+	*val = simple_strtoul(tmp, strp, base);
+
+	if (tmp == *strp)
+		return 0; /* no new value parsed */
+	else
+		return 1;
+}
+
+/**
  *	memparse - parse a string with mem suffixes into a number
  *	@ptr: Where parse begins
  *	@retptr: (output) Optional pointer to next char after parse completes
Signature · 8 lines
1.7.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw

PATCH v2 3/3 Add documentation and credits for BadRAM

In reply to Stefan Assmann

Add Documentation/BadRAM.txt for in-depth information and update Documentation/kernel-parameters.txt.

---
 CREDITS                             |    9 +
 Documentation/BadRAM.txt            |  370 +++++++++++++++++++++++++++++++++++
 Documentation/kernel-parameters.txt |    6 +
 3 files changed, 385 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/BadRAM.txt
CREDITS +9 -0
index dca6abc..d57d4af 100644
@@ -2899,6 +2899,15 @@ S: 6 Karen Drive
 S: Malvern, Pennsylvania 19355
 S: USA
 
+N: Rick van Rein
+E: [email protected]
+W: http://rick.vanrein.org/
+D: Memory, the BadRAM subsystem dealing with defective RAM modules.
+S: Haarlebrink 5
+S: 7544 WP  Enschede
+S: The Netherlands
+P: 1024D/89754606  CD46 B5F2 E876 A5EE 9A85  1735 1411 A9C2 8975 4606
+
 N: Stefan Reinauer
 E: [email protected]
 W: http://www.freiburg.linux.de/~stepan/
Documentation/BadRAM.txt new file +370 -0

370 lines not on this page · raw message

Documentation/kernel-parameters.txt +6 -0
index cc85a92..a12b27a 100644
@@ -51,6 +51,7 @@ parameter is applicable:
 	FB	The frame buffer device is enabled.
 	GCOV	GCOV profiling is enabled.
 	HW	Appropriate hardware is enabled.
+	HWPOISON HWPOISON support is enabled.
 	IA-64	IA-64 architecture is enabled.
 	IMA     Integrity measurement architecture is enabled.
 	IOSCHED	More than one I/O scheduler is enabled.
@@ -373,6 +374,11 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 
 	autotest	[IA64]
 
+	badram=		[HWPOISON]
+			Allows memory areas to be flagged as HWPOISON.
+			Format: <addr>,<mask>[,...]
+			See Documentation/BadRAM.txt
+
 	baycom_epp=	[HW,AX25]
 			Format: <io>,<mode>
 
Signature · 8 lines
1.7.4.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw

PATCH v2 2/3 support for broken memory modules (BadRAM)

In reply to Stefan Assmann

BadRAM is a mechanism to exclude memory addresses (pages) from being used by the system. The addresses are given to the kernel via kernel command line. This is useful for systems with defective RAM modules, especially if the RAM modules cannot be replaced.

command line parameter: badram=<addr>,<mask>[,...]

Patterns for the command line parameter can be obtained by running Memtest86. In Memtest86 press "c" for configuration, select "Error Report Mode" and finally "BadRAM Patterns"

This has already been done by Rick van Rein a long time ago but it never found it's way into the kernel.

---
 mm/memory-failure.c |  100 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 100 insertions(+), 0 deletions(-)
mm/memory-failure.c +100 -0
index 2b9a5ee..97c7f7c 100644
@@ -52,6 +52,8 @@
 #include <linux/swapops.h>
 #include <linux/hugetlb.h>
 #include <linux/memory_hotplug.h>
+#include <linux/memblock.h>
+#include <linux/bootmem.h>
 #include "internal.h"
 
 int sysctl_memory_failure_early_kill __read_mostly = 0;
@@ -1487,3 +1489,101 @@ done:
 	/* keep elevated page count for bad page */
 	return ret;
 }
+
+/*
+ * Return 0 if no address found else return 1, new address is stored in addrp.
+ **/
+static int __init next_masked_address(unsigned long *addrp, unsigned long mask)
+{
+	unsigned long total_mem = (max_pfn + 1) << PAGE_SHIFT;
+	unsigned long tmp_addr = *addrp;
+	unsigned long inc = 1;
+
+	while (inc & mask)
+		inc = inc << 1;
+
+	while (inc != 0) {
+		tmp_addr += inc;
+		tmp_addr &= ~mask;
+		tmp_addr |= ((*addrp) & mask);
+
+		/* address is bigger than phys memory */
+		if (tmp_addr >= total_mem)
+			return 0;
+
+		/* address found */
+		if (tmp_addr > *addrp) {
+			*addrp = tmp_addr;
+			return 1;
+		}
+
+		while (inc & ~mask)
+			inc = inc << 1;
+		inc = inc << 1;
+	}
+
+	return 0;
+}
+
+/*
+ * Set hwpoison pageflag on all pages specified by addr/mask.
+ */
+static int __init badram_mark_pages(unsigned long addr, unsigned long mask)
+{
+	unsigned long pagecount = 0, is_reserved = 0;
+
+	mask |= ~PAGE_MASK; /* smallest chunk is a page */
+	addr &= mask;
+
+	printk(KERN_INFO "BadRAM: mark 0x%lx with mask 0x%0lx\n", addr, mask);
+
+	do {
+		unsigned long pfn = addr >> PAGE_SHIFT;
+		struct page *page = pfn_to_page(pfn);
+
+		if (!pfn_valid(pfn))
+			continue;
+		if (memblock_is_reserved(addr)) {
+			pr_debug("BadRAM: page %lu reserved by kernel\n", pfn);
+			is_reserved++;
+			continue;
+		}
+
+		SetPageHWPoison(page);
+		atomic_long_add(1, &mce_bad_pages);
+		pagecount++;
+		pr_debug("BadRAM: page %lu (addr 0x%0lx) marked bad "
+			 "[total %lu]\n", pfn, addr, pagecount);
+	} while (next_masked_address(&addr, mask));
+
+	if (is_reserved)
+		printk(KERN_WARNING "BadRAM: %lu page(s) already reserved and "
+		       "could not be marked bad\n", is_reserved);
+
+	return pagecount;
+}
+
+static int __init badram_setup(char *str)
+{
+	printk(KERN_DEBUG "BadRAM: cmdline option is %s\n", str);
+
+	if (*str++ != '=')
+		return 0;
+
+	while (*str) {
+		unsigned long addr = 0, mask = 0, pagecount = 0;
+
+		if (!get_next_ulong(&str, &addr, ',', 16)) {
+			printk(KERN_WARNING "BadRAM: parsing error\n");
+			return 0;
+		}
+		if (!get_next_ulong(&str, &mask, ',', 16))
+			mask = ~(0UL);
+
+		pagecount = badram_mark_pages(addr, mask);
+		printk(KERN_INFO "BadRAM: %lu page(s) bad\n", pagecount);
+	}
+
+	return 0;
+}
+__setup("badram", badram_setup);
Signature · 8 lines
1.7.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#4 lore raw
In reply to Stefan Assmann
Quoted 2 lines · On Tue, 21 Jun 2011 11:23:15 +0200 Stefan Assmann <[email protected]> wrote:

Following the RFC for the BadRAM feature here's the updated version with spelling fixes, thanks go to Randy Dunlap.

I have some thoughts but I think that linux-mm is too narrow an audience for a patchset of this scope.

Please resend the patchset cc'ing linux-kernel so that others can see what we're talking about.

Thanks.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw
Quoted 11 lines · Andrew Morton
Quoted 2 lines · On Tue, 21 Jun 2011 11:23:15 +0200 Stefan Assmann <[email protected]> wrote:

Following the RFC for the BadRAM feature here's the updated version with spelling fixes, thanks go to Randy Dunlap.

I have some thoughts but I think that linux-mm is too narrow an audience for a patchset of this scope.

Please resend the patchset cc'ing linux-kernel so that others can see what we're talking about.

Sure, I'm looking forward to your feedback. Patches are going to be reposted with LKML in Cc soon.
Thanks!

Stefan

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>