Loading...
1/*
2 * Copyright (C) 2015 Imagination Technologies
3 * Author: Alex Smith <alex.smith@imgtec.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 */
10
11#include <linux/binfmts.h>
12#include <linux/elf.h>
13#include <linux/err.h>
14#include <linux/init.h>
15#include <linux/ioport.h>
16#include <linux/irqchip/mips-gic.h>
17#include <linux/mm.h>
18#include <linux/sched.h>
19#include <linux/slab.h>
20#include <linux/timekeeper_internal.h>
21
22#include <asm/abi.h>
23#include <asm/vdso.h>
24
25/* Kernel-provided data used by the VDSO. */
26static union mips_vdso_data vdso_data __page_aligned_data;
27
28/*
29 * Mapping for the VDSO data/GIC pages. The real pages are mapped manually, as
30 * what we map and where within the area they are mapped is determined at
31 * runtime.
32 */
33static struct page *no_pages[] = { NULL };
34static struct vm_special_mapping vdso_vvar_mapping = {
35 .name = "[vvar]",
36 .pages = no_pages,
37};
38
39static void __init init_vdso_image(struct mips_vdso_image *image)
40{
41 unsigned long num_pages, i;
42
43 BUG_ON(!PAGE_ALIGNED(image->data));
44 BUG_ON(!PAGE_ALIGNED(image->size));
45
46 num_pages = image->size / PAGE_SIZE;
47
48 for (i = 0; i < num_pages; i++) {
49 image->mapping.pages[i] =
50 virt_to_page(image->data + (i * PAGE_SIZE));
51 }
52}
53
54static int __init init_vdso(void)
55{
56 init_vdso_image(&vdso_image);
57
58#ifdef CONFIG_MIPS32_O32
59 init_vdso_image(&vdso_image_o32);
60#endif
61
62#ifdef CONFIG_MIPS32_N32
63 init_vdso_image(&vdso_image_n32);
64#endif
65
66 return 0;
67}
68subsys_initcall(init_vdso);
69
70void update_vsyscall(struct timekeeper *tk)
71{
72 vdso_data_write_begin(&vdso_data);
73
74 vdso_data.xtime_sec = tk->xtime_sec;
75 vdso_data.xtime_nsec = tk->tkr_mono.xtime_nsec;
76 vdso_data.wall_to_mono_sec = tk->wall_to_monotonic.tv_sec;
77 vdso_data.wall_to_mono_nsec = tk->wall_to_monotonic.tv_nsec;
78 vdso_data.cs_shift = tk->tkr_mono.shift;
79
80 vdso_data.clock_mode = tk->tkr_mono.clock->archdata.vdso_clock_mode;
81 if (vdso_data.clock_mode != VDSO_CLOCK_NONE) {
82 vdso_data.cs_mult = tk->tkr_mono.mult;
83 vdso_data.cs_cycle_last = tk->tkr_mono.cycle_last;
84 vdso_data.cs_mask = tk->tkr_mono.mask;
85 }
86
87 vdso_data_write_end(&vdso_data);
88}
89
90void update_vsyscall_tz(void)
91{
92 if (vdso_data.clock_mode != VDSO_CLOCK_NONE) {
93 vdso_data.tz_minuteswest = sys_tz.tz_minuteswest;
94 vdso_data.tz_dsttime = sys_tz.tz_dsttime;
95 }
96}
97
98int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
99{
100 struct mips_vdso_image *image = current->thread.abi->vdso;
101 struct mm_struct *mm = current->mm;
102 unsigned long gic_size, vvar_size, size, base, data_addr, vdso_addr;
103 struct vm_area_struct *vma;
104 struct resource gic_res;
105 int ret;
106
107 down_write(&mm->mmap_sem);
108
109 /*
110 * Determine total area size. This includes the VDSO data itself, the
111 * data page, and the GIC user page if present. Always create a mapping
112 * for the GIC user area if the GIC is present regardless of whether it
113 * is the current clocksource, in case it comes into use later on. We
114 * only map a page even though the total area is 64K, as we only need
115 * the counter registers at the start.
116 */
117 gic_size = gic_present ? PAGE_SIZE : 0;
118 vvar_size = gic_size + PAGE_SIZE;
119 size = vvar_size + image->size;
120
121 base = get_unmapped_area(NULL, 0, size, 0, 0);
122 if (IS_ERR_VALUE(base)) {
123 ret = base;
124 goto out;
125 }
126
127 data_addr = base + gic_size;
128 vdso_addr = data_addr + PAGE_SIZE;
129
130 vma = _install_special_mapping(mm, base, vvar_size,
131 VM_READ | VM_MAYREAD,
132 &vdso_vvar_mapping);
133 if (IS_ERR(vma)) {
134 ret = PTR_ERR(vma);
135 goto out;
136 }
137
138 /* Map GIC user page. */
139 if (gic_size) {
140 ret = gic_get_usm_range(&gic_res);
141 if (ret)
142 goto out;
143
144 ret = io_remap_pfn_range(vma, base,
145 gic_res.start >> PAGE_SHIFT,
146 gic_size,
147 pgprot_noncached(PAGE_READONLY));
148 if (ret)
149 goto out;
150 }
151
152 /* Map data page. */
153 ret = remap_pfn_range(vma, data_addr,
154 virt_to_phys(&vdso_data) >> PAGE_SHIFT,
155 PAGE_SIZE, PAGE_READONLY);
156 if (ret)
157 goto out;
158
159 /* Map VDSO image. */
160 vma = _install_special_mapping(mm, vdso_addr, image->size,
161 VM_READ | VM_EXEC |
162 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
163 &image->mapping);
164 if (IS_ERR(vma)) {
165 ret = PTR_ERR(vma);
166 goto out;
167 }
168
169 mm->context.vdso = (void *)vdso_addr;
170 ret = 0;
171
172out:
173 up_write(&mm->mmap_sem);
174 return ret;
175}
1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2009, 2010 Cavium Networks, Inc.
7 */
8
9
10#include <linux/kernel.h>
11#include <linux/err.h>
12#include <linux/sched.h>
13#include <linux/mm.h>
14#include <linux/init.h>
15#include <linux/binfmts.h>
16#include <linux/elf.h>
17#include <linux/vmalloc.h>
18#include <linux/unistd.h>
19
20#include <asm/vdso.h>
21#include <asm/uasm.h>
22
23/*
24 * Including <asm/unistd.h> would give use the 64-bit syscall numbers ...
25 */
26#define __NR_O32_sigreturn 4119
27#define __NR_O32_rt_sigreturn 4193
28#define __NR_N32_rt_sigreturn 6211
29
30static struct page *vdso_page;
31
32static void __init install_trampoline(u32 *tramp, unsigned int sigreturn)
33{
34 uasm_i_addiu(&tramp, 2, 0, sigreturn); /* li v0, sigreturn */
35 uasm_i_syscall(&tramp, 0);
36}
37
38static int __init init_vdso(void)
39{
40 struct mips_vdso *vdso;
41
42 vdso_page = alloc_page(GFP_KERNEL);
43 if (!vdso_page)
44 panic("Cannot allocate vdso");
45
46 vdso = vmap(&vdso_page, 1, 0, PAGE_KERNEL);
47 if (!vdso)
48 panic("Cannot map vdso");
49 clear_page(vdso);
50
51 install_trampoline(vdso->rt_signal_trampoline, __NR_rt_sigreturn);
52#ifdef CONFIG_32BIT
53 install_trampoline(vdso->signal_trampoline, __NR_sigreturn);
54#else
55 install_trampoline(vdso->n32_rt_signal_trampoline,
56 __NR_N32_rt_sigreturn);
57 install_trampoline(vdso->o32_signal_trampoline, __NR_O32_sigreturn);
58 install_trampoline(vdso->o32_rt_signal_trampoline,
59 __NR_O32_rt_sigreturn);
60#endif
61
62 vunmap(vdso);
63
64 return 0;
65}
66subsys_initcall(init_vdso);
67
68static unsigned long vdso_addr(unsigned long start)
69{
70 return STACK_TOP;
71}
72
73int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
74{
75 int ret;
76 unsigned long addr;
77 struct mm_struct *mm = current->mm;
78
79 down_write(&mm->mmap_sem);
80
81 addr = vdso_addr(mm->start_stack);
82
83 addr = get_unmapped_area(NULL, addr, PAGE_SIZE, 0, 0);
84 if (IS_ERR_VALUE(addr)) {
85 ret = addr;
86 goto up_fail;
87 }
88
89 ret = install_special_mapping(mm, addr, PAGE_SIZE,
90 VM_READ|VM_EXEC|
91 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
92 &vdso_page);
93
94 if (ret)
95 goto up_fail;
96
97 mm->context.vdso = (void *)addr;
98
99up_fail:
100 up_write(&mm->mmap_sem);
101 return ret;
102}
103
104const char *arch_vma_name(struct vm_area_struct *vma)
105{
106 if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
107 return "[vdso]";
108 return NULL;
109}