aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-generic
diff options
context:
space:
mode:
Diffstat (limited to 'include/asm-generic')
-rw-r--r--include/asm-generic/4level-fixup.h3
-rw-r--r--include/asm-generic/5level-fixup.h41
-rw-r--r--include/asm-generic/pgtable-nop4d-hack.h62
-rw-r--r--include/asm-generic/pgtable-nop4d.h56
-rw-r--r--include/asm-generic/pgtable-nopud.h48
-rw-r--r--include/asm-generic/pgtable.h48
-rw-r--r--include/asm-generic/tlb.h14
7 files changed, 244 insertions, 28 deletions
diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
index 5bdab6bffd23..928fd66b1271 100644
--- a/include/asm-generic/4level-fixup.h
+++ b/include/asm-generic/4level-fixup.h
@@ -15,7 +15,6 @@
15 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \ 15 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
16 NULL: pmd_offset(pud, address)) 16 NULL: pmd_offset(pud, address))
17 17
18#define pud_alloc(mm, pgd, address) (pgd)
19#define pud_offset(pgd, start) (pgd) 18#define pud_offset(pgd, start) (pgd)
20#define pud_none(pud) 0 19#define pud_none(pud) 0
21#define pud_bad(pud) 0 20#define pud_bad(pud) 0
@@ -35,4 +34,6 @@
35#undef pud_addr_end 34#undef pud_addr_end
36#define pud_addr_end(addr, end) (end) 35#define pud_addr_end(addr, end) (end)
37 36
37#include <asm-generic/5level-fixup.h>
38
38#endif 39#endif
diff --git a/include/asm-generic/5level-fixup.h b/include/asm-generic/5level-fixup.h
new file mode 100644
index 000000000000..b5ca82dc4175
--- /dev/null
+++ b/include/asm-generic/5level-fixup.h
@@ -0,0 +1,41 @@
1#ifndef _5LEVEL_FIXUP_H
2#define _5LEVEL_FIXUP_H
3
4#define __ARCH_HAS_5LEVEL_HACK
5#define __PAGETABLE_P4D_FOLDED
6
7#define P4D_SHIFT PGDIR_SHIFT
8#define P4D_SIZE PGDIR_SIZE
9#define P4D_MASK PGDIR_MASK
10#define PTRS_PER_P4D 1
11
12#define p4d_t pgd_t
13
14#define pud_alloc(mm, p4d, address) \
15 ((unlikely(pgd_none(*(p4d))) && __pud_alloc(mm, p4d, address)) ? \
16 NULL : pud_offset(p4d, address))
17
18#define p4d_alloc(mm, pgd, address) (pgd)
19#define p4d_offset(pgd, start) (pgd)
20#define p4d_none(p4d) 0
21#define p4d_bad(p4d) 0
22#define p4d_present(p4d) 1
23#define p4d_ERROR(p4d) do { } while (0)
24#define p4d_clear(p4d) pgd_clear(p4d)
25#define p4d_val(p4d) pgd_val(p4d)
26#define p4d_populate(mm, p4d, pud) pgd_populate(mm, p4d, pud)
27#define p4d_page(p4d) pgd_page(p4d)
28#define p4d_page_vaddr(p4d) pgd_page_vaddr(p4d)
29
30#define __p4d(x) __pgd(x)
31#define set_p4d(p4dp, p4d) set_pgd(p4dp, p4d)
32
33#undef p4d_free_tlb
34#define p4d_free_tlb(tlb, x, addr) do { } while (0)
35#define p4d_free(mm, x) do { } while (0)
36#define __p4d_free_tlb(tlb, x, addr) do { } while (0)
37
38#undef p4d_addr_end
39#define p4d_addr_end(addr, end) (end)
40
41#endif
diff --git a/include/asm-generic/pgtable-nop4d-hack.h b/include/asm-generic/pgtable-nop4d-hack.h
new file mode 100644
index 000000000000..752fb7511750
--- /dev/null
+++ b/include/asm-generic/pgtable-nop4d-hack.h
@@ -0,0 +1,62 @@
1#ifndef _PGTABLE_NOP4D_HACK_H
2#define _PGTABLE_NOP4D_HACK_H
3
4#ifndef __ASSEMBLY__
5#include <asm-generic/5level-fixup.h>
6
7#define __PAGETABLE_PUD_FOLDED
8
9/*
10 * Having the pud type consist of a pgd gets the size right, and allows
11 * us to conceptually access the pgd entry that this pud is folded into
12 * without casting.
13 */
14typedef struct { pgd_t pgd; } pud_t;
15
16#define PUD_SHIFT PGDIR_SHIFT
17#define PTRS_PER_PUD 1
18#define PUD_SIZE (1UL << PUD_SHIFT)
19#define PUD_MASK (~(PUD_SIZE-1))
20
21/*
22 * The "pgd_xxx()" functions here are trivial for a folded two-level
23 * setup: the pud is never bad, and a pud always exists (as it's folded
24 * into the pgd entry)
25 */
26static inline int pgd_none(pgd_t pgd) { return 0; }
27static inline int pgd_bad(pgd_t pgd) { return 0; }
28static inline int pgd_present(pgd_t pgd) { return 1; }
29static inline void pgd_clear(pgd_t *pgd) { }
30#define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
31
32#define pgd_populate(mm, pgd, pud) do { } while (0)
33/*
34 * (puds are folded into pgds so this doesn't get actually called,
35 * but the define is needed for a generic inline function.)
36 */
37#define set_pgd(pgdptr, pgdval) set_pud((pud_t *)(pgdptr), (pud_t) { pgdval })
38
39static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
40{
41 return (pud_t *)pgd;
42}
43
44#define pud_val(x) (pgd_val((x).pgd))
45#define __pud(x) ((pud_t) { __pgd(x) })
46
47#define pgd_page(pgd) (pud_page((pud_t){ pgd }))
48#define pgd_page_vaddr(pgd) (pud_page_vaddr((pud_t){ pgd }))
49
50/*
51 * allocating and freeing a pud is trivial: the 1-entry pud is
52 * inside the pgd, so has no extra memory associated with it.
53 */
54#define pud_alloc_one(mm, address) NULL
55#define pud_free(mm, x) do { } while (0)
56#define __pud_free_tlb(tlb, x, a) do { } while (0)
57
58#undef pud_addr_end
59#define pud_addr_end(addr, end) (end)
60
61#endif /* __ASSEMBLY__ */
62#endif /* _PGTABLE_NOP4D_HACK_H */
diff --git a/include/asm-generic/pgtable-nop4d.h b/include/asm-generic/pgtable-nop4d.h
new file mode 100644
index 000000000000..de364ecb8df6
--- /dev/null
+++ b/include/asm-generic/pgtable-nop4d.h
@@ -0,0 +1,56 @@
1#ifndef _PGTABLE_NOP4D_H
2#define _PGTABLE_NOP4D_H
3
4#ifndef __ASSEMBLY__
5
6#define __PAGETABLE_P4D_FOLDED
7
8typedef struct { pgd_t pgd; } p4d_t;
9
10#define P4D_SHIFT PGDIR_SHIFT
11#define PTRS_PER_P4D 1
12#define P4D_SIZE (1UL << P4D_SHIFT)
13#define P4D_MASK (~(P4D_SIZE-1))
14
15/*
16 * The "pgd_xxx()" functions here are trivial for a folded two-level
17 * setup: the p4d is never bad, and a p4d always exists (as it's folded
18 * into the pgd entry)
19 */
20static inline int pgd_none(pgd_t pgd) { return 0; }
21static inline int pgd_bad(pgd_t pgd) { return 0; }
22static inline int pgd_present(pgd_t pgd) { return 1; }
23static inline void pgd_clear(pgd_t *pgd) { }
24#define p4d_ERROR(p4d) (pgd_ERROR((p4d).pgd))
25
26#define pgd_populate(mm, pgd, p4d) do { } while (0)
27/*
28 * (p4ds are folded into pgds so this doesn't get actually called,
29 * but the define is needed for a generic inline function.)
30 */
31#define set_pgd(pgdptr, pgdval) set_p4d((p4d_t *)(pgdptr), (p4d_t) { pgdval })
32
33static inline p4d_t *p4d_offset(pgd_t *pgd, unsigned long address)
34{
35 return (p4d_t *)pgd;
36}
37
38#define p4d_val(x) (pgd_val((x).pgd))
39#define __p4d(x) ((p4d_t) { __pgd(x) })
40
41#define pgd_page(pgd) (p4d_page((p4d_t){ pgd }))
42#define pgd_page_vaddr(pgd) (p4d_page_vaddr((p4d_t){ pgd }))
43
44/*
45 * allocating and freeing a p4d is trivial: the 1-entry p4d is
46 * inside the pgd, so has no extra memory associated with it.
47 */
48#define p4d_alloc_one(mm, address) NULL
49#define p4d_free(mm, x) do { } while (0)
50#define __p4d_free_tlb(tlb, x, a) do { } while (0)
51
52#undef p4d_addr_end
53#define p4d_addr_end(addr, end) (end)
54
55#endif /* __ASSEMBLY__ */
56#endif /* _PGTABLE_NOP4D_H */
diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
index 810431d8351b..c2b9b96d6268 100644
--- a/include/asm-generic/pgtable-nopud.h
+++ b/include/asm-generic/pgtable-nopud.h
@@ -3,52 +3,57 @@
3 3
4#ifndef __ASSEMBLY__ 4#ifndef __ASSEMBLY__
5 5
6#ifdef __ARCH_USE_5LEVEL_HACK
7#include <asm-generic/pgtable-nop4d-hack.h>
8#else
9#include <asm-generic/pgtable-nop4d.h>
10
6#define __PAGETABLE_PUD_FOLDED 11#define __PAGETABLE_PUD_FOLDED
7 12
8/* 13/*
9 * Having the pud type consist of a pgd gets the size right, and allows 14 * Having the pud type consist of a p4d gets the size right, and allows
10 * us to conceptually access the pgd entry that this pud is folded into 15 * us to conceptually access the p4d entry that this pud is folded into
11 * without casting. 16 * without casting.
12 */ 17 */
13typedef struct { pgd_t pgd; } pud_t; 18typedef struct { p4d_t p4d; } pud_t;
14 19
15#define PUD_SHIFT PGDIR_SHIFT 20#define PUD_SHIFT P4D_SHIFT
16#define PTRS_PER_PUD 1 21#define PTRS_PER_PUD 1
17#define PUD_SIZE (1UL << PUD_SHIFT) 22#define PUD_SIZE (1UL << PUD_SHIFT)
18#define PUD_MASK (~(PUD_SIZE-1)) 23#define PUD_MASK (~(PUD_SIZE-1))
19 24
20/* 25/*
21 * The "pgd_xxx()" functions here are trivial for a folded two-level 26 * The "p4d_xxx()" functions here are trivial for a folded two-level
22 * setup: the pud is never bad, and a pud always exists (as it's folded 27 * setup: the pud is never bad, and a pud always exists (as it's folded
23 * into the pgd entry) 28 * into the p4d entry)
24 */ 29 */
25static inline int pgd_none(pgd_t pgd) { return 0; } 30static inline int p4d_none(p4d_t p4d) { return 0; }
26static inline int pgd_bad(pgd_t pgd) { return 0; } 31static inline int p4d_bad(p4d_t p4d) { return 0; }
27static inline int pgd_present(pgd_t pgd) { return 1; } 32static inline int p4d_present(p4d_t p4d) { return 1; }
28static inline void pgd_clear(pgd_t *pgd) { } 33static inline void p4d_clear(p4d_t *p4d) { }
29#define pud_ERROR(pud) (pgd_ERROR((pud).pgd)) 34#define pud_ERROR(pud) (p4d_ERROR((pud).p4d))
30 35
31#define pgd_populate(mm, pgd, pud) do { } while (0) 36#define p4d_populate(mm, p4d, pud) do { } while (0)
32/* 37/*
33 * (puds are folded into pgds so this doesn't get actually called, 38 * (puds are folded into p4ds so this doesn't get actually called,
34 * but the define is needed for a generic inline function.) 39 * but the define is needed for a generic inline function.)
35 */ 40 */
36#define set_pgd(pgdptr, pgdval) set_pud((pud_t *)(pgdptr), (pud_t) { pgdval }) 41#define set_p4d(p4dptr, p4dval) set_pud((pud_t *)(p4dptr), (pud_t) { p4dval })
37 42
38static inline pud_t * pud_offset(pgd_t * pgd, unsigned long address) 43static inline pud_t *pud_offset(p4d_t *p4d, unsigned long address)
39{ 44{
40 return (pud_t *)pgd; 45 return (pud_t *)p4d;
41} 46}
42 47
43#define pud_val(x) (pgd_val((x).pgd)) 48#define pud_val(x) (p4d_val((x).p4d))
44#define __pud(x) ((pud_t) { __pgd(x) } ) 49#define __pud(x) ((pud_t) { __p4d(x) })
45 50
46#define pgd_page(pgd) (pud_page((pud_t){ pgd })) 51#define p4d_page(p4d) (pud_page((pud_t){ p4d }))
47#define pgd_page_vaddr(pgd) (pud_page_vaddr((pud_t){ pgd })) 52#define p4d_page_vaddr(p4d) (pud_page_vaddr((pud_t){ p4d }))
48 53
49/* 54/*
50 * allocating and freeing a pud is trivial: the 1-entry pud is 55 * allocating and freeing a pud is trivial: the 1-entry pud is
51 * inside the pgd, so has no extra memory associated with it. 56 * inside the p4d, so has no extra memory associated with it.
52 */ 57 */
53#define pud_alloc_one(mm, address) NULL 58#define pud_alloc_one(mm, address) NULL
54#define pud_free(mm, x) do { } while (0) 59#define pud_free(mm, x) do { } while (0)
@@ -58,4 +63,5 @@ static inline pud_t * pud_offset(pgd_t * pgd, unsigned long address)
58#define pud_addr_end(addr, end) (end) 63#define pud_addr_end(addr, end) (end)
59 64
60#endif /* __ASSEMBLY__ */ 65#endif /* __ASSEMBLY__ */
66#endif /* !__ARCH_USE_5LEVEL_HACK */
61#endif /* _PGTABLE_NOPUD_H */ 67#endif /* _PGTABLE_NOPUD_H */
diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
index f4ca23b158b3..1fad160f35de 100644
--- a/include/asm-generic/pgtable.h
+++ b/include/asm-generic/pgtable.h
@@ -10,9 +10,9 @@
10#include <linux/bug.h> 10#include <linux/bug.h>
11#include <linux/errno.h> 11#include <linux/errno.h>
12 12
13#if 4 - defined(__PAGETABLE_PUD_FOLDED) - defined(__PAGETABLE_PMD_FOLDED) != \ 13#if 5 - defined(__PAGETABLE_P4D_FOLDED) - defined(__PAGETABLE_PUD_FOLDED) - \
14 CONFIG_PGTABLE_LEVELS 14 defined(__PAGETABLE_PMD_FOLDED) != CONFIG_PGTABLE_LEVELS
15#error CONFIG_PGTABLE_LEVELS is not consistent with __PAGETABLE_{PUD,PMD}_FOLDED 15#error CONFIG_PGTABLE_LEVELS is not consistent with __PAGETABLE_{P4D,PUD,PMD}_FOLDED
16#endif 16#endif
17 17
18/* 18/*
@@ -424,6 +424,13 @@ static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
424 (__boundary - 1 < (end) - 1)? __boundary: (end); \ 424 (__boundary - 1 < (end) - 1)? __boundary: (end); \
425}) 425})
426 426
427#ifndef p4d_addr_end
428#define p4d_addr_end(addr, end) \
429({ unsigned long __boundary = ((addr) + P4D_SIZE) & P4D_MASK; \
430 (__boundary - 1 < (end) - 1)? __boundary: (end); \
431})
432#endif
433
427#ifndef pud_addr_end 434#ifndef pud_addr_end
428#define pud_addr_end(addr, end) \ 435#define pud_addr_end(addr, end) \
429({ unsigned long __boundary = ((addr) + PUD_SIZE) & PUD_MASK; \ 436({ unsigned long __boundary = ((addr) + PUD_SIZE) & PUD_MASK; \
@@ -444,6 +451,7 @@ static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
444 * Do the tests inline, but report and clear the bad entry in mm/memory.c. 451 * Do the tests inline, but report and clear the bad entry in mm/memory.c.
445 */ 452 */
446void pgd_clear_bad(pgd_t *); 453void pgd_clear_bad(pgd_t *);
454void p4d_clear_bad(p4d_t *);
447void pud_clear_bad(pud_t *); 455void pud_clear_bad(pud_t *);
448void pmd_clear_bad(pmd_t *); 456void pmd_clear_bad(pmd_t *);
449 457
@@ -458,6 +466,17 @@ static inline int pgd_none_or_clear_bad(pgd_t *pgd)
458 return 0; 466 return 0;
459} 467}
460 468
469static inline int p4d_none_or_clear_bad(p4d_t *p4d)
470{
471 if (p4d_none(*p4d))
472 return 1;
473 if (unlikely(p4d_bad(*p4d))) {
474 p4d_clear_bad(p4d);
475 return 1;
476 }
477 return 0;
478}
479
461static inline int pud_none_or_clear_bad(pud_t *pud) 480static inline int pud_none_or_clear_bad(pud_t *pud)
462{ 481{
463 if (pud_none(*pud)) 482 if (pud_none(*pud))
@@ -844,11 +863,30 @@ static inline int pmd_protnone(pmd_t pmd)
844#endif /* CONFIG_MMU */ 863#endif /* CONFIG_MMU */
845 864
846#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP 865#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
866
867#ifndef __PAGETABLE_P4D_FOLDED
868int p4d_set_huge(p4d_t *p4d, phys_addr_t addr, pgprot_t prot);
869int p4d_clear_huge(p4d_t *p4d);
870#else
871static inline int p4d_set_huge(p4d_t *p4d, phys_addr_t addr, pgprot_t prot)
872{
873 return 0;
874}
875static inline int p4d_clear_huge(p4d_t *p4d)
876{
877 return 0;
878}
879#endif /* !__PAGETABLE_P4D_FOLDED */
880
847int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot); 881int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot);
848int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot); 882int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot);
849int pud_clear_huge(pud_t *pud); 883int pud_clear_huge(pud_t *pud);
850int pmd_clear_huge(pmd_t *pmd); 884int pmd_clear_huge(pmd_t *pmd);
851#else /* !CONFIG_HAVE_ARCH_HUGE_VMAP */ 885#else /* !CONFIG_HAVE_ARCH_HUGE_VMAP */
886static inline int p4d_set_huge(p4d_t *p4d, phys_addr_t addr, pgprot_t prot)
887{
888 return 0;
889}
852static inline int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot) 890static inline int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)
853{ 891{
854 return 0; 892 return 0;
@@ -857,6 +895,10 @@ static inline int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot)
857{ 895{
858 return 0; 896 return 0;
859} 897}
898static inline int p4d_clear_huge(p4d_t *p4d)
899{
900 return 0;
901}
860static inline int pud_clear_huge(pud_t *pud) 902static inline int pud_clear_huge(pud_t *pud)
861{ 903{
862 return 0; 904 return 0;
diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h
index 4329bc6ef04b..8afa4335e5b2 100644
--- a/include/asm-generic/tlb.h
+++ b/include/asm-generic/tlb.h
@@ -270,6 +270,12 @@ static inline void tlb_remove_check_page_size_change(struct mmu_gather *tlb,
270 __pte_free_tlb(tlb, ptep, address); \ 270 __pte_free_tlb(tlb, ptep, address); \
271 } while (0) 271 } while (0)
272 272
273#define pmd_free_tlb(tlb, pmdp, address) \
274 do { \
275 __tlb_adjust_range(tlb, address, PAGE_SIZE); \
276 __pmd_free_tlb(tlb, pmdp, address); \
277 } while (0)
278
273#ifndef __ARCH_HAS_4LEVEL_HACK 279#ifndef __ARCH_HAS_4LEVEL_HACK
274#define pud_free_tlb(tlb, pudp, address) \ 280#define pud_free_tlb(tlb, pudp, address) \
275 do { \ 281 do { \
@@ -278,11 +284,13 @@ static inline void tlb_remove_check_page_size_change(struct mmu_gather *tlb,
278 } while (0) 284 } while (0)
279#endif 285#endif
280 286
281#define pmd_free_tlb(tlb, pmdp, address) \ 287#ifndef __ARCH_HAS_5LEVEL_HACK
288#define p4d_free_tlb(tlb, pudp, address) \
282 do { \ 289 do { \
283 __tlb_adjust_range(tlb, address, PAGE_SIZE); \ 290 __tlb_adjust_range(tlb, address, PAGE_SIZE); \
284 __pmd_free_tlb(tlb, pmdp, address); \ 291 __p4d_free_tlb(tlb, pudp, address); \
285 } while (0) 292 } while (0)
293#endif
286 294
287#define tlb_migrate_finish(mm) do {} while (0) 295#define tlb_migrate_finish(mm) do {} while (0)
288 296