diff options
Diffstat (limited to 'arch/x86/kernel/machine_kexec_64.c')
-rw-r--r-- | arch/x86/kernel/machine_kexec_64.c | 82 |
1 files changed, 55 insertions, 27 deletions
diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c index c43caa3a91f..6993d51b7fd 100644 --- a/arch/x86/kernel/machine_kexec_64.c +++ b/arch/x86/kernel/machine_kexec_64.c | |||
@@ -18,15 +18,6 @@ | |||
18 | #include <asm/mmu_context.h> | 18 | #include <asm/mmu_context.h> |
19 | #include <asm/io.h> | 19 | #include <asm/io.h> |
20 | 20 | ||
21 | #define PAGE_ALIGNED __attribute__ ((__aligned__(PAGE_SIZE))) | ||
22 | static u64 kexec_pgd[512] PAGE_ALIGNED; | ||
23 | static u64 kexec_pud0[512] PAGE_ALIGNED; | ||
24 | static u64 kexec_pmd0[512] PAGE_ALIGNED; | ||
25 | static u64 kexec_pte0[512] PAGE_ALIGNED; | ||
26 | static u64 kexec_pud1[512] PAGE_ALIGNED; | ||
27 | static u64 kexec_pmd1[512] PAGE_ALIGNED; | ||
28 | static u64 kexec_pte1[512] PAGE_ALIGNED; | ||
29 | |||
30 | static void init_level2_page(pmd_t *level2p, unsigned long addr) | 21 | static void init_level2_page(pmd_t *level2p, unsigned long addr) |
31 | { | 22 | { |
32 | unsigned long end_addr; | 23 | unsigned long end_addr; |
@@ -107,12 +98,65 @@ out: | |||
107 | return result; | 98 | return result; |
108 | } | 99 | } |
109 | 100 | ||
101 | static void free_transition_pgtable(struct kimage *image) | ||
102 | { | ||
103 | free_page((unsigned long)image->arch.pud); | ||
104 | free_page((unsigned long)image->arch.pmd); | ||
105 | free_page((unsigned long)image->arch.pte); | ||
106 | } | ||
107 | |||
108 | static int init_transition_pgtable(struct kimage *image, pgd_t *pgd) | ||
109 | { | ||
110 | pud_t *pud; | ||
111 | pmd_t *pmd; | ||
112 | pte_t *pte; | ||
113 | unsigned long vaddr, paddr; | ||
114 | int result = -ENOMEM; | ||
115 | |||
116 | vaddr = (unsigned long)relocate_kernel; | ||
117 | paddr = __pa(page_address(image->control_code_page)+PAGE_SIZE); | ||
118 | pgd += pgd_index(vaddr); | ||
119 | if (!pgd_present(*pgd)) { | ||
120 | pud = (pud_t *)get_zeroed_page(GFP_KERNEL); | ||
121 | if (!pud) | ||
122 | goto err; | ||
123 | image->arch.pud = pud; | ||
124 | set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE)); | ||
125 | } | ||
126 | pud = pud_offset(pgd, vaddr); | ||
127 | if (!pud_present(*pud)) { | ||
128 | pmd = (pmd_t *)get_zeroed_page(GFP_KERNEL); | ||
129 | if (!pmd) | ||
130 | goto err; | ||
131 | image->arch.pmd = pmd; | ||
132 | set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE)); | ||
133 | } | ||
134 | pmd = pmd_offset(pud, vaddr); | ||
135 | if (!pmd_present(*pmd)) { | ||
136 | pte = (pte_t *)get_zeroed_page(GFP_KERNEL); | ||
137 | if (!pte) | ||
138 | goto err; | ||
139 | image->arch.pte = pte; | ||
140 | set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE)); | ||
141 | } | ||
142 | pte = pte_offset_kernel(pmd, vaddr); | ||
143 | set_pte(pte, pfn_pte(paddr >> PAGE_SHIFT, PAGE_KERNEL_EXEC)); | ||
144 | return 0; | ||
145 | err: | ||
146 | free_transition_pgtable(image); | ||
147 | return result; | ||
148 | } | ||
149 | |||
110 | 150 | ||
111 | static int init_pgtable(struct kimage *image, unsigned long start_pgtable) | 151 | static int init_pgtable(struct kimage *image, unsigned long start_pgtable) |
112 | { | 152 | { |
113 | pgd_t *level4p; | 153 | pgd_t *level4p; |
154 | int result; | ||
114 | level4p = (pgd_t *)__va(start_pgtable); | 155 | level4p = (pgd_t *)__va(start_pgtable); |
115 | return init_level4_page(image, level4p, 0, max_pfn << PAGE_SHIFT); | 156 | result = init_level4_page(image, level4p, 0, max_pfn << PAGE_SHIFT); |
157 | if (result) | ||
158 | return result; | ||
159 | return init_transition_pgtable(image, level4p); | ||
116 | } | 160 | } |
117 | 161 | ||
118 | static void set_idt(void *newidt, u16 limit) | 162 | static void set_idt(void *newidt, u16 limit) |
@@ -174,7 +218,7 @@ int machine_kexec_prepare(struct kimage *image) | |||
174 | 218 | ||
175 | void machine_kexec_cleanup(struct kimage *image) | 219 | void machine_kexec_cleanup(struct kimage *image) |
176 | { | 220 | { |
177 | return; | 221 | free_transition_pgtable(image); |
178 | } | 222 | } |
179 | 223 | ||
180 | /* | 224 | /* |
@@ -195,22 +239,6 @@ void machine_kexec(struct kimage *image) | |||
195 | memcpy(control_page, relocate_kernel, PAGE_SIZE); | 239 | memcpy(control_page, relocate_kernel, PAGE_SIZE); |
196 | 240 | ||
197 | page_list[PA_CONTROL_PAGE] = virt_to_phys(control_page); | 241 | page_list[PA_CONTROL_PAGE] = virt_to_phys(control_page); |
198 | page_list[VA_CONTROL_PAGE] = (unsigned long)relocate_kernel; | ||
199 | page_list[PA_PGD] = virt_to_phys(&kexec_pgd); | ||
200 | page_list[VA_PGD] = (unsigned long)kexec_pgd; | ||
201 | page_list[PA_PUD_0] = virt_to_phys(&kexec_pud0); | ||
202 | page_list[VA_PUD_0] = (unsigned long)kexec_pud0; | ||
203 | page_list[PA_PMD_0] = virt_to_phys(&kexec_pmd0); | ||
204 | page_list[VA_PMD_0] = (unsigned long)kexec_pmd0; | ||
205 | page_list[PA_PTE_0] = virt_to_phys(&kexec_pte0); | ||
206 | page_list[VA_PTE_0] = (unsigned long)kexec_pte0; | ||
207 | page_list[PA_PUD_1] = virt_to_phys(&kexec_pud1); | ||
208 | page_list[VA_PUD_1] = (unsigned long)kexec_pud1; | ||
209 | page_list[PA_PMD_1] = virt_to_phys(&kexec_pmd1); | ||
210 | page_list[VA_PMD_1] = (unsigned long)kexec_pmd1; | ||
211 | page_list[PA_PTE_1] = virt_to_phys(&kexec_pte1); | ||
212 | page_list[VA_PTE_1] = (unsigned long)kexec_pte1; | ||
213 | |||
214 | page_list[PA_TABLE_PAGE] = | 242 | page_list[PA_TABLE_PAGE] = |
215 | (unsigned long)__pa(page_address(image->control_code_page)); | 243 | (unsigned long)__pa(page_address(image->control_code_page)); |
216 | 244 | ||