From: Horms Subject: Re: Re: [PATCH]: kexec: framework and i386 (Take IX) Date: Wed, 17 May 2006 18:52:15 +0900 Message-ID: <20060517095213.GA31686@verge.net.au> References: <20060509091849.GA18206@verge.net.au> <3c347db5fc144e0809c47b5efe8f6582@cl.cam.ac.uk> <12c36e8e9c573c900cd75f27b3d650d3@cl.cam.ac.uk> <20060517024402.GA13874@verge.net.au> <20060517045322.GA24072@verge.net.au> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="UlVJffcvxoiEqYs2" Return-path: Content-Disposition: inline In-Reply-To: <20060517045322.GA24072@verge.net.au> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Keir Fraser Cc: Ian Pratt , Kazuo Moriwaka , xen-devel@lists.xensource.com, Akio Takebe , Isaku Yamahata , Magnus Damm , Mark Williamson List-Id: xen-devel@lists.xenproject.org --UlVJffcvxoiEqYs2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, as promised earlier in the day, here is an update on the kexec/kdump patch. The main changes are that SMP now works, and the dumping of cpu registers for kdump has been moved into the hypervisor so as to allow all CPUs to be captured, not just dom0's VCPUs. Also, as mentioned earlier in the day linux->xen and xen->xen kexec does work, contrary to what I previously reported. I have also broken the patch out into generic, x86 and x86_32 patches which need to be applied in that order. This was done to allow other architectures to be worked on more easily. By that, I mean it makes it easier for my colleagues and I to work together. It should also make it easier to review the code. If a monolithic patch is desired please let me know as it is very easy for me to produce one. I hope to make the next round available within the next few (working) days. This will change page table handling around a bit (only for kexec/kdump not for the rest of the time) so as to avoid trampling the page tables, which is a problem for kdump as it destroys data that might otherwise be analysed. My colleague Magnus Damm is working on having his approach addoped by Linux kdump. Beyond that, Magnus has also been working on a x86_64 port, though that is not quite working. And I plan to start on ia64 soon. -- Horms http://www.vergenet.net/~horms/ --UlVJffcvxoiEqYs2 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="51.1-kexec-generic-upstream.patch" kexec: framework This is an implementation of kexec for dom0/xen, that allows kexecing of the physical machine from xen. The approach taken is to move the architecture-dependant kexec code into a new hypercall. This patch only includes the framework, it cann't be used without architecture dependant hooks, however the code should compile as is. linux-2.6-xen-sparse/drivers/xen/core/Makefile | 1 linux-2.6-xen-sparse/drivers/xen/core/crash.c | 48 ++ linux-2.6-xen-sparse/drivers/xen/core/machine_kexec.c | 100 ++++++ linux-2.6-xen-sparse/drivers/xen/core/reboot.c | 4 linux-2.6-xen-sparse/include/asm-i386/kexec-xen.h | 27 + patches/linux-2.6.16.13/kexec.patch | 274 +++++++++++++++++ xen/arch/x86/Makefile | 2 xen/arch/x86/crash.c | 26 + xen/arch/x86/machine_kexec.c | 51 +++ xen/common/Makefile | 1 xen/common/kexec.c | 183 +++++++++++ xen/common/page_alloc.c | 33 +- xen/drivers/char/console.c | 3 xen/include/asm-x86/kexec.h | 32 + xen/include/public/kexec.h | 48 ++ xen/include/public/xen.h | 12 xen/include/xen/elfcore.h | 73 ++++ xen/include/xen/kexec.h | 33 ++ xen/include/xen/mm.h | 1 19 files changed, 941 insertions(+), 11 deletions(-) --- x/linux-2.6-xen-sparse/drivers/xen/core/Makefile +++ x/linux-2.6-xen-sparse/drivers/xen/core/Makefile @@ -9,3 +9,4 @@ obj-$(CONFIG_NET) += skbuff.o obj-$(CONFIG_SMP) += smpboot.o obj-$(CONFIG_SYSFS) += hypervisor_sysfs.o obj-$(CONFIG_XEN_SYSFS) += xen_sysfs.o +obj-$(CONFIG_KEXEC) += machine_kexec.o crash.o --- /dev/null +++ x/linux-2.6-xen-sparse/drivers/xen/core/crash.c @@ -0,0 +1,48 @@ +/* + * Architecture independent functions for kexec based crash dumps in xen. + * + * Created by: Horms + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * This passes the registers's down to the hypervisor and has it kexec() + * This is a bit different to the linux implementation which + * has this call save registers and stop CPUs and then goes into + * machine_kexec() later. But for Xen it makes more sense to + * have the kexec hypercall do everything, and this call + * has the registers parameter that is needed. + * to the hypervisor to allow the hypervisor to kdump itself + * on an internal panic + */ +void machine_crash_shutdown(struct pt_regs *regs) +{ + kexec_arg_t hypercall_arg; + printk("machine_crash_shutdown: %d\n", smp_processor_id()); + local_irq_disable(); +#ifdef CONFIG_X86_IO_APIC + disable_IO_APIC(); +#endif + crash_translate_regs(regs, &hypercall_arg.u.regs); + HYPERVISOR_kexec(KEXEC_CMD_kexec, KEXEC_TYPE_CRASH, &hypercall_arg); +} + +/* + * Local variables: + * c-file-style: "linux" + * indent-tabs-mode: t + * c-indent-level: 8 + * c-basic-offset: 8 + * tab-width: 8 + * End: + */ --- /dev/null +++ x/linux-2.6-xen-sparse/drivers/xen/core/machine_kexec.c @@ -0,0 +1,100 @@ +/* + * drivers/xen/core/machine_kexec.c + * handle transition of Linux booting another kernel + * + * Created By: Horms + * + * Losely based on arch/i386/kernel/machine_kexec.c + */ + +#include +#include +#include +#include +#include + +const extern unsigned char relocate_new_kernel[]; +extern unsigned int relocate_new_kernel_size; + +/* + * A architecture hook called to validate the + * proposed image and prepare the control pages + * as needed. The pages for KEXEC_CONTROL_CODE_SIZE + * have been allocated, but the segments have yet + * been copied into the kernel. + * + * Do what every setup is needed on image and the + * reboot code buffer to allow us to avoid allocations + * later. + * + * Currently nothing. + */ +int machine_kexec_prepare(struct kimage *image) +{ + return HYPERVISOR_kexec(KEXEC_CMD_kexec_prepare, image->type, NULL); +} + +/* + * Undo anything leftover by machine_kexec_prepare + * when an image is freed. + */ +void machine_kexec_cleanup(struct kimage *image) +{ + HYPERVISOR_kexec(KEXEC_CMD_kexec_cleanup, image->type, NULL); +} + + +/* + * Load the image into xen so xen can kdump itself + * This might have been done in prepare, but prepare + * is currently called too early. It might make sense + * to move prepare, buf for now, just add an extra hook. + */ +int machine_kexec_load(struct kimage *image) +{ + kexec_arg_t hypercall_arg; + hypercall_arg.u.image.indirection_page = image->head; + hypercall_arg.u.image.reboot_code_buffer = + pfn_to_mfn(page_to_pfn(image->control_code_page)) << PAGE_SHIFT; + hypercall_arg.u.image.start_address = image->start; + hypercall_arg.u.image.relocate_new_kernel = relocate_new_kernel; + hypercall_arg.u.image.relocate_new_kernel_size = + relocate_new_kernel_size; + return HYPERVISOR_kexec(KEXEC_CMD_kexec_load, image->type, + &hypercall_arg); +} + +/* + * Unload the image that was stored by machine_kexec_load() + * This might have been done in machine_kexec_cleanup() but it + * is called too late, and its possible xen could try and kdump + * using resources that have been freed. + */ +void machine_kexec_unload(struct kimage *image) +{ + HYPERVISOR_kexec(KEXEC_CMD_kexec_unload, image->type, NULL); +} + +/* + * Do not allocate memory (or fail in any way) in machine_kexec(). + * We are past the point of no return, committed to rebooting now. + * + * This has the hypervisor move to the prefered reboot CPU, + * stop all CPUs and kexec. That is it combines machine_shutdown() + * and machine_kexec() in Linux kexec terms. + */ +NORET_TYPE void machine_kexec(struct kimage *image) +{ + printk("machine_kexec\n"); + HYPERVISOR_kexec(KEXEC_CMD_kexec, image->type, NULL); +} + +/* + * Local variables: + * c-file-style: "linux" + * indent-tabs-mode: t + * c-indent-level: 8 + * c-basic-offset: 8 + * tab-width: 8 + * End: + */ --- x/linux-2.6-xen-sparse/drivers/xen/core/reboot.c +++ x/linux-2.6-xen-sparse/drivers/xen/core/reboot.c @@ -66,6 +66,10 @@ void machine_power_off(void) HYPERVISOR_shutdown(SHUTDOWN_poweroff); } +#ifdef CONFIG_KEXEC +void machine_shutdown(void) { } +#endif + int reboot_thru_bios = 0; /* for dmi_scan.c */ EXPORT_SYMBOL(machine_restart); EXPORT_SYMBOL(machine_halt); --- /dev/null +++ x/linux-2.6-xen-sparse/include/asm-i386/kexec-xen.h @@ -0,0 +1,27 @@ +/* + * include/asm-i386/kexec-xen.h + * + * Created By: Horms + */ + +#ifndef _I386_KEXEC_XEN_H +#define _I386_KEXEC_XEN_H + +static inline void crash_translate_regs(struct pt_regs *linux_regs, + struct cpu_user_regs *xen_regs) +{ + printk("STUB: include/asm-i386/kexec-xen.h: crash_translate_regs: " + "not implemented\n"); +} + +#endif /* _I386_KEXEC_XEN_H */ + +/* + * Local variables: + * c-file-style: "linux" + * indent-tabs-mode: t + * c-indent-level: 8 + * c-basic-offset: 8 + * tab-width: 8 + * End: + */ --- x/xen/arch/x86/Makefile +++ x/xen/arch/x86/Makefile @@ -39,6 +39,8 @@ obj-y += trampoline.o obj-y += traps.o obj-y += usercopy.o obj-y += x86_emulate.o +obj-y += machine_kexec.o +obj-y += crash.o ifneq ($(pae),n) obj-$(x86_32) += shadow.o shadow_public.o shadow_guest32.o --- /dev/null +++ x/xen/arch/x86/crash.c @@ -0,0 +1,26 @@ +/****************************************************************************** + * arch/x86/crash.c + * + * Created By: Horms + * + * Should be based heavily on arch/i386/kernel/crash.c from Linux 2.6.16 + */ + +#include /* for printk() used in stub */ +#include +#include + +void machine_crash_shutdown(struct cpu_user_regs *regs) +{ + printk("STUB: arch/x86/crash.c: machine_crash_shutdown: not implemented\n"); +} + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --- /dev/null +++ x/xen/arch/x86/machine_kexec.c @@ -0,0 +1,51 @@ +/****************************************************************************** + * arch/x86/machine_kexec.c + * + * Created By: Horms + * + */ + +#include /* for printk() used in stubs */ +#include +#include + +int machine_kexec_prepare(int type, struct kexec_arg *arg) +{ + printk("STUB: arch/x86/machine_kexec.c: machine_kexec_prepare: " + "not implemented\n"); + return -1; +} + +void machine_kexec_cleanup(int type, struct kexec_arg *arg) +{ + printk("STUB: arch/x86/machine_kexec.c: machine_kexec_cleanup: " + "not implemented\n"); +} + +void machine_kexec_reserved(struct kexec_arg *arg) +{ + printk("STUB: arch/x86/machine_kexec.c: machine_kexec_reserved: " + "not implemented\n"); +} + +void machine_kexec(struct kexec_arg *arg) +{ + printk("STUB: arch/x86/machine_kexec.c: machine_kexec: " + "not implemented\n"); +} + +void machine_shutdown(struct kexec_arg *arg) +{ + printk("STUB: arch/x86/machine_shutdown.c: machine_shutdown: " + "not implemented\n"); +} + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --- x/xen/common/Makefile +++ x/xen/common/Makefile @@ -7,6 +7,7 @@ obj-y += event_channel.o obj-y += grant_table.o obj-y += kernel.o obj-y += keyhandler.o +obj-y += kexec.o obj-y += lib.o obj-y += memory.o obj-y += multicall.o --- /dev/null +++ x/xen/common/kexec.c @@ -0,0 +1,183 @@ +/* + * common/kexec.c - Achitecture independent kexec code for Xen + * + * Created By: Horms + * + * Based in part on Linux 2.6.16's kernel/kexec.c + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +DEFINE_PER_CPU (note_buf_t, crash_notes); + +static struct kexec_arg kexec_image; +static int kexec_image_set = 0; +static struct kexec_arg kexec_crash_image; +static int kexec_crash_image_set = 0; +static int kexec_crash_lock = 0; + +/* Must call with kexec_crash_lock held */ +void __crash_kexec(struct cpu_user_regs *regs) +{ + struct cpu_user_regs fixed_regs; + + if (!kexec_crash_image_set) + return; + crash_setup_regs(&fixed_regs, regs); + machine_crash_shutdown(&fixed_regs); + machine_kexec(&kexec_crash_image); /* Does not return */ +} + +void crash_kexec(struct cpu_user_regs *regs) +{ + int locked; + + locked = xchg(&kexec_crash_lock, 1); + if (locked) + return; + __crash_kexec(regs); + xchg(&kexec_crash_lock, 0); +} + +static int get_crash_note(XEN_GUEST_HANDLE(kexec_arg_t) uarg) +{ + struct kexec_arg arg; + int locked, cpu; + + if ( unlikely(copy_from_guest(&arg, uarg, 1) != 0) ) + { + printk("do_kexec: get_crash_note: __copy_from_guest failed\n"); + return -EFAULT; + } + + cpu = (int)arg.u.crash_note; + if (cpu < 0) + return -EINVAL; + + if (cpu > num_booting_cpus()) + arg.u.crash_note = 0L; + else { + locked = xchg(&kexec_crash_lock, 1); + if (locked) + { + printk("do_kexec: get_crash_note: in xen-generated kdump\n"); + return -EFAULT; + } + arg.u.crash_note = __pa((unsigned long)per_cpu(crash_notes, cpu)); + xchg(&kexec_crash_lock, 0); + } + + if ( unlikely(copy_to_guest(uarg, &arg, 1) != 0) ) + { + printk("do_kexec: get_crash_note: copy_to_guest failed\n"); + return -EFAULT; + } + + return 0; +} + + +int do_kexec(unsigned long op, int type, XEN_GUEST_HANDLE(kexec_arg_t) uarg) +{ + struct kexec_arg *image, tmp_arg; + int locked; + int *image_set; + int status = -EINVAL; + + if ( !IS_PRIV(current->domain) ) + return -EPERM; + + switch (op) + { + case KEXEC_CMD_kexec_crash_note: + return get_crash_note(uarg); + case KEXEC_CMD_kexec_reserve: + machine_kexec_reserved(&tmp_arg); + if ( unlikely(copy_to_guest(uarg, &tmp_arg, 1) != 0) ) + { + printk("do_kexec (CMD_kexec_reserve): copy_to_guest failed\n"); + return -EFAULT; + } + return 0; + } + + if (type == KEXEC_TYPE_CRASH) + { + image = &kexec_crash_image; + image_set = &kexec_crash_image_set; + locked = xchg(&kexec_crash_lock, 1); + if (locked) + { + printk("do_kexec: dump is locked\n"); + return -EFAULT; + } + } + else + { + image = &kexec_image; + image_set = &kexec_image_set; + } + + switch(op) { + case KEXEC_CMD_kexec: + BUG_ON(!*image_set); + if (type == KEXEC_TYPE_CRASH) { + if ( unlikely(copy_from_guest(&tmp_arg, uarg, 1) != 0) ) + { + printk("do_kexec (CMD_kexec): copy_from_guest failed\n"); + status = -EFAULT; + break; + } + __crash_kexec(&tmp_arg.u.regs); + } + else + machine_shutdown(image); /* Does not return */ + break; + case KEXEC_CMD_kexec_prepare: + /* Might need to tighten up kexec_crash_lock semantics, + * but this currently does nothing. ditto for cleanup */ + status = machine_kexec_prepare(type, image); + break; + case KEXEC_CMD_kexec_cleanup: + machine_kexec_cleanup(type, image); + status = 0; + break; + case KEXEC_CMD_kexec_load: + BUG_ON(*image_set); + if ( unlikely(copy_from_guest(image, uarg, 1) != 0) ) + { + printk("do_kexec (CMD_kexec_load): copy_from_guest failed\n"); + status = -EFAULT; + break; + } + *image_set = 1; + status = 0; + break; + case KEXEC_CMD_kexec_unload: + BUG_ON(!*image_set); + *image_set = 0; + status = 0; + break; + } + + if (type == KEXEC_TYPE_CRASH) + xchg(&kexec_crash_lock, 0); + return status; +} + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --- x/xen/common/page_alloc.c +++ x/xen/common/page_alloc.c @@ -212,24 +212,35 @@ void init_boot_pages(paddr_t ps, paddr_t } } +unsigned long alloc_boot_pages_at(unsigned long nr_pfns, unsigned long pfn_at) +{ + unsigned long i; + + for ( i = 0; i < nr_pfns; i++ ) + if ( allocated_in_map(pfn_at + i) ) + break; + + if ( i == nr_pfns ) + { + map_alloc(pfn_at, nr_pfns); + return pfn_at; + } + + return 0; +} + unsigned long alloc_boot_pages(unsigned long nr_pfns, unsigned long pfn_align) { - unsigned long pg, i; + unsigned long pg, i = 0; for ( pg = 0; (pg + nr_pfns) < max_page; pg += pfn_align ) { - for ( i = 0; i < nr_pfns; i++ ) - if ( allocated_in_map(pg + i) ) - break; - - if ( i == nr_pfns ) - { - map_alloc(pg, nr_pfns); - return pg; - } + i = alloc_boot_pages_at(nr_pfns, pg); + if (i != 0) + break; } - return 0; + return i; } --- x/xen/drivers/char/console.c +++ x/xen/drivers/char/console.c @@ -677,6 +677,7 @@ void panic(const char *fmt, ...) unsigned long flags; static spinlock_t lock = SPIN_LOCK_UNLOCKED; extern void machine_restart(char *); + extern void crash_kexec(struct cpu_user_regs *regs); debugtrace_dump(); @@ -696,6 +697,8 @@ void panic(const char *fmt, ...) debugger_trap_immediate(); + crash_kexec(NULL); + watchdog_disable(); mdelay(5000); machine_restart(0); --- /dev/null +++ x/xen/include/asm-x86/kexec.h @@ -0,0 +1,32 @@ +/****************************************************************************** + * include/asm-x86/kexec.h + * + * Created By: Horms + * + */ + +#ifndef __X86_KEXEC_H__ +#define __X86_KEXEC_H__ + +#include /* for printk() used in stub */ +#include +#include + +static void crash_setup_regs(struct cpu_user_regs *newregs, + struct cpu_user_regs *oldregs) +{ + printk("STUB: include/asm-x86/kexec.h: crash_setup_regs: " + "not implemented\n"); +} + +#endif /* __X86_KEXEC_H__ */ + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --- /dev/null +++ x/xen/include/public/kexec.h @@ -0,0 +1,48 @@ +/* + * kexec.h - Public portion + * + * Created By: Horms + */ + +#ifndef _XEN_PUBLIC_KEXEC_H +#define _XEN_PUBLIC_KEXEC_H + +#include "xen.h" + +#define KEXEC_TYPE_DEFAULT 0 +#define KEXEC_TYPE_CRASH 1 + +/* + * Scratch space for passing arguments to the kexec hypercall + */ +typedef struct kexec_arg { + union { + struct { + unsigned long indirection_page; + unsigned long reboot_code_buffer; + unsigned long start_address; + const char *relocate_new_kernel; + unsigned int relocate_new_kernel_size; + unsigned int type; + } image; + struct cpu_user_regs regs; + struct { + unsigned long size; + unsigned long start; + } reserve; + unsigned long crash_note; + } u; +} kexec_arg_t; +DEFINE_XEN_GUEST_HANDLE(kexec_arg_t); + +#endif + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --- x/xen/include/public/xen.h +++ x/xen/include/public/xen.h @@ -64,6 +64,7 @@ #define __HYPERVISOR_xenoprof_op 31 #define __HYPERVISOR_event_channel_op 32 #define __HYPERVISOR_physdev_op 33 +#define __HYPERVISOR_kexec_op 34 /* Architecture-specific hypercall definitions. */ #define __HYPERVISOR_arch_0 48 @@ -238,6 +239,17 @@ DEFINE_XEN_GUEST_HANDLE(mmuext_op_t); #define VMASST_TYPE_writable_pagetables 2 #define MAX_VMASST_TYPE 2 +/* + * Operations for kexec. + */ +#define KEXEC_CMD_kexec 0 +#define KEXEC_CMD_kexec_prepare 1 +#define KEXEC_CMD_kexec_cleanup 2 +#define KEXEC_CMD_kexec_load 3 +#define KEXEC_CMD_kexec_unload 4 +#define KEXEC_CMD_kexec_reserve 5 +#define KEXEC_CMD_kexec_crash_note 6 + #ifndef __ASSEMBLY__ typedef uint16_t domid_t; --- /dev/null +++ x/xen/include/xen/elfcore.h @@ -0,0 +1,73 @@ +/****************************************************************************** + * include/xen/elfcore.h + * + * Created By: Horms + * + * Based heavily on include/linux/elfcore.h from Linux 2.6.16 + * Naming scheeme based on include/xen/elf.h (not include/linux/elfcore.h) + * + */ + +#ifndef __ELFCOREC_H__ +#define __ELFCOREC_H__ + +#include +#include +#include + +#define NT_PRSTATUS 1 + +typedef struct +{ + int signo; /* signal number */ + int code; /* extra code */ + int errno; /* errno */ +} ELF_Signifo; + +/* These seem to be the same length on all architectures on Linux */ +typedef int ELF_Pid; +typedef struct { + long tv_sec; + long tv_usec; +} ELF_Timeval; +typedef unsigned long ELF_Greg; +#define ELF_NGREG (sizeof (struct cpu_user_regs) / sizeof(ELF_Greg)) +typedef ELF_Greg ELF_Gregset[ELF_NGREG]; + +/* + * Definitions to generate Intel SVR4-like core files. + * These mostly have the same names as the SVR4 types with "elf_" + * tacked on the front to prevent clashes with linux definitions, + * and the typedef forms have been avoided. This is mostly like + * the SVR4 structure, but more Linuxy, with things that Linux does + * not support and which gdb doesn't really use excluded. + */ +typedef struct +{ + ELF_Signifo pr_info; /* Info associated with signal */ + short pr_cursig; /* Current signal */ + unsigned long pr_sigpend; /* Set of pending signals */ + unsigned long pr_sighold; /* Set of held signals */ + ELF_Pid pr_pid; + ELF_Pid pr_ppid; + ELF_Pid pr_pgrp; + ELF_Pid pr_sid; + ELF_Timeval pr_utime; /* User time */ + ELF_Timeval pr_stime; /* System time */ + ELF_Timeval pr_cutime; /* Cumulative user time */ + ELF_Timeval pr_cstime; /* Cumulative system time */ + ELF_Gregset pr_reg; /* GP registers */ + int pr_fpvalid; /* True if math co-processor being used. */ +} ELF_Prstatus; + +#endif /* __ELFCOREC_H__ */ + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --- /dev/null +++ x/xen/include/xen/kexec.h @@ -0,0 +1,33 @@ +/* + * include/xen/kexec.h - Internal archtecture independant portion + * + * Created By: Horms + * + */ + +#include + +#define MAX_NOTE_BYTES 1024 + +typedef u32 note_buf_t[MAX_NOTE_BYTES/4]; +DECLARE_PER_CPU (note_buf_t, crash_notes); + +int machine_kexec_prepare(int type, struct kexec_arg *arg); +void machine_kexec_cleanup(int type, struct kexec_arg *arg); +void machine_kexec_reserved(struct kexec_arg *arg); +void machine_kexec(struct kexec_arg *arg); +void machine_shutdown(struct kexec_arg *arg); +void machine_crash_shutdown(struct cpu_user_regs *regs); + +extern unsigned int opt_kdump_megabytes; +extern unsigned int opt_kdump_megabytes_base; + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --- x/xen/include/xen/mm.h +++ x/xen/include/xen/mm.h @@ -40,6 +40,7 @@ struct page_info; paddr_t init_boot_allocator(paddr_t bitmap_start); void init_boot_pages(paddr_t ps, paddr_t pe); unsigned long alloc_boot_pages(unsigned long nr_pfns, unsigned long pfn_align); +unsigned long alloc_boot_pages_at(unsigned long nr_pfns, unsigned long pfn_at); void end_boot_allocator(void); /* Generic allocator. These functions are *not* interrupt-safe. */ --- /dev/null 2006-05-09 15:32:30.399072192 +0900 +++ x/patches/linux-2.6.16.13/kexec.patch 2006-05-17 18:37:45.000000000 +0900 @@ -0,0 +1,274 @@ +--- x/drivers/base/cpu.c ++++ x/drivers/base/cpu.c +@@ -80,12 +80,30 @@ void unregister_cpu(struct cpu *cpu, str + #else /* ... !CONFIG_HOTPLUG_CPU */ + static inline void register_cpu_control(struct cpu *cpu) + { ++#ifdef CONFIG_XEN ++#include ++ kexec_arg_t hypercall_arg; ++ hypercall_arg.u.crash_note = (unsigned long)cpu; ++#endif + } + #endif /* CONFIG_HOTPLUG_CPU */ + + #ifdef CONFIG_KEXEC + #include + ++#ifdef CONFIG_XEN ++static unsigned long get_crash_notes(int cpu) ++{ ++ kexec_arg_t hypercall_arg; ++ ++ hypercall_arg.u.crash_note = (unsigned long)cpu; ++ if (HYPERVISOR_kexec(KEXEC_CMD_kexec_crash_note, 0, &hypercall_arg) < 0) ++ return 0L; ++ return hypercall_arg.u.crash_note; ++} ++#endif ++ ++/* XXX: This only finds dom0's CPU's */ + static ssize_t show_crash_notes(struct sys_device *dev, char *buf) + { + struct cpu *cpu = container_of(dev, struct cpu, sysdev); +@@ -101,7 +119,11 @@ static ssize_t show_crash_notes(struct s + * boot up and this data does not change there after. Hence this + * operation should be safe. No locking required. + */ ++#ifndef CONFIG_XEN + addr = __pa(per_cpu_ptr(crash_notes, cpunum)); ++#else ++ addr = (unsigned long long)get_crash_notes(cpunum); ++#endif + rc = sprintf(buf, "%Lx\n", addr); + return rc; + } +--- x/include/linux/kexec.h ++++ x/include/linux/kexec.h +@@ -91,6 +91,10 @@ struct kimage { + extern NORET_TYPE void machine_kexec(struct kimage *image) ATTRIB_NORET; + extern int machine_kexec_prepare(struct kimage *image); + extern void machine_kexec_cleanup(struct kimage *image); ++#ifdef CONFIG_XEN ++extern int machine_kexec_load(struct kimage *image); ++extern void machine_kexec_unload(struct kimage *image); ++#endif + extern asmlinkage long sys_kexec_load(unsigned long entry, + unsigned long nr_segments, + struct kexec_segment __user *segments, +--- x/kernel/kexec.c ++++ x/kernel/kexec.c +@@ -27,8 +27,10 @@ + #include + #include + ++#ifndef CONFIG_XEN + /* Per cpu memory for storing cpu states in case of system crash. */ + note_buf_t* crash_notes; ++#endif + + /* Location of the reserved area for the crash kernel */ + struct resource crashk_res = { +@@ -38,6 +40,20 @@ struct resource crashk_res = { + .flags = IORESOURCE_BUSY | IORESOURCE_MEM + }; + ++/* Kexec needs to know about the actually physical addresss. ++ * But in xen, a physical address is a pseudo-physical addresss. */ ++#ifndef CONFIG_XEN ++#define kexec_page_to_pfn(page) page_to_pfn(page) ++#define kexec_pfn_to_page(pfn) pfn_to_page(pfn) ++#define kexec_virt_to_phys(addr) virt_to_phys(addr) ++#define kexec_phys_to_virt(addr) phys_to_virt(addr) ++#else ++#define kexec_page_to_pfn(page) pfn_to_mfn(page_to_pfn(page)) ++#define kexec_pfn_to_page(pfn) pfn_to_page(mfn_to_pfn(pfn)) ++#define kexec_virt_to_phys(addr) virt_to_machine(addr) ++#define kexec_phys_to_virt(addr) phys_to_virt(machine_to_phys(addr)) ++#endif ++ + int kexec_should_crash(struct task_struct *p) + { + if (in_interrupt() || !p->pid || p->pid == 1 || panic_on_oops) +@@ -403,7 +419,7 @@ static struct page *kimage_alloc_normal_ + pages = kimage_alloc_pages(GFP_KERNEL, order); + if (!pages) + break; +- pfn = page_to_pfn(pages); ++ pfn = kexec_page_to_pfn(pages); + epfn = pfn + count; + addr = pfn << PAGE_SHIFT; + eaddr = epfn << PAGE_SHIFT; +@@ -437,6 +453,7 @@ static struct page *kimage_alloc_normal_ + return pages; + } + ++#ifndef CONFIG_XEN + static struct page *kimage_alloc_crash_control_pages(struct kimage *image, + unsigned int order) + { +@@ -490,7 +507,7 @@ static struct page *kimage_alloc_crash_c + } + /* If I don't overlap any segments I have found my hole! */ + if (i == image->nr_segments) { +- pages = pfn_to_page(hole_start >> PAGE_SHIFT); ++ pages = kexec_pfn_to_page(hole_start >> PAGE_SHIFT); + break; + } + } +@@ -517,6 +534,13 @@ struct page *kimage_alloc_control_pages( + + return pages; + } ++#else /* !CONFIG_XEN */ ++struct page *kimage_alloc_control_pages(struct kimage *image, ++ unsigned int order) ++{ ++ return kimage_alloc_normal_control_pages(image, order); ++} ++#endif + + static int kimage_add_entry(struct kimage *image, kimage_entry_t entry) + { +@@ -532,7 +556,7 @@ static int kimage_add_entry(struct kimag + return -ENOMEM; + + ind_page = page_address(page); +- *image->entry = virt_to_phys(ind_page) | IND_INDIRECTION; ++ *image->entry = kexec_virt_to_phys(ind_page) | IND_INDIRECTION; + image->entry = ind_page; + image->last_entry = ind_page + + ((PAGE_SIZE/sizeof(kimage_entry_t)) - 1); +@@ -593,13 +617,13 @@ static int kimage_terminate(struct kimag + #define for_each_kimage_entry(image, ptr, entry) \ + for (ptr = &image->head; (entry = *ptr) && !(entry & IND_DONE); \ + ptr = (entry & IND_INDIRECTION)? \ +- phys_to_virt((entry & PAGE_MASK)): ptr +1) ++ kexec_phys_to_virt((entry & PAGE_MASK)): ptr +1) + + static void kimage_free_entry(kimage_entry_t entry) + { + struct page *page; + +- page = pfn_to_page(entry >> PAGE_SHIFT); ++ page = kexec_pfn_to_page(entry >> PAGE_SHIFT); + kimage_free_pages(page); + } + +@@ -611,6 +635,10 @@ static void kimage_free(struct kimage *i + if (!image) + return; + ++#ifdef CONFIG_XEN ++ machine_kexec_unload(image); ++#endif ++ + kimage_free_extra_pages(image); + for_each_kimage_entry(image, ptr, entry) { + if (entry & IND_INDIRECTION) { +@@ -686,7 +714,7 @@ static struct page *kimage_alloc_page(st + * have a match. + */ + list_for_each_entry(page, &image->dest_pages, lru) { +- addr = page_to_pfn(page) << PAGE_SHIFT; ++ addr = kexec_page_to_pfn(page) << PAGE_SHIFT; + if (addr == destination) { + list_del(&page->lru); + return page; +@@ -701,12 +729,12 @@ static struct page *kimage_alloc_page(st + if (!page) + return NULL; + /* If the page cannot be used file it away */ +- if (page_to_pfn(page) > ++ if (kexec_page_to_pfn(page) > + (KEXEC_SOURCE_MEMORY_LIMIT >> PAGE_SHIFT)) { + list_add(&page->lru, &image->unuseable_pages); + continue; + } +- addr = page_to_pfn(page) << PAGE_SHIFT; ++ addr = kexec_page_to_pfn(page) << PAGE_SHIFT; + + /* If it is the destination page we want use it */ + if (addr == destination) +@@ -729,7 +757,7 @@ static struct page *kimage_alloc_page(st + struct page *old_page; + + old_addr = *old & PAGE_MASK; +- old_page = pfn_to_page(old_addr >> PAGE_SHIFT); ++ old_page = kexec_pfn_to_page(old_addr >> PAGE_SHIFT); + copy_highpage(page, old_page); + *old = addr | (*old & ~PAGE_MASK); + +@@ -779,7 +807,7 @@ static int kimage_load_normal_segment(st + result = -ENOMEM; + goto out; + } +- result = kimage_add_page(image, page_to_pfn(page) ++ result = kimage_add_page(image, kexec_page_to_pfn(page) + << PAGE_SHIFT); + if (result < 0) + goto out; +@@ -811,6 +839,7 @@ out: + return result; + } + ++#ifndef CONFIG_XEN + static int kimage_load_crash_segment(struct kimage *image, + struct kexec_segment *segment) + { +@@ -833,7 +862,7 @@ static int kimage_load_crash_segment(str + char *ptr; + size_t uchunk, mchunk; + +- page = pfn_to_page(maddr >> PAGE_SHIFT); ++ page = kexec_pfn_to_page(maddr >> PAGE_SHIFT); + if (page == 0) { + result = -ENOMEM; + goto out; +@@ -881,6 +910,13 @@ static int kimage_load_segment(struct ki + + return result; + } ++#else /* CONFIG_XEN */ ++static int kimage_load_segment(struct kimage *image, ++ struct kexec_segment *segment) ++{ ++ return kimage_load_normal_segment(image, segment); ++} ++#endif + + /* + * Exec Kernel system call: for obvious reasons only root may call it. +@@ -991,6 +1027,11 @@ asmlinkage long sys_kexec_load(unsigned + if (result) + goto out; + } ++#ifdef CONFIG_XEN ++ result = machine_kexec_load(image); ++ if (result) ++ goto out; ++#endif + /* Install the new kernel, and Uninstall the old */ + image = xchg(dest_image, image); + +@@ -1045,7 +1086,6 @@ void crash_kexec(struct pt_regs *regs) + struct kimage *image; + int locked; + +- + /* Take the kexec_lock here to prevent sys_kexec_load + * running on one cpu from replacing the crash kernel + * we are using after a panic on a different cpu. +@@ -1067,6 +1107,7 @@ void crash_kexec(struct pt_regs *regs) + } + } + ++#ifndef CONFIG_XEN + static int __init crash_notes_memory_init(void) + { + /* Allocate memory for saving cpu registers. */ +@@ -1079,3 +1120,4 @@ static int __init crash_notes_memory_ini + return 0; + } + module_init(crash_notes_memory_init) ++#endif --UlVJffcvxoiEqYs2 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="51.2.1-kexec-x86-upstream.patch" kexec: x86 This is the x86 component of kexec for xen. The generic component is a prerequsite for this patch. The x86_64 or x86_32 (i386) patch is also needed in order to use this code, however the code should compile is. xen/arch/x86/crash.c | 171 ++++++++++++++++++++++++++++++++++- xen/arch/x86/dom0_ops.c | 3 xen/arch/x86/machine_kexec.c | 58 +++++++++-- xen/arch/x86/setup.c | 75 +++++++++++++-- xen/arch/x86/x86_32/Makefile | 1 xen/arch/x86/x86_32/machine_kexec.c | 27 +++++ xen/arch/x86/x86_64/Makefile | 1 xen/arch/x86/x86_64/machine_kexec.c | 28 +++++ xen/common/kexec.c | 3 xen/include/asm-x86/elf.h | 27 +++++ xen/include/asm-x86/hypercall.h | 6 + xen/include/asm-x86/kexec.h | 14 +- xen/include/asm-x86/x86_32/elf.h | 30 ++++++ xen/include/asm-x86/x86_32/kexec.h | 51 ++++++++++ xen/include/asm-x86/x86_64/elf.h | 30 ++++++ xen/include/asm-x86/x86_64/kexec.h | 50 ++++++++++ 16 files changed, 542 insertions(+), 33 deletions(-) --- x/xen/arch/x86/crash.c +++ x/xen/arch/x86/crash.c @@ -3,16 +3,181 @@ * * Created By: Horms * - * Should be based heavily on arch/i386/kernel/crash.c from Linux 2.6.16 + * Based heavily on arch/i386/kernel/crash.c from Linux 2.6.16 */ -#include /* for printk() used in stub */ +#include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include +static int crashing_cpu; + +static u32 *append_elf_note(u32 *buf, char *name, unsigned type, void *data, + size_t data_len) +{ + Elf_Note note; + + note.namesz = strlen(name) + 1; + note.descsz = data_len; + note.type = type; + memcpy(buf, ¬e, sizeof(note)); + buf += (sizeof(note) +3)/4; + memcpy(buf, name, note.namesz); + buf += (note.namesz + 3)/4; + memcpy(buf, data, note.descsz); + buf += (note.descsz + 3)/4; + + return buf; +} + +static void final_note(u32 *buf) +{ + Elf_Note note; + + note.namesz = 0; + note.descsz = 0; + note.type = 0; + memcpy(buf, ¬e, sizeof(note)); +} + +static void crash_save_this_cpu(struct cpu_user_regs *regs, int cpu) +{ + ELF_Prstatus prstatus; + uint32_t *buf; + + printk("crash_save_this_cpu: %d\n", cpu); + + if ((cpu < 0) || (cpu >= NR_CPUS)) + return; + + /* Using ELF notes here is opportunistic. + * A well defined structure format with tags is needed + * ELF notes happen to provide this and there is infastructure + * in the Linux kernel to supprot them. In order to make + * crash dumps produced by xen the same, the same + * technique is used here. + */ + + /* It should be safe to use per_cpu() here instead of per_cpu_ptr() + * (which does not exist in xen) as kexecing_lock must be held in + * order to get anywhere near here */ + buf = (uint32_t *)per_cpu(crash_notes, cpu); + if (!buf) /* XXX: Can this ever occur? */ + return; + memset(&prstatus, 0, sizeof(prstatus)); + /* XXX: Xen does not have processes. For the crashing CPU on a dom0 + * crash this could be pased down from dom0, but is this + * neccessary? + * prstatus.pr_pid = current->pid; */ + ELF_CORE_COPY_REGS(prstatus.pr_reg, regs); + buf = append_elf_note(buf, "CORE", NT_PRSTATUS, &prstatus, + sizeof(prstatus)); + final_note(buf); +} + +static void crash_save_self(struct cpu_user_regs *regs) +{ + crash_save_this_cpu(regs, smp_processor_id()); +} + +#ifdef CONFIG_SMP +static atomic_t waiting_for_crash_ipi; + +static int crash_nmi_callback(struct cpu_user_regs *regs, int cpu) +{ + struct cpu_user_regs fixed_regs; + + /* Don't do anything if this handler is invoked on crashing cpu. + * Otherwise, system will completely hang. Crashing cpu can get + * an NMI if system was initially booted with nmi_watchdog parameter. + */ + if (cpu == crashing_cpu) + return 1; + local_irq_disable(); + + if (!user_mode(regs)) { + crash_fixup_ss_esp(&fixed_regs, regs); + regs = &fixed_regs; + } + crash_save_this_cpu(regs, cpu); + disable_local_APIC(); + atomic_dec(&waiting_for_crash_ipi); + /* Assume hlt works */ + __asm__ __volatile__ ( "hlt" ); + for(;;); + + return 1; + + /* Need to use this somewhere as Xen builds with -Werror */ + crash_setup_regs(&fixed_regs, regs); +} + +/* + * By using the NMI code instead of a vector we just sneak thru the + * word generator coming out with just what we want. AND it does + * not matter if clustered_apic_mode is set or not. + */ +static void smp_send_nmi_allbutself(void) +{ + cpumask_t allbutself = cpu_online_map; + cpu_clear(smp_processor_id(), allbutself); + send_IPI_mask(allbutself, APIC_DM_NMI); +} + +static void nmi_shootdown_cpus(void) +{ + unsigned long msecs; + + atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1); + /* Would it be better to replace the trap vector here? */ + set_nmi_callback(crash_nmi_callback); + /* Ensure the new callback function is set before sending + * out the NMI + */ + wmb(); + + smp_send_nmi_allbutself(); + + msecs = 1000; /* Wait at most a second for the other cpus to stop */ + while ((atomic_read(&waiting_for_crash_ipi) > 0) && msecs) { + mdelay(1); + msecs--; + } + + /* Leave the nmi callback set */ + disable_local_APIC(); +} +#else +static void nmi_shootdown_cpus(void) +{ + /* There are no cpus to shootdown */ +} +#endif + void machine_crash_shutdown(struct cpu_user_regs *regs) { - printk("STUB: arch/x86/crash.c: machine_crash_shutdown: not implemented\n"); + printk("machine_crash_shutdown: %d\n", smp_processor_id()); + local_irq_disable(); + + crashing_cpu = smp_processor_id(); + nmi_shootdown_cpus(); +#ifdef CONFIG_X86_IO_APIC + disable_IO_APIC(); +#endif + crash_save_self(regs); } /* --- x/xen/arch/x86/dom0_ops.c +++ x/xen/arch/x86/dom0_ops.c @@ -29,6 +29,9 @@ #include #include "cpu/mtrr/mtrr.h" +extern unsigned int opt_kdump_megabytes; +extern unsigned int opt_kdump_megabytes_base; + #define TRC_DOM0OP_ENTER_BASE 0x00020000 #define TRC_DOM0OP_LEAVE_BASE 0x00030000 --- x/xen/arch/x86/machine_kexec.c +++ x/xen/arch/x86/machine_kexec.c @@ -5,39 +5,71 @@ * */ -#include /* for printk() used in stubs */ +#include +#include +#include +#include +#include +#include #include +#include +#include #include int machine_kexec_prepare(int type, struct kexec_arg *arg) { - printk("STUB: arch/x86/machine_kexec.c: machine_kexec_prepare: " - "not implemented\n"); - return -1; + return 0; } void machine_kexec_cleanup(int type, struct kexec_arg *arg) { - printk("STUB: arch/x86/machine_kexec.c: machine_kexec_cleanup: " - "not implemented\n"); } void machine_kexec_reserved(struct kexec_arg *arg) { - printk("STUB: arch/x86/machine_kexec.c: machine_kexec_reserved: " - "not implemented\n"); + arg->u.reserve.size = opt_kdump_megabytes << 20; + arg->u.reserve.start = opt_kdump_megabytes_base << 20; } -void machine_kexec(struct kexec_arg *arg) +static void __machine_shutdown(void *data) { - printk("STUB: arch/x86/machine_kexec.c: machine_kexec: " - "not implemented\n"); + struct kexec_arg *arg = (struct kexec_arg *)data; + + printk("__machine_shutdown: cpu=%u\n", smp_processor_id()); + + watchdog_disable(); + console_start_sync(); + + smp_send_stop(); + +#ifdef CONFIG_X86_IO_APIC + disable_IO_APIC(); +#endif + + machine_kexec(arg); } void machine_shutdown(struct kexec_arg *arg) { - printk("STUB: arch/x86/machine_shutdown.c: machine_shutdown: " - "not implemented\n"); + int reboot_cpu_id; + cpumask_t reboot_cpu; + + + reboot_cpu_id = 0; + + if (!cpu_isset(reboot_cpu_id, cpu_online_map)) + reboot_cpu_id = smp_processor_id(); + + if (reboot_cpu_id != smp_processor_id()) { + cpus_clear(reboot_cpu); + cpu_set(reboot_cpu_id, reboot_cpu); + on_selected_cpus(reboot_cpu, __machine_shutdown, arg, 1, 0); + for (;;) + ; /* nothing */ + } + else + __machine_shutdown(arg); + BUG(); } /* --- x/xen/arch/x86/setup.c +++ x/xen/arch/x86/setup.c @@ -38,6 +38,11 @@ static unsigned int opt_xenheap_megabyte integer_param("xenheap_megabytes", opt_xenheap_megabytes); #endif +unsigned int opt_kdump_megabytes = 0; +integer_param("kdump_megabytes", opt_kdump_megabytes); +unsigned int opt_kdump_megabytes_base = 0; +integer_param("kdump_megabytes_base", opt_kdump_megabytes_base); + /* opt_nosmp: If true, secondary processors are ignored. */ static int opt_nosmp = 0; boolean_param("nosmp", opt_nosmp); @@ -192,6 +197,20 @@ static void percpu_free_unused_areas(voi __pa(__per_cpu_end)); } +void __init move_memory(unsigned long dst, + unsigned long src_start, unsigned long src_end) +{ +#if defined(CONFIG_X86_32) + memmove((void *)dst, /* use low mapping */ + (void *)src_start, /* use low mapping */ + src_end - src_start); +#elif defined(CONFIG_X86_64) + memmove(__va(dst), + __va(src_start), + src_end - src_start); +#endif +} + void __init __start_xen(multiboot_info_t *mbi) { char __cmdline[] = "", *cmdline = __cmdline; @@ -327,15 +346,8 @@ void __init __start_xen(multiboot_info_t initial_images_start = xenheap_phys_end; initial_images_end = initial_images_start + modules_length; -#if defined(CONFIG_X86_32) - memmove((void *)initial_images_start, /* use low mapping */ - (void *)mod[0].mod_start, /* use low mapping */ - mod[mbi->mods_count-1].mod_end - mod[0].mod_start); -#elif defined(CONFIG_X86_64) - memmove(__va(initial_images_start), - __va(mod[0].mod_start), - mod[mbi->mods_count-1].mod_end - mod[0].mod_start); -#endif + move_memory(initial_images_start, + mod[0].mod_start, mod[mbi->mods_count-1].mod_end); /* Initialise boot-time allocator with all RAM situated after modules. */ xenheap_phys_start = init_boot_allocator(__pa(&_end)); @@ -383,6 +395,51 @@ void __init __start_xen(multiboot_info_t #endif } + if (opt_kdump_megabytes) { + unsigned long kdump_start, kdump_size, k; + + /* mark images pages as free for now */ + + init_boot_pages(initial_images_start, initial_images_end); + + kdump_start = opt_kdump_megabytes_base << 20; + kdump_size = opt_kdump_megabytes << 20; + + printk("Kdump: %luMB (%lukB) at 0x%lx\n", + kdump_size >> 20, + kdump_size >> 10, + kdump_start); + + if ((kdump_start & ~PAGE_MASK) || (kdump_size & ~PAGE_MASK)) + panic("Kdump parameters not page aligned\n"); + + kdump_start >>= PAGE_SHIFT; + kdump_size >>= PAGE_SHIFT; + + /* allocate pages for Kdump memory area */ + + k = alloc_boot_pages_at(kdump_size, kdump_start); + + if (k != kdump_start) + panic("Unable to reserve Kdump memory\n"); + + /* allocate pages for relocated initial images */ + + k = ((initial_images_end - initial_images_start) & ~PAGE_MASK) ? 1 : 0; + k += (initial_images_end - initial_images_start) >> PAGE_SHIFT; + + k = alloc_boot_pages(k, 1); + + if (!k) + panic("Unable to allocate initial images memory\n"); + + move_memory(k << PAGE_SHIFT, initial_images_start, initial_images_end); + + initial_images_end -= initial_images_start; + initial_images_start = k << PAGE_SHIFT; + initial_images_end += initial_images_start; + } + memguard_init(); printk("System RAM: %luMB (%lukB)\n", --- x/xen/arch/x86/x86_32/Makefile +++ x/xen/arch/x86/x86_32/Makefile @@ -3,5 +3,6 @@ obj-y += entry.o obj-y += mm.o obj-y += seg_fixup.o obj-y += traps.o +obj-y += machine_kexec.o obj-$(supervisor_mode_kernel) += supervisor_mode_kernel.o --- /dev/null +++ x/xen/arch/x86/x86_32/machine_kexec.c @@ -0,0 +1,27 @@ +/* + * arch/x86/x86_32/machine_kexec.c + * Handle transition of Linux booting another kernel + * + * Created By: Horms + * + * Should be losely based on arch/i386/kernel/machine_kexec.c + */ + +#include /* for printk() used in stub */ +#include + +void machine_kexec(struct kexec_arg *arg) +{ + printk("STUB: arch/x86/x86_32/machine_kexec.c: machine_kexec: " + "not implemented\n"); +} + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --- x/xen/arch/x86/x86_64/Makefile +++ x/xen/arch/x86/x86_64/Makefile @@ -1,3 +1,4 @@ obj-y += entry.o obj-y += mm.o obj-y += traps.o +obj-y += machine_kexec.o --- /dev/null +++ x/xen/arch/x86/x86_64/machine_kexec.c @@ -0,0 +1,28 @@ +/* + * arch/x86/x86_64/machine_kexec.c + * Handle transition of Linux booting another kernel + * + * Created By: Horms + * + * Should be losely based on arch/x86_64/kernel/machine_kexec.c + */ + +#include /* for printk() used in stubs */ +#include +#include + +void machine_kexec(struct kexec_arg *arg) +{ + printk("STUB: arch/x86/x86_64/machine_kexec.c: machine_kexec: " + "not implemented\n"); +} + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --- x/xen/common/kexec.c +++ x/xen/common/kexec.c @@ -99,7 +99,8 @@ int do_kexec(unsigned long op, int type, case KEXEC_CMD_kexec_crash_note: return get_crash_note(uarg); case KEXEC_CMD_kexec_reserve: - machine_kexec_reserved(&tmp_arg); + tmp_arg.u.reserve.size = opt_kdump_megabytes << 20; + tmp_arg.u.reserve.start = opt_kdump_megabytes_base << 20; if ( unlikely(copy_to_guest(uarg, &tmp_arg, 1) != 0) ) { printk("do_kexec (CMD_kexec_reserve): copy_to_guest failed\n"); --- /dev/null +++ x/xen/include/asm-x86/elf.h @@ -0,0 +1,27 @@ +/****************************************************************************** + * include/asm-x86/elf.h + * + * Created By: Horms + * + */ + +#ifndef __X86_ELF_H__ +#define __X86_ELF_H__ + +#ifdef __x86_64__ +#include +#else +#include +#endif + +#endif /* __X86_ELF_H__ */ + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --- x/xen/include/asm-x86/hypercall.h +++ x/xen/include/asm-x86/hypercall.h @@ -6,6 +6,8 @@ #define __ASM_X86_HYPERCALL_H__ #include +#include +#include extern long do_event_channel_op_compat( @@ -87,6 +89,10 @@ extern long arch_do_vcpu_op( int cmd, struct vcpu *v, XEN_GUEST_HANDLE(void) arg); +extern int +do_kexec( + unsigned long op, XEN_GUEST_HANDLE(kexec_arg_t) uarg); + #ifdef __x86_64__ extern long --- x/xen/include/asm-x86/kexec.h +++ x/xen/include/asm-x86/kexec.h @@ -8,16 +8,16 @@ #ifndef __X86_KEXEC_H__ #define __X86_KEXEC_H__ -#include /* for printk() used in stub */ +#include #include +#include #include -static void crash_setup_regs(struct cpu_user_regs *newregs, - struct cpu_user_regs *oldregs) -{ - printk("STUB: include/asm-x86/kexec.h: crash_setup_regs: " - "not implemented\n"); -} +#ifdef __x86_64__ +#include +#else +#include +#endif #endif /* __X86_KEXEC_H__ */ --- /dev/null +++ x/xen/include/asm-x86/x86_32/elf.h @@ -0,0 +1,30 @@ +/****************************************************************************** + * include/asm-x86/x86_32/elf.h + * + * Created By: Horms + * + * Should pull be based on include/asm-i386/elf.h:ELF_CORE_COPY_REGS + * from Linux 2.6.16 + */ + +#ifndef __X86_ELF_X86_32_H__ +#define __X86_ELF_X86_32_H__ + +#include /* for printk() used in stub */ + +#define ELF_CORE_COPY_REGS(pr_reg, regs) \ + printk("STUB: include/asm-x86/x86_32/kexec.h: ELF_CORE_COPY_REGS: " \ + "not implemented\n") + + +#endif /* __X86_ELF_X86_32_H__ */ + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --- /dev/null +++ x/xen/include/asm-x86/x86_32/kexec.h @@ -0,0 +1,51 @@ +/****************************************************************************** + * include/asm-x86/x86_32/kexec.h + * + * Created By: Horms + * + * Should be based heavily on include/asm-i386/kexec.h from Linux 2.6.16 + * + */ + +#ifndef __X86_32_KEXEC_H__ +#define __X86_32_KEXEC_H__ + +#include /* for printk() used in stub */ +#include +#include + +static void crash_fixup_ss_esp(struct cpu_user_regs *newregs, + struct cpu_user_regs *oldregs) +{ + printk("STUB: include/asm-x86/x86_32/kexec.h: crash_fixup_ss_esp: " + "not implemented\n"); + return; + crash_fixup_ss_esp(newregs, oldregs); +} + +static void crash_setup_regs(struct cpu_user_regs *newregs, + struct cpu_user_regs *oldregs) +{ + printk("STUB: include/asm-x86/x86_32/kexec.h: crash_setup_regs: " + "not implemented\n"); +} + +static inline int user_mode(struct cpu_user_regs *regs) +{ + printk("STUB: include/asm-x86/x86_32/kexec.h: user_mode: " + "not implemented\n"); + return -1; +} + + +#endif /* __X86_32_KEXEC_H__ */ + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --- /dev/null +++ x/xen/include/asm-x86/x86_64/elf.h @@ -0,0 +1,30 @@ +/****************************************************************************** + * include/asm-x86/x86_64/elf.h + * + * Created By: Horms + * + * Should pull be based on include/asm-x86_64/elf.h:ELF_CORE_COPY_REGS + * from Linux 2.6.16 + */ + +#ifndef __X86_ELF_X86_64_H__ +#define __X86_ELF_X86_64_H__ + +#include /* for printk() used in stub */ + +#define ELF_CORE_COPY_REGS(pr_reg, regs) \ + printk("STUB: include/asm-x86/x86_64/kexec.h: ELF_CORE_COPY_REGS: " \ + "not implemented\n") + + +#endif /* __X86_ELF_X86_64_H__ */ + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --- /dev/null +++ x/xen/include/asm-x86/x86_64/kexec.h @@ -0,0 +1,50 @@ +/****************************************************************************** + * include/asm-x86/x86_64/kexec.h + * + * Created By: Horms + * + * Should be based heavily on include/asm-x86_64/kexec.h from Linux 2.6.16 + * + */ + +#ifndef __X86_64_KEXEC_H__ +#define __X86_64_KEXEC_H__ + +#include /* for printk() used in stub */ +#include +#include + +static void crash_fixup_ss_esp(struct cpu_user_regs *newregs, + struct cpu_user_regs *oldregs) +{ + printk("STUB: include/asm-x86/x86_64/kexec.h: crash_fixup_ss_esp: " + "not implemented\n"); +} + +static void crash_setup_regs(struct cpu_user_regs *newregs, + struct cpu_user_regs *oldregs) +{ + printk("STUB: include/asm-x86/x86_64/kexec.h: crash_setup_regs: " + "not implemented\n"); + return; + crash_fixup_ss_esp(newregs, oldregs); +} + +static inline int user_mode(struct cpu_user_regs *regs) +{ + printk("STUB: include/asm-x86/x86_64/kexec.h: user_mode: " + "not implemented\n"); + return -1; +} + +#endif /* __X86_64_KEXEC_H__ */ + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --UlVJffcvxoiEqYs2 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="51.2.1.1-kexec-x86_32-upstream.patch" kexec: x86_32 This is the x86_32 component of kexec for xen. The x86 component is a prerequsite for this patch. buildconfigs/linux-defconfig_xen_x86_32 | 1 linux-2.6-xen-sparse/arch/i386/Kconfig | 2 linux-2.6-xen-sparse/arch/i386/kernel/Makefile | 2 linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c | 25 + linux-2.6-xen-sparse/drivers/xen/core/crash.c | 2 linux-2.6-xen-sparse/include/asm-i386/kexec-xen.h | 19 + linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypercall.h | 10 patches/linux-2.6.16.13/kexec-x86_32.patch | 12 xen/arch/x86/machine_kexec.c | 6 xen/arch/x86/x86_32/entry.S | 2 xen/arch/x86/x86_32/machine_kexec.c | 143 +++++++++- xen/include/asm-x86/x86_32/elf.h | 34 +- xen/include/asm-x86/x86_32/kexec.h | 68 +++- xen/include/xen/kexec.h | 1 14 files changed, 281 insertions(+), 46 deletions(-) --- x/buildconfigs/linux-defconfig_xen_x86_32 +++ x/buildconfigs/linux-defconfig_xen_x86_32 @@ -184,6 +184,7 @@ CONFIG_MTRR=y CONFIG_REGPARM=y CONFIG_SECCOMP=y CONFIG_HZ_100=y +CONFIG_KEXEC=y # CONFIG_HZ_250 is not set # CONFIG_HZ_1000 is not set CONFIG_HZ=100 --- x/linux-2.6-xen-sparse/arch/i386/Kconfig +++ x/linux-2.6-xen-sparse/arch/i386/Kconfig @@ -726,7 +726,7 @@ source kernel/Kconfig.hz config KEXEC bool "kexec system call (EXPERIMENTAL)" - depends on EXPERIMENTAL && !X86_XEN + 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 --- x/linux-2.6-xen-sparse/arch/i386/kernel/Makefile +++ x/linux-2.6-xen-sparse/arch/i386/kernel/Makefile @@ -89,7 +89,7 @@ include $(srctree)/scripts/Makefile.xen obj-y += fixup.o microcode-$(subst m,y,$(CONFIG_MICROCODE)) := microcode-xen.o -n-obj-xen := i8259.o timers/ reboot.o smpboot.o trampoline.o +n-obj-xen := i8259.o timers/ reboot.o smpboot.o trampoline.o machine_kexec.o crash.o obj-y := $(call filterxen, $(obj-y), $(n-obj-xen)) obj-y := $(call cherrypickxen, $(obj-y)) --- x/linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c +++ x/linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c @@ -68,6 +68,10 @@ #include "setup_arch_pre.h" #include +#ifdef CONFIG_XEN +#include +#endif + /* Forward Declaration. */ void __init find_max_pfn(void); @@ -932,6 +936,7 @@ static void __init parse_cmdline_early ( * after a kernel panic. */ else if (!memcmp(from, "crashkernel=", 12)) { +#ifndef CONFIG_XEN unsigned long size, base; size = memparse(from+12, &from); if (*from == '@') { @@ -942,6 +947,10 @@ static void __init parse_cmdline_early ( crashk_res.start = base; crashk_res.end = base + size - 1; } +#else + printk("Ignoring crashkernel command line, " + "parameter will be supplied by xen\n"); +#endif } #endif #ifdef CONFIG_PROC_VMCORE @@ -1318,9 +1327,22 @@ void __init setup_bootmem_allocator(void } #endif #ifdef CONFIG_KEXEC +#ifndef CONFIG_XEN if (crashk_res.start != crashk_res.end) reserve_bootmem(crashk_res.start, crashk_res.end - crashk_res.start + 1); +#else + { + struct kexec_arg xen_kexec_arg; + BUG_ON(HYPERVISOR_kexec(KEXEC_CMD_kexec_reserve, 0, + &xen_kexec_arg)); + if (xen_kexec_arg.u.reserve.size) { + crashk_res.start = xen_kexec_arg.u.reserve.start; + crashk_res.end = xen_kexec_arg.u.reserve.start + + xen_kexec_arg.u.reserve.size - 1; + } + } +#endif #endif if (!xen_feature(XENFEAT_auto_translated_physmap)) @@ -1395,6 +1417,9 @@ legacy_init_iomem_resources(struct resou res->end = map[i].end - 1; res->flags = IORESOURCE_MEM | IORESOURCE_BUSY; request_resource(&iomem_resource, res); +#ifdef CONFIG_KEXEC + request_resource(res, &crashk_res); +#endif } free_bootmem(__pa(map), PAGE_SIZE); --- x/linux-2.6-xen-sparse/drivers/xen/core/crash.c +++ x/linux-2.6-xen-sparse/drivers/xen/core/crash.c @@ -1,5 +1,5 @@ /* - * Architecture independent functions for kexec based crash dumps in xen. + * Architecture specific (i386-xen) functions for kexec based crash dumps. * * Created by: Horms * --- x/linux-2.6-xen-sparse/include/asm-i386/kexec-xen.h +++ x/linux-2.6-xen-sparse/include/asm-i386/kexec-xen.h @@ -7,11 +7,26 @@ #ifndef _I386_KEXEC_XEN_H #define _I386_KEXEC_XEN_H +#include +#include +#include + static inline void crash_translate_regs(struct pt_regs *linux_regs, struct cpu_user_regs *xen_regs) { - printk("STUB: include/asm-i386/kexec-xen.h: crash_translate_regs: " - "not implemented\n"); + xen_regs->ebx = linux_regs->ebx; + xen_regs->ecx = linux_regs->ecx; + xen_regs->edx = linux_regs->edx; + xen_regs->esi = linux_regs->esi; + xen_regs->edi = linux_regs->edi; + xen_regs->ebp = linux_regs->ebp; + xen_regs->eax = linux_regs->eax; + xen_regs->esp = linux_regs->esp; + xen_regs->ss = linux_regs->xss; + xen_regs->cs = linux_regs->xcs; + xen_regs->ds = linux_regs->xds; + xen_regs->es = linux_regs->xes; + xen_regs->eflags = linux_regs->eflags; } #endif /* _I386_KEXEC_XEN_H */ --- x/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypercall.h +++ x/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypercall.h @@ -39,6 +39,8 @@ # error "please don't include this file directly" #endif +#include + #define __STR(x) #x #define STR(x) __STR(x) @@ -359,6 +361,14 @@ HYPERVISOR_xenoprof_op( return _hypercall2(int, xenoprof_op, op, arg); } +static inline int +HYPERVISOR_kexec( + unsigned long op, int type, kexec_arg_t * arg) +{ + return _hypercall3(int, kexec_op, op, type, arg); +} + + #endif /* __HYPERCALL_H__ */ --- x/xen/arch/x86/machine_kexec.c +++ x/xen/arch/x86/machine_kexec.c @@ -25,12 +25,6 @@ void machine_kexec_cleanup(int type, str { } -void machine_kexec_reserved(struct kexec_arg *arg) -{ - arg->u.reserve.size = opt_kdump_megabytes << 20; - arg->u.reserve.start = opt_kdump_megabytes_base << 20; -} - static void __machine_shutdown(void *data) { struct kexec_arg *arg = (struct kexec_arg *)data; --- x/xen/arch/x86/x86_32/entry.S +++ x/xen/arch/x86/x86_32/entry.S @@ -648,6 +648,7 @@ ENTRY(hypercall_table) .long do_xenoprof_op .long do_event_channel_op .long do_physdev_op + .long do_kexec .rept NR_hypercalls-((.-hypercall_table)/4) .long do_ni_hypercall .endr @@ -687,6 +688,7 @@ ENTRY(hypercall_args_table) .byte 2 /* do_xenoprof_op */ .byte 2 /* do_event_channel_op */ .byte 2 /* do_physdev_op */ + .byte 3 /* do_kexec */ .rept NR_hypercalls-(.-hypercall_args_table) .byte 0 /* do_ni_hypercall */ .endr --- x/xen/arch/x86/x86_32/machine_kexec.c +++ x/xen/arch/x86/x86_32/machine_kexec.c @@ -1,19 +1,146 @@ -/* +/****************************************************************************** * arch/x86/x86_32/machine_kexec.c - * Handle transition of Linux booting another kernel - * - * Created By: Horms + * + * Created By: Horms * - * Should be losely based on arch/i386/kernel/machine_kexec.c + * Based heavily on arch/i386/machine_kexec.c from Linux 2.6.16 */ -#include /* for printk() used in stub */ +#include +#include +#include +#include +#include +#include #include +typedef asmlinkage void (*relocate_new_kernel_t)( + unsigned long indirection_page, + unsigned long reboot_code_buffer, + unsigned long start_address, + unsigned int has_pae); + +#define PAGE_ALIGNED __attribute__ ((__aligned__(PAGE_SIZE))) + +#define L0_ATTR (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY) +#define L1_ATTR (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY) +#define L2_ATTR (_PAGE_PRESENT) + +#ifndef CONFIG_X86_PAE + +static u32 pgtable_level1[L1_PAGETABLE_ENTRIES] PAGE_ALIGNED; + +static void identity_map_page(unsigned long address) +{ + unsigned long mfn; + u32 *pgtable_level2; + + /* Find the current page table */ + mfn = read_cr3() >> PAGE_SHIFT; + pgtable_level2 = map_domain_page(mfn); + + /* Identity map the page table entry */ + pgtable_level1[l1_table_offset(address)] = address | L0_ATTR; + pgtable_level2[l2_table_offset(address)] = __pa(pgtable_level1) | L1_ATTR; + + /* Flush the tlb so the new mapping takes effect. + * Global tlb entries are not flushed but that is not an issue. + */ + write_cr3(mfn << PAGE_SHIFT); + + unmap_domain_page(pgtable_level2); +} + +#else +static u64 pgtable_level1[L1_PAGETABLE_ENTRIES] PAGE_ALIGNED; +static u64 pgtable_level2[L2_PAGETABLE_ENTRIES] PAGE_ALIGNED; + +static void identity_map_page(unsigned long address) +{ + int mfn; + intpte_t *pgtable_level3; + + /* Find the current page table */ + mfn = read_cr3() >> PAGE_SHIFT; + pgtable_level3 = map_domain_page(mfn); + + /* Identity map the page table entry */ + pgtable_level1[l1_table_offset(address)] = address | L0_ATTR; + pgtable_level2[l2_table_offset(address)] = __pa(pgtable_level1) | L1_ATTR; + set_64bit(&pgtable_level3[l3_table_offset(address)], + __pa(pgtable_level2) | L2_ATTR); + + /* Flush the tlb so the new mapping takes effect. + * Global tlb entries are not flushed but that is not an issue. + */ + load_cr3(mfn << PAGE_SHIFT); + + unmap_domain_page(pgtable_level3); +} +#endif + +static void kexec_load_segments(void) +{ +#define __SSTR(X) #X +#define SSTR(X) __SSTR(X) + __asm__ __volatile__ ( + "\tljmp $"SSTR(__HYPERVISOR_CS)",$1f\n" + "\t1:\n" + "\tmovl $"SSTR(__HYPERVISOR_DS)",%%eax\n" + "\tmovl %%eax,%%ds\n" + "\tmovl %%eax,%%es\n" + "\tmovl %%eax,%%fs\n" + "\tmovl %%eax,%%gs\n" + "\tmovl %%eax,%%ss\n" + ::: "eax", "memory"); +#undef SSTR +#undef __SSTR +} + +#define kexec_load_idt(dtr) __asm__ __volatile("lidt %0"::"m" (*dtr)) +static void kexec_set_idt(void *newidt, __u16 limit) +{ + struct Xgt_desc_struct curidt; + + /* ia32 supports unaliged loads & stores */ + curidt.size = limit; + curidt.address = (unsigned long)newidt; + + kexec_load_idt(&curidt); + +}; + +#define kexec_load_gdt(dtr) __asm__ __volatile("lgdt %0"::"m" (*dtr)) +static void kexec_set_gdt(void *newgdt, __u16 limit) +{ + struct Xgt_desc_struct curgdt; + + /* ia32 supports unaligned loads & stores */ + curgdt.size = limit; + curgdt.address = (unsigned long)newgdt; + + kexec_load_gdt(&curgdt); +}; + void machine_kexec(struct kexec_arg *arg) { - printk("STUB: arch/x86/x86_32/machine_kexec.c: machine_kexec: " - "not implemented\n"); + relocate_new_kernel_t rnk; + + local_irq_disable(); + + identity_map_page(arg->u.image.reboot_code_buffer); + + copy_from_user((void *)arg->u.image.reboot_code_buffer, + arg->u.image.relocate_new_kernel, + arg->u.image.relocate_new_kernel_size); + + kexec_load_segments(); + kexec_set_gdt(__va(0),0); + kexec_set_idt(__va(0),0); + + rnk = (relocate_new_kernel_t) arg->u.image.reboot_code_buffer; + (*rnk)(arg->u.image.indirection_page, arg->u.image.reboot_code_buffer, + arg->u.image.start_address, cpu_has_pae); } /* --- x/xen/include/asm-x86/x86_32/elf.h +++ x/xen/include/asm-x86/x86_32/elf.h @@ -3,19 +3,39 @@ * * Created By: Horms * - * Should pull be based on include/asm-i386/elf.h:ELF_CORE_COPY_REGS - * from Linux 2.6.16 + * Based heavily on include/asm-i386/elf.h and + * include/asm-i386/system.h from Linux 2.6.16 */ #ifndef __X86_ELF_X86_32_H__ #define __X86_ELF_X86_32_H__ -#include /* for printk() used in stub */ +/* XXX: Xen doesn't have orig_eax. For kdump, on a dom0 crash, the values + * for the crashing CPU could could be passed down from dom0, but is that + * neccessary? + * Also, I'm not sure why fs and gs are derived from the CPU + * rather than regs */ -#define ELF_CORE_COPY_REGS(pr_reg, regs) \ - printk("STUB: include/asm-x86/x86_32/kexec.h: ELF_CORE_COPY_REGS: " \ - "not implemented\n") - +#define ELF_CORE_COPY_REGS(pr_reg, regs) do { \ + unsigned i; \ + pr_reg[0] = regs->ebx; \ + pr_reg[1] = regs->ecx; \ + pr_reg[2] = regs->edx; \ + pr_reg[3] = regs->esi; \ + pr_reg[4] = regs->edi; \ + pr_reg[5] = regs->ebp; \ + pr_reg[6] = regs->eax; \ + pr_reg[7] = regs->ds; \ + pr_reg[8] = regs->es; \ + asm volatile("mov %%fs,%0":"=rm" (i)); pr_reg[9] = i; \ + asm volatile("mov %%gs,%0":"=rm" (i)); pr_reg[10] = i; \ + pr_reg[11] = 0; /* regs->orig_eax; */ \ + pr_reg[12] = regs->eip; \ + pr_reg[13] = regs->cs; \ + pr_reg[14] = regs->eflags; \ + pr_reg[15] = regs->esp; \ + pr_reg[16] = regs->ss; \ +} while(0); #endif /* __X86_ELF_X86_32_H__ */ --- x/xen/include/asm-x86/x86_32/kexec.h +++ x/xen/include/asm-x86/x86_32/kexec.h @@ -3,42 +3,72 @@ * * Created By: Horms * - * Should be based heavily on include/asm-i386/kexec.h from Linux 2.6.16 - * + * Based heavily on include/asm-i386/kexec.h from Linux 2.6.16 */ -#ifndef __X86_32_KEXEC_H__ -#define __X86_32_KEXEC_H__ - -#include /* for printk() used in stub */ -#include -#include +#ifndef __X86_KEXEC_X86_32_H__ +#define __X86_KEXEC_X86_32_H__ +/* CPU does not save ss and esp on stack if execution is already + * running in kernel mode at the time of NMI occurrence. This code + * fixes it. + */ static void crash_fixup_ss_esp(struct cpu_user_regs *newregs, - struct cpu_user_regs *oldregs) + struct cpu_user_regs *oldregs) { - printk("STUB: include/asm-x86/x86_32/kexec.h: crash_fixup_ss_esp: " - "not implemented\n"); - return; - crash_fixup_ss_esp(newregs, oldregs); + memcpy(newregs, oldregs, sizeof(*newregs)); + newregs->esp = (unsigned long)&(oldregs->esp); + __asm__ __volatile__( + "xorl %%eax, %%eax\n\t" + "movw %%ss, %%ax\n\t" + :"=a"(newregs->ss)); } +/* + * This function is responsible for capturing register states if coming + * via panic otherwise just fix up the ss and esp if coming via kernel + * mode exception. + */ static void crash_setup_regs(struct cpu_user_regs *newregs, struct cpu_user_regs *oldregs) { - printk("STUB: include/asm-x86/x86_32/kexec.h: crash_setup_regs: " - "not implemented\n"); + if (oldregs) + crash_fixup_ss_esp(newregs, oldregs); + else { + __asm__ __volatile__("movl %%ebx,%0" : "=m"(newregs->ebx)); + __asm__ __volatile__("movl %%ecx,%0" : "=m"(newregs->ecx)); + __asm__ __volatile__("movl %%edx,%0" : "=m"(newregs->edx)); + __asm__ __volatile__("movl %%esi,%0" : "=m"(newregs->esi)); + __asm__ __volatile__("movl %%edi,%0" : "=m"(newregs->edi)); + __asm__ __volatile__("movl %%ebp,%0" : "=m"(newregs->ebp)); + __asm__ __volatile__("movl %%eax,%0" : "=m"(newregs->eax)); + __asm__ __volatile__("movl %%esp,%0" : "=m"(newregs->esp)); + __asm__ __volatile__("movw %%ss, %%ax;" :"=a"(newregs->ss)); + __asm__ __volatile__("movw %%cs, %%ax;" :"=a"(newregs->cs)); + __asm__ __volatile__("movw %%ds, %%ax;" :"=a"(newregs->ds)); + __asm__ __volatile__("movw %%es, %%ax;" :"=a"(newregs->es)); + __asm__ __volatile__("pushfl; popl %0" :"=m"(newregs->eflags)); + + newregs->eip = (unsigned long)current_text_addr(); + } } +/* + * From Linux 2.6.16's include/asm-i386/mach-xen/asm/ptrace.h + * + * user_mode_vm(regs) determines whether a register set came from user mode. + * This is true if V8086 mode was enabled OR if the register set was from + * protected mode with RPL-3 CS value. This tricky test checks that with + * one comparison. Many places in the kernel can bypass this full check + * if they have already ruled out V8086 mode, so user_mode(regs) can be used. + */ static inline int user_mode(struct cpu_user_regs *regs) { - printk("STUB: include/asm-x86/x86_32/kexec.h: user_mode: " - "not implemented\n"); - return -1; + return (regs->cs & 2) != 0; } -#endif /* __X86_32_KEXEC_H__ */ +#endif /* __X86_KEXEC_X86_32_H__ */ /* * Local variables: --- x/xen/include/xen/kexec.h +++ x/xen/include/xen/kexec.h @@ -14,7 +14,6 @@ DECLARE_PER_CPU (note_buf_t, crash_notes int machine_kexec_prepare(int type, struct kexec_arg *arg); void machine_kexec_cleanup(int type, struct kexec_arg *arg); -void machine_kexec_reserved(struct kexec_arg *arg); void machine_kexec(struct kexec_arg *arg); void machine_shutdown(struct kexec_arg *arg); void machine_crash_shutdown(struct cpu_user_regs *regs); --- /dev/null 2006-05-09 15:32:30.399072192 +0900 +++ x/patches/linux-2.6.16.13/kexec-x86_32.patch 2006-05-17 18:37:45.000000000 +0900 @@ -0,0 +1,12 @@ +--- x/arch/i386/kernel/crash.c ++++ x/arch/i386/kernel/crash.c +@@ -175,9 +175,5 @@ void machine_crash_shutdown(struct pt_re + /* Make a note of crashing cpu. Will be used in NMI callback.*/ + crashing_cpu = smp_processor_id(); + nmi_shootdown_cpus(); +- lapic_shutdown(); +-#if defined(CONFIG_X86_IO_APIC) +- disable_IO_APIC(); +-#endif + crash_save_self(regs); + } --UlVJffcvxoiEqYs2 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --UlVJffcvxoiEqYs2--