]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
x86/boot: Defer initialization of VM space related global variables
authorArd Biesheuvel <ardb@kernel.org>
Tue, 13 May 2025 11:11:59 +0000 (13:11 +0200)
committerIngo Molnar <mingo@kernel.org>
Wed, 14 May 2025 08:06:35 +0000 (10:06 +0200)
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 <ardb@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20250513111157.717727-9-ardb+git@google.com
arch/x86/boot/startup/map_kernel.c
arch/x86/kernel/head64.c

index 099ae25593361aa2c5fd4550aff34f8f65520276..905e8734b5a31ba404b4b518d92d489a67e74238 100644 (file)
@@ -29,9 +29,6 @@ static inline bool check_la57_support(void)
        __pgtable_l5_enabled    = 1;
        pgdir_shift             = 48;
        ptrs_per_p4d            = 512;
-       page_offset_base        = __PAGE_OFFSET_BASE_L5;
-       vmalloc_base            = __VMALLOC_BASE_L5;
-       vmemmap_base            = __VMEMMAP_BASE_L5;
 
        return true;
 }
index 510fb41f55fce7521943f6c0f065509b7cb726e0..14f7dda20954b6719af54ce5d7174e196478a0f5 100644 (file)
@@ -62,13 +62,10 @@ EXPORT_SYMBOL(ptrs_per_p4d);
 #ifdef CONFIG_DYNAMIC_MEMORY_LAYOUT
 unsigned long page_offset_base __ro_after_init = __PAGE_OFFSET_BASE_L4;
 EXPORT_SYMBOL(page_offset_base);
-SYM_PIC_ALIAS(page_offset_base);
 unsigned long vmalloc_base __ro_after_init = __VMALLOC_BASE_L4;
 EXPORT_SYMBOL(vmalloc_base);
-SYM_PIC_ALIAS(vmalloc_base);
 unsigned long vmemmap_base __ro_after_init = __VMEMMAP_BASE_L4;
 EXPORT_SYMBOL(vmemmap_base);
-SYM_PIC_ALIAS(vmemmap_base);
 #endif
 
 /* 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
        /* Kill off the identity-map trampoline */
        reset_early_page_tables();
 
+       if (pgtable_l5_enabled()) {
+               page_offset_base        = __PAGE_OFFSET_BASE_L5;
+               vmalloc_base            = __VMALLOC_BASE_L5;
+               vmemmap_base            = __VMEMMAP_BASE_L5;
+       }
+
        clear_bss();
 
        /*