Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
| 3 | * Copyright (C) 1995 Linus Torvalds |
| 4 | * |
| 5 | * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999 |
| 6 | */ |
| 7 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/module.h> |
| 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> |
| 17 | #include <linux/mm.h> |
| 18 | #include <linux/hugetlb.h> |
| 19 | #include <linux/swap.h> |
| 20 | #include <linux/smp.h> |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/highmem.h> |
| 23 | #include <linux/pagemap.h> |
Jeremy Fitzhardinge | cfb80c9 | 2008-12-16 12:17:36 -0800 | [diff] [blame] | 24 | #include <linux/pci.h> |
Jan Beulich | 6fb1475 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 25 | #include <linux/pfn.h> |
Randy Dunlap | c9cf552 | 2006-06-27 02:53:52 -0700 | [diff] [blame] | 26 | #include <linux/poison.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/bootmem.h> |
| 28 | #include <linux/slab.h> |
| 29 | #include <linux/proc_fs.h> |
Dave Hansen | 05039b9 | 2005-10-29 18:16:57 -0700 | [diff] [blame] | 30 | #include <linux/memory_hotplug.h> |
Adrian Bunk | 27d99f7 | 2005-11-13 16:06:51 -0800 | [diff] [blame] | 31 | #include <linux/initrd.h> |
Shaohua Li | 55b2355 | 2006-06-23 02:04:49 -0700 | [diff] [blame] | 32 | #include <linux/cpumask.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
H. Peter Anvin | f832ff1 | 2008-02-04 16:47:58 +0100 | [diff] [blame] | 34 | #include <asm/asm.h> |
Ingo Molnar | 46eaa67 | 2008-10-12 15:06:29 +0200 | [diff] [blame] | 35 | #include <asm/bios_ebda.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <asm/processor.h> |
| 37 | #include <asm/system.h> |
| 38 | #include <asm/uaccess.h> |
| 39 | #include <asm/pgtable.h> |
| 40 | #include <asm/dma.h> |
| 41 | #include <asm/fixmap.h> |
| 42 | #include <asm/e820.h> |
| 43 | #include <asm/apic.h> |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 44 | #include <asm/bugs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <asm/tlb.h> |
| 46 | #include <asm/tlbflush.h> |
Jeremy Fitzhardinge | a5a19c6 | 2008-01-30 13:33:39 +0100 | [diff] [blame] | 47 | #include <asm/pgalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <asm/sections.h> |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 49 | #include <asm/paravirt.h> |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 50 | #include <asm/setup.h> |
Harvey Harrison | 7bfeab9 | 2008-02-12 12:12:01 -0800 | [diff] [blame] | 51 | #include <asm/cacheflush.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Yinghai Lu | f361a45 | 2008-07-10 20:38:26 -0700 | [diff] [blame] | 53 | unsigned long max_low_pfn_mapped; |
Thomas Gleixner | 6779429 | 2008-03-21 21:27:10 +0100 | [diff] [blame] | 54 | unsigned long max_pfn_mapped; |
Andi Kleen | 7d1116a | 2008-03-12 03:53:27 +0100 | [diff] [blame] | 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); |
| 57 | unsigned long highstart_pfn, highend_pfn; |
| 58 | |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 59 | static noinline int do_test_wp_bit(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Yinghai Lu | 4e29684 | 2008-06-24 12:18:14 -0700 | [diff] [blame] | 61 | |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame^] | 62 | extern unsigned long __initdata table_start; |
| 63 | extern unsigned long __meminitdata table_end; |
| 64 | extern unsigned long __meminitdata table_top; |
Pekka Enberg | 4bbd4fa | 2009-03-05 14:54:53 +0200 | [diff] [blame] | 65 | |
Jan Beulich | d6be89a | 2008-12-16 11:42:45 +0000 | [diff] [blame] | 66 | static __init void *alloc_low_page(void) |
Yinghai Lu | 4e29684 | 2008-06-24 12:18:14 -0700 | [diff] [blame] | 67 | { |
| 68 | unsigned long pfn = table_end++; |
| 69 | void *adr; |
| 70 | |
| 71 | if (pfn >= table_top) |
| 72 | panic("alloc_low_page: ran out of memory"); |
| 73 | |
| 74 | adr = __va(pfn * PAGE_SIZE); |
| 75 | memset(adr, 0, PAGE_SIZE); |
Yinghai Lu | 4e29684 | 2008-06-24 12:18:14 -0700 | [diff] [blame] | 76 | return adr; |
| 77 | } |
| 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | /* |
| 80 | * Creates a middle page table and puts a pointer to it in the |
| 81 | * given global directory entry. This only returns the gd entry |
| 82 | * in non-PAE compilation mode, since the middle layer is folded. |
| 83 | */ |
| 84 | static pmd_t * __init one_md_table_init(pgd_t *pgd) |
| 85 | { |
| 86 | pud_t *pud; |
| 87 | pmd_t *pmd_table; |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | #ifdef CONFIG_X86_PAE |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 90 | if (!(pgd_val(*pgd) & _PAGE_PRESENT)) { |
Pekka Enberg | c464573 | 2009-03-05 14:54:58 +0200 | [diff] [blame] | 91 | if (after_bootmem) |
Yinghai Lu | 4e29684 | 2008-06-24 12:18:14 -0700 | [diff] [blame] | 92 | pmd_table = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE); |
| 93 | else |
Jan Beulich | d6be89a | 2008-12-16 11:42:45 +0000 | [diff] [blame] | 94 | pmd_table = (pmd_t *)alloc_low_page(); |
Jeremy Fitzhardinge | 6944a9c | 2008-03-17 16:37:01 -0700 | [diff] [blame] | 95 | paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT); |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 96 | set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT)); |
| 97 | pud = pud_offset(pgd, 0); |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 98 | BUG_ON(pmd_table != pmd_offset(pud, 0)); |
Zhaolei | a376f30 | 2008-10-31 17:43:04 +0800 | [diff] [blame] | 99 | |
| 100 | return pmd_table; |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 101 | } |
| 102 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | pud = pud_offset(pgd, 0); |
| 104 | pmd_table = pmd_offset(pud, 0); |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | return pmd_table; |
| 107 | } |
| 108 | |
| 109 | /* |
| 110 | * Create a page table and place a pointer to it in a middle page |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 111 | * directory entry: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | */ |
| 113 | static pte_t * __init one_page_table_init(pmd_t *pmd) |
| 114 | { |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 115 | if (!(pmd_val(*pmd) & _PAGE_PRESENT)) { |
Ingo Molnar | 509a80c | 2007-10-17 18:04:34 +0200 | [diff] [blame] | 116 | pte_t *page_table = NULL; |
| 117 | |
Pekka Enberg | c464573 | 2009-03-05 14:54:58 +0200 | [diff] [blame] | 118 | if (after_bootmem) { |
Ingo Molnar | 509a80c | 2007-10-17 18:04:34 +0200 | [diff] [blame] | 119 | #ifdef CONFIG_DEBUG_PAGEALLOC |
Yinghai Lu | 4e29684 | 2008-06-24 12:18:14 -0700 | [diff] [blame] | 120 | page_table = (pte_t *) alloc_bootmem_pages(PAGE_SIZE); |
Ingo Molnar | 509a80c | 2007-10-17 18:04:34 +0200 | [diff] [blame] | 121 | #endif |
Yinghai Lu | 4e29684 | 2008-06-24 12:18:14 -0700 | [diff] [blame] | 122 | if (!page_table) |
| 123 | page_table = |
Ingo Molnar | 509a80c | 2007-10-17 18:04:34 +0200 | [diff] [blame] | 124 | (pte_t *)alloc_bootmem_low_pages(PAGE_SIZE); |
Jan Beulich | d6be89a | 2008-12-16 11:42:45 +0000 | [diff] [blame] | 125 | } else |
| 126 | page_table = (pte_t *)alloc_low_page(); |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 127 | |
Jeremy Fitzhardinge | 6944a9c | 2008-03-17 16:37:01 -0700 | [diff] [blame] | 128 | paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE)); |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 130 | BUG_ON(page_table != pte_offset_kernel(pmd, 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | } |
Ingo Molnar | 509a80c | 2007-10-17 18:04:34 +0200 | [diff] [blame] | 132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | return pte_offset_kernel(pmd, 0); |
| 134 | } |
| 135 | |
Jan Beulich | a3c6018 | 2009-01-16 11:59:33 +0000 | [diff] [blame] | 136 | static pte_t *__init page_table_kmap_check(pte_t *pte, pmd_t *pmd, |
| 137 | unsigned long vaddr, pte_t *lastpte) |
| 138 | { |
| 139 | #ifdef CONFIG_HIGHMEM |
| 140 | /* |
| 141 | * Something (early fixmap) may already have put a pte |
| 142 | * page here, which causes the page table allocation |
| 143 | * to become nonlinear. Attempt to fix it, and if it |
| 144 | * is still nonlinear then we have to bug. |
| 145 | */ |
| 146 | int pmd_idx_kmap_begin = fix_to_virt(FIX_KMAP_END) >> PMD_SHIFT; |
| 147 | int pmd_idx_kmap_end = fix_to_virt(FIX_KMAP_BEGIN) >> PMD_SHIFT; |
| 148 | |
| 149 | if (pmd_idx_kmap_begin != pmd_idx_kmap_end |
| 150 | && (vaddr >> PMD_SHIFT) >= pmd_idx_kmap_begin |
| 151 | && (vaddr >> PMD_SHIFT) <= pmd_idx_kmap_end |
| 152 | && ((__pa(pte) >> PAGE_SHIFT) < table_start |
| 153 | || (__pa(pte) >> PAGE_SHIFT) >= table_end)) { |
| 154 | pte_t *newpte; |
| 155 | int i; |
| 156 | |
Pekka Enberg | c464573 | 2009-03-05 14:54:58 +0200 | [diff] [blame] | 157 | BUG_ON(after_bootmem); |
Jan Beulich | a3c6018 | 2009-01-16 11:59:33 +0000 | [diff] [blame] | 158 | newpte = alloc_low_page(); |
| 159 | for (i = 0; i < PTRS_PER_PTE; i++) |
| 160 | set_pte(newpte + i, pte[i]); |
| 161 | |
| 162 | paravirt_alloc_pte(&init_mm, __pa(newpte) >> PAGE_SHIFT); |
| 163 | set_pmd(pmd, __pmd(__pa(newpte)|_PAGE_TABLE)); |
| 164 | BUG_ON(newpte != pte_offset_kernel(pmd, 0)); |
| 165 | __flush_tlb_all(); |
| 166 | |
| 167 | paravirt_release_pte(__pa(pte) >> PAGE_SHIFT); |
| 168 | pte = newpte; |
| 169 | } |
| 170 | BUG_ON(vaddr < fix_to_virt(FIX_KMAP_BEGIN - 1) |
| 171 | && vaddr > fix_to_virt(FIX_KMAP_END) |
| 172 | && lastpte && lastpte + PTRS_PER_PTE != pte); |
| 173 | #endif |
| 174 | return pte; |
| 175 | } |
| 176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | /* |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 178 | * This function initializes a certain range of kernel virtual memory |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | * with new bootmem page tables, everywhere page tables are missing in |
| 180 | * the given range. |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 181 | * |
| 182 | * NOTE: The pagetables are allocated contiguous on the physical space |
| 183 | * so we can cache the place of the first one and move around without |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | * checking the pgd every time. |
| 185 | */ |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 186 | static void __init |
| 187 | page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | int pgd_idx, pmd_idx; |
| 190 | unsigned long vaddr; |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 191 | pgd_t *pgd; |
| 192 | pmd_t *pmd; |
Jan Beulich | a3c6018 | 2009-01-16 11:59:33 +0000 | [diff] [blame] | 193 | pte_t *pte = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
| 195 | vaddr = start; |
| 196 | pgd_idx = pgd_index(vaddr); |
| 197 | pmd_idx = pmd_index(vaddr); |
| 198 | pgd = pgd_base + pgd_idx; |
| 199 | |
| 200 | for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) { |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 201 | pmd = one_md_table_init(pgd); |
| 202 | pmd = pmd + pmd_index(vaddr); |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 203 | for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end); |
| 204 | pmd++, pmd_idx++) { |
Jan Beulich | a3c6018 | 2009-01-16 11:59:33 +0000 | [diff] [blame] | 205 | pte = page_table_kmap_check(one_page_table_init(pmd), |
| 206 | pmd, vaddr, pte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
| 208 | vaddr += PMD_SIZE; |
| 209 | } |
| 210 | pmd_idx = 0; |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | static inline int is_kernel_text(unsigned long addr) |
| 215 | { |
| 216 | if (addr >= PAGE_OFFSET && addr <= (unsigned long)__init_end) |
| 217 | return 1; |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | /* |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 222 | * This maps the physical memory to kernel virtual address space, a total |
| 223 | * of max_low_pfn pages, by creating page tables starting from address |
| 224 | * PAGE_OFFSET: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | */ |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame^] | 226 | void __init kernel_physical_mapping_init(unsigned long start_pfn, |
| 227 | unsigned long end_pfn, |
| 228 | int use_pse) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | { |
Pekka Enberg | e717985 | 2009-03-05 14:54:55 +0200 | [diff] [blame] | 230 | pgd_t *pgd_base = swapper_pg_dir; |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 231 | int pgd_idx, pmd_idx, pte_ofs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | unsigned long pfn; |
| 233 | pgd_t *pgd; |
| 234 | pmd_t *pmd; |
| 235 | pte_t *pte; |
Suresh Siddha | a2699e4 | 2008-09-23 14:00:38 -0700 | [diff] [blame] | 236 | unsigned pages_2m, pages_4k; |
| 237 | int mapping_iter; |
| 238 | |
| 239 | /* |
| 240 | * First iteration will setup identity mapping using large/small pages |
| 241 | * based on use_pse, with other attributes same as set by |
| 242 | * the early code in head_32.S |
| 243 | * |
| 244 | * Second iteration will setup the appropriate attributes (NX, GLOBAL..) |
| 245 | * as desired for the kernel identity mapping. |
| 246 | * |
| 247 | * This two pass mechanism conforms to the TLB app note which says: |
| 248 | * |
| 249 | * "Software should not write to a paging-structure entry in a way |
| 250 | * that would change, for any linear address, both the page size |
| 251 | * and either the page frame or attributes." |
| 252 | */ |
| 253 | mapping_iter = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
Yinghai Lu | a04ad82 | 2008-06-29 00:39:06 -0700 | [diff] [blame] | 255 | if (!cpu_has_pse) |
| 256 | use_pse = 0; |
| 257 | |
Suresh Siddha | a2699e4 | 2008-09-23 14:00:38 -0700 | [diff] [blame] | 258 | repeat: |
| 259 | pages_2m = pages_4k = 0; |
Yinghai Lu | a04ad82 | 2008-06-29 00:39:06 -0700 | [diff] [blame] | 260 | pfn = start_pfn; |
| 261 | pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | pgd = pgd_base + pgd_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) { |
| 264 | pmd = one_md_table_init(pgd); |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 265 | |
Yinghai Lu | a04ad82 | 2008-06-29 00:39:06 -0700 | [diff] [blame] | 266 | if (pfn >= end_pfn) |
| 267 | continue; |
| 268 | #ifdef CONFIG_X86_PAE |
| 269 | pmd_idx = pmd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET); |
| 270 | pmd += pmd_idx; |
| 271 | #else |
| 272 | pmd_idx = 0; |
| 273 | #endif |
| 274 | for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn; |
Jeremy Fitzhardinge | f3f20de | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 275 | pmd++, pmd_idx++) { |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 276 | unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 278 | /* |
| 279 | * Map with big pages if possible, otherwise |
| 280 | * create normal page tables: |
| 281 | */ |
Yinghai Lu | a04ad82 | 2008-06-29 00:39:06 -0700 | [diff] [blame] | 282 | if (use_pse) { |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 283 | unsigned int addr2; |
Jeremy Fitzhardinge | f3f20de | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 284 | pgprot_t prot = PAGE_KERNEL_LARGE; |
Suresh Siddha | a2699e4 | 2008-09-23 14:00:38 -0700 | [diff] [blame] | 285 | /* |
| 286 | * first pass will use the same initial |
| 287 | * identity mapping attribute + _PAGE_PSE. |
| 288 | */ |
| 289 | pgprot_t init_prot = |
| 290 | __pgprot(PTE_IDENT_ATTR | |
| 291 | _PAGE_PSE); |
Jeremy Fitzhardinge | f3f20de | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 292 | |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 293 | addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE + |
Jeremy Fitzhardinge | f3f20de | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 294 | PAGE_OFFSET + PAGE_SIZE-1; |
| 295 | |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 296 | if (is_kernel_text(addr) || |
| 297 | is_kernel_text(addr2)) |
Jeremy Fitzhardinge | f3f20de | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 298 | prot = PAGE_KERNEL_LARGE_EXEC; |
| 299 | |
Andi Kleen | ce0c0e5 | 2008-05-02 11:46:49 +0200 | [diff] [blame] | 300 | pages_2m++; |
Suresh Siddha | a2699e4 | 2008-09-23 14:00:38 -0700 | [diff] [blame] | 301 | if (mapping_iter == 1) |
| 302 | set_pmd(pmd, pfn_pmd(pfn, init_prot)); |
| 303 | else |
| 304 | set_pmd(pmd, pfn_pmd(pfn, prot)); |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 305 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | pfn += PTRS_PER_PTE; |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 307 | continue; |
| 308 | } |
| 309 | pte = one_page_table_init(pmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
Yinghai Lu | a04ad82 | 2008-06-29 00:39:06 -0700 | [diff] [blame] | 311 | pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET); |
| 312 | pte += pte_ofs; |
| 313 | for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn; |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 314 | pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) { |
| 315 | pgprot_t prot = PAGE_KERNEL; |
Suresh Siddha | a2699e4 | 2008-09-23 14:00:38 -0700 | [diff] [blame] | 316 | /* |
| 317 | * first pass will use the same initial |
| 318 | * identity mapping attribute. |
| 319 | */ |
| 320 | pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR); |
Jeremy Fitzhardinge | f3f20de | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 321 | |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 322 | if (is_kernel_text(addr)) |
| 323 | prot = PAGE_KERNEL_EXEC; |
Jeremy Fitzhardinge | f3f20de | 2008-01-30 13:31:09 +0100 | [diff] [blame] | 324 | |
Andi Kleen | ce0c0e5 | 2008-05-02 11:46:49 +0200 | [diff] [blame] | 325 | pages_4k++; |
Suresh Siddha | a2699e4 | 2008-09-23 14:00:38 -0700 | [diff] [blame] | 326 | if (mapping_iter == 1) |
| 327 | set_pte(pte, pfn_pte(pfn, init_prot)); |
| 328 | else |
| 329 | set_pte(pte, pfn_pte(pfn, prot)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | } |
| 331 | } |
| 332 | } |
Suresh Siddha | a2699e4 | 2008-09-23 14:00:38 -0700 | [diff] [blame] | 333 | if (mapping_iter == 1) { |
| 334 | /* |
| 335 | * update direct mapping page count only in the first |
| 336 | * iteration. |
| 337 | */ |
| 338 | update_page_count(PG_LEVEL_2M, pages_2m); |
| 339 | update_page_count(PG_LEVEL_4K, pages_4k); |
| 340 | |
| 341 | /* |
| 342 | * local global flush tlb, which will flush the previous |
| 343 | * mappings present in both small and large page TLB's. |
| 344 | */ |
| 345 | __flush_tlb_all(); |
| 346 | |
| 347 | /* |
| 348 | * Second iteration will set the actual desired PTE attributes. |
| 349 | */ |
| 350 | mapping_iter = 2; |
| 351 | goto repeat; |
| 352 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | pte_t *kmap_pte; |
| 356 | pgprot_t kmap_prot; |
| 357 | |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 358 | static inline pte_t *kmap_get_fixmap_pte(unsigned long vaddr) |
| 359 | { |
| 360 | return pte_offset_kernel(pmd_offset(pud_offset(pgd_offset_k(vaddr), |
| 361 | vaddr), vaddr), vaddr); |
| 362 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | |
| 364 | static void __init kmap_init(void) |
| 365 | { |
| 366 | unsigned long kmap_vstart; |
| 367 | |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 368 | /* |
| 369 | * Cache the first kmap pte: |
| 370 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | kmap_vstart = __fix_to_virt(FIX_KMAP_BEGIN); |
| 372 | kmap_pte = kmap_get_fixmap_pte(kmap_vstart); |
| 373 | |
| 374 | kmap_prot = PAGE_KERNEL; |
| 375 | } |
| 376 | |
Keith Packard | fd94093 | 2008-10-30 19:37:09 -0700 | [diff] [blame] | 377 | #ifdef CONFIG_HIGHMEM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | static void __init permanent_kmaps_init(pgd_t *pgd_base) |
| 379 | { |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 380 | unsigned long vaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | pgd_t *pgd; |
| 382 | pud_t *pud; |
| 383 | pmd_t *pmd; |
| 384 | pte_t *pte; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
| 386 | vaddr = PKMAP_BASE; |
| 387 | page_table_range_init(vaddr, vaddr + PAGE_SIZE*LAST_PKMAP, pgd_base); |
| 388 | |
| 389 | pgd = swapper_pg_dir + pgd_index(vaddr); |
| 390 | pud = pud_offset(pgd, vaddr); |
| 391 | pmd = pmd_offset(pud, vaddr); |
| 392 | pte = pte_offset_kernel(pmd, vaddr); |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 393 | pkmap_page_table = pte; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Yinghai Lu | cc9f7a0 | 2008-06-16 16:11:08 -0700 | [diff] [blame] | 396 | static void __init add_one_highpage_init(struct page *page, int pfn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | { |
Yinghai Lu | cc9f7a0 | 2008-06-16 16:11:08 -0700 | [diff] [blame] | 398 | ClearPageReserved(page); |
| 399 | init_page_count(page); |
| 400 | __free_page(page); |
| 401 | totalhigh_pages++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Yinghai Lu | b5bc6c0 | 2008-06-14 18:32:52 -0700 | [diff] [blame] | 404 | struct add_highpages_data { |
| 405 | unsigned long start_pfn; |
| 406 | unsigned long end_pfn; |
Yinghai Lu | b5bc6c0 | 2008-06-14 18:32:52 -0700 | [diff] [blame] | 407 | }; |
| 408 | |
Yinghai Lu | d52d53b | 2008-06-16 20:10:55 -0700 | [diff] [blame] | 409 | static int __init add_highpages_work_fn(unsigned long start_pfn, |
Yinghai Lu | b5bc6c0 | 2008-06-14 18:32:52 -0700 | [diff] [blame] | 410 | unsigned long end_pfn, void *datax) |
| 411 | { |
| 412 | int node_pfn; |
| 413 | struct page *page; |
| 414 | unsigned long final_start_pfn, final_end_pfn; |
| 415 | struct add_highpages_data *data; |
Yinghai Lu | b5bc6c0 | 2008-06-14 18:32:52 -0700 | [diff] [blame] | 416 | |
| 417 | data = (struct add_highpages_data *)datax; |
Yinghai Lu | b5bc6c0 | 2008-06-14 18:32:52 -0700 | [diff] [blame] | 418 | |
| 419 | final_start_pfn = max(start_pfn, data->start_pfn); |
| 420 | final_end_pfn = min(end_pfn, data->end_pfn); |
| 421 | if (final_start_pfn >= final_end_pfn) |
Yinghai Lu | d52d53b | 2008-06-16 20:10:55 -0700 | [diff] [blame] | 422 | return 0; |
Yinghai Lu | b5bc6c0 | 2008-06-14 18:32:52 -0700 | [diff] [blame] | 423 | |
| 424 | for (node_pfn = final_start_pfn; node_pfn < final_end_pfn; |
| 425 | node_pfn++) { |
| 426 | if (!pfn_valid(node_pfn)) |
| 427 | continue; |
| 428 | page = pfn_to_page(node_pfn); |
Yinghai Lu | cc9f7a0 | 2008-06-16 16:11:08 -0700 | [diff] [blame] | 429 | add_one_highpage_init(page, node_pfn); |
Yinghai Lu | b5bc6c0 | 2008-06-14 18:32:52 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Yinghai Lu | d52d53b | 2008-06-16 20:10:55 -0700 | [diff] [blame] | 432 | return 0; |
| 433 | |
Yinghai Lu | b5bc6c0 | 2008-06-14 18:32:52 -0700 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | void __init add_highpages_with_active_regions(int nid, unsigned long start_pfn, |
Yinghai Lu | cc9f7a0 | 2008-06-16 16:11:08 -0700 | [diff] [blame] | 437 | unsigned long end_pfn) |
Yinghai Lu | b5bc6c0 | 2008-06-14 18:32:52 -0700 | [diff] [blame] | 438 | { |
| 439 | struct add_highpages_data data; |
| 440 | |
| 441 | data.start_pfn = start_pfn; |
| 442 | data.end_pfn = end_pfn; |
Yinghai Lu | b5bc6c0 | 2008-06-14 18:32:52 -0700 | [diff] [blame] | 443 | |
| 444 | work_with_active_regions(nid, add_highpages_work_fn, &data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | #else |
Ingo Brueckl | e8e3232 | 2009-01-02 14:42:00 +0100 | [diff] [blame] | 448 | static inline void permanent_kmaps_init(pgd_t *pgd_base) |
| 449 | { |
| 450 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | #endif /* CONFIG_HIGHMEM */ |
| 452 | |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 453 | void __init native_pagetable_setup_start(pgd_t *base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | { |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 455 | unsigned long pfn, va; |
| 456 | pgd_t *pgd; |
| 457 | pud_t *pud; |
| 458 | pmd_t *pmd; |
| 459 | pte_t *pte; |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 460 | |
| 461 | /* |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 462 | * Remove any mappings which extend past the end of physical |
| 463 | * memory from the boot time page table: |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 464 | */ |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 465 | for (pfn = max_low_pfn + 1; pfn < 1<<(32-PAGE_SHIFT); pfn++) { |
| 466 | va = PAGE_OFFSET + (pfn<<PAGE_SHIFT); |
| 467 | pgd = base + pgd_index(va); |
| 468 | if (!pgd_present(*pgd)) |
| 469 | break; |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 470 | |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 471 | pud = pud_offset(pgd, va); |
| 472 | pmd = pmd_offset(pud, va); |
| 473 | if (!pmd_present(*pmd)) |
| 474 | break; |
| 475 | |
| 476 | pte = pte_offset_kernel(pmd, va); |
| 477 | if (!pte_present(*pte)) |
| 478 | break; |
| 479 | |
| 480 | pte_clear(NULL, va, pte); |
| 481 | } |
Jeremy Fitzhardinge | 6944a9c | 2008-03-17 16:37:01 -0700 | [diff] [blame] | 482 | paravirt_alloc_pmd(&init_mm, __pa(base) >> PAGE_SHIFT); |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | void __init native_pagetable_setup_done(pgd_t *base) |
| 486 | { |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | /* |
| 490 | * Build a proper pagetable for the kernel mappings. Up until this |
| 491 | * point, we've been running on some set of pagetables constructed by |
| 492 | * the boot process. |
| 493 | * |
| 494 | * If we're booting on native hardware, this will be a pagetable |
Ian Campbell | 551889a6 | 2008-02-09 23:24:09 +0100 | [diff] [blame] | 495 | * constructed in arch/x86/kernel/head_32.S. The root of the |
| 496 | * pagetable will be swapper_pg_dir. |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 497 | * |
| 498 | * If we're booting paravirtualized under a hypervisor, then there are |
| 499 | * more options: we may already be running PAE, and the pagetable may |
| 500 | * or may not be based in swapper_pg_dir. In any case, |
| 501 | * paravirt_pagetable_setup_start() will set up swapper_pg_dir |
| 502 | * appropriately for the rest of the initialization to work. |
| 503 | * |
| 504 | * In general, pagetable_init() assumes that the pagetable may already |
| 505 | * be partially populated, and so it avoids stomping on any existing |
| 506 | * mappings. |
| 507 | */ |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame^] | 508 | void __init early_ioremap_page_table_range_init(void) |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 509 | { |
Pekka Enberg | e717985 | 2009-03-05 14:54:55 +0200 | [diff] [blame] | 510 | pgd_t *pgd_base = swapper_pg_dir; |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 511 | unsigned long vaddr, end; |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 512 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | /* |
| 514 | * Fixed mappings, only the page table structure has to be |
| 515 | * created - mappings will be set by set_fixmap(): |
| 516 | */ |
| 517 | vaddr = __fix_to_virt(__end_of_fixed_addresses - 1) & PMD_MASK; |
Jeremy Fitzhardinge | b239fb2 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 518 | end = (FIXADDR_TOP + PMD_SIZE - 1) & PMD_MASK; |
| 519 | page_table_range_init(vaddr, end, pgd_base); |
Huang, Ying | beacfaa | 2008-01-30 13:33:44 +0100 | [diff] [blame] | 520 | early_ioremap_reset(); |
Yinghai Lu | e7b3789 | 2008-06-25 21:51:28 -0700 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | static void __init pagetable_init(void) |
| 524 | { |
| 525 | pgd_t *pgd_base = swapper_pg_dir; |
| 526 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | permanent_kmaps_init(pgd_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | } |
| 529 | |
Rafael J. Wysocki | a6eb84b | 2008-02-01 15:28:16 +0100 | [diff] [blame] | 530 | #ifdef CONFIG_ACPI_SLEEP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | /* |
Rafael J. Wysocki | a6eb84b | 2008-02-01 15:28:16 +0100 | [diff] [blame] | 532 | * ACPI suspend needs this for resume, because things like the intel-agp |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | * driver might have split up a kernel 4MB mapping. |
| 534 | */ |
Rafael J. Wysocki | a6eb84b | 2008-02-01 15:28:16 +0100 | [diff] [blame] | 535 | char swsusp_pg_dir[PAGE_SIZE] |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 536 | __attribute__ ((aligned(PAGE_SIZE))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | |
| 538 | static inline void save_pg_dir(void) |
| 539 | { |
| 540 | memcpy(swsusp_pg_dir, swapper_pg_dir, PAGE_SIZE); |
| 541 | } |
Rafael J. Wysocki | a6eb84b | 2008-02-01 15:28:16 +0100 | [diff] [blame] | 542 | #else /* !CONFIG_ACPI_SLEEP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | static inline void save_pg_dir(void) |
| 544 | { |
| 545 | } |
Rafael J. Wysocki | a6eb84b | 2008-02-01 15:28:16 +0100 | [diff] [blame] | 546 | #endif /* !CONFIG_ACPI_SLEEP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 548 | void zap_low_mappings(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | { |
| 550 | int i; |
| 551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | /* |
| 553 | * Zap initial low-memory mappings. |
| 554 | * |
| 555 | * Note that "pgd_clear()" doesn't do it for |
| 556 | * us, because pgd_clear() is a no-op on i386. |
| 557 | */ |
Jeremy Fitzhardinge | 68db065 | 2008-03-17 16:37:13 -0700 | [diff] [blame] | 558 | for (i = 0; i < KERNEL_PGD_BOUNDARY; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | #ifdef CONFIG_X86_PAE |
| 560 | set_pgd(swapper_pg_dir+i, __pgd(1 + __pa(empty_zero_page))); |
| 561 | #else |
| 562 | set_pgd(swapper_pg_dir+i, __pgd(0)); |
| 563 | #endif |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 564 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | flush_tlb_all(); |
| 566 | } |
| 567 | |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 568 | int nx_enabled; |
Jan Beulich | d5321ab | 2007-07-21 17:10:26 +0200 | [diff] [blame] | 569 | |
Jeremy Fitzhardinge | be43d72 | 2008-09-07 15:21:13 -0700 | [diff] [blame] | 570 | pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP); |
Jeremy Fitzhardinge | 6fdc05d | 2008-01-30 13:32:57 +0100 | [diff] [blame] | 571 | EXPORT_SYMBOL_GPL(__supported_pte_mask); |
| 572 | |
Jan Beulich | d5321ab | 2007-07-21 17:10:26 +0200 | [diff] [blame] | 573 | #ifdef CONFIG_X86_PAE |
| 574 | |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 575 | static int disable_nx __initdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | |
| 577 | /* |
| 578 | * noexec = on|off |
| 579 | * |
| 580 | * Control non executable mappings. |
| 581 | * |
| 582 | * on Enable |
| 583 | * off Disable |
| 584 | */ |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 585 | static int __init noexec_setup(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | { |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 587 | if (!str || !strcmp(str, "on")) { |
| 588 | if (cpu_has_nx) { |
| 589 | __supported_pte_mask |= _PAGE_NX; |
| 590 | disable_nx = 0; |
| 591 | } |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 592 | } else { |
| 593 | if (!strcmp(str, "off")) { |
| 594 | disable_nx = 1; |
| 595 | __supported_pte_mask &= ~_PAGE_NX; |
| 596 | } else { |
| 597 | return -EINVAL; |
| 598 | } |
| 599 | } |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 600 | |
| 601 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | } |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 603 | early_param("noexec", noexec_setup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | static void __init set_nx(void) |
| 606 | { |
| 607 | unsigned int v[4], l, h; |
| 608 | |
| 609 | if (cpu_has_pae && (cpuid_eax(0x80000000) > 0x80000001)) { |
| 610 | cpuid(0x80000001, &v[0], &v[1], &v[2], &v[3]); |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 611 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | if ((v[3] & (1 << 20)) && !disable_nx) { |
| 613 | rdmsr(MSR_EFER, l, h); |
| 614 | l |= EFER_NX; |
| 615 | wrmsr(MSR_EFER, l, h); |
| 616 | nx_enabled = 1; |
| 617 | __supported_pte_mask |= _PAGE_NX; |
| 618 | } |
| 619 | } |
| 620 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | #endif |
| 622 | |
Yinghai Lu | 90d967e | 2008-06-23 21:00:45 +0200 | [diff] [blame] | 623 | /* user-defined highmem size */ |
| 624 | static unsigned int highmem_pages = -1; |
| 625 | |
| 626 | /* |
| 627 | * highmem=size forces highmem to be exactly 'size' bytes. |
| 628 | * This works even on boxes that have no highmem otherwise. |
| 629 | * This also works to reduce highmem size on bigger boxes. |
| 630 | */ |
| 631 | static int __init parse_highmem(char *arg) |
| 632 | { |
| 633 | if (!arg) |
| 634 | return -EINVAL; |
| 635 | |
| 636 | highmem_pages = memparse(arg, &arg) >> PAGE_SHIFT; |
| 637 | return 0; |
| 638 | } |
| 639 | early_param("highmem", parse_highmem); |
| 640 | |
Ingo Molnar | 4769843 | 2009-02-12 13:31:41 +0100 | [diff] [blame] | 641 | #define MSG_HIGHMEM_TOO_BIG \ |
| 642 | "highmem size (%luMB) is bigger than pages available (%luMB)!\n" |
| 643 | |
| 644 | #define MSG_LOWMEM_TOO_SMALL \ |
| 645 | "highmem size (%luMB) results in <64MB lowmem, ignoring it!\n" |
| 646 | /* |
| 647 | * All of RAM fits into lowmem - but if user wants highmem |
| 648 | * artificially via the highmem=x boot parameter then create |
| 649 | * it: |
| 650 | */ |
| 651 | void __init lowmem_pfn_init(void) |
| 652 | { |
Ingo Molnar | d88316c2 | 2009-02-12 15:16:03 +0100 | [diff] [blame] | 653 | /* max_low_pfn is 0, we already have early_res support */ |
| 654 | max_low_pfn = max_pfn; |
| 655 | |
Ingo Molnar | 4769843 | 2009-02-12 13:31:41 +0100 | [diff] [blame] | 656 | if (highmem_pages == -1) |
| 657 | highmem_pages = 0; |
| 658 | #ifdef CONFIG_HIGHMEM |
| 659 | if (highmem_pages >= max_pfn) { |
| 660 | printk(KERN_ERR MSG_HIGHMEM_TOO_BIG, |
| 661 | pages_to_mb(highmem_pages), pages_to_mb(max_pfn)); |
| 662 | highmem_pages = 0; |
| 663 | } |
| 664 | if (highmem_pages) { |
| 665 | if (max_low_pfn - highmem_pages < 64*1024*1024/PAGE_SIZE) { |
| 666 | printk(KERN_ERR MSG_LOWMEM_TOO_SMALL, |
| 667 | pages_to_mb(highmem_pages)); |
| 668 | highmem_pages = 0; |
| 669 | } |
| 670 | max_low_pfn -= highmem_pages; |
| 671 | } |
| 672 | #else |
| 673 | if (highmem_pages) |
| 674 | printk(KERN_ERR "ignoring highmem size on non-highmem kernel!\n"); |
| 675 | #endif |
| 676 | } |
| 677 | |
| 678 | #define MSG_HIGHMEM_TOO_SMALL \ |
| 679 | "only %luMB highmem pages available, ignoring highmem size of %luMB!\n" |
| 680 | |
| 681 | #define MSG_HIGHMEM_TRIMMED \ |
| 682 | "Warning: only 4GB will be used. Use a HIGHMEM64G enabled kernel!\n" |
| 683 | /* |
| 684 | * We have more RAM than fits into lowmem - we try to put it into |
| 685 | * highmem, also taking the highmem=x boot parameter into account: |
| 686 | */ |
| 687 | void __init highmem_pfn_init(void) |
| 688 | { |
Ingo Molnar | d88316c2 | 2009-02-12 15:16:03 +0100 | [diff] [blame] | 689 | max_low_pfn = MAXMEM_PFN; |
| 690 | |
Ingo Molnar | 4769843 | 2009-02-12 13:31:41 +0100 | [diff] [blame] | 691 | if (highmem_pages == -1) |
| 692 | highmem_pages = max_pfn - MAXMEM_PFN; |
| 693 | |
| 694 | if (highmem_pages + MAXMEM_PFN < max_pfn) |
| 695 | max_pfn = MAXMEM_PFN + highmem_pages; |
| 696 | |
| 697 | if (highmem_pages + MAXMEM_PFN > max_pfn) { |
| 698 | printk(KERN_WARNING MSG_HIGHMEM_TOO_SMALL, |
| 699 | pages_to_mb(max_pfn - MAXMEM_PFN), |
| 700 | pages_to_mb(highmem_pages)); |
| 701 | highmem_pages = 0; |
| 702 | } |
Ingo Molnar | 4769843 | 2009-02-12 13:31:41 +0100 | [diff] [blame] | 703 | #ifndef CONFIG_HIGHMEM |
| 704 | /* Maximum memory usable is what is directly addressable */ |
| 705 | printk(KERN_WARNING "Warning only %ldMB will be used.\n", MAXMEM>>20); |
| 706 | if (max_pfn > MAX_NONPAE_PFN) |
| 707 | printk(KERN_WARNING "Use a HIGHMEM64G enabled kernel.\n"); |
| 708 | else |
| 709 | printk(KERN_WARNING "Use a HIGHMEM enabled kernel.\n"); |
| 710 | max_pfn = MAXMEM_PFN; |
| 711 | #else /* !CONFIG_HIGHMEM */ |
| 712 | #ifndef CONFIG_HIGHMEM64G |
| 713 | if (max_pfn > MAX_NONPAE_PFN) { |
| 714 | max_pfn = MAX_NONPAE_PFN; |
| 715 | printk(KERN_WARNING MSG_HIGHMEM_TRIMMED); |
| 716 | } |
| 717 | #endif /* !CONFIG_HIGHMEM64G */ |
| 718 | #endif /* !CONFIG_HIGHMEM */ |
| 719 | } |
| 720 | |
Yinghai Lu | 90d967e | 2008-06-23 21:00:45 +0200 | [diff] [blame] | 721 | /* |
| 722 | * Determine low and high memory ranges: |
| 723 | */ |
Yinghai Lu | 2ec65f8 | 2008-06-23 03:05:30 -0700 | [diff] [blame] | 724 | void __init find_low_pfn_range(void) |
Yinghai Lu | 90d967e | 2008-06-23 21:00:45 +0200 | [diff] [blame] | 725 | { |
Yinghai Lu | 2ec65f8 | 2008-06-23 03:05:30 -0700 | [diff] [blame] | 726 | /* it could update max_pfn */ |
| 727 | |
Ingo Molnar | d88316c2 | 2009-02-12 15:16:03 +0100 | [diff] [blame] | 728 | if (max_pfn <= MAXMEM_PFN) |
Ingo Molnar | 4769843 | 2009-02-12 13:31:41 +0100 | [diff] [blame] | 729 | lowmem_pfn_init(); |
Ingo Molnar | d88316c2 | 2009-02-12 15:16:03 +0100 | [diff] [blame] | 730 | else |
| 731 | highmem_pfn_init(); |
Yinghai Lu | 90d967e | 2008-06-23 21:00:45 +0200 | [diff] [blame] | 732 | } |
| 733 | |
Yinghai Lu | b2ac82a | 2008-06-22 02:45:39 -0700 | [diff] [blame] | 734 | #ifndef CONFIG_NEED_MULTIPLE_NODES |
Yinghai Lu | 2ec65f8 | 2008-06-23 03:05:30 -0700 | [diff] [blame] | 735 | void __init initmem_init(unsigned long start_pfn, |
Yinghai Lu | b2ac82a | 2008-06-22 02:45:39 -0700 | [diff] [blame] | 736 | unsigned long end_pfn) |
| 737 | { |
Yinghai Lu | b2ac82a | 2008-06-22 02:45:39 -0700 | [diff] [blame] | 738 | #ifdef CONFIG_HIGHMEM |
| 739 | highstart_pfn = highend_pfn = max_pfn; |
| 740 | if (max_pfn > max_low_pfn) |
| 741 | highstart_pfn = max_low_pfn; |
| 742 | memory_present(0, 0, highend_pfn); |
Yinghai Lu | cb95a13 | 2008-07-02 00:31:02 -0700 | [diff] [blame] | 743 | e820_register_active_regions(0, 0, highend_pfn); |
Yinghai Lu | b2ac82a | 2008-06-22 02:45:39 -0700 | [diff] [blame] | 744 | printk(KERN_NOTICE "%ldMB HIGHMEM available.\n", |
| 745 | pages_to_mb(highend_pfn - highstart_pfn)); |
| 746 | num_physpages = highend_pfn; |
| 747 | high_memory = (void *) __va(highstart_pfn * PAGE_SIZE - 1) + 1; |
| 748 | #else |
| 749 | memory_present(0, 0, max_low_pfn); |
Yinghai Lu | cb95a13 | 2008-07-02 00:31:02 -0700 | [diff] [blame] | 750 | e820_register_active_regions(0, 0, max_low_pfn); |
Yinghai Lu | b2ac82a | 2008-06-22 02:45:39 -0700 | [diff] [blame] | 751 | num_physpages = max_low_pfn; |
| 752 | high_memory = (void *) __va(max_low_pfn * PAGE_SIZE - 1) + 1; |
| 753 | #endif |
| 754 | #ifdef CONFIG_FLATMEM |
| 755 | max_mapnr = num_physpages; |
| 756 | #endif |
| 757 | printk(KERN_NOTICE "%ldMB LOWMEM available.\n", |
| 758 | pages_to_mb(max_low_pfn)); |
| 759 | |
| 760 | setup_bootmem_allocator(); |
Yinghai Lu | b2ac82a | 2008-06-22 02:45:39 -0700 | [diff] [blame] | 761 | } |
Yinghai Lu | cb95a13 | 2008-07-02 00:31:02 -0700 | [diff] [blame] | 762 | #endif /* !CONFIG_NEED_MULTIPLE_NODES */ |
Yinghai Lu | b2ac82a | 2008-06-22 02:45:39 -0700 | [diff] [blame] | 763 | |
Yinghai Lu | cb95a13 | 2008-07-02 00:31:02 -0700 | [diff] [blame] | 764 | static void __init zone_sizes_init(void) |
Yinghai Lu | b2ac82a | 2008-06-22 02:45:39 -0700 | [diff] [blame] | 765 | { |
| 766 | unsigned long max_zone_pfns[MAX_NR_ZONES]; |
| 767 | memset(max_zone_pfns, 0, sizeof(max_zone_pfns)); |
| 768 | max_zone_pfns[ZONE_DMA] = |
| 769 | virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT; |
| 770 | max_zone_pfns[ZONE_NORMAL] = max_low_pfn; |
Yinghai Lu | b2ac82a | 2008-06-22 02:45:39 -0700 | [diff] [blame] | 771 | #ifdef CONFIG_HIGHMEM |
| 772 | max_zone_pfns[ZONE_HIGHMEM] = highend_pfn; |
Yinghai Lu | b2ac82a | 2008-06-22 02:45:39 -0700 | [diff] [blame] | 773 | #endif |
| 774 | |
| 775 | free_area_init_nodes(max_zone_pfns); |
| 776 | } |
Yinghai Lu | b2ac82a | 2008-06-22 02:45:39 -0700 | [diff] [blame] | 777 | |
Yinghai Lu | a71edd1 | 2009-03-04 01:22:35 -0800 | [diff] [blame] | 778 | static unsigned long __init setup_node_bootmem(int nodeid, |
| 779 | unsigned long start_pfn, |
| 780 | unsigned long end_pfn, |
| 781 | unsigned long bootmap) |
| 782 | { |
| 783 | unsigned long bootmap_size; |
| 784 | |
| 785 | if (start_pfn > max_low_pfn) |
| 786 | return bootmap; |
| 787 | if (end_pfn > max_low_pfn) |
| 788 | end_pfn = max_low_pfn; |
| 789 | |
| 790 | /* don't touch min_low_pfn */ |
| 791 | bootmap_size = init_bootmem_node(NODE_DATA(nodeid), |
| 792 | bootmap >> PAGE_SHIFT, |
| 793 | start_pfn, end_pfn); |
| 794 | printk(KERN_INFO " node %d low ram: %08lx - %08lx\n", |
| 795 | nodeid, start_pfn<<PAGE_SHIFT, end_pfn<<PAGE_SHIFT); |
| 796 | printk(KERN_INFO " node %d bootmap %08lx - %08lx\n", |
| 797 | nodeid, bootmap, bootmap + bootmap_size); |
| 798 | free_bootmem_with_active_regions(nodeid, end_pfn); |
| 799 | early_res_to_bootmem(start_pfn<<PAGE_SHIFT, end_pfn<<PAGE_SHIFT); |
| 800 | |
| 801 | return bootmap + bootmap_size; |
| 802 | } |
Yinghai Lu | a71edd1 | 2009-03-04 01:22:35 -0800 | [diff] [blame] | 803 | |
Yinghai Lu | b2ac82a | 2008-06-22 02:45:39 -0700 | [diff] [blame] | 804 | void __init setup_bootmem_allocator(void) |
| 805 | { |
Yinghai Lu | a71edd1 | 2009-03-04 01:22:35 -0800 | [diff] [blame] | 806 | int nodeid; |
Yinghai Lu | b2ac82a | 2008-06-22 02:45:39 -0700 | [diff] [blame] | 807 | unsigned long bootmap_size, bootmap; |
| 808 | /* |
| 809 | * Initialize the boot-time allocator (with low memory only): |
| 810 | */ |
| 811 | bootmap_size = bootmem_bootmap_pages(max_low_pfn)<<PAGE_SHIFT; |
Yinghai Lu | fc5efe3 | 2009-03-04 12:21:24 -0800 | [diff] [blame] | 812 | bootmap = find_e820_area(0, max_pfn_mapped<<PAGE_SHIFT, bootmap_size, |
Yinghai Lu | b2ac82a | 2008-06-22 02:45:39 -0700 | [diff] [blame] | 813 | PAGE_SIZE); |
| 814 | if (bootmap == -1L) |
| 815 | panic("Cannot find bootmem map of size %ld\n", bootmap_size); |
| 816 | reserve_early(bootmap, bootmap + bootmap_size, "BOOTMAP"); |
Yinghai Lu | 225c37d | 2008-06-22 02:46:58 -0700 | [diff] [blame] | 817 | |
Yinghai Lu | b2ac82a | 2008-06-22 02:45:39 -0700 | [diff] [blame] | 818 | printk(KERN_INFO " mapped low ram: 0 - %08lx\n", |
| 819 | max_pfn_mapped<<PAGE_SHIFT); |
Yinghai Lu | fc5efe3 | 2009-03-04 12:21:24 -0800 | [diff] [blame] | 820 | printk(KERN_INFO " low ram: 0 - %08lx\n", max_low_pfn<<PAGE_SHIFT); |
Yinghai Lu | a71edd1 | 2009-03-04 01:22:35 -0800 | [diff] [blame] | 821 | |
| 822 | #ifdef CONFIG_NEED_MULTIPLE_NODES |
| 823 | for_each_online_node(nodeid) |
| 824 | bootmap = setup_node_bootmem(nodeid, node_start_pfn[nodeid], |
| 825 | node_end_pfn[nodeid], bootmap); |
| 826 | #else |
Yinghai Lu | fc5efe3 | 2009-03-04 12:21:24 -0800 | [diff] [blame] | 827 | bootmap = setup_node_bootmem(0, 0, max_low_pfn, bootmap); |
Yinghai Lu | a71edd1 | 2009-03-04 01:22:35 -0800 | [diff] [blame] | 828 | #endif |
Yinghai Lu | b2ac82a | 2008-06-22 02:45:39 -0700 | [diff] [blame] | 829 | |
Pekka Enberg | c464573 | 2009-03-05 14:54:58 +0200 | [diff] [blame] | 830 | after_bootmem = 1; |
Yinghai Lu | b2ac82a | 2008-06-22 02:45:39 -0700 | [diff] [blame] | 831 | } |
| 832 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | /* |
| 834 | * paging_init() sets up the page tables - note that the first 8MB are |
| 835 | * already mapped by head.S. |
| 836 | * |
| 837 | * This routines also unmaps the page at virtual kernel address 0, so |
| 838 | * that we can trap those pesky NULL-reference errors in the kernel. |
| 839 | */ |
| 840 | void __init paging_init(void) |
| 841 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | pagetable_init(); |
| 843 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | __flush_tlb_all(); |
| 845 | |
| 846 | kmap_init(); |
Yinghai Lu | 11cd0bc | 2008-06-23 19:51:10 -0700 | [diff] [blame] | 847 | |
| 848 | /* |
| 849 | * NOTE: at this point the bootmem allocator is fully available. |
| 850 | */ |
Yinghai Lu | 11cd0bc | 2008-06-23 19:51:10 -0700 | [diff] [blame] | 851 | sparse_init(); |
| 852 | zone_sizes_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | /* |
| 856 | * Test if the WP bit works in supervisor mode. It isn't supported on 386's |
Dmitri Vorobiev | f7f17a6 | 2008-04-21 00:47:55 +0400 | [diff] [blame] | 857 | * and also on some strange 486's. All 586+'s are OK. This used to involve |
| 858 | * black magic jumps to work around some nasty CPU bugs, but fortunately the |
| 859 | * switch to using exceptions got rid of all that. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | static void __init test_wp_bit(void) |
| 862 | { |
Ingo Molnar | d7d119d | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 863 | printk(KERN_INFO |
| 864 | "Checking if this processor honours the WP bit even in supervisor mode..."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
| 866 | /* Any page-aligned address will do, the test is non-destructive */ |
| 867 | __set_fixmap(FIX_WP_TEST, __pa(&swapper_pg_dir), PAGE_READONLY); |
| 868 | boot_cpu_data.wp_works_ok = do_test_wp_bit(); |
| 869 | clear_fixmap(FIX_WP_TEST); |
| 870 | |
| 871 | if (!boot_cpu_data.wp_works_ok) { |
Ingo Molnar | d7d119d | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 872 | printk(KERN_CONT "No.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | #ifdef CONFIG_X86_WP_WORKS_OK |
Ingo Molnar | d7d119d | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 874 | panic( |
| 875 | "This kernel doesn't support CPU's with broken WP. Recompile it for a 386!"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | #endif |
| 877 | } else { |
Ingo Molnar | d7d119d | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 878 | printk(KERN_CONT "Ok.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | } |
| 880 | } |
| 881 | |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 882 | static struct kcore_list kcore_mem, kcore_vmalloc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | |
| 884 | void __init mem_init(void) |
| 885 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | int codesize, reservedpages, datasize, initsize; |
Yinghai Lu | cc9f7a0 | 2008-06-16 16:11:08 -0700 | [diff] [blame] | 887 | int tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | |
Jeremy Fitzhardinge | cfb80c9 | 2008-12-16 12:17:36 -0800 | [diff] [blame] | 889 | pci_iommu_alloc(); |
| 890 | |
Andy Whitcroft | 05b79bd | 2005-06-23 00:07:57 -0700 | [diff] [blame] | 891 | #ifdef CONFIG_FLATMEM |
Eric Sesterhenn | 8d8f3cb | 2006-10-03 23:34:58 +0200 | [diff] [blame] | 892 | BUG_ON(!mem_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | /* this will put all low memory onto the freelists */ |
| 895 | totalram_pages += free_all_bootmem(); |
| 896 | |
| 897 | reservedpages = 0; |
| 898 | for (tmp = 0; tmp < max_low_pfn; tmp++) |
| 899 | /* |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 900 | * Only count reserved RAM pages: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | */ |
| 902 | if (page_is_ram(tmp) && PageReserved(pfn_to_page(tmp))) |
| 903 | reservedpages++; |
| 904 | |
Yinghai Lu | cc9f7a0 | 2008-06-16 16:11:08 -0700 | [diff] [blame] | 905 | set_highmem_pages_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | |
| 907 | codesize = (unsigned long) &_etext - (unsigned long) &_text; |
| 908 | datasize = (unsigned long) &_edata - (unsigned long) &_etext; |
| 909 | initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin; |
| 910 | |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 911 | kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT); |
| 912 | kclist_add(&kcore_vmalloc, (void *)VMALLOC_START, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | VMALLOC_END-VMALLOC_START); |
| 914 | |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 915 | printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, " |
| 916 | "%dk reserved, %dk data, %dk init, %ldk highmem)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | (unsigned long) nr_free_pages() << (PAGE_SHIFT-10), |
| 918 | num_physpages << (PAGE_SHIFT-10), |
| 919 | codesize >> 10, |
| 920 | reservedpages << (PAGE_SHIFT-10), |
| 921 | datasize >> 10, |
| 922 | initsize >> 10, |
| 923 | (unsigned long) (totalhigh_pages << (PAGE_SHIFT-10)) |
| 924 | ); |
| 925 | |
Ingo Molnar | d7d119d | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 926 | printk(KERN_INFO "virtual kernel memory layout:\n" |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 927 | " fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n" |
Jeremy Fitzhardinge | 052e799 | 2006-09-25 23:32:25 -0700 | [diff] [blame] | 928 | #ifdef CONFIG_HIGHMEM |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 929 | " pkmap : 0x%08lx - 0x%08lx (%4ld kB)\n" |
Jeremy Fitzhardinge | 052e799 | 2006-09-25 23:32:25 -0700 | [diff] [blame] | 930 | #endif |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 931 | " vmalloc : 0x%08lx - 0x%08lx (%4ld MB)\n" |
| 932 | " lowmem : 0x%08lx - 0x%08lx (%4ld MB)\n" |
| 933 | " .init : 0x%08lx - 0x%08lx (%4ld kB)\n" |
| 934 | " .data : 0x%08lx - 0x%08lx (%4ld kB)\n" |
| 935 | " .text : 0x%08lx - 0x%08lx (%4ld kB)\n", |
| 936 | FIXADDR_START, FIXADDR_TOP, |
| 937 | (FIXADDR_TOP - FIXADDR_START) >> 10, |
Jeremy Fitzhardinge | 052e799 | 2006-09-25 23:32:25 -0700 | [diff] [blame] | 938 | |
| 939 | #ifdef CONFIG_HIGHMEM |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 940 | PKMAP_BASE, PKMAP_BASE+LAST_PKMAP*PAGE_SIZE, |
| 941 | (LAST_PKMAP*PAGE_SIZE) >> 10, |
Jeremy Fitzhardinge | 052e799 | 2006-09-25 23:32:25 -0700 | [diff] [blame] | 942 | #endif |
| 943 | |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 944 | VMALLOC_START, VMALLOC_END, |
| 945 | (VMALLOC_END - VMALLOC_START) >> 20, |
Jeremy Fitzhardinge | 052e799 | 2006-09-25 23:32:25 -0700 | [diff] [blame] | 946 | |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 947 | (unsigned long)__va(0), (unsigned long)high_memory, |
| 948 | ((unsigned long)high_memory - (unsigned long)__va(0)) >> 20, |
Jeremy Fitzhardinge | 052e799 | 2006-09-25 23:32:25 -0700 | [diff] [blame] | 949 | |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 950 | (unsigned long)&__init_begin, (unsigned long)&__init_end, |
| 951 | ((unsigned long)&__init_end - |
| 952 | (unsigned long)&__init_begin) >> 10, |
Jeremy Fitzhardinge | 052e799 | 2006-09-25 23:32:25 -0700 | [diff] [blame] | 953 | |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 954 | (unsigned long)&_etext, (unsigned long)&_edata, |
| 955 | ((unsigned long)&_edata - (unsigned long)&_etext) >> 10, |
Jeremy Fitzhardinge | 052e799 | 2006-09-25 23:32:25 -0700 | [diff] [blame] | 956 | |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 957 | (unsigned long)&_text, (unsigned long)&_etext, |
| 958 | ((unsigned long)&_etext - (unsigned long)&_text) >> 10); |
Jeremy Fitzhardinge | 052e799 | 2006-09-25 23:32:25 -0700 | [diff] [blame] | 959 | |
Jan Beulich | beeb419 | 2008-12-16 11:45:56 +0000 | [diff] [blame] | 960 | /* |
| 961 | * Check boundaries twice: Some fundamental inconsistencies can |
| 962 | * be detected at build time already. |
| 963 | */ |
| 964 | #define __FIXADDR_TOP (-PAGE_SIZE) |
| 965 | #ifdef CONFIG_HIGHMEM |
| 966 | BUILD_BUG_ON(PKMAP_BASE + LAST_PKMAP*PAGE_SIZE > FIXADDR_START); |
| 967 | BUILD_BUG_ON(VMALLOC_END > PKMAP_BASE); |
| 968 | #endif |
| 969 | #define high_memory (-128UL << 20) |
| 970 | BUILD_BUG_ON(VMALLOC_START >= VMALLOC_END); |
| 971 | #undef high_memory |
| 972 | #undef __FIXADDR_TOP |
| 973 | |
Jeremy Fitzhardinge | 052e799 | 2006-09-25 23:32:25 -0700 | [diff] [blame] | 974 | #ifdef CONFIG_HIGHMEM |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 975 | BUG_ON(PKMAP_BASE + LAST_PKMAP*PAGE_SIZE > FIXADDR_START); |
| 976 | BUG_ON(VMALLOC_END > PKMAP_BASE); |
Jeremy Fitzhardinge | 052e799 | 2006-09-25 23:32:25 -0700 | [diff] [blame] | 977 | #endif |
Jan Beulich | beeb419 | 2008-12-16 11:45:56 +0000 | [diff] [blame] | 978 | BUG_ON(VMALLOC_START >= VMALLOC_END); |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 979 | BUG_ON((unsigned long)high_memory > VMALLOC_START); |
Jeremy Fitzhardinge | 052e799 | 2006-09-25 23:32:25 -0700 | [diff] [blame] | 980 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | if (boot_cpu_data.wp_works_ok < 0) |
| 982 | test_wp_bit(); |
| 983 | |
Hugh Dickins | 61165d7 | 2008-05-13 14:26:57 +0100 | [diff] [blame] | 984 | save_pg_dir(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | zap_low_mappings(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | } |
| 987 | |
KAMEZAWA Hiroyuki | ad8f579 | 2006-05-20 15:00:03 -0700 | [diff] [blame] | 988 | #ifdef CONFIG_MEMORY_HOTPLUG |
Yasunori Goto | bc02af9 | 2006-06-27 02:53:30 -0700 | [diff] [blame] | 989 | int arch_add_memory(int nid, u64 start, u64 size) |
Dave Hansen | 05039b9 | 2005-10-29 18:16:57 -0700 | [diff] [blame] | 990 | { |
Yasunori Goto | 7c7e942 | 2006-12-22 01:11:13 -0800 | [diff] [blame] | 991 | struct pglist_data *pgdata = NODE_DATA(nid); |
Christoph Lameter | 776ed98 | 2006-09-25 23:31:09 -0700 | [diff] [blame] | 992 | struct zone *zone = pgdata->node_zones + ZONE_HIGHMEM; |
Dave Hansen | 05039b9 | 2005-10-29 18:16:57 -0700 | [diff] [blame] | 993 | unsigned long start_pfn = start >> PAGE_SHIFT; |
| 994 | unsigned long nr_pages = size >> PAGE_SHIFT; |
| 995 | |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 996 | return __add_pages(nid, zone, start_pfn, nr_pages); |
Dave Hansen | 05039b9 | 2005-10-29 18:16:57 -0700 | [diff] [blame] | 997 | } |
Andi Kleen | 9d99aaa | 2006-04-07 19:49:15 +0200 | [diff] [blame] | 998 | #endif |
Dave Hansen | 05039b9 | 2005-10-29 18:16:57 -0700 | [diff] [blame] | 999 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | /* |
| 1001 | * This function cannot be __init, since exceptions don't work in that |
| 1002 | * section. Put this after the callers, so that it cannot be inlined. |
| 1003 | */ |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1004 | static noinline int do_test_wp_bit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | { |
| 1006 | char tmp_reg; |
| 1007 | int flag; |
| 1008 | |
| 1009 | __asm__ __volatile__( |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1010 | " movb %0, %1 \n" |
| 1011 | "1: movb %1, %0 \n" |
| 1012 | " xorl %2, %2 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | "2: \n" |
H. Peter Anvin | f832ff1 | 2008-02-04 16:47:58 +0100 | [diff] [blame] | 1014 | _ASM_EXTABLE(1b,2b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | :"=m" (*(char *)fix_to_virt(FIX_WP_TEST)), |
| 1016 | "=q" (tmp_reg), |
| 1017 | "=r" (flag) |
| 1018 | :"2" (1) |
| 1019 | :"memory"); |
Ingo Molnar | 8550eb9 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1020 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | return flag; |
| 1022 | } |
| 1023 | |
Arjan van de Ven | 63aaf30 | 2006-01-06 00:12:02 -0800 | [diff] [blame] | 1024 | #ifdef CONFIG_DEBUG_RODATA |
Arjan van de Ven | edeed30 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 1025 | const int rodata_test_data = 0xC3; |
| 1026 | EXPORT_SYMBOL_GPL(rodata_test_data); |
Arjan van de Ven | 63aaf30 | 2006-01-06 00:12:02 -0800 | [diff] [blame] | 1027 | |
Arjan van de Ven | 63aaf30 | 2006-01-06 00:12:02 -0800 | [diff] [blame] | 1028 | void mark_rodata_ro(void) |
| 1029 | { |
Jan Beulich | 6fb1475 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 1030 | unsigned long start = PFN_ALIGN(_text); |
| 1031 | unsigned long size = PFN_ALIGN(_etext) - start; |
Arjan van de Ven | 63aaf30 | 2006-01-06 00:12:02 -0800 | [diff] [blame] | 1032 | |
Steven Rostedt | 8f0f996 | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 1033 | #ifndef CONFIG_DYNAMIC_FTRACE |
| 1034 | /* Dynamic tracing modifies the kernel text section */ |
Mathieu Desnoyers | 4e4eee0 | 2008-02-02 15:42:20 -0500 | [diff] [blame] | 1035 | set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT); |
| 1036 | printk(KERN_INFO "Write protecting the kernel text: %luk\n", |
| 1037 | size >> 10); |
Andi Kleen | 0c42f39 | 2008-01-30 13:33:42 +0100 | [diff] [blame] | 1038 | |
| 1039 | #ifdef CONFIG_CPA_DEBUG |
Mathieu Desnoyers | 4e4eee0 | 2008-02-02 15:42:20 -0500 | [diff] [blame] | 1040 | printk(KERN_INFO "Testing CPA: Reverting %lx-%lx\n", |
| 1041 | start, start+size); |
| 1042 | set_pages_rw(virt_to_page(start), size>>PAGE_SHIFT); |
Andi Kleen | 0c42f39 | 2008-01-30 13:33:42 +0100 | [diff] [blame] | 1043 | |
Mathieu Desnoyers | 4e4eee0 | 2008-02-02 15:42:20 -0500 | [diff] [blame] | 1044 | printk(KERN_INFO "Testing CPA: write protecting again\n"); |
| 1045 | set_pages_ro(virt_to_page(start), size>>PAGE_SHIFT); |
Linus Torvalds | 602033e | 2007-07-26 12:07:21 -0700 | [diff] [blame] | 1046 | #endif |
Steven Rostedt | 8f0f996 | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 1047 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
| 1048 | |
Jan Beulich | 6fb1475 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 1049 | start += size; |
| 1050 | size = (unsigned long)__end_rodata - start; |
Arjan van de Ven | 6d238cc | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 1051 | set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT); |
Ingo Molnar | d7d119d | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1052 | printk(KERN_INFO "Write protecting the kernel read-only data: %luk\n", |
| 1053 | size >> 10); |
Arjan van de Ven | edeed30 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 1054 | rodata_test(); |
Arjan van de Ven | 63aaf30 | 2006-01-06 00:12:02 -0800 | [diff] [blame] | 1055 | |
Andi Kleen | 0c42f39 | 2008-01-30 13:33:42 +0100 | [diff] [blame] | 1056 | #ifdef CONFIG_CPA_DEBUG |
Ingo Molnar | d7d119d | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1057 | printk(KERN_INFO "Testing CPA: undo %lx-%lx\n", start, start + size); |
Arjan van de Ven | 6d238cc | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 1058 | set_pages_rw(virt_to_page(start), size >> PAGE_SHIFT); |
Andi Kleen | 0c42f39 | 2008-01-30 13:33:42 +0100 | [diff] [blame] | 1059 | |
Ingo Molnar | d7d119d | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1060 | printk(KERN_INFO "Testing CPA: write protecting again\n"); |
Arjan van de Ven | 6d238cc | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 1061 | set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT); |
Andi Kleen | 0c42f39 | 2008-01-30 13:33:42 +0100 | [diff] [blame] | 1062 | #endif |
Arjan van de Ven | 63aaf30 | 2006-01-06 00:12:02 -0800 | [diff] [blame] | 1063 | } |
| 1064 | #endif |
| 1065 | |
Yinghai Lu | d2dbf34 | 2008-06-13 02:00:56 -0700 | [diff] [blame] | 1066 | int __init reserve_bootmem_generic(unsigned long phys, unsigned long len, |
| 1067 | int flags) |
| 1068 | { |
| 1069 | return reserve_bootmem(phys, len, flags); |
| 1070 | } |