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 | * Copyright (C) 2001 Andrea Arcangeli <andrea@suse.de> SuSE |
| 3 | * Copyright 2003 Andi Kleen, SuSE Labs. |
| 4 | * |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 5 | * [ NOTE: this mechanism is now deprecated in favor of the vDSO. ] |
| 6 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Thanks to hpa@transmeta.com for some useful hint. |
| 8 | * Special thanks to Ingo Molnar for his early experience with |
| 9 | * a different vsyscall implementation for Linux/IA32 and for the name. |
| 10 | * |
| 11 | * vsyscall 1 is located at -10Mbyte, vsyscall 2 is located |
| 12 | * at virtual address -10Mbyte+1024bytes etc... There are at max 4 |
| 13 | * vsyscalls. One vsyscall can reserve more than 1 slot to avoid |
| 14 | * jumping out of line if necessary. We cannot add more with this |
| 15 | * mechanism because older kernels won't return -ENOSYS. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 17 | * Note: the concept clashes with user mode linux. UML users should |
| 18 | * use the vDSO. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include <linux/time.h> |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/timer.h> |
| 25 | #include <linux/seqlock.h> |
| 26 | #include <linux/jiffies.h> |
| 27 | #include <linux/sysctl.h> |
Paul Gortmaker | 2957402 | 2011-05-26 12:33:18 -0400 | [diff] [blame] | 28 | #include <linux/topology.h> |
john stultz | 7460ed2 | 2007-02-16 01:28:21 -0800 | [diff] [blame] | 29 | #include <linux/clocksource.h> |
Vojtech Pavlik | c08c820 | 2006-09-26 10:52:28 +0200 | [diff] [blame] | 30 | #include <linux/getcpu.h> |
Andi Kleen | 8c131af | 2006-11-14 16:57:46 +0100 | [diff] [blame] | 31 | #include <linux/cpu.h> |
| 32 | #include <linux/smp.h> |
| 33 | #include <linux/notifier.h> |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 34 | #include <linux/syscalls.h> |
| 35 | #include <linux/ratelimit.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | #include <asm/vsyscall.h> |
| 38 | #include <asm/pgtable.h> |
Andy Lutomirski | c971294 | 2011-07-13 09:24:09 -0400 | [diff] [blame] | 39 | #include <asm/compat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <asm/page.h> |
john stultz | 7460ed2 | 2007-02-16 01:28:21 -0800 | [diff] [blame] | 41 | #include <asm/unistd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <asm/fixmap.h> |
| 43 | #include <asm/errno.h> |
| 44 | #include <asm/io.h> |
Vojtech Pavlik | c08c820 | 2006-09-26 10:52:28 +0200 | [diff] [blame] | 45 | #include <asm/segment.h> |
| 46 | #include <asm/desc.h> |
| 47 | #include <asm/topology.h> |
Andi Kleen | 2aae950 | 2007-07-21 17:10:01 +0200 | [diff] [blame] | 48 | #include <asm/vgtod.h> |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 49 | #include <asm/traps.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Andy Lutomirski | c149a66 | 2011-08-03 09:31:54 -0400 | [diff] [blame] | 51 | #define CREATE_TRACE_POINTS |
| 52 | #include "vsyscall_trace.h" |
| 53 | |
Andy Lutomirski | 8c49d9a | 2011-05-23 09:31:24 -0400 | [diff] [blame] | 54 | DEFINE_VVAR(int, vgetcpu_mode); |
| 55 | DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data) = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | { |
Eric Dumazet | c4dbe54 | 2011-05-24 14:08:08 +0200 | [diff] [blame] | 57 | .lock = __SEQLOCK_UNLOCKED(__vsyscall_gtod_data.lock), |
john stultz | 7460ed2 | 2007-02-16 01:28:21 -0800 | [diff] [blame] | 58 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Andy Lutomirski | 2e57ae0 | 2011-11-07 16:33:41 -0800 | [diff] [blame^] | 60 | static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE; |
Andy Lutomirski | 3ae3665 | 2011-08-10 11:15:32 -0400 | [diff] [blame] | 61 | |
| 62 | static int __init vsyscall_setup(char *str) |
| 63 | { |
| 64 | if (str) { |
| 65 | if (!strcmp("emulate", str)) |
| 66 | vsyscall_mode = EMULATE; |
| 67 | else if (!strcmp("native", str)) |
| 68 | vsyscall_mode = NATIVE; |
| 69 | else if (!strcmp("none", str)) |
| 70 | vsyscall_mode = NONE; |
| 71 | else |
| 72 | return -EINVAL; |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | return -EINVAL; |
| 78 | } |
| 79 | early_param("vsyscall", vsyscall_setup); |
| 80 | |
Tony Breeds | 2c62214 | 2007-10-18 03:04:57 -0700 | [diff] [blame] | 81 | void update_vsyscall_tz(void) |
| 82 | { |
| 83 | unsigned long flags; |
| 84 | |
| 85 | write_seqlock_irqsave(&vsyscall_gtod_data.lock, flags); |
| 86 | /* sys_tz has changed */ |
| 87 | vsyscall_gtod_data.sys_tz = sys_tz; |
| 88 | write_sequnlock_irqrestore(&vsyscall_gtod_data.lock, flags); |
| 89 | } |
| 90 | |
John Stultz | 7615856 | 2010-07-13 17:56:23 -0700 | [diff] [blame] | 91 | void update_vsyscall(struct timespec *wall_time, struct timespec *wtm, |
| 92 | struct clocksource *clock, u32 mult) |
john stultz | 7460ed2 | 2007-02-16 01:28:21 -0800 | [diff] [blame] | 93 | { |
| 94 | unsigned long flags; |
| 95 | |
| 96 | write_seqlock_irqsave(&vsyscall_gtod_data.lock, flags); |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 97 | |
john stultz | 7460ed2 | 2007-02-16 01:28:21 -0800 | [diff] [blame] | 98 | /* copy vsyscall data */ |
Andy Lutomirski | 98d0ac3 | 2011-07-14 06:47:22 -0400 | [diff] [blame] | 99 | vsyscall_gtod_data.clock.vclock_mode = clock->archdata.vclock_mode; |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 100 | vsyscall_gtod_data.clock.cycle_last = clock->cycle_last; |
| 101 | vsyscall_gtod_data.clock.mask = clock->mask; |
| 102 | vsyscall_gtod_data.clock.mult = mult; |
| 103 | vsyscall_gtod_data.clock.shift = clock->shift; |
| 104 | vsyscall_gtod_data.wall_time_sec = wall_time->tv_sec; |
| 105 | vsyscall_gtod_data.wall_time_nsec = wall_time->tv_nsec; |
| 106 | vsyscall_gtod_data.wall_to_monotonic = *wtm; |
| 107 | vsyscall_gtod_data.wall_time_coarse = __current_kernel_time(); |
| 108 | |
john stultz | 7460ed2 | 2007-02-16 01:28:21 -0800 | [diff] [blame] | 109 | write_sequnlock_irqrestore(&vsyscall_gtod_data.lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 112 | static void warn_bad_vsyscall(const char *level, struct pt_regs *regs, |
| 113 | const char *message) |
| 114 | { |
| 115 | static DEFINE_RATELIMIT_STATE(rs, DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST); |
| 116 | struct task_struct *tsk; |
| 117 | |
| 118 | if (!show_unhandled_signals || !__ratelimit(&rs)) |
| 119 | return; |
| 120 | |
| 121 | tsk = current; |
| 122 | |
Andy Lutomirski | c971294 | 2011-07-13 09:24:09 -0400 | [diff] [blame] | 123 | printk("%s%s[%d] %s ip:%lx cs:%lx sp:%lx ax:%lx si:%lx di:%lx\n", |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 124 | level, tsk->comm, task_pid_nr(tsk), |
Andy Lutomirski | 3ae3665 | 2011-08-10 11:15:32 -0400 | [diff] [blame] | 125 | message, regs->ip, regs->cs, |
Andy Lutomirski | c971294 | 2011-07-13 09:24:09 -0400 | [diff] [blame] | 126 | regs->sp, regs->ax, regs->si, regs->di); |
| 127 | } |
| 128 | |
| 129 | static int addr_to_vsyscall_nr(unsigned long addr) |
| 130 | { |
| 131 | int nr; |
| 132 | |
| 133 | if ((addr & ~0xC00UL) != VSYSCALL_START) |
| 134 | return -EINVAL; |
| 135 | |
| 136 | nr = (addr & 0xC00UL) >> 10; |
| 137 | if (nr >= 3) |
| 138 | return -EINVAL; |
| 139 | |
| 140 | return nr; |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 141 | } |
| 142 | |
Andy Lutomirski | 4fc3490 | 2011-11-07 16:33:40 -0800 | [diff] [blame] | 143 | static bool write_ok_or_segv(unsigned long ptr, size_t size) |
| 144 | { |
| 145 | /* |
| 146 | * XXX: if access_ok, get_user, and put_user handled |
| 147 | * sig_on_uaccess_error, this could go away. |
| 148 | */ |
| 149 | |
| 150 | if (!access_ok(VERIFY_WRITE, (void __user *)ptr, size)) { |
| 151 | siginfo_t info; |
| 152 | struct thread_struct *thread = ¤t->thread; |
| 153 | |
| 154 | thread->error_code = 6; /* user fault, no page, write */ |
| 155 | thread->cr2 = ptr; |
| 156 | thread->trap_no = 14; |
| 157 | |
| 158 | memset(&info, 0, sizeof(info)); |
| 159 | info.si_signo = SIGSEGV; |
| 160 | info.si_errno = 0; |
| 161 | info.si_code = SEGV_MAPERR; |
| 162 | info.si_addr = (void __user *)ptr; |
| 163 | |
| 164 | force_sig_info(SIGSEGV, &info, current); |
| 165 | return false; |
| 166 | } else { |
| 167 | return true; |
| 168 | } |
| 169 | } |
| 170 | |
Andy Lutomirski | 3ae3665 | 2011-08-10 11:15:32 -0400 | [diff] [blame] | 171 | bool emulate_vsyscall(struct pt_regs *regs, unsigned long address) |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 172 | { |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 173 | struct task_struct *tsk; |
| 174 | unsigned long caller; |
| 175 | int vsyscall_nr; |
Andy Lutomirski | 4fc3490 | 2011-11-07 16:33:40 -0800 | [diff] [blame] | 176 | int prev_sig_on_uaccess_error; |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 177 | long ret; |
| 178 | |
Andy Lutomirski | 3ae3665 | 2011-08-10 11:15:32 -0400 | [diff] [blame] | 179 | /* |
| 180 | * No point in checking CS -- the only way to get here is a user mode |
| 181 | * trap to a high address, which means that we're in 64-bit user code. |
| 182 | */ |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 183 | |
Andy Lutomirski | 3ae3665 | 2011-08-10 11:15:32 -0400 | [diff] [blame] | 184 | WARN_ON_ONCE(address != regs->ip); |
Andy Lutomirski | c971294 | 2011-07-13 09:24:09 -0400 | [diff] [blame] | 185 | |
Andy Lutomirski | 3ae3665 | 2011-08-10 11:15:32 -0400 | [diff] [blame] | 186 | if (vsyscall_mode == NONE) { |
| 187 | warn_bad_vsyscall(KERN_INFO, regs, |
| 188 | "vsyscall attempted with vsyscall=none"); |
| 189 | return false; |
Andy Lutomirski | c971294 | 2011-07-13 09:24:09 -0400 | [diff] [blame] | 190 | } |
| 191 | |
Andy Lutomirski | 3ae3665 | 2011-08-10 11:15:32 -0400 | [diff] [blame] | 192 | vsyscall_nr = addr_to_vsyscall_nr(address); |
Andy Lutomirski | c149a66 | 2011-08-03 09:31:54 -0400 | [diff] [blame] | 193 | |
| 194 | trace_emulate_vsyscall(vsyscall_nr); |
| 195 | |
Andy Lutomirski | c971294 | 2011-07-13 09:24:09 -0400 | [diff] [blame] | 196 | if (vsyscall_nr < 0) { |
| 197 | warn_bad_vsyscall(KERN_WARNING, regs, |
Andy Lutomirski | 3ae3665 | 2011-08-10 11:15:32 -0400 | [diff] [blame] | 198 | "misaligned vsyscall (exploit attempt or buggy program) -- look up the vsyscall kernel parameter if you need a workaround"); |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 199 | goto sigsegv; |
| 200 | } |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 201 | |
| 202 | if (get_user(caller, (unsigned long __user *)regs->sp) != 0) { |
Andy Lutomirski | 3ae3665 | 2011-08-10 11:15:32 -0400 | [diff] [blame] | 203 | warn_bad_vsyscall(KERN_WARNING, regs, |
| 204 | "vsyscall with bad stack (exploit attempt?)"); |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 205 | goto sigsegv; |
| 206 | } |
| 207 | |
| 208 | tsk = current; |
| 209 | if (seccomp_mode(&tsk->seccomp)) |
| 210 | do_exit(SIGKILL); |
| 211 | |
Andy Lutomirski | 4fc3490 | 2011-11-07 16:33:40 -0800 | [diff] [blame] | 212 | /* |
| 213 | * With a real vsyscall, page faults cause SIGSEGV. We want to |
| 214 | * preserve that behavior to make writing exploits harder. |
| 215 | */ |
| 216 | prev_sig_on_uaccess_error = current_thread_info()->sig_on_uaccess_error; |
| 217 | current_thread_info()->sig_on_uaccess_error = 1; |
| 218 | |
| 219 | /* |
| 220 | * 0 is a valid user pointer (in the access_ok sense) on 32-bit and |
| 221 | * 64-bit, so we don't need to special-case it here. For all the |
| 222 | * vsyscalls, 0 means "don't write anything" not "write it at |
| 223 | * address 0". |
| 224 | */ |
| 225 | ret = -EFAULT; |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 226 | switch (vsyscall_nr) { |
| 227 | case 0: |
Andy Lutomirski | 4fc3490 | 2011-11-07 16:33:40 -0800 | [diff] [blame] | 228 | if (!write_ok_or_segv(regs->di, sizeof(struct timeval)) || |
| 229 | !write_ok_or_segv(regs->si, sizeof(struct timezone))) |
| 230 | break; |
| 231 | |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 232 | ret = sys_gettimeofday( |
| 233 | (struct timeval __user *)regs->di, |
| 234 | (struct timezone __user *)regs->si); |
| 235 | break; |
| 236 | |
| 237 | case 1: |
Andy Lutomirski | 4fc3490 | 2011-11-07 16:33:40 -0800 | [diff] [blame] | 238 | if (!write_ok_or_segv(regs->di, sizeof(time_t))) |
| 239 | break; |
| 240 | |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 241 | ret = sys_time((time_t __user *)regs->di); |
| 242 | break; |
| 243 | |
| 244 | case 2: |
Andy Lutomirski | 4fc3490 | 2011-11-07 16:33:40 -0800 | [diff] [blame] | 245 | if (!write_ok_or_segv(regs->di, sizeof(unsigned)) || |
| 246 | !write_ok_or_segv(regs->si, sizeof(unsigned))) |
| 247 | break; |
| 248 | |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 249 | ret = sys_getcpu((unsigned __user *)regs->di, |
| 250 | (unsigned __user *)regs->si, |
| 251 | 0); |
| 252 | break; |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 253 | } |
| 254 | |
Andy Lutomirski | 4fc3490 | 2011-11-07 16:33:40 -0800 | [diff] [blame] | 255 | current_thread_info()->sig_on_uaccess_error = prev_sig_on_uaccess_error; |
| 256 | |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 257 | if (ret == -EFAULT) { |
Andy Lutomirski | 4fc3490 | 2011-11-07 16:33:40 -0800 | [diff] [blame] | 258 | /* Bad news -- userspace fed a bad pointer to a vsyscall. */ |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 259 | warn_bad_vsyscall(KERN_INFO, regs, |
| 260 | "vsyscall fault (exploit attempt?)"); |
Andy Lutomirski | 4fc3490 | 2011-11-07 16:33:40 -0800 | [diff] [blame] | 261 | |
| 262 | /* |
| 263 | * If we failed to generate a signal for any reason, |
| 264 | * generate one here. (This should be impossible.) |
| 265 | */ |
| 266 | if (WARN_ON_ONCE(!sigismember(&tsk->pending.signal, SIGBUS) && |
| 267 | !sigismember(&tsk->pending.signal, SIGSEGV))) |
| 268 | goto sigsegv; |
| 269 | |
| 270 | return true; /* Don't emulate the ret. */ |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | regs->ax = ret; |
| 274 | |
| 275 | /* Emulate a ret instruction. */ |
| 276 | regs->ip = caller; |
| 277 | regs->sp += 8; |
| 278 | |
Andy Lutomirski | 3ae3665 | 2011-08-10 11:15:32 -0400 | [diff] [blame] | 279 | return true; |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 280 | |
| 281 | sigsegv: |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 282 | force_sig(SIGSEGV, current); |
Andy Lutomirski | 3ae3665 | 2011-08-10 11:15:32 -0400 | [diff] [blame] | 283 | return true; |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | /* |
| 287 | * Assume __initcall executes before all user space. Hopefully kmod |
| 288 | * doesn't violate that. We'll find out if it does. |
john stultz | 7460ed2 | 2007-02-16 01:28:21 -0800 | [diff] [blame] | 289 | */ |
Andi Kleen | 8c131af | 2006-11-14 16:57:46 +0100 | [diff] [blame] | 290 | static void __cpuinit vsyscall_set_cpu(int cpu) |
Vojtech Pavlik | c08c820 | 2006-09-26 10:52:28 +0200 | [diff] [blame] | 291 | { |
Jeremy Fitzhardinge | fc8b8a6 | 2008-06-25 00:19:01 -0400 | [diff] [blame] | 292 | unsigned long d; |
Vojtech Pavlik | c08c820 | 2006-09-26 10:52:28 +0200 | [diff] [blame] | 293 | unsigned long node = 0; |
| 294 | #ifdef CONFIG_NUMA |
Mike Travis | 98c9e27 | 2007-10-17 18:04:39 +0200 | [diff] [blame] | 295 | node = cpu_to_node(cpu); |
Vojtech Pavlik | c08c820 | 2006-09-26 10:52:28 +0200 | [diff] [blame] | 296 | #endif |
Mike Travis | 92cb761 | 2007-10-19 20:35:04 +0200 | [diff] [blame] | 297 | if (cpu_has(&cpu_data(cpu), X86_FEATURE_RDTSCP)) |
Andi Kleen | 8c131af | 2006-11-14 16:57:46 +0100 | [diff] [blame] | 298 | write_rdtscp_aux((node << 12) | cpu); |
Vojtech Pavlik | c08c820 | 2006-09-26 10:52:28 +0200 | [diff] [blame] | 299 | |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 300 | /* |
| 301 | * Store cpu number in limit so that it can be loaded quickly |
| 302 | * in user space in vgetcpu. (12 bits for the CPU and 8 bits for the node) |
| 303 | */ |
Jeremy Fitzhardinge | fc8b8a6 | 2008-06-25 00:19:01 -0400 | [diff] [blame] | 304 | d = 0x0f40000000000ULL; |
| 305 | d |= cpu; |
| 306 | d |= (node & 0xf) << 12; |
| 307 | d |= (node >> 4) << 48; |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 308 | |
Jeremy Fitzhardinge | fc8b8a6 | 2008-06-25 00:19:01 -0400 | [diff] [blame] | 309 | write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_PER_CPU, &d, DESCTYPE_S); |
Vojtech Pavlik | c08c820 | 2006-09-26 10:52:28 +0200 | [diff] [blame] | 310 | } |
| 311 | |
Andi Kleen | 8c131af | 2006-11-14 16:57:46 +0100 | [diff] [blame] | 312 | static void __cpuinit cpu_vsyscall_init(void *arg) |
| 313 | { |
| 314 | /* preemption should be already off */ |
| 315 | vsyscall_set_cpu(raw_smp_processor_id()); |
| 316 | } |
| 317 | |
| 318 | static int __cpuinit |
| 319 | cpu_vsyscall_notifier(struct notifier_block *n, unsigned long action, void *arg) |
| 320 | { |
| 321 | long cpu = (long)arg; |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 322 | |
Rafael J. Wysocki | 8bb7844 | 2007-05-09 02:35:10 -0700 | [diff] [blame] | 323 | if (action == CPU_ONLINE || action == CPU_ONLINE_FROZEN) |
Jens Axboe | 8691e5a | 2008-06-06 11:18:06 +0200 | [diff] [blame] | 324 | smp_call_function_single(cpu, cpu_vsyscall_init, NULL, 1); |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 325 | |
Andi Kleen | 8c131af | 2006-11-14 16:57:46 +0100 | [diff] [blame] | 326 | return NOTIFY_DONE; |
| 327 | } |
| 328 | |
Ingo Molnar | e402644 | 2008-01-30 13:32:39 +0100 | [diff] [blame] | 329 | void __init map_vsyscall(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | { |
Andy Lutomirski | 3ae3665 | 2011-08-10 11:15:32 -0400 | [diff] [blame] | 331 | extern char __vsyscall_page; |
| 332 | unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page); |
Andy Lutomirski | 9fd67b4 | 2011-06-05 13:50:19 -0400 | [diff] [blame] | 333 | extern char __vvar_page; |
| 334 | unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
Andy Lutomirski | 3ae3665 | 2011-08-10 11:15:32 -0400 | [diff] [blame] | 336 | __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, |
| 337 | vsyscall_mode == NATIVE |
| 338 | ? PAGE_KERNEL_VSYSCALL |
| 339 | : PAGE_KERNEL_VVAR); |
| 340 | BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) != |
| 341 | (unsigned long)VSYSCALL_START); |
| 342 | |
Andy Lutomirski | 9fd67b4 | 2011-06-05 13:50:19 -0400 | [diff] [blame] | 343 | __set_fixmap(VVAR_PAGE, physaddr_vvar_page, PAGE_KERNEL_VVAR); |
Andy Lutomirski | 3ae3665 | 2011-08-10 11:15:32 -0400 | [diff] [blame] | 344 | BUILD_BUG_ON((unsigned long)__fix_to_virt(VVAR_PAGE) != |
| 345 | (unsigned long)VVAR_ADDRESS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | static int __init vsyscall_init(void) |
| 349 | { |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 350 | BUG_ON(VSYSCALL_ADDR(0) != __fix_to_virt(VSYSCALL_FIRST_PAGE)); |
| 351 | |
Jens Axboe | 15c8b6c | 2008-05-09 09:39:44 +0200 | [diff] [blame] | 352 | on_each_cpu(cpu_vsyscall_init, NULL, 1); |
Sheng Yang | be43f83 | 2009-12-18 16:48:45 +0800 | [diff] [blame] | 353 | /* notifier priority > KVM */ |
| 354 | hotcpu_notifier(cpu_vsyscall_notifier, 30); |
Andy Lutomirski | 5cec93c | 2011-06-05 13:50:24 -0400 | [diff] [blame] | 355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | return 0; |
| 357 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | __initcall(vsyscall_init); |