Skip to content

Commit 717cce3

Browse files
Sebastian Andrzej SiewiorKAGA-KOKO
authored andcommitted
x86/cpu: Provide the full setup for getcpu() on x86-32
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 <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Roland Mainz <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 4c382d7 commit 717cce3

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

arch/x86/include/asm/segment.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
*
9797
* 26 - ESPFIX small SS
9898
* 27 - per-cpu [ offset to per-cpu data area ]
99-
* 28 - unused
99+
* 28 - VDSO getcpu
100100
* 29 - unused
101101
* 30 - unused
102102
* 31 - TSS for double fault handler
@@ -119,6 +119,7 @@
119119

120120
#define GDT_ENTRY_ESPFIX_SS 26
121121
#define GDT_ENTRY_PERCPU 27
122+
#define GDT_ENTRY_CPUNODE 28
122123

123124
#define GDT_ENTRY_DOUBLEFAULT_TSS 31
124125

@@ -159,6 +160,8 @@
159160
# define __KERNEL_PERCPU 0
160161
#endif
161162

163+
#define __CPUNODE_SEG (GDT_ENTRY_CPUNODE*8 + 3)
164+
162165
#else /* 64-bit: */
163166

164167
#include <asm/cache.h>
@@ -226,8 +229,6 @@
226229
#define GDT_ENTRY_TLS_ENTRIES 3
227230
#define TLS_SIZE (GDT_ENTRY_TLS_ENTRIES* 8)
228231

229-
#ifdef CONFIG_X86_64
230-
231232
/* Bit size and mask of CPU number stored in the per CPU data (and TSC_AUX) */
232233
#define VDSO_CPUNODE_BITS 12
233234
#define VDSO_CPUNODE_MASK 0xfff
@@ -265,7 +266,6 @@ static inline void vdso_read_cpunode(unsigned *cpu, unsigned *node)
265266
}
266267

267268
#endif /* !__ASSEMBLY__ */
268-
#endif /* CONFIG_X86_64 */
269269

270270
#ifdef __KERNEL__
271271

arch/x86/kernel/cpu/common.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,7 +2124,6 @@ static void wait_for_master_cpu(int cpu)
21242124
#endif
21252125
}
21262126

2127-
#ifdef CONFIG_X86_64
21282127
static inline void setup_getcpu(int cpu)
21292128
{
21302129
unsigned long cpudata = vdso_encode_cpunode(cpu, early_cpu_to_node(cpu));
@@ -2146,6 +2145,7 @@ static inline void setup_getcpu(int cpu)
21462145
write_gdt_entry(get_cpu_gdt_rw(cpu), GDT_ENTRY_CPUNODE, &d, DESCTYPE_S);
21472146
}
21482147

2148+
#ifdef CONFIG_X86_64
21492149
static inline void ucode_cpu_init(int cpu)
21502150
{
21512151
if (cpu)
@@ -2165,8 +2165,6 @@ static inline void tss_setup_ist(struct tss_struct *tss)
21652165

21662166
#else /* CONFIG_X86_64 */
21672167

2168-
static inline void setup_getcpu(int cpu) { }
2169-
21702168
static inline void ucode_cpu_init(int cpu)
21712169
{
21722170
show_ucode_info_early();

0 commit comments

Comments
 (0)