Linux-libre 4.9.63-gnu
[librecmc/linux-libre.git] / arch / s390 / include / asm / tlbflush.h
1 #ifndef _S390_TLBFLUSH_H
2 #define _S390_TLBFLUSH_H
3
4 #include <linux/mm.h>
5 #include <linux/sched.h>
6 #include <asm/processor.h>
7 #include <asm/pgalloc.h>
8 #include <asm/pgtable.h>
9
10 /*
11  * Flush all TLB entries on the local CPU.
12  */
13 static inline void __tlb_flush_local(void)
14 {
15         asm volatile("ptlb" : : : "memory");
16 }
17
18 /*
19  * Flush TLB entries for a specific ASCE on all CPUs
20  */
21 static inline void __tlb_flush_idte(unsigned long asce)
22 {
23         /* Global TLB flush for the mm */
24         asm volatile(
25                 "       .insn   rrf,0xb98e0000,0,%0,%1,0"
26                 : : "a" (2048), "a" (asce) : "cc");
27 }
28
29 #ifdef CONFIG_SMP
30 void smp_ptlb_all(void);
31
32 /*
33  * Flush all TLB entries on all CPUs.
34  */
35 static inline void __tlb_flush_global(void)
36 {
37         unsigned int dummy = 0;
38
39         csp(&dummy, 0, 0);
40 }
41
42 /*
43  * Flush TLB entries for a specific mm on all CPUs (in case gmap is used
44  * this implicates multiple ASCEs!).
45  */
46 static inline void __tlb_flush_mm(struct mm_struct *mm)
47 {
48         unsigned long gmap_asce;
49
50         /*
51          * If the machine has IDTE we prefer to do a per mm flush
52          * on all cpus instead of doing a local flush if the mm
53          * only ran on the local cpu.
54          */
55         preempt_disable();
56         atomic_inc(&mm->context.flush_count);
57         /* Reset TLB flush mask */
58         cpumask_copy(mm_cpumask(mm), &mm->context.cpu_attach_mask);
59         barrier();
60         gmap_asce = READ_ONCE(mm->context.gmap_asce);
61         if (MACHINE_HAS_IDTE && gmap_asce != -1UL) {
62                 if (gmap_asce)
63                         __tlb_flush_idte(gmap_asce);
64                 __tlb_flush_idte(mm->context.asce);
65         } else {
66                 /* Global TLB flush */
67                 __tlb_flush_global();
68         }
69         atomic_dec(&mm->context.flush_count);
70         preempt_enable();
71 }
72
73 static inline void __tlb_flush_kernel(void)
74 {
75         if (MACHINE_HAS_IDTE)
76                 __tlb_flush_idte(init_mm.context.asce);
77         else
78                 __tlb_flush_global();
79 }
80 #else
81 #define __tlb_flush_global()    __tlb_flush_local()
82
83 /*
84  * Flush TLB entries for a specific ASCE on all CPUs.
85  */
86 static inline void __tlb_flush_mm(struct mm_struct *mm)
87 {
88         __tlb_flush_local();
89 }
90
91 static inline void __tlb_flush_kernel(void)
92 {
93         __tlb_flush_local();
94 }
95 #endif
96
97 static inline void __tlb_flush_mm_lazy(struct mm_struct * mm)
98 {
99         spin_lock(&mm->context.lock);
100         if (mm->context.flush_mm) {
101                 mm->context.flush_mm = 0;
102                 __tlb_flush_mm(mm);
103         }
104         spin_unlock(&mm->context.lock);
105 }
106
107 /*
108  * TLB flushing:
109  *  flush_tlb() - flushes the current mm struct TLBs
110  *  flush_tlb_all() - flushes all processes TLBs
111  *  flush_tlb_mm(mm) - flushes the specified mm context TLB's
112  *  flush_tlb_page(vma, vmaddr) - flushes one page
113  *  flush_tlb_range(vma, start, end) - flushes a range of pages
114  *  flush_tlb_kernel_range(start, end) - flushes a range of kernel pages
115  */
116
117 /*
118  * flush_tlb_mm goes together with ptep_set_wrprotect for the
119  * copy_page_range operation and flush_tlb_range is related to
120  * ptep_get_and_clear for change_protection. ptep_set_wrprotect and
121  * ptep_get_and_clear do not flush the TLBs directly if the mm has
122  * only one user. At the end of the update the flush_tlb_mm and
123  * flush_tlb_range functions need to do the flush.
124  */
125 #define flush_tlb()                             do { } while (0)
126 #define flush_tlb_all()                         do { } while (0)
127 #define flush_tlb_page(vma, addr)               do { } while (0)
128
129 static inline void flush_tlb_mm(struct mm_struct *mm)
130 {
131         __tlb_flush_mm_lazy(mm);
132 }
133
134 static inline void flush_tlb_range(struct vm_area_struct *vma,
135                                    unsigned long start, unsigned long end)
136 {
137         __tlb_flush_mm_lazy(vma->vm_mm);
138 }
139
140 static inline void flush_tlb_kernel_range(unsigned long start,
141                                           unsigned long end)
142 {
143         __tlb_flush_kernel();
144 }
145
146 #endif /* _S390_TLBFLUSH_H */