vdso.c 19 KB

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