public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] x86/boot/64: Load kernel GDT in early boot
@ 2024-02-26 22:05 Brian Gerst
  2024-02-27 14:57 ` Ard Biesheuvel
  2024-02-28 10:11 ` [tip: x86/boot] x86/boot/64: Load the final kernel GDT during early boot directly, remove startup_gdt[] tip-bot2 for Brian Gerst
  0 siblings, 2 replies; 3+ messages in thread
From: Brian Gerst @ 2024-02-26 22:05 UTC (permalink / raw)
  To: linux-kernel, x86
  Cc: Ingo Molnar, Thomas Gleixner, Borislav Petkov, H . Peter Anvin,
	Peter Zijlstra, Ard Biesheuvel, Brian Gerst

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>
---
v2: Updated to latest tip tree

 arch/x86/include/asm/desc.h |  1 +
 arch/x86/kernel/head64.c    | 13 ++-----------
 2 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
index ec95fe44fa3a..62dc9f59ea76 100644
--- a/arch/x86/include/asm/desc.h
+++ b/arch/x86/include/asm/desc.h
@@ -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)
diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
index 72351c3121a6..fd77a266f29d 100644
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -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 */

base-commit: afb9cce6ad6e808cf659f43925941be96f61b9c9
-- 
2.43.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] x86/boot/64: Load kernel GDT in early boot
  2024-02-26 22:05 [PATCH v2] x86/boot/64: Load kernel GDT in early boot Brian Gerst
@ 2024-02-27 14:57 ` Ard Biesheuvel
  2024-02-28 10:11 ` [tip: x86/boot] x86/boot/64: Load the final kernel GDT during early boot directly, remove startup_gdt[] tip-bot2 for Brian Gerst
  1 sibling, 0 replies; 3+ messages in thread
From: Ard Biesheuvel @ 2024-02-27 14:57 UTC (permalink / raw)
  To: Brian Gerst
  Cc: linux-kernel, x86, Ingo Molnar, Thomas Gleixner, Borislav Petkov,
	H . Peter Anvin, Peter Zijlstra

On Mon, 26 Feb 2024 at 23:05, Brian Gerst <brgerst@gmail.com> wrote:
>
> 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>
> ---
> v2: Updated to latest tip tree
>

Acked-by: Ard Biesheuvel <ardb@kernel.org>

>  arch/x86/include/asm/desc.h |  1 +
>  arch/x86/kernel/head64.c    | 13 ++-----------
>  2 files changed, 3 insertions(+), 11 deletions(-)
>
> diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
> index ec95fe44fa3a..62dc9f59ea76 100644
> --- a/arch/x86/include/asm/desc.h
> +++ b/arch/x86/include/asm/desc.h
> @@ -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)
> diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
> index 72351c3121a6..fd77a266f29d 100644
> --- a/arch/x86/kernel/head64.c
> +++ b/arch/x86/kernel/head64.c
> @@ -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 */
>
> base-commit: afb9cce6ad6e808cf659f43925941be96f61b9c9
> --
> 2.43.2
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip: x86/boot] x86/boot/64: Load the final kernel GDT during early boot directly, remove startup_gdt[]
  2024-02-26 22:05 [PATCH v2] x86/boot/64: Load kernel GDT in early boot Brian Gerst
  2024-02-27 14:57 ` Ard Biesheuvel
@ 2024-02-28 10:11 ` tip-bot2 for Brian Gerst
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Brian Gerst @ 2024-02-28 10:11 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Brian Gerst, Ingo Molnar, Ard Biesheuvel, Kees Cook,
	Andy Lutomirski, Linus Torvalds, H. Peter Anvin, Josh Poimboeuf,
	x86, linux-kernel

The following commit has been merged into the x86/boot branch of tip:

Commit-ID:     11e36b0f7c2150a6453872b79555767b43c846d0
Gitweb:        https://git.kernel.org/tip/11e36b0f7c2150a6453872b79555767b43c846d0
Author:        Brian Gerst <brgerst@gmail.com>
AuthorDate:    Mon, 26 Feb 2024 17:05:44 -05:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Wed, 28 Feb 2024 11:02:16 +01:00

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
---
 arch/x86/include/asm/desc.h |  1 +
 arch/x86/kernel/head64.c    | 13 ++-----------
 2 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
index ab97b22..52c0150 100644
--- a/arch/x86/include/asm/desc.h
+++ b/arch/x86/include/asm/desc.h
@@ -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)
diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
index 72351c3..fd77a26 100644
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -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 */

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-28 10:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-26 22:05 [PATCH v2] x86/boot/64: Load kernel GDT in early boot Brian Gerst
2024-02-27 14:57 ` Ard Biesheuvel
2024-02-28 10:11 ` [tip: x86/boot] x86/boot/64: Load the final kernel GDT during early boot directly, remove startup_gdt[] tip-bot2 for Brian Gerst

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox