614b7d7
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
614b7d7
From: Dave Young <dyoung@redhat.com>
614b7d7
Date: Mon, 4 Jun 2018 01:38:25 -0400
614b7d7
Subject: [PATCH] kdump: round up the total memory size to 128M for crashkernel
614b7d7
 reservation
614b7d7
614b7d7
Message-id: <20180604013831.523644967@redhat.com>
614b7d7
Patchwork-id: 8165
614b7d7
O-Subject: [kernel team] [PATCH RHEL8.0 V2 1/2] kdump: round up the total memory size to 128M for crashkernel reservation
614b7d7
Bugzilla: 1507353
614b7d7
RH-Acked-by: Don Zickus <dzickus@redhat.com>
614b7d7
RH-Acked-by: Baoquan He <bhe@redhat.com>
614b7d7
RH-Acked-by: Pingfan Liu <piliu@redhat.com>
614b7d7
614b7d7
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1507353
614b7d7
Build: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=16534135
614b7d7
Tested: ppc64le, x86_64 with several memory sizes.
614b7d7
614b7d7
The total memory size we get in kernel is usually slightly less than 2G with
614b7d7
2G memory module machine. The main reason is bios/firmware reserve some area
614b7d7
it will not export all memory as usable to Linux.
614b7d7
614b7d7
2G memory X86 kvm guest test result of the total_mem value:
614b7d7
UEFI boot with ovmf: 0x7ef10000
614b7d7
Legacy boot kvm guest: 0x7ff7cc00
614b7d7
This is also a problem on arm64 UEFI booted system according to my test.
614b7d7
614b7d7
Thus for example crashkernel=1G-2G:128M,  if we have a 1G memory
614b7d7
machine, we get total size 1023M from firmware then it will not fall
614b7d7
into 1G-2G thus no memory reserved.  User will never know that, it is
614b7d7
hard to let user to know the exact total value we get in kernel
614b7d7
614b7d7
An option is to use dmi/smbios to get physical memory size, but it's not
614b7d7
reliable as well. According to Prarit hardware vendors sometimes screw this up.
614b7d7
Thus round up total size to 128M to workaround this problem.
614b7d7
614b7d7
Posted below patch in upstream, but no response yet:
614b7d7
http://lists.infradead.org/pipermail/kexec/2018-April/020568.html
614b7d7
614b7d7
Upstream Status: RHEL only
614b7d7
Signed-off-by: Dave Young <dyoung@redhat.com>
614b7d7
Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
614b7d7
---
614b7d7
 kernel/crash_core.c | 14 ++++++++++++--
614b7d7
 1 file changed, 12 insertions(+), 2 deletions(-)
614b7d7
614b7d7
diff --git a/kernel/crash_core.c b/kernel/crash_core.c
614b7d7
index 9f1557b98468..d631d22089ba 100644
614b7d7
--- a/kernel/crash_core.c
614b7d7
+++ b/kernel/crash_core.c
614b7d7
@@ -7,6 +7,7 @@
614b7d7
 #include <linux/crash_core.h>
614b7d7
 #include <linux/utsname.h>
614b7d7
 #include <linux/vmalloc.h>
614b7d7
+#include <linux/sizes.h>
614b7d7
614b7d7
 #include <asm/page.h>
614b7d7
 #include <asm/sections.h>
614b7d7
@@ -39,6 +40,15 @@ static int __init parse_crashkernel_mem(char *cmdline,
614b7d7
 					unsigned long long *crash_base)
614b7d7
 {
614b7d7
 	char *cur = cmdline, *tmp;
614b7d7
+	unsigned long long total_mem = system_ram;
614b7d7
+
614b7d7
+	/*
614b7d7
+	 * Firmware sometimes reserves some memory regions for it's own use.
614b7d7
+	 * so we get less than actual system memory size.
614b7d7
+	 * Workaround this by round up the total size to 128M which is
614b7d7
+	 * enough for most test cases.
614b7d7
+	 */
614b7d7
+	total_mem = roundup(total_mem, SZ_128M);
614b7d7
614b7d7
 	/* for each entry of the comma-separated list */
614b7d7
 	do {
614b7d7
@@ -83,13 +93,13 @@ static int __init parse_crashkernel_mem(char *cmdline,
614b7d7
 			return -EINVAL;
614b7d7
 		}
614b7d7
 		cur = tmp;
614b7d7
-		if (size >= system_ram) {
614b7d7
+		if (size >= total_mem) {
614b7d7
 			pr_warn("crashkernel: invalid size\n");
614b7d7
 			return -EINVAL;
614b7d7
 		}
614b7d7
614b7d7
 		/* match ? */
614b7d7
-		if (system_ram >= start && system_ram < end) {
614b7d7
+		if (total_mem >= start && total_mem < end) {
614b7d7
 			*crash_size = size;
614b7d7
 			break;
614b7d7
 		}
614b7d7
-- 
614b7d7
2.26.2
614b7d7