All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86: Find offset for crashkernel reservation automatically
@ 2008-06-26 19:54 ` Bernhard Walle
  0 siblings, 0 replies; 38+ messages in thread
From: Bernhard Walle @ 2008-06-26 19:54 UTC (permalink / raw)
  To: kexec; +Cc: Bernhard Walle, x86, linux-kernel, vgoyal

This patch removes the need of the crashkernel=...@offset parameter to define
a fixed offset for crashkernel reservation. That feature can be used together
with a relocatable kernel where the kexec-tools relocate the kernel and
get the actual offset from /proc/iomem.

The use case is a kernel where the .text+.data+.bss is after 16M physical
memory (debug kernel with lockdep on x86_64 can cause that) which caused a
major pain in autoconfiguration in our distribution.

Also, that patch unifies crashdump architectures a bit since IA64 has
that semantics from the very beginning of the kdump port.

Please provide feedback!


Signed-off-by: Bernhard Walle <bwalle@suse.de>
---
 arch/x86/kernel/setup.c |   70 +++++++++++++++++++++++++++++++++++------------
 1 files changed, 52 insertions(+), 18 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index a81d82c..c30bb7b 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -435,6 +435,34 @@ static inline unsigned long long get_total_mem(void)
 }
 
 #ifdef CONFIG_KEXEC
+
+/**
+ * Reserve @size bytes of crashkernel memory at any suitable offset.
+ *
+ * @size: Size of the crashkernel memory to reserve.
+ * Returns the base address on success, and -1ULL on failure.
+ */
+unsigned long long find_and_reserve_crashkernel(unsigned long long size)
+{
+	const unsigned long long alignment = 16<<20; 	/* 16M */
+	unsigned long long start = 0LL;
+
+	while (1) {
+		int ret;
+
+		start = find_e820_area(start, ULONG_MAX, size, alignment);
+		if (start == -1ULL)
+			return start;
+
+		/* try to reserve it */
+		ret = reserve_bootmem_generic(start, size, BOOTMEM_EXCLUSIVE);
+		if (ret >= 0)
+			return start;
+
+		start += alignment;
+	}
+}
+
 void __init reserve_crashkernel(void)
 {
 	unsigned long long total_mem;
@@ -445,30 +473,36 @@ void __init reserve_crashkernel(void)
 
 	ret = parse_crashkernel(boot_command_line, total_mem,
 			&crash_size, &crash_base);
-	if (ret == 0 && crash_size > 0) {
-		if (crash_base <= 0) {
-			printk(KERN_INFO "crashkernel reservation failed - "
-					"you have to specify a base address\n");
+	if (ret != 0 || crash_size <= 0)
+		return;
+
+	/* 0 means: find the address automatically */
+	if (crash_base <= 0) {
+		crash_base = find_and_reserve_crashkernel(crash_size);
+		if (crash_base == -1ULL) {
+			pr_info("crashkernel reservation failed. "
+				"No suitable area found.\n");
 			return;
 		}
-
-		if (reserve_bootmem_generic(crash_base, crash_size,
-					BOOTMEM_EXCLUSIVE) < 0) {
-			printk(KERN_INFO "crashkernel reservation failed - "
-					"memory is in use\n");
+	} else {
+		ret = reserve_bootmem_generic(crash_base, crash_size,
+					BOOTMEM_EXCLUSIVE);
+		if (ret < 0) {
+			pr_info("crashkernel reservation failed - "
+				"memory is in use\n");
 			return;
 		}
+	}
 
-		printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
-				"for crashkernel (System RAM: %ldMB)\n",
-				(unsigned long)(crash_size >> 20),
-				(unsigned long)(crash_base >> 20),
-				(unsigned long)(total_mem >> 20));
+	printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
+			"for crashkernel (System RAM: %ldMB)\n",
+			(unsigned long)(crash_size >> 20),
+			(unsigned long)(crash_base >> 20),
+			(unsigned long)(total_mem >> 20));
 
-		crashk_res.start = crash_base;
-		crashk_res.end   = crash_base + crash_size - 1;
-		insert_resource(&iomem_resource, &crashk_res);
-	}
+	crashk_res.start = crash_base;
+	crashk_res.end   = crash_base + crash_size - 1;
+	insert_resource(&iomem_resource, &crashk_res);
 }
 #else
 void __init reserve_crashkernel(void)
-- 
1.5.6


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply related	[flat|nested] 38+ messages in thread

end of thread, other threads:[~2008-07-14 19:08 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-26 19:54 [PATCH] x86: Find offset for crashkernel reservation automatically Bernhard Walle
2008-06-26 19:54 ` Bernhard Walle
2008-06-27 13:32 ` Vivek Goyal
2008-06-27 13:32   ` Vivek Goyal
2008-06-27 13:42   ` Vivek Goyal
2008-06-27 13:42     ` Vivek Goyal
2008-06-27 14:06     ` Bernhard Walle
2008-06-27 14:06       ` Bernhard Walle
2008-06-27 14:19       ` Vivek Goyal
2008-06-27 14:19         ` Vivek Goyal
2008-06-27 14:22         ` Bernhard Walle
2008-06-27 14:22           ` Bernhard Walle
2008-06-27 18:00           ` Eric W. Biederman
2008-06-27 18:00             ` Eric W. Biederman
2008-06-27 18:29             ` Bernhard Walle
2008-06-27 18:29               ` Bernhard Walle
2008-07-03 13:14               ` Ingo Molnar
2008-07-03 13:14                 ` Ingo Molnar
2008-07-14  7:11   ` Yinghai Lu
2008-07-14  7:11     ` Yinghai Lu
2008-07-14  9:24     ` Bernhard Walle
2008-07-14  9:24       ` Bernhard Walle
2008-07-14  9:44       ` Eric W. Biederman
2008-07-14  9:44         ` Eric W. Biederman
2008-07-14 17:06         ` Yinghai Lu
2008-07-14 17:06           ` Yinghai Lu
2008-07-14 17:30           ` Eric W. Biederman
2008-07-14 17:30             ` Eric W. Biederman
2008-07-14 18:17             ` Yinghai Lu
2008-07-14 18:17               ` Yinghai Lu
2008-07-14 18:41               ` Eric W. Biederman
2008-07-14 18:41                 ` Eric W. Biederman
2008-07-14 18:47                 ` Bernhard Walle
2008-07-14 18:47                   ` Bernhard Walle
2008-07-14 18:55                   ` Eric W. Biederman
2008-07-14 18:55                     ` Eric W. Biederman
2008-07-14 19:08                     ` Yinghai Lu
2008-07-14 19:08                       ` Yinghai Lu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.