2 * linux/arch/x86_64/mm/init.c
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>
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/proc_fs.h>
25 #include <linux/pci.h>
26 #include <linux/pfn.h>
27 #include <linux/poison.h>
28 #include <linux/dma-mapping.h>
29 #include <linux/module.h>
30 #include <linux/memory_hotplug.h>
31 #include <linux/nmi.h>
33 #include <asm/processor.h>
34 #include <asm/system.h>
35 #include <asm/uaccess.h>
36 #include <asm/pgtable.h>
37 #include <asm/pgalloc.h>
39 #include <asm/fixmap.h>
43 #include <asm/mmu_context.h>
44 #include <asm/proto.h>
46 #include <asm/sections.h>
47 #include <asm/kdebug.h>
49 #include <asm/cacheflush.h>
52 * end_pfn only includes RAM, while max_pfn_mapped includes all e820 entries.
53 * The direct mapping extends to max_pfn_mapped, so that we can directly access
54 * apertures, ACPI and other tables without having to play with fixmaps.
56 unsigned long max_pfn_mapped;
58 static unsigned long dma_reserve __initdata;
60 DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
62 int direct_gbpages __meminitdata
63 #ifdef CONFIG_DIRECT_GBPAGES
68 static int __init parse_direct_gbpages_off(char *arg)
73 early_param("nogbpages", parse_direct_gbpages_off);
75 static int __init parse_direct_gbpages_on(char *arg)
80 early_param("gbpages", parse_direct_gbpages_on);
83 * NOTE: pagetable_init alloc all the fixmap pagetables contiguous on the
84 * physical space so we can cache the place of the first one and move
85 * around without checking the pgd every time.
90 long i, total = 0, reserved = 0;
91 long shared = 0, cached = 0;
95 printk(KERN_INFO "Mem-info:\n");
97 for_each_online_pgdat(pgdat) {
98 for (i = 0; i < pgdat->node_spanned_pages; ++i) {
100 * This loop can take a while with 256 GB and
101 * 4k pages so defer the NMI watchdog:
103 if (unlikely(i % MAX_ORDER_NR_PAGES == 0))
104 touch_nmi_watchdog();
106 if (!pfn_valid(pgdat->node_start_pfn + i))
109 page = pfn_to_page(pgdat->node_start_pfn + i);
111 if (PageReserved(page))
113 else if (PageSwapCache(page))
115 else if (page_count(page))
116 shared += page_count(page) - 1;
119 printk(KERN_INFO "%lu pages of RAM\n", total);
120 printk(KERN_INFO "%lu reserved pages\n", reserved);
121 printk(KERN_INFO "%lu pages shared\n", shared);
122 printk(KERN_INFO "%lu pages swap cached\n", cached);
127 static __init void *spp_getpage(void)
132 ptr = (void *) get_zeroed_page(GFP_ATOMIC);
134 ptr = alloc_bootmem_pages(PAGE_SIZE);
136 if (!ptr || ((unsigned long)ptr & ~PAGE_MASK)) {
137 panic("set_pte_phys: cannot allocate page data %s\n",
138 after_bootmem ? "after bootmem" : "");
141 pr_debug("spp_getpage %p\n", ptr);
147 set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
153 pud = pud_page + pud_index(vaddr);
154 if (pud_none(*pud)) {
155 pmd = (pmd_t *) spp_getpage();
156 pud_populate(&init_mm, pud, pmd);
157 if (pmd != pmd_offset(pud, 0)) {
158 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
159 pmd, pmd_offset(pud, 0));
163 pmd = pmd_offset(pud, vaddr);
164 if (pmd_none(*pmd)) {
165 pte = (pte_t *) spp_getpage();
166 pmd_populate_kernel(&init_mm, pmd, pte);
167 if (pte != pte_offset_kernel(pmd, 0)) {
168 printk(KERN_ERR "PAGETABLE BUG #02!\n");
173 pte = pte_offset_kernel(pmd, vaddr);
174 if (!pte_none(*pte) && pte_val(new_pte) &&
175 pte_val(*pte) != (pte_val(new_pte) & __supported_pte_mask))
177 set_pte(pte, new_pte);
180 * It's enough to flush this one mapping.
181 * (PGE mappings get flushed as well)
183 __flush_tlb_one(vaddr);
187 set_pte_vaddr(unsigned long vaddr, pte_t pteval)
192 pr_debug("set_pte_vaddr %lx to %lx\n", vaddr, native_pte_val(pteval));
194 pgd = pgd_offset_k(vaddr);
195 if (pgd_none(*pgd)) {
197 "PGD FIXMAP MISSING, it should be setup in head.S!\n");
200 pud_page = (pud_t*)pgd_page_vaddr(*pgd);
201 set_pte_vaddr_pud(pud_page, vaddr, pteval);
205 * The head.S code sets up the kernel high mapping:
207 * from __START_KERNEL_map to __START_KERNEL_map + size (== _end-_text)
209 * phys_addr holds the negative offset to the kernel, which is added
210 * to the compile time generated pmds. This results in invalid pmds up
211 * to the point where we hit the physaddr 0 mapping.
213 * We limit the mappings to the region from _text to _end. _end is
214 * rounded up to the 2MB boundary. This catches the invalid pmds as
215 * well, as they are located before _text:
217 void __init cleanup_highmap(void)
219 unsigned long vaddr = __START_KERNEL_map;
220 unsigned long end = round_up((unsigned long)_end, PMD_SIZE) - 1;
221 pmd_t *pmd = level2_kernel_pgt;
222 pmd_t *last_pmd = pmd + PTRS_PER_PMD;
224 for (; pmd < last_pmd; pmd++, vaddr += PMD_SIZE) {
227 if (vaddr < (unsigned long) _text || vaddr > end)
228 set_pmd(pmd, __pmd(0));
232 static unsigned long __initdata table_start;
233 static unsigned long __meminitdata table_end;
234 static unsigned long __meminitdata table_top;
236 static __meminit void *alloc_low_page(unsigned long *phys)
238 unsigned long pfn = table_end++;
242 adr = (void *)get_zeroed_page(GFP_ATOMIC);
248 if (pfn >= table_top)
249 panic("alloc_low_page: ran out of memory");
251 adr = early_ioremap(pfn * PAGE_SIZE, PAGE_SIZE);
252 memset(adr, 0, PAGE_SIZE);
253 *phys = pfn * PAGE_SIZE;
257 static __meminit void unmap_low_page(void *adr)
262 early_iounmap(adr, PAGE_SIZE);
265 static void __meminit
266 phys_pte_init(pte_t *pte_page, unsigned long addr, unsigned long end)
270 pte_t *pte = pte_page + pte_index(addr);
272 for(i = pte_index(addr); i < PTRS_PER_PTE; i++, addr += PAGE_SIZE, pte++) {
275 if (!after_bootmem) {
276 for(; i < PTRS_PER_PTE; i++, pte++)
277 set_pte(pte, __pte(0));
286 printk(" pte=%p addr=%lx pte=%016lx\n",
287 pte, addr, pfn_pte(addr >> PAGE_SHIFT, PAGE_KERNEL).pte);
288 set_pte(pte, pfn_pte(addr >> PAGE_SHIFT, PAGE_KERNEL));
291 update_page_count(PG_LEVEL_4K, pages);
294 static void __meminit
295 phys_pte_update(pmd_t *pmd, unsigned long address, unsigned long end)
297 pte_t *pte = (pte_t *)pmd_page_vaddr(*pmd);
299 phys_pte_init(pte, address, end);
302 static unsigned long __meminit
303 phys_pmd_init(pmd_t *pmd_page, unsigned long address, unsigned long end)
305 unsigned long pages = 0;
307 int i = pmd_index(address);
309 for (; i < PTRS_PER_PMD; i++, address += PMD_SIZE) {
310 unsigned long pte_phys;
311 pmd_t *pmd = pmd_page + pmd_index(address);
314 if (address >= end) {
315 if (!after_bootmem) {
316 for (; i < PTRS_PER_PMD; i++, pmd++)
317 set_pmd(pmd, __pmd(0));
323 if (!pmd_large(*pmd))
324 phys_pte_update(pmd, address, end);
330 set_pte((pte_t *)pmd,
331 pfn_pte(address >> PAGE_SHIFT, PAGE_KERNEL_LARGE));
335 pte = alloc_low_page(&pte_phys);
336 phys_pte_init(pte, address, end);
339 pmd_populate_kernel(&init_mm, pmd, __va(pte_phys));
341 update_page_count(PG_LEVEL_2M, pages);
345 static unsigned long __meminit
346 phys_pmd_update(pud_t *pud, unsigned long address, unsigned long end)
348 pmd_t *pmd = pmd_offset(pud, 0);
349 unsigned long last_map_addr;
351 spin_lock(&init_mm.page_table_lock);
352 last_map_addr = phys_pmd_init(pmd, address, end);
353 spin_unlock(&init_mm.page_table_lock);
355 return last_map_addr;
358 static unsigned long __meminit
359 phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end)
361 unsigned long pages = 0;
362 unsigned long last_map_addr = end;
363 int i = pud_index(addr);
365 for (; i < PTRS_PER_PUD; i++, addr = (addr & PUD_MASK) + PUD_SIZE) {
366 unsigned long pmd_phys;
367 pud_t *pud = pud_page + pud_index(addr);
373 if (!after_bootmem &&
374 !e820_any_mapped(addr, addr+PUD_SIZE, 0)) {
375 set_pud(pud, __pud(0));
380 if (!pud_large(*pud))
381 last_map_addr = phys_pmd_update(pud, addr, end);
385 if (direct_gbpages) {
387 set_pte((pte_t *)pud,
388 pfn_pte(addr >> PAGE_SHIFT, PAGE_KERNEL_LARGE));
389 last_map_addr = (addr & PUD_MASK) + PUD_SIZE;
393 pmd = alloc_low_page(&pmd_phys);
395 spin_lock(&init_mm.page_table_lock);
396 last_map_addr = phys_pmd_init(pmd, addr, end);
398 pud_populate(&init_mm, pud, __va(pmd_phys));
399 spin_unlock(&init_mm.page_table_lock);
403 update_page_count(PG_LEVEL_1G, pages);
405 return last_map_addr;
408 static unsigned long __meminit
409 phys_pud_update(pgd_t *pgd, unsigned long addr, unsigned long end)
413 pud = (pud_t *)pgd_page_vaddr(*pgd);
415 return phys_pud_init(pud, addr, end);
418 static void __init find_early_table_space(unsigned long end)
420 unsigned long puds, tables, start;
422 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
423 tables = round_up(puds * sizeof(pud_t), PAGE_SIZE);
424 if (!direct_gbpages) {
425 unsigned long pmds = (end + PMD_SIZE - 1) >> PMD_SHIFT;
426 tables += round_up(pmds * sizeof(pmd_t), PAGE_SIZE);
429 unsigned long ptes = (end + PAGE_SIZE - 1) >> PAGE_SHIFT;
430 tables += round_up(ptes * sizeof(pte_t), PAGE_SIZE);
434 * RED-PEN putting page tables only on node 0 could
435 * cause a hotspot and fill up ZONE_DMA. The page tables
436 * need roughly 0.5KB per GB.
439 table_start = find_e820_area(start, end, tables, PAGE_SIZE);
440 if (table_start == -1UL)
441 panic("Cannot find space for the kernel page tables");
443 table_start >>= PAGE_SHIFT;
444 table_end = table_start;
445 table_top = table_start + (tables >> PAGE_SHIFT);
447 printk(KERN_DEBUG "kernel direct mapping tables up to %lx @ %lx-%lx\n",
448 end, table_start << PAGE_SHIFT, table_top << PAGE_SHIFT);
451 static void __init init_gbpages(void)
453 if (direct_gbpages && cpu_has_gbpages)
454 printk(KERN_INFO "Using GB pages for direct mapping\n");
459 #ifdef CONFIG_MEMTEST
461 static void __init memtest(unsigned long start_phys, unsigned long size,
465 unsigned long *start;
466 unsigned long start_bad;
467 unsigned long last_bad;
469 unsigned long start_phys_aligned;
481 val = 0x5555555555555555UL;
484 val = 0xaaaaaaaaaaaaaaaaUL;
490 incr = sizeof(unsigned long);
491 start_phys_aligned = ALIGN(start_phys, incr);
492 count = (size - (start_phys_aligned - start_phys))/incr;
493 start = __va(start_phys_aligned);
497 for (i = 0; i < count; i++)
499 for (i = 0; i < count; i++, start++, start_phys_aligned += incr) {
501 if (start_phys_aligned == last_bad + incr) {
505 printk(KERN_CONT "\n %016lx bad mem addr %016lx - %016lx reserved",
506 val, start_bad, last_bad + incr);
507 reserve_early(start_bad, last_bad - start_bad, "BAD RAM");
509 start_bad = last_bad = start_phys_aligned;
514 printk(KERN_CONT "\n %016lx bad mem addr %016lx - %016lx reserved",
515 val, start_bad, last_bad + incr);
516 reserve_early(start_bad, last_bad - start_bad, "BAD RAM");
521 /* default is disabled */
522 static int memtest_pattern __initdata;
524 static int __init parse_memtest(char *arg)
527 memtest_pattern = simple_strtoul(arg, NULL, 0);
531 early_param("memtest", parse_memtest);
533 static void __init early_memtest(unsigned long start, unsigned long end)
538 if (!memtest_pattern)
541 printk(KERN_INFO "early_memtest: pattern num %d", memtest_pattern);
542 for (pattern = 0; pattern < memtest_pattern; pattern++) {
545 while (t_start < end) {
546 t_start = find_e820_area_size(t_start, &t_size, 1);
551 if (t_start + t_size > end)
552 t_size = end - t_start;
554 printk(KERN_CONT "\n %016llx - %016llx pattern %d",
555 (unsigned long long)t_start,
556 (unsigned long long)t_start + t_size, pattern);
558 memtest(t_start, t_size, pattern);
563 printk(KERN_CONT "\n");
566 static void __init early_memtest(unsigned long start, unsigned long end)
572 * Setup the direct mapping of the physical memory at PAGE_OFFSET.
573 * This runs before bootmem is initialized and gets pages directly from
574 * the physical memory. To access them they are temporarily mapped.
576 unsigned long __init_refok init_memory_mapping(unsigned long start, unsigned long end)
578 unsigned long next, last_map_addr = end;
579 unsigned long start_phys = start, end_phys = end;
581 printk(KERN_INFO "init_memory_mapping\n");
584 * Find space for the kernel direct mapping tables.
586 * Later we should allocate these tables in the local node of the
587 * memory mapped. Unfortunately this is done currently before the
588 * nodes are discovered.
590 if (!after_bootmem) {
592 find_early_table_space(end);
595 start = (unsigned long)__va(start);
596 end = (unsigned long)__va(end);
598 for (; start < end; start = next) {
599 pgd_t *pgd = pgd_offset_k(start);
600 unsigned long pud_phys;
603 next = start + PGDIR_SIZE;
608 last_map_addr = phys_pud_update(pgd, __pa(start), __pa(end));
613 pud = pud_offset(pgd, start & PGDIR_MASK);
615 pud = alloc_low_page(&pud_phys);
617 last_map_addr = phys_pud_init(pud, __pa(start), __pa(next));
619 pgd_populate(&init_mm, pgd_offset_k(start),
624 mmu_cr4_features = read_cr4();
628 reserve_early(table_start << PAGE_SHIFT,
629 table_end << PAGE_SHIFT, "PGTABLE");
632 early_memtest(start_phys, end_phys);
634 return last_map_addr >> PAGE_SHIFT;
638 void __init initmem_init(unsigned long start_pfn, unsigned long end_pfn)
640 unsigned long bootmap_size, bootmap;
642 bootmap_size = bootmem_bootmap_pages(end_pfn)<<PAGE_SHIFT;
643 bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT, bootmap_size,
646 panic("Cannot find bootmem map of size %ld\n", bootmap_size);
647 /* don't touch min_low_pfn */
648 bootmap_size = init_bootmem_node(NODE_DATA(0), bootmap >> PAGE_SHIFT,
650 e820_register_active_regions(0, start_pfn, end_pfn);
651 free_bootmem_with_active_regions(0, end_pfn);
652 early_res_to_bootmem(0, end_pfn<<PAGE_SHIFT);
653 reserve_bootmem(bootmap, bootmap_size, BOOTMEM_DEFAULT);
656 void __init paging_init(void)
658 unsigned long max_zone_pfns[MAX_NR_ZONES];
660 memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
661 max_zone_pfns[ZONE_DMA] = MAX_DMA_PFN;
662 max_zone_pfns[ZONE_DMA32] = MAX_DMA32_PFN;
663 max_zone_pfns[ZONE_NORMAL] = max_pfn;
665 memory_present(0, 0, max_pfn);
667 free_area_init_nodes(max_zone_pfns);
672 * Memory hotplug specific functions
674 #ifdef CONFIG_MEMORY_HOTPLUG
676 * Memory is added always to NORMAL zone. This means you will never get
677 * additional DMA/DMA32 memory.
679 int arch_add_memory(int nid, u64 start, u64 size)
681 struct pglist_data *pgdat = NODE_DATA(nid);
682 struct zone *zone = pgdat->node_zones + ZONE_NORMAL;
683 unsigned long last_mapped_pfn, start_pfn = start >> PAGE_SHIFT;
684 unsigned long nr_pages = size >> PAGE_SHIFT;
687 last_mapped_pfn = init_memory_mapping(start, start + size-1);
688 if (last_mapped_pfn > max_pfn_mapped)
689 max_pfn_mapped = last_mapped_pfn;
691 ret = __add_pages(zone, start_pfn, nr_pages);
696 EXPORT_SYMBOL_GPL(arch_add_memory);
698 #if !defined(CONFIG_ACPI_NUMA) && defined(CONFIG_NUMA)
699 int memory_add_physaddr_to_nid(u64 start)
703 EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
706 #endif /* CONFIG_MEMORY_HOTPLUG */
709 * devmem_is_allowed() checks to see if /dev/mem access to a certain address
710 * is valid. The argument is a physical page number.
713 * On x86, access has to be given to the first megabyte of ram because that area
714 * contains bios code and data regions used by X and dosemu and similar apps.
715 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
716 * mmio resources as well as potential bios/acpi data regions.
718 int devmem_is_allowed(unsigned long pagenr)
722 if (!page_is_ram(pagenr))
728 static struct kcore_list kcore_mem, kcore_vmalloc, kcore_kernel,
729 kcore_modules, kcore_vsyscall;
731 void __init mem_init(void)
733 long codesize, reservedpages, datasize, initsize;
737 /* clear_bss() already clear the empty_zero_page */
741 /* this will put all low memory onto the freelists */
743 totalram_pages = numa_free_all_bootmem();
745 totalram_pages = free_all_bootmem();
747 reservedpages = max_pfn - totalram_pages -
748 absent_pages_in_range(0, max_pfn);
751 codesize = (unsigned long) &_etext - (unsigned long) &_text;
752 datasize = (unsigned long) &_edata - (unsigned long) &_etext;
753 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
755 /* Register memory areas for /proc/kcore */
756 kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT);
757 kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
758 VMALLOC_END-VMALLOC_START);
759 kclist_add(&kcore_kernel, &_stext, _end - _stext);
760 kclist_add(&kcore_modules, (void *)MODULES_VADDR, MODULES_LEN);
761 kclist_add(&kcore_vsyscall, (void *)VSYSCALL_START,
762 VSYSCALL_END - VSYSCALL_START);
764 printk(KERN_INFO "Memory: %luk/%luk available (%ldk kernel code, "
765 "%ldk reserved, %ldk data, %ldk init)\n",
766 (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
767 max_pfn << (PAGE_SHIFT-10),
769 reservedpages << (PAGE_SHIFT-10),
776 void free_init_pages(char *what, unsigned long begin, unsigned long end)
778 unsigned long addr = begin;
784 * If debugging page accesses then do not free this memory but
785 * mark them not present - any buggy init-section access will
786 * create a kernel page fault:
788 #ifdef CONFIG_DEBUG_PAGEALLOC
789 printk(KERN_INFO "debug: unmapping init memory %08lx..%08lx\n",
790 begin, PAGE_ALIGN(end));
791 set_memory_np(begin, (end - begin) >> PAGE_SHIFT);
793 printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
795 for (; addr < end; addr += PAGE_SIZE) {
796 ClearPageReserved(virt_to_page(addr));
797 init_page_count(virt_to_page(addr));
798 memset((void *)(addr & ~(PAGE_SIZE-1)),
799 POISON_FREE_INITMEM, PAGE_SIZE);
806 void free_initmem(void)
808 free_init_pages("unused kernel memory",
809 (unsigned long)(&__init_begin),
810 (unsigned long)(&__init_end));
813 #ifdef CONFIG_DEBUG_RODATA
814 const int rodata_test_data = 0xC3;
815 EXPORT_SYMBOL_GPL(rodata_test_data);
817 void mark_rodata_ro(void)
819 unsigned long start = PFN_ALIGN(_stext), end = PFN_ALIGN(__end_rodata);
821 printk(KERN_INFO "Write protecting the kernel read-only data: %luk\n",
822 (end - start) >> 10);
823 set_memory_ro(start, (end - start) >> PAGE_SHIFT);
826 * The rodata section (but not the kernel text!) should also be
829 start = ((unsigned long)__start_rodata + PAGE_SIZE - 1) & PAGE_MASK;
830 set_memory_nx(start, (end - start) >> PAGE_SHIFT);
834 #ifdef CONFIG_CPA_DEBUG
835 printk(KERN_INFO "Testing CPA: undo %lx-%lx\n", start, end);
836 set_memory_rw(start, (end-start) >> PAGE_SHIFT);
838 printk(KERN_INFO "Testing CPA: again\n");
839 set_memory_ro(start, (end-start) >> PAGE_SHIFT);
845 #ifdef CONFIG_BLK_DEV_INITRD
846 void free_initrd_mem(unsigned long start, unsigned long end)
848 free_init_pages("initrd memory", start, end);
852 int __init reserve_bootmem_generic(unsigned long phys, unsigned long len,
859 unsigned long pfn = phys >> PAGE_SHIFT;
861 if (pfn >= max_pfn) {
863 * This can happen with kdump kernels when accessing
866 if (pfn < max_pfn_mapped)
869 printk(KERN_ERR "reserve_bootmem: illegal reserve %lx %lu\n",
874 /* Should check here against the e820 map to avoid double free */
876 nid = phys_to_nid(phys);
877 next_nid = phys_to_nid(phys + len - 1);
879 ret = reserve_bootmem_node(NODE_DATA(nid), phys, len, flags);
881 ret = reserve_bootmem(phys, len, flags);
887 reserve_bootmem(phys, len, BOOTMEM_DEFAULT);
890 if (phys+len <= MAX_DMA_PFN*PAGE_SIZE) {
891 dma_reserve += len / PAGE_SIZE;
892 set_dma_reserve(dma_reserve);
898 int kern_addr_valid(unsigned long addr)
900 unsigned long above = ((long)addr) >> __VIRTUAL_MASK_SHIFT;
906 if (above != 0 && above != -1UL)
909 pgd = pgd_offset_k(addr);
913 pud = pud_offset(pgd, addr);
917 pmd = pmd_offset(pud, addr);
922 return pfn_valid(pmd_pfn(*pmd));
924 pte = pte_offset_kernel(pmd, addr);
928 return pfn_valid(pte_pfn(*pte));
932 * A pseudo VMA to allow ptrace access for the vsyscall page. This only
933 * covers the 64bit vsyscall page now. 32bit has a real VMA now and does
934 * not need special handling anymore:
936 static struct vm_area_struct gate_vma = {
937 .vm_start = VSYSCALL_START,
938 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
939 .vm_page_prot = PAGE_READONLY_EXEC,
940 .vm_flags = VM_READ | VM_EXEC
943 struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
945 #ifdef CONFIG_IA32_EMULATION
946 if (test_tsk_thread_flag(tsk, TIF_IA32))
952 int in_gate_area(struct task_struct *task, unsigned long addr)
954 struct vm_area_struct *vma = get_gate_vma(task);
959 return (addr >= vma->vm_start) && (addr < vma->vm_end);
963 * Use this when you have no reliable task/vma, typically from interrupt
964 * context. It is less reliable than using the task's vma and may give
967 int in_gate_area_no_task(unsigned long addr)
969 return (addr >= VSYSCALL_START) && (addr < VSYSCALL_END);
972 const char *arch_vma_name(struct vm_area_struct *vma)
974 if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
976 if (vma == &gate_vma)
981 #ifdef CONFIG_SPARSEMEM_VMEMMAP
983 * Initialise the sparsemem vmemmap using huge-pages at the PMD level.
985 static long __meminitdata addr_start, addr_end;
986 static void __meminitdata *p_start, *p_end;
987 static int __meminitdata node_start;
990 vmemmap_populate(struct page *start_page, unsigned long size, int node)
992 unsigned long addr = (unsigned long)start_page;
993 unsigned long end = (unsigned long)(start_page + size);
999 for (; addr < end; addr = next) {
1002 pgd = vmemmap_pgd_populate(addr, node);
1006 pud = vmemmap_pud_populate(pgd, addr, node);
1011 next = (addr + PAGE_SIZE) & PAGE_MASK;
1012 pmd = vmemmap_pmd_populate(pud, addr, node);
1017 p = vmemmap_pte_populate(pmd, addr, node);
1022 addr_end = addr + PAGE_SIZE;
1023 p_end = p + PAGE_SIZE;
1025 next = pmd_addr_end(addr, end);
1027 pmd = pmd_offset(pud, addr);
1028 if (pmd_none(*pmd)) {
1031 p = vmemmap_alloc_block(PMD_SIZE, node);
1035 entry = pfn_pte(__pa(p) >> PAGE_SHIFT,
1037 set_pmd(pmd, __pmd(pte_val(entry)));
1039 addr_end = addr + PMD_SIZE;
1040 p_end = p + PMD_SIZE;
1042 /* check to see if we have contiguous blocks */
1043 if (p_end != p || node_start != node) {
1045 printk(KERN_DEBUG " [%lx-%lx] PMD -> [%p-%p] on node %d\n",
1046 addr_start, addr_end-1, p_start, p_end-1, node_start);
1052 vmemmap_verify((pte_t *)pmd, node, addr, next);
1059 void __meminit vmemmap_populate_print_last(void)
1062 printk(KERN_DEBUG " [%lx-%lx] PMD -> [%p-%p] on node %d\n",
1063 addr_start, addr_end-1, p_start, p_end-1, node_start);