Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/mm: Identify the end of the kernel area to be reserved

The memory occupied by the kernel is reserved using memblock_reserve()
in setup_arch(). Currently, the area is from symbols _text to __bss_stop.
Everything after __bss_stop must be specifically reserved otherwise it
is discarded. This is not clearly documented.

Add a new symbol, __end_of_kernel_reserve, that more readily identifies
what is reserved, along with comments that indicate what is reserved,
what is discarded and what needs to be done to prevent a section from
being discarded.

Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Baoquan He <bhe@redhat.com>
Reviewed-by: Dave Hansen <dave.hansen@intel.com>
Tested-by: Lianbo Jiang <lijiang@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Joerg Roedel <jroedel@suse.de>
Cc: Juergen Gross <jgross@suse.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Pavel Tatashin <pasha.tatashin@oracle.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Robert Richter <rrichter@marvell.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: Sinan Kaya <okaya@codeaurora.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "x86@kernel.org" <x86@kernel.org>
Link: https://lkml.kernel.org/r/7db7da45b435f8477f25e66f292631ff766a844c.1560969363.git.thomas.lendacky@amd.com

authored by

Thomas Lendacky and committed by
Borislav Petkov
c603a309 9e0babf2

+17 -2
+2
arch/x86/include/asm/sections.h
··· 13 13 extern char __end_rodata_hpage_align[]; 14 14 #endif 15 15 16 + extern char __end_of_kernel_reserve[]; 17 + 16 18 #endif /* _ASM_X86_SECTIONS_H */
+7 -1
arch/x86/kernel/setup.c
··· 827 827 828 828 void __init setup_arch(char **cmdline_p) 829 829 { 830 + /* 831 + * Reserve the memory occupied by the kernel between _text and 832 + * __end_of_kernel_reserve symbols. Any kernel sections after the 833 + * __end_of_kernel_reserve symbol must be explicitly reserved with a 834 + * separate memblock_reserve() or they will be discarded. 835 + */ 830 836 memblock_reserve(__pa_symbol(_text), 831 - (unsigned long)__bss_stop - (unsigned long)_text); 837 + (unsigned long)__end_of_kernel_reserve - (unsigned long)_text); 832 838 833 839 /* 834 840 * Make sure page 0 is always reserved because on systems with
+8 -1
arch/x86/kernel/vmlinux.lds.S
··· 368 368 __bss_stop = .; 369 369 } 370 370 371 + /* 372 + * The memory occupied from _text to here, __end_of_kernel_reserve, is 373 + * automatically reserved in setup_arch(). Anything after here must be 374 + * explicitly reserved using memblock_reserve() or it will be discarded 375 + * and treated as available memory. 376 + */ 377 + __end_of_kernel_reserve = .; 378 + 371 379 . = ALIGN(PAGE_SIZE); 372 380 .brk : AT(ADDR(.brk) - LOAD_OFFSET) { 373 381 __brk_base = .; ··· 390 382 STABS_DEBUG 391 383 DWARF_DEBUG 392 384 393 - /* Sections to be discarded */ 394 385 DISCARDS 395 386 /DISCARD/ : { 396 387 *(.eh_frame)