Skip to contentSkip to conversation

kexec based crashdumps

PATCH In review Hariprasad Nellitheertha 1 participant 5 messages Oct 21, 2004

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

Hi,

The following patchset completes the basic functionality on kexec based crashdumps on i386. The first patch makes it possible to boot an i386 kernel from a non-default physical address. The rest of the patches are minor clean-ups and bug-fixes.

All the patches are on top of 2.6.9-rc4-mm1.

Kindly review them and let us know your feedback.

Thanks and Regards,
Hari

#1 lore raw

PATCH 1/4 kexec based dump: Loading kernel from non-default offset

This patch makes it possible for us to load i386 kernels from non-default physical addresses.

Regards, Hari

---

 linux-old-hari/arch/i386/Kconfig                 |   10 ++++
 linux-old-hari/arch/i386/boot/compressed/head.S  |    6 +-
 linux-old-hari/arch/i386/boot/compressed/misc.c  |    7 +-
 linux-old-hari/arch/i386/kernel/vmlinux.lds.S    |   56 +++++++++++++----------
 linux-old-hari/include/asm-generic/vmlinux.lds.h |    2 
 linux-old-hari/include/asm-i386/segment.h        |    2 
 6 files changed, 54 insertions(+), 29 deletions(-)
arch/i386/Kconfig renamed from arch/i386/Kconfig~kd-kern-offset +10 -0
diff -puN arch/i386/Kconfig~kd-kern-offset arch/i386/Kconfig
@@ -882,6 +882,16 @@ config REGPARM
 
 source "drivers/perfctr/Kconfig"
 
+config KERN_PHYS_OFFSET
+	int "Physical address where the kernel is loaded (1-112)MB"
+	range 1 112
+	default "1"
+	help
+	  This gives the physical address where the kernel is loaded.
+	  Primarily used in the case of kexec on panic where the
+	  recovery kernel needs to run at a different address than
+	  the panic-ed kernel.
+
 config KEXEC
 	bool "kexec system call (EXPERIMENTAL)"
 	depends on EXPERIMENTAL
arch/i386/boot/compressed/head.S renamed from arch/i386/boot/compressed/head.S~kd-kern-offset +3 -3
diff -puN arch/i386/boot/compressed/head.S~kd-kern-offset arch/i386/boot/compressed/head.S
@@ -74,7 +74,7 @@ startup_32:
 	popl %esi	# discard address
 	popl %esi	# real mode pointer
 	xorl %ebx,%ebx
-	ljmp $(__BOOT_CS), $0x100000
+	ljmp $(__BOOT_CS), $KERN_PHYS_OFFSET
 
 /*
  * We come here, if we were loaded high.
@@ -99,7 +99,7 @@ startup_32:
 	popl %ecx	# lcount
 	popl %edx	# high_buffer_start
 	popl %eax	# hcount
-	movl $0x100000,%edi
+	movl $KERN_PHYS_OFFSET,%edi
 	cli		# make sure we don't get interrupted
 	ljmp $(__BOOT_CS), $0x1000 # and jump to the move routine
 
@@ -124,5 +124,5 @@ move_routine_start:
 	movsl
 	movl %ebx,%esi	# Restore setup pointer
 	xorl %ebx,%ebx
-	ljmp $(__BOOT_CS), $0x100000
+	ljmp $(__BOOT_CS), $KERN_PHYS_OFFSET
 move_routine_end:
arch/i386/boot/compressed/misc.c renamed from arch/i386/boot/compressed/misc.c~kd-kern-offset +4 -3
diff -puN arch/i386/boot/compressed/misc.c~kd-kern-offset arch/i386/boot/compressed/misc.c
@@ -14,6 +14,7 @@
 #include <linux/tty.h>
 #include <video/edid.h>
 #include <asm/io.h>
+#include <asm/segment.h>
 
 /*
  * gzip declarations
@@ -309,7 +310,7 @@ static void setup_normal_output_buffer(v
 #else
 	if ((RM_ALT_MEM_K > RM_EXT_MEM_K ? RM_ALT_MEM_K : RM_EXT_MEM_K) < 1024) error("Less than 2MB of memory");
 #endif
-	output_data = (char *)0x100000; /* Points to 1M */
+	output_data = (char *)KERN_PHYS_OFFSET; /* Points to 1M */
 	free_mem_end_ptr = (long)real_mode;
 }
 
@@ -334,8 +335,8 @@ static void setup_output_buffer_if_we_ru
 	low_buffer_size = low_buffer_end - LOW_BUFFER_START;
 	high_loaded = 1;
 	free_mem_end_ptr = (long)high_buffer_start;
-	if ( (0x100000 + low_buffer_size) > ((ulg)high_buffer_start)) {
-		high_buffer_start = (uch *)(0x100000 + low_buffer_size);
+	if ( (KERN_PHYS_OFFSET + low_buffer_size) > ((ulg)high_buffer_start)) {
+		high_buffer_start = (uch *)(KERN_PHYS_OFFSET + low_buffer_size);
 		mv->hcount = 0; /* say: we need not to move high_buffer */
 	}
 	else mv->hcount = -1;
include/asm-i386/segment.h renamed from include/asm-i386/segment.h~kd-kern-offset +2 -0
diff -puN include/asm-i386/segment.h~kd-kern-offset include/asm-i386/segment.h
@@ -95,4 +95,6 @@
  */
 #define IDT_ENTRIES 256
 
+#define KERN_PHYS_OFFSET (CONFIG_KERN_PHYS_OFFSET * 0x100000)
+
 #endif
include/asm-generic/vmlinux.lds.h renamed from include/asm-generic/vmlinux.lds.h~kd-kern-offset +1 -1
diff -puN include/asm-generic/vmlinux.lds.h~kd-kern-offset include/asm-generic/vmlinux.lds.h
@@ -70,7 +70,7 @@
 	}
 
 #define SECURITY_INIT							\
-	.security_initcall.init : {					\
+	.security_initcall.init : AT(ADDR(.security_initcall.init) - LOAD_OFFSET) {\
 		VMLINUX_SYMBOL(__security_initcall_start) = .;		\
 		*(.security_initcall.init) 				\
 		VMLINUX_SYMBOL(__security_initcall_end) = .;		\
arch/i386/kernel/vmlinux.lds.S renamed from arch/i386/kernel/vmlinux.lds.S~kd-kern-offset +34 -22

135 lines not on this page · raw message

_

#2 lore raw

Re: [PATCH][2/4] kexec: Enable co-existence of normal kexec Image and kexec on panic Image

This patch, to kexec, makes it possible to separate out the two uses of kexec - for normal kexec usage and kexec-on-panic. The image for the panic case is loaded using the "kexec -p" option instead of "kexec -l".

Regards, Hari

---

 linux-kexec-hari/include/linux/kexec.h |    1 +
 linux-kexec-hari/kernel/kexec.c        |   13 +++++--------
 2 files changed, 6 insertions(+), 8 deletions(-)
include/linux/kexec.h renamed from include/linux/kexec.h~kexec-panic +1 -0
diff -puN include/linux/kexec.h~kexec-panic include/linux/kexec.h
@@ -52,5 +52,6 @@ extern asmlinkage long sys_kexec(unsigne
 	struct kexec_segment *segments);
 extern struct page *kimage_alloc_control_pages(struct kimage *image, unsigned int order);
 extern struct kimage *kexec_image;
+extern struct kimage *kexec_crash_image;
 #endif
 #endif /* LINUX_KEXEC_H */
kernel/kexec.c renamed from kernel/kexec.c~kexec-panic +5 -8
diff -puN kernel/kexec.c~kexec-panic kernel/kexec.c
@@ -585,6 +585,7 @@ static int kimage_load_segment(struct ki
  * that to happen you need to do that yourself.
  */
 struct kimage *kexec_image = NULL;
+struct kimage *kexec_crash_image = NULL;
 
 asmlinkage long sys_kexec_load(unsigned long entry, unsigned long nr_segments,
 	struct kexec_segment *segments, unsigned long flags)
@@ -596,13 +597,6 @@ asmlinkage long sys_kexec_load(unsigned 
 	if (!capable(CAP_SYS_BOOT))
 		return -EPERM;
 
-	/*
-	 * In case we need just a little bit of special behavior for
-	 * reboot on panic.
-	 */
-	if (flags != 0)
-		return -EINVAL;
-
 	if (nr_segments > KEXEC_SEGMENT_MAX)
 		return -EINVAL;
 
@@ -632,7 +626,10 @@ asmlinkage long sys_kexec_load(unsigned 
 		}
 	}
 
-	image = xchg(&kexec_image, image);
+	if (!flags)
+		image = xchg(&kexec_image, image);
+	else
+		image = xchg(&kexec_crash_image, image);
 
  out:
 	kimage_free(image);

_

#3 lore raw

Re: [PATCH][3/4] kexec based dump: Minor bug fixes

This patch fixes a problem where the kernel compilation was failing upon disabling PROC_FS. It also ensures the reboot-on-panic kernel is pointed to by a different variable, thereby separating the normal use of kexec from the crashdump situation.

Regards, Hari

---

 linux-2.6.9-rc4-hari/Documentation/kdump.txt    |   24 ++++++++----------------
 linux-2.6.9-rc4-hari/include/linux/crash_dump.h |   11 ++++++++---
 linux-2.6.9-rc4-hari/kernel/crash.c             |    5 ++++-
 3 files changed, 20 insertions(+), 20 deletions(-)
Documentation/kdump.txt renamed from Documentation/kdump.txt~kd-misc-changes +8 -16
diff -puN Documentation/kdump.txt~kd-misc-changes Documentation/kdump.txt
@@ -27,19 +27,11 @@ SETUP
 1) Obtain the appropriate -mm tree patch and apply it on to the vanilla
    kernel tree.
 
-2) In order to enable the kernel to boot from a non-default location, the
-   following patches (by Eric Biederman) needs to be applied.
-
-   http://www.xmission.com/~ebiederm/files/kexec/2.6.8.1-kexec3/
-	broken-out/highbzImage.i386.patch
-   http://www.xmission.com/~ebiederm/files/kexec/2.6.8.1-kexec3/
-	broken-out/vmlinux-lds.i386.patch
-
-3) Two kernels need to be built in order to get this feature working.
+2) Two kernels need to be built in order to get this feature working.
 
    For the first kernel, choose the default values for the following options.
 
-   a) Physical address where the kernel expects to be loaded
+   a) Physical address where the kernel is loaded
    b) kexec system call
    c) kernel crash dumps
 
@@ -51,28 +43,28 @@ SETUP
 
    Also ensure you have CONFIG_HIGHMEM on.
 
-4) Boot into the first kernel. You are now ready to try out kexec based crash
+3) Boot into the first kernel. You are now ready to try out kexec based crash
    dumps.
 
-5) Load the second kernel to be booted using
+4) Load the second kernel to be booted using
 
-   kexec -l <second-kernel> --args-linux --append="root=<root-dev> dump
+   kexec -p <second-kernel> --args-linux --append="root=<root-dev> dump
    init 1 memmap=exactmap memmap=640k@0 memmap=32M@16M"
 
    Note that <second-kernel> has to be a vmlinux image. bzImage will not
    work, as of now.
 
-6) Enable kexec based dumping by
+5) Enable kexec based dumping by
 
    echo 1 > /proc/kexec-dump
 
    If this is not set, the system will not do a kexec reboot in the event
    of a panic.
 
-7) System reboots into the second kernel when a panic occurs.
+6) System reboots into the second kernel when a panic occurs.
    You could write a module to call panic, for testing purposes.
 
-8) Write out the dump file using
+7) Write out the dump file using
 
    cp /proc/vmcore <dump-file>
 
include/linux/crash_dump.h renamed from include/linux/crash_dump.h~kd-misc-changes +8 -3
diff -puN include/linux/crash_dump.h~kd-misc-changes include/linux/crash_dump.h
@@ -15,15 +15,20 @@ extern void elf_kcore_store_hdr(char *, 
 #ifdef CONFIG_CRASH_DUMP
 extern ssize_t copy_oldmem_page(unsigned long, char *, size_t, int);
 extern void __crash_machine_kexec(void);
-extern void crash_enable_by_proc(void);
-extern void crash_create_proc_entry(void);
 extern int crash_dump_on;
 static inline void crash_machine_kexec(void)
 {
 	 __crash_machine_kexec();
 }
 #else
+#define crash_machine_kexec()	do { } while(0)
+#endif
+
+
+#if defined(CONFIG_CRASH_DUMP) && defined(CONFIG_PROC_FS)
+extern void crash_enable_by_proc(void);
+extern void crash_create_proc_entry(void);
+#else
 #define crash_enable_by_proc() do { } while(0)
 #define crash_create_proc_entry() do { } while(0)
-#define crash_machine_kexec()	do { } while(0)
 #endif
kernel/crash.c renamed from kernel/crash.c~kd-misc-changes +4 -1
diff -puN kernel/crash.c~kd-misc-changes kernel/crash.c
@@ -16,6 +16,7 @@
 #include <asm/io.h>
 #include <asm/uaccess.h>
 
+#ifdef CONFIG_PROC_FS
 /*
  * Enable kexec reboot upon panic; for dumping
  */
@@ -57,6 +58,8 @@ void crash_create_proc_entry(void)
 	}
 }
 
+#endif /* CONFIG_PROC_FS */
+
 void __crash_machine_kexec(void)
 {
 	struct kimage *image;
@@ -64,7 +67,7 @@ void __crash_machine_kexec(void)
 	if ((!crash_dump_on) || (crashed))
 		return;
 
-	image = xchg(&kexec_image, 0);
+	image = xchg(&kexec_crash_image, 0);
 	if (image) {
 		crashed = 1;
 		printk(KERN_EMERG "kexec: opening parachute\n");

_

#4 lore raw

Re: [PATCH][4/4] kexec based dump: Minor cleanups

This patch moves some crashdump related calls out of machine_kexec so that we leave the core kexec code untouched.

Regards, Hari

---

 linux-2.6.9-rc4-hari/arch/i386/kernel/machine_kexec.c |   10 ----------
 linux-2.6.9-rc4-hari/kernel/crash.c                   |    9 +++++++++
 2 files changed, 9 insertions(+), 10 deletions(-)
arch/i386/kernel/machine_kexec.c renamed from arch/i386/kernel/machine_kexec.c~kd-cleanup +0 -10
diff -puN arch/i386/kernel/machine_kexec.c~kd-cleanup arch/i386/kernel/machine_kexec.c
@@ -195,9 +195,6 @@ void machine_kexec(struct kimage *image)
 	unsigned long reboot_code_buffer;
 	relocate_new_kernel_t rnk;
 
-	crash_dump_stop_cpus();
-	crash_dump_save_registers();
-
 	/* Interrupts aren't acceptable while we reboot */
 	local_irq_disable();
 
@@ -208,13 +205,6 @@ void machine_kexec(struct kimage *image)
 	/* Set up an identity mapping for the reboot_code_buffer */
 	identity_map_page(reboot_code_buffer);
 
-	/*
-	 * If we are here to do a crash dump, save the memory from
-	 * 0-640k before we copy over the kexec kernel image.  Otherwise
-	 * our dump will show the wrong kernel entirely.
-	 */
-	crash_relocate_mem();
-
 	/* copy it out */
 	memcpy((void *)reboot_code_buffer, relocate_new_kernel, relocate_new_kernel_size);
 
kernel/crash.c renamed from kernel/crash.c~kd-cleanup +9 -0
diff -puN kernel/crash.c~kd-cleanup kernel/crash.c
@@ -71,6 +71,15 @@ void __crash_machine_kexec(void)
 	if (image) {
 		crashed = 1;
 		printk(KERN_EMERG "kexec: opening parachute\n");
+		crash_dump_stop_cpus();
+		crash_dump_save_registers();
+
+         /* If we are here to do a crash dump, save the memory from
+          * 0-640k before we copy over the kexec kernel image.  Otherwise
+          * our dump will show the wrong kernel entirely.
+          */
+        	crash_relocate_mem();
+
 		machine_kexec(image);
 	} else {
 		printk(KERN_EMERG "kexec: No kernel image loaded!\n");

_