Skip to contentSkip to conversation

kexec based crash dumping

PATCH In review Hariprasad Nellitheertha 5 participants 20 messages Sep 15, 2004 – Sep 20, 2004

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

Hi Andrew,

The patches that follow contain the kexec based crash dumping implementation. Based on feedback received last time, we have made several changes. Some of them are:

- The dumping kernel now boots from a non-default location. This is possible due to Eric's patch which allows i386 kernels to boot from a non-default location. This change means that we need two different kernels to get this setup. The documentation patch has complete details on how to do this.
- We can now choose whether or not to dump from panic. The documentation patch has details on this as well.
- The linear view is now called oldmem.
- Changes as per the code review comments from the previous posting.

The patches correspond to 2.6.9-rc1-mm5.

Kindly review these patches and let me know your thoughts.

Regards, Hari

Signature · 4 lines
Hariprasad Nellitheertha
Linux Technology Center
India Software Labs
IBM India, Bangalore
#1 lore raw

PATCH 1/6 Documentation

Regards, Hari

Signature · 4 lines
Hariprasad Nellitheertha
Linux Technology Center
India Software Labs
IBM India, Bangalore

This patch contains the documentation for the kexec based crash dump tool.

Signed off by Hariprasad Nellitheertha <[email protected]>

---

 linux-2.6.9-rc1-hari/Documentation/kdump.txt |  133 +++++++++++++++++++++++++++
 1 files changed, 133 insertions(+)
Documentation/kdump.txt new file +133 -0
diff -puN /dev/null Documentation/kdump.txt
@@ -0,0 +1,133 @@
+Documentation for kdump - the kexec based crash dumping solution
+================================================================
+
+DESIGN
+======
+
+We use kexec to reboot to a second kernel whenever a dump needs to be taken.
+This second kernel is booted with with very little memory (configurable
+at compile time). The first kernel reserves the section of memory that the
+second kernel uses. This ensures that on-going DMA from the first kernel
+does not corrupt the second kernel. The first 640k of physical memory is
+needed irrespective of where the kernel loads at. Hence, this region is
+backed up before reboot.
+
+In the second kernel, "old memory" can be accessed in two ways. The
+first one is through a device interface. We can create a /dev/oldmem or
+whatever and write out the memory in raw format. The second interface is
+through /proc/vmcore. This exports the dump as an ELF format file which
+can be written out using any file copy command (cp, scp, etc). Further, gdb
+can be used to perform some minimal debugging on the dump file. Both these
+methods ensure that there is correct ordering of the dump pages (corresponding
+to the first 640k that has been relocated).
+
+Note that the two approaches are independent and the patches
+can be used depending on the functionality needed. More details on the
+patches below.
+
+PATCHES
+=======
+
+We currently have 6 patches.
+
+1) kd-doc-<version>.patch - Contains basic documentation (this document!!)
+2) kd-reb-<version>.patch - This patch ensures we do a kexec reboot upon panic
+   and also saves the necessary regions of  memory into a backup area
+3) kd-copy-<version>.patch - This contains the code for reading the dump pages
+   in the second kernel.
+4) kd-reg-<version>.patch - This patch is for snapshotting the register contents
+   of all processors on to the backup area before rebooting.
+5) kd-elf-<version>.patch - This patch provides an ELF format interface to
+   the dump, post-reboot.
+6) kd-oldmem-<version>.patch - This patch contains the code to access the dump as
+   an /dev/oldmem.
+
+SETUP
+=====
+
+1) Apply the appropriate -mm patch on to the vanilla kernel tree. The -mm
+   tree has the kexec patches included.
+
+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) Apply the crash dump patches.
+
+4) 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
+   b) kexec system call
+   c) kernel crash dumps
+
+   All the options are under "Processor type and features"
+
+   For the second kernel, change (a) to 16MB. If you want to choose another
+   value here, ensure "location of the crash dumps backup region" under (c)
+   reflects the same value.
+
+   Also ensure you have CONFIG_HIGHMEM on.
+
+5) 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
+
+   kexec -l <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
+
+   echo 1 > /proc/kexec-dump
+
+7) 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
+
+   cp /proc/vmcore <dump-file>
+
+You can also access the dump as a device for a linear/raw view. To do this,
+you will need the kd-oldmem-<version>.patch built into the kernel. To create
+the device, type
+
+  mknod /dev/oldmem c 1 12
+
+Use "dd" with suitable options for count, bs and skip to access specific
+portions of the dump.
+
+ANALYSIS
+========
+
+You can run gdb on the dump file copied out of /proc/vmcore. Use vmlinux built
+with -g and run
+
+  gdb vmlinux <dump-file>
+
+Stack trace for the task on processor 0, register display, memory display
+work fine.
+
+TODO
+====
+
+1) Provide a kernel-pages only view for the dump. This could possibly turn up
+   as /proc/vmcore-kern.
+2) Provide register contents of all processors (similar to what multi-threaded
+   core dumps does).
+3) Modify "crash" to make it recognize this dump.
+4) Make the i386 kernel boot from any location so we can run the second kernel
+   from the reserved location instead of the current approach.
+
+CONTACT
+=======
+
+Hariprasad Nellitheertha - hari at in dot ibm dot com

_

#2 lore raw

Re: [PATCH][2/6]Memory preserving reboot using kexec

Regards, Hari

Signature · 4 lines
Hariprasad Nellitheertha
Linux Technology Center
India Software Labs
IBM India, Bangalore

This patch contains the code that does the memory preserving reboot. It copies over the first 640k into a backup region before handing over to kexec. The second kernel will boot using only the backup region.

Signed off by Hariprasad Nellitheertha <[email protected]> Signed off by Adam Litke <[email protected]>

---

 linux-2.6.9-rc1-hari/arch/i386/Kconfig                |   20 ++++++++
 linux-2.6.9-rc1-hari/arch/i386/kernel/machine_kexec.c |   31 ++++++++++++
 linux-2.6.9-rc1-hari/arch/i386/kernel/setup.c         |   13 +++++
 linux-2.6.9-rc1-hari/fs/proc/proc_misc.c              |   25 ++++++++++
 linux-2.6.9-rc1-hari/include/asm-i386/crash_dump.h    |   44 ++++++++++++++++++
 linux-2.6.9-rc1-hari/include/linux/bootmem.h          |    1 
 linux-2.6.9-rc1-hari/include/linux/crash_dump.h       |   28 +++++++++++
 linux-2.6.9-rc1-hari/kernel/panic.c                   |    7 ++
 linux-2.6.9-rc1-hari/mm/bootmem.c                     |    5 ++
 9 files changed, 174 insertions(+)
arch/i386/Kconfig renamed from arch/i386/Kconfig~kd-reb-269rc1-mm5 +20 -0
diff -puN arch/i386/Kconfig~kd-reb-269rc1-mm5 arch/i386/Kconfig
@@ -894,6 +894,26 @@ config KEXEC
 	  support.  As of this writing the exact hardware interface is
 	  strongly in flux, so no good recommendation can be made.
 
+config CRASH_DUMP
+	bool "kernel crash dumps (EXPERIMENTAL)"
+	depends on KEXEC
+	help
+	  Generate crash dump using kexec.
+
+config BACKUP_BASE
+	int "location of the crash dumps backup region"
+	depends on CRASH_DUMP
+	default 16
+	help
+	This is the location where the second kernel will boot from.
+
+config BACKUP_SIZE
+	int "Size of the crash dumps backup region"
+	depends on CRASH_DUMP
+	range 16 64
+	default 32
+	help
+	The size of the second kernel's memory.
 endmenu
 
 
arch/i386/kernel/setup.c renamed from arch/i386/kernel/setup.c~kd-reb-269rc1-mm5 +13 -0
diff -puN arch/i386/kernel/setup.c~kd-reb-269rc1-mm5 arch/i386/kernel/setup.c
@@ -39,6 +39,7 @@
 #include <linux/efi.h>
 #include <linux/init.h>
 #include <linux/edd.h>
+#include <linux/crash_dump.h>
 #include <video/edid.h>
 #include <asm/e820.h>
 #include <asm/mpspec.h>
@@ -57,6 +58,7 @@
 unsigned long init_pg_tables_end __initdata = ~0UL;
 
 int disable_pse __initdata = 0;
+unsigned int dump_enabled;
 
 /*
  * Machine setup..
@@ -708,6 +710,11 @@ static void __init parse_cmdline_early (
 			if (to != command_line)
 				to--;
 			if (!memcmp(from+7, "exactmap", 8)) {
+				/* If we are doing a crash dump, we
+				 * still need to know the real mem
+				 * size.
+				 */
+				set_saved_max_pfn();
 				from += 8+7;
 				e820.nr_map = 0;
 				userdef = 1;
@@ -815,6 +822,9 @@ static void __init parse_cmdline_early (
 		if (c == ' ' && !memcmp(from, "highmem=", 8))
 			highmem_pages = memparse(from+8, &from) >> PAGE_SHIFT;
 	
+		if (!memcmp(from, "dump", 4))
+			dump_enabled = 1;
+
 		c = *(from++);
 		if (!c)
 			break;
@@ -1102,6 +1112,9 @@ static unsigned long __init setup_memory
 		}
 	}
 #endif
+
+	crash_reserve_bootmem();
+
 	return max_low_pfn;
 }
 #else
include/asm-i386/crash_dump.h new file +44 -0

44 lines not on this page · raw message

include/linux/bootmem.h renamed from include/linux/bootmem.h~kd-reb-269rc1-mm5 +1 -0
diff -puN include/linux/bootmem.h~kd-reb-269rc1-mm5 include/linux/bootmem.h
@@ -21,6 +21,7 @@ extern unsigned long min_low_pfn;
  * highest page
  */
 extern unsigned long max_pfn;
+extern unsigned long saved_max_pfn;
 
 /*
  * node_bootmem_map is a map pointer - the bits represent all physical 
include/linux/crash_dump.h new file +28 -0
diff -puN /dev/null include/linux/crash_dump.h
@@ -0,0 +1,28 @@
+#include <linux/kexec.h>
+#include <linux/smp_lock.h>
+#include <linux/device.h>
+#include <asm/crash_dump.h>
+
+#ifdef CONFIG_CRASH_DUMP
+extern int crash_dump_on;
+static inline void crash_machine_kexec(void)
+{
+	struct kimage *image;
+
+	if ((!crash_dump_on) || (crashed))
+		return;
+
+	image = xchg(&kexec_image, 0);
+	if (image) {
+		crashed = 1;
+		device_shutdown();
+		printk(KERN_EMERG "kexec: opening parachute\n");
+		machine_kexec(image);
+		while (1);
+	} else {
+		printk(KERN_EMERG "kexec: No kernel image loaded!\n");
+	}
+}
+#else
+#define crash_machine_kexec()	do { } while(0)
+#endif
kernel/panic.c renamed from kernel/panic.c~kd-reb-269rc1-mm5 +7 -0
diff -puN kernel/panic.c~kd-reb-269rc1-mm5 kernel/panic.c
@@ -19,10 +19,14 @@
 #include <linux/syscalls.h>
 #include <linux/interrupt.h>
 #include <linux/nmi.h>
+#include <linux/kexec.h>
+#include <linux/crash_dump.h>
 
 int panic_timeout;
 int panic_on_oops;
 int tainted;
+unsigned int crashed;
+int crash_dump_on;
 
 EXPORT_SYMBOL(panic_timeout);
 
@@ -62,6 +66,9 @@ NORET_TYPE void panic(const char * fmt, 
 	printk(KERN_EMERG "Kernel panic - not syncing: %s\n",buf);
 	bust_spinlocks(0);
 
+	/* If we have crashed, perform a kexec reboot, for dump write-out */
+	crash_machine_kexec();
+
 #ifdef CONFIG_SMP
 	smp_send_stop();
 #endif
mm/bootmem.c renamed from mm/bootmem.c~kd-reb-269rc1-mm5 +5 -0
diff -puN mm/bootmem.c~kd-reb-269rc1-mm5 mm/bootmem.c
@@ -27,6 +27,11 @@
 unsigned long max_low_pfn;
 unsigned long min_low_pfn;
 unsigned long max_pfn;
+/*
+ * If we have booted due to a crash, max_pfn will be a very low value. We need
+ * to know the amount of memory that the previous kernel used.
+ */
+unsigned long saved_max_pfn;
 
 EXPORT_SYMBOL(max_pfn);		/* This is exported so
 				 * dma_get_required_mask(), which uses
fs/proc/proc_misc.c renamed from fs/proc/proc_misc.c~kd-reb-269rc1-mm5 +25 -0
diff -puN fs/proc/proc_misc.c~kd-reb-269rc1-mm5 fs/proc/proc_misc.c
@@ -44,6 +44,7 @@
 #include <linux/jiffies.h>
 #include <linux/sysrq.h>
 #include <linux/vmalloc.h>
+#include <linux/crash_dump.h>
 #include <asm/uaccess.h>
 #include <asm/pgtable.h>
 #include <asm/io.h>
@@ -563,6 +564,25 @@ static struct file_operations proc_sysrq
 };
 #endif
 
+#ifdef CONFIG_CRASH_DUMP
+/*
+ * Enable kexec reboot upon panic; for dumping
+ */
+static ssize_t write_crash_dump_on(struct file *file, const char __user *buf,
+					size_t count, loff_t *ppos)
+{
+	if (count) {
+		if (get_user(crash_dump_on, buf))
+			return -EFAULT;
+	}
+	return count;
+}
+
+static struct file_operations proc_crash_dump_on_operations = {
+	.write		= write_crash_dump_on,
+};
+#endif
+
 struct proc_dir_entry *proc_root_kcore;
 
 static void create_seq_entry(char *name, mode_t mode, struct file_operations *f)
@@ -663,6 +683,11 @@ void __init proc_misc_init(void)
 	if (entry)
 		entry->proc_fops = &proc_sysrq_trigger_operations;
 #endif
+#ifdef CONFIG_CRASH_DUMP
+	entry = create_proc_entry("kexec-dump", S_IWUSR, NULL);
+	if (entry)
+		entry->proc_fops = &proc_crash_dump_on_operations;
+#endif
 #ifdef CONFIG_LOCKMETER
 	entry = create_proc_entry("lockmeter", S_IWUSR | S_IRUGO, NULL);
 	if (entry) {
arch/i386/kernel/machine_kexec.c renamed from arch/i386/kernel/machine_kexec.c~kd-reb-269rc1-mm5 +31 -0
diff -puN arch/i386/kernel/machine_kexec.c~kd-reb-269rc1-mm5 arch/i386/kernel/machine_kexec.c
@@ -161,6 +161,30 @@ void machine_kexec_cleanup(struct kimage
 }
 
 /*
+ * We are going to do a memory preserving reboot. So, we copy over the
+ * first 640k of memory into a backup location. Though the second kernel
+ * boots from a different location, it still requires the first 640k.
+ * Hence this backup.
+ */
+void __crash_relocate_mem(unsigned long backup_addr, unsigned long backup_size)
+{
+	unsigned long pfn, pfn_max;
+	void *src_addr, *dest_addr;
+	struct page *page;
+
+	pfn_max = backup_size >> PAGE_SHIFT;
+	for (pfn = 0; pfn < pfn_max; pfn++) {
+		src_addr = phys_to_virt(pfn << PAGE_SHIFT);
+		dest_addr = backup_addr + src_addr;
+		if (!pfn_valid(pfn))
+			continue;
+		page = pfn_to_page(pfn);
+		if (PageReserved(page))
+			copy_page(dest_addr, src_addr);
+	}
+}
+
+/*
  * Do not allocate memory (or fail in any way) in machine_kexec().
  * We are past the point of no return, committed to rebooting now.
  */
@@ -180,6 +204,13 @@ 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);
 

_

#3 lore raw

Re: [PATCH][3/6]Routines for copying the dump pages

Regards, Hari

Signature · 4 lines
Hariprasad Nellitheertha
Linux Technology Center
India Software Labs
IBM India, Bangalore

This patch provides the interfaces necessary to read the dump contents, treating it as a high memory device.

Signed off by Hariprasad Nellitheertha <[email protected]>

---

 linux-2.6.9-rc1-hari/arch/i386/mm/highmem.c     |   18 +++++++++++++
 linux-2.6.9-rc1-hari/include/asm-i386/highmem.h |    1 
 linux-2.6.9-rc1-hari/include/linux/highmem.h    |   31 ++++++++++++++++++++++++
 3 files changed, 50 insertions(+)
arch/i386/mm/highmem.c renamed from arch/i386/mm/highmem.c~kd-copy-269rc1-mm5 +18 -0
diff -puN arch/i386/mm/highmem.c~kd-copy-269rc1-mm5 arch/i386/mm/highmem.c
@@ -74,6 +74,24 @@ void kunmap_atomic(void *kvaddr, enum km
 	preempt_check_resched();
 }
 
+/* This is the same as kmap_atomic() but can map memory that doesn't
+ * have a struct page associated with it.
+ */
+void *kmap_atomic_pfn(unsigned long pfn, enum km_type type)
+{
+        enum fixed_addresses idx;
+        unsigned long vaddr;
+
+        inc_preempt_count();
+
+        idx = type + KM_TYPE_NR*smp_processor_id();
+        vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
+        set_pte(kmap_pte-idx, pfn_pte(pfn, kmap_prot));
+        __flush_tlb_one(vaddr);
+
+        return (void*) vaddr;
+}
+
 struct page *kmap_atomic_to_page(void *ptr)
 {
 	unsigned long idx, vaddr = (unsigned long)ptr;
include/asm-i386/highmem.h renamed from include/asm-i386/highmem.h~kd-copy-269rc1-mm5 +1 -0
diff -puN include/asm-i386/highmem.h~kd-copy-269rc1-mm5 include/asm-i386/highmem.h
@@ -61,6 +61,7 @@ void *kmap(struct page *page);
 void kunmap(struct page *page);
 void *kmap_atomic(struct page *page, enum km_type type);
 void kunmap_atomic(void *kvaddr, enum km_type type);
+void *kmap_atomic_pfn(unsigned long pfn, enum km_type type);
 struct page *kmap_atomic_to_page(void *ptr);
 
 #define flush_cache_kmaps()	do { } while (0)
include/linux/highmem.h renamed from include/linux/highmem.h~kd-copy-269rc1-mm5 +31 -0
diff -puN include/linux/highmem.h~kd-copy-269rc1-mm5 include/linux/highmem.h
@@ -6,6 +6,7 @@
 #include <linux/mm.h>
 
 #include <asm/cacheflush.h>
+#include <asm/uaccess.h>
 
 #ifdef CONFIG_HIGHMEM
 
@@ -30,6 +31,7 @@ static inline void *kmap(struct page *pa
 
 #define kmap_atomic(page, idx)		page_address(page)
 #define kunmap_atomic(addr, idx)	do { } while (0)
+#define kmap_atomic_pfn(pfn, idx)	page_address(pfn_to_page(pfn))
 #define kmap_atomic_to_page(ptr)	virt_to_page(ptr)
 
 #endif /* CONFIG_HIGHMEM */
@@ -86,4 +88,33 @@ static inline void copy_highpage(struct 
 	kunmap_atomic(vto, KM_USER1);
 }
 
+/*
+ * Copy a page from "oldmem". For this page, there is no pte mapped
+ * in the current kernel. We stitch up a pte, similar to kmap_atomic.
+ */
+static inline ssize_t copy_oldmem_page(unsigned long pfn,
+			char *buf, size_t csize, int userbuf)
+{
+        void *page, *vaddr;
+
+        if (!csize)
+                return 0;
+
+        page = kmalloc(PAGE_SIZE, GFP_KERNEL);
+
+        vaddr = kmap_atomic_pfn(pfn, KM_PTE0);
+        copy_page(page, vaddr);
+        kunmap_atomic(vaddr, KM_PTE0);
+
+        if (userbuf) {
+                if (copy_to_user(buf, page, csize)) {
+                        kfree(page);
+                        return -EFAULT;
+                }
+        } else
+                memcpy(buf, page, csize);
+        kfree(page);
+
+        return 0;
+}
 #endif /* _LINUX_HIGHMEM_H */

_

#4 lore raw

Re: [PATCH][4/6]Register snapshotting before kexec boot

Regards, Hari

Signature · 4 lines
Hariprasad Nellitheertha
Linux Technology Center
India Software Labs
IBM India, Bangalore

This patch contains the code for stopping the other cpus and snapshotting their register values before doing the kexec reboot.

Signed off by Hariprasad Nellitheertha <[email protected]>

---

 linux-2.6.9-rc1-hari/arch/i386/kernel/Makefile                   |    1 
 linux-2.6.9-rc1-hari/arch/i386/kernel/crash_dump.c               |  101 ++++++++++
 linux-2.6.9-rc1-hari/arch/i386/kernel/machine_kexec.c            |    4 
 linux-2.6.9-rc1-hari/arch/i386/kernel/smp.c                      |   13 +
 linux-2.6.9-rc1-hari/include/asm-i386/crash_dump.h               |   41 +++-
 linux-2.6.9-rc1-hari/include/asm-i386/mach-default/irq_vectors.h |    1 
 linux-2.6.9-rc1-hari/include/asm-i386/smp.h                      |    1 
 7 files changed, 160 insertions(+), 2 deletions(-)
arch/i386/kernel/Makefile renamed from arch/i386/kernel/Makefile~kd-reg-269rc1-mm5 +1 -0
diff -puN arch/i386/kernel/Makefile~kd-reg-269rc1-mm5 arch/i386/kernel/Makefile
@@ -25,6 +25,7 @@ obj-$(CONFIG_X86_MPPARSE)	+= mpparse.o
 obj-$(CONFIG_X86_LOCAL_APIC)	+= apic.o nmi.o
 obj-$(CONFIG_X86_IO_APIC)	+= io_apic.o
 obj-$(CONFIG_KEXEC)		+= machine_kexec.o relocate_kernel.o
+obj-$(CONFIG_CRASH_DUMP)	+= crash_dump.o
 obj-$(CONFIG_X86_NUMAQ)		+= numaq.o
 obj-$(CONFIG_X86_SUMMIT_NUMA)	+= summit.o
 obj-$(CONFIG_KPROBES)		+= kprobes.o
arch/i386/kernel/crash_dump.c new file +101 -0

101 lines not on this page · raw message

arch/i386/kernel/machine_kexec.c renamed from arch/i386/kernel/machine_kexec.c~kd-reg-269rc1-mm5 +4 -0
diff -puN arch/i386/kernel/machine_kexec.c~kd-reg-269rc1-mm5 arch/i386/kernel/machine_kexec.c
@@ -9,6 +9,7 @@
 #include <linux/mm.h>
 #include <linux/kexec.h>
 #include <linux/delay.h>
+#include <linux/crash_dump.h>
 #include <asm/pgtable.h>
 #include <asm/pgalloc.h>
 #include <asm/tlbflush.h>
@@ -194,6 +195,9 @@ 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();
 
arch/i386/kernel/smp.c renamed from arch/i386/kernel/smp.c~kd-reg-269rc1-mm5 +12 -1
diff -puN arch/i386/kernel/smp.c~kd-reg-269rc1-mm5 arch/i386/kernel/smp.c
@@ -143,6 +143,9 @@ void __send_IPI_shortcut(unsigned int sh
 	 */
 	cfg = __prepare_ICR(shortcut, vector);
 
+	if (vector == CRASH_DUMP_VECTOR)
+		cfg = (cfg&~APIC_VECTOR_MASK)|APIC_DM_NMI;
+
 	/*
 	 * Send the IPI. The write to APIC_ICR fires this off.
 	 */
@@ -221,6 +224,9 @@ inline void send_IPI_mask_sequence(cpuma
 			 */
 			cfg = __prepare_ICR(0, vector);
 			
+			if (vector == CRASH_DUMP_VECTOR)
+				cfg = (cfg&~APIC_VECTOR_MASK)|APIC_DM_NMI;
+
 			/*
 			 * Send the IPI. The write to APIC_ICR fires this off.
 			 */
@@ -489,6 +495,11 @@ void smp_send_reschedule(int cpu)
 	send_IPI_mask(cpumask_of_cpu(cpu), RESCHEDULE_VECTOR);
 }
 
+void crash_dump_send_ipi(void)
+{
+	send_IPI_allbutself(CRASH_DUMP_VECTOR);
+}
+
 /*
  * Structure and data for smp_call_function(). This is designed to minimise
  * static memory requirements. It also looks cleaner.
@@ -565,7 +576,7 @@ int smp_call_function (void (*func) (voi
 	return 0;
 }
 
-static void stop_this_cpu (void * dummy)
+void stop_this_cpu (void * dummy)
 {
 	/*
 	 * Remove this CPU:
include/asm-i386/crash_dump.h renamed from include/asm-i386/crash_dump.h~kd-reg-269rc1-mm5 +40 -1

64 lines not on this page · raw message

include/asm-i386/mach-default/irq_vectors.h renamed from include/asm-i386/mach-default/irq_vectors.h~kd-reg-269rc1-mm5 +1 -0
diff -puN include/asm-i386/mach-default/irq_vectors.h~kd-reg-269rc1-mm5 include/asm-i386/mach-default/irq_vectors.h
@@ -48,6 +48,7 @@
 #define INVALIDATE_TLB_VECTOR	0xfd
 #define RESCHEDULE_VECTOR	0xfc
 #define CALL_FUNCTION_VECTOR	0xfb
+#define CRASH_DUMP_VECTOR	0xfa
 
 #define THERMAL_APIC_VECTOR	0xf0
 /*
include/asm-i386/smp.h renamed from include/asm-i386/smp.h~kd-reg-269rc1-mm5 +1 -0
diff -puN include/asm-i386/smp.h~kd-reg-269rc1-mm5 include/asm-i386/smp.h
@@ -41,6 +41,7 @@ extern void smp_message_irq(int cpl, voi
 extern void smp_invalidate_rcv(void);		/* Process an NMI */
 extern void (*mtrr_hook) (void);
 extern void zap_low_mappings (void);
+extern void stop_this_cpu(void *);
 
 #define MAX_APICID 256
 extern u8 x86_cpu_to_apicid[];

_

#5 lore raw

Re: [PATCH][5/6]ELF format dump file access

Regards, Hari

Signature · 4 lines
Hariprasad Nellitheertha
Linux Technology Center
India Software Labs
IBM India, Bangalore

This patch contains the code that provides an ELF format interface to the previous kernel's memory post kexec reboot.

Signed off by Hariprasad Nellitheertha <[email protected]>

---

 linux-2.6.9-rc1-hari/fs/proc/Makefile           |    1 
 linux-2.6.9-rc1-hari/fs/proc/kcore.c            |   10 -
 linux-2.6.9-rc1-hari/fs/proc/proc_misc.c        |   12 +
 linux-2.6.9-rc1-hari/fs/proc/vmcore.c           |  238 ++++++++++++++++++++++++
 linux-2.6.9-rc1-hari/include/linux/crash_dump.h |    8 
 linux-2.6.9-rc1-hari/include/linux/proc_fs.h    |    2 
 6 files changed, 266 insertions(+), 5 deletions(-)
fs/proc/Makefile renamed from fs/proc/Makefile~kd-elf-269rc1-mm5 +1 -0
diff -puN fs/proc/Makefile~kd-elf-269rc1-mm5 fs/proc/Makefile
@@ -11,4 +11,5 @@ proc-y       += inode.o root.o base.o ge
 		kmsg.o proc_tty.o proc_misc.o
 
 proc-$(CONFIG_PROC_KCORE)	+= kcore.o
+proc-$(CONFIG_CRASH_DUMP)	+= vmcore.o
 proc-$(CONFIG_PROC_DEVICETREE)	+= proc_devtree.o
fs/proc/kcore.c renamed from fs/proc/kcore.c~kd-elf-269rc1-mm5 +5 -5
diff -puN fs/proc/kcore.c~kd-elf-269rc1-mm5 fs/proc/kcore.c
@@ -114,7 +114,7 @@ static size_t get_kcore_size(int *nphdr,
 /*
  * determine size of ELF note
  */
-static int notesize(struct memelfnote *en)
+int notesize(struct memelfnote *en)
 {
 	int sz;
 
@@ -129,7 +129,7 @@ static int notesize(struct memelfnote *e
 /*
  * store a note in the header buffer
  */
-static char *storenote(struct memelfnote *men, char *bufp)
+char *storenote(struct memelfnote *men, char *bufp)
 {
 	struct elf_note en;
 
@@ -156,7 +156,7 @@ static char *storenote(struct memelfnote
  * store an ELF coredump header in the supplied buffer
  * nphdr is the number of elf_phdr to insert
  */
-static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff)
+void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff, struct kcore_list *clist)
 {
 	struct elf_prstatus prstatus;	/* NT_PRSTATUS */
 	struct elf_prpsinfo prpsinfo;	/* NT_PRPSINFO */
@@ -208,7 +208,7 @@ static void elf_kcore_store_hdr(char *bu
 	nhdr->p_align	= 0;
 
 	/* setup ELF PT_LOAD program header for every area */
-	for (m=kclist; m; m=m->next) {
+	for (m=clist; m; m=m->next) {
 		phdr = (struct elf_phdr *) bufp;
 		bufp += sizeof(struct elf_phdr);
 		offset += sizeof(struct elf_phdr);
@@ -305,7 +305,7 @@ read_kcore(struct file *file, char __use
 			return -ENOMEM;
 		}
 		memset(elf_buf, 0, elf_buflen);
-		elf_kcore_store_hdr(elf_buf, nphdr, elf_buflen);
+		elf_kcore_store_hdr(elf_buf, nphdr, elf_buflen, kclist);
 		read_unlock(&kclist_lock);
 		if (copy_to_user(buffer, elf_buf + *fpos, tsz)) {
 			kfree(elf_buf);
fs/proc/proc_misc.c renamed from fs/proc/proc_misc.c~kd-elf-269rc1-mm5 +12 -0
diff -puN fs/proc/proc_misc.c~kd-elf-269rc1-mm5 fs/proc/proc_misc.c
@@ -44,6 +44,7 @@
 #include <linux/jiffies.h>
 #include <linux/sysrq.h>
 #include <linux/vmalloc.h>
+#include <linux/bootmem.h>
 #include <linux/crash_dump.h>
 #include <asm/uaccess.h>
 #include <asm/pgtable.h>
@@ -584,6 +585,7 @@ static struct file_operations proc_crash
 #endif
 
 struct proc_dir_entry *proc_root_kcore;
+struct proc_dir_entry *proc_vmcore;
 
 static void create_seq_entry(char *name, mode_t mode, struct file_operations *f)
 {
@@ -678,6 +680,16 @@ void __init proc_misc_init(void)
 				(size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
 	}
 #endif
+#ifdef CONFIG_CRASH_DUMP
+	if (dump_enabled) {
+		proc_vmcore = create_proc_entry("vmcore", S_IRUSR, NULL);
+		if (proc_vmcore) {
+			proc_vmcore->proc_fops = &proc_vmcore_operations;
+			proc_vmcore->size =
+			(size_t)(saved_max_pfn << PAGE_SHIFT);
+		}
+	}
+#endif
 #ifdef CONFIG_MAGIC_SYSRQ
 	entry = create_proc_entry("sysrq-trigger", S_IWUSR, NULL);
 	if (entry)
fs/proc/vmcore.c new file +238 -0

238 lines not on this page · raw message

include/linux/crash_dump.h renamed from include/linux/crash_dump.h~kd-elf-269rc1-mm5 +8 -0
diff -puN include/linux/crash_dump.h~kd-elf-269rc1-mm5 include/linux/crash_dump.h
@@ -1,8 +1,16 @@
 #include <linux/kexec.h>
 #include <linux/smp_lock.h>
 #include <linux/device.h>
+#include <linux/proc_fs.h>
 #include <asm/crash_dump.h>
 
+extern unsigned long saved_max_pfn;
+extern struct memelfnote memelfnote;
+extern int notesize(struct memelfnote *);
+extern char *storenote(struct memelfnote *, char *);
+extern ssize_t copy_oldmem_page(unsigned long, char *, size_t, int);
+extern void elf_kcore_store_hdr(char *, int, int, struct kcore_list *);
+
 #ifdef CONFIG_CRASH_DUMP
 extern int crash_dump_on;
 static inline void crash_machine_kexec(void)
include/linux/proc_fs.h renamed from include/linux/proc_fs.h~kd-elf-269rc1-mm5 +2 -0
diff -puN include/linux/proc_fs.h~kd-elf-269rc1-mm5 include/linux/proc_fs.h
@@ -82,6 +82,7 @@ extern struct proc_dir_entry *proc_net;
 extern struct proc_dir_entry *proc_bus;
 extern struct proc_dir_entry *proc_root_driver;
 extern struct proc_dir_entry *proc_root_kcore;
+extern struct proc_dir_entry *proc_vmcore;
 
 extern void proc_root_init(void);
 extern void proc_misc_init(void);
@@ -117,6 +118,7 @@ extern int proc_readdir(struct file *, v
 extern struct dentry *proc_lookup(struct inode *, struct dentry *, struct nameidata *);
 
 extern struct file_operations proc_kcore_operations;
+extern struct file_operations proc_vmcore_operations;
 extern struct file_operations proc_kmsg_operations;
 extern struct file_operations ppc_htab_operations;
 

_

#6 lore raw

Re: [PATCH][6/6]Linear/raw format dump file access

Regards, Hari

Signature · 4 lines
Hariprasad Nellitheertha
Linux Technology Center
India Software Labs
IBM India, Bangalore

This patch contains the code that enables us to access the previous kernel's memory as /dev/oldmem.

Signed off by Hariprasad Nellitheertha <[email protected]> Signed off by Adam Litke <[email protected]>

---

 linux-2.6.9-rc1-hari/Documentation/devices.txt |    1 
 linux-2.6.9-rc1-hari/drivers/char/mem.c        |   66 +++++++++++++++++++++++++
 2 files changed, 67 insertions(+)
Documentation/devices.txt renamed from Documentation/devices.txt~kd-oldmem-269rc1-mm5 +1 -0
diff -puN Documentation/devices.txt~kd-oldmem-269rc1-mm5 Documentation/devices.txt
@@ -100,6 +100,7 @@ Your cooperation is appreciated.
 		  9 = /dev/urandom	Faster, less secure random number gen.
 		 10 = /dev/aio		Asyncronous I/O notification interface
 		 11 = /dev/kmsg		Writes to this come out as printk's
+		 12 = /dev/oldmem		Access to kexec-ed crash dump
   1 block	RAM disk
 		  0 = /dev/ram0		First RAM disk
 		  1 = /dev/ram1		Second RAM disk
drivers/char/mem.c renamed from drivers/char/mem.c~kd-oldmem-269rc1-mm5 +66 -0

102 lines not on this page · raw message

_

#7 lore raw

Re: [PATCH][5/6]ELF format dump file access

In reply to Hariprasad Nellitheertha

fs/proc/kcore.c static int notesize(struct memelfnote *e · line 132

Quoted 12 lines · Hariprasad Nellitheertha
fs/proc/kcore.c renamed from fs/proc/kcore.c~kd-elf-269rc1-mm5 +2 -2
-static int notesize(struct memelfnote *en)
+int notesize(struct memelfnote *en)
 {
 	int sz;
@@ -129,7 +129,7 @@ static int notesize(struct memelfnote *e
 /*
  * store a note in the header buffer
  */
-static char *storenote(struct memelfnote *men, char *bufp)
+char *storenote(struct memelfnote *men, char *bufp)

As you're giving these kernel-wide scope, please also rename them to elf_notesize() and elf_storenote().

#8 lore raw

Re: [PATCH][5/6]ELF format dump file access

In reply to Hariprasad Nellitheertha

fs/proc/proc_misc.c void __init proc_misc_init(void) · line 692

Quoted 11 lines · Hariprasad Nellitheertha
fs/proc/proc_misc.c renamed from fs/proc/proc_misc.c~kd-elf-269rc1-mm5 +10 -0
+#ifdef CONFIG_CRASH_DUMP
+	if (dump_enabled) {
+		proc_vmcore = create_proc_entry("vmcore", S_IRUSR, NULL);
+		if (proc_vmcore) {
+			proc_vmcore->proc_fops = &proc_vmcore_operations;
+			proc_vmcore->size =
+			(size_t)(saved_max_pfn << PAGE_SHIFT);
+		}
+	}
+#endif

Again, please try to move this out of procfs and into a crashdump-specific file.

#9 lore raw

Re: [PATCH][5/6]ELF format dump file access

In reply to Hariprasad Nellitheertha
Quoted 18 lines · Hariprasad Nellitheertha
fs/proc/vmcore.c new file +17 -0
+/*
+ * Reads from the oldmem device from given offset till
+ * given count
+ */
+static ssize_t read_from_oldmem(char *buf, size_t count,
+			     loff_t *ppos, int userbuf)
+{
+	unsigned long pfn, p = *ppos;
+	size_t read = 0;
+
+	pfn = p / PAGE_SIZE;
+	p = p % PAGE_SIZE;
+
+	if (pfn > saved_max_pfn) {
+		read = -EINVAL;
+		goto done;
+	}

fs/proc/vmcore.c line 98

Quoted 10 lines
fs/proc/vmcore.c new file +10 -0
+
+	if (count > PAGE_SIZE - p)
+		count = PAGE_SIZE - p;
+
+	if (copy_oldmem_page(pfn, buf, count, userbuf)) {
+		read = -EFAULT;
+		goto done;
+	}
+
+	*ppos += count;

hm, what's going on here? *ppos is a loff_t but you've copied it into a 32-bit local prior to calculating the pfn.

#10 lore raw

Re: [PATCH][4/6]Register snapshotting before kexec boot

In reply to Hariprasad Nellitheertha
Quoted 19 lines · Hariprasad Nellitheertha
arch/i386/kernel/crash_dump.c new file +18 -0
+void __crash_dump_stop_cpus(void)
+{
+	int i, cpu = smp_processor_id();
+	int other_cpus = num_online_cpus()-1;
+
+	if (other_cpus > 0) {
+		atomic_set(&waiting_for_dump_ipi, other_cpus);
+
+		for (i = 0; i < NR_CPUS; i++)
+			crash_dump_expect_ipi[i] = (i != cpu && cpu_online(i));
+
+		set_nmi_callback(crash_dump_nmi_callback);
+		/* Ensure the new callback function is set before sending
+		 * out the IPI
+		 */
+		wmb();
+
+		crash_dump_send_ipi();

arch/i386/kernel/crash_dump.c line 72

Quoted 10 lines
arch/i386/kernel/crash_dump.c new file +10 -0
+		while (atomic_read(&waiting_for_dump_ipi) > 0)
+			cpu_relax();
+
+		unset_nmi_callback();
+	} else {
+		local_irq_disable();
+		disable_local_APIC();
+		local_irq_enable();
+	}
+}

Is dodgy wrt CPU hotplug, but there's not a lot we can do about that in this context, I expect. Which is a shame, given that CPU hotplug is a likely time at which to be taking a crashdump ;)

Rusty, you may like to review these patches...

#11 lore raw

Re: [Fastboot] Re: [PATCH][4/6]Register snapshotting before kexec boot

Quoted 25 lines · Andrew Morton
Quoted 24 lines · Hariprasad Nellitheertha
arch/i386/kernel/crash_dump.c new file +24 -0
+void __crash_dump_stop_cpus(void)
+{
+	int i, cpu = smp_processor_id();
+	int other_cpus = num_online_cpus()-1;
+
+	if (other_cpus > 0) {
+		atomic_set(&waiting_for_dump_ipi, other_cpus);
+
+		for (i = 0; i < NR_CPUS; i++)
+			crash_dump_expect_ipi[i] = (i != cpu && cpu_online(i));
+
+		set_nmi_callback(crash_dump_nmi_callback);
+		/* Ensure the new callback function is set before sending
+		 * out the IPI
+		 */
+		wmb();
+
+		crash_dump_send_ipi();
+		while (atomic_read(&waiting_for_dump_ipi) > 0)
+			cpu_relax();
+
+		unset_nmi_callback();
+	} else {
+		local_irq_disable();
Quoted 8 lines

arch/i386/kernel/crash_dump.c line 72

Quoted 4 lines
arch/i386/kernel/crash_dump.c new file +4 -0
+		disable_local_APIC();
+		local_irq_enable();
+	}
+}

Is dodgy wrt CPU hotplug, but there's not a lot we can do about that in this context, I expect. Which is a shame, given that CPU hotplug is a likely time at which to be taking a crashdump ;)

If Hari disables preemption during this entire section of code, he should be safe from CPU hotplug, AFAICS. The stop machine threads will never get to run on that CPU.

Thanks
Dipankar

#12 lore raw

Re: [Fastboot] Re: [PATCH][4/6]Register snapshotting before kexec boot

Quoted 8 lines · Dipankar Sarma
Quoted 3 lines · Andrew Morton

Is dodgy wrt CPU hotplug, but there's not a lot we can do about that in this context, I expect. Which is a shame, given that CPU hotplug is a likely time at which to be taking a crashdump ;)

If Hari disables preemption during this entire section of code, he should be safe from CPU hotplug, AFAICS. The stop machine threads will never get to run on that CPU.

This will work for CPU remove, not CPU add, since the later is not atomic (yet).

Rusty, do you think it would be worthwhile making CPU add atomic? I can give it a shot :)

Signature · 5 lines
Thanks and Regards,
Srivatsa Vaddagiri,
Linux Technology Center,
IBM Software Labs,
Bangalore, INDIA - 560017
#13 lore raw

Re: [Fastboot] Re: [PATCH][4/6]Register snapshotting before kexec boot

Quoted 10 lines · Srivatsa Vaddagiri
Quoted 8 lines · Dipankar Sarma
Quoted 3 lines · Andrew Morton

Is dodgy wrt CPU hotplug, but there's not a lot we can do about that in this context, I expect. Which is a shame, given that CPU hotplug is a likely time at which to be taking a crashdump ;)

If Hari disables preemption during this entire section of code, he should be safe from CPU hotplug, AFAICS. The stop machine threads will never get to run on that CPU.

Quoted 5 lines

This will work for CPU remove, not CPU add, since the later is not atomic (yet).

Rusty, do you think it would be worthwhile making CPU add atomic? I can give it a shot :)

The whole section should be run with interrupts disabled, so disabling preemption should be trivial.

Beyond this the code needs a bogomips based timeout, (we can't use external time sources just the delay loop). Any of the other cpu's could have crashed at this point, or our accounting data structures could be currupt.

Putting the initial call inside of machine_kexec is also bogus. crash_machine_kexec needs to call crash_stop_cpus and then machine_kexec. machine_kexec is currently factored as a perfectly reusable piece of code let's not mess that up.

Eric

#14 lore raw

Re: [PATCH][3/6]Routines for copying the dump pages

In reply to Hariprasad Nellitheertha

include/linux/highmem.h static inline void copy_highpage(struct · line 96

Quoted 7 lines · Hariprasad Nellitheertha
include/linux/highmem.h renamed from include/linux/highmem.h~kd-copy-269rc1-mm5 +6 -0
+/*
+ * Copy a page from "oldmem". For this page, there is no pte mapped
+ * in the current kernel. We stitch up a pte, similar to kmap_atomic.
+ */
+static inline ssize_t copy_oldmem_page(unsigned long pfn,
+			char *buf, size_t csize, int userbuf)

Again, why inline this function?

#15 lore raw

Re: [PATCH][2/6]Memory preserving reboot using kexec

In reply to Hariprasad Nellitheertha

I'll add these to -mm. Minor things:

Quoted 4 lines
arch/i386/Kconfig renamed from arch/i386/Kconfig~kd-reb-269rc1-mm5 +4 -0
+config BACKUP_BASE
+	int "location of the crash dumps backup region"
+	depends on CRASH_DUMP
+	default 16

arch/i386/Kconfig config KEXEC · line 916

Quoted 10 lines
arch/i386/Kconfig renamed from arch/i386/Kconfig~kd-reb-269rc1-mm5 +10 -0
+	help
+	This is the location where the second kernel will boot from.
+
+config BACKUP_SIZE
+	int "Size of the crash dumps backup region"
+	depends on CRASH_DUMP
+	range 16 64
+	default 32
+	help
+	The size of the second kernel's memory.

You should tell the user the units of the parameter. So

"location of the crash dumps backup region (MB)"

would be nice.

include/asm-i386/crash_dump.h line 10

Quoted 12 lines

+++ linux-2.6.9-rc1-hari/include/asm-i386/crash_dump.h 2004-09-15 17:36:30.000000000 +0530

include/asm-i386/crash_dump.h new file +10 -0
@@ -0,0 +1,44 @@
+/* asm-i386/crash_dump.h */
+#include <linux/bootmem.h>
+
+extern unsigned int dump_enabled;
+
+void __crash_relocate_mem(unsigned long, unsigned long);
+unsigned long __init find_max_low_pfn(void);
+void __init find_max_pfn(void);
+
+extern unsigned int crashed;

Should the above declarations be inside CONFIG_CRASH_DUMP? We don't want to leave them in scope if they don't exist.

Quoted 8 lines
include/linux/crash_dump.h new file +8 -0
+static inline void crash_machine_kexec(void)
+{
+	struct kimage *image;
+
+	if ((!crash_dump_on) || (crashed))
+		return;
+
+	image = xchg(&kexec_image, 0);

include/linux/crash_dump.h line 25

Quoted 10 lines
include/linux/crash_dump.h new file +10 -0
+	if (image) {
+		crashed = 1;
+		device_shutdown();
+		printk(KERN_EMERG "kexec: opening parachute\n");
+		machine_kexec(image);
+		while (1);
+	} else {
+		printk(KERN_EMERG "kexec: No kernel image loaded!\n");
+	}
+}

I don't see why this is inlined??

Quoted 24 lines
fs/proc/proc_misc.c renamed from fs/proc/proc_misc.c~kd-reb-269rc1-mm5 +19 -0
+#ifdef CONFIG_CRASH_DUMP
+/*
+ * Enable kexec reboot upon panic; for dumping
+ */
+static ssize_t write_crash_dump_on(struct file *file, const char __user *buf,
+					size_t count, loff_t *ppos)
+{
+	if (count) {
+		if (get_user(crash_dump_on, buf))
+			return -EFAULT;
+	}
+	return count;
+}
+
+static struct file_operations proc_crash_dump_on_operations = {
+	.write		= write_crash_dump_on,
+};
+#endif
+
 struct proc_dir_entry *proc_root_kcore;
 
 static void create_seq_entry(char *name, mode_t mode, struct file_operations *f)
@@ -663,6 +683,11 @@ void __init proc_misc_init(void)
 	if (entry)

fs/proc/proc_misc.c void __init proc_misc_init(void) · line 693

Quoted 10 lines
fs/proc/proc_misc.c renamed from fs/proc/proc_misc.c~kd-reb-269rc1-mm5 +5 -0
 		entry->proc_fops = &proc_sysrq_trigger_operations;
 #endif
+#ifdef CONFIG_CRASH_DUMP
+	entry = create_proc_entry("kexec-dump", S_IWUSR, NULL);
+	if (entry)
+		entry->proc_fops = &proc_crash_dump_on_operations;
+#endif
 #ifdef CONFIG_LOCKMETER
 	entry = create_proc_entry("lockmeter", S_IWUSR | S_IRUGO, NULL);
 	if (entry) {

Please do all the above in a crashdump-specific file, not inside proc_misc.c

#16 lore raw

Re: [Fastboot] Re: [PATCH][2/6]Memory preserving reboot using kexec

In reply to Hariprasad Nellitheertha
Quoted 12 lines · Hariprasad Nellitheertha

Regards, Hari

Signature · 10 lines
Hariprasad Nellitheertha
Linux Technology Center
India Software Labs
IBM India, Bangalore



This patch contains the code that does the memory preserving reboot. It 
copies over the first 640k into a backup region before handing over to 
kexec. The second kernel will boot using only the backup region.

Do you know what the kernel does with the low 1M?

Nothing in the hardware architecture requires us to use the low 1M. So I think we would be safer if we could track down and remove this dependency.

In general I agree that we need to be prepared to save some of the original machine state, because some architectures give special meaning to addresses in memory. But x86 is not one of those.

Perhaps the proper abstraction is to add a use_mem= variable that simply tells us which memory addresses we can use.

By still doing some copying we run into the problem, of potentially running out of memory areas where ongoing DMA transfers may be happening. So this is worth tracking down.

include/linux/crash_dump.h 2004-09-15 line 6

Quoted 12 lines

diff -puN /dev/null include/linux/crash_dump.h

include/linux/crash_dump.h 2004-09-15 new file +0 -0

17:36:30.000000000 +0530

include/linux/crash_dump.h 2004-09-15 new file +6 -0
@@ -0,0 +1,28 @@
+#include <linux/kexec.h>
+#include <linux/smp_lock.h>
+#include <linux/device.h>
+#include <asm/crash_dump.h>
+
+#ifdef CONFIG_CRASH_DUMP

Why is this function an inline in a header file? I know we only call it once but still unnecessary code in a header file seems silly.

include/linux/crash_dump.h 2004-09-15 line 15

Quoted 9 lines
include/linux/crash_dump.h 2004-09-15 new file +9 -0
+extern int crash_dump_on;
+static inline void crash_machine_kexec(void)
+{
+	struct kimage *image;
+
+	if ((!crash_dump_on) || (crashed))
+		return;
+
+	image = xchg(&kexec_image, 0);

You are still not using a different global variable here.

With a separate kexec_crash_image variable if the image is present we do a crash dump. That should allow you to remove the crash_dump_on variable and the test above.

include/linux/crash_dump.h 2004-09-15 line 17

Quoted 2 lines
include/linux/crash_dump.h 2004-09-15 new file +2 -0
+	if (image) {
+		crashed = 1;

We should not need the magic global variable crashed. We can just call the one or two functions needed from crash_machine_kexec.

include/linux/crash_dump.h 2004-09-15 line 18

Quoted 1 line
include/linux/crash_dump.h 2004-09-15 new file +1 -0
+		device_shutdown();

Why are you calling device_shutdown here?

include/linux/crash_dump.h 2004-09-15 line 19

Quoted 1 line
include/linux/crash_dump.h 2004-09-15 new file +1 -0
+		printk(KERN_EMERG "kexec: opening parachute\n");

To wrap things prettily we should probably add a machine_crash_shutdown() and place in machine_crash_shutdown whatever architecture specific magic needs to happen.

include/linux/crash_dump.h 2004-09-15 line 21

Quoted 2 lines
include/linux/crash_dump.h 2004-09-15 new file +2 -0
+		machine_kexec(image);
+		while (1);

The while look is unnecessary machine_kexec cannot return.

Quoted 7 lines
include/linux/crash_dump.h 2004-09-15 new file +7 -0
+	} else {
+		printk(KERN_EMERG "kexec: No kernel image loaded!\n");
+	}
+}
+#else
+#define crash_machine_kexec()	do { } while(0)
+#endif
#17 lore raw

Re: [Fastboot] Re: [PATCH][2/6]Memory preserving reboot using kexec

Hi Eric,

Quoted 16 lines · Eric W. Biederman
Quoted 3 lines · Hariprasad Nellitheertha

This patch contains the code that does the memory preserving reboot. It copies over the first 640k into a backup region before handing over to kexec. The second kernel will boot using only the backup region.

Do you know what the kernel does with the low 1M?

Nothing in the hardware architecture requires us to use the low 1M. So I think we would be safer if we could track down and remove this dependency.

In general I agree that we need to be prepared to save some of the original machine state, because some architectures give special meaning to addresses in memory. But x86 is not one of those.

Quoted 7 lines

Perhaps the proper abstraction is to add a use_mem= variable that simply tells us which memory addresses we can use.

By still doing some copying we run into the problem, of potentially running out of memory areas where ongoing DMA transfers may be happening. So this is worth tracking down.

I am trying to track this down. I tried moving the first segment of vmlinux into the reserved section by modifying kexec-tools. This is the command line argument segment. It still seems to need the first few kilobytes, though.

Eliminating this is definitely needed so we can avoid using the first kernel's region completely.

Also, I will make the changes in the rest of the patch as per your review comments.

Regards, Hari

Signature · 4 lines
Hariprasad Nellitheertha
Linux Technology Center
India Software Labs
IBM India, Bangalore
#18 lore raw

Re: [Fastboot] Re: [PATCH][2/6]Memory preserving reboot using kexec

Quoted 22 lines · Hariprasad Nellitheertha

Hi Eric,

Quoted 19 lines · Eric W. Biederman
Quoted 3 lines · Hariprasad Nellitheertha

This patch contains the code that does the memory preserving reboot. It copies over the first 640k into a backup region before handing over to kexec. The second kernel will boot using only the backup region.

Do you know what the kernel does with the low 1M?

Nothing in the hardware architecture requires us to use the low 1M. So I think we would be safer if we could track down and remove this dependency.

In general I agree that we need to be prepared to save some of the original machine state, because some architectures give special meaning to addresses in memory. But x86 is not one of those.

Perhaps the proper abstraction is to add a use_mem= variable that simply tells us which memory addresses we can use.

Quoted 8 lines
Quoted 4 lines

By still doing some copying we run into the problem, of potentially running out of memory areas where ongoing DMA transfers may be happening. So this is worth tracking down.

I am trying to track this down. I tried moving the first segment of vmlinux into the reserved section by modifying kexec-tools. This is the command line argument segment. It still seems to need the first few kilobytes, though.

Right that is being automatically placed there.
For testing it should not be too hard to hard code it at someplace appropriate.

Quoted 5 lines

Eliminating this is definitely needed so we can avoid using the first kernel's region completely.

Also, I will make the changes in the rest of the patch as per your review comments.

Thanks.

#19 lore raw
In reply to Hariprasad Nellitheertha
Quoted 10 lines · Hariprasad Nellitheertha

Hi Andrew,

The patches that follow contain the kexec based crash dumping implementation. Based on feedback received last time, we have made several changes. Some of them are:

- The dumping kernel now boots from a non-default location. This is possible due to Eric's patch which allows i386 kernels to boot from a non-default location. This change means that we need two different kernels to get this setup. The documentation patch has complete details on how to do this.

Cool. I am glad you could get this going this should make things easier.

Quoted 8 lines

- We can now choose whether or not to dump from panic. The documentation patch has details on this as well.
- The linear view is now called oldmem.
- Changes as per the code review comments from the previous posting.

The patches correspond to 2.6.9-rc1-mm5.

Kindly review these patches and let me know your thoughts.

I will start with my standard objections about it still being incompatible with other uses of kexec.

More later when I get a chance. Things seem to slowly be going in the right direction.

Eric