vdso.c 20 KB

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