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