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

TOMOYO Linux Cross Reference
Linux/kernel/crash_reserve.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /kernel/crash_reserve.c (Architecture alpha) and /kernel/crash_reserve.c (Architecture i386)


  1 // SPDX-License-Identifier: GPL-2.0-only            1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*                                                  2 /*
  3  * crash.c - kernel crash support code.             3  * crash.c - kernel crash support code.
  4  * Copyright (C) 2002-2004 Eric Biederman  <eb      4  * Copyright (C) 2002-2004 Eric Biederman  <ebiederm@xmission.com>
  5  */                                                 5  */
  6                                                     6 
  7 #include <linux/buildid.h>                          7 #include <linux/buildid.h>
  8 #include <linux/init.h>                             8 #include <linux/init.h>
  9 #include <linux/utsname.h>                          9 #include <linux/utsname.h>
 10 #include <linux/vmalloc.h>                         10 #include <linux/vmalloc.h>
 11 #include <linux/sizes.h>                           11 #include <linux/sizes.h>
 12 #include <linux/kexec.h>                           12 #include <linux/kexec.h>
 13 #include <linux/memory.h>                          13 #include <linux/memory.h>
 14 #include <linux/cpuhotplug.h>                      14 #include <linux/cpuhotplug.h>
 15 #include <linux/memblock.h>                        15 #include <linux/memblock.h>
 16 #include <linux/kmemleak.h>                        16 #include <linux/kmemleak.h>
 17                                                    17 
 18 #include <asm/page.h>                              18 #include <asm/page.h>
 19 #include <asm/sections.h>                          19 #include <asm/sections.h>
 20                                                    20 
 21 #include <crypto/sha1.h>                           21 #include <crypto/sha1.h>
 22                                                    22 
 23 #include "kallsyms_internal.h"                     23 #include "kallsyms_internal.h"
 24 #include "kexec_internal.h"                        24 #include "kexec_internal.h"
 25                                                    25 
 26 /* Location of the reserved area for the crash     26 /* Location of the reserved area for the crash kernel */
 27 struct resource crashk_res = {                     27 struct resource crashk_res = {
 28         .name  = "Crash kernel",                   28         .name  = "Crash kernel",
 29         .start = 0,                                29         .start = 0,
 30         .end   = 0,                                30         .end   = 0,
 31         .flags = IORESOURCE_BUSY | IORESOURCE_     31         .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM,
 32         .desc  = IORES_DESC_CRASH_KERNEL           32         .desc  = IORES_DESC_CRASH_KERNEL
 33 };                                                 33 };
 34 struct resource crashk_low_res = {                 34 struct resource crashk_low_res = {
 35         .name  = "Crash kernel",                   35         .name  = "Crash kernel",
 36         .start = 0,                                36         .start = 0,
 37         .end   = 0,                                37         .end   = 0,
 38         .flags = IORESOURCE_BUSY | IORESOURCE_     38         .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM,
 39         .desc  = IORES_DESC_CRASH_KERNEL           39         .desc  = IORES_DESC_CRASH_KERNEL
 40 };                                                 40 };
 41                                                    41 
 42 /*                                                 42 /*
 43  * parsing the "crashkernel" commandline           43  * parsing the "crashkernel" commandline
 44  *                                                 44  *
 45  * this code is intended to be called from arc     45  * this code is intended to be called from architecture specific code
 46  */                                                46  */
 47                                                    47 
 48                                                    48 
 49 /*                                                 49 /*
 50  * This function parses command lines in the f     50  * This function parses command lines in the format
 51  *                                                 51  *
 52  *   crashkernel=ramsize-range:size[,...][@off     52  *   crashkernel=ramsize-range:size[,...][@offset]
 53  *                                                 53  *
 54  * The function returns 0 on success and -EINV     54  * The function returns 0 on success and -EINVAL on failure.
 55  */                                                55  */
 56 static int __init parse_crashkernel_mem(char *     56 static int __init parse_crashkernel_mem(char *cmdline,
 57                                         unsign     57                                         unsigned long long system_ram,
 58                                         unsign     58                                         unsigned long long *crash_size,
 59                                         unsign     59                                         unsigned long long *crash_base)
 60 {                                                  60 {
 61         char *cur = cmdline, *tmp;                 61         char *cur = cmdline, *tmp;
 62         unsigned long long total_mem = system_     62         unsigned long long total_mem = system_ram;
 63                                                    63 
 64         /*                                         64         /*
 65          * Firmware sometimes reserves some me     65          * Firmware sometimes reserves some memory regions for its own use,
 66          * so the system memory size is less t     66          * so the system memory size is less than the actual physical memory
 67          * size. Work around this by rounding      67          * size. Work around this by rounding up the total size to 128M,
 68          * which is enough for most test cases     68          * which is enough for most test cases.
 69          */                                        69          */
 70         total_mem = roundup(total_mem, SZ_128M     70         total_mem = roundup(total_mem, SZ_128M);
 71                                                    71 
 72         /* for each entry of the comma-separat     72         /* for each entry of the comma-separated list */
 73         do {                                       73         do {
 74                 unsigned long long start, end      74                 unsigned long long start, end = ULLONG_MAX, size;
 75                                                    75 
 76                 /* get the start of the range      76                 /* get the start of the range */
 77                 start = memparse(cur, &tmp);       77                 start = memparse(cur, &tmp);
 78                 if (cur == tmp) {                  78                 if (cur == tmp) {
 79                         pr_warn("crashkernel:      79                         pr_warn("crashkernel: Memory value expected\n");
 80                         return -EINVAL;            80                         return -EINVAL;
 81                 }                                  81                 }
 82                 cur = tmp;                         82                 cur = tmp;
 83                 if (*cur != '-') {                 83                 if (*cur != '-') {
 84                         pr_warn("crashkernel:      84                         pr_warn("crashkernel: '-' expected\n");
 85                         return -EINVAL;            85                         return -EINVAL;
 86                 }                                  86                 }
 87                 cur++;                             87                 cur++;
 88                                                    88 
 89                 /* if no ':' is here, than we      89                 /* if no ':' is here, than we read the end */
 90                 if (*cur != ':') {                 90                 if (*cur != ':') {
 91                         end = memparse(cur, &t     91                         end = memparse(cur, &tmp);
 92                         if (cur == tmp) {          92                         if (cur == tmp) {
 93                                 pr_warn("crash     93                                 pr_warn("crashkernel: Memory value expected\n");
 94                                 return -EINVAL     94                                 return -EINVAL;
 95                         }                          95                         }
 96                         cur = tmp;                 96                         cur = tmp;
 97                         if (end <= start) {        97                         if (end <= start) {
 98                                 pr_warn("crash     98                                 pr_warn("crashkernel: end <= start\n");
 99                                 return -EINVAL     99                                 return -EINVAL;
100                         }                         100                         }
101                 }                                 101                 }
102                                                   102 
103                 if (*cur != ':') {                103                 if (*cur != ':') {
104                         pr_warn("crashkernel:     104                         pr_warn("crashkernel: ':' expected\n");
105                         return -EINVAL;           105                         return -EINVAL;
106                 }                                 106                 }
107                 cur++;                            107                 cur++;
108                                                   108 
109                 size = memparse(cur, &tmp);       109                 size = memparse(cur, &tmp);
110                 if (cur == tmp) {                 110                 if (cur == tmp) {
111                         pr_warn("crashkernel:     111                         pr_warn("crashkernel: Memory value expected\n");
112                         return -EINVAL;           112                         return -EINVAL;
113                 }                                 113                 }
114                 cur = tmp;                        114                 cur = tmp;
115                 if (size >= total_mem) {          115                 if (size >= total_mem) {
116                         pr_warn("crashkernel:     116                         pr_warn("crashkernel: invalid size\n");
117                         return -EINVAL;           117                         return -EINVAL;
118                 }                                 118                 }
119                                                   119 
120                 /* match ? */                     120                 /* match ? */
121                 if (total_mem >= start && tota    121                 if (total_mem >= start && total_mem < end) {
122                         *crash_size = size;       122                         *crash_size = size;
123                         break;                    123                         break;
124                 }                                 124                 }
125         } while (*cur++ == ',');                  125         } while (*cur++ == ',');
126                                                   126 
127         if (*crash_size > 0) {                    127         if (*crash_size > 0) {
128                 while (*cur && *cur != ' ' &&     128                 while (*cur && *cur != ' ' && *cur != '@')
129                         cur++;                    129                         cur++;
130                 if (*cur == '@') {                130                 if (*cur == '@') {
131                         cur++;                    131                         cur++;
132                         *crash_base = memparse    132                         *crash_base = memparse(cur, &tmp);
133                         if (cur == tmp) {         133                         if (cur == tmp) {
134                                 pr_warn("crahs    134                                 pr_warn("crahskernel: Memory value expected after '@'\n");
135                                 return -EINVAL    135                                 return -EINVAL;
136                         }                         136                         }
137                 }                                 137                 }
138         } else                                    138         } else
139                 pr_info("crashkernel size resu    139                 pr_info("crashkernel size resulted in zero bytes\n");
140                                                   140 
141         return 0;                                 141         return 0;
142 }                                                 142 }
143                                                   143 
144 /*                                                144 /*
145  * That function parses "simple" (old) crashke    145  * That function parses "simple" (old) crashkernel command lines like
146  *                                                146  *
147  *      crashkernel=size[@offset]                 147  *      crashkernel=size[@offset]
148  *                                                148  *
149  * It returns 0 on success and -EINVAL on fail    149  * It returns 0 on success and -EINVAL on failure.
150  */                                               150  */
151 static int __init parse_crashkernel_simple(cha    151 static int __init parse_crashkernel_simple(char *cmdline,
152                                            uns    152                                            unsigned long long *crash_size,
153                                            uns    153                                            unsigned long long *crash_base)
154 {                                                 154 {
155         char *cur = cmdline;                      155         char *cur = cmdline;
156                                                   156 
157         *crash_size = memparse(cmdline, &cur);    157         *crash_size = memparse(cmdline, &cur);
158         if (cmdline == cur) {                     158         if (cmdline == cur) {
159                 pr_warn("crashkernel: memory v    159                 pr_warn("crashkernel: memory value expected\n");
160                 return -EINVAL;                   160                 return -EINVAL;
161         }                                         161         }
162                                                   162 
163         if (*cur == '@')                          163         if (*cur == '@')
164                 *crash_base = memparse(cur+1,     164                 *crash_base = memparse(cur+1, &cur);
165         else if (*cur != ' ' && *cur != '\0')     165         else if (*cur != ' ' && *cur != '\0') {
166                 pr_warn("crashkernel: unrecogn    166                 pr_warn("crashkernel: unrecognized char: %c\n", *cur);
167                 return -EINVAL;                   167                 return -EINVAL;
168         }                                         168         }
169                                                   169 
170         return 0;                                 170         return 0;
171 }                                                 171 }
172                                                   172 
173 #define SUFFIX_HIGH 0                             173 #define SUFFIX_HIGH 0
174 #define SUFFIX_LOW  1                             174 #define SUFFIX_LOW  1
175 #define SUFFIX_NULL 2                             175 #define SUFFIX_NULL 2
176 static __initdata char *suffix_tbl[] = {          176 static __initdata char *suffix_tbl[] = {
177         [SUFFIX_HIGH] = ",high",                  177         [SUFFIX_HIGH] = ",high",
178         [SUFFIX_LOW]  = ",low",                   178         [SUFFIX_LOW]  = ",low",
179         [SUFFIX_NULL] = NULL,                     179         [SUFFIX_NULL] = NULL,
180 };                                                180 };
181                                                   181 
182 /*                                                182 /*
183  * That function parses "suffix"  crashkernel     183  * That function parses "suffix"  crashkernel command lines like
184  *                                                184  *
185  *      crashkernel=size,[high|low]               185  *      crashkernel=size,[high|low]
186  *                                                186  *
187  * It returns 0 on success and -EINVAL on fail    187  * It returns 0 on success and -EINVAL on failure.
188  */                                               188  */
189 static int __init parse_crashkernel_suffix(cha    189 static int __init parse_crashkernel_suffix(char *cmdline,
190                                            uns    190                                            unsigned long long *crash_size,
191                                            con    191                                            const char *suffix)
192 {                                                 192 {
193         char *cur = cmdline;                      193         char *cur = cmdline;
194                                                   194 
195         *crash_size = memparse(cmdline, &cur);    195         *crash_size = memparse(cmdline, &cur);
196         if (cmdline == cur) {                     196         if (cmdline == cur) {
197                 pr_warn("crashkernel: memory v    197                 pr_warn("crashkernel: memory value expected\n");
198                 return -EINVAL;                   198                 return -EINVAL;
199         }                                         199         }
200                                                   200 
201         /* check with suffix */                   201         /* check with suffix */
202         if (strncmp(cur, suffix, strlen(suffix    202         if (strncmp(cur, suffix, strlen(suffix))) {
203                 pr_warn("crashkernel: unrecogn    203                 pr_warn("crashkernel: unrecognized char: %c\n", *cur);
204                 return -EINVAL;                   204                 return -EINVAL;
205         }                                         205         }
206         cur += strlen(suffix);                    206         cur += strlen(suffix);
207         if (*cur != ' ' && *cur != '\0') {        207         if (*cur != ' ' && *cur != '\0') {
208                 pr_warn("crashkernel: unrecogn    208                 pr_warn("crashkernel: unrecognized char: %c\n", *cur);
209                 return -EINVAL;                   209                 return -EINVAL;
210         }                                         210         }
211                                                   211 
212         return 0;                                 212         return 0;
213 }                                                 213 }
214                                                   214 
215 static __init char *get_last_crashkernel(char     215 static __init char *get_last_crashkernel(char *cmdline,
216                              const char *name,    216                              const char *name,
217                              const char *suffi    217                              const char *suffix)
218 {                                                 218 {
219         char *p = cmdline, *ck_cmdline = NULL;    219         char *p = cmdline, *ck_cmdline = NULL;
220                                                   220 
221         /* find crashkernel and use the last o    221         /* find crashkernel and use the last one if there are more */
222         p = strstr(p, name);                      222         p = strstr(p, name);
223         while (p) {                               223         while (p) {
224                 char *end_p = strchr(p, ' ');     224                 char *end_p = strchr(p, ' ');
225                 char *q;                          225                 char *q;
226                                                   226 
227                 if (!end_p)                       227                 if (!end_p)
228                         end_p = p + strlen(p);    228                         end_p = p + strlen(p);
229                                                   229 
230                 if (!suffix) {                    230                 if (!suffix) {
231                         int i;                    231                         int i;
232                                                   232 
233                         /* skip the one with a    233                         /* skip the one with any known suffix */
234                         for (i = 0; suffix_tbl    234                         for (i = 0; suffix_tbl[i]; i++) {
235                                 q = end_p - st    235                                 q = end_p - strlen(suffix_tbl[i]);
236                                 if (!strncmp(q    236                                 if (!strncmp(q, suffix_tbl[i],
237                                              s    237                                              strlen(suffix_tbl[i])))
238                                         goto n    238                                         goto next;
239                         }                         239                         }
240                         ck_cmdline = p;           240                         ck_cmdline = p;
241                 } else {                          241                 } else {
242                         q = end_p - strlen(suf    242                         q = end_p - strlen(suffix);
243                         if (!strncmp(q, suffix    243                         if (!strncmp(q, suffix, strlen(suffix)))
244                                 ck_cmdline = p    244                                 ck_cmdline = p;
245                 }                                 245                 }
246 next:                                             246 next:
247                 p = strstr(p+1, name);            247                 p = strstr(p+1, name);
248         }                                         248         }
249                                                   249 
250         return ck_cmdline;                        250         return ck_cmdline;
251 }                                                 251 }
252                                                   252 
253 static int __init __parse_crashkernel(char *cm    253 static int __init __parse_crashkernel(char *cmdline,
254                              unsigned long lon    254                              unsigned long long system_ram,
255                              unsigned long lon    255                              unsigned long long *crash_size,
256                              unsigned long lon    256                              unsigned long long *crash_base,
257                              const char *suffi    257                              const char *suffix)
258 {                                                 258 {
259         char *first_colon, *first_space;          259         char *first_colon, *first_space;
260         char *ck_cmdline;                         260         char *ck_cmdline;
261         char *name = "crashkernel=";              261         char *name = "crashkernel=";
262                                                   262 
263         BUG_ON(!crash_size || !crash_base);       263         BUG_ON(!crash_size || !crash_base);
264         *crash_size = 0;                          264         *crash_size = 0;
265         *crash_base = 0;                          265         *crash_base = 0;
266                                                   266 
267         ck_cmdline = get_last_crashkernel(cmdl    267         ck_cmdline = get_last_crashkernel(cmdline, name, suffix);
268         if (!ck_cmdline)                          268         if (!ck_cmdline)
269                 return -ENOENT;                   269                 return -ENOENT;
270                                                   270 
271         ck_cmdline += strlen(name);               271         ck_cmdline += strlen(name);
272                                                   272 
273         if (suffix)                               273         if (suffix)
274                 return parse_crashkernel_suffi    274                 return parse_crashkernel_suffix(ck_cmdline, crash_size,
275                                 suffix);          275                                 suffix);
276         /*                                        276         /*
277          * if the commandline contains a ':',     277          * if the commandline contains a ':', then that's the extended
278          * syntax -- if not, it must be the cl    278          * syntax -- if not, it must be the classic syntax
279          */                                       279          */
280         first_colon = strchr(ck_cmdline, ':');    280         first_colon = strchr(ck_cmdline, ':');
281         first_space = strchr(ck_cmdline, ' ');    281         first_space = strchr(ck_cmdline, ' ');
282         if (first_colon && (!first_space || fi    282         if (first_colon && (!first_space || first_colon < first_space))
283                 return parse_crashkernel_mem(c    283                 return parse_crashkernel_mem(ck_cmdline, system_ram,
284                                 crash_size, cr    284                                 crash_size, crash_base);
285                                                   285 
286         return parse_crashkernel_simple(ck_cmd    286         return parse_crashkernel_simple(ck_cmdline, crash_size, crash_base);
287 }                                                 287 }
288                                                   288 
289 /*                                                289 /*
290  * That function is the entry point for comman    290  * That function is the entry point for command line parsing and should be
291  * called from the arch-specific code.            291  * called from the arch-specific code.
292  *                                                292  *
293  * If crashkernel=,high|low is supported on ar    293  * If crashkernel=,high|low is supported on architecture, non-NULL values
294  * should be passed to parameters 'low_size' a    294  * should be passed to parameters 'low_size' and 'high'.
295  */                                               295  */
296 int __init parse_crashkernel(char *cmdline,       296 int __init parse_crashkernel(char *cmdline,
297                              unsigned long lon    297                              unsigned long long system_ram,
298                              unsigned long lon    298                              unsigned long long *crash_size,
299                              unsigned long lon    299                              unsigned long long *crash_base,
300                              unsigned long lon    300                              unsigned long long *low_size,
301                              bool *high)          301                              bool *high)
302 {                                                 302 {
303         int ret;                                  303         int ret;
304                                                   304 
305         /* crashkernel=X[@offset] */              305         /* crashkernel=X[@offset] */
306         ret = __parse_crashkernel(cmdline, sys    306         ret = __parse_crashkernel(cmdline, system_ram, crash_size,
307                                 crash_base, NU    307                                 crash_base, NULL);
308 #ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RES    308 #ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION
309         /*                                        309         /*
310          * If non-NULL 'high' passed in and no    310          * If non-NULL 'high' passed in and no normal crashkernel
311          * setting detected, try parsing crash    311          * setting detected, try parsing crashkernel=,high|low.
312          */                                       312          */
313         if (high && ret == -ENOENT) {             313         if (high && ret == -ENOENT) {
314                 ret = __parse_crashkernel(cmdl    314                 ret = __parse_crashkernel(cmdline, 0, crash_size,
315                                 crash_base, su    315                                 crash_base, suffix_tbl[SUFFIX_HIGH]);
316                 if (ret || !*crash_size)          316                 if (ret || !*crash_size)
317                         return -EINVAL;           317                         return -EINVAL;
318                                                   318 
319                 /*                                319                 /*
320                  * crashkernel=Y,low can be sp    320                  * crashkernel=Y,low can be specified or not, but invalid value
321                  * is not allowed.                321                  * is not allowed.
322                  */                               322                  */
323                 ret = __parse_crashkernel(cmdl    323                 ret = __parse_crashkernel(cmdline, 0, low_size,
324                                 crash_base, su    324                                 crash_base, suffix_tbl[SUFFIX_LOW]);
325                 if (ret == -ENOENT) {             325                 if (ret == -ENOENT) {
326                         *low_size = DEFAULT_CR    326                         *low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE;
327                         ret = 0;                  327                         ret = 0;
328                 } else if (ret) {                 328                 } else if (ret) {
329                         return ret;               329                         return ret;
330                 }                                 330                 }
331                                                   331 
332                 *high = true;                     332                 *high = true;
333         }                                         333         }
334 #endif                                            334 #endif
335         if (!*crash_size)                         335         if (!*crash_size)
336                 ret = -EINVAL;                    336                 ret = -EINVAL;
337                                                   337 
338         if (*crash_size >= system_ram)            338         if (*crash_size >= system_ram)
339                 ret = -EINVAL;                    339                 ret = -EINVAL;
340                                                   340 
341         return ret;                               341         return ret;
342 }                                                 342 }
343                                                   343 
344 /*                                                344 /*
345  * Add a dummy early_param handler to mark cra    345  * Add a dummy early_param handler to mark crashkernel= as a known command line
346  * parameter and suppress incorrect warnings i    346  * parameter and suppress incorrect warnings in init/main.c.
347  */                                               347  */
348 static int __init parse_crashkernel_dummy(char    348 static int __init parse_crashkernel_dummy(char *arg)
349 {                                                 349 {
350         return 0;                                 350         return 0;
351 }                                                 351 }
352 early_param("crashkernel", parse_crashkernel_d    352 early_param("crashkernel", parse_crashkernel_dummy);
353                                                   353 
354 #ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RES    354 #ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION
355 static int __init reserve_crashkernel_low(unsi    355 static int __init reserve_crashkernel_low(unsigned long long low_size)
356 {                                                 356 {
357 #ifdef CONFIG_64BIT                               357 #ifdef CONFIG_64BIT
358         unsigned long long low_base;              358         unsigned long long low_base;
359                                                   359 
360         low_base = memblock_phys_alloc_range(l    360         low_base = memblock_phys_alloc_range(low_size, CRASH_ALIGN, 0, CRASH_ADDR_LOW_MAX);
361         if (!low_base) {                          361         if (!low_base) {
362                 pr_err("cannot allocate crashk    362                 pr_err("cannot allocate crashkernel low memory (size:0x%llx).\n", low_size);
363                 return -ENOMEM;                   363                 return -ENOMEM;
364         }                                         364         }
365                                                   365 
366         pr_info("crashkernel low memory reserv    366         pr_info("crashkernel low memory reserved: 0x%08llx - 0x%08llx (%lld MB)\n",
367                 low_base, low_base + low_size,    367                 low_base, low_base + low_size, low_size >> 20);
368                                                   368 
369         crashk_low_res.start = low_base;          369         crashk_low_res.start = low_base;
370         crashk_low_res.end   = low_base + low_    370         crashk_low_res.end   = low_base + low_size - 1;
371 #ifdef HAVE_ARCH_ADD_CRASH_RES_TO_IOMEM_EARLY     371 #ifdef HAVE_ARCH_ADD_CRASH_RES_TO_IOMEM_EARLY
372         insert_resource(&iomem_resource, &cras    372         insert_resource(&iomem_resource, &crashk_low_res);
373 #endif                                            373 #endif
374 #endif                                            374 #endif
375         return 0;                                 375         return 0;
376 }                                                 376 }
377                                                   377 
378 void __init reserve_crashkernel_generic(char *    378 void __init reserve_crashkernel_generic(char *cmdline,
379                              unsigned long lon    379                              unsigned long long crash_size,
380                              unsigned long lon    380                              unsigned long long crash_base,
381                              unsigned long lon    381                              unsigned long long crash_low_size,
382                              bool high)           382                              bool high)
383 {                                                 383 {
384         unsigned long long search_end = CRASH_    384         unsigned long long search_end = CRASH_ADDR_LOW_MAX, search_base = 0;
385         bool fixed_base = false;                  385         bool fixed_base = false;
386                                                   386 
387         /* User specifies base address explici    387         /* User specifies base address explicitly. */
388         if (crash_base) {                         388         if (crash_base) {
389                 fixed_base = true;                389                 fixed_base = true;
390                 search_base = crash_base;         390                 search_base = crash_base;
391                 search_end = crash_base + cras    391                 search_end = crash_base + crash_size;
392         } else if (high) {                        392         } else if (high) {
393                 search_base = CRASH_ADDR_LOW_M    393                 search_base = CRASH_ADDR_LOW_MAX;
394                 search_end = CRASH_ADDR_HIGH_M    394                 search_end = CRASH_ADDR_HIGH_MAX;
395         }                                         395         }
396                                                   396 
397 retry:                                            397 retry:
398         crash_base = memblock_phys_alloc_range    398         crash_base = memblock_phys_alloc_range(crash_size, CRASH_ALIGN,
399                                                   399                                                search_base, search_end);
400         if (!crash_base) {                        400         if (!crash_base) {
401                 /*                                401                 /*
402                  * For crashkernel=size[KMG]@o    402                  * For crashkernel=size[KMG]@offset[KMG], print out failure
403                  * message if can't reserve th    403                  * message if can't reserve the specified region.
404                  */                               404                  */
405                 if (fixed_base) {                 405                 if (fixed_base) {
406                         pr_warn("crashkernel r    406                         pr_warn("crashkernel reservation failed - memory is in use.\n");
407                         return;                   407                         return;
408                 }                                 408                 }
409                                                   409 
410                 /*                                410                 /*
411                  * For crashkernel=size[KMG],     411                  * For crashkernel=size[KMG], if the first attempt was for
412                  * low memory, fall back to hi    412                  * low memory, fall back to high memory, the minimum required
413                  * low memory will be reserved    413                  * low memory will be reserved later.
414                  */                               414                  */
415                 if (!high && search_end == CRA    415                 if (!high && search_end == CRASH_ADDR_LOW_MAX) {
416                         search_end = CRASH_ADD    416                         search_end = CRASH_ADDR_HIGH_MAX;
417                         search_base = CRASH_AD    417                         search_base = CRASH_ADDR_LOW_MAX;
418                         crash_low_size = DEFAU    418                         crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE;
419                         goto retry;               419                         goto retry;
420                 }                                 420                 }
421                                                   421 
422                 /*                                422                 /*
423                  * For crashkernel=size[KMG],h    423                  * For crashkernel=size[KMG],high, if the first attempt was
424                  * for high memory, fall back     424                  * for high memory, fall back to low memory.
425                  */                               425                  */
426                 if (high && search_end == CRAS    426                 if (high && search_end == CRASH_ADDR_HIGH_MAX) {
427                         search_end = CRASH_ADD    427                         search_end = CRASH_ADDR_LOW_MAX;
428                         search_base = 0;          428                         search_base = 0;
429                         if (search_end != CRAS    429                         if (search_end != CRASH_ADDR_HIGH_MAX)
430                                 goto retry;       430                                 goto retry;
431                 }                                 431                 }
432                 pr_warn("cannot allocate crash    432                 pr_warn("cannot allocate crashkernel (size:0x%llx)\n",
433                         crash_size);              433                         crash_size);
434                 return;                           434                 return;
435         }                                         435         }
436                                                   436 
437         if ((crash_base >= CRASH_ADDR_LOW_MAX)    437         if ((crash_base >= CRASH_ADDR_LOW_MAX) &&
438              crash_low_size && reserve_crashke    438              crash_low_size && reserve_crashkernel_low(crash_low_size)) {
439                 memblock_phys_free(crash_base,    439                 memblock_phys_free(crash_base, crash_size);
440                 return;                           440                 return;
441         }                                         441         }
442                                                   442 
443         pr_info("crashkernel reserved: 0x%016l    443         pr_info("crashkernel reserved: 0x%016llx - 0x%016llx (%lld MB)\n",
444                 crash_base, crash_base + crash    444                 crash_base, crash_base + crash_size, crash_size >> 20);
445                                                   445 
446         /*                                        446         /*
447          * The crashkernel memory will be remo    447          * The crashkernel memory will be removed from the kernel linear
448          * map. Inform kmemleak so that it won    448          * map. Inform kmemleak so that it won't try to access it.
449          */                                       449          */
450         kmemleak_ignore_phys(crash_base);         450         kmemleak_ignore_phys(crash_base);
451         if (crashk_low_res.end)                   451         if (crashk_low_res.end)
452                 kmemleak_ignore_phys(crashk_lo    452                 kmemleak_ignore_phys(crashk_low_res.start);
453                                                   453 
454         crashk_res.start = crash_base;            454         crashk_res.start = crash_base;
455         crashk_res.end = crash_base + crash_si    455         crashk_res.end = crash_base + crash_size - 1;
456 #ifdef HAVE_ARCH_ADD_CRASH_RES_TO_IOMEM_EARLY     456 #ifdef HAVE_ARCH_ADD_CRASH_RES_TO_IOMEM_EARLY
457         insert_resource(&iomem_resource, &cras    457         insert_resource(&iomem_resource, &crashk_res);
458 #endif                                            458 #endif
459 }                                                 459 }
460                                                   460 
461 #ifndef HAVE_ARCH_ADD_CRASH_RES_TO_IOMEM_EARLY    461 #ifndef HAVE_ARCH_ADD_CRASH_RES_TO_IOMEM_EARLY
462 static __init int insert_crashkernel_resources    462 static __init int insert_crashkernel_resources(void)
463 {                                                 463 {
464         if (crashk_res.start < crashk_res.end)    464         if (crashk_res.start < crashk_res.end)
465                 insert_resource(&iomem_resourc    465                 insert_resource(&iomem_resource, &crashk_res);
466                                                   466 
467         if (crashk_low_res.start < crashk_low_    467         if (crashk_low_res.start < crashk_low_res.end)
468                 insert_resource(&iomem_resourc    468                 insert_resource(&iomem_resource, &crashk_low_res);
469                                                   469 
470         return 0;                                 470         return 0;
471 }                                                 471 }
472 early_initcall(insert_crashkernel_resources);     472 early_initcall(insert_crashkernel_resources);
473 #endif                                            473 #endif
474 #endif                                            474 #endif
475                                                   475 

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

kernel.org | git.kernel.org | LWN.net | Project Home | 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.

sflogo.php