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 extern char __aarch32_sigret_code_start[], __aarch32_sigret_code_end[];
62
63 int kuser_sz = __kuser_helper_end - __kuser_helper_start;
64 int sigret_sz = __aarch32_sigret_code_end - __aarch32_sigret_code_start;
65 unsigned long vpage;
66
67 vpage = get_zeroed_page(GFP_ATOMIC);
68
69 if (!vpage)
70 return -ENOMEM;
71
72
73 memcpy((void *)vpage + 0x1000 - kuser_sz, __kuser_helper_start,
74 kuser_sz);
75
76
77 memcpy((void *)vpage + AARCH32_KERN_SIGRET_CODE_OFFSET,
78 __aarch32_sigret_code_start, sigret_sz);
79
80 flush_icache_range(vpage, vpage + PAGE_SIZE);
81 vectors_page[0] = virt_to_page(vpage);
82
83 return 0;
84}
85arch_initcall(alloc_vectors_page);
86
87int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp)
88{
89 struct mm_struct *mm = current->mm;
90 unsigned long addr = AARCH32_VECTORS_BASE;
91 int ret;
92
93 down_write(&mm->mmap_sem);
94 current->mm->context.vdso = (void *)addr;
95
96
97 ret = install_special_mapping(mm, addr, PAGE_SIZE,
98 VM_READ|VM_EXEC|VM_MAYREAD|VM_MAYEXEC,
99 vectors_page);
100
101 up_write(&mm->mmap_sem);
102
103 return ret;
104}
105#endif
106
107static int __init vdso_init(void)
108{
109 int i;
110
111 if (memcmp(&vdso_start, "\177ELF", 4)) {
112 pr_err("vDSO is not a valid ELF object!\n");
113 return -EINVAL;
114 }
115
116 vdso_pages = (&vdso_end - &vdso_start) >> PAGE_SHIFT;
117 pr_info("vdso: %ld pages (%ld code, %ld data) at base %p\n",
118 vdso_pages + 1, vdso_pages, 1L, &vdso_start);
119
120
121 vdso_pagelist = kcalloc(vdso_pages + 1, sizeof(struct page *),
122 GFP_KERNEL);
123 if (vdso_pagelist == NULL)
124 return -ENOMEM;
125
126
127 for (i = 0; i < vdso_pages; i++)
128 vdso_pagelist[i] = virt_to_page(&vdso_start + i * PAGE_SIZE);
129
130
131 vdso_pagelist[i] = virt_to_page(vdso_data);
132
133 return 0;
134}
135arch_initcall(vdso_init);
136
137int arch_setup_additional_pages(struct linux_binprm *bprm,
138 int uses_interp)
139{
140 struct mm_struct *mm = current->mm;
141 unsigned long vdso_base, vdso_mapping_len;
142 int ret;
143
144
145 vdso_mapping_len = (vdso_pages + 1) << PAGE_SHIFT;
146
147 down_write(&mm->mmap_sem);
148 vdso_base = get_unmapped_area(NULL, 0, vdso_mapping_len, 0, 0);
149 if (IS_ERR_VALUE(vdso_base)) {
150 ret = vdso_base;
151 goto up_fail;
152 }
153 mm->context.vdso = (void *)vdso_base;
154
155 ret = install_special_mapping(mm, vdso_base, vdso_mapping_len,
156 VM_READ|VM_EXEC|
157 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
158 vdso_pagelist);
159 if (ret) {
160 mm->context.vdso = NULL;
161 goto up_fail;
162 }
163
164up_fail:
165 up_write(&mm->mmap_sem);
166
167 return ret;
168}
169
170const char *arch_vma_name(struct vm_area_struct *vma)
171{
172
173
174
175
176
177
178 if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso) {
179#ifdef CONFIG_COMPAT
180 if (vma->vm_start == AARCH32_VECTORS_BASE)
181 return "[vectors]";
182#endif
183 return "[vdso]";
184 }
185
186 return NULL;
187}
188
189
190
191
192
193int in_gate_area_no_mm(unsigned long addr)
194{
195 return 0;
196}
197
198int in_gate_area(struct mm_struct *mm, unsigned long addr)
199{
200 return 0;
201}
202
203struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
204{
205 return NULL;
206}
207
208
209
210
211void update_vsyscall(struct timekeeper *tk)
212{
213 struct timespec xtime_coarse;
214 u32 use_syscall = strcmp(tk->clock->name, "arch_sys_counter");
215
216 ++vdso_data->tb_seq_count;
217 smp_wmb();
218
219 xtime_coarse = __current_kernel_time();
220 vdso_data->use_syscall = use_syscall;
221 vdso_data->xtime_coarse_sec = xtime_coarse.tv_sec;
222 vdso_data->xtime_coarse_nsec = xtime_coarse.tv_nsec;
223 vdso_data->wtm_clock_sec = tk->wall_to_monotonic.tv_sec;
224 vdso_data->wtm_clock_nsec = tk->wall_to_monotonic.tv_nsec;
225
226 if (!use_syscall) {
227 vdso_data->cs_cycle_last = tk->clock->cycle_last;
228 vdso_data->xtime_clock_sec = tk->xtime_sec;
229 vdso_data->xtime_clock_nsec = tk->xtime_nsec;
230 vdso_data->cs_mult = tk->mult;
231 vdso_data->cs_shift = tk->shift;
232 }
233
234 smp_wmb();
235 ++vdso_data->tb_seq_count;
236}
237
238void update_vsyscall_tz(void)
239{
240 vdso_data->tz_minuteswest = sys_tz.tz_minuteswest;
241 vdso_data->tz_dsttime = sys_tz.tz_dsttime;
242}
243