kexec x86_64: Add kexec jump support for x86_64
PATCH 2/2 kexec x86_64: Add kexec jump support for x86_64
This patch add kexec jump support for x86_64. More information about kexec jump can be found in corresponding x86_32 support patch.
Signed-off-by Huang Ying <[email protected]>
--- arch/x86/Kconfig | 2 arch/x86/include/asm/kexec.h | 13 +- arch/x86/kernel/machine_kexec_64.c | 41 +++++++- arch/x86/kernel/relocate_kernel_64.S | 170 ++++++++++++++++++++++++++++------- arch/x86/kernel/vmlinux_64.lds.S | 7 + 5 files changed, 192 insertions(+), 41 deletions(-)
arch/x86/kernel/machine_kexec_64.c +37 -4
@@ -12,6 +12,7 @@#include <linux/reboot.h> #include <linux/numa.h> #include <linux/ftrace.h> +#include <linux/suspend.h> #include <asm/pgtable.h> #include <asm/tlbflush.h>
@@ -269,19 +270,42 @@ void machine_kexec(struct kimage *image) {unsigned long page_list[PAGES_NR ];void *control_page; +int save_ftrace_enabled; -tracer_disable (); +#ifdef CONFIG_KEXEC_JUMP +if (kexec_image->preserve_context) +save_processor_state (); +#endif + + save_ftrace_enabled =__ftrace_enabled_save ();/* Interrupts aren't acceptable while we reboot */ local_irq_disable (); +if (image->preserve_context) { +#ifdef CONFIG_X86_IO_APIC +/* We need to put APICs in legacy mode so that we can +* get timer interrupts in second kernel. kexec/kdump +* paths already have calls to disable_IO_APIC() in +* one form or other. kexec jump path also need +* one. +*/ +disable_IO_APIC (); +#endif + } + control_page =page_address (image->control_code_page) +PAGE_SIZE ; -memcpy (control_page, relocate_kernel,PAGE_SIZE ); +memcpy (control_page, relocate_kernel,KEXEC_CONTROL_CODE_MAX_SIZE ); page_list[PA_CONTROL_PAGE ] =virt_to_phys (control_page); + page_list[VA_CONTROL_PAGE ] = (unsigned long )control_page; page_list[PA_TABLE_PAGE ] = (unsigned long )__pa (page_address (image->control_code_page)); +if (image->type ==KEXEC_TYPE_DEFAULT ) + page_list[PA_SWAP_PAGE ] = (page_to_pfn (image->swap_page) + <<PAGE_SHIFT ); +/* The segment registers are funny things, they have both a * visible and an invisible part. Whenever the visible part is * set to a specific selector, the invisible part is loaded
@@ -299,8 +323,17 @@ void machine_kexec(struct kimage *image)set_idt (phys_to_virt (0 ),0 );/* now call it */ -relocate_kernel ((unsigned long )image->head, (unsigned long )page_list, - image->start); + image->start =relocate_kernel ((unsigned long )image->head, + (unsigned long )page_list, + image->start, + image->preserve_context); + +#ifdef CONFIG_KEXEC_JUMP +if (kexec_image->preserve_context) +restore_processor_state (); +#endif + +__ftrace_enabled_restore (save_ftrace_enabled); }void arch_crash_save_vmcoreinfo (void )
arch/x86/include/asm/kexec.h +7 -6
@@ -9,13 +9,13 @@# define PAGES_NR 4#else # define PA_CONTROL_PAGE 0 -# define PA_TABLE_PAGE 1 -# define PAGES_NR 2 +# define VA_CONTROL_PAGE 1 +# define PA_TABLE_PAGE 2 +# define PA_SWAP_PAGE 3 +# define PAGES_NR 4#endif -#ifdef CONFIG_X86_32 # define KEXEC_CONTROL_CODE_MAX_SIZE 2048 -#endif #ifndef __ASSEMBLY__
@@ -136,10 +136,11 @@ relocate_kernel(unsigned long indirectiounsigned int has_pae, unsigned int preserve_context);#else -NORET_TYPE void +unsigned long relocate_kernel (unsigned long indirection_page,unsigned long page_list, - unsigned long start_address) ATTRIB_NORET; +unsigned long start_address, +unsigned int preserve_context);#endif #define ARCH_HAS_KIMAGE_ARCH
arch/x86/kernel/relocate_kernel_64.S +140 -30
209 lines not on this page · raw message
arch/x86/kernel/vmlinux_64.lds.S +7 -0
@@ -244,3 +244,10 @@ SECTIONS */ ASSERT((_end - _text <= KERNEL_IMAGE_SIZE), "kernel image bigger than KERNEL_IMAGE_SIZE") + +#ifdef CONFIG_KEXEC +#include <asm/kexec.h> + +ASSERT(kexec_control_code_size <= KEXEC_CONTROL_CODE_MAX_SIZE, + "kexec control code size is too big") +#endif
arch/x86/Kconfig +1 -1
@@ -1400,7 +1400,7 @@ config CRASH_DUMP config KEXEC_JUMP bool "kexec jump (EXPERIMENTAL)" depends on EXPERIMENTAL - depends on KEXEC && HIBERNATION && X86_32 + depends on KEXEC && HIBERNATION help Jump between original kernel and kexeced kernel and invoke code in physical address mode via KEXEC