Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * (C) Copyright 2002 Linus Torvalds |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 3 | * Portions based on the vdso-randomization code from exec-shield: |
| 4 | * Copyright(C) 2005-2006, Red Hat, Inc., Ingo Molnar |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * This file contains the needed initializations to support sysenter. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/init.h> |
| 10 | #include <linux/smp.h> |
Andy Lutomirski | 18d0a6f | 2014-05-05 12:19:35 -0700 | [diff] [blame] | 11 | #include <linux/kernel.h> |
| 12 | #include <linux/mm_types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
| 14 | #include <asm/cpufeature.h> |
Andy Lutomirski | 18d0a6f | 2014-05-05 12:19:35 -0700 | [diff] [blame] | 15 | #include <asm/processor.h> |
Roland McGrath | 6c3652e | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 16 | #include <asm/vdso.h> |
Jeremy Fitzhardinge | 1dbf527c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 17 | |
Jeremy Fitzhardinge | 1dbf527c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 18 | #ifdef CONFIG_COMPAT_VDSO |
Andy Lutomirski | b0b49f2 | 2014-03-13 16:01:26 -0700 | [diff] [blame] | 19 | #define VDSO_DEFAULT 0 |
Jeremy Fitzhardinge | 1dbf527c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 20 | #else |
Andy Lutomirski | b0b49f2 | 2014-03-13 16:01:26 -0700 | [diff] [blame] | 21 | #define VDSO_DEFAULT 1 |
Jeremy Fitzhardinge | 1dbf527c | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 22 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 24 | /* |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 25 | * Should the kernel map a VDSO page into processes and pass its |
| 26 | * address down to glibc upon exec()? |
| 27 | */ |
Andy Lutomirski | 3d7ee96 | 2014-05-05 12:19:32 -0700 | [diff] [blame] | 28 | unsigned int __read_mostly vdso32_enabled = VDSO_DEFAULT; |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 29 | |
Andy Lutomirski | 3d7ee96 | 2014-05-05 12:19:32 -0700 | [diff] [blame] | 30 | static int __init vdso32_setup(char *s) |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 31 | { |
Andy Lutomirski | 3d7ee96 | 2014-05-05 12:19:32 -0700 | [diff] [blame] | 32 | vdso32_enabled = simple_strtoul(s, NULL, 0); |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 33 | |
Andy Lutomirski | 3d7ee96 | 2014-05-05 12:19:32 -0700 | [diff] [blame] | 34 | if (vdso32_enabled > 1) |
Andy Lutomirski | b0b49f2 | 2014-03-13 16:01:26 -0700 | [diff] [blame] | 35 | pr_warn("vdso32 values other than 0 and 1 are no longer allowed; vdso disabled\n"); |
| 36 | |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 37 | return 1; |
| 38 | } |
| 39 | |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 40 | /* |
| 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 Lutomirski | 3d7ee96 | 2014-05-05 12:19:32 -0700 | [diff] [blame] | 45 | __setup("vdso32=", vdso32_setup); |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 46 | |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 47 | #ifdef CONFIG_X86_32 |
Andy Lutomirski | 3d7ee96 | 2014-05-05 12:19:32 -0700 | [diff] [blame] | 48 | __setup_param("vdso=", vdso_setup, vdso32_setup, 0); |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 49 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 51 | #ifdef CONFIG_X86_64 |
| 52 | |
Jeremy Fitzhardinge | b6ad92d | 2008-07-10 18:13:36 -0700 | [diff] [blame] | 53 | #define vdso32_sysenter() (boot_cpu_has(X86_FEATURE_SYSENTER32)) |
Jeremy Fitzhardinge | 6a52e4b | 2008-07-12 02:22:00 -0700 | [diff] [blame] | 54 | #define vdso32_syscall() (boot_cpu_has(X86_FEATURE_SYSCALL32)) |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 55 | |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 56 | #else /* CONFIG_X86_32 */ |
| 57 | |
| 58 | #define vdso32_sysenter() (boot_cpu_has(X86_FEATURE_SEP)) |
Jeremy Fitzhardinge | 6a52e4b | 2008-07-12 02:22:00 -0700 | [diff] [blame] | 59 | #define vdso32_syscall() (0) |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 60 | |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 61 | #endif /* CONFIG_X86_64 */ |
| 62 | |
Andy Lutomirski | 6f121e5 | 2014-05-05 12:19:34 -0700 | [diff] [blame] | 63 | #if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT) |
| 64 | const struct vdso_image *selected_vdso32; |
| 65 | #endif |
| 66 | |
Jeremy Fitzhardinge | a6c4e07 | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 67 | int __init sysenter_setup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | { |
Andy Lutomirski | b67e612 | 2014-03-20 15:01:21 -0700 | [diff] [blame] | 69 | #ifdef CONFIG_COMPAT |
Andy Lutomirski | 6f121e5 | 2014-05-05 12:19:34 -0700 | [diff] [blame] | 70 | if (vdso32_syscall()) |
| 71 | selected_vdso32 = &vdso_image_32_syscall; |
| 72 | else |
Andy Lutomirski | b67e612 | 2014-03-20 15:01:21 -0700 | [diff] [blame] | 73 | #endif |
Andy Lutomirski | 6f121e5 | 2014-05-05 12:19:34 -0700 | [diff] [blame] | 74 | if (vdso32_sysenter()) |
| 75 | selected_vdso32 = &vdso_image_32_sysenter; |
| 76 | else |
| 77 | selected_vdso32 = &vdso_image_32_int80; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
Andy Lutomirski | 6f121e5 | 2014-05-05 12:19:34 -0700 | [diff] [blame] | 79 | init_vdso_image(selected_vdso32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | return 0; |
| 82 | } |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 83 | |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 84 | #ifdef CONFIG_X86_64 |
| 85 | |
Jiri Slaby | d7a0380 | 2010-06-16 22:30:42 +0200 | [diff] [blame] | 86 | subsys_initcall(sysenter_setup); |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 87 | |
Roland McGrath | a97f52e | 2008-01-30 13:31:55 +0100 | [diff] [blame] | 88 | #ifdef CONFIG_SYSCTL |
| 89 | /* Register vsyscall32 into the ABI table */ |
| 90 | #include <linux/sysctl.h> |
| 91 | |
Joe Perches | f07d91e | 2013-06-13 19:37:33 -0700 | [diff] [blame] | 92 | static struct ctl_table abi_table2[] = { |
Roland McGrath | a97f52e | 2008-01-30 13:31:55 +0100 | [diff] [blame] | 93 | { |
| 94 | .procname = "vsyscall32", |
Andy Lutomirski | 3d7ee96 | 2014-05-05 12:19:32 -0700 | [diff] [blame] | 95 | .data = &vdso32_enabled, |
Roland McGrath | a97f52e | 2008-01-30 13:31:55 +0100 | [diff] [blame] | 96 | .maxlen = sizeof(int), |
| 97 | .mode = 0644, |
| 98 | .proc_handler = proc_dointvec |
| 99 | }, |
| 100 | {} |
| 101 | }; |
| 102 | |
Joe Perches | f07d91e | 2013-06-13 19:37:33 -0700 | [diff] [blame] | 103 | static struct ctl_table abi_root_table2[] = { |
Roland McGrath | a97f52e | 2008-01-30 13:31:55 +0100 | [diff] [blame] | 104 | { |
Roland McGrath | a97f52e | 2008-01-30 13:31:55 +0100 | [diff] [blame] | 105 | .procname = "abi", |
| 106 | .mode = 0555, |
| 107 | .child = abi_table2 |
| 108 | }, |
| 109 | {} |
| 110 | }; |
| 111 | |
| 112 | static __init int ia32_binfmt_init(void) |
| 113 | { |
| 114 | register_sysctl_table(abi_root_table2); |
| 115 | return 0; |
| 116 | } |
| 117 | __initcall(ia32_binfmt_init); |
Andy Lutomirski | a6c19df | 2014-08-08 14:23:40 -0700 | [diff] [blame] | 118 | #endif /* CONFIG_SYSCTL */ |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 119 | |
| 120 | #endif /* CONFIG_X86_64 */ |