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 <asm/uv/uv.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
);
111 if (pgd_none(*pgd_ref
))
114 spin_lock(&pgd_lock
);
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 /* the pgt_lock only for Xen */
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(&pgd_lock
);
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
= pgt_buf_end
++;
322 adr
= (void *)get_zeroed_page(GFP_ATOMIC
| __GFP_NOTRACK
);
328 if (pfn
>= pgt_buf_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 *map_low_page(void *virt
)
340 unsigned long phys
, left
;
346 left
= phys
& (PAGE_SIZE
- 1);
347 adr
= early_memremap(phys
& PAGE_MASK
, PAGE_SIZE
);
348 adr
= (void *)(((unsigned long)adr
) | left
);
353 static __ref
void unmap_low_page(void *adr
)
358 early_iounmap((void *)((unsigned long)adr
& PAGE_MASK
), PAGE_SIZE
);
361 static unsigned long __meminit
362 phys_pte_init(pte_t
*pte_page
, unsigned long addr
, unsigned long end
,
366 unsigned long last_map_addr
= end
;
369 pte_t
*pte
= pte_page
+ pte_index(addr
);
371 for(i
= pte_index(addr
); i
< PTRS_PER_PTE
; i
++, addr
+= PAGE_SIZE
, pte
++) {
374 if (!after_bootmem
) {
375 for(; i
< PTRS_PER_PTE
; i
++, pte
++)
376 set_pte(pte
, __pte(0));
382 * We will re-use the existing mapping.
383 * Xen for example has some special requirements, like mapping
384 * pagetable pages as RO. So assume someone who pre-setup
385 * these mappings are more intelligent.
393 printk(" pte=%p addr=%lx pte=%016lx\n",
394 pte
, addr
, pfn_pte(addr
>> PAGE_SHIFT
, PAGE_KERNEL
).pte
);
396 set_pte(pte
, pfn_pte(addr
>> PAGE_SHIFT
, prot
));
397 last_map_addr
= (addr
& PAGE_MASK
) + PAGE_SIZE
;
400 update_page_count(PG_LEVEL_4K
, pages
);
402 return last_map_addr
;
405 static unsigned long __meminit
406 phys_pmd_init(pmd_t
*pmd_page
, unsigned long address
, unsigned long end
,
407 unsigned long page_size_mask
, pgprot_t prot
)
409 unsigned long pages
= 0;
410 unsigned long last_map_addr
= end
;
412 int i
= pmd_index(address
);
414 for (; i
< PTRS_PER_PMD
; i
++, address
+= PMD_SIZE
) {
415 unsigned long pte_phys
;
416 pmd_t
*pmd
= pmd_page
+ pmd_index(address
);
418 pgprot_t new_prot
= prot
;
420 if (address
>= end
) {
421 if (!after_bootmem
) {
422 for (; i
< PTRS_PER_PMD
; i
++, pmd
++)
423 set_pmd(pmd
, __pmd(0));
429 if (!pmd_large(*pmd
)) {
430 spin_lock(&init_mm
.page_table_lock
);
431 pte
= map_low_page((pte_t
*)pmd_page_vaddr(*pmd
));
432 last_map_addr
= phys_pte_init(pte
, address
,
435 spin_unlock(&init_mm
.page_table_lock
);
439 * If we are ok with PG_LEVEL_2M mapping, then we will
440 * use the existing mapping,
442 * Otherwise, we will split the large page mapping but
443 * use the same existing protection bits except for
444 * large page, so that we don't violate Intel's TLB
445 * Application note (317080) which says, while changing
446 * the page sizes, new and old translations should
447 * not differ with respect to page frame and
450 if (page_size_mask
& (1 << PG_LEVEL_2M
)) {
454 new_prot
= pte_pgprot(pte_clrhuge(*(pte_t
*)pmd
));
457 if (page_size_mask
& (1<<PG_LEVEL_2M
)) {
459 spin_lock(&init_mm
.page_table_lock
);
460 set_pte((pte_t
*)pmd
,
461 pfn_pte(address
>> PAGE_SHIFT
,
462 __pgprot(pgprot_val(prot
) | _PAGE_PSE
)));
463 spin_unlock(&init_mm
.page_table_lock
);
464 last_map_addr
= (address
& PMD_MASK
) + PMD_SIZE
;
468 pte
= alloc_low_page(&pte_phys
);
469 last_map_addr
= phys_pte_init(pte
, address
, end
, new_prot
);
472 spin_lock(&init_mm
.page_table_lock
);
473 pmd_populate_kernel(&init_mm
, pmd
, __va(pte_phys
));
474 spin_unlock(&init_mm
.page_table_lock
);
476 update_page_count(PG_LEVEL_2M
, pages
);
477 return last_map_addr
;
480 static unsigned long __meminit
481 phys_pud_init(pud_t
*pud_page
, unsigned long addr
, unsigned long end
,
482 unsigned long page_size_mask
)
484 unsigned long pages
= 0;
485 unsigned long last_map_addr
= end
;
486 int i
= pud_index(addr
);
488 for (; i
< PTRS_PER_PUD
; i
++, addr
= (addr
& PUD_MASK
) + PUD_SIZE
) {
489 unsigned long pmd_phys
;
490 pud_t
*pud
= pud_page
+ pud_index(addr
);
492 pgprot_t prot
= PAGE_KERNEL
;
497 if (!after_bootmem
&&
498 !e820_any_mapped(addr
, addr
+PUD_SIZE
, 0)) {
499 set_pud(pud
, __pud(0));
504 if (!pud_large(*pud
)) {
505 pmd
= map_low_page(pmd_offset(pud
, 0));
506 last_map_addr
= phys_pmd_init(pmd
, addr
, end
,
507 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 unsigned long __meminit
558 kernel_physical_mapping_init(unsigned long start
,
560 unsigned long page_size_mask
)
562 bool pgd_changed
= false;
563 unsigned long next
, last_map_addr
= end
;
566 start
= (unsigned long)__va(start
);
567 end
= (unsigned long)__va(end
);
570 for (; start
< end
; start
= next
) {
571 pgd_t
*pgd
= pgd_offset_k(start
);
572 unsigned long pud_phys
;
575 next
= (start
+ PGDIR_SIZE
) & PGDIR_MASK
;
580 pud
= map_low_page((pud_t
*)pgd_page_vaddr(*pgd
));
581 last_map_addr
= phys_pud_init(pud
, __pa(start
),
582 __pa(end
), page_size_mask
);
587 pud
= alloc_low_page(&pud_phys
);
588 last_map_addr
= phys_pud_init(pud
, __pa(start
), __pa(next
),
592 spin_lock(&init_mm
.page_table_lock
);
593 pgd_populate(&init_mm
, pgd
, __va(pud_phys
));
594 spin_unlock(&init_mm
.page_table_lock
);
599 sync_global_pgds(addr
, end
);
603 return last_map_addr
;
607 void __init
initmem_init(void)
609 memblock_x86_register_active_regions(0, 0, max_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
)
903 #define MIN_MEMORY_BLOCK_SIZE (1 << SECTION_SIZE_BITS)
905 unsigned long memory_block_size_bytes(void)
907 if (is_uv_system()) {
908 printk(KERN_INFO
"UV: memory block size 2GB\n");
909 return 2UL * 1024 * 1024 * 1024;
911 return MIN_MEMORY_BLOCK_SIZE
;
915 #ifdef CONFIG_SPARSEMEM_VMEMMAP
917 * Initialise the sparsemem vmemmap using huge-pages at the PMD level.
919 static long __meminitdata addr_start
, addr_end
;
920 static void __meminitdata
*p_start
, *p_end
;
921 static int __meminitdata node_start
;
924 vmemmap_populate(struct page
*start_page
, unsigned long size
, int node
)
926 unsigned long addr
= (unsigned long)start_page
;
927 unsigned long end
= (unsigned long)(start_page
+ size
);
933 for (; addr
< end
; addr
= next
) {
936 pgd
= vmemmap_pgd_populate(addr
, node
);
940 pud
= vmemmap_pud_populate(pgd
, addr
, node
);
945 next
= (addr
+ PAGE_SIZE
) & PAGE_MASK
;
946 pmd
= vmemmap_pmd_populate(pud
, addr
, node
);
951 p
= vmemmap_pte_populate(pmd
, addr
, node
);
956 addr_end
= addr
+ PAGE_SIZE
;
957 p_end
= p
+ PAGE_SIZE
;
959 next
= pmd_addr_end(addr
, end
);
961 pmd
= pmd_offset(pud
, addr
);
962 if (pmd_none(*pmd
)) {
965 p
= vmemmap_alloc_block_buf(PMD_SIZE
, node
);
969 entry
= pfn_pte(__pa(p
) >> PAGE_SHIFT
,
971 set_pmd(pmd
, __pmd(pte_val(entry
)));
973 /* check to see if we have contiguous blocks */
974 if (p_end
!= p
|| node_start
!= node
) {
976 printk(KERN_DEBUG
" [%lx-%lx] PMD -> [%p-%p] on node %d\n",
977 addr_start
, addr_end
-1, p_start
, p_end
-1, node_start
);
983 addr_end
= addr
+ PMD_SIZE
;
984 p_end
= p
+ PMD_SIZE
;
986 vmemmap_verify((pte_t
*)pmd
, node
, addr
, next
);
990 sync_global_pgds((unsigned long)start_page
, end
);
994 void __meminit
vmemmap_populate_print_last(void)
997 printk(KERN_DEBUG
" [%lx-%lx] PMD -> [%p-%p] on node %d\n",
998 addr_start
, addr_end
-1, p_start
, p_end
-1, node_start
);