[S390] vdso: compile fix
[deliverable/linux.git] / arch / s390 / kernel / vdso.c
CommitLineData
b020632e
MS
1/*
2 * vdso setup for s390
3 *
4 * Copyright IBM Corp. 2008
5 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License (version 2 only)
9 * as published by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/errno.h>
14#include <linux/sched.h>
15#include <linux/kernel.h>
16#include <linux/mm.h>
17#include <linux/smp.h>
18#include <linux/stddef.h>
19#include <linux/unistd.h>
20#include <linux/slab.h>
21#include <linux/user.h>
22#include <linux/elf.h>
23#include <linux/security.h>
24#include <linux/bootmem.h>
25
26#include <asm/pgtable.h>
27#include <asm/system.h>
28#include <asm/processor.h>
29#include <asm/mmu.h>
30#include <asm/mmu_context.h>
31#include <asm/sections.h>
32#include <asm/vdso.h>
33
b020632e
MS
34#if defined(CONFIG_32BIT) || defined(CONFIG_COMPAT)
35extern char vdso32_start, vdso32_end;
36static void *vdso32_kbase = &vdso32_start;
37static unsigned int vdso32_pages;
38static struct page **vdso32_pagelist;
39#endif
40
41#ifdef CONFIG_64BIT
42extern char vdso64_start, vdso64_end;
43static void *vdso64_kbase = &vdso64_start;
44static unsigned int vdso64_pages;
45static struct page **vdso64_pagelist;
46#endif /* CONFIG_64BIT */
47
48/*
49 * Should the kernel map a VDSO page into processes and pass its
50 * address down to glibc upon exec()?
51 */
52unsigned int __read_mostly vdso_enabled = 1;
53
54static int __init vdso_setup(char *s)
55{
56 vdso_enabled = simple_strtoul(s, NULL, 0);
57 return 1;
58}
59__setup("vdso=", vdso_setup);
60
61/*
62 * The vdso data page
63 */
64static union {
65 struct vdso_data data;
66 u8 page[PAGE_SIZE];
67} vdso_data_store __attribute__((__section__(".data.page_aligned")));
68struct vdso_data *vdso_data = &vdso_data_store.data;
69
c742b31c
MS
70/*
71 * Setup vdso data page.
72 */
73static void vdso_init_data(struct vdso_data *vd)
74{
75 unsigned int facility_list;
76
77 facility_list = stfl();
78 vd->ectg_available = switch_amode && (facility_list & 1);
79}
80
81#ifdef CONFIG_64BIT
82/*
83 * Setup per cpu vdso data page.
84 */
85static void vdso_init_per_cpu_data(int cpu, struct vdso_per_cpu_data *vpcd)
86{
87}
88
89/*
90 * Allocate/free per cpu vdso data.
91 */
92#ifdef CONFIG_64BIT
93#define SEGMENT_ORDER 2
94#else
95#define SEGMENT_ORDER 1
96#endif
97
98int vdso_alloc_per_cpu(int cpu, struct _lowcore *lowcore)
99{
100 unsigned long segment_table, page_table, page_frame;
101 u32 *psal, *aste;
102 int i;
103
104 lowcore->vdso_per_cpu_data = __LC_PASTE;
105
106 if (!switch_amode || !vdso_enabled)
107 return 0;
108
109 segment_table = __get_free_pages(GFP_KERNEL, SEGMENT_ORDER);
110 page_table = get_zeroed_page(GFP_KERNEL | GFP_DMA);
111 page_frame = get_zeroed_page(GFP_KERNEL);
112 if (!segment_table || !page_table || !page_frame)
113 goto out;
114
115 clear_table((unsigned long *) segment_table, _SEGMENT_ENTRY_EMPTY,
116 PAGE_SIZE << SEGMENT_ORDER);
117 clear_table((unsigned long *) page_table, _PAGE_TYPE_EMPTY,
118 256*sizeof(unsigned long));
119
120 *(unsigned long *) segment_table = _SEGMENT_ENTRY + page_table;
121 *(unsigned long *) page_table = _PAGE_RO + page_frame;
122
123 psal = (u32 *) (page_table + 256*sizeof(unsigned long));
124 aste = psal + 32;
125
126 for (i = 4; i < 32; i += 4)
127 psal[i] = 0x80000000;
128
129 lowcore->paste[4] = (u32)(addr_t) psal;
130 psal[0] = 0x20000000;
131 psal[2] = (u32)(addr_t) aste;
132 *(unsigned long *) (aste + 2) = segment_table +
133 _ASCE_TABLE_LENGTH + _ASCE_USER_BITS + _ASCE_TYPE_SEGMENT;
134 aste[4] = (u32)(addr_t) psal;
135 lowcore->vdso_per_cpu_data = page_frame;
136
137 vdso_init_per_cpu_data(cpu, (struct vdso_per_cpu_data *) page_frame);
138 return 0;
139
140out:
141 free_page(page_frame);
142 free_page(page_table);
143 free_pages(segment_table, SEGMENT_ORDER);
144 return -ENOMEM;
145}
146
147#ifdef CONFIG_HOTPLUG_CPU
148void vdso_free_per_cpu(int cpu, struct _lowcore *lowcore)
149{
150 unsigned long segment_table, page_table, page_frame;
151 u32 *psal, *aste;
152
153 if (!switch_amode || !vdso_enabled)
154 return;
155
156 psal = (u32 *)(addr_t) lowcore->paste[4];
157 aste = (u32 *)(addr_t) psal[2];
158 segment_table = *(unsigned long *)(aste + 2) & PAGE_MASK;
159 page_table = *(unsigned long *) segment_table;
160 page_frame = *(unsigned long *) page_table;
161
162 free_page(page_frame);
163 free_page(page_table);
164 free_pages(segment_table, SEGMENT_ORDER);
165}
166#endif /* CONFIG_HOTPLUG_CPU */
167
168static void __vdso_init_cr5(void *dummy)
169{
170 unsigned long cr5;
171
172 cr5 = offsetof(struct _lowcore, paste);
173 __ctl_load(cr5, 5, 5);
174}
175
176static void vdso_init_cr5(void)
177{
178 if (switch_amode && vdso_enabled)
179 on_each_cpu(__vdso_init_cr5, NULL, 1);
180}
181#endif /* CONFIG_64BIT */
182
b020632e
MS
183/*
184 * This is called from binfmt_elf, we create the special vma for the
185 * vDSO and insert it into the mm struct tree
186 */
187int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
188{
189 struct mm_struct *mm = current->mm;
190 struct page **vdso_pagelist;
191 unsigned long vdso_pages;
192 unsigned long vdso_base;
193 int rc;
194
195 if (!vdso_enabled)
196 return 0;
197 /*
198 * Only map the vdso for dynamically linked elf binaries.
199 */
200 if (!uses_interp)
201 return 0;
202
203 vdso_base = mm->mmap_base;
204#ifdef CONFIG_64BIT
205 vdso_pagelist = vdso64_pagelist;
206 vdso_pages = vdso64_pages;
207#ifdef CONFIG_COMPAT
208 if (test_thread_flag(TIF_31BIT)) {
209 vdso_pagelist = vdso32_pagelist;
210 vdso_pages = vdso32_pages;
211 }
212#endif
213#else
214 vdso_pagelist = vdso32_pagelist;
215 vdso_pages = vdso32_pages;
216#endif
217
218 /*
219 * vDSO has a problem and was disabled, just don't "enable" it for
220 * the process
221 */
222 if (vdso_pages == 0)
223 return 0;
224
225 current->mm->context.vdso_base = 0;
226
227 /*
228 * pick a base address for the vDSO in process space. We try to put
229 * it at vdso_base which is the "natural" base for it, but we might
230 * fail and end up putting it elsewhere.
231 */
232 down_write(&mm->mmap_sem);
233 vdso_base = get_unmapped_area(NULL, vdso_base,
234 vdso_pages << PAGE_SHIFT, 0, 0);
235 if (IS_ERR_VALUE(vdso_base)) {
236 rc = vdso_base;
237 goto out_up;
238 }
239
240 /*
241 * our vma flags don't have VM_WRITE so by default, the process
242 * isn't allowed to write those pages.
243 * gdb can break that with ptrace interface, and thus trigger COW
244 * on those pages but it's then your responsibility to never do that
245 * on the "data" page of the vDSO or you'll stop getting kernel
246 * updates and your nice userland gettimeofday will be totally dead.
247 * It's fine to use that for setting breakpoints in the vDSO code
248 * pages though
249 *
250 * Make sure the vDSO gets into every core dump.
251 * Dumping its contents makes post-mortem fully interpretable later
252 * without matching up the same kernel and hardware config to see
253 * what PC values meant.
254 */
255 rc = install_special_mapping(mm, vdso_base, vdso_pages << PAGE_SHIFT,
256 VM_READ|VM_EXEC|
257 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
258 VM_ALWAYSDUMP,
259 vdso_pagelist);
260 if (rc)
261 goto out_up;
262
263 /* Put vDSO base into mm struct */
264 current->mm->context.vdso_base = vdso_base;
265
266 up_write(&mm->mmap_sem);
267 return 0;
268
269out_up:
270 up_write(&mm->mmap_sem);
271 return rc;
272}
273
274const char *arch_vma_name(struct vm_area_struct *vma)
275{
276 if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso_base)
277 return "[vdso]";
278 return NULL;
279}
280
281static int __init vdso_init(void)
282{
283 int i;
284
c742b31c
MS
285 if (!vdso_enabled)
286 return 0;
287 vdso_init_data(vdso_data);
b020632e
MS
288#if defined(CONFIG_32BIT) || defined(CONFIG_COMPAT)
289 /* Calculate the size of the 32 bit vDSO */
290 vdso32_pages = ((&vdso32_end - &vdso32_start
291 + PAGE_SIZE - 1) >> PAGE_SHIFT) + 1;
292
293 /* Make sure pages are in the correct state */
294 vdso32_pagelist = kzalloc(sizeof(struct page *) * (vdso32_pages + 1),
295 GFP_KERNEL);
296 BUG_ON(vdso32_pagelist == NULL);
297 for (i = 0; i < vdso32_pages - 1; i++) {
298 struct page *pg = virt_to_page(vdso32_kbase + i*PAGE_SIZE);
299 ClearPageReserved(pg);
300 get_page(pg);
301 vdso32_pagelist[i] = pg;
302 }
303 vdso32_pagelist[vdso32_pages - 1] = virt_to_page(vdso_data);
304 vdso32_pagelist[vdso32_pages] = NULL;
305#endif
306
307#ifdef CONFIG_64BIT
308 /* Calculate the size of the 64 bit vDSO */
309 vdso64_pages = ((&vdso64_end - &vdso64_start
310 + PAGE_SIZE - 1) >> PAGE_SHIFT) + 1;
311
312 /* Make sure pages are in the correct state */
313 vdso64_pagelist = kzalloc(sizeof(struct page *) * (vdso64_pages + 1),
314 GFP_KERNEL);
315 BUG_ON(vdso64_pagelist == NULL);
316 for (i = 0; i < vdso64_pages - 1; i++) {
317 struct page *pg = virt_to_page(vdso64_kbase + i*PAGE_SIZE);
318 ClearPageReserved(pg);
319 get_page(pg);
320 vdso64_pagelist[i] = pg;
321 }
322 vdso64_pagelist[vdso64_pages - 1] = virt_to_page(vdso_data);
323 vdso64_pagelist[vdso64_pages] = NULL;
c742b31c 324#ifndef CONFIG_SMP
81ffa041
HC
325 if (vdso_alloc_per_cpu(0, &S390_lowcore))
326 BUG();
c742b31c
MS
327#endif
328 vdso_init_cr5();
b020632e
MS
329#endif /* CONFIG_64BIT */
330
331 get_page(virt_to_page(vdso_data));
332
333 smp_wmb();
334
335 return 0;
336}
337arch_initcall(vdso_init);
338
339int in_gate_area_no_task(unsigned long addr)
340{
341 return 0;
342}
343
344int in_gate_area(struct task_struct *task, unsigned long addr)
345{
346 return 0;
347}
348
349struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
350{
351 return NULL;
352}
This page took 0.049231 seconds and 5 git commands to generate.