Commit 63bed966 authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Borislav Petkov (AMD)

x86/startup_64: Defer assignment of 5-level paging global variables

Assigning the 5-level paging related global variables from the earliest
C code using explicit references that use the 1:1 translation of memory
is unnecessary, as the startup code itself does not rely on them to
create the initial page tables, and this is all it should be doing. So
defer these assignments to the primary C entry code that executes via
the ordinary kernel virtual mapping.
Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
Signed-off-by: default avatarBorislav Petkov (AMD) <bp@alien8.de>
Tested-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
Link: https://lore.kernel.org/r/20240227151907.387873-13-ardb+git@google.com
parent dada8587
...@@ -21,9 +21,9 @@ typedef unsigned long pgprotval_t; ...@@ -21,9 +21,9 @@ typedef unsigned long pgprotval_t;
typedef struct { pteval_t pte; } pte_t; typedef struct { pteval_t pte; } pte_t;
typedef struct { pmdval_t pmd; } pmd_t; typedef struct { pmdval_t pmd; } pmd_t;
#ifdef CONFIG_X86_5LEVEL
extern unsigned int __pgtable_l5_enabled; extern unsigned int __pgtable_l5_enabled;
#ifdef CONFIG_X86_5LEVEL
#ifdef USE_EARLY_PGTABLE_L5 #ifdef USE_EARLY_PGTABLE_L5
/* /*
* cpu_feature_enabled() is not available in early boot code. * cpu_feature_enabled() is not available in early boot code.
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <linux/pgtable.h> #include <linux/pgtable.h>
#include <asm/asm.h> #include <asm/asm.h>
#include <asm/page_64.h>
#include <asm/processor.h> #include <asm/processor.h>
#include <asm/proto.h> #include <asm/proto.h>
#include <asm/smp.h> #include <asm/smp.h>
...@@ -68,24 +69,11 @@ unsigned long vmemmap_base __ro_after_init = __VMEMMAP_BASE_L4; ...@@ -68,24 +69,11 @@ unsigned long vmemmap_base __ro_after_init = __VMEMMAP_BASE_L4;
EXPORT_SYMBOL(vmemmap_base); EXPORT_SYMBOL(vmemmap_base);
#endif #endif
#ifdef CONFIG_X86_5LEVEL static inline bool check_la57_support(void)
static void __head *fixup_pointer(void *ptr, unsigned long physaddr)
{ {
return ptr - (void *)_text + (void *)physaddr; if (!IS_ENABLED(CONFIG_X86_5LEVEL))
} return false;
static unsigned long __head *fixup_long(void *ptr, unsigned long physaddr)
{
return fixup_pointer(ptr, physaddr);
}
static unsigned int __head *fixup_int(void *ptr, unsigned long physaddr)
{
return fixup_pointer(ptr, physaddr);
}
static bool __head check_la57_support(unsigned long physaddr)
{
/* /*
* 5-level paging is detected and enabled at kernel decompression * 5-level paging is detected and enabled at kernel decompression
* stage. Only check if it has been enabled there. * stage. Only check if it has been enabled there.
...@@ -93,21 +81,8 @@ static bool __head check_la57_support(unsigned long physaddr) ...@@ -93,21 +81,8 @@ static bool __head check_la57_support(unsigned long physaddr)
if (!(native_read_cr4() & X86_CR4_LA57)) if (!(native_read_cr4() & X86_CR4_LA57))
return false; return false;
*fixup_int(&__pgtable_l5_enabled, physaddr) = 1;
*fixup_int(&pgdir_shift, physaddr) = 48;
*fixup_int(&ptrs_per_p4d, physaddr) = 512;
*fixup_long(&page_offset_base, physaddr) = __PAGE_OFFSET_BASE_L5;
*fixup_long(&vmalloc_base, physaddr) = __VMALLOC_BASE_L5;
*fixup_long(&vmemmap_base, physaddr) = __VMEMMAP_BASE_L5;
return true; return true;
} }
#else
static bool __head check_la57_support(unsigned long physaddr)
{
return false;
}
#endif
static unsigned long __head sme_postprocess_startup(struct boot_params *bp, pmdval_t *pmd) static unsigned long __head sme_postprocess_startup(struct boot_params *bp, pmdval_t *pmd)
{ {
...@@ -171,7 +146,7 @@ unsigned long __head __startup_64(unsigned long physaddr, ...@@ -171,7 +146,7 @@ unsigned long __head __startup_64(unsigned long physaddr,
bool la57; bool la57;
int i; int i;
la57 = check_la57_support(physaddr); la57 = check_la57_support();
/* Is the address too large? */ /* Is the address too large? */
if (physaddr >> MAX_PHYSMEM_BITS) if (physaddr >> MAX_PHYSMEM_BITS)
...@@ -456,6 +431,15 @@ asmlinkage __visible void __init __noreturn x86_64_start_kernel(char * real_mode ...@@ -456,6 +431,15 @@ asmlinkage __visible void __init __noreturn x86_64_start_kernel(char * real_mode
(__START_KERNEL & PGDIR_MASK))); (__START_KERNEL & PGDIR_MASK)));
BUILD_BUG_ON(__fix_to_virt(__end_of_fixed_addresses) <= MODULES_END); BUILD_BUG_ON(__fix_to_virt(__end_of_fixed_addresses) <= MODULES_END);
if (check_la57_support()) {
__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;
}
cr4_init_shadow(); cr4_init_shadow();
/* Kill off the identity-map trampoline */ /* Kill off the identity-map trampoline */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment