Skip to contentSkip to conversation

x86/vdso: choose the right GDT_ENTRY_CPUNODE for 32-bit getcpu() on 64-bit kernel

PATCH Applied Xin Li 2 participants 2 messages Mar 22, 2023 – Aug 8, 2023 x86

lore
Share & tools
lore

Xin Li

author
#0 lore raw

PATCH v2 1/1 x86/vdso: choose the right GDT_ENTRY_CPUNODE for 32-bit getcpu() on 64-bit kernel

The vDSO getcpu() reads CPU ID from the GDT_ENTRY_CPUNODE entry when the RDPID instruction is not available. And GDT_ENTRY_CPUNODE is defined as 28 on 32-bit Linux kernel and 15 on 64-bit. But the 32-bit getcpu() on 64-bit Linux kernel is compiled with 32-bit Linux kernel GDT_ENTRY_CPUNODE, i.e., 28, beyond the 64-bit Linux kernel GDT limit. Thus, it just fails _silently_.

When BUILD_VDSO32_64 is defined, choose the 64-bit Linux kernel GDT definitions to compile the 32-bit getcpu().

Fixes 877cff5296faa6e ("x86/vdso: Fake 32bit VDSO build on 64bit compile for vgetcpu")

https://lore.kernel.org/oe-lkp/[email protected]/

---

Change since v1:
* Define all of the GDT_ENTRY_* macros in *one* place, then make that *one* place depend on BUILD_VDSO32_64 (Dave Hansen).

---
 arch/x86/include/asm/segment.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/segment.h +1 -1
index 794f69625780..9d6411c65920 100644
@@ -56,7 +56,7 @@
 
 #define GDT_ENTRY_INVALID_SEG	0
 
-#ifdef CONFIG_X86_32
+#if defined(CONFIG_X86_32) && !defined(BUILD_VDSO32_64)
 /*
  * The layout of the per-CPU GDT under Linux:
  *
Signature · 1 line
2.34.1
merge bot Applied
#1 lore raw

[tip: x86/urgent] x86/vdso: Choose the right GDT_ENTRY_CPUNODE for 32-bit getcpu() on 64-bit kernel

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

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

Commit-ID:     39163d5479285a36522b6e8f9cc568cc4987db08
Gitweb:        https://git.kernel.org/tip/39163d5479285a36522b6e8f9cc568cc4987db08
Author:        Xin Li <[email protected]>
AuthorDate:    Tue, 21 Mar 2023 23:17:58 -07:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Tue, 08 Aug 2023 09:31:43 +02:00

x86/vdso: Choose the right GDT_ENTRY_CPUNODE for 32-bit getcpu() on 64-bit kernel

The vDSO getcpu() reads CPU ID from the GDT_ENTRY_CPUNODE entry when the RDPID instruction is not available. And GDT_ENTRY_CPUNODE is defined as 28 on 32-bit Linux kernel and 15 on 64-bit. But the 32-bit getcpu() on 64-bit Linux kernel is compiled with 32-bit Linux kernel GDT_ENTRY_CPUNODE, i.e., 28, beyond the 64-bit Linux kernel GDT limit. Thus, it just fails _silently_.

When BUILD_VDSO32_64 is defined, choose the 64-bit Linux kernel GDT definitions to compile the 32-bit getcpu().

---
 arch/x86/include/asm/segment.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/segment.h +1 -1
index 794f696..9d6411c 100644
@@ -56,7 +56,7 @@
 
 #define GDT_ENTRY_INVALID_SEG	0
 
-#ifdef CONFIG_X86_32
+#if defined(CONFIG_X86_32) && !defined(BUILD_VDSO32_64)
 /*
  * The layout of the per-CPU GDT under Linux:
  *