kexec for ia64
PATCH 1/1 kexec for ia64
I have updated kexec patch for ia64. Attached patch fixes a couple of bugs from previous version and incorporates code developed by Nan Hai. This patch works on 2.6.16-rc6 kernel. Also attached is a patch for kexec-tools which applies on top of kexec-tools-1.101 release from Eric Biederman <http://www.xmission.com/%
7Eebiederm/files/kexec/kexec-tools-1.101.tar.gz> and adds support for ia64. Please test and provide feedback.
I am working on integrating kdump support and will post that patch once I have tested it.
Signature · 9 lines
Khalid ==================================================================== Khalid Aziz Open Source and Linux Organization (970)898-9214 Hewlett-Packard [email protected] Fort Collins, CO "The Linux kernel is subject to relentless development" - Alessandro Rubini
arch/ia64/hp/common/sba_iommu.c +22 -0
@@ -1624,6 +1624,28 @@ ioc_iova_init(struct ioc *ioc)READ_REG (ioc->ioc_hpa +IOC_IBASE ); } +#ifdef CONFIG_KEXEC +void +ioc_iova_disable (void ) +{ +struct ioc *ioc; + + ioc = ioc_list; + +while (ioc !=NULL ) { +/* Disable IOVA translation */ +WRITE_REG (ioc->ibase &0xfffffffffffffffe , ioc->ioc_hpa +IOC_IBASE ); +READ_REG (ioc->ioc_hpa +IOC_IBASE ); + +/* Clear I/O TLB of any possible entries */ +WRITE_REG (ioc->ibase | (get_iovp_order (ioc->iov_size) + iovp_shift), ioc->ioc_hpa +IOC_PCOM ); +READ_REG (ioc->ioc_hpa +IOC_PCOM ); + + ioc = ioc->next; + } +} +#endif +static void __init ioc_resource_init (struct ioc *ioc) {
arch/ia64/Kconfig +17 -0
@@ -374,6 +374,23 @@ config IA64_PALINFO To use this option, you have to ensure that the "/proc file system support" (CONFIG_PROC_FS) is enabled, too. +config KEXEC + bool "kexec system call (EXPERIMENTAL)" + depends on EXPERIMENTAL + help + kexec is a system call that implements the ability to shutdown your + current kernel, and to start another kernel. It is like a reboot + but it is indepedent of the system firmware. And like a reboot + you can start any kernel with it, not just Linux. + + The name comes from the similiarity to the exec system call. + + It is an ongoing process to be certain the hardware in a machine + is properly shutdown, so do not be surprised if this code does not + initially work for you. It may help to enable device hotplugging + support. As of this writing the exact hardware interface is + strongly in flux, so no good recommendation can be made. + source "drivers/firmware/Kconfig" source "fs/Kconfig.binfmt"
arch/ia64/kernel/crash.c +46 -0
46 lines not on this page · raw message
arch/ia64/kernel/entry.S +1 -1
@@ -1588,7 +1588,7 @@ sys_call_table: data8 sys_mq_timedreceive // 1265 data8 sys_mq_notify data8 sys_mq_getsetattr - data8 sys_ni_syscall // reserved for kexec_load + data8 sys_kexec_load data8 sys_ni_syscall // reserved for vserver data8 sys_waitid // 1270 data8 sys_add_key
arch/ia64/kernel/machine_kexec.c +165 -0
165 lines not on this page · raw message
arch/ia64/kernel/Makefile +1 -0
@@ -28,6 +28,7 @@ obj-$(CONFIG_IA64_CYCLONE) += cyclone.o obj-$(CONFIG_CPU_FREQ) += cpufreq/ obj-$(CONFIG_IA64_MCA_RECOVERY) += mca_recovery.o obj-$(CONFIG_KPROBES) += kprobes.o jprobes.o +obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o crash.o obj-$(CONFIG_IA64_UNCACHED_ALLOCATOR) += uncached.o mca_recovery-y += mca_drv.o mca_drv_asm.o
arch/ia64/kernel/relocate_kernel.S +364 -0
364 lines not on this page · raw message
arch/ia64/kernel/smp.c +40 -0
@@ -30,6 +30,9 @@#include <linux/delay.h> #include <linux/efi.h> #include <linux/bitops.h> +#ifdef CONFIG_KEXEC +#include <linux/kexec.h> +#endif #include <asm/atomic.h> #include <asm/current.h>
@@ -84,6 +87,43 @@ unlock_ipi_calllock(void)spin_unlock_irq (&call_lock); } +#ifdef CONFIG_KEXEC +extern void kexec_fake_sal_rendez (void *start,unsigned long wake_up, +unsigned long pal_base); + +#define pte_bits 3 +#define vmlpt_bits (impl_va_bits - PAGE_SHIFT + pte_bits) +#define POW2 (n) (1ULL << (n)) + +DECLARE_PER_CPU (u64, ia64_mca_pal_base); + +/* +* Stop the CPU and put it in fake SAL rendezvous. This allows CPU to wake +* up with IPI from boot processor +*/ +void +kexec_stop_this_cpu (void *func) +{ +unsigned long pta, impl_va_bits, pal_base; + +/* +* Remove this CPU by putting it into fake SAL rendezvous +*/ +cpu_clear (smp_processor_id (), cpu_online_map); +max_xtp (); +ia64_eoi (); + +/* Disable VHPT */ + impl_va_bits =ffz (~(local_cpu_data->unimpl_va_mask | (7UL <<61 ))); + pta =POW2 (61 ) -POW2 (vmlpt_bits); +ia64_set_pta (pta | (0 <<8 ) | (vmlpt_bits <<2 ) |0 ); + +local_irq_disable (); + pal_base =__get_cpu_var (ia64_mca_pal_base); +kexec_fake_sal_rendez (func, ap_wakeup_vector, pal_base); +} +#endif +static void stop_this_cpu (void ) {
include/asm-ia64/kexec.h +24 -0
@@ -0,0 +1,24 @@ +#ifndef _ASM_IA64_KEXEC_H +#define _ASM_IA64_KEXEC_H + + +/* Maximum physical address we can use pages from */ +#define KEXEC_SOURCE_MEMORY_LIMIT (-1UL) +/* Maximum address we can reach in physical address mode */ +#define KEXEC_DESTINATION_MEMORY_LIMIT (-1UL) +/* Maximum address we can use for the control code buffer */ +#define KEXEC_CONTROL_MEMORY_LIMIT TASK_SIZE + +#define KEXEC_CONTROL_CODE_SIZE (8192 + 8192 + 4096) + +/* The native architecture */ +#define KEXEC_ARCH KEXEC_ARCH_IA_64 + +#define MAX_NOTE_BYTES 1024 + + +static inline void +crash_setup_regs (struct pt_regs *newregs,struct pt_regs *oldregs) +{ +} +#endif /* _ASM_IA64_KEXEC_H */
kernel/irq/handle.c +19 -0
@@ -100,6 +100,25 @@ fastcall int handle_IRQ_event(unsigned i }/* +* Terminate any outstanding interrupts +*/ +void terminate_irqs (void ) +{ +struct irqaction * action; +irq_desc_t *idesc; +int i; + +for (i=0 ; i<NR_IRQS ; i++) { + idesc =irq_descp (i); + action = idesc->action; +if (!action) +continue ; +if (idesc->handler->end) + idesc->handler->end (i); + } +} + +/* * do_IRQ handles all normal device IRQ's (the special * SMP cross-CPU interrupts have their own specific * handlers).
kdump/kdump.8 +39 -0
@@ -0,0 +1,39 @@ +.\" Hey, EMACS: -*- nroff -*- +.\" First parameter, NAME, should be all caps +.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection +.\" other parameters are allowed: see man(7), man(1) +.TH KDUMP 8 "Jul 27, 2005" +.\" Please adjust this date whenever revising the manpage. +.\" +.\" Some roff macros, for reference: +.\" .nh disable hyphenation +.\" .hy enable hyphenation +.\" .ad l left justify +.\" .ad b justify to both left and right margins +.\" .nf disable filling +.\" .fi enable filling +.\" .br insert line break +.\" .sp <n> insert n+1 empty lines +.\" for manpage-specific macros, see man(7) +.SH NAME +kdump \- This is just a placeholder until real man page has been written +.SH SYNOPSIS +.B kdump +.RI [ options ] " start_address" ... +.SH DESCRIPTION +.PP +.\" TeX users may be more comfortable with the \fB<whatever>\fP and +.\" \fI<whatever>\fP escape sequences to invode bold face and italics, +.\" respectively. +\fBkdump\fP does not have a man page yet. +.SH OPTIONS +.\"These programs follow the usual GNU command line syntax, with long +.\"options starting with two dashes (`-'). +.\"A summary of options is included below. +.\"For a complete description, see the Info files. +.SH SEE ALSO +.SH AUTHOR +kdump was written by Eric Biederman. +.PP +This manual page was written by Khalid Aziz <[email protected]>, +for the Debian project (but may be used by others).
kdump/Makefile +4 -0
@@ -10,6 +10,7 @@ KDUMP_SRCS:= $(KDUMP_C_SRCS) KDUMP_OBJS:= $(KDUMP_C_OBJS) KDUMP_DEPS:= $(KDUMP_C_DEPS) KDUMP:= $(SBINDIR)/kdump +KDUMP_MANPAGE:= $(MANDIR)/man8/kdump.8 include $(KDUMP_DEPS)
@@ -25,6 +26,9 @@ $(KDUMP): $(KDUMP_OBJS) mkdir -p $(@D) $(CC) $(CFLAGS) -o $@ $(KDUMP_OBJS) +$(KDUMP_MANPAGE): kdump/kdump.8 + $(MKDIR) -p $(MANDIR)/man8 + cp kdump/kdump.8 $(KDUMP_MANPAGE) echo:: @echo "KDUMP_C_SRCS $(KDUMP_C_SRCS)" @echo "KDUMP_C_DEPS $(KDUMP_C_DEPS)"
kexec/arch/ia64/kexec-elf-ia64.c +52 -8
111 lines not on this page · raw message
kexec/arch/ia64/kexec-elf-rel-ia64.c +91 -5
126 lines not on this page · raw message
kexec/arch/ia64/kexec-ia64.c +9 -32
71 lines not on this page · raw message
kexec/kexec.8 +38 -8
75 lines not on this page · raw message
kexec/kexec.c +1 -1
@@ -187,7 +187,7 @@ unsigned long locate_hole(struct kexec_i }/* Compute the free memory ranges */ - max_mem_ranges = memory_ranges + (info->nr_segments -1 ); + max_mem_ranges = memory_ranges + info->nr_segments; mem_range =malloc (max_mem_ranges *sizeof (struct memory_range )); mem_ranges =0 ;
kexec/Makefile +4 -0
@@ -27,6 +27,7 @@ KEXEC_SRCS:= $(KEXEC_C_SRCS) $(KEXEC_S_S KEXEC_OBJS:= $(KEXEC_C_OBJS) $(KEXEC_S_OBJS) KEXEC_DEPS:= $(KEXEC_C_DEPS) $(KEXEC_S_DEPS) KEXEC:= $(SBINDIR)/kexec +KEXEC_MANPAGE:= $(MANDIR)/man8/kexec.8 include $(KEXEC_DEPS)
@@ -50,6 +51,9 @@ $(KEXEC): $(KEXEC_OBJS) $(UTIL_LIB) mkdir -p $(@D) $(CC) $(KCFLAGS) -o $@ $(KEXEC_OBJS) $(UTIL_LIB) $(LIBS) +$(KEXEC_MANPAGE): kexec/kexec.8 + $(MKDIR) -p $(MANDIR)/man8 + cp kexec/kexec.8 $(KEXEC_MANPAGE) echo:: @echo "KEXEC_C_SRCS $(KEXEC_C_SRCS)" @echo "KEXEC_C_DEPS $(KEXEC_C_DEPS)"
Makefile +1 -0
@@ -43,6 +43,7 @@ PKGLIBDIR=$(LIBDIR)/$(PACKAGE) PKGINCLUDEIR=$(INCLUDEDIR)/$(PACKAGE) MAN_PAGES:= kexec/kexec.8 +MAN_PAGES+= kdump/kdump.8 BINARIES_i386:= $(SBINDIR)/kexec $(PKGLIBDIR)/kexec_test BINARIES_x86_64:=$(SBINDIR)/kexec $(PKGLIBDIR)/kexec_test BINARIES:=$(SBINDIR)/kexec $(SBINDIR)/kdump $(BINARIES_$(ARCH))
purgatory/arch/ia64/entry.S +85 -0
85 lines not on this page · raw message
purgatory/arch/ia64/include/arch/io.h +25 -0
@@ -0,0 +1,25 @@ +#ifndef ARCH_IO_H +#define ARCH_IO_H + +#include <stdint.h> +/* Helper functions for directly doing I/O */ + +extern inline uint8_t inb (void *port) +{ +volatile unsigned char *addr = (unsigned char *)port; +uint8_t result; + + result = *addr; + asmvolatile ("mf.a" :::"memory" ); +return result; +} + +extern inline void outb (uint8_t value,void *port) +{ +volatile unsigned char *addr = (unsigned char *)port; + + *addr = value; + asmvolatile ("mf.a" :::"memory" ); +} + +#endif /* ARCH_IO_H */
purgatory/arch/ia64/Makefile +2 -2
@@ -1,8 +1,8 @@ # # Purgatory ia64 # - -PURGATORY_S_SRCS+= +PCFLAGS += -ffixed-r28 +PURGATORY_S_SRCS+= purgatory/arch/ia64/entry.S PURGATORY_C_SRCS+= purgatory/arch/ia64/purgatory-ia64.c PURGATORY_C_SRCS+= purgatory/arch/ia64/console-ia64.c PURGATORY_C_SRCS+=
purgatory/arch/ia64/purgatory-ia64.c +106 -0
113 lines not on this page · raw message
purgatory/Makefile +1 -1
@@ -6,7 +6,7 @@ # There is probably a cleaner way to do this but for now this # should keep us from accidentially include unsafe library functions # or headers. -PCFLAGS:=-Wall -Os \ +PCFLAGS:=-Wall -Os -g \ -I$(shell $(CC) -print-file-name=include) \ -Ipurgatory/include -Ipurgatory/arch/$(ARCH)/include \ $(CPPFLAGS)
Quoted 16 lines · Khalid Aziz
I have updated kexec patch for ia64. Attached patch fixes a couple of bugs from previous version and incorporates code developed by Nan Hai. This patch works on 2.6.16-rc6 kernel. Also attached is a patch for kexec-tools which applies on top of kexec-tools-1.101 release from Eric Biederman <http://www.xmission.com/%
7Eebiederm/files/kexec/kexec-tools-1.101.tar.gz> and adds support for ia64. Please test and provide feedback.I am working on integrating kdump support and will post that patch once I have tested it.
diff -urNp
linux-2.6.16-rc2/arch/ia64/kernel/crash.clinux-2.6.16-rc2-ia64kexec/arch/ia64/kernel/crash.c
arch/ia64/kernel/crash.c line 23
Quoted 3 lines
arch/ia64/kernel/crash.c +1
-0+extern void device_shutdown (void );
extern declarations always go in headers, please. This patch adds zillions of them in .c files. It is risky and duplicative.
arch/ia64/kernel/machine_kexec.c line 20
Quoted 12 lines
diff -urNp
linux-2.6.16-rc2/arch/ia64/kernel/machine_kexec.clinux-2.6.16-rc2-ia64kexec/arch/ia64/kernel/machine_kexec.carch/ia64/kernel/machine_kexec.c +8
-0+#include <linux/kernel.h> +#include <linux/config.h> +#include <linux/mm.h> +#include <linux/kexec.h> +#include <linux/pci.h> +#ifdef CONFIG_HOTPLUG_CPU +#include <linux/cpu.h> +#endif
The ifdef shouldn't be needed.
arch/ia64/kernel/machine_kexec.c line 34
Quoted 7 lines
arch/ia64/kernel/machine_kexec.c +7
-0+ +DECLARE_PER_CPU (u64, ia64_mca_pal_base); + +extern unsigned long ia64_iobase; +extern unsigned long kexec_reboot; +extern void kexec_stop_this_cpu (void *); +extern struct subsystem devices_subsys;
In header files.
arch/ia64/kernel/machine_kexec.c line 50
Quoted 3 lines
arch/ia64/kernel/machine_kexec.c +3
-0+const extern unsigned char relocate_new_kernel[]; +const extern unsigned long kexec_fake_sal_rendez[]; +const extern unsigned int relocate_new_kernel_size;
Even things which are defined via vmlinux.lds magic should be declared in headers.
Quoted 1 line
+extern void
ioc_iova_disable(void);
In a header.
arch/ia64/kernel/machine_kexec.c line 54
Quoted 2 lines
arch/ia64/kernel/machine_kexec.c +2
-0+volatile extern long kexec_rendez; +volatile const extern unsigned char kexec_rendez_reloc[];
Ditto.
arch/ia64/kernel/machine_kexec.c line 89
Quoted 12 lines
arch/ia64/kernel/machine_kexec.c +12
-0+ +void machine_shutdown (void ) +{ +struct pci_dev *dev; +irq_desc_t *idesc; +cpumask_t mask =CPU_MASK_NONE ; + +/* Disable all PCI devices */ +list_for_each_entry (dev, &pci_devices, global_list) { +if (!(dev->is_enabled)) { +continue ; + }
Unneeded braces.
arch/ia64/kernel/machine_kexec.c line 90
Quoted 1 line
arch/ia64/kernel/machine_kexec.c +1
-0+if (!(idesc =irq_descp (dev->irq)))
This:
idesc = irq_descp(dev->irq); if (!idesc)
is preferred.
arch/ia64/kernel/machine_kexec.c line 114
Quoted 2 lines
arch/ia64/kernel/machine_kexec.c +2
-0+#ifdef CONFIG_SMP +#ifdef CONFIG_HOTPLUG_CPU
#if defined(CONFIG_SMP) && defined(CONFIG_HOTPLUG_CPU)
is tidier. But CONFIG_HOTPLUG_CPU already depends on CONFIG_SMP.
arch/ia64/kernel/machine_kexec.c line 124
Quoted 10 lines
arch/ia64/kernel/machine_kexec.c +10
-0+int cpu; + +for_each_online_cpu (cpu) { +if (cpu !=smp_processor_id ()) +cpu_down (cpu); + } +#else +smp_call_function (kexec_stop_this_cpu, (void *)image->start,0 ,0 ); +#endif +#endif
Why is different code needed for hotplug cpu?
arch/ia64/kernel/machine_kexec.c line 137
Quoted 12 lines
arch/ia64/kernel/machine_kexec.c +12
-0+ia64_set_itv (1 <<16 ); +/* Interrupts aren't acceptable while we reboot */ +local_irq_disable (); + +/* set kr0 to the appropriate address */ +set_io_base (); + + { +unsigned long pta, impl_va_bits; + +# define pte_bits 3 +# define vmlpt_bits (impl_va_bits - PAGE_SHIFT + pte_bits)
Why not simply open-code these things?
Quoted 1 line
+# define POW2(n) (1ULL << (n))
And that.
Quoted 15 lines
arch/ia64/kernel/machine_kexec.c +9
-0+/* Disable VHPT */ + impl_va_bits =ffz (~(local_cpu_data->unimpl_va_mask | (7UL <<61 ))); + pta =POW2 (61 ) -POW2 (vmlpt_bits); +ia64_set_pta (pta | (0 <<8 ) | (vmlpt_bits <<2 ) |0 ); + } + +#ifdef CONFIG_IA64_HP_ZX1 +ioc_iova_disable (); +#endif
arch/ia64/kernel/smp.c line 35
Quoted 6 lines
arch/ia64/kernel/smp.c +3
-0@@ -30,6 +30,9 @@#include <linux/delay.h> #include <linux/efi.h> #include <linux/bitops.h> +#ifdef CONFIG_KEXEC +#include <linux/kexec.h> +#endif
The ifdefs shouldn't be needed.
arch/ia64/kernel/smp.c unlock_ipi_calllock(void) · line 92
Quoted 9 lines
arch/ia64/kernel/smp.c +3
-0#include <asm/atomic.h> #include <asm/current.h> @@ -84,6 +87,43 @@ unlock_ipi_calllock(void)spin_unlock_irq (&call_lock); } +#ifdef CONFIG_KEXEC +extern void kexec_fake_sal_rendez (void *start,unsigned long wake_up, +unsigned long pal_base);
That should go in a header file.
arch/ia64/kernel/smp.c unlock_ipi_calllock(void) · line 96
Quoted 3 lines
arch/ia64/kernel/smp.c +3
-0+#define pte_bits 3 +#define vmlpt_bits (impl_va_bits - PAGE_SHIFT + pte_bits) +#define POW2 (n) (1ULL << (n))
Duplicative.
arch/ia64/kernel/smp.c unlock_ipi_calllock(void) · line 96
Quoted 1 line
arch/ia64/kernel/smp.c +1
-0+DECLARE_PER_CPU (u64, ia64_mca_pal_base);
In a header file.
Quoted 8 lines
arch/ia64/kernel/smp.c +7
-0/* +* Terminate any outstanding interrupts +*/ +void terminate_irqs (void ) +{ +struct irqaction * action; +irq_desc_t *idesc; +int i;
arch/ia64/kernel/smp.c unlock_ipi_calllock(void) · line 114
Quoted 10 lines
arch/ia64/kernel/smp.c +10
-0+ +for (i=0 ; i<NR_IRQS ; i++) { + idesc =irq_descp (i); + action = idesc->action; +if (!action) +continue ; +if (idesc->handler->end) + idesc->handler->end (i); + } +}
Perhaps that should be in kernel/irq/something.c?
Quoted 13 lines · Andrew Morton
arch/ia64/kernel/machine_kexec.c line 124
Quoted 10 lines · Khalid Aziz
arch/ia64/kernel/machine_kexec.c +10
-0+int cpu; + +for_each_online_cpu (cpu) { +if (cpu !=smp_processor_id ()) +cpu_down (cpu); + } +#else +smp_call_function (kexec_stop_this_cpu, (void *)image->start,0 ,0 ); +#endif +#endif Why is different code needed for hotplug cpu?
Hi Andrew,
It is preferable to use cpu_down() to shoot down a cpu, but this function is available only with CONFIG_HOTPLUG_CPU. If CONFIG_HOTPLUG_CPU is not enabled, only other way to shut down slave CPUs in a state where they would come back up when the new kernel boots up and sends them IPI is to hold them in a fake rendezvous which is what the function kexec_stop_this_cpu() does. So the choices are either to keep both ways of shutting down CPUs or go with kexec_stop_this_cpu() for all cases.
Thanks for the comments. I will move declarations to header files as you suggested.
Signature · 9 lines
Khalid ================================== Khalid Aziz Open Source and Linux Organization (970)898-9214 Hewlett-Packard [email protected] Fort Collins, CO "The Linux kernel is subject to relentless development" - Alessandro Rubini
Quoted 10 lines · Khalid Aziz
I have updated kexec patch for ia64. Attached patch fixes a couple of bugs from previous version and incorporates code developed by Nan Hai. This patch works on 2.6.16-rc6 kernel. Also attached is a patch for kexec-tools which applies on top of kexec-tools-1.101 release from Eric Biederman <http://www.xmission.com/%
7Eebiederm/files/kexec/kexec-tools-1.101.tar.gz> and adds support for ia64. Please test and provide feedback.I am working on integrating kdump support and will post that patch once I have tested it.
Thanks for merging the patches,
Some issues in the patches.
1. in machine_crash_shutdown
we can't call device_shutdown, because device or device driver may fail at this point.
call to machine_shutdown is unnecessary, because high level code will call it.
2. I am afraid
#ifdef ...
#include ...
#endif
is not the linux including style, ifdefs are already in header file, you
just need to include the header. and there is also some unnecessary extern declares in your code.
3. Is the set ar.k0 code necessary? ar.k0 is already holding the right value.
4. Is the VHPT disable code necessary? kernel will soon goes into Physical mode and the new kernel will reset VHPT walker.
5. Is the PCI disable code too complex?
The overall concern is I am afraid the code is too much than necessary.
Attach is the kdump patches which I have sent to you for merging. I post it to community for early test on various platforms before merging is done.
the first patch applies to 2.6.15 kernel
the second patch applies to kexec-tools-1.101 and the generic kexec-tools-1.101-kdump.patch
to test kexec, build the kernel with CPU_HOTPLUG and kexec enabled, reboot to this kernel.
kexec -l vmlinux.gz --initrd="...." --append="...." kexec -e
the second kernel can be any kernel even an 2.4 based kernel...
to test kdump, build the first kernel with kdump enabled, you may need to enable sysrq support to help you trigger a crash.
Build a second crashdumping UP kernel with pseudo proc fs vmcore enabled.
boot to first kernel with kernel parameter crashkernel=XXXM@YYYM which means reserve XXXM memory at physical address YYYM for crashdumping kernel.
then kexec -p crash-kernel-vmlinux.gz --initrd="...." --append="...."
echo c > /proc/sysre-trigger
to tigger a crash.
Then the crash dumping kernel boots, log into the crash dumping kernel, cp /proc/vmcore core
gdb first-kernel-vmlinux core
Thanks
Zou Nan hai
arch/ia64/Kconfig +17 -0
@@ -374,6 +374,23 @@ config IA64_PALINFO To use this option, you have to ensure that the "/proc file system support" (CONFIG_PROC_FS) is enabled, too. +config KEXEC + bool "kexec system call (EXPERIMENTAL)" + depends on EXPERIMENTAL && (!SMP || HOTPLUG_CPU) + help + kexec is a system call that implements the ability to shutdown your + current kernel, and to start another kernel. It is like a reboot + but it is indepedent of the system firmware. And like a reboot + you can start any kernel with it, not just Linux. + + The name comes from the similiarity to the exec system call. + +config CRASH_DUMP + bool "kernel crash dumps (EXPERIMENTAL)" + depends on EXPERIMENTAL + help + Generate crash dump after being started by kexec. + source "drivers/firmware/Kconfig" source "fs/Kconfig.binfmt"
arch/ia64/kernel/crash.c +104 -0
104 lines not on this page · raw message
arch/ia64/kernel/efi.c +19 -15
@@ -25,6 +25,7 @@#include <linux/types.h> #include <linux/time.h> #include <linux/efi.h> +#include <linux/kexec.h> #include <asm/io.h> #include <asm/kregs.h>
@@ -40,7 +41,7 @@ extern efi_status_t efi_call_phys (voidstruct efi efi;EXPORT_SYMBOL (efi);static efi_runtime_services_t *runtime; -static unsigned long mem_limit = ~0UL , max_addr = ~0UL ; +static unsigned long mem_limit = ~0UL , max_addr = ~0UL , min_addr =0UL ; #define efi_call_virt(f, args...) (*(f))(args)
@@ -384,24 +385,18 @@ efi_init (void)efi_config_table_t *config_tables;efi_char16_t *c16;u64 efi_desc_size; -char *cp, *end, vendor[100 ] ="unknown" ; +char *cp, vendor[100 ] ="unknown" ;extern char saved_command_line[];int i;/* it's too early to be able to use the standard kernel command line support... */ for (cp = saved_command_line; *cp; ) {if (memcmp (cp,"mem=" ,4 ) ==0 ) { - cp +=4 ; - mem_limit =memparse (cp, &end); -if (end != cp) -break ; - cp = end; + mem_limit =memparse (cp +4 , &cp); }else if (memcmp (cp,"max_addr=" ,9 ) ==0 ) { - cp +=9 ; - max_addr =GRANULEROUNDDOWN (memparse (cp, &end)); -if (end != cp) -break ; - cp = end; + max_addr =GRANULEROUNDDOWN (memparse (cp +9 , &cp)); + }else if (memcmp (cp,"min_addr=" ,9 ) ==0 ) { + min_addr =GRANULEROUNDDOWN (memparse (cp +9 , &cp)); }else {while (*cp !=' ' && *cp) ++cp;
@@ -409,9 +404,11 @@ efi_init (void) ++cp; } } + +if (min_addr !=0UL ) +printk (KERN_INFO "Ignoring memory below %luMB\n" , min_addr >>20 );if (max_addr != ~0UL )printk (KERN_INFO "Ignoring memory above %luMB\n" , max_addr >>20 ); - efi.systab =__va (ia64_boot_param->efi_systab);/*
@@ -785,7 +782,8 @@ find_memmap_space (void) as =max (contig_low, md->phys_addr); ae =min (contig_high,efi_md_end (md)); -/* keep within max_addr= command line arg */ +/* keep within max_addr= and min_addr= command line arg */ + as =max (as, min_addr); ae =min (ae, max_addr);if (ae <= as)continue ;
@@ -895,7 +893,8 @@ efi_memmap_init(unsigned long *s, unsign }else ae =efi_md_end (md); -/* keep within max_addr= command line arg */ +/* keep within max_addr= and min_addr command line arg */ + as =max (as, min_addr); ae =min (ae, max_addr);if (ae <= as)continue ;
@@ -1007,6 +1006,11 @@ efi_initialize_iomem_resources(struct re*/ insert_resource (res, code_resource);insert_resource (res, data_resource); +#ifdef CONFIG_KEXEC +if (crashk_res.end > crashk_res.start) +insert_resource (res, &crashk_res); +#endif + } } }
arch/ia64/kernel/entry.S +1 -1
@@ -1588,7 +1588,7 @@ sys_call_table: data8 sys_mq_timedreceive // 1265 data8 sys_mq_notify data8 sys_mq_getsetattr - data8 sys_ni_syscall // reserved for kexec_load + data8 sys_kexec_load data8 sys_ni_syscall // reserved for vserver data8 sys_waitid // 1270 data8 sys_add_key
arch/ia64/kernel/machine_kexec.c +67 -0
67 lines not on this page · raw message
arch/ia64/kernel/Makefile +1 -0
@@ -23,6 +23,7 @@ obj-$(CONFIG_IA64_CYCLONE) += cyclone.o obj-$(CONFIG_CPU_FREQ) += cpufreq/ obj-$(CONFIG_IA64_MCA_RECOVERY) += mca_recovery.o obj-$(CONFIG_KPROBES) += kprobes.o jprobes.o +obj-$(CONFIG_KEXEC) += machine_kexec.o crash.o relocate_kernel.o obj-$(CONFIG_IA64_UNCACHED_ALLOCATOR) += uncached.o mca_recovery-y += mca_drv.o mca_drv_asm.o
arch/ia64/kernel/relocate_kernel.S +187 -0
187 lines not on this page · raw message
arch/ia64/kernel/setup.c +38 -0
@@ -43,6 +43,8 @@#include <linux/initrd.h> #include <linux/platform.h> #include <linux/pm.h> +#include <linux/kexec.h> +#include <linux/crash_dump.h> #include <asm/ia32.h> #include <asm/machvec.h>
@@ -247,6 +249,32 @@ reserve_memory (void) }#endif +#ifdef CONFIG_KEXEC +/* crashkernel=size@addr specifies the location to reserve for +* a crash kernel. By reserving this memory we guarantee +* that linux never set's it up as a DMA target. +* Useful for holding code to do something appropriate +* after a kernel panic. +*/ + { +char *from =strstr (saved_command_line,"crashkernel=" ); +if (from) { +unsigned long size, base; + size =memparse (from +12 , &from); +if (*from =='@' ) { + base =memparse (from +1 , &from); + rsvd_region[n].start = + (unsigned long )__va (base); + rsvd_region[n].end = + (unsigned long )__va (base + size); + crashk_res.start = base; + crashk_res.end = base + size -1 ; + n++; + } + } + } +#endif +efi_memmap_init (&rsvd_region[n].start, &rsvd_region[n].end); n++;
@@ -489,6 +517,16 @@ setup_arch (char **cmdline_p)if (!strstr (saved_command_line,"nomca" ))ia64_mca_init (); +#ifdef CONFIG_CRASH_DUMP + { +char *from =strstr (saved_command_line,"elfcorehdr=" ); +if (from) + elfcorehdr_addr =memparse (from+11 , &from); + + saved_max_pfn = (unsigned long )-1 ; + } +#endif +platform_setup (cmdline_p);paging_init (); }
include/asm/kexec.h +29 -0
@@ -0,0 +1,29 @@ +#ifndef _IA64_KEXEC_H +#define _IA64_KEXEC_H + +/* +* KEXEC_SOURCE_MEMORY_LIMIT maximum page get_free_page can return. +* I.e. Maximum page that is mapped directly into kernel memory, +* and kmap is not required. +* +* Someone correct me if FIXADDR_START - PAGEOFFSET is not the correct +* calculation for the amount of memory directly mappable into the +* kernel memory space. +*/ + +/* Maximum physical address we can use pages from */ +#define KEXEC_SOURCE_MEMORY_LIMIT (-1UL) +/* Maximum address we can reach in physical address mode */ +#define KEXEC_DESTINATION_MEMORY_LIMIT (-1UL) +/* Maximum address we can use for the control code buffer */ +#define KEXEC_CONTROL_MEMORY_LIMIT TASK_SIZE + +#define KEXEC_CONTROL_CODE_SIZE (1UL << 14) + +/* The native architecture */ +#define KEXEC_ARCH KEXEC_ARCH_IA_64 + +#define MAX_NOTE_BYTES 1024 +typedef u32 note_buf_t [MAX_NOTE_BYTES /4 ]; +extern note_buf_t crash_notes[]; +#endif
include/asm/meminit.h +2 -1
@@ -16,11 +16,12 @@* - initrd (optional) * - command line string * - kernel code & data +* - crash dumping code reserved region * - Kernel memory map built from EFI memory map * * More could be added if necessary */ -#define IA64_MAX_RSVD_REGIONS 6 +#define IA64_MAX_RSVD_REGIONS 7struct rsvd_region {unsigned long start;/* virtual address of beginning of element */
include/asm-ia64/kexec.h +29 -0
@@ -0,0 +1,29 @@ +#ifndef _IA64_KEXEC_H +#define _IA64_KEXEC_H + +/* +* KEXEC_SOURCE_MEMORY_LIMIT maximum page get_free_page can return. +* I.e. Maximum page that is mapped directly into kernel memory, +* and kmap is not required. +* +* Someone correct me if FIXADDR_START - PAGEOFFSET is not the correct +* calculation for the amount of memory directly mappable into the +* kernel memory space. +*/ + +/* Maximum physical address we can use pages from */ +#define KEXEC_SOURCE_MEMORY_LIMIT (-1UL) +/* Maximum address we can reach in physical address mode */ +#define KEXEC_DESTINATION_MEMORY_LIMIT (-1UL) +/* Maximum address we can use for the control code buffer */ +#define KEXEC_CONTROL_MEMORY_LIMIT TASK_SIZE + +#define KEXEC_CONTROL_CODE_SIZE (1UL << 14) + +/* The native architecture */ +#define KEXEC_ARCH KEXEC_ARCH_IA_64 + +#define MAX_NOTE_BYTES 1024 +typedef u32 note_buf_t [MAX_NOTE_BYTES /4 ]; +extern note_buf_t crash_notes[]; +#endif
include/asm-ia64/meminit.h +2 -1
@@ -16,11 +16,12 @@* - initrd (optional) * - command line string * - kernel code & data +* - crash dumping code reserved region * - Kernel memory map built from EFI memory map * * More could be added if necessary */ -#define IA64_MAX_RSVD_REGIONS 6 +#define IA64_MAX_RSVD_REGIONS 7struct rsvd_region {unsigned long start;/* virtual address of beginning of element */
include/linux/kexec.h +1 -1
@@ -41,7 +41,7 @@ typedef unsigned long kimage_entry_t;#define IND_DONE 0x4#define IND_SOURCE 0x8 -#define KEXEC_SEGMENT_MAX 8 +#define KEXEC_SEGMENT_MAX 16struct kexec_segment {void __user *buf;size_t bufsz;
Quoted 2 lines · Zou Nan hai
3. Is the set ar.k0 code necessary? ar.k0 is already holding the right value.
Purely defensive coding to ensure new kernel does not fall on its face :)
Quoted 3 lines
4. Is the VHPT disable code necessary? kernel will soon goes into Physical mode and the new kernel will reset VHPT walker.
Again, playing it safe. We do not want VHPT walker waking up at this point. Instead of assuming code will not do anything that could cause VHPT walker to wake up, it is better to just disable it. This way, if any code makes erroneous references to a virtual address which causes VHPT walker to make a TLB entry, it will simply get a page fault and we can catch that. It is much harder to debug if VHPT walker silently makes a TLB entry for an unexpected virtual address reference and then things go wrong further down the line.
Quoted 2 lines
5. Is the PCI disable code too complex?
I have simplified it as much as I can. Suggestions to simplify further would be appreciated.
Quoted 4 lines
The overall concern is I am afraid the code is too much than necessary.
After testing this kexec code for over 10,000 iterations of kexec'ing, I have found not shutting devices down results in many corner cases that have been fairly hard to debug. Adding all this code to shut down as much of the hardware as possible has resulted in much more reliable kexec code.
Signature · 9 lines
Khalid ================================== Khalid Aziz Open Source and Linux Organization (970)898-9214 Hewlett-Packard [email protected] Fort Collins, CO "The Linux kernel is subject to relentless development" - Alessandro Rubini
Quoted 7 lines · Khalid Aziz
Quoted 2 lines · Zou Nan hai
3. Is the set ar.k0 code necessary? ar.k0 is already holding the right value.
Purely defensive coding to ensure new kernel does not fall on its face :)
I am afraid purely defensive code should go through efi memory map and
find out the ar.k0. This can be done in purgatory code, In my current pugatory implement, ar.k0 is take from the previous kernel, but I can modify it to pick the value from efi memmap if this is really a concern.
Quoted 4 lines
Quoted 3 lines
4. Is the VHPT disable code necessary? kernel will soon goes into Physical mode and the new kernel will reset VHPT walker.
Quoted 9 lines
Again, playing it safe. We do not want VHPT walker waking up at this point. Instead of assuming code will not do anything that could cause VHPT walker to wake up, it is better to just disable it. This way, if any code makes erroneous references to a virtual address which causes VHPT walker to make a TLB entry, it will simply get a page fault and we can catch that. It is much harder to debug if VHPT walker silently makes a TLB entry for an unexpected virtual address reference and then things go wrong further down the line.
But we are running in physical mode, how could VHPT walker be
invoked?
Quoted 6 lines
Quoted 2 lines
5. Is the PCI disable code too complex?
I have simplified it as much as I can. Suggestions to simplify further would be appreciated.
Quoted 1 line
I am afraid the irq and device disable code in machine_shutdown in
your patch will never be called because kernel has already iterate on each device and called the driver->shutdown method for them, and I don't think we need to set affinity and power state here.
Please take a look at my patch, machine_shutdown is empty except CPU
down code. There is another function device_shootdown used at the time of crashing.
Quoted 9 lines
Quoted 3 lines
The overall concern is I am afraid the code is too much than necessary.
After testing this kexec code for over 10,000 iterations of kexec'ing, I have found not shutting devices down results in many corner cases that have been fairly hard to debug. Adding all this code to shut down as much of the hardware as possible has resulted in much more reliable kexec code.
I have also tested tens of thousands round of kexec to kexec over my
patch, I have never seem device shutdown issue.
I still prefer small and clean kernel patch than put too much
redundant code in kernel.
Thanks.
Zou Nan hai