Skip to contentSkip to conversation

support for broken memory modules (BadRAM)

RFC PATCH In review Stefan Assmann 4 participants 13 messages Apr 27, 2011 – Apr 29, 2011

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

cover support for broken memory modules (BadRAM)

This is a RFC for the BadRAM feature originally developed by Rick van Rein. Patches are against vanilla 2.6.38.

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            |  369 +++++++++++++++++++++++++++++++++++
 Documentation/kernel-parameters.txt |    5 +
 include/linux/kernel.h              |    1 +
 lib/cmdline.c                       |   35 ++++
 mm/memory-failure.c                 |   95 +++++++++
 6 files changed, 514 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

RFC PATCH 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 2fe6e84..b6ded39 100644
@@ -218,6 +218,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>
#10 lore raw

RFC PATCH 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            |  369 +++++++++++++++++++++++++++++++++++
 Documentation/kernel-parameters.txt |    5 +
 3 files changed, 383 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/BadRAM.txt
CREDITS +9 -0
index 1d39a6d..22ee8ae 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 +369 -0

369 lines not on this page · raw message

Documentation/kernel-parameters.txt +5 -0
index f4a04c0..84f9ef5 100644
@@ -373,6 +373,11 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 
 	autotest	[IA64]
 
+	badram=		When CONFIG_MEMORY_FAILURE is set, this parameter
+			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

--
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

RFC PATCH 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 |   95 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 95 insertions(+), 0 deletions(-)
mm/memory-failure.c +95 -0
index 0207c2f..dac506c 100644
@@ -52,6 +52,7 @@
 #include <linux/swapops.h>
 #include <linux/hugetlb.h>
 #include <linux/memory_hotplug.h>
+#include <linux/memblock.h>
 #include "internal.h"
 
 int sysctl_memory_failure_early_kill __read_mostly = 0;
@@ -1519,3 +1520,97 @@ int is_hwpoison_address(unsigned long addr)
 	return is_hwpoison_entry(entry);
 }
 EXPORT_SYMBOL_GPL(is_hwpoison_address);
+
+/*
+ * 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;
+
+	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)) {
+			printk(KERN_DEBUG
+			       "BadRAM: page %lu reserved by kernel\n", pfn);
+			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));
+
+	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>
#2 lore raw

Re: [RFC PATCH 1/3] Add string parsing function get_next_ulong

In reply to Stefan Assmann
Quoted 27 lines · On Wed, 27 Apr 2011 18:16:45 +0200 Stefan Assmann wrote:

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 2fe6e84..b6ded39 100644
@@ -218,6 +218,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 +0 -0
index f5f3ad8..82a6616 100644

lib/cmdline.c char *get_options(const char *str, int nints, int *ints) · line 118

Quoted 5 lines
lib/cmdline.c +2 -0
@@ -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

^ input/output

lib/cmdline.c char *get_options(const char *str, int nints, int *ints) · line 126

Quoted 8 lines
lib/cmdline.c +8 -0
+ *	@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

@val @strp

lib/cmdline.c char *get_options(const char *str, int nints, int *ints) · line 129

Quoted 3 lines
lib/cmdline.c +3 -0
+ *	will point to the character *after* the parsed unsigned long.
+ *
+ *	In the error case 0 is returned, val and *strp stay unaltered.

@val and @strp

Quoted 16 lines
lib/cmdline.c +15 -0
+ *	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);
+

lib/cmdline.c char *get_options(const char *str, int nints, int *ints) · line 154

Quoted 10 lines
lib/cmdline.c +7 -0
+	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

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

--
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>

#11 lore raw

Re: [RFC PATCH 3/3] Add documentation and credits for BadRAM

In reply to Stefan Assmann
Quoted 17 lines · On Wed, 27 Apr 2011 18:16:47 +0200 Stefan Assmann wrote:

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

---
 CREDITS                             |    9 +
 Documentation/BadRAM.txt            |  369 +++++++++++++++++++++++++++++++++++
 Documentation/kernel-parameters.txt |    5 +
 3 files changed, 383 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/BadRAM.txt
Documentation/BadRAM.txt new file +0 -0
new file mode 100644
index 0000000..67a7ccc

Documentation/BadRAM.txt line 33

Quoted 5 lines
Documentation/BadRAM.txt new file +4 -0
@@ -0,0 +1,369 @@
 
+Reasons for using BadRAM
+------------------------
+
+Chip manufacturing process use lots of harsh chemicals, and the less

processes

Quoted 5 lines
Documentation/BadRAM.txt new file +5 -0
+of these used, the better.  Being able to make good use of partially
+failed memory chips means that far less of those chemicals are needed
+to provide storage.  This reduces expenses and it is lighter on the
+environment in which we live.
+

...

Quoted 5 lines
Documentation/BadRAM.txt new file +5 -0
+
+
+Running example
+---------------
+

...

Documentation/BadRAM.txt line 67

Quoted 3 lines
Documentation/BadRAM.txt new file +3 -0
+
+After being patched and invoked with the properly formatted description,
+the kernel held back only the memory pages with faults, and never haded

handed

Quoted 28 lines
Documentation/BadRAM.txt new file +27 -0
+them out for allocation. The allocation routines could therefore
+progress as normally, without any adaption.  This is important, since
+all the work is done at booting time.  After booting, the kernel does
+not have to do spend any time to implement BadRAM.
+
+As a result of this initial exercise, I gained 30 MB out of the 32 MB
+DIMM that would otherwise have been thrown away.  Of course, these
+numbers scale up with larger memory modules, but the principle is
+the same.
+
+
 
+BadRAM's notation for memory faults
+-----------------------------------
+
+Instead of manually providing all 512 errors in the running example
+to the kernel, it's easier to use a pattern notation. Since the
+regularity is based on address decoding software, which generally
+takes certain bits into account and ignores others, we shall
+provide a faulty address F, together with a bit mask M that
+specifies which bits must be equal to F. In C code, an address A
+is faulty if and only if
+
+	(F & M) == (A & M)
+
+or alternately (closer to a hardware implementation):
+
+	~((F ^ A) & M)

Documentation/BadRAM.txt line 129

Quoted 10 lines
Documentation/BadRAM.txt new file +10 -0
+
+In the example 32 MB chip, I had the faulty addresses in 8MB-16MB:
+
+	xxx42f4         ....0100....
+	xxx62f4         ....0110....
+	xxxc2f4         ....1100....
+	xxxe2f4         ....1110....
+
+The second column represents the alternating hex digit in binary form.
+Apperantly, the first and next to last binary digit can be anything,

Apparently,

Quoted 11 lines
Documentation/BadRAM.txt new file +11 -0
+so the binary mask for that part is 0101. The mask for the part after
+this is 0xfff, and the part before should select anything in the range
+8MB-16MB, or 0x00800000-0x01000000; this is done with a bitmask
+0xff80xxxx. Combining these partial masks, we get:
+
+	F=0x008042f4    M=0xff805fff
+
+That covers every fault in this DIMM; for more complicated failing
+DIMMs, or for a combination of multiple failing DIMMs, it can be
+necessary to set up a number of such F/M pairs.
+

Documentation/BadRAM.txt line 166

Quoted 10 lines
Documentation/BadRAM.txt new file +10 -0
+
+Running a memory checker
+------------------------
+
+There is no memory checker built into the kernel, to avoid delays
+at runtime or while booting. If you experience problems that may
+be caused by RAM, run a good outside RAM checker.  The Memtest86
+checker is a popular, free, high-quality checker.  Many Linux
+distributions include it as an alternate boot option, so you may
+simply find it in your GRUB boot menu.

boot loader's boot menu.

Quoted 17 lines
Documentation/BadRAM.txt new file +17 -0
+
+The memory checker lists all addresses that have a fault.  It will
+do this for a given configuration of the DIMMs in your motherboard;
+if you replace or move memory modules you may find other addresses.
+In the running example's 32 MB chip, with the DIMM in slot #0 on
+the motherboard, the errors were found in the 8MB-16MB range:
+
+	xxx42f4
+	xxx62f4
+	xxxc2f4
+	xxxe2f4
+
+The error reported was a "sticky 1 bit", a memory bit that always
+reads as "1" even if a "0" was just written to it.  This is
+probably caused by a damaged buffer on one of the rows or columns
+in one of the memory chips.
+

...

Quoted 12 lines
Documentation/BadRAM.txt new file +12 -0
+
+Rebooting Linux
+---------------
+
+Once the fault patterns are known we simply restart Linux with
+these F/M pairs as a parameter If your normal boot options look
+like
+
+       root=/dev/sda1 ro
+
+you should now boot with options
+

Documentation/BadRAM.txt line 229

Quoted 10 lines
Documentation/BadRAM.txt new file +10 -0
+       root=/dev/sda1 ro badram=0x008042f4,0xff805fff
+
+or perhaps by mentioning more F/M pairs in an order F0,M0,F1,M1,...
+When you provide an odd number of arguments to badram, the default
+mask 0xffffffff (meaning that only one address is matched) is
+applied to the last address.
+
+If your bootloader is GRUB, you can supply this additional
+parameter interactively during boot.  This way, you can try them
+before you edit /boot/grub/menu.lst to put them in forever.

I thought that /boot/grub/grub.conf was the current file name. (?)

Quoted 16 lines
Documentation/BadRAM.txt new file +16 -0
+
+When the kernel now boots, it should not give any trouble with RAM.
+Mind you, this is under the assumption that the kernel and its data
+storage do not overlap an erroneous part. If they do, and the
+kernel does not choke on it right away, BadRAM itself will stop the
+system with a kernel panic.  When the error is that low in memory,
+you will need additional bootloader magic, to load the kernel at an
+alternative address.
+
+Now look up your memory status with
+
+	cat /proc/meminfo |grep HardwareCorrupted
+
+which prints a single line with information like
+
+HardwareCorrupted:  2048 kB

Documentation/BadRAM.txt line 255

Quoted 10 lines
Documentation/BadRAM.txt new file +10 -0
+
+The entry HardwareCorrupted: 2048k represents the loss of 2MB
+of general purpose RAM due to the errors. Or, positively rephrased,
+instead of throwing out 32MB as useless, you only throw out 2MB.
+Note that 2048 kB equals 512 pages of 4kB.  The size of a page is
+defined by the processor architecture.
+
+If the system is stable (which you can test by compiling a few
+kernels, and a few file finds in / or so) you can decide to add
+the boot parameter to /boot/grub/menu.lst, in addition to any

file name?

Quoted 14 lines
Documentation/BadRAM.txt new file +14 -0
+other boot parameters that may already be there.  For example,
+
+	kernel /boot/vmlinuz root=/dev/sda1 ro
+
+would become
+
+	kernel /boot/vmlinuz root=/dev/sda1 ro badram=0x008042f4,0xff805fff
+
+Depending on how helpful your Linux distribution is, you may
+have to add this feature again after upgrading your kernel.  If
+your boot loader is GRUB, you can always do this manually if you
+rebooted before you remembered to make that adaption.
+
+

...

Documentation/kernel-parameters.txt bytes respectively. Such letter suffixes can also be entirely omitted. · line 377

Quoted 10 lines
Documentation/kernel-parameters.txt +2 -0
index f4a04c0..84f9ef5 100644
@@ -373,6 +373,11 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 
 	autotest	[IA64]
 
+	badram=		When CONFIG_MEMORY_FAILURE is set, this parameter
+			allows memory areas to be flagged as hwpoison.

hwpoison?? undefined.

Documentation/kernel-parameters.txt bytes respectively. Such letter suffixes can also be entirely omitted. · line 380

Quoted 3 lines
Documentation/kernel-parameters.txt +3 -0
+			Format: <addr>,<mask>[,...]
+			See Documentation/BadRAM.txt
+

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

--
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>

#12 lore raw

Re: [RFC PATCH 3/3] Add documentation and credits for BadRAM

Quoted 13 lines · Randy Dunlap
Quoted 10 lines · On Wed, 27 Apr 2011 18:16:47 +0200 Stefan Assmann wrote:

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

---
 CREDITS                             |    9 +
 Documentation/BadRAM.txt            |  369 +++++++++++++++++++++++++++++++++++
 Documentation/kernel-parameters.txt |    5 +
 3 files changed, 383 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/BadRAM.txt
Quoted 7 lines

Documentation/BadRAM.txt

Quoted 6 lines
Documentation/BadRAM.txt new file +0 -0
new file mode 100644
index 0000000..67a7ccc
@@ -0,0 +1,369 @@

[snip]

Spelling errors will be fixed in next version. Thanks!

Quoted 1 line

I thought that /boot/grub/grub.conf was the current file name. (?)

Not sure about that, some distros use menu.lst others grub.conf for GRUB. Also GRUB 2 uses /boot/grub/grub.cfg. Either of these would be fine with me, /boot/grub/menu.lst sometimes is a symlink to /boot/grub/grub.conf and I felt it's the most convenient one, but I have no strong preference here.

Quoted 21 lines
Quoted 21 lines
Documentation/BadRAM.txt new file +20 -0
+
+When the kernel now boots, it should not give any trouble with RAM.
+Mind you, this is under the assumption that the kernel and its data
+storage do not overlap an erroneous part. If they do, and the
+kernel does not choke on it right away, BadRAM itself will stop the
+system with a kernel panic.  When the error is that low in memory,
+you will need additional bootloader magic, to load the kernel at an
+alternative address.
+
+Now look up your memory status with
+
+	cat /proc/meminfo |grep HardwareCorrupted
+
+which prints a single line with information like
+
+HardwareCorrupted:  2048 kB
+
+The entry HardwareCorrupted: 2048k represents the loss of 2MB
+of general purpose RAM due to the errors. Or, positively rephrased,
+instead of throwing out 32MB as useless, you only throw out 2MB.
Quoted 8 lines

Documentation/BadRAM.txt line 255

Quoted 6 lines
Documentation/BadRAM.txt new file +6 -0
+Note that 2048 kB equals 512 pages of 4kB.  The size of a page is
+defined by the processor architecture.
+
+If the system is stable (which you can test by compiling a few
+kernels, and a few file finds in / or so) you can decide to add
+the boot parameter to /boot/grub/menu.lst, in addition to any

file name?

See above comment.

Quoted 24 lines
Quoted 15 lines
Documentation/BadRAM.txt new file +14 -0
+other boot parameters that may already be there.  For example,
+
+	kernel /boot/vmlinuz root=/dev/sda1 ro
+
+would become
+
+	kernel /boot/vmlinuz root=/dev/sda1 ro badram=0x008042f4,0xff805fff
+
+Depending on how helpful your Linux distribution is, you may
+have to add this feature again after upgrading your kernel.  If
+your boot loader is GRUB, you can always do this manually if you
+rebooted before you remembered to make that adaption.
+
+

...

Quoted 6 lines
Documentation/kernel-parameters.txt +0 -0
index f4a04c0..84f9ef5 100644
@@ -373,6 +373,11 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 
Quoted 6 lines

Documentation/kernel-parameters.txt bytes respectively. Such letter suffixes can also be entirely omitted. · line 377

Quoted 4 lines
Documentation/kernel-parameters.txt +2 -0
 	autotest	[IA64]
 
+	badram=		When CONFIG_MEMORY_FAILURE is set, this parameter
+			allows memory areas to be flagged as hwpoison.

hwpoison?? undefined.

BadRAM depends on hwpoison to be available. The code is located in mm/memory-failure.c. That file is only compiled if CONFIG_MEMORY_FAILURE is defined.
grep CONFIG_MEMORY_FAILURE mm/Makefile obj-$(CONFIG_MEMORY_FAILURE) += memory-failure.o

So for your question, if hwpoison is not available BadRAM also won't be available.

Quoted 9 lines

Documentation/kernel-parameters.txt bytes respectively. Such letter suffixes can also be entirely omitted. · line 380

Quoted 4 lines
Documentation/kernel-parameters.txt +3 -0
+			Format: <addr>,<mask>[,...]
+			See Documentation/BadRAM.txt
+

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

Thanks for the review Randy!

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>

#4 lore raw
In reply to Stefan Assmann
Quoted 5 lines · 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.

Quoted 8 lines

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.

Looks good to me, except for the too verbose printks. Logging every page this way will be very noisy for larger areas.

The mask will also only work for very simple memory interleaving setups, so I suspect it won't work for a lot of modern systems unless you go more fancy.

Longer term there should be also likely a better way to specify these pages than the kernel command line, e.g. the new persistent store on some systems.

-Andi

--
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 12 lines · Andi Kleen
Quoted 11 lines · 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"

Quoted 5 lines
Quoted 2 lines

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

Looks good to me, except for the too verbose printks. Logging every page this way will be very noisy for larger areas.

You're right, logging every page marked would be too verbose. That's why I wrapped that logging into pr_debug.
http://www.kernel.org/doc/local/pr_debug.txt
This way it shouldn't bother anybody but it still could be useful in the case of debugging.
However I kept the printk in the case of early allocated pages. The user should be notified of the attempt to mark a page that's already been allocated by the kernel itself.

Quoted 8 lines

The mask will also only work for very simple memory interleaving setups, so I suspect it won't work for a lot of modern systems unless you go more fancy.

Longer term there should be also likely a better way to specify these pages than the kernel command line, e.g. the new persistent store on some systems.

I'd be happy to help improving and refining things for more fancy scenarios after this is done.

Thanks for the feedback Andi.

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>

#6 lore raw
Quoted 2 lines

You're right, logging every page marked would be too verbose. That's why I wrapped that logging into pr_debug.

pr_debug still floods the kernel log buffer. On large systems it often already overflows.

Quoted 3 lines

However I kept the printk in the case of early allocated pages. The user should be notified of the attempt to mark a page that's already been allocated by the kernel itself.

That's ok, although if you're unlucky (e.g. hit a large mem_map area) it can be also very nosiy.

It would be better if you fixed the printks to output ranges.

-Andi

--
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>

#7 lore raw
Quoted 5 lines · Andi Kleen
Quoted 2 lines

You're right, logging every page marked would be too verbose. That's why I wrapped that logging into pr_debug.

pr_debug still floods the kernel log buffer. On large systems it often already overflows.

That's a pain then, I understand.

Quoted 9 lines
Quoted 4 lines

However I kept the printk in the case of early allocated pages. The user should be notified of the attempt to mark a page that's already been allocated by the kernel itself.

That's ok, although if you're unlucky (e.g. hit a large mem_map area) it can be also very nosiy.

It would be better if you fixed the printks to output ranges.

BadRAM patterns might often mark non-consecutive pages so outputting ranges could be more verbose than what we have now. I'll try to think of something to minimize log output.

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>

#8 lore raw
Quoted 3 lines

BadRAM patterns might often mark non-consecutive pages so outputting ranges could be more verbose than what we have now. I'll try to think of something to minimize log output.

How about printing the pattern together with a count of pages affected:

badram: addr=foo mask=bar (1024 pages = 4MB marked unusable)

-Tony

--
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>

#9 lore raw
In reply to Stefan Assmann
Quoted 8 lines · Stefan Assmann
Quoted 5 lines · Andi Kleen
Quoted 2 lines

You're right, logging every page marked would be too verbose. That's why I wrapped that logging into pr_debug.

pr_debug still floods the kernel log buffer. On large systems it often already overflows.

That's a pain then, I understand.

I took a closer look at pr_debug and it seems that pr_debug gets evaluated to a conditional branch and thus does not flood the log buffer if not explicitly enabled. I confirmed that by dumping the log buffer. So in the normal use-case things should be fine and if pr_debug really is enabled it dumps a lot of data, which I hope is acceptable for debugging purposes.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

However I kept the printk in the case of early allocated pages. The user should be notified of the attempt to mark a page that's already been allocated by the kernel itself.

Quoted 8 lines
Quoted 4 lines

That's ok, although if you're unlucky (e.g. hit a large mem_map area) it can be also very nosiy.

It would be better if you fixed the printks to output ranges.

BadRAM patterns might often mark non-consecutive pages so outputting ranges could be more verbose than what we have now. I'll try to think of something to minimize log output.

How about the following:
static int __init badram_mark_pages(unsigned long addr, unsigned long mask)

{
	unsigned long pagecount = 0, is_reserved = 0;
[...]
	printk(KERN_INFO "BadRAM: mark 0x%lx with mask 0x%0lx\n", addr, mask);

	do {
[...]
		if (memblock_is_reserved(addr)) {
			pr_debug("BadRAM: page %lu reserved by kernel\n", pfn);
			is_reserved++;
			continue;
		}
[...]
		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;
}

This way everything with possibly high volume log output is guarded by pr_debug and only the summary gets printed by default. No log_buf cluttering but also a bit harder to debug for somebody who's interested in finding out which pages are already reserved.

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>