• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /* include/asm-generic/tlb.h
3  *
4  *	Generic TLB shootdown code
5  *
6  * Copyright 2001 Red Hat, Inc.
7  * Based on code from mm/memory.c Copyright Linus Torvalds and others.
8  *
9  * Copyright 2011 Red Hat, Inc., Peter Zijlstra
10  */
11 #ifndef _ASM_GENERIC__TLB_H
12 #define _ASM_GENERIC__TLB_H
13 
14 #include <linux/mmu_notifier.h>
15 #include <linux/swap.h>
16 #include <asm/pgalloc.h>
17 #include <asm/tlbflush.h>
18 #include <asm/cacheflush.h>
19 
20 /*
21  * Blindly accessing user memory from NMI context can be dangerous
22  * if we're in the middle of switching the current user task or switching
23  * the loaded mm.
24  */
25 #ifndef nmi_uaccess_okay
26 # define nmi_uaccess_okay() true
27 #endif
28 
29 #ifdef CONFIG_MMU
30 
31 /*
32  * Generic MMU-gather implementation.
33  *
34  * The mmu_gather data structure is used by the mm code to implement the
35  * correct and efficient ordering of freeing pages and TLB invalidations.
36  *
37  * This correct ordering is:
38  *
39  *  1) unhook page
40  *  2) TLB invalidate page
41  *  3) free page
42  *
43  * That is, we must never free a page before we have ensured there are no live
44  * translations left to it. Otherwise it might be possible to observe (or
45  * worse, change) the page content after it has been reused.
46  *
47  * The mmu_gather API consists of:
48  *
49  *  - tlb_gather_mmu() / tlb_finish_mmu(); start and finish a mmu_gather
50  *
51  *    Finish in particular will issue a (final) TLB invalidate and free
52  *    all (remaining) queued pages.
53  *
54  *  - tlb_start_vma() / tlb_end_vma(); marks the start / end of a VMA
55  *
56  *    Defaults to flushing at tlb_end_vma() to reset the range; helps when
57  *    there's large holes between the VMAs.
58  *
59  *  - tlb_remove_page() / __tlb_remove_page()
60  *  - tlb_remove_page_size() / __tlb_remove_page_size()
61  *
62  *    __tlb_remove_page_size() is the basic primitive that queues a page for
63  *    freeing. __tlb_remove_page() assumes PAGE_SIZE. Both will return a
64  *    boolean indicating if the queue is (now) full and a call to
65  *    tlb_flush_mmu() is required.
66  *
67  *    tlb_remove_page() and tlb_remove_page_size() imply the call to
68  *    tlb_flush_mmu() when required and has no return value.
69  *
70  *  - tlb_change_page_size()
71  *
72  *    call before __tlb_remove_page*() to set the current page-size; implies a
73  *    possible tlb_flush_mmu() call.
74  *
75  *  - tlb_flush_mmu() / tlb_flush_mmu_tlbonly()
76  *
77  *    tlb_flush_mmu_tlbonly() - does the TLB invalidate (and resets
78  *                              related state, like the range)
79  *
80  *    tlb_flush_mmu() - in addition to the above TLB invalidate, also frees
81  *			whatever pages are still batched.
82  *
83  *  - mmu_gather::fullmm
84  *
85  *    A flag set by tlb_gather_mmu() to indicate we're going to free
86  *    the entire mm; this allows a number of optimizations.
87  *
88  *    - We can ignore tlb_{start,end}_vma(); because we don't
89  *      care about ranges. Everything will be shot down.
90  *
91  *    - (RISC) architectures that use ASIDs can cycle to a new ASID
92  *      and delay the invalidation until ASID space runs out.
93  *
94  *  - mmu_gather::need_flush_all
95  *
96  *    A flag that can be set by the arch code if it wants to force
97  *    flush the entire TLB irrespective of the range. For instance
98  *    x86-PAE needs this when changing top-level entries.
99  *
100  * And allows the architecture to provide and implement tlb_flush():
101  *
102  * tlb_flush() may, in addition to the above mentioned mmu_gather fields, make
103  * use of:
104  *
105  *  - mmu_gather::start / mmu_gather::end
106  *
107  *    which provides the range that needs to be flushed to cover the pages to
108  *    be freed.
109  *
110  *  - mmu_gather::freed_tables
111  *
112  *    set when we freed page table pages
113  *
114  *  - tlb_get_unmap_shift() / tlb_get_unmap_size()
115  *
116  *    returns the smallest TLB entry size unmapped in this range.
117  *
118  * If an architecture does not provide tlb_flush() a default implementation
119  * based on flush_tlb_range() will be used, unless MMU_GATHER_NO_RANGE is
120  * specified, in which case we'll default to flush_tlb_mm().
121  *
122  * Additionally there are a few opt-in features:
123  *
124  *  HAVE_MMU_GATHER_PAGE_SIZE
125  *
126  *  This ensures we call tlb_flush() every time tlb_change_page_size() actually
127  *  changes the size and provides mmu_gather::page_size to tlb_flush().
128  *
129  *  HAVE_RCU_TABLE_FREE
130  *
131  *  This provides tlb_remove_table(), to be used instead of tlb_remove_page()
132  *  for page directores (__p*_free_tlb()). This provides separate freeing of
133  *  the page-table pages themselves in a semi-RCU fashion (see comment below).
134  *  Useful if your architecture doesn't use IPIs for remote TLB invalidates
135  *  and therefore doesn't naturally serialize with software page-table walkers.
136  *
137  *  When used, an architecture is expected to provide __tlb_remove_table()
138  *  which does the actual freeing of these pages.
139  *
140  *  MMU_GATHER_NO_RANGE
141  *
142  *  Use this if your architecture lacks an efficient flush_tlb_range().
143  */
144 
145 #ifdef CONFIG_HAVE_RCU_TABLE_FREE
146 /*
147  * Semi RCU freeing of the page directories.
148  *
149  * This is needed by some architectures to implement software pagetable walkers.
150  *
151  * gup_fast() and other software pagetable walkers do a lockless page-table
152  * walk and therefore needs some synchronization with the freeing of the page
153  * directories. The chosen means to accomplish that is by disabling IRQs over
154  * the walk.
155  *
156  * Architectures that use IPIs to flush TLBs will then automagically DTRT,
157  * since we unlink the page, flush TLBs, free the page. Since the disabling of
158  * IRQs delays the completion of the TLB flush we can never observe an already
159  * freed page.
160  *
161  * Architectures that do not have this (PPC) need to delay the freeing by some
162  * other means, this is that means.
163  *
164  * What we do is batch the freed directory pages (tables) and RCU free them.
165  * We use the sched RCU variant, as that guarantees that IRQ/preempt disabling
166  * holds off grace periods.
167  *
168  * However, in order to batch these pages we need to allocate storage, this
169  * allocation is deep inside the MM code and can thus easily fail on memory
170  * pressure. To guarantee progress we fall back to single table freeing, see
171  * the implementation of tlb_remove_table_one().
172  *
173  */
174 struct mmu_table_batch {
175 	struct rcu_head		rcu;
176 	unsigned int		nr;
177 	void			*tables[0];
178 };
179 
180 #define MAX_TABLE_BATCH		\
181 	((PAGE_SIZE - sizeof(struct mmu_table_batch)) / sizeof(void *))
182 
183 extern void tlb_remove_table(struct mmu_gather *tlb, void *table);
184 
185 /*
186  * This allows an architecture that does not use the linux page-tables for
187  * hardware to skip the TLBI when freeing page tables.
188  */
189 #ifndef tlb_needs_table_invalidate
190 #define tlb_needs_table_invalidate() (true)
191 #endif
192 
193 void tlb_remove_table_sync_one(void);
194 
195 #else
196 
197 #ifdef tlb_needs_table_invalidate
198 #error tlb_needs_table_invalidate() requires HAVE_RCU_TABLE_FREE
199 #endif
200 
tlb_remove_table_sync_one(void)201 static inline void tlb_remove_table_sync_one(void) { }
202 
203 #endif /* CONFIG_HAVE_RCU_TABLE_FREE */
204 
205 
206 #ifndef CONFIG_HAVE_MMU_GATHER_NO_GATHER
207 /*
208  * If we can't allocate a page to make a big batch of page pointers
209  * to work on, then just handle a few from the on-stack structure.
210  */
211 #define MMU_GATHER_BUNDLE	8
212 
213 struct mmu_gather_batch {
214 	struct mmu_gather_batch	*next;
215 	unsigned int		nr;
216 	unsigned int		max;
217 	struct page		*pages[0];
218 };
219 
220 #define MAX_GATHER_BATCH	\
221 	((PAGE_SIZE - sizeof(struct mmu_gather_batch)) / sizeof(void *))
222 
223 /*
224  * Limit the maximum number of mmu_gather batches to reduce a risk of soft
225  * lockups for non-preemptible kernels on huge machines when a lot of memory
226  * is zapped during unmapping.
227  * 10K pages freed at once should be safe even without a preemption point.
228  */
229 #define MAX_GATHER_BATCH_COUNT	(10000UL/MAX_GATHER_BATCH)
230 
231 extern bool __tlb_remove_page_size(struct mmu_gather *tlb, struct page *page,
232 				   int page_size);
233 #endif
234 
235 /*
236  * struct mmu_gather is an opaque type used by the mm code for passing around
237  * any data needed by arch specific code for tlb_remove_page.
238  */
239 struct mmu_gather {
240 	struct mm_struct	*mm;
241 
242 #ifdef CONFIG_HAVE_RCU_TABLE_FREE
243 	struct mmu_table_batch	*batch;
244 #endif
245 
246 	unsigned long		start;
247 	unsigned long		end;
248 	/*
249 	 * we are in the middle of an operation to clear
250 	 * a full mm and can make some optimizations
251 	 */
252 	unsigned int		fullmm : 1;
253 
254 	/*
255 	 * we have performed an operation which
256 	 * requires a complete flush of the tlb
257 	 */
258 	unsigned int		need_flush_all : 1;
259 
260 	/*
261 	 * we have removed page directories
262 	 */
263 	unsigned int		freed_tables : 1;
264 
265 	/*
266 	 * at which levels have we cleared entries?
267 	 */
268 	unsigned int		cleared_ptes : 1;
269 	unsigned int		cleared_pmds : 1;
270 	unsigned int		cleared_puds : 1;
271 	unsigned int		cleared_p4ds : 1;
272 
273 	/*
274 	 * tracks VM_EXEC | VM_HUGETLB in tlb_start_vma
275 	 */
276 	unsigned int		vma_exec : 1;
277 	unsigned int		vma_huge : 1;
278 
279 	unsigned int		batch_count;
280 
281 #ifndef CONFIG_HAVE_MMU_GATHER_NO_GATHER
282 	struct mmu_gather_batch *active;
283 	struct mmu_gather_batch	local;
284 	struct page		*__pages[MMU_GATHER_BUNDLE];
285 
286 #ifdef CONFIG_HAVE_MMU_GATHER_PAGE_SIZE
287 	unsigned int page_size;
288 #endif
289 #endif
290 };
291 
292 void arch_tlb_gather_mmu(struct mmu_gather *tlb,
293 	struct mm_struct *mm, unsigned long start, unsigned long end);
294 void tlb_flush_mmu(struct mmu_gather *tlb);
295 void arch_tlb_finish_mmu(struct mmu_gather *tlb,
296 			 unsigned long start, unsigned long end, bool force);
297 
__tlb_adjust_range(struct mmu_gather * tlb,unsigned long address,unsigned int range_size)298 static inline void __tlb_adjust_range(struct mmu_gather *tlb,
299 				      unsigned long address,
300 				      unsigned int range_size)
301 {
302 	tlb->start = min(tlb->start, address);
303 	tlb->end = max(tlb->end, address + range_size);
304 }
305 
__tlb_reset_range(struct mmu_gather * tlb)306 static inline void __tlb_reset_range(struct mmu_gather *tlb)
307 {
308 	if (tlb->fullmm) {
309 		tlb->start = tlb->end = ~0;
310 	} else {
311 		tlb->start = TASK_SIZE;
312 		tlb->end = 0;
313 	}
314 	tlb->freed_tables = 0;
315 	tlb->cleared_ptes = 0;
316 	tlb->cleared_pmds = 0;
317 	tlb->cleared_puds = 0;
318 	tlb->cleared_p4ds = 0;
319 	/*
320 	 * Do not reset mmu_gather::vma_* fields here, we do not
321 	 * call into tlb_start_vma() again to set them if there is an
322 	 * intermediate flush.
323 	 */
324 }
325 
326 #ifdef CONFIG_MMU_GATHER_NO_RANGE
327 
328 #if defined(tlb_flush) || defined(tlb_start_vma) || defined(tlb_end_vma)
329 #error MMU_GATHER_NO_RANGE relies on default tlb_flush(), tlb_start_vma() and tlb_end_vma()
330 #endif
331 
332 /*
333  * When an architecture does not have efficient means of range flushing TLBs
334  * there is no point in doing intermediate flushes on tlb_end_vma() to keep the
335  * range small. We equally don't have to worry about page granularity or other
336  * things.
337  *
338  * All we need to do is issue a full flush for any !0 range.
339  */
tlb_flush(struct mmu_gather * tlb)340 static inline void tlb_flush(struct mmu_gather *tlb)
341 {
342 	if (tlb->end)
343 		flush_tlb_mm(tlb->mm);
344 }
345 
346 static inline void
tlb_update_vma_flags(struct mmu_gather * tlb,struct vm_area_struct * vma)347 tlb_update_vma_flags(struct mmu_gather *tlb, struct vm_area_struct *vma) { }
348 
349 #define tlb_end_vma tlb_end_vma
tlb_end_vma(struct mmu_gather * tlb,struct vm_area_struct * vma)350 static inline void tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vma) { }
351 
352 #else /* CONFIG_MMU_GATHER_NO_RANGE */
353 
354 #ifndef tlb_flush
355 
356 #if defined(tlb_start_vma) || defined(tlb_end_vma)
357 #error Default tlb_flush() relies on default tlb_start_vma() and tlb_end_vma()
358 #endif
359 
360 /*
361  * When an architecture does not provide its own tlb_flush() implementation
362  * but does have a reasonably efficient flush_vma_range() implementation
363  * use that.
364  */
tlb_flush(struct mmu_gather * tlb)365 static inline void tlb_flush(struct mmu_gather *tlb)
366 {
367 	if (tlb->fullmm || tlb->need_flush_all) {
368 		flush_tlb_mm(tlb->mm);
369 	} else if (tlb->end) {
370 		struct vm_area_struct vma = {
371 			.vm_mm = tlb->mm,
372 			.vm_flags = (tlb->vma_exec ? VM_EXEC    : 0) |
373 				    (tlb->vma_huge ? VM_HUGETLB : 0),
374 		};
375 
376 		flush_tlb_range(&vma, tlb->start, tlb->end);
377 	}
378 }
379 
380 static inline void
tlb_update_vma_flags(struct mmu_gather * tlb,struct vm_area_struct * vma)381 tlb_update_vma_flags(struct mmu_gather *tlb, struct vm_area_struct *vma)
382 {
383 	/*
384 	 * flush_tlb_range() implementations that look at VM_HUGETLB (tile,
385 	 * mips-4k) flush only large pages.
386 	 *
387 	 * flush_tlb_range() implementations that flush I-TLB also flush D-TLB
388 	 * (tile, xtensa, arm), so it's ok to just add VM_EXEC to an existing
389 	 * range.
390 	 *
391 	 * We rely on tlb_end_vma() to issue a flush, such that when we reset
392 	 * these values the batch is empty.
393 	 */
394 	tlb->vma_huge = !!(vma->vm_flags & VM_HUGETLB);
395 	tlb->vma_exec = !!(vma->vm_flags & VM_EXEC);
396 }
397 
398 #else
399 
400 static inline void
tlb_update_vma_flags(struct mmu_gather * tlb,struct vm_area_struct * vma)401 tlb_update_vma_flags(struct mmu_gather *tlb, struct vm_area_struct *vma) { }
402 
403 #endif
404 
405 #endif /* CONFIG_MMU_GATHER_NO_RANGE */
406 
tlb_flush_mmu_tlbonly(struct mmu_gather * tlb)407 static inline void tlb_flush_mmu_tlbonly(struct mmu_gather *tlb)
408 {
409 	if (!tlb->end)
410 		return;
411 
412 	tlb_flush(tlb);
413 	mmu_notifier_invalidate_range(tlb->mm, tlb->start, tlb->end);
414 	__tlb_reset_range(tlb);
415 }
416 
tlb_remove_page_size(struct mmu_gather * tlb,struct page * page,int page_size)417 static inline void tlb_remove_page_size(struct mmu_gather *tlb,
418 					struct page *page, int page_size)
419 {
420 	if (__tlb_remove_page_size(tlb, page, page_size))
421 		tlb_flush_mmu(tlb);
422 }
423 
__tlb_remove_page(struct mmu_gather * tlb,struct page * page)424 static inline bool __tlb_remove_page(struct mmu_gather *tlb, struct page *page)
425 {
426 	return __tlb_remove_page_size(tlb, page, PAGE_SIZE);
427 }
428 
429 /* tlb_remove_page
430  *	Similar to __tlb_remove_page but will call tlb_flush_mmu() itself when
431  *	required.
432  */
tlb_remove_page(struct mmu_gather * tlb,struct page * page)433 static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
434 {
435 	return tlb_remove_page_size(tlb, page, PAGE_SIZE);
436 }
437 
tlb_change_page_size(struct mmu_gather * tlb,unsigned int page_size)438 static inline void tlb_change_page_size(struct mmu_gather *tlb,
439 						     unsigned int page_size)
440 {
441 #ifdef CONFIG_HAVE_MMU_GATHER_PAGE_SIZE
442 	if (tlb->page_size && tlb->page_size != page_size) {
443 		if (!tlb->fullmm)
444 			tlb_flush_mmu(tlb);
445 	}
446 
447 	tlb->page_size = page_size;
448 #endif
449 }
450 
tlb_get_unmap_shift(struct mmu_gather * tlb)451 static inline unsigned long tlb_get_unmap_shift(struct mmu_gather *tlb)
452 {
453 	if (tlb->cleared_ptes)
454 		return PAGE_SHIFT;
455 	if (tlb->cleared_pmds)
456 		return PMD_SHIFT;
457 	if (tlb->cleared_puds)
458 		return PUD_SHIFT;
459 	if (tlb->cleared_p4ds)
460 		return P4D_SHIFT;
461 
462 	return PAGE_SHIFT;
463 }
464 
tlb_get_unmap_size(struct mmu_gather * tlb)465 static inline unsigned long tlb_get_unmap_size(struct mmu_gather *tlb)
466 {
467 	return 1UL << tlb_get_unmap_shift(tlb);
468 }
469 
470 /*
471  * In the case of tlb vma handling, we can optimise these away in the
472  * case where we're doing a full MM flush.  When we're doing a munmap,
473  * the vmas are adjusted to only cover the region to be torn down.
474  */
475 #ifndef tlb_start_vma
tlb_start_vma(struct mmu_gather * tlb,struct vm_area_struct * vma)476 static inline void tlb_start_vma(struct mmu_gather *tlb, struct vm_area_struct *vma)
477 {
478 	if (tlb->fullmm)
479 		return;
480 
481 	tlb_update_vma_flags(tlb, vma);
482 	flush_cache_range(vma, vma->vm_start, vma->vm_end);
483 }
484 #endif
485 
486 #ifndef tlb_end_vma
tlb_end_vma(struct mmu_gather * tlb,struct vm_area_struct * vma)487 static inline void tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vma)
488 {
489 	if (tlb->fullmm)
490 		return;
491 
492 	/*
493 	 * Do a TLB flush and reset the range at VMA boundaries; this avoids
494 	 * the ranges growing with the unused space between consecutive VMAs,
495 	 * but also the mmu_gather::vma_* flags from tlb_start_vma() rely on
496 	 * this.
497 	 */
498 	tlb_flush_mmu_tlbonly(tlb);
499 }
500 #endif
501 
502 /*
503  * tlb_flush_{pte|pmd|pud|p4d}_range() adjust the tlb->start and tlb->end,
504  * and set corresponding cleared_*.
505  */
tlb_flush_pte_range(struct mmu_gather * tlb,unsigned long address,unsigned long size)506 static inline void tlb_flush_pte_range(struct mmu_gather *tlb,
507 				     unsigned long address, unsigned long size)
508 {
509 	__tlb_adjust_range(tlb, address, size);
510 	tlb->cleared_ptes = 1;
511 }
512 
tlb_flush_pmd_range(struct mmu_gather * tlb,unsigned long address,unsigned long size)513 static inline void tlb_flush_pmd_range(struct mmu_gather *tlb,
514 				     unsigned long address, unsigned long size)
515 {
516 	__tlb_adjust_range(tlb, address, size);
517 	tlb->cleared_pmds = 1;
518 }
519 
tlb_flush_pud_range(struct mmu_gather * tlb,unsigned long address,unsigned long size)520 static inline void tlb_flush_pud_range(struct mmu_gather *tlb,
521 				     unsigned long address, unsigned long size)
522 {
523 	__tlb_adjust_range(tlb, address, size);
524 	tlb->cleared_puds = 1;
525 }
526 
tlb_flush_p4d_range(struct mmu_gather * tlb,unsigned long address,unsigned long size)527 static inline void tlb_flush_p4d_range(struct mmu_gather *tlb,
528 				     unsigned long address, unsigned long size)
529 {
530 	__tlb_adjust_range(tlb, address, size);
531 	tlb->cleared_p4ds = 1;
532 }
533 
534 #ifndef __tlb_remove_tlb_entry
535 #define __tlb_remove_tlb_entry(tlb, ptep, address) do { } while (0)
536 #endif
537 
538 /**
539  * tlb_remove_tlb_entry - remember a pte unmapping for later tlb invalidation.
540  *
541  * Record the fact that pte's were really unmapped by updating the range,
542  * so we can later optimise away the tlb invalidate.   This helps when
543  * userspace is unmapping already-unmapped pages, which happens quite a lot.
544  */
545 #define tlb_remove_tlb_entry(tlb, ptep, address)		\
546 	do {							\
547 		tlb_flush_pte_range(tlb, address, PAGE_SIZE);	\
548 		__tlb_remove_tlb_entry(tlb, ptep, address);	\
549 	} while (0)
550 
551 #define tlb_remove_huge_tlb_entry(h, tlb, ptep, address)	\
552 	do {							\
553 		unsigned long _sz = huge_page_size(h);		\
554 		if (_sz >= P4D_SIZE)				\
555 			tlb_flush_p4d_range(tlb, address, _sz);	\
556 		else if (_sz >= PUD_SIZE)			\
557 			tlb_flush_pud_range(tlb, address, _sz);	\
558 		else if (_sz >= PMD_SIZE)			\
559 			tlb_flush_pmd_range(tlb, address, _sz);	\
560 		else						\
561 			tlb_flush_pte_range(tlb, address, _sz);	\
562 		__tlb_remove_tlb_entry(tlb, ptep, address);	\
563 	} while (0)
564 
565 /**
566  * tlb_remove_pmd_tlb_entry - remember a pmd mapping for later tlb invalidation
567  * This is a nop so far, because only x86 needs it.
568  */
569 #ifndef __tlb_remove_pmd_tlb_entry
570 #define __tlb_remove_pmd_tlb_entry(tlb, pmdp, address) do {} while (0)
571 #endif
572 
573 #define tlb_remove_pmd_tlb_entry(tlb, pmdp, address)			\
574 	do {								\
575 		tlb_flush_pmd_range(tlb, address, HPAGE_PMD_SIZE);	\
576 		__tlb_remove_pmd_tlb_entry(tlb, pmdp, address);		\
577 	} while (0)
578 
579 /**
580  * tlb_remove_pud_tlb_entry - remember a pud mapping for later tlb
581  * invalidation. This is a nop so far, because only x86 needs it.
582  */
583 #ifndef __tlb_remove_pud_tlb_entry
584 #define __tlb_remove_pud_tlb_entry(tlb, pudp, address) do {} while (0)
585 #endif
586 
587 #define tlb_remove_pud_tlb_entry(tlb, pudp, address)			\
588 	do {								\
589 		tlb_flush_pud_range(tlb, address, HPAGE_PUD_SIZE);	\
590 		__tlb_remove_pud_tlb_entry(tlb, pudp, address);		\
591 	} while (0)
592 
593 /*
594  * For things like page tables caches (ie caching addresses "inside" the
595  * page tables, like x86 does), for legacy reasons, flushing an
596  * individual page had better flush the page table caches behind it. This
597  * is definitely how x86 works, for example. And if you have an
598  * architected non-legacy page table cache (which I'm not aware of
599  * anybody actually doing), you're going to have some architecturally
600  * explicit flushing for that, likely *separate* from a regular TLB entry
601  * flush, and thus you'd need more than just some range expansion..
602  *
603  * So if we ever find an architecture
604  * that would want something that odd, I think it is up to that
605  * architecture to do its own odd thing, not cause pain for others
606  * http://lkml.kernel.org/r/CA+55aFzBggoXtNXQeng5d_mRoDnaMBE5Y+URs+PHR67nUpMtaw@mail.gmail.com
607  *
608  * For now w.r.t page table cache, mark the range_size as PAGE_SIZE
609  */
610 
611 #ifndef pte_free_tlb
612 #define pte_free_tlb(tlb, ptep, address)			\
613 	do {							\
614 		tlb_flush_pmd_range(tlb, address, PAGE_SIZE);	\
615 		tlb->freed_tables = 1;				\
616 		__pte_free_tlb(tlb, ptep, address);		\
617 	} while (0)
618 #endif
619 
620 #ifndef pmd_free_tlb
621 #define pmd_free_tlb(tlb, pmdp, address)			\
622 	do {							\
623 		tlb_flush_pud_range(tlb, address, PAGE_SIZE);	\
624 		tlb->freed_tables = 1;				\
625 		__pmd_free_tlb(tlb, pmdp, address);		\
626 	} while (0)
627 #endif
628 
629 #ifndef __ARCH_HAS_4LEVEL_HACK
630 #ifndef pud_free_tlb
631 #define pud_free_tlb(tlb, pudp, address)			\
632 	do {							\
633 		tlb_flush_p4d_range(tlb, address, PAGE_SIZE);	\
634 		tlb->freed_tables = 1;				\
635 		__pud_free_tlb(tlb, pudp, address);		\
636 	} while (0)
637 #endif
638 #endif
639 
640 #ifndef __ARCH_HAS_5LEVEL_HACK
641 #ifndef p4d_free_tlb
642 #define p4d_free_tlb(tlb, pudp, address)			\
643 	do {							\
644 		__tlb_adjust_range(tlb, address, PAGE_SIZE);	\
645 		tlb->freed_tables = 1;				\
646 		__p4d_free_tlb(tlb, pudp, address);		\
647 	} while (0)
648 #endif
649 #endif
650 
651 #endif /* CONFIG_MMU */
652 
653 #endif /* _ASM_GENERIC__TLB_H */
654