Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/x86_64/mm/init.c |
| 3 | * |
| 4 | * Copyright (C) 1995 Linus Torvalds |
Pavel Machek | a253129 | 2010-07-18 14:27:13 +0200 | [diff] [blame] | 5 | * Copyright (C) 2000 Pavel Machek <pavel@ucw.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Copyright (C) 2002,2003 Andi Kleen <ak@suse.de> |
| 7 | */ |
| 8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Thomas Gleixner | 11034d5 | 2008-05-12 15:43:36 +0200 | [diff] [blame] | 21 | #include <linux/initrd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/pagemap.h> |
| 23 | #include <linux/bootmem.h> |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 24 | #include <linux/memblock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/proc_fs.h> |
Andi Kleen | 5917089 | 2005-11-05 17:25:53 +0100 | [diff] [blame] | 26 | #include <linux/pci.h> |
Jan Beulich | 6fb1475 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 27 | #include <linux/pfn.h> |
Randy Dunlap | c9cf552 | 2006-06-27 02:53:52 -0700 | [diff] [blame] | 28 | #include <linux/poison.h> |
Muli Ben-Yehuda | 17a941d | 2006-01-11 22:44:42 +0100 | [diff] [blame] | 29 | #include <linux/dma-mapping.h> |
Benjamin Herrenschmidt | a63fdc5 | 2011-06-14 10:57:50 +1000 | [diff] [blame] | 30 | #include <linux/memory.h> |
Matt Tolentino | 44df75e | 2006-01-17 07:03:41 +0100 | [diff] [blame] | 31 | #include <linux/memory_hotplug.h> |
Dan Williams | 4b94ffd | 2016-01-15 16:56:22 -0800 | [diff] [blame] | 32 | #include <linux/memremap.h> |
Konrad Rzeszutek | ae32b12 | 2007-05-02 19:27:11 +0200 | [diff] [blame] | 33 | #include <linux/nmi.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 34 | #include <linux/gfp.h> |
David Howells | 2f96b8c | 2013-04-12 00:10:25 +0100 | [diff] [blame] | 35 | #include <linux/kcore.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | #include <asm/processor.h> |
Ingo Molnar | 46eaa67 | 2008-10-12 15:06:29 +0200 | [diff] [blame] | 38 | #include <asm/bios_ebda.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 39 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <asm/pgtable.h> |
| 41 | #include <asm/pgalloc.h> |
| 42 | #include <asm/dma.h> |
| 43 | #include <asm/fixmap.h> |
Ingo Molnar | 66441bd | 2017-01-27 10:27:10 +0100 | [diff] [blame] | 44 | #include <asm/e820/api.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <asm/apic.h> |
| 46 | #include <asm/tlb.h> |
| 47 | #include <asm/mmu_context.h> |
| 48 | #include <asm/proto.h> |
| 49 | #include <asm/smp.h> |
Andi Kleen | 2bc0414 | 2005-11-05 17:25:53 +0100 | [diff] [blame] | 50 | #include <asm/sections.h> |
Thomas Gleixner | 718fc13 | 2008-01-30 13:30:17 +0100 | [diff] [blame] | 51 | #include <asm/kdebug.h> |
Thomas Gleixner | aaa64e0 | 2008-01-30 13:30:17 +0100 | [diff] [blame] | 52 | #include <asm/numa.h> |
Laura Abbott | d116365 | 2017-05-08 15:58:11 -0700 | [diff] [blame^] | 53 | #include <asm/set_memory.h> |
Pekka Enberg | 4fcb208 | 2009-03-05 14:55:08 +0200 | [diff] [blame] | 54 | #include <asm/init.h> |
Seth Jennings | 43c75f9 | 2015-11-30 10:47:43 -0600 | [diff] [blame] | 55 | #include <asm/uv/uv.h> |
Yinghai Lu | e5f15b4 | 2011-02-18 11:30:30 +0000 | [diff] [blame] | 56 | #include <asm/setup.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Yinghai Lu | 5c51bdb | 2012-11-16 19:39:01 -0800 | [diff] [blame] | 58 | #include "mm_internal.h" |
| 59 | |
Yinghai Lu | cf4fb15 | 2016-05-06 15:01:34 -0700 | [diff] [blame] | 60 | #include "ident_map.c" |
Yinghai Lu | aece278 | 2013-01-24 12:19:48 -0800 | [diff] [blame] | 61 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | /* |
| 63 | * NOTE: pagetable_init alloc all the fixmap pagetables contiguous on the |
| 64 | * physical space so we can cache the place of the first one and move |
| 65 | * around without checking the pgd every time. |
| 66 | */ |
| 67 | |
David Vrabel | f955371 | 2014-01-07 17:03:06 +0000 | [diff] [blame] | 68 | pteval_t __supported_pte_mask __read_mostly = ~0; |
Yinghai Lu | bd220a2 | 2008-09-05 00:58:28 -0700 | [diff] [blame] | 69 | EXPORT_SYMBOL_GPL(__supported_pte_mask); |
| 70 | |
Yinghai Lu | bd220a2 | 2008-09-05 00:58:28 -0700 | [diff] [blame] | 71 | int force_personality32; |
| 72 | |
Ingo Molnar | deed05b | 2008-09-05 10:23:26 +0200 | [diff] [blame] | 73 | /* |
| 74 | * noexec32=on|off |
| 75 | * Control non executable heap for 32bit processes. |
| 76 | * To control the stack too use noexec=off |
| 77 | * |
| 78 | * on PROT_READ does not imply PROT_EXEC for 32-bit processes (default) |
| 79 | * off PROT_READ implies PROT_EXEC |
| 80 | */ |
Yinghai Lu | bd220a2 | 2008-09-05 00:58:28 -0700 | [diff] [blame] | 81 | static int __init nonx32_setup(char *str) |
| 82 | { |
| 83 | if (!strcmp(str, "on")) |
| 84 | force_personality32 &= ~READ_IMPLIES_EXEC; |
| 85 | else if (!strcmp(str, "off")) |
| 86 | force_personality32 |= READ_IMPLIES_EXEC; |
| 87 | return 1; |
| 88 | } |
| 89 | __setup("noexec32=", nonx32_setup); |
| 90 | |
Marcin Slusarz | 8d6ea967 | 2008-08-15 18:32:24 +0200 | [diff] [blame] | 91 | /* |
Kirill A. Shutemov | 5372e15 | 2016-12-15 02:44:03 +0300 | [diff] [blame] | 92 | * When memory was added make sure all the processes MM have |
Haicheng Li | 6afb515 | 2010-05-19 17:42:14 +0800 | [diff] [blame] | 93 | * suitable PGD entries in the local PGD level page. |
| 94 | */ |
Kirill A. Shutemov | 5372e15 | 2016-12-15 02:44:03 +0300 | [diff] [blame] | 95 | void sync_global_pgds(unsigned long start, unsigned long end) |
Haicheng Li | 6afb515 | 2010-05-19 17:42:14 +0800 | [diff] [blame] | 96 | { |
Jeremy Fitzhardinge | 44235dc | 2010-10-14 17:04:59 -0700 | [diff] [blame] | 97 | unsigned long address; |
Haicheng Li | 6afb515 | 2010-05-19 17:42:14 +0800 | [diff] [blame] | 98 | |
Jeremy Fitzhardinge | 44235dc | 2010-10-14 17:04:59 -0700 | [diff] [blame] | 99 | for (address = start; address <= end; address += PGDIR_SIZE) { |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 100 | pgd_t *pgd_ref = pgd_offset_k(address); |
| 101 | const p4d_t *p4d_ref; |
Jeremy Fitzhardinge | 44235dc | 2010-10-14 17:04:59 -0700 | [diff] [blame] | 102 | struct page *page; |
Haicheng Li | 6afb515 | 2010-05-19 17:42:14 +0800 | [diff] [blame] | 103 | |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 104 | /* |
| 105 | * With folded p4d, pgd_none() is always false, we need to |
| 106 | * handle synchonization on p4d level. |
| 107 | */ |
| 108 | BUILD_BUG_ON(pgd_none(*pgd_ref)); |
| 109 | p4d_ref = p4d_offset(pgd_ref, address); |
| 110 | |
| 111 | if (p4d_none(*p4d_ref)) |
Jeremy Fitzhardinge | 44235dc | 2010-10-14 17:04:59 -0700 | [diff] [blame] | 112 | continue; |
Haicheng Li | 6afb515 | 2010-05-19 17:42:14 +0800 | [diff] [blame] | 113 | |
Andrea Arcangeli | a79e53d | 2011-02-16 15:45:22 -0800 | [diff] [blame] | 114 | spin_lock(&pgd_lock); |
Jeremy Fitzhardinge | 44235dc | 2010-10-14 17:04:59 -0700 | [diff] [blame] | 115 | list_for_each_entry(page, &pgd_list, lru) { |
Linus Torvalds | be354f4 | 2012-12-15 12:29:54 -0800 | [diff] [blame] | 116 | pgd_t *pgd; |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 117 | p4d_t *p4d; |
Jeremy Fitzhardinge | 617d34d | 2010-09-21 12:01:51 -0700 | [diff] [blame] | 118 | spinlock_t *pgt_lock; |
| 119 | |
Jeremy Fitzhardinge | 44235dc | 2010-10-14 17:04:59 -0700 | [diff] [blame] | 120 | pgd = (pgd_t *)page_address(page) + pgd_index(address); |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 121 | p4d = p4d_offset(pgd, address); |
Andrea Arcangeli | a79e53d | 2011-02-16 15:45:22 -0800 | [diff] [blame] | 122 | /* the pgt_lock only for Xen */ |
Jeremy Fitzhardinge | 617d34d | 2010-09-21 12:01:51 -0700 | [diff] [blame] | 123 | pgt_lock = &pgd_page_get_mm(page)->page_table_lock; |
| 124 | spin_lock(pgt_lock); |
| 125 | |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 126 | if (!p4d_none(*p4d_ref) && !p4d_none(*p4d)) |
| 127 | BUG_ON(p4d_page_vaddr(*p4d) |
| 128 | != p4d_page_vaddr(*p4d_ref)); |
Jeremy Fitzhardinge | 617d34d | 2010-09-21 12:01:51 -0700 | [diff] [blame] | 129 | |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 130 | if (p4d_none(*p4d)) |
| 131 | set_p4d(p4d, *p4d_ref); |
Yasuaki Ishimatsu | 9661d5b | 2014-08-22 13:27:34 -0700 | [diff] [blame] | 132 | |
Jeremy Fitzhardinge | 617d34d | 2010-09-21 12:01:51 -0700 | [diff] [blame] | 133 | spin_unlock(pgt_lock); |
Jeremy Fitzhardinge | 44235dc | 2010-10-14 17:04:59 -0700 | [diff] [blame] | 134 | } |
Andrea Arcangeli | a79e53d | 2011-02-16 15:45:22 -0800 | [diff] [blame] | 135 | spin_unlock(&pgd_lock); |
Jeremy Fitzhardinge | 44235dc | 2010-10-14 17:04:59 -0700 | [diff] [blame] | 136 | } |
Haicheng Li | 6afb515 | 2010-05-19 17:42:14 +0800 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /* |
Marcin Slusarz | 8d6ea967 | 2008-08-15 18:32:24 +0200 | [diff] [blame] | 140 | * NOTE: This function is marked __ref because it calls __init function |
| 141 | * (alloc_bootmem_pages). It's safe to do it ONLY when after_bootmem == 0. |
| 142 | */ |
| 143 | static __ref void *spp_getpage(void) |
Thomas Gleixner | 14a62c3 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 144 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | void *ptr; |
Thomas Gleixner | 14a62c3 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | if (after_bootmem) |
Vegard Nossum | 9e73023 | 2009-02-22 11:28:25 +0100 | [diff] [blame] | 148 | ptr = (void *) get_zeroed_page(GFP_ATOMIC | __GFP_NOTRACK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | else |
| 150 | ptr = alloc_bootmem_pages(PAGE_SIZE); |
Thomas Gleixner | 14a62c3 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 151 | |
| 152 | if (!ptr || ((unsigned long)ptr & ~PAGE_MASK)) { |
| 153 | panic("set_pte_phys: cannot allocate page data %s\n", |
| 154 | after_bootmem ? "after bootmem" : ""); |
| 155 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Ingo Molnar | 10f22dd | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 157 | pr_debug("spp_getpage %p\n", ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
Thomas Gleixner | 14a62c3 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 159 | return ptr; |
| 160 | } |
| 161 | |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 162 | static p4d_t *fill_p4d(pgd_t *pgd, unsigned long vaddr) |
Tejun Heo | 458a3e6 | 2009-02-24 11:57:21 +0900 | [diff] [blame] | 163 | { |
| 164 | if (pgd_none(*pgd)) { |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 165 | p4d_t *p4d = (p4d_t *)spp_getpage(); |
| 166 | pgd_populate(&init_mm, pgd, p4d); |
| 167 | if (p4d != p4d_offset(pgd, 0)) |
Tejun Heo | 458a3e6 | 2009-02-24 11:57:21 +0900 | [diff] [blame] | 168 | printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n", |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 169 | p4d, p4d_offset(pgd, 0)); |
Tejun Heo | 458a3e6 | 2009-02-24 11:57:21 +0900 | [diff] [blame] | 170 | } |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 171 | return p4d_offset(pgd, vaddr); |
| 172 | } |
| 173 | |
| 174 | static pud_t *fill_pud(p4d_t *p4d, unsigned long vaddr) |
| 175 | { |
| 176 | if (p4d_none(*p4d)) { |
| 177 | pud_t *pud = (pud_t *)spp_getpage(); |
| 178 | p4d_populate(&init_mm, p4d, pud); |
| 179 | if (pud != pud_offset(p4d, 0)) |
| 180 | printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n", |
| 181 | pud, pud_offset(p4d, 0)); |
| 182 | } |
| 183 | return pud_offset(p4d, vaddr); |
Tejun Heo | 458a3e6 | 2009-02-24 11:57:21 +0900 | [diff] [blame] | 184 | } |
| 185 | |
Jeremy Fitzhardinge | f254f39 | 2009-03-03 12:02:57 -0800 | [diff] [blame] | 186 | static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr) |
Tejun Heo | 458a3e6 | 2009-02-24 11:57:21 +0900 | [diff] [blame] | 187 | { |
| 188 | if (pud_none(*pud)) { |
| 189 | pmd_t *pmd = (pmd_t *) spp_getpage(); |
| 190 | pud_populate(&init_mm, pud, pmd); |
| 191 | if (pmd != pmd_offset(pud, 0)) |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 192 | printk(KERN_ERR "PAGETABLE BUG #02! %p <-> %p\n", |
Tejun Heo | 458a3e6 | 2009-02-24 11:57:21 +0900 | [diff] [blame] | 193 | pmd, pmd_offset(pud, 0)); |
| 194 | } |
| 195 | return pmd_offset(pud, vaddr); |
| 196 | } |
| 197 | |
Jeremy Fitzhardinge | f254f39 | 2009-03-03 12:02:57 -0800 | [diff] [blame] | 198 | static pte_t *fill_pte(pmd_t *pmd, unsigned long vaddr) |
Tejun Heo | 458a3e6 | 2009-02-24 11:57:21 +0900 | [diff] [blame] | 199 | { |
| 200 | if (pmd_none(*pmd)) { |
| 201 | pte_t *pte = (pte_t *) spp_getpage(); |
| 202 | pmd_populate_kernel(&init_mm, pmd, pte); |
| 203 | if (pte != pte_offset_kernel(pmd, 0)) |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 204 | printk(KERN_ERR "PAGETABLE BUG #03!\n"); |
Tejun Heo | 458a3e6 | 2009-02-24 11:57:21 +0900 | [diff] [blame] | 205 | } |
| 206 | return pte_offset_kernel(pmd, vaddr); |
| 207 | } |
| 208 | |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 209 | static void __set_pte_vaddr(pud_t *pud, unsigned long vaddr, pte_t new_pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | { |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 211 | pmd_t *pmd = fill_pmd(pud, vaddr); |
| 212 | pte_t *pte = fill_pte(pmd, vaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | set_pte(pte, new_pte); |
| 215 | |
| 216 | /* |
| 217 | * It's enough to flush this one mapping. |
| 218 | * (PGE mappings get flushed as well) |
| 219 | */ |
| 220 | __flush_tlb_one(vaddr); |
| 221 | } |
| 222 | |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 223 | void set_pte_vaddr_p4d(p4d_t *p4d_page, unsigned long vaddr, pte_t new_pte) |
| 224 | { |
| 225 | p4d_t *p4d = p4d_page + p4d_index(vaddr); |
| 226 | pud_t *pud = fill_pud(p4d, vaddr); |
| 227 | |
| 228 | __set_pte_vaddr(pud, vaddr, new_pte); |
| 229 | } |
| 230 | |
| 231 | void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte) |
| 232 | { |
| 233 | pud_t *pud = pud_page + pud_index(vaddr); |
| 234 | |
| 235 | __set_pte_vaddr(pud, vaddr, new_pte); |
| 236 | } |
| 237 | |
Tejun Heo | 458a3e6 | 2009-02-24 11:57:21 +0900 | [diff] [blame] | 238 | void set_pte_vaddr(unsigned long vaddr, pte_t pteval) |
Eduardo Habkost | 0814e0b | 2008-06-25 00:19:22 -0400 | [diff] [blame] | 239 | { |
| 240 | pgd_t *pgd; |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 241 | p4d_t *p4d_page; |
Eduardo Habkost | 0814e0b | 2008-06-25 00:19:22 -0400 | [diff] [blame] | 242 | |
| 243 | pr_debug("set_pte_vaddr %lx to %lx\n", vaddr, native_pte_val(pteval)); |
| 244 | |
| 245 | pgd = pgd_offset_k(vaddr); |
| 246 | if (pgd_none(*pgd)) { |
| 247 | printk(KERN_ERR |
| 248 | "PGD FIXMAP MISSING, it should be setup in head.S!\n"); |
| 249 | return; |
| 250 | } |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 251 | |
| 252 | p4d_page = p4d_offset(pgd, 0); |
| 253 | set_pte_vaddr_p4d(p4d_page, vaddr, pteval); |
Eduardo Habkost | 0814e0b | 2008-06-25 00:19:22 -0400 | [diff] [blame] | 254 | } |
| 255 | |
Tejun Heo | 458a3e6 | 2009-02-24 11:57:21 +0900 | [diff] [blame] | 256 | pmd_t * __init populate_extra_pmd(unsigned long vaddr) |
Tejun Heo | 1112441 | 2009-02-20 16:29:09 +0900 | [diff] [blame] | 257 | { |
| 258 | pgd_t *pgd; |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 259 | p4d_t *p4d; |
Tejun Heo | 1112441 | 2009-02-20 16:29:09 +0900 | [diff] [blame] | 260 | pud_t *pud; |
| 261 | |
| 262 | pgd = pgd_offset_k(vaddr); |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 263 | p4d = fill_p4d(pgd, vaddr); |
| 264 | pud = fill_pud(p4d, vaddr); |
Tejun Heo | 458a3e6 | 2009-02-24 11:57:21 +0900 | [diff] [blame] | 265 | return fill_pmd(pud, vaddr); |
| 266 | } |
Tejun Heo | 1112441 | 2009-02-20 16:29:09 +0900 | [diff] [blame] | 267 | |
Tejun Heo | 458a3e6 | 2009-02-24 11:57:21 +0900 | [diff] [blame] | 268 | pte_t * __init populate_extra_pte(unsigned long vaddr) |
| 269 | { |
| 270 | pmd_t *pmd; |
| 271 | |
| 272 | pmd = populate_extra_pmd(vaddr); |
| 273 | return fill_pte(pmd, vaddr); |
Tejun Heo | 1112441 | 2009-02-20 16:29:09 +0900 | [diff] [blame] | 274 | } |
| 275 | |
Thomas Gleixner | 31eedd8 | 2008-02-15 17:29:12 +0100 | [diff] [blame] | 276 | /* |
Jack Steiner | 3a9e189 | 2008-07-01 14:45:32 -0500 | [diff] [blame] | 277 | * Create large page table mappings for a range of physical addresses. |
| 278 | */ |
| 279 | static void __init __init_extra_mapping(unsigned long phys, unsigned long size, |
Juergen Gross | 2df58b6 | 2014-11-03 14:01:52 +0100 | [diff] [blame] | 280 | enum page_cache_mode cache) |
Jack Steiner | 3a9e189 | 2008-07-01 14:45:32 -0500 | [diff] [blame] | 281 | { |
| 282 | pgd_t *pgd; |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 283 | p4d_t *p4d; |
Jack Steiner | 3a9e189 | 2008-07-01 14:45:32 -0500 | [diff] [blame] | 284 | pud_t *pud; |
| 285 | pmd_t *pmd; |
Juergen Gross | 2df58b6 | 2014-11-03 14:01:52 +0100 | [diff] [blame] | 286 | pgprot_t prot; |
Jack Steiner | 3a9e189 | 2008-07-01 14:45:32 -0500 | [diff] [blame] | 287 | |
Juergen Gross | 2df58b6 | 2014-11-03 14:01:52 +0100 | [diff] [blame] | 288 | pgprot_val(prot) = pgprot_val(PAGE_KERNEL_LARGE) | |
| 289 | pgprot_val(pgprot_4k_2_large(cachemode2pgprot(cache))); |
Jack Steiner | 3a9e189 | 2008-07-01 14:45:32 -0500 | [diff] [blame] | 290 | BUG_ON((phys & ~PMD_MASK) || (size & ~PMD_MASK)); |
| 291 | for (; size; phys += PMD_SIZE, size -= PMD_SIZE) { |
| 292 | pgd = pgd_offset_k((unsigned long)__va(phys)); |
| 293 | if (pgd_none(*pgd)) { |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 294 | p4d = (p4d_t *) spp_getpage(); |
| 295 | set_pgd(pgd, __pgd(__pa(p4d) | _KERNPG_TABLE | |
Jack Steiner | 3a9e189 | 2008-07-01 14:45:32 -0500 | [diff] [blame] | 296 | _PAGE_USER)); |
| 297 | } |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 298 | p4d = p4d_offset(pgd, (unsigned long)__va(phys)); |
| 299 | if (p4d_none(*p4d)) { |
| 300 | pud = (pud_t *) spp_getpage(); |
| 301 | set_p4d(p4d, __p4d(__pa(pud) | _KERNPG_TABLE | |
| 302 | _PAGE_USER)); |
| 303 | } |
| 304 | pud = pud_offset(p4d, (unsigned long)__va(phys)); |
Jack Steiner | 3a9e189 | 2008-07-01 14:45:32 -0500 | [diff] [blame] | 305 | if (pud_none(*pud)) { |
| 306 | pmd = (pmd_t *) spp_getpage(); |
| 307 | set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE | |
| 308 | _PAGE_USER)); |
| 309 | } |
| 310 | pmd = pmd_offset(pud, phys); |
| 311 | BUG_ON(!pmd_none(*pmd)); |
| 312 | set_pmd(pmd, __pmd(phys | pgprot_val(prot))); |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | void __init init_extra_mapping_wb(unsigned long phys, unsigned long size) |
| 317 | { |
Juergen Gross | 2df58b6 | 2014-11-03 14:01:52 +0100 | [diff] [blame] | 318 | __init_extra_mapping(phys, size, _PAGE_CACHE_MODE_WB); |
Jack Steiner | 3a9e189 | 2008-07-01 14:45:32 -0500 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | void __init init_extra_mapping_uc(unsigned long phys, unsigned long size) |
| 322 | { |
Juergen Gross | 2df58b6 | 2014-11-03 14:01:52 +0100 | [diff] [blame] | 323 | __init_extra_mapping(phys, size, _PAGE_CACHE_MODE_UC); |
Jack Steiner | 3a9e189 | 2008-07-01 14:45:32 -0500 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | /* |
Ingo Molnar | 88f3aec | 2008-02-21 11:04:11 +0100 | [diff] [blame] | 327 | * The head.S code sets up the kernel high mapping: |
| 328 | * |
| 329 | * from __START_KERNEL_map to __START_KERNEL_map + size (== _end-_text) |
Thomas Gleixner | 31eedd8 | 2008-02-15 17:29:12 +0100 | [diff] [blame] | 330 | * |
Zhang Yanfei | 1e3b308 | 2013-05-15 10:58:07 +0800 | [diff] [blame] | 331 | * phys_base holds the negative offset to the kernel, which is added |
Thomas Gleixner | 31eedd8 | 2008-02-15 17:29:12 +0100 | [diff] [blame] | 332 | * to the compile time generated pmds. This results in invalid pmds up |
| 333 | * to the point where we hit the physaddr 0 mapping. |
| 334 | * |
Yinghai Lu | e5f15b4 | 2011-02-18 11:30:30 +0000 | [diff] [blame] | 335 | * We limit the mappings to the region from _text to _brk_end. _brk_end |
| 336 | * is rounded up to the 2MB boundary. This catches the invalid pmds as |
Thomas Gleixner | 31eedd8 | 2008-02-15 17:29:12 +0100 | [diff] [blame] | 337 | * well, as they are located before _text: |
| 338 | */ |
| 339 | void __init cleanup_highmap(void) |
| 340 | { |
| 341 | unsigned long vaddr = __START_KERNEL_map; |
Yinghai Lu | 1005423 | 2013-01-24 12:19:54 -0800 | [diff] [blame] | 342 | unsigned long vaddr_end = __START_KERNEL_map + KERNEL_IMAGE_SIZE; |
Yinghai Lu | e5f15b4 | 2011-02-18 11:30:30 +0000 | [diff] [blame] | 343 | unsigned long end = roundup((unsigned long)_brk_end, PMD_SIZE) - 1; |
Thomas Gleixner | 31eedd8 | 2008-02-15 17:29:12 +0100 | [diff] [blame] | 344 | pmd_t *pmd = level2_kernel_pgt; |
Thomas Gleixner | 31eedd8 | 2008-02-15 17:29:12 +0100 | [diff] [blame] | 345 | |
Yinghai Lu | 1005423 | 2013-01-24 12:19:54 -0800 | [diff] [blame] | 346 | /* |
| 347 | * Native path, max_pfn_mapped is not set yet. |
| 348 | * Xen has valid max_pfn_mapped set in |
| 349 | * arch/x86/xen/mmu.c:xen_setup_kernel_pagetable(). |
| 350 | */ |
| 351 | if (max_pfn_mapped) |
| 352 | vaddr_end = __START_KERNEL_map + (max_pfn_mapped << PAGE_SHIFT); |
| 353 | |
Yinghai Lu | e5f15b4 | 2011-02-18 11:30:30 +0000 | [diff] [blame] | 354 | for (; vaddr + PMD_SIZE - 1 < vaddr_end; pmd++, vaddr += PMD_SIZE) { |
Hugh Dickins | 2884f11 | 2008-05-28 19:36:07 +0100 | [diff] [blame] | 355 | if (pmd_none(*pmd)) |
Thomas Gleixner | 31eedd8 | 2008-02-15 17:29:12 +0100 | [diff] [blame] | 356 | continue; |
| 357 | if (vaddr < (unsigned long) _text || vaddr > end) |
| 358 | set_pmd(pmd, __pmd(0)); |
| 359 | } |
| 360 | } |
| 361 | |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 362 | /* |
| 363 | * Create PTE level page table mapping for physical addresses. |
| 364 | * It returns the last physical address mapped. |
| 365 | */ |
Yinghai Lu | 7b16eb8 | 2008-07-09 20:15:02 -0700 | [diff] [blame] | 366 | static unsigned long __meminit |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 367 | phys_pte_init(pte_t *pte_page, unsigned long paddr, unsigned long paddr_end, |
Suresh Siddha | b27a43c | 2008-10-07 13:58:46 -0700 | [diff] [blame] | 368 | pgprot_t prot) |
Jeremy Fitzhardinge | 4f9c11d | 2008-06-25 00:19:19 -0400 | [diff] [blame] | 369 | { |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 370 | unsigned long pages = 0, paddr_next; |
| 371 | unsigned long paddr_last = paddr_end; |
| 372 | pte_t *pte; |
Jeremy Fitzhardinge | 4f9c11d | 2008-06-25 00:19:19 -0400 | [diff] [blame] | 373 | int i; |
Yinghai Lu | 7b16eb8 | 2008-07-09 20:15:02 -0700 | [diff] [blame] | 374 | |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 375 | pte = pte_page + pte_index(paddr); |
| 376 | i = pte_index(paddr); |
Jeremy Fitzhardinge | 4f9c11d | 2008-06-25 00:19:19 -0400 | [diff] [blame] | 377 | |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 378 | for (; i < PTRS_PER_PTE; i++, paddr = paddr_next, pte++) { |
| 379 | paddr_next = (paddr & PAGE_MASK) + PAGE_SIZE; |
| 380 | if (paddr >= paddr_end) { |
Yinghai Lu | eceb363 | 2012-11-16 19:38:56 -0800 | [diff] [blame] | 381 | if (!after_bootmem && |
Ingo Molnar | 3bce64f | 2017-01-28 14:14:25 +0100 | [diff] [blame] | 382 | !e820__mapped_any(paddr & PAGE_MASK, paddr_next, |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 383 | E820_TYPE_RAM) && |
Ingo Molnar | 3bce64f | 2017-01-28 14:14:25 +0100 | [diff] [blame] | 384 | !e820__mapped_any(paddr & PAGE_MASK, paddr_next, |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 385 | E820_TYPE_RESERVED_KERN)) |
Yinghai Lu | eceb363 | 2012-11-16 19:38:56 -0800 | [diff] [blame] | 386 | set_pte(pte, __pte(0)); |
| 387 | continue; |
Jeremy Fitzhardinge | 4f9c11d | 2008-06-25 00:19:19 -0400 | [diff] [blame] | 388 | } |
| 389 | |
Suresh Siddha | b27a43c | 2008-10-07 13:58:46 -0700 | [diff] [blame] | 390 | /* |
| 391 | * We will re-use the existing mapping. |
| 392 | * Xen for example has some special requirements, like mapping |
| 393 | * pagetable pages as RO. So assume someone who pre-setup |
| 394 | * these mappings are more intelligent. |
| 395 | */ |
Dave Hansen | dcb32d9 | 2016-07-07 17:19:15 -0700 | [diff] [blame] | 396 | if (!pte_none(*pte)) { |
Jan Beulich | 876ee61 | 2012-10-04 14:48:10 +0100 | [diff] [blame] | 397 | if (!after_bootmem) |
| 398 | pages++; |
Jeremy Fitzhardinge | 4f9c11d | 2008-06-25 00:19:19 -0400 | [diff] [blame] | 399 | continue; |
Yinghai Lu | 3afa394 | 2008-10-25 22:58:21 -0700 | [diff] [blame] | 400 | } |
Jeremy Fitzhardinge | 4f9c11d | 2008-06-25 00:19:19 -0400 | [diff] [blame] | 401 | |
| 402 | if (0) |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 403 | pr_info(" pte=%p addr=%lx pte=%016lx\n", pte, paddr, |
| 404 | pfn_pte(paddr >> PAGE_SHIFT, PAGE_KERNEL).pte); |
Jeremy Fitzhardinge | 4f9c11d | 2008-06-25 00:19:19 -0400 | [diff] [blame] | 405 | pages++; |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 406 | set_pte(pte, pfn_pte(paddr >> PAGE_SHIFT, prot)); |
| 407 | paddr_last = (paddr & PAGE_MASK) + PAGE_SIZE; |
Jeremy Fitzhardinge | 4f9c11d | 2008-06-25 00:19:19 -0400 | [diff] [blame] | 408 | } |
Suresh Siddha | a2699e4 | 2008-09-23 14:00:38 -0700 | [diff] [blame] | 409 | |
Jeremy Fitzhardinge | 4f9c11d | 2008-06-25 00:19:19 -0400 | [diff] [blame] | 410 | update_page_count(PG_LEVEL_4K, pages); |
Yinghai Lu | 7b16eb8 | 2008-07-09 20:15:02 -0700 | [diff] [blame] | 411 | |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 412 | return paddr_last; |
Jeremy Fitzhardinge | 4f9c11d | 2008-06-25 00:19:19 -0400 | [diff] [blame] | 413 | } |
| 414 | |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 415 | /* |
| 416 | * Create PMD level page table mapping for physical addresses. The virtual |
| 417 | * and physical address have to be aligned at this level. |
| 418 | * It returns the last physical address mapped. |
| 419 | */ |
Yinghai Lu | 7b16eb8 | 2008-07-09 20:15:02 -0700 | [diff] [blame] | 420 | static unsigned long __meminit |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 421 | phys_pmd_init(pmd_t *pmd_page, unsigned long paddr, unsigned long paddr_end, |
Suresh Siddha | b27a43c | 2008-10-07 13:58:46 -0700 | [diff] [blame] | 422 | unsigned long page_size_mask, pgprot_t prot) |
Matt Tolentino | 44df75e | 2006-01-17 07:03:41 +0100 | [diff] [blame] | 423 | { |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 424 | unsigned long pages = 0, paddr_next; |
| 425 | unsigned long paddr_last = paddr_end; |
Andi Kleen | ce0c0e5 | 2008-05-02 11:46:49 +0200 | [diff] [blame] | 426 | |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 427 | int i = pmd_index(paddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 429 | for (; i < PTRS_PER_PMD; i++, paddr = paddr_next) { |
| 430 | pmd_t *pmd = pmd_page + pmd_index(paddr); |
Jeremy Fitzhardinge | 4f9c11d | 2008-06-25 00:19:19 -0400 | [diff] [blame] | 431 | pte_t *pte; |
Suresh Siddha | b27a43c | 2008-10-07 13:58:46 -0700 | [diff] [blame] | 432 | pgprot_t new_prot = prot; |
Matt Tolentino | 44df75e | 2006-01-17 07:03:41 +0100 | [diff] [blame] | 433 | |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 434 | paddr_next = (paddr & PMD_MASK) + PMD_SIZE; |
| 435 | if (paddr >= paddr_end) { |
Yinghai Lu | eceb363 | 2012-11-16 19:38:56 -0800 | [diff] [blame] | 436 | if (!after_bootmem && |
Ingo Molnar | 3bce64f | 2017-01-28 14:14:25 +0100 | [diff] [blame] | 437 | !e820__mapped_any(paddr & PMD_MASK, paddr_next, |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 438 | E820_TYPE_RAM) && |
Ingo Molnar | 3bce64f | 2017-01-28 14:14:25 +0100 | [diff] [blame] | 439 | !e820__mapped_any(paddr & PMD_MASK, paddr_next, |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 440 | E820_TYPE_RESERVED_KERN)) |
Yinghai Lu | eceb363 | 2012-11-16 19:38:56 -0800 | [diff] [blame] | 441 | set_pmd(pmd, __pmd(0)); |
| 442 | continue; |
| 443 | } |
Jan Beulich | 20167d3 | 2012-05-16 14:06:26 +0100 | [diff] [blame] | 444 | |
Dave Hansen | dcb32d9 | 2016-07-07 17:19:15 -0700 | [diff] [blame] | 445 | if (!pmd_none(*pmd)) { |
Jan Beulich | 8ae3a5a | 2008-08-21 14:27:22 +0100 | [diff] [blame] | 446 | if (!pmd_large(*pmd)) { |
| 447 | spin_lock(&init_mm.page_table_lock); |
Yinghai Lu | 973dc4f | 2012-11-16 19:38:59 -0800 | [diff] [blame] | 448 | pte = (pte_t *)pmd_page_vaddr(*pmd); |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 449 | paddr_last = phys_pte_init(pte, paddr, |
| 450 | paddr_end, prot); |
Jan Beulich | 8ae3a5a | 2008-08-21 14:27:22 +0100 | [diff] [blame] | 451 | spin_unlock(&init_mm.page_table_lock); |
Suresh Siddha | a2699e4 | 2008-09-23 14:00:38 -0700 | [diff] [blame] | 452 | continue; |
Jan Beulich | 8ae3a5a | 2008-08-21 14:27:22 +0100 | [diff] [blame] | 453 | } |
Suresh Siddha | b27a43c | 2008-10-07 13:58:46 -0700 | [diff] [blame] | 454 | /* |
| 455 | * If we are ok with PG_LEVEL_2M mapping, then we will |
| 456 | * use the existing mapping, |
| 457 | * |
| 458 | * Otherwise, we will split the large page mapping but |
| 459 | * use the same existing protection bits except for |
| 460 | * large page, so that we don't violate Intel's TLB |
| 461 | * Application note (317080) which says, while changing |
| 462 | * the page sizes, new and old translations should |
| 463 | * not differ with respect to page frame and |
| 464 | * attributes. |
| 465 | */ |
Yinghai Lu | 3afa394 | 2008-10-25 22:58:21 -0700 | [diff] [blame] | 466 | if (page_size_mask & (1 << PG_LEVEL_2M)) { |
Jan Beulich | 876ee61 | 2012-10-04 14:48:10 +0100 | [diff] [blame] | 467 | if (!after_bootmem) |
| 468 | pages++; |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 469 | paddr_last = paddr_next; |
Suresh Siddha | b27a43c | 2008-10-07 13:58:46 -0700 | [diff] [blame] | 470 | continue; |
Yinghai Lu | 3afa394 | 2008-10-25 22:58:21 -0700 | [diff] [blame] | 471 | } |
Suresh Siddha | b27a43c | 2008-10-07 13:58:46 -0700 | [diff] [blame] | 472 | new_prot = pte_pgprot(pte_clrhuge(*(pte_t *)pmd)); |
Jeremy Fitzhardinge | 4f9c11d | 2008-06-25 00:19:19 -0400 | [diff] [blame] | 473 | } |
Keith Mannthey | 6ad9165 | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 474 | |
Yinghai Lu | b50efd2 | 2008-07-08 01:41:05 -0700 | [diff] [blame] | 475 | if (page_size_mask & (1<<PG_LEVEL_2M)) { |
Jeremy Fitzhardinge | 4f9c11d | 2008-06-25 00:19:19 -0400 | [diff] [blame] | 476 | pages++; |
Jan Beulich | 8ae3a5a | 2008-08-21 14:27:22 +0100 | [diff] [blame] | 477 | spin_lock(&init_mm.page_table_lock); |
Jeremy Fitzhardinge | 4f9c11d | 2008-06-25 00:19:19 -0400 | [diff] [blame] | 478 | set_pte((pte_t *)pmd, |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 479 | pfn_pte((paddr & PMD_MASK) >> PAGE_SHIFT, |
Suresh Siddha | b27a43c | 2008-10-07 13:58:46 -0700 | [diff] [blame] | 480 | __pgprot(pgprot_val(prot) | _PAGE_PSE))); |
Jan Beulich | 8ae3a5a | 2008-08-21 14:27:22 +0100 | [diff] [blame] | 481 | spin_unlock(&init_mm.page_table_lock); |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 482 | paddr_last = paddr_next; |
Jeremy Fitzhardinge | 4f9c11d | 2008-06-25 00:19:19 -0400 | [diff] [blame] | 483 | continue; |
| 484 | } |
| 485 | |
Yinghai Lu | 868bf4d | 2012-11-16 19:39:00 -0800 | [diff] [blame] | 486 | pte = alloc_low_page(); |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 487 | paddr_last = phys_pte_init(pte, paddr, paddr_end, new_prot); |
Jeremy Fitzhardinge | 4f9c11d | 2008-06-25 00:19:19 -0400 | [diff] [blame] | 488 | |
Jan Beulich | 8ae3a5a | 2008-08-21 14:27:22 +0100 | [diff] [blame] | 489 | spin_lock(&init_mm.page_table_lock); |
Yinghai Lu | 868bf4d | 2012-11-16 19:39:00 -0800 | [diff] [blame] | 490 | pmd_populate_kernel(&init_mm, pmd, pte); |
Jan Beulich | 8ae3a5a | 2008-08-21 14:27:22 +0100 | [diff] [blame] | 491 | spin_unlock(&init_mm.page_table_lock); |
Matt Tolentino | 44df75e | 2006-01-17 07:03:41 +0100 | [diff] [blame] | 492 | } |
Andi Kleen | ce0c0e5 | 2008-05-02 11:46:49 +0200 | [diff] [blame] | 493 | update_page_count(PG_LEVEL_2M, pages); |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 494 | return paddr_last; |
Matt Tolentino | 44df75e | 2006-01-17 07:03:41 +0100 | [diff] [blame] | 495 | } |
| 496 | |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 497 | /* |
| 498 | * Create PUD level page table mapping for physical addresses. The virtual |
Thomas Garnier | faa3793 | 2016-06-21 17:47:00 -0700 | [diff] [blame] | 499 | * and physical address do not have to be aligned at this level. KASLR can |
| 500 | * randomize virtual addresses up to this level. |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 501 | * It returns the last physical address mapped. |
| 502 | */ |
Andi Kleen | cc61503 | 2008-03-12 03:53:28 +0100 | [diff] [blame] | 503 | static unsigned long __meminit |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 504 | phys_pud_init(pud_t *pud_page, unsigned long paddr, unsigned long paddr_end, |
| 505 | unsigned long page_size_mask) |
Thomas Gleixner | 14a62c3 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 506 | { |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 507 | unsigned long pages = 0, paddr_next; |
| 508 | unsigned long paddr_last = paddr_end; |
Thomas Garnier | faa3793 | 2016-06-21 17:47:00 -0700 | [diff] [blame] | 509 | unsigned long vaddr = (unsigned long)__va(paddr); |
| 510 | int i = pud_index(vaddr); |
Matt Tolentino | 44df75e | 2006-01-17 07:03:41 +0100 | [diff] [blame] | 511 | |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 512 | for (; i < PTRS_PER_PUD; i++, paddr = paddr_next) { |
Thomas Garnier | faa3793 | 2016-06-21 17:47:00 -0700 | [diff] [blame] | 513 | pud_t *pud; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | pmd_t *pmd; |
Suresh Siddha | b27a43c | 2008-10-07 13:58:46 -0700 | [diff] [blame] | 515 | pgprot_t prot = PAGE_KERNEL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | |
Thomas Garnier | faa3793 | 2016-06-21 17:47:00 -0700 | [diff] [blame] | 517 | vaddr = (unsigned long)__va(paddr); |
| 518 | pud = pud_page + pud_index(vaddr); |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 519 | paddr_next = (paddr & PUD_MASK) + PUD_SIZE; |
Thomas Garnier | faa3793 | 2016-06-21 17:47:00 -0700 | [diff] [blame] | 520 | |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 521 | if (paddr >= paddr_end) { |
Yinghai Lu | eceb363 | 2012-11-16 19:38:56 -0800 | [diff] [blame] | 522 | if (!after_bootmem && |
Ingo Molnar | 3bce64f | 2017-01-28 14:14:25 +0100 | [diff] [blame] | 523 | !e820__mapped_any(paddr & PUD_MASK, paddr_next, |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 524 | E820_TYPE_RAM) && |
Ingo Molnar | 3bce64f | 2017-01-28 14:14:25 +0100 | [diff] [blame] | 525 | !e820__mapped_any(paddr & PUD_MASK, paddr_next, |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 526 | E820_TYPE_RESERVED_KERN)) |
Yinghai Lu | eceb363 | 2012-11-16 19:38:56 -0800 | [diff] [blame] | 527 | set_pud(pud, __pud(0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | continue; |
Thomas Gleixner | 14a62c3 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 529 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | |
Dave Hansen | dcb32d9 | 2016-07-07 17:19:15 -0700 | [diff] [blame] | 531 | if (!pud_none(*pud)) { |
Suresh Siddha | a2699e4 | 2008-09-23 14:00:38 -0700 | [diff] [blame] | 532 | if (!pud_large(*pud)) { |
Yinghai Lu | 973dc4f | 2012-11-16 19:38:59 -0800 | [diff] [blame] | 533 | pmd = pmd_offset(pud, 0); |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 534 | paddr_last = phys_pmd_init(pmd, paddr, |
| 535 | paddr_end, |
| 536 | page_size_mask, |
| 537 | prot); |
Yinghai Lu | 4b239f4 | 2010-12-17 16:58:28 -0800 | [diff] [blame] | 538 | __flush_tlb_all(); |
Suresh Siddha | a2699e4 | 2008-09-23 14:00:38 -0700 | [diff] [blame] | 539 | continue; |
| 540 | } |
Suresh Siddha | b27a43c | 2008-10-07 13:58:46 -0700 | [diff] [blame] | 541 | /* |
| 542 | * If we are ok with PG_LEVEL_1G mapping, then we will |
| 543 | * use the existing mapping. |
| 544 | * |
| 545 | * Otherwise, we will split the gbpage mapping but use |
| 546 | * the same existing protection bits except for large |
| 547 | * page, so that we don't violate Intel's TLB |
| 548 | * Application note (317080) which says, while changing |
| 549 | * the page sizes, new and old translations should |
| 550 | * not differ with respect to page frame and |
| 551 | * attributes. |
| 552 | */ |
Yinghai Lu | 3afa394 | 2008-10-25 22:58:21 -0700 | [diff] [blame] | 553 | if (page_size_mask & (1 << PG_LEVEL_1G)) { |
Jan Beulich | 876ee61 | 2012-10-04 14:48:10 +0100 | [diff] [blame] | 554 | if (!after_bootmem) |
| 555 | pages++; |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 556 | paddr_last = paddr_next; |
Suresh Siddha | b27a43c | 2008-10-07 13:58:46 -0700 | [diff] [blame] | 557 | continue; |
Yinghai Lu | 3afa394 | 2008-10-25 22:58:21 -0700 | [diff] [blame] | 558 | } |
Suresh Siddha | b27a43c | 2008-10-07 13:58:46 -0700 | [diff] [blame] | 559 | prot = pte_pgprot(pte_clrhuge(*(pte_t *)pud)); |
Andi Kleen | ef92576 | 2008-04-17 17:40:45 +0200 | [diff] [blame] | 560 | } |
| 561 | |
Yinghai Lu | b50efd2 | 2008-07-08 01:41:05 -0700 | [diff] [blame] | 562 | if (page_size_mask & (1<<PG_LEVEL_1G)) { |
Andi Kleen | ce0c0e5 | 2008-05-02 11:46:49 +0200 | [diff] [blame] | 563 | pages++; |
Jan Beulich | 8ae3a5a | 2008-08-21 14:27:22 +0100 | [diff] [blame] | 564 | spin_lock(&init_mm.page_table_lock); |
Andi Kleen | ef92576 | 2008-04-17 17:40:45 +0200 | [diff] [blame] | 565 | set_pte((pte_t *)pud, |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 566 | pfn_pte((paddr & PUD_MASK) >> PAGE_SHIFT, |
Yinghai Lu | 960ddb4f | 2012-11-16 19:38:54 -0800 | [diff] [blame] | 567 | PAGE_KERNEL_LARGE)); |
Jan Beulich | 8ae3a5a | 2008-08-21 14:27:22 +0100 | [diff] [blame] | 568 | spin_unlock(&init_mm.page_table_lock); |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 569 | paddr_last = paddr_next; |
Keith Mannthey | 6ad9165 | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 570 | continue; |
| 571 | } |
| 572 | |
Yinghai Lu | 868bf4d | 2012-11-16 19:39:00 -0800 | [diff] [blame] | 573 | pmd = alloc_low_page(); |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 574 | paddr_last = phys_pmd_init(pmd, paddr, paddr_end, |
| 575 | page_size_mask, prot); |
Jan Beulich | 8ae3a5a | 2008-08-21 14:27:22 +0100 | [diff] [blame] | 576 | |
| 577 | spin_lock(&init_mm.page_table_lock); |
Yinghai Lu | 868bf4d | 2012-11-16 19:39:00 -0800 | [diff] [blame] | 578 | pud_populate(&init_mm, pud, pmd); |
Matt Tolentino | 44df75e | 2006-01-17 07:03:41 +0100 | [diff] [blame] | 579 | spin_unlock(&init_mm.page_table_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | } |
Andi Kleen | 1a2b441 | 2008-01-30 13:33:54 +0100 | [diff] [blame] | 581 | __flush_tlb_all(); |
Suresh Siddha | a2699e4 | 2008-09-23 14:00:38 -0700 | [diff] [blame] | 582 | |
Andi Kleen | ce0c0e5 | 2008-05-02 11:46:49 +0200 | [diff] [blame] | 583 | update_page_count(PG_LEVEL_1G, pages); |
Andi Kleen | cc61503 | 2008-03-12 03:53:28 +0100 | [diff] [blame] | 584 | |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 585 | return paddr_last; |
Thomas Gleixner | 14a62c3 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 586 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 588 | /* |
| 589 | * Create page table mapping for the physical memory for specific physical |
Thomas Garnier | faa3793 | 2016-06-21 17:47:00 -0700 | [diff] [blame] | 590 | * addresses. The virtual and physical addresses have to be aligned on PMD level |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 591 | * down. It returns the last physical address mapped. |
| 592 | */ |
Shaohua Li | 41d840e | 2009-06-12 12:57:52 +0800 | [diff] [blame] | 593 | unsigned long __meminit |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 594 | kernel_physical_mapping_init(unsigned long paddr_start, |
| 595 | unsigned long paddr_end, |
Pekka Enberg | f765090 | 2009-03-05 14:55:05 +0200 | [diff] [blame] | 596 | unsigned long page_size_mask) |
Yinghai Lu | b50efd2 | 2008-07-08 01:41:05 -0700 | [diff] [blame] | 597 | { |
Haicheng Li | 9b86152 | 2010-08-20 17:50:16 +0800 | [diff] [blame] | 598 | bool pgd_changed = false; |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 599 | unsigned long vaddr, vaddr_start, vaddr_end, vaddr_next, paddr_last; |
Yinghai Lu | b50efd2 | 2008-07-08 01:41:05 -0700 | [diff] [blame] | 600 | |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 601 | paddr_last = paddr_end; |
| 602 | vaddr = (unsigned long)__va(paddr_start); |
| 603 | vaddr_end = (unsigned long)__va(paddr_end); |
| 604 | vaddr_start = vaddr; |
Yinghai Lu | b50efd2 | 2008-07-08 01:41:05 -0700 | [diff] [blame] | 605 | |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 606 | for (; vaddr < vaddr_end; vaddr = vaddr_next) { |
| 607 | pgd_t *pgd = pgd_offset_k(vaddr); |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 608 | p4d_t *p4d; |
Yinghai Lu | b50efd2 | 2008-07-08 01:41:05 -0700 | [diff] [blame] | 609 | pud_t *pud; |
| 610 | |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 611 | vaddr_next = (vaddr & PGDIR_MASK) + PGDIR_SIZE; |
Yinghai Lu | b50efd2 | 2008-07-08 01:41:05 -0700 | [diff] [blame] | 612 | |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 613 | BUILD_BUG_ON(pgd_none(*pgd)); |
| 614 | p4d = p4d_offset(pgd, vaddr); |
| 615 | if (p4d_val(*p4d)) { |
| 616 | pud = (pud_t *)p4d_page_vaddr(*p4d); |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 617 | paddr_last = phys_pud_init(pud, __pa(vaddr), |
| 618 | __pa(vaddr_end), |
| 619 | page_size_mask); |
Yinghai Lu | b50efd2 | 2008-07-08 01:41:05 -0700 | [diff] [blame] | 620 | continue; |
| 621 | } |
| 622 | |
Yinghai Lu | 868bf4d | 2012-11-16 19:39:00 -0800 | [diff] [blame] | 623 | pud = alloc_low_page(); |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 624 | paddr_last = phys_pud_init(pud, __pa(vaddr), __pa(vaddr_end), |
| 625 | page_size_mask); |
Jan Beulich | 8ae3a5a | 2008-08-21 14:27:22 +0100 | [diff] [blame] | 626 | |
| 627 | spin_lock(&init_mm.page_table_lock); |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 628 | p4d_populate(&init_mm, p4d, pud); |
Jan Beulich | 8ae3a5a | 2008-08-21 14:27:22 +0100 | [diff] [blame] | 629 | spin_unlock(&init_mm.page_table_lock); |
Haicheng Li | 9b86152 | 2010-08-20 17:50:16 +0800 | [diff] [blame] | 630 | pgd_changed = true; |
Yinghai Lu | b50efd2 | 2008-07-08 01:41:05 -0700 | [diff] [blame] | 631 | } |
Haicheng Li | 9b86152 | 2010-08-20 17:50:16 +0800 | [diff] [blame] | 632 | |
| 633 | if (pgd_changed) |
Kirill A. Shutemov | 5372e15 | 2016-12-15 02:44:03 +0300 | [diff] [blame] | 634 | sync_global_pgds(vaddr_start, vaddr_end - 1); |
Haicheng Li | 9b86152 | 2010-08-20 17:50:16 +0800 | [diff] [blame] | 635 | |
Suresh Siddha | a2699e4 | 2008-09-23 14:00:38 -0700 | [diff] [blame] | 636 | __flush_tlb_all(); |
Yinghai Lu | b50efd2 | 2008-07-08 01:41:05 -0700 | [diff] [blame] | 637 | |
Thomas Garnier | 59b3d02 | 2016-06-21 17:46:59 -0700 | [diff] [blame] | 638 | return paddr_last; |
Yinghai Lu | b50efd2 | 2008-07-08 01:41:05 -0700 | [diff] [blame] | 639 | } |
Yinghai Lu | 7b16eb8 | 2008-07-09 20:15:02 -0700 | [diff] [blame] | 640 | |
Matt Tolentino | 2b97690 | 2005-06-23 00:08:06 -0700 | [diff] [blame] | 641 | #ifndef CONFIG_NUMA |
Tejun Heo | d8fc3af | 2011-02-16 12:13:06 +0100 | [diff] [blame] | 642 | void __init initmem_init(void) |
Yinghai Lu | 1f75d7e | 2008-06-22 02:44:49 -0700 | [diff] [blame] | 643 | { |
Tang Chen | e7e8de5 | 2014-01-21 15:49:26 -0800 | [diff] [blame] | 644 | memblock_set_node(0, (phys_addr_t)ULLONG_MAX, &memblock.memory, 0); |
Yinghai Lu | 1f75d7e | 2008-06-22 02:44:49 -0700 | [diff] [blame] | 645 | } |
Pekka Enberg | 3551f88 | 2009-05-07 15:35:41 +0300 | [diff] [blame] | 646 | #endif |
Yinghai Lu | 1f75d7e | 2008-06-22 02:44:49 -0700 | [diff] [blame] | 647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | void __init paging_init(void) |
| 649 | { |
Pekka Enberg | 3551f88 | 2009-05-07 15:35:41 +0300 | [diff] [blame] | 650 | sparse_memory_present_with_active_regions(MAX_NUMNODES); |
Matt Tolentino | 44df75e | 2006-01-17 07:03:41 +0100 | [diff] [blame] | 651 | sparse_init(); |
Yinghai Lu | 44b5728 | 2009-07-08 09:50:19 -0700 | [diff] [blame] | 652 | |
| 653 | /* |
| 654 | * clear the default setting with node 0 |
| 655 | * note: don't use nodes_clear here, that is really clearing when |
| 656 | * numa support is not compiled in, and later node_set_state |
| 657 | * will not set it back. |
| 658 | */ |
Lai Jiangshan | 4b0ef1fe | 2012-12-12 13:51:46 -0800 | [diff] [blame] | 659 | node_clear_state(0, N_MEMORY); |
| 660 | if (N_MEMORY != N_NORMAL_MEMORY) |
| 661 | node_clear_state(0, N_NORMAL_MEMORY); |
Yinghai Lu | 44b5728 | 2009-07-08 09:50:19 -0700 | [diff] [blame] | 662 | |
Pekka Enberg | 4c0b2e5 | 2011-11-01 15:58:17 +0200 | [diff] [blame] | 663 | zone_sizes_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | |
Thomas Gleixner | 14a62c3 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 666 | /* |
Matt Tolentino | 44df75e | 2006-01-17 07:03:41 +0100 | [diff] [blame] | 667 | * Memory hotplug specific functions |
Matt Tolentino | 44df75e | 2006-01-17 07:03:41 +0100 | [diff] [blame] | 668 | */ |
Yasunori Goto | bc02af9 | 2006-06-27 02:53:30 -0700 | [diff] [blame] | 669 | #ifdef CONFIG_MEMORY_HOTPLUG |
| 670 | /* |
Shaohui Zheng | ea08541 | 2010-02-02 13:44:16 -0800 | [diff] [blame] | 671 | * After memory hotplug the variables max_pfn, max_low_pfn and high_memory need |
| 672 | * updating. |
| 673 | */ |
| 674 | static void update_end_of_memory_vars(u64 start, u64 size) |
| 675 | { |
| 676 | unsigned long end_pfn = PFN_UP(start + size); |
| 677 | |
| 678 | if (end_pfn > max_pfn) { |
| 679 | max_pfn = end_pfn; |
| 680 | max_low_pfn = end_pfn; |
| 681 | high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1; |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | /* |
Yasunori Goto | bc02af9 | 2006-06-27 02:53:30 -0700 | [diff] [blame] | 686 | * Memory is added always to NORMAL zone. This means you will never get |
| 687 | * additional DMA/DMA32 memory. |
| 688 | */ |
Dan Williams | 033fbae | 2015-08-09 15:29:06 -0400 | [diff] [blame] | 689 | int arch_add_memory(int nid, u64 start, u64 size, bool for_device) |
Yasunori Goto | bc02af9 | 2006-06-27 02:53:30 -0700 | [diff] [blame] | 690 | { |
| 691 | struct pglist_data *pgdat = NODE_DATA(nid); |
Wang Nan | 9bfc411 | 2014-08-06 16:07:38 -0700 | [diff] [blame] | 692 | struct zone *zone = pgdat->node_zones + |
Dan Williams | 033fbae | 2015-08-09 15:29:06 -0400 | [diff] [blame] | 693 | zone_for_memory(nid, start, size, ZONE_NORMAL, for_device); |
Jacob Shin | 66520eb | 2012-11-16 19:38:52 -0800 | [diff] [blame] | 694 | unsigned long start_pfn = start >> PAGE_SHIFT; |
Yasunori Goto | bc02af9 | 2006-06-27 02:53:30 -0700 | [diff] [blame] | 695 | unsigned long nr_pages = size >> PAGE_SHIFT; |
| 696 | int ret; |
| 697 | |
Jacob Shin | 66520eb | 2012-11-16 19:38:52 -0800 | [diff] [blame] | 698 | init_memory_mapping(start, start + size); |
Keith Mannthey | 45e0b78 | 2006-09-30 23:27:09 -0700 | [diff] [blame] | 699 | |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 700 | ret = __add_pages(nid, zone, start_pfn, nr_pages); |
Gary Hade | fe8b868 | 2008-10-28 16:43:14 -0700 | [diff] [blame] | 701 | WARN_ON_ONCE(ret); |
Yasunori Goto | bc02af9 | 2006-06-27 02:53:30 -0700 | [diff] [blame] | 702 | |
Shaohui Zheng | ea08541 | 2010-02-02 13:44:16 -0800 | [diff] [blame] | 703 | /* update max_pfn, max_low_pfn and high_memory */ |
| 704 | update_end_of_memory_vars(start, size); |
| 705 | |
Yasunori Goto | bc02af9 | 2006-06-27 02:53:30 -0700 | [diff] [blame] | 706 | return ret; |
Yasunori Goto | bc02af9 | 2006-06-27 02:53:30 -0700 | [diff] [blame] | 707 | } |
| 708 | EXPORT_SYMBOL_GPL(arch_add_memory); |
| 709 | |
Wen Congyang | ae9aae9 | 2013-02-22 16:33:04 -0800 | [diff] [blame] | 710 | #define PAGE_INUSE 0xFD |
| 711 | |
| 712 | static void __meminit free_pagetable(struct page *page, int order) |
| 713 | { |
Wen Congyang | ae9aae9 | 2013-02-22 16:33:04 -0800 | [diff] [blame] | 714 | unsigned long magic; |
| 715 | unsigned int nr_pages = 1 << order; |
Dan Williams | 4b94ffd | 2016-01-15 16:56:22 -0800 | [diff] [blame] | 716 | struct vmem_altmap *altmap = to_vmem_altmap((unsigned long) page); |
| 717 | |
| 718 | if (altmap) { |
| 719 | vmem_altmap_free(altmap, nr_pages); |
| 720 | return; |
| 721 | } |
Wen Congyang | ae9aae9 | 2013-02-22 16:33:04 -0800 | [diff] [blame] | 722 | |
| 723 | /* bootmem page has reserved flag */ |
| 724 | if (PageReserved(page)) { |
| 725 | __ClearPageReserved(page); |
Wen Congyang | ae9aae9 | 2013-02-22 16:33:04 -0800 | [diff] [blame] | 726 | |
Yasuaki Ishimatsu | ddffe98 | 2017-02-22 15:45:13 -0800 | [diff] [blame] | 727 | magic = (unsigned long)page->freelist; |
Wen Congyang | ae9aae9 | 2013-02-22 16:33:04 -0800 | [diff] [blame] | 728 | if (magic == SECTION_INFO || magic == MIX_SECTION_INFO) { |
| 729 | while (nr_pages--) |
| 730 | put_page_bootmem(page++); |
| 731 | } else |
Jiang Liu | 170a5a7 | 2013-07-03 15:03:17 -0700 | [diff] [blame] | 732 | while (nr_pages--) |
| 733 | free_reserved_page(page++); |
Wen Congyang | ae9aae9 | 2013-02-22 16:33:04 -0800 | [diff] [blame] | 734 | } else |
| 735 | free_pages((unsigned long)page_address(page), order); |
Wen Congyang | ae9aae9 | 2013-02-22 16:33:04 -0800 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | static void __meminit free_pte_table(pte_t *pte_start, pmd_t *pmd) |
| 739 | { |
| 740 | pte_t *pte; |
| 741 | int i; |
| 742 | |
| 743 | for (i = 0; i < PTRS_PER_PTE; i++) { |
| 744 | pte = pte_start + i; |
Dave Hansen | dcb32d9 | 2016-07-07 17:19:15 -0700 | [diff] [blame] | 745 | if (!pte_none(*pte)) |
Wen Congyang | ae9aae9 | 2013-02-22 16:33:04 -0800 | [diff] [blame] | 746 | return; |
| 747 | } |
| 748 | |
| 749 | /* free a pte talbe */ |
| 750 | free_pagetable(pmd_page(*pmd), 0); |
| 751 | spin_lock(&init_mm.page_table_lock); |
| 752 | pmd_clear(pmd); |
| 753 | spin_unlock(&init_mm.page_table_lock); |
| 754 | } |
| 755 | |
| 756 | static void __meminit free_pmd_table(pmd_t *pmd_start, pud_t *pud) |
| 757 | { |
| 758 | pmd_t *pmd; |
| 759 | int i; |
| 760 | |
| 761 | for (i = 0; i < PTRS_PER_PMD; i++) { |
| 762 | pmd = pmd_start + i; |
Dave Hansen | dcb32d9 | 2016-07-07 17:19:15 -0700 | [diff] [blame] | 763 | if (!pmd_none(*pmd)) |
Wen Congyang | ae9aae9 | 2013-02-22 16:33:04 -0800 | [diff] [blame] | 764 | return; |
| 765 | } |
| 766 | |
| 767 | /* free a pmd talbe */ |
| 768 | free_pagetable(pud_page(*pud), 0); |
| 769 | spin_lock(&init_mm.page_table_lock); |
| 770 | pud_clear(pud); |
| 771 | spin_unlock(&init_mm.page_table_lock); |
| 772 | } |
| 773 | |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 774 | static void __meminit free_pud_table(pud_t *pud_start, p4d_t *p4d) |
| 775 | { |
| 776 | pud_t *pud; |
| 777 | int i; |
| 778 | |
| 779 | for (i = 0; i < PTRS_PER_PUD; i++) { |
| 780 | pud = pud_start + i; |
| 781 | if (!pud_none(*pud)) |
| 782 | return; |
| 783 | } |
| 784 | |
| 785 | /* free a pud talbe */ |
| 786 | free_pagetable(p4d_page(*p4d), 0); |
| 787 | spin_lock(&init_mm.page_table_lock); |
| 788 | p4d_clear(p4d); |
| 789 | spin_unlock(&init_mm.page_table_lock); |
| 790 | } |
| 791 | |
Wen Congyang | ae9aae9 | 2013-02-22 16:33:04 -0800 | [diff] [blame] | 792 | static void __meminit |
| 793 | remove_pte_table(pte_t *pte_start, unsigned long addr, unsigned long end, |
| 794 | bool direct) |
| 795 | { |
| 796 | unsigned long next, pages = 0; |
| 797 | pte_t *pte; |
| 798 | void *page_addr; |
| 799 | phys_addr_t phys_addr; |
| 800 | |
| 801 | pte = pte_start + pte_index(addr); |
| 802 | for (; addr < end; addr = next, pte++) { |
| 803 | next = (addr + PAGE_SIZE) & PAGE_MASK; |
| 804 | if (next > end) |
| 805 | next = end; |
| 806 | |
| 807 | if (!pte_present(*pte)) |
| 808 | continue; |
| 809 | |
| 810 | /* |
| 811 | * We mapped [0,1G) memory as identity mapping when |
| 812 | * initializing, in arch/x86/kernel/head_64.S. These |
| 813 | * pagetables cannot be removed. |
| 814 | */ |
| 815 | phys_addr = pte_val(*pte) + (addr & PAGE_MASK); |
| 816 | if (phys_addr < (phys_addr_t)0x40000000) |
| 817 | return; |
| 818 | |
Kefeng Wang | b500f77 | 2016-01-12 10:19:30 +0800 | [diff] [blame] | 819 | if (PAGE_ALIGNED(addr) && PAGE_ALIGNED(next)) { |
Wen Congyang | ae9aae9 | 2013-02-22 16:33:04 -0800 | [diff] [blame] | 820 | /* |
| 821 | * Do not free direct mapping pages since they were |
| 822 | * freed when offlining, or simplely not in use. |
| 823 | */ |
| 824 | if (!direct) |
| 825 | free_pagetable(pte_page(*pte), 0); |
| 826 | |
| 827 | spin_lock(&init_mm.page_table_lock); |
| 828 | pte_clear(&init_mm, addr, pte); |
| 829 | spin_unlock(&init_mm.page_table_lock); |
| 830 | |
| 831 | /* For non-direct mapping, pages means nothing. */ |
| 832 | pages++; |
| 833 | } else { |
| 834 | /* |
| 835 | * If we are here, we are freeing vmemmap pages since |
| 836 | * direct mapped memory ranges to be freed are aligned. |
| 837 | * |
| 838 | * If we are not removing the whole page, it means |
| 839 | * other page structs in this page are being used and |
| 840 | * we canot remove them. So fill the unused page_structs |
| 841 | * with 0xFD, and remove the page when it is wholly |
| 842 | * filled with 0xFD. |
| 843 | */ |
| 844 | memset((void *)addr, PAGE_INUSE, next - addr); |
| 845 | |
| 846 | page_addr = page_address(pte_page(*pte)); |
| 847 | if (!memchr_inv(page_addr, PAGE_INUSE, PAGE_SIZE)) { |
| 848 | free_pagetable(pte_page(*pte), 0); |
| 849 | |
| 850 | spin_lock(&init_mm.page_table_lock); |
| 851 | pte_clear(&init_mm, addr, pte); |
| 852 | spin_unlock(&init_mm.page_table_lock); |
| 853 | } |
| 854 | } |
| 855 | } |
| 856 | |
| 857 | /* Call free_pte_table() in remove_pmd_table(). */ |
| 858 | flush_tlb_all(); |
| 859 | if (direct) |
| 860 | update_page_count(PG_LEVEL_4K, -pages); |
| 861 | } |
| 862 | |
| 863 | static void __meminit |
| 864 | remove_pmd_table(pmd_t *pmd_start, unsigned long addr, unsigned long end, |
| 865 | bool direct) |
| 866 | { |
| 867 | unsigned long next, pages = 0; |
| 868 | pte_t *pte_base; |
| 869 | pmd_t *pmd; |
| 870 | void *page_addr; |
| 871 | |
| 872 | pmd = pmd_start + pmd_index(addr); |
| 873 | for (; addr < end; addr = next, pmd++) { |
| 874 | next = pmd_addr_end(addr, end); |
| 875 | |
| 876 | if (!pmd_present(*pmd)) |
| 877 | continue; |
| 878 | |
| 879 | if (pmd_large(*pmd)) { |
| 880 | if (IS_ALIGNED(addr, PMD_SIZE) && |
| 881 | IS_ALIGNED(next, PMD_SIZE)) { |
| 882 | if (!direct) |
| 883 | free_pagetable(pmd_page(*pmd), |
| 884 | get_order(PMD_SIZE)); |
| 885 | |
| 886 | spin_lock(&init_mm.page_table_lock); |
| 887 | pmd_clear(pmd); |
| 888 | spin_unlock(&init_mm.page_table_lock); |
| 889 | pages++; |
| 890 | } else { |
| 891 | /* If here, we are freeing vmemmap pages. */ |
| 892 | memset((void *)addr, PAGE_INUSE, next - addr); |
| 893 | |
| 894 | page_addr = page_address(pmd_page(*pmd)); |
| 895 | if (!memchr_inv(page_addr, PAGE_INUSE, |
| 896 | PMD_SIZE)) { |
| 897 | free_pagetable(pmd_page(*pmd), |
| 898 | get_order(PMD_SIZE)); |
| 899 | |
| 900 | spin_lock(&init_mm.page_table_lock); |
| 901 | pmd_clear(pmd); |
| 902 | spin_unlock(&init_mm.page_table_lock); |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | continue; |
| 907 | } |
| 908 | |
| 909 | pte_base = (pte_t *)pmd_page_vaddr(*pmd); |
| 910 | remove_pte_table(pte_base, addr, next, direct); |
| 911 | free_pte_table(pte_base, pmd); |
| 912 | } |
| 913 | |
| 914 | /* Call free_pmd_table() in remove_pud_table(). */ |
| 915 | if (direct) |
| 916 | update_page_count(PG_LEVEL_2M, -pages); |
| 917 | } |
| 918 | |
| 919 | static void __meminit |
| 920 | remove_pud_table(pud_t *pud_start, unsigned long addr, unsigned long end, |
| 921 | bool direct) |
| 922 | { |
| 923 | unsigned long next, pages = 0; |
| 924 | pmd_t *pmd_base; |
| 925 | pud_t *pud; |
| 926 | void *page_addr; |
| 927 | |
| 928 | pud = pud_start + pud_index(addr); |
| 929 | for (; addr < end; addr = next, pud++) { |
| 930 | next = pud_addr_end(addr, end); |
| 931 | |
| 932 | if (!pud_present(*pud)) |
| 933 | continue; |
| 934 | |
| 935 | if (pud_large(*pud)) { |
| 936 | if (IS_ALIGNED(addr, PUD_SIZE) && |
| 937 | IS_ALIGNED(next, PUD_SIZE)) { |
| 938 | if (!direct) |
| 939 | free_pagetable(pud_page(*pud), |
| 940 | get_order(PUD_SIZE)); |
| 941 | |
| 942 | spin_lock(&init_mm.page_table_lock); |
| 943 | pud_clear(pud); |
| 944 | spin_unlock(&init_mm.page_table_lock); |
| 945 | pages++; |
| 946 | } else { |
| 947 | /* If here, we are freeing vmemmap pages. */ |
| 948 | memset((void *)addr, PAGE_INUSE, next - addr); |
| 949 | |
| 950 | page_addr = page_address(pud_page(*pud)); |
| 951 | if (!memchr_inv(page_addr, PAGE_INUSE, |
| 952 | PUD_SIZE)) { |
| 953 | free_pagetable(pud_page(*pud), |
| 954 | get_order(PUD_SIZE)); |
| 955 | |
| 956 | spin_lock(&init_mm.page_table_lock); |
| 957 | pud_clear(pud); |
| 958 | spin_unlock(&init_mm.page_table_lock); |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | continue; |
| 963 | } |
| 964 | |
Kirill A. Shutemov | e6ab9c4 | 2017-04-25 12:25:57 +0300 | [diff] [blame] | 965 | pmd_base = pmd_offset(pud, 0); |
Wen Congyang | ae9aae9 | 2013-02-22 16:33:04 -0800 | [diff] [blame] | 966 | remove_pmd_table(pmd_base, addr, next, direct); |
| 967 | free_pmd_table(pmd_base, pud); |
| 968 | } |
| 969 | |
| 970 | if (direct) |
| 971 | update_page_count(PG_LEVEL_1G, -pages); |
| 972 | } |
| 973 | |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 974 | static void __meminit |
| 975 | remove_p4d_table(p4d_t *p4d_start, unsigned long addr, unsigned long end, |
| 976 | bool direct) |
| 977 | { |
| 978 | unsigned long next, pages = 0; |
| 979 | pud_t *pud_base; |
| 980 | p4d_t *p4d; |
| 981 | |
| 982 | p4d = p4d_start + p4d_index(addr); |
| 983 | for (; addr < end; addr = next, p4d++) { |
| 984 | next = p4d_addr_end(addr, end); |
| 985 | |
| 986 | if (!p4d_present(*p4d)) |
| 987 | continue; |
| 988 | |
| 989 | BUILD_BUG_ON(p4d_large(*p4d)); |
| 990 | |
Kirill A. Shutemov | e6ab9c4 | 2017-04-25 12:25:57 +0300 | [diff] [blame] | 991 | pud_base = pud_offset(p4d, 0); |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 992 | remove_pud_table(pud_base, addr, next, direct); |
| 993 | free_pud_table(pud_base, p4d); |
| 994 | } |
| 995 | |
| 996 | if (direct) |
| 997 | update_page_count(PG_LEVEL_512G, -pages); |
| 998 | } |
| 999 | |
Wen Congyang | ae9aae9 | 2013-02-22 16:33:04 -0800 | [diff] [blame] | 1000 | /* start and end are both virtual address. */ |
| 1001 | static void __meminit |
| 1002 | remove_pagetable(unsigned long start, unsigned long end, bool direct) |
| 1003 | { |
| 1004 | unsigned long next; |
Yasuaki Ishimatsu | 5255e0a | 2014-08-22 13:27:31 -0700 | [diff] [blame] | 1005 | unsigned long addr; |
Wen Congyang | ae9aae9 | 2013-02-22 16:33:04 -0800 | [diff] [blame] | 1006 | pgd_t *pgd; |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 1007 | p4d_t *p4d; |
Wen Congyang | ae9aae9 | 2013-02-22 16:33:04 -0800 | [diff] [blame] | 1008 | |
Yasuaki Ishimatsu | 5255e0a | 2014-08-22 13:27:31 -0700 | [diff] [blame] | 1009 | for (addr = start; addr < end; addr = next) { |
| 1010 | next = pgd_addr_end(addr, end); |
Wen Congyang | ae9aae9 | 2013-02-22 16:33:04 -0800 | [diff] [blame] | 1011 | |
Yasuaki Ishimatsu | 5255e0a | 2014-08-22 13:27:31 -0700 | [diff] [blame] | 1012 | pgd = pgd_offset_k(addr); |
Wen Congyang | ae9aae9 | 2013-02-22 16:33:04 -0800 | [diff] [blame] | 1013 | if (!pgd_present(*pgd)) |
| 1014 | continue; |
| 1015 | |
Kirill A. Shutemov | e6ab9c4 | 2017-04-25 12:25:57 +0300 | [diff] [blame] | 1016 | p4d = p4d_offset(pgd, 0); |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 1017 | remove_p4d_table(p4d, addr, next, direct); |
Wen Congyang | ae9aae9 | 2013-02-22 16:33:04 -0800 | [diff] [blame] | 1018 | } |
| 1019 | |
Wen Congyang | ae9aae9 | 2013-02-22 16:33:04 -0800 | [diff] [blame] | 1020 | flush_tlb_all(); |
| 1021 | } |
| 1022 | |
Johannes Weiner | 0aad818 | 2013-04-29 15:07:50 -0700 | [diff] [blame] | 1023 | void __ref vmemmap_free(unsigned long start, unsigned long end) |
Tang Chen | 0197518 | 2013-02-22 16:33:08 -0800 | [diff] [blame] | 1024 | { |
Tang Chen | 0197518 | 2013-02-22 16:33:08 -0800 | [diff] [blame] | 1025 | remove_pagetable(start, end, false); |
| 1026 | } |
| 1027 | |
Tang Chen | 587ff8c | 2013-04-15 17:46:46 +0800 | [diff] [blame] | 1028 | #ifdef CONFIG_MEMORY_HOTREMOVE |
Tang Chen | bbcab87 | 2013-02-22 16:33:06 -0800 | [diff] [blame] | 1029 | static void __meminit |
| 1030 | kernel_physical_mapping_remove(unsigned long start, unsigned long end) |
| 1031 | { |
| 1032 | start = (unsigned long)__va(start); |
| 1033 | end = (unsigned long)__va(end); |
| 1034 | |
| 1035 | remove_pagetable(start, end, true); |
| 1036 | } |
| 1037 | |
Wen Congyang | 24d335c | 2013-02-22 16:32:58 -0800 | [diff] [blame] | 1038 | int __ref arch_remove_memory(u64 start, u64 size) |
| 1039 | { |
| 1040 | unsigned long start_pfn = start >> PAGE_SHIFT; |
| 1041 | unsigned long nr_pages = size >> PAGE_SHIFT; |
Dan Williams | 4b94ffd | 2016-01-15 16:56:22 -0800 | [diff] [blame] | 1042 | struct page *page = pfn_to_page(start_pfn); |
| 1043 | struct vmem_altmap *altmap; |
Wen Congyang | 24d335c | 2013-02-22 16:32:58 -0800 | [diff] [blame] | 1044 | struct zone *zone; |
| 1045 | int ret; |
| 1046 | |
Dan Williams | 4b94ffd | 2016-01-15 16:56:22 -0800 | [diff] [blame] | 1047 | /* With altmap the first mapped page is offset from @start */ |
| 1048 | altmap = to_vmem_altmap((unsigned long) page); |
| 1049 | if (altmap) |
| 1050 | page += vmem_altmap_offset(altmap); |
| 1051 | zone = page_zone(page); |
Wen Congyang | 24d335c | 2013-02-22 16:32:58 -0800 | [diff] [blame] | 1052 | ret = __remove_pages(zone, start_pfn, nr_pages); |
| 1053 | WARN_ON_ONCE(ret); |
Dan Williams | 4b94ffd | 2016-01-15 16:56:22 -0800 | [diff] [blame] | 1054 | kernel_physical_mapping_remove(start, start + size); |
Wen Congyang | 24d335c | 2013-02-22 16:32:58 -0800 | [diff] [blame] | 1055 | |
| 1056 | return ret; |
| 1057 | } |
| 1058 | #endif |
Keith Mannthey | 45e0b78 | 2006-09-30 23:27:09 -0700 | [diff] [blame] | 1059 | #endif /* CONFIG_MEMORY_HOTPLUG */ |
| 1060 | |
KAMEZAWA Hiroyuki | 81ac3ad | 2009-09-22 16:45:49 -0700 | [diff] [blame] | 1061 | static struct kcore_list kcore_vsyscall; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | |
Yinghai Lu | 94b43c3 | 2012-11-16 19:39:19 -0800 | [diff] [blame] | 1063 | static void __init register_page_bootmem_info(void) |
| 1064 | { |
| 1065 | #ifdef CONFIG_NUMA |
| 1066 | int i; |
| 1067 | |
| 1068 | for_each_online_node(i) |
| 1069 | register_page_bootmem_info_node(NODE_DATA(i)); |
| 1070 | #endif |
| 1071 | } |
| 1072 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | void __init mem_init(void) |
| 1074 | { |
Jon Mason | 0dc243a | 2006-06-26 13:58:11 +0200 | [diff] [blame] | 1075 | pci_iommu_alloc(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | |
Yinghai Lu | 48ddb15 | 2008-01-30 13:32:36 +0100 | [diff] [blame] | 1077 | /* clear_bss() already clear the empty_zero_page */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | |
Yinghai Lu | 94b43c3 | 2012-11-16 19:39:19 -0800 | [diff] [blame] | 1079 | register_page_bootmem_info(); |
Jiang Liu | bced0e3 | 2013-04-29 15:06:53 -0700 | [diff] [blame] | 1080 | |
| 1081 | /* this will put all memory onto the freelists */ |
Jiang Liu | 0c98853 | 2013-07-03 15:03:24 -0700 | [diff] [blame] | 1082 | free_all_bootmem(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | after_bootmem = 1; |
| 1084 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | /* Register memory areas for /proc/kcore */ |
Andy Lutomirski | f40c330 | 2014-05-05 12:19:36 -0700 | [diff] [blame] | 1086 | kclist_add(&kcore_vsyscall, (void *)VSYSCALL_ADDR, |
| 1087 | PAGE_SIZE, KCORE_OTHER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | |
Jiang Liu | 46a8413 | 2013-07-03 15:04:19 -0700 | [diff] [blame] | 1089 | mem_init_print_info(NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
Suresh Siddha | 502f660 | 2009-10-28 18:46:56 -0800 | [diff] [blame] | 1092 | int kernel_set_to_readonly; |
Steven Rostedt | 1623963 | 2009-02-17 17:57:30 -0500 | [diff] [blame] | 1093 | |
| 1094 | void set_kernel_text_rw(void) |
| 1095 | { |
Suresh Siddha | b9af7c0 | 2009-10-14 14:46:55 -0700 | [diff] [blame] | 1096 | unsigned long start = PFN_ALIGN(_text); |
Suresh Siddha | e7d23dd | 2009-10-28 18:46:58 -0800 | [diff] [blame] | 1097 | unsigned long end = PFN_ALIGN(__stop___ex_table); |
Steven Rostedt | 1623963 | 2009-02-17 17:57:30 -0500 | [diff] [blame] | 1098 | |
| 1099 | if (!kernel_set_to_readonly) |
| 1100 | return; |
| 1101 | |
| 1102 | pr_debug("Set kernel text: %lx - %lx for read write\n", |
| 1103 | start, end); |
| 1104 | |
Suresh Siddha | e7d23dd | 2009-10-28 18:46:58 -0800 | [diff] [blame] | 1105 | /* |
| 1106 | * Make the kernel identity mapping for text RW. Kernel text |
| 1107 | * mapping will always be RO. Refer to the comment in |
| 1108 | * static_protections() in pageattr.c |
| 1109 | */ |
Steven Rostedt | 1623963 | 2009-02-17 17:57:30 -0500 | [diff] [blame] | 1110 | set_memory_rw(start, (end - start) >> PAGE_SHIFT); |
| 1111 | } |
| 1112 | |
| 1113 | void set_kernel_text_ro(void) |
| 1114 | { |
Suresh Siddha | b9af7c0 | 2009-10-14 14:46:55 -0700 | [diff] [blame] | 1115 | unsigned long start = PFN_ALIGN(_text); |
Suresh Siddha | e7d23dd | 2009-10-28 18:46:58 -0800 | [diff] [blame] | 1116 | unsigned long end = PFN_ALIGN(__stop___ex_table); |
Steven Rostedt | 1623963 | 2009-02-17 17:57:30 -0500 | [diff] [blame] | 1117 | |
| 1118 | if (!kernel_set_to_readonly) |
| 1119 | return; |
| 1120 | |
| 1121 | pr_debug("Set kernel text: %lx - %lx for read only\n", |
| 1122 | start, end); |
| 1123 | |
Suresh Siddha | e7d23dd | 2009-10-28 18:46:58 -0800 | [diff] [blame] | 1124 | /* |
| 1125 | * Set the kernel identity mapping for text RO. |
| 1126 | */ |
Steven Rostedt | 1623963 | 2009-02-17 17:57:30 -0500 | [diff] [blame] | 1127 | set_memory_ro(start, (end - start) >> PAGE_SHIFT); |
| 1128 | } |
| 1129 | |
Arjan van de Ven | 67df197 | 2006-01-06 00:12:04 -0800 | [diff] [blame] | 1130 | void mark_rodata_ro(void) |
| 1131 | { |
Suresh Siddha | 74e0817 | 2009-10-14 14:46:56 -0700 | [diff] [blame] | 1132 | unsigned long start = PFN_ALIGN(_text); |
Alexander Duyck | fc8d782 | 2012-11-16 13:57:13 -0800 | [diff] [blame] | 1133 | unsigned long rodata_start = PFN_ALIGN(__start_rodata); |
Suresh Siddha | 74e0817 | 2009-10-14 14:46:56 -0700 | [diff] [blame] | 1134 | unsigned long end = (unsigned long) &__end_rodata_hpage_align; |
Alexander Duyck | fc8d782 | 2012-11-16 13:57:13 -0800 | [diff] [blame] | 1135 | unsigned long text_end = PFN_ALIGN(&__stop___ex_table); |
| 1136 | unsigned long rodata_end = PFN_ALIGN(&__end_rodata); |
Kees Cook | 45e2a9d | 2014-11-14 11:47:37 -0800 | [diff] [blame] | 1137 | unsigned long all_end; |
Steven Rostedt | 8f0f996 | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 1138 | |
Jan Beulich | 6fb1475 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 1139 | printk(KERN_INFO "Write protecting the kernel read-only data: %luk\n", |
Linus Torvalds | e3ebadd | 2007-05-07 08:44:24 -0700 | [diff] [blame] | 1140 | (end - start) >> 10); |
Arjan van de Ven | 984bb80 | 2008-02-06 22:39:45 +0100 | [diff] [blame] | 1141 | set_memory_ro(start, (end - start) >> PAGE_SHIFT); |
| 1142 | |
Steven Rostedt | 1623963 | 2009-02-17 17:57:30 -0500 | [diff] [blame] | 1143 | kernel_set_to_readonly = 1; |
| 1144 | |
Arjan van de Ven | 984bb80 | 2008-02-06 22:39:45 +0100 | [diff] [blame] | 1145 | /* |
Yinghai Lu | 7221267 | 2013-01-24 12:20:13 -0800 | [diff] [blame] | 1146 | * The rodata/data/bss/brk section (but not the kernel text!) |
| 1147 | * should also be not-executable. |
Kees Cook | 45e2a9d | 2014-11-14 11:47:37 -0800 | [diff] [blame] | 1148 | * |
| 1149 | * We align all_end to PMD_SIZE because the existing mapping |
| 1150 | * is a full PMD. If we would align _brk_end to PAGE_SIZE we |
| 1151 | * split the PMD and the reminder between _brk_end and the end |
| 1152 | * of the PMD will remain mapped executable. |
| 1153 | * |
| 1154 | * Any PMD which was setup after the one which covers _brk_end |
| 1155 | * has been zapped already via cleanup_highmem(). |
Arjan van de Ven | 984bb80 | 2008-02-06 22:39:45 +0100 | [diff] [blame] | 1156 | */ |
Kees Cook | 45e2a9d | 2014-11-14 11:47:37 -0800 | [diff] [blame] | 1157 | all_end = roundup((unsigned long)_brk_end, PMD_SIZE); |
Stephen Smalley | ab76f7b | 2015-10-01 09:04:22 -0400 | [diff] [blame] | 1158 | set_memory_nx(text_end, (all_end - text_end) >> PAGE_SHIFT); |
Arjan van de Ven | 67df197 | 2006-01-06 00:12:04 -0800 | [diff] [blame] | 1159 | |
Andi Kleen | 0c42f39 | 2008-01-30 13:33:42 +0100 | [diff] [blame] | 1160 | #ifdef CONFIG_CPA_DEBUG |
Ingo Molnar | 10f22dd | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1161 | printk(KERN_INFO "Testing CPA: undo %lx-%lx\n", start, end); |
Arjan van de Ven | 6d238cc | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 1162 | set_memory_rw(start, (end-start) >> PAGE_SHIFT); |
Andi Kleen | 0c42f39 | 2008-01-30 13:33:42 +0100 | [diff] [blame] | 1163 | |
Ingo Molnar | 10f22dd | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1164 | printk(KERN_INFO "Testing CPA: again\n"); |
Arjan van de Ven | 6d238cc | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 1165 | set_memory_ro(start, (end-start) >> PAGE_SHIFT); |
Andi Kleen | 0c42f39 | 2008-01-30 13:33:42 +0100 | [diff] [blame] | 1166 | #endif |
Suresh Siddha | 74e0817 | 2009-10-14 14:46:56 -0700 | [diff] [blame] | 1167 | |
Jiang Liu | c88442e | 2013-07-03 15:02:58 -0700 | [diff] [blame] | 1168 | free_init_pages("unused kernel", |
Alexander Duyck | fc8d782 | 2012-11-16 13:57:13 -0800 | [diff] [blame] | 1169 | (unsigned long) __va(__pa_symbol(text_end)), |
| 1170 | (unsigned long) __va(__pa_symbol(rodata_start))); |
Jiang Liu | c88442e | 2013-07-03 15:02:58 -0700 | [diff] [blame] | 1171 | free_init_pages("unused kernel", |
Alexander Duyck | fc8d782 | 2012-11-16 13:57:13 -0800 | [diff] [blame] | 1172 | (unsigned long) __va(__pa_symbol(rodata_end)), |
| 1173 | (unsigned long) __va(__pa_symbol(_sdata))); |
Stephen Smalley | e1a5832 | 2015-10-05 12:55:20 -0400 | [diff] [blame] | 1174 | |
| 1175 | debug_checkwx(); |
Arjan van de Ven | 67df197 | 2006-01-06 00:12:04 -0800 | [diff] [blame] | 1176 | } |
Mathieu Desnoyers | 4e4eee0 | 2008-02-02 15:42:20 -0500 | [diff] [blame] | 1177 | |
Thomas Gleixner | 14a62c3 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1178 | int kern_addr_valid(unsigned long addr) |
| 1179 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | unsigned long above = ((long)addr) >> __VIRTUAL_MASK_SHIFT; |
Thomas Gleixner | 14a62c3 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1181 | pgd_t *pgd; |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 1182 | p4d_t *p4d; |
Thomas Gleixner | 14a62c3 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1183 | pud_t *pud; |
| 1184 | pmd_t *pmd; |
| 1185 | pte_t *pte; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | |
| 1187 | if (above != 0 && above != -1UL) |
Thomas Gleixner | 14a62c3 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1188 | return 0; |
| 1189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | pgd = pgd_offset_k(addr); |
| 1191 | if (pgd_none(*pgd)) |
| 1192 | return 0; |
| 1193 | |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 1194 | p4d = p4d_offset(pgd, addr); |
| 1195 | if (p4d_none(*p4d)) |
| 1196 | return 0; |
| 1197 | |
| 1198 | pud = pud_offset(p4d, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | if (pud_none(*pud)) |
Thomas Gleixner | 14a62c3 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1200 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | |
Mel Gorman | 0ee364e | 2013-02-11 14:52:36 +0000 | [diff] [blame] | 1202 | if (pud_large(*pud)) |
| 1203 | return pfn_valid(pud_pfn(*pud)); |
| 1204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | pmd = pmd_offset(pud, addr); |
| 1206 | if (pmd_none(*pmd)) |
| 1207 | return 0; |
Thomas Gleixner | 14a62c3 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | if (pmd_large(*pmd)) |
| 1210 | return pfn_valid(pmd_pfn(*pmd)); |
| 1211 | |
| 1212 | pte = pte_offset_kernel(pmd, addr); |
| 1213 | if (pte_none(*pte)) |
| 1214 | return 0; |
Thomas Gleixner | 14a62c3 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | return pfn_valid(pte_pfn(*pte)); |
| 1217 | } |
| 1218 | |
Yinghai Lu | 982792c | 2014-06-04 16:06:32 -0700 | [diff] [blame] | 1219 | static unsigned long probe_memory_block_size(void) |
Nathan Fontenot | 1dc41aa | 2011-01-20 10:46:15 -0600 | [diff] [blame] | 1220 | { |
Seth Jennings | 43c75f9 | 2015-11-30 10:47:43 -0600 | [diff] [blame] | 1221 | unsigned long bz = MIN_MEMORY_BLOCK_SIZE; |
Yinghai Lu | 982792c | 2014-06-04 16:06:32 -0700 | [diff] [blame] | 1222 | |
Seth Jennings | 43c75f9 | 2015-11-30 10:47:43 -0600 | [diff] [blame] | 1223 | /* if system is UV or has 64GB of RAM or more, use large blocks */ |
| 1224 | if (is_uv_system() || ((max_pfn << PAGE_SHIFT) >= (64UL << 30))) |
| 1225 | bz = 2UL << 30; /* 2GB */ |
Nathan Fontenot | 1dc41aa | 2011-01-20 10:46:15 -0600 | [diff] [blame] | 1226 | |
Seth Jennings | 43c75f9 | 2015-11-30 10:47:43 -0600 | [diff] [blame] | 1227 | pr_info("x86/mm: Memory block size: %ldMB\n", bz >> 20); |
Yinghai Lu | 982792c | 2014-06-04 16:06:32 -0700 | [diff] [blame] | 1228 | |
| 1229 | return bz; |
| 1230 | } |
| 1231 | |
| 1232 | static unsigned long memory_block_size_probed; |
| 1233 | unsigned long memory_block_size_bytes(void) |
| 1234 | { |
| 1235 | if (!memory_block_size_probed) |
| 1236 | memory_block_size_probed = probe_memory_block_size(); |
| 1237 | |
| 1238 | return memory_block_size_probed; |
| 1239 | } |
| 1240 | |
Christoph Lameter | 0889eba | 2007-10-16 01:24:15 -0700 | [diff] [blame] | 1241 | #ifdef CONFIG_SPARSEMEM_VMEMMAP |
| 1242 | /* |
| 1243 | * Initialise the sparsemem vmemmap using huge-pages at the PMD level. |
| 1244 | */ |
Yinghai Lu | c2b91e2 | 2008-04-12 01:19:24 -0700 | [diff] [blame] | 1245 | static long __meminitdata addr_start, addr_end; |
| 1246 | static void __meminitdata *p_start, *p_end; |
| 1247 | static int __meminitdata node_start; |
| 1248 | |
Johannes Weiner | e8216da | 2013-04-29 15:07:54 -0700 | [diff] [blame] | 1249 | static int __meminit vmemmap_populate_hugepages(unsigned long start, |
Dan Williams | 4b94ffd | 2016-01-15 16:56:22 -0800 | [diff] [blame] | 1250 | unsigned long end, int node, struct vmem_altmap *altmap) |
Christoph Lameter | 0889eba | 2007-10-16 01:24:15 -0700 | [diff] [blame] | 1251 | { |
Johannes Weiner | 0aad818 | 2013-04-29 15:07:50 -0700 | [diff] [blame] | 1252 | unsigned long addr; |
Christoph Lameter | 0889eba | 2007-10-16 01:24:15 -0700 | [diff] [blame] | 1253 | unsigned long next; |
| 1254 | pgd_t *pgd; |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 1255 | p4d_t *p4d; |
Christoph Lameter | 0889eba | 2007-10-16 01:24:15 -0700 | [diff] [blame] | 1256 | pud_t *pud; |
| 1257 | pmd_t *pmd; |
| 1258 | |
Johannes Weiner | 0aad818 | 2013-04-29 15:07:50 -0700 | [diff] [blame] | 1259 | for (addr = start; addr < end; addr = next) { |
Johannes Weiner | e8216da | 2013-04-29 15:07:54 -0700 | [diff] [blame] | 1260 | next = pmd_addr_end(addr, end); |
Christoph Lameter | 0889eba | 2007-10-16 01:24:15 -0700 | [diff] [blame] | 1261 | |
| 1262 | pgd = vmemmap_pgd_populate(addr, node); |
| 1263 | if (!pgd) |
| 1264 | return -ENOMEM; |
Thomas Gleixner | 14a62c3 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1265 | |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 1266 | p4d = vmemmap_p4d_populate(pgd, addr, node); |
| 1267 | if (!p4d) |
| 1268 | return -ENOMEM; |
| 1269 | |
| 1270 | pud = vmemmap_pud_populate(p4d, addr, node); |
Christoph Lameter | 0889eba | 2007-10-16 01:24:15 -0700 | [diff] [blame] | 1271 | if (!pud) |
| 1272 | return -ENOMEM; |
| 1273 | |
Johannes Weiner | e8216da | 2013-04-29 15:07:54 -0700 | [diff] [blame] | 1274 | pmd = pmd_offset(pud, addr); |
| 1275 | if (pmd_none(*pmd)) { |
Johannes Weiner | e8216da | 2013-04-29 15:07:54 -0700 | [diff] [blame] | 1276 | void *p; |
Thomas Gleixner | 14a62c3 | 2008-01-30 13:34:10 +0100 | [diff] [blame] | 1277 | |
Dan Williams | 4b94ffd | 2016-01-15 16:56:22 -0800 | [diff] [blame] | 1278 | p = __vmemmap_alloc_block_buf(PMD_SIZE, node, altmap); |
Johannes Weiner | 8e2cdbc | 2013-04-29 15:07:56 -0700 | [diff] [blame] | 1279 | if (p) { |
| 1280 | pte_t entry; |
Jeremy Fitzhardinge | 7c934d3 | 2008-06-25 00:19:20 -0400 | [diff] [blame] | 1281 | |
Johannes Weiner | 8e2cdbc | 2013-04-29 15:07:56 -0700 | [diff] [blame] | 1282 | entry = pfn_pte(__pa(p) >> PAGE_SHIFT, |
| 1283 | PAGE_KERNEL_LARGE); |
| 1284 | set_pmd(pmd, __pmd(pte_val(entry))); |
Jeremy Fitzhardinge | 7c934d3 | 2008-06-25 00:19:20 -0400 | [diff] [blame] | 1285 | |
Johannes Weiner | 8e2cdbc | 2013-04-29 15:07:56 -0700 | [diff] [blame] | 1286 | /* check to see if we have contiguous blocks */ |
| 1287 | if (p_end != p || node_start != node) { |
| 1288 | if (p_start) |
Dan Williams | c9cdaeb | 2015-09-17 16:27:57 -0400 | [diff] [blame] | 1289 | pr_debug(" [%lx-%lx] PMD -> [%p-%p] on node %d\n", |
Johannes Weiner | 8e2cdbc | 2013-04-29 15:07:56 -0700 | [diff] [blame] | 1290 | addr_start, addr_end-1, p_start, p_end-1, node_start); |
| 1291 | addr_start = addr; |
| 1292 | node_start = node; |
| 1293 | p_start = p; |
| 1294 | } |
| 1295 | |
| 1296 | addr_end = addr + PMD_SIZE; |
| 1297 | p_end = p + PMD_SIZE; |
| 1298 | continue; |
Dan Williams | 4b94ffd | 2016-01-15 16:56:22 -0800 | [diff] [blame] | 1299 | } else if (altmap) |
| 1300 | return -ENOMEM; /* no fallback */ |
Johannes Weiner | 8e2cdbc | 2013-04-29 15:07:56 -0700 | [diff] [blame] | 1301 | } else if (pmd_large(*pmd)) { |
Johannes Weiner | e8216da | 2013-04-29 15:07:54 -0700 | [diff] [blame] | 1302 | vmemmap_verify((pte_t *)pmd, node, addr, next); |
Johannes Weiner | 8e2cdbc | 2013-04-29 15:07:56 -0700 | [diff] [blame] | 1303 | continue; |
| 1304 | } |
| 1305 | pr_warn_once("vmemmap: falling back to regular page backing\n"); |
| 1306 | if (vmemmap_populate_basepages(addr, next, node)) |
| 1307 | return -ENOMEM; |
Christoph Lameter | 0889eba | 2007-10-16 01:24:15 -0700 | [diff] [blame] | 1308 | } |
Christoph Lameter | 0889eba | 2007-10-16 01:24:15 -0700 | [diff] [blame] | 1309 | return 0; |
| 1310 | } |
Yinghai Lu | c2b91e2 | 2008-04-12 01:19:24 -0700 | [diff] [blame] | 1311 | |
Johannes Weiner | e8216da | 2013-04-29 15:07:54 -0700 | [diff] [blame] | 1312 | int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node) |
| 1313 | { |
Dan Williams | 4b94ffd | 2016-01-15 16:56:22 -0800 | [diff] [blame] | 1314 | struct vmem_altmap *altmap = to_vmem_altmap(start); |
Johannes Weiner | e8216da | 2013-04-29 15:07:54 -0700 | [diff] [blame] | 1315 | int err; |
| 1316 | |
Borislav Petkov | 16bf922 | 2016-03-29 17:42:03 +0200 | [diff] [blame] | 1317 | if (boot_cpu_has(X86_FEATURE_PSE)) |
Dan Williams | 4b94ffd | 2016-01-15 16:56:22 -0800 | [diff] [blame] | 1318 | err = vmemmap_populate_hugepages(start, end, node, altmap); |
| 1319 | else if (altmap) { |
| 1320 | pr_err_once("%s: no cpu support for altmap allocations\n", |
| 1321 | __func__); |
| 1322 | err = -ENOMEM; |
| 1323 | } else |
Johannes Weiner | e8216da | 2013-04-29 15:07:54 -0700 | [diff] [blame] | 1324 | err = vmemmap_populate_basepages(start, end, node); |
| 1325 | if (!err) |
Kirill A. Shutemov | 5372e15 | 2016-12-15 02:44:03 +0300 | [diff] [blame] | 1326 | sync_global_pgds(start, end - 1); |
Johannes Weiner | e8216da | 2013-04-29 15:07:54 -0700 | [diff] [blame] | 1327 | return err; |
| 1328 | } |
| 1329 | |
Yasuaki Ishimatsu | 46723bf | 2013-02-22 16:33:00 -0800 | [diff] [blame] | 1330 | #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HAVE_BOOTMEM_INFO_NODE) |
| 1331 | void register_page_bootmem_memmap(unsigned long section_nr, |
| 1332 | struct page *start_page, unsigned long size) |
| 1333 | { |
| 1334 | unsigned long addr = (unsigned long)start_page; |
| 1335 | unsigned long end = (unsigned long)(start_page + size); |
| 1336 | unsigned long next; |
| 1337 | pgd_t *pgd; |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 1338 | p4d_t *p4d; |
Yasuaki Ishimatsu | 46723bf | 2013-02-22 16:33:00 -0800 | [diff] [blame] | 1339 | pud_t *pud; |
| 1340 | pmd_t *pmd; |
| 1341 | unsigned int nr_pages; |
| 1342 | struct page *page; |
| 1343 | |
| 1344 | for (; addr < end; addr = next) { |
| 1345 | pte_t *pte = NULL; |
| 1346 | |
| 1347 | pgd = pgd_offset_k(addr); |
| 1348 | if (pgd_none(*pgd)) { |
| 1349 | next = (addr + PAGE_SIZE) & PAGE_MASK; |
| 1350 | continue; |
| 1351 | } |
| 1352 | get_page_bootmem(section_nr, pgd_page(*pgd), MIX_SECTION_INFO); |
| 1353 | |
Kirill A. Shutemov | f2a6a70 | 2017-03-17 21:55:15 +0300 | [diff] [blame] | 1354 | p4d = p4d_offset(pgd, addr); |
| 1355 | if (p4d_none(*p4d)) { |
| 1356 | next = (addr + PAGE_SIZE) & PAGE_MASK; |
| 1357 | continue; |
| 1358 | } |
| 1359 | get_page_bootmem(section_nr, p4d_page(*p4d), MIX_SECTION_INFO); |
| 1360 | |
| 1361 | pud = pud_offset(p4d, addr); |
Yasuaki Ishimatsu | 46723bf | 2013-02-22 16:33:00 -0800 | [diff] [blame] | 1362 | if (pud_none(*pud)) { |
| 1363 | next = (addr + PAGE_SIZE) & PAGE_MASK; |
| 1364 | continue; |
| 1365 | } |
| 1366 | get_page_bootmem(section_nr, pud_page(*pud), MIX_SECTION_INFO); |
| 1367 | |
Borislav Petkov | 16bf922 | 2016-03-29 17:42:03 +0200 | [diff] [blame] | 1368 | if (!boot_cpu_has(X86_FEATURE_PSE)) { |
Yasuaki Ishimatsu | 46723bf | 2013-02-22 16:33:00 -0800 | [diff] [blame] | 1369 | next = (addr + PAGE_SIZE) & PAGE_MASK; |
| 1370 | pmd = pmd_offset(pud, addr); |
| 1371 | if (pmd_none(*pmd)) |
| 1372 | continue; |
| 1373 | get_page_bootmem(section_nr, pmd_page(*pmd), |
| 1374 | MIX_SECTION_INFO); |
| 1375 | |
| 1376 | pte = pte_offset_kernel(pmd, addr); |
| 1377 | if (pte_none(*pte)) |
| 1378 | continue; |
| 1379 | get_page_bootmem(section_nr, pte_page(*pte), |
| 1380 | SECTION_INFO); |
| 1381 | } else { |
| 1382 | next = pmd_addr_end(addr, end); |
| 1383 | |
| 1384 | pmd = pmd_offset(pud, addr); |
| 1385 | if (pmd_none(*pmd)) |
| 1386 | continue; |
| 1387 | |
| 1388 | nr_pages = 1 << (get_order(PMD_SIZE)); |
| 1389 | page = pmd_page(*pmd); |
| 1390 | while (nr_pages--) |
| 1391 | get_page_bootmem(section_nr, page++, |
| 1392 | SECTION_INFO); |
| 1393 | } |
| 1394 | } |
| 1395 | } |
| 1396 | #endif |
| 1397 | |
Yinghai Lu | c2b91e2 | 2008-04-12 01:19:24 -0700 | [diff] [blame] | 1398 | void __meminit vmemmap_populate_print_last(void) |
| 1399 | { |
| 1400 | if (p_start) { |
Dan Williams | c9cdaeb | 2015-09-17 16:27:57 -0400 | [diff] [blame] | 1401 | pr_debug(" [%lx-%lx] PMD -> [%p-%p] on node %d\n", |
Yinghai Lu | c2b91e2 | 2008-04-12 01:19:24 -0700 | [diff] [blame] | 1402 | addr_start, addr_end-1, p_start, p_end-1, node_start); |
| 1403 | p_start = NULL; |
| 1404 | p_end = NULL; |
| 1405 | node_start = 0; |
| 1406 | } |
| 1407 | } |
Christoph Lameter | 0889eba | 2007-10-16 01:24:15 -0700 | [diff] [blame] | 1408 | #endif |