This source file includes following definitions.
- hpte_need_flush
- __flush_tlb_pending
- hash__tlb_flush
- __flush_hash_table_range
- flush_tlb_pmd_range
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <linux/kernel.h>
21 #include <linux/mm.h>
22 #include <linux/percpu.h>
23 #include <linux/hardirq.h>
24 #include <asm/pgalloc.h>
25 #include <asm/tlbflush.h>
26 #include <asm/tlb.h>
27 #include <asm/bug.h>
28 #include <asm/pte-walk.h>
29
30
31 #include <trace/events/thp.h>
32
33 DEFINE_PER_CPU(struct ppc64_tlb_batch, ppc64_tlb_batch);
34
35
36
37
38
39
40
41 void hpte_need_flush(struct mm_struct *mm, unsigned long addr,
42 pte_t *ptep, unsigned long pte, int huge)
43 {
44 unsigned long vpn;
45 struct ppc64_tlb_batch *batch = &get_cpu_var(ppc64_tlb_batch);
46 unsigned long vsid;
47 unsigned int psize;
48 int ssize;
49 real_pte_t rpte;
50 int i, offset;
51
52 i = batch->index;
53
54
55
56
57
58
59
60
61
62 if (huge) {
63 #ifdef CONFIG_HUGETLB_PAGE
64 psize = get_slice_psize(mm, addr);
65
66 addr &= ~((1UL << mmu_psize_defs[psize].shift) - 1);
67 if (unlikely(psize == MMU_PAGE_16G))
68 offset = PTRS_PER_PUD;
69 else
70 offset = PTRS_PER_PMD;
71 #else
72 BUG();
73 psize = pte_pagesize_index(mm, addr, pte);
74 #endif
75 } else {
76 psize = pte_pagesize_index(mm, addr, pte);
77
78
79
80
81
82
83 addr &= PAGE_MASK;
84 offset = PTRS_PER_PTE;
85 }
86
87
88
89 if (!is_kernel_addr(addr)) {
90 ssize = user_segment_size(addr);
91 vsid = get_user_vsid(&mm->context, addr, ssize);
92 } else {
93 vsid = get_kernel_vsid(addr, mmu_kernel_ssize);
94 ssize = mmu_kernel_ssize;
95 }
96 WARN_ON(vsid == 0);
97 vpn = hpt_vpn(addr, vsid, ssize);
98 rpte = __real_pte(__pte(pte), ptep, offset);
99
100
101
102
103
104 if (!batch->active) {
105 flush_hash_page(vpn, rpte, psize, ssize, mm_is_thread_local(mm));
106 put_cpu_var(ppc64_tlb_batch);
107 return;
108 }
109
110
111
112
113
114
115
116
117
118
119
120 if (i != 0 && (mm != batch->mm || batch->psize != psize ||
121 batch->ssize != ssize)) {
122 __flush_tlb_pending(batch);
123 i = 0;
124 }
125 if (i == 0) {
126 batch->mm = mm;
127 batch->psize = psize;
128 batch->ssize = ssize;
129 }
130 batch->pte[i] = rpte;
131 batch->vpn[i] = vpn;
132 batch->index = ++i;
133 if (i >= PPC64_TLB_BATCH_NR)
134 __flush_tlb_pending(batch);
135 put_cpu_var(ppc64_tlb_batch);
136 }
137
138
139
140
141
142
143
144
145 void __flush_tlb_pending(struct ppc64_tlb_batch *batch)
146 {
147 int i, local;
148
149 i = batch->index;
150 local = mm_is_thread_local(batch->mm);
151 if (i == 1)
152 flush_hash_page(batch->vpn[0], batch->pte[0],
153 batch->psize, batch->ssize, local);
154 else
155 flush_hash_range(i, local);
156 batch->index = 0;
157 }
158
159 void hash__tlb_flush(struct mmu_gather *tlb)
160 {
161 struct ppc64_tlb_batch *tlbbatch = &get_cpu_var(ppc64_tlb_batch);
162
163
164
165
166
167
168 if (tlbbatch->index)
169 __flush_tlb_pending(tlbbatch);
170
171 put_cpu_var(ppc64_tlb_batch);
172 }
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192 void __flush_hash_table_range(struct mm_struct *mm, unsigned long start,
193 unsigned long end)
194 {
195 bool is_thp;
196 int hugepage_shift;
197 unsigned long flags;
198
199 start = _ALIGN_DOWN(start, PAGE_SIZE);
200 end = _ALIGN_UP(end, PAGE_SIZE);
201
202 BUG_ON(!mm->pgd);
203
204
205
206
207
208
209
210
211
212 local_irq_save(flags);
213 arch_enter_lazy_mmu_mode();
214 for (; start < end; start += PAGE_SIZE) {
215 pte_t *ptep = find_current_mm_pte(mm->pgd, start, &is_thp,
216 &hugepage_shift);
217 unsigned long pte;
218
219 if (ptep == NULL)
220 continue;
221 pte = pte_val(*ptep);
222 if (is_thp)
223 trace_hugepage_invalidate(start, pte);
224 if (!(pte & H_PAGE_HASHPTE))
225 continue;
226 if (unlikely(is_thp))
227 hpte_do_hugepage_flush(mm, start, (pmd_t *)ptep, pte);
228 else
229 hpte_need_flush(mm, start, ptep, pte, hugepage_shift);
230 }
231 arch_leave_lazy_mmu_mode();
232 local_irq_restore(flags);
233 }
234
235 void flush_tlb_pmd_range(struct mm_struct *mm, pmd_t *pmd, unsigned long addr)
236 {
237 pte_t *pte;
238 pte_t *start_pte;
239 unsigned long flags;
240
241 addr = _ALIGN_DOWN(addr, PMD_SIZE);
242
243
244
245
246
247
248
249
250 local_irq_save(flags);
251 arch_enter_lazy_mmu_mode();
252 start_pte = pte_offset_map(pmd, addr);
253 for (pte = start_pte; pte < start_pte + PTRS_PER_PTE; pte++) {
254 unsigned long pteval = pte_val(*pte);
255 if (pteval & H_PAGE_HASHPTE)
256 hpte_need_flush(mm, addr, pte, pteval, 0);
257 addr += PAGE_SIZE;
258 }
259 arch_leave_lazy_mmu_mode();
260 local_irq_restore(flags);
261 }