fs: check for statfs overflow
[deliverable/linux.git] / arch / powerpc / mm / hugetlbpage.c
CommitLineData
1da177e4
LT
1/*
2 * PPC64 (POWER4) Huge TLB Page Support for Kernel.
3 *
4 * Copyright (C) 2003 David Gibson, IBM Corporation.
5 *
6 * Based on the IA-32 version:
7 * Copyright (C) 2002, Rohit Seth <rohit.seth@intel.com>
8 */
9
10#include <linux/init.h>
11#include <linux/fs.h>
12#include <linux/mm.h>
13#include <linux/hugetlb.h>
14#include <linux/pagemap.h>
1da177e4
LT
15#include <linux/slab.h>
16#include <linux/err.h>
17#include <linux/sysctl.h>
18#include <asm/mman.h>
19#include <asm/pgalloc.h>
20#include <asm/tlb.h>
21#include <asm/tlbflush.h>
22#include <asm/mmu_context.h>
23#include <asm/machdep.h>
24#include <asm/cputable.h>
94b2a439 25#include <asm/spu.h>
1da177e4 26
91224346
JT
27#define PAGE_SHIFT_64K 16
28#define PAGE_SHIFT_16M 24
29#define PAGE_SHIFT_16G 34
4ec161cf 30
c594adad
DG
31#define NUM_LOW_AREAS (0x100000000UL >> SID_SHIFT)
32#define NUM_HIGH_AREAS (PGTABLE_RANGE >> HTLB_AREA_SHIFT)
ec4b2c0c
JT
33#define MAX_NUMBER_GPAGES 1024
34
35/* Tracks the 16G pages after the device tree is scanned and before the
36 * huge_boot_pages list is ready. */
37static unsigned long gpage_freearray[MAX_NUMBER_GPAGES];
38static unsigned nr_gpages;
c594adad 39
4ec161cf
JT
40unsigned int hugepte_shift;
41#define PTRS_PER_HUGEPTE (1 << hugepte_shift)
42#define HUGEPTE_TABLE_SIZE (sizeof(pte_t) << hugepte_shift)
f10a04c0 43
4ec161cf 44#define HUGEPD_SHIFT (HPAGE_SHIFT + hugepte_shift)
f10a04c0
DG
45#define HUGEPD_SIZE (1UL << HUGEPD_SHIFT)
46#define HUGEPD_MASK (~(HUGEPD_SIZE-1))
47
48#define huge_pgtable_cache (pgtable_cache[HUGEPTE_CACHE_NUM])
49
50/* Flag to mark huge PD pointers. This means pmd_bad() and pud_bad()
51 * will choke on pointers to hugepte tables, which is handy for
52 * catching screwups early. */
53#define HUGEPD_OK 0x1
54
55typedef struct { unsigned long pd; } hugepd_t;
56
57#define hugepd_none(hpd) ((hpd).pd == 0)
58
59static inline pte_t *hugepd_page(hugepd_t hpd)
60{
61 BUG_ON(!(hpd.pd & HUGEPD_OK));
62 return (pte_t *)(hpd.pd & ~HUGEPD_OK);
63}
64
65static inline pte_t *hugepte_offset(hugepd_t *hpdp, unsigned long addr)
66{
67 unsigned long idx = ((addr >> HPAGE_SHIFT) & (PTRS_PER_HUGEPTE-1));
68 pte_t *dir = hugepd_page(*hpdp);
69
70 return dir + idx;
71}
72
73static int __hugepte_alloc(struct mm_struct *mm, hugepd_t *hpdp,
74 unsigned long address)
75{
76 pte_t *new = kmem_cache_alloc(huge_pgtable_cache,
77 GFP_KERNEL|__GFP_REPEAT);
78
79 if (! new)
80 return -ENOMEM;
81
82 spin_lock(&mm->page_table_lock);
83 if (!hugepd_none(*hpdp))
84 kmem_cache_free(huge_pgtable_cache, new);
85 else
86 hpdp->pd = (unsigned long)new | HUGEPD_OK;
87 spin_unlock(&mm->page_table_lock);
88 return 0;
89}
90
4ec161cf
JT
91/* Base page size affects how we walk hugetlb page tables */
92#ifdef CONFIG_PPC_64K_PAGES
93#define hpmd_offset(pud, addr) pmd_offset(pud, addr)
94#define hpmd_alloc(mm, pud, addr) pmd_alloc(mm, pud, addr)
95#else
96static inline
97pmd_t *hpmd_offset(pud_t *pud, unsigned long addr)
98{
91224346 99 if (HPAGE_SHIFT == PAGE_SHIFT_64K)
4ec161cf
JT
100 return pmd_offset(pud, addr);
101 else
102 return (pmd_t *) pud;
103}
104static inline
105pmd_t *hpmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long addr)
106{
91224346 107 if (HPAGE_SHIFT == PAGE_SHIFT_64K)
4ec161cf
JT
108 return pmd_alloc(mm, pud, addr);
109 else
110 return (pmd_t *) pud;
111}
112#endif
113
658013e9
JT
114/* Build list of addresses of gigantic pages. This function is used in early
115 * boot before the buddy or bootmem allocator is setup.
116 */
117void add_gpage(unsigned long addr, unsigned long page_size,
118 unsigned long number_of_pages)
119{
120 if (!addr)
121 return;
122 while (number_of_pages > 0) {
123 gpage_freearray[nr_gpages] = addr;
124 nr_gpages++;
125 number_of_pages--;
126 addr += page_size;
127 }
128}
129
ec4b2c0c
JT
130/* Moves the gigantic page addresses from the temporary list to the
131 * huge_boot_pages list. */
132int alloc_bootmem_huge_page(struct hstate *h)
133{
134 struct huge_bootmem_page *m;
135 if (nr_gpages == 0)
136 return 0;
137 m = phys_to_virt(gpage_freearray[--nr_gpages]);
138 gpage_freearray[nr_gpages] = 0;
139 list_add(&m->list, &huge_boot_pages);
140 m->hstate = h;
141 return 1;
142}
143
144
e28f7faf
DG
145/* Modelled after find_linux_pte() */
146pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr)
1da177e4 147{
e28f7faf
DG
148 pgd_t *pg;
149 pud_t *pu;
4ec161cf 150 pmd_t *pm;
1da177e4 151
d0f13e3c 152 BUG_ON(get_slice_psize(mm, addr) != mmu_huge_psize);
1da177e4 153
e28f7faf
DG
154 addr &= HPAGE_MASK;
155
156 pg = pgd_offset(mm, addr);
157 if (!pgd_none(*pg)) {
158 pu = pud_offset(pg, addr);
159 if (!pud_none(*pu)) {
4ec161cf 160 pm = hpmd_offset(pu, addr);
f10a04c0
DG
161 if (!pmd_none(*pm))
162 return hugepte_offset((hugepd_t *)pm, addr);
e28f7faf
DG
163 }
164 }
1da177e4 165
e28f7faf 166 return NULL;
1da177e4
LT
167}
168
a5516438
AK
169pte_t *huge_pte_alloc(struct mm_struct *mm,
170 unsigned long addr, unsigned long sz)
1da177e4 171{
e28f7faf
DG
172 pgd_t *pg;
173 pud_t *pu;
4ec161cf 174 pmd_t *pm;
f10a04c0 175 hugepd_t *hpdp = NULL;
1da177e4 176
d0f13e3c 177 BUG_ON(get_slice_psize(mm, addr) != mmu_huge_psize);
1da177e4 178
e28f7faf 179 addr &= HPAGE_MASK;
1da177e4 180
e28f7faf
DG
181 pg = pgd_offset(mm, addr);
182 pu = pud_alloc(mm, pg, addr);
1da177e4 183
e28f7faf 184 if (pu) {
4ec161cf 185 pm = hpmd_alloc(mm, pu, addr);
f10a04c0
DG
186 if (pm)
187 hpdp = (hugepd_t *)pm;
f10a04c0
DG
188 }
189
190 if (! hpdp)
191 return NULL;
192
193 if (hugepd_none(*hpdp) && __hugepte_alloc(mm, hpdp, addr))
194 return NULL;
195
196 return hugepte_offset(hpdp, addr);
197}
198
39dde65c
CK
199int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
200{
201 return 0;
202}
203
f10a04c0
DG
204static void free_hugepte_range(struct mmu_gather *tlb, hugepd_t *hpdp)
205{
206 pte_t *hugepte = hugepd_page(*hpdp);
207
208 hpdp->pd = 0;
209 tlb->need_flush = 1;
210 pgtable_free_tlb(tlb, pgtable_free_cache(hugepte, HUGEPTE_CACHE_NUM,
c9169f87 211 PGF_CACHENUM_MASK));
f10a04c0
DG
212}
213
f10a04c0
DG
214static void hugetlb_free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
215 unsigned long addr, unsigned long end,
216 unsigned long floor, unsigned long ceiling)
217{
218 pmd_t *pmd;
219 unsigned long next;
220 unsigned long start;
221
222 start = addr;
223 pmd = pmd_offset(pud, addr);
224 do {
225 next = pmd_addr_end(addr, end);
226 if (pmd_none(*pmd))
227 continue;
228 free_hugepte_range(tlb, (hugepd_t *)pmd);
229 } while (pmd++, addr = next, addr != end);
230
231 start &= PUD_MASK;
232 if (start < floor)
233 return;
234 if (ceiling) {
235 ceiling &= PUD_MASK;
236 if (!ceiling)
237 return;
1da177e4 238 }
f10a04c0
DG
239 if (end - 1 > ceiling - 1)
240 return;
1da177e4 241
f10a04c0
DG
242 pmd = pmd_offset(pud, start);
243 pud_clear(pud);
244 pmd_free_tlb(tlb, pmd);
245}
f10a04c0
DG
246
247static void hugetlb_free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
248 unsigned long addr, unsigned long end,
249 unsigned long floor, unsigned long ceiling)
250{
251 pud_t *pud;
252 unsigned long next;
253 unsigned long start;
254
255 start = addr;
256 pud = pud_offset(pgd, addr);
257 do {
258 next = pud_addr_end(addr, end);
259#ifdef CONFIG_PPC_64K_PAGES
260 if (pud_none_or_clear_bad(pud))
261 continue;
262 hugetlb_free_pmd_range(tlb, pud, addr, next, floor, ceiling);
263#else
91224346 264 if (HPAGE_SHIFT == PAGE_SHIFT_64K) {
4ec161cf
JT
265 if (pud_none_or_clear_bad(pud))
266 continue;
267 hugetlb_free_pmd_range(tlb, pud, addr, next, floor, ceiling);
268 } else {
269 if (pud_none(*pud))
270 continue;
271 free_hugepte_range(tlb, (hugepd_t *)pud);
272 }
f10a04c0
DG
273#endif
274 } while (pud++, addr = next, addr != end);
275
276 start &= PGDIR_MASK;
277 if (start < floor)
278 return;
279 if (ceiling) {
280 ceiling &= PGDIR_MASK;
281 if (!ceiling)
282 return;
283 }
284 if (end - 1 > ceiling - 1)
285 return;
286
287 pud = pud_offset(pgd, start);
288 pgd_clear(pgd);
289 pud_free_tlb(tlb, pud);
290}
291
292/*
293 * This function frees user-level page tables of a process.
294 *
295 * Must be called with pagetable lock held.
296 */
42b77728 297void hugetlb_free_pgd_range(struct mmu_gather *tlb,
f10a04c0
DG
298 unsigned long addr, unsigned long end,
299 unsigned long floor, unsigned long ceiling)
300{
301 pgd_t *pgd;
302 unsigned long next;
303 unsigned long start;
304
305 /*
306 * Comments below take from the normal free_pgd_range(). They
307 * apply here too. The tests against HUGEPD_MASK below are
308 * essential, because we *don't* test for this at the bottom
309 * level. Without them we'll attempt to free a hugepte table
310 * when we unmap just part of it, even if there are other
311 * active mappings using it.
312 *
313 * The next few lines have given us lots of grief...
314 *
315 * Why are we testing HUGEPD* at this top level? Because
316 * often there will be no work to do at all, and we'd prefer
317 * not to go all the way down to the bottom just to discover
318 * that.
319 *
320 * Why all these "- 1"s? Because 0 represents both the bottom
321 * of the address space and the top of it (using -1 for the
322 * top wouldn't help much: the masks would do the wrong thing).
323 * The rule is that addr 0 and floor 0 refer to the bottom of
324 * the address space, but end 0 and ceiling 0 refer to the top
325 * Comparisons need to use "end - 1" and "ceiling - 1" (though
326 * that end 0 case should be mythical).
327 *
328 * Wherever addr is brought up or ceiling brought down, we
329 * must be careful to reject "the opposite 0" before it
330 * confuses the subsequent tests. But what about where end is
331 * brought down by HUGEPD_SIZE below? no, end can't go down to
332 * 0 there.
333 *
334 * Whereas we round start (addr) and ceiling down, by different
335 * masks at different levels, in order to test whether a table
336 * now has no other vmas using it, so can be freed, we don't
337 * bother to round floor or end up - the tests don't need that.
338 */
339
340 addr &= HUGEPD_MASK;
341 if (addr < floor) {
342 addr += HUGEPD_SIZE;
343 if (!addr)
344 return;
345 }
346 if (ceiling) {
347 ceiling &= HUGEPD_MASK;
348 if (!ceiling)
349 return;
350 }
351 if (end - 1 > ceiling - 1)
352 end -= HUGEPD_SIZE;
353 if (addr > end - 1)
354 return;
355
356 start = addr;
42b77728 357 pgd = pgd_offset(tlb->mm, addr);
f10a04c0 358 do {
42b77728 359 BUG_ON(get_slice_psize(tlb->mm, addr) != mmu_huge_psize);
f10a04c0
DG
360 next = pgd_addr_end(addr, end);
361 if (pgd_none_or_clear_bad(pgd))
362 continue;
42b77728 363 hugetlb_free_pud_range(tlb, pgd, addr, next, floor, ceiling);
f10a04c0 364 } while (pgd++, addr = next, addr != end);
1da177e4
LT
365}
366
e28f7faf
DG
367void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
368 pte_t *ptep, pte_t pte)
369{
e28f7faf 370 if (pte_present(*ptep)) {
3c726f8d 371 /* We open-code pte_clear because we need to pass the right
a741e679
BH
372 * argument to hpte_need_flush (huge / !huge). Might not be
373 * necessary anymore if we make hpte_need_flush() get the
374 * page size from the slices
3c726f8d 375 */
a741e679 376 pte_update(mm, addr & HPAGE_MASK, ptep, ~0UL, 1);
e28f7faf 377 }
3c726f8d 378 *ptep = __pte(pte_val(pte) & ~_PAGE_HPTEFLAGS);
1da177e4
LT
379}
380
e28f7faf
DG
381pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
382 pte_t *ptep)
1da177e4 383{
a741e679 384 unsigned long old = pte_update(mm, addr, ptep, ~0UL, 1);
e28f7faf 385 return __pte(old);
1da177e4
LT
386}
387
1da177e4
LT
388struct page *
389follow_huge_addr(struct mm_struct *mm, unsigned long address, int write)
390{
391 pte_t *ptep;
392 struct page *page;
393
d0f13e3c 394 if (get_slice_psize(mm, address) != mmu_huge_psize)
1da177e4
LT
395 return ERR_PTR(-EINVAL);
396
397 ptep = huge_pte_offset(mm, address);
398 page = pte_page(*ptep);
399 if (page)
400 page += (address % HPAGE_SIZE) / PAGE_SIZE;
401
402 return page;
403}
404
405int pmd_huge(pmd_t pmd)
406{
407 return 0;
408}
409
ceb86879
AK
410int pud_huge(pud_t pud)
411{
412 return 0;
413}
414
1da177e4
LT
415struct page *
416follow_huge_pmd(struct mm_struct *mm, unsigned long address,
417 pmd_t *pmd, int write)
418{
419 BUG();
420 return NULL;
421}
422
1da177e4
LT
423
424unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
425 unsigned long len, unsigned long pgoff,
426 unsigned long flags)
427{
d0f13e3c
BH
428 return slice_get_unmapped_area(addr, len, flags,
429 mmu_huge_psize, 1, 0);
1da177e4
LT
430}
431
cbf52afd
DG
432/*
433 * Called by asm hashtable.S for doing lazy icache flush
434 */
435static unsigned int hash_huge_page_do_lazy_icache(unsigned long rflags,
436 pte_t pte, int trap)
437{
438 struct page *page;
439 int i;
440
441 if (!pfn_valid(pte_pfn(pte)))
442 return rflags;
443
444 page = pte_page(pte);
445
446 /* page is dirty */
447 if (!test_bit(PG_arch_1, &page->flags) && !PageReserved(page)) {
448 if (trap == 0x400) {
449 for (i = 0; i < (HPAGE_SIZE / PAGE_SIZE); i++)
450 __flush_dcache_icache(page_address(page+i));
451 set_bit(PG_arch_1, &page->flags);
452 } else {
453 rflags |= HPTE_R_N;
454 }
455 }
456 return rflags;
457}
458
1da177e4 459int hash_huge_page(struct mm_struct *mm, unsigned long access,
cbf52afd
DG
460 unsigned long ea, unsigned long vsid, int local,
461 unsigned long trap)
1da177e4
LT
462{
463 pte_t *ptep;
3c726f8d
BH
464 unsigned long old_pte, new_pte;
465 unsigned long va, rflags, pa;
1da177e4
LT
466 long slot;
467 int err = 1;
1189be65 468 int ssize = user_segment_size(ea);
1da177e4 469
1da177e4
LT
470 ptep = huge_pte_offset(mm, ea);
471
472 /* Search the Linux page table for a match with va */
1189be65 473 va = hpt_va(ea, vsid, ssize);
1da177e4
LT
474
475 /*
476 * If no pte found or not present, send the problem up to
477 * do_page_fault
478 */
479 if (unlikely(!ptep || pte_none(*ptep)))
480 goto out;
481
1da177e4
LT
482 /*
483 * Check the user's access rights to the page. If access should be
484 * prevented then send the problem up to do_page_fault.
485 */
486 if (unlikely(access & ~pte_val(*ptep)))
487 goto out;
488 /*
489 * At this point, we have a pte (old_pte) which can be used to build
490 * or update an HPTE. There are 2 cases:
491 *
492 * 1. There is a valid (present) pte with no associated HPTE (this is
493 * the most common case)
494 * 2. There is a valid (present) pte with an associated HPTE. The
495 * current values of the pp bits in the HPTE prevent access
496 * because we are doing software DIRTY bit management and the
497 * page is currently not DIRTY.
498 */
499
500
3c726f8d
BH
501 do {
502 old_pte = pte_val(*ptep);
503 if (old_pte & _PAGE_BUSY)
504 goto out;
41743a4e 505 new_pte = old_pte | _PAGE_BUSY | _PAGE_ACCESSED;
3c726f8d
BH
506 } while(old_pte != __cmpxchg_u64((unsigned long *)ptep,
507 old_pte, new_pte));
508
509 rflags = 0x2 | (!(new_pte & _PAGE_RW));
1da177e4 510 /* _PAGE_EXEC -> HW_NO_EXEC since it's inverted */
3c726f8d 511 rflags |= ((new_pte & _PAGE_EXEC) ? 0 : HPTE_R_N);
cbf52afd
DG
512 if (!cpu_has_feature(CPU_FTR_COHERENT_ICACHE))
513 /* No CPU has hugepages but lacks no execute, so we
514 * don't need to worry about that case */
515 rflags = hash_huge_page_do_lazy_icache(rflags, __pte(old_pte),
516 trap);
1da177e4
LT
517
518 /* Check if pte already has an hpte (case 2) */
3c726f8d 519 if (unlikely(old_pte & _PAGE_HASHPTE)) {
1da177e4
LT
520 /* There MIGHT be an HPTE for this pte */
521 unsigned long hash, slot;
522
1189be65 523 hash = hpt_hash(va, HPAGE_SHIFT, ssize);
3c726f8d 524 if (old_pte & _PAGE_F_SECOND)
1da177e4
LT
525 hash = ~hash;
526 slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
3c726f8d 527 slot += (old_pte & _PAGE_F_GIX) >> 12;
1da177e4 528
325c82a0 529 if (ppc_md.hpte_updatepp(slot, rflags, va, mmu_huge_psize,
1189be65 530 ssize, local) == -1)
3c726f8d 531 old_pte &= ~_PAGE_HPTEFLAGS;
1da177e4
LT
532 }
533
3c726f8d 534 if (likely(!(old_pte & _PAGE_HASHPTE))) {
1189be65 535 unsigned long hash = hpt_hash(va, HPAGE_SHIFT, ssize);
1da177e4
LT
536 unsigned long hpte_group;
537
3c726f8d 538 pa = pte_pfn(__pte(old_pte)) << PAGE_SHIFT;
1da177e4
LT
539
540repeat:
541 hpte_group = ((hash & htab_hash_mask) *
542 HPTES_PER_GROUP) & ~0x7UL;
543
3c726f8d 544 /* clear HPTE slot informations in new PTE */
41743a4e
BH
545#ifdef CONFIG_PPC_64K_PAGES
546 new_pte = (new_pte & ~_PAGE_HPTEFLAGS) | _PAGE_HPTE_SUB0;
547#else
3c726f8d 548 new_pte = (new_pte & ~_PAGE_HPTEFLAGS) | _PAGE_HASHPTE;
41743a4e 549#endif
1da177e4 550 /* Add in WIMG bits */
87e9ab13
DK
551 rflags |= (new_pte & (_PAGE_WRITETHRU | _PAGE_NO_CACHE |
552 _PAGE_COHERENT | _PAGE_GUARDED));
1da177e4 553
3c726f8d
BH
554 /* Insert into the hash table, primary slot */
555 slot = ppc_md.hpte_insert(hpte_group, va, pa, rflags, 0,
1189be65 556 mmu_huge_psize, ssize);
1da177e4
LT
557
558 /* Primary is full, try the secondary */
559 if (unlikely(slot == -1)) {
1da177e4
LT
560 hpte_group = ((~hash & htab_hash_mask) *
561 HPTES_PER_GROUP) & ~0x7UL;
3c726f8d 562 slot = ppc_md.hpte_insert(hpte_group, va, pa, rflags,
67b10813 563 HPTE_V_SECONDARY,
1189be65 564 mmu_huge_psize, ssize);
1da177e4
LT
565 if (slot == -1) {
566 if (mftb() & 0x1)
67b10813
BH
567 hpte_group = ((hash & htab_hash_mask) *
568 HPTES_PER_GROUP)&~0x7UL;
1da177e4
LT
569
570 ppc_md.hpte_remove(hpte_group);
571 goto repeat;
572 }
573 }
574
575 if (unlikely(slot == -2))
576 panic("hash_huge_page: pte_insert failed\n");
577
d649bd7b 578 new_pte |= (slot << 12) & (_PAGE_F_SECOND | _PAGE_F_GIX);
1da177e4
LT
579 }
580
3c726f8d 581 /*
01edcd89 582 * No need to use ldarx/stdcx here
3c726f8d
BH
583 */
584 *ptep = __pte(new_pte & ~_PAGE_BUSY);
585
1da177e4
LT
586 err = 0;
587
588 out:
1da177e4
LT
589 return err;
590}
f10a04c0 591
4ec161cf
JT
592void set_huge_psize(int psize)
593{
594 /* Check that it is a page size supported by the hardware and
595 * that it fits within pagetable limits. */
91224346
JT
596 if (mmu_psize_defs[psize].shift &&
597 mmu_psize_defs[psize].shift < SID_SHIFT_1T &&
4ec161cf 598 (mmu_psize_defs[psize].shift > MIN_HUGEPTE_SHIFT ||
91224346
JT
599 mmu_psize_defs[psize].shift == PAGE_SHIFT_64K ||
600 mmu_psize_defs[psize].shift == PAGE_SHIFT_16G)) {
601 /* Return if huge page size is the same as the
602 * base page size. */
603 if (mmu_psize_defs[psize].shift == PAGE_SHIFT)
604 return;
605
4ec161cf
JT
606 HPAGE_SHIFT = mmu_psize_defs[psize].shift;
607 mmu_huge_psize = psize;
4ec161cf 608
91224346
JT
609 switch (HPAGE_SHIFT) {
610 case PAGE_SHIFT_64K:
611 /* We only allow 64k hpages with 4k base page,
612 * which was checked above, and always put them
613 * at the PMD */
614 hugepte_shift = PMD_SHIFT;
615 break;
616 case PAGE_SHIFT_16M:
617 /* 16M pages can be at two different levels
618 * of pagestables based on base page size */
619 if (PAGE_SHIFT == PAGE_SHIFT_64K)
620 hugepte_shift = PMD_SHIFT;
621 else /* 4k base page */
622 hugepte_shift = PUD_SHIFT;
623 break;
624 case PAGE_SHIFT_16G:
625 /* 16G pages are always at PGD level */
626 hugepte_shift = PGDIR_SHIFT;
627 break;
628 }
629 hugepte_shift -= HPAGE_SHIFT;
4ec161cf
JT
630 } else
631 HPAGE_SHIFT = 0;
632}
633
634static int __init hugepage_setup_sz(char *str)
635{
636 unsigned long long size;
637 int mmu_psize = -1;
638 int shift;
639
640 size = memparse(str, &str);
641
642 shift = __ffs(size);
643 switch (shift) {
644#ifndef CONFIG_PPC_64K_PAGES
91224346 645 case PAGE_SHIFT_64K:
4ec161cf
JT
646 mmu_psize = MMU_PAGE_64K;
647 break;
648#endif
91224346 649 case PAGE_SHIFT_16M:
4ec161cf
JT
650 mmu_psize = MMU_PAGE_16M;
651 break;
91224346
JT
652 case PAGE_SHIFT_16G:
653 mmu_psize = MMU_PAGE_16G;
654 break;
4ec161cf
JT
655 }
656
91224346 657 if (mmu_psize >= 0 && mmu_psize_defs[mmu_psize].shift) {
4ec161cf 658 set_huge_psize(mmu_psize);
91224346
JT
659 hugetlb_add_hstate(shift - PAGE_SHIFT);
660 }
4ec161cf
JT
661 else
662 printk(KERN_WARNING "Invalid huge page size specified(%llu)\n", size);
663
664 return 1;
665}
666__setup("hugepagesz=", hugepage_setup_sz);
667
4ba9b9d0 668static void zero_ctor(struct kmem_cache *cache, void *addr)
f10a04c0
DG
669{
670 memset(addr, 0, kmem_cache_size(cache));
671}
672
673static int __init hugetlbpage_init(void)
674{
675 if (!cpu_has_feature(CPU_FTR_16M_PAGE))
676 return -ENODEV;
677
678 huge_pgtable_cache = kmem_cache_create("hugepte_cache",
679 HUGEPTE_TABLE_SIZE,
680 HUGEPTE_TABLE_SIZE,
f0f3980b 681 0,
20c2df83 682 zero_ctor);
f10a04c0
DG
683 if (! huge_pgtable_cache)
684 panic("hugetlbpage_init(): could not create hugepte cache\n");
685
686 return 0;
687}
688
689module_init(hugetlbpage_init);
This page took 0.476983 seconds and 5 git commands to generate.