chengshan / rpms / kernel

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