vdso.c 20 KB

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