x86 and others: vsyscall and vdso cleanups
Subsystems (14)
v2 cover x86 and others: vsyscall and vdso cleanups
This is v2. I'm resending it because the fallout from the 3.16 changes seems to have settled down, and because arm is about to run in to the same problem that I ran in to, which is fixed in the big cross-arch patch.
Patch 1 fixes a minor bug; it might make sense to backport it.
Patch 3 removes the vsyscall mapping when vsyscall=none.
Patch 4 and 5 remove some unnecessary vvars. gtod is the only one left now.
Patch 9 is a big cross-arch cleanup. The old code was supposedly generic, but it was only useful for ia64, and it was actively harmful for lots of other architectures.
Patch 10 makes vsyscall emulation optional. It's hidden under CONFIG_EXPERT.
If this should be split or reordered, please let me know.
NB: I wouldn't be surprised if Nathan Lynch ends up wanting patch 9 for ARM's upcoming vdso, so it would be nice to get at least that patch into an upstream-pointing git tree somewhere. I'm not sure what the appropriate tree is.
Changes from v1:
- Rebased to 3.16-rc3.
- The last patch is new.
Andy Lutomirski (10):
x86_64,vsyscall: Fix warn_bad_vsyscall log output x86_64,vsyscall: Move all of the gate_area code to vsyscall_64.c x86_64,vsyscall: Turn vsyscalls all the way off when vsyscall=none x86_64,vdso: Remove jiffies from the vvar page
x86,vdso: Replace vgetcpu_mode with static_cpu_has
x86_64: Move getcpu code from vsyscall_64.c to vdso/vma.c x86_64,vsyscall: Rewrite comment and clean up headers in vsyscall code x86_64,vdso: Clean up vgetcpu init and merge the vdso initcalls arm64,ia64,ppc,s390,sh,tile,um,x86,mm: Remove default gate area x86_64,vsyscall: Make vsyscall emulation configurable
arch/arm64/include/asm/page.h | 3 - arch/arm64/kernel/vdso.c | 19 ----- arch/ia64/include/asm/page.h | 2 + arch/ia64/mm/init.c | 26 +++++++ arch/powerpc/include/asm/page.h | 3 - arch/powerpc/kernel/vdso.c | 16 ---- arch/s390/include/asm/page.h | 2 - arch/s390/kernel/vdso.c | 15 ---- arch/sh/include/asm/page.h | 5 -- arch/sh/kernel/vsyscall/vsyscall.c | 15 ---- arch/tile/include/asm/page.h | 6 -- arch/tile/kernel/vdso.c | 15 ---- arch/um/include/asm/page.h | 5 ++ arch/x86/Kconfig | 18 +++++ arch/x86/include/asm/fixmap.h | 2 + arch/x86/include/asm/page.h | 1 - arch/x86/include/asm/page_64.h | 4 + arch/x86/include/asm/vgtod.h | 21 +++++ arch/x86/include/asm/vsyscall.h | 33 ++------ arch/x86/include/asm/vvar.h | 2 - arch/x86/kernel/Makefile | 3 +- arch/x86/kernel/cpu/common.c | 10 --- arch/x86/kernel/setup.c | 2 - arch/x86/kernel/time.c | 2 +- arch/x86/kernel/vsyscall_64.c | 155 ++++++++++++++++--------------------- arch/x86/mm/init_64.c | 49 ------------ arch/x86/um/asm/elf.h | 1 - arch/x86/um/mem_64.c | 15 ---- arch/x86/vdso/vclock_gettime.c | 3 + arch/x86/vdso/vdso32-setup.c | 19 +---- arch/x86/vdso/vgetcpu.c | 5 +- arch/x86/vdso/vma.c | 81 ++++++++++++++----- arch/x86/xen/mmu.c | 6 +- include/linux/mm.h | 17 ++-- mm/memory.c | 38 --------- mm/nommu.c | 5 -- 36 files changed, 239 insertions(+), 385 deletions(-)
Signature · 1 line
1.9.3
PATCH v2 1/10 x86_64,vsyscall: Fix warn_bad_vsyscall log output
This commit in Linux 3.6:
commit c767a54ba0657e52e6edaa97cbe0b0a8bf1c1655
Author: Joe Perches <[email protected]>
Date: Mon May 21 19:50:07 2012 -0700
x86/debug: Add KERN_<LEVEL> to bare printks, convert printks to pr_<level>
caused warn_bad_vsyscall to output garbage in the middle of the line. Revert the bad part of it.
The printk in question isn't actually bare; the level is "%s".
The bug this fixes is purely cosmetic; backports are optional.
--- arch/x86/kernel/vsyscall_64.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/kernel/vsyscall_64.c +4 -4
@@ -81,10 +81,10 @@ static void warn_bad_vsyscall(const char *level, struct pt_regs *regs,if (!show_unhandled_signals)return ; -pr_notice_ratelimited ("%s%s[%d] %s ip:%lx cs:%lx sp:%lx ax:%lx si:%lx di:%lx\n" , - level, current->comm,task_pid_nr (current), - message, regs->ip, regs->cs, - regs->sp, regs->ax, regs->si, regs->di); +printk_ratelimited ("%s%s[%d] %s ip:%lx cs:%lx sp:%lx ax:%lx si:%lx di:%lx\n" , + level, current->comm,task_pid_nr (current), + message, regs->ip, regs->cs, + regs->sp, regs->ax, regs->si, regs->di); }static int addr_to_vsyscall_nr (unsigned long addr)
Signature · 1 line
1.9.3
PATCH v2 2/10 x86_64,vsyscall: Move all of the gate_area code to vsyscall_64.c
In reply to Andy LutomirskiThis code exists for the sole purpose of making the vsyscall page look sort of like real userspace memory. Move it so that it lives with the rest of the vsyscall code.
--- arch/x86/kernel/vsyscall_64.c | 49 +++++++++++++++++++++++++++++++++++++++++++ arch/x86/mm/init_64.c | 49 ------------------------------------------- 2 files changed, 49 insertions(+), 49 deletions(-)
arch/x86/kernel/vsyscall_64.c +49 -0
@@ -284,6 +284,55 @@ sigsegv: }/* +* A pseudo VMA to allow ptrace access for the vsyscall page. This only +* covers the 64bit vsyscall page now. 32bit has a real VMA now and does +* not need special handling anymore: +*/ +static const char *gate_vma_name (struct vm_area_struct *vma) +{ +return "[vsyscall]" ; +} +static struct vm_operations_struct gate_vma_ops = { + .name = gate_vma_name, +}; +static struct vm_area_struct gate_vma = { + .vm_start =VSYSCALL_ADDR , + .vm_end =VSYSCALL_ADDR +PAGE_SIZE , + .vm_page_prot =PAGE_READONLY_EXEC , + .vm_flags =VM_READ |VM_EXEC , + .vm_ops = &gate_vma_ops, +}; + +struct vm_area_struct *get_gate_vma (struct mm_struct *mm) +{ +#ifdef CONFIG_IA32_EMULATION +if (!mm || mm->context.ia32_compat) +return NULL ; +#endif +return &gate_vma; +} + +int in_gate_area (struct mm_struct *mm,unsigned long addr) +{ +struct vm_area_struct *vma =get_gate_vma (mm); + +if (!vma) +return 0 ; + +return (addr >= vma->vm_start) && (addr < vma->vm_end); +} + +/* +* Use this when you have no reliable mm, typically from interrupt +* context. It is less reliable than using a task's mm and may give +* false positives. +*/ +int in_gate_area_no_mm (unsigned long addr) +{ +return (addr &PAGE_MASK ) ==VSYSCALL_ADDR ; +} + +/* * Assume __initcall executes before all user space. Hopefully kmod * doesn't violate that. We'll find out if it does. */
arch/x86/mm/init_64.c +0 -49
55 lines not on this page · raw message
Signature · 1 line
1.9.3
PATCH v2 3/10 x86_64,vsyscall: Turn vsyscalls all the way off when vsyscall=none
In reply to Andy LutomirskiI see no point in having an unusable read-only page sitting at 0xffffffffff600000 when vsyscall=none. Instead, skip mapping it and remove it from /proc/PID/maps.
I kept the ratelimited warning when programs try to use a vsyscall in this mode, since it may help admins avoid confusion.
--- arch/x86/kernel/vsyscall_64.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
arch/x86/kernel/vsyscall_64.c +9 -5
@@ -309,6 +309,8 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)if (!mm || mm->context.ia32_compat)return NULL ;#endif +if (vsyscall_mode ==NONE ) +return NULL ;return &gate_vma; }
@@ -329,7 +331,7 @@ int in_gate_area(struct mm_struct *mm, unsigned long addr)*/ int in_gate_area_no_mm (unsigned long addr) { -return (addr &PAGE_MASK ) ==VSYSCALL_ADDR ; +return vsyscall_mode !=NONE && (addr &PAGE_MASK ) ==VSYSCALL_ADDR ; }/*
@@ -380,10 +382,12 @@ void __init map_vsyscall(void)extern char __vsyscall_page;unsigned long physaddr_vsyscall =__pa_symbol (&__vsyscall_page); -__set_fixmap (VSYSCALL_PAGE , physaddr_vsyscall, - vsyscall_mode ==NATIVE - ?PAGE_KERNEL_VSYSCALL - :PAGE_KERNEL_VVAR ); +if (vsyscall_mode !=NONE ) +__set_fixmap (VSYSCALL_PAGE , physaddr_vsyscall, + vsyscall_mode ==NATIVE + ?PAGE_KERNEL_VSYSCALL + :PAGE_KERNEL_VVAR ); +BUILD_BUG_ON ((unsigned long )__fix_to_virt (VSYSCALL_PAGE ) != (unsigned long )VSYSCALL_ADDR ); }
Signature · 1 line
1.9.3
PATCH v2 4/10 x86_64,vdso: Remove jiffies from the vvar page
In reply to Andy LutomirskiI think that the jiffies vvar was once used for the vgetcpu cache. That code is long gone, so let's just make jiffies be a normal variable.
--- arch/x86/include/asm/vvar.h | 1 - arch/x86/kernel/time.c | 2 +- arch/x86/vdso/vgetcpu.c | 1 - 3 files changed, 1 insertion(+), 3 deletions(-)
arch/x86/include/asm/vvar.h +0 -1
@@ -44,7 +44,6 @@ extern char __vvar_page;/* DECLARE_VVAR(offset, type, name) */ -DECLARE_VVAR(0, volatile unsigned long, jiffies) DECLARE_VVAR(16, int, vgetcpu_mode) DECLARE_VVAR(128, struct vsyscall_gtod_data, vsyscall_gtod_data)
arch/x86/kernel/time.c +1 -1
@@ -23,7 +23,7 @@#include <asm/time.h> #ifdef CONFIG_X86_64 -__visible DEFINE_VVAR (volatile unsigned long ,jiffies ) =INITIAL_JIFFIES ; +__visible volatile unsigned long jiffies __cacheline_aligned = INITIAL_JIFFIES;#endif unsigned long profile_pc (struct pt_regs *regs)
arch/x86/vdso/vgetcpu.c +0 -1
@@ -7,7 +7,6 @@#include <linux/kernel.h> #include <linux/getcpu.h> -#include <linux/jiffies.h> #include <linux/time.h> #include <asm/vsyscall.h> #include <asm/vgtod.h>
Signature · 1 line
1.9.3
PATCH v2 5/10 x86,vdso: Replace vgetcpu_mode with static_cpu_has
In reply to Andy LutomirskiThe vdso has supported alternatives for a while; use them instead of a vvar to select the vgetcpu mode.
--- arch/x86/include/asm/vgtod.h | 21 +++++++++++++++++++++ arch/x86/include/asm/vsyscall.h | 29 ----------------------------- arch/x86/include/asm/vvar.h | 1 - arch/x86/kernel/cpu/common.c | 10 ---------- arch/x86/kernel/vsyscall_64.c | 2 -- arch/x86/vdso/vclock_gettime.c | 3 +++ arch/x86/vdso/vgetcpu.c | 4 +++- arch/x86/vdso/vma.c | 1 + 8 files changed, 28 insertions(+), 43 deletions(-)
arch/x86/include/asm/vgtod.h +21 -0
@@ -70,4 +70,25 @@ static inline void gtod_write_end(struct vsyscall_gtod_data *s) ++s->seq; } +#ifdef CONFIG_X86_64 + +#define VGETCPU_CPU_MASK 0xfff + +static inline unsigned int __getcpu (void ) +{ +unsigned int p; + +if (static_cpu_has (X86_FEATURE_RDTSCP )) { +/* Load per CPU data from RDTSCP */ +native_read_tscp (&p); + }else { +/* Load per CPU data from GDT */ + asm("lsl %1,%0" :"=r" (p) :"r" (__PER_CPU_SEG)); + } + +return p; +} + +#endif /* CONFIG_X86_64 */ +#endif /* _ASM_X86_VGTOD_H */
arch/x86/include/asm/vsyscall.h +0 -29
@@ -4,15 +4,6 @@#include <linux/seqlock.h> #include <uapi/asm/vsyscall.h> -#define VGETCPU_RDTSCP 1 -#define VGETCPU_LSL 2 - -/* kernel space (writeable) */ -extern int vgetcpu_mode; -extern struct timezone sys_tz; - -#include <asm/vvar.h> -extern void map_vsyscall (void );/*
@@ -21,24 +12,4 @@ extern void map_vsyscall(void);*/ extern bool emulate_vsyscall (struct pt_regs *regs,unsigned long address); -#ifdef CONFIG_X86_64 - -#define VGETCPU_CPU_MASK 0xfff - -static inline unsigned int __getcpu (void ) -{ -unsigned int p; - -if (VVAR (vgetcpu_mode) ==VGETCPU_RDTSCP ) { -/* Load per CPU data from RDTSCP */ -native_read_tscp (&p); - }else { -/* Load per CPU data from GDT */ - asm("lsl %1,%0" :"=r" (p) :"r" (__PER_CPU_SEG)); - } - -return p; -} -#endif /* CONFIG_X86_64 */ -#endif /* _ASM_X86_VSYSCALL_H */
arch/x86/include/asm/vvar.h +0 -1
@@ -44,7 +44,6 @@ extern char __vvar_page;/* DECLARE_VVAR(offset, type, name) */ -DECLARE_VVAR(16, int, vgetcpu_mode) DECLARE_VVAR(128, struct vsyscall_gtod_data, vsyscall_gtod_data)#undef DECLARE_VVAR
arch/x86/kernel/cpu/common.c +0 -10
@@ -948,14 +948,6 @@ static void identify_cpu(struct cpuinfo_x86 *c) }#ifdef CONFIG_X86_64 -static void vgetcpu_set_mode (void ) -{ -if (cpu_has (&boot_cpu_data,X86_FEATURE_RDTSCP )) - vgetcpu_mode =VGETCPU_RDTSCP ; -else - vgetcpu_mode =VGETCPU_LSL ; -} -/* May not be __init: called during resume */ static void syscall32_cpu_init (void ) {
@@ -996,8 +988,6 @@ void __init identify_boot_cpu(void)#ifdef CONFIG_X86_32 sysenter_setup ();enable_sep_cpu (); -#else -vgetcpu_set_mode ();#endif cpu_detect_tlb (&boot_cpu_data); }
arch/x86/kernel/vsyscall_64.c +0 -2
@@ -52,8 +52,6 @@#define CREATE_TRACE_POINTS #include "vsyscall_trace.h" -DEFINE_VVAR (int, vgetcpu_mode); -static enum {EMULATE ,NATIVE ,NONE } vsyscall_mode =EMULATE ;static int __init vsyscall_setup (char *str)
arch/x86/vdso/vclock_gettime.c +3 -0
@@ -11,6 +11,9 @@* Check with readelf after changing. */ +/* Disable static_cpu_has debugging; it doesn't work in the vDSO */ +#undef CONFIG_X86_DEBUG_STATIC_CPU_HAS +#include <uapi/linux/time.h> #include <asm/vgtod.h> #include <asm/hpet.h>
arch/x86/vdso/vgetcpu.c +3 -1
@@ -5,10 +5,12 @@* Fast user context implementation of getcpu() */ +/* Disable static_cpu_has debugging; it doesn't work in the vDSO */ +#undef CONFIG_X86_DEBUG_STATIC_CPU_HAS +#include <linux/kernel.h> #include <linux/getcpu.h> #include <linux/time.h> -#include <asm/vsyscall.h> #include <asm/vgtod.h> notrace long
arch/x86/vdso/vma.c +1 -0
@@ -16,6 +16,7 @@#include <asm/vdso.h> #include <asm/page.h> #include <asm/hpet.h> +#include <asm/vvar.h> #if defined(CONFIG_X86_64 )unsigned int __read_mostly vdso64_enabled =1 ;
Signature · 1 line
1.9.3
PATCH v2 6/10 x86_64: Move getcpu code from vsyscall_64.c to vdso/vma.c
In reply to Andy LutomirskiThis is pure cut-and-paste. At this point, vsyscall_64.c contains only code needed for vsyscall emulation, but some of the comments and function names are still confused.
--- arch/x86/kernel/vsyscall_64.c | 57 ---------------------------------------- arch/x86/vdso/vma.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 57 deletions(-)
arch/x86/kernel/vsyscall_64.c +0 -57
@@ -332,49 +332,6 @@ int in_gate_area_no_mm(unsigned long addr)return vsyscall_mode !=NONE && (addr &PAGE_MASK ) ==VSYSCALL_ADDR ; } -/* -* Assume __initcall executes before all user space. Hopefully kmod -* doesn't violate that. We'll find out if it does. -*/ -static void vsyscall_set_cpu (int cpu) -{ -unsigned long d; -unsigned long node =0 ; -#ifdef CONFIG_NUMA - node =cpu_to_node (cpu); -#endif -if (cpu_has (&cpu_data (cpu),X86_FEATURE_RDTSCP )) -write_rdtscp_aux ((node <<12 ) | cpu); - -/* -* Store cpu number in limit so that it can be loaded quickly -* in user space in vgetcpu. (12 bits for the CPU and 8 bits for the node) -*/ - d =0x0f40000000000ULL ; - d |= cpu; - d |= (node &0xf ) <<12 ; - d |= (node >>4 ) <<48 ; - -write_gdt_entry (get_cpu_gdt_table (cpu),GDT_ENTRY_PER_CPU , &d,DESCTYPE_S ); -} - -static void cpu_vsyscall_init (void *arg) -{ -/* preemption should be already off */ -vsyscall_set_cpu (raw_smp_processor_id ()); -} - -static int -cpu_vsyscall_notifier (struct notifier_block *n,unsigned long action,void *arg) -{ -long cpu = (long )arg; - -if (action ==CPU_ONLINE || action ==CPU_ONLINE_FROZEN ) -smp_call_function_single (cpu, cpu_vsyscall_init,NULL ,1 ); - -return NOTIFY_DONE ; -} -void __init map_vsyscall (void ) {extern char __vsyscall_page;
@@ -389,17 +346,3 @@ void __init map_vsyscall(void)BUILD_BUG_ON ((unsigned long )__fix_to_virt (VSYSCALL_PAGE ) != (unsigned long )VSYSCALL_ADDR ); } - -static int __init vsyscall_init (void ) -{ -cpu_notifier_register_begin (); - -on_each_cpu (cpu_vsyscall_init,NULL ,1 ); -/* notifier priority > KVM */ -__hotcpu_notifier (cpu_vsyscall_notifier,30 ); - -cpu_notifier_register_done (); - -return 0 ; -} -__initcall (vsyscall_init);
arch/x86/vdso/vma.c +61 -0
76 lines not on this page · raw message
Signature · 1 line
1.9.3
PATCH v2 7/10 x86_64,vsyscall: Rewrite comment and clean up headers in vsyscall code
In reply to Andy Lutomirskivsyscall_64.c is just vsyscall emulation. Tidy it up accordingly.
If my comment editing offends anyone, let me know and I can fix it.
--- arch/x86/kernel/vsyscall_64.c | 51 +++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 33 deletions(-)
arch/x86/kernel/vsyscall_64.c +18 -33
@@ -1,52 +1,37 @@/* -* Copyright (C) 2001 Andrea Arcangeli <[email protected]> SuSE -* Copyright 2003 Andi Kleen, SuSE Labs. +* Mostly copyright (c) 2012-2014 Andy Lutomirski <[email protected]> * -* [ NOTE: this mechanism is now deprecated in favor of the vDSO. ] +* This file implements vsyscall emulation. vsyscalls are a legacy ABI: +* userspace can request certain kernel services by calling fixed +* addresses. This concept is problematic: * -* Thanks to [email protected] for some useful hint. -* Special thanks to Ingo Molnar for his early experience with -* a different vsyscall implementation for Linux/IA32 and for the name. +* - It interferes with ASLR. +* - It's awkward to write code that lives in kernel addresses but is +* callable by userspace at fixed addresses. +* - The whole concept is impossible for 32-bit compat userspace. +* - UML cannot easily virtualize a vsyscall. * -* vsyscall 1 is located at -10Mbyte, vsyscall 2 is located -* at virtual address -10Mbyte+1024bytes etc... There are at max 4 -* vsyscalls. One vsyscall can reserve more than 1 slot to avoid -* jumping out of line if necessary. We cannot add more with this -* mechanism because older kernels won't return -ENOSYS. +* As of mid-2014, I believe that there is no new userspace code that +* will use a vsyscall if the vDSO is present. I hope that there will +* soon be no new userspace code that will ever use a vsyscall. * -* Note: the concept clashes with user mode linux. UML users should -* use the vDSO. +* The code in this file emulates vsyscalls when notified of a page +* fault to a vsyscall address. +* +* The original version of this code is: +* Copyright (C) 2001 Andrea Arcangeli <[email protected]> SuSE +* Copyright 2003 Andi Kleen, SuSE Labs. */ -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/time.h> -#include <linux/init.h> #include <linux/kernel.h> #include <linux/timer.h> -#include <linux/seqlock.h> -#include <linux/jiffies.h> -#include <linux/sysctl.h> -#include <linux/topology.h> -#include <linux/timekeeper_internal.h> -#include <linux/getcpu.h> -#include <linux/cpu.h> -#include <linux/smp.h> -#include <linux/notifier.h> #include <linux/syscalls.h> #include <linux/ratelimit.h> #include <asm/vsyscall.h> -#include <asm/pgtable.h> -#include <asm/compat.h> -#include <asm/page.h> #include <asm/unistd.h> #include <asm/fixmap.h> -#include <asm/errno.h> -#include <asm/io.h> -#include <asm/segment.h> -#include <asm/desc.h> -#include <asm/topology.h> #include <asm/traps.h> #define CREATE_TRACE_POINTS
Signature · 1 line
1.9.3
PATCH v2 8/10 x86_64,vdso: Clean up vgetcpu init and merge the vdso initcalls
In reply to Andy LutomirskiNow vdso/vma.c has a single initcall and no references to "vsyscall".
--- arch/x86/vdso/vma.c | 61 +++++++++++++++++++---------------------------------- 1 file changed, 22 insertions(+), 39 deletions(-)
arch/x86/vdso/vma.c +22 -39
@@ -1,7 +1,8 @@/* -* Set up the VMAs to tell the VM about the vDSO. * Copyright 2007 Andi Kleen, SUSE Labs. * Subject to the GPL, v.2 +* +* This contains most of the x86 vDSO kernel-side code. */ #include <linux/mm.h> #include <linux/err.h>
@@ -11,7 +12,6 @@#include <linux/random.h> #include <linux/elf.h> #include <linux/cpu.h> -#include <asm/vsyscall.h> #include <asm/vgtod.h> #include <asm/proto.h> #include <asm/vdso.h>
@@ -22,8 +22,6 @@#if defined(CONFIG_X86_64 )unsigned int __read_mostly vdso64_enabled =1 ; - -extern unsigned short vdso_sync_cpuid;#endif void __init init_vdso_image (const struct vdso_image *image)
@@ -41,20 +39,6 @@ void __init init_vdso_image(const struct vdso_image *image) image->alt_len)); } -#if defined(CONFIG_X86_64 ) -static int __init init_vdso (void ) -{ -init_vdso_image (&vdso_image_64); - -#ifdef CONFIG_X86_X32_ABI -init_vdso_image (&vdso_image_x32); -#endif - -return 0 ; -} -subsys_initcall (init_vdso); -#endif -struct linux_binprm ;/* Put the vdso above the (randomized) stack with another randomized offset.
@@ -237,12 +221,9 @@ __setup("vdso=", vdso_setup);#endif #ifdef CONFIG_X86_64 -/* -* Assume __initcall executes before all user space. Hopefully kmod -* doesn't violate that. We'll find out if it does. -*/ -static void vsyscall_set_cpu (int cpu) +static void vgetcpu_cpu_init (void *arg) { +int cpu =smp_processor_id ();unsigned long d;unsigned long node =0 ;#ifdef CONFIG_NUMA
@@ -252,45 +233,47 @@ static void vsyscall_set_cpu(int cpu)write_rdtscp_aux ((node <<12 ) | cpu);/* -* Store cpu number in limit so that it can be loaded quickly -* in user space in vgetcpu. (12 bits for the CPU and 8 bits for the node) +* Store cpu number in limit so that it can be loaded quickly in +* user space in vgetcpu. (12 bits for the CPU and 8 bits for +* the node) */ d =0x0f40000000000ULL ; d |= cpu; d |= (node &0xf ) <<12 ; d |= (node >>4 ) <<48 ; - write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_PER_CPU, &d, DESCTYPE_S); -} - -static void cpu_vsyscall_init (void *arg) -{ -/* preemption should be already off */ -vsyscall_set_cpu (raw_smp_processor_id ()); +write_gdt_entry (get_cpu_gdt_table (cpu), + GDT_ENTRY_PER_CPU, &d, DESCTYPE_S); }static int -cpu_vsyscall_notifier (struct notifier_block *n,unsigned long action,void *arg) +vgetcpu_cpu_notifier (struct notifier_block *n,unsigned long action,void *arg) {long cpu = (long )arg;if (action ==CPU_ONLINE || action ==CPU_ONLINE_FROZEN ) -smp_call_function_single (cpu, cpu_vsyscall_init,NULL ,1 ); +smp_call_function_single (cpu, vgetcpu_cpu_init,NULL ,1 );return NOTIFY_DONE ; } -static int __init vsyscall_init (void ) +static int __init init_vdso (void ) { +init_vdso_image (&vdso_image_64); + +#ifdef CONFIG_X86_X32_ABI +init_vdso_image (&vdso_image_x32); +#endif +cpu_notifier_register_begin (); -on_each_cpu (cpu_vsyscall_init,NULL ,1 ); +on_each_cpu (vgetcpu_cpu_init,NULL ,1 );/* notifier priority > KVM */ -__hotcpu_notifier (cpu_vsyscall_notifier,30 ); +__hotcpu_notifier (vgetcpu_cpu_notifier,30 );cpu_notifier_register_done ();return 0 ; } -__initcall (vsyscall_init); -#endif +subsys_initcall (init_vdso); +#endif /* CONFIG_X86_64 */
Signature · 1 line
1.9.3
PATCH v2 9/10 arm64,ia64,ppc,s390,sh,tile,um,x86,mm: Remove default gate area
In reply to Andy LutomirskiThe core mm code will provide a default gate area based on FIXADDR_USER_START and FIXADDR_USER_END if !defined(__HAVE_ARCH_GATE_AREA) && defined(AT_SYSINFO_EHDR).
This default is only useful for ia64. arm64, ppc, s390, sh, tile, 64-bit UML, and x86_32 have their own code just to disable it. arm, 32-bit UML, and x86_64 have gate areas, but they have their own implementations.
This gets rid of the default and moves the code into ia64.
This should save some code on architectures without a gate area: it's now possible to inline the gate_area functions in the default case.
--- arch/arm64/include/asm/page.h | 3 --- arch/arm64/kernel/vdso.c | 19 ------------------- arch/ia64/include/asm/page.h | 2 ++ arch/ia64/mm/init.c | 26 ++++++++++++++++++++++++++ arch/powerpc/include/asm/page.h | 3 --- arch/powerpc/kernel/vdso.c | 16 ---------------- arch/s390/include/asm/page.h | 2 -- arch/s390/kernel/vdso.c | 15 --------------- arch/sh/include/asm/page.h | 5 ----- arch/sh/kernel/vsyscall/vsyscall.c | 15 --------------- arch/tile/include/asm/page.h | 6 ------ arch/tile/kernel/vdso.c | 15 --------------- arch/um/include/asm/page.h | 5 +++++ arch/x86/include/asm/page.h | 1 - arch/x86/include/asm/page_64.h | 2 ++ arch/x86/um/asm/elf.h | 1 - arch/x86/um/mem_64.c | 15 --------------- arch/x86/vdso/vdso32-setup.c | 19 +------------------ include/linux/mm.h | 17 ++++++++++++----- mm/memory.c | 38 -------------------------------------- mm/nommu.c | 5 ----- 21 files changed, 48 insertions(+), 182 deletions(-)
arch/arm64/include/asm/page.h +0 -3
@@ -28,9 +28,6 @@#define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT)#define PAGE_MASK (~(PAGE_SIZE-1)) -/* We do define AT_SYSINFO_EHDR but don't use the gate mechanism */ -#define __HAVE_ARCH_GATE_AREA 1 -#ifndef __ASSEMBLY__#ifdef CONFIG_ARM64_64K_PAGES
arch/arm64/kernel/vdso.c +0 -19
@@ -187,25 +187,6 @@ const char *arch_vma_name(struct vm_area_struct *vma) }/* -* We define AT_SYSINFO_EHDR, so we need these function stubs to keep -* Linux happy. -*/ -int in_gate_area_no_mm (unsigned long addr) -{ -return 0 ; -} - -int in_gate_area (struct mm_struct *mm,unsigned long addr) -{ -return 0 ; -} - -struct vm_area_struct *get_gate_vma (struct mm_struct *mm) -{ -return NULL ; -} - -/* * Update the vDSO data page to keep in sync with kernel timekeeping. */ void update_vsyscall (struct timekeeper *tk)
arch/ia64/include/asm/page.h +2 -0
@@ -231,4 +231,6 @@ get_order (unsigned long size)#define PERCPU_ADDR (-PERCPU_PAGE_SIZE)#define LOAD_OFFSET (KERNEL_START - KERNEL_TR_PAGE_SIZE) +#define __HAVE_ARCH_GATE_AREA 1 +#endif /* _ASM_IA64_PAGE_H */
arch/ia64/mm/init.c +26 -0
@@ -278,6 +278,32 @@ setup_gate (void)ia64_patch_gate (); } +static struct vm_area_struct gate_vma; + +static int __init gate_vma_init (void ) +{ + gate_vma.vm_mm =NULL ; + gate_vma.vm_start =FIXADDR_USER_START ; + gate_vma.vm_end =FIXADDR_USER_END ; + gate_vma.vm_flags =VM_READ |VM_MAYREAD |VM_EXEC |VM_MAYEXEC ; + gate_vma.vm_page_prot = __P101; + +return 0 ; +} +__initcall (gate_vma_init); + +struct vm_area_struct *get_gate_vma (struct mm_struct *mm) +{ +return &gate_vma; +} + +int in_gate_area_no_mm (unsigned long addr) +{ +if ((addr >=FIXADDR_USER_START ) && (addr <FIXADDR_USER_END )) +return 1 ; +return 0 ; +} +void ia64_mmu_init (void *my_cpu_data) {unsigned long pta, impl_va_bits;
arch/powerpc/include/asm/page.h +0 -3
@@ -48,9 +48,6 @@ extern unsigned int HPAGE_SHIFT;#define HUGE_MAX_HSTATE (MMU_PAGE_COUNT-1)#endif -/* We do define AT_SYSINFO_EHDR but don't use the gate mechanism */ -#define __HAVE_ARCH_GATE_AREA 1 -/* * Subtle: (1 << PAGE_SHIFT) is an int, not an unsigned long. So if we * assign PAGE_MASK to a larger type it gets extended the way we want
arch/powerpc/kernel/vdso.c +0 -16
@@ -840,19 +840,3 @@ static int __init vdso_init(void)return 0 ; }arch_initcall (vdso_init); - -int in_gate_area_no_mm (unsigned long addr) -{ -return 0 ; -} - -int in_gate_area (struct mm_struct *mm,unsigned long addr) -{ -return 0 ; -} - -struct vm_area_struct *get_gate_vma (struct mm_struct *mm) -{ -return NULL ; -} -
arch/s390/include/asm/page.h +0 -2
@@ -162,6 +162,4 @@ static inline int devmem_is_allowed(unsigned long pfn)#include <asm-generic/memory_model.h> #include <asm-generic/getorder.h> -#define __HAVE_ARCH_GATE_AREA 1 -#endif /* _S390_PAGE_H */
arch/s390/kernel/vdso.c +0 -15
@@ -316,18 +316,3 @@ static int __init vdso_init(void)return 0 ; }early_initcall (vdso_init); - -int in_gate_area_no_mm (unsigned long addr) -{ -return 0 ; -} - -int in_gate_area (struct mm_struct *mm,unsigned long addr) -{ -return 0 ; -} - -struct vm_area_struct *get_gate_vma (struct mm_struct *mm) -{ -return NULL ; -}
arch/sh/include/asm/page.h +0 -5
@@ -186,11 +186,6 @@ typedef struct page *pgtable_t;#include <asm-generic/memory_model.h> #include <asm-generic/getorder.h> -/* vDSO support */ -#ifdef CONFIG_VSYSCALL -#define __HAVE_ARCH_GATE_AREA -#endif -/* * Some drivers need to perform DMA into kmalloc'ed buffers * and so we have to increase the kmalloc minalign for this.
arch/sh/kernel/vsyscall/vsyscall.c +0 -15
@@ -92,18 +92,3 @@ const char *arch_vma_name(struct vm_area_struct *vma)return NULL ; } - -struct vm_area_struct *get_gate_vma (struct mm_struct *mm) -{ -return NULL ; -} - -int in_gate_area (struct mm_struct *mm,unsigned long address) -{ -return 0 ; -} - -int in_gate_area_no_mm (unsigned long address) -{ -return 0 ; -}
arch/tile/include/asm/page.h +0 -6
@@ -39,12 +39,6 @@#define HPAGE_MASK (~(HPAGE_SIZE - 1))/* -* We do define AT_SYSINFO_EHDR to support vDSO, -* but don't use the gate mechanism. -*/ -#define __HAVE_ARCH_GATE_AREA 1 - -/* * If the Kconfig doesn't specify, set a maximum zone order that * is enough so that we can create huge pages from small pages given * the respective sizes of the two page types. See <linux/mmzone.h>.
arch/tile/kernel/vdso.c +0 -15
@@ -121,21 +121,6 @@ const char *arch_vma_name(struct vm_area_struct *vma)return NULL ; } -struct vm_area_struct *get_gate_vma (struct mm_struct *mm) -{ -return NULL ; -} - -int in_gate_area (struct mm_struct *mm,unsigned long address) -{ -return 0 ; -} - -int in_gate_area_no_mm (unsigned long address) -{ -return 0 ; -} -int setup_vdso_pages (void ) {struct page **pagelist;
arch/um/include/asm/page.h +5 -0
@@ -119,4 +119,9 @@ extern unsigned long uml_physmem;#include <asm-generic/getorder.h> #endif /* __ASSEMBLY__ */ + +#ifdef CONFIG_X86_32 +#define __HAVE_ARCH_GATE_AREA 1 +#endif +#endif /* __UM_PAGE_H */
arch/x86/include/asm/page.h +0 -1
@@ -70,7 +70,6 @@ extern bool __virt_addr_valid(unsigned long kaddr);#include <asm-generic/memory_model.h> #include <asm-generic/getorder.h> -#define __HAVE_ARCH_GATE_AREA 1#define HAVE_ARCH_HUGETLB_UNMAPPED_AREA #endif /* __KERNEL__ */
arch/x86/include/asm/page_64.h +2 -0
@@ -39,4 +39,6 @@ void copy_page(void *to, void *from);#endif /* !__ASSEMBLY__ */ +#define __HAVE_ARCH_GATE_AREA 1 +#endif /* _ASM_X86_PAGE_64_H */
arch/x86/um/asm/elf.h +0 -1
@@ -216,6 +216,5 @@ extern long elf_aux_hwcap;#define ELF_HWCAP (elf_aux_hwcap)#define SET_PERSONALITY (ex) do ; while(0) -#define __HAVE_ARCH_GATE_AREA 1#endif
arch/x86/um/mem_64.c +0 -15
@@ -9,18 +9,3 @@ const char *arch_vma_name(struct vm_area_struct *vma)return NULL ; } - -struct vm_area_struct *get_gate_vma (struct mm_struct *mm) -{ -return NULL ; -} - -int in_gate_area (struct mm_struct *mm,unsigned long addr) -{ -return 0 ; -} - -int in_gate_area_no_mm (unsigned long addr) -{ -return 0 ; -}
arch/x86/vdso/vdso32-setup.c +1 -18
@@ -115,23 +115,6 @@ static __init int ia32_binfmt_init(void)return 0 ; }__initcall (ia32_binfmt_init); -#endif - -#else /* CONFIG_X86_32 */ - -struct vm_area_struct *get_gate_vma (struct mm_struct *mm) -{ -return NULL ; -} - -int in_gate_area (struct mm_struct *mm,unsigned long addr) -{ -return 0 ; -} - -int in_gate_area_no_mm (unsigned long addr) -{ -return 0 ; -} +#endif /* CONFIG_SYSCTL */ #endif /* CONFIG_X86_64 */
include/linux/mm.h +12 -5
@@ -2014,13 +2014,20 @@ static inline bool kernel_page_present(struct page *page) { return true; }#endif /* CONFIG_HIBERNATION */ #endif +#ifdef __HAVE_ARCH_GATE_AREAextern struct vm_area_struct *get_gate_vma (struct mm_struct *mm); -#ifdef __HAVE_ARCH_GATE_AREA -int in_gate_area_no_mm (unsigned long addr); -int in_gate_area (struct mm_struct *mm,unsigned long addr); +extern int in_gate_area_no_mm (unsigned long addr); +extern int in_gate_area (struct mm_struct *mm,unsigned long addr);#else -int in_gate_area_no_mm (unsigned long addr); -#define in_gate_area (mm, addr) ({(void)mm; in_gate_area_no_mm(addr);}) +static inline struct vm_area_struct *get_gate_vma (struct mm_struct *mm) +{ +return NULL ; +} +static inline int in_gate_area_no_mm (unsigned long addr) {return 0 ; } +static inline int in_gate_area (struct mm_struct *mm,unsigned long addr) +{ +return 0 ; +}#endif /* __HAVE_ARCH_GATE_AREA */ #ifdef CONFIG_SYSCTL
mm/memory.c +0 -38
@@ -3399,44 +3399,6 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address) }#endif /* __PAGETABLE_PMD_FOLDED */ -#if !defined(__HAVE_ARCH_GATE_AREA) - -#if defined(AT_SYSINFO_EHDR ) -static struct vm_area_struct gate_vma; - -static int __init gate_vma_init (void ) -{ - gate_vma.vm_mm =NULL ; - gate_vma.vm_start =FIXADDR_USER_START ; - gate_vma.vm_end =FIXADDR_USER_END ; - gate_vma.vm_flags =VM_READ |VM_MAYREAD |VM_EXEC |VM_MAYEXEC ; - gate_vma.vm_page_prot = __P101; - -return 0 ; -} -__initcall (gate_vma_init); -#endif - -struct vm_area_struct *get_gate_vma (struct mm_struct *mm) -{ -#ifdef AT_SYSINFO_EHDR -return &gate_vma; -#else -return NULL ; -#endif -} - -int in_gate_area_no_mm (unsigned long addr) -{ -#ifdef AT_SYSINFO_EHDR -if ((addr >=FIXADDR_USER_START ) && (addr <FIXADDR_USER_END )) -return 1 ; -#endif -return 0 ; -} - -#endif /* __HAVE_ARCH_GATE_AREA */ -static int __follow_pte (struct mm_struct *mm,unsigned long address,pte_t **ptepp,spinlock_t **ptlp) {
mm/nommu.c +0 -5
@@ -1981,11 +1981,6 @@ error:return -ENOMEM ; } -int in_gate_area_no_mm (unsigned long addr) -{ -return 0 ; -} -int filemap_fault (struct vm_area_struct *vma,struct vm_fault *vmf) {BUG ();
Signature · 7 lines
1.9.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 09/10] arm64,ia64,ppc,s390,sh,tile,um,x86,mm: Remove default gate area
Quoted 9 lines · Andy Lutomirski
The core mm code will provide a default gate area based on
FIXADDR_USER_STARTandFIXADDR_USER_ENDif !defined(__HAVE_ARCH_GATE_AREA) &&defined(AT_SYSINFO_EHDR).This default is only useful for ia64. arm64, ppc, s390, sh, tile, 64-bit UML, and
x86_32have their own code just to disable it. arm, 32-bit UML, andx86_64have gate areas, but they have their own implementations.
Quoted 4 lines
This gets rid of the default and moves the code into ia64.
This should save some code on architectures without a gate area: it's now possible to inline the
gate_areafunctions in the default case.
For the arm64 bit:
Will
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 10/10 x86_64,vsyscall: Make vsyscall emulation configurable
In reply to Andy LutomirskiThis 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.
--- arch/x86/Kconfig | 18 ++++++++++++++++++ arch/x86/include/asm/fixmap.h | 2 ++ arch/x86/include/asm/page_64.h | 4 +++- arch/x86/include/asm/vsyscall.h | 8 ++++++++ arch/x86/kernel/Makefile | 3 +-- arch/x86/kernel/setup.c | 2 -- arch/x86/xen/mmu.c | 6 ++++-- 7 files changed, 36 insertions(+), 7 deletions(-)
arch/x86/Kconfig +18 -0
@@ -935,6 +935,24 @@ config X86_ESPFIX64 def_bool y depends on X86_16BIT && X86_64 +config X86_VSYSCALL_EMULATION + bool "Enable vsyscall emulation" if EXPERT + default y + depends on X86_64 + ---help--- + This enables emulation of the legacy vsyscall page. Disabling + it is roughly equivalent to booting with vsyscall=none, except + that it will also disable the helpful warning if a program + tries to use a vsyscall. With this option set to N, offending + program will just segfault, citing addresses of the form + 0xffffffffff600?00. + + This option is required by many programs built before 2013, and + care should be used even with newer programs if set to N. + + Disabling this option saves about 7K of kernel size and + possibly 4K of additional runtime pagetable memory. + config TOSHIBA tristate "Toshiba Laptop support" depends on X86_32
arch/x86/include/asm/fixmap.h +2 -0
@@ -69,7 +69,9 @@ enum fixed_addresses {#ifdef CONFIG_X86_32 FIX_HOLE,#else +#ifdef CONFIG_X86_VSYSCALL_EMULATION VSYSCALL_PAGE = (FIXADDR_TOP - VSYSCALL_ADDR) >> PAGE_SHIFT, +#endif #ifdef CONFIG_PARAVIRT_CLOCK PVCLOCK_FIXMAP_BEGIN , PVCLOCK_FIXMAP_END = PVCLOCK_FIXMAP_BEGIN+PVCLOCK_VSYSCALL_NR_PAGES-1,
arch/x86/include/asm/page_64.h +3 -1
@@ -39,6 +39,8 @@ void copy_page(void *to, void *from);#endif /* !__ASSEMBLY__ */ -#define __HAVE_ARCH_GATE_AREA 1 +#ifdef CONFIG_X86_VSYSCALL_EMULATION +# define __HAVE_ARCH_GATE_AREA 1 +#endif #endif /* _ASM_X86_PAGE_64_H */
arch/x86/include/asm/vsyscall.h +8 -0
@@ -4,6 +4,7 @@#include <linux/seqlock.h> #include <uapi/asm/vsyscall.h> +#ifdef CONFIG_X86_VSYSCALL_EMULATION extern void map_vsyscall (void );/*
@@ -11,5 +12,12 @@ extern void map_vsyscall(void);* Returns true if handled. */ extern bool emulate_vsyscall (struct pt_regs *regs,unsigned long address); +#else +static inline void map_vsyscall (void ) {} +static inline bool emulate_vsyscall (struct pt_regs *regs,unsigned long address) +{ +return false; +} +#endif #endif /* _ASM_X86_VSYSCALL_H */
arch/x86/kernel/Makefile +1 -2
@@ -28,8 +28,7 @@ obj-$(CONFIG_X86_32) += i386_ksyms_32.o obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o obj-$(CONFIG_X86_64) += mcount_64.o obj-y += syscall_$(BITS).o vsyscall_gtod.o -obj-$(CONFIG_X86_64) += vsyscall_64.o -obj-$(CONFIG_X86_64) += vsyscall_emu_64.o +obj-$(CONFIG_X86_VSYSCALL_EMULATION) += vsyscall_64.o vsyscall_emu_64.o obj-$(CONFIG_X86_ESPFIX64) += espfix_64.o obj-$(CONFIG_SYSFS) += ksysfs.o obj-y += bootflag.o e820.o
arch/x86/kernel/setup.c +0 -2
@@ -1181,9 +1181,7 @@ void __init setup_arch(char **cmdline_p)tboot_probe (); -#ifdef CONFIG_X86_64 map_vsyscall (); -#endif generic_apic_probe ();
arch/x86/xen/mmu.c +4 -2
@@ -1493,11 +1493,13 @@ static int xen_pgd_alloc(struct mm_struct *mm) user_pgd = (pgd_t *)__get_free_page (GFP_KERNEL | __GFP_ZERO); page->private = (unsigned long )user_pgd; +#ifdef CONFIG_X86_VSYSCALL_EMULATION if (user_pgd !=NULL ) { user_pgd[pgd_index (VSYSCALL_ADDR )] =__pgd (__pa (level3_user_vsyscall) | _PAGE_TABLE); ret =0 ; } +#endif BUG_ON (PagePinned (virt_to_page (xen_get_user_pgd (pgd)))); }
@@ -2061,7 +2063,7 @@ static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot)# ifdef CONFIG_HIGHMEM case FIX_KMAP_BEGIN ... FIX_KMAP_END:# endif -#else +#elif defined(CONFIG_X86_VSYSCALL_EMULATION )case VSYSCALL_PAGE :#endif case FIX_TEXT_POKE0 :
@@ -2100,7 +2102,7 @@ static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot)__native_set_fixmap (idx, pte); -#ifdef CONFIG_X86_64 +#ifdef CONFIG_X86_VSYSCALL_EMULATION /* Replicate changes to map the vsyscall page into the user pagetable vsyscall mapping. */ if (idx ==VSYSCALL_PAGE ) {
Signature · 1 line
1.9.3