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