Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit adbc742

Browse files
Yinghai LuH. Peter Anvin
authored andcommitted
x86, kdump: Change crashkernel_high/low= to crashkernel=,high/low
Per hpa, use crashkernel=X,high crashkernel=Y,low instead of crashkernel_hign=X crashkernel_low=Y. As that could be extensible. -v2: according to Vivek, change delimiter to ; -v3: let hign and low only handle simple form and it conforms to description in kernel-parameters.txt still keep crashkernel=X override any crashkernel=X,high crashkernel=Y,low -v4: update get_last_crashkernel returning and add more strict checking in parse_crashkernel_simple() found by HATAYAMA. -v5: Change delimiter back to , according to HPA. also separate parse_suffix from parse_simper according to vivek. so we can avoid @pos in that path. -v6: Tight the checking about crashkernel=X,highblahblah,high found by HTYAYAMA. Cc: HATAYAMA Daisuke <[email protected]> Signed-off-by: Yinghai Lu <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Acked-by: Vivek Goyal <[email protected]> Signed-off-by: H. Peter Anvin <[email protected]>
1 parent 55a20ee commit adbc742

File tree

3 files changed

+104
-21
lines changed

3 files changed

+104
-21
lines changed

Documentation/kernel-parameters.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -603,24 +603,24 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
603603
a memory unit (amount[KMG]). See also
604604
Documentation/kdump/kdump.txt for an example.
605605

606-
crashkernel_high=size[KMG]
606+
crashkernel=size[KMG],high
607607
[KNL, x86_64] range could be above 4G. Allow kernel
608608
to allocate physical memory region from top, so could
609609
be above 4G if system have more than 4G ram installed.
610610
Otherwise memory region will be allocated below 4G, if
611611
available.
612612
It will be ignored if crashkernel=X is specified.
613-
crashkernel_low=size[KMG]
614-
[KNL, x86_64] range under 4G. When crashkernel_high= is
615-
passed, kernel could allocate physical memory region
613+
crashkernel=size[KMG],low
614+
[KNL, x86_64] range under 4G. When crashkernel=X,high
615+
is passed, kernel could allocate physical memory region
616616
above 4G, that cause second kernel crash on system
617617
that require some amount of low memory, e.g. swiotlb
618618
requires at least 64M+32K low memory. Kernel would
619619
try to allocate 72M below 4G automatically.
620620
This one let user to specify own low range under 4G
621621
for second kernel instead.
622622
0: to disable low allocation.
623-
It will be ignored when crashkernel_high=X is not used
623+
It will be ignored when crashkernel=X,high is not used
624624
or memory reserved is below 4G.
625625

626626
cs89x0_dma= [HW,NET]

arch/x86/kernel/setup.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ static void __init reserve_crashkernel_low(void)
528528
int ret;
529529

530530
total_low_mem = memblock_mem_size(1UL<<(32-PAGE_SHIFT));
531-
/* crashkernel_low=YM */
531+
/* crashkernel=Y,low */
532532
ret = parse_crashkernel_low(boot_command_line, total_low_mem,
533533
&low_size, &base);
534534
if (ret != 0) {
@@ -542,7 +542,7 @@ static void __init reserve_crashkernel_low(void)
542542
low_size = swiotlb_size_or_default() + (8UL<<20);
543543
auto_set = true;
544544
} else {
545-
/* passed with crashkernel_low=0 ? */
545+
/* passed with crashkernel=0,low ? */
546546
if (!low_size)
547547
return;
548548
}
@@ -582,7 +582,7 @@ static void __init reserve_crashkernel(void)
582582
ret = parse_crashkernel(boot_command_line, total_mem,
583583
&crash_size, &crash_base);
584584
if (ret != 0 || crash_size <= 0) {
585-
/* crashkernel_high=XM */
585+
/* crashkernel=X,high */
586586
ret = parse_crashkernel_high(boot_command_line, total_mem,
587587
&crash_size, &crash_base);
588588
if (ret != 0 || crash_size <= 0)

kernel/kexec.c

Lines changed: 96 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,35 +1368,114 @@ static int __init parse_crashkernel_simple(char *cmdline,
13681368
return 0;
13691369
}
13701370

1371+
#define SUFFIX_HIGH 0
1372+
#define SUFFIX_LOW 1
1373+
#define SUFFIX_NULL 2
1374+
static __initdata char *suffix_tbl[] = {
1375+
[SUFFIX_HIGH] = ",high",
1376+
[SUFFIX_LOW] = ",low",
1377+
[SUFFIX_NULL] = NULL,
1378+
};
1379+
13711380
/*
1372-
* That function is the entry point for command line parsing and should be
1373-
* called from the arch-specific code.
1381+
* That function parses "suffix" crashkernel command lines like
1382+
*
1383+
* crashkernel=size,[high|low]
1384+
*
1385+
* It returns 0 on success and -EINVAL on failure.
13741386
*/
1387+
static int __init parse_crashkernel_suffix(char *cmdline,
1388+
unsigned long long *crash_size,
1389+
unsigned long long *crash_base,
1390+
const char *suffix)
1391+
{
1392+
char *cur = cmdline;
1393+
1394+
*crash_size = memparse(cmdline, &cur);
1395+
if (cmdline == cur) {
1396+
pr_warn("crashkernel: memory value expected\n");
1397+
return -EINVAL;
1398+
}
1399+
1400+
/* check with suffix */
1401+
if (strncmp(cur, suffix, strlen(suffix))) {
1402+
pr_warn("crashkernel: unrecognized char\n");
1403+
return -EINVAL;
1404+
}
1405+
cur += strlen(suffix);
1406+
if (*cur != ' ' && *cur != '\0') {
1407+
pr_warn("crashkernel: unrecognized char\n");
1408+
return -EINVAL;
1409+
}
1410+
1411+
return 0;
1412+
}
1413+
1414+
static __init char *get_last_crashkernel(char *cmdline,
1415+
const char *name,
1416+
const char *suffix)
1417+
{
1418+
char *p = cmdline, *ck_cmdline = NULL;
1419+
1420+
/* find crashkernel and use the last one if there are more */
1421+
p = strstr(p, name);
1422+
while (p) {
1423+
char *end_p = strchr(p, ' ');
1424+
char *q;
1425+
1426+
if (!end_p)
1427+
end_p = p + strlen(p);
1428+
1429+
if (!suffix) {
1430+
int i;
1431+
1432+
/* skip the one with any known suffix */
1433+
for (i = 0; suffix_tbl[i]; i++) {
1434+
q = end_p - strlen(suffix_tbl[i]);
1435+
if (!strncmp(q, suffix_tbl[i],
1436+
strlen(suffix_tbl[i])))
1437+
goto next;
1438+
}
1439+
ck_cmdline = p;
1440+
} else {
1441+
q = end_p - strlen(suffix);
1442+
if (!strncmp(q, suffix, strlen(suffix)))
1443+
ck_cmdline = p;
1444+
}
1445+
next:
1446+
p = strstr(p+1, name);
1447+
}
1448+
1449+
if (!ck_cmdline)
1450+
return NULL;
1451+
1452+
return ck_cmdline;
1453+
}
1454+
13751455
static int __init __parse_crashkernel(char *cmdline,
13761456
unsigned long long system_ram,
13771457
unsigned long long *crash_size,
13781458
unsigned long long *crash_base,
1379-
const char *name)
1459+
const char *name,
1460+
const char *suffix)
13801461
{
1381-
char *p = cmdline, *ck_cmdline = NULL;
13821462
char *first_colon, *first_space;
1463+
char *ck_cmdline;
13831464

13841465
BUG_ON(!crash_size || !crash_base);
13851466
*crash_size = 0;
13861467
*crash_base = 0;
13871468

1388-
/* find crashkernel and use the last one if there are more */
1389-
p = strstr(p, name);
1390-
while (p) {
1391-
ck_cmdline = p;
1392-
p = strstr(p+1, name);
1393-
}
1469+
ck_cmdline = get_last_crashkernel(cmdline, name, suffix);
13941470

13951471
if (!ck_cmdline)
13961472
return -EINVAL;
13971473

13981474
ck_cmdline += strlen(name);
13991475

1476+
if (suffix)
1477+
return parse_crashkernel_suffix(ck_cmdline, crash_size,
1478+
crash_base, suffix);
14001479
/*
14011480
* if the commandline contains a ':', then that's the extended
14021481
* syntax -- if not, it must be the classic syntax
@@ -1413,13 +1492,17 @@ static int __init __parse_crashkernel(char *cmdline,
14131492
return 0;
14141493
}
14151494

1495+
/*
1496+
* That function is the entry point for command line parsing and should be
1497+
* called from the arch-specific code.
1498+
*/
14161499
int __init parse_crashkernel(char *cmdline,
14171500
unsigned long long system_ram,
14181501
unsigned long long *crash_size,
14191502
unsigned long long *crash_base)
14201503
{
14211504
return __parse_crashkernel(cmdline, system_ram, crash_size, crash_base,
1422-
"crashkernel=");
1505+
"crashkernel=", NULL);
14231506
}
14241507

14251508
int __init parse_crashkernel_high(char *cmdline,
@@ -1428,7 +1511,7 @@ int __init parse_crashkernel_high(char *cmdline,
14281511
unsigned long long *crash_base)
14291512
{
14301513
return __parse_crashkernel(cmdline, system_ram, crash_size, crash_base,
1431-
"crashkernel_high=");
1514+
"crashkernel=", suffix_tbl[SUFFIX_HIGH]);
14321515
}
14331516

14341517
int __init parse_crashkernel_low(char *cmdline,
@@ -1437,7 +1520,7 @@ int __init parse_crashkernel_low(char *cmdline,
14371520
unsigned long long *crash_base)
14381521
{
14391522
return __parse_crashkernel(cmdline, system_ram, crash_size, crash_base,
1440-
"crashkernel_low=");
1523+
"crashkernel=", suffix_tbl[SUFFIX_LOW]);
14411524
}
14421525

14431526
static void update_vmcoreinfo_note(void)

0 commit comments

Comments
 (0)