vdso.c 21 KB

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