Last active
August 12, 2018 10:36
-
-
Save fcicq/264648c18e6c5e762f4a2cded063e307 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From: Brian Maly <brian.maly@oracle.com> | |
Date: Wed, 20 Dec 2017 04:58:08 +0000 (-0500) | |
Subject: x86: add support for crashkernel=auto | |
X-Git-Tag: v4.14.14-11~1221 | |
X-Git-Url: http://oss.oracle.com/git/gitweb.cgi?p=linux-uek5.git;a=commitdiff_plain;h=f03174698ead1617281e7cb0b56b937731ce1790;hp=ef29b7a9e060d1034edf0b8584d5231ca96847e9 | |
x86: add support for crashkernel=auto | |
This patch adds support for "crashkernel=auto" and was backported from RHEL7. | |
Orabug: 27234070 | |
Signed-off-by: Brian Maly <brian.maly@oracle.com> | |
Signed-off-by: Guangyu Sun <guangyu.sun@oracle.com> | |
Signed-off-by: Santosh Shilimkar <santosh.shilimkar@oracle.com> | |
--- | |
Signed-off-by: Brian Maly <brian.maly@oracle.com> | |
Signed-off-by: Somasundaram Krishnasamy <somasundaram.krishnasamy@oracle.com> | |
--- | |
diff --git a/Documentation/kdump/kdump.txt b/Documentation/kdump/kdump.txt | |
index 5181445..245b4d2 100644 | |
--- a/Documentation/kdump/kdump.txt | |
+++ b/Documentation/kdump/kdump.txt | |
@@ -150,6 +150,15 @@ System kernel config options | |
analysis tools require a vmlinux with debug symbols in order to read | |
and analyze a dump file. | |
+4) Enable "automatically reserve memory for kexec kernel" in | |
+ "Processor type and features." | |
+ | |
+ CONFIG_KEXEC_AUTO_RESERVE=y | |
+ | |
+ This will let you to use "crashkernel=auto", instead of specifying | |
+ numbers for "crashkernel=". Note, you need to have enough memory. | |
+ The threshold and reserved memory size are arch-dependent. | |
+ | |
Dump-capture kernel config options (Arch Independent) | |
----------------------------------------------------- | |
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig | |
index af8f5ad..32a4b85 100644 | |
--- a/arch/x86/Kconfig | |
+++ b/arch/x86/Kconfig | |
@@ -1971,6 +1971,19 @@ config KEXEC_BZIMAGE_VERIFY_SIG | |
---help--- | |
Enable bzImage signature verification support. | |
+config KEXEC_AUTO_RESERVE | |
+ bool "automatically reserve memory for kexec kernel" | |
+ depends on KEXEC | |
+ default y | |
+ ---help--- | |
+ Automatically reserve memory for a kexec kernel, so that you don't | |
+ need to specify numbers for the "crashkernel=X@Y" boot option, | |
+ instead you can use "crashkernel=auto". To make this work, you need | |
+ to have more than 4G memory. | |
+ | |
+ On x86_32, 128M is reserved, on x86_64 1/32 of your memory is | |
+ reserved, but it will not exceed 4G. | |
+ | |
config CRASH_DUMP | |
bool "kernel crash dumps" | |
depends on X86_64 || (X86_32 && HIGHMEM) | |
diff --git a/arch/x86/configs/x86_64_defconfig b/arch/x86/configs/x86_64_defconfig | |
index e32fc1f..03a9cb2 100644 | |
--- a/arch/x86/configs/x86_64_defconfig | |
+++ b/arch/x86/configs/x86_64_defconfig | |
@@ -53,6 +53,7 @@ CONFIG_X86_CHECK_BIOS_CORRUPTION=y | |
CONFIG_EFI=y | |
CONFIG_HZ_1000=y | |
CONFIG_KEXEC=y | |
+CONFIG_KEXEC_AUTO_RESERVE=y | |
CONFIG_CRASH_DUMP=y | |
CONFIG_RANDOMIZE_BASE=y | |
CONFIG_RANDOMIZE_MEMORY=y | |
diff --git a/arch/x86/include/asm/kexec.h b/arch/x86/include/asm/kexec.h | |
index f327236..4d3717b 100644 | |
--- a/arch/x86/include/asm/kexec.h | |
+++ b/arch/x86/include/asm/kexec.h | |
@@ -226,3 +226,15 @@ extern void kdump_nmi_shootdown_cpus(void); | |
#endif /* __ASSEMBLY__ */ | |
#endif /* _ASM_X86_KEXEC_H */ | |
+ | |
+#ifdef CONFIG_KEXEC_AUTO_RESERVE | |
+ | |
+#ifndef KEXEC_AUTO_RESERVED_SIZE | |
+#define KEXEC_AUTO_RESERVED_SIZE (1ULL<<28) /* 256M */ | |
+#endif | |
+#ifndef KEXEC_AUTO_THRESHOLD | |
+#define KEXEC_AUTO_THRESHOLD (1ULL<<31) /* 2G */ | |
+#endif | |
+ | |
+ | |
+#endif /* CONFIG_KEXEC_AUTO_RESERVE */ | |
diff --git a/kernel/crash_core.c b/kernel/crash_core.c | |
index 2d90996..ffb0f2e 100644 | |
--- a/kernel/crash_core.c | |
+++ b/kernel/crash_core.c | |
@@ -9,6 +9,7 @@ | |
#include <linux/crash_core.h> | |
#include <linux/utsname.h> | |
#include <linux/vmalloc.h> | |
+#include <linux/kexec.h> | |
#include <asm/page.h> | |
#include <asm/sections.h> | |
@@ -225,6 +226,44 @@ next: | |
return ck_cmdline; | |
} | |
+#ifdef CONFIG_KEXEC_AUTO_RESERVE | |
+#ifndef arch_default_crash_size | |
+unsigned long long __init arch_default_crash_size(unsigned long long total_size) | |
+{ | |
+ /* | |
+ * BIOS usually will reserve some memory regions for it's own use. | |
+ * so we will get less than actual memory in e820 usable areas. | |
+ * We workaround this by round up the total size to 128M which is | |
+ * enough for our current 2G kdump auto reserve threshold. | |
+ */ | |
+ if (roundup(total_size, 0x8000000) < KEXEC_AUTO_THRESHOLD) { | |
+ return 0; | |
+ | |
+ } else { | |
+ /* | |
+ * Filtering logic in kdump initrd requires 2bits per 4K page. | |
+ * Hence reserve 2bits per 4K of RAM (or 1byte per 16K of RAM) | |
+ * on top of base of 128M (KEXEC_AUTO_RESERVED_SIZE). | |
+ */ | |
+ return KEXEC_AUTO_RESERVED_SIZE + | |
+ roundup((total_size - KEXEC_AUTO_RESERVED_SIZE) | |
+ / (1ULL<<14), 1ULL<<20); | |
+ } | |
+} | |
+#define arch_default_crash_size arch_default_crash_size | |
+#endif | |
+ | |
+#ifndef arch_default_crash_base | |
+unsigned long long __init arch_default_crash_base(void) | |
+{ | |
+ /* 0 means find the base address automatically. */ | |
+ return 0; | |
+} | |
+#define arch_default_crash_base arch_default_crash_base | |
+#endif | |
+ | |
+#endif /*CONFIG_KEXEC_AUTO_RESERVE*/ | |
+ | |
static int __init __parse_crashkernel(char *cmdline, | |
unsigned long long system_ram, | |
unsigned long long *crash_size, | |
@@ -249,6 +288,23 @@ static int __init __parse_crashkernel(char *cmdline, | |
if (suffix) | |
return parse_crashkernel_suffix(ck_cmdline, crash_size, | |
suffix); | |
+ | |
+#ifdef CONFIG_KEXEC_AUTO_RESERVE | |
+ if (strncmp(ck_cmdline, "auto", 4) == 0) { | |
+ unsigned long long size; | |
+ | |
+ size = arch_default_crash_size(system_ram); | |
+ if (size != 0) { | |
+ *crash_size = size; | |
+ *crash_base = arch_default_crash_base(); | |
+ return 0; | |
+ | |
+ } else { | |
+ pr_warn("crashkernel=auto resulted in zero bytes of reserved memory.\n"); | |
+ return -ENOMEM; | |
+ } | |
+ } | |
+#endif | |
/* | |
* if the commandline contains a ':', then that's the extended | |
* syntax -- if not, it must be the classic syntax | |
diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c | |
index 20fef1a..2687946 100644 | |
--- a/kernel/kexec_core.c | |
+++ b/kernel/kexec_core.c | |
@@ -42,6 +42,7 @@ | |
#include <asm/page.h> | |
#include <asm/sections.h> | |
+#include <asm/setup.h> | |
#include <crypto/hash.h> | |
#include <crypto/sha.h> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment