vdso.c 18 KB

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