init.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. /*
  2. * linux/arch/x86_64/mm/init.c
  3. *
  4. * Copyright (C) 1995 Linus Torvalds
  5. * Copyright (C) 2000 Pavel Machek <pavel@suse.cz>
  6. * Copyright (C) 2002,2003 Andi Kleen <ak@suse.de>
  7. */
  8. #include <linux/config.h>
  9. #include <linux/signal.h>
  10. #include <linux/sched.h>
  11. #include <linux/kernel.h>
  12. #include <linux/errno.h>
  13. #include <linux/string.h>
  14. #include <linux/types.h>
  15. #include <linux/ptrace.h>
  16. #include <linux/mman.h>
  17. #include <linux/mm.h>
  18. #include <linux/swap.h>
  19. #include <linux/smp.h>
  20. #include <linux/init.h>
  21. #include <linux/pagemap.h>
  22. #include <linux/bootmem.h>
  23. #include <linux/proc_fs.h>
  24. #include <linux/pci.h>
  25. #include <linux/dma-mapping.h>
  26. #include <asm/processor.h>
  27. #include <asm/system.h>
  28. #include <asm/uaccess.h>
  29. #include <asm/pgtable.h>
  30. #include <asm/pgalloc.h>
  31. #include <asm/dma.h>
  32. #include <asm/fixmap.h>
  33. #include <asm/e820.h>
  34. #include <asm/apic.h>
  35. #include <asm/tlb.h>
  36. #include <asm/mmu_context.h>
  37. #include <asm/proto.h>
  38. #include <asm/smp.h>
  39. #include <asm/sections.h>
  40. #include <asm/dma-mapping.h>
  41. #include <asm/swiotlb.h>
  42. #ifndef Dprintk
  43. #define Dprintk(x...)
  44. #endif
  45. struct dma_mapping_ops* dma_ops;
  46. EXPORT_SYMBOL(dma_ops);
  47. static unsigned long dma_reserve __initdata;
  48. DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
  49. /*
  50. * NOTE: pagetable_init alloc all the fixmap pagetables contiguous on the
  51. * physical space so we can cache the place of the first one and move
  52. * around without checking the pgd every time.
  53. */
  54. void show_mem(void)
  55. {
  56. long i, total = 0, reserved = 0;
  57. long shared = 0, cached = 0;
  58. pg_data_t *pgdat;
  59. struct page *page;
  60. printk(KERN_INFO "Mem-info:\n");
  61. show_free_areas();
  62. printk(KERN_INFO "Free swap: %6ldkB\n", nr_swap_pages<<(PAGE_SHIFT-10));
  63. for_each_pgdat(pgdat) {
  64. for (i = 0; i < pgdat->node_spanned_pages; ++i) {
  65. page = pfn_to_page(pgdat->node_start_pfn + i);
  66. total++;
  67. if (PageReserved(page))
  68. reserved++;
  69. else if (PageSwapCache(page))
  70. cached++;
  71. else if (page_count(page))
  72. shared += page_count(page) - 1;
  73. }
  74. }
  75. printk(KERN_INFO "%lu pages of RAM\n", total);
  76. printk(KERN_INFO "%lu reserved pages\n",reserved);
  77. printk(KERN_INFO "%lu pages shared\n",shared);
  78. printk(KERN_INFO "%lu pages swap cached\n",cached);
  79. }
  80. /* References to section boundaries */
  81. int after_bootmem;
  82. static void *spp_getpage(void)
  83. {
  84. void *ptr;
  85. if (after_bootmem)
  86. ptr = (void *) get_zeroed_page(GFP_ATOMIC);
  87. else
  88. ptr = alloc_bootmem_pages(PAGE_SIZE);
  89. if (!ptr || ((unsigned long)ptr & ~PAGE_MASK))
  90. panic("set_pte_phys: cannot allocate page data %s\n", after_bootmem?"after bootmem":"");
  91. Dprintk("spp_getpage %p\n", ptr);
  92. return ptr;
  93. }
  94. static void set_pte_phys(unsigned long vaddr,
  95. unsigned long phys, pgprot_t prot)
  96. {
  97. pgd_t *pgd;
  98. pud_t *pud;
  99. pmd_t *pmd;
  100. pte_t *pte, new_pte;
  101. Dprintk("set_pte_phys %lx to %lx\n", vaddr, phys);
  102. pgd = pgd_offset_k(vaddr);
  103. if (pgd_none(*pgd)) {
  104. printk("PGD FIXMAP MISSING, it should be setup in head.S!\n");
  105. return;
  106. }
  107. pud = pud_offset(pgd, vaddr);
  108. if (pud_none(*pud)) {
  109. pmd = (pmd_t *) spp_getpage();
  110. set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE | _PAGE_USER));
  111. if (pmd != pmd_offset(pud, 0)) {
  112. printk("PAGETABLE BUG #01! %p <-> %p\n", pmd, pmd_offset(pud,0));
  113. return;
  114. }
  115. }
  116. pmd = pmd_offset(pud, vaddr);
  117. if (pmd_none(*pmd)) {
  118. pte = (pte_t *) spp_getpage();
  119. set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE | _PAGE_USER));
  120. if (pte != pte_offset_kernel(pmd, 0)) {
  121. printk("PAGETABLE BUG #02!\n");
  122. return;
  123. }
  124. }
  125. new_pte = pfn_pte(phys >> PAGE_SHIFT, prot);
  126. pte = pte_offset_kernel(pmd, vaddr);
  127. if (!pte_none(*pte) &&
  128. pte_val(*pte) != (pte_val(new_pte) & __supported_pte_mask))
  129. pte_ERROR(*pte);
  130. set_pte(pte, new_pte);
  131. /*
  132. * It's enough to flush this one mapping.
  133. * (PGE mappings get flushed as well)
  134. */
  135. __flush_tlb_one(vaddr);
  136. }
  137. /* NOTE: this is meant to be run only at boot */
  138. void __set_fixmap (enum fixed_addresses idx, unsigned long phys, pgprot_t prot)
  139. {
  140. unsigned long address = __fix_to_virt(idx);
  141. if (idx >= __end_of_fixed_addresses) {
  142. printk("Invalid __set_fixmap\n");
  143. return;
  144. }
  145. set_pte_phys(address, phys, prot);
  146. }
  147. unsigned long __initdata table_start, table_end;
  148. extern pmd_t temp_boot_pmds[];
  149. static struct temp_map {
  150. pmd_t *pmd;
  151. void *address;
  152. int allocated;
  153. } temp_mappings[] __initdata = {
  154. { &temp_boot_pmds[0], (void *)(40UL * 1024 * 1024) },
  155. { &temp_boot_pmds[1], (void *)(42UL * 1024 * 1024) },
  156. {}
  157. };
  158. static __init void *alloc_low_page(int *index, unsigned long *phys)
  159. {
  160. struct temp_map *ti;
  161. int i;
  162. unsigned long pfn = table_end++, paddr;
  163. void *adr;
  164. if (pfn >= end_pfn)
  165. panic("alloc_low_page: ran out of memory");
  166. for (i = 0; temp_mappings[i].allocated; i++) {
  167. if (!temp_mappings[i].pmd)
  168. panic("alloc_low_page: ran out of temp mappings");
  169. }
  170. ti = &temp_mappings[i];
  171. paddr = (pfn << PAGE_SHIFT) & PMD_MASK;
  172. set_pmd(ti->pmd, __pmd(paddr | _KERNPG_TABLE | _PAGE_PSE));
  173. ti->allocated = 1;
  174. __flush_tlb();
  175. adr = ti->address + ((pfn << PAGE_SHIFT) & ~PMD_MASK);
  176. *index = i;
  177. *phys = pfn * PAGE_SIZE;
  178. return adr;
  179. }
  180. static __init void unmap_low_page(int i)
  181. {
  182. struct temp_map *ti = &temp_mappings[i];
  183. set_pmd(ti->pmd, __pmd(0));
  184. ti->allocated = 0;
  185. }
  186. static void __init phys_pud_init(pud_t *pud, unsigned long address, unsigned long end)
  187. {
  188. long i, j;
  189. i = pud_index(address);
  190. pud = pud + i;
  191. for (; i < PTRS_PER_PUD; pud++, i++) {
  192. int map;
  193. unsigned long paddr, pmd_phys;
  194. pmd_t *pmd;
  195. paddr = address + i*PUD_SIZE;
  196. if (paddr >= end) {
  197. for (; i < PTRS_PER_PUD; i++, pud++)
  198. set_pud(pud, __pud(0));
  199. break;
  200. }
  201. if (!e820_mapped(paddr, paddr+PUD_SIZE, 0)) {
  202. set_pud(pud, __pud(0));
  203. continue;
  204. }
  205. pmd = alloc_low_page(&map, &pmd_phys);
  206. set_pud(pud, __pud(pmd_phys | _KERNPG_TABLE));
  207. for (j = 0; j < PTRS_PER_PMD; pmd++, j++, paddr += PMD_SIZE) {
  208. unsigned long pe;
  209. if (paddr >= end) {
  210. for (; j < PTRS_PER_PMD; j++, pmd++)
  211. set_pmd(pmd, __pmd(0));
  212. break;
  213. }
  214. pe = _PAGE_NX|_PAGE_PSE | _KERNPG_TABLE | _PAGE_GLOBAL | paddr;
  215. pe &= __supported_pte_mask;
  216. set_pmd(pmd, __pmd(pe));
  217. }
  218. unmap_low_page(map);
  219. }
  220. __flush_tlb();
  221. }
  222. static void __init find_early_table_space(unsigned long end)
  223. {
  224. unsigned long puds, pmds, tables, start;
  225. puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
  226. pmds = (end + PMD_SIZE - 1) >> PMD_SHIFT;
  227. tables = round_up(puds * sizeof(pud_t), PAGE_SIZE) +
  228. round_up(pmds * sizeof(pmd_t), PAGE_SIZE);
  229. /* RED-PEN putting page tables only on node 0 could
  230. cause a hotspot and fill up ZONE_DMA. The page tables
  231. need roughly 0.5KB per GB. */
  232. start = 0x8000;
  233. table_start = find_e820_area(start, end, tables);
  234. if (table_start == -1UL)
  235. panic("Cannot find space for the kernel page tables");
  236. table_start >>= PAGE_SHIFT;
  237. table_end = table_start;
  238. }
  239. /* Setup the direct mapping of the physical memory at PAGE_OFFSET.
  240. This runs before bootmem is initialized and gets pages directly from the
  241. physical memory. To access them they are temporarily mapped. */
  242. void __init init_memory_mapping(unsigned long start, unsigned long end)
  243. {
  244. unsigned long next;
  245. Dprintk("init_memory_mapping\n");
  246. /*
  247. * Find space for the kernel direct mapping tables.
  248. * Later we should allocate these tables in the local node of the memory
  249. * mapped. Unfortunately this is done currently before the nodes are
  250. * discovered.
  251. */
  252. find_early_table_space(end);
  253. start = (unsigned long)__va(start);
  254. end = (unsigned long)__va(end);
  255. for (; start < end; start = next) {
  256. int map;
  257. unsigned long pud_phys;
  258. pud_t *pud = alloc_low_page(&map, &pud_phys);
  259. next = start + PGDIR_SIZE;
  260. if (next > end)
  261. next = end;
  262. phys_pud_init(pud, __pa(start), __pa(next));
  263. set_pgd(pgd_offset_k(start), mk_kernel_pgd(pud_phys));
  264. unmap_low_page(map);
  265. }
  266. asm volatile("movq %%cr4,%0" : "=r" (mmu_cr4_features));
  267. __flush_tlb_all();
  268. early_printk("kernel direct mapping tables upto %lx @ %lx-%lx\n", end,
  269. table_start<<PAGE_SHIFT,
  270. table_end<<PAGE_SHIFT);
  271. }
  272. void __cpuinit zap_low_mappings(int cpu)
  273. {
  274. if (cpu == 0) {
  275. pgd_t *pgd = pgd_offset_k(0UL);
  276. pgd_clear(pgd);
  277. } else {
  278. /*
  279. * For AP's, zap the low identity mappings by changing the cr3
  280. * to init_level4_pgt and doing local flush tlb all
  281. */
  282. asm volatile("movq %0,%%cr3" :: "r" (__pa_symbol(&init_level4_pgt)));
  283. }
  284. __flush_tlb_all();
  285. }
  286. /* Compute zone sizes for the DMA and DMA32 zones in a node. */
  287. __init void
  288. size_zones(unsigned long *z, unsigned long *h,
  289. unsigned long start_pfn, unsigned long end_pfn)
  290. {
  291. int i;
  292. unsigned long w;
  293. for (i = 0; i < MAX_NR_ZONES; i++)
  294. z[i] = 0;
  295. if (start_pfn < MAX_DMA_PFN)
  296. z[ZONE_DMA] = MAX_DMA_PFN - start_pfn;
  297. if (start_pfn < MAX_DMA32_PFN) {
  298. unsigned long dma32_pfn = MAX_DMA32_PFN;
  299. if (dma32_pfn > end_pfn)
  300. dma32_pfn = end_pfn;
  301. z[ZONE_DMA32] = dma32_pfn - start_pfn;
  302. }
  303. z[ZONE_NORMAL] = end_pfn - start_pfn;
  304. /* Remove lower zones from higher ones. */
  305. w = 0;
  306. for (i = 0; i < MAX_NR_ZONES; i++) {
  307. if (z[i])
  308. z[i] -= w;
  309. w += z[i];
  310. }
  311. /* Compute holes */
  312. w = start_pfn;
  313. for (i = 0; i < MAX_NR_ZONES; i++) {
  314. unsigned long s = w;
  315. w += z[i];
  316. h[i] = e820_hole_size(s, w);
  317. }
  318. /* Add the space pace needed for mem_map to the holes too. */
  319. for (i = 0; i < MAX_NR_ZONES; i++)
  320. h[i] += (z[i] * sizeof(struct page)) / PAGE_SIZE;
  321. /* The 16MB DMA zone has the kernel and other misc mappings.
  322. Account them too */
  323. if (h[ZONE_DMA]) {
  324. h[ZONE_DMA] += dma_reserve;
  325. if (h[ZONE_DMA] >= z[ZONE_DMA]) {
  326. printk(KERN_WARNING
  327. "Kernel too large and filling up ZONE_DMA?\n");
  328. h[ZONE_DMA] = z[ZONE_DMA];
  329. }
  330. }
  331. }
  332. #ifndef CONFIG_NUMA
  333. void __init paging_init(void)
  334. {
  335. unsigned long zones[MAX_NR_ZONES], holes[MAX_NR_ZONES];
  336. size_zones(zones, holes, 0, end_pfn);
  337. free_area_init_node(0, NODE_DATA(0), zones,
  338. __pa(PAGE_OFFSET) >> PAGE_SHIFT, holes);
  339. }
  340. #endif
  341. /* Unmap a kernel mapping if it exists. This is useful to avoid prefetches
  342. from the CPU leading to inconsistent cache lines. address and size
  343. must be aligned to 2MB boundaries.
  344. Does nothing when the mapping doesn't exist. */
  345. void __init clear_kernel_mapping(unsigned long address, unsigned long size)
  346. {
  347. unsigned long end = address + size;
  348. BUG_ON(address & ~LARGE_PAGE_MASK);
  349. BUG_ON(size & ~LARGE_PAGE_MASK);
  350. for (; address < end; address += LARGE_PAGE_SIZE) {
  351. pgd_t *pgd = pgd_offset_k(address);
  352. pud_t *pud;
  353. pmd_t *pmd;
  354. if (pgd_none(*pgd))
  355. continue;
  356. pud = pud_offset(pgd, address);
  357. if (pud_none(*pud))
  358. continue;
  359. pmd = pmd_offset(pud, address);
  360. if (!pmd || pmd_none(*pmd))
  361. continue;
  362. if (0 == (pmd_val(*pmd) & _PAGE_PSE)) {
  363. /* Could handle this, but it should not happen currently. */
  364. printk(KERN_ERR
  365. "clear_kernel_mapping: mapping has been split. will leak memory\n");
  366. pmd_ERROR(*pmd);
  367. }
  368. set_pmd(pmd, __pmd(0));
  369. }
  370. __flush_tlb_all();
  371. }
  372. static struct kcore_list kcore_mem, kcore_vmalloc, kcore_kernel, kcore_modules,
  373. kcore_vsyscall;
  374. void __init mem_init(void)
  375. {
  376. long codesize, reservedpages, datasize, initsize;
  377. #ifdef CONFIG_SWIOTLB
  378. pci_swiotlb_init();
  379. #endif
  380. no_iommu_init();
  381. /* How many end-of-memory variables you have, grandma! */
  382. max_low_pfn = end_pfn;
  383. max_pfn = end_pfn;
  384. num_physpages = end_pfn;
  385. high_memory = (void *) __va(end_pfn * PAGE_SIZE);
  386. /* clear the zero-page */
  387. memset(empty_zero_page, 0, PAGE_SIZE);
  388. reservedpages = 0;
  389. /* this will put all low memory onto the freelists */
  390. #ifdef CONFIG_NUMA
  391. totalram_pages = numa_free_all_bootmem();
  392. #else
  393. totalram_pages = free_all_bootmem();
  394. #endif
  395. reservedpages = end_pfn - totalram_pages - e820_hole_size(0, end_pfn);
  396. after_bootmem = 1;
  397. codesize = (unsigned long) &_etext - (unsigned long) &_text;
  398. datasize = (unsigned long) &_edata - (unsigned long) &_etext;
  399. initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
  400. /* Register memory areas for /proc/kcore */
  401. kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT);
  402. kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
  403. VMALLOC_END-VMALLOC_START);
  404. kclist_add(&kcore_kernel, &_stext, _end - _stext);
  405. kclist_add(&kcore_modules, (void *)MODULES_VADDR, MODULES_LEN);
  406. kclist_add(&kcore_vsyscall, (void *)VSYSCALL_START,
  407. VSYSCALL_END - VSYSCALL_START);
  408. printk("Memory: %luk/%luk available (%ldk kernel code, %ldk reserved, %ldk data, %ldk init)\n",
  409. (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
  410. end_pfn << (PAGE_SHIFT-10),
  411. codesize >> 10,
  412. reservedpages << (PAGE_SHIFT-10),
  413. datasize >> 10,
  414. initsize >> 10);
  415. #ifdef CONFIG_SMP
  416. /*
  417. * Sync boot_level4_pgt mappings with the init_level4_pgt
  418. * except for the low identity mappings which are already zapped
  419. * in init_level4_pgt. This sync-up is essential for AP's bringup
  420. */
  421. memcpy(boot_level4_pgt+1, init_level4_pgt+1, (PTRS_PER_PGD-1)*sizeof(pgd_t));
  422. #endif
  423. }
  424. void free_initmem(void)
  425. {
  426. unsigned long addr;
  427. addr = (unsigned long)(&__init_begin);
  428. for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) {
  429. ClearPageReserved(virt_to_page(addr));
  430. set_page_count(virt_to_page(addr), 1);
  431. memset((void *)(addr & ~(PAGE_SIZE-1)), 0xcc, PAGE_SIZE);
  432. free_page(addr);
  433. totalram_pages++;
  434. }
  435. memset(__initdata_begin, 0xba, __initdata_end - __initdata_begin);
  436. printk ("Freeing unused kernel memory: %luk freed\n", (__init_end - __init_begin) >> 10);
  437. }
  438. #ifdef CONFIG_DEBUG_RODATA
  439. extern char __start_rodata, __end_rodata;
  440. void mark_rodata_ro(void)
  441. {
  442. unsigned long addr = (unsigned long)&__start_rodata;
  443. for (; addr < (unsigned long)&__end_rodata; addr += PAGE_SIZE)
  444. change_page_attr_addr(addr, 1, PAGE_KERNEL_RO);
  445. printk ("Write protecting the kernel read-only data: %luk\n",
  446. (&__end_rodata - &__start_rodata) >> 10);
  447. /*
  448. * change_page_attr_addr() requires a global_flush_tlb() call after it.
  449. * We do this after the printk so that if something went wrong in the
  450. * change, the printk gets out at least to give a better debug hint
  451. * of who is the culprit.
  452. */
  453. global_flush_tlb();
  454. }
  455. #endif
  456. #ifdef CONFIG_BLK_DEV_INITRD
  457. void free_initrd_mem(unsigned long start, unsigned long end)
  458. {
  459. if (start >= end)
  460. return;
  461. printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
  462. for (; start < end; start += PAGE_SIZE) {
  463. ClearPageReserved(virt_to_page(start));
  464. set_page_count(virt_to_page(start), 1);
  465. free_page(start);
  466. totalram_pages++;
  467. }
  468. }
  469. #endif
  470. void __init reserve_bootmem_generic(unsigned long phys, unsigned len)
  471. {
  472. /* Should check here against the e820 map to avoid double free */
  473. #ifdef CONFIG_NUMA
  474. int nid = phys_to_nid(phys);
  475. reserve_bootmem_node(NODE_DATA(nid), phys, len);
  476. #else
  477. reserve_bootmem(phys, len);
  478. #endif
  479. if (phys+len <= MAX_DMA_PFN*PAGE_SIZE)
  480. dma_reserve += len / PAGE_SIZE;
  481. }
  482. int kern_addr_valid(unsigned long addr)
  483. {
  484. unsigned long above = ((long)addr) >> __VIRTUAL_MASK_SHIFT;
  485. pgd_t *pgd;
  486. pud_t *pud;
  487. pmd_t *pmd;
  488. pte_t *pte;
  489. if (above != 0 && above != -1UL)
  490. return 0;
  491. pgd = pgd_offset_k(addr);
  492. if (pgd_none(*pgd))
  493. return 0;
  494. pud = pud_offset(pgd, addr);
  495. if (pud_none(*pud))
  496. return 0;
  497. pmd = pmd_offset(pud, addr);
  498. if (pmd_none(*pmd))
  499. return 0;
  500. if (pmd_large(*pmd))
  501. return pfn_valid(pmd_pfn(*pmd));
  502. pte = pte_offset_kernel(pmd, addr);
  503. if (pte_none(*pte))
  504. return 0;
  505. return pfn_valid(pte_pfn(*pte));
  506. }
  507. #ifdef CONFIG_SYSCTL
  508. #include <linux/sysctl.h>
  509. extern int exception_trace, page_fault_trace;
  510. static ctl_table debug_table2[] = {
  511. { 99, "exception-trace", &exception_trace, sizeof(int), 0644, NULL,
  512. proc_dointvec },
  513. { 0, }
  514. };
  515. static ctl_table debug_root_table2[] = {
  516. { .ctl_name = CTL_DEBUG, .procname = "debug", .mode = 0555,
  517. .child = debug_table2 },
  518. { 0 },
  519. };
  520. static __init int x8664_sysctl_init(void)
  521. {
  522. register_sysctl_table(debug_root_table2, 1);
  523. return 0;
  524. }
  525. __initcall(x8664_sysctl_init);
  526. #endif
  527. /* A pseudo VMAs to allow ptrace access for the vsyscall page. This only
  528. covers the 64bit vsyscall page now. 32bit has a real VMA now and does
  529. not need special handling anymore. */
  530. static struct vm_area_struct gate_vma = {
  531. .vm_start = VSYSCALL_START,
  532. .vm_end = VSYSCALL_END,
  533. .vm_page_prot = PAGE_READONLY
  534. };
  535. struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
  536. {
  537. #ifdef CONFIG_IA32_EMULATION
  538. if (test_tsk_thread_flag(tsk, TIF_IA32))
  539. return NULL;
  540. #endif
  541. return &gate_vma;
  542. }
  543. int in_gate_area(struct task_struct *task, unsigned long addr)
  544. {
  545. struct vm_area_struct *vma = get_gate_vma(task);
  546. if (!vma)
  547. return 0;
  548. return (addr >= vma->vm_start) && (addr < vma->vm_end);
  549. }
  550. /* Use this when you have no reliable task/vma, typically from interrupt
  551. * context. It is less reliable than using the task's vma and may give
  552. * false positives.
  553. */
  554. int in_gate_area_no_task(unsigned long addr)
  555. {
  556. return (addr >= VSYSCALL_START) && (addr < VSYSCALL_END);
  557. }