Commit 7c53976404e2f906c60b69cc5793add87ee49c6a

Authored by Alexander van Heukelum
Committed by Ingo Molnar
1 parent 4c8337ac42

x86: cleanup boot-heap usage

The kernel decompressor wrapper uses memory located beyond the
end of the image. This might lead to hard to debug problems,
but even if it can be proven to be safe, it is at the very
least unclean. I don't see any advantages either, unless you
count it not being zeroed out as an advantage. This patch
moves the boot-heap area to the bss segment.

Signed-off-by: Alexander van Heukelum <heukelum@fastmail.fm>

Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

Showing 4 changed files with 31 additions and 22 deletions Side-by-side Diff

arch/x86/boot/compressed/head_32.S
... ... @@ -130,7 +130,7 @@
130 130 /*
131 131 * Setup the stack for the decompressor
132 132 */
133   - leal stack_end(%ebx), %esp
  133 + leal boot_stack_end(%ebx), %esp
134 134  
135 135 /*
136 136 * Do the decompression, and jump to the new kernel..
... ... @@ -142,8 +142,8 @@
142 142 pushl %eax # input_len
143 143 leal input_data(%ebx), %eax
144 144 pushl %eax # input_data
145   - leal _end(%ebx), %eax
146   - pushl %eax # end of the image as third argument
  145 + leal boot_heap(%ebx), %eax
  146 + pushl %eax # heap area as third argument
147 147 pushl %esi # real mode pointer as second arg
148 148 call decompress_kernel
149 149 addl $20, %esp
150 150  
... ... @@ -181,8 +181,11 @@
181 181 jmp *%ebp
182 182  
183 183 .bss
  184 +/* Stack and heap for uncompression */
184 185 .balign 4
185   -stack:
186   - .fill 4096, 1, 0
187   -stack_end:
  186 +boot_heap:
  187 + .fill BOOT_HEAP_SIZE, 1, 0
  188 +boot_stack:
  189 + .fill BOOT_STACK_SIZE, 1, 0
  190 +boot_stack_end:
arch/x86/boot/compressed/head_64.S
... ... @@ -28,6 +28,7 @@
28 28 #include <asm/segment.h>
29 29 #include <asm/pgtable.h>
30 30 #include <asm/page.h>
  31 +#include <asm/boot.h>
31 32 #include <asm/msr.h>
32 33 #include <asm/asm-offsets.h>
33 34  
... ... @@ -62,7 +63,7 @@
62 63 subl $1b, %ebp
63 64  
64 65 /* setup a stack and make sure cpu supports long mode. */
65   - movl $user_stack_end, %eax
  66 + movl $boot_stack_end, %eax
66 67 addl %ebp, %eax
67 68 movl %eax, %esp
68 69  
... ... @@ -274,7 +275,7 @@
274 275 stosb
275 276  
276 277 /* Setup the stack */
277   - leaq user_stack_end(%rip), %rsp
  278 + leaq boot_stack_end(%rip), %rsp
278 279  
279 280 /* zero EFLAGS after setting rsp */
280 281 pushq $0
... ... @@ -285,7 +286,7 @@
285 286 */
286 287 pushq %rsi # Save the real mode argument
287 288 movq %rsi, %rdi # real mode address
288   - leaq _heap(%rip), %rsi # _heap
  289 + leaq boot_heap(%rip), %rsi # malloc area for uncompression
289 290 leaq input_data(%rip), %rdx # input_data
290 291 movl input_len(%rip), %eax
291 292 movq %rax, %rcx # input_len
... ... @@ -310,10 +311,13 @@
310 311 .quad 0x0080890000000000 /* TS descriptor */
311 312 .quad 0x0000000000000000 /* TS continued */
312 313 gdt_end:
313   - .bss
314   -/* Stack for uncompression */
315   - .balign 4
316   -user_stack:
317   - .fill 4096,4,0
318   -user_stack_end:
  314 +
  315 +.bss
  316 +/* Stack and heap for uncompression */
  317 +.balign 4
  318 +boot_heap:
  319 + .fill BOOT_HEAP_SIZE, 1, 0
  320 +boot_stack:
  321 + .fill BOOT_STACK_SIZE, 1, 0
  322 +boot_stack_end:
arch/x86/boot/compressed/misc.c
... ... @@ -217,12 +217,6 @@
217 217 static memptr free_mem_ptr;
218 218 static memptr free_mem_end_ptr;
219 219  
220   -#ifdef CONFIG_X86_64
221   -#define HEAP_SIZE 0x7000
222   -#else
223   -#define HEAP_SIZE 0x4000
224   -#endif
225   -
226 220 static char *vidmem;
227 221 static int vidport;
228 222 static int lines, cols;
... ... @@ -449,7 +443,7 @@
449 443  
450 444 window = output; /* Output buffer (Normally at 1M) */
451 445 free_mem_ptr = heap; /* Heap */
452   - free_mem_end_ptr = heap + HEAP_SIZE;
  446 + free_mem_end_ptr = heap + BOOT_HEAP_SIZE;
453 447 inbuf = input_data; /* Input buffer */
454 448 insize = input_len;
455 449 inptr = 0;
include/asm-x86/boot.h
... ... @@ -17,5 +17,13 @@
17 17 + (CONFIG_PHYSICAL_ALIGN - 1)) \
18 18 & ~(CONFIG_PHYSICAL_ALIGN - 1))
19 19  
  20 +#ifdef CONFIG_X86_64
  21 +#define BOOT_HEAP_SIZE 0x7000
  22 +#define BOOT_STACK_SIZE 0x4000
  23 +#else
  24 +#define BOOT_HEAP_SIZE 0x4000
  25 +#define BOOT_STACK_SIZE 0x1000
  26 +#endif
  27 +
20 28 #endif /* _ASM_BOOT_H */