Skip to content
/ linux Public
forked from torvalds/linux

Commit

Permalink
kdump: round up the total memory size to 128M for crashkernel reserva…
Browse files Browse the repository at this point in the history
…tion

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]>
  • Loading branch information
liutgnu authored and akpm00 committed Jul 18, 2022
1 parent 376b0c2 commit 46d36b1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions kernel/crash_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <linux/init.h>
#include <linux/utsname.h>
#include <linux/vmalloc.h>
#include <linux/sizes.h>

#include <asm/page.h>
#include <asm/sections.h>
Expand Down Expand Up @@ -45,6 +46,15 @@ static int __init parse_crashkernel_mem(char *cmdline,
unsigned long long *crash_base)
{
char *cur = cmdline, *tmp;
unsigned long long total_mem = system_ram;

/*
* Firmware sometimes reserves some memory regions for its own use,
* so the system memory size is less than the actual physical memory
* size. Work around this by rounding up the total size to 128M,
* which is enough for most test cases.
*/
total_mem = roundup(total_mem, SZ_128M);

/* for each entry of the comma-separated list */
do {
Expand Down Expand Up @@ -89,13 +99,13 @@ static int __init parse_crashkernel_mem(char *cmdline,
return -EINVAL;
}
cur = tmp;
if (size >= system_ram) {
if (size >= total_mem) {
pr_warn("crashkernel: invalid size\n");
return -EINVAL;
}

/* match ? */
if (system_ram >= start && system_ram < end) {
if (total_mem >= start && total_mem < end) {
*crash_size = size;
break;
}
Expand Down

0 comments on commit 46d36b1

Please sign in to comment.