Skip to content

Commit 3100e44

Browse files
committed
Merge branch 'x86-vdso-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 vdso updates from Ingo Molnar: "Various vDSO updates from Andy Lutomirski, mostly cleanups and reorganization to improve maintainability, but also some micro-optimizations and robustization changes" * 'x86-vdso-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86_64/vsyscall: Restore orig_ax after vsyscall seccomp x86_64: Add a comment explaining the TASK_SIZE_MAX guard page x86_64,vsyscall: Make vsyscall emulation configurable x86_64, vsyscall: Rewrite comment and clean up headers in vsyscall code x86_64, vsyscall: Turn vsyscalls all the way off when vsyscall==none x86,vdso: Use LSL unconditionally for vgetcpu x86: vdso: Fix build with older gcc x86_64/vdso: Clean up vgetcpu init and merge the vdso initcalls x86_64/vdso: Remove jiffies from the vvar page x86/vdso: Make the PER_CPU segment 32 bits x86/vdso: Make the PER_CPU segment start out accessed x86/vdso: Change the PER_CPU segment to use struct desc_struct x86_64/vdso: Move getcpu code from vsyscall_64.c to vdso/vma.c x86_64/vsyscall: Move all of the gate_area code to vsyscall_64.c
2 parents c9f861c + 2689310 commit 3100e44

16 files changed

Lines changed: 190 additions & 200 deletions

File tree

‎arch/x86/Kconfig‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,24 @@ config X86_ESPFIX64
992992
def_bool y
993993
depends on X86_16BIT && X86_64
994994

995+
config X86_VSYSCALL_EMULATION
996+
bool "Enable vsyscall emulation" if EXPERT
997+
default y
998+
depends on X86_64
999+
---help---
1000+
This enables emulation of the legacy vsyscall page. Disabling
1001+
it is roughly equivalent to booting with vsyscall=none, except
1002+
that it will also disable the helpful warning if a program
1003+
tries to use a vsyscall. With this option set to N, offending
1004+
programs will just segfault, citing addresses of the form
1005+
0xffffffffff600?00.
1006+
1007+
This option is required by many programs built before 2013, and
1008+
care should be used even with newer programs if set to N.
1009+
1010+
Disabling this option saves about 7K of kernel size and
1011+
possibly 4K of additional runtime pagetable memory.
1012+
9951013
config TOSHIBA
9961014
tristate "Toshiba Laptop support"
9971015
depends on X86_32

‎arch/x86/include/asm/fixmap.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ enum fixed_addresses {
6969
#ifdef CONFIG_X86_32
7070
FIX_HOLE,
7171
#else
72+
#ifdef CONFIG_X86_VSYSCALL_EMULATION
7273
VSYSCALL_PAGE = (FIXADDR_TOP - VSYSCALL_ADDR) >> PAGE_SHIFT,
74+
#endif
7375
#ifdef CONFIG_PARAVIRT_CLOCK
7476
PVCLOCK_FIXMAP_BEGIN,
7577
PVCLOCK_FIXMAP_END = PVCLOCK_FIXMAP_BEGIN+PVCLOCK_VSYSCALL_NR_PAGES-1,

‎arch/x86/include/asm/page_64.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ void copy_page(void *to, void *from);
3939

4040
#endif /* !__ASSEMBLY__ */
4141

42-
#define __HAVE_ARCH_GATE_AREA 1
42+
#ifdef CONFIG_X86_VSYSCALL_EMULATION
43+
# define __HAVE_ARCH_GATE_AREA 1
44+
#endif
4345

4446
#endif /* _ASM_X86_PAGE_64_H */

‎arch/x86/include/asm/processor.h‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
894894

895895
#else
896896
/*
897-
* User space process size. 47bits minus one guard page.
897+
* User space process size. 47bits minus one guard page. The guard
898+
* page is necessary on Intel CPUs: if a SYSCALL instruction is at
899+
* the highest possible canonical userspace address, then that
900+
* syscall will enter the kernel with a non-canonical return
901+
* address, and SYSRET will explode dangerously. We avoid this
902+
* particular problem by preventing anything from being mapped
903+
* at the maximum canonical address.
898904
*/
899905
#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
900906

‎arch/x86/include/asm/vgtod.h‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,23 @@ static inline void gtod_write_end(struct vsyscall_gtod_data *s)
7070
++s->seq;
7171
}
7272

73+
#ifdef CONFIG_X86_64
74+
75+
#define VGETCPU_CPU_MASK 0xfff
76+
77+
static inline unsigned int __getcpu(void)
78+
{
79+
unsigned int p;
80+
81+
/*
82+
* Load per CPU data from GDT. LSL is faster than RDTSCP and
83+
* works on all CPUs.
84+
*/
85+
asm("lsl %1,%0" : "=r" (p) : "r" (__PER_CPU_SEG));
86+
87+
return p;
88+
}
89+
90+
#endif /* CONFIG_X86_64 */
91+
7392
#endif /* _ASM_X86_VGTOD_H */

‎arch/x86/include/asm/vsyscall.h‎

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,20 @@
44
#include <linux/seqlock.h>
55
#include <uapi/asm/vsyscall.h>
66

7-
#define VGETCPU_RDTSCP 1
8-
#define VGETCPU_LSL 2
9-
10-
/* kernel space (writeable) */
11-
extern int vgetcpu_mode;
12-
extern struct timezone sys_tz;
13-
14-
#include <asm/vvar.h>
15-
7+
#ifdef CONFIG_X86_VSYSCALL_EMULATION
168
extern void map_vsyscall(void);
179

1810
/*
1911
* Called on instruction fetch fault in vsyscall page.
2012
* Returns true if handled.
2113
*/
2214
extern bool emulate_vsyscall(struct pt_regs *regs, unsigned long address);
23-
24-
#ifdef CONFIG_X86_64
25-
26-
#define VGETCPU_CPU_MASK 0xfff
27-
28-
static inline unsigned int __getcpu(void)
15+
#else
16+
static inline void map_vsyscall(void) {}
17+
static inline bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
2918
{
30-
unsigned int p;
31-
32-
if (VVAR(vgetcpu_mode) == VGETCPU_RDTSCP) {
33-
/* Load per CPU data from RDTSCP */
34-
native_read_tscp(&p);
35-
} else {
36-
/* Load per CPU data from GDT */
37-
asm("lsl %1,%0" : "=r" (p) : "r" (__PER_CPU_SEG));
38-
}
39-
40-
return p;
19+
return false;
4120
}
42-
#endif /* CONFIG_X86_64 */
21+
#endif
4322

4423
#endif /* _ASM_X86_VSYSCALL_H */

‎arch/x86/include/asm/vvar.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ extern char __vvar_page;
4444

4545
/* DECLARE_VVAR(offset, type, name) */
4646

47-
DECLARE_VVAR(0, volatile unsigned long, jiffies)
48-
DECLARE_VVAR(16, int, vgetcpu_mode)
4947
DECLARE_VVAR(128, struct vsyscall_gtod_data, vsyscall_gtod_data)
5048

5149
#undef DECLARE_VVAR

‎arch/x86/kernel/Makefile‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ obj-$(CONFIG_X86_32) += i386_ksyms_32.o
2828
obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
2929
obj-$(CONFIG_X86_64) += mcount_64.o
3030
obj-y += syscall_$(BITS).o vsyscall_gtod.o
31-
obj-$(CONFIG_X86_64) += vsyscall_64.o
32-
obj-$(CONFIG_X86_64) += vsyscall_emu_64.o
31+
obj-$(CONFIG_X86_VSYSCALL_EMULATION) += vsyscall_64.o vsyscall_emu_64.o
3332
obj-$(CONFIG_X86_ESPFIX64) += espfix_64.o
3433
obj-$(CONFIG_SYSFS) += ksysfs.o
3534
obj-y += bootflag.o e820.o

‎arch/x86/kernel/cpu/common.c‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -958,14 +958,6 @@ static void identify_cpu(struct cpuinfo_x86 *c)
958958
}
959959

960960
#ifdef CONFIG_X86_64
961-
static void vgetcpu_set_mode(void)
962-
{
963-
if (cpu_has(&boot_cpu_data, X86_FEATURE_RDTSCP))
964-
vgetcpu_mode = VGETCPU_RDTSCP;
965-
else
966-
vgetcpu_mode = VGETCPU_LSL;
967-
}
968-
969961
#ifdef CONFIG_IA32_EMULATION
970962
/* May not be __init: called during resume */
971963
static void syscall32_cpu_init(void)
@@ -1008,8 +1000,6 @@ void __init identify_boot_cpu(void)
10081000
#ifdef CONFIG_X86_32
10091001
sysenter_setup();
10101002
enable_sep_cpu();
1011-
#else
1012-
vgetcpu_set_mode();
10131003
#endif
10141004
cpu_detect_tlb(&boot_cpu_data);
10151005
}

‎arch/x86/kernel/setup.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,9 +1192,7 @@ void __init setup_arch(char **cmdline_p)
11921192

11931193
tboot_probe();
11941194

1195-
#ifdef CONFIG_X86_64
11961195
map_vsyscall();
1197-
#endif
11981196

11991197
generic_apic_probe();
12001198

0 commit comments

Comments
 (0)