x86: memtest update
Subsystems (3)
cover x86: memtest update
Hi,
Following patches contain minor fixes and changes of memtest code. Please apply.
Thanks,
Andreas
PATCH 1/7 x86: memtest: reuse test patterns when memtest parameter exceeds number of available patterns
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.
--- arch/x86/mm/memtest.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
arch/x86/mm/memtest.c +7 -2
@@ -9,6 +9,8 @@#include <asm/e820.h> +#define _MAX_MEM_PATTERNS 4 +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; + pattern = pattern % _MAX_MEM_PATTERNS; +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" , - (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);
Signature · 1 line
1.6.1.2
PATCH 2/7 x86: memtest: introduce array to store memtest patterns
In reply to Andreas HerrmannImpact: code cleanup
--- arch/x86/mm/memtest.c | 61 ++++++++++++++++++------------------------------ 1 files changed, 23 insertions(+), 38 deletions(-)
arch/x86/mm/memtest.c +23 -38
@@ -9,47 +9,29 @@#include <asm/e820.h> -#define _MAX_MEM_PATTERNS 4 +static unsigned long patterns[] = { +0UL , +-1UL , +#ifdef CONFIG_X86_64 +0x5555555555555555UL , +0xaaaaaaaaaaaaaaaaUL , +#else +0x55555555UL , +0xaaaaaaaaUL , +#endif +};static void __init memtest (unsigned long start_phys,unsigned long size, -unsigned pattern) +unsigned long pattern) {unsigned long i;unsigned long *start;unsigned long start_bad;unsigned long last_bad; -unsigned long val;unsigned long start_phys_aligned;unsigned long count;unsigned long incr; - pattern = pattern % _MAX_MEM_PATTERNS; - -switch (pattern) { -case 0 : - val =0UL ; -break ; -case 1 : - val =-1UL ; -break ; -case 2 : -#ifdef CONFIG_X86_64 - val =0x5555555555555555UL ; -#else - val =0x55555555UL ; -#endif -break ; -case 3 : -#ifdef CONFIG_X86_64 - val =0xaaaaaaaaaaaaaaaaUL ; -#else - val =0xaaaaaaaaUL ; -#endif -break ; -default : -return ; - } - incr =sizeof (unsigned long ); start_phys_aligned =ALIGN (start_phys, incr); count = (size - (start_phys_aligned - start_phys))/incr;
@@ -58,15 +40,16 @@ static void __init memtest(unsigned long start_phys, unsigned long size, last_bad =0 ;for (i =0 ; i < count; i++) - start[i] = val; + start[i] = pattern;for (i =0 ; i < count; i++, start++, start_phys_aligned += incr) { -if (*start != val) { +if (*start != pattern) {if (start_phys_aligned == last_bad + incr) { last_bad += incr; }else {if (start_bad) {printk (KERN_CONT "\n %016lx bad mem addr %010lx - %010lx reserved" , - val, start_bad, last_bad + incr); + pattern, start_bad, + last_bad + incr);reserve_early (start_bad, last_bad + incr,"BAD RAM" ); } start_bad = last_bad = start_phys_aligned;
@@ -75,7 +58,7 @@ static void __init memtest(unsigned long start_phys, unsigned long size, }if (start_bad) {printk (KERN_CONT "\n %016lx bad mem addr %010lx - %010lx reserved" , - val, start_bad, last_bad + incr); + pattern, start_bad, last_bad + incr);reserve_early (start_bad, last_bad + incr,"BAD RAM" ); } }
@@ -95,13 +78,16 @@ early_param("memtest", parse_memtest);void __init early_memtest (unsigned long start,unsigned long end) {u64 t_start, t_size; -unsigned pattern; +unsigned int i; +unsigned long pattern;if (!memtest_pattern)return ;printk (KERN_INFO "early_memtest: pattern num %d" , memtest_pattern); -for (pattern =0 ; pattern < memtest_pattern; pattern++) { +for (i =0 ; i < memtest_pattern; i++) { +unsigned int idx = i %ARRAY_SIZE (patterns); + pattern = patterns[idx]; t_start = start; t_size =0 ;while (t_start < end) {
@@ -115,8 +101,7 @@ void __init early_memtest(unsigned long start, unsigned long end)printk (KERN_CONT "\n %010llx - %010llx pattern %d" , (unsigned long long )t_start, - (unsigned long long )t_start + t_size, - pattern % _MAX_MEM_PATTERNS); + (unsigned long long )t_start + t_size, idx);memtest (t_start, t_size, pattern);
Signature · 1 line
1.6.1.2
H. Peter Anvin
reviewerRe: [PATCH 2/7] x86: memtest: introduce array to store memtest patterns
arch/x86/mm/memtest.c line 22
Quoted 12 lines · Andreas Herrmann
arch/x86/mm/memtest.c +11
-1-#define _MAX_MEM_PATTERNS 4 +static unsigned long patterns[] = { +0UL , +-1UL , +#ifdef CONFIG_X86_64 +0x5555555555555555UL , +0xaaaaaaaaaaaaaaaaUL , +#else +0x55555555UL , +0xaaaaaaaaUL , +#endif +};
Why not just use u64 for the pattern even on 32 bits?
-hpa
Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.
Re: [PATCH 2/7] x86: memtest: introduce array to store memtest patterns
Quoted 15 lines · H. Peter Anvin
arch/x86/mm/memtest.c line 22
Quoted 12 lines · Andreas Herrmann
arch/x86/mm/memtest.c +11
-1-#define _MAX_MEM_PATTERNS 4 +static unsigned long patterns[] = { +0UL , +-1UL , +#ifdef CONFIG_X86_64 +0x5555555555555555UL , +0xaaaaaaaaaaaaaaaaUL , +#else +0x55555555UL , +0xaaaaaaaaUL , +#endif +};Why not just use u64 for the pattern even on 32 bits?
I just assumed that this was a settled thing.
Yinghai, was there a specific reason why you did not use an u64 for the memory test pattern on 32-bit?
(See commit 1f067167a83d1c7f80437fd1d32b55508aaca009 "x86: seperate memtest from init_64.c")
If not I'll adapt this and send out a new patch set.
Regards,
Andreas
Re: [PATCH 2/7] x86: memtest: introduce array to store memtest patterns
Quoted 17 lines · Andreas Herrmann
Quoted 15 lines · H. Peter Anvin
arch/x86/mm/memtest.c line 22
Quoted 12 lines · Andreas Herrmann
arch/x86/mm/memtest.c +11
-1-#define _MAX_MEM_PATTERNS 4 +static unsigned long patterns[] = { +0UL , +-1UL , +#ifdef CONFIG_X86_64 +0x5555555555555555UL , +0xaaaaaaaaaaaaaaaaUL , +#else +0x55555555UL , +0xaaaaaaaaUL , +#endif +};Why not just use u64 for the pattern even on 32 bits?
Quoted 8 lines
I just assumed that this was a settled thing.
Yinghai, was there a specific reason why you did not use an u64 for the memory test pattern on 32-bit?
(See commit1f067167a83d1c7f80437fd1d32b55508aaca009"x86: seperate memtest frominit_64.c")If not I'll adapt this and send out a new patch set.
should be ok, but please make sure target range is u64 alignment.
YH
PATCH 3/7 x86: memtest: cleanup memtest function
In reply to Andreas HerrmannImpact: code cleanup
--- arch/x86/mm/memtest.c | 36 +++++++++++++++++++----------------- 1 files changed, 19 insertions(+), 17 deletions(-)
arch/x86/mm/memtest.c +19 -17
@@ -21,6 +21,15 @@ static unsigned long patterns[] = {#endif }; +static void reserve_bad_mem (unsigned long pattern,unsigned long start_bad, +unsigned long end_bad) +{ +printk (KERN_CONT "\n %016lx bad mem addr " +"%010lx - %010lx reserved" , + pattern, start_bad, end_bad); +reserve_early (start_bad, end_bad,"BAD RAM" ); +} +static void __init memtest (unsigned long start_phys,unsigned long size,unsigned long pattern) {
@@ -42,25 +51,18 @@ static void __init memtest(unsigned long start_phys, unsigned long size,for (i =0 ; i < count; i++) start[i] = pattern;for (i =0 ; i < count; i++, start++, start_phys_aligned += incr) { -if (*start != pattern) { -if (start_phys_aligned == last_bad + incr) { - last_bad += incr; - }else { -if (start_bad) { -printk (KERN_CONT "\n %016lx bad mem addr %010lx - %010lx reserved" , - pattern, start_bad, - last_bad + incr); -reserve_early (start_bad, last_bad + incr,"BAD RAM" ); - } - start_bad = last_bad = start_phys_aligned; - } +if (*start == pattern) +continue ; +if (start_phys_aligned == last_bad + incr) { + last_bad += incr; +continue ; } +if (start_bad) +reserve_bad_mem (pattern, start_bad, last_bad + incr); + start_bad = last_bad = start_phys_aligned; } -if (start_bad) { -printk (KERN_CONT "\n %016lx bad mem addr %010lx - %010lx reserved" , - pattern, start_bad, last_bad + incr); -reserve_early (start_bad, last_bad + incr,"BAD RAM" ); - } +if (start_bad) +reserve_bad_mem (pattern, start_bad, last_bad + incr); }/* default is disabled */
Signature · 1 line
1.6.1.2
PATCH 4/7 x86: memtest: adapt log messages
In reply to Andreas HerrmannAdapt log messages to
* print test pattern instead of pattern number,
* correct format for output on 32-bit
* show pattern as stored in memory.
--- arch/x86/mm/memtest.c | 23 +++++++++++++++-------- 1 files changed, 15 insertions(+), 8 deletions(-)
arch/x86/mm/memtest.c +15 -8
@@ -24,9 +24,13 @@ static unsigned long patterns[] = {static void reserve_bad_mem (unsigned long pattern,unsigned long start_bad,unsigned long end_bad) { -printk (KERN_CONT "\n %016lx bad mem addr " -"%010lx - %010lx reserved" , - pattern, start_bad, end_bad); +#ifdef CONFIG_X86_64 +printk (KERN_CONT "\n %016llx bad mem addr %010lx - %010lx reserved" , +cpu_to_be64 (pattern), start_bad, end_bad); +#else +printk (KERN_CONT "\n %08x bad mem addr %010lx - %010lx reserved" , +cpu_to_be32 (pattern), start_bad, end_bad); +#endif reserve_early (start_bad, end_bad,"BAD RAM" ); }
@@ -86,7 +90,7 @@ void __init early_memtest(unsigned long start, unsigned long end)if (!memtest_pattern)return ; -printk (KERN_INFO "early_memtest: pattern num %d" , memtest_pattern); +printk (KERN_INFO "early_memtest: number of tests %d" , memtest_pattern);for (i =0 ; i < memtest_pattern; i++) {unsigned int idx = i %ARRAY_SIZE (patterns); pattern = patterns[idx];
@@ -101,10 +105,13 @@ void __init early_memtest(unsigned long start, unsigned long end)if (t_start + t_size > end) 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, idx); - +#ifdef CONFIG_X86_64 +printk (KERN_CONT "\n %010llx - %010llx pattern %016llx" , + t_start, t_start + t_size,cpu_to_be64 (pattern)); +#else +printk (KERN_CONT "\n %010llx - %010llx pattern %08x" , + t_start, t_start + t_size,cpu_to_be32 (pattern)); +#endif memtest (t_start, t_size, pattern); t_start += t_size;
Signature · 1 line
1.6.1.2
Re: [PATCH 4/7] x86: memtest: adapt log messages
arch/x86/mm/memtest.c void __init early_memtest(unsigned long start, unsigned long end) · line 114
Quoted 7 lines · Andreas Herrmann
arch/x86/mm/memtest.c +7
-0+#ifdef CONFIG_X86_64 +printk (KERN_CONT "\n %010llx - %010llx pattern %016llx" , + t_start, t_start + t_size,cpu_to_be64 (pattern)); +#else +printk (KERN_CONT "\n %010llx - %010llx pattern %08x" , + t_start, t_start + t_size,cpu_to_be32 (pattern)); +#endif
hm, is there really no cleaner way to do this?
Ingo
Re: [PATCH 4/7] x86: memtest: adapt log messages
Quoted 12 lines · Ingo Molnar
arch/x86/mm/memtest.c void __init early_memtest(unsigned long start, unsigned long end) · line 114
Quoted 7 lines · Andreas Herrmann
arch/x86/mm/memtest.c +7
-0+#ifdef CONFIG_X86_64 +printk (KERN_CONT "\n %010llx - %010llx pattern %016llx" , + t_start, t_start + t_size,cpu_to_be64 (pattern)); +#else +printk (KERN_CONT "\n %010llx - %010llx pattern %08x" , + t_start, t_start + t_size,cpu_to_be32 (pattern)); +#endif hm, is there really no cleaner way to do this?
Can we use this:
+ printk(KERN_CONT "\n %010llx - %010llx pattern %016llx",
+ t_start, t_start + t_size, cpu_to_be64(pattern));
--
JSR
H. Peter Anvin
reviewerRe: [PATCH 4/7] x86: memtest: adapt log messages
Quoted 15 lines · Jaswinder Singh Rajput
Quoted 10 lines · Ingo Molnar
arch/x86/mm/memtest.c void __init early_memtest(unsigned long start, unsigned long end) · line 114
Quoted 7 lines · Andreas Herrmann
arch/x86/mm/memtest.c +7
-0+#ifdef CONFIG_X86_64 +printk (KERN_CONT "\n %010llx - %010llx pattern %016llx" , + t_start, t_start + t_size,cpu_to_be64 (pattern)); +#else +printk (KERN_CONT "\n %010llx - %010llx pattern %08x" , + t_start, t_start + t_size,cpu_to_be32 (pattern)); +#endif hm, is there really no cleaner way to do this?
Can we use this:
arch/x86/mm/memtest.c void __init early_memtest(unsigned long start, unsigned long end) · line 110
Quoted 2 lines
arch/x86/mm/memtest.c +2
-0+printk (KERN_CONT "\n %010llx - %010llx pattern %016llx" , + t_start, t_start + t_size,cpu_to_be64 (pattern));
Only if you don't mind 8 extra zeros on 32 bits.
There are other problems with this, too. There is a KERN_CONT at the end of it, but it starts a new line, and then doesn't have another priority flag.
-hpa
Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.
Re: [PATCH 4/7] x86: memtest: adapt log messages
Quoted 21 lines · H. Peter Anvin
Quoted 15 lines · Jaswinder Singh Rajput
Quoted 10 lines · Ingo Molnar
arch/x86/mm/memtest.c void __init early_memtest(unsigned long start, unsigned long end) · line 114
Quoted 7 lines · Andreas Herrmann
arch/x86/mm/memtest.c +7
-0+#ifdef CONFIG_X86_64 +printk (KERN_CONT "\n %010llx - %010llx pattern %016llx" , + t_start, t_start + t_size,cpu_to_be64 (pattern)); +#else +printk (KERN_CONT "\n %010llx - %010llx pattern %08x" , + t_start, t_start + t_size,cpu_to_be32 (pattern)); +#endif hm, is there really no cleaner way to do this?
Can we use this:
arch/x86/mm/memtest.c void __init early_memtest(unsigned long start, unsigned long end) · line 110
Quoted 2 lines
arch/x86/mm/memtest.c +2
-0+printk (KERN_CONT "\n %010llx - %010llx pattern %016llx" , + t_start, t_start + t_size,cpu_to_be64 (pattern));Only if you don't mind 8 extra zeros on 32 bits.
Quoted 3 lines
There are other problems with this, too. There is a
KERN_CONTat the end of it, but it starts a new line, and then doesn't have another priority flag.
Ok, I see. I'll replace KERN_CONT with an appropriate priority flag and move the newline to the end of the format string.
Regards,
Andreas
Re: [PATCH 4/7] x86: memtest: adapt log messages
In reply to Ingo MolnarQuoted 12 lines · Ingo Molnar
arch/x86/mm/memtest.c void __init early_memtest(unsigned long start, unsigned long end) · line 114
Quoted 7 lines · Andreas Herrmann
arch/x86/mm/memtest.c +7
-0+#ifdef CONFIG_X86_64 +printk (KERN_CONT "\n %010llx - %010llx pattern %016llx" , + t_start, t_start + t_size,cpu_to_be64 (pattern)); +#else +printk (KERN_CONT "\n %010llx - %010llx pattern %08x" , + t_start, t_start + t_size,cpu_to_be32 (pattern)); +#endif hm, is there really no cleaner way to do this?
There is -- but only if 32-bit-code is changed to use u64 for the test pattern.
Andreas
PATCH 5/7 x86: memtest: add additional (silly) test patterns
In reply to Andreas Herrmann--- arch/x86/mm/memtest.c | 22 ++++++++++++++++------ 1 files changed, 16 insertions(+), 6 deletions(-)
arch/x86/mm/memtest.c +16 -6
@@ -9,15 +9,25 @@#include <asm/e820.h> +#ifdef CONFIG_X86_64 +#define _regular_pattern (p) 0x##p##p##p##p##p##p##p##p##UL +#else +#define _regular_pattern (p) 0x##p##p##p##p##UL +#endif +static unsigned long patterns[] = { -0UL , --1UL , +_regular_pattern (00 ),_regular_pattern (ff), +_regular_pattern (55 ),_regular_pattern (aa), +_regular_pattern (11 ),_regular_pattern (22 ), +_regular_pattern (44 ),_regular_pattern (88 ), +_regular_pattern (33 ),_regular_pattern (66 ), +_regular_pattern (99 ),_regular_pattern (cc), +_regular_pattern (77 ),_regular_pattern (bb), +_regular_pattern (dd),_regular_pattern (ee), #ifdef CONFIG_X86_64 -0x5555555555555555UL , -0xaaaaaaaaaaaaaaaaUL , +0x7a6c7258554e494cUL ,/* 64-bit only ;-) */ #else -0x55555555UL , -0xaaaaaaaaUL , +0xefbeadde , #endif };
Signature · 1 line
1.6.1.2
PATCH 6/7 x86: memtest: wipe out test pattern from memory
In reply to Andreas Herrmann--- arch/x86/mm/memtest.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
arch/x86/mm/memtest.c +7 -0
@@ -126,6 +126,13 @@ void __init early_memtest(unsigned long start, unsigned long end) t_start += t_size; } +if (idx && (i == (memtest_pattern -1 ))) { + i =-1 ; + memtest_pattern =1 ; +printk (KERN_CONT "\n" ); +printk (KERN_INFO "early_memtest: wipe out last pattern" ); +continue ;/* one more test to wipe out patterns */ + } }printk (KERN_CONT "\n" ); }
Signature · 1 line
1.6.1.2
PATCH 7/7 x86: update description for memtest boot parameter
In reply to Andreas Herrmann--- Documentation/kernel-parameters.txt | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
Documentation/kernel-parameters.txt +6 -1
@@ -1308,8 +1308,13 @@ and is between 256 and 4096 characters. It is defined in the file memtest= [KNL,X86] Enable memtest Format: <integer> - range: 0,4 : pattern number default : 0 <disable> + Specifies the number of memtest passes to be + performed. Each pass selects another test + pattern from a given set of patterns. Memtest + fills the memory with this pattern, validates + memory contents and reserves bad memory + regions that are detected. meye.*= [HW] Set MotionEye Camera parameters See Documentation/video4linux/meye.txt.
Signature · 1 line
1.6.1.2