x86/boot/64: Load the final kernel GDT during early boot directly, remove startup_gdt[]
authorBrian Gerst <brgerst@gmail.com>
Mon, 26 Feb 2024 22:05:44 +0000 (17:05 -0500)
committerIngo Molnar <mingo@kernel.org>
Wed, 28 Feb 2024 10:02:16 +0000 (11:02 +0100)
Instead of loading a duplicate GDT just for early boot, load the kernel
GDT from its physical address.

Signed-off-by: Brian Gerst <brgerst@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Link: https://lore.kernel.org/r/20240226220544.70769-1-brgerst@gmail.com
arch/x86/include/asm/desc.h
arch/x86/kernel/head64.c

index ab97b22ac04a263ab78782a9d00f2237c98e0f20..52c0150179907f8b506ed9f9230301bdae31d2bc 100644 (file)
@@ -46,6 +46,7 @@ struct gdt_page {
 } __attribute__((aligned(PAGE_SIZE)));
 
 DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
+DECLARE_INIT_PER_CPU(gdt_page);
 
 /* Provide the original GDT */
 static inline struct desc_struct *get_cpu_gdt_rw(unsigned int cpu)
index 72351c3121a62f283f1b4028b3547b53e5c9165b..fd77a266f29dddce92ce0bbc03f47fadf076e1ee 100644 (file)
@@ -68,15 +68,6 @@ unsigned long vmemmap_base __ro_after_init = __VMEMMAP_BASE_L4;
 EXPORT_SYMBOL(vmemmap_base);
 #endif
 
-/*
- * GDT used on the boot CPU before switching to virtual addresses.
- */
-static struct desc_struct startup_gdt[GDT_ENTRIES] __initdata = {
-       [GDT_ENTRY_KERNEL32_CS]         = GDT_ENTRY_INIT(DESC_CODE32, 0, 0xfffff),
-       [GDT_ENTRY_KERNEL_CS]           = GDT_ENTRY_INIT(DESC_CODE64, 0, 0xfffff),
-       [GDT_ENTRY_KERNEL_DS]           = GDT_ENTRY_INIT(DESC_DATA64, 0, 0xfffff),
-};
-
 #ifdef CONFIG_X86_5LEVEL
 static void __head *fixup_pointer(void *ptr, unsigned long physaddr)
 {
@@ -589,8 +580,8 @@ void __head startup_64_setup_gdt_idt(void)
        void *handler = NULL;
 
        struct desc_ptr startup_gdt_descr = {
-               .address = (unsigned long)&RIP_REL_REF(startup_gdt),
-               .size    = sizeof(startup_gdt) - 1,
+               .address = (unsigned long)&RIP_REL_REF(init_per_cpu_var(gdt_page.gdt)),
+               .size    = GDT_SIZE - 1,
        };
 
        /* Load GDT */