Blame view

mm/memtest.c 2.75 KB
1f067167a   Yinghai Lu   x86: seperate mem...
1
  #include <linux/kernel.h>
1f067167a   Yinghai Lu   x86: seperate mem...
2
  #include <linux/types.h>
1f067167a   Yinghai Lu   x86: seperate mem...
3
  #include <linux/init.h>
a9ce6bc15   Yinghai Lu   x86, memblock: Re...
4
  #include <linux/memblock.h>
1f067167a   Yinghai Lu   x86: seperate mem...
5

6d74171bf   Andreas Herrmann   x86: memtest: int...
6
  static u64 patterns[] __initdata = {
20bf062c6   Alexander Holler   x86/memtest: Shor...
7
  	/* The first entry has to be 0 to leave memtest with zeroed memory */
6d74171bf   Andreas Herrmann   x86: memtest: int...
8
9
10
11
  	0,
  	0xffffffffffffffffULL,
  	0x5555555555555555ULL,
  	0xaaaaaaaaaaaaaaaaULL,
63823126c   Andreas Herrmann   x86: memtest: add...
12
13
14
15
16
17
18
19
20
21
22
23
24
  	0x1111111111111111ULL,
  	0x2222222222222222ULL,
  	0x4444444444444444ULL,
  	0x8888888888888888ULL,
  	0x3333333333333333ULL,
  	0x6666666666666666ULL,
  	0x9999999999999999ULL,
  	0xccccccccccccccccULL,
  	0x7777777777777777ULL,
  	0xbbbbbbbbbbbbbbbbULL,
  	0xddddddddddddddddULL,
  	0xeeeeeeeeeeeeeeeeULL,
  	0x7a6c7258554e494cULL, /* yeah ;-) */
6d74171bf   Andreas Herrmann   x86: memtest: int...
25
  };
40823f737   Andreas Herrmann   x86: memtest: reu...
26

7f70baeeb   Vladimir Murzin   memtest: use phys...
27
  static void __init reserve_bad_mem(u64 pattern, phys_addr_t start_bad, phys_addr_t end_bad)
7dad169e5   Andreas Herrmann   x86: memtest: cle...
28
  {
f373bafca   Vladimir Murzin   memtest: cleanup ...
29
30
31
  	pr_info("  %016llx bad mem addr %pa - %pa reserved
  ",
  		cpu_to_be64(pattern), &start_bad, &end_bad);
24aa07882   Tejun Heo   memblock, x86: Re...
32
  	memblock_reserve(start_bad, end_bad - start_bad);
7dad169e5   Andreas Herrmann   x86: memtest: cle...
33
  }
7f70baeeb   Vladimir Murzin   memtest: use phys...
34
  static void __init memtest(u64 pattern, phys_addr_t start_phys, phys_addr_t size)
1f067167a   Yinghai Lu   x86: seperate mem...
35
  {
9866b7e86   Thomas Gleixner   x86: memtest: use...
36
  	u64 *p, *start, *end;
7f70baeeb   Vladimir Murzin   memtest: use phys...
37
38
  	phys_addr_t start_bad, last_bad;
  	phys_addr_t start_phys_aligned;
9866b7e86   Thomas Gleixner   x86: memtest: use...
39
  	const size_t incr = sizeof(pattern);
1f067167a   Yinghai Lu   x86: seperate mem...
40

1f067167a   Yinghai Lu   x86: seperate mem...
41
  	start_phys_aligned = ALIGN(start_phys, incr);
1f067167a   Yinghai Lu   x86: seperate mem...
42
  	start = __va(start_phys_aligned);
9866b7e86   Thomas Gleixner   x86: memtest: use...
43
  	end = start + (size - (start_phys_aligned - start_phys)) / incr;
1f067167a   Yinghai Lu   x86: seperate mem...
44
45
  	start_bad = 0;
  	last_bad = 0;
c9690998e   Andreas Herrmann   x86: memtest: rem...
46
47
  	for (p = start; p < end; p++)
  		*p = pattern;
9866b7e86   Thomas Gleixner   x86: memtest: use...
48

c9690998e   Andreas Herrmann   x86: memtest: rem...
49
50
  	for (p = start; p < end; p++, start_phys_aligned += incr) {
  		if (*p == pattern)
7dad169e5   Andreas Herrmann   x86: memtest: cle...
51
52
53
54
  			continue;
  		if (start_phys_aligned == last_bad + incr) {
  			last_bad += incr;
  			continue;
1f067167a   Yinghai Lu   x86: seperate mem...
55
  		}
7dad169e5   Andreas Herrmann   x86: memtest: cle...
56
57
58
  		if (start_bad)
  			reserve_bad_mem(pattern, start_bad, last_bad + incr);
  		start_bad = last_bad = start_phys_aligned;
1f067167a   Yinghai Lu   x86: seperate mem...
59
  	}
7dad169e5   Andreas Herrmann   x86: memtest: cle...
60
61
  	if (start_bad)
  		reserve_bad_mem(pattern, start_bad, last_bad + incr);
1f067167a   Yinghai Lu   x86: seperate mem...
62
  }
7f70baeeb   Vladimir Murzin   memtest: use phys...
63
  static void __init do_one_pass(u64 pattern, phys_addr_t start, phys_addr_t end)
bfb4dc0da   Andreas Herrmann   x86: memtest: wip...
64
  {
8d89ac808   Tejun Heo   x86: Replace memb...
65
66
  	u64 i;
  	phys_addr_t this_start, this_end;
fc6daaf93   Tony Luck   mm/memblock: add ...
67
68
  	for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, &this_start,
  				&this_end, NULL) {
7f70baeeb   Vladimir Murzin   memtest: use phys...
69
70
  		this_start = clamp(this_start, start, end);
  		this_end = clamp(this_end, start, end);
8d89ac808   Tejun Heo   x86: Replace memb...
71
  		if (this_start < this_end) {
f373bafca   Vladimir Murzin   memtest: cleanup ...
72
73
74
  			pr_info("  %pa - %pa pattern %016llx
  ",
  				&this_start, &this_end, cpu_to_be64(pattern));
8d89ac808   Tejun Heo   x86: Replace memb...
75
76
  			memtest(pattern, this_start, this_end - this_start);
  		}
bfb4dc0da   Andreas Herrmann   x86: memtest: wip...
77
78
  	}
  }
1f067167a   Yinghai Lu   x86: seperate mem...
79
  /* default is disabled */
06f805965   Vladimir Murzin   memtest: use kstr...
80
  static unsigned int memtest_pattern __initdata;
1f067167a   Yinghai Lu   x86: seperate mem...
81
82
83
  
  static int __init parse_memtest(char *arg)
  {
06f805965   Vladimir Murzin   memtest: use kstr...
84
  	int ret = 0;
1f067167a   Yinghai Lu   x86: seperate mem...
85
  	if (arg)
06f805965   Vladimir Murzin   memtest: use kstr...
86
  		ret = kstrtouint(arg, 0, &memtest_pattern);
d1a8e7792   Yinghai Lu   x86: make "memtes...
87
88
  	else
  		memtest_pattern = ARRAY_SIZE(patterns);
06f805965   Vladimir Murzin   memtest: use kstr...
89
  	return ret;
1f067167a   Yinghai Lu   x86: seperate mem...
90
91
92
  }
  
  early_param("memtest", parse_memtest);
7f70baeeb   Vladimir Murzin   memtest: use phys...
93
  void __init early_memtest(phys_addr_t start, phys_addr_t end)
1f067167a   Yinghai Lu   x86: seperate mem...
94
  {
6d74171bf   Andreas Herrmann   x86: memtest: int...
95
  	unsigned int i;
bfb4dc0da   Andreas Herrmann   x86: memtest: wip...
96
  	unsigned int idx = 0;
1f067167a   Yinghai Lu   x86: seperate mem...
97
98
99
  
  	if (!memtest_pattern)
  		return;
f373bafca   Vladimir Murzin   memtest: cleanup ...
100
101
  	pr_info("early_memtest: # of tests: %u
  ", memtest_pattern);
20bf062c6   Alexander Holler   x86/memtest: Shor...
102
  	for (i = memtest_pattern-1; i < UINT_MAX; --i) {
bfb4dc0da   Andreas Herrmann   x86: memtest: wip...
103
104
105
  		idx = i % ARRAY_SIZE(patterns);
  		do_one_pass(patterns[idx], start, end);
  	}
1f067167a   Yinghai Lu   x86: seperate mem...
106
  }