vdso.c 20 KB

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