Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2002 Andi Kleen, SuSE Labs. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Thanks to Ben LaHaise for precious feedback. |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 4 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | #include <linux/highmem.h> |
Ingo Molnar | 8192206 | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 6 | #include <linux/bootmem.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <linux/module.h> |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 8 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/slab.h> |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 10 | #include <linux/mm.h> |
| 11 | |
Thomas Gleixner | 950f9d9 | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 12 | #include <asm/e820.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <asm/processor.h> |
| 14 | #include <asm/tlbflush.h> |
Dave Jones | f8af095 | 2006-01-06 00:12:10 -0800 | [diff] [blame] | 15 | #include <asm/sections.h> |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 16 | #include <asm/uaccess.h> |
| 17 | #include <asm/pgalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
Arjan van de Ven | ed724be | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 19 | static inline int |
| 20 | within(unsigned long addr, unsigned long start, unsigned long end) |
Ingo Molnar | 687c482 | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 21 | { |
Arjan van de Ven | ed724be | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 22 | return addr >= start && addr < end; |
| 23 | } |
| 24 | |
| 25 | /* |
Thomas Gleixner | d7c8f21 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 26 | * Flushing functions |
| 27 | */ |
Thomas Gleixner | cd8ddf1 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 28 | |
Thomas Gleixner | cd8ddf1 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 29 | /** |
| 30 | * clflush_cache_range - flush a cache range with clflush |
| 31 | * @addr: virtual start address |
| 32 | * @size: number of bytes to flush |
| 33 | * |
| 34 | * clflush is an unordered instruction which needs fencing with mfence |
| 35 | * to avoid ordering issues. |
| 36 | */ |
Ingo Molnar | 4c61afc | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 37 | void clflush_cache_range(void *vaddr, unsigned int size) |
Thomas Gleixner | d7c8f21 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 38 | { |
Ingo Molnar | 4c61afc | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 39 | void *vend = vaddr + size - 1; |
Thomas Gleixner | d7c8f21 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 40 | |
Thomas Gleixner | cd8ddf1 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 41 | mb(); |
Ingo Molnar | 4c61afc | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 42 | |
| 43 | for (; vaddr < vend; vaddr += boot_cpu_data.x86_clflush_size) |
| 44 | clflush(vaddr); |
| 45 | /* |
| 46 | * Flush any possible final partial cacheline: |
| 47 | */ |
| 48 | clflush(vend); |
| 49 | |
Thomas Gleixner | cd8ddf1 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 50 | mb(); |
Thomas Gleixner | d7c8f21 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 51 | } |
| 52 | |
Thomas Gleixner | af1e684 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 53 | static void __cpa_flush_all(void *arg) |
Thomas Gleixner | d7c8f21 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 54 | { |
| 55 | /* |
| 56 | * Flush all to work around Errata in early athlons regarding |
| 57 | * large page flushing. |
| 58 | */ |
| 59 | __flush_tlb_all(); |
| 60 | |
| 61 | if (boot_cpu_data.x86_model >= 4) |
| 62 | wbinvd(); |
| 63 | } |
| 64 | |
Thomas Gleixner | af1e684 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 65 | static void cpa_flush_all(void) |
Thomas Gleixner | d7c8f21 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 66 | { |
| 67 | BUG_ON(irqs_disabled()); |
| 68 | |
Thomas Gleixner | af1e684 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 69 | on_each_cpu(__cpa_flush_all, NULL, 1, 1); |
Thomas Gleixner | d7c8f21 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Thomas Gleixner | 57a6a46 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 72 | static void __cpa_flush_range(void *arg) |
| 73 | { |
Thomas Gleixner | 57a6a46 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 74 | /* |
| 75 | * We could optimize that further and do individual per page |
| 76 | * tlb invalidates for a low number of pages. Caveat: we must |
| 77 | * flush the high aliases on 64bit as well. |
| 78 | */ |
| 79 | __flush_tlb_all(); |
Thomas Gleixner | 57a6a46 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 80 | } |
| 81 | |
Ingo Molnar | 4c61afc | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 82 | static void cpa_flush_range(unsigned long start, int numpages) |
Thomas Gleixner | 57a6a46 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 83 | { |
Ingo Molnar | 4c61afc | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 84 | unsigned int i, level; |
| 85 | unsigned long addr; |
| 86 | |
Thomas Gleixner | 57a6a46 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 87 | BUG_ON(irqs_disabled()); |
Ingo Molnar | 4c61afc | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 88 | WARN_ON(PAGE_ALIGN(start) != start); |
Thomas Gleixner | 57a6a46 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 89 | |
Thomas Gleixner | 3b233e5 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 90 | on_each_cpu(__cpa_flush_range, NULL, 1, 1); |
Thomas Gleixner | 57a6a46 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 91 | |
Thomas Gleixner | 3b233e5 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 92 | /* |
| 93 | * We only need to flush on one CPU, |
| 94 | * clflush is a MESI-coherent instruction that |
| 95 | * will cause all other CPUs to flush the same |
| 96 | * cachelines: |
| 97 | */ |
Ingo Molnar | 4c61afc | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 98 | for (i = 0, addr = start; i < numpages; i++, addr += PAGE_SIZE) { |
| 99 | pte_t *pte = lookup_address(addr, &level); |
| 100 | |
| 101 | /* |
| 102 | * Only flush present addresses: |
| 103 | */ |
| 104 | if (pte && pte_present(*pte)) |
| 105 | clflush_cache_range((void *) addr, PAGE_SIZE); |
| 106 | } |
Thomas Gleixner | 57a6a46 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 107 | } |
| 108 | |
Arjan van de Ven | cc0f21b | 2008-02-04 16:48:05 +0100 | [diff] [blame] | 109 | #define HIGH_MAP_START __START_KERNEL_map |
| 110 | #define HIGH_MAP_END (__START_KERNEL_map + KERNEL_TEXT_SIZE) |
| 111 | |
| 112 | |
| 113 | /* |
| 114 | * Converts a virtual address to a X86-64 highmap address |
| 115 | */ |
| 116 | static unsigned long virt_to_highmap(void *address) |
| 117 | { |
| 118 | #ifdef CONFIG_X86_64 |
| 119 | return __pa((unsigned long)address) + HIGH_MAP_START - phys_base; |
| 120 | #else |
| 121 | return (unsigned long)address; |
| 122 | #endif |
| 123 | } |
| 124 | |
Thomas Gleixner | d7c8f21 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 125 | /* |
Arjan van de Ven | ed724be | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 126 | * Certain areas of memory on x86 require very specific protection flags, |
| 127 | * for example the BIOS area or kernel text. Callers don't always get this |
| 128 | * right (again, ioremap() on BIOS memory is not uncommon) so this function |
| 129 | * checks and fixes these known static required protection bits. |
| 130 | */ |
| 131 | static inline pgprot_t static_protections(pgprot_t prot, unsigned long address) |
| 132 | { |
| 133 | pgprot_t forbidden = __pgprot(0); |
| 134 | |
Ingo Molnar | 687c482 | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 135 | /* |
Arjan van de Ven | ed724be | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 136 | * The BIOS area between 640k and 1Mb needs to be executable for |
| 137 | * PCI BIOS based config access (CONFIG_PCI_GOBIOS) support. |
Ingo Molnar | 687c482 | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 138 | */ |
Arjan van de Ven | ed724be | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 139 | if (within(__pa(address), BIOS_BEGIN, BIOS_END)) |
| 140 | pgprot_val(forbidden) |= _PAGE_NX; |
| 141 | |
| 142 | /* |
| 143 | * The kernel text needs to be executable for obvious reasons |
| 144 | * Does not cover __inittext since that is gone later on |
| 145 | */ |
| 146 | if (within(address, (unsigned long)_text, (unsigned long)_etext)) |
| 147 | pgprot_val(forbidden) |= _PAGE_NX; |
Arjan van de Ven | cc0f21b | 2008-02-04 16:48:05 +0100 | [diff] [blame] | 148 | /* |
| 149 | * Do the same for the x86-64 high kernel mapping |
| 150 | */ |
| 151 | if (within(address, virt_to_highmap(_text), virt_to_highmap(_etext))) |
| 152 | pgprot_val(forbidden) |= _PAGE_NX; |
| 153 | |
Arjan van de Ven | ed724be | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 154 | |
| 155 | #ifdef CONFIG_DEBUG_RODATA |
| 156 | /* The .rodata section needs to be read-only */ |
| 157 | if (within(address, (unsigned long)__start_rodata, |
| 158 | (unsigned long)__end_rodata)) |
| 159 | pgprot_val(forbidden) |= _PAGE_RW; |
Arjan van de Ven | cc0f21b | 2008-02-04 16:48:05 +0100 | [diff] [blame] | 160 | /* |
| 161 | * Do the same for the x86-64 high kernel mapping |
| 162 | */ |
| 163 | if (within(address, virt_to_highmap(__start_rodata), |
| 164 | virt_to_highmap(__end_rodata))) |
| 165 | pgprot_val(forbidden) |= _PAGE_RW; |
Arjan van de Ven | ed724be | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 166 | #endif |
| 167 | |
| 168 | prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden)); |
Ingo Molnar | 687c482 | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 169 | |
| 170 | return prot; |
| 171 | } |
| 172 | |
Ingo Molnar | f0646e4 | 2008-01-30 13:33:43 +0100 | [diff] [blame] | 173 | pte_t *lookup_address(unsigned long address, int *level) |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 174 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | pgd_t *pgd = pgd_offset_k(address); |
| 176 | pud_t *pud; |
| 177 | pmd_t *pmd; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 178 | |
Thomas Gleixner | 30551bb | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 179 | *level = PG_LEVEL_NONE; |
| 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | if (pgd_none(*pgd)) |
| 182 | return NULL; |
| 183 | pud = pud_offset(pgd, address); |
| 184 | if (pud_none(*pud)) |
| 185 | return NULL; |
| 186 | pmd = pmd_offset(pud, address); |
| 187 | if (pmd_none(*pmd)) |
| 188 | return NULL; |
Thomas Gleixner | 30551bb | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 189 | |
| 190 | *level = PG_LEVEL_2M; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | if (pmd_large(*pmd)) |
| 192 | return (pte_t *)pmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
Thomas Gleixner | 30551bb | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 194 | *level = PG_LEVEL_4K; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 195 | return pte_offset_kernel(pmd, address); |
| 196 | } |
| 197 | |
Ingo Molnar | 9a3dc78 | 2008-01-30 13:33:57 +0100 | [diff] [blame] | 198 | static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte) |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 199 | { |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 200 | /* change init_mm */ |
| 201 | set_pte_atomic(kpte, pte); |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 202 | #ifdef CONFIG_X86_32 |
Ingo Molnar | e4b71dc | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 203 | if (!SHARED_KERNEL_PMD) { |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 204 | struct page *page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Jeremy Fitzhardinge | e3ed910 | 2008-01-30 13:34:11 +0100 | [diff] [blame] | 206 | list_for_each_entry(page, &pgd_list, lru) { |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 207 | pgd_t *pgd; |
| 208 | pud_t *pud; |
| 209 | pmd_t *pmd; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 210 | |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 211 | pgd = (pgd_t *)page_address(page) + pgd_index(address); |
| 212 | pud = pud_offset(pgd, address); |
| 213 | pmd = pmd_offset(pud, address); |
| 214 | set_pte_atomic((pte_t *)pmd, pte); |
| 215 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | } |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 217 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Ingo Molnar | 7afe15b | 2008-01-30 13:33:57 +0100 | [diff] [blame] | 220 | static int split_large_page(pte_t *kpte, unsigned long address) |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 221 | { |
Ingo Molnar | 7afe15b | 2008-01-30 13:33:57 +0100 | [diff] [blame] | 222 | pgprot_t ref_prot = pte_pgprot(pte_clrhuge(*kpte)); |
Ingo Molnar | 12d6f21 | 2008-01-30 13:33:58 +0100 | [diff] [blame] | 223 | gfp_t gfp_flags = GFP_KERNEL; |
Thomas Gleixner | 63c1dcf | 2008-02-04 16:48:05 +0100 | [diff] [blame] | 224 | unsigned long flags, addr, pfn; |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 225 | pte_t *pbase, *tmp; |
| 226 | struct page *base; |
Ingo Molnar | 86f0398 | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 227 | unsigned int i, level; |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 228 | |
Ingo Molnar | 12d6f21 | 2008-01-30 13:33:58 +0100 | [diff] [blame] | 229 | #ifdef CONFIG_DEBUG_PAGEALLOC |
Ingo Molnar | 86f0398 | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 230 | gfp_flags = __GFP_HIGH | __GFP_NOFAIL | __GFP_NOWARN; |
| 231 | gfp_flags = GFP_ATOMIC | __GFP_NOWARN; |
Ingo Molnar | 12d6f21 | 2008-01-30 13:33:58 +0100 | [diff] [blame] | 232 | #endif |
| 233 | base = alloc_pages(gfp_flags, 0); |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 234 | if (!base) |
| 235 | return -ENOMEM; |
| 236 | |
Ingo Molnar | 9a3dc78 | 2008-01-30 13:33:57 +0100 | [diff] [blame] | 237 | spin_lock_irqsave(&pgd_lock, flags); |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 238 | /* |
| 239 | * Check for races, another CPU might have split this page |
| 240 | * up for us already: |
| 241 | */ |
| 242 | tmp = lookup_address(address, &level); |
Ingo Molnar | 5508a74 | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 243 | if (tmp != kpte) { |
| 244 | WARN_ON_ONCE(1); |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 245 | goto out_unlock; |
Ingo Molnar | 5508a74 | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 246 | } |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 247 | |
| 248 | address = __pa(address); |
| 249 | addr = address & LARGE_PAGE_MASK; |
| 250 | pbase = (pte_t *)page_address(base); |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 251 | #ifdef CONFIG_X86_32 |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 252 | paravirt_alloc_pt(&init_mm, page_to_pfn(base)); |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 253 | #endif |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 254 | |
Thomas Gleixner | 63c1dcf | 2008-02-04 16:48:05 +0100 | [diff] [blame] | 255 | /* |
| 256 | * Get the target pfn from the original entry: |
| 257 | */ |
| 258 | pfn = pte_pfn(*kpte); |
| 259 | for (i = 0; i < PTRS_PER_PTE; i++, pfn++) |
| 260 | set_pte(&pbase[i], pfn_pte(pfn, ref_prot)); |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 261 | |
| 262 | /* |
Huang, Ying | 4c881ca | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 263 | * Install the new, split up pagetable. Important detail here: |
| 264 | * |
| 265 | * On Intel the NX bit of all levels must be cleared to make a |
| 266 | * page executable. See section 4.13.2 of Intel 64 and IA-32 |
| 267 | * Architectures Software Developer's Manual). |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 268 | */ |
Huang, Ying | 4c881ca | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 269 | ref_prot = pte_pgprot(pte_mkexec(pte_clrhuge(*kpte))); |
Ingo Molnar | 9a3dc78 | 2008-01-30 13:33:57 +0100 | [diff] [blame] | 270 | __set_pmd_pte(kpte, address, mk_pte(base, ref_prot)); |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 271 | base = NULL; |
| 272 | |
| 273 | out_unlock: |
Ingo Molnar | 9a3dc78 | 2008-01-30 13:33:57 +0100 | [diff] [blame] | 274 | spin_unlock_irqrestore(&pgd_lock, flags); |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 275 | |
| 276 | if (base) |
| 277 | __free_pages(base, 0); |
| 278 | |
| 279 | return 0; |
| 280 | } |
| 281 | |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 282 | static int |
Arjan van de Ven | 626c2c9 | 2008-02-04 16:48:05 +0100 | [diff] [blame] | 283 | __change_page_attr(unsigned long address, pgprot_t mask_set, pgprot_t mask_clr) |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 284 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | struct page *kpte_page; |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 286 | int level, err = 0; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 287 | pte_t *kpte; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
Ingo Molnar | 97f99fe | 2008-01-30 13:33:55 +0100 | [diff] [blame] | 289 | repeat: |
Ingo Molnar | f0646e4 | 2008-01-30 13:33:43 +0100 | [diff] [blame] | 290 | kpte = lookup_address(address, &level); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | if (!kpte) |
| 292 | return -EINVAL; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | kpte_page = virt_to_page(kpte); |
Andi Kleen | 65d2f0b | 2007-07-21 17:09:51 +0200 | [diff] [blame] | 295 | BUG_ON(PageLRU(kpte_page)); |
| 296 | BUG_ON(PageCompound(kpte_page)); |
| 297 | |
Thomas Gleixner | 30551bb | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 298 | if (level == PG_LEVEL_4K) { |
Ingo Molnar | 86f0398 | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 299 | pte_t new_pte, old_pte = *kpte; |
Arjan van de Ven | 626c2c9 | 2008-02-04 16:48:05 +0100 | [diff] [blame] | 300 | pgprot_t new_prot = pte_pgprot(old_pte); |
| 301 | |
| 302 | if(!pte_val(old_pte)) { |
| 303 | WARN_ON_ONCE(1); |
| 304 | return -EINVAL; |
| 305 | } |
Thomas Gleixner | a72a08a | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 306 | |
Ingo Molnar | 86f0398 | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 307 | pgprot_val(new_prot) &= ~pgprot_val(mask_clr); |
| 308 | pgprot_val(new_prot) |= pgprot_val(mask_set); |
| 309 | |
| 310 | new_prot = static_protections(new_prot, address); |
| 311 | |
Arjan van de Ven | 626c2c9 | 2008-02-04 16:48:05 +0100 | [diff] [blame] | 312 | /* |
| 313 | * We need to keep the pfn from the existing PTE, |
| 314 | * after all we're only going to change it's attributes |
| 315 | * not the memory it points to |
| 316 | */ |
| 317 | new_pte = pfn_pte(pte_pfn(old_pte), canon_pgprot(new_prot)); |
Ingo Molnar | 86f0398 | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 318 | set_pte_atomic(kpte, new_pte); |
| 319 | } else { |
Ingo Molnar | 7afe15b | 2008-01-30 13:33:57 +0100 | [diff] [blame] | 320 | err = split_large_page(kpte, address); |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 321 | if (!err) |
| 322 | goto repeat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | } |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 324 | return err; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 325 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 327 | /** |
| 328 | * change_page_attr_addr - Change page table attributes in linear mapping |
| 329 | * @address: Virtual address in linear mapping. |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 330 | * @prot: New page table attribute (PAGE_*) |
| 331 | * |
| 332 | * Change page attributes of a page in the direct mapping. This is a variant |
| 333 | * of change_page_attr() that also works on memory holes that do not have |
| 334 | * mem_map entry (pfn_valid() is false). |
| 335 | * |
| 336 | * See change_page_attr() documentation for more details. |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 337 | * |
| 338 | * Modules and drivers should use the set_memory_* APIs instead. |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 339 | */ |
| 340 | |
Thomas Gleixner | 0879750 | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 341 | |
Ingo Molnar | 86f0398 | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 342 | static int |
| 343 | change_page_attr_addr(unsigned long address, pgprot_t mask_set, |
Thomas Gleixner | 0879750 | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 344 | pgprot_t mask_clr) |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 345 | { |
Thomas Gleixner | 0879750 | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 346 | int err; |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 347 | |
Arjan van de Ven | 488fd99 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 348 | #ifdef CONFIG_X86_64 |
Arjan van de Ven | 626c2c9 | 2008-02-04 16:48:05 +0100 | [diff] [blame] | 349 | unsigned long phys_addr = __pa(address); |
| 350 | |
Arjan van de Ven | 488fd99 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 351 | /* |
Thomas Gleixner | 0879750 | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 352 | * If we are inside the high mapped kernel range, then we |
| 353 | * fixup the low mapping first. __va() returns the virtual |
| 354 | * address in the linear mapping: |
Arjan van de Ven | 488fd99 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 355 | */ |
Thomas Gleixner | 0879750 | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 356 | if (within(address, HIGH_MAP_START, HIGH_MAP_END)) |
| 357 | address = (unsigned long) __va(phys_addr); |
Arjan van de Ven | 488fd99 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 358 | #endif |
| 359 | |
Arjan van de Ven | 626c2c9 | 2008-02-04 16:48:05 +0100 | [diff] [blame] | 360 | err = __change_page_attr(address, mask_set, mask_clr); |
Thomas Gleixner | 0879750 | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 361 | if (err) |
| 362 | return err; |
| 363 | |
| 364 | #ifdef CONFIG_X86_64 |
| 365 | /* |
| 366 | * If the physical address is inside the kernel map, we need |
| 367 | * to touch the high mapped kernel as well: |
| 368 | */ |
| 369 | if (within(phys_addr, 0, KERNEL_TEXT_SIZE)) { |
| 370 | /* |
| 371 | * Calc the high mapping address. See __phys_addr() |
| 372 | * for the non obvious details. |
Arjan van de Ven | cc0f21b | 2008-02-04 16:48:05 +0100 | [diff] [blame] | 373 | * |
| 374 | * Note that NX and other required permissions are |
| 375 | * checked in static_protections(). |
Thomas Gleixner | 0879750 | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 376 | */ |
| 377 | address = phys_addr + HIGH_MAP_START - phys_base; |
Thomas Gleixner | 0879750 | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 378 | |
| 379 | /* |
| 380 | * Our high aliases are imprecise, because we check |
| 381 | * everything between 0 and KERNEL_TEXT_SIZE, so do |
| 382 | * not propagate lookup failures back to users: |
| 383 | */ |
Arjan van de Ven | 626c2c9 | 2008-02-04 16:48:05 +0100 | [diff] [blame] | 384 | __change_page_attr(address, mask_set, mask_clr); |
Thomas Gleixner | 0879750 | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 385 | } |
| 386 | #endif |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 387 | return err; |
| 388 | } |
| 389 | |
Thomas Gleixner | ff31452 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 390 | static int __change_page_attr_set_clr(unsigned long addr, int numpages, |
| 391 | pgprot_t mask_set, pgprot_t mask_clr) |
| 392 | { |
Ingo Molnar | 86f0398 | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 393 | unsigned int i; |
| 394 | int ret; |
Thomas Gleixner | ff31452 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 395 | |
Ingo Molnar | 86f0398 | 2008-01-30 13:34:09 +0100 | [diff] [blame] | 396 | for (i = 0; i < numpages ; i++, addr += PAGE_SIZE) { |
| 397 | ret = change_page_attr_addr(addr, mask_set, mask_clr); |
Thomas Gleixner | ff31452 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 398 | if (ret) |
| 399 | return ret; |
Thomas Gleixner | ff31452 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | return 0; |
| 403 | } |
| 404 | |
| 405 | static int change_page_attr_set_clr(unsigned long addr, int numpages, |
| 406 | pgprot_t mask_set, pgprot_t mask_clr) |
| 407 | { |
Thomas Gleixner | 331e406 | 2008-02-04 16:48:06 +0100 | [diff] [blame^] | 408 | int ret; |
| 409 | |
| 410 | /* |
| 411 | * Check, if we are requested to change a not supported |
| 412 | * feature: |
| 413 | */ |
| 414 | mask_set = canon_pgprot(mask_set); |
| 415 | mask_clr = canon_pgprot(mask_clr); |
| 416 | if (!pgprot_val(mask_set) && !pgprot_val(mask_clr)) |
| 417 | return 0; |
| 418 | |
| 419 | ret = __change_page_attr_set_clr(addr, numpages, mask_set, mask_clr); |
Thomas Gleixner | ff31452 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 420 | |
Thomas Gleixner | 57a6a46 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 421 | /* |
| 422 | * On success we use clflush, when the CPU supports it to |
| 423 | * avoid the wbindv. If the CPU does not support it and in the |
Thomas Gleixner | af1e684 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 424 | * error case we fall back to cpa_flush_all (which uses |
Thomas Gleixner | 57a6a46 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 425 | * wbindv): |
| 426 | */ |
| 427 | if (!ret && cpu_has_clflush) |
| 428 | cpa_flush_range(addr, numpages); |
| 429 | else |
Thomas Gleixner | af1e684 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 430 | cpa_flush_all(); |
Thomas Gleixner | ff31452 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 431 | |
| 432 | return ret; |
| 433 | } |
| 434 | |
Thomas Gleixner | 5674454 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 435 | static inline int change_page_attr_set(unsigned long addr, int numpages, |
| 436 | pgprot_t mask) |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 437 | { |
Thomas Gleixner | 5674454 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 438 | return change_page_attr_set_clr(addr, numpages, mask, __pgprot(0)); |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 439 | } |
| 440 | |
Thomas Gleixner | 5674454 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 441 | static inline int change_page_attr_clear(unsigned long addr, int numpages, |
| 442 | pgprot_t mask) |
Thomas Gleixner | 72932c7 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 443 | { |
Huang, Ying | 5827040 | 2008-01-31 22:05:43 +0100 | [diff] [blame] | 444 | return change_page_attr_set_clr(addr, numpages, __pgprot(0), mask); |
Thomas Gleixner | 72932c7 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 445 | } |
| 446 | |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 447 | int set_memory_uc(unsigned long addr, int numpages) |
| 448 | { |
Thomas Gleixner | 72932c7 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 449 | return change_page_attr_set(addr, numpages, |
| 450 | __pgprot(_PAGE_PCD | _PAGE_PWT)); |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 451 | } |
| 452 | EXPORT_SYMBOL(set_memory_uc); |
| 453 | |
| 454 | int set_memory_wb(unsigned long addr, int numpages) |
| 455 | { |
Thomas Gleixner | 72932c7 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 456 | return change_page_attr_clear(addr, numpages, |
| 457 | __pgprot(_PAGE_PCD | _PAGE_PWT)); |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 458 | } |
| 459 | EXPORT_SYMBOL(set_memory_wb); |
| 460 | |
| 461 | int set_memory_x(unsigned long addr, int numpages) |
| 462 | { |
Thomas Gleixner | 72932c7 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 463 | return change_page_attr_clear(addr, numpages, __pgprot(_PAGE_NX)); |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 464 | } |
| 465 | EXPORT_SYMBOL(set_memory_x); |
| 466 | |
| 467 | int set_memory_nx(unsigned long addr, int numpages) |
| 468 | { |
Thomas Gleixner | 72932c7 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 469 | return change_page_attr_set(addr, numpages, __pgprot(_PAGE_NX)); |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 470 | } |
| 471 | EXPORT_SYMBOL(set_memory_nx); |
| 472 | |
| 473 | int set_memory_ro(unsigned long addr, int numpages) |
| 474 | { |
Thomas Gleixner | 72932c7 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 475 | return change_page_attr_clear(addr, numpages, __pgprot(_PAGE_RW)); |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 476 | } |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 477 | |
| 478 | int set_memory_rw(unsigned long addr, int numpages) |
| 479 | { |
Thomas Gleixner | 72932c7 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 480 | return change_page_attr_set(addr, numpages, __pgprot(_PAGE_RW)); |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 481 | } |
Ingo Molnar | f62d0f0 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 482 | |
| 483 | int set_memory_np(unsigned long addr, int numpages) |
| 484 | { |
Thomas Gleixner | 72932c7 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 485 | return change_page_attr_clear(addr, numpages, __pgprot(_PAGE_PRESENT)); |
Ingo Molnar | f62d0f0 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 486 | } |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 487 | |
| 488 | int set_pages_uc(struct page *page, int numpages) |
| 489 | { |
| 490 | unsigned long addr = (unsigned long)page_address(page); |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 491 | |
Thomas Gleixner | d7c8f21 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 492 | return set_memory_uc(addr, numpages); |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 493 | } |
| 494 | EXPORT_SYMBOL(set_pages_uc); |
| 495 | |
| 496 | int set_pages_wb(struct page *page, int numpages) |
| 497 | { |
| 498 | unsigned long addr = (unsigned long)page_address(page); |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 499 | |
Thomas Gleixner | d7c8f21 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 500 | return set_memory_wb(addr, numpages); |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 501 | } |
| 502 | EXPORT_SYMBOL(set_pages_wb); |
| 503 | |
| 504 | int set_pages_x(struct page *page, int numpages) |
| 505 | { |
| 506 | unsigned long addr = (unsigned long)page_address(page); |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 507 | |
Thomas Gleixner | d7c8f21 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 508 | return set_memory_x(addr, numpages); |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 509 | } |
| 510 | EXPORT_SYMBOL(set_pages_x); |
| 511 | |
| 512 | int set_pages_nx(struct page *page, int numpages) |
| 513 | { |
| 514 | unsigned long addr = (unsigned long)page_address(page); |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 515 | |
Thomas Gleixner | d7c8f21 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 516 | return set_memory_nx(addr, numpages); |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 517 | } |
| 518 | EXPORT_SYMBOL(set_pages_nx); |
| 519 | |
| 520 | int set_pages_ro(struct page *page, int numpages) |
| 521 | { |
| 522 | unsigned long addr = (unsigned long)page_address(page); |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 523 | |
Thomas Gleixner | d7c8f21 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 524 | return set_memory_ro(addr, numpages); |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 525 | } |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 526 | |
| 527 | int set_pages_rw(struct page *page, int numpages) |
| 528 | { |
| 529 | unsigned long addr = (unsigned long)page_address(page); |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 530 | |
Thomas Gleixner | d7c8f21 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 531 | return set_memory_rw(addr, numpages); |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 532 | } |
Arjan van de Ven | 75cbade | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 533 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
Thomas Gleixner | 5674454 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 535 | #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_CPA_DEBUG) |
| 536 | static inline int __change_page_attr_set(unsigned long addr, int numpages, |
| 537 | pgprot_t mask) |
| 538 | { |
| 539 | return __change_page_attr_set_clr(addr, numpages, mask, __pgprot(0)); |
| 540 | } |
| 541 | |
| 542 | static inline int __change_page_attr_clear(unsigned long addr, int numpages, |
| 543 | pgprot_t mask) |
| 544 | { |
| 545 | return __change_page_attr_set_clr(addr, numpages, __pgprot(0), mask); |
| 546 | } |
| 547 | #endif |
| 548 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | #ifdef CONFIG_DEBUG_PAGEALLOC |
Ingo Molnar | f62d0f0 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 550 | |
| 551 | static int __set_pages_p(struct page *page, int numpages) |
| 552 | { |
| 553 | unsigned long addr = (unsigned long)page_address(page); |
Thomas Gleixner | 72932c7 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 554 | |
| 555 | return __change_page_attr_set(addr, numpages, |
| 556 | __pgprot(_PAGE_PRESENT | _PAGE_RW)); |
Ingo Molnar | f62d0f0 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | static int __set_pages_np(struct page *page, int numpages) |
| 560 | { |
| 561 | unsigned long addr = (unsigned long)page_address(page); |
Thomas Gleixner | 72932c7 | 2008-01-30 13:34:08 +0100 | [diff] [blame] | 562 | |
| 563 | return __change_page_attr_clear(addr, numpages, |
| 564 | __pgprot(_PAGE_PRESENT)); |
Ingo Molnar | f62d0f0 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 565 | } |
| 566 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | void kernel_map_pages(struct page *page, int numpages, int enable) |
| 568 | { |
| 569 | if (PageHighMem(page)) |
| 570 | return; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 571 | if (!enable) { |
Ingo Molnar | f9b8404 | 2006-06-27 02:54:49 -0700 | [diff] [blame] | 572 | debug_check_no_locks_freed(page_address(page), |
| 573 | numpages * PAGE_SIZE); |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 574 | } |
Ingo Molnar | de5097c | 2006-01-09 15:59:21 -0800 | [diff] [blame] | 575 | |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 576 | /* |
Ingo Molnar | 12d6f21 | 2008-01-30 13:33:58 +0100 | [diff] [blame] | 577 | * If page allocator is not up yet then do not call c_p_a(): |
| 578 | */ |
| 579 | if (!debug_pagealloc_enabled) |
| 580 | return; |
| 581 | |
| 582 | /* |
Ingo Molnar | e4b71dc | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 583 | * The return value is ignored - the calls cannot fail, |
| 584 | * large pages are disabled at boot time: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | */ |
Ingo Molnar | f62d0f0 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 586 | if (enable) |
| 587 | __set_pages_p(page, numpages); |
| 588 | else |
| 589 | __set_pages_np(page, numpages); |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 590 | |
| 591 | /* |
Ingo Molnar | e4b71dc | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 592 | * We should perform an IPI and flush all tlbs, |
| 593 | * but that can deadlock->flush only current cpu: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | */ |
| 595 | __flush_tlb_all(); |
| 596 | } |
| 597 | #endif |
Arjan van de Ven | d1028a1 | 2008-01-30 13:34:07 +0100 | [diff] [blame] | 598 | |
| 599 | /* |
| 600 | * The testcases use internal knowledge of the implementation that shouldn't |
| 601 | * be exposed to the rest of the kernel. Include these directly here. |
| 602 | */ |
| 603 | #ifdef CONFIG_CPA_DEBUG |
| 604 | #include "pageattr-test.c" |
| 605 | #endif |