x86: memtest: reuse test patterns when memtest parameter exceeds number of available...
authorAndreas Herrmann <andreas.herrmann3@amd.com>
Wed, 25 Feb 2009 10:26:18 +0000 (11:26 +0100)
committerIngo Molnar <mingo@elte.hu>
Wed, 25 Feb 2009 11:19:44 +0000 (12:19 +0100)
Impact: fix unexpected behaviour when pattern number is out of range

Current implementation provides 4 patterns for memtest. The code doesn't
check whether the memtest parameter value exceeds the maximum pattern number.

Instead the memtest code pretends to test with non-existing patterns, e.g.
when booting with memtest=10 I've observed the following

  ...
  early_memtest: pattern num 10
  0000001000 - 0000006000 pattern 0
  ...
  0000001000 - 0000006000 pattern 1
  ...
  0000001000 - 0000006000 pattern 2
  ...
  0000001000 - 0000006000 pattern 3
  ...
  0000001000 - 0000006000 pattern 4
  ...
  0000001000 - 0000006000 pattern 5
  ...
  0000001000 - 0000006000 pattern 6
  ...
  0000001000 - 0000006000 pattern 7
  ...
  0000001000 - 0000006000 pattern 8
  ...
  0000001000 - 0000006000 pattern 9
  ...

But in fact Linux didn't test anything for patterns > 4 as the default
case in memtest() is to leave the function.

I suggest to use the memtest parameter as the number of tests to be
performed and to re-iterate over all existing patterns.

Signed-off-by: Andreas Herrmann <andreas.herrmann3@amd.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
arch/x86/mm/memtest.c

index 9cab18b..00b8bdc 100644 (file)
@@ -9,6 +9,8 @@
 
 #include <asm/e820.h>
 
 
 #include <asm/e820.h>
 
+#define _MAX_MEM_PATTERNS 4
+
 static void __init memtest(unsigned long start_phys, unsigned long size,
                                 unsigned pattern)
 {
 static void __init memtest(unsigned long start_phys, unsigned long size,
                                 unsigned pattern)
 {
@@ -21,6 +23,8 @@ static void __init memtest(unsigned long start_phys, unsigned long size,
        unsigned long count;
        unsigned long incr;
 
        unsigned long count;
        unsigned long incr;
 
+       pattern = pattern % _MAX_MEM_PATTERNS;
+
        switch (pattern) {
        case 0:
                val = 0UL;
        switch (pattern) {
        case 0:
                val = 0UL;
@@ -110,8 +114,9 @@ void __init early_memtest(unsigned long start, unsigned long end)
                                t_size = end - t_start;
 
                        printk(KERN_CONT "\n  %010llx - %010llx pattern %d",
                                t_size = end - t_start;
 
                        printk(KERN_CONT "\n  %010llx - %010llx pattern %d",
-                               (unsigned long long)t_start,
-                               (unsigned long long)t_start + t_size, pattern);
+                              (unsigned long long)t_start,
+                              (unsigned long long)t_start + t_size,
+                              pattern % _MAX_MEM_PATTERNS);
 
                        memtest(t_start, t_size, pattern);
 
 
                        memtest(t_start, t_size, pattern);