Skip to contentSkip to conversation

sh: Add vmlinux crash dump support

PATCH In review Magnus Damm 3 participants 4 messages Sep 3, 2008 – Sep 4, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sh: Add vmlinux crash dump support

From: Magnus Damm <[email protected]>

This patch adds SuperH crash dump support. The vmlinux loader is modified with crash dump hooks as on other architectures. SuperH does not need any backup region, so only the elf header is allocated from the top of the reserved memory window. The actual size of the memory window is passed to the secondary kernel on the command line using "mem=".

The secondary kernel must be configured to match the reserved memory window, change kernel parameters CONFIG_MEMORY_START and CONFIG_MEMORY_SIZE.

Linux-2.6.27 should be usable as primary kernel on SuperH, later kernel versions are needed to fully support secondary kernel /proc/vmcore.

---

 kexec/arch/sh/Makefile       |    1 
 kexec/arch/sh/crashdump-sh.c |  186 ++++++++++++++++++++++++++++++++++++++++++
 kexec/arch/sh/crashdump-sh.h |    9 ++
 kexec/arch/sh/kexec-elf-sh.c |   31 ++++++-
 kexec/arch/sh/kexec-sh.c     |   30 +++++-
 kexec/arch/sh/kexec-sh.h     |    2 
 6 files changed, 249 insertions(+), 10 deletions(-)
kexec/arch/sh/Makefile +1 -0
@@ -7,6 +7,7 @@ sh_KEXEC_SRCS += kexec/arch/sh/kexec-net
 sh_KEXEC_SRCS += kexec/arch/sh/kexec-elf-sh.c
 sh_KEXEC_SRCS += kexec/arch/sh/kexec-elf-rel-sh.c
 sh_KEXEC_SRCS += kexec/arch/sh/netbsd_booter.S
+sh_KEXEC_SRCS += kexec/arch/sh/crashdump-sh.c
 
 sh_ADD_BUFFER =
 sh_ADD_SEGMENT =
kexec/arch/sh/crashdump-sh.c new file +186 -0

186 lines not on this page · raw message

kexec/arch/sh/crashdump-sh.h new file +9 -0
@@ -0,0 +1,9 @@
+#ifndef CRASHDUMP_SH_H
+#define CRASHDUMP_SH_H
+
+struct kexec_info;
+int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline);
+
+#define PAGE_OFFSET	0x80000000
+
+#endif /* CRASHDUMP_SH_H */
kexec/arch/sh/kexec-elf-sh.c +28 -3
@@ -37,6 +37,7 @@
 #include "../../kexec-elf.h"
 #include "../../kexec-elf-boot.h"
 #include <arch/options.h>
+#include "crashdump-sh.h"
 #include "kexec-sh.h"
 
 int elf_sh_probe(const char *buf, off_t len)
@@ -70,8 +71,9 @@ int elf_sh_load(int argc, char **argv, c
 {
 	struct mem_ehdr ehdr;
 	char *command_line;
+	char *modified_cmdline;
 	struct mem_sym sym;
-	int opt;
+	int opt, rc;
 	static const struct option options[] = {
 		KEXEC_ARCH_OPTIONS
 		{ 0, 0, 0, 0 },
@@ -82,7 +84,7 @@ int elf_sh_load(int argc, char **argv, c
 	/*
 	 * Parse the command line arguments
 	 */
-	command_line = 0;
+	command_line = modified_cmdline = 0;
 	while((opt = getopt_long(argc, argv, short_options, options, 0)) != -1) {
 		switch(opt) {
 		default:
@@ -99,9 +101,32 @@ int elf_sh_load(int argc, char **argv, c
 		}
 	}
 
+	/* Need to append some command line parameters internally in case of
+	 * taking crash dumps.
+	 */
+	if (info->kexec_flags & KEXEC_ON_CRASH) {
+		modified_cmdline = xmalloc(COMMAND_LINE_SIZE);
+		memset((void *)modified_cmdline, 0, COMMAND_LINE_SIZE);
+		if (command_line) {
+			strncpy(modified_cmdline, command_line,
+						COMMAND_LINE_SIZE);
+			modified_cmdline[COMMAND_LINE_SIZE - 1] = '\0';
+		}
+	}
+
 	/* Load the ELF executable */
 	elf_exec_build_load(info, &ehdr, buf, len, 0);
-	info->entry = (void *)ehdr.e_entry;
+	info->entry = (void *)virt_to_phys(ehdr.e_entry);
+
+	/* If panic kernel is being loaded, additional segments need
+	 * to be created. */
+	if (info->kexec_flags & KEXEC_ON_CRASH) {
+		rc = load_crashdump_segments(info, modified_cmdline);
+		if (rc < 0)
+			return -1;
+		/* Use new command line. */
+		command_line = modified_cmdline;
+	}
 
 	/* If we're booting a vmlinux then fill in empty_zero_page */
 	if (elf_rel_find_symbol(&ehdr, "empty_zero_page", &sym) == 0) {
kexec/arch/sh/kexec-sh.c +23 -7
@@ -41,12 +41,33 @@ static int kexec_sh_memory_range_callbac
 int get_memory_ranges(struct memory_range **range, int *ranges,
 		      unsigned long kexec_flags)
 {
-	int nr;
-
+	int nr, ret;
 	nr = kexec_iomem_for_each_line("System RAM\n",
 				       kexec_sh_memory_range_callback, NULL);
 	*range = memory_range;
 	*ranges = nr;
+
+	/*
+	 * Redefine the memory region boundaries if kernel
+	 * exports the limits and if it is panic kernel.
+	 * Override user values only if kernel exported values are
+	 * subset of user defined values.
+	 */
+	if (kexec_flags & KEXEC_ON_CRASH) {
+		unsigned long long start, end;
+
+		ret = parse_iomem_single("Crash kernel\n", &start, &end);
+		if (ret != 0) {
+			fprintf(stderr, "parse_iomem_single failed.\n");
+			return -1;
+		}
+
+		if (start > mem_min)
+			mem_min = start;
+		if (end < mem_max)
+			mem_max = end;
+	}
+
 	return 0;
 }
 
@@ -156,11 +177,6 @@ void kexec_sh_setup_zero_page(char *zero
 	}
 }
 
-int is_crashkernel_mem_reserved(void)
-{
-	return 0; /* kdump is not supported on this platform (yet) */
-}
-
 unsigned long virt_to_phys(unsigned long addr)
 {
 	unsigned long seg = addr & 0xe0000000;
kexec/arch/sh/kexec-sh.h +2 -0
@@ -1,6 +1,8 @@
 #ifndef KEXEC_SH_H
 #define KEXEC_SH_H
 
+#define COMMAND_LINE_SIZE 2048
+
 int zImage_sh_probe(const char *buf, off_t len);
 int zImage_sh_load(int argc, char **argv, const char *buf, off_t len,
 	struct kexec_info *info);

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#1 lore raw
Quoted 8 lines · Magnus Damm

From: Magnus Damm <[email protected]>

This patch adds SuperH crash dump support. The vmlinux loader is modified with crash dump hooks as on other architectures. SuperH does not need any backup region, so only the elf header is allocated from the top of the reserved memory window. The actual size of the memory window is passed to the secondary kernel on the command line using "mem=".

Quoted 5 lines

The secondary kernel must be configured to match the reserved memory window, change kernel parameters CONFIG_MEMORY_START and CONFIG_MEMORY_SIZE.

Linux-2.6.27 should be usable as primary kernel on SuperH, later kernel versions are needed to fully support secondary kernel /proc/vmcore.

Hi Magnus,

this looks ok to me. Has Paul or someone else reviewed it?

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

Acked-by
#2 lore raw
Quoted 12 lines · Simon Horman
Quoted 11 lines · Magnus Damm

From: Magnus Damm <[email protected]>

This patch adds SuperH crash dump support. The vmlinux loader is modified with crash dump hooks as on other architectures. SuperH does not need any backup region, so only the elf header is allocated from the top of the reserved memory window. The actual size of the memory window is passed to the secondary kernel on the command line using "mem=".

The secondary kernel must be configured to match the reserved memory window, change kernel parameters CONFIG_MEMORY_START and CONFIG_MEMORY_SIZE.

Quoted 7 lines
Quoted 2 lines

Linux-2.6.27 should be usable as primary kernel on SuperH, later kernel versions are needed to fully support secondary kernel /proc/vmcore.

Hi Magnus,

this looks ok to me. Has Paul or someone else reviewed it?

I have now, looks good to me.

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#3 lore raw
Quoted 13 lines · Paul Mundt
Quoted 12 lines · Simon Horman
Quoted 11 lines · Magnus Damm

From: Magnus Damm <[email protected]>

This patch adds SuperH crash dump support. The vmlinux loader is modified with crash dump hooks as on other architectures. SuperH does not need any backup region, so only the elf header is allocated from the top of the reserved memory window. The actual size of the memory window is passed to the secondary kernel on the command line using "mem=".

The secondary kernel must be configured to match the reserved memory window, change kernel parameters CONFIG_MEMORY_START and CONFIG_MEMORY_SIZE.

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

Linux-2.6.27 should be usable as primary kernel on SuperH, later kernel versions are needed to fully support secondary kernel /proc/vmcore.

Hi Magnus,

this looks ok to me. Has Paul or someone else reviewed it?

I have now, looks good to me.

Thanks Magnus, Thanks Paul. Applied :-)

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec