2 * linux/arch/x86_64/mm/init.c
4 * Copyright (C) 1995 Linus Torvalds
5 * Copyright (C) 2000 Pavel Machek <pavel@ucw.cz>
6 * Copyright (C) 2002,2003 Andi Kleen <ak@suse.de>
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>
18 #include <linux/swap.h>
19 #include <linux/smp.h>
20 #include <linux/init.h>
21 #include <linux/initrd.h>
22 #include <linux/pagemap.h>
23 #include <linux/bootmem.h>
24 #include <linux/memblock.h>
25 #include <linux/proc_fs.h>
26 #include <linux/pci.h>
27 #include <linux/pfn.h>
28 #include <linux/poison.h>
29 #include <linux/dma-mapping.h>
30 #include <linux/module.h>
31 #include <linux/memory_hotplug.h>
32 #include <linux/nmi.h>
33 #include <linux/gfp.h>
35 #include <asm/processor.h>
36 #include <asm/bios_ebda.h>
37 #include <asm/system.h>
38 #include <asm/uaccess.h>
39 #include <asm/pgtable.h>
40 #include <asm/pgalloc.h>
42 #include <asm/fixmap.h>
46 #include <asm/mmu_context.h>
47 #include <asm/proto.h>
49 #include <asm/sections.h>
50 #include <asm/kdebug.h>
52 #include <asm/cacheflush.h>
54 #include <linux/bootmem.h>
56 static int __init parse_direct_gbpages_off(char *arg)
61 early_param("nogbpages", parse_direct_gbpages_off);
63 static int __init parse_direct_gbpages_on(char *arg)
68 early_param("gbpages", parse_direct_gbpages_on);
71 * NOTE: pagetable_init alloc all the fixmap pagetables contiguous on the
72 * physical space so we can cache the place of the first one and move
73 * around without checking the pgd every time.
76 pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
77 EXPORT_SYMBOL_GPL(__supported_pte_mask);
79 int force_personality32;
83 * Control non executable heap for 32bit processes.
84 * To control the stack too use noexec=off
86 * on PROT_READ does not imply PROT_EXEC for 32-bit processes (default)
87 * off PROT_READ implies PROT_EXEC
89 static int __init nonx32_setup(char *str)
91 if (!strcmp(str, "on"))
92 force_personality32 &= ~READ_IMPLIES_EXEC;
93 else if (!strcmp(str, "off"))
94 force_personality32 |= READ_IMPLIES_EXEC;
97 __setup("noexec32=", nonx32_setup);
100 * When memory was added/removed make sure all the processes MM have
101 * suitable PGD entries in the local PGD level page.
103 void sync_global_pgds(unsigned long start, unsigned long end)
105 unsigned long address;
107 for (address = start; address <= end; address += PGDIR_SIZE) {
108 const pgd_t *pgd_ref = pgd_offset_k(address);
112 if (pgd_none(*pgd_ref))
115 spin_lock_irqsave(&pgd_lock, flags);
116 list_for_each_entry(page, &pgd_list, lru) {
118 spinlock_t *pgt_lock;
120 pgd = (pgd_t *)page_address(page) + pgd_index(address);
121 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
125 set_pgd(pgd, *pgd_ref);
127 BUG_ON(pgd_page_vaddr(*pgd)
128 != pgd_page_vaddr(*pgd_ref));
130 spin_unlock(pgt_lock);
132 spin_unlock_irqrestore(&pgd_lock, flags);
137 * NOTE: This function is marked __ref because it calls __init function
138 * (alloc_bootmem_pages). It's safe to do it ONLY when after_bootmem == 0.
140 static __ref void *spp_getpage(void)
145 ptr = (void *) get_zeroed_page(GFP_ATOMIC | __GFP_NOTRACK);
147 ptr = alloc_bootmem_pages(PAGE_SIZE);
149 if (!ptr || ((unsigned long)ptr & ~PAGE_MASK)) {
150 panic("set_pte_phys: cannot allocate page data %s\n",
151 after_bootmem ? "after bootmem" : "");
154 pr_debug("spp_getpage %p\n", ptr);
159 static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
161 if (pgd_none(*pgd)) {
162 pud_t *pud = (pud_t *)spp_getpage();
163 pgd_populate(&init_mm, pgd, pud);
164 if (pud != pud_offset(pgd, 0))
165 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
166 pud, pud_offset(pgd, 0));
168 return pud_offset(pgd, vaddr);
171 static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
173 if (pud_none(*pud)) {
174 pmd_t *pmd = (pmd_t *) spp_getpage();
175 pud_populate(&init_mm, pud, pmd);
176 if (pmd != pmd_offset(pud, 0))
177 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
178 pmd, pmd_offset(pud, 0));
180 return pmd_offset(pud, vaddr);
183 static pte_t *fill_pte(pmd_t *pmd, unsigned long vaddr)
185 if (pmd_none(*pmd)) {
186 pte_t *pte = (pte_t *) spp_getpage();
187 pmd_populate_kernel(&init_mm, pmd, pte);
188 if (pte != pte_offset_kernel(pmd, 0))
189 printk(KERN_ERR "PAGETABLE BUG #02!\n");
191 return pte_offset_kernel(pmd, vaddr);
194 void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
200 pud = pud_page + pud_index(vaddr);
201 pmd = fill_pmd(pud, vaddr);
202 pte = fill_pte(pmd, vaddr);
204 set_pte(pte, new_pte);
207 * It's enough to flush this one mapping.
208 * (PGE mappings get flushed as well)
210 __flush_tlb_one(vaddr);
213 void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
218 pr_debug("set_pte_vaddr %lx to %lx\n", vaddr, native_pte_val(pteval));
220 pgd = pgd_offset_k(vaddr);
221 if (pgd_none(*pgd)) {
223 "PGD FIXMAP MISSING, it should be setup in head.S!\n");
226 pud_page = (pud_t*)pgd_page_vaddr(*pgd);
227 set_pte_vaddr_pud(pud_page, vaddr, pteval);
230 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
235 pgd = pgd_offset_k(vaddr);
236 pud = fill_pud(pgd, vaddr);
237 return fill_pmd(pud, vaddr);
240 pte_t * __init populate_extra_pte(unsigned long vaddr)
244 pmd = populate_extra_pmd(vaddr);
245 return fill_pte(pmd, vaddr);
249 * Create large page table mappings for a range of physical addresses.
251 static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
258 BUG_ON((phys & ~PMD_MASK) || (size & ~PMD_MASK));
259 for (; size; phys += PMD_SIZE, size -= PMD_SIZE) {
260 pgd = pgd_offset_k((unsigned long)__va(phys));
261 if (pgd_none(*pgd)) {
262 pud = (pud_t *) spp_getpage();
263 set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
266 pud = pud_offset(pgd, (unsigned long)__va(phys));
267 if (pud_none(*pud)) {
268 pmd = (pmd_t *) spp_getpage();
269 set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
272 pmd = pmd_offset(pud, phys);
273 BUG_ON(!pmd_none(*pmd));
274 set_pmd(pmd, __pmd(phys | pgprot_val(prot)));
278 void __init init_extra_mapping_wb(unsigned long phys, unsigned long size)
280 __init_extra_mapping(phys, size, PAGE_KERNEL_LARGE);
283 void __init init_extra_mapping_uc(unsigned long phys, unsigned long size)
285 __init_extra_mapping(phys, size, PAGE_KERNEL_LARGE_NOCACHE);
289 * The head.S code sets up the kernel high mapping:
291 * from __START_KERNEL_map to __START_KERNEL_map + size (== _end-_text)
293 * phys_addr holds the negative offset to the kernel, which is added
294 * to the compile time generated pmds. This results in invalid pmds up
295 * to the point where we hit the physaddr 0 mapping.
297 * We limit the mappings to the region from _text to _end. _end is
298 * rounded up to the 2MB boundary. This catches the invalid pmds as
299 * well, as they are located before _text:
301 void __init cleanup_highmap(void)
303 unsigned long vaddr = __START_KERNEL_map;
304 unsigned long end = roundup((unsigned long)_end, PMD_SIZE) - 1;
305 pmd_t *pmd = level2_kernel_pgt;
306 pmd_t *last_pmd = pmd + PTRS_PER_PMD;
308 for (; pmd < last_pmd; pmd++, vaddr += PMD_SIZE) {
311 if (vaddr < (unsigned long) _text || vaddr > end)
312 set_pmd(pmd, __pmd(0));
316 static __ref void *alloc_low_page(unsigned long *phys)
318 unsigned long pfn = e820_table_end++;
322 adr = (void *)get_zeroed_page(GFP_ATOMIC | __GFP_NOTRACK);
328 if (pfn >= e820_table_top)
329 panic("alloc_low_page: ran out of memory");
331 adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
333 *phys = pfn * PAGE_SIZE;
337 static __ref void unmap_low_page(void *adr)
342 early_iounmap(adr, PAGE_SIZE);
345 static unsigned long __meminit
346 phys_pte_init(pte_t *pte_page, unsigned long addr, unsigned long end,
350 unsigned long last_map_addr = end;
353 pte_t *pte = pte_page + pte_index(addr);
355 for(i = pte_index(addr); i < PTRS_PER_PTE; i++, addr += PAGE_SIZE, pte++) {
358 if (!after_bootmem) {
359 for(; i < PTRS_PER_PTE; i++, pte++)
360 set_pte(pte, __pte(0));
366 * We will re-use the existing mapping.
367 * Xen for example has some special requirements, like mapping
368 * pagetable pages as RO. So assume someone who pre-setup
369 * these mappings are more intelligent.
377 printk(" pte=%p addr=%lx pte=%016lx\n",
378 pte, addr, pfn_pte(addr >> PAGE_SHIFT, PAGE_KERNEL).pte);
380 set_pte(pte, pfn_pte(addr >> PAGE_SHIFT, prot));
381 last_map_addr = (addr & PAGE_MASK) + PAGE_SIZE;
384 update_page_count(PG_LEVEL_4K, pages);
386 return last_map_addr;
389 static unsigned long __meminit
390 phys_pte_update(pmd_t *pmd, unsigned long address, unsigned long end,
393 pte_t *pte = (pte_t *)pmd_page_vaddr(*pmd);
395 return phys_pte_init(pte, address, end, prot);
398 static unsigned long __meminit
399 phys_pmd_init(pmd_t *pmd_page, unsigned long address, unsigned long end,
400 unsigned long page_size_mask, pgprot_t prot)
402 unsigned long pages = 0;
403 unsigned long last_map_addr = end;
405 int i = pmd_index(address);
407 for (; i < PTRS_PER_PMD; i++, address += PMD_SIZE) {
408 unsigned long pte_phys;
409 pmd_t *pmd = pmd_page + pmd_index(address);
411 pgprot_t new_prot = prot;
413 if (address >= end) {
414 if (!after_bootmem) {
415 for (; i < PTRS_PER_PMD; i++, pmd++)
416 set_pmd(pmd, __pmd(0));
422 if (!pmd_large(*pmd)) {
423 spin_lock(&init_mm.page_table_lock);
424 last_map_addr = phys_pte_update(pmd, address,
426 spin_unlock(&init_mm.page_table_lock);
430 * If we are ok with PG_LEVEL_2M mapping, then we will
431 * use the existing mapping,
433 * Otherwise, we will split the large page mapping but
434 * use the same existing protection bits except for
435 * large page, so that we don't violate Intel's TLB
436 * Application note (317080) which says, while changing
437 * the page sizes, new and old translations should
438 * not differ with respect to page frame and
441 if (page_size_mask & (1 << PG_LEVEL_2M)) {
445 new_prot = pte_pgprot(pte_clrhuge(*(pte_t *)pmd));
448 if (page_size_mask & (1<<PG_LEVEL_2M)) {
450 spin_lock(&init_mm.page_table_lock);
451 set_pte((pte_t *)pmd,
452 pfn_pte(address >> PAGE_SHIFT,
453 __pgprot(pgprot_val(prot) | _PAGE_PSE)));
454 spin_unlock(&init_mm.page_table_lock);
455 last_map_addr = (address & PMD_MASK) + PMD_SIZE;
459 pte = alloc_low_page(&pte_phys);
460 last_map_addr = phys_pte_init(pte, address, end, new_prot);
463 spin_lock(&init_mm.page_table_lock);
464 pmd_populate_kernel(&init_mm, pmd, __va(pte_phys));
465 spin_unlock(&init_mm.page_table_lock);
467 update_page_count(PG_LEVEL_2M, pages);
468 return last_map_addr;
471 static unsigned long __meminit
472 phys_pmd_update(pud_t *pud, unsigned long address, unsigned long end,
473 unsigned long page_size_mask, pgprot_t prot)
475 pmd_t *pmd = pmd_offset(pud, 0);
476 unsigned long last_map_addr;
478 last_map_addr = phys_pmd_init(pmd, address, end, page_size_mask, prot);
480 return last_map_addr;
483 static unsigned long __meminit
484 phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
485 unsigned long page_size_mask)
487 unsigned long pages = 0;
488 unsigned long last_map_addr = end;
489 int i = pud_index(addr);
491 for (; i < PTRS_PER_PUD; i++, addr = (addr & PUD_MASK) + PUD_SIZE) {
492 unsigned long pmd_phys;
493 pud_t *pud = pud_page + pud_index(addr);
495 pgprot_t prot = PAGE_KERNEL;
500 if (!after_bootmem &&
501 !e820_any_mapped(addr, addr+PUD_SIZE, 0)) {
502 set_pud(pud, __pud(0));
507 if (!pud_large(*pud)) {
508 last_map_addr = phys_pmd_update(pud, addr, end,
509 page_size_mask, prot);
513 * If we are ok with PG_LEVEL_1G mapping, then we will
514 * use the existing mapping.
516 * Otherwise, we will split the gbpage mapping but use
517 * the same existing protection bits except for large
518 * page, so that we don't violate Intel's TLB
519 * Application note (317080) which says, while changing
520 * the page sizes, new and old translations should
521 * not differ with respect to page frame and
524 if (page_size_mask & (1 << PG_LEVEL_1G)) {
528 prot = pte_pgprot(pte_clrhuge(*(pte_t *)pud));
531 if (page_size_mask & (1<<PG_LEVEL_1G)) {
533 spin_lock(&init_mm.page_table_lock);
534 set_pte((pte_t *)pud,
535 pfn_pte(addr >> PAGE_SHIFT, PAGE_KERNEL_LARGE));
536 spin_unlock(&init_mm.page_table_lock);
537 last_map_addr = (addr & PUD_MASK) + PUD_SIZE;
541 pmd = alloc_low_page(&pmd_phys);
542 last_map_addr = phys_pmd_init(pmd, addr, end, page_size_mask,
546 spin_lock(&init_mm.page_table_lock);
547 pud_populate(&init_mm, pud, __va(pmd_phys));
548 spin_unlock(&init_mm.page_table_lock);
552 update_page_count(PG_LEVEL_1G, pages);
554 return last_map_addr;
557 static unsigned long __meminit
558 phys_pud_update(pgd_t *pgd, unsigned long addr, unsigned long end,
559 unsigned long page_size_mask)
563 pud = (pud_t *)pgd_page_vaddr(*pgd);
565 return phys_pud_init(pud, addr, end, page_size_mask);
568 unsigned long __meminit
569 kernel_physical_mapping_init(unsigned long start,
571 unsigned long page_size_mask)
573 bool pgd_changed = false;
574 unsigned long next, last_map_addr = end;
577 start = (unsigned long)__va(start);
578 end = (unsigned long)__va(end);
581 for (; start < end; start = next) {
582 pgd_t *pgd = pgd_offset_k(start);
583 unsigned long pud_phys;
586 next = (start + PGDIR_SIZE) & PGDIR_MASK;
591 last_map_addr = phys_pud_update(pgd, __pa(start),
592 __pa(end), page_size_mask);
596 pud = alloc_low_page(&pud_phys);
597 last_map_addr = phys_pud_init(pud, __pa(start), __pa(next),
601 spin_lock(&init_mm.page_table_lock);
602 pgd_populate(&init_mm, pgd, __va(pud_phys));
603 spin_unlock(&init_mm.page_table_lock);
608 sync_global_pgds(addr, end);
612 return last_map_addr;
616 void __init initmem_init(unsigned long start_pfn, unsigned long end_pfn,
619 memblock_x86_register_active_regions(0, start_pfn, end_pfn);
623 void __init paging_init(void)
625 unsigned long max_zone_pfns[MAX_NR_ZONES];
627 memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
628 max_zone_pfns[ZONE_DMA] = MAX_DMA_PFN;
629 max_zone_pfns[ZONE_DMA32] = MAX_DMA32_PFN;
630 max_zone_pfns[ZONE_NORMAL] = max_pfn;
632 sparse_memory_present_with_active_regions(MAX_NUMNODES);
636 * clear the default setting with node 0
637 * note: don't use nodes_clear here, that is really clearing when
638 * numa support is not compiled in, and later node_set_state
639 * will not set it back.
641 node_clear_state(0, N_NORMAL_MEMORY);
643 free_area_init_nodes(max_zone_pfns);
647 * Memory hotplug specific functions
649 #ifdef CONFIG_MEMORY_HOTPLUG
651 * After memory hotplug the variables max_pfn, max_low_pfn and high_memory need
654 static void update_end_of_memory_vars(u64 start, u64 size)
656 unsigned long end_pfn = PFN_UP(start + size);
658 if (end_pfn > max_pfn) {
660 max_low_pfn = end_pfn;
661 high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
666 * Memory is added always to NORMAL zone. This means you will never get
667 * additional DMA/DMA32 memory.
669 int arch_add_memory(int nid, u64 start, u64 size)
671 struct pglist_data *pgdat = NODE_DATA(nid);
672 struct zone *zone = pgdat->node_zones + ZONE_NORMAL;
673 unsigned long last_mapped_pfn, start_pfn = start >> PAGE_SHIFT;
674 unsigned long nr_pages = size >> PAGE_SHIFT;
677 last_mapped_pfn = init_memory_mapping(start, start + size);
678 if (last_mapped_pfn > max_pfn_mapped)
679 max_pfn_mapped = last_mapped_pfn;
681 ret = __add_pages(nid, zone, start_pfn, nr_pages);
684 /* update max_pfn, max_low_pfn and high_memory */
685 update_end_of_memory_vars(start, size);
689 EXPORT_SYMBOL_GPL(arch_add_memory);
691 #if !defined(CONFIG_ACPI_NUMA) && defined(CONFIG_NUMA)
692 int memory_add_physaddr_to_nid(u64 start)
696 EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
699 #endif /* CONFIG_MEMORY_HOTPLUG */
701 static struct kcore_list kcore_vsyscall;
703 void __init mem_init(void)
705 long codesize, reservedpages, datasize, initsize;
706 unsigned long absent_pages;
710 /* clear_bss() already clear the empty_zero_page */
714 /* this will put all low memory onto the freelists */
716 totalram_pages = numa_free_all_bootmem();
718 totalram_pages = free_all_bootmem();
721 absent_pages = absent_pages_in_range(0, max_pfn);
722 reservedpages = max_pfn - totalram_pages - absent_pages;
725 codesize = (unsigned long) &_etext - (unsigned long) &_text;
726 datasize = (unsigned long) &_edata - (unsigned long) &_etext;
727 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
729 /* Register memory areas for /proc/kcore */
730 kclist_add(&kcore_vsyscall, (void *)VSYSCALL_START,
731 VSYSCALL_END - VSYSCALL_START, KCORE_OTHER);
733 printk(KERN_INFO "Memory: %luk/%luk available (%ldk kernel code, "
734 "%ldk absent, %ldk reserved, %ldk data, %ldk init)\n",
735 nr_free_pages() << (PAGE_SHIFT-10),
736 max_pfn << (PAGE_SHIFT-10),
738 absent_pages << (PAGE_SHIFT-10),
739 reservedpages << (PAGE_SHIFT-10),
744 #ifdef CONFIG_DEBUG_RODATA
745 const int rodata_test_data = 0xC3;
746 EXPORT_SYMBOL_GPL(rodata_test_data);
748 int kernel_set_to_readonly;
750 void set_kernel_text_rw(void)
752 unsigned long start = PFN_ALIGN(_text);
753 unsigned long end = PFN_ALIGN(__stop___ex_table);
755 if (!kernel_set_to_readonly)
758 pr_debug("Set kernel text: %lx - %lx for read write\n",
762 * Make the kernel identity mapping for text RW. Kernel text
763 * mapping will always be RO. Refer to the comment in
764 * static_protections() in pageattr.c
766 set_memory_rw(start, (end - start) >> PAGE_SHIFT);
769 void set_kernel_text_ro(void)
771 unsigned long start = PFN_ALIGN(_text);
772 unsigned long end = PFN_ALIGN(__stop___ex_table);
774 if (!kernel_set_to_readonly)
777 pr_debug("Set kernel text: %lx - %lx for read only\n",
781 * Set the kernel identity mapping for text RO.
783 set_memory_ro(start, (end - start) >> PAGE_SHIFT);
786 void mark_rodata_ro(void)
788 unsigned long start = PFN_ALIGN(_text);
789 unsigned long rodata_start =
790 ((unsigned long)__start_rodata + PAGE_SIZE - 1) & PAGE_MASK;
791 unsigned long end = (unsigned long) &__end_rodata_hpage_align;
792 unsigned long text_end = PAGE_ALIGN((unsigned long) &__stop___ex_table);
793 unsigned long rodata_end = PAGE_ALIGN((unsigned long) &__end_rodata);
794 unsigned long data_start = (unsigned long) &_sdata;
796 printk(KERN_INFO "Write protecting the kernel read-only data: %luk\n",
797 (end - start) >> 10);
798 set_memory_ro(start, (end - start) >> PAGE_SHIFT);
800 kernel_set_to_readonly = 1;
803 * The rodata section (but not the kernel text!) should also be
806 set_memory_nx(rodata_start, (end - rodata_start) >> PAGE_SHIFT);
810 #ifdef CONFIG_CPA_DEBUG
811 printk(KERN_INFO "Testing CPA: undo %lx-%lx\n", start, end);
812 set_memory_rw(start, (end-start) >> PAGE_SHIFT);
814 printk(KERN_INFO "Testing CPA: again\n");
815 set_memory_ro(start, (end-start) >> PAGE_SHIFT);
818 free_init_pages("unused kernel memory",
819 (unsigned long) page_address(virt_to_page(text_end)),
821 page_address(virt_to_page(rodata_start)));
822 free_init_pages("unused kernel memory",
823 (unsigned long) page_address(virt_to_page(rodata_end)),
824 (unsigned long) page_address(virt_to_page(data_start)));
829 int kern_addr_valid(unsigned long addr)
831 unsigned long above = ((long)addr) >> __VIRTUAL_MASK_SHIFT;
837 if (above != 0 && above != -1UL)
840 pgd = pgd_offset_k(addr);
844 pud = pud_offset(pgd, addr);
848 pmd = pmd_offset(pud, addr);
853 return pfn_valid(pmd_pfn(*pmd));
855 pte = pte_offset_kernel(pmd, addr);
859 return pfn_valid(pte_pfn(*pte));
863 * A pseudo VMA to allow ptrace access for the vsyscall page. This only
864 * covers the 64bit vsyscall page now. 32bit has a real VMA now and does
865 * not need special handling anymore:
867 static struct vm_area_struct gate_vma = {
868 .vm_start = VSYSCALL_START,
869 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
870 .vm_page_prot = PAGE_READONLY_EXEC,
871 .vm_flags = VM_READ | VM_EXEC
874 struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
876 #ifdef CONFIG_IA32_EMULATION
877 if (test_tsk_thread_flag(tsk, TIF_IA32))
883 int in_gate_area(struct task_struct *task, unsigned long addr)
885 struct vm_area_struct *vma = get_gate_vma(task);
890 return (addr >= vma->vm_start) && (addr < vma->vm_end);
894 * Use this when you have no reliable task/vma, typically from interrupt
895 * context. It is less reliable than using the task's vma and may give
898 int in_gate_area_no_task(unsigned long addr)
900 return (addr >= VSYSCALL_START) && (addr < VSYSCALL_END);
903 const char *arch_vma_name(struct vm_area_struct *vma)
905 if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
907 if (vma == &gate_vma)
912 #ifdef CONFIG_SPARSEMEM_VMEMMAP
914 * Initialise the sparsemem vmemmap using huge-pages at the PMD level.
916 static long __meminitdata addr_start, addr_end;
917 static void __meminitdata *p_start, *p_end;
918 static int __meminitdata node_start;
921 vmemmap_populate(struct page *start_page, unsigned long size, int node)
923 unsigned long addr = (unsigned long)start_page;
924 unsigned long end = (unsigned long)(start_page + size);
930 for (; addr < end; addr = next) {
933 pgd = vmemmap_pgd_populate(addr, node);
937 pud = vmemmap_pud_populate(pgd, addr, node);
942 next = (addr + PAGE_SIZE) & PAGE_MASK;
943 pmd = vmemmap_pmd_populate(pud, addr, node);
948 p = vmemmap_pte_populate(pmd, addr, node);
953 addr_end = addr + PAGE_SIZE;
954 p_end = p + PAGE_SIZE;
956 next = pmd_addr_end(addr, end);
958 pmd = pmd_offset(pud, addr);
959 if (pmd_none(*pmd)) {
962 p = vmemmap_alloc_block_buf(PMD_SIZE, node);
966 entry = pfn_pte(__pa(p) >> PAGE_SHIFT,
968 set_pmd(pmd, __pmd(pte_val(entry)));
970 /* check to see if we have contiguous blocks */
971 if (p_end != p || node_start != node) {
973 printk(KERN_DEBUG " [%lx-%lx] PMD -> [%p-%p] on node %d\n",
974 addr_start, addr_end-1, p_start, p_end-1, node_start);
980 addr_end = addr + PMD_SIZE;
981 p_end = p + PMD_SIZE;
983 vmemmap_verify((pte_t *)pmd, node, addr, next);
987 sync_global_pgds((unsigned long)start_page, end);
991 void __meminit vmemmap_populate_print_last(void)
994 printk(KERN_DEBUG " [%lx-%lx] PMD -> [%p-%p] on node %d\n",
995 addr_start, addr_end-1, p_start, p_end-1, node_start);