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.h>
32 #include <linux/memory_hotplug.h>
33 #include <linux/nmi.h>
34 #include <linux/gfp.h>
36 #include <asm/processor.h>
37 #include <asm/bios_ebda.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 <asm/uv/uv.h>
55 #include <asm/setup.h>
57 #include "mm_internal.h"
59 static int __init parse_direct_gbpages_off(char *arg)
64 early_param("nogbpages", parse_direct_gbpages_off);
66 static int __init parse_direct_gbpages_on(char *arg)
71 early_param("gbpages", parse_direct_gbpages_on);
74 * NOTE: pagetable_init alloc all the fixmap pagetables contiguous on the
75 * physical space so we can cache the place of the first one and move
76 * around without checking the pgd every time.
79 pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
80 EXPORT_SYMBOL_GPL(__supported_pte_mask);
82 int force_personality32;
86 * Control non executable heap for 32bit processes.
87 * To control the stack too use noexec=off
89 * on PROT_READ does not imply PROT_EXEC for 32-bit processes (default)
90 * off PROT_READ implies PROT_EXEC
92 static int __init nonx32_setup(char *str)
94 if (!strcmp(str, "on"))
95 force_personality32 &= ~READ_IMPLIES_EXEC;
96 else if (!strcmp(str, "off"))
97 force_personality32 |= READ_IMPLIES_EXEC;
100 __setup("noexec32=", nonx32_setup);
103 * When memory was added/removed make sure all the processes MM have
104 * suitable PGD entries in the local PGD level page.
106 void sync_global_pgds(unsigned long start, unsigned long end)
108 unsigned long address;
110 for (address = start; address <= end; address += PGDIR_SIZE) {
111 const pgd_t *pgd_ref = pgd_offset_k(address);
114 if (pgd_none(*pgd_ref))
117 spin_lock(&pgd_lock);
118 list_for_each_entry(page, &pgd_list, lru) {
120 spinlock_t *pgt_lock;
122 pgd = (pgd_t *)page_address(page) + pgd_index(address);
123 /* the pgt_lock only for Xen */
124 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
128 set_pgd(pgd, *pgd_ref);
130 BUG_ON(pgd_page_vaddr(*pgd)
131 != pgd_page_vaddr(*pgd_ref));
133 spin_unlock(pgt_lock);
135 spin_unlock(&pgd_lock);
140 * NOTE: This function is marked __ref because it calls __init function
141 * (alloc_bootmem_pages). It's safe to do it ONLY when after_bootmem == 0.
143 static __ref void *spp_getpage(void)
148 ptr = (void *) get_zeroed_page(GFP_ATOMIC | __GFP_NOTRACK);
150 ptr = alloc_bootmem_pages(PAGE_SIZE);
152 if (!ptr || ((unsigned long)ptr & ~PAGE_MASK)) {
153 panic("set_pte_phys: cannot allocate page data %s\n",
154 after_bootmem ? "after bootmem" : "");
157 pr_debug("spp_getpage %p\n", ptr);
162 static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
164 if (pgd_none(*pgd)) {
165 pud_t *pud = (pud_t *)spp_getpage();
166 pgd_populate(&init_mm, pgd, pud);
167 if (pud != pud_offset(pgd, 0))
168 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
169 pud, pud_offset(pgd, 0));
171 return pud_offset(pgd, vaddr);
174 static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
176 if (pud_none(*pud)) {
177 pmd_t *pmd = (pmd_t *) spp_getpage();
178 pud_populate(&init_mm, pud, pmd);
179 if (pmd != pmd_offset(pud, 0))
180 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
181 pmd, pmd_offset(pud, 0));
183 return pmd_offset(pud, vaddr);
186 static pte_t *fill_pte(pmd_t *pmd, unsigned long vaddr)
188 if (pmd_none(*pmd)) {
189 pte_t *pte = (pte_t *) spp_getpage();
190 pmd_populate_kernel(&init_mm, pmd, pte);
191 if (pte != pte_offset_kernel(pmd, 0))
192 printk(KERN_ERR "PAGETABLE BUG #02!\n");
194 return pte_offset_kernel(pmd, vaddr);
197 void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
203 pud = pud_page + pud_index(vaddr);
204 pmd = fill_pmd(pud, vaddr);
205 pte = fill_pte(pmd, vaddr);
207 set_pte(pte, new_pte);
210 * It's enough to flush this one mapping.
211 * (PGE mappings get flushed as well)
213 __flush_tlb_one(vaddr);
216 void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
221 pr_debug("set_pte_vaddr %lx to %lx\n", vaddr, native_pte_val(pteval));
223 pgd = pgd_offset_k(vaddr);
224 if (pgd_none(*pgd)) {
226 "PGD FIXMAP MISSING, it should be setup in head.S!\n");
229 pud_page = (pud_t*)pgd_page_vaddr(*pgd);
230 set_pte_vaddr_pud(pud_page, vaddr, pteval);
233 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
238 pgd = pgd_offset_k(vaddr);
239 pud = fill_pud(pgd, vaddr);
240 return fill_pmd(pud, vaddr);
243 pte_t * __init populate_extra_pte(unsigned long vaddr)
247 pmd = populate_extra_pmd(vaddr);
248 return fill_pte(pmd, vaddr);
252 * Create large page table mappings for a range of physical addresses.
254 static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
261 BUG_ON((phys & ~PMD_MASK) || (size & ~PMD_MASK));
262 for (; size; phys += PMD_SIZE, size -= PMD_SIZE) {
263 pgd = pgd_offset_k((unsigned long)__va(phys));
264 if (pgd_none(*pgd)) {
265 pud = (pud_t *) spp_getpage();
266 set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
269 pud = pud_offset(pgd, (unsigned long)__va(phys));
270 if (pud_none(*pud)) {
271 pmd = (pmd_t *) spp_getpage();
272 set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
275 pmd = pmd_offset(pud, phys);
276 BUG_ON(!pmd_none(*pmd));
277 set_pmd(pmd, __pmd(phys | pgprot_val(prot)));
281 void __init init_extra_mapping_wb(unsigned long phys, unsigned long size)
283 __init_extra_mapping(phys, size, PAGE_KERNEL_LARGE);
286 void __init init_extra_mapping_uc(unsigned long phys, unsigned long size)
288 __init_extra_mapping(phys, size, PAGE_KERNEL_LARGE_NOCACHE);
292 * The head.S code sets up the kernel high mapping:
294 * from __START_KERNEL_map to __START_KERNEL_map + size (== _end-_text)
296 * phys_addr holds the negative offset to the kernel, which is added
297 * to the compile time generated pmds. This results in invalid pmds up
298 * to the point where we hit the physaddr 0 mapping.
300 * We limit the mappings to the region from _text to _brk_end. _brk_end
301 * is rounded up to the 2MB boundary. This catches the invalid pmds as
302 * well, as they are located before _text:
304 void __init cleanup_highmap(void)
306 unsigned long vaddr = __START_KERNEL_map;
307 unsigned long vaddr_end = __START_KERNEL_map + (max_pfn_mapped << PAGE_SHIFT);
308 unsigned long end = roundup((unsigned long)_brk_end, PMD_SIZE) - 1;
309 pmd_t *pmd = level2_kernel_pgt;
311 for (; vaddr + PMD_SIZE - 1 < vaddr_end; pmd++, vaddr += PMD_SIZE) {
314 if (vaddr < (unsigned long) _text || vaddr > end)
315 set_pmd(pmd, __pmd(0));
319 static unsigned long __meminit
320 phys_pte_init(pte_t *pte_page, unsigned long addr, unsigned long end,
323 unsigned long pages = 0, next;
324 unsigned long last_map_addr = end;
327 pte_t *pte = pte_page + pte_index(addr);
329 for (i = pte_index(addr); i < PTRS_PER_PTE; i++, addr = next, pte++) {
330 next = (addr & PAGE_MASK) + PAGE_SIZE;
332 if (!after_bootmem &&
333 !e820_any_mapped(addr & PAGE_MASK, next, E820_RAM) &&
334 !e820_any_mapped(addr & PAGE_MASK, next, E820_RESERVED_KERN))
335 set_pte(pte, __pte(0));
340 * We will re-use the existing mapping.
341 * Xen for example has some special requirements, like mapping
342 * pagetable pages as RO. So assume someone who pre-setup
343 * these mappings are more intelligent.
352 printk(" pte=%p addr=%lx pte=%016lx\n",
353 pte, addr, pfn_pte(addr >> PAGE_SHIFT, PAGE_KERNEL).pte);
355 set_pte(pte, pfn_pte(addr >> PAGE_SHIFT, prot));
356 last_map_addr = (addr & PAGE_MASK) + PAGE_SIZE;
359 update_page_count(PG_LEVEL_4K, pages);
361 return last_map_addr;
364 static unsigned long __meminit
365 phys_pmd_init(pmd_t *pmd_page, unsigned long address, unsigned long end,
366 unsigned long page_size_mask, pgprot_t prot)
368 unsigned long pages = 0, next;
369 unsigned long last_map_addr = end;
371 int i = pmd_index(address);
373 for (; i < PTRS_PER_PMD; i++, address = next) {
374 pmd_t *pmd = pmd_page + pmd_index(address);
376 pgprot_t new_prot = prot;
378 next = (address & PMD_MASK) + PMD_SIZE;
379 if (address >= end) {
380 if (!after_bootmem &&
381 !e820_any_mapped(address & PMD_MASK, next, E820_RAM) &&
382 !e820_any_mapped(address & PMD_MASK, next, E820_RESERVED_KERN))
383 set_pmd(pmd, __pmd(0));
388 if (!pmd_large(*pmd)) {
389 spin_lock(&init_mm.page_table_lock);
390 pte = (pte_t *)pmd_page_vaddr(*pmd);
391 last_map_addr = phys_pte_init(pte, address,
393 spin_unlock(&init_mm.page_table_lock);
397 * If we are ok with PG_LEVEL_2M mapping, then we will
398 * use the existing mapping,
400 * Otherwise, we will split the large page mapping but
401 * use the same existing protection bits except for
402 * large page, so that we don't violate Intel's TLB
403 * Application note (317080) which says, while changing
404 * the page sizes, new and old translations should
405 * not differ with respect to page frame and
408 if (page_size_mask & (1 << PG_LEVEL_2M)) {
411 last_map_addr = next;
414 new_prot = pte_pgprot(pte_clrhuge(*(pte_t *)pmd));
417 if (page_size_mask & (1<<PG_LEVEL_2M)) {
419 spin_lock(&init_mm.page_table_lock);
420 set_pte((pte_t *)pmd,
421 pfn_pte((address & PMD_MASK) >> PAGE_SHIFT,
422 __pgprot(pgprot_val(prot) | _PAGE_PSE)));
423 spin_unlock(&init_mm.page_table_lock);
424 last_map_addr = next;
428 pte = alloc_low_page();
429 last_map_addr = phys_pte_init(pte, address, end, new_prot);
431 spin_lock(&init_mm.page_table_lock);
432 pmd_populate_kernel(&init_mm, pmd, pte);
433 spin_unlock(&init_mm.page_table_lock);
435 update_page_count(PG_LEVEL_2M, pages);
436 return last_map_addr;
439 static unsigned long __meminit
440 phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
441 unsigned long page_size_mask)
443 unsigned long pages = 0, next;
444 unsigned long last_map_addr = end;
445 int i = pud_index(addr);
447 for (; i < PTRS_PER_PUD; i++, addr = next) {
448 pud_t *pud = pud_page + pud_index(addr);
450 pgprot_t prot = PAGE_KERNEL;
452 next = (addr & PUD_MASK) + PUD_SIZE;
454 if (!after_bootmem &&
455 !e820_any_mapped(addr & PUD_MASK, next, E820_RAM) &&
456 !e820_any_mapped(addr & PUD_MASK, next, E820_RESERVED_KERN))
457 set_pud(pud, __pud(0));
462 if (!pud_large(*pud)) {
463 pmd = pmd_offset(pud, 0);
464 last_map_addr = phys_pmd_init(pmd, addr, end,
465 page_size_mask, prot);
470 * If we are ok with PG_LEVEL_1G mapping, then we will
471 * use the existing mapping.
473 * Otherwise, we will split the gbpage mapping but use
474 * the same existing protection bits except for large
475 * page, so that we don't violate Intel's TLB
476 * Application note (317080) which says, while changing
477 * the page sizes, new and old translations should
478 * not differ with respect to page frame and
481 if (page_size_mask & (1 << PG_LEVEL_1G)) {
484 last_map_addr = next;
487 prot = pte_pgprot(pte_clrhuge(*(pte_t *)pud));
490 if (page_size_mask & (1<<PG_LEVEL_1G)) {
492 spin_lock(&init_mm.page_table_lock);
493 set_pte((pte_t *)pud,
494 pfn_pte((addr & PUD_MASK) >> PAGE_SHIFT,
496 spin_unlock(&init_mm.page_table_lock);
497 last_map_addr = next;
501 pmd = alloc_low_page();
502 last_map_addr = phys_pmd_init(pmd, addr, end, page_size_mask,
505 spin_lock(&init_mm.page_table_lock);
506 pud_populate(&init_mm, pud, pmd);
507 spin_unlock(&init_mm.page_table_lock);
511 update_page_count(PG_LEVEL_1G, pages);
513 return last_map_addr;
516 unsigned long __meminit
517 kernel_physical_mapping_init(unsigned long start,
519 unsigned long page_size_mask)
521 bool pgd_changed = false;
522 unsigned long next, last_map_addr = end;
525 start = (unsigned long)__va(start);
526 end = (unsigned long)__va(end);
529 for (; start < end; start = next) {
530 pgd_t *pgd = pgd_offset_k(start);
533 next = (start + PGDIR_SIZE) & PGDIR_MASK;
538 pud = (pud_t *)pgd_page_vaddr(*pgd);
539 last_map_addr = phys_pud_init(pud, __pa(start),
540 __pa(end), page_size_mask);
544 pud = alloc_low_page();
545 last_map_addr = phys_pud_init(pud, __pa(start), __pa(next),
548 spin_lock(&init_mm.page_table_lock);
549 pgd_populate(&init_mm, pgd, pud);
550 spin_unlock(&init_mm.page_table_lock);
555 sync_global_pgds(addr, end);
559 return last_map_addr;
563 void __init initmem_init(void)
565 memblock_set_node(0, (phys_addr_t)ULLONG_MAX, 0);
569 void __init paging_init(void)
571 sparse_memory_present_with_active_regions(MAX_NUMNODES);
575 * clear the default setting with node 0
576 * note: don't use nodes_clear here, that is really clearing when
577 * numa support is not compiled in, and later node_set_state
578 * will not set it back.
580 node_clear_state(0, N_MEMORY);
581 if (N_MEMORY != N_NORMAL_MEMORY)
582 node_clear_state(0, N_NORMAL_MEMORY);
588 * Memory hotplug specific functions
590 #ifdef CONFIG_MEMORY_HOTPLUG
592 * After memory hotplug the variables max_pfn, max_low_pfn and high_memory need
595 static void update_end_of_memory_vars(u64 start, u64 size)
597 unsigned long end_pfn = PFN_UP(start + size);
599 if (end_pfn > max_pfn) {
601 max_low_pfn = end_pfn;
602 high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
607 * Memory is added always to NORMAL zone. This means you will never get
608 * additional DMA/DMA32 memory.
610 int arch_add_memory(int nid, u64 start, u64 size)
612 struct pglist_data *pgdat = NODE_DATA(nid);
613 struct zone *zone = pgdat->node_zones + ZONE_NORMAL;
614 unsigned long start_pfn = start >> PAGE_SHIFT;
615 unsigned long nr_pages = size >> PAGE_SHIFT;
618 init_memory_mapping(start, start + size);
620 ret = __add_pages(nid, zone, start_pfn, nr_pages);
623 /* update max_pfn, max_low_pfn and high_memory */
624 update_end_of_memory_vars(start, size);
628 EXPORT_SYMBOL_GPL(arch_add_memory);
630 #endif /* CONFIG_MEMORY_HOTPLUG */
632 static struct kcore_list kcore_vsyscall;
634 static void __init register_page_bootmem_info(void)
639 for_each_online_node(i)
640 register_page_bootmem_info_node(NODE_DATA(i));
644 void __init mem_init(void)
646 long codesize, reservedpages, datasize, initsize;
647 unsigned long absent_pages;
651 /* clear_bss() already clear the empty_zero_page */
655 /* this will put all low memory onto the freelists */
656 register_page_bootmem_info();
657 totalram_pages = free_all_bootmem();
659 absent_pages = absent_pages_in_range(0, max_pfn);
660 reservedpages = max_pfn - totalram_pages - absent_pages;
663 codesize = (unsigned long) &_etext - (unsigned long) &_text;
664 datasize = (unsigned long) &_edata - (unsigned long) &_etext;
665 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
667 /* Register memory areas for /proc/kcore */
668 kclist_add(&kcore_vsyscall, (void *)VSYSCALL_START,
669 VSYSCALL_END - VSYSCALL_START, KCORE_OTHER);
671 printk(KERN_INFO "Memory: %luk/%luk available (%ldk kernel code, "
672 "%ldk absent, %ldk reserved, %ldk data, %ldk init)\n",
673 nr_free_pages() << (PAGE_SHIFT-10),
674 max_pfn << (PAGE_SHIFT-10),
676 absent_pages << (PAGE_SHIFT-10),
677 reservedpages << (PAGE_SHIFT-10),
682 #ifdef CONFIG_DEBUG_RODATA
683 const int rodata_test_data = 0xC3;
684 EXPORT_SYMBOL_GPL(rodata_test_data);
686 int kernel_set_to_readonly;
688 void set_kernel_text_rw(void)
690 unsigned long start = PFN_ALIGN(_text);
691 unsigned long end = PFN_ALIGN(__stop___ex_table);
693 if (!kernel_set_to_readonly)
696 pr_debug("Set kernel text: %lx - %lx for read write\n",
700 * Make the kernel identity mapping for text RW. Kernel text
701 * mapping will always be RO. Refer to the comment in
702 * static_protections() in pageattr.c
704 set_memory_rw(start, (end - start) >> PAGE_SHIFT);
707 void set_kernel_text_ro(void)
709 unsigned long start = PFN_ALIGN(_text);
710 unsigned long end = PFN_ALIGN(__stop___ex_table);
712 if (!kernel_set_to_readonly)
715 pr_debug("Set kernel text: %lx - %lx for read only\n",
719 * Set the kernel identity mapping for text RO.
721 set_memory_ro(start, (end - start) >> PAGE_SHIFT);
724 void mark_rodata_ro(void)
726 unsigned long start = PFN_ALIGN(_text);
727 unsigned long rodata_start =
728 ((unsigned long)__start_rodata + PAGE_SIZE - 1) & PAGE_MASK;
729 unsigned long end = (unsigned long) &__end_rodata_hpage_align;
730 unsigned long text_end = PAGE_ALIGN((unsigned long) &__stop___ex_table);
731 unsigned long rodata_end = PAGE_ALIGN((unsigned long) &__end_rodata);
732 unsigned long data_start = (unsigned long) &_sdata;
734 printk(KERN_INFO "Write protecting the kernel read-only data: %luk\n",
735 (end - start) >> 10);
736 set_memory_ro(start, (end - start) >> PAGE_SHIFT);
738 kernel_set_to_readonly = 1;
741 * The rodata section (but not the kernel text!) should also be
744 set_memory_nx(rodata_start, (end - rodata_start) >> PAGE_SHIFT);
748 #ifdef CONFIG_CPA_DEBUG
749 printk(KERN_INFO "Testing CPA: undo %lx-%lx\n", start, end);
750 set_memory_rw(start, (end-start) >> PAGE_SHIFT);
752 printk(KERN_INFO "Testing CPA: again\n");
753 set_memory_ro(start, (end-start) >> PAGE_SHIFT);
756 free_init_pages("unused kernel memory",
757 (unsigned long) page_address(virt_to_page(text_end)),
759 page_address(virt_to_page(rodata_start)));
760 free_init_pages("unused kernel memory",
761 (unsigned long) page_address(virt_to_page(rodata_end)),
762 (unsigned long) page_address(virt_to_page(data_start)));
767 int kern_addr_valid(unsigned long addr)
769 unsigned long above = ((long)addr) >> __VIRTUAL_MASK_SHIFT;
775 if (above != 0 && above != -1UL)
778 pgd = pgd_offset_k(addr);
782 pud = pud_offset(pgd, addr);
786 pmd = pmd_offset(pud, addr);
791 return pfn_valid(pmd_pfn(*pmd));
793 pte = pte_offset_kernel(pmd, addr);
797 return pfn_valid(pte_pfn(*pte));
801 * A pseudo VMA to allow ptrace access for the vsyscall page. This only
802 * covers the 64bit vsyscall page now. 32bit has a real VMA now and does
803 * not need special handling anymore:
805 static struct vm_area_struct gate_vma = {
806 .vm_start = VSYSCALL_START,
807 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
808 .vm_page_prot = PAGE_READONLY_EXEC,
809 .vm_flags = VM_READ | VM_EXEC
812 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
814 #ifdef CONFIG_IA32_EMULATION
815 if (!mm || mm->context.ia32_compat)
821 int in_gate_area(struct mm_struct *mm, unsigned long addr)
823 struct vm_area_struct *vma = get_gate_vma(mm);
828 return (addr >= vma->vm_start) && (addr < vma->vm_end);
832 * Use this when you have no reliable mm, typically from interrupt
833 * context. It is less reliable than using a task's mm and may give
836 int in_gate_area_no_mm(unsigned long addr)
838 return (addr >= VSYSCALL_START) && (addr < VSYSCALL_END);
841 const char *arch_vma_name(struct vm_area_struct *vma)
843 if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
845 if (vma == &gate_vma)
851 unsigned long memory_block_size_bytes(void)
853 if (is_uv_system()) {
854 printk(KERN_INFO "UV: memory block size 2GB\n");
855 return 2UL * 1024 * 1024 * 1024;
857 return MIN_MEMORY_BLOCK_SIZE;
861 #ifdef CONFIG_SPARSEMEM_VMEMMAP
863 * Initialise the sparsemem vmemmap using huge-pages at the PMD level.
865 static long __meminitdata addr_start, addr_end;
866 static void __meminitdata *p_start, *p_end;
867 static int __meminitdata node_start;
870 vmemmap_populate(struct page *start_page, unsigned long size, int node)
872 unsigned long addr = (unsigned long)start_page;
873 unsigned long end = (unsigned long)(start_page + size);
879 for (; addr < end; addr = next) {
882 pgd = vmemmap_pgd_populate(addr, node);
886 pud = vmemmap_pud_populate(pgd, addr, node);
891 next = (addr + PAGE_SIZE) & PAGE_MASK;
892 pmd = vmemmap_pmd_populate(pud, addr, node);
897 p = vmemmap_pte_populate(pmd, addr, node);
902 addr_end = addr + PAGE_SIZE;
903 p_end = p + PAGE_SIZE;
905 next = pmd_addr_end(addr, end);
907 pmd = pmd_offset(pud, addr);
908 if (pmd_none(*pmd)) {
911 p = vmemmap_alloc_block_buf(PMD_SIZE, node);
915 entry = pfn_pte(__pa(p) >> PAGE_SHIFT,
917 set_pmd(pmd, __pmd(pte_val(entry)));
919 /* check to see if we have contiguous blocks */
920 if (p_end != p || node_start != node) {
922 printk(KERN_DEBUG " [%lx-%lx] PMD -> [%p-%p] on node %d\n",
923 addr_start, addr_end-1, p_start, p_end-1, node_start);
929 addr_end = addr + PMD_SIZE;
930 p_end = p + PMD_SIZE;
932 vmemmap_verify((pte_t *)pmd, node, addr, next);
936 sync_global_pgds((unsigned long)start_page, end);
940 void __meminit vmemmap_populate_print_last(void)
943 printk(KERN_DEBUG " [%lx-%lx] PMD -> [%p-%p] on node %d\n",
944 addr_start, addr_end-1, p_start, p_end-1, node_start);