chengshan / rpms / kernel

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