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 | |
Ingo Molnar | 4554ab9 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 12 | void clflush_cache_range(void *addr, int size) |
| 13 | { |
| 14 | int i; |
| 15 | |
| 16 | for (i = 0; i < size; i += boot_cpu_data.x86_clflush_size) |
| 17 | clflush(addr+i); |
| 18 | } |
| 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <asm/processor.h> |
| 21 | #include <asm/tlbflush.h> |
Dave Jones | f8af095 | 2006-01-06 00:12:10 -0800 | [diff] [blame] | 22 | #include <asm/sections.h> |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 23 | #include <asm/uaccess.h> |
| 24 | #include <asm/pgalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Ingo Molnar | 687c482 | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 26 | /* |
Arjan van de Ven | ed724be | 2008-01-30 13:34:04 +0100 | [diff] [blame^] | 27 | * We must allow the BIOS range to be executable: |
Ingo Molnar | 687c482 | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 28 | */ |
| 29 | #define BIOS_BEGIN 0x000a0000 |
| 30 | #define BIOS_END 0x00100000 |
| 31 | |
Arjan van de Ven | ed724be | 2008-01-30 13:34:04 +0100 | [diff] [blame^] | 32 | static inline int |
| 33 | within(unsigned long addr, unsigned long start, unsigned long end) |
Ingo Molnar | 687c482 | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 34 | { |
Arjan van de Ven | ed724be | 2008-01-30 13:34:04 +0100 | [diff] [blame^] | 35 | return addr >= start && addr < end; |
| 36 | } |
| 37 | |
| 38 | /* |
| 39 | * Certain areas of memory on x86 require very specific protection flags, |
| 40 | * for example the BIOS area or kernel text. Callers don't always get this |
| 41 | * right (again, ioremap() on BIOS memory is not uncommon) so this function |
| 42 | * checks and fixes these known static required protection bits. |
| 43 | */ |
| 44 | static inline pgprot_t static_protections(pgprot_t prot, unsigned long address) |
| 45 | { |
| 46 | pgprot_t forbidden = __pgprot(0); |
| 47 | |
Ingo Molnar | 687c482 | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 48 | /* |
Arjan van de Ven | ed724be | 2008-01-30 13:34:04 +0100 | [diff] [blame^] | 49 | * The BIOS area between 640k and 1Mb needs to be executable for |
| 50 | * PCI BIOS based config access (CONFIG_PCI_GOBIOS) support. |
Ingo Molnar | 687c482 | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 51 | */ |
Arjan van de Ven | ed724be | 2008-01-30 13:34:04 +0100 | [diff] [blame^] | 52 | if (within(__pa(address), BIOS_BEGIN, BIOS_END)) |
| 53 | pgprot_val(forbidden) |= _PAGE_NX; |
| 54 | |
| 55 | /* |
| 56 | * The kernel text needs to be executable for obvious reasons |
| 57 | * Does not cover __inittext since that is gone later on |
| 58 | */ |
| 59 | if (within(address, (unsigned long)_text, (unsigned long)_etext)) |
| 60 | pgprot_val(forbidden) |= _PAGE_NX; |
| 61 | |
| 62 | #ifdef CONFIG_DEBUG_RODATA |
| 63 | /* The .rodata section needs to be read-only */ |
| 64 | if (within(address, (unsigned long)__start_rodata, |
| 65 | (unsigned long)__end_rodata)) |
| 66 | pgprot_val(forbidden) |= _PAGE_RW; |
| 67 | #endif |
| 68 | |
| 69 | prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden)); |
Ingo Molnar | 687c482 | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 70 | |
| 71 | return prot; |
| 72 | } |
| 73 | |
Ingo Molnar | f0646e4 | 2008-01-30 13:33:43 +0100 | [diff] [blame] | 74 | pte_t *lookup_address(unsigned long address, int *level) |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 75 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | pgd_t *pgd = pgd_offset_k(address); |
| 77 | pud_t *pud; |
| 78 | pmd_t *pmd; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 79 | |
Thomas Gleixner | 30551bb | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 80 | *level = PG_LEVEL_NONE; |
| 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | if (pgd_none(*pgd)) |
| 83 | return NULL; |
| 84 | pud = pud_offset(pgd, address); |
| 85 | if (pud_none(*pud)) |
| 86 | return NULL; |
| 87 | pmd = pmd_offset(pud, address); |
| 88 | if (pmd_none(*pmd)) |
| 89 | return NULL; |
Thomas Gleixner | 30551bb | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 90 | |
| 91 | *level = PG_LEVEL_2M; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | if (pmd_large(*pmd)) |
| 93 | return (pte_t *)pmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
Thomas Gleixner | 30551bb | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 95 | *level = PG_LEVEL_4K; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 96 | return pte_offset_kernel(pmd, address); |
| 97 | } |
| 98 | |
Ingo Molnar | 9a3dc78 | 2008-01-30 13:33:57 +0100 | [diff] [blame] | 99 | 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] | 100 | { |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 101 | /* change init_mm */ |
| 102 | set_pte_atomic(kpte, pte); |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 103 | #ifdef CONFIG_X86_32 |
Ingo Molnar | e4b71dc | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 104 | if (!SHARED_KERNEL_PMD) { |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 105 | struct page *page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 107 | for (page = pgd_list; page; page = (struct page *)page->index) { |
| 108 | pgd_t *pgd; |
| 109 | pud_t *pud; |
| 110 | pmd_t *pmd; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 111 | |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 112 | pgd = (pgd_t *)page_address(page) + pgd_index(address); |
| 113 | pud = pud_offset(pgd, address); |
| 114 | pmd = pmd_offset(pud, address); |
| 115 | set_pte_atomic((pte_t *)pmd, pte); |
| 116 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 118 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Ingo Molnar | 7afe15b | 2008-01-30 13:33:57 +0100 | [diff] [blame] | 121 | static int split_large_page(pte_t *kpte, unsigned long address) |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 122 | { |
Ingo Molnar | 7afe15b | 2008-01-30 13:33:57 +0100 | [diff] [blame] | 123 | pgprot_t ref_prot = pte_pgprot(pte_clrhuge(*kpte)); |
Ingo Molnar | 12d6f21 | 2008-01-30 13:33:58 +0100 | [diff] [blame] | 124 | gfp_t gfp_flags = GFP_KERNEL; |
Ingo Molnar | 9a3dc78 | 2008-01-30 13:33:57 +0100 | [diff] [blame] | 125 | unsigned long flags; |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 126 | unsigned long addr; |
| 127 | pte_t *pbase, *tmp; |
| 128 | struct page *base; |
Ingo Molnar | 7afe15b | 2008-01-30 13:33:57 +0100 | [diff] [blame] | 129 | int i, level; |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 130 | |
Ingo Molnar | 12d6f21 | 2008-01-30 13:33:58 +0100 | [diff] [blame] | 131 | #ifdef CONFIG_DEBUG_PAGEALLOC |
| 132 | gfp_flags = GFP_ATOMIC; |
| 133 | #endif |
| 134 | base = alloc_pages(gfp_flags, 0); |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 135 | if (!base) |
| 136 | return -ENOMEM; |
| 137 | |
Ingo Molnar | 9a3dc78 | 2008-01-30 13:33:57 +0100 | [diff] [blame] | 138 | spin_lock_irqsave(&pgd_lock, flags); |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 139 | /* |
| 140 | * Check for races, another CPU might have split this page |
| 141 | * up for us already: |
| 142 | */ |
| 143 | tmp = lookup_address(address, &level); |
Ingo Molnar | 5508a74 | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 144 | if (tmp != kpte) { |
| 145 | WARN_ON_ONCE(1); |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 146 | goto out_unlock; |
Ingo Molnar | 5508a74 | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 147 | } |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 148 | |
| 149 | address = __pa(address); |
| 150 | addr = address & LARGE_PAGE_MASK; |
| 151 | pbase = (pte_t *)page_address(base); |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 152 | #ifdef CONFIG_X86_32 |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 153 | paravirt_alloc_pt(&init_mm, page_to_pfn(base)); |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 154 | #endif |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 155 | |
| 156 | for (i = 0; i < PTRS_PER_PTE; i++, addr += PAGE_SIZE) |
| 157 | set_pte(&pbase[i], pfn_pte(addr >> PAGE_SHIFT, ref_prot)); |
| 158 | |
| 159 | /* |
Huang, Ying | 4c881ca | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 160 | * Install the new, split up pagetable. Important detail here: |
| 161 | * |
| 162 | * On Intel the NX bit of all levels must be cleared to make a |
| 163 | * page executable. See section 4.13.2 of Intel 64 and IA-32 |
| 164 | * Architectures Software Developer's Manual). |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 165 | */ |
Huang, Ying | 4c881ca | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 166 | ref_prot = pte_pgprot(pte_mkexec(pte_clrhuge(*kpte))); |
Ingo Molnar | 9a3dc78 | 2008-01-30 13:33:57 +0100 | [diff] [blame] | 167 | __set_pmd_pte(kpte, address, mk_pte(base, ref_prot)); |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 168 | base = NULL; |
| 169 | |
| 170 | out_unlock: |
Ingo Molnar | 9a3dc78 | 2008-01-30 13:33:57 +0100 | [diff] [blame] | 171 | spin_unlock_irqrestore(&pgd_lock, flags); |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 172 | |
| 173 | if (base) |
| 174 | __free_pages(base, 0); |
| 175 | |
| 176 | return 0; |
| 177 | } |
| 178 | |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 179 | static int |
Ingo Molnar | 8192206 | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 180 | __change_page_attr(unsigned long address, unsigned long pfn, pgprot_t prot) |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 181 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | struct page *kpte_page; |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 183 | int level, err = 0; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 184 | pte_t *kpte; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
Ingo Molnar | 8192206 | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 186 | #ifdef CONFIG_X86_32 |
| 187 | BUG_ON(pfn > max_low_pfn); |
| 188 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
Ingo Molnar | 97f99fe | 2008-01-30 13:33:55 +0100 | [diff] [blame] | 190 | repeat: |
Ingo Molnar | f0646e4 | 2008-01-30 13:33:43 +0100 | [diff] [blame] | 191 | kpte = lookup_address(address, &level); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | if (!kpte) |
| 193 | return -EINVAL; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | kpte_page = virt_to_page(kpte); |
Andi Kleen | 65d2f0b | 2007-07-21 17:09:51 +0200 | [diff] [blame] | 196 | BUG_ON(PageLRU(kpte_page)); |
| 197 | BUG_ON(PageCompound(kpte_page)); |
| 198 | |
Arjan van de Ven | ed724be | 2008-01-30 13:34:04 +0100 | [diff] [blame^] | 199 | prot = static_protections(prot, address); |
Andi Kleen | 65d2f0b | 2007-07-21 17:09:51 +0200 | [diff] [blame] | 200 | |
Thomas Gleixner | 30551bb | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 201 | if (level == PG_LEVEL_4K) { |
Ingo Molnar | 8192206 | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 202 | set_pte_atomic(kpte, pfn_pte(pfn, canon_pgprot(prot))); |
Ingo Molnar | 78c94ab | 2008-01-30 13:33:55 +0100 | [diff] [blame] | 203 | } else { |
Ingo Molnar | 7afe15b | 2008-01-30 13:33:57 +0100 | [diff] [blame] | 204 | err = split_large_page(kpte, address); |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 205 | if (!err) |
| 206 | goto repeat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | } |
Ingo Molnar | bb5c2db | 2008-01-30 13:33:56 +0100 | [diff] [blame] | 208 | return err; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 209 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 211 | /** |
| 212 | * change_page_attr_addr - Change page table attributes in linear mapping |
| 213 | * @address: Virtual address in linear mapping. |
| 214 | * @numpages: Number of pages to change |
| 215 | * @prot: New page table attribute (PAGE_*) |
| 216 | * |
| 217 | * Change page attributes of a page in the direct mapping. This is a variant |
| 218 | * of change_page_attr() that also works on memory holes that do not have |
| 219 | * mem_map entry (pfn_valid() is false). |
| 220 | * |
| 221 | * See change_page_attr() documentation for more details. |
| 222 | */ |
| 223 | |
| 224 | int change_page_attr_addr(unsigned long address, int numpages, pgprot_t prot) |
| 225 | { |
| 226 | int err = 0, kernel_map = 0, i; |
| 227 | |
| 228 | #ifdef CONFIG_X86_64 |
| 229 | if (address >= __START_KERNEL_map && |
| 230 | address < __START_KERNEL_map + KERNEL_TEXT_SIZE) { |
| 231 | |
| 232 | address = (unsigned long)__va(__pa(address)); |
| 233 | kernel_map = 1; |
| 234 | } |
| 235 | #endif |
| 236 | |
| 237 | for (i = 0; i < numpages; i++, address += PAGE_SIZE) { |
| 238 | unsigned long pfn = __pa(address) >> PAGE_SHIFT; |
| 239 | |
| 240 | if (!kernel_map || pte_present(pfn_pte(0, prot))) { |
Ingo Molnar | 8192206 | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 241 | err = __change_page_attr(address, pfn, prot); |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 242 | if (err) |
| 243 | break; |
| 244 | } |
| 245 | #ifdef CONFIG_X86_64 |
| 246 | /* |
| 247 | * Handle kernel mapping too which aliases part of |
| 248 | * lowmem: |
| 249 | */ |
| 250 | if (__pa(address) < KERNEL_TEXT_SIZE) { |
| 251 | unsigned long addr2; |
| 252 | pgprot_t prot2; |
| 253 | |
| 254 | addr2 = __START_KERNEL_map + __pa(address); |
| 255 | /* Make sure the kernel mappings stay executable */ |
| 256 | prot2 = pte_pgprot(pte_mkexec(pfn_pte(0, prot))); |
Ingo Molnar | 8192206 | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 257 | err = __change_page_attr(addr2, pfn, prot2); |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 258 | } |
| 259 | #endif |
| 260 | } |
| 261 | |
| 262 | return err; |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * change_page_attr - Change page table attributes in the linear mapping. |
| 267 | * @page: First page to change |
| 268 | * @numpages: Number of pages to change |
| 269 | * @prot: New protection/caching type (PAGE_*) |
| 270 | * |
| 271 | * Returns 0 on success, otherwise a negated errno. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | * |
| 273 | * This should be used when a page is mapped with a different caching policy |
| 274 | * than write-back somewhere - some CPUs do not like it when mappings with |
| 275 | * different caching policies exist. This changes the page attributes of the |
| 276 | * in kernel linear mapping too. |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 277 | * |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 278 | * Caller must call global_flush_tlb() later to make the changes active. |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 279 | * |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 280 | * The caller needs to ensure that there are no conflicting mappings elsewhere |
| 281 | * (e.g. in user space) * This function only deals with the kernel linear map. |
| 282 | * |
| 283 | * For MMIO areas without mem_map use change_page_attr_addr() instead. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | */ |
| 285 | int change_page_attr(struct page *page, int numpages, pgprot_t prot) |
| 286 | { |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 287 | unsigned long addr = (unsigned long)page_address(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
Ingo Molnar | 44af6c4 | 2008-01-30 13:34:03 +0100 | [diff] [blame] | 289 | return change_page_attr_addr(addr, numpages, prot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | } |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 291 | EXPORT_SYMBOL(change_page_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
Ingo Molnar | 78c94ab | 2008-01-30 13:33:55 +0100 | [diff] [blame] | 293 | static void flush_kernel_map(void *arg) |
| 294 | { |
| 295 | /* |
| 296 | * Flush all to work around Errata in early athlons regarding |
| 297 | * large page flushing. |
| 298 | */ |
| 299 | __flush_tlb_all(); |
| 300 | |
| 301 | if (boot_cpu_data.x86_model >= 4) |
| 302 | wbinvd(); |
| 303 | } |
| 304 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | void global_flush_tlb(void) |
Oleg Nesterov | 626ab0e | 2006-06-23 02:05:55 -0700 | [diff] [blame] | 306 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | BUG_ON(irqs_disabled()); |
| 308 | |
Ingo Molnar | 78c94ab | 2008-01-30 13:33:55 +0100 | [diff] [blame] | 309 | on_each_cpu(flush_kernel_map, NULL, 1, 1); |
Oleg Nesterov | 626ab0e | 2006-06-23 02:05:55 -0700 | [diff] [blame] | 310 | } |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 311 | EXPORT_SYMBOL(global_flush_tlb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
| 313 | #ifdef CONFIG_DEBUG_PAGEALLOC |
| 314 | void kernel_map_pages(struct page *page, int numpages, int enable) |
| 315 | { |
| 316 | if (PageHighMem(page)) |
| 317 | return; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 318 | if (!enable) { |
Ingo Molnar | f9b8404 | 2006-06-27 02:54:49 -0700 | [diff] [blame] | 319 | debug_check_no_locks_freed(page_address(page), |
| 320 | numpages * PAGE_SIZE); |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 321 | } |
Ingo Molnar | de5097c | 2006-01-09 15:59:21 -0800 | [diff] [blame] | 322 | |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 323 | /* |
Ingo Molnar | 12d6f21 | 2008-01-30 13:33:58 +0100 | [diff] [blame] | 324 | * If page allocator is not up yet then do not call c_p_a(): |
| 325 | */ |
| 326 | if (!debug_pagealloc_enabled) |
| 327 | return; |
| 328 | |
| 329 | /* |
Ingo Molnar | e4b71dc | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 330 | * The return value is ignored - the calls cannot fail, |
| 331 | * large pages are disabled at boot time: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | */ |
| 333 | change_page_attr(page, numpages, enable ? PAGE_KERNEL : __pgprot(0)); |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 334 | |
| 335 | /* |
Ingo Molnar | e4b71dc | 2008-01-30 13:34:04 +0100 | [diff] [blame] | 336 | * We should perform an IPI and flush all tlbs, |
| 337 | * but that can deadlock->flush only current cpu: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | */ |
| 339 | __flush_tlb_all(); |
| 340 | } |
| 341 | #endif |