vdso.c 21 KB

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