x86/cpu: Provide the full setup for getcpu() on x86-32
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Fri, 25 Nov 2022 09:42:14 +0000 (10:42 +0100)
committerThomas Gleixner <tglx@linutronix.de>
Mon, 6 Feb 2023 14:48:54 +0000 (15:48 +0100)
setup_getcpu() configures two things:

  - it writes the current CPU & node information into MSR_TSC_AUX
  - it writes the same information as a GDT entry.

By using the "full" setup_getcpu() on i386 it is possible to read the CPU
information in userland via RDTSCP() or via LSL from the GDT.

Provide an GDT_ENTRY_CPUNODE for x86-32 and make the setup function
unconditionally available.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Roland Mainz <roland.mainz@nrubsig.org>
Link: https://lore.kernel.org/r/20221125094216.3663444-2-bigeasy@linutronix.de
arch/x86/include/asm/segment.h
arch/x86/kernel/cpu/common.c

index c390a67..794f696 100644 (file)
@@ -96,7 +96,7 @@
  *
  *  26 - ESPFIX small SS
  *  27 - per-cpu                       [ offset to per-cpu data area ]
- *  28 - unused
+ *  28 - VDSO getcpu
  *  29 - unused
  *  30 - unused
  *  31 - TSS for double fault handler
 
 #define GDT_ENTRY_ESPFIX_SS            26
 #define GDT_ENTRY_PERCPU               27
+#define GDT_ENTRY_CPUNODE              28
 
 #define GDT_ENTRY_DOUBLEFAULT_TSS      31
 
 # define __KERNEL_PERCPU               0
 #endif
 
+#define __CPUNODE_SEG                  (GDT_ENTRY_CPUNODE*8 + 3)
+
 #else /* 64-bit: */
 
 #include <asm/cache.h>
 #define GDT_ENTRY_TLS_ENTRIES          3
 #define TLS_SIZE                       (GDT_ENTRY_TLS_ENTRIES* 8)
 
-#ifdef CONFIG_X86_64
-
 /* Bit size and mask of CPU number stored in the per CPU data (and TSC_AUX) */
 #define VDSO_CPUNODE_BITS              12
 #define VDSO_CPUNODE_MASK              0xfff
@@ -265,7 +266,6 @@ static inline void vdso_read_cpunode(unsigned *cpu, unsigned *node)
 }
 
 #endif /* !__ASSEMBLY__ */
-#endif /* CONFIG_X86_64 */
 
 #ifdef __KERNEL__
 
index 3a9043e..a26ce20 100644 (file)
@@ -2124,7 +2124,6 @@ static void wait_for_master_cpu(int cpu)
 #endif
 }
 
-#ifdef CONFIG_X86_64
 static inline void setup_getcpu(int cpu)
 {
        unsigned long cpudata = vdso_encode_cpunode(cpu, early_cpu_to_node(cpu));
@@ -2146,6 +2145,7 @@ static inline void setup_getcpu(int cpu)
        write_gdt_entry(get_cpu_gdt_rw(cpu), GDT_ENTRY_CPUNODE, &d, DESCTYPE_S);
 }
 
+#ifdef CONFIG_X86_64
 static inline void ucode_cpu_init(int cpu)
 {
        if (cpu)
@@ -2165,8 +2165,6 @@ static inline void tss_setup_ist(struct tss_struct *tss)
 
 #else /* CONFIG_X86_64 */
 
-static inline void setup_getcpu(int cpu) { }
-
 static inline void ucode_cpu_init(int cpu)
 {
        show_ucode_info_early();