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