Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 1 | /* |
Dave Jones | 835c34a | 2007-10-12 21:10:53 -0400 | [diff] [blame] | 2 | * handle transition of Linux booting another kernel |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 3 | * Copyright (C) 2002-2005 Eric Biederman <ebiederm@xmission.com> |
| 4 | * |
| 5 | * This source code is licensed under the GNU General Public License, |
| 6 | * Version 2. See the file COPYING for more details. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/mm.h> |
| 10 | #include <linux/kexec.h> |
| 11 | #include <linux/delay.h> |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 12 | #include <linux/init.h> |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 13 | #include <linux/numa.h> |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 14 | #include <asm/pgtable.h> |
| 15 | #include <asm/pgalloc.h> |
| 16 | #include <asm/tlbflush.h> |
| 17 | #include <asm/mmu_context.h> |
| 18 | #include <asm/io.h> |
| 19 | #include <asm/apic.h> |
| 20 | #include <asm/cpufeature.h> |
Eric W. Biederman | e7b47cc | 2005-07-29 13:01:18 -0600 | [diff] [blame] | 21 | #include <asm/desc.h> |
Zachary Amsden | 4bb0d3e | 2005-09-03 15:56:36 -0700 | [diff] [blame] | 22 | #include <asm/system.h> |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 23 | |
| 24 | #define PAGE_ALIGNED __attribute__ ((__aligned__(PAGE_SIZE))) |
Magnus Damm | 3566561 | 2006-09-26 10:52:38 +0200 | [diff] [blame] | 25 | static u32 kexec_pgd[1024] PAGE_ALIGNED; |
| 26 | #ifdef CONFIG_X86_PAE |
| 27 | static u32 kexec_pmd0[1024] PAGE_ALIGNED; |
| 28 | static u32 kexec_pmd1[1024] PAGE_ALIGNED; |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 29 | #endif |
Magnus Damm | 3566561 | 2006-09-26 10:52:38 +0200 | [diff] [blame] | 30 | static u32 kexec_pte0[1024] PAGE_ALIGNED; |
| 31 | static u32 kexec_pte1[1024] PAGE_ALIGNED; |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 32 | |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 33 | static void set_idt(void *newidt, __u16 limit) |
| 34 | { |
Glauber de Oliveira Costa | 6b68f01 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 35 | struct desc_ptr curidt; |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 36 | |
| 37 | /* ia32 supports unaliged loads & stores */ |
Eric W. Biederman | e7b47cc | 2005-07-29 13:01:18 -0600 | [diff] [blame] | 38 | curidt.size = limit; |
| 39 | curidt.address = (unsigned long)newidt; |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 40 | |
Zachary Amsden | f2ab446 | 2005-09-03 15:56:42 -0700 | [diff] [blame] | 41 | load_idt(&curidt); |
WANG Cong | 378fc6e | 2008-06-24 16:21:18 +0100 | [diff] [blame^] | 42 | } |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 43 | |
| 44 | |
| 45 | static void set_gdt(void *newgdt, __u16 limit) |
| 46 | { |
Glauber de Oliveira Costa | 6b68f01 | 2008-01-30 13:31:12 +0100 | [diff] [blame] | 47 | struct desc_ptr curgdt; |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 48 | |
| 49 | /* ia32 supports unaligned loads & stores */ |
Eric W. Biederman | e7b47cc | 2005-07-29 13:01:18 -0600 | [diff] [blame] | 50 | curgdt.size = limit; |
| 51 | curgdt.address = (unsigned long)newgdt; |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 52 | |
Zachary Amsden | f2ab446 | 2005-09-03 15:56:42 -0700 | [diff] [blame] | 53 | load_gdt(&curgdt); |
WANG Cong | 378fc6e | 2008-06-24 16:21:18 +0100 | [diff] [blame^] | 54 | } |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 55 | |
| 56 | static void load_segments(void) |
| 57 | { |
| 58 | #define __STR(X) #X |
| 59 | #define STR(X) __STR(X) |
| 60 | |
| 61 | __asm__ __volatile__ ( |
| 62 | "\tljmp $"STR(__KERNEL_CS)",$1f\n" |
| 63 | "\t1:\n" |
Michael Matz | 2ec5e3a | 2006-03-07 21:55:48 -0800 | [diff] [blame] | 64 | "\tmovl $"STR(__KERNEL_DS)",%%eax\n" |
| 65 | "\tmovl %%eax,%%ds\n" |
| 66 | "\tmovl %%eax,%%es\n" |
| 67 | "\tmovl %%eax,%%fs\n" |
| 68 | "\tmovl %%eax,%%gs\n" |
| 69 | "\tmovl %%eax,%%ss\n" |
| 70 | ::: "eax", "memory"); |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 71 | #undef STR |
| 72 | #undef __STR |
| 73 | } |
| 74 | |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 75 | /* |
| 76 | * A architecture hook called to validate the |
| 77 | * proposed image and prepare the control pages |
| 78 | * as needed. The pages for KEXEC_CONTROL_CODE_SIZE |
| 79 | * have been allocated, but the segments have yet |
| 80 | * been copied into the kernel. |
| 81 | * |
| 82 | * Do what every setup is needed on image and the |
| 83 | * reboot code buffer to allow us to avoid allocations |
| 84 | * later. |
| 85 | * |
| 86 | * Currently nothing. |
| 87 | */ |
| 88 | int machine_kexec_prepare(struct kimage *image) |
| 89 | { |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | /* |
| 94 | * Undo anything leftover by machine_kexec_prepare |
| 95 | * when an image is freed. |
| 96 | */ |
| 97 | void machine_kexec_cleanup(struct kimage *image) |
| 98 | { |
| 99 | } |
| 100 | |
| 101 | /* |
| 102 | * Do not allocate memory (or fail in any way) in machine_kexec(). |
| 103 | * We are past the point of no return, committed to rebooting now. |
| 104 | */ |
| 105 | NORET_TYPE void machine_kexec(struct kimage *image) |
| 106 | { |
Magnus Damm | 3566561 | 2006-09-26 10:52:38 +0200 | [diff] [blame] | 107 | unsigned long page_list[PAGES_NR]; |
| 108 | void *control_page; |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 109 | |
| 110 | /* Interrupts aren't acceptable while we reboot */ |
| 111 | local_irq_disable(); |
| 112 | |
Magnus Damm | 3566561 | 2006-09-26 10:52:38 +0200 | [diff] [blame] | 113 | control_page = page_address(image->control_code_page); |
| 114 | memcpy(control_page, relocate_kernel, PAGE_SIZE); |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 115 | |
Magnus Damm | 3566561 | 2006-09-26 10:52:38 +0200 | [diff] [blame] | 116 | page_list[PA_CONTROL_PAGE] = __pa(control_page); |
| 117 | page_list[VA_CONTROL_PAGE] = (unsigned long)relocate_kernel; |
| 118 | page_list[PA_PGD] = __pa(kexec_pgd); |
| 119 | page_list[VA_PGD] = (unsigned long)kexec_pgd; |
| 120 | #ifdef CONFIG_X86_PAE |
| 121 | page_list[PA_PMD_0] = __pa(kexec_pmd0); |
| 122 | page_list[VA_PMD_0] = (unsigned long)kexec_pmd0; |
| 123 | page_list[PA_PMD_1] = __pa(kexec_pmd1); |
| 124 | page_list[VA_PMD_1] = (unsigned long)kexec_pmd1; |
| 125 | #endif |
| 126 | page_list[PA_PTE_0] = __pa(kexec_pte0); |
| 127 | page_list[VA_PTE_0] = (unsigned long)kexec_pte0; |
| 128 | page_list[PA_PTE_1] = __pa(kexec_pte1); |
| 129 | page_list[VA_PTE_1] = (unsigned long)kexec_pte1; |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 130 | |
Eric W. Biederman | 2a8a3d5 | 2006-07-30 03:03:20 -0700 | [diff] [blame] | 131 | /* The segment registers are funny things, they have both a |
| 132 | * visible and an invisible part. Whenever the visible part is |
| 133 | * set to a specific selector, the invisible part is loaded |
| 134 | * with from a table in memory. At no other time is the |
| 135 | * descriptor table in memory accessed. |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 136 | * |
| 137 | * I take advantage of this here by force loading the |
| 138 | * segments, before I zap the gdt with an invalid value. |
| 139 | */ |
| 140 | load_segments(); |
| 141 | /* The gdt & idt are now invalid. |
| 142 | * If you want to load them you must set up your own idt & gdt. |
| 143 | */ |
| 144 | set_gdt(phys_to_virt(0),0); |
| 145 | set_idt(phys_to_virt(0),0); |
| 146 | |
| 147 | /* now call it */ |
Magnus Damm | 3566561 | 2006-09-26 10:52:38 +0200 | [diff] [blame] | 148 | relocate_kernel((unsigned long)image->head, (unsigned long)page_list, |
| 149 | image->start, cpu_has_pae); |
Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 150 | } |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 151 | |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 152 | void arch_crash_save_vmcoreinfo(void) |
| 153 | { |
Ken'ichi Ohmichi | 92df5c3 | 2008-02-07 00:15:23 -0800 | [diff] [blame] | 154 | #ifdef CONFIG_NUMA |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 155 | VMCOREINFO_SYMBOL(node_data); |
| 156 | VMCOREINFO_LENGTH(node_data, MAX_NUMNODES); |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 157 | #endif |
| 158 | #ifdef CONFIG_X86_PAE |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 159 | VMCOREINFO_CONFIG(X86_PAE); |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 160 | #endif |
| 161 | } |
| 162 | |