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/bios_ebda.h>
35 #include <asm/system.h>
36 #include <asm/uaccess.h>
37 #include <asm/pgtable.h>
38 #include <asm/pgalloc.h>
40 #include <asm/fixmap.h>
44 #include <asm/mmu_context.h>
45 #include <asm/proto.h>
47 #include <asm/sections.h>
48 #include <asm/kdebug.h>
50 #include <asm/cacheflush.h>
52 #include <linux/bootmem.h>
54 static unsigned long dma_reserve __initdata
;
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 * NOTE: This function is marked __ref because it calls __init function
101 * (alloc_bootmem_pages). It's safe to do it ONLY when after_bootmem == 0.
103 static __ref
void *spp_getpage(void)
108 ptr
= (void *) get_zeroed_page(GFP_ATOMIC
| __GFP_NOTRACK
);
110 ptr
= alloc_bootmem_pages(PAGE_SIZE
);
112 if (!ptr
|| ((unsigned long)ptr
& ~PAGE_MASK
)) {
113 panic("set_pte_phys: cannot allocate page data %s\n",
114 after_bootmem
? "after bootmem" : "");
117 pr_debug("spp_getpage %p\n", ptr
);
122 static pud_t
*fill_pud(pgd_t
*pgd
, unsigned long vaddr
)
124 if (pgd_none(*pgd
)) {
125 pud_t
*pud
= (pud_t
*)spp_getpage();
126 pgd_populate(&init_mm
, pgd
, pud
);
127 if (pud
!= pud_offset(pgd
, 0))
128 printk(KERN_ERR
"PAGETABLE BUG #00! %p <-> %p\n",
129 pud
, pud_offset(pgd
, 0));
131 return pud_offset(pgd
, vaddr
);
134 static pmd_t
*fill_pmd(pud_t
*pud
, unsigned long vaddr
)
136 if (pud_none(*pud
)) {
137 pmd_t
*pmd
= (pmd_t
*) spp_getpage();
138 pud_populate(&init_mm
, pud
, pmd
);
139 if (pmd
!= pmd_offset(pud
, 0))
140 printk(KERN_ERR
"PAGETABLE BUG #01! %p <-> %p\n",
141 pmd
, pmd_offset(pud
, 0));
143 return pmd_offset(pud
, vaddr
);
146 static pte_t
*fill_pte(pmd_t
*pmd
, unsigned long vaddr
)
148 if (pmd_none(*pmd
)) {
149 pte_t
*pte
= (pte_t
*) spp_getpage();
150 pmd_populate_kernel(&init_mm
, pmd
, pte
);
151 if (pte
!= pte_offset_kernel(pmd
, 0))
152 printk(KERN_ERR
"PAGETABLE BUG #02!\n");
154 return pte_offset_kernel(pmd
, vaddr
);
157 void set_pte_vaddr_pud(pud_t
*pud_page
, unsigned long vaddr
, pte_t new_pte
)
163 pud
= pud_page
+ pud_index(vaddr
);
164 pmd
= fill_pmd(pud
, vaddr
);
165 pte
= fill_pte(pmd
, vaddr
);
167 set_pte(pte
, new_pte
);
170 * It's enough to flush this one mapping.
171 * (PGE mappings get flushed as well)
173 __flush_tlb_one(vaddr
);
176 void set_pte_vaddr(unsigned long vaddr
, pte_t pteval
)
181 pr_debug("set_pte_vaddr %lx to %lx\n", vaddr
, native_pte_val(pteval
));
183 pgd
= pgd_offset_k(vaddr
);
184 if (pgd_none(*pgd
)) {
186 "PGD FIXMAP MISSING, it should be setup in head.S!\n");
189 pud_page
= (pud_t
*)pgd_page_vaddr(*pgd
);
190 set_pte_vaddr_pud(pud_page
, vaddr
, pteval
);
193 pmd_t
* __init
populate_extra_pmd(unsigned long vaddr
)
198 pgd
= pgd_offset_k(vaddr
);
199 pud
= fill_pud(pgd
, vaddr
);
200 return fill_pmd(pud
, vaddr
);
203 pte_t
* __init
populate_extra_pte(unsigned long vaddr
)
207 pmd
= populate_extra_pmd(vaddr
);
208 return fill_pte(pmd
, vaddr
);
212 * Create large page table mappings for a range of physical addresses.
214 static void __init
__init_extra_mapping(unsigned long phys
, unsigned long size
,
221 BUG_ON((phys
& ~PMD_MASK
) || (size
& ~PMD_MASK
));
222 for (; size
; phys
+= PMD_SIZE
, size
-= PMD_SIZE
) {
223 pgd
= pgd_offset_k((unsigned long)__va(phys
));
224 if (pgd_none(*pgd
)) {
225 pud
= (pud_t
*) spp_getpage();
226 set_pgd(pgd
, __pgd(__pa(pud
) | _KERNPG_TABLE
|
229 pud
= pud_offset(pgd
, (unsigned long)__va(phys
));
230 if (pud_none(*pud
)) {
231 pmd
= (pmd_t
*) spp_getpage();
232 set_pud(pud
, __pud(__pa(pmd
) | _KERNPG_TABLE
|
235 pmd
= pmd_offset(pud
, phys
);
236 BUG_ON(!pmd_none(*pmd
));
237 set_pmd(pmd
, __pmd(phys
| pgprot_val(prot
)));
241 void __init
init_extra_mapping_wb(unsigned long phys
, unsigned long size
)
243 __init_extra_mapping(phys
, size
, PAGE_KERNEL_LARGE
);
246 void __init
init_extra_mapping_uc(unsigned long phys
, unsigned long size
)
248 __init_extra_mapping(phys
, size
, PAGE_KERNEL_LARGE_NOCACHE
);
252 * The head.S code sets up the kernel high mapping:
254 * from __START_KERNEL_map to __START_KERNEL_map + size (== _end-_text)
256 * phys_addr holds the negative offset to the kernel, which is added
257 * to the compile time generated pmds. This results in invalid pmds up
258 * to the point where we hit the physaddr 0 mapping.
260 * We limit the mappings to the region from _text to _end. _end is
261 * rounded up to the 2MB boundary. This catches the invalid pmds as
262 * well, as they are located before _text:
264 void __init
cleanup_highmap(void)
266 unsigned long vaddr
= __START_KERNEL_map
;
267 unsigned long end
= roundup((unsigned long)_end
, PMD_SIZE
) - 1;
268 pmd_t
*pmd
= level2_kernel_pgt
;
269 pmd_t
*last_pmd
= pmd
+ PTRS_PER_PMD
;
271 for (; pmd
< last_pmd
; pmd
++, vaddr
+= PMD_SIZE
) {
274 if (vaddr
< (unsigned long) _text
|| vaddr
> end
)
275 set_pmd(pmd
, __pmd(0));
279 static __ref
void *alloc_low_page(unsigned long *phys
)
281 unsigned long pfn
= e820_table_end
++;
285 adr
= (void *)get_zeroed_page(GFP_ATOMIC
| __GFP_NOTRACK
);
291 if (pfn
>= e820_table_top
)
292 panic("alloc_low_page: ran out of memory");
294 adr
= early_memremap(pfn
* PAGE_SIZE
, PAGE_SIZE
);
295 memset(adr
, 0, PAGE_SIZE
);
296 *phys
= pfn
* PAGE_SIZE
;
300 static __ref
void unmap_low_page(void *adr
)
305 early_iounmap(adr
, PAGE_SIZE
);
308 static unsigned long __meminit
309 phys_pte_init(pte_t
*pte_page
, unsigned long addr
, unsigned long end
,
313 unsigned long last_map_addr
= end
;
316 pte_t
*pte
= pte_page
+ pte_index(addr
);
318 for(i
= pte_index(addr
); i
< PTRS_PER_PTE
; i
++, addr
+= PAGE_SIZE
, pte
++) {
321 if (!after_bootmem
) {
322 for(; i
< PTRS_PER_PTE
; i
++, pte
++)
323 set_pte(pte
, __pte(0));
329 * We will re-use the existing mapping.
330 * Xen for example has some special requirements, like mapping
331 * pagetable pages as RO. So assume someone who pre-setup
332 * these mappings are more intelligent.
340 printk(" pte=%p addr=%lx pte=%016lx\n",
341 pte
, addr
, pfn_pte(addr
>> PAGE_SHIFT
, PAGE_KERNEL
).pte
);
343 set_pte(pte
, pfn_pte(addr
>> PAGE_SHIFT
, prot
));
344 last_map_addr
= (addr
& PAGE_MASK
) + PAGE_SIZE
;
347 update_page_count(PG_LEVEL_4K
, pages
);
349 return last_map_addr
;
352 static unsigned long __meminit
353 phys_pte_update(pmd_t
*pmd
, unsigned long address
, unsigned long end
,
356 pte_t
*pte
= (pte_t
*)pmd_page_vaddr(*pmd
);
358 return phys_pte_init(pte
, address
, end
, prot
);
361 static unsigned long __meminit
362 phys_pmd_init(pmd_t
*pmd_page
, unsigned long address
, unsigned long end
,
363 unsigned long page_size_mask
, pgprot_t prot
)
365 unsigned long pages
= 0;
366 unsigned long last_map_addr
= end
;
368 int i
= pmd_index(address
);
370 for (; i
< PTRS_PER_PMD
; i
++, address
+= PMD_SIZE
) {
371 unsigned long pte_phys
;
372 pmd_t
*pmd
= pmd_page
+ pmd_index(address
);
374 pgprot_t new_prot
= prot
;
376 if (address
>= end
) {
377 if (!after_bootmem
) {
378 for (; i
< PTRS_PER_PMD
; i
++, pmd
++)
379 set_pmd(pmd
, __pmd(0));
385 if (!pmd_large(*pmd
)) {
386 spin_lock(&init_mm
.page_table_lock
);
387 last_map_addr
= phys_pte_update(pmd
, address
,
389 spin_unlock(&init_mm
.page_table_lock
);
393 * If we are ok with PG_LEVEL_2M mapping, then we will
394 * use the existing mapping,
396 * Otherwise, we will split the large page mapping but
397 * use the same existing protection bits except for
398 * large page, so that we don't violate Intel's TLB
399 * Application note (317080) which says, while changing
400 * the page sizes, new and old translations should
401 * not differ with respect to page frame and
404 if (page_size_mask
& (1 << PG_LEVEL_2M
)) {
408 new_prot
= pte_pgprot(pte_clrhuge(*(pte_t
*)pmd
));
411 if (page_size_mask
& (1<<PG_LEVEL_2M
)) {
413 spin_lock(&init_mm
.page_table_lock
);
414 set_pte((pte_t
*)pmd
,
415 pfn_pte(address
>> PAGE_SHIFT
,
416 __pgprot(pgprot_val(prot
) | _PAGE_PSE
)));
417 spin_unlock(&init_mm
.page_table_lock
);
418 last_map_addr
= (address
& PMD_MASK
) + PMD_SIZE
;
422 pte
= alloc_low_page(&pte_phys
);
423 last_map_addr
= phys_pte_init(pte
, address
, end
, new_prot
);
426 spin_lock(&init_mm
.page_table_lock
);
427 pmd_populate_kernel(&init_mm
, pmd
, __va(pte_phys
));
428 spin_unlock(&init_mm
.page_table_lock
);
430 update_page_count(PG_LEVEL_2M
, pages
);
431 return last_map_addr
;
434 static unsigned long __meminit
435 phys_pmd_update(pud_t
*pud
, unsigned long address
, unsigned long end
,
436 unsigned long page_size_mask
, pgprot_t prot
)
438 pmd_t
*pmd
= pmd_offset(pud
, 0);
439 unsigned long last_map_addr
;
441 last_map_addr
= phys_pmd_init(pmd
, address
, end
, page_size_mask
, prot
);
443 return last_map_addr
;
446 static unsigned long __meminit
447 phys_pud_init(pud_t
*pud_page
, unsigned long addr
, unsigned long end
,
448 unsigned long page_size_mask
)
450 unsigned long pages
= 0;
451 unsigned long last_map_addr
= end
;
452 int i
= pud_index(addr
);
454 for (; i
< PTRS_PER_PUD
; i
++, addr
= (addr
& PUD_MASK
) + PUD_SIZE
) {
455 unsigned long pmd_phys
;
456 pud_t
*pud
= pud_page
+ pud_index(addr
);
458 pgprot_t prot
= PAGE_KERNEL
;
463 if (!after_bootmem
&&
464 !e820_any_mapped(addr
, addr
+PUD_SIZE
, 0)) {
465 set_pud(pud
, __pud(0));
470 if (!pud_large(*pud
)) {
471 last_map_addr
= phys_pmd_update(pud
, addr
, end
,
472 page_size_mask
, prot
);
476 * If we are ok with PG_LEVEL_1G mapping, then we will
477 * use the existing mapping.
479 * Otherwise, we will split the gbpage mapping but use
480 * the same existing protection bits except for large
481 * page, so that we don't violate Intel's TLB
482 * Application note (317080) which says, while changing
483 * the page sizes, new and old translations should
484 * not differ with respect to page frame and
487 if (page_size_mask
& (1 << PG_LEVEL_1G
)) {
491 prot
= pte_pgprot(pte_clrhuge(*(pte_t
*)pud
));
494 if (page_size_mask
& (1<<PG_LEVEL_1G
)) {
496 spin_lock(&init_mm
.page_table_lock
);
497 set_pte((pte_t
*)pud
,
498 pfn_pte(addr
>> PAGE_SHIFT
, PAGE_KERNEL_LARGE
));
499 spin_unlock(&init_mm
.page_table_lock
);
500 last_map_addr
= (addr
& PUD_MASK
) + PUD_SIZE
;
504 pmd
= alloc_low_page(&pmd_phys
);
505 last_map_addr
= phys_pmd_init(pmd
, addr
, end
, page_size_mask
,
509 spin_lock(&init_mm
.page_table_lock
);
510 pud_populate(&init_mm
, pud
, __va(pmd_phys
));
511 spin_unlock(&init_mm
.page_table_lock
);
515 update_page_count(PG_LEVEL_1G
, pages
);
517 return last_map_addr
;
520 static unsigned long __meminit
521 phys_pud_update(pgd_t
*pgd
, unsigned long addr
, unsigned long end
,
522 unsigned long page_size_mask
)
526 pud
= (pud_t
*)pgd_page_vaddr(*pgd
);
528 return phys_pud_init(pud
, addr
, end
, page_size_mask
);
531 unsigned long __meminit
532 kernel_physical_mapping_init(unsigned long start
,
534 unsigned long page_size_mask
)
537 unsigned long next
, last_map_addr
= end
;
539 start
= (unsigned long)__va(start
);
540 end
= (unsigned long)__va(end
);
542 for (; start
< end
; start
= next
) {
543 pgd_t
*pgd
= pgd_offset_k(start
);
544 unsigned long pud_phys
;
547 next
= (start
+ PGDIR_SIZE
) & PGDIR_MASK
;
552 last_map_addr
= phys_pud_update(pgd
, __pa(start
),
553 __pa(end
), page_size_mask
);
557 pud
= alloc_low_page(&pud_phys
);
558 last_map_addr
= phys_pud_init(pud
, __pa(start
), __pa(next
),
562 spin_lock(&init_mm
.page_table_lock
);
563 pgd_populate(&init_mm
, pgd
, __va(pud_phys
));
564 spin_unlock(&init_mm
.page_table_lock
);
568 return last_map_addr
;
572 void __init
initmem_init(unsigned long start_pfn
, unsigned long end_pfn
,
575 unsigned long bootmap_size
, bootmap
;
577 bootmap_size
= bootmem_bootmap_pages(end_pfn
)<<PAGE_SHIFT
;
578 bootmap
= find_e820_area(0, end_pfn
<<PAGE_SHIFT
, bootmap_size
,
581 panic("Cannot find bootmem map of size %ld\n", bootmap_size
);
582 /* don't touch min_low_pfn */
583 bootmap_size
= init_bootmem_node(NODE_DATA(0), bootmap
>> PAGE_SHIFT
,
585 e820_register_active_regions(0, start_pfn
, end_pfn
);
586 free_bootmem_with_active_regions(0, end_pfn
);
587 early_res_to_bootmem(0, end_pfn
<<PAGE_SHIFT
);
588 reserve_bootmem(bootmap
, bootmap_size
, BOOTMEM_DEFAULT
);
592 void __init
paging_init(void)
594 unsigned long max_zone_pfns
[MAX_NR_ZONES
];
596 memset(max_zone_pfns
, 0, sizeof(max_zone_pfns
));
597 max_zone_pfns
[ZONE_DMA
] = MAX_DMA_PFN
;
598 max_zone_pfns
[ZONE_DMA32
] = MAX_DMA32_PFN
;
599 max_zone_pfns
[ZONE_NORMAL
] = max_pfn
;
601 sparse_memory_present_with_active_regions(MAX_NUMNODES
);
605 * clear the default setting with node 0
606 * note: don't use nodes_clear here, that is really clearing when
607 * numa support is not compiled in, and later node_set_state
608 * will not set it back.
610 node_clear_state(0, N_NORMAL_MEMORY
);
612 free_area_init_nodes(max_zone_pfns
);
616 * Memory hotplug specific functions
618 #ifdef CONFIG_MEMORY_HOTPLUG
620 * After memory hotplug the variables max_pfn, max_low_pfn and high_memory need
623 static void update_end_of_memory_vars(u64 start
, u64 size
)
625 unsigned long end_pfn
= PFN_UP(start
+ size
);
627 if (end_pfn
> max_pfn
) {
629 max_low_pfn
= end_pfn
;
630 high_memory
= (void *)__va(max_pfn
* PAGE_SIZE
- 1) + 1;
635 * Memory is added always to NORMAL zone. This means you will never get
636 * additional DMA/DMA32 memory.
638 int arch_add_memory(int nid
, u64 start
, u64 size
)
640 struct pglist_data
*pgdat
= NODE_DATA(nid
);
641 struct zone
*zone
= pgdat
->node_zones
+ ZONE_NORMAL
;
642 unsigned long last_mapped_pfn
, start_pfn
= start
>> PAGE_SHIFT
;
643 unsigned long nr_pages
= size
>> PAGE_SHIFT
;
646 last_mapped_pfn
= init_memory_mapping(start
, start
+ size
);
647 if (last_mapped_pfn
> max_pfn_mapped
)
648 max_pfn_mapped
= last_mapped_pfn
;
650 ret
= __add_pages(nid
, zone
, start_pfn
, nr_pages
);
653 /* update max_pfn, max_low_pfn and high_memory */
654 update_end_of_memory_vars(start
, size
);
658 EXPORT_SYMBOL_GPL(arch_add_memory
);
660 #if !defined(CONFIG_ACPI_NUMA) && defined(CONFIG_NUMA)
661 int memory_add_physaddr_to_nid(u64 start
)
665 EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid
);
668 #endif /* CONFIG_MEMORY_HOTPLUG */
670 static struct kcore_list kcore_vsyscall
;
672 void __init
mem_init(void)
674 long codesize
, reservedpages
, datasize
, initsize
;
675 unsigned long absent_pages
;
679 /* clear_bss() already clear the empty_zero_page */
683 /* this will put all low memory onto the freelists */
685 totalram_pages
= numa_free_all_bootmem();
687 totalram_pages
= free_all_bootmem();
690 absent_pages
= absent_pages_in_range(0, max_pfn
);
691 reservedpages
= max_pfn
- totalram_pages
- absent_pages
;
694 codesize
= (unsigned long) &_etext
- (unsigned long) &_text
;
695 datasize
= (unsigned long) &_edata
- (unsigned long) &_etext
;
696 initsize
= (unsigned long) &__init_end
- (unsigned long) &__init_begin
;
698 /* Register memory areas for /proc/kcore */
699 kclist_add(&kcore_vsyscall
, (void *)VSYSCALL_START
,
700 VSYSCALL_END
- VSYSCALL_START
, KCORE_OTHER
);
702 printk(KERN_INFO
"Memory: %luk/%luk available (%ldk kernel code, "
703 "%ldk absent, %ldk reserved, %ldk data, %ldk init)\n",
704 nr_free_pages() << (PAGE_SHIFT
-10),
705 max_pfn
<< (PAGE_SHIFT
-10),
707 absent_pages
<< (PAGE_SHIFT
-10),
708 reservedpages
<< (PAGE_SHIFT
-10),
713 #ifdef CONFIG_DEBUG_RODATA
714 const int rodata_test_data
= 0xC3;
715 EXPORT_SYMBOL_GPL(rodata_test_data
);
717 int kernel_set_to_readonly
;
719 void set_kernel_text_rw(void)
721 unsigned long start
= PFN_ALIGN(_text
);
722 unsigned long end
= PFN_ALIGN(__stop___ex_table
);
724 if (!kernel_set_to_readonly
)
727 pr_debug("Set kernel text: %lx - %lx for read write\n",
731 * Make the kernel identity mapping for text RW. Kernel text
732 * mapping will always be RO. Refer to the comment in
733 * static_protections() in pageattr.c
735 set_memory_rw(start
, (end
- start
) >> PAGE_SHIFT
);
738 void set_kernel_text_ro(void)
740 unsigned long start
= PFN_ALIGN(_text
);
741 unsigned long end
= PFN_ALIGN(__stop___ex_table
);
743 if (!kernel_set_to_readonly
)
746 pr_debug("Set kernel text: %lx - %lx for read only\n",
750 * Set the kernel identity mapping for text RO.
752 set_memory_ro(start
, (end
- start
) >> PAGE_SHIFT
);
755 void mark_rodata_ro(void)
757 unsigned long start
= PFN_ALIGN(_text
);
758 unsigned long rodata_start
=
759 ((unsigned long)__start_rodata
+ PAGE_SIZE
- 1) & PAGE_MASK
;
760 unsigned long end
= (unsigned long) &__end_rodata_hpage_align
;
761 unsigned long text_end
= PAGE_ALIGN((unsigned long) &__stop___ex_table
);
762 unsigned long rodata_end
= PAGE_ALIGN((unsigned long) &__end_rodata
);
763 unsigned long data_start
= (unsigned long) &_sdata
;
765 printk(KERN_INFO
"Write protecting the kernel read-only data: %luk\n",
766 (end
- start
) >> 10);
767 set_memory_ro(start
, (end
- start
) >> PAGE_SHIFT
);
769 kernel_set_to_readonly
= 1;
772 * The rodata section (but not the kernel text!) should also be
775 set_memory_nx(rodata_start
, (end
- rodata_start
) >> PAGE_SHIFT
);
779 #ifdef CONFIG_CPA_DEBUG
780 printk(KERN_INFO
"Testing CPA: undo %lx-%lx\n", start
, end
);
781 set_memory_rw(start
, (end
-start
) >> PAGE_SHIFT
);
783 printk(KERN_INFO
"Testing CPA: again\n");
784 set_memory_ro(start
, (end
-start
) >> PAGE_SHIFT
);
787 free_init_pages("unused kernel memory",
788 (unsigned long) page_address(virt_to_page(text_end
)),
790 page_address(virt_to_page(rodata_start
)));
791 free_init_pages("unused kernel memory",
792 (unsigned long) page_address(virt_to_page(rodata_end
)),
793 (unsigned long) page_address(virt_to_page(data_start
)));
798 int __init
reserve_bootmem_generic(unsigned long phys
, unsigned long len
,
805 unsigned long pfn
= phys
>> PAGE_SHIFT
;
807 if (pfn
>= max_pfn
) {
809 * This can happen with kdump kernels when accessing
812 if (pfn
< max_pfn_mapped
)
815 printk(KERN_ERR
"reserve_bootmem: illegal reserve %lx %lu\n",
820 /* Should check here against the e820 map to avoid double free */
822 nid
= phys_to_nid(phys
);
823 next_nid
= phys_to_nid(phys
+ len
- 1);
825 ret
= reserve_bootmem_node(NODE_DATA(nid
), phys
, len
, flags
);
827 ret
= reserve_bootmem(phys
, len
, flags
);
833 reserve_bootmem(phys
, len
, flags
);
836 if (phys
+len
<= MAX_DMA_PFN
*PAGE_SIZE
) {
837 dma_reserve
+= len
/ PAGE_SIZE
;
838 set_dma_reserve(dma_reserve
);
844 int kern_addr_valid(unsigned long addr
)
846 unsigned long above
= ((long)addr
) >> __VIRTUAL_MASK_SHIFT
;
852 if (above
!= 0 && above
!= -1UL)
855 pgd
= pgd_offset_k(addr
);
859 pud
= pud_offset(pgd
, addr
);
863 pmd
= pmd_offset(pud
, addr
);
868 return pfn_valid(pmd_pfn(*pmd
));
870 pte
= pte_offset_kernel(pmd
, addr
);
874 return pfn_valid(pte_pfn(*pte
));
878 * A pseudo VMA to allow ptrace access for the vsyscall page. This only
879 * covers the 64bit vsyscall page now. 32bit has a real VMA now and does
880 * not need special handling anymore:
882 static struct vm_area_struct gate_vma
= {
883 .vm_start
= VSYSCALL_START
,
884 .vm_end
= VSYSCALL_START
+ (VSYSCALL_MAPPED_PAGES
* PAGE_SIZE
),
885 .vm_page_prot
= PAGE_READONLY_EXEC
,
886 .vm_flags
= VM_READ
| VM_EXEC
889 struct vm_area_struct
*get_gate_vma(struct task_struct
*tsk
)
891 #ifdef CONFIG_IA32_EMULATION
892 if (test_tsk_thread_flag(tsk
, TIF_IA32
))
898 int in_gate_area(struct task_struct
*task
, unsigned long addr
)
900 struct vm_area_struct
*vma
= get_gate_vma(task
);
905 return (addr
>= vma
->vm_start
) && (addr
< vma
->vm_end
);
909 * Use this when you have no reliable task/vma, typically from interrupt
910 * context. It is less reliable than using the task's vma and may give
913 int in_gate_area_no_task(unsigned long addr
)
915 return (addr
>= VSYSCALL_START
) && (addr
< VSYSCALL_END
);
918 const char *arch_vma_name(struct vm_area_struct
*vma
)
920 if (vma
->vm_mm
&& vma
->vm_start
== (long)vma
->vm_mm
->context
.vdso
)
922 if (vma
== &gate_vma
)
927 #ifdef CONFIG_SPARSEMEM_VMEMMAP
929 * Initialise the sparsemem vmemmap using huge-pages at the PMD level.
931 static long __meminitdata addr_start
, addr_end
;
932 static void __meminitdata
*p_start
, *p_end
;
933 static int __meminitdata node_start
;
936 vmemmap_populate(struct page
*start_page
, unsigned long size
, int node
)
938 unsigned long addr
= (unsigned long)start_page
;
939 unsigned long end
= (unsigned long)(start_page
+ size
);
945 for (; addr
< end
; addr
= next
) {
948 pgd
= vmemmap_pgd_populate(addr
, node
);
952 pud
= vmemmap_pud_populate(pgd
, addr
, node
);
957 next
= (addr
+ PAGE_SIZE
) & PAGE_MASK
;
958 pmd
= vmemmap_pmd_populate(pud
, addr
, node
);
963 p
= vmemmap_pte_populate(pmd
, addr
, node
);
968 addr_end
= addr
+ PAGE_SIZE
;
969 p_end
= p
+ PAGE_SIZE
;
971 next
= pmd_addr_end(addr
, end
);
973 pmd
= pmd_offset(pud
, addr
);
974 if (pmd_none(*pmd
)) {
977 p
= vmemmap_alloc_block(PMD_SIZE
, node
);
981 entry
= pfn_pte(__pa(p
) >> PAGE_SHIFT
,
983 set_pmd(pmd
, __pmd(pte_val(entry
)));
985 /* check to see if we have contiguous blocks */
986 if (p_end
!= p
|| node_start
!= node
) {
988 printk(KERN_DEBUG
" [%lx-%lx] PMD -> [%p-%p] on node %d\n",
989 addr_start
, addr_end
-1, p_start
, p_end
-1, node_start
);
995 addr_end
= addr
+ PMD_SIZE
;
996 p_end
= p
+ PMD_SIZE
;
998 vmemmap_verify((pte_t
*)pmd
, node
, addr
, next
);
1005 void __meminit
vmemmap_populate_print_last(void)
1008 printk(KERN_DEBUG
" [%lx-%lx] PMD -> [%p-%p] on node %d\n",
1009 addr_start
, addr_end
-1, p_start
, p_end
-1, node_start
);