diff options
author | Thomas Gleixner <tglx@linutronix.de> | 2008-01-30 07:34:10 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-01-30 07:34:10 -0500 |
commit | 14a62c34b134d24f7fedb8fd66028ecdcffb32c8 (patch) | |
tree | 58198c293144cfad46f8ed0cd816d8a9e3867cb2 /arch/x86 | |
parent | a3828064be4ed8e95907d3943e7af13cb709694d (diff) |
x86: unify ioremap
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'arch/x86')
-rw-r--r-- | arch/x86/mm/init_64.c | 301 |
1 files changed, 175 insertions, 126 deletions
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index 8a7b725ce3c7..bb732bb79b4a 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c | |||
@@ -47,10 +47,10 @@ | |||
47 | #include <asm/numa.h> | 47 | #include <asm/numa.h> |
48 | 48 | ||
49 | #ifndef Dprintk | 49 | #ifndef Dprintk |
50 | #define Dprintk(x...) | 50 | # define Dprintk(x...) |
51 | #endif | 51 | #endif |
52 | 52 | ||
53 | const struct dma_mapping_ops* dma_ops; | 53 | const struct dma_mapping_ops *dma_ops; |
54 | EXPORT_SYMBOL(dma_ops); | 54 | EXPORT_SYMBOL(dma_ops); |
55 | 55 | ||
56 | static unsigned long dma_reserve __initdata; | 56 | static unsigned long dma_reserve __initdata; |
@@ -67,22 +67,26 @@ void show_mem(void) | |||
67 | { | 67 | { |
68 | long i, total = 0, reserved = 0; | 68 | long i, total = 0, reserved = 0; |
69 | long shared = 0, cached = 0; | 69 | long shared = 0, cached = 0; |
70 | pg_data_t *pgdat; | ||
71 | struct page *page; | 70 | struct page *page; |
71 | pg_data_t *pgdat; | ||
72 | 72 | ||
73 | printk(KERN_INFO "Mem-info:\n"); | 73 | printk(KERN_INFO "Mem-info:\n"); |
74 | show_free_areas(); | 74 | show_free_areas(); |
75 | printk(KERN_INFO "Free swap: %6ldkB\n", nr_swap_pages<<(PAGE_SHIFT-10)); | 75 | printk(KERN_INFO "Free swap: %6ldkB\n", |
76 | nr_swap_pages << (PAGE_SHIFT-10)); | ||
76 | 77 | ||
77 | for_each_online_pgdat(pgdat) { | 78 | for_each_online_pgdat(pgdat) { |
78 | for (i = 0; i < pgdat->node_spanned_pages; ++i) { | 79 | for (i = 0; i < pgdat->node_spanned_pages; ++i) { |
79 | /* this loop can take a while with 256 GB and 4k pages | 80 | /* |
80 | so update the NMI watchdog */ | 81 | * This loop can take a while with 256 GB and |
81 | if (unlikely(i % MAX_ORDER_NR_PAGES == 0)) { | 82 | * 4k pages so defer the NMI watchdog: |
83 | */ | ||
84 | if (unlikely(i % MAX_ORDER_NR_PAGES == 0)) | ||
82 | touch_nmi_watchdog(); | 85 | touch_nmi_watchdog(); |
83 | } | 86 | |
84 | if (!pfn_valid(pgdat->node_start_pfn + i)) | 87 | if (!pfn_valid(pgdat->node_start_pfn + i)) |
85 | continue; | 88 | continue; |
89 | |||
86 | page = pfn_to_page(pgdat->node_start_pfn + i); | 90 | page = pfn_to_page(pgdat->node_start_pfn + i); |
87 | total++; | 91 | total++; |
88 | if (PageReserved(page)) | 92 | if (PageReserved(page)) |
@@ -91,32 +95,37 @@ void show_mem(void) | |||
91 | cached++; | 95 | cached++; |
92 | else if (page_count(page)) | 96 | else if (page_count(page)) |
93 | shared += page_count(page) - 1; | 97 | shared += page_count(page) - 1; |
94 | } | 98 | } |
95 | } | 99 | } |
96 | printk(KERN_INFO "%lu pages of RAM\n", total); | 100 | printk(KERN_INFO "%lu pages of RAM\n", total); |
97 | printk(KERN_INFO "%lu reserved pages\n",reserved); | 101 | printk(KERN_INFO "%lu reserved pages\n", reserved); |
98 | printk(KERN_INFO "%lu pages shared\n",shared); | 102 | printk(KERN_INFO "%lu pages shared\n", shared); |
99 | printk(KERN_INFO "%lu pages swap cached\n",cached); | 103 | printk(KERN_INFO "%lu pages swap cached\n", cached); |
100 | } | 104 | } |
101 | 105 | ||
102 | int after_bootmem; | 106 | int after_bootmem; |
103 | 107 | ||
104 | static __init void *spp_getpage(void) | 108 | static __init void *spp_getpage(void) |
105 | { | 109 | { |
106 | void *ptr; | 110 | void *ptr; |
111 | |||
107 | if (after_bootmem) | 112 | if (after_bootmem) |
108 | ptr = (void *) get_zeroed_page(GFP_ATOMIC); | 113 | ptr = (void *) get_zeroed_page(GFP_ATOMIC); |
109 | else | 114 | else |
110 | ptr = alloc_bootmem_pages(PAGE_SIZE); | 115 | ptr = alloc_bootmem_pages(PAGE_SIZE); |
111 | if (!ptr || ((unsigned long)ptr & ~PAGE_MASK)) | 116 | |
112 | panic("set_pte_phys: cannot allocate page data %s\n", after_bootmem?"after bootmem":""); | 117 | if (!ptr || ((unsigned long)ptr & ~PAGE_MASK)) { |
118 | panic("set_pte_phys: cannot allocate page data %s\n", | ||
119 | after_bootmem ? "after bootmem" : ""); | ||
120 | } | ||
113 | 121 | ||
114 | Dprintk("spp_getpage %p\n", ptr); | 122 | Dprintk("spp_getpage %p\n", ptr); |
123 | |||
115 | return ptr; | 124 | return ptr; |
116 | } | 125 | } |
117 | 126 | ||
118 | static __init void set_pte_phys(unsigned long vaddr, | 127 | static __init void |
119 | unsigned long phys, pgprot_t prot) | 128 | set_pte_phys(unsigned long vaddr, unsigned long phys, pgprot_t prot) |
120 | { | 129 | { |
121 | pgd_t *pgd; | 130 | pgd_t *pgd; |
122 | pud_t *pud; | 131 | pud_t *pud; |
@@ -132,10 +141,11 @@ static __init void set_pte_phys(unsigned long vaddr, | |||
132 | } | 141 | } |
133 | pud = pud_offset(pgd, vaddr); | 142 | pud = pud_offset(pgd, vaddr); |
134 | if (pud_none(*pud)) { | 143 | if (pud_none(*pud)) { |
135 | pmd = (pmd_t *) spp_getpage(); | 144 | pmd = (pmd_t *) spp_getpage(); |
136 | set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE | _PAGE_USER)); | 145 | set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE | _PAGE_USER)); |
137 | if (pmd != pmd_offset(pud, 0)) { | 146 | if (pmd != pmd_offset(pud, 0)) { |
138 | printk("PAGETABLE BUG #01! %p <-> %p\n", pmd, pmd_offset(pud,0)); | 147 | printk("PAGETABLE BUG #01! %p <-> %p\n", |
148 | pmd, pmd_offset(pud, 0)); | ||
139 | return; | 149 | return; |
140 | } | 150 | } |
141 | } | 151 | } |
@@ -164,8 +174,8 @@ static __init void set_pte_phys(unsigned long vaddr, | |||
164 | } | 174 | } |
165 | 175 | ||
166 | /* NOTE: this is meant to be run only at boot */ | 176 | /* NOTE: this is meant to be run only at boot */ |
167 | void __init | 177 | void __init |
168 | __set_fixmap (enum fixed_addresses idx, unsigned long phys, pgprot_t prot) | 178 | __set_fixmap(enum fixed_addresses idx, unsigned long phys, pgprot_t prot) |
169 | { | 179 | { |
170 | unsigned long address = __fix_to_virt(idx); | 180 | unsigned long address = __fix_to_virt(idx); |
171 | 181 | ||
@@ -180,18 +190,19 @@ static unsigned long __initdata table_start; | |||
180 | static unsigned long __meminitdata table_end; | 190 | static unsigned long __meminitdata table_end; |
181 | 191 | ||
182 | static __meminit void *alloc_low_page(unsigned long *phys) | 192 | static __meminit void *alloc_low_page(unsigned long *phys) |
183 | { | 193 | { |
184 | unsigned long pfn = table_end++; | 194 | unsigned long pfn = table_end++; |
185 | void *adr; | 195 | void *adr; |
186 | 196 | ||
187 | if (after_bootmem) { | 197 | if (after_bootmem) { |
188 | adr = (void *)get_zeroed_page(GFP_ATOMIC); | 198 | adr = (void *)get_zeroed_page(GFP_ATOMIC); |
189 | *phys = __pa(adr); | 199 | *phys = __pa(adr); |
200 | |||
190 | return adr; | 201 | return adr; |
191 | } | 202 | } |
192 | 203 | ||
193 | if (pfn >= end_pfn) | 204 | if (pfn >= end_pfn) |
194 | panic("alloc_low_page: ran out of memory"); | 205 | panic("alloc_low_page: ran out of memory"); |
195 | 206 | ||
196 | adr = early_ioremap(pfn * PAGE_SIZE, PAGE_SIZE); | 207 | adr = early_ioremap(pfn * PAGE_SIZE, PAGE_SIZE); |
197 | memset(adr, 0, PAGE_SIZE); | 208 | memset(adr, 0, PAGE_SIZE); |
@@ -200,44 +211,49 @@ static __meminit void *alloc_low_page(unsigned long *phys) | |||
200 | } | 211 | } |
201 | 212 | ||
202 | static __meminit void unmap_low_page(void *adr) | 213 | static __meminit void unmap_low_page(void *adr) |
203 | { | 214 | { |
204 | |||
205 | if (after_bootmem) | 215 | if (after_bootmem) |
206 | return; | 216 | return; |
207 | 217 | ||
208 | early_iounmap(adr, PAGE_SIZE); | 218 | early_iounmap(adr, PAGE_SIZE); |
209 | } | 219 | } |
210 | 220 | ||
211 | /* Must run before zap_low_mappings */ | 221 | /* Must run before zap_low_mappings */ |
212 | __meminit void *early_ioremap(unsigned long addr, unsigned long size) | 222 | __meminit void *early_ioremap(unsigned long addr, unsigned long size) |
213 | { | 223 | { |
214 | unsigned long vaddr; | ||
215 | pmd_t *pmd, *last_pmd; | 224 | pmd_t *pmd, *last_pmd; |
225 | unsigned long vaddr; | ||
216 | int i, pmds; | 226 | int i, pmds; |
217 | 227 | ||
218 | pmds = ((addr & ~PMD_MASK) + size + ~PMD_MASK) / PMD_SIZE; | 228 | pmds = ((addr & ~PMD_MASK) + size + ~PMD_MASK) / PMD_SIZE; |
219 | vaddr = __START_KERNEL_map; | 229 | vaddr = __START_KERNEL_map; |
220 | pmd = level2_kernel_pgt; | 230 | pmd = level2_kernel_pgt; |
221 | last_pmd = level2_kernel_pgt + PTRS_PER_PMD - 1; | 231 | last_pmd = level2_kernel_pgt + PTRS_PER_PMD - 1; |
232 | |||
222 | for (; pmd <= last_pmd; pmd++, vaddr += PMD_SIZE) { | 233 | for (; pmd <= last_pmd; pmd++, vaddr += PMD_SIZE) { |
223 | for (i = 0; i < pmds; i++) { | 234 | for (i = 0; i < pmds; i++) { |
224 | if (pmd_present(pmd[i])) | 235 | if (pmd_present(pmd[i])) |
225 | goto next; | 236 | goto continue_outer_loop; |
226 | } | 237 | } |
227 | vaddr += addr & ~PMD_MASK; | 238 | vaddr += addr & ~PMD_MASK; |
228 | addr &= PMD_MASK; | 239 | addr &= PMD_MASK; |
240 | |||
229 | for (i = 0; i < pmds; i++, addr += PMD_SIZE) | 241 | for (i = 0; i < pmds; i++, addr += PMD_SIZE) |
230 | set_pmd(pmd+i, __pmd(addr | __PAGE_KERNEL_LARGE_EXEC)); | 242 | set_pmd(pmd+i, __pmd(addr | __PAGE_KERNEL_LARGE_EXEC)); |
231 | __flush_tlb_all(); | 243 | __flush_tlb_all(); |
244 | |||
232 | return (void *)vaddr; | 245 | return (void *)vaddr; |
233 | next: | 246 | continue_outer_loop: |
234 | ; | 247 | ; |
235 | } | 248 | } |
236 | printk("early_ioremap(0x%lx, %lu) failed\n", addr, size); | 249 | printk("early_ioremap(0x%lx, %lu) failed\n", addr, size); |
250 | |||
237 | return NULL; | 251 | return NULL; |
238 | } | 252 | } |
239 | 253 | ||
240 | /* To avoid virtual aliases later */ | 254 | /* |
255 | * To avoid virtual aliases later: | ||
256 | */ | ||
241 | __meminit void early_iounmap(void *addr, unsigned long size) | 257 | __meminit void early_iounmap(void *addr, unsigned long size) |
242 | { | 258 | { |
243 | unsigned long vaddr; | 259 | unsigned long vaddr; |
@@ -247,8 +263,10 @@ __meminit void early_iounmap(void *addr, unsigned long size) | |||
247 | vaddr = (unsigned long)addr; | 263 | vaddr = (unsigned long)addr; |
248 | pmds = ((vaddr & ~PMD_MASK) + size + ~PMD_MASK) / PMD_SIZE; | 264 | pmds = ((vaddr & ~PMD_MASK) + size + ~PMD_MASK) / PMD_SIZE; |
249 | pmd = level2_kernel_pgt + pmd_index(vaddr); | 265 | pmd = level2_kernel_pgt + pmd_index(vaddr); |
266 | |||
250 | for (i = 0; i < pmds; i++) | 267 | for (i = 0; i < pmds; i++) |
251 | pmd_clear(pmd + i); | 268 | pmd_clear(pmd + i); |
269 | |||
252 | __flush_tlb_all(); | 270 | __flush_tlb_all(); |
253 | } | 271 | } |
254 | 272 | ||
@@ -262,9 +280,10 @@ phys_pmd_init(pmd_t *pmd_page, unsigned long address, unsigned long end) | |||
262 | pmd_t *pmd = pmd_page + pmd_index(address); | 280 | pmd_t *pmd = pmd_page + pmd_index(address); |
263 | 281 | ||
264 | if (address >= end) { | 282 | if (address >= end) { |
265 | if (!after_bootmem) | 283 | if (!after_bootmem) { |
266 | for (; i < PTRS_PER_PMD; i++, pmd++) | 284 | for (; i < PTRS_PER_PMD; i++, pmd++) |
267 | set_pmd(pmd, __pmd(0)); | 285 | set_pmd(pmd, __pmd(0)); |
286 | } | ||
268 | break; | 287 | break; |
269 | } | 288 | } |
270 | 289 | ||
@@ -280,19 +299,19 @@ phys_pmd_init(pmd_t *pmd_page, unsigned long address, unsigned long end) | |||
280 | static void __meminit | 299 | static void __meminit |
281 | phys_pmd_update(pud_t *pud, unsigned long address, unsigned long end) | 300 | phys_pmd_update(pud_t *pud, unsigned long address, unsigned long end) |
282 | { | 301 | { |
283 | pmd_t *pmd = pmd_offset(pud,0); | 302 | pmd_t *pmd = pmd_offset(pud, 0); |
284 | spin_lock(&init_mm.page_table_lock); | 303 | spin_lock(&init_mm.page_table_lock); |
285 | phys_pmd_init(pmd, address, end); | 304 | phys_pmd_init(pmd, address, end); |
286 | spin_unlock(&init_mm.page_table_lock); | 305 | spin_unlock(&init_mm.page_table_lock); |
287 | __flush_tlb_all(); | 306 | __flush_tlb_all(); |
288 | } | 307 | } |
289 | 308 | ||
290 | static void __meminit phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end) | 309 | static void __meminit |
291 | { | 310 | phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end) |
311 | { | ||
292 | int i = pud_index(addr); | 312 | int i = pud_index(addr); |
293 | 313 | ||
294 | 314 | for (; i < PTRS_PER_PUD; i++, addr = (addr & PUD_MASK) + PUD_SIZE) { | |
295 | for (; i < PTRS_PER_PUD; i++, addr = (addr & PUD_MASK) + PUD_SIZE ) { | ||
296 | unsigned long pmd_phys; | 315 | unsigned long pmd_phys; |
297 | pud_t *pud = pud_page + pud_index(addr); | 316 | pud_t *pud = pud_page + pud_index(addr); |
298 | pmd_t *pmd; | 317 | pmd_t *pmd; |
@@ -300,10 +319,11 @@ static void __meminit phys_pud_init(pud_t *pud_page, unsigned long addr, unsigne | |||
300 | if (addr >= end) | 319 | if (addr >= end) |
301 | break; | 320 | break; |
302 | 321 | ||
303 | if (!after_bootmem && !e820_any_mapped(addr,addr+PUD_SIZE,0)) { | 322 | if (!after_bootmem && |
304 | set_pud(pud, __pud(0)); | 323 | !e820_any_mapped(addr, addr+PUD_SIZE, 0)) { |
324 | set_pud(pud, __pud(0)); | ||
305 | continue; | 325 | continue; |
306 | } | 326 | } |
307 | 327 | ||
308 | if (pud_val(*pud)) { | 328 | if (pud_val(*pud)) { |
309 | phys_pmd_update(pud, addr, end); | 329 | phys_pmd_update(pud, addr, end); |
@@ -311,14 +331,16 @@ static void __meminit phys_pud_init(pud_t *pud_page, unsigned long addr, unsigne | |||
311 | } | 331 | } |
312 | 332 | ||
313 | pmd = alloc_low_page(&pmd_phys); | 333 | pmd = alloc_low_page(&pmd_phys); |
334 | |||
314 | spin_lock(&init_mm.page_table_lock); | 335 | spin_lock(&init_mm.page_table_lock); |
315 | set_pud(pud, __pud(pmd_phys | _KERNPG_TABLE)); | 336 | set_pud(pud, __pud(pmd_phys | _KERNPG_TABLE)); |
316 | phys_pmd_init(pmd, addr, end); | 337 | phys_pmd_init(pmd, addr, end); |
317 | spin_unlock(&init_mm.page_table_lock); | 338 | spin_unlock(&init_mm.page_table_lock); |
339 | |||
318 | unmap_low_page(pmd); | 340 | unmap_low_page(pmd); |
319 | } | 341 | } |
320 | __flush_tlb_all(); | 342 | __flush_tlb_all(); |
321 | } | 343 | } |
322 | 344 | ||
323 | static void __init find_early_table_space(unsigned long end) | 345 | static void __init find_early_table_space(unsigned long end) |
324 | { | 346 | { |
@@ -329,11 +351,13 @@ static void __init find_early_table_space(unsigned long end) | |||
329 | tables = round_up(puds * sizeof(pud_t), PAGE_SIZE) + | 351 | tables = round_up(puds * sizeof(pud_t), PAGE_SIZE) + |
330 | round_up(pmds * sizeof(pmd_t), PAGE_SIZE); | 352 | round_up(pmds * sizeof(pmd_t), PAGE_SIZE); |
331 | 353 | ||
332 | /* RED-PEN putting page tables only on node 0 could | 354 | /* |
333 | cause a hotspot and fill up ZONE_DMA. The page tables | 355 | * RED-PEN putting page tables only on node 0 could |
334 | need roughly 0.5KB per GB. */ | 356 | * cause a hotspot and fill up ZONE_DMA. The page tables |
335 | start = 0x8000; | 357 | * need roughly 0.5KB per GB. |
336 | table_start = find_e820_area(start, end, tables); | 358 | */ |
359 | start = 0x8000; | ||
360 | table_start = find_e820_area(start, end, tables); | ||
337 | if (table_start == -1UL) | 361 | if (table_start == -1UL) |
338 | panic("Cannot find space for the kernel page tables"); | 362 | panic("Cannot find space for the kernel page tables"); |
339 | 363 | ||
@@ -345,20 +369,23 @@ static void __init find_early_table_space(unsigned long end) | |||
345 | (table_start << PAGE_SHIFT) + tables); | 369 | (table_start << PAGE_SHIFT) + tables); |
346 | } | 370 | } |
347 | 371 | ||
348 | /* Setup the direct mapping of the physical memory at PAGE_OFFSET. | 372 | /* |
349 | This runs before bootmem is initialized and gets pages directly from the | 373 | * Setup the direct mapping of the physical memory at PAGE_OFFSET. |
350 | physical memory. To access them they are temporarily mapped. */ | 374 | * This runs before bootmem is initialized and gets pages directly from |
375 | * the physical memory. To access them they are temporarily mapped. | ||
376 | */ | ||
351 | void __init_refok init_memory_mapping(unsigned long start, unsigned long end) | 377 | void __init_refok init_memory_mapping(unsigned long start, unsigned long end) |
352 | { | 378 | { |
353 | unsigned long next; | 379 | unsigned long next; |
354 | 380 | ||
355 | Dprintk("init_memory_mapping\n"); | 381 | Dprintk("init_memory_mapping\n"); |
356 | 382 | ||
357 | /* | 383 | /* |
358 | * Find space for the kernel direct mapping tables. | 384 | * Find space for the kernel direct mapping tables. |
359 | * Later we should allocate these tables in the local node of the memory | 385 | * |
360 | * mapped. Unfortunately this is done currently before the nodes are | 386 | * Later we should allocate these tables in the local node of the |
361 | * discovered. | 387 | * memory mapped. Unfortunately this is done currently before the |
388 | * nodes are discovered. | ||
362 | */ | 389 | */ |
363 | if (!after_bootmem) | 390 | if (!after_bootmem) |
364 | find_early_table_space(end); | 391 | find_early_table_space(end); |
@@ -367,8 +394,8 @@ void __init_refok init_memory_mapping(unsigned long start, unsigned long end) | |||
367 | end = (unsigned long)__va(end); | 394 | end = (unsigned long)__va(end); |
368 | 395 | ||
369 | for (; start < end; start = next) { | 396 | for (; start < end; start = next) { |
370 | unsigned long pud_phys; | ||
371 | pgd_t *pgd = pgd_offset_k(start); | 397 | pgd_t *pgd = pgd_offset_k(start); |
398 | unsigned long pud_phys; | ||
372 | pud_t *pud; | 399 | pud_t *pud; |
373 | 400 | ||
374 | if (after_bootmem) | 401 | if (after_bootmem) |
@@ -377,13 +404,13 @@ void __init_refok init_memory_mapping(unsigned long start, unsigned long end) | |||
377 | pud = alloc_low_page(&pud_phys); | 404 | pud = alloc_low_page(&pud_phys); |
378 | 405 | ||
379 | next = start + PGDIR_SIZE; | 406 | next = start + PGDIR_SIZE; |
380 | if (next > end) | 407 | if (next > end) |
381 | next = end; | 408 | next = end; |
382 | phys_pud_init(pud, __pa(start), __pa(next)); | 409 | phys_pud_init(pud, __pa(start), __pa(next)); |
383 | if (!after_bootmem) | 410 | if (!after_bootmem) |
384 | set_pgd(pgd_offset_k(start), mk_kernel_pgd(pud_phys)); | 411 | set_pgd(pgd_offset_k(start), mk_kernel_pgd(pud_phys)); |
385 | unmap_low_page(pud); | 412 | unmap_low_page(pud); |
386 | } | 413 | } |
387 | 414 | ||
388 | if (!after_bootmem) | 415 | if (!after_bootmem) |
389 | mmu_cr4_features = read_cr4(); | 416 | mmu_cr4_features = read_cr4(); |
@@ -396,6 +423,7 @@ void __init_refok init_memory_mapping(unsigned long start, unsigned long end) | |||
396 | void __init paging_init(void) | 423 | void __init paging_init(void) |
397 | { | 424 | { |
398 | unsigned long max_zone_pfns[MAX_NR_ZONES]; | 425 | unsigned long max_zone_pfns[MAX_NR_ZONES]; |
426 | |||
399 | memset(max_zone_pfns, 0, sizeof(max_zone_pfns)); | 427 | memset(max_zone_pfns, 0, sizeof(max_zone_pfns)); |
400 | max_zone_pfns[ZONE_DMA] = MAX_DMA_PFN; | 428 | max_zone_pfns[ZONE_DMA] = MAX_DMA_PFN; |
401 | max_zone_pfns[ZONE_DMA32] = MAX_DMA32_PFN; | 429 | max_zone_pfns[ZONE_DMA32] = MAX_DMA32_PFN; |
@@ -407,39 +435,48 @@ void __init paging_init(void) | |||
407 | } | 435 | } |
408 | #endif | 436 | #endif |
409 | 437 | ||
410 | /* Unmap a kernel mapping if it exists. This is useful to avoid prefetches | 438 | /* |
411 | from the CPU leading to inconsistent cache lines. address and size | 439 | * Unmap a kernel mapping if it exists. This is useful to avoid |
412 | must be aligned to 2MB boundaries. | 440 | * prefetches from the CPU leading to inconsistent cache lines. |
413 | Does nothing when the mapping doesn't exist. */ | 441 | * address and size must be aligned to 2MB boundaries. |
414 | void __init clear_kernel_mapping(unsigned long address, unsigned long size) | 442 | * Does nothing when the mapping doesn't exist. |
443 | */ | ||
444 | void __init clear_kernel_mapping(unsigned long address, unsigned long size) | ||
415 | { | 445 | { |
416 | unsigned long end = address + size; | 446 | unsigned long end = address + size; |
417 | 447 | ||
418 | BUG_ON(address & ~LARGE_PAGE_MASK); | 448 | BUG_ON(address & ~LARGE_PAGE_MASK); |
419 | BUG_ON(size & ~LARGE_PAGE_MASK); | 449 | BUG_ON(size & ~LARGE_PAGE_MASK); |
420 | 450 | ||
421 | for (; address < end; address += LARGE_PAGE_SIZE) { | 451 | for (; address < end; address += LARGE_PAGE_SIZE) { |
422 | pgd_t *pgd = pgd_offset_k(address); | 452 | pgd_t *pgd = pgd_offset_k(address); |
423 | pud_t *pud; | 453 | pud_t *pud; |
424 | pmd_t *pmd; | 454 | pmd_t *pmd; |
455 | |||
425 | if (pgd_none(*pgd)) | 456 | if (pgd_none(*pgd)) |
426 | continue; | 457 | continue; |
458 | |||
427 | pud = pud_offset(pgd, address); | 459 | pud = pud_offset(pgd, address); |
428 | if (pud_none(*pud)) | 460 | if (pud_none(*pud)) |
429 | continue; | 461 | continue; |
462 | |||
430 | pmd = pmd_offset(pud, address); | 463 | pmd = pmd_offset(pud, address); |
431 | if (!pmd || pmd_none(*pmd)) | 464 | if (!pmd || pmd_none(*pmd)) |
432 | continue; | 465 | continue; |
433 | if (0 == (pmd_val(*pmd) & _PAGE_PSE)) { | 466 | |
434 | /* Could handle this, but it should not happen currently. */ | 467 | if (!(pmd_val(*pmd) & _PAGE_PSE)) { |
435 | printk(KERN_ERR | 468 | /* |
436 | "clear_kernel_mapping: mapping has been split. will leak memory\n"); | 469 | * Could handle this, but it should not happen |
437 | pmd_ERROR(*pmd); | 470 | * currently: |
471 | */ | ||
472 | printk(KERN_ERR "clear_kernel_mapping: " | ||
473 | "mapping has been split. will leak memory\n"); | ||
474 | pmd_ERROR(*pmd); | ||
438 | } | 475 | } |
439 | set_pmd(pmd, __pmd(0)); | 476 | set_pmd(pmd, __pmd(0)); |
440 | } | 477 | } |
441 | __flush_tlb_all(); | 478 | __flush_tlb_all(); |
442 | } | 479 | } |
443 | 480 | ||
444 | /* | 481 | /* |
445 | * Memory hotplug specific functions | 482 | * Memory hotplug specific functions |
@@ -466,16 +503,13 @@ int arch_add_memory(int nid, u64 start, u64 size) | |||
466 | unsigned long nr_pages = size >> PAGE_SHIFT; | 503 | unsigned long nr_pages = size >> PAGE_SHIFT; |
467 | int ret; | 504 | int ret; |
468 | 505 | ||
469 | init_memory_mapping(start, (start + size -1)); | 506 | init_memory_mapping(start, start + size-1); |
470 | 507 | ||
471 | ret = __add_pages(zone, start_pfn, nr_pages); | 508 | ret = __add_pages(zone, start_pfn, nr_pages); |
472 | if (ret) | 509 | if (ret) |
473 | goto error; | 510 | printk("%s: Problem encountered in __add_pages!\n", __func__); |
474 | 511 | ||
475 | return ret; | 512 | return ret; |
476 | error: | ||
477 | printk("%s: Problem encountered in __add_pages!\n", __func__); | ||
478 | return ret; | ||
479 | } | 513 | } |
480 | EXPORT_SYMBOL_GPL(arch_add_memory); | 514 | EXPORT_SYMBOL_GPL(arch_add_memory); |
481 | 515 | ||
@@ -489,8 +523,8 @@ EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid); | |||
489 | 523 | ||
490 | #endif /* CONFIG_MEMORY_HOTPLUG */ | 524 | #endif /* CONFIG_MEMORY_HOTPLUG */ |
491 | 525 | ||
492 | static struct kcore_list kcore_mem, kcore_vmalloc, kcore_kernel, kcore_modules, | 526 | static struct kcore_list kcore_mem, kcore_vmalloc, kcore_kernel, |
493 | kcore_vsyscall; | 527 | kcore_modules, kcore_vsyscall; |
494 | 528 | ||
495 | void __init mem_init(void) | 529 | void __init mem_init(void) |
496 | { | 530 | { |
@@ -518,7 +552,6 @@ void __init mem_init(void) | |||
518 | #endif | 552 | #endif |
519 | reservedpages = end_pfn - totalram_pages - | 553 | reservedpages = end_pfn - totalram_pages - |
520 | absent_pages_in_range(0, end_pfn); | 554 | absent_pages_in_range(0, end_pfn); |
521 | |||
522 | after_bootmem = 1; | 555 | after_bootmem = 1; |
523 | 556 | ||
524 | codesize = (unsigned long) &_etext - (unsigned long) &_text; | 557 | codesize = (unsigned long) &_etext - (unsigned long) &_text; |
@@ -526,15 +559,16 @@ void __init mem_init(void) | |||
526 | initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin; | 559 | initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin; |
527 | 560 | ||
528 | /* Register memory areas for /proc/kcore */ | 561 | /* Register memory areas for /proc/kcore */ |
529 | kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT); | 562 | kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT); |
530 | kclist_add(&kcore_vmalloc, (void *)VMALLOC_START, | 563 | kclist_add(&kcore_vmalloc, (void *)VMALLOC_START, |
531 | VMALLOC_END-VMALLOC_START); | 564 | VMALLOC_END-VMALLOC_START); |
532 | kclist_add(&kcore_kernel, &_stext, _end - _stext); | 565 | kclist_add(&kcore_kernel, &_stext, _end - _stext); |
533 | kclist_add(&kcore_modules, (void *)MODULES_VADDR, MODULES_LEN); | 566 | kclist_add(&kcore_modules, (void *)MODULES_VADDR, MODULES_LEN); |
534 | kclist_add(&kcore_vsyscall, (void *)VSYSCALL_START, | 567 | kclist_add(&kcore_vsyscall, (void *)VSYSCALL_START, |
535 | VSYSCALL_END - VSYSCALL_START); | 568 | VSYSCALL_END - VSYSCALL_START); |
536 | 569 | ||
537 | printk("Memory: %luk/%luk available (%ldk kernel code, %ldk reserved, %ldk data, %ldk init)\n", | 570 | printk("Memory: %luk/%luk available (%ldk kernel code, " |
571 | "%ldk reserved, %ldk data, %ldk init)\n", | ||
538 | (unsigned long) nr_free_pages() << (PAGE_SHIFT-10), | 572 | (unsigned long) nr_free_pages() << (PAGE_SHIFT-10), |
539 | end_pfn << (PAGE_SHIFT-10), | 573 | end_pfn << (PAGE_SHIFT-10), |
540 | codesize >> 10, | 574 | codesize >> 10, |
@@ -561,6 +595,7 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end) | |||
561 | set_memory_np(begin, (end - begin) >> PAGE_SHIFT); | 595 | set_memory_np(begin, (end - begin) >> PAGE_SHIFT); |
562 | #else | 596 | #else |
563 | printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10); | 597 | printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10); |
598 | |||
564 | for (addr = begin; addr < end; addr += PAGE_SIZE) { | 599 | for (addr = begin; addr < end; addr += PAGE_SIZE) { |
565 | ClearPageReserved(virt_to_page(addr)); | 600 | ClearPageReserved(virt_to_page(addr)); |
566 | init_page_count(virt_to_page(addr)); | 601 | init_page_count(virt_to_page(addr)); |
@@ -596,7 +631,7 @@ void mark_rodata_ro(void) | |||
596 | #ifdef CONFIG_KPROBES | 631 | #ifdef CONFIG_KPROBES |
597 | start = (unsigned long)__start_rodata; | 632 | start = (unsigned long)__start_rodata; |
598 | #endif | 633 | #endif |
599 | 634 | ||
600 | end = (unsigned long)__end_rodata; | 635 | end = (unsigned long)__end_rodata; |
601 | start = (start + PAGE_SIZE - 1) & PAGE_MASK; | 636 | start = (start + PAGE_SIZE - 1) & PAGE_MASK; |
602 | end &= PAGE_MASK; | 637 | end &= PAGE_MASK; |
@@ -627,17 +662,21 @@ void free_initrd_mem(unsigned long start, unsigned long end) | |||
627 | } | 662 | } |
628 | #endif | 663 | #endif |
629 | 664 | ||
630 | void __init reserve_bootmem_generic(unsigned long phys, unsigned len) | 665 | void __init reserve_bootmem_generic(unsigned long phys, unsigned len) |
631 | { | 666 | { |
632 | #ifdef CONFIG_NUMA | 667 | #ifdef CONFIG_NUMA |
633 | int nid = phys_to_nid(phys); | 668 | int nid = phys_to_nid(phys); |
634 | #endif | 669 | #endif |
635 | unsigned long pfn = phys >> PAGE_SHIFT; | 670 | unsigned long pfn = phys >> PAGE_SHIFT; |
671 | |||
636 | if (pfn >= end_pfn) { | 672 | if (pfn >= end_pfn) { |
637 | /* This can happen with kdump kernels when accessing firmware | 673 | /* |
638 | tables. */ | 674 | * This can happen with kdump kernels when accessing |
675 | * firmware tables: | ||
676 | */ | ||
639 | if (pfn < end_pfn_map) | 677 | if (pfn < end_pfn_map) |
640 | return; | 678 | return; |
679 | |||
641 | printk(KERN_ERR "reserve_bootmem: illegal reserve %lx %u\n", | 680 | printk(KERN_ERR "reserve_bootmem: illegal reserve %lx %u\n", |
642 | phys, len); | 681 | phys, len); |
643 | return; | 682 | return; |
@@ -645,9 +684,9 @@ void __init reserve_bootmem_generic(unsigned long phys, unsigned len) | |||
645 | 684 | ||
646 | /* Should check here against the e820 map to avoid double free */ | 685 | /* Should check here against the e820 map to avoid double free */ |
647 | #ifdef CONFIG_NUMA | 686 | #ifdef CONFIG_NUMA |
648 | reserve_bootmem_node(NODE_DATA(nid), phys, len); | 687 | reserve_bootmem_node(NODE_DATA(nid), phys, len); |
649 | #else | 688 | #else |
650 | reserve_bootmem(phys, len); | 689 | reserve_bootmem(phys, len); |
651 | #endif | 690 | #endif |
652 | if (phys+len <= MAX_DMA_PFN*PAGE_SIZE) { | 691 | if (phys+len <= MAX_DMA_PFN*PAGE_SIZE) { |
653 | dma_reserve += len / PAGE_SIZE; | 692 | dma_reserve += len / PAGE_SIZE; |
@@ -655,46 +694,49 @@ void __init reserve_bootmem_generic(unsigned long phys, unsigned len) | |||
655 | } | 694 | } |
656 | } | 695 | } |
657 | 696 | ||
658 | int kern_addr_valid(unsigned long addr) | 697 | int kern_addr_valid(unsigned long addr) |
659 | { | 698 | { |
660 | unsigned long above = ((long)addr) >> __VIRTUAL_MASK_SHIFT; | 699 | unsigned long above = ((long)addr) >> __VIRTUAL_MASK_SHIFT; |
661 | pgd_t *pgd; | 700 | pgd_t *pgd; |
662 | pud_t *pud; | 701 | pud_t *pud; |
663 | pmd_t *pmd; | 702 | pmd_t *pmd; |
664 | pte_t *pte; | 703 | pte_t *pte; |
665 | 704 | ||
666 | if (above != 0 && above != -1UL) | 705 | if (above != 0 && above != -1UL) |
667 | return 0; | 706 | return 0; |
668 | 707 | ||
669 | pgd = pgd_offset_k(addr); | 708 | pgd = pgd_offset_k(addr); |
670 | if (pgd_none(*pgd)) | 709 | if (pgd_none(*pgd)) |
671 | return 0; | 710 | return 0; |
672 | 711 | ||
673 | pud = pud_offset(pgd, addr); | 712 | pud = pud_offset(pgd, addr); |
674 | if (pud_none(*pud)) | 713 | if (pud_none(*pud)) |
675 | return 0; | 714 | return 0; |
676 | 715 | ||
677 | pmd = pmd_offset(pud, addr); | 716 | pmd = pmd_offset(pud, addr); |
678 | if (pmd_none(*pmd)) | 717 | if (pmd_none(*pmd)) |
679 | return 0; | 718 | return 0; |
719 | |||
680 | if (pmd_large(*pmd)) | 720 | if (pmd_large(*pmd)) |
681 | return pfn_valid(pmd_pfn(*pmd)); | 721 | return pfn_valid(pmd_pfn(*pmd)); |
682 | 722 | ||
683 | pte = pte_offset_kernel(pmd, addr); | 723 | pte = pte_offset_kernel(pmd, addr); |
684 | if (pte_none(*pte)) | 724 | if (pte_none(*pte)) |
685 | return 0; | 725 | return 0; |
726 | |||
686 | return pfn_valid(pte_pfn(*pte)); | 727 | return pfn_valid(pte_pfn(*pte)); |
687 | } | 728 | } |
688 | 729 | ||
689 | /* A pseudo VMA to allow ptrace access for the vsyscall page. This only | 730 | /* |
690 | covers the 64bit vsyscall page now. 32bit has a real VMA now and does | 731 | * A pseudo VMA to allow ptrace access for the vsyscall page. This only |
691 | not need special handling anymore. */ | 732 | * covers the 64bit vsyscall page now. 32bit has a real VMA now and does |
692 | 733 | * not need special handling anymore: | |
734 | */ | ||
693 | static struct vm_area_struct gate_vma = { | 735 | static struct vm_area_struct gate_vma = { |
694 | .vm_start = VSYSCALL_START, | 736 | .vm_start = VSYSCALL_START, |
695 | .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES << PAGE_SHIFT), | 737 | .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE), |
696 | .vm_page_prot = PAGE_READONLY_EXEC, | 738 | .vm_page_prot = PAGE_READONLY_EXEC, |
697 | .vm_flags = VM_READ | VM_EXEC | 739 | .vm_flags = VM_READ | VM_EXEC |
698 | }; | 740 | }; |
699 | 741 | ||
700 | struct vm_area_struct *get_gate_vma(struct task_struct *tsk) | 742 | struct vm_area_struct *get_gate_vma(struct task_struct *tsk) |
@@ -709,14 +751,17 @@ struct vm_area_struct *get_gate_vma(struct task_struct *tsk) | |||
709 | int in_gate_area(struct task_struct *task, unsigned long addr) | 751 | int in_gate_area(struct task_struct *task, unsigned long addr) |
710 | { | 752 | { |
711 | struct vm_area_struct *vma = get_gate_vma(task); | 753 | struct vm_area_struct *vma = get_gate_vma(task); |
754 | |||
712 | if (!vma) | 755 | if (!vma) |
713 | return 0; | 756 | return 0; |
757 | |||
714 | return (addr >= vma->vm_start) && (addr < vma->vm_end); | 758 | return (addr >= vma->vm_start) && (addr < vma->vm_end); |
715 | } | 759 | } |
716 | 760 | ||
717 | /* Use this when you have no reliable task/vma, typically from interrupt | 761 | /* |
718 | * context. It is less reliable than using the task's vma and may give | 762 | * Use this when you have no reliable task/vma, typically from interrupt |
719 | * false positives. | 763 | * context. It is less reliable than using the task's vma and may give |
764 | * false positives: | ||
720 | */ | 765 | */ |
721 | int in_gate_area_no_task(unsigned long addr) | 766 | int in_gate_area_no_task(unsigned long addr) |
722 | { | 767 | { |
@@ -736,8 +781,8 @@ const char *arch_vma_name(struct vm_area_struct *vma) | |||
736 | /* | 781 | /* |
737 | * Initialise the sparsemem vmemmap using huge-pages at the PMD level. | 782 | * Initialise the sparsemem vmemmap using huge-pages at the PMD level. |
738 | */ | 783 | */ |
739 | int __meminit vmemmap_populate(struct page *start_page, | 784 | int __meminit |
740 | unsigned long size, int node) | 785 | vmemmap_populate(struct page *start_page, unsigned long size, int node) |
741 | { | 786 | { |
742 | unsigned long addr = (unsigned long)start_page; | 787 | unsigned long addr = (unsigned long)start_page; |
743 | unsigned long end = (unsigned long)(start_page + size); | 788 | unsigned long end = (unsigned long)(start_page + size); |
@@ -752,6 +797,7 @@ int __meminit vmemmap_populate(struct page *start_page, | |||
752 | pgd = vmemmap_pgd_populate(addr, node); | 797 | pgd = vmemmap_pgd_populate(addr, node); |
753 | if (!pgd) | 798 | if (!pgd) |
754 | return -ENOMEM; | 799 | return -ENOMEM; |
800 | |||
755 | pud = vmemmap_pud_populate(pgd, addr, node); | 801 | pud = vmemmap_pud_populate(pgd, addr, node); |
756 | if (!pud) | 802 | if (!pud) |
757 | return -ENOMEM; | 803 | return -ENOMEM; |
@@ -759,19 +805,22 @@ int __meminit vmemmap_populate(struct page *start_page, | |||
759 | pmd = pmd_offset(pud, addr); | 805 | pmd = pmd_offset(pud, addr); |
760 | if (pmd_none(*pmd)) { | 806 | if (pmd_none(*pmd)) { |
761 | pte_t entry; | 807 | pte_t entry; |
762 | void *p = vmemmap_alloc_block(PMD_SIZE, node); | 808 | void *p; |
809 | |||
810 | p = vmemmap_alloc_block(PMD_SIZE, node); | ||
763 | if (!p) | 811 | if (!p) |
764 | return -ENOMEM; | 812 | return -ENOMEM; |
765 | 813 | ||
766 | entry = pfn_pte(__pa(p) >> PAGE_SHIFT, PAGE_KERNEL_LARGE); | 814 | entry = pfn_pte(__pa(p) >> PAGE_SHIFT, |
815 | PAGE_KERNEL_LARGE); | ||
767 | set_pmd(pmd, __pmd(pte_val(entry))); | 816 | set_pmd(pmd, __pmd(pte_val(entry))); |
768 | 817 | ||
769 | printk(KERN_DEBUG " [%lx-%lx] PMD ->%p on node %d\n", | 818 | printk(KERN_DEBUG " [%lx-%lx] PMD ->%p on node %d\n", |
770 | addr, addr + PMD_SIZE - 1, p, node); | 819 | addr, addr + PMD_SIZE - 1, p, node); |
771 | } else | 820 | } else { |
772 | vmemmap_verify((pte_t *)pmd, node, addr, next); | 821 | vmemmap_verify((pte_t *)pmd, node, addr, next); |
822 | } | ||
773 | } | 823 | } |
774 | |||
775 | return 0; | 824 | return 0; |
776 | } | 825 | } |
777 | #endif | 826 | #endif |