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>
55 static int __init parse_direct_gbpages_off(char *arg)
60 early_param("nogbpages", parse_direct_gbpages_off);
62 static int __init parse_direct_gbpages_on(char *arg)
67 early_param("gbpages", parse_direct_gbpages_on);
70 * NOTE: pagetable_init alloc all the fixmap pagetables contiguous on the
71 * physical space so we can cache the place of the first one and move
72 * around without checking the pgd every time.
75 pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
76 EXPORT_SYMBOL_GPL(__supported_pte_mask);
78 int force_personality32;
82 * Control non executable heap for 32bit processes.
83 * To control the stack too use noexec=off
85 * on PROT_READ does not imply PROT_EXEC for 32-bit processes (default)
86 * off PROT_READ implies PROT_EXEC
88 static int __init nonx32_setup(char *str)
90 if (!strcmp(str, "on"))
91 force_personality32 &= ~READ_IMPLIES_EXEC;
92 else if (!strcmp(str, "off"))
93 force_personality32 |= READ_IMPLIES_EXEC;
96 __setup("noexec32=", nonx32_setup);
99 * When memory was added/removed make sure all the processes MM have
100 * suitable PGD entries in the local PGD level page.
102 void sync_global_pgds(unsigned long start, unsigned long end)
104 unsigned long address;
106 for (address = start; address <= end; address += PGDIR_SIZE) {
107 const pgd_t *pgd_ref = pgd_offset_k(address);
111 if (pgd_none(*pgd_ref))
114 spin_lock_irqsave(&pgd_lock, flags);
115 list_for_each_entry(page, &pgd_list, lru) {
117 spinlock_t *pgt_lock;
119 pgd = (pgd_t *)page_address(page) + pgd_index(address);
120 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
124 set_pgd(pgd, *pgd_ref);
126 BUG_ON(pgd_page_vaddr(*pgd)
127 != pgd_page_vaddr(*pgd_ref));
129 spin_unlock(pgt_lock);
131 spin_unlock_irqrestore(&pgd_lock, flags);
136 * NOTE: This function is marked __ref because it calls __init function
137 * (alloc_bootmem_pages). It's safe to do it ONLY when after_bootmem == 0.
139 static __ref void *spp_getpage(void)
144 ptr = (void *) get_zeroed_page(GFP_ATOMIC | __GFP_NOTRACK);
146 ptr = alloc_bootmem_pages(PAGE_SIZE);
148 if (!ptr || ((unsigned long)ptr & ~PAGE_MASK)) {
149 panic("set_pte_phys: cannot allocate page data %s\n",
150 after_bootmem ? "after bootmem" : "");
153 pr_debug("spp_getpage %p\n", ptr);
158 static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
160 if (pgd_none(*pgd)) {
161 pud_t *pud = (pud_t *)spp_getpage();
162 pgd_populate(&init_mm, pgd, pud);
163 if (pud != pud_offset(pgd, 0))
164 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
165 pud, pud_offset(pgd, 0));
167 return pud_offset(pgd, vaddr);
170 static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
172 if (pud_none(*pud)) {
173 pmd_t *pmd = (pmd_t *) spp_getpage();
174 pud_populate(&init_mm, pud, pmd);
175 if (pmd != pmd_offset(pud, 0))
176 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
177 pmd, pmd_offset(pud, 0));
179 return pmd_offset(pud, vaddr);
182 static pte_t *fill_pte(pmd_t *pmd, unsigned long vaddr)
184 if (pmd_none(*pmd)) {
185 pte_t *pte = (pte_t *) spp_getpage();
186 pmd_populate_kernel(&init_mm, pmd, pte);
187 if (pte != pte_offset_kernel(pmd, 0))
188 printk(KERN_ERR "PAGETABLE BUG #02!\n");
190 return pte_offset_kernel(pmd, vaddr);
193 void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
199 pud = pud_page + pud_index(vaddr);
200 pmd = fill_pmd(pud, vaddr);
201 pte = fill_pte(pmd, vaddr);
203 set_pte(pte, new_pte);
206 * It's enough to flush this one mapping.
207 * (PGE mappings get flushed as well)
209 __flush_tlb_one(vaddr);
212 void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
217 pr_debug("set_pte_vaddr %lx to %lx\n", vaddr, native_pte_val(pteval));
219 pgd = pgd_offset_k(vaddr);
220 if (pgd_none(*pgd)) {
222 "PGD FIXMAP MISSING, it should be setup in head.S!\n");
225 pud_page = (pud_t*)pgd_page_vaddr(*pgd);
226 set_pte_vaddr_pud(pud_page, vaddr, pteval);
229 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
234 pgd = pgd_offset_k(vaddr);
235 pud = fill_pud(pgd, vaddr);
236 return fill_pmd(pud, vaddr);
239 pte_t * __init populate_extra_pte(unsigned long vaddr)
243 pmd = populate_extra_pmd(vaddr);
244 return fill_pte(pmd, vaddr);
248 * Create large page table mappings for a range of physical addresses.
250 static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
257 BUG_ON((phys & ~PMD_MASK) || (size & ~PMD_MASK));
258 for (; size; phys += PMD_SIZE, size -= PMD_SIZE) {
259 pgd = pgd_offset_k((unsigned long)__va(phys));
260 if (pgd_none(*pgd)) {
261 pud = (pud_t *) spp_getpage();
262 set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
265 pud = pud_offset(pgd, (unsigned long)__va(phys));
266 if (pud_none(*pud)) {
267 pmd = (pmd_t *) spp_getpage();
268 set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
271 pmd = pmd_offset(pud, phys);
272 BUG_ON(!pmd_none(*pmd));
273 set_pmd(pmd, __pmd(phys | pgprot_val(prot)));
277 void __init init_extra_mapping_wb(unsigned long phys, unsigned long size)
279 __init_extra_mapping(phys, size, PAGE_KERNEL_LARGE);
282 void __init init_extra_mapping_uc(unsigned long phys, unsigned long size)
284 __init_extra_mapping(phys, size, PAGE_KERNEL_LARGE_NOCACHE);
288 * The head.S code sets up the kernel high mapping:
290 * from __START_KERNEL_map to __START_KERNEL_map + size (== _end-_text)
292 * phys_addr holds the negative offset to the kernel, which is added
293 * to the compile time generated pmds. This results in invalid pmds up
294 * to the point where we hit the physaddr 0 mapping.
296 * We limit the mappings to the region from _text to _end. _end is
297 * rounded up to the 2MB boundary. This catches the invalid pmds as
298 * well, as they are located before _text:
300 void __init cleanup_highmap(void)
302 unsigned long vaddr = __START_KERNEL_map;
303 unsigned long end = roundup((unsigned long)_end, PMD_SIZE) - 1;
304 pmd_t *pmd = level2_kernel_pgt;
305 pmd_t *last_pmd = pmd + PTRS_PER_PMD;
307 for (; pmd < last_pmd; pmd++, vaddr += PMD_SIZE) {
310 if (vaddr < (unsigned long) _text || vaddr > end)
311 set_pmd(pmd, __pmd(0));
315 static __ref void *alloc_low_page(unsigned long *phys)
317 unsigned long pfn = e820_table_end++;
321 adr = (void *)get_zeroed_page(GFP_ATOMIC | __GFP_NOTRACK);
327 if (pfn >= e820_table_top)
328 panic("alloc_low_page: ran out of memory");
330 adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
332 *phys = pfn * PAGE_SIZE;
336 static __ref void *map_low_page(void *virt)
339 unsigned long phys, left;
345 left = phys & (PAGE_SIZE - 1);
346 adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
347 adr = (void *)(((unsigned long)adr) | left);
352 static __ref void unmap_low_page(void *adr)
357 early_iounmap((void *)((unsigned long)adr & PAGE_MASK), PAGE_SIZE);
360 static unsigned long __meminit
361 phys_pte_init(pte_t *pte_page, unsigned long addr, unsigned long end,
365 unsigned long last_map_addr = end;
368 pte_t *pte = pte_page + pte_index(addr);
370 for(i = pte_index(addr); i < PTRS_PER_PTE; i++, addr += PAGE_SIZE, pte++) {
373 if (!after_bootmem) {
374 for(; i < PTRS_PER_PTE; i++, pte++)
375 set_pte(pte, __pte(0));
381 * We will re-use the existing mapping.
382 * Xen for example has some special requirements, like mapping
383 * pagetable pages as RO. So assume someone who pre-setup
384 * these mappings are more intelligent.
392 printk(" pte=%p addr=%lx pte=%016lx\n",
393 pte, addr, pfn_pte(addr >> PAGE_SHIFT, PAGE_KERNEL).pte);
395 set_pte(pte, pfn_pte(addr >> PAGE_SHIFT, prot));
396 last_map_addr = (addr & PAGE_MASK) + PAGE_SIZE;
399 update_page_count(PG_LEVEL_4K, pages);
401 return last_map_addr;
404 static unsigned long __meminit
405 phys_pmd_init(pmd_t *pmd_page, unsigned long address, unsigned long end,
406 unsigned long page_size_mask, pgprot_t prot)
408 unsigned long pages = 0;
409 unsigned long last_map_addr = end;
411 int i = pmd_index(address);
413 for (; i < PTRS_PER_PMD; i++, address += PMD_SIZE) {
414 unsigned long pte_phys;
415 pmd_t *pmd = pmd_page + pmd_index(address);
417 pgprot_t new_prot = prot;
419 if (address >= end) {
420 if (!after_bootmem) {
421 for (; i < PTRS_PER_PMD; i++, pmd++)
422 set_pmd(pmd, __pmd(0));
428 if (!pmd_large(*pmd)) {
429 spin_lock(&init_mm.page_table_lock);
430 pte = map_low_page((pte_t *)pmd_page_vaddr(*pmd));
431 last_map_addr = phys_pte_init(pte, address,
434 spin_unlock(&init_mm.page_table_lock);
438 * If we are ok with PG_LEVEL_2M mapping, then we will
439 * use the existing mapping,
441 * Otherwise, we will split the large page mapping but
442 * use the same existing protection bits except for
443 * large page, so that we don't violate Intel's TLB
444 * Application note (317080) which says, while changing
445 * the page sizes, new and old translations should
446 * not differ with respect to page frame and
449 if (page_size_mask & (1 << PG_LEVEL_2M)) {
453 new_prot = pte_pgprot(pte_clrhuge(*(pte_t *)pmd));
456 if (page_size_mask & (1<<PG_LEVEL_2M)) {
458 spin_lock(&init_mm.page_table_lock);
459 set_pte((pte_t *)pmd,
460 pfn_pte(address >> PAGE_SHIFT,
461 __pgprot(pgprot_val(prot) | _PAGE_PSE)));
462 spin_unlock(&init_mm.page_table_lock);
463 last_map_addr = (address & PMD_MASK) + PMD_SIZE;
467 pte = alloc_low_page(&pte_phys);
468 last_map_addr = phys_pte_init(pte, address, end, new_prot);
471 spin_lock(&init_mm.page_table_lock);
472 pmd_populate_kernel(&init_mm, pmd, __va(pte_phys));
473 spin_unlock(&init_mm.page_table_lock);
475 update_page_count(PG_LEVEL_2M, pages);
476 return last_map_addr;
479 static unsigned long __meminit
480 phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
481 unsigned long page_size_mask)
483 unsigned long pages = 0;
484 unsigned long last_map_addr = end;
485 int i = pud_index(addr);
487 for (; i < PTRS_PER_PUD; i++, addr = (addr & PUD_MASK) + PUD_SIZE) {
488 unsigned long pmd_phys;
489 pud_t *pud = pud_page + pud_index(addr);
491 pgprot_t prot = PAGE_KERNEL;
496 if (!after_bootmem &&
497 !e820_any_mapped(addr, addr+PUD_SIZE, 0)) {
498 set_pud(pud, __pud(0));
503 if (!pud_large(*pud)) {
504 pmd = map_low_page(pmd_offset(pud, 0));
505 last_map_addr = phys_pmd_init(pmd, addr, end,
506 page_size_mask, prot);
512 * If we are ok with PG_LEVEL_1G mapping, then we will
513 * use the existing mapping.
515 * Otherwise, we will split the gbpage mapping but use
516 * the same existing protection bits except for large
517 * page, so that we don't violate Intel's TLB
518 * Application note (317080) which says, while changing
519 * the page sizes, new and old translations should
520 * not differ with respect to page frame and
523 if (page_size_mask & (1 << PG_LEVEL_1G)) {
527 prot = pte_pgprot(pte_clrhuge(*(pte_t *)pud));
530 if (page_size_mask & (1<<PG_LEVEL_1G)) {
532 spin_lock(&init_mm.page_table_lock);
533 set_pte((pte_t *)pud,
534 pfn_pte(addr >> PAGE_SHIFT, PAGE_KERNEL_LARGE));
535 spin_unlock(&init_mm.page_table_lock);
536 last_map_addr = (addr & PUD_MASK) + PUD_SIZE;
540 pmd = alloc_low_page(&pmd_phys);
541 last_map_addr = phys_pmd_init(pmd, addr, end, page_size_mask,
545 spin_lock(&init_mm.page_table_lock);
546 pud_populate(&init_mm, pud, __va(pmd_phys));
547 spin_unlock(&init_mm.page_table_lock);
551 update_page_count(PG_LEVEL_1G, pages);
553 return last_map_addr;
556 unsigned long __meminit
557 kernel_physical_mapping_init(unsigned long start,
559 unsigned long page_size_mask)
561 bool pgd_changed = false;
562 unsigned long next, last_map_addr = end;
565 start = (unsigned long)__va(start);
566 end = (unsigned long)__va(end);
569 for (; start < end; start = next) {
570 pgd_t *pgd = pgd_offset_k(start);
571 unsigned long pud_phys;
574 next = (start + PGDIR_SIZE) & PGDIR_MASK;
579 pud = map_low_page((pud_t *)pgd_page_vaddr(*pgd));
580 last_map_addr = phys_pud_init(pud, __pa(start),
581 __pa(end), page_size_mask);
586 pud = alloc_low_page(&pud_phys);
587 last_map_addr = phys_pud_init(pud, __pa(start), __pa(next),
591 spin_lock(&init_mm.page_table_lock);
592 pgd_populate(&init_mm, pgd, __va(pud_phys));
593 spin_unlock(&init_mm.page_table_lock);
598 sync_global_pgds(addr, end);
602 return last_map_addr;
606 void __init initmem_init(unsigned long start_pfn, unsigned long end_pfn,
609 memblock_x86_register_active_regions(0, start_pfn, end_pfn);
613 void __init paging_init(void)
615 unsigned long max_zone_pfns[MAX_NR_ZONES];
617 memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
618 max_zone_pfns[ZONE_DMA] = MAX_DMA_PFN;
619 max_zone_pfns[ZONE_DMA32] = MAX_DMA32_PFN;
620 max_zone_pfns[ZONE_NORMAL] = max_pfn;
622 sparse_memory_present_with_active_regions(MAX_NUMNODES);
626 * clear the default setting with node 0
627 * note: don't use nodes_clear here, that is really clearing when
628 * numa support is not compiled in, and later node_set_state
629 * will not set it back.
631 node_clear_state(0, N_NORMAL_MEMORY);
633 free_area_init_nodes(max_zone_pfns);
637 * Memory hotplug specific functions
639 #ifdef CONFIG_MEMORY_HOTPLUG
641 * After memory hotplug the variables max_pfn, max_low_pfn and high_memory need
644 static void update_end_of_memory_vars(u64 start, u64 size)
646 unsigned long end_pfn = PFN_UP(start + size);
648 if (end_pfn > max_pfn) {
650 max_low_pfn = end_pfn;
651 high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
656 * Memory is added always to NORMAL zone. This means you will never get
657 * additional DMA/DMA32 memory.
659 int arch_add_memory(int nid, u64 start, u64 size)
661 struct pglist_data *pgdat = NODE_DATA(nid);
662 struct zone *zone = pgdat->node_zones + ZONE_NORMAL;
663 unsigned long last_mapped_pfn, start_pfn = start >> PAGE_SHIFT;
664 unsigned long nr_pages = size >> PAGE_SHIFT;
667 last_mapped_pfn = init_memory_mapping(start, start + size);
668 if (last_mapped_pfn > max_pfn_mapped)
669 max_pfn_mapped = last_mapped_pfn;
671 ret = __add_pages(nid, zone, start_pfn, nr_pages);
674 /* update max_pfn, max_low_pfn and high_memory */
675 update_end_of_memory_vars(start, size);
679 EXPORT_SYMBOL_GPL(arch_add_memory);
681 #if !defined(CONFIG_ACPI_NUMA) && defined(CONFIG_NUMA)
682 int memory_add_physaddr_to_nid(u64 start)
686 EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
689 #endif /* CONFIG_MEMORY_HOTPLUG */
691 static struct kcore_list kcore_vsyscall;
693 void __init mem_init(void)
695 long codesize, reservedpages, datasize, initsize;
696 unsigned long absent_pages;
700 /* clear_bss() already clear the empty_zero_page */
704 /* this will put all low memory onto the freelists */
706 totalram_pages = numa_free_all_bootmem();
708 totalram_pages = free_all_bootmem();
711 absent_pages = absent_pages_in_range(0, max_pfn);
712 reservedpages = max_pfn - totalram_pages - absent_pages;
715 codesize = (unsigned long) &_etext - (unsigned long) &_text;
716 datasize = (unsigned long) &_edata - (unsigned long) &_etext;
717 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
719 /* Register memory areas for /proc/kcore */
720 kclist_add(&kcore_vsyscall, (void *)VSYSCALL_START,
721 VSYSCALL_END - VSYSCALL_START, KCORE_OTHER);
723 printk(KERN_INFO "Memory: %luk/%luk available (%ldk kernel code, "
724 "%ldk absent, %ldk reserved, %ldk data, %ldk init)\n",
725 nr_free_pages() << (PAGE_SHIFT-10),
726 max_pfn << (PAGE_SHIFT-10),
728 absent_pages << (PAGE_SHIFT-10),
729 reservedpages << (PAGE_SHIFT-10),
734 #ifdef CONFIG_DEBUG_RODATA
735 const int rodata_test_data = 0xC3;
736 EXPORT_SYMBOL_GPL(rodata_test_data);
738 int kernel_set_to_readonly;
740 void set_kernel_text_rw(void)
742 unsigned long start = PFN_ALIGN(_text);
743 unsigned long end = PFN_ALIGN(__stop___ex_table);
745 if (!kernel_set_to_readonly)
748 pr_debug("Set kernel text: %lx - %lx for read write\n",
752 * Make the kernel identity mapping for text RW. Kernel text
753 * mapping will always be RO. Refer to the comment in
754 * static_protections() in pageattr.c
756 set_memory_rw(start, (end - start) >> PAGE_SHIFT);
759 void set_kernel_text_ro(void)
761 unsigned long start = PFN_ALIGN(_text);
762 unsigned long end = PFN_ALIGN(__stop___ex_table);
764 if (!kernel_set_to_readonly)
767 pr_debug("Set kernel text: %lx - %lx for read only\n",
771 * Set the kernel identity mapping for text RO.
773 set_memory_ro(start, (end - start) >> PAGE_SHIFT);
776 void mark_rodata_ro(void)
778 unsigned long start = PFN_ALIGN(_text);
779 unsigned long rodata_start =
780 ((unsigned long)__start_rodata + PAGE_SIZE - 1) & PAGE_MASK;
781 unsigned long end = (unsigned long) &__end_rodata_hpage_align;
782 unsigned long text_end = PAGE_ALIGN((unsigned long) &__stop___ex_table);
783 unsigned long rodata_end = PAGE_ALIGN((unsigned long) &__end_rodata);
784 unsigned long data_start = (unsigned long) &_sdata;
786 printk(KERN_INFO "Write protecting the kernel read-only data: %luk\n",
787 (end - start) >> 10);
788 set_memory_ro(start, (end - start) >> PAGE_SHIFT);
790 kernel_set_to_readonly = 1;
793 * The rodata section (but not the kernel text!) should also be
796 set_memory_nx(rodata_start, (end - rodata_start) >> PAGE_SHIFT);
800 #ifdef CONFIG_CPA_DEBUG
801 printk(KERN_INFO "Testing CPA: undo %lx-%lx\n", start, end);
802 set_memory_rw(start, (end-start) >> PAGE_SHIFT);
804 printk(KERN_INFO "Testing CPA: again\n");
805 set_memory_ro(start, (end-start) >> PAGE_SHIFT);
808 free_init_pages("unused kernel memory",
809 (unsigned long) page_address(virt_to_page(text_end)),
811 page_address(virt_to_page(rodata_start)));
812 free_init_pages("unused kernel memory",
813 (unsigned long) page_address(virt_to_page(rodata_end)),
814 (unsigned long) page_address(virt_to_page(data_start)));
819 int kern_addr_valid(unsigned long addr)
821 unsigned long above = ((long)addr) >> __VIRTUAL_MASK_SHIFT;
827 if (above != 0 && above != -1UL)
830 pgd = pgd_offset_k(addr);
834 pud = pud_offset(pgd, addr);
838 pmd = pmd_offset(pud, addr);
843 return pfn_valid(pmd_pfn(*pmd));
845 pte = pte_offset_kernel(pmd, addr);
849 return pfn_valid(pte_pfn(*pte));
853 * A pseudo VMA to allow ptrace access for the vsyscall page. This only
854 * covers the 64bit vsyscall page now. 32bit has a real VMA now and does
855 * not need special handling anymore:
857 static struct vm_area_struct gate_vma = {
858 .vm_start = VSYSCALL_START,
859 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
860 .vm_page_prot = PAGE_READONLY_EXEC,
861 .vm_flags = VM_READ | VM_EXEC
864 struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
866 #ifdef CONFIG_IA32_EMULATION
867 if (test_tsk_thread_flag(tsk, TIF_IA32))
873 int in_gate_area(struct task_struct *task, unsigned long addr)
875 struct vm_area_struct *vma = get_gate_vma(task);
880 return (addr >= vma->vm_start) && (addr < vma->vm_end);
884 * Use this when you have no reliable task/vma, typically from interrupt
885 * context. It is less reliable than using the task's vma and may give
888 int in_gate_area_no_task(unsigned long addr)
890 return (addr >= VSYSCALL_START) && (addr < VSYSCALL_END);
893 const char *arch_vma_name(struct vm_area_struct *vma)
895 if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
897 if (vma == &gate_vma)
902 #ifdef CONFIG_SPARSEMEM_VMEMMAP
904 * Initialise the sparsemem vmemmap using huge-pages at the PMD level.
906 static long __meminitdata addr_start, addr_end;
907 static void __meminitdata *p_start, *p_end;
908 static int __meminitdata node_start;
911 vmemmap_populate(struct page *start_page, unsigned long size, int node)
913 unsigned long addr = (unsigned long)start_page;
914 unsigned long end = (unsigned long)(start_page + size);
920 for (; addr < end; addr = next) {
923 pgd = vmemmap_pgd_populate(addr, node);
927 pud = vmemmap_pud_populate(pgd, addr, node);
932 next = (addr + PAGE_SIZE) & PAGE_MASK;
933 pmd = vmemmap_pmd_populate(pud, addr, node);
938 p = vmemmap_pte_populate(pmd, addr, node);
943 addr_end = addr + PAGE_SIZE;
944 p_end = p + PAGE_SIZE;
946 next = pmd_addr_end(addr, end);
948 pmd = pmd_offset(pud, addr);
949 if (pmd_none(*pmd)) {
952 p = vmemmap_alloc_block_buf(PMD_SIZE, node);
956 entry = pfn_pte(__pa(p) >> PAGE_SHIFT,
958 set_pmd(pmd, __pmd(pte_val(entry)));
960 /* check to see if we have contiguous blocks */
961 if (p_end != p || node_start != node) {
963 printk(KERN_DEBUG " [%lx-%lx] PMD -> [%p-%p] on node %d\n",
964 addr_start, addr_end-1, p_start, p_end-1, node_start);
970 addr_end = addr + PMD_SIZE;
971 p_end = p + PMD_SIZE;
973 vmemmap_verify((pte_t *)pmd, node, addr, next);
977 sync_global_pgds((unsigned long)start_page, end);
981 void __meminit vmemmap_populate_print_last(void)
984 printk(KERN_DEBUG " [%lx-%lx] PMD -> [%p-%p] on node %d\n",
985 addr_start, addr_end-1, p_start, p_end-1, node_start);