direct-io.hg

view patches/linux-2.6.16.33/git-3566561bfadffcb5dbc85d576be80c0dbf2cccc9.patch @ 12988:e080700efa56

[TOOLS] Fix the build. Clearly demarcate PPC-specific stuff.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Wed Dec 13 10:23:53 2006 +0000 (2006-12-13)
parents 5690d18637f5
children
line source
1 From: Magnus Damm <magnus@valinux.co.jp>
2 Date: Tue, 26 Sep 2006 08:52:38 +0000 (+0200)
3 Subject: [PATCH] i386: Avoid overwriting the current pgd (V4, i386)
4 X-Git-Url: http://www.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=3566561bfadffcb5dbc85d576be80c0dbf2cccc9
6 [PATCH] i386: Avoid overwriting the current pgd (V4, i386)
8 kexec: Avoid overwriting the current pgd (V4, i386)
10 This patch upgrades the i386-specific kexec code to avoid overwriting the
11 current pgd. Overwriting the current pgd is bad when CONFIG_CRASH_DUMP is used
12 to start a secondary kernel that dumps the memory of the previous kernel.
14 The code introduces a new set of page tables. These tables are used to provide
15 an executable identity mapping without overwriting the current pgd.
17 Signed-off-by: Magnus Damm <magnus@valinux.co.jp>
18 Signed-off-by: Andi Kleen <ak@suse.de>
19 ---
21 --- a/arch/i386/kernel/machine_kexec.c
22 +++ b/arch/i386/kernel/machine_kexec.c
23 @@ -21,70 +21,13 @@
24 #include <asm/system.h>
26 #define PAGE_ALIGNED __attribute__ ((__aligned__(PAGE_SIZE)))
27 -
28 -#define L0_ATTR (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY)
29 -#define L1_ATTR (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY)
30 -#define L2_ATTR (_PAGE_PRESENT)
31 -
32 -#define LEVEL0_SIZE (1UL << 12UL)
33 -
34 -#ifndef CONFIG_X86_PAE
35 -#define LEVEL1_SIZE (1UL << 22UL)
36 -static u32 pgtable_level1[1024] PAGE_ALIGNED;
37 -
38 -static void identity_map_page(unsigned long address)
39 -{
40 - unsigned long level1_index, level2_index;
41 - u32 *pgtable_level2;
42 -
43 - /* Find the current page table */
44 - pgtable_level2 = __va(read_cr3());
45 -
46 - /* Find the indexes of the physical address to identity map */
47 - level1_index = (address % LEVEL1_SIZE)/LEVEL0_SIZE;
48 - level2_index = address / LEVEL1_SIZE;
49 -
50 - /* Identity map the page table entry */
51 - pgtable_level1[level1_index] = address | L0_ATTR;
52 - pgtable_level2[level2_index] = __pa(pgtable_level1) | L1_ATTR;
53 -
54 - /* Flush the tlb so the new mapping takes effect.
55 - * Global tlb entries are not flushed but that is not an issue.
56 - */
57 - load_cr3(pgtable_level2);
58 -}
59 -
60 -#else
61 -#define LEVEL1_SIZE (1UL << 21UL)
62 -#define LEVEL2_SIZE (1UL << 30UL)
63 -static u64 pgtable_level1[512] PAGE_ALIGNED;
64 -static u64 pgtable_level2[512] PAGE_ALIGNED;
65 -
66 -static void identity_map_page(unsigned long address)
67 -{
68 - unsigned long level1_index, level2_index, level3_index;
69 - u64 *pgtable_level3;
70 -
71 - /* Find the current page table */
72 - pgtable_level3 = __va(read_cr3());
73 -
74 - /* Find the indexes of the physical address to identity map */
75 - level1_index = (address % LEVEL1_SIZE)/LEVEL0_SIZE;
76 - level2_index = (address % LEVEL2_SIZE)/LEVEL1_SIZE;
77 - level3_index = address / LEVEL2_SIZE;
78 -
79 - /* Identity map the page table entry */
80 - pgtable_level1[level1_index] = address | L0_ATTR;
81 - pgtable_level2[level2_index] = __pa(pgtable_level1) | L1_ATTR;
82 - set_64bit(&pgtable_level3[level3_index],
83 - __pa(pgtable_level2) | L2_ATTR);
84 -
85 - /* Flush the tlb so the new mapping takes effect.
86 - * Global tlb entries are not flushed but that is not an issue.
87 - */
88 - load_cr3(pgtable_level3);
89 -}
90 +static u32 kexec_pgd[1024] PAGE_ALIGNED;
91 +#ifdef CONFIG_X86_PAE
92 +static u32 kexec_pmd0[1024] PAGE_ALIGNED;
93 +static u32 kexec_pmd1[1024] PAGE_ALIGNED;
94 #endif
95 +static u32 kexec_pte0[1024] PAGE_ALIGNED;
96 +static u32 kexec_pte1[1024] PAGE_ALIGNED;
98 static void set_idt(void *newidt, __u16 limit)
99 {
100 @@ -128,16 +71,6 @@ static void load_segments(void)
101 #undef __STR
102 }
104 -typedef asmlinkage NORET_TYPE void (*relocate_new_kernel_t)(
105 - unsigned long indirection_page,
106 - unsigned long reboot_code_buffer,
107 - unsigned long start_address,
108 - unsigned int has_pae) ATTRIB_NORET;
109 -
110 -extern const unsigned char relocate_new_kernel[];
111 -extern void relocate_new_kernel_end(void);
112 -extern const unsigned int relocate_new_kernel_size;
113 -
114 /*
115 * A architecture hook called to validate the
116 * proposed image and prepare the control pages
117 @@ -170,25 +103,29 @@ void machine_kexec_cleanup(struct kimage
118 */
119 NORET_TYPE void machine_kexec(struct kimage *image)
120 {
121 - unsigned long page_list;
122 - unsigned long reboot_code_buffer;
123 -
124 - relocate_new_kernel_t rnk;
125 + unsigned long page_list[PAGES_NR];
126 + void *control_page;
128 /* Interrupts aren't acceptable while we reboot */
129 local_irq_disable();
131 - /* Compute some offsets */
132 - reboot_code_buffer = page_to_pfn(image->control_code_page)
133 - << PAGE_SHIFT;
134 - page_list = image->head;
135 -
136 - /* Set up an identity mapping for the reboot_code_buffer */
137 - identity_map_page(reboot_code_buffer);
138 -
139 - /* copy it out */
140 - memcpy((void *)reboot_code_buffer, relocate_new_kernel,
141 - relocate_new_kernel_size);
142 + control_page = page_address(image->control_code_page);
143 + memcpy(control_page, relocate_kernel, PAGE_SIZE);
144 +
145 + page_list[PA_CONTROL_PAGE] = __pa(control_page);
146 + page_list[VA_CONTROL_PAGE] = (unsigned long)relocate_kernel;
147 + page_list[PA_PGD] = __pa(kexec_pgd);
148 + page_list[VA_PGD] = (unsigned long)kexec_pgd;
149 +#ifdef CONFIG_X86_PAE
150 + page_list[PA_PMD_0] = __pa(kexec_pmd0);
151 + page_list[VA_PMD_0] = (unsigned long)kexec_pmd0;
152 + page_list[PA_PMD_1] = __pa(kexec_pmd1);
153 + page_list[VA_PMD_1] = (unsigned long)kexec_pmd1;
154 +#endif
155 + page_list[PA_PTE_0] = __pa(kexec_pte0);
156 + page_list[VA_PTE_0] = (unsigned long)kexec_pte0;
157 + page_list[PA_PTE_1] = __pa(kexec_pte1);
158 + page_list[VA_PTE_1] = (unsigned long)kexec_pte1;
160 /* The segment registers are funny things, they have both a
161 * visible and an invisible part. Whenever the visible part is
162 @@ -207,8 +144,8 @@ NORET_TYPE void machine_kexec(struct kim
163 set_idt(phys_to_virt(0),0);
165 /* now call it */
166 - rnk = (relocate_new_kernel_t) reboot_code_buffer;
167 - (*rnk)(page_list, reboot_code_buffer, image->start, cpu_has_pae);
168 + relocate_kernel((unsigned long)image->head, (unsigned long)page_list,
169 + image->start, cpu_has_pae);
170 }
172 /* crashkernel=size@addr specifies the location to reserve for
173 --- a/arch/i386/kernel/relocate_kernel.S
174 +++ b/arch/i386/kernel/relocate_kernel.S
175 @@ -7,16 +7,138 @@
176 */
178 #include <linux/linkage.h>
179 +#include <asm/page.h>
180 +#include <asm/kexec.h>
181 +
182 +/*
183 + * Must be relocatable PIC code callable as a C function
184 + */
185 +
186 +#define PTR(x) (x << 2)
187 +#define PAGE_ALIGNED (1 << PAGE_SHIFT)
188 +#define PAGE_ATTR 0x63 /* _PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY */
189 +#define PAE_PGD_ATTR 0x01 /* _PAGE_PRESENT */
190 +
191 + .text
192 + .align PAGE_ALIGNED
193 + .globl relocate_kernel
194 +relocate_kernel:
195 + movl 8(%esp), %ebp /* list of pages */
196 +
197 +#ifdef CONFIG_X86_PAE
198 + /* map the control page at its virtual address */
199 +
200 + movl PTR(VA_PGD)(%ebp), %edi
201 + movl PTR(VA_CONTROL_PAGE)(%ebp), %eax
202 + andl $0xc0000000, %eax
203 + shrl $27, %eax
204 + addl %edi, %eax
205 +
206 + movl PTR(PA_PMD_0)(%ebp), %edx
207 + orl $PAE_PGD_ATTR, %edx
208 + movl %edx, (%eax)
209 +
210 + movl PTR(VA_PMD_0)(%ebp), %edi
211 + movl PTR(VA_CONTROL_PAGE)(%ebp), %eax
212 + andl $0x3fe00000, %eax
213 + shrl $18, %eax
214 + addl %edi, %eax
215 +
216 + movl PTR(PA_PTE_0)(%ebp), %edx
217 + orl $PAGE_ATTR, %edx
218 + movl %edx, (%eax)
219 +
220 + movl PTR(VA_PTE_0)(%ebp), %edi
221 + movl PTR(VA_CONTROL_PAGE)(%ebp), %eax
222 + andl $0x001ff000, %eax
223 + shrl $9, %eax
224 + addl %edi, %eax
225 +
226 + movl PTR(PA_CONTROL_PAGE)(%ebp), %edx
227 + orl $PAGE_ATTR, %edx
228 + movl %edx, (%eax)
229 +
230 + /* identity map the control page at its physical address */
231 +
232 + movl PTR(VA_PGD)(%ebp), %edi
233 + movl PTR(PA_CONTROL_PAGE)(%ebp), %eax
234 + andl $0xc0000000, %eax
235 + shrl $27, %eax
236 + addl %edi, %eax
237 +
238 + movl PTR(PA_PMD_1)(%ebp), %edx
239 + orl $PAE_PGD_ATTR, %edx
240 + movl %edx, (%eax)
241 +
242 + movl PTR(VA_PMD_1)(%ebp), %edi
243 + movl PTR(PA_CONTROL_PAGE)(%ebp), %eax
244 + andl $0x3fe00000, %eax
245 + shrl $18, %eax
246 + addl %edi, %eax
247 +
248 + movl PTR(PA_PTE_1)(%ebp), %edx
249 + orl $PAGE_ATTR, %edx
250 + movl %edx, (%eax)
251 +
252 + movl PTR(VA_PTE_1)(%ebp), %edi
253 + movl PTR(PA_CONTROL_PAGE)(%ebp), %eax
254 + andl $0x001ff000, %eax
255 + shrl $9, %eax
256 + addl %edi, %eax
257 +
258 + movl PTR(PA_CONTROL_PAGE)(%ebp), %edx
259 + orl $PAGE_ATTR, %edx
260 + movl %edx, (%eax)
261 +#else
262 + /* map the control page at its virtual address */
263 +
264 + movl PTR(VA_PGD)(%ebp), %edi
265 + movl PTR(VA_CONTROL_PAGE)(%ebp), %eax
266 + andl $0xffc00000, %eax
267 + shrl $20, %eax
268 + addl %edi, %eax
269 +
270 + movl PTR(PA_PTE_0)(%ebp), %edx
271 + orl $PAGE_ATTR, %edx
272 + movl %edx, (%eax)
273 +
274 + movl PTR(VA_PTE_0)(%ebp), %edi
275 + movl PTR(VA_CONTROL_PAGE)(%ebp), %eax
276 + andl $0x003ff000, %eax
277 + shrl $10, %eax
278 + addl %edi, %eax
279 +
280 + movl PTR(PA_CONTROL_PAGE)(%ebp), %edx
281 + orl $PAGE_ATTR, %edx
282 + movl %edx, (%eax)
283 +
284 + /* identity map the control page at its physical address */
285 +
286 + movl PTR(VA_PGD)(%ebp), %edi
287 + movl PTR(PA_CONTROL_PAGE)(%ebp), %eax
288 + andl $0xffc00000, %eax
289 + shrl $20, %eax
290 + addl %edi, %eax
291 +
292 + movl PTR(PA_PTE_1)(%ebp), %edx
293 + orl $PAGE_ATTR, %edx
294 + movl %edx, (%eax)
295 +
296 + movl PTR(VA_PTE_1)(%ebp), %edi
297 + movl PTR(PA_CONTROL_PAGE)(%ebp), %eax
298 + andl $0x003ff000, %eax
299 + shrl $10, %eax
300 + addl %edi, %eax
301 +
302 + movl PTR(PA_CONTROL_PAGE)(%ebp), %edx
303 + orl $PAGE_ATTR, %edx
304 + movl %edx, (%eax)
305 +#endif
307 - /*
308 - * Must be relocatable PIC code callable as a C function, that once
309 - * it starts can not use the previous processes stack.
310 - */
311 - .globl relocate_new_kernel
312 relocate_new_kernel:
313 /* read the arguments and say goodbye to the stack */
314 movl 4(%esp), %ebx /* page_list */
315 - movl 8(%esp), %ebp /* reboot_code_buffer */
316 + movl 8(%esp), %ebp /* list of pages */
317 movl 12(%esp), %edx /* start address */
318 movl 16(%esp), %ecx /* cpu_has_pae */
320 @@ -24,11 +146,26 @@ relocate_new_kernel:
321 pushl $0
322 popfl
324 - /* set a new stack at the bottom of our page... */
325 - lea 4096(%ebp), %esp
326 + /* get physical address of control page now */
327 + /* this is impossible after page table switch */
328 + movl PTR(PA_CONTROL_PAGE)(%ebp), %edi
329 +
330 + /* switch to new set of page tables */
331 + movl PTR(PA_PGD)(%ebp), %eax
332 + movl %eax, %cr3
333 +
334 + /* setup a new stack at the end of the physical control page */
335 + lea 4096(%edi), %esp
337 - /* store the parameters back on the stack */
338 - pushl %edx /* store the start address */
339 + /* jump to identity mapped page */
340 + movl %edi, %eax
341 + addl $(identity_mapped - relocate_kernel), %eax
342 + pushl %eax
343 + ret
344 +
345 +identity_mapped:
346 + /* store the start address on the stack */
347 + pushl %edx
349 /* Set cr0 to a known state:
350 * 31 0 == Paging disabled
351 @@ -113,8 +250,3 @@ relocate_new_kernel:
352 xorl %edi, %edi
353 xorl %ebp, %ebp
354 ret
355 -relocate_new_kernel_end:
356 -
357 - .globl relocate_new_kernel_size
358 -relocate_new_kernel_size:
359 - .long relocate_new_kernel_end - relocate_new_kernel
360 --- a/include/asm-i386/kexec.h
361 +++ b/include/asm-i386/kexec.h
362 @@ -1,6 +1,26 @@
363 #ifndef _I386_KEXEC_H
364 #define _I386_KEXEC_H
366 +#define PA_CONTROL_PAGE 0
367 +#define VA_CONTROL_PAGE 1
368 +#define PA_PGD 2
369 +#define VA_PGD 3
370 +#define PA_PTE_0 4
371 +#define VA_PTE_0 5
372 +#define PA_PTE_1 6
373 +#define VA_PTE_1 7
374 +#ifdef CONFIG_X86_PAE
375 +#define PA_PMD_0 8
376 +#define VA_PMD_0 9
377 +#define PA_PMD_1 10
378 +#define VA_PMD_1 11
379 +#define PAGES_NR 12
380 +#else
381 +#define PAGES_NR 8
382 +#endif
383 +
384 +#ifndef __ASSEMBLY__
385 +
386 #include <asm/fixmap.h>
387 #include <asm/ptrace.h>
388 #include <asm/string.h>
389 @@ -72,5 +92,12 @@ static inline void crash_setup_regs(stru
390 newregs->eip = (unsigned long)current_text_addr();
391 }
392 }
393 +asmlinkage NORET_TYPE void
394 +relocate_kernel(unsigned long indirection_page,
395 + unsigned long control_page,
396 + unsigned long start_address,
397 + unsigned int has_pae) ATTRIB_NORET;
398 +
399 +#endif /* __ASSEMBLY__ */
401 #endif /* _I386_KEXEC_H */