blob: 5d2259468d3cdce0cfdedb22a5a42f2dfdb9d487 [file] [log] [blame]
Ingo Molnar9f4c8152008-01-30 13:33:41 +01001/*
2 * Copyright 2002 Andi Kleen, SuSE Labs.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Thanks to Ben LaHaise for precious feedback.
Ingo Molnar9f4c8152008-01-30 13:33:41 +01004 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#include <linux/highmem.h>
Ingo Molnar81922062008-01-30 13:34:04 +01006#include <linux/bootmem.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/module.h>
Ingo Molnar9f4c8152008-01-30 13:33:41 +01008#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/slab.h>
Ingo Molnar9f4c8152008-01-30 13:33:41 +010010#include <linux/mm.h>
Thomas Gleixner76ebd052008-02-09 23:24:09 +010011#include <linux/interrupt.h>
Ingo Molnar9f4c8152008-01-30 13:33:41 +010012
Thomas Gleixner950f9d92008-01-30 13:34:06 +010013#include <asm/e820.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <asm/processor.h>
15#include <asm/tlbflush.h>
Dave Jonesf8af0952006-01-06 00:12:10 -080016#include <asm/sections.h>
Ingo Molnar9f4c8152008-01-30 13:33:41 +010017#include <asm/uaccess.h>
18#include <asm/pgalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Ingo Molnar9df84992008-02-04 16:48:09 +010020/*
21 * The current flushing context - we pass it instead of 5 arguments:
22 */
Thomas Gleixner72e458d2008-02-04 16:48:07 +010023struct cpa_data {
24 unsigned long vaddr;
Thomas Gleixner72e458d2008-02-04 16:48:07 +010025 pgprot_t mask_set;
26 pgprot_t mask_clr;
Thomas Gleixner65e074d2008-02-04 16:48:07 +010027 int numpages;
Thomas Gleixnerf4ae5da2008-02-04 16:48:07 +010028 int flushtlb;
Thomas Gleixner72e458d2008-02-04 16:48:07 +010029};
30
Arjan van de Vened724be2008-01-30 13:34:04 +010031static inline int
32within(unsigned long addr, unsigned long start, unsigned long end)
Ingo Molnar687c4822008-01-30 13:34:04 +010033{
Arjan van de Vened724be2008-01-30 13:34:04 +010034 return addr >= start && addr < end;
35}
36
37/*
Thomas Gleixnerd7c8f212008-01-30 13:34:07 +010038 * Flushing functions
39 */
Thomas Gleixnercd8ddf12008-01-30 13:34:08 +010040
Thomas Gleixnercd8ddf12008-01-30 13:34:08 +010041/**
42 * clflush_cache_range - flush a cache range with clflush
43 * @addr: virtual start address
44 * @size: number of bytes to flush
45 *
46 * clflush is an unordered instruction which needs fencing with mfence
47 * to avoid ordering issues.
48 */
Ingo Molnar4c61afc2008-01-30 13:34:09 +010049void clflush_cache_range(void *vaddr, unsigned int size)
Thomas Gleixnerd7c8f212008-01-30 13:34:07 +010050{
Ingo Molnar4c61afc2008-01-30 13:34:09 +010051 void *vend = vaddr + size - 1;
Thomas Gleixnerd7c8f212008-01-30 13:34:07 +010052
Thomas Gleixnercd8ddf12008-01-30 13:34:08 +010053 mb();
Ingo Molnar4c61afc2008-01-30 13:34:09 +010054
55 for (; vaddr < vend; vaddr += boot_cpu_data.x86_clflush_size)
56 clflush(vaddr);
57 /*
58 * Flush any possible final partial cacheline:
59 */
60 clflush(vend);
61
Thomas Gleixnercd8ddf12008-01-30 13:34:08 +010062 mb();
Thomas Gleixnerd7c8f212008-01-30 13:34:07 +010063}
64
Thomas Gleixneraf1e6842008-01-30 13:34:08 +010065static void __cpa_flush_all(void *arg)
Thomas Gleixnerd7c8f212008-01-30 13:34:07 +010066{
Andi Kleen6bb83832008-02-04 16:48:06 +010067 unsigned long cache = (unsigned long)arg;
68
Thomas Gleixnerd7c8f212008-01-30 13:34:07 +010069 /*
70 * Flush all to work around Errata in early athlons regarding
71 * large page flushing.
72 */
73 __flush_tlb_all();
74
Andi Kleen6bb83832008-02-04 16:48:06 +010075 if (cache && boot_cpu_data.x86_model >= 4)
Thomas Gleixnerd7c8f212008-01-30 13:34:07 +010076 wbinvd();
77}
78
Andi Kleen6bb83832008-02-04 16:48:06 +010079static void cpa_flush_all(unsigned long cache)
Thomas Gleixnerd7c8f212008-01-30 13:34:07 +010080{
81 BUG_ON(irqs_disabled());
82
Andi Kleen6bb83832008-02-04 16:48:06 +010083 on_each_cpu(__cpa_flush_all, (void *) cache, 1, 1);
Thomas Gleixnerd7c8f212008-01-30 13:34:07 +010084}
85
Thomas Gleixner57a6a462008-01-30 13:34:08 +010086static void __cpa_flush_range(void *arg)
87{
Thomas Gleixner57a6a462008-01-30 13:34:08 +010088 /*
89 * We could optimize that further and do individual per page
90 * tlb invalidates for a low number of pages. Caveat: we must
91 * flush the high aliases on 64bit as well.
92 */
93 __flush_tlb_all();
Thomas Gleixner57a6a462008-01-30 13:34:08 +010094}
95
Andi Kleen6bb83832008-02-04 16:48:06 +010096static void cpa_flush_range(unsigned long start, int numpages, int cache)
Thomas Gleixner57a6a462008-01-30 13:34:08 +010097{
Ingo Molnar4c61afc2008-01-30 13:34:09 +010098 unsigned int i, level;
99 unsigned long addr;
100
Thomas Gleixner57a6a462008-01-30 13:34:08 +0100101 BUG_ON(irqs_disabled());
Ingo Molnar4c61afc2008-01-30 13:34:09 +0100102 WARN_ON(PAGE_ALIGN(start) != start);
Thomas Gleixner57a6a462008-01-30 13:34:08 +0100103
Thomas Gleixner3b233e52008-01-30 13:34:08 +0100104 on_each_cpu(__cpa_flush_range, NULL, 1, 1);
Thomas Gleixner57a6a462008-01-30 13:34:08 +0100105
Andi Kleen6bb83832008-02-04 16:48:06 +0100106 if (!cache)
107 return;
108
Thomas Gleixner3b233e52008-01-30 13:34:08 +0100109 /*
110 * We only need to flush on one CPU,
111 * clflush is a MESI-coherent instruction that
112 * will cause all other CPUs to flush the same
113 * cachelines:
114 */
Ingo Molnar4c61afc2008-01-30 13:34:09 +0100115 for (i = 0, addr = start; i < numpages; i++, addr += PAGE_SIZE) {
116 pte_t *pte = lookup_address(addr, &level);
117
118 /*
119 * Only flush present addresses:
120 */
Thomas Gleixner7bfb72e2008-02-04 16:48:08 +0100121 if (pte && (pte_val(*pte) & _PAGE_PRESENT))
Ingo Molnar4c61afc2008-01-30 13:34:09 +0100122 clflush_cache_range((void *) addr, PAGE_SIZE);
123 }
Thomas Gleixner57a6a462008-01-30 13:34:08 +0100124}
125
Arjan van de Vencc0f21b2008-02-04 16:48:05 +0100126#define HIGH_MAP_START __START_KERNEL_map
127#define HIGH_MAP_END (__START_KERNEL_map + KERNEL_TEXT_SIZE)
128
129
130/*
131 * Converts a virtual address to a X86-64 highmap address
132 */
133static unsigned long virt_to_highmap(void *address)
134{
135#ifdef CONFIG_X86_64
136 return __pa((unsigned long)address) + HIGH_MAP_START - phys_base;
137#else
138 return (unsigned long)address;
139#endif
140}
141
Thomas Gleixnerd7c8f212008-01-30 13:34:07 +0100142/*
Arjan van de Vened724be2008-01-30 13:34:04 +0100143 * Certain areas of memory on x86 require very specific protection flags,
144 * for example the BIOS area or kernel text. Callers don't always get this
145 * right (again, ioremap() on BIOS memory is not uncommon) so this function
146 * checks and fixes these known static required protection bits.
147 */
148static inline pgprot_t static_protections(pgprot_t prot, unsigned long address)
149{
150 pgprot_t forbidden = __pgprot(0);
151
Ingo Molnar687c4822008-01-30 13:34:04 +0100152 /*
Arjan van de Vened724be2008-01-30 13:34:04 +0100153 * The BIOS area between 640k and 1Mb needs to be executable for
154 * PCI BIOS based config access (CONFIG_PCI_GOBIOS) support.
Ingo Molnar687c4822008-01-30 13:34:04 +0100155 */
Arjan van de Vened724be2008-01-30 13:34:04 +0100156 if (within(__pa(address), BIOS_BEGIN, BIOS_END))
157 pgprot_val(forbidden) |= _PAGE_NX;
158
159 /*
160 * The kernel text needs to be executable for obvious reasons
161 * Does not cover __inittext since that is gone later on
162 */
163 if (within(address, (unsigned long)_text, (unsigned long)_etext))
164 pgprot_val(forbidden) |= _PAGE_NX;
Arjan van de Vencc0f21b2008-02-04 16:48:05 +0100165 /*
166 * Do the same for the x86-64 high kernel mapping
167 */
168 if (within(address, virt_to_highmap(_text), virt_to_highmap(_etext)))
169 pgprot_val(forbidden) |= _PAGE_NX;
170
Arjan van de Vened724be2008-01-30 13:34:04 +0100171 /* The .rodata section needs to be read-only */
172 if (within(address, (unsigned long)__start_rodata,
173 (unsigned long)__end_rodata))
174 pgprot_val(forbidden) |= _PAGE_RW;
Arjan van de Vencc0f21b2008-02-04 16:48:05 +0100175 /*
176 * Do the same for the x86-64 high kernel mapping
177 */
178 if (within(address, virt_to_highmap(__start_rodata),
179 virt_to_highmap(__end_rodata)))
180 pgprot_val(forbidden) |= _PAGE_RW;
Arjan van de Vened724be2008-01-30 13:34:04 +0100181
182 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
Ingo Molnar687c4822008-01-30 13:34:04 +0100183
184 return prot;
185}
186
Thomas Gleixner9a14aef2008-02-04 16:48:07 +0100187/*
188 * Lookup the page table entry for a virtual address. Return a pointer
189 * to the entry and the level of the mapping.
190 *
191 * Note: We return pud and pmd either when the entry is marked large
192 * or when the present bit is not set. Otherwise we would return a
193 * pointer to a nonexisting mapping.
194 */
Harvey Harrisonda7bfc52008-02-09 23:24:08 +0100195pte_t *lookup_address(unsigned long address, unsigned int *level)
Ingo Molnar9f4c8152008-01-30 13:33:41 +0100196{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 pgd_t *pgd = pgd_offset_k(address);
198 pud_t *pud;
199 pmd_t *pmd;
Ingo Molnar9f4c8152008-01-30 13:33:41 +0100200
Thomas Gleixner30551bb2008-01-30 13:34:04 +0100201 *level = PG_LEVEL_NONE;
202
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 if (pgd_none(*pgd))
204 return NULL;
Ingo Molnar9df84992008-02-04 16:48:09 +0100205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 pud = pud_offset(pgd, address);
207 if (pud_none(*pud))
208 return NULL;
Andi Kleenc2f71ee2008-02-04 16:48:09 +0100209
210 *level = PG_LEVEL_1G;
211 if (pud_large(*pud) || !pud_present(*pud))
212 return (pte_t *)pud;
213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 pmd = pmd_offset(pud, address);
215 if (pmd_none(*pmd))
216 return NULL;
Thomas Gleixner30551bb2008-01-30 13:34:04 +0100217
218 *level = PG_LEVEL_2M;
Thomas Gleixner9a14aef2008-02-04 16:48:07 +0100219 if (pmd_large(*pmd) || !pmd_present(*pmd))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 return (pte_t *)pmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Thomas Gleixner30551bb2008-01-30 13:34:04 +0100222 *level = PG_LEVEL_4K;
Ingo Molnar9df84992008-02-04 16:48:09 +0100223
Ingo Molnar9f4c8152008-01-30 13:33:41 +0100224 return pte_offset_kernel(pmd, address);
225}
226
Ingo Molnar9df84992008-02-04 16:48:09 +0100227/*
228 * Set the new pmd in all the pgds we know about:
229 */
Ingo Molnar9a3dc782008-01-30 13:33:57 +0100230static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
Ingo Molnar9f4c8152008-01-30 13:33:41 +0100231{
Ingo Molnar9f4c8152008-01-30 13:33:41 +0100232 /* change init_mm */
233 set_pte_atomic(kpte, pte);
Ingo Molnar44af6c42008-01-30 13:34:03 +0100234#ifdef CONFIG_X86_32
Ingo Molnare4b71dc2008-01-30 13:34:04 +0100235 if (!SHARED_KERNEL_PMD) {
Ingo Molnar44af6c42008-01-30 13:34:03 +0100236 struct page *page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Jeremy Fitzhardingee3ed9102008-01-30 13:34:11 +0100238 list_for_each_entry(page, &pgd_list, lru) {
Ingo Molnar44af6c42008-01-30 13:34:03 +0100239 pgd_t *pgd;
240 pud_t *pud;
241 pmd_t *pmd;
Ingo Molnar9f4c8152008-01-30 13:33:41 +0100242
Ingo Molnar44af6c42008-01-30 13:34:03 +0100243 pgd = (pgd_t *)page_address(page) + pgd_index(address);
244 pud = pud_offset(pgd, address);
245 pmd = pmd_offset(pud, address);
246 set_pte_atomic((pte_t *)pmd, pte);
247 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 }
Ingo Molnar44af6c42008-01-30 13:34:03 +0100249#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250}
251
Ingo Molnar9df84992008-02-04 16:48:09 +0100252static int
253try_preserve_large_page(pte_t *kpte, unsigned long address,
254 struct cpa_data *cpa)
Thomas Gleixner65e074d2008-02-04 16:48:07 +0100255{
Thomas Gleixnerfac84932008-02-09 23:24:09 +0100256 unsigned long nextpage_addr, numpages, pmask, psize, flags, addr;
Thomas Gleixner65e074d2008-02-04 16:48:07 +0100257 pte_t new_pte, old_pte, *tmp;
258 pgprot_t old_prot, new_prot;
Thomas Gleixnerfac84932008-02-09 23:24:09 +0100259 int i, do_split = 1;
Harvey Harrisonda7bfc52008-02-09 23:24:08 +0100260 unsigned int level;
Thomas Gleixner65e074d2008-02-04 16:48:07 +0100261
262 spin_lock_irqsave(&pgd_lock, flags);
263 /*
264 * Check for races, another CPU might have split this page
265 * up already:
266 */
267 tmp = lookup_address(address, &level);
268 if (tmp != kpte)
269 goto out_unlock;
270
271 switch (level) {
272 case PG_LEVEL_2M:
Andi Kleen31422c52008-02-04 16:48:08 +0100273 psize = PMD_PAGE_SIZE;
274 pmask = PMD_PAGE_MASK;
Thomas Gleixner65e074d2008-02-04 16:48:07 +0100275 break;
Andi Kleenf07333f2008-02-04 16:48:09 +0100276#ifdef CONFIG_X86_64
Thomas Gleixner65e074d2008-02-04 16:48:07 +0100277 case PG_LEVEL_1G:
Andi Kleen5d3c8b22008-02-13 16:20:35 +0100278 psize = PUD_PAGE_SIZE;
279 pmask = PUD_PAGE_MASK;
Andi Kleenf07333f2008-02-04 16:48:09 +0100280 break;
281#endif
Thomas Gleixner65e074d2008-02-04 16:48:07 +0100282 default:
Ingo Molnarbeaff632008-02-04 16:48:09 +0100283 do_split = -EINVAL;
Thomas Gleixner65e074d2008-02-04 16:48:07 +0100284 goto out_unlock;
285 }
286
287 /*
288 * Calculate the number of pages, which fit into this large
289 * page starting at address:
290 */
291 nextpage_addr = (address + psize) & pmask;
292 numpages = (nextpage_addr - address) >> PAGE_SHIFT;
293 if (numpages < cpa->numpages)
294 cpa->numpages = numpages;
295
296 /*
297 * We are safe now. Check whether the new pgprot is the same:
298 */
299 old_pte = *kpte;
300 old_prot = new_prot = pte_pgprot(old_pte);
301
302 pgprot_val(new_prot) &= ~pgprot_val(cpa->mask_clr);
303 pgprot_val(new_prot) |= pgprot_val(cpa->mask_set);
304 new_prot = static_protections(new_prot, address);
305
306 /*
Thomas Gleixnerfac84932008-02-09 23:24:09 +0100307 * We need to check the full range, whether
308 * static_protection() requires a different pgprot for one of
309 * the pages in the range we try to preserve:
310 */
311 addr = address + PAGE_SIZE;
312 for (i = 1; i < cpa->numpages; i++, addr += PAGE_SIZE) {
313 pgprot_t chk_prot = static_protections(new_prot, addr);
314
315 if (pgprot_val(chk_prot) != pgprot_val(new_prot))
316 goto out_unlock;
317 }
318
319 /*
Thomas Gleixner65e074d2008-02-04 16:48:07 +0100320 * If there are no changes, return. maxpages has been updated
321 * above:
322 */
323 if (pgprot_val(new_prot) == pgprot_val(old_prot)) {
Ingo Molnarbeaff632008-02-04 16:48:09 +0100324 do_split = 0;
Thomas Gleixner65e074d2008-02-04 16:48:07 +0100325 goto out_unlock;
326 }
327
328 /*
329 * We need to change the attributes. Check, whether we can
330 * change the large page in one go. We request a split, when
331 * the address is not aligned and the number of pages is
332 * smaller than the number of pages in the large page. Note
333 * that we limited the number of possible pages already to
334 * the number of pages in the large page.
335 */
336 if (address == (nextpage_addr - psize) && cpa->numpages == numpages) {
337 /*
338 * The address is aligned and the number of pages
339 * covers the full page.
340 */
341 new_pte = pfn_pte(pte_pfn(old_pte), canon_pgprot(new_prot));
342 __set_pmd_pte(kpte, address, new_pte);
343 cpa->flushtlb = 1;
Ingo Molnarbeaff632008-02-04 16:48:09 +0100344 do_split = 0;
Thomas Gleixner65e074d2008-02-04 16:48:07 +0100345 }
346
347out_unlock:
348 spin_unlock_irqrestore(&pgd_lock, flags);
Ingo Molnar9df84992008-02-04 16:48:09 +0100349
Ingo Molnarbeaff632008-02-04 16:48:09 +0100350 return do_split;
Thomas Gleixner65e074d2008-02-04 16:48:07 +0100351}
352
Thomas Gleixner76ebd052008-02-09 23:24:09 +0100353static LIST_HEAD(page_pool);
354static unsigned long pool_size, pool_pages, pool_low;
355static unsigned long pool_used, pool_failed, pool_refill;
356
357static void cpa_fill_pool(void)
358{
359 struct page *p;
360 gfp_t gfp = GFP_KERNEL;
361
362 /* Do not allocate from interrupt context */
363 if (in_irq() || irqs_disabled())
364 return;
365 /*
366 * Check unlocked. I does not matter when we have one more
367 * page in the pool. The bit lock avoids recursive pool
368 * allocations:
369 */
370 if (pool_pages >= pool_size || test_and_set_bit_lock(0, &pool_refill))
371 return;
372
373#ifdef CONFIG_DEBUG_PAGEALLOC
374 /*
375 * We could do:
376 * gfp = in_atomic() ? GFP_ATOMIC : GFP_KERNEL;
377 * but this fails on !PREEMPT kernels
378 */
379 gfp = GFP_ATOMIC | __GFP_NORETRY | __GFP_NOWARN;
380#endif
381
382 while (pool_pages < pool_size) {
383 p = alloc_pages(gfp, 0);
384 if (!p) {
385 pool_failed++;
386 break;
387 }
388 spin_lock_irq(&pgd_lock);
389 list_add(&p->lru, &page_pool);
390 pool_pages++;
391 spin_unlock_irq(&pgd_lock);
392 }
393 clear_bit_unlock(0, &pool_refill);
394}
395
396#define SHIFT_MB (20 - PAGE_SHIFT)
397#define ROUND_MB_GB ((1 << 10) - 1)
398#define SHIFT_MB_GB 10
399#define POOL_PAGES_PER_GB 16
400
401void __init cpa_init(void)
402{
403 struct sysinfo si;
404 unsigned long gb;
405
406 si_meminfo(&si);
407 /*
408 * Calculate the number of pool pages:
409 *
410 * Convert totalram (nr of pages) to MiB and round to the next
411 * GiB. Shift MiB to Gib and multiply the result by
412 * POOL_PAGES_PER_GB:
413 */
414 gb = ((si.totalram >> SHIFT_MB) + ROUND_MB_GB) >> SHIFT_MB_GB;
415 pool_size = POOL_PAGES_PER_GB * gb;
416 pool_low = pool_size;
417
418 cpa_fill_pool();
419 printk(KERN_DEBUG
420 "CPA: page pool initialized %lu of %lu pages preallocated\n",
421 pool_pages, pool_size);
422}
423
Ingo Molnar7afe15b2008-01-30 13:33:57 +0100424static int split_large_page(pte_t *kpte, unsigned long address)
Ingo Molnarbb5c2db2008-01-30 13:33:56 +0100425{
Thomas Gleixner7b610ee2008-02-04 16:48:10 +0100426 unsigned long flags, pfn, pfninc = 1;
Ingo Molnar86f03982008-01-30 13:34:09 +0100427 unsigned int i, level;
Ingo Molnar9df84992008-02-04 16:48:09 +0100428 pte_t *pbase, *tmp;
429 pgprot_t ref_prot;
430 struct page *base;
Ingo Molnarbb5c2db2008-01-30 13:33:56 +0100431
Thomas Gleixnereb5b5f02008-02-09 23:24:09 +0100432 /*
433 * Get a page from the pool. The pool list is protected by the
434 * pgd_lock, which we have to take anyway for the split
435 * operation:
436 */
Ingo Molnar9a3dc782008-01-30 13:33:57 +0100437 spin_lock_irqsave(&pgd_lock, flags);
Thomas Gleixnereb5b5f02008-02-09 23:24:09 +0100438 if (list_empty(&page_pool)) {
439 spin_unlock_irqrestore(&pgd_lock, flags);
440 return -ENOMEM;
441 }
442
443 base = list_first_entry(&page_pool, struct page, lru);
444 list_del(&base->lru);
445 pool_pages--;
446
447 if (pool_pages < pool_low)
448 pool_low = pool_pages;
449
Ingo Molnarbb5c2db2008-01-30 13:33:56 +0100450 /*
451 * Check for races, another CPU might have split this page
452 * up for us already:
453 */
454 tmp = lookup_address(address, &level);
Ingo Molnar6ce9fc12008-02-04 16:48:08 +0100455 if (tmp != kpte)
Ingo Molnarbb5c2db2008-01-30 13:33:56 +0100456 goto out_unlock;
457
Ingo Molnarbb5c2db2008-01-30 13:33:56 +0100458 pbase = (pte_t *)page_address(base);
Ingo Molnar44af6c42008-01-30 13:34:03 +0100459#ifdef CONFIG_X86_32
Ingo Molnarbb5c2db2008-01-30 13:33:56 +0100460 paravirt_alloc_pt(&init_mm, page_to_pfn(base));
Ingo Molnar44af6c42008-01-30 13:34:03 +0100461#endif
Thomas Gleixner07cf89c2008-02-04 16:48:08 +0100462 ref_prot = pte_pgprot(pte_clrhuge(*kpte));
Ingo Molnarbb5c2db2008-01-30 13:33:56 +0100463
Andi Kleenf07333f2008-02-04 16:48:09 +0100464#ifdef CONFIG_X86_64
465 if (level == PG_LEVEL_1G) {
466 pfninc = PMD_PAGE_SIZE >> PAGE_SHIFT;
467 pgprot_val(ref_prot) |= _PAGE_PSE;
Andi Kleenf07333f2008-02-04 16:48:09 +0100468 }
469#endif
470
Thomas Gleixner63c1dcf2008-02-04 16:48:05 +0100471 /*
472 * Get the target pfn from the original entry:
473 */
474 pfn = pte_pfn(*kpte);
Andi Kleenf07333f2008-02-04 16:48:09 +0100475 for (i = 0; i < PTRS_PER_PTE; i++, pfn += pfninc)
Thomas Gleixner63c1dcf2008-02-04 16:48:05 +0100476 set_pte(&pbase[i], pfn_pte(pfn, ref_prot));
Ingo Molnarbb5c2db2008-01-30 13:33:56 +0100477
478 /*
Thomas Gleixner07cf89c2008-02-04 16:48:08 +0100479 * Install the new, split up pagetable. Important details here:
Huang, Ying4c881ca2008-01-30 13:34:04 +0100480 *
481 * On Intel the NX bit of all levels must be cleared to make a
482 * page executable. See section 4.13.2 of Intel 64 and IA-32
483 * Architectures Software Developer's Manual).
Thomas Gleixner07cf89c2008-02-04 16:48:08 +0100484 *
485 * Mark the entry present. The current mapping might be
486 * set to not present, which we preserved above.
Ingo Molnarbb5c2db2008-01-30 13:33:56 +0100487 */
Huang, Ying4c881ca2008-01-30 13:34:04 +0100488 ref_prot = pte_pgprot(pte_mkexec(pte_clrhuge(*kpte)));
Thomas Gleixner07cf89c2008-02-04 16:48:08 +0100489 pgprot_val(ref_prot) |= _PAGE_PRESENT;
Ingo Molnar9a3dc782008-01-30 13:33:57 +0100490 __set_pmd_pte(kpte, address, mk_pte(base, ref_prot));
Ingo Molnarbb5c2db2008-01-30 13:33:56 +0100491 base = NULL;
492
493out_unlock:
Thomas Gleixnereb5b5f02008-02-09 23:24:09 +0100494 /*
495 * If we dropped out via the lookup_address check under
496 * pgd_lock then stick the page back into the pool:
497 */
498 if (base) {
499 list_add(&base->lru, &page_pool);
500 pool_pages++;
501 } else
502 pool_used++;
Ingo Molnar9a3dc782008-01-30 13:33:57 +0100503 spin_unlock_irqrestore(&pgd_lock, flags);
Ingo Molnarbb5c2db2008-01-30 13:33:56 +0100504
Ingo Molnarbb5c2db2008-01-30 13:33:56 +0100505 return 0;
506}
507
Thomas Gleixner72e458d2008-02-04 16:48:07 +0100508static int __change_page_attr(unsigned long address, struct cpa_data *cpa)
Ingo Molnar9f4c8152008-01-30 13:33:41 +0100509{
Harvey Harrisonda7bfc52008-02-09 23:24:08 +0100510 int do_split, err;
511 unsigned int level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 struct page *kpte_page;
Ingo Molnar9f4c8152008-01-30 13:33:41 +0100513 pte_t *kpte;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
Ingo Molnar97f99fe2008-01-30 13:33:55 +0100515repeat:
Ingo Molnarf0646e42008-01-30 13:33:43 +0100516 kpte = lookup_address(address, &level);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 if (!kpte)
518 return -EINVAL;
Ingo Molnar9f4c8152008-01-30 13:33:41 +0100519
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 kpte_page = virt_to_page(kpte);
Andi Kleen65d2f0b2007-07-21 17:09:51 +0200521 BUG_ON(PageLRU(kpte_page));
522 BUG_ON(PageCompound(kpte_page));
523
Thomas Gleixner30551bb2008-01-30 13:34:04 +0100524 if (level == PG_LEVEL_4K) {
Ingo Molnar86f03982008-01-30 13:34:09 +0100525 pte_t new_pte, old_pte = *kpte;
Arjan van de Ven626c2c92008-02-04 16:48:05 +0100526 pgprot_t new_prot = pte_pgprot(old_pte);
527
528 if(!pte_val(old_pte)) {
Thomas Gleixner72e458d2008-02-04 16:48:07 +0100529 printk(KERN_WARNING "CPA: called for zero pte. "
530 "vaddr = %lx cpa->vaddr = %lx\n", address,
531 cpa->vaddr);
532 WARN_ON(1);
Arjan van de Ven626c2c92008-02-04 16:48:05 +0100533 return -EINVAL;
534 }
Thomas Gleixnera72a08a2008-01-30 13:34:07 +0100535
Thomas Gleixner72e458d2008-02-04 16:48:07 +0100536 pgprot_val(new_prot) &= ~pgprot_val(cpa->mask_clr);
537 pgprot_val(new_prot) |= pgprot_val(cpa->mask_set);
Ingo Molnar86f03982008-01-30 13:34:09 +0100538
539 new_prot = static_protections(new_prot, address);
540
Arjan van de Ven626c2c92008-02-04 16:48:05 +0100541 /*
542 * We need to keep the pfn from the existing PTE,
543 * after all we're only going to change it's attributes
544 * not the memory it points to
545 */
546 new_pte = pfn_pte(pte_pfn(old_pte), canon_pgprot(new_prot));
Thomas Gleixnerf4ae5da2008-02-04 16:48:07 +0100547
548 /*
549 * Do we really change anything ?
550 */
551 if (pte_val(old_pte) != pte_val(new_pte)) {
552 set_pte_atomic(kpte, new_pte);
553 cpa->flushtlb = 1;
554 }
Thomas Gleixner65e074d2008-02-04 16:48:07 +0100555 cpa->numpages = 1;
556 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 }
Thomas Gleixner65e074d2008-02-04 16:48:07 +0100558
559 /*
560 * Check, whether we can keep the large page intact
561 * and just change the pte:
562 */
Ingo Molnarbeaff632008-02-04 16:48:09 +0100563 do_split = try_preserve_large_page(kpte, address, cpa);
Thomas Gleixner65e074d2008-02-04 16:48:07 +0100564 /*
565 * When the range fits into the existing large page,
566 * return. cp->numpages and cpa->tlbflush have been updated in
567 * try_large_page:
568 */
Ingo Molnar87f7f8f2008-02-04 16:48:10 +0100569 if (do_split <= 0)
570 return do_split;
Thomas Gleixner65e074d2008-02-04 16:48:07 +0100571
572 /*
573 * We have to split the large page:
574 */
Ingo Molnar87f7f8f2008-02-04 16:48:10 +0100575 err = split_large_page(kpte, address);
576 if (!err) {
577 cpa->flushtlb = 1;
578 goto repeat;
579 }
Ingo Molnarbeaff632008-02-04 16:48:09 +0100580
Ingo Molnar87f7f8f2008-02-04 16:48:10 +0100581 return err;
Ingo Molnar9f4c8152008-01-30 13:33:41 +0100582}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Ingo Molnar44af6c42008-01-30 13:34:03 +0100584/**
585 * change_page_attr_addr - Change page table attributes in linear mapping
586 * @address: Virtual address in linear mapping.
Ingo Molnar44af6c42008-01-30 13:34:03 +0100587 * @prot: New page table attribute (PAGE_*)
588 *
589 * Change page attributes of a page in the direct mapping. This is a variant
590 * of change_page_attr() that also works on memory holes that do not have
591 * mem_map entry (pfn_valid() is false).
592 *
593 * See change_page_attr() documentation for more details.
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100594 *
595 * Modules and drivers should use the set_memory_* APIs instead.
Ingo Molnar44af6c42008-01-30 13:34:03 +0100596 */
Thomas Gleixner72e458d2008-02-04 16:48:07 +0100597static int change_page_attr_addr(struct cpa_data *cpa)
Ingo Molnar44af6c42008-01-30 13:34:03 +0100598{
Thomas Gleixner08797502008-01-30 13:34:09 +0100599 int err;
Thomas Gleixner72e458d2008-02-04 16:48:07 +0100600 unsigned long address = cpa->vaddr;
Ingo Molnar44af6c42008-01-30 13:34:03 +0100601
Arjan van de Ven488fd992008-01-30 13:34:07 +0100602#ifdef CONFIG_X86_64
Arjan van de Ven626c2c92008-02-04 16:48:05 +0100603 unsigned long phys_addr = __pa(address);
604
Arjan van de Ven488fd992008-01-30 13:34:07 +0100605 /*
Thomas Gleixner08797502008-01-30 13:34:09 +0100606 * If we are inside the high mapped kernel range, then we
607 * fixup the low mapping first. __va() returns the virtual
608 * address in the linear mapping:
Arjan van de Ven488fd992008-01-30 13:34:07 +0100609 */
Thomas Gleixner08797502008-01-30 13:34:09 +0100610 if (within(address, HIGH_MAP_START, HIGH_MAP_END))
611 address = (unsigned long) __va(phys_addr);
Arjan van de Ven488fd992008-01-30 13:34:07 +0100612#endif
613
Thomas Gleixner72e458d2008-02-04 16:48:07 +0100614 err = __change_page_attr(address, cpa);
Thomas Gleixner08797502008-01-30 13:34:09 +0100615 if (err)
616 return err;
617
618#ifdef CONFIG_X86_64
619 /*
620 * If the physical address is inside the kernel map, we need
621 * to touch the high mapped kernel as well:
622 */
623 if (within(phys_addr, 0, KERNEL_TEXT_SIZE)) {
624 /*
625 * Calc the high mapping address. See __phys_addr()
626 * for the non obvious details.
Arjan van de Vencc0f21b2008-02-04 16:48:05 +0100627 *
628 * Note that NX and other required permissions are
629 * checked in static_protections().
Thomas Gleixner08797502008-01-30 13:34:09 +0100630 */
631 address = phys_addr + HIGH_MAP_START - phys_base;
Thomas Gleixner08797502008-01-30 13:34:09 +0100632
633 /*
634 * Our high aliases are imprecise, because we check
635 * everything between 0 and KERNEL_TEXT_SIZE, so do
636 * not propagate lookup failures back to users:
637 */
Thomas Gleixner72e458d2008-02-04 16:48:07 +0100638 __change_page_attr(address, cpa);
Thomas Gleixner08797502008-01-30 13:34:09 +0100639 }
640#endif
Ingo Molnar44af6c42008-01-30 13:34:03 +0100641 return err;
642}
643
Thomas Gleixner72e458d2008-02-04 16:48:07 +0100644static int __change_page_attr_set_clr(struct cpa_data *cpa)
Thomas Gleixnerff314522008-01-30 13:34:08 +0100645{
Thomas Gleixner65e074d2008-02-04 16:48:07 +0100646 int ret, numpages = cpa->numpages;
Thomas Gleixnerff314522008-01-30 13:34:08 +0100647
Thomas Gleixner65e074d2008-02-04 16:48:07 +0100648 while (numpages) {
649 /*
650 * Store the remaining nr of pages for the large page
651 * preservation check.
652 */
653 cpa->numpages = numpages;
Thomas Gleixner72e458d2008-02-04 16:48:07 +0100654 ret = change_page_attr_addr(cpa);
Thomas Gleixnerff314522008-01-30 13:34:08 +0100655 if (ret)
656 return ret;
Thomas Gleixnerff314522008-01-30 13:34:08 +0100657
Thomas Gleixner65e074d2008-02-04 16:48:07 +0100658 /*
659 * Adjust the number of pages with the result of the
660 * CPA operation. Either a large page has been
661 * preserved or a single page update happened.
662 */
663 BUG_ON(cpa->numpages > numpages);
664 numpages -= cpa->numpages;
665 cpa->vaddr += cpa->numpages * PAGE_SIZE;
666 }
Thomas Gleixnerff314522008-01-30 13:34:08 +0100667 return 0;
668}
669
Andi Kleen6bb83832008-02-04 16:48:06 +0100670static inline int cache_attr(pgprot_t attr)
671{
672 return pgprot_val(attr) &
673 (_PAGE_PAT | _PAGE_PAT_LARGE | _PAGE_PWT | _PAGE_PCD);
674}
675
Thomas Gleixnerff314522008-01-30 13:34:08 +0100676static int change_page_attr_set_clr(unsigned long addr, int numpages,
677 pgprot_t mask_set, pgprot_t mask_clr)
678{
Thomas Gleixner72e458d2008-02-04 16:48:07 +0100679 struct cpa_data cpa;
Andi Kleen6bb83832008-02-04 16:48:06 +0100680 int ret, cache;
Thomas Gleixner331e4062008-02-04 16:48:06 +0100681
682 /*
683 * Check, if we are requested to change a not supported
684 * feature:
685 */
686 mask_set = canon_pgprot(mask_set);
687 mask_clr = canon_pgprot(mask_clr);
688 if (!pgprot_val(mask_set) && !pgprot_val(mask_clr))
689 return 0;
690
Thomas Gleixner69b14152008-02-13 11:04:50 +0100691 /* Ensure we are PAGE_SIZE aligned */
692 if (addr & ~PAGE_MASK) {
693 addr &= PAGE_MASK;
694 /*
695 * People should not be passing in unaligned addresses:
696 */
697 WARN_ON_ONCE(1);
698 }
699
Thomas Gleixner72e458d2008-02-04 16:48:07 +0100700 cpa.vaddr = addr;
701 cpa.numpages = numpages;
702 cpa.mask_set = mask_set;
703 cpa.mask_clr = mask_clr;
Thomas Gleixnerf4ae5da2008-02-04 16:48:07 +0100704 cpa.flushtlb = 0;
Thomas Gleixner72e458d2008-02-04 16:48:07 +0100705
706 ret = __change_page_attr_set_clr(&cpa);
Thomas Gleixnerff314522008-01-30 13:34:08 +0100707
Thomas Gleixner57a6a462008-01-30 13:34:08 +0100708 /*
Thomas Gleixnerf4ae5da2008-02-04 16:48:07 +0100709 * Check whether we really changed something:
710 */
711 if (!cpa.flushtlb)
Thomas Gleixner76ebd052008-02-09 23:24:09 +0100712 goto out;
Thomas Gleixnerf4ae5da2008-02-04 16:48:07 +0100713
714 /*
Andi Kleen6bb83832008-02-04 16:48:06 +0100715 * No need to flush, when we did not set any of the caching
716 * attributes:
717 */
718 cache = cache_attr(mask_set);
719
720 /*
Thomas Gleixner57a6a462008-01-30 13:34:08 +0100721 * On success we use clflush, when the CPU supports it to
722 * avoid the wbindv. If the CPU does not support it and in the
Thomas Gleixneraf1e6842008-01-30 13:34:08 +0100723 * error case we fall back to cpa_flush_all (which uses
Thomas Gleixner57a6a462008-01-30 13:34:08 +0100724 * wbindv):
725 */
726 if (!ret && cpu_has_clflush)
Andi Kleen6bb83832008-02-04 16:48:06 +0100727 cpa_flush_range(addr, numpages, cache);
Thomas Gleixner57a6a462008-01-30 13:34:08 +0100728 else
Andi Kleen6bb83832008-02-04 16:48:06 +0100729 cpa_flush_all(cache);
Thomas Gleixnerff314522008-01-30 13:34:08 +0100730
Thomas Gleixner76ebd052008-02-09 23:24:09 +0100731out:
732 cpa_fill_pool();
Thomas Gleixnerff314522008-01-30 13:34:08 +0100733 return ret;
734}
735
Thomas Gleixner56744542008-01-30 13:34:08 +0100736static inline int change_page_attr_set(unsigned long addr, int numpages,
737 pgprot_t mask)
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100738{
Thomas Gleixner56744542008-01-30 13:34:08 +0100739 return change_page_attr_set_clr(addr, numpages, mask, __pgprot(0));
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100740}
741
Thomas Gleixner56744542008-01-30 13:34:08 +0100742static inline int change_page_attr_clear(unsigned long addr, int numpages,
743 pgprot_t mask)
Thomas Gleixner72932c72008-01-30 13:34:08 +0100744{
Huang, Ying58270402008-01-31 22:05:43 +0100745 return change_page_attr_set_clr(addr, numpages, __pgprot(0), mask);
Thomas Gleixner72932c72008-01-30 13:34:08 +0100746}
747
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100748int set_memory_uc(unsigned long addr, int numpages)
749{
Thomas Gleixner72932c72008-01-30 13:34:08 +0100750 return change_page_attr_set(addr, numpages,
751 __pgprot(_PAGE_PCD | _PAGE_PWT));
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100752}
753EXPORT_SYMBOL(set_memory_uc);
754
755int set_memory_wb(unsigned long addr, int numpages)
756{
Thomas Gleixner72932c72008-01-30 13:34:08 +0100757 return change_page_attr_clear(addr, numpages,
758 __pgprot(_PAGE_PCD | _PAGE_PWT));
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100759}
760EXPORT_SYMBOL(set_memory_wb);
761
762int set_memory_x(unsigned long addr, int numpages)
763{
Thomas Gleixner72932c72008-01-30 13:34:08 +0100764 return change_page_attr_clear(addr, numpages, __pgprot(_PAGE_NX));
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100765}
766EXPORT_SYMBOL(set_memory_x);
767
768int set_memory_nx(unsigned long addr, int numpages)
769{
Thomas Gleixner72932c72008-01-30 13:34:08 +0100770 return change_page_attr_set(addr, numpages, __pgprot(_PAGE_NX));
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100771}
772EXPORT_SYMBOL(set_memory_nx);
773
774int set_memory_ro(unsigned long addr, int numpages)
775{
Thomas Gleixner72932c72008-01-30 13:34:08 +0100776 return change_page_attr_clear(addr, numpages, __pgprot(_PAGE_RW));
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100777}
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100778
779int set_memory_rw(unsigned long addr, int numpages)
780{
Thomas Gleixner72932c72008-01-30 13:34:08 +0100781 return change_page_attr_set(addr, numpages, __pgprot(_PAGE_RW));
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100782}
Ingo Molnarf62d0f02008-01-30 13:34:07 +0100783
784int set_memory_np(unsigned long addr, int numpages)
785{
Thomas Gleixner72932c72008-01-30 13:34:08 +0100786 return change_page_attr_clear(addr, numpages, __pgprot(_PAGE_PRESENT));
Ingo Molnarf62d0f02008-01-30 13:34:07 +0100787}
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100788
789int set_pages_uc(struct page *page, int numpages)
790{
791 unsigned long addr = (unsigned long)page_address(page);
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100792
Thomas Gleixnerd7c8f212008-01-30 13:34:07 +0100793 return set_memory_uc(addr, numpages);
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100794}
795EXPORT_SYMBOL(set_pages_uc);
796
797int set_pages_wb(struct page *page, int numpages)
798{
799 unsigned long addr = (unsigned long)page_address(page);
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100800
Thomas Gleixnerd7c8f212008-01-30 13:34:07 +0100801 return set_memory_wb(addr, numpages);
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100802}
803EXPORT_SYMBOL(set_pages_wb);
804
805int set_pages_x(struct page *page, int numpages)
806{
807 unsigned long addr = (unsigned long)page_address(page);
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100808
Thomas Gleixnerd7c8f212008-01-30 13:34:07 +0100809 return set_memory_x(addr, numpages);
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100810}
811EXPORT_SYMBOL(set_pages_x);
812
813int set_pages_nx(struct page *page, int numpages)
814{
815 unsigned long addr = (unsigned long)page_address(page);
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100816
Thomas Gleixnerd7c8f212008-01-30 13:34:07 +0100817 return set_memory_nx(addr, numpages);
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100818}
819EXPORT_SYMBOL(set_pages_nx);
820
821int set_pages_ro(struct page *page, int numpages)
822{
823 unsigned long addr = (unsigned long)page_address(page);
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100824
Thomas Gleixnerd7c8f212008-01-30 13:34:07 +0100825 return set_memory_ro(addr, numpages);
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100826}
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100827
828int set_pages_rw(struct page *page, int numpages)
829{
830 unsigned long addr = (unsigned long)page_address(page);
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100831
Thomas Gleixnerd7c8f212008-01-30 13:34:07 +0100832 return set_memory_rw(addr, numpages);
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100833}
Arjan van de Ven75cbade2008-01-30 13:34:06 +0100834
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835#ifdef CONFIG_DEBUG_PAGEALLOC
Ingo Molnarf62d0f02008-01-30 13:34:07 +0100836
837static int __set_pages_p(struct page *page, int numpages)
838{
Thomas Gleixner72e458d2008-02-04 16:48:07 +0100839 struct cpa_data cpa = { .vaddr = (unsigned long) page_address(page),
840 .numpages = numpages,
841 .mask_set = __pgprot(_PAGE_PRESENT | _PAGE_RW),
842 .mask_clr = __pgprot(0)};
Thomas Gleixner72932c72008-01-30 13:34:08 +0100843
Thomas Gleixner72e458d2008-02-04 16:48:07 +0100844 return __change_page_attr_set_clr(&cpa);
Ingo Molnarf62d0f02008-01-30 13:34:07 +0100845}
846
847static int __set_pages_np(struct page *page, int numpages)
848{
Thomas Gleixner72e458d2008-02-04 16:48:07 +0100849 struct cpa_data cpa = { .vaddr = (unsigned long) page_address(page),
850 .numpages = numpages,
851 .mask_set = __pgprot(0),
852 .mask_clr = __pgprot(_PAGE_PRESENT | _PAGE_RW)};
Thomas Gleixner72932c72008-01-30 13:34:08 +0100853
Thomas Gleixner72e458d2008-02-04 16:48:07 +0100854 return __change_page_attr_set_clr(&cpa);
Ingo Molnarf62d0f02008-01-30 13:34:07 +0100855}
856
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857void kernel_map_pages(struct page *page, int numpages, int enable)
858{
859 if (PageHighMem(page))
860 return;
Ingo Molnar9f4c8152008-01-30 13:33:41 +0100861 if (!enable) {
Ingo Molnarf9b84042006-06-27 02:54:49 -0700862 debug_check_no_locks_freed(page_address(page),
863 numpages * PAGE_SIZE);
Ingo Molnar9f4c8152008-01-30 13:33:41 +0100864 }
Ingo Molnarde5097c2006-01-09 15:59:21 -0800865
Ingo Molnar9f4c8152008-01-30 13:33:41 +0100866 /*
Ingo Molnar12d6f212008-01-30 13:33:58 +0100867 * If page allocator is not up yet then do not call c_p_a():
868 */
869 if (!debug_pagealloc_enabled)
870 return;
871
872 /*
Ingo Molnare4b71dc2008-01-30 13:34:04 +0100873 * The return value is ignored - the calls cannot fail,
874 * large pages are disabled at boot time:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 */
Ingo Molnarf62d0f02008-01-30 13:34:07 +0100876 if (enable)
877 __set_pages_p(page, numpages);
878 else
879 __set_pages_np(page, numpages);
Ingo Molnar9f4c8152008-01-30 13:33:41 +0100880
881 /*
Ingo Molnare4b71dc2008-01-30 13:34:04 +0100882 * We should perform an IPI and flush all tlbs,
883 * but that can deadlock->flush only current cpu:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 */
885 __flush_tlb_all();
Thomas Gleixner76ebd052008-02-09 23:24:09 +0100886
887 /*
888 * Try to refill the page pool here. We can do this only after
889 * the tlb flush.
890 */
891 cpa_fill_pool();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892}
893#endif
Arjan van de Vend1028a12008-01-30 13:34:07 +0100894
895/*
896 * The testcases use internal knowledge of the implementation that shouldn't
897 * be exposed to the rest of the kernel. Include these directly here.
898 */
899#ifdef CONFIG_CPA_DEBUG
900#include "pageattr-test.c"
901#endif