kdump: round up the total memory size to 128M for crashkernel reservation
authorTao Liu <ltao@redhat.com>
Mon, 27 Jun 2022 07:44:41 +0000 (15:44 +0800)
committerakpm <akpm@linux-foundation.org>
Mon, 18 Jul 2022 00:31:40 +0000 (17:31 -0700)
commit46d36b1be18b745fc9f6be2087633ba2f9895ffe
tree9ee68befcceca8cd2e62a7c71ed3c5ec21ce023b
parent376b0c266143a1dda162db6d5bc9b3a7f0ae97c9
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/20220627074440.187222-1-ltao@redhat.com
Signed-off-by: Tao Liu <ltao@redhat.com>
Acked-by: Baoquan He <bhe@redhat.com>
Cc: Dave Young <dyoung@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
kernel/crash_core.c