Skip to contentSkip to conversation

x86/boot/64: Strip percpu address space from gdt kernel load

PATCH Applied Uros Bizjak 3 participants 3 messages Aug 19, 2024 – Aug 25, 2024 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/boot/64: Strip percpu address space from gdt kernel load

init_per_cpu_var() returns pointer in the percpu address space while rip_rel_ptr() expects pointer in the generic address space, resulting in:

asm.h:124:63: error: passing argument 1 of ‘rip_rel_ptr’ from pointer to non-enclosed address space

when strict address space checks are enabled.

Add explicit casts to remove address space of the returned pointer.

Found by GCC's named address space checks.

There were no changes in the resulting object file.

Fixes 11e36b0f7c21 ("x86/boot/64: Load the final kernel GDT during early boot directly, remove startup_gdt[]")
Cc Brian Gerst <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Dave Hansen <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/kernel/head64.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/kernel/head64.c +3 -1
index a817ed0724d1..2b7a4e28e72f 100644
@@ -560,9 +560,11 @@ void early_setup_idt(void)
 void __head startup_64_setup_gdt_idt(void)
 {
 	void *handler = NULL;
+	struct desc_struct *gdt =
+		(void *)(__force unsigned long)init_per_cpu_var(gdt_page.gdt);
 
 	struct desc_ptr startup_gdt_descr = {
-		.address = (unsigned long)&RIP_REL_REF(init_per_cpu_var(gdt_page.gdt)),
+		.address = (unsigned long)&RIP_REL_REF(*gdt),
 		.size    = GDT_SIZE - 1,
 	};
 
Signature · 1 line
2.46.0
#1 lore raw
Quoted 2 lines · Uros Bizjak

Found by GCC's named address space checks.

Which GCC version?

Thanks

tglx

merge bot Applied
#2 lore raw

[tip: x86/cleanups] x86/boot/64: Strip percpu address space when setting up GDT descriptors

In reply to Uros Bizjak
The following commit has been merged into the x86/cleanups branch of tip:

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

Commit-ID:     b51207dc02ec3aeaa849e419f79055d7334845b6
Gitweb:        https://git.kernel.org/tip/b51207dc02ec3aeaa849e419f79055d7334845b6
Author:        Uros Bizjak <[email protected]>
AuthorDate:    Mon, 19 Aug 2024 10:33:13 +02:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Sun, 25 Aug 2024 16:07:51 +02:00

x86/boot/64: Strip percpu address space when setting up GDT descriptors

init_per_cpu_var() returns a pointer in the percpu address space while rip_rel_ptr() expects a pointer in the generic address space.

When strict address space checks are enabled, GCC's named address space checks fail:

asm.h:124:63: error: passing argument 1 of 'rip_rel_ptr' from
pointer to non-enclosed address space

Add a explicit cast to remove address space of the returned pointer.

Fixes 11e36b0f7c21 ("x86/boot/64: Load the final kernel GDT during early boot directly, remove startup_gdt[]")
---
 arch/x86/kernel/head64.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/head64.c +2 -1
index a817ed0..4b9d455 100644
@@ -559,10 +559,11 @@ void early_setup_idt(void)
  */
 void __head startup_64_setup_gdt_idt(void)
 {
+	struct desc_struct *gdt = (void *)(__force unsigned long)init_per_cpu_var(gdt_page.gdt);
 	void *handler = NULL;
 
 	struct desc_ptr startup_gdt_descr = {
-		.address = (unsigned long)&RIP_REL_REF(init_per_cpu_var(gdt_page.gdt)),
+		.address = (unsigned long)&RIP_REL_REF(*gdt),
 		.size    = GDT_SIZE - 1,
 	};