Skip to content

Commit 1869dbe

Browse files
swahlhpesuryasaimadhu
authored andcommitted
x86/boot/64: Round memory hole size up to next PMD page
The kernel image map is created using PMD pages, which can include some extra space beyond what's actually needed. Round the size of the memory hole we search for up to the next PMD boundary, to be certain all of the space to be mapped is usable RAM and includes no reserved areas. Signed-off-by: Steve Wahl <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Acked-by: Dave Hansen <[email protected]> Acked-by: Kirill A. Shutemov <[email protected]> Cc: Baoquan He <[email protected]> Cc: Brijesh Singh <[email protected]> Cc: [email protected] Cc: Feng Tang <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jordan Borgner <[email protected]> Cc: Juergen Gross <[email protected]> Cc: [email protected] Cc: [email protected] Cc: Thomas Gleixner <[email protected]> Cc: x86-ml <[email protected]> Cc: Zhenzhong Duan <[email protected]> Link: https://lkml.kernel.org/r/df4f49f05c0c27f108234eb93db5c613d09ea62e.1569358539.git.steve.wahl@hpe.com
1 parent 2aa85f2 commit 1869dbe

File tree

1 file changed

+19
-6
lines changed
  • arch/x86/boot/compressed

1 file changed

+19
-6
lines changed

arch/x86/boot/compressed/misc.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap,
345345
{
346346
const unsigned long kernel_total_size = VO__end - VO__text;
347347
unsigned long virt_addr = LOAD_PHYSICAL_ADDR;
348+
unsigned long needed_size;
348349

349350
/* Retain x86 boot parameters pointer passed from startup_32/64. */
350351
boot_params = rmode;
@@ -379,26 +380,38 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap,
379380
free_mem_ptr = heap; /* Heap */
380381
free_mem_end_ptr = heap + BOOT_HEAP_SIZE;
381382

383+
/*
384+
* The memory hole needed for the kernel is the larger of either
385+
* the entire decompressed kernel plus relocation table, or the
386+
* entire decompressed kernel plus .bss and .brk sections.
387+
*
388+
* On X86_64, the memory is mapped with PMD pages. Round the
389+
* size up so that the full extent of PMD pages mapped is
390+
* included in the check against the valid memory table
391+
* entries. This ensures the full mapped area is usable RAM
392+
* and doesn't include any reserved areas.
393+
*/
394+
needed_size = max(output_len, kernel_total_size);
395+
#ifdef CONFIG_X86_64
396+
needed_size = ALIGN(needed_size, MIN_KERNEL_ALIGN);
397+
#endif
398+
382399
/* Report initial kernel position details. */
383400
debug_putaddr(input_data);
384401
debug_putaddr(input_len);
385402
debug_putaddr(output);
386403
debug_putaddr(output_len);
387404
debug_putaddr(kernel_total_size);
405+
debug_putaddr(needed_size);
388406

389407
#ifdef CONFIG_X86_64
390408
/* Report address of 32-bit trampoline */
391409
debug_putaddr(trampoline_32bit);
392410
#endif
393411

394-
/*
395-
* The memory hole needed for the kernel is the larger of either
396-
* the entire decompressed kernel plus relocation table, or the
397-
* entire decompressed kernel plus .bss and .brk sections.
398-
*/
399412
choose_random_location((unsigned long)input_data, input_len,
400413
(unsigned long *)&output,
401-
max(output_len, kernel_total_size),
414+
needed_size,
402415
&virt_addr);
403416

404417
/* Validate memory location choices. */

0 commit comments

Comments
 (0)