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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <linux/highmem.h> |
| 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <asm/processor.h> |
| 13 | #include <asm/tlbflush.h> |
Dave Jones | f8af095 | 2006-01-06 00:12:10 -0800 | [diff] [blame] | 14 | #include <asm/sections.h> |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 15 | #include <asm/uaccess.h> |
| 16 | #include <asm/pgalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | static DEFINE_SPINLOCK(cpa_lock); |
| 19 | static struct list_head df_list = LIST_HEAD_INIT(df_list); |
| 20 | |
Ingo Molnar | f0646e4 | 2008-01-30 13:33:43 +0100 | [diff] [blame^] | 21 | pte_t *lookup_address(unsigned long address, int *level) |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 22 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | pgd_t *pgd = pgd_offset_k(address); |
| 24 | pud_t *pud; |
| 25 | pmd_t *pmd; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | if (pgd_none(*pgd)) |
| 28 | return NULL; |
| 29 | pud = pud_offset(pgd, address); |
| 30 | if (pud_none(*pud)) |
| 31 | return NULL; |
| 32 | pmd = pmd_offset(pud, address); |
| 33 | if (pmd_none(*pmd)) |
| 34 | return NULL; |
Ingo Molnar | f0646e4 | 2008-01-30 13:33:43 +0100 | [diff] [blame^] | 35 | *level = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | if (pmd_large(*pmd)) |
| 37 | return (pte_t *)pmd; |
Ingo Molnar | f0646e4 | 2008-01-30 13:33:43 +0100 | [diff] [blame^] | 38 | *level = 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 40 | return pte_offset_kernel(pmd, address); |
| 41 | } |
| 42 | |
| 43 | static struct page * |
| 44 | split_large_page(unsigned long address, pgprot_t prot, pgprot_t ref_prot) |
| 45 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | unsigned long addr; |
| 47 | struct page *base; |
| 48 | pte_t *pbase; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 49 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | spin_unlock_irq(&cpa_lock); |
| 52 | base = alloc_pages(GFP_KERNEL, 0); |
| 53 | spin_lock_irq(&cpa_lock); |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 54 | if (!base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | return NULL; |
| 56 | |
Nick Piggin | 84d1c05 | 2006-03-22 00:08:31 -0800 | [diff] [blame] | 57 | /* |
| 58 | * page_private is used to track the number of entries in |
| 59 | * the page table page that have non standard attributes. |
| 60 | */ |
| 61 | SetPagePrivate(base); |
| 62 | page_private(base) = 0; |
| 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | address = __pa(address); |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 65 | addr = address & LARGE_PAGE_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | pbase = (pte_t *)page_address(base); |
Jeremy Fitzhardinge | fdb4c33 | 2007-07-17 18:37:03 -0700 | [diff] [blame] | 67 | paravirt_alloc_pt(&init_mm, page_to_pfn(base)); |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | for (i = 0; i < PTRS_PER_PTE; i++, addr += PAGE_SIZE) { |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 70 | set_pte(&pbase[i], pfn_pte(addr >> PAGE_SHIFT, |
| 71 | addr == address ? prot : ref_prot)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | } |
| 73 | return base; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 74 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Andi Kleen | 018d2ad | 2007-06-20 12:23:36 +0200 | [diff] [blame] | 76 | static void cache_flush_page(struct page *p) |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 77 | { |
| 78 | void *addr = page_address(p); |
Andi Kleen | 018d2ad | 2007-06-20 12:23:36 +0200 | [diff] [blame] | 79 | int i; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 80 | |
Andi Kleen | 018d2ad | 2007-06-20 12:23:36 +0200 | [diff] [blame] | 81 | for (i = 0; i < PAGE_SIZE; i += boot_cpu_data.x86_clflush_size) |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 82 | clflush(addr + i); |
Andi Kleen | 018d2ad | 2007-06-20 12:23:36 +0200 | [diff] [blame] | 83 | } |
Andi Kleen | 3760dd6 | 2006-12-07 02:14:05 +0100 | [diff] [blame] | 84 | |
Andi Kleen | 018d2ad | 2007-06-20 12:23:36 +0200 | [diff] [blame] | 85 | static void flush_kernel_map(void *arg) |
| 86 | { |
| 87 | struct list_head *lh = (struct list_head *)arg; |
| 88 | struct page *p; |
| 89 | |
| 90 | /* High level code is not ready for clflush yet */ |
Andi Kleen | d3f3c93 | 2007-08-10 22:31:02 +0200 | [diff] [blame] | 91 | if (0 && cpu_has_clflush) { |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 92 | list_for_each_entry(p, lh, lru) |
Andi Kleen | 018d2ad | 2007-06-20 12:23:36 +0200 | [diff] [blame] | 93 | cache_flush_page(p); |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 94 | } else { |
| 95 | if (boot_cpu_data.x86_model >= 4) |
| 96 | wbinvd(); |
| 97 | } |
Andi Kleen | 3760dd6 | 2006-12-07 02:14:05 +0100 | [diff] [blame] | 98 | |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 99 | /* |
| 100 | * Flush all to work around Errata in early athlons regarding |
| 101 | * large page flushing. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | */ |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 103 | __flush_tlb_all(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 106 | static void set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte) |
| 107 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | unsigned long flags; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 109 | struct page *page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 111 | /* change init_mm */ |
| 112 | set_pte_atomic(kpte, pte); |
Jeremy Fitzhardinge | 5311ab6 | 2007-05-02 19:27:13 +0200 | [diff] [blame] | 113 | if (SHARED_KERNEL_PMD) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | return; |
| 115 | |
| 116 | spin_lock_irqsave(&pgd_lock, flags); |
| 117 | for (page = pgd_list; page; page = (struct page *)page->index) { |
| 118 | pgd_t *pgd; |
| 119 | pud_t *pud; |
| 120 | pmd_t *pmd; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | pgd = (pgd_t *)page_address(page) + pgd_index(address); |
| 123 | pud = pud_offset(pgd, address); |
| 124 | pmd = pmd_offset(pud, address); |
| 125 | set_pte_atomic((pte_t *)pmd, pte); |
| 126 | } |
| 127 | spin_unlock_irqrestore(&pgd_lock, flags); |
| 128 | } |
| 129 | |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 130 | /* |
| 131 | * No more special protections in this 2/4MB area - revert to a large |
| 132 | * page again. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | */ |
| 134 | static inline void revert_page(struct page *kpte_page, unsigned long address) |
| 135 | { |
Dave Jones | f8af095 | 2006-01-06 00:12:10 -0800 | [diff] [blame] | 136 | pgprot_t ref_prot; |
| 137 | pte_t *linear; |
| 138 | |
| 139 | ref_prot = |
| 140 | ((address & LARGE_PAGE_MASK) < (unsigned long)&_etext) |
| 141 | ? PAGE_KERNEL_LARGE_EXEC : PAGE_KERNEL_LARGE; |
| 142 | |
| 143 | linear = (pte_t *) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | pmd_offset(pud_offset(pgd_offset_k(address), address), address); |
| 145 | set_pmd_pte(linear, address, |
| 146 | pfn_pte((__pa(address) & LARGE_PAGE_MASK) >> PAGE_SHIFT, |
Dave Jones | f8af095 | 2006-01-06 00:12:10 -0800 | [diff] [blame] | 147 | ref_prot)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Andi Kleen | 65d2f0b | 2007-07-21 17:09:51 +0200 | [diff] [blame] | 150 | static inline void save_page(struct page *kpte_page) |
| 151 | { |
| 152 | if (!test_and_set_bit(PG_arch_1, &kpte_page->flags)) |
| 153 | list_add(&kpte_page->lru, &df_list); |
| 154 | } |
| 155 | |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 156 | static int __change_page_attr(struct page *page, pgprot_t prot) |
| 157 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | struct page *kpte_page; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 159 | unsigned long address; |
| 160 | pte_t *kpte; |
Ingo Molnar | f0646e4 | 2008-01-30 13:33:43 +0100 | [diff] [blame^] | 161 | int level; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
| 163 | BUG_ON(PageHighMem(page)); |
| 164 | address = (unsigned long)page_address(page); |
| 165 | |
Ingo Molnar | f0646e4 | 2008-01-30 13:33:43 +0100 | [diff] [blame^] | 166 | kpte = lookup_address(address, &level); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | if (!kpte) |
| 168 | return -EINVAL; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | kpte_page = virt_to_page(kpte); |
Andi Kleen | 65d2f0b | 2007-07-21 17:09:51 +0200 | [diff] [blame] | 171 | BUG_ON(PageLRU(kpte_page)); |
| 172 | BUG_ON(PageCompound(kpte_page)); |
| 173 | |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 174 | if (pgprot_val(prot) != pgprot_val(PAGE_KERNEL)) { |
Jan Beulich | d01ad8d | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 175 | if (!pte_huge(*kpte)) { |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 176 | set_pte_atomic(kpte, mk_pte(page, prot)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | } else { |
Dave Jones | f8af095 | 2006-01-06 00:12:10 -0800 | [diff] [blame] | 178 | struct page *split; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 179 | pgprot_t ref_prot; |
Dave Jones | f8af095 | 2006-01-06 00:12:10 -0800 | [diff] [blame] | 180 | |
| 181 | ref_prot = |
| 182 | ((address & LARGE_PAGE_MASK) < (unsigned long)&_etext) |
| 183 | ? PAGE_KERNEL_EXEC : PAGE_KERNEL; |
| 184 | split = split_large_page(address, prot, ref_prot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | if (!split) |
| 186 | return -ENOMEM; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 187 | |
| 188 | set_pmd_pte(kpte, address, mk_pte(split, ref_prot)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | kpte_page = split; |
Nick Piggin | 84d1c05 | 2006-03-22 00:08:31 -0800 | [diff] [blame] | 190 | } |
| 191 | page_private(kpte_page)++; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 192 | } else { |
| 193 | if (!pte_huge(*kpte)) { |
| 194 | set_pte_atomic(kpte, mk_pte(page, PAGE_KERNEL)); |
| 195 | BUG_ON(page_private(kpte_page) == 0); |
| 196 | page_private(kpte_page)--; |
| 197 | } else |
| 198 | BUG(); |
| 199 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
| 201 | /* |
| 202 | * If the pte was reserved, it means it was created at boot |
| 203 | * time (not via split_large_page) and in turn we must not |
| 204 | * replace it with a largepage. |
| 205 | */ |
Andi Kleen | 65d2f0b | 2007-07-21 17:09:51 +0200 | [diff] [blame] | 206 | |
| 207 | save_page(kpte_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | if (!PageReserved(kpte_page)) { |
Nick Piggin | 84d1c05 | 2006-03-22 00:08:31 -0800 | [diff] [blame] | 209 | if (cpu_has_pse && (page_private(kpte_page) == 0)) { |
Zachary Amsden | c119ecc | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 210 | paravirt_release_pt(page_to_pfn(kpte_page)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | revert_page(kpte_page, address); |
| 212 | } |
| 213 | } |
| 214 | return 0; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 215 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
Andi Kleen | 018d2ad | 2007-06-20 12:23:36 +0200 | [diff] [blame] | 217 | static inline void flush_map(struct list_head *l) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | { |
Andi Kleen | 018d2ad | 2007-06-20 12:23:36 +0200 | [diff] [blame] | 219 | on_each_cpu(flush_kernel_map, l, 1, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | /* |
| 223 | * Change the page attributes of an page in the linear mapping. |
| 224 | * |
| 225 | * This should be used when a page is mapped with a different caching policy |
| 226 | * than write-back somewhere - some CPUs do not like it when mappings with |
| 227 | * different caching policies exist. This changes the page attributes of the |
| 228 | * in kernel linear mapping too. |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 229 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | * The caller needs to ensure that there are no conflicting mappings elsewhere. |
| 231 | * This function only deals with the kernel linear map. |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 232 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | * Caller must call global_flush_tlb() after this. |
| 234 | */ |
| 235 | int change_page_attr(struct page *page, int numpages, pgprot_t prot) |
| 236 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | unsigned long flags; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 238 | int err = 0, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
| 240 | spin_lock_irqsave(&cpa_lock, flags); |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 241 | for (i = 0; i < numpages; i++, page++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | err = __change_page_attr(page, prot); |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 243 | if (err) |
| 244 | break; |
| 245 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | spin_unlock_irqrestore(&cpa_lock, flags); |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | return err; |
| 249 | } |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 250 | EXPORT_SYMBOL(change_page_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
| 252 | void global_flush_tlb(void) |
Oleg Nesterov | 626ab0e | 2006-06-23 02:05:55 -0700 | [diff] [blame] | 253 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | struct page *pg, *next; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 255 | struct list_head l; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
| 257 | BUG_ON(irqs_disabled()); |
| 258 | |
| 259 | spin_lock_irq(&cpa_lock); |
Oleg Nesterov | 626ab0e | 2006-06-23 02:05:55 -0700 | [diff] [blame] | 260 | list_replace_init(&df_list, &l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | spin_unlock_irq(&cpa_lock); |
Andi Kleen | 018d2ad | 2007-06-20 12:23:36 +0200 | [diff] [blame] | 262 | flush_map(&l); |
Andi Kleen | 3760dd6 | 2006-12-07 02:14:05 +0100 | [diff] [blame] | 263 | list_for_each_entry_safe(pg, next, &l, lru) { |
Andi Kleen | 65d2f0b | 2007-07-21 17:09:51 +0200 | [diff] [blame] | 264 | list_del(&pg->lru); |
| 265 | clear_bit(PG_arch_1, &pg->flags); |
| 266 | if (PageReserved(pg) || !cpu_has_pse || page_private(pg) != 0) |
| 267 | continue; |
| 268 | ClearPagePrivate(pg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | __free_page(pg); |
Andi Kleen | 3760dd6 | 2006-12-07 02:14:05 +0100 | [diff] [blame] | 270 | } |
Oleg Nesterov | 626ab0e | 2006-06-23 02:05:55 -0700 | [diff] [blame] | 271 | } |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 272 | EXPORT_SYMBOL(global_flush_tlb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
| 274 | #ifdef CONFIG_DEBUG_PAGEALLOC |
| 275 | void kernel_map_pages(struct page *page, int numpages, int enable) |
| 276 | { |
| 277 | if (PageHighMem(page)) |
| 278 | return; |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 279 | if (!enable) { |
Ingo Molnar | f9b8404 | 2006-06-27 02:54:49 -0700 | [diff] [blame] | 280 | debug_check_no_locks_freed(page_address(page), |
| 281 | numpages * PAGE_SIZE); |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 282 | } |
Ingo Molnar | de5097c | 2006-01-09 15:59:21 -0800 | [diff] [blame] | 283 | |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 284 | /* |
| 285 | * the return value is ignored - the calls cannot fail, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | * large pages are disabled at boot time. |
| 287 | */ |
| 288 | change_page_attr(page, numpages, enable ? PAGE_KERNEL : __pgprot(0)); |
Ingo Molnar | 9f4c815 | 2008-01-30 13:33:41 +0100 | [diff] [blame] | 289 | |
| 290 | /* |
| 291 | * we should perform an IPI and flush all tlbs, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | * but that can deadlock->flush only current cpu. |
| 293 | */ |
| 294 | __flush_tlb_all(); |
| 295 | } |
| 296 | #endif |