Skip to content

Commit 6479755

Browse files
ardbiesheuvelIngo Molnar
authored andcommitted
x86/boot: Defer initialization of VM space related global variables
The global pseudo-constants 'page_offset_base', 'vmalloc_base' and 'vmemmap_base' are not used extremely early during the boot, and cannot be used safely until after the KASLR memory randomization code in kernel_randomize_memory() executes, which may update their values. So there is no point in setting these variables extremely early, and it can wait until after the kernel itself is mapped and running from its permanent virtual mapping. Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: Linus Torvalds <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 891d3b8 commit 6479755

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

arch/x86/boot/startup/map_kernel.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ static inline bool check_la57_support(void)
2929
__pgtable_l5_enabled = 1;
3030
pgdir_shift = 48;
3131
ptrs_per_p4d = 512;
32-
page_offset_base = __PAGE_OFFSET_BASE_L5;
33-
vmalloc_base = __VMALLOC_BASE_L5;
34-
vmemmap_base = __VMEMMAP_BASE_L5;
3532

3633
return true;
3734
}

arch/x86/kernel/head64.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,10 @@ EXPORT_SYMBOL(ptrs_per_p4d);
6262
#ifdef CONFIG_DYNAMIC_MEMORY_LAYOUT
6363
unsigned long page_offset_base __ro_after_init = __PAGE_OFFSET_BASE_L4;
6464
EXPORT_SYMBOL(page_offset_base);
65-
SYM_PIC_ALIAS(page_offset_base);
6665
unsigned long vmalloc_base __ro_after_init = __VMALLOC_BASE_L4;
6766
EXPORT_SYMBOL(vmalloc_base);
68-
SYM_PIC_ALIAS(vmalloc_base);
6967
unsigned long vmemmap_base __ro_after_init = __VMEMMAP_BASE_L4;
7068
EXPORT_SYMBOL(vmemmap_base);
71-
SYM_PIC_ALIAS(vmemmap_base);
7269
#endif
7370

7471
/* Wipe all early page tables except for the kernel symbol map */
@@ -244,6 +241,12 @@ asmlinkage __visible void __init __noreturn x86_64_start_kernel(char * real_mode
244241
/* Kill off the identity-map trampoline */
245242
reset_early_page_tables();
246243

244+
if (pgtable_l5_enabled()) {
245+
page_offset_base = __PAGE_OFFSET_BASE_L5;
246+
vmalloc_base = __VMALLOC_BASE_L5;
247+
vmemmap_base = __VMEMMAP_BASE_L5;
248+
}
249+
247250
clear_bss();
248251

249252
/*

0 commit comments

Comments
 (0)