2005-06-26 05:57:56 +08:00
|
|
|
/*
|
2007-10-13 09:10:53 +08:00
|
|
|
* handle transition of Linux booting another kernel
|
2005-06-26 05:57:56 +08:00
|
|
|
* Copyright (C) 2002-2005 Eric Biederman <ebiederm@xmission.com>
|
|
|
|
*
|
|
|
|
* This source code is licensed under the GNU General Public License,
|
|
|
|
* Version 2. See the file COPYING for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/kexec.h>
|
|
|
|
#include <linux/delay.h>
|
2007-10-17 14:27:27 +08:00
|
|
|
#include <linux/numa.h>
|
2008-05-13 03:20:43 +08:00
|
|
|
#include <linux/ftrace.h>
|
2008-08-15 15:40:26 +08:00
|
|
|
#include <linux/suspend.h>
|
2008-10-31 09:48:08 +08:00
|
|
|
#include <linux/gfp.h>
|
2009-03-10 10:56:57 +08:00
|
|
|
#include <linux/io.h>
|
2008-05-13 03:20:43 +08:00
|
|
|
|
2005-06-26 05:57:56 +08:00
|
|
|
#include <asm/pgtable.h>
|
|
|
|
#include <asm/pgalloc.h>
|
|
|
|
#include <asm/tlbflush.h>
|
|
|
|
#include <asm/mmu_context.h>
|
|
|
|
#include <asm/apic.h>
|
2014-10-27 16:12:04 +08:00
|
|
|
#include <asm/io_apic.h>
|
2005-06-26 05:57:56 +08:00
|
|
|
#include <asm/cpufeature.h>
|
2005-07-30 03:01:18 +08:00
|
|
|
#include <asm/desc.h>
|
2017-05-09 06:58:11 +08:00
|
|
|
#include <asm/set_memory.h>
|
2009-06-02 02:16:03 +08:00
|
|
|
#include <asm/debugreg.h>
|
2005-06-26 05:57:56 +08:00
|
|
|
|
|
|
|
static void set_gdt(void *newgdt, __u16 limit)
|
|
|
|
{
|
2008-01-30 20:31:12 +08:00
|
|
|
struct desc_ptr curgdt;
|
2005-06-26 05:57:56 +08:00
|
|
|
|
|
|
|
/* ia32 supports unaligned loads & stores */
|
2005-07-30 03:01:18 +08:00
|
|
|
curgdt.size = limit;
|
|
|
|
curgdt.address = (unsigned long)newgdt;
|
2005-06-26 05:57:56 +08:00
|
|
|
|
2005-09-04 06:56:42 +08:00
|
|
|
load_gdt(&curgdt);
|
2008-06-24 23:21:18 +08:00
|
|
|
}
|
2005-06-26 05:57:56 +08:00
|
|
|
|
|
|
|
static void load_segments(void)
|
|
|
|
{
|
|
|
|
#define __STR(X) #X
|
|
|
|
#define STR(X) __STR(X)
|
|
|
|
|
|
|
|
__asm__ __volatile__ (
|
|
|
|
"\tljmp $"STR(__KERNEL_CS)",$1f\n"
|
|
|
|
"\t1:\n"
|
2006-03-08 13:55:48 +08:00
|
|
|
"\tmovl $"STR(__KERNEL_DS)",%%eax\n"
|
|
|
|
"\tmovl %%eax,%%ds\n"
|
|
|
|
"\tmovl %%eax,%%es\n"
|
|
|
|
"\tmovl %%eax,%%ss\n"
|
2009-03-10 10:56:57 +08:00
|
|
|
: : : "eax", "memory");
|
2005-06-26 05:57:56 +08:00
|
|
|
#undef STR
|
|
|
|
#undef __STR
|
|
|
|
}
|
|
|
|
|
2008-10-31 09:48:08 +08:00
|
|
|
static void machine_kexec_free_page_tables(struct kimage *image)
|
|
|
|
{
|
|
|
|
free_page((unsigned long)image->arch.pgd);
|
2018-05-09 18:42:20 +08:00
|
|
|
image->arch.pgd = NULL;
|
2008-10-31 09:48:08 +08:00
|
|
|
#ifdef CONFIG_X86_PAE
|
|
|
|
free_page((unsigned long)image->arch.pmd0);
|
2018-05-09 18:42:20 +08:00
|
|
|
image->arch.pmd0 = NULL;
|
2008-10-31 09:48:08 +08:00
|
|
|
free_page((unsigned long)image->arch.pmd1);
|
2018-05-09 18:42:20 +08:00
|
|
|
image->arch.pmd1 = NULL;
|
2008-10-31 09:48:08 +08:00
|
|
|
#endif
|
|
|
|
free_page((unsigned long)image->arch.pte0);
|
2018-05-09 18:42:20 +08:00
|
|
|
image->arch.pte0 = NULL;
|
2008-10-31 09:48:08 +08:00
|
|
|
free_page((unsigned long)image->arch.pte1);
|
2018-05-09 18:42:20 +08:00
|
|
|
image->arch.pte1 = NULL;
|
2008-10-31 09:48:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int machine_kexec_alloc_page_tables(struct kimage *image)
|
|
|
|
{
|
|
|
|
image->arch.pgd = (pgd_t *)get_zeroed_page(GFP_KERNEL);
|
|
|
|
#ifdef CONFIG_X86_PAE
|
|
|
|
image->arch.pmd0 = (pmd_t *)get_zeroed_page(GFP_KERNEL);
|
|
|
|
image->arch.pmd1 = (pmd_t *)get_zeroed_page(GFP_KERNEL);
|
|
|
|
#endif
|
|
|
|
image->arch.pte0 = (pte_t *)get_zeroed_page(GFP_KERNEL);
|
|
|
|
image->arch.pte1 = (pte_t *)get_zeroed_page(GFP_KERNEL);
|
|
|
|
if (!image->arch.pgd ||
|
|
|
|
#ifdef CONFIG_X86_PAE
|
|
|
|
!image->arch.pmd0 || !image->arch.pmd1 ||
|
|
|
|
#endif
|
|
|
|
!image->arch.pte0 || !image->arch.pte1) {
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-31 09:48:15 +08:00
|
|
|
static void machine_kexec_page_table_set_one(
|
|
|
|
pgd_t *pgd, pmd_t *pmd, pte_t *pte,
|
|
|
|
unsigned long vaddr, unsigned long paddr)
|
|
|
|
{
|
2017-03-18 02:55:10 +08:00
|
|
|
p4d_t *p4d;
|
2008-10-31 09:48:15 +08:00
|
|
|
pud_t *pud;
|
|
|
|
|
|
|
|
pgd += pgd_index(vaddr);
|
|
|
|
#ifdef CONFIG_X86_PAE
|
|
|
|
if (!(pgd_val(*pgd) & _PAGE_PRESENT))
|
|
|
|
set_pgd(pgd, __pgd(__pa(pmd) | _PAGE_PRESENT));
|
|
|
|
#endif
|
2017-03-18 02:55:10 +08:00
|
|
|
p4d = p4d_offset(pgd, vaddr);
|
|
|
|
pud = pud_offset(p4d, vaddr);
|
2008-10-31 09:48:15 +08:00
|
|
|
pmd = pmd_offset(pud, vaddr);
|
|
|
|
if (!(pmd_val(*pmd) & _PAGE_PRESENT))
|
|
|
|
set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
|
|
|
|
pte = pte_offset_kernel(pmd, vaddr);
|
|
|
|
set_pte(pte, pfn_pte(paddr >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void machine_kexec_prepare_page_tables(struct kimage *image)
|
|
|
|
{
|
|
|
|
void *control_page;
|
2009-02-22 08:00:57 +08:00
|
|
|
pmd_t *pmd = NULL;
|
2008-10-31 09:48:15 +08:00
|
|
|
|
|
|
|
control_page = page_address(image->control_code_page);
|
|
|
|
#ifdef CONFIG_X86_PAE
|
|
|
|
pmd = image->arch.pmd0;
|
|
|
|
#endif
|
|
|
|
machine_kexec_page_table_set_one(
|
|
|
|
image->arch.pgd, pmd, image->arch.pte0,
|
|
|
|
(unsigned long)control_page, __pa(control_page));
|
|
|
|
#ifdef CONFIG_X86_PAE
|
|
|
|
pmd = image->arch.pmd1;
|
|
|
|
#endif
|
|
|
|
machine_kexec_page_table_set_one(
|
|
|
|
image->arch.pgd, pmd, image->arch.pte1,
|
|
|
|
__pa(control_page), __pa(control_page));
|
|
|
|
}
|
|
|
|
|
2005-06-26 05:57:56 +08:00
|
|
|
/*
|
|
|
|
* A architecture hook called to validate the
|
|
|
|
* proposed image and prepare the control pages
|
2008-08-15 15:40:22 +08:00
|
|
|
* as needed. The pages for KEXEC_CONTROL_PAGE_SIZE
|
2005-06-26 05:57:56 +08:00
|
|
|
* 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.
|
|
|
|
*
|
2008-10-31 09:48:08 +08:00
|
|
|
* - Make control page executable.
|
|
|
|
* - Allocate page tables
|
2008-10-31 09:48:15 +08:00
|
|
|
* - Setup page tables
|
2005-06-26 05:57:56 +08:00
|
|
|
*/
|
|
|
|
int machine_kexec_prepare(struct kimage *image)
|
|
|
|
{
|
2008-10-31 09:48:15 +08:00
|
|
|
int error;
|
|
|
|
|
2009-11-14 07:28:15 +08:00
|
|
|
set_pages_x(image->control_code_page, 1);
|
2008-10-31 09:48:15 +08:00
|
|
|
error = machine_kexec_alloc_page_tables(image);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
machine_kexec_prepare_page_tables(image);
|
|
|
|
return 0;
|
2005-06-26 05:57:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Undo anything leftover by machine_kexec_prepare
|
|
|
|
* when an image is freed.
|
|
|
|
*/
|
|
|
|
void machine_kexec_cleanup(struct kimage *image)
|
|
|
|
{
|
2009-11-14 07:28:15 +08:00
|
|
|
set_pages_nx(image->control_code_page, 1);
|
2008-10-31 09:48:08 +08:00
|
|
|
machine_kexec_free_page_tables(image);
|
2005-06-26 05:57:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do not allocate memory (or fail in any way) in machine_kexec().
|
|
|
|
* We are past the point of no return, committed to rebooting now.
|
|
|
|
*/
|
2008-07-26 10:45:07 +08:00
|
|
|
void machine_kexec(struct kimage *image)
|
2005-06-26 05:57:56 +08:00
|
|
|
{
|
2006-09-26 16:52:38 +08:00
|
|
|
unsigned long page_list[PAGES_NR];
|
|
|
|
void *control_page;
|
2008-08-15 15:40:26 +08:00
|
|
|
int save_ftrace_enabled;
|
2008-07-26 10:45:07 +08:00
|
|
|
asmlinkage unsigned long
|
|
|
|
(*relocate_kernel_ptr)(unsigned long indirection_page,
|
|
|
|
unsigned long control_page,
|
|
|
|
unsigned long start_address,
|
|
|
|
unsigned int has_pae,
|
|
|
|
unsigned int preserve_context);
|
2005-06-26 05:57:56 +08:00
|
|
|
|
2008-08-15 15:40:26 +08:00
|
|
|
#ifdef CONFIG_KEXEC_JUMP
|
2009-05-08 10:51:41 +08:00
|
|
|
if (image->preserve_context)
|
2008-08-15 15:40:26 +08:00
|
|
|
save_processor_state();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
save_ftrace_enabled = __ftrace_enabled_save();
|
2008-05-13 03:20:43 +08:00
|
|
|
|
2005-06-26 05:57:56 +08:00
|
|
|
/* Interrupts aren't acceptable while we reboot */
|
|
|
|
local_irq_disable();
|
2009-06-02 02:16:03 +08:00
|
|
|
hw_breakpoint_disable();
|
2005-06-26 05:57:56 +08:00
|
|
|
|
kexec jump: save/restore device state
This patch implements devices state save/restore before after kexec.
This patch together with features in kexec_jump patch can be used for
following:
- A simple hibernation implementation without ACPI support. You can kexec a
hibernating kernel, save the memory image of original system and shutdown
the system. When resuming, you restore the memory image of original system
via ordinary kexec load then jump back.
- Kernel/system debug through making system snapshot. You can make system
snapshot, jump back, do some thing and make another system snapshot.
- Cooperative multi-kernel/system. With kexec jump, you can switch between
several kernels/systems quickly without boot process except the first time.
This appears like swap a whole kernel/system out/in.
- A general method to call program in physical mode (paging turning
off). This can be used to invoke BIOS code under Linux.
The following user-space tools can be used with kexec jump:
- kexec-tools needs to be patched to support kexec jump. The patches
and the precompiled kexec can be download from the following URL:
source: http://khibernation.sourceforge.net/download/release_v10/kexec-tools/kexec-tools-src_git_kh10.tar.bz2
patches: http://khibernation.sourceforge.net/download/release_v10/kexec-tools/kexec-tools-patches_git_kh10.tar.bz2
binary: http://khibernation.sourceforge.net/download/release_v10/kexec-tools/kexec_git_kh10
- makedumpfile with patches are used as memory image saving tool, it
can exclude free pages from original kernel memory image file. The
patches and the precompiled makedumpfile can be download from the
following URL:
source: http://khibernation.sourceforge.net/download/release_v10/makedumpfile/makedumpfile-src_cvs_kh10.tar.bz2
patches: http://khibernation.sourceforge.net/download/release_v10/makedumpfile/makedumpfile-patches_cvs_kh10.tar.bz2
binary: http://khibernation.sourceforge.net/download/release_v10/makedumpfile/makedumpfile_cvs_kh10
- An initramfs image can be used as the root file system of kexeced
kernel. An initramfs image built with "BuildRoot" can be downloaded
from the following URL:
initramfs image: http://khibernation.sourceforge.net/download/release_v10/initramfs/rootfs_cvs_kh10.gz
All user space tools above are included in the initramfs image.
Usage example of simple hibernation:
1. Compile and install patched kernel with following options selected:
CONFIG_X86_32=y
CONFIG_RELOCATABLE=y
CONFIG_KEXEC=y
CONFIG_CRASH_DUMP=y
CONFIG_PM=y
CONFIG_HIBERNATION=y
CONFIG_KEXEC_JUMP=y
2. Build an initramfs image contains kexec-tool and makedumpfile, or
download the pre-built initramfs image, called rootfs.gz in
following text.
3. Prepare a partition to save memory image of original kernel, called
hibernating partition in following text.
4. Boot kernel compiled in step 1 (kernel A).
5. In the kernel A, load kernel compiled in step 1 (kernel B) with
/sbin/kexec. The shell command line can be as follow:
/sbin/kexec --load-preserve-context /boot/bzImage --mem-min=0x100000
--mem-max=0xffffff --initrd=rootfs.gz
6. Boot the kernel B with following shell command line:
/sbin/kexec -e
7. The kernel B will boot as normal kexec. In kernel B the memory
image of kernel A can be saved into hibernating partition as
follow:
jump_back_entry=`cat /proc/cmdline | tr ' ' '\n' | grep kexec_jump_back_entry | cut -d '='`
echo $jump_back_entry > kexec_jump_back_entry
cp /proc/vmcore dump.elf
Then you can shutdown the machine as normal.
8. Boot kernel compiled in step 1 (kernel C). Use the rootfs.gz as
root file system.
9. In kernel C, load the memory image of kernel A as follow:
/sbin/kexec -l --args-none --entry=`cat kexec_jump_back_entry` dump.elf
10. Jump back to the kernel A as follow:
/sbin/kexec -e
Then, kernel A is resumed.
Implementation point:
To support jumping between two kernels, before jumping to (executing)
the new kernel and jumping back to the original kernel, the devices
are put into quiescent state, and the state of devices and CPU is
saved. After jumping back from kexeced kernel and jumping to the new
kernel, the state of devices and CPU are restored accordingly. The
devices/CPU state save/restore code of software suspend is called to
implement corresponding function.
Known issues:
- Because the segment number supported by sys_kexec_load is limited,
hibernation image with many segments may not be load. This is
planned to be eliminated by adding a new flag to sys_kexec_load to
make a image can be loaded with multiple sys_kexec_load invoking.
Now, only the i386 architecture is supported.
Signed-off-by: Huang Ying <ying.huang@intel.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Nigel Cunningham <nigel@nigel.suspend2.net>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-07-26 10:45:10 +08:00
|
|
|
if (image->preserve_context) {
|
|
|
|
#ifdef CONFIG_X86_IO_APIC
|
2009-03-10 10:56:57 +08:00
|
|
|
/*
|
|
|
|
* We need to put APICs in legacy mode so that we can
|
kexec jump: save/restore device state
This patch implements devices state save/restore before after kexec.
This patch together with features in kexec_jump patch can be used for
following:
- A simple hibernation implementation without ACPI support. You can kexec a
hibernating kernel, save the memory image of original system and shutdown
the system. When resuming, you restore the memory image of original system
via ordinary kexec load then jump back.
- Kernel/system debug through making system snapshot. You can make system
snapshot, jump back, do some thing and make another system snapshot.
- Cooperative multi-kernel/system. With kexec jump, you can switch between
several kernels/systems quickly without boot process except the first time.
This appears like swap a whole kernel/system out/in.
- A general method to call program in physical mode (paging turning
off). This can be used to invoke BIOS code under Linux.
The following user-space tools can be used with kexec jump:
- kexec-tools needs to be patched to support kexec jump. The patches
and the precompiled kexec can be download from the following URL:
source: http://khibernation.sourceforge.net/download/release_v10/kexec-tools/kexec-tools-src_git_kh10.tar.bz2
patches: http://khibernation.sourceforge.net/download/release_v10/kexec-tools/kexec-tools-patches_git_kh10.tar.bz2
binary: http://khibernation.sourceforge.net/download/release_v10/kexec-tools/kexec_git_kh10
- makedumpfile with patches are used as memory image saving tool, it
can exclude free pages from original kernel memory image file. The
patches and the precompiled makedumpfile can be download from the
following URL:
source: http://khibernation.sourceforge.net/download/release_v10/makedumpfile/makedumpfile-src_cvs_kh10.tar.bz2
patches: http://khibernation.sourceforge.net/download/release_v10/makedumpfile/makedumpfile-patches_cvs_kh10.tar.bz2
binary: http://khibernation.sourceforge.net/download/release_v10/makedumpfile/makedumpfile_cvs_kh10
- An initramfs image can be used as the root file system of kexeced
kernel. An initramfs image built with "BuildRoot" can be downloaded
from the following URL:
initramfs image: http://khibernation.sourceforge.net/download/release_v10/initramfs/rootfs_cvs_kh10.gz
All user space tools above are included in the initramfs image.
Usage example of simple hibernation:
1. Compile and install patched kernel with following options selected:
CONFIG_X86_32=y
CONFIG_RELOCATABLE=y
CONFIG_KEXEC=y
CONFIG_CRASH_DUMP=y
CONFIG_PM=y
CONFIG_HIBERNATION=y
CONFIG_KEXEC_JUMP=y
2. Build an initramfs image contains kexec-tool and makedumpfile, or
download the pre-built initramfs image, called rootfs.gz in
following text.
3. Prepare a partition to save memory image of original kernel, called
hibernating partition in following text.
4. Boot kernel compiled in step 1 (kernel A).
5. In the kernel A, load kernel compiled in step 1 (kernel B) with
/sbin/kexec. The shell command line can be as follow:
/sbin/kexec --load-preserve-context /boot/bzImage --mem-min=0x100000
--mem-max=0xffffff --initrd=rootfs.gz
6. Boot the kernel B with following shell command line:
/sbin/kexec -e
7. The kernel B will boot as normal kexec. In kernel B the memory
image of kernel A can be saved into hibernating partition as
follow:
jump_back_entry=`cat /proc/cmdline | tr ' ' '\n' | grep kexec_jump_back_entry | cut -d '='`
echo $jump_back_entry > kexec_jump_back_entry
cp /proc/vmcore dump.elf
Then you can shutdown the machine as normal.
8. Boot kernel compiled in step 1 (kernel C). Use the rootfs.gz as
root file system.
9. In kernel C, load the memory image of kernel A as follow:
/sbin/kexec -l --args-none --entry=`cat kexec_jump_back_entry` dump.elf
10. Jump back to the kernel A as follow:
/sbin/kexec -e
Then, kernel A is resumed.
Implementation point:
To support jumping between two kernels, before jumping to (executing)
the new kernel and jumping back to the original kernel, the devices
are put into quiescent state, and the state of devices and CPU is
saved. After jumping back from kexeced kernel and jumping to the new
kernel, the state of devices and CPU are restored accordingly. The
devices/CPU state save/restore code of software suspend is called to
implement corresponding function.
Known issues:
- Because the segment number supported by sys_kexec_load is limited,
hibernation image with many segments may not be load. This is
planned to be eliminated by adding a new flag to sys_kexec_load to
make a image can be loaded with multiple sys_kexec_load invoking.
Now, only the i386 architecture is supported.
Signed-off-by: Huang Ying <ying.huang@intel.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Nigel Cunningham <nigel@nigel.suspend2.net>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-07-26 10:45:10 +08:00
|
|
|
* get timer interrupts in second kernel. kexec/kdump
|
2018-02-14 13:46:54 +08:00
|
|
|
* paths already have calls to restore_boot_irq_mode()
|
|
|
|
* in one form or other. kexec jump path also need one.
|
kexec jump: save/restore device state
This patch implements devices state save/restore before after kexec.
This patch together with features in kexec_jump patch can be used for
following:
- A simple hibernation implementation without ACPI support. You can kexec a
hibernating kernel, save the memory image of original system and shutdown
the system. When resuming, you restore the memory image of original system
via ordinary kexec load then jump back.
- Kernel/system debug through making system snapshot. You can make system
snapshot, jump back, do some thing and make another system snapshot.
- Cooperative multi-kernel/system. With kexec jump, you can switch between
several kernels/systems quickly without boot process except the first time.
This appears like swap a whole kernel/system out/in.
- A general method to call program in physical mode (paging turning
off). This can be used to invoke BIOS code under Linux.
The following user-space tools can be used with kexec jump:
- kexec-tools needs to be patched to support kexec jump. The patches
and the precompiled kexec can be download from the following URL:
source: http://khibernation.sourceforge.net/download/release_v10/kexec-tools/kexec-tools-src_git_kh10.tar.bz2
patches: http://khibernation.sourceforge.net/download/release_v10/kexec-tools/kexec-tools-patches_git_kh10.tar.bz2
binary: http://khibernation.sourceforge.net/download/release_v10/kexec-tools/kexec_git_kh10
- makedumpfile with patches are used as memory image saving tool, it
can exclude free pages from original kernel memory image file. The
patches and the precompiled makedumpfile can be download from the
following URL:
source: http://khibernation.sourceforge.net/download/release_v10/makedumpfile/makedumpfile-src_cvs_kh10.tar.bz2
patches: http://khibernation.sourceforge.net/download/release_v10/makedumpfile/makedumpfile-patches_cvs_kh10.tar.bz2
binary: http://khibernation.sourceforge.net/download/release_v10/makedumpfile/makedumpfile_cvs_kh10
- An initramfs image can be used as the root file system of kexeced
kernel. An initramfs image built with "BuildRoot" can be downloaded
from the following URL:
initramfs image: http://khibernation.sourceforge.net/download/release_v10/initramfs/rootfs_cvs_kh10.gz
All user space tools above are included in the initramfs image.
Usage example of simple hibernation:
1. Compile and install patched kernel with following options selected:
CONFIG_X86_32=y
CONFIG_RELOCATABLE=y
CONFIG_KEXEC=y
CONFIG_CRASH_DUMP=y
CONFIG_PM=y
CONFIG_HIBERNATION=y
CONFIG_KEXEC_JUMP=y
2. Build an initramfs image contains kexec-tool and makedumpfile, or
download the pre-built initramfs image, called rootfs.gz in
following text.
3. Prepare a partition to save memory image of original kernel, called
hibernating partition in following text.
4. Boot kernel compiled in step 1 (kernel A).
5. In the kernel A, load kernel compiled in step 1 (kernel B) with
/sbin/kexec. The shell command line can be as follow:
/sbin/kexec --load-preserve-context /boot/bzImage --mem-min=0x100000
--mem-max=0xffffff --initrd=rootfs.gz
6. Boot the kernel B with following shell command line:
/sbin/kexec -e
7. The kernel B will boot as normal kexec. In kernel B the memory
image of kernel A can be saved into hibernating partition as
follow:
jump_back_entry=`cat /proc/cmdline | tr ' ' '\n' | grep kexec_jump_back_entry | cut -d '='`
echo $jump_back_entry > kexec_jump_back_entry
cp /proc/vmcore dump.elf
Then you can shutdown the machine as normal.
8. Boot kernel compiled in step 1 (kernel C). Use the rootfs.gz as
root file system.
9. In kernel C, load the memory image of kernel A as follow:
/sbin/kexec -l --args-none --entry=`cat kexec_jump_back_entry` dump.elf
10. Jump back to the kernel A as follow:
/sbin/kexec -e
Then, kernel A is resumed.
Implementation point:
To support jumping between two kernels, before jumping to (executing)
the new kernel and jumping back to the original kernel, the devices
are put into quiescent state, and the state of devices and CPU is
saved. After jumping back from kexeced kernel and jumping to the new
kernel, the state of devices and CPU are restored accordingly. The
devices/CPU state save/restore code of software suspend is called to
implement corresponding function.
Known issues:
- Because the segment number supported by sys_kexec_load is limited,
hibernation image with many segments may not be load. This is
planned to be eliminated by adding a new flag to sys_kexec_load to
make a image can be loaded with multiple sys_kexec_load invoking.
Now, only the i386 architecture is supported.
Signed-off-by: Huang Ying <ying.huang@intel.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Nigel Cunningham <nigel@nigel.suspend2.net>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-07-26 10:45:10 +08:00
|
|
|
*/
|
2018-02-14 13:46:52 +08:00
|
|
|
clear_IO_APIC();
|
|
|
|
restore_boot_irq_mode();
|
kexec jump: save/restore device state
This patch implements devices state save/restore before after kexec.
This patch together with features in kexec_jump patch can be used for
following:
- A simple hibernation implementation without ACPI support. You can kexec a
hibernating kernel, save the memory image of original system and shutdown
the system. When resuming, you restore the memory image of original system
via ordinary kexec load then jump back.
- Kernel/system debug through making system snapshot. You can make system
snapshot, jump back, do some thing and make another system snapshot.
- Cooperative multi-kernel/system. With kexec jump, you can switch between
several kernels/systems quickly without boot process except the first time.
This appears like swap a whole kernel/system out/in.
- A general method to call program in physical mode (paging turning
off). This can be used to invoke BIOS code under Linux.
The following user-space tools can be used with kexec jump:
- kexec-tools needs to be patched to support kexec jump. The patches
and the precompiled kexec can be download from the following URL:
source: http://khibernation.sourceforge.net/download/release_v10/kexec-tools/kexec-tools-src_git_kh10.tar.bz2
patches: http://khibernation.sourceforge.net/download/release_v10/kexec-tools/kexec-tools-patches_git_kh10.tar.bz2
binary: http://khibernation.sourceforge.net/download/release_v10/kexec-tools/kexec_git_kh10
- makedumpfile with patches are used as memory image saving tool, it
can exclude free pages from original kernel memory image file. The
patches and the precompiled makedumpfile can be download from the
following URL:
source: http://khibernation.sourceforge.net/download/release_v10/makedumpfile/makedumpfile-src_cvs_kh10.tar.bz2
patches: http://khibernation.sourceforge.net/download/release_v10/makedumpfile/makedumpfile-patches_cvs_kh10.tar.bz2
binary: http://khibernation.sourceforge.net/download/release_v10/makedumpfile/makedumpfile_cvs_kh10
- An initramfs image can be used as the root file system of kexeced
kernel. An initramfs image built with "BuildRoot" can be downloaded
from the following URL:
initramfs image: http://khibernation.sourceforge.net/download/release_v10/initramfs/rootfs_cvs_kh10.gz
All user space tools above are included in the initramfs image.
Usage example of simple hibernation:
1. Compile and install patched kernel with following options selected:
CONFIG_X86_32=y
CONFIG_RELOCATABLE=y
CONFIG_KEXEC=y
CONFIG_CRASH_DUMP=y
CONFIG_PM=y
CONFIG_HIBERNATION=y
CONFIG_KEXEC_JUMP=y
2. Build an initramfs image contains kexec-tool and makedumpfile, or
download the pre-built initramfs image, called rootfs.gz in
following text.
3. Prepare a partition to save memory image of original kernel, called
hibernating partition in following text.
4. Boot kernel compiled in step 1 (kernel A).
5. In the kernel A, load kernel compiled in step 1 (kernel B) with
/sbin/kexec. The shell command line can be as follow:
/sbin/kexec --load-preserve-context /boot/bzImage --mem-min=0x100000
--mem-max=0xffffff --initrd=rootfs.gz
6. Boot the kernel B with following shell command line:
/sbin/kexec -e
7. The kernel B will boot as normal kexec. In kernel B the memory
image of kernel A can be saved into hibernating partition as
follow:
jump_back_entry=`cat /proc/cmdline | tr ' ' '\n' | grep kexec_jump_back_entry | cut -d '='`
echo $jump_back_entry > kexec_jump_back_entry
cp /proc/vmcore dump.elf
Then you can shutdown the machine as normal.
8. Boot kernel compiled in step 1 (kernel C). Use the rootfs.gz as
root file system.
9. In kernel C, load the memory image of kernel A as follow:
/sbin/kexec -l --args-none --entry=`cat kexec_jump_back_entry` dump.elf
10. Jump back to the kernel A as follow:
/sbin/kexec -e
Then, kernel A is resumed.
Implementation point:
To support jumping between two kernels, before jumping to (executing)
the new kernel and jumping back to the original kernel, the devices
are put into quiescent state, and the state of devices and CPU is
saved. After jumping back from kexeced kernel and jumping to the new
kernel, the state of devices and CPU are restored accordingly. The
devices/CPU state save/restore code of software suspend is called to
implement corresponding function.
Known issues:
- Because the segment number supported by sys_kexec_load is limited,
hibernation image with many segments may not be load. This is
planned to be eliminated by adding a new flag to sys_kexec_load to
make a image can be loaded with multiple sys_kexec_load invoking.
Now, only the i386 architecture is supported.
Signed-off-by: Huang Ying <ying.huang@intel.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Nigel Cunningham <nigel@nigel.suspend2.net>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-07-26 10:45:10 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-09-26 16:52:38 +08:00
|
|
|
control_page = page_address(image->control_code_page);
|
2008-08-15 15:40:23 +08:00
|
|
|
memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
|
2006-09-26 16:52:38 +08:00
|
|
|
|
2008-07-26 10:45:07 +08:00
|
|
|
relocate_kernel_ptr = control_page;
|
2006-09-26 16:52:38 +08:00
|
|
|
page_list[PA_CONTROL_PAGE] = __pa(control_page);
|
2008-07-26 10:45:07 +08:00
|
|
|
page_list[VA_CONTROL_PAGE] = (unsigned long)control_page;
|
2008-10-31 09:48:08 +08:00
|
|
|
page_list[PA_PGD] = __pa(image->arch.pgd);
|
2008-10-20 12:51:52 +08:00
|
|
|
|
|
|
|
if (image->type == KEXEC_TYPE_DEFAULT)
|
|
|
|
page_list[PA_SWAP_PAGE] = (page_to_pfn(image->swap_page)
|
|
|
|
<< PAGE_SHIFT);
|
2005-06-26 05:57:56 +08:00
|
|
|
|
2009-03-10 10:56:57 +08:00
|
|
|
/*
|
|
|
|
* The segment registers are funny things, they have both a
|
2006-07-30 18:03:20 +08:00
|
|
|
* visible and an invisible part. Whenever the visible part is
|
|
|
|
* set to a specific selector, the invisible part is loaded
|
|
|
|
* with from a table in memory. At no other time is the
|
|
|
|
* descriptor table in memory accessed.
|
2005-06-26 05:57:56 +08:00
|
|
|
*
|
|
|
|
* I take advantage of this here by force loading the
|
|
|
|
* segments, before I zap the gdt with an invalid value.
|
|
|
|
*/
|
|
|
|
load_segments();
|
2009-03-10 10:56:57 +08:00
|
|
|
/*
|
|
|
|
* The gdt & idt are now invalid.
|
2005-06-26 05:57:56 +08:00
|
|
|
* If you want to load them you must set up your own idt & gdt.
|
|
|
|
*/
|
2017-08-28 14:47:46 +08:00
|
|
|
idt_invalidate(phys_to_virt(0));
|
x86-32: Fix kexec with stack canary (CONFIG_CC_STACKPROTECTOR)
Commit e802a51ede91 ("x86/idt: Consolidate IDT invalidation") cleaned up
and unified the IDT invalidation that existed in a couple of places. It
changed no actual real code.
Despite not changing any actual real code, it _did_ change code generation:
by implementing the common idt_invalidate() function in
archx86/kernel/idt.c, it made the use of the function in
arch/x86/kernel/machine_kexec_32.c be a real function call rather than an
(accidental) inlining of the function.
That, in turn, exposed two issues:
- in load_segments(), we had incorrectly reset all the segment
registers, which then made the stack canary load (which gcc does
using offset of %gs) cause a trap. Instead of %gs pointing to the
stack canary, it will be the normal zero-based kernel segment, and
the stack canary load will take a page fault at address 0x14.
- to make this even harder to debug, we had invalidated the GDT just
before calling idt_invalidate(), which meant that the fault happened
with an invalid GDT, which in turn causes a triple fault and
immediate reboot.
Fix this by
(a) not reloading the special segments in load_segments(). We currently
don't do any percpu accesses (which would require %fs on x86-32) in
this area, but there's no reason to think that we might not want to
do them, and like %gs, it's pointless to break it.
(b) doing idt_invalidate() before invalidating the GDT, to keep things
at least _slightly_ more debuggable for a bit longer. Without a
IDT, traps will not work. Without a GDT, traps also will not work,
but neither will any segment loads etc. So in a very real sense,
the GDT is even more core than the IDT.
Fixes: e802a51ede91 ("x86/idt: Consolidate IDT invalidation")
Reported-and-tested-by: Alexandru Chirvasitu <achirvasub@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/alpine.LFD.2.21.1712271143180.8572@i7.lan
2017-12-28 03:48:50 +08:00
|
|
|
set_gdt(phys_to_virt(0), 0);
|
2005-06-26 05:57:56 +08:00
|
|
|
|
|
|
|
/* now call it */
|
2008-07-26 10:45:07 +08:00
|
|
|
image->start = relocate_kernel_ptr((unsigned long)image->head,
|
|
|
|
(unsigned long)page_list,
|
2014-09-12 05:15:11 +08:00
|
|
|
image->start,
|
|
|
|
boot_cpu_has(X86_FEATURE_PAE),
|
2008-07-26 10:45:07 +08:00
|
|
|
image->preserve_context);
|
2008-08-15 15:40:26 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_KEXEC_JUMP
|
2009-05-08 10:51:41 +08:00
|
|
|
if (image->preserve_context)
|
2008-08-15 15:40:26 +08:00
|
|
|
restore_processor_state();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
__ftrace_enabled_restore(save_ftrace_enabled);
|
2005-06-26 05:57:56 +08:00
|
|
|
}
|
2006-09-26 16:52:32 +08:00
|
|
|
|
2007-10-17 14:27:27 +08:00
|
|
|
void arch_crash_save_vmcoreinfo(void)
|
|
|
|
{
|
2008-02-07 16:15:23 +08:00
|
|
|
#ifdef CONFIG_NUMA
|
2007-10-17 14:27:30 +08:00
|
|
|
VMCOREINFO_SYMBOL(node_data);
|
|
|
|
VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
|
2007-10-17 14:27:27 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_X86_PAE
|
2007-10-17 14:27:30 +08:00
|
|
|
VMCOREINFO_CONFIG(X86_PAE);
|
2007-10-17 14:27:27 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|