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