blob: e904c270573bf58054d5fd83f2b9c77b0ee81347 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * (C) Copyright 2002 Linus Torvalds
Ingo Molnare6e54942006-06-27 02:53:50 -07003 * Portions based on the vdso-randomization code from exec-shield:
4 * Copyright(C) 2005-2006, Red Hat, Inc., Ingo Molnar
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * This file contains the needed initializations to support sysenter.
7 */
8
9#include <linux/init.h>
10#include <linux/smp.h>
Andy Lutomirski18d0a6f2014-05-05 12:19:35 -070011#include <linux/kernel.h>
12#include <linux/mm_types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14#include <asm/cpufeature.h>
Andy Lutomirski18d0a6f2014-05-05 12:19:35 -070015#include <asm/processor.h>
Roland McGrath6c3652e2008-01-30 13:30:42 +010016#include <asm/vdso.h>
Jeremy Fitzhardinge1dbf527c2007-05-02 19:27:12 +020017
Jeremy Fitzhardinge1dbf527c2007-05-02 19:27:12 +020018#ifdef CONFIG_COMPAT_VDSO
Andy Lutomirskib0b49f22014-03-13 16:01:26 -070019#define VDSO_DEFAULT 0
Jeremy Fitzhardinge1dbf527c2007-05-02 19:27:12 +020020#else
Andy Lutomirskib0b49f22014-03-13 16:01:26 -070021#define VDSO_DEFAULT 1
Jeremy Fitzhardinge1dbf527c2007-05-02 19:27:12 +020022#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Roland McGrathaf65d642008-01-30 13:30:43 +010024/*
Ingo Molnare6e54942006-06-27 02:53:50 -070025 * Should the kernel map a VDSO page into processes and pass its
26 * address down to glibc upon exec()?
27 */
Andy Lutomirski3d7ee962014-05-05 12:19:32 -070028unsigned int __read_mostly vdso32_enabled = VDSO_DEFAULT;
Ingo Molnare6e54942006-06-27 02:53:50 -070029
Andy Lutomirski3d7ee962014-05-05 12:19:32 -070030static int __init vdso32_setup(char *s)
Ingo Molnare6e54942006-06-27 02:53:50 -070031{
Andy Lutomirski3d7ee962014-05-05 12:19:32 -070032 vdso32_enabled = simple_strtoul(s, NULL, 0);
Ingo Molnare6e54942006-06-27 02:53:50 -070033
Andy Lutomirski3d7ee962014-05-05 12:19:32 -070034 if (vdso32_enabled > 1)
Andy Lutomirskib0b49f22014-03-13 16:01:26 -070035 pr_warn("vdso32 values other than 0 and 1 are no longer allowed; vdso disabled\n");
36
Ingo Molnare6e54942006-06-27 02:53:50 -070037 return 1;
38}
39
Roland McGrathaf65d642008-01-30 13:30:43 +010040/*
41 * For consistency, the argument vdso32=[012] affects the 32-bit vDSO
42 * behavior on both 64-bit and 32-bit kernels.
43 * On 32-bit kernels, vdso=[012] means the same thing.
44 */
Andy Lutomirski3d7ee962014-05-05 12:19:32 -070045__setup("vdso32=", vdso32_setup);
Ingo Molnare6e54942006-06-27 02:53:50 -070046
Roland McGrathaf65d642008-01-30 13:30:43 +010047#ifdef CONFIG_X86_32
Andy Lutomirski3d7ee962014-05-05 12:19:32 -070048__setup_param("vdso=", vdso_setup, vdso32_setup, 0);
Roland McGrathaf65d642008-01-30 13:30:43 +010049#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Roland McGrathaf65d642008-01-30 13:30:43 +010051#ifdef CONFIG_X86_64
52
Jeremy Fitzhardingeb6ad92d2008-07-10 18:13:36 -070053#define vdso32_sysenter() (boot_cpu_has(X86_FEATURE_SYSENTER32))
Jeremy Fitzhardinge6a52e4b2008-07-12 02:22:00 -070054#define vdso32_syscall() (boot_cpu_has(X86_FEATURE_SYSCALL32))
Roland McGrathaf65d642008-01-30 13:30:43 +010055
Roland McGrathaf65d642008-01-30 13:30:43 +010056#else /* CONFIG_X86_32 */
57
58#define vdso32_sysenter() (boot_cpu_has(X86_FEATURE_SEP))
Jeremy Fitzhardinge6a52e4b2008-07-12 02:22:00 -070059#define vdso32_syscall() (0)
Roland McGrathaf65d642008-01-30 13:30:43 +010060
Roland McGrathaf65d642008-01-30 13:30:43 +010061#endif /* CONFIG_X86_64 */
62
Andy Lutomirski6f121e52014-05-05 12:19:34 -070063#if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT)
64const struct vdso_image *selected_vdso32;
65#endif
66
Jeremy Fitzhardingea6c4e072007-05-02 19:27:12 +020067int __init sysenter_setup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
Andy Lutomirskib67e6122014-03-20 15:01:21 -070069#ifdef CONFIG_COMPAT
Andy Lutomirski6f121e52014-05-05 12:19:34 -070070 if (vdso32_syscall())
71 selected_vdso32 = &vdso_image_32_syscall;
72 else
Andy Lutomirskib67e6122014-03-20 15:01:21 -070073#endif
Andy Lutomirski6f121e52014-05-05 12:19:34 -070074 if (vdso32_sysenter())
75 selected_vdso32 = &vdso_image_32_sysenter;
76 else
77 selected_vdso32 = &vdso_image_32_int80;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Andy Lutomirski6f121e52014-05-05 12:19:34 -070079 init_vdso_image(selected_vdso32);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 return 0;
82}
Ingo Molnare6e54942006-06-27 02:53:50 -070083
Roland McGrathaf65d642008-01-30 13:30:43 +010084#ifdef CONFIG_X86_64
85
Jiri Slabyd7a03802010-06-16 22:30:42 +020086subsys_initcall(sysenter_setup);
Roland McGrathaf65d642008-01-30 13:30:43 +010087
Roland McGratha97f52e2008-01-30 13:31:55 +010088#ifdef CONFIG_SYSCTL
89/* Register vsyscall32 into the ABI table */
90#include <linux/sysctl.h>
91
Joe Perchesf07d91e2013-06-13 19:37:33 -070092static struct ctl_table abi_table2[] = {
Roland McGratha97f52e2008-01-30 13:31:55 +010093 {
94 .procname = "vsyscall32",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -070095 .data = &vdso32_enabled,
Roland McGratha97f52e2008-01-30 13:31:55 +010096 .maxlen = sizeof(int),
97 .mode = 0644,
98 .proc_handler = proc_dointvec
99 },
100 {}
101};
102
Joe Perchesf07d91e2013-06-13 19:37:33 -0700103static struct ctl_table abi_root_table2[] = {
Roland McGratha97f52e2008-01-30 13:31:55 +0100104 {
Roland McGratha97f52e2008-01-30 13:31:55 +0100105 .procname = "abi",
106 .mode = 0555,
107 .child = abi_table2
108 },
109 {}
110};
111
112static __init int ia32_binfmt_init(void)
113{
114 register_sysctl_table(abi_root_table2);
115 return 0;
116}
117__initcall(ia32_binfmt_init);
Andy Lutomirskia6c19df2014-08-08 14:23:40 -0700118#endif /* CONFIG_SYSCTL */
Roland McGrathaf65d642008-01-30 13:30:43 +0100119
120#endif /* CONFIG_X86_64 */