blob: 77eee5477a52fa8ce8404d8c6fd8a4fdfdac51f5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _S390_TLB_H
2#define _S390_TLB_H
3
4/*
Martin Schwidefskyba8a9222007-10-22 12:52:44 +02005 * 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 Torvalds1da177e2005-04-16 15:20:36 -070022 */
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020023
24#include <linux/mm.h>
Heiko Carstensc84ca002011-01-31 11:30:06 +010025#include <linux/pagemap.h>
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020026#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 Schwidefskyba8a9222007-10-22 12:52:44 +020032struct mmu_gather {
33 struct mm_struct *mm;
34 unsigned int fullmm;
35 unsigned int nr_ptes;
Martin Schwidefsky5a216a22008-02-09 18:24:36 +010036 unsigned int nr_pxds;
Peter Zijlstra68f03922011-05-24 17:11:51 -070037 unsigned int max;
38 void **array;
39 void *local[8];
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020040};
41
Peter Zijlstra68f03922011-05-24 17:11:51 -070042static inline void __tlb_alloc_page(struct mmu_gather *tlb)
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020043{
Peter Zijlstra68f03922011-05-24 17:11:51 -070044 unsigned long addr = __get_free_pages(GFP_NOWAIT | __GFP_NOWARN, 0);
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020045
Peter Zijlstra68f03922011-05-24 17:11:51 -070046 if (addr) {
47 tlb->array = (void *) addr;
48 tlb->max = PAGE_SIZE / sizeof(void *);
49 }
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020050}
51
Peter Zijlstra68f03922011-05-24 17:11:51 -070052static inline void tlb_gather_mmu(struct mmu_gather *tlb,
53 struct mm_struct *mm,
54 unsigned int full_mm_flush)
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020055{
Peter Zijlstra68f03922011-05-24 17:11:51 -070056 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
68static inline void tlb_flush_mmu(struct mmu_gather *tlb)
69{
70 if (!tlb->fullmm && (tlb->nr_ptes > 0 || tlb->nr_pxds < tlb->max))
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020071 __tlb_flush_mm(tlb->mm);
72 while (tlb->nr_ptes > 0)
Martin Schwidefsky80217142010-10-25 16:10:11 +020073 page_table_free_rcu(tlb->mm, tlb->array[--tlb->nr_ptes]);
Peter Zijlstra68f03922011-05-24 17:11:51 -070074 while (tlb->nr_pxds < tlb->max)
Martin Schwidefsky80217142010-10-25 16:10:11 +020075 crst_table_free_rcu(tlb->mm, tlb->array[tlb->nr_pxds++]);
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020076}
77
78static inline void tlb_finish_mmu(struct mmu_gather *tlb,
79 unsigned long start, unsigned long end)
80{
Peter Zijlstra68f03922011-05-24 17:11:51 -070081 tlb_flush_mmu(tlb);
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020082
Martin Schwidefsky80217142010-10-25 16:10:11 +020083 rcu_table_freelist_finish();
84
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020085 /* keep the page table cache within bounds */
86 check_pgt_cache();
87
Peter Zijlstra68f03922011-05-24 17:11:51 -070088 if (tlb->array != tlb->local)
89 free_pages((unsigned long) tlb->array, 0);
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020090}
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92/*
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020093 * Release the page cache reference for a pte removed by
Peter Zijlstra68f03922011-05-24 17:11:51 -070094 * tlb_ptep_clear_flush. In both flush modes the tlb for a page cache page
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020095 * has already been freed, so just do free_page_and_swap_cache.
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 */
Peter Zijlstra68f03922011-05-24 17:11:51 -070097static 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 Schwidefskyba8a9222007-10-22 12:52:44 +0200103static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
104{
105 free_page_and_swap_cache(page);
106}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200108/*
109 * pte_free_tlb frees a pte table and clears the CRSTE for the
110 * page table from the tlb.
111 */
Benjamin Herrenschmidt9e1b32c2009-07-22 15:44:28 +1000112static inline void pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte,
113 unsigned long address)
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200114{
115 if (!tlb->fullmm) {
Martin Schwidefsky146e4b32008-02-09 18:24:35 +0100116 tlb->array[tlb->nr_ptes++] = pte;
Martin Schwidefsky5a216a22008-02-09 18:24:36 +0100117 if (tlb->nr_ptes >= tlb->nr_pxds)
Peter Zijlstra68f03922011-05-24 17:11:51 -0700118 tlb_flush_mmu(tlb);
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200119 } else
Martin Schwidefsky80217142010-10-25 16:10:11 +0200120 page_table_free(tlb->mm, (unsigned long *) pte);
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200121}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200123/*
124 * pmd_free_tlb frees a pmd table and clears the CRSTE for the
125 * segment table entry from the tlb.
Martin Schwidefsky6252d702008-02-09 18:24:37 +0100126 * 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 Schwidefskyba8a9222007-10-22 12:52:44 +0200129 */
Benjamin Herrenschmidt9e1b32c2009-07-22 15:44:28 +1000130static inline void pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
131 unsigned long address)
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200132{
133#ifdef __s390x__
Martin Schwidefsky6252d702008-02-09 18:24:37 +0100134 if (tlb->mm->context.asce_limit <= (1UL << 31))
135 return;
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200136 if (!tlb->fullmm) {
Martin Schwidefsky5a216a22008-02-09 18:24:36 +0100137 tlb->array[--tlb->nr_pxds] = pmd;
138 if (tlb->nr_ptes >= tlb->nr_pxds)
Peter Zijlstra68f03922011-05-24 17:11:51 -0700139 tlb_flush_mmu(tlb);
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200140 } else
Martin Schwidefsky80217142010-10-25 16:10:11 +0200141 crst_table_free(tlb->mm, (unsigned long *) pmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#endif
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200143}
144
Martin Schwidefsky5a216a22008-02-09 18:24:36 +0100145/*
146 * pud_free_tlb frees a pud table and clears the CRSTE for the
147 * region third table entry from the tlb.
Martin Schwidefsky6252d702008-02-09 18:24:37 +0100148 * 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 Schwidefsky5a216a22008-02-09 18:24:36 +0100151 */
Benjamin Herrenschmidt9e1b32c2009-07-22 15:44:28 +1000152static inline void pud_free_tlb(struct mmu_gather *tlb, pud_t *pud,
153 unsigned long address)
Martin Schwidefsky5a216a22008-02-09 18:24:36 +0100154{
155#ifdef __s390x__
Martin Schwidefsky6252d702008-02-09 18:24:37 +0100156 if (tlb->mm->context.asce_limit <= (1UL << 42))
157 return;
Martin Schwidefsky5a216a22008-02-09 18:24:36 +0100158 if (!tlb->fullmm) {
159 tlb->array[--tlb->nr_pxds] = pud;
160 if (tlb->nr_ptes >= tlb->nr_pxds)
Peter Zijlstra68f03922011-05-24 17:11:51 -0700161 tlb_flush_mmu(tlb);
Martin Schwidefsky5a216a22008-02-09 18:24:36 +0100162 } else
Martin Schwidefsky80217142010-10-25 16:10:11 +0200163 crst_table_free(tlb->mm, (unsigned long *) pud);
Martin Schwidefsky5a216a22008-02-09 18:24:36 +0100164#endif
165}
Martin Schwidefsky190a1d72007-10-22 12:52:48 +0200166
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200167#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 */