Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _S390_TLB_H |
| 2 | #define _S390_TLB_H |
| 3 | |
| 4 | /* |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 5 | * TLB flushing on s390 is complicated. The following requirement |
| 6 | * from the principles of operation is the most arduous: |
| 7 | * |
| 8 | * "A valid table entry must not be changed while it is attached |
| 9 | * to any CPU and may be used for translation by that CPU except to |
| 10 | * (1) invalidate the entry by using INVALIDATE PAGE TABLE ENTRY, |
| 11 | * or INVALIDATE DAT TABLE ENTRY, (2) alter bits 56-63 of a page |
| 12 | * table entry, or (3) make a change by means of a COMPARE AND SWAP |
| 13 | * AND PURGE instruction that purges the TLB." |
| 14 | * |
| 15 | * The modification of a pte of an active mm struct therefore is |
| 16 | * a two step process: i) invalidate the pte, ii) store the new pte. |
| 17 | * This is true for the page protection bit as well. |
| 18 | * The only possible optimization is to flush at the beginning of |
| 19 | * a tlb_gather_mmu cycle if the mm_struct is currently not in use. |
| 20 | * |
| 21 | * Pages used for the page tables is a different story. FIXME: more |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | */ |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 23 | |
| 24 | #include <linux/mm.h> |
Heiko Carstens | c84ca00 | 2011-01-31 11:30:06 +0100 | [diff] [blame] | 25 | #include <linux/pagemap.h> |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 26 | #include <linux/swap.h> |
| 27 | #include <asm/processor.h> |
| 28 | #include <asm/pgalloc.h> |
| 29 | #include <asm/smp.h> |
| 30 | #include <asm/tlbflush.h> |
| 31 | |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 32 | struct mmu_gather { |
| 33 | struct mm_struct *mm; |
| 34 | unsigned int fullmm; |
| 35 | unsigned int nr_ptes; |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 36 | unsigned int nr_pxds; |
Peter Zijlstra | 68f0392 | 2011-05-24 17:11:51 -0700 | [diff] [blame] | 37 | unsigned int max; |
| 38 | void **array; |
| 39 | void *local[8]; |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 40 | }; |
| 41 | |
Peter Zijlstra | 68f0392 | 2011-05-24 17:11:51 -0700 | [diff] [blame] | 42 | static inline void __tlb_alloc_page(struct mmu_gather *tlb) |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 43 | { |
Peter Zijlstra | 68f0392 | 2011-05-24 17:11:51 -0700 | [diff] [blame] | 44 | unsigned long addr = __get_free_pages(GFP_NOWAIT | __GFP_NOWARN, 0); |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 45 | |
Peter Zijlstra | 68f0392 | 2011-05-24 17:11:51 -0700 | [diff] [blame] | 46 | if (addr) { |
| 47 | tlb->array = (void *) addr; |
| 48 | tlb->max = PAGE_SIZE / sizeof(void *); |
| 49 | } |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 50 | } |
| 51 | |
Peter Zijlstra | 68f0392 | 2011-05-24 17:11:51 -0700 | [diff] [blame] | 52 | static inline void tlb_gather_mmu(struct mmu_gather *tlb, |
| 53 | struct mm_struct *mm, |
| 54 | unsigned int full_mm_flush) |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 55 | { |
Peter Zijlstra | 68f0392 | 2011-05-24 17:11:51 -0700 | [diff] [blame] | 56 | tlb->mm = mm; |
| 57 | tlb->max = ARRAY_SIZE(tlb->local); |
| 58 | tlb->array = tlb->local; |
| 59 | tlb->fullmm = full_mm_flush; |
| 60 | if (tlb->fullmm) |
| 61 | __tlb_flush_mm(mm); |
| 62 | else |
| 63 | __tlb_alloc_page(tlb); |
| 64 | tlb->nr_ptes = 0; |
| 65 | tlb->nr_pxds = tlb->max; |
| 66 | } |
| 67 | |
| 68 | static inline void tlb_flush_mmu(struct mmu_gather *tlb) |
| 69 | { |
| 70 | if (!tlb->fullmm && (tlb->nr_ptes > 0 || tlb->nr_pxds < tlb->max)) |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 71 | __tlb_flush_mm(tlb->mm); |
| 72 | while (tlb->nr_ptes > 0) |
Martin Schwidefsky | 8021714 | 2010-10-25 16:10:11 +0200 | [diff] [blame] | 73 | page_table_free_rcu(tlb->mm, tlb->array[--tlb->nr_ptes]); |
Peter Zijlstra | 68f0392 | 2011-05-24 17:11:51 -0700 | [diff] [blame] | 74 | while (tlb->nr_pxds < tlb->max) |
Martin Schwidefsky | 8021714 | 2010-10-25 16:10:11 +0200 | [diff] [blame] | 75 | crst_table_free_rcu(tlb->mm, tlb->array[tlb->nr_pxds++]); |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | static inline void tlb_finish_mmu(struct mmu_gather *tlb, |
| 79 | unsigned long start, unsigned long end) |
| 80 | { |
Peter Zijlstra | 68f0392 | 2011-05-24 17:11:51 -0700 | [diff] [blame] | 81 | tlb_flush_mmu(tlb); |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 82 | |
Martin Schwidefsky | 8021714 | 2010-10-25 16:10:11 +0200 | [diff] [blame] | 83 | rcu_table_freelist_finish(); |
| 84 | |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 85 | /* keep the page table cache within bounds */ |
| 86 | check_pgt_cache(); |
| 87 | |
Peter Zijlstra | 68f0392 | 2011-05-24 17:11:51 -0700 | [diff] [blame] | 88 | if (tlb->array != tlb->local) |
| 89 | free_pages((unsigned long) tlb->array, 0); |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 90 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | /* |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 93 | * Release the page cache reference for a pte removed by |
Peter Zijlstra | 68f0392 | 2011-05-24 17:11:51 -0700 | [diff] [blame] | 94 | * tlb_ptep_clear_flush. In both flush modes the tlb for a page cache page |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 95 | * has already been freed, so just do free_page_and_swap_cache. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | */ |
Peter Zijlstra | 68f0392 | 2011-05-24 17:11:51 -0700 | [diff] [blame] | 97 | static inline int __tlb_remove_page(struct mmu_gather *tlb, struct page *page) |
| 98 | { |
| 99 | free_page_and_swap_cache(page); |
| 100 | return 1; /* avoid calling tlb_flush_mmu */ |
| 101 | } |
| 102 | |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 103 | static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page) |
| 104 | { |
| 105 | free_page_and_swap_cache(page); |
| 106 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 108 | /* |
| 109 | * pte_free_tlb frees a pte table and clears the CRSTE for the |
| 110 | * page table from the tlb. |
| 111 | */ |
Benjamin Herrenschmidt | 9e1b32c | 2009-07-22 15:44:28 +1000 | [diff] [blame] | 112 | static inline void pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte, |
| 113 | unsigned long address) |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 114 | { |
| 115 | if (!tlb->fullmm) { |
Martin Schwidefsky | 146e4b3 | 2008-02-09 18:24:35 +0100 | [diff] [blame] | 116 | tlb->array[tlb->nr_ptes++] = pte; |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 117 | if (tlb->nr_ptes >= tlb->nr_pxds) |
Peter Zijlstra | 68f0392 | 2011-05-24 17:11:51 -0700 | [diff] [blame] | 118 | tlb_flush_mmu(tlb); |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 119 | } else |
Martin Schwidefsky | 8021714 | 2010-10-25 16:10:11 +0200 | [diff] [blame] | 120 | page_table_free(tlb->mm, (unsigned long *) pte); |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 121 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 123 | /* |
| 124 | * pmd_free_tlb frees a pmd table and clears the CRSTE for the |
| 125 | * segment table entry from the tlb. |
Martin Schwidefsky | 6252d70 | 2008-02-09 18:24:37 +0100 | [diff] [blame] | 126 | * If the mm uses a two level page table the single pmd is freed |
| 127 | * as the pgd. pmd_free_tlb checks the asce_limit against 2GB |
| 128 | * to avoid the double free of the pmd in this case. |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 129 | */ |
Benjamin Herrenschmidt | 9e1b32c | 2009-07-22 15:44:28 +1000 | [diff] [blame] | 130 | static inline void pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd, |
| 131 | unsigned long address) |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 132 | { |
| 133 | #ifdef __s390x__ |
Martin Schwidefsky | 6252d70 | 2008-02-09 18:24:37 +0100 | [diff] [blame] | 134 | if (tlb->mm->context.asce_limit <= (1UL << 31)) |
| 135 | return; |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 136 | if (!tlb->fullmm) { |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 137 | tlb->array[--tlb->nr_pxds] = pmd; |
| 138 | if (tlb->nr_ptes >= tlb->nr_pxds) |
Peter Zijlstra | 68f0392 | 2011-05-24 17:11:51 -0700 | [diff] [blame] | 139 | tlb_flush_mmu(tlb); |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 140 | } else |
Martin Schwidefsky | 8021714 | 2010-10-25 16:10:11 +0200 | [diff] [blame] | 141 | crst_table_free(tlb->mm, (unsigned long *) pmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | #endif |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 143 | } |
| 144 | |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 145 | /* |
| 146 | * pud_free_tlb frees a pud table and clears the CRSTE for the |
| 147 | * region third table entry from the tlb. |
Martin Schwidefsky | 6252d70 | 2008-02-09 18:24:37 +0100 | [diff] [blame] | 148 | * If the mm uses a three level page table the single pud is freed |
| 149 | * as the pgd. pud_free_tlb checks the asce_limit against 4TB |
| 150 | * to avoid the double free of the pud in this case. |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 151 | */ |
Benjamin Herrenschmidt | 9e1b32c | 2009-07-22 15:44:28 +1000 | [diff] [blame] | 152 | static inline void pud_free_tlb(struct mmu_gather *tlb, pud_t *pud, |
| 153 | unsigned long address) |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 154 | { |
| 155 | #ifdef __s390x__ |
Martin Schwidefsky | 6252d70 | 2008-02-09 18:24:37 +0100 | [diff] [blame] | 156 | if (tlb->mm->context.asce_limit <= (1UL << 42)) |
| 157 | return; |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 158 | if (!tlb->fullmm) { |
| 159 | tlb->array[--tlb->nr_pxds] = pud; |
| 160 | if (tlb->nr_ptes >= tlb->nr_pxds) |
Peter Zijlstra | 68f0392 | 2011-05-24 17:11:51 -0700 | [diff] [blame] | 161 | tlb_flush_mmu(tlb); |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 162 | } else |
Martin Schwidefsky | 8021714 | 2010-10-25 16:10:11 +0200 | [diff] [blame] | 163 | crst_table_free(tlb->mm, (unsigned long *) pud); |
Martin Schwidefsky | 5a216a2 | 2008-02-09 18:24:36 +0100 | [diff] [blame] | 164 | #endif |
| 165 | } |
Martin Schwidefsky | 190a1d7 | 2007-10-22 12:52:48 +0200 | [diff] [blame] | 166 | |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 167 | #define tlb_start_vma(tlb, vma) do { } while (0) |
| 168 | #define tlb_end_vma(tlb, vma) do { } while (0) |
| 169 | #define tlb_remove_tlb_entry(tlb, ptep, addr) do { } while (0) |
| 170 | #define tlb_migrate_finish(mm) do { } while (0) |
| 171 | |
| 172 | #endif /* _S390_TLB_H */ |