Skip to content

Commit a0abcf2

Browse files
committed
Merge branch 'x86/vdso' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip into next
Pull x86 cdso updates from Peter Anvin: "Vdso cleanups and improvements largely from Andy Lutomirski. This makes the vdso a lot less ''special''" * 'x86/vdso' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/vdso, build: Make LE access macros clearer, host-safe x86/vdso, build: Fix cross-compilation from big-endian architectures x86/vdso, build: When vdso2c fails, unlink the output x86, vdso: Fix an OOPS accessing the HPET mapping w/o an HPET x86, mm: Replace arch_vma_name with vm_ops->name for vsyscalls x86, mm: Improve _install_special_mapping and fix x86 vdso naming mm, fs: Add vm_ops->name as an alternative to arch_vma_name x86, vdso: Fix an OOPS accessing the HPET mapping w/o an HPET x86, vdso: Remove vestiges of VDSO_PRELINK and some outdated comments x86, vdso: Move the vvar and hpet mappings next to the 64-bit vDSO x86, vdso: Move the 32-bit vdso special pages after the text x86, vdso: Reimplement vdso.so preparation in build-time C x86, vdso: Move syscall and sysenter setup into kernel/cpu/common.c x86, vdso: Clean up 32-bit vs 64-bit vdso params x86, mm: Ensure correct alignment of the fixmap
2 parents 2071b3e + c191920 commit a0abcf2

40 files changed

Lines changed: 794 additions & 608 deletions

‎arch/x86/ia32/ia32_signal.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,8 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
383383
} else {
384384
/* Return stub is in 32bit vsyscall page */
385385
if (current->mm->context.vdso)
386-
restorer = VDSO32_SYMBOL(current->mm->context.vdso,
387-
sigreturn);
386+
restorer = current->mm->context.vdso +
387+
selected_vdso32->sym___kernel_sigreturn;
388388
else
389389
restorer = &frame->retcode;
390390
}
@@ -462,8 +462,8 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
462462
if (ksig->ka.sa.sa_flags & SA_RESTORER)
463463
restorer = ksig->ka.sa.sa_restorer;
464464
else
465-
restorer = VDSO32_SYMBOL(current->mm->context.vdso,
466-
rt_sigreturn);
465+
restorer = current->mm->context.vdso +
466+
selected_vdso32->sym___kernel_rt_sigreturn;
467467
put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
468468

469469
/*

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ typedef struct user_fxsr_struct elf_fpxregset_t;
7575

7676
#include <asm/vdso.h>
7777

78-
extern unsigned int vdso_enabled;
78+
#ifdef CONFIG_X86_64
79+
extern unsigned int vdso64_enabled;
80+
#endif
81+
#if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT)
82+
extern unsigned int vdso32_enabled;
83+
#endif
7984

8085
/*
8186
* This is used to ensure we don't load something for the wrong architecture.
@@ -269,9 +274,9 @@ extern int force_personality32;
269274

270275
struct task_struct;
271276

272-
#define ARCH_DLINFO_IA32(vdso_enabled) \
277+
#define ARCH_DLINFO_IA32 \
273278
do { \
274-
if (vdso_enabled) { \
279+
if (vdso32_enabled) { \
275280
NEW_AUX_ENT(AT_SYSINFO, VDSO_ENTRY); \
276281
NEW_AUX_ENT(AT_SYSINFO_EHDR, VDSO_CURRENT_BASE); \
277282
} \
@@ -281,7 +286,7 @@ do { \
281286

282287
#define STACK_RND_MASK (0x7ff)
283288

284-
#define ARCH_DLINFO ARCH_DLINFO_IA32(vdso_enabled)
289+
#define ARCH_DLINFO ARCH_DLINFO_IA32
285290

286291
/* update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes */
287292

@@ -292,16 +297,17 @@ do { \
292297

293298
#define ARCH_DLINFO \
294299
do { \
295-
if (vdso_enabled) \
300+
if (vdso64_enabled) \
296301
NEW_AUX_ENT(AT_SYSINFO_EHDR, \
297-
(unsigned long)current->mm->context.vdso); \
302+
(unsigned long __force)current->mm->context.vdso); \
298303
} while (0)
299304

305+
/* As a historical oddity, the x32 and x86_64 vDSOs are controlled together. */
300306
#define ARCH_DLINFO_X32 \
301307
do { \
302-
if (vdso_enabled) \
308+
if (vdso64_enabled) \
303309
NEW_AUX_ENT(AT_SYSINFO_EHDR, \
304-
(unsigned long)current->mm->context.vdso); \
310+
(unsigned long __force)current->mm->context.vdso); \
305311
} while (0)
306312

307313
#define AT_SYSINFO 32
@@ -310,7 +316,7 @@ do { \
310316
if (test_thread_flag(TIF_X32)) \
311317
ARCH_DLINFO_X32; \
312318
else \
313-
ARCH_DLINFO_IA32(sysctl_vsyscall32)
319+
ARCH_DLINFO_IA32
314320

315321
#define COMPAT_ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
316322

@@ -319,18 +325,17 @@ else \
319325
#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
320326

321327
#define VDSO_ENTRY \
322-
((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
328+
((unsigned long)current->mm->context.vdso + \
329+
selected_vdso32->sym___kernel_vsyscall)
323330

324331
struct linux_binprm;
325332

326333
#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
327334
extern int arch_setup_additional_pages(struct linux_binprm *bprm,
328335
int uses_interp);
329-
extern int x32_setup_additional_pages(struct linux_binprm *bprm,
330-
int uses_interp);
331-
332-
extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
333-
#define compat_arch_setup_additional_pages syscall32_setup_pages
336+
extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
337+
int uses_interp);
338+
#define compat_arch_setup_additional_pages compat_arch_setup_additional_pages
334339

335340
extern unsigned long arch_randomize_brk(struct mm_struct *mm);
336341
#define arch_randomize_brk arch_randomize_brk

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include <linux/threads.h>
2525
#include <asm/kmap_types.h>
2626
#else
27-
#include <asm/vsyscall.h>
27+
#include <uapi/asm/vsyscall.h>
2828
#endif
2929

3030
/*
@@ -41,7 +41,8 @@
4141
extern unsigned long __FIXADDR_TOP;
4242
#define FIXADDR_TOP ((unsigned long)__FIXADDR_TOP)
4343
#else
44-
#define FIXADDR_TOP (VSYSCALL_END-PAGE_SIZE)
44+
#define FIXADDR_TOP (round_up(VSYSCALL_ADDR + PAGE_SIZE, 1<<PMD_SHIFT) - \
45+
PAGE_SIZE)
4546
#endif
4647

4748

@@ -68,11 +69,7 @@ enum fixed_addresses {
6869
#ifdef CONFIG_X86_32
6970
FIX_HOLE,
7071
#else
71-
VSYSCALL_LAST_PAGE,
72-
VSYSCALL_FIRST_PAGE = VSYSCALL_LAST_PAGE
73-
+ ((VSYSCALL_END-VSYSCALL_START) >> PAGE_SHIFT) - 1,
74-
VVAR_PAGE,
75-
VSYSCALL_HPET,
72+
VSYSCALL_PAGE = (FIXADDR_TOP - VSYSCALL_ADDR) >> PAGE_SHIFT,
7673
#ifdef CONFIG_PARAVIRT_CLOCK
7774
PVCLOCK_FIXMAP_BEGIN,
7875
PVCLOCK_FIXMAP_END = PVCLOCK_FIXMAP_BEGIN+PVCLOCK_VSYSCALL_NR_PAGES-1,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ typedef struct {
1818
#endif
1919

2020
struct mutex lock;
21-
void *vdso;
21+
void __user *vdso;
2222
} mm_context_t;
2323

2424
#ifdef CONFIG_SMP

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ void ia32_syscall(void);
1212
void ia32_cstar_target(void);
1313
void ia32_sysenter_target(void);
1414

15-
void syscall32_cpu_init(void);
16-
1715
void x86_configure_nx(void);
1816
void x86_report_nx(void);
1917

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

Lines changed: 33 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,63 +3,51 @@
33

44
#include <asm/page_types.h>
55
#include <linux/linkage.h>
6+
#include <linux/init.h>
67

7-
#ifdef __ASSEMBLER__
8+
#ifndef __ASSEMBLER__
89

9-
#define DEFINE_VDSO_IMAGE(symname, filename) \
10-
__PAGE_ALIGNED_DATA ; \
11-
.globl symname##_start, symname##_end ; \
12-
.align PAGE_SIZE ; \
13-
symname##_start: ; \
14-
.incbin filename ; \
15-
symname##_end: ; \
16-
.align PAGE_SIZE /* extra data here leaks to userspace. */ ; \
17-
\
18-
.previous ; \
19-
\
20-
.globl symname##_pages ; \
21-
.bss ; \
22-
.align 8 ; \
23-
.type symname##_pages, @object ; \
24-
symname##_pages: ; \
25-
.zero (symname##_end - symname##_start + PAGE_SIZE - 1) / PAGE_SIZE * (BITS_PER_LONG / 8) ; \
26-
.size symname##_pages, .-symname##_pages
10+
#include <linux/mm_types.h>
2711

28-
#else
12+
struct vdso_image {
13+
void *data;
14+
unsigned long size; /* Always a multiple of PAGE_SIZE */
2915

30-
#define DECLARE_VDSO_IMAGE(symname) \
31-
extern char symname##_start[], symname##_end[]; \
32-
extern struct page *symname##_pages[]
16+
/* text_mapping.pages is big enough for data/size page pointers */
17+
struct vm_special_mapping text_mapping;
3318

34-
#if defined CONFIG_X86_32 || defined CONFIG_COMPAT
19+
unsigned long alt, alt_len;
3520

36-
#include <asm/vdso32.h>
21+
unsigned long sym_end_mapping; /* Total size of the mapping */
3722

38-
DECLARE_VDSO_IMAGE(vdso32_int80);
39-
#ifdef CONFIG_COMPAT
40-
DECLARE_VDSO_IMAGE(vdso32_syscall);
23+
unsigned long sym_vvar_page;
24+
unsigned long sym_hpet_page;
25+
unsigned long sym_VDSO32_NOTE_MASK;
26+
unsigned long sym___kernel_sigreturn;
27+
unsigned long sym___kernel_rt_sigreturn;
28+
unsigned long sym___kernel_vsyscall;
29+
unsigned long sym_VDSO32_SYSENTER_RETURN;
30+
};
31+
32+
#ifdef CONFIG_X86_64
33+
extern const struct vdso_image vdso_image_64;
34+
#endif
35+
36+
#ifdef CONFIG_X86_X32
37+
extern const struct vdso_image vdso_image_x32;
4138
#endif
42-
DECLARE_VDSO_IMAGE(vdso32_sysenter);
4339

44-
/*
45-
* Given a pointer to the vDSO image, find the pointer to VDSO32_name
46-
* as that symbol is defined in the vDSO sources or linker script.
47-
*/
48-
#define VDSO32_SYMBOL(base, name) \
49-
({ \
50-
extern const char VDSO32_##name[]; \
51-
(void __user *)(VDSO32_##name + (unsigned long)(base)); \
52-
})
40+
#if defined CONFIG_X86_32 || defined CONFIG_COMPAT
41+
extern const struct vdso_image vdso_image_32_int80;
42+
#ifdef CONFIG_COMPAT
43+
extern const struct vdso_image vdso_image_32_syscall;
5344
#endif
45+
extern const struct vdso_image vdso_image_32_sysenter;
5446

55-
/*
56-
* These symbols are defined with the addresses in the vsyscall page.
57-
* See vsyscall-sigreturn.S.
58-
*/
59-
extern void __user __kernel_sigreturn;
60-
extern void __user __kernel_rt_sigreturn;
47+
extern const struct vdso_image *selected_vdso32;
48+
#endif
6149

62-
void __init patch_vdso32(void *vdso, size_t len);
50+
extern void __init init_vdso_image(const struct vdso_image *image);
6351

6452
#endif /* __ASSEMBLER__ */
6553

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

Lines changed: 0 additions & 11 deletions
This file was deleted.

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

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,13 @@
2929

3030
#else
3131

32-
#ifdef BUILD_VDSO32
32+
extern char __vvar_page;
3333

3434
#define DECLARE_VVAR(offset, type, name) \
3535
extern type vvar_ ## name __attribute__((visibility("hidden")));
3636

3737
#define VVAR(name) (vvar_ ## name)
3838

39-
#else
40-
41-
extern char __vvar_page;
42-
43-
/* Base address of vvars. This is not ABI. */
44-
#ifdef CONFIG_X86_64
45-
#define VVAR_ADDRESS (-10*1024*1024 - 4096)
46-
#else
47-
#define VVAR_ADDRESS (&__vvar_page)
48-
#endif
49-
50-
#define DECLARE_VVAR(offset, type, name) \
51-
static type const * const vvaraddr_ ## name = \
52-
(void *)(VVAR_ADDRESS + (offset));
53-
54-
#define VVAR(name) (*vvaraddr_ ## name)
55-
#endif
56-
5739
#define DEFINE_VVAR(type, name) \
5840
type name \
5941
__attribute__((section(".vvar_" #name), aligned(16))) __visible

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ enum vsyscall_num {
77
__NR_vgetcpu,
88
};
99

10-
#define VSYSCALL_START (-10UL << 20)
11-
#define VSYSCALL_SIZE 1024
12-
#define VSYSCALL_END (-2UL << 20)
13-
#define VSYSCALL_MAPPED_PAGES 1
14-
#define VSYSCALL_ADDR(vsyscall_nr) (VSYSCALL_START+VSYSCALL_SIZE*(vsyscall_nr))
15-
10+
#define VSYSCALL_ADDR (-10UL << 20)
1611

1712
#endif /* _UAPI_ASM_X86_VSYSCALL_H */

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <asm/processor.h>
2121
#include <asm/debugreg.h>
2222
#include <asm/sections.h>
23+
#include <asm/vsyscall.h>
2324
#include <linux/topology.h>
2425
#include <linux/cpumask.h>
2526
#include <asm/pgtable.h>
@@ -953,6 +954,38 @@ static void vgetcpu_set_mode(void)
953954
else
954955
vgetcpu_mode = VGETCPU_LSL;
955956
}
957+
958+
/* May not be __init: called during resume */
959+
static void syscall32_cpu_init(void)
960+
{
961+
/* Load these always in case some future AMD CPU supports
962+
SYSENTER from compat mode too. */
963+
wrmsrl_safe(MSR_IA32_SYSENTER_CS, (u64)__KERNEL_CS);
964+
wrmsrl_safe(MSR_IA32_SYSENTER_ESP, 0ULL);
965+
wrmsrl_safe(MSR_IA32_SYSENTER_EIP, (u64)ia32_sysenter_target);
966+
967+
wrmsrl(MSR_CSTAR, ia32_cstar_target);
968+
}
969+
#endif
970+
971+
#ifdef CONFIG_X86_32
972+
void enable_sep_cpu(void)
973+
{
974+
int cpu = get_cpu();
975+
struct tss_struct *tss = &per_cpu(init_tss, cpu);
976+
977+
if (!boot_cpu_has(X86_FEATURE_SEP)) {
978+
put_cpu();
979+
return;
980+
}
981+
982+
tss->x86_tss.ss1 = __KERNEL_CS;
983+
tss->x86_tss.sp1 = sizeof(struct tss_struct) + (unsigned long) tss;
984+
wrmsr(MSR_IA32_SYSENTER_CS, __KERNEL_CS, 0);
985+
wrmsr(MSR_IA32_SYSENTER_ESP, tss->x86_tss.sp1, 0);
986+
wrmsr(MSR_IA32_SYSENTER_EIP, (unsigned long) ia32_sysenter_target, 0);
987+
put_cpu();
988+
}
956989
#endif
957990

958991
void __init identify_boot_cpu(void)

0 commit comments

Comments
 (0)