Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/arch/x86_64/mm/init.c | |
3 | * | |
4 | * Copyright (C) 1995 Linus Torvalds | |
a2531293 | 5 | * Copyright (C) 2000 Pavel Machek <pavel@ucw.cz> |
1da177e4 LT |
6 | * Copyright (C) 2002,2003 Andi Kleen <ak@suse.de> |
7 | */ | |
8 | ||
1da177e4 LT |
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/swap.h> | |
19 | #include <linux/smp.h> | |
20 | #include <linux/init.h> | |
11034d55 | 21 | #include <linux/initrd.h> |
1da177e4 LT |
22 | #include <linux/pagemap.h> |
23 | #include <linux/bootmem.h> | |
a9ce6bc1 | 24 | #include <linux/memblock.h> |
1da177e4 | 25 | #include <linux/proc_fs.h> |
59170891 | 26 | #include <linux/pci.h> |
6fb14755 | 27 | #include <linux/pfn.h> |
c9cf5528 | 28 | #include <linux/poison.h> |
17a941d8 | 29 | #include <linux/dma-mapping.h> |
44df75e6 | 30 | #include <linux/module.h> |
a63fdc51 | 31 | #include <linux/memory.h> |
44df75e6 | 32 | #include <linux/memory_hotplug.h> |
ae32b129 | 33 | #include <linux/nmi.h> |
5a0e3ad6 | 34 | #include <linux/gfp.h> |
1da177e4 LT |
35 | |
36 | #include <asm/processor.h> | |
46eaa670 | 37 | #include <asm/bios_ebda.h> |
1da177e4 LT |
38 | #include <asm/uaccess.h> |
39 | #include <asm/pgtable.h> | |
40 | #include <asm/pgalloc.h> | |
41 | #include <asm/dma.h> | |
42 | #include <asm/fixmap.h> | |
43 | #include <asm/e820.h> | |
44 | #include <asm/apic.h> | |
45 | #include <asm/tlb.h> | |
46 | #include <asm/mmu_context.h> | |
47 | #include <asm/proto.h> | |
48 | #include <asm/smp.h> | |
2bc0414e | 49 | #include <asm/sections.h> |
718fc13b | 50 | #include <asm/kdebug.h> |
aaa64e04 | 51 | #include <asm/numa.h> |
7bfeab9a | 52 | #include <asm/cacheflush.h> |
4fcb2083 | 53 | #include <asm/init.h> |
1dc41aa6 | 54 | #include <asm/uv/uv.h> |
e5f15b45 | 55 | #include <asm/setup.h> |
1da177e4 | 56 | |
00d1c5e0 IM |
57 | static int __init parse_direct_gbpages_off(char *arg) |
58 | { | |
59 | direct_gbpages = 0; | |
60 | return 0; | |
61 | } | |
62 | early_param("nogbpages", parse_direct_gbpages_off); | |
63 | ||
64 | static int __init parse_direct_gbpages_on(char *arg) | |
65 | { | |
66 | direct_gbpages = 1; | |
67 | return 0; | |
68 | } | |
69 | early_param("gbpages", parse_direct_gbpages_on); | |
70 | ||
1da177e4 LT |
71 | /* |
72 | * NOTE: pagetable_init alloc all the fixmap pagetables contiguous on the | |
73 | * physical space so we can cache the place of the first one and move | |
74 | * around without checking the pgd every time. | |
75 | */ | |
76 | ||
be43d728 | 77 | pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP; |
bd220a24 YL |
78 | EXPORT_SYMBOL_GPL(__supported_pte_mask); |
79 | ||
bd220a24 YL |
80 | int force_personality32; |
81 | ||
deed05b7 IM |
82 | /* |
83 | * noexec32=on|off | |
84 | * Control non executable heap for 32bit processes. | |
85 | * To control the stack too use noexec=off | |
86 | * | |
87 | * on PROT_READ does not imply PROT_EXEC for 32-bit processes (default) | |
88 | * off PROT_READ implies PROT_EXEC | |
89 | */ | |
bd220a24 YL |
90 | static int __init nonx32_setup(char *str) |
91 | { | |
92 | if (!strcmp(str, "on")) | |
93 | force_personality32 &= ~READ_IMPLIES_EXEC; | |
94 | else if (!strcmp(str, "off")) | |
95 | force_personality32 |= READ_IMPLIES_EXEC; | |
96 | return 1; | |
97 | } | |
98 | __setup("noexec32=", nonx32_setup); | |
99 | ||
6afb5157 HL |
100 | /* |
101 | * When memory was added/removed make sure all the processes MM have | |
102 | * suitable PGD entries in the local PGD level page. | |
103 | */ | |
104 | void sync_global_pgds(unsigned long start, unsigned long end) | |
105 | { | |
44235dcd JF |
106 | unsigned long address; |
107 | ||
108 | for (address = start; address <= end; address += PGDIR_SIZE) { | |
109 | const pgd_t *pgd_ref = pgd_offset_k(address); | |
44235dcd JF |
110 | struct page *page; |
111 | ||
112 | if (pgd_none(*pgd_ref)) | |
113 | continue; | |
114 | ||
a79e53d8 | 115 | spin_lock(&pgd_lock); |
44235dcd JF |
116 | list_for_each_entry(page, &pgd_list, lru) { |
117 | pgd_t *pgd; | |
617d34d9 JF |
118 | spinlock_t *pgt_lock; |
119 | ||
44235dcd | 120 | pgd = (pgd_t *)page_address(page) + pgd_index(address); |
a79e53d8 | 121 | /* the pgt_lock only for Xen */ |
617d34d9 JF |
122 | pgt_lock = &pgd_page_get_mm(page)->page_table_lock; |
123 | spin_lock(pgt_lock); | |
124 | ||
44235dcd JF |
125 | if (pgd_none(*pgd)) |
126 | set_pgd(pgd, *pgd_ref); | |
127 | else | |
128 | BUG_ON(pgd_page_vaddr(*pgd) | |
129 | != pgd_page_vaddr(*pgd_ref)); | |
617d34d9 JF |
130 | |
131 | spin_unlock(pgt_lock); | |
44235dcd | 132 | } |
a79e53d8 | 133 | spin_unlock(&pgd_lock); |
44235dcd | 134 | } |
6afb5157 HL |
135 | } |
136 | ||
8d6ea967 MS |
137 | /* |
138 | * NOTE: This function is marked __ref because it calls __init function | |
139 | * (alloc_bootmem_pages). It's safe to do it ONLY when after_bootmem == 0. | |
140 | */ | |
141 | static __ref void *spp_getpage(void) | |
14a62c34 | 142 | { |
1da177e4 | 143 | void *ptr; |
14a62c34 | 144 | |
1da177e4 | 145 | if (after_bootmem) |
9e730237 | 146 | ptr = (void *) get_zeroed_page(GFP_ATOMIC | __GFP_NOTRACK); |
1da177e4 LT |
147 | else |
148 | ptr = alloc_bootmem_pages(PAGE_SIZE); | |
14a62c34 TG |
149 | |
150 | if (!ptr || ((unsigned long)ptr & ~PAGE_MASK)) { | |
151 | panic("set_pte_phys: cannot allocate page data %s\n", | |
152 | after_bootmem ? "after bootmem" : ""); | |
153 | } | |
1da177e4 | 154 | |
10f22dde | 155 | pr_debug("spp_getpage %p\n", ptr); |
14a62c34 | 156 | |
1da177e4 | 157 | return ptr; |
14a62c34 | 158 | } |
1da177e4 | 159 | |
f254f390 | 160 | static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr) |
1da177e4 | 161 | { |
458a3e64 TH |
162 | if (pgd_none(*pgd)) { |
163 | pud_t *pud = (pud_t *)spp_getpage(); | |
164 | pgd_populate(&init_mm, pgd, pud); | |
165 | if (pud != pud_offset(pgd, 0)) | |
166 | printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n", | |
167 | pud, pud_offset(pgd, 0)); | |
168 | } | |
169 | return pud_offset(pgd, vaddr); | |
170 | } | |
1da177e4 | 171 | |
f254f390 | 172 | static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr) |
458a3e64 | 173 | { |
1da177e4 | 174 | if (pud_none(*pud)) { |
458a3e64 | 175 | pmd_t *pmd = (pmd_t *) spp_getpage(); |
bb23e403 | 176 | pud_populate(&init_mm, pud, pmd); |
458a3e64 | 177 | if (pmd != pmd_offset(pud, 0)) |
10f22dde | 178 | printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n", |
458a3e64 | 179 | pmd, pmd_offset(pud, 0)); |
1da177e4 | 180 | } |
458a3e64 TH |
181 | return pmd_offset(pud, vaddr); |
182 | } | |
183 | ||
f254f390 | 184 | static pte_t *fill_pte(pmd_t *pmd, unsigned long vaddr) |
458a3e64 | 185 | { |
1da177e4 | 186 | if (pmd_none(*pmd)) { |
458a3e64 | 187 | pte_t *pte = (pte_t *) spp_getpage(); |
bb23e403 | 188 | pmd_populate_kernel(&init_mm, pmd, pte); |
458a3e64 | 189 | if (pte != pte_offset_kernel(pmd, 0)) |
10f22dde | 190 | printk(KERN_ERR "PAGETABLE BUG #02!\n"); |
1da177e4 | 191 | } |
458a3e64 TH |
192 | return pte_offset_kernel(pmd, vaddr); |
193 | } | |
194 | ||
195 | void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte) | |
196 | { | |
197 | pud_t *pud; | |
198 | pmd_t *pmd; | |
199 | pte_t *pte; | |
200 | ||
201 | pud = pud_page + pud_index(vaddr); | |
202 | pmd = fill_pmd(pud, vaddr); | |
203 | pte = fill_pte(pmd, vaddr); | |
1da177e4 | 204 | |
1da177e4 LT |
205 | set_pte(pte, new_pte); |
206 | ||
207 | /* | |
208 | * It's enough to flush this one mapping. | |
209 | * (PGE mappings get flushed as well) | |
210 | */ | |
211 | __flush_tlb_one(vaddr); | |
212 | } | |
213 | ||
458a3e64 | 214 | void set_pte_vaddr(unsigned long vaddr, pte_t pteval) |
0814e0ba EH |
215 | { |
216 | pgd_t *pgd; | |
217 | pud_t *pud_page; | |
218 | ||
219 | pr_debug("set_pte_vaddr %lx to %lx\n", vaddr, native_pte_val(pteval)); | |
220 | ||
221 | pgd = pgd_offset_k(vaddr); | |
222 | if (pgd_none(*pgd)) { | |
223 | printk(KERN_ERR | |
224 | "PGD FIXMAP MISSING, it should be setup in head.S!\n"); | |
225 | return; | |
226 | } | |
227 | pud_page = (pud_t*)pgd_page_vaddr(*pgd); | |
228 | set_pte_vaddr_pud(pud_page, vaddr, pteval); | |
229 | } | |
230 | ||
458a3e64 | 231 | pmd_t * __init populate_extra_pmd(unsigned long vaddr) |
11124411 TH |
232 | { |
233 | pgd_t *pgd; | |
234 | pud_t *pud; | |
235 | ||
236 | pgd = pgd_offset_k(vaddr); | |
458a3e64 TH |
237 | pud = fill_pud(pgd, vaddr); |
238 | return fill_pmd(pud, vaddr); | |
239 | } | |
240 | ||
241 | pte_t * __init populate_extra_pte(unsigned long vaddr) | |
242 | { | |
243 | pmd_t *pmd; | |
11124411 | 244 | |
458a3e64 TH |
245 | pmd = populate_extra_pmd(vaddr); |
246 | return fill_pte(pmd, vaddr); | |
11124411 TH |
247 | } |
248 | ||
3a9e189d JS |
249 | /* |
250 | * Create large page table mappings for a range of physical addresses. | |
251 | */ | |
252 | static void __init __init_extra_mapping(unsigned long phys, unsigned long size, | |
253 | pgprot_t prot) | |
254 | { | |
255 | pgd_t *pgd; | |
256 | pud_t *pud; | |
257 | pmd_t *pmd; | |
258 | ||
259 | BUG_ON((phys & ~PMD_MASK) || (size & ~PMD_MASK)); | |
260 | for (; size; phys += PMD_SIZE, size -= PMD_SIZE) { | |
261 | pgd = pgd_offset_k((unsigned long)__va(phys)); | |
262 | if (pgd_none(*pgd)) { | |
263 | pud = (pud_t *) spp_getpage(); | |
264 | set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE | | |
265 | _PAGE_USER)); | |
266 | } | |
267 | pud = pud_offset(pgd, (unsigned long)__va(phys)); | |
268 | if (pud_none(*pud)) { | |
269 | pmd = (pmd_t *) spp_getpage(); | |
270 | set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE | | |
271 | _PAGE_USER)); | |
272 | } | |
273 | pmd = pmd_offset(pud, phys); | |
274 | BUG_ON(!pmd_none(*pmd)); | |
275 | set_pmd(pmd, __pmd(phys | pgprot_val(prot))); | |
276 | } | |
277 | } | |
278 | ||
279 | void __init init_extra_mapping_wb(unsigned long phys, unsigned long size) | |
280 | { | |
281 | __init_extra_mapping(phys, size, PAGE_KERNEL_LARGE); | |
282 | } | |
283 | ||
284 | void __init init_extra_mapping_uc(unsigned long phys, unsigned long size) | |
285 | { | |
286 | __init_extra_mapping(phys, size, PAGE_KERNEL_LARGE_NOCACHE); | |
287 | } | |
288 | ||
31eedd82 | 289 | /* |
88f3aec7 IM |
290 | * The head.S code sets up the kernel high mapping: |
291 | * | |
292 | * from __START_KERNEL_map to __START_KERNEL_map + size (== _end-_text) | |
31eedd82 TG |
293 | * |
294 | * phys_addr holds the negative offset to the kernel, which is added | |
295 | * to the compile time generated pmds. This results in invalid pmds up | |
296 | * to the point where we hit the physaddr 0 mapping. | |
297 | * | |
e5f15b45 YL |
298 | * We limit the mappings to the region from _text to _brk_end. _brk_end |
299 | * is rounded up to the 2MB boundary. This catches the invalid pmds as | |
31eedd82 TG |
300 | * well, as they are located before _text: |
301 | */ | |
302 | void __init cleanup_highmap(void) | |
303 | { | |
304 | unsigned long vaddr = __START_KERNEL_map; | |
e5f15b45 YL |
305 | unsigned long vaddr_end = __START_KERNEL_map + (max_pfn_mapped << PAGE_SHIFT); |
306 | unsigned long end = roundup((unsigned long)_brk_end, PMD_SIZE) - 1; | |
31eedd82 | 307 | pmd_t *pmd = level2_kernel_pgt; |
31eedd82 | 308 | |
e5f15b45 | 309 | for (; vaddr + PMD_SIZE - 1 < vaddr_end; pmd++, vaddr += PMD_SIZE) { |
2884f110 | 310 | if (pmd_none(*pmd)) |
31eedd82 TG |
311 | continue; |
312 | if (vaddr < (unsigned long) _text || vaddr > end) | |
313 | set_pmd(pmd, __pmd(0)); | |
314 | } | |
315 | } | |
316 | ||
9482ac6e | 317 | static __ref void *alloc_low_page(unsigned long *phys) |
14a62c34 | 318 | { |
8d57470d | 319 | unsigned long pfn; |
1da177e4 LT |
320 | void *adr; |
321 | ||
44df75e6 | 322 | if (after_bootmem) { |
9e730237 | 323 | adr = (void *)get_zeroed_page(GFP_ATOMIC | __GFP_NOTRACK); |
44df75e6 | 324 | *phys = __pa(adr); |
14a62c34 | 325 | |
44df75e6 MT |
326 | return adr; |
327 | } | |
328 | ||
8d57470d YL |
329 | if ((pgt_buf_end + 1) >= pgt_buf_top) { |
330 | unsigned long ret; | |
331 | if (min_pfn_mapped >= max_pfn_mapped) | |
332 | panic("alloc_low_page: ran out of memory"); | |
333 | ret = memblock_find_in_range(min_pfn_mapped << PAGE_SHIFT, | |
334 | max_pfn_mapped << PAGE_SHIFT, | |
335 | PAGE_SIZE, PAGE_SIZE); | |
336 | if (!ret) | |
337 | panic("alloc_low_page: can not alloc memory"); | |
338 | memblock_reserve(ret, PAGE_SIZE); | |
339 | pfn = ret >> PAGE_SHIFT; | |
340 | } else | |
341 | pfn = pgt_buf_end++; | |
dafe41ee | 342 | |
14941779 | 343 | adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE); |
234bb549 | 344 | clear_page(adr); |
dafe41ee VG |
345 | *phys = pfn * PAGE_SIZE; |
346 | return adr; | |
347 | } | |
1da177e4 | 348 | |
4b239f45 YL |
349 | static __ref void *map_low_page(void *virt) |
350 | { | |
351 | void *adr; | |
352 | unsigned long phys, left; | |
353 | ||
354 | if (after_bootmem) | |
355 | return virt; | |
356 | ||
357 | phys = __pa(virt); | |
358 | left = phys & (PAGE_SIZE - 1); | |
359 | adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE); | |
360 | adr = (void *)(((unsigned long)adr) | left); | |
361 | ||
362 | return adr; | |
363 | } | |
364 | ||
9482ac6e | 365 | static __ref void unmap_low_page(void *adr) |
14a62c34 | 366 | { |
44df75e6 MT |
367 | if (after_bootmem) |
368 | return; | |
369 | ||
4b239f45 | 370 | early_iounmap((void *)((unsigned long)adr & PAGE_MASK), PAGE_SIZE); |
14a62c34 | 371 | } |
1da177e4 | 372 | |
7b16eb89 | 373 | static unsigned long __meminit |
b27a43c1 SS |
374 | phys_pte_init(pte_t *pte_page, unsigned long addr, unsigned long end, |
375 | pgprot_t prot) | |
4f9c11dd | 376 | { |
eceb3632 | 377 | unsigned long pages = 0, next; |
7b16eb89 | 378 | unsigned long last_map_addr = end; |
4f9c11dd | 379 | int i; |
7b16eb89 | 380 | |
4f9c11dd JF |
381 | pte_t *pte = pte_page + pte_index(addr); |
382 | ||
eceb3632 YL |
383 | for (i = pte_index(addr); i < PTRS_PER_PTE; i++, addr = next, pte++) { |
384 | next = (addr & PAGE_MASK) + PAGE_SIZE; | |
4f9c11dd | 385 | if (addr >= end) { |
eceb3632 YL |
386 | if (!after_bootmem && |
387 | !e820_any_mapped(addr & PAGE_MASK, next, E820_RAM) && | |
388 | !e820_any_mapped(addr & PAGE_MASK, next, E820_RESERVED_KERN)) | |
389 | set_pte(pte, __pte(0)); | |
390 | continue; | |
4f9c11dd JF |
391 | } |
392 | ||
b27a43c1 SS |
393 | /* |
394 | * We will re-use the existing mapping. | |
395 | * Xen for example has some special requirements, like mapping | |
396 | * pagetable pages as RO. So assume someone who pre-setup | |
397 | * these mappings are more intelligent. | |
398 | */ | |
3afa3949 | 399 | if (pte_val(*pte)) { |
876ee61a JB |
400 | if (!after_bootmem) |
401 | pages++; | |
4f9c11dd | 402 | continue; |
3afa3949 | 403 | } |
4f9c11dd JF |
404 | |
405 | if (0) | |
406 | printk(" pte=%p addr=%lx pte=%016lx\n", | |
407 | pte, addr, pfn_pte(addr >> PAGE_SHIFT, PAGE_KERNEL).pte); | |
4f9c11dd | 408 | pages++; |
b27a43c1 | 409 | set_pte(pte, pfn_pte(addr >> PAGE_SHIFT, prot)); |
7b16eb89 | 410 | last_map_addr = (addr & PAGE_MASK) + PAGE_SIZE; |
4f9c11dd | 411 | } |
a2699e47 | 412 | |
4f9c11dd | 413 | update_page_count(PG_LEVEL_4K, pages); |
7b16eb89 YL |
414 | |
415 | return last_map_addr; | |
4f9c11dd JF |
416 | } |
417 | ||
cc615032 | 418 | static unsigned long __meminit |
b50efd2a | 419 | phys_pmd_init(pmd_t *pmd_page, unsigned long address, unsigned long end, |
b27a43c1 | 420 | unsigned long page_size_mask, pgprot_t prot) |
44df75e6 | 421 | { |
20167d34 | 422 | unsigned long pages = 0, next; |
7b16eb89 | 423 | unsigned long last_map_addr = end; |
ce0c0e50 | 424 | |
6ad91658 | 425 | int i = pmd_index(address); |
44df75e6 | 426 | |
20167d34 | 427 | for (; i < PTRS_PER_PMD; i++, address = next) { |
4f9c11dd | 428 | unsigned long pte_phys; |
6ad91658 | 429 | pmd_t *pmd = pmd_page + pmd_index(address); |
4f9c11dd | 430 | pte_t *pte; |
b27a43c1 | 431 | pgprot_t new_prot = prot; |
44df75e6 | 432 | |
eceb3632 | 433 | next = (address & PMD_MASK) + PMD_SIZE; |
5f51e139 | 434 | if (address >= end) { |
eceb3632 YL |
435 | if (!after_bootmem && |
436 | !e820_any_mapped(address & PMD_MASK, next, E820_RAM) && | |
437 | !e820_any_mapped(address & PMD_MASK, next, E820_RESERVED_KERN)) | |
438 | set_pmd(pmd, __pmd(0)); | |
439 | continue; | |
44df75e6 | 440 | } |
6ad91658 | 441 | |
4f9c11dd | 442 | if (pmd_val(*pmd)) { |
8ae3a5a8 JB |
443 | if (!pmd_large(*pmd)) { |
444 | spin_lock(&init_mm.page_table_lock); | |
4b239f45 YL |
445 | pte = map_low_page((pte_t *)pmd_page_vaddr(*pmd)); |
446 | last_map_addr = phys_pte_init(pte, address, | |
b27a43c1 | 447 | end, prot); |
4b239f45 | 448 | unmap_low_page(pte); |
8ae3a5a8 | 449 | spin_unlock(&init_mm.page_table_lock); |
a2699e47 | 450 | continue; |
8ae3a5a8 | 451 | } |
b27a43c1 SS |
452 | /* |
453 | * If we are ok with PG_LEVEL_2M mapping, then we will | |
454 | * use the existing mapping, | |
455 | * | |
456 | * Otherwise, we will split the large page mapping but | |
457 | * use the same existing protection bits except for | |
458 | * large page, so that we don't violate Intel's TLB | |
459 | * Application note (317080) which says, while changing | |
460 | * the page sizes, new and old translations should | |
461 | * not differ with respect to page frame and | |
462 | * attributes. | |
463 | */ | |
3afa3949 | 464 | if (page_size_mask & (1 << PG_LEVEL_2M)) { |
876ee61a JB |
465 | if (!after_bootmem) |
466 | pages++; | |
20167d34 | 467 | last_map_addr = next; |
b27a43c1 | 468 | continue; |
3afa3949 | 469 | } |
b27a43c1 | 470 | new_prot = pte_pgprot(pte_clrhuge(*(pte_t *)pmd)); |
4f9c11dd JF |
471 | } |
472 | ||
b50efd2a | 473 | if (page_size_mask & (1<<PG_LEVEL_2M)) { |
4f9c11dd | 474 | pages++; |
8ae3a5a8 | 475 | spin_lock(&init_mm.page_table_lock); |
4f9c11dd | 476 | set_pte((pte_t *)pmd, |
960ddb4f | 477 | pfn_pte((address & PMD_MASK) >> PAGE_SHIFT, |
b27a43c1 | 478 | __pgprot(pgprot_val(prot) | _PAGE_PSE))); |
8ae3a5a8 | 479 | spin_unlock(&init_mm.page_table_lock); |
20167d34 | 480 | last_map_addr = next; |
6ad91658 | 481 | continue; |
4f9c11dd | 482 | } |
6ad91658 | 483 | |
4f9c11dd | 484 | pte = alloc_low_page(&pte_phys); |
b27a43c1 | 485 | last_map_addr = phys_pte_init(pte, address, end, new_prot); |
4f9c11dd JF |
486 | unmap_low_page(pte); |
487 | ||
8ae3a5a8 | 488 | spin_lock(&init_mm.page_table_lock); |
4f9c11dd | 489 | pmd_populate_kernel(&init_mm, pmd, __va(pte_phys)); |
8ae3a5a8 | 490 | spin_unlock(&init_mm.page_table_lock); |
44df75e6 | 491 | } |
ce0c0e50 | 492 | update_page_count(PG_LEVEL_2M, pages); |
7b16eb89 | 493 | return last_map_addr; |
44df75e6 MT |
494 | } |
495 | ||
cc615032 | 496 | static unsigned long __meminit |
b50efd2a YL |
497 | phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end, |
498 | unsigned long page_size_mask) | |
14a62c34 | 499 | { |
20167d34 | 500 | unsigned long pages = 0, next; |
cc615032 | 501 | unsigned long last_map_addr = end; |
6ad91658 | 502 | int i = pud_index(addr); |
44df75e6 | 503 | |
20167d34 | 504 | for (; i < PTRS_PER_PUD; i++, addr = next) { |
6ad91658 KM |
505 | unsigned long pmd_phys; |
506 | pud_t *pud = pud_page + pud_index(addr); | |
1da177e4 | 507 | pmd_t *pmd; |
b27a43c1 | 508 | pgprot_t prot = PAGE_KERNEL; |
1da177e4 | 509 | |
20167d34 | 510 | next = (addr & PUD_MASK) + PUD_SIZE; |
eceb3632 YL |
511 | if (addr >= end) { |
512 | if (!after_bootmem && | |
513 | !e820_any_mapped(addr & PUD_MASK, next, E820_RAM) && | |
514 | !e820_any_mapped(addr & PUD_MASK, next, E820_RESERVED_KERN)) | |
515 | set_pud(pud, __pud(0)); | |
1da177e4 | 516 | continue; |
14a62c34 | 517 | } |
1da177e4 | 518 | |
6ad91658 | 519 | if (pud_val(*pud)) { |
a2699e47 | 520 | if (!pud_large(*pud)) { |
4b239f45 YL |
521 | pmd = map_low_page(pmd_offset(pud, 0)); |
522 | last_map_addr = phys_pmd_init(pmd, addr, end, | |
b27a43c1 | 523 | page_size_mask, prot); |
4b239f45 YL |
524 | unmap_low_page(pmd); |
525 | __flush_tlb_all(); | |
a2699e47 SS |
526 | continue; |
527 | } | |
b27a43c1 SS |
528 | /* |
529 | * If we are ok with PG_LEVEL_1G mapping, then we will | |
530 | * use the existing mapping. | |
531 | * | |
532 | * Otherwise, we will split the gbpage mapping but use | |
533 | * the same existing protection bits except for large | |
534 | * page, so that we don't violate Intel's TLB | |
535 | * Application note (317080) which says, while changing | |
536 | * the page sizes, new and old translations should | |
537 | * not differ with respect to page frame and | |
538 | * attributes. | |
539 | */ | |
3afa3949 | 540 | if (page_size_mask & (1 << PG_LEVEL_1G)) { |
876ee61a JB |
541 | if (!after_bootmem) |
542 | pages++; | |
20167d34 | 543 | last_map_addr = next; |
b27a43c1 | 544 | continue; |
3afa3949 | 545 | } |
b27a43c1 | 546 | prot = pte_pgprot(pte_clrhuge(*(pte_t *)pud)); |
ef925766 AK |
547 | } |
548 | ||
b50efd2a | 549 | if (page_size_mask & (1<<PG_LEVEL_1G)) { |
ce0c0e50 | 550 | pages++; |
8ae3a5a8 | 551 | spin_lock(&init_mm.page_table_lock); |
ef925766 | 552 | set_pte((pte_t *)pud, |
960ddb4f YL |
553 | pfn_pte((addr & PUD_MASK) >> PAGE_SHIFT, |
554 | PAGE_KERNEL_LARGE)); | |
8ae3a5a8 | 555 | spin_unlock(&init_mm.page_table_lock); |
20167d34 | 556 | last_map_addr = next; |
6ad91658 KM |
557 | continue; |
558 | } | |
559 | ||
dafe41ee | 560 | pmd = alloc_low_page(&pmd_phys); |
b27a43c1 SS |
561 | last_map_addr = phys_pmd_init(pmd, addr, end, page_size_mask, |
562 | prot); | |
4f9c11dd | 563 | unmap_low_page(pmd); |
8ae3a5a8 JB |
564 | |
565 | spin_lock(&init_mm.page_table_lock); | |
4f9c11dd | 566 | pud_populate(&init_mm, pud, __va(pmd_phys)); |
44df75e6 | 567 | spin_unlock(&init_mm.page_table_lock); |
1da177e4 | 568 | } |
1a2b4412 | 569 | __flush_tlb_all(); |
a2699e47 | 570 | |
ce0c0e50 | 571 | update_page_count(PG_LEVEL_1G, pages); |
cc615032 | 572 | |
1a0db38e | 573 | return last_map_addr; |
14a62c34 | 574 | } |
1da177e4 | 575 | |
41d840e2 | 576 | unsigned long __meminit |
f765090a PE |
577 | kernel_physical_mapping_init(unsigned long start, |
578 | unsigned long end, | |
579 | unsigned long page_size_mask) | |
14a62c34 | 580 | { |
9b861528 | 581 | bool pgd_changed = false; |
b50efd2a | 582 | unsigned long next, last_map_addr = end; |
9b861528 | 583 | unsigned long addr; |
1da177e4 LT |
584 | |
585 | start = (unsigned long)__va(start); | |
586 | end = (unsigned long)__va(end); | |
1c5f50ee | 587 | addr = start; |
1da177e4 LT |
588 | |
589 | for (; start < end; start = next) { | |
44df75e6 | 590 | pgd_t *pgd = pgd_offset_k(start); |
14a62c34 | 591 | unsigned long pud_phys; |
44df75e6 MT |
592 | pud_t *pud; |
593 | ||
e22146e6 | 594 | next = (start + PGDIR_SIZE) & PGDIR_MASK; |
4f9c11dd JF |
595 | if (next > end) |
596 | next = end; | |
597 | ||
598 | if (pgd_val(*pgd)) { | |
4b239f45 YL |
599 | pud = map_low_page((pud_t *)pgd_page_vaddr(*pgd)); |
600 | last_map_addr = phys_pud_init(pud, __pa(start), | |
b50efd2a | 601 | __pa(end), page_size_mask); |
4b239f45 | 602 | unmap_low_page(pud); |
4f9c11dd JF |
603 | continue; |
604 | } | |
605 | ||
8ae3a5a8 | 606 | pud = alloc_low_page(&pud_phys); |
b50efd2a YL |
607 | last_map_addr = phys_pud_init(pud, __pa(start), __pa(next), |
608 | page_size_mask); | |
4f9c11dd | 609 | unmap_low_page(pud); |
8ae3a5a8 JB |
610 | |
611 | spin_lock(&init_mm.page_table_lock); | |
612 | pgd_populate(&init_mm, pgd, __va(pud_phys)); | |
613 | spin_unlock(&init_mm.page_table_lock); | |
9b861528 | 614 | pgd_changed = true; |
14a62c34 | 615 | } |
9b861528 HL |
616 | |
617 | if (pgd_changed) | |
618 | sync_global_pgds(addr, end); | |
619 | ||
a2699e47 | 620 | __flush_tlb_all(); |
1da177e4 | 621 | |
b50efd2a YL |
622 | return last_map_addr; |
623 | } | |
7b16eb89 | 624 | |
2b97690f | 625 | #ifndef CONFIG_NUMA |
d8fc3afc | 626 | void __init initmem_init(void) |
1f75d7e3 | 627 | { |
0608f70c | 628 | memblock_set_node(0, (phys_addr_t)ULLONG_MAX, 0); |
1f75d7e3 | 629 | } |
3551f88f | 630 | #endif |
1f75d7e3 | 631 | |
1da177e4 LT |
632 | void __init paging_init(void) |
633 | { | |
3551f88f | 634 | sparse_memory_present_with_active_regions(MAX_NUMNODES); |
44df75e6 | 635 | sparse_init(); |
44b57280 YL |
636 | |
637 | /* | |
638 | * clear the default setting with node 0 | |
639 | * note: don't use nodes_clear here, that is really clearing when | |
640 | * numa support is not compiled in, and later node_set_state | |
641 | * will not set it back. | |
642 | */ | |
643 | node_clear_state(0, N_NORMAL_MEMORY); | |
644 | ||
4c0b2e5f | 645 | zone_sizes_init(); |
1da177e4 | 646 | } |
1da177e4 | 647 | |
44df75e6 MT |
648 | /* |
649 | * Memory hotplug specific functions | |
44df75e6 | 650 | */ |
bc02af93 | 651 | #ifdef CONFIG_MEMORY_HOTPLUG |
ea085417 SZ |
652 | /* |
653 | * After memory hotplug the variables max_pfn, max_low_pfn and high_memory need | |
654 | * updating. | |
655 | */ | |
656 | static void update_end_of_memory_vars(u64 start, u64 size) | |
657 | { | |
658 | unsigned long end_pfn = PFN_UP(start + size); | |
659 | ||
660 | if (end_pfn > max_pfn) { | |
661 | max_pfn = end_pfn; | |
662 | max_low_pfn = end_pfn; | |
663 | high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1; | |
664 | } | |
665 | } | |
666 | ||
9d99aaa3 AK |
667 | /* |
668 | * Memory is added always to NORMAL zone. This means you will never get | |
669 | * additional DMA/DMA32 memory. | |
670 | */ | |
bc02af93 | 671 | int arch_add_memory(int nid, u64 start, u64 size) |
44df75e6 | 672 | { |
bc02af93 | 673 | struct pglist_data *pgdat = NODE_DATA(nid); |
776ed98b | 674 | struct zone *zone = pgdat->node_zones + ZONE_NORMAL; |
66520ebc | 675 | unsigned long start_pfn = start >> PAGE_SHIFT; |
44df75e6 MT |
676 | unsigned long nr_pages = size >> PAGE_SHIFT; |
677 | int ret; | |
678 | ||
66520ebc | 679 | init_memory_mapping(start, start + size); |
45e0b78b | 680 | |
c04fc586 | 681 | ret = __add_pages(nid, zone, start_pfn, nr_pages); |
fe8b868e | 682 | WARN_ON_ONCE(ret); |
44df75e6 | 683 | |
ea085417 SZ |
684 | /* update max_pfn, max_low_pfn and high_memory */ |
685 | update_end_of_memory_vars(start, size); | |
686 | ||
44df75e6 | 687 | return ret; |
44df75e6 | 688 | } |
bc02af93 | 689 | EXPORT_SYMBOL_GPL(arch_add_memory); |
44df75e6 | 690 | |
45e0b78b KM |
691 | #endif /* CONFIG_MEMORY_HOTPLUG */ |
692 | ||
81ac3ad9 | 693 | static struct kcore_list kcore_vsyscall; |
1da177e4 LT |
694 | |
695 | void __init mem_init(void) | |
696 | { | |
0a43e4bf | 697 | long codesize, reservedpages, datasize, initsize; |
11a6b0c9 | 698 | unsigned long absent_pages; |
1da177e4 | 699 | |
0dc243ae | 700 | pci_iommu_alloc(); |
1da177e4 | 701 | |
48ddb154 | 702 | /* clear_bss() already clear the empty_zero_page */ |
1da177e4 LT |
703 | |
704 | reservedpages = 0; | |
705 | ||
706 | /* this will put all low memory onto the freelists */ | |
2b97690f | 707 | #ifdef CONFIG_NUMA |
0a43e4bf | 708 | totalram_pages = numa_free_all_bootmem(); |
1da177e4 | 709 | #else |
0a43e4bf | 710 | totalram_pages = free_all_bootmem(); |
1da177e4 | 711 | #endif |
11a6b0c9 YL |
712 | |
713 | absent_pages = absent_pages_in_range(0, max_pfn); | |
714 | reservedpages = max_pfn - totalram_pages - absent_pages; | |
1da177e4 LT |
715 | after_bootmem = 1; |
716 | ||
717 | codesize = (unsigned long) &_etext - (unsigned long) &_text; | |
718 | datasize = (unsigned long) &_edata - (unsigned long) &_etext; | |
719 | initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin; | |
720 | ||
721 | /* Register memory areas for /proc/kcore */ | |
14a62c34 | 722 | kclist_add(&kcore_vsyscall, (void *)VSYSCALL_START, |
c30bb2a2 | 723 | VSYSCALL_END - VSYSCALL_START, KCORE_OTHER); |
1da177e4 | 724 | |
10f22dde | 725 | printk(KERN_INFO "Memory: %luk/%luk available (%ldk kernel code, " |
11a6b0c9 | 726 | "%ldk absent, %ldk reserved, %ldk data, %ldk init)\n", |
cc013a88 | 727 | nr_free_pages() << (PAGE_SHIFT-10), |
c987d12f | 728 | max_pfn << (PAGE_SHIFT-10), |
1da177e4 | 729 | codesize >> 10, |
11a6b0c9 | 730 | absent_pages << (PAGE_SHIFT-10), |
1da177e4 LT |
731 | reservedpages << (PAGE_SHIFT-10), |
732 | datasize >> 10, | |
733 | initsize >> 10); | |
1da177e4 LT |
734 | } |
735 | ||
67df197b | 736 | #ifdef CONFIG_DEBUG_RODATA |
edeed305 AV |
737 | const int rodata_test_data = 0xC3; |
738 | EXPORT_SYMBOL_GPL(rodata_test_data); | |
67df197b | 739 | |
502f6604 | 740 | int kernel_set_to_readonly; |
16239630 SR |
741 | |
742 | void set_kernel_text_rw(void) | |
743 | { | |
b9af7c0d | 744 | unsigned long start = PFN_ALIGN(_text); |
e7d23dde | 745 | unsigned long end = PFN_ALIGN(__stop___ex_table); |
16239630 SR |
746 | |
747 | if (!kernel_set_to_readonly) | |
748 | return; | |
749 | ||
750 | pr_debug("Set kernel text: %lx - %lx for read write\n", | |
751 | start, end); | |
752 | ||
e7d23dde SS |
753 | /* |
754 | * Make the kernel identity mapping for text RW. Kernel text | |
755 | * mapping will always be RO. Refer to the comment in | |
756 | * static_protections() in pageattr.c | |
757 | */ | |
16239630 SR |
758 | set_memory_rw(start, (end - start) >> PAGE_SHIFT); |
759 | } | |
760 | ||
761 | void set_kernel_text_ro(void) | |
762 | { | |
b9af7c0d | 763 | unsigned long start = PFN_ALIGN(_text); |
e7d23dde | 764 | unsigned long end = PFN_ALIGN(__stop___ex_table); |
16239630 SR |
765 | |
766 | if (!kernel_set_to_readonly) | |
767 | return; | |
768 | ||
769 | pr_debug("Set kernel text: %lx - %lx for read only\n", | |
770 | start, end); | |
771 | ||
e7d23dde SS |
772 | /* |
773 | * Set the kernel identity mapping for text RO. | |
774 | */ | |
16239630 SR |
775 | set_memory_ro(start, (end - start) >> PAGE_SHIFT); |
776 | } | |
777 | ||
67df197b AV |
778 | void mark_rodata_ro(void) |
779 | { | |
74e08179 | 780 | unsigned long start = PFN_ALIGN(_text); |
8f0f996e SR |
781 | unsigned long rodata_start = |
782 | ((unsigned long)__start_rodata + PAGE_SIZE - 1) & PAGE_MASK; | |
74e08179 SS |
783 | unsigned long end = (unsigned long) &__end_rodata_hpage_align; |
784 | unsigned long text_end = PAGE_ALIGN((unsigned long) &__stop___ex_table); | |
785 | unsigned long rodata_end = PAGE_ALIGN((unsigned long) &__end_rodata); | |
786 | unsigned long data_start = (unsigned long) &_sdata; | |
8f0f996e | 787 | |
6fb14755 | 788 | printk(KERN_INFO "Write protecting the kernel read-only data: %luk\n", |
e3ebadd9 | 789 | (end - start) >> 10); |
984bb80d AV |
790 | set_memory_ro(start, (end - start) >> PAGE_SHIFT); |
791 | ||
16239630 SR |
792 | kernel_set_to_readonly = 1; |
793 | ||
984bb80d AV |
794 | /* |
795 | * The rodata section (but not the kernel text!) should also be | |
796 | * not-executable. | |
797 | */ | |
72b59d67 | 798 | set_memory_nx(rodata_start, (end - rodata_start) >> PAGE_SHIFT); |
67df197b | 799 | |
1a487252 AV |
800 | rodata_test(); |
801 | ||
0c42f392 | 802 | #ifdef CONFIG_CPA_DEBUG |
10f22dde | 803 | printk(KERN_INFO "Testing CPA: undo %lx-%lx\n", start, end); |
6d238cc4 | 804 | set_memory_rw(start, (end-start) >> PAGE_SHIFT); |
0c42f392 | 805 | |
10f22dde | 806 | printk(KERN_INFO "Testing CPA: again\n"); |
6d238cc4 | 807 | set_memory_ro(start, (end-start) >> PAGE_SHIFT); |
0c42f392 | 808 | #endif |
74e08179 SS |
809 | |
810 | free_init_pages("unused kernel memory", | |
811 | (unsigned long) page_address(virt_to_page(text_end)), | |
812 | (unsigned long) | |
813 | page_address(virt_to_page(rodata_start))); | |
814 | free_init_pages("unused kernel memory", | |
815 | (unsigned long) page_address(virt_to_page(rodata_end)), | |
816 | (unsigned long) page_address(virt_to_page(data_start))); | |
67df197b | 817 | } |
4e4eee0e | 818 | |
67df197b AV |
819 | #endif |
820 | ||
14a62c34 TG |
821 | int kern_addr_valid(unsigned long addr) |
822 | { | |
1da177e4 | 823 | unsigned long above = ((long)addr) >> __VIRTUAL_MASK_SHIFT; |
14a62c34 TG |
824 | pgd_t *pgd; |
825 | pud_t *pud; | |
826 | pmd_t *pmd; | |
827 | pte_t *pte; | |
1da177e4 LT |
828 | |
829 | if (above != 0 && above != -1UL) | |
14a62c34 TG |
830 | return 0; |
831 | ||
1da177e4 LT |
832 | pgd = pgd_offset_k(addr); |
833 | if (pgd_none(*pgd)) | |
834 | return 0; | |
835 | ||
836 | pud = pud_offset(pgd, addr); | |
837 | if (pud_none(*pud)) | |
14a62c34 | 838 | return 0; |
1da177e4 LT |
839 | |
840 | pmd = pmd_offset(pud, addr); | |
841 | if (pmd_none(*pmd)) | |
842 | return 0; | |
14a62c34 | 843 | |
1da177e4 LT |
844 | if (pmd_large(*pmd)) |
845 | return pfn_valid(pmd_pfn(*pmd)); | |
846 | ||
847 | pte = pte_offset_kernel(pmd, addr); | |
848 | if (pte_none(*pte)) | |
849 | return 0; | |
14a62c34 | 850 | |
1da177e4 LT |
851 | return pfn_valid(pte_pfn(*pte)); |
852 | } | |
853 | ||
14a62c34 TG |
854 | /* |
855 | * A pseudo VMA to allow ptrace access for the vsyscall page. This only | |
856 | * covers the 64bit vsyscall page now. 32bit has a real VMA now and does | |
857 | * not need special handling anymore: | |
858 | */ | |
1da177e4 | 859 | static struct vm_area_struct gate_vma = { |
14a62c34 TG |
860 | .vm_start = VSYSCALL_START, |
861 | .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE), | |
862 | .vm_page_prot = PAGE_READONLY_EXEC, | |
863 | .vm_flags = VM_READ | VM_EXEC | |
1da177e4 LT |
864 | }; |
865 | ||
31db58b3 | 866 | struct vm_area_struct *get_gate_vma(struct mm_struct *mm) |
1da177e4 LT |
867 | { |
868 | #ifdef CONFIG_IA32_EMULATION | |
31db58b3 | 869 | if (!mm || mm->context.ia32_compat) |
1e014410 | 870 | return NULL; |
1da177e4 LT |
871 | #endif |
872 | return &gate_vma; | |
873 | } | |
874 | ||
83b964bb | 875 | int in_gate_area(struct mm_struct *mm, unsigned long addr) |
1da177e4 | 876 | { |
83b964bb | 877 | struct vm_area_struct *vma = get_gate_vma(mm); |
14a62c34 | 878 | |
1e014410 AK |
879 | if (!vma) |
880 | return 0; | |
14a62c34 | 881 | |
1da177e4 LT |
882 | return (addr >= vma->vm_start) && (addr < vma->vm_end); |
883 | } | |
884 | ||
14a62c34 | 885 | /* |
cae5d390 SW |
886 | * Use this when you have no reliable mm, typically from interrupt |
887 | * context. It is less reliable than using a task's mm and may give | |
888 | * false positives. | |
1da177e4 | 889 | */ |
cae5d390 | 890 | int in_gate_area_no_mm(unsigned long addr) |
1da177e4 | 891 | { |
1e014410 | 892 | return (addr >= VSYSCALL_START) && (addr < VSYSCALL_END); |
1da177e4 | 893 | } |
2e1c49db | 894 | |
2aae950b AK |
895 | const char *arch_vma_name(struct vm_area_struct *vma) |
896 | { | |
897 | if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso) | |
898 | return "[vdso]"; | |
899 | if (vma == &gate_vma) | |
900 | return "[vsyscall]"; | |
901 | return NULL; | |
902 | } | |
0889eba5 | 903 | |
1dc41aa6 | 904 | #ifdef CONFIG_X86_UV |
1dc41aa6 NF |
905 | unsigned long memory_block_size_bytes(void) |
906 | { | |
907 | if (is_uv_system()) { | |
908 | printk(KERN_INFO "UV: memory block size 2GB\n"); | |
909 | return 2UL * 1024 * 1024 * 1024; | |
910 | } | |
911 | return MIN_MEMORY_BLOCK_SIZE; | |
912 | } | |
913 | #endif | |
914 | ||
0889eba5 CL |
915 | #ifdef CONFIG_SPARSEMEM_VMEMMAP |
916 | /* | |
917 | * Initialise the sparsemem vmemmap using huge-pages at the PMD level. | |
918 | */ | |
c2b91e2e YL |
919 | static long __meminitdata addr_start, addr_end; |
920 | static void __meminitdata *p_start, *p_end; | |
921 | static int __meminitdata node_start; | |
922 | ||
14a62c34 TG |
923 | int __meminit |
924 | vmemmap_populate(struct page *start_page, unsigned long size, int node) | |
0889eba5 CL |
925 | { |
926 | unsigned long addr = (unsigned long)start_page; | |
927 | unsigned long end = (unsigned long)(start_page + size); | |
928 | unsigned long next; | |
929 | pgd_t *pgd; | |
930 | pud_t *pud; | |
931 | pmd_t *pmd; | |
932 | ||
933 | for (; addr < end; addr = next) { | |
7c934d39 | 934 | void *p = NULL; |
0889eba5 CL |
935 | |
936 | pgd = vmemmap_pgd_populate(addr, node); | |
937 | if (!pgd) | |
938 | return -ENOMEM; | |
14a62c34 | 939 | |
0889eba5 CL |
940 | pud = vmemmap_pud_populate(pgd, addr, node); |
941 | if (!pud) | |
942 | return -ENOMEM; | |
943 | ||
7c934d39 JF |
944 | if (!cpu_has_pse) { |
945 | next = (addr + PAGE_SIZE) & PAGE_MASK; | |
946 | pmd = vmemmap_pmd_populate(pud, addr, node); | |
947 | ||
948 | if (!pmd) | |
949 | return -ENOMEM; | |
950 | ||
951 | p = vmemmap_pte_populate(pmd, addr, node); | |
14a62c34 | 952 | |
0889eba5 CL |
953 | if (!p) |
954 | return -ENOMEM; | |
955 | ||
7c934d39 JF |
956 | addr_end = addr + PAGE_SIZE; |
957 | p_end = p + PAGE_SIZE; | |
14a62c34 | 958 | } else { |
7c934d39 JF |
959 | next = pmd_addr_end(addr, end); |
960 | ||
961 | pmd = pmd_offset(pud, addr); | |
962 | if (pmd_none(*pmd)) { | |
963 | pte_t entry; | |
964 | ||
9bdac914 | 965 | p = vmemmap_alloc_block_buf(PMD_SIZE, node); |
7c934d39 JF |
966 | if (!p) |
967 | return -ENOMEM; | |
968 | ||
969 | entry = pfn_pte(__pa(p) >> PAGE_SHIFT, | |
970 | PAGE_KERNEL_LARGE); | |
971 | set_pmd(pmd, __pmd(pte_val(entry))); | |
972 | ||
7c934d39 JF |
973 | /* check to see if we have contiguous blocks */ |
974 | if (p_end != p || node_start != node) { | |
975 | if (p_start) | |
976 | printk(KERN_DEBUG " [%lx-%lx] PMD -> [%p-%p] on node %d\n", | |
977 | addr_start, addr_end-1, p_start, p_end-1, node_start); | |
978 | addr_start = addr; | |
979 | node_start = node; | |
980 | p_start = p; | |
981 | } | |
49c980df YL |
982 | |
983 | addr_end = addr + PMD_SIZE; | |
984 | p_end = p + PMD_SIZE; | |
7c934d39 JF |
985 | } else |
986 | vmemmap_verify((pte_t *)pmd, node, addr, next); | |
14a62c34 | 987 | } |
7c934d39 | 988 | |
0889eba5 | 989 | } |
9b861528 | 990 | sync_global_pgds((unsigned long)start_page, end); |
0889eba5 CL |
991 | return 0; |
992 | } | |
c2b91e2e YL |
993 | |
994 | void __meminit vmemmap_populate_print_last(void) | |
995 | { | |
996 | if (p_start) { | |
997 | printk(KERN_DEBUG " [%lx-%lx] PMD -> [%p-%p] on node %d\n", | |
998 | addr_start, addr_end-1, p_start, p_end-1, node_start); | |
999 | p_start = NULL; | |
1000 | p_end = NULL; | |
1001 | node_start = 0; | |
1002 | } | |
1003 | } | |
0889eba5 | 1004 | #endif |