~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/mm/memtest.c

Version: ~ [ linux-5.4-rc3 ] ~ [ linux-5.3.6 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.79 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.149 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.196 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.196 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.75 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #include <linux/kernel.h>
  2 #include <linux/types.h>
  3 #include <linux/init.h>
  4 #include <linux/memblock.h>
  5 
  6 static u64 patterns[] __initdata = {
  7         /* The first entry has to be 0 to leave memtest with zeroed memory */
  8         0,
  9         0xffffffffffffffffULL,
 10         0x5555555555555555ULL,
 11         0xaaaaaaaaaaaaaaaaULL,
 12         0x1111111111111111ULL,
 13         0x2222222222222222ULL,
 14         0x4444444444444444ULL,
 15         0x8888888888888888ULL,
 16         0x3333333333333333ULL,
 17         0x6666666666666666ULL,
 18         0x9999999999999999ULL,
 19         0xccccccccccccccccULL,
 20         0x7777777777777777ULL,
 21         0xbbbbbbbbbbbbbbbbULL,
 22         0xddddddddddddddddULL,
 23         0xeeeeeeeeeeeeeeeeULL,
 24         0x7a6c7258554e494cULL, /* yeah ;-) */
 25 };
 26 
 27 static void __init reserve_bad_mem(u64 pattern, phys_addr_t start_bad, phys_addr_t end_bad)
 28 {
 29         pr_info("  %016llx bad mem addr %pa - %pa reserved\n",
 30                 cpu_to_be64(pattern), &start_bad, &end_bad);
 31         memblock_reserve(start_bad, end_bad - start_bad);
 32 }
 33 
 34 static void __init memtest(u64 pattern, phys_addr_t start_phys, phys_addr_t size)
 35 {
 36         u64 *p, *start, *end;
 37         phys_addr_t start_bad, last_bad;
 38         phys_addr_t start_phys_aligned;
 39         const size_t incr = sizeof(pattern);
 40 
 41         start_phys_aligned = ALIGN(start_phys, incr);
 42         start = __va(start_phys_aligned);
 43         end = start + (size - (start_phys_aligned - start_phys)) / incr;
 44         start_bad = 0;
 45         last_bad = 0;
 46 
 47         for (p = start; p < end; p++)
 48                 *p = pattern;
 49 
 50         for (p = start; p < end; p++, start_phys_aligned += incr) {
 51                 if (*p == pattern)
 52                         continue;
 53                 if (start_phys_aligned == last_bad + incr) {
 54                         last_bad += incr;
 55                         continue;
 56                 }
 57                 if (start_bad)
 58                         reserve_bad_mem(pattern, start_bad, last_bad + incr);
 59                 start_bad = last_bad = start_phys_aligned;
 60         }
 61         if (start_bad)
 62                 reserve_bad_mem(pattern, start_bad, last_bad + incr);
 63 }
 64 
 65 static void __init do_one_pass(u64 pattern, phys_addr_t start, phys_addr_t end)
 66 {
 67         u64 i;
 68         phys_addr_t this_start, this_end;
 69 
 70         for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, &this_start,
 71                                 &this_end, NULL) {
 72                 this_start = clamp(this_start, start, end);
 73                 this_end = clamp(this_end, start, end);
 74                 if (this_start < this_end) {
 75                         pr_info("  %pa - %pa pattern %016llx\n",
 76                                 &this_start, &this_end, cpu_to_be64(pattern));
 77                         memtest(pattern, this_start, this_end - this_start);
 78                 }
 79         }
 80 }
 81 
 82 /* default is disabled */
 83 static unsigned int memtest_pattern __initdata;
 84 
 85 static int __init parse_memtest(char *arg)
 86 {
 87         int ret = 0;
 88 
 89         if (arg)
 90                 ret = kstrtouint(arg, 0, &memtest_pattern);
 91         else
 92                 memtest_pattern = ARRAY_SIZE(patterns);
 93 
 94         return ret;
 95 }
 96 
 97 early_param("memtest", parse_memtest);
 98 
 99 void __init early_memtest(phys_addr_t start, phys_addr_t end)
100 {
101         unsigned int i;
102         unsigned int idx = 0;
103 
104         if (!memtest_pattern)
105                 return;
106 
107         pr_info("early_memtest: # of tests: %u\n", memtest_pattern);
108         for (i = memtest_pattern-1; i < UINT_MAX; --i) {
109                 idx = i % ARRAY_SIZE(patterns);
110                 do_one_pass(patterns[idx], start, end);
111         }
112 }
113 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp