1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <linux/kernel.h>
22#include <linux/clocksource.h>
23#include <linux/elf.h>
24#include <linux/err.h>
25#include <linux/errno.h>
26#include <linux/gfp.h>
27#include <linux/mm.h>
28#include <linux/sched.h>
29#include <linux/signal.h>
30#include <linux/slab.h>
31#include <linux/timekeeper_internal.h>
32#include <linux/vmalloc.h>
33
34#include <asm/cacheflush.h>
35#include <asm/signal32.h>
36#include <asm/vdso.h>
37#include <asm/vdso_datapage.h>
38
39extern char vdso_start, vdso_end;
40static unsigned long vdso_pages;
41static struct page **vdso_pagelist;
42
43
44
45
46static union {
47 struct vdso_data data;
48 u8 page[PAGE_SIZE];
49} vdso_data_store __page_aligned_data;
50struct vdso_data *vdso_data = &vdso_data_store.data;
51
52#ifdef CONFIG_COMPAT
53
54
55
56static struct page *vectors_page[1];
57
58static int alloc_vectors_page(void)
59{
60 extern char __kuser_helper_start[], __kuser_helper_end[];
61 int kuser_sz = __kuser_helper_end - __kuser_helper_start;
62 unsigned long vpage;
63
64 vpage = get_zeroed_page(GFP_ATOMIC);
65
66 if (!vpage)
67 return -ENOMEM;
68
69
70 memcpy((void *)vpage + 0x1000 - kuser_sz, __kuser_helper_start,
71 kuser_sz);
72
73
74 memcpy((void *)vpage + AARCH32_KERN_SIGRET_CODE_OFFSET,
75 aarch32_sigret_code, sizeof(aarch32_sigret_code));
76
77 flush_icache_range(vpage, vpage + PAGE_SIZE);
78 vectors_page[0] = virt_to_page(vpage);
79
80 return 0;
81}
82arch_initcall(alloc_vectors_page);
83
84int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp)
85{
86 struct mm_struct *mm = current->mm;
87 unsigned long addr = AARCH32_VECTORS_BASE;
88 int ret;
89
90 down_write(&mm->mmap_sem);
91 current->mm->context.vdso = (void *)addr;
92
93
94 ret = install_special_mapping(mm, addr, PAGE_SIZE,
95 VM_READ|VM_EXEC|VM_MAYREAD|VM_MAYEXEC,
96 vectors_page);
97
98 up_write(&mm->mmap_sem);
99
100 return ret;
101}
102#endif
103
104static int __init vdso_init(void)
105{
106 struct page *pg;
107 char *vbase;
108 int i, ret = 0;
109
110 vdso_pages = (&vdso_end - &vdso_start) >> PAGE_SHIFT;
111 pr_info("vdso: %ld pages (%ld code, %ld data) at base %p\n",
112 vdso_pages + 1, vdso_pages, 1L, &vdso_start);
113
114
115 vdso_pagelist = kzalloc(sizeof(struct page *) * (vdso_pages + 1),
116 GFP_KERNEL);
117 if (vdso_pagelist == NULL) {
118 pr_err("Failed to allocate vDSO pagelist!\n");
119 return -ENOMEM;
120 }
121
122
123 for (i = 0; i < vdso_pages; i++) {
124 pg = virt_to_page(&vdso_start + i*PAGE_SIZE);
125 ClearPageReserved(pg);
126 get_page(pg);
127 vdso_pagelist[i] = pg;
128 }
129
130
131 vbase = vmap(vdso_pagelist, 1, 0, PAGE_KERNEL);
132 if (vbase == NULL) {
133 pr_err("Failed to map vDSO pagelist!\n");
134 return -ENOMEM;
135 } else if (memcmp(vbase, "\177ELF", 4)) {
136 pr_err("vDSO is not a valid ELF object!\n");
137 ret = -EINVAL;
138 goto unmap;
139 }
140
141
142 pg = virt_to_page(vdso_data);
143 get_page(pg);
144 vdso_pagelist[i] = pg;
145
146unmap:
147 vunmap(vbase);
148 return ret;
149}
150arch_initcall(vdso_init);
151
152int arch_setup_additional_pages(struct linux_binprm *bprm,
153 int uses_interp)
154{
155 struct mm_struct *mm = current->mm;
156 unsigned long vdso_base, vdso_mapping_len;
157 int ret;
158
159
160 vdso_mapping_len = (vdso_pages + 1) << PAGE_SHIFT;
161
162 down_write(&mm->mmap_sem);
163 vdso_base = get_unmapped_area(NULL, 0, vdso_mapping_len, 0, 0);
164 if (IS_ERR_VALUE(vdso_base)) {
165 ret = vdso_base;
166 goto up_fail;
167 }
168 mm->context.vdso = (void *)vdso_base;
169
170 ret = install_special_mapping(mm, vdso_base, vdso_mapping_len,
171 VM_READ|VM_EXEC|
172 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
173 vdso_pagelist);
174 if (ret) {
175 mm->context.vdso = NULL;
176 goto up_fail;
177 }
178
179up_fail:
180 up_write(&mm->mmap_sem);
181
182 return ret;
183}
184
185const char *arch_vma_name(struct vm_area_struct *vma)
186{
187
188
189
190
191
192
193 if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso) {
194#ifdef CONFIG_COMPAT
195 if (vma->vm_start == AARCH32_VECTORS_BASE)
196 return "[vectors]";
197#endif
198 return "[vdso]";
199 }
200
201 return NULL;
202}
203
204
205
206
207
208int in_gate_area_no_mm(unsigned long addr)
209{
210 return 0;
211}
212
213int in_gate_area(struct mm_struct *mm, unsigned long addr)
214{
215 return 0;
216}
217
218struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
219{
220 return NULL;
221}
222
223
224
225
226void update_vsyscall(struct timekeeper *tk)
227{
228 struct timespec xtime_coarse;
229 u32 use_syscall = strcmp(tk->clock->name, "arch_sys_counter");
230
231 ++vdso_data->tb_seq_count;
232 smp_wmb();
233
234 xtime_coarse = __current_kernel_time();
235 vdso_data->use_syscall = use_syscall;
236 vdso_data->xtime_coarse_sec = xtime_coarse.tv_sec;
237 vdso_data->xtime_coarse_nsec = xtime_coarse.tv_nsec;
238
239 if (!use_syscall) {
240 vdso_data->cs_cycle_last = tk->clock->cycle_last;
241 vdso_data->xtime_clock_sec = tk->xtime_sec;
242 vdso_data->xtime_clock_nsec = tk->xtime_nsec >> tk->shift;
243 vdso_data->cs_mult = tk->mult;
244 vdso_data->cs_shift = tk->shift;
245 vdso_data->wtm_clock_sec = tk->wall_to_monotonic.tv_sec;
246 vdso_data->wtm_clock_nsec = tk->wall_to_monotonic.tv_nsec;
247 }
248
249 smp_wmb();
250 ++vdso_data->tb_seq_count;
251}
252
253void update_vsyscall_tz(void)
254{
255 ++vdso_data->tb_seq_count;
256 smp_wmb();
257 vdso_data->tz_minuteswest = sys_tz.tz_minuteswest;
258 vdso_data->tz_dsttime = sys_tz.tz_dsttime;
259 smp_wmb();
260 ++vdso_data->tb_seq_count;
261}
262