Skip to content

Commit 1ad83c8

Browse files
amlutoKAGA-KOKO
authored andcommitted
x86_64,vsyscall: Make vsyscall emulation configurable
This adds CONFIG_X86_VSYSCALL_EMULATION, guarded by CONFIG_EXPERT. Turning it off completely disables vsyscall emulation, saving ~3.5k for vsyscall_64.c, 4k for vsyscall_emu_64.S (the fake vsyscall page), some tiny amount of core mm code that supports a gate area, and possibly 4k for a wasted pagetable. The latter is because the vsyscall addresses are misaligned and fit poorly in the fixmap. Signed-off-by: Andy Lutomirski <luto@amacapital.net> Reviewed-by: Josh Triplett <josh@joshtriplett.org> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Link: http://lkml.kernel.org/r/406db88b8dd5f0cbbf38216d11be34bbb43c7eae.1414618407.git.luto@amacapital.net Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent 95c46b5 commit 1ad83c8

File tree

7 files changed

+36
-7
lines changed

7 files changed

+36
-7
lines changed

arch/x86/Kconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,24 @@ config X86_ESPFIX64
984984
def_bool y
985985
depends on X86_16BIT && X86_64
986986

987+
config X86_VSYSCALL_EMULATION
988+
bool "Enable vsyscall emulation" if EXPERT
989+
default y
990+
depends on X86_64
991+
---help---
992+
This enables emulation of the legacy vsyscall page. Disabling
993+
it is roughly equivalent to booting with vsyscall=none, except
994+
that it will also disable the helpful warning if a program
995+
tries to use a vsyscall. With this option set to N, offending
996+
programs will just segfault, citing addresses of the form
997+
0xffffffffff600?00.
998+
999+
This option is required by many programs built before 2013, and
1000+
care should be used even with newer programs if set to N.
1001+
1002+
Disabling this option saves about 7K of kernel size and
1003+
possibly 4K of additional runtime pagetable memory.
1004+
9871005
config TOSHIBA
9881006
tristate "Toshiba Laptop support"
9891007
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/vsyscall.h

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

7+
#ifdef CONFIG_X86_VSYSCALL_EMULATION
78
extern void map_vsyscall(void);
89

910
/*
1011
* Called on instruction fetch fault in vsyscall page.
1112
* Returns true if handled.
1213
*/
1314
extern bool emulate_vsyscall(struct pt_regs *regs, unsigned long address);
15+
#else
16+
static inline void map_vsyscall(void) {}
17+
static inline bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
18+
{
19+
return false;
20+
}
21+
#endif
1422

1523
#endif /* _ASM_X86_VSYSCALL_H */

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/setup.c

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

11911191
tboot_probe();
11921192

1193-
#ifdef CONFIG_X86_64
11941193
map_vsyscall();
1195-
#endif
11961194

11971195
generic_apic_probe();
11981196

arch/x86/xen/mmu.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,8 +1457,10 @@ static int xen_pgd_alloc(struct mm_struct *mm)
14571457
page->private = (unsigned long)user_pgd;
14581458

14591459
if (user_pgd != NULL) {
1460+
#ifdef CONFIG_X86_VSYSCALL_EMULATION
14601461
user_pgd[pgd_index(VSYSCALL_ADDR)] =
14611462
__pgd(__pa(level3_user_vsyscall) | _PAGE_TABLE);
1463+
#endif
14621464
ret = 0;
14631465
}
14641466

@@ -2021,7 +2023,7 @@ static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot)
20212023
# ifdef CONFIG_HIGHMEM
20222024
case FIX_KMAP_BEGIN ... FIX_KMAP_END:
20232025
# endif
2024-
#else
2026+
#elif defined(CONFIG_X86_VSYSCALL_EMULATION)
20252027
case VSYSCALL_PAGE:
20262028
#endif
20272029
case FIX_TEXT_POKE0:
@@ -2060,7 +2062,7 @@ static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot)
20602062

20612063
__native_set_fixmap(idx, pte);
20622064

2063-
#ifdef CONFIG_X86_64
2065+
#ifdef CONFIG_X86_VSYSCALL_EMULATION
20642066
/* Replicate changes to map the vsyscall page into the user
20652067
pagetable vsyscall mapping. */
20662068
if (idx == VSYSCALL_PAGE) {

0 commit comments

Comments
 (0)