Skip to content

Commit 46d36b1

Browse files
liutgnuakpm00
authored andcommitted
kdump: round up the total memory size to 128M for crashkernel reservation
The total memory size we get in kernel is usually slightly less than the actual memory size because BIOS/firmware will reserve some memory region. So it won't export all memory as usable. E.g, on my x86_64 kvm guest with 1G memory, the total_mem value shows: UEFI boot with ovmf: 0x3faef000 Legacy boot kvm guest: 0x3ff7ec00 When specifying crashkernel=1G-2G:128M, if we have a 1G memory machine, we get total size 1023M from firmware. Then it will not fall into 1G-2G, thus no memory reserved. User will never know this, it is hard to let user know the exact total value in kernel. One way is to use dmi/smbios to get physical memory size, but it's not reliable as well. According to Prarit hardware vendors sometimes screw this up. Thus round up total size to 128M to work around this problem. This patch is a resend of [1] and rebased onto v5.19-rc2, and the original credit goes to Dave Young. [1]: http://lists.infradead.org/pipermail/kexec/2018-April/020568.html Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Tao Liu <[email protected]> Acked-by: Baoquan He <[email protected]> Cc: Dave Young <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 376b0c2 commit 46d36b1

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

kernel/crash_core.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/init.h>
1010
#include <linux/utsname.h>
1111
#include <linux/vmalloc.h>
12+
#include <linux/sizes.h>
1213

1314
#include <asm/page.h>
1415
#include <asm/sections.h>
@@ -45,6 +46,15 @@ static int __init parse_crashkernel_mem(char *cmdline,
4546
unsigned long long *crash_base)
4647
{
4748
char *cur = cmdline, *tmp;
49+
unsigned long long total_mem = system_ram;
50+
51+
/*
52+
* Firmware sometimes reserves some memory regions for its own use,
53+
* so the system memory size is less than the actual physical memory
54+
* size. Work around this by rounding up the total size to 128M,
55+
* which is enough for most test cases.
56+
*/
57+
total_mem = roundup(total_mem, SZ_128M);
4858

4959
/* for each entry of the comma-separated list */
5060
do {
@@ -89,13 +99,13 @@ static int __init parse_crashkernel_mem(char *cmdline,
8999
return -EINVAL;
90100
}
91101
cur = tmp;
92-
if (size >= system_ram) {
102+
if (size >= total_mem) {
93103
pr_warn("crashkernel: invalid size\n");
94104
return -EINVAL;
95105
}
96106

97107
/* match ? */
98-
if (system_ram >= start && system_ram < end) {
108+
if (total_mem >= start && total_mem < end) {
99109
*crash_size = size;
100110
break;
101111
}

0 commit comments

Comments
 (0)