fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / arch / powerpc / kernel / vdso.c
1 /*
2  *    Copyright (C) 2004 Benjamin Herrenschmidt, IBM Corp.
3  *                       <benh@kernel.crashing.org>
4  *
5  *  This program is free software; you can redistribute it and/or
6  *  modify it under the terms of the GNU General Public License
7  *  as published by the Free Software Foundation; either version
8  *  2 of the License, or (at your option) any later version.
9  */
10
11 #include <linux/module.h>
12 #include <linux/errno.h>
13 #include <linux/sched.h>
14 #include <linux/kernel.h>
15 #include <linux/mm.h>
16 #include <linux/smp.h>
17 #include <linux/smp_lock.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 #include <linux/vs_memory.h>
26
27 #include <asm/pgtable.h>
28 #include <asm/system.h>
29 #include <asm/processor.h>
30 #include <asm/mmu.h>
31 #include <asm/mmu_context.h>
32 #include <asm/lmb.h>
33 #include <asm/machdep.h>
34 #include <asm/cputable.h>
35 #include <asm/sections.h>
36 #include <asm/firmware.h>
37 #include <asm/vdso.h>
38 #include <asm/vdso_datapage.h>
39
40 #include "setup.h"
41
42 #undef DEBUG
43
44 #ifdef DEBUG
45 #define DBG(fmt...) printk(fmt)
46 #else
47 #define DBG(fmt...)
48 #endif
49
50 /* Max supported size for symbol names */
51 #define MAX_SYMNAME     64
52
53 extern char vdso32_start, vdso32_end;
54 static void *vdso32_kbase = &vdso32_start;
55 unsigned int vdso32_pages;
56 unsigned long vdso32_sigtramp;
57 unsigned long vdso32_rt_sigtramp;
58
59 #ifdef CONFIG_PPC64
60 extern char vdso64_start, vdso64_end;
61 static void *vdso64_kbase = &vdso64_start;
62 unsigned int vdso64_pages;
63 unsigned long vdso64_rt_sigtramp;
64 #endif /* CONFIG_PPC64 */
65
66 /*
67  * The vdso data page (aka. systemcfg for old ppc64 fans) is here.
68  * Once the early boot kernel code no longer needs to muck around
69  * with it, it will become dynamically allocated
70  */
71 static union {
72         struct vdso_data        data;
73         u8                      page[PAGE_SIZE];
74 } vdso_data_store __attribute__((__section__(".data.page_aligned")));
75 struct vdso_data *vdso_data = &vdso_data_store.data;
76
77 /* Format of the patch table */
78 struct vdso_patch_def
79 {
80         unsigned long   ftr_mask, ftr_value;
81         const char      *gen_name;
82         const char      *fix_name;
83 };
84
85 /* Table of functions to patch based on the CPU type/revision
86  *
87  * Currently, we only change sync_dicache to do nothing on processors
88  * with a coherent icache
89  */
90 static struct vdso_patch_def vdso_patches[] = {
91         {
92                 CPU_FTR_COHERENT_ICACHE, CPU_FTR_COHERENT_ICACHE,
93                 "__kernel_sync_dicache", "__kernel_sync_dicache_p5"
94         },
95         {
96                 CPU_FTR_USE_TB, 0,
97                 "__kernel_gettimeofday", NULL
98         },
99 };
100
101 /*
102  * Some infos carried around for each of them during parsing at
103  * boot time.
104  */
105 struct lib32_elfinfo
106 {
107         Elf32_Ehdr      *hdr;           /* ptr to ELF */
108         Elf32_Sym       *dynsym;        /* ptr to .dynsym section */
109         unsigned long   dynsymsize;     /* size of .dynsym section */
110         char            *dynstr;        /* ptr to .dynstr section */
111         unsigned long   text;           /* offset of .text section in .so */
112 };
113
114 struct lib64_elfinfo
115 {
116         Elf64_Ehdr      *hdr;
117         Elf64_Sym       *dynsym;
118         unsigned long   dynsymsize;
119         char            *dynstr;
120         unsigned long   text;
121 };
122
123
124 #ifdef __DEBUG
125 static void dump_one_vdso_page(struct page *pg, struct page *upg)
126 {
127         printk("kpg: %p (c:%d,f:%08lx)", __va(page_to_pfn(pg) << PAGE_SHIFT),
128                page_count(pg),
129                pg->flags);
130         if (upg/* && pg != upg*/) {
131                 printk(" upg: %p (c:%d,f:%08lx)", __va(page_to_pfn(upg)
132                                                        << PAGE_SHIFT),
133                        page_count(upg),
134                        upg->flags);
135         }
136         printk("\n");
137 }
138
139 static void dump_vdso_pages(struct vm_area_struct * vma)
140 {
141         int i;
142
143         if (!vma || test_thread_flag(TIF_32BIT)) {
144                 printk("vDSO32 @ %016lx:\n", (unsigned long)vdso32_kbase);
145                 for (i=0; i<vdso32_pages; i++) {
146                         struct page *pg = virt_to_page(vdso32_kbase +
147                                                        i*PAGE_SIZE);
148                         struct page *upg = (vma && vma->vm_mm) ?
149                                 follow_page(vma, vma->vm_start + i*PAGE_SIZE, 0)
150                                 : NULL;
151                         dump_one_vdso_page(pg, upg);
152                 }
153         }
154         if (!vma || !test_thread_flag(TIF_32BIT)) {
155                 printk("vDSO64 @ %016lx:\n", (unsigned long)vdso64_kbase);
156                 for (i=0; i<vdso64_pages; i++) {
157                         struct page *pg = virt_to_page(vdso64_kbase +
158                                                        i*PAGE_SIZE);
159                         struct page *upg = (vma && vma->vm_mm) ?
160                                 follow_page(vma, vma->vm_start + i*PAGE_SIZE, 0)
161                                 : NULL;
162                         dump_one_vdso_page(pg, upg);
163                 }
164         }
165 }
166 #endif /* DEBUG */
167
168 /*
169  * Keep a dummy vma_close for now, it will prevent VMA merging.
170  */
171 static void vdso_vma_close(struct vm_area_struct * vma)
172 {
173 }
174
175 /*
176  * Our nopage() function, maps in the actual vDSO kernel pages, they will
177  * be mapped read-only by do_no_page(), and eventually COW'ed, either
178  * right away for an initial write access, or by do_wp_page().
179  */
180 static struct page * vdso_vma_nopage(struct vm_area_struct * vma,
181                                      unsigned long address, int *type)
182 {
183         unsigned long offset = address - vma->vm_start;
184         struct page *pg;
185 #ifdef CONFIG_PPC64
186         void *vbase = (vma->vm_mm->task_size > TASK_SIZE_USER32) ?
187                 vdso64_kbase : vdso32_kbase;
188 #else
189         void *vbase = vdso32_kbase;
190 #endif
191
192         DBG("vdso_vma_nopage(current: %s, address: %016lx, off: %lx)\n",
193             current->comm, address, offset);
194
195         if (address < vma->vm_start || address > vma->vm_end)
196                 return NOPAGE_SIGBUS;
197
198         /*
199          * Last page is systemcfg.
200          */
201         if ((vma->vm_end - address) <= PAGE_SIZE)
202                 pg = virt_to_page(vdso_data);
203         else
204                 pg = virt_to_page(vbase + offset);
205
206         get_page(pg);
207         DBG(" ->page count: %d\n", page_count(pg));
208
209         return pg;
210 }
211
212 static struct vm_operations_struct vdso_vmops = {
213         .close  = vdso_vma_close,
214         .nopage = vdso_vma_nopage,
215 };
216
217 /*
218  * This is called from binfmt_elf, we create the special vma for the
219  * vDSO and insert it into the mm struct tree
220  */
221 int arch_setup_additional_pages(struct linux_binprm *bprm,
222                                 int executable_stack, unsigned long start_code,
223                                 unsigned long interp_map_address)
224 {
225         struct mm_struct *mm = current->mm;
226         struct vm_area_struct *vma;
227         unsigned long vdso_pages;
228         unsigned long vdso_base;
229         int rc;
230
231 #ifdef CONFIG_PPC64
232         if (test_thread_flag(TIF_32BIT)) {
233                 vdso_pages = vdso32_pages;
234                 vdso_base = VDSO32_MBASE;
235         } else {
236                 vdso_pages = vdso64_pages;
237                 vdso_base = VDSO64_MBASE;
238         }
239 #else
240         vdso_pages = vdso32_pages;
241         vdso_base = VDSO32_MBASE;
242 #endif
243
244         current->mm->context.vdso_base = 0;
245
246         /* vDSO has a problem and was disabled, just don't "enable" it for the
247          * process
248          */
249         if (vdso_pages == 0)
250                 return 0;
251         /* Add a page to the vdso size for the data page */
252         vdso_pages ++;
253
254         /*
255          * pick a base address for the vDSO in process space. We try to put it
256          * at vdso_base which is the "natural" base for it, but we might fail
257          * and end up putting it elsewhere.
258          */
259         down_write(&mm->mmap_sem);
260         vdso_base = get_unmapped_area(NULL, vdso_base,
261                                       vdso_pages << PAGE_SHIFT, 0, 0);
262         if (IS_ERR_VALUE(vdso_base)) {
263                 rc = vdso_base;
264                 goto fail_mmapsem;
265         }
266
267
268         /* Allocate a VMA structure and fill it up */
269         vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
270         if (vma == NULL) {
271                 rc = -ENOMEM;
272                 goto fail_mmapsem;
273         }
274         vma->vm_mm = mm;
275         vma->vm_start = vdso_base;
276         vma->vm_end = vma->vm_start + (vdso_pages << PAGE_SHIFT);
277
278         /*
279          * our vma flags don't have VM_WRITE so by default, the process isn't
280          * allowed to write those pages.
281          * gdb can break that with ptrace interface, and thus trigger COW on
282          * those pages but it's then your responsibility to never do that on
283          * the "data" page of the vDSO or you'll stop getting kernel updates
284          * and your nice userland gettimeofday will be totally dead.
285          * It's fine to use that for setting breakpoints in the vDSO code
286          * pages though
287          */
288         vma->vm_flags = VM_READ|VM_EXEC|VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC;
289         /*
290          * Make sure the vDSO gets into every core dump.
291          * Dumping its contents makes post-mortem fully interpretable later
292          * without matching up the same kernel and hardware config to see
293          * what PC values meant.
294          */
295         vma->vm_flags |= VM_ALWAYSDUMP;
296         vma->vm_flags |= mm->def_flags;
297         vma->vm_page_prot = protection_map[vma->vm_flags & 0x7];
298         vma->vm_ops = &vdso_vmops;
299
300         /* Insert new VMA */
301         rc = insert_vm_struct(mm, vma);
302         if (rc)
303                 goto fail_vma;
304
305         /* Put vDSO base into mm struct and account for memory usage */
306         current->mm->context.vdso_base = vdso_base;
307         vx_vmpages_add(mm, (vma->vm_end - vma->vm_start) >> PAGE_SHIFT);
308         up_write(&mm->mmap_sem);
309         return 0;
310
311  fail_vma:
312         kmem_cache_free(vm_area_cachep, vma);
313  fail_mmapsem:
314         up_write(&mm->mmap_sem);
315         return rc;
316 }
317
318 const char *arch_vma_name(struct vm_area_struct *vma)
319 {
320         if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso_base)
321                 return "[vdso]";
322         return NULL;
323 }
324
325
326
327 static void * __init find_section32(Elf32_Ehdr *ehdr, const char *secname,
328                                   unsigned long *size)
329 {
330         Elf32_Shdr *sechdrs;
331         unsigned int i;
332         char *secnames;
333
334         /* Grab section headers and strings so we can tell who is who */
335         sechdrs = (void *)ehdr + ehdr->e_shoff;
336         secnames = (void *)ehdr + sechdrs[ehdr->e_shstrndx].sh_offset;
337
338         /* Find the section they want */
339         for (i = 1; i < ehdr->e_shnum; i++) {
340                 if (strcmp(secnames+sechdrs[i].sh_name, secname) == 0) {
341                         if (size)
342                                 *size = sechdrs[i].sh_size;
343                         return (void *)ehdr + sechdrs[i].sh_offset;
344                 }
345         }
346         *size = 0;
347         return NULL;
348 }
349
350 static Elf32_Sym * __init find_symbol32(struct lib32_elfinfo *lib,
351                                         const char *symname)
352 {
353         unsigned int i;
354         char name[MAX_SYMNAME], *c;
355
356         for (i = 0; i < (lib->dynsymsize / sizeof(Elf32_Sym)); i++) {
357                 if (lib->dynsym[i].st_name == 0)
358                         continue;
359                 strlcpy(name, lib->dynstr + lib->dynsym[i].st_name,
360                         MAX_SYMNAME);
361                 c = strchr(name, '@');
362                 if (c)
363                         *c = 0;
364                 if (strcmp(symname, name) == 0)
365                         return &lib->dynsym[i];
366         }
367         return NULL;
368 }
369
370 /* Note that we assume the section is .text and the symbol is relative to
371  * the library base
372  */
373 static unsigned long __init find_function32(struct lib32_elfinfo *lib,
374                                             const char *symname)
375 {
376         Elf32_Sym *sym = find_symbol32(lib, symname);
377
378         if (sym == NULL) {
379                 printk(KERN_WARNING "vDSO32: function %s not found !\n",
380                        symname);
381                 return 0;
382         }
383         return sym->st_value - VDSO32_LBASE;
384 }
385
386 static int vdso_do_func_patch32(struct lib32_elfinfo *v32,
387                                 struct lib64_elfinfo *v64,
388                                 const char *orig, const char *fix)
389 {
390         Elf32_Sym *sym32_gen, *sym32_fix;
391
392         sym32_gen = find_symbol32(v32, orig);
393         if (sym32_gen == NULL) {
394                 printk(KERN_ERR "vDSO32: Can't find symbol %s !\n", orig);
395                 return -1;
396         }
397         if (fix == NULL) {
398                 sym32_gen->st_name = 0;
399                 return 0;
400         }
401         sym32_fix = find_symbol32(v32, fix);
402         if (sym32_fix == NULL) {
403                 printk(KERN_ERR "vDSO32: Can't find symbol %s !\n", fix);
404                 return -1;
405         }
406         sym32_gen->st_value = sym32_fix->st_value;
407         sym32_gen->st_size = sym32_fix->st_size;
408         sym32_gen->st_info = sym32_fix->st_info;
409         sym32_gen->st_other = sym32_fix->st_other;
410         sym32_gen->st_shndx = sym32_fix->st_shndx;
411
412         return 0;
413 }
414
415
416 #ifdef CONFIG_PPC64
417
418 static void * __init find_section64(Elf64_Ehdr *ehdr, const char *secname,
419                                   unsigned long *size)
420 {
421         Elf64_Shdr *sechdrs;
422         unsigned int i;
423         char *secnames;
424
425         /* Grab section headers and strings so we can tell who is who */
426         sechdrs = (void *)ehdr + ehdr->e_shoff;
427         secnames = (void *)ehdr + sechdrs[ehdr->e_shstrndx].sh_offset;
428
429         /* Find the section they want */
430         for (i = 1; i < ehdr->e_shnum; i++) {
431                 if (strcmp(secnames+sechdrs[i].sh_name, secname) == 0) {
432                         if (size)
433                                 *size = sechdrs[i].sh_size;
434                         return (void *)ehdr + sechdrs[i].sh_offset;
435                 }
436         }
437         if (size)
438                 *size = 0;
439         return NULL;
440 }
441
442 static Elf64_Sym * __init find_symbol64(struct lib64_elfinfo *lib,
443                                         const char *symname)
444 {
445         unsigned int i;
446         char name[MAX_SYMNAME], *c;
447
448         for (i = 0; i < (lib->dynsymsize / sizeof(Elf64_Sym)); i++) {
449                 if (lib->dynsym[i].st_name == 0)
450                         continue;
451                 strlcpy(name, lib->dynstr + lib->dynsym[i].st_name,
452                         MAX_SYMNAME);
453                 c = strchr(name, '@');
454                 if (c)
455                         *c = 0;
456                 if (strcmp(symname, name) == 0)
457                         return &lib->dynsym[i];
458         }
459         return NULL;
460 }
461
462 /* Note that we assume the section is .text and the symbol is relative to
463  * the library base
464  */
465 static unsigned long __init find_function64(struct lib64_elfinfo *lib,
466                                             const char *symname)
467 {
468         Elf64_Sym *sym = find_symbol64(lib, symname);
469
470         if (sym == NULL) {
471                 printk(KERN_WARNING "vDSO64: function %s not found !\n",
472                        symname);
473                 return 0;
474         }
475 #ifdef VDS64_HAS_DESCRIPTORS
476         return *((u64 *)(vdso64_kbase + sym->st_value - VDSO64_LBASE)) -
477                 VDSO64_LBASE;
478 #else
479         return sym->st_value - VDSO64_LBASE;
480 #endif
481 }
482
483 static int vdso_do_func_patch64(struct lib32_elfinfo *v32,
484                                 struct lib64_elfinfo *v64,
485                                 const char *orig, const char *fix)
486 {
487         Elf64_Sym *sym64_gen, *sym64_fix;
488
489         sym64_gen = find_symbol64(v64, orig);
490         if (sym64_gen == NULL) {
491                 printk(KERN_ERR "vDSO64: Can't find symbol %s !\n", orig);
492                 return -1;
493         }
494         if (fix == NULL) {
495                 sym64_gen->st_name = 0;
496                 return 0;
497         }
498         sym64_fix = find_symbol64(v64, fix);
499         if (sym64_fix == NULL) {
500                 printk(KERN_ERR "vDSO64: Can't find symbol %s !\n", fix);
501                 return -1;
502         }
503         sym64_gen->st_value = sym64_fix->st_value;
504         sym64_gen->st_size = sym64_fix->st_size;
505         sym64_gen->st_info = sym64_fix->st_info;
506         sym64_gen->st_other = sym64_fix->st_other;
507         sym64_gen->st_shndx = sym64_fix->st_shndx;
508
509         return 0;
510 }
511
512 #endif /* CONFIG_PPC64 */
513
514
515 static __init int vdso_do_find_sections(struct lib32_elfinfo *v32,
516                                         struct lib64_elfinfo *v64)
517 {
518         void *sect;
519
520         /*
521          * Locate symbol tables & text section
522          */
523
524         v32->dynsym = find_section32(v32->hdr, ".dynsym", &v32->dynsymsize);
525         v32->dynstr = find_section32(v32->hdr, ".dynstr", NULL);
526         if (v32->dynsym == NULL || v32->dynstr == NULL) {
527                 printk(KERN_ERR "vDSO32: required symbol section not found\n");
528                 return -1;
529         }
530         sect = find_section32(v32->hdr, ".text", NULL);
531         if (sect == NULL) {
532                 printk(KERN_ERR "vDSO32: the .text section was not found\n");
533                 return -1;
534         }
535         v32->text = sect - vdso32_kbase;
536
537 #ifdef CONFIG_PPC64
538         v64->dynsym = find_section64(v64->hdr, ".dynsym", &v64->dynsymsize);
539         v64->dynstr = find_section64(v64->hdr, ".dynstr", NULL);
540         if (v64->dynsym == NULL || v64->dynstr == NULL) {
541                 printk(KERN_ERR "vDSO64: required symbol section not found\n");
542                 return -1;
543         }
544         sect = find_section64(v64->hdr, ".text", NULL);
545         if (sect == NULL) {
546                 printk(KERN_ERR "vDSO64: the .text section was not found\n");
547                 return -1;
548         }
549         v64->text = sect - vdso64_kbase;
550 #endif /* CONFIG_PPC64 */
551
552         return 0;
553 }
554
555 static __init void vdso_setup_trampolines(struct lib32_elfinfo *v32,
556                                           struct lib64_elfinfo *v64)
557 {
558         /*
559          * Find signal trampolines
560          */
561
562 #ifdef CONFIG_PPC64
563         vdso64_rt_sigtramp = find_function64(v64, "__kernel_sigtramp_rt64");
564 #endif
565         vdso32_sigtramp    = find_function32(v32, "__kernel_sigtramp32");
566         vdso32_rt_sigtramp = find_function32(v32, "__kernel_sigtramp_rt32");
567 }
568
569 static __init int vdso_fixup_datapage(struct lib32_elfinfo *v32,
570                                        struct lib64_elfinfo *v64)
571 {
572         Elf32_Sym *sym32;
573 #ifdef CONFIG_PPC64
574         Elf64_Sym *sym64;
575
576         sym64 = find_symbol64(v64, "__kernel_datapage_offset");
577         if (sym64 == NULL) {
578                 printk(KERN_ERR "vDSO64: Can't find symbol "
579                        "__kernel_datapage_offset !\n");
580                 return -1;
581         }
582         *((int *)(vdso64_kbase + sym64->st_value - VDSO64_LBASE)) =
583                 (vdso64_pages << PAGE_SHIFT) -
584                 (sym64->st_value - VDSO64_LBASE);
585 #endif /* CONFIG_PPC64 */
586
587         sym32 = find_symbol32(v32, "__kernel_datapage_offset");
588         if (sym32 == NULL) {
589                 printk(KERN_ERR "vDSO32: Can't find symbol "
590                        "__kernel_datapage_offset !\n");
591                 return -1;
592         }
593         *((int *)(vdso32_kbase + (sym32->st_value - VDSO32_LBASE))) =
594                 (vdso32_pages << PAGE_SHIFT) -
595                 (sym32->st_value - VDSO32_LBASE);
596
597         return 0;
598 }
599
600
601 static __init int vdso_fixup_features(struct lib32_elfinfo *v32,
602                                       struct lib64_elfinfo *v64)
603 {
604         void *start32;
605         unsigned long size32;
606
607 #ifdef CONFIG_PPC64
608         void *start64;
609         unsigned long size64;
610
611         start64 = find_section64(v64->hdr, "__ftr_fixup", &size64);
612         if (start64)
613                 do_feature_fixups(cur_cpu_spec->cpu_features,
614                                   start64, start64 + size64);
615
616         start64 = find_section64(v64->hdr, "__fw_ftr_fixup", &size64);
617         if (start64)
618                 do_feature_fixups(powerpc_firmware_features,
619                                   start64, start64 + size64);
620 #endif /* CONFIG_PPC64 */
621
622         start32 = find_section32(v32->hdr, "__ftr_fixup", &size32);
623         if (start32)
624                 do_feature_fixups(cur_cpu_spec->cpu_features,
625                                   start32, start32 + size32);
626
627 #ifdef CONFIG_PPC64
628         start32 = find_section32(v32->hdr, "__fw_ftr_fixup", &size32);
629         if (start32)
630                 do_feature_fixups(powerpc_firmware_features,
631                                   start32, start32 + size32);
632 #endif /* CONFIG_PPC64 */
633
634         return 0;
635 }
636
637 static __init int vdso_fixup_alt_funcs(struct lib32_elfinfo *v32,
638                                        struct lib64_elfinfo *v64)
639 {
640         int i;
641
642         for (i = 0; i < ARRAY_SIZE(vdso_patches); i++) {
643                 struct vdso_patch_def *patch = &vdso_patches[i];
644                 int match = (cur_cpu_spec->cpu_features & patch->ftr_mask)
645                         == patch->ftr_value;
646                 if (!match)
647                         continue;
648
649                 DBG("replacing %s with %s...\n", patch->gen_name,
650                     patch->fix_name ? "NONE" : patch->fix_name);
651
652                 /*
653                  * Patch the 32 bits and 64 bits symbols. Note that we do not
654                  * patch the "." symbol on 64 bits.
655                  * It would be easy to do, but doesn't seem to be necessary,
656                  * patching the OPD symbol is enough.
657                  */
658                 vdso_do_func_patch32(v32, v64, patch->gen_name,
659                                      patch->fix_name);
660 #ifdef CONFIG_PPC64
661                 vdso_do_func_patch64(v32, v64, patch->gen_name,
662                                      patch->fix_name);
663 #endif /* CONFIG_PPC64 */
664         }
665
666         return 0;
667 }
668
669
670 static __init int vdso_setup(void)
671 {
672         struct lib32_elfinfo    v32;
673         struct lib64_elfinfo    v64;
674
675         v32.hdr = vdso32_kbase;
676 #ifdef CONFIG_PPC64
677         v64.hdr = vdso64_kbase;
678 #endif
679         if (vdso_do_find_sections(&v32, &v64))
680                 return -1;
681
682         if (vdso_fixup_datapage(&v32, &v64))
683                 return -1;
684
685         if (vdso_fixup_features(&v32, &v64))
686                 return -1;
687
688         if (vdso_fixup_alt_funcs(&v32, &v64))
689                 return -1;
690
691         vdso_setup_trampolines(&v32, &v64);
692
693         return 0;
694 }
695
696 /*
697  * Called from setup_arch to initialize the bitmap of available
698  * syscalls in the systemcfg page
699  */
700 static void __init vdso_setup_syscall_map(void)
701 {
702         unsigned int i;
703         extern unsigned long *sys_call_table;
704         extern unsigned long sys_ni_syscall;
705
706
707         for (i = 0; i < __NR_syscalls; i++) {
708 #ifdef CONFIG_PPC64
709                 if (sys_call_table[i*2] != sys_ni_syscall)
710                         vdso_data->syscall_map_64[i >> 5] |=
711                                 0x80000000UL >> (i & 0x1f);
712                 if (sys_call_table[i*2+1] != sys_ni_syscall)
713                         vdso_data->syscall_map_32[i >> 5] |=
714                                 0x80000000UL >> (i & 0x1f);
715 #else /* CONFIG_PPC64 */
716                 if (sys_call_table[i] != sys_ni_syscall)
717                         vdso_data->syscall_map_32[i >> 5] |=
718                                 0x80000000UL >> (i & 0x1f);
719 #endif /* CONFIG_PPC64 */
720         }
721 }
722
723
724 void __init vdso_init(void)
725 {
726         int i;
727
728 #ifdef CONFIG_PPC64
729         /*
730          * Fill up the "systemcfg" stuff for backward compatiblity
731          */
732         strcpy(vdso_data->eye_catcher, "SYSTEMCFG:PPC64");
733         vdso_data->version.major = SYSTEMCFG_MAJOR;
734         vdso_data->version.minor = SYSTEMCFG_MINOR;
735         vdso_data->processor = mfspr(SPRN_PVR);
736         /*
737          * Fake the old platform number for pSeries and iSeries and add
738          * in LPAR bit if necessary
739          */
740         vdso_data->platform = machine_is(iseries) ? 0x200 : 0x100;
741         if (firmware_has_feature(FW_FEATURE_LPAR))
742                 vdso_data->platform |= 1;
743         vdso_data->physicalMemorySize = lmb_phys_mem_size();
744         vdso_data->dcache_size = ppc64_caches.dsize;
745         vdso_data->dcache_line_size = ppc64_caches.dline_size;
746         vdso_data->icache_size = ppc64_caches.isize;
747         vdso_data->icache_line_size = ppc64_caches.iline_size;
748
749         /*
750          * Calculate the size of the 64 bits vDSO
751          */
752         vdso64_pages = (&vdso64_end - &vdso64_start) >> PAGE_SHIFT;
753         DBG("vdso64_kbase: %p, 0x%x pages\n", vdso64_kbase, vdso64_pages);
754 #endif /* CONFIG_PPC64 */
755
756
757         /*
758          * Calculate the size of the 32 bits vDSO
759          */
760         vdso32_pages = (&vdso32_end - &vdso32_start) >> PAGE_SHIFT;
761         DBG("vdso32_kbase: %p, 0x%x pages\n", vdso32_kbase, vdso32_pages);
762
763
764         /*
765          * Setup the syscall map in the vDOS
766          */
767         vdso_setup_syscall_map();
768
769         /*
770          * Initialize the vDSO images in memory, that is do necessary
771          * fixups of vDSO symbols, locate trampolines, etc...
772          */
773         if (vdso_setup()) {
774                 printk(KERN_ERR "vDSO setup failure, not enabled !\n");
775                 vdso32_pages = 0;
776 #ifdef CONFIG_PPC64
777                 vdso64_pages = 0;
778 #endif
779                 return;
780         }
781
782         /* Make sure pages are in the correct state */
783         for (i = 0; i < vdso32_pages; i++) {
784                 struct page *pg = virt_to_page(vdso32_kbase + i*PAGE_SIZE);
785                 ClearPageReserved(pg);
786                 get_page(pg);
787
788         }
789 #ifdef CONFIG_PPC64
790         for (i = 0; i < vdso64_pages; i++) {
791                 struct page *pg = virt_to_page(vdso64_kbase + i*PAGE_SIZE);
792                 ClearPageReserved(pg);
793                 get_page(pg);
794         }
795 #endif /* CONFIG_PPC64 */
796
797         get_page(virt_to_page(vdso_data));
798 }
799
800 int in_gate_area_no_task(unsigned long addr)
801 {
802         return 0;
803 }
804
805 int in_gate_area(struct task_struct *task, unsigned long addr)
806 {
807         return 0;
808 }
809
810 struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
811 {
812         return NULL;
813 }
814