Skip to content

Commit 11e36b0

Browse files
Brian GerstIngo Molnar
authored andcommitted
x86/boot/64: Load the final kernel GDT during early boot directly, remove startup_gdt[]
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
1 parent 533568e commit 11e36b0

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

arch/x86/include/asm/desc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct gdt_page {
4646
} __attribute__((aligned(PAGE_SIZE)));
4747

4848
DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
49+
DECLARE_INIT_PER_CPU(gdt_page);
4950

5051
/* Provide the original GDT */
5152
static inline struct desc_struct *get_cpu_gdt_rw(unsigned int cpu)

arch/x86/kernel/head64.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,6 @@ unsigned long vmemmap_base __ro_after_init = __VMEMMAP_BASE_L4;
6868
EXPORT_SYMBOL(vmemmap_base);
6969
#endif
7070

71-
/*
72-
* GDT used on the boot CPU before switching to virtual addresses.
73-
*/
74-
static struct desc_struct startup_gdt[GDT_ENTRIES] __initdata = {
75-
[GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(DESC_CODE32, 0, 0xfffff),
76-
[GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(DESC_CODE64, 0, 0xfffff),
77-
[GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(DESC_DATA64, 0, 0xfffff),
78-
};
79-
8071
#ifdef CONFIG_X86_5LEVEL
8172
static void __head *fixup_pointer(void *ptr, unsigned long physaddr)
8273
{
@@ -589,8 +580,8 @@ void __head startup_64_setup_gdt_idt(void)
589580
void *handler = NULL;
590581

591582
struct desc_ptr startup_gdt_descr = {
592-
.address = (unsigned long)&RIP_REL_REF(startup_gdt),
593-
.size = sizeof(startup_gdt) - 1,
583+
.address = (unsigned long)&RIP_REL_REF(init_per_cpu_var(gdt_page.gdt)),
584+
.size = GDT_SIZE - 1,
594585
};
595586

596587
/* Load GDT */

0 commit comments

Comments
 (0)