Skip to content

Commit a30e32b

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
asm-generic/tlb: Provide generic tlb_flush() based on flush_tlb_mm()
When an architecture does not have (an efficient) flush_tlb_range(), but instead always uses full TLB invalidates, the current generic tlb_flush() is sub-optimal, for it will generate extra flushes in order to keep the range small. But if we cannot do range flushes, that is a moot concern. Optionally provide this simplified default. No change in behavior intended. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Will Deacon <will.deacon@arm.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rik van Riel <riel@surriel.com> Cc: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 5f307be commit a30e32b

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

include/asm-generic/tlb.h

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@
114114
* returns the smallest TLB entry size unmapped in this range.
115115
*
116116
* If an architecture does not provide tlb_flush() a default implementation
117-
* based on flush_tlb_range() will be used.
117+
* based on flush_tlb_range() will be used, unless MMU_GATHER_NO_RANGE is
118+
* specified, in which case we'll default to flush_tlb_mm().
118119
*
119120
* Additionally there are a few opt-in features:
120121
*
@@ -140,6 +141,9 @@
140141
* the page-table pages. Required if you use HAVE_RCU_TABLE_FREE and your
141142
* architecture uses the Linux page-tables natively.
142143
*
144+
* MMU_GATHER_NO_RANGE
145+
*
146+
* Use this if your architecture lacks an efficient flush_tlb_range().
143147
*/
144148
#define HAVE_GENERIC_MMU_GATHER
145149

@@ -302,12 +306,45 @@ static inline void __tlb_reset_range(struct mmu_gather *tlb)
302306
*/
303307
}
304308

309+
#ifdef CONFIG_MMU_GATHER_NO_RANGE
310+
311+
#if defined(tlb_flush) || defined(tlb_start_vma) || defined(tlb_end_vma)
312+
#error MMU_GATHER_NO_RANGE relies on default tlb_flush(), tlb_start_vma() and tlb_end_vma()
313+
#endif
314+
315+
/*
316+
* When an architecture does not have efficient means of range flushing TLBs
317+
* there is no point in doing intermediate flushes on tlb_end_vma() to keep the
318+
* range small. We equally don't have to worry about page granularity or other
319+
* things.
320+
*
321+
* All we need to do is issue a full flush for any !0 range.
322+
*/
323+
static inline void tlb_flush(struct mmu_gather *tlb)
324+
{
325+
if (tlb->end)
326+
flush_tlb_mm(tlb->mm);
327+
}
328+
329+
static inline void
330+
tlb_update_vma_flags(struct mmu_gather *tlb, struct vm_area_struct *vma) { }
331+
332+
#define tlb_end_vma tlb_end_vma
333+
static inline void tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vma) { }
334+
335+
#else /* CONFIG_MMU_GATHER_NO_RANGE */
336+
305337
#ifndef tlb_flush
306338

307339
#if defined(tlb_start_vma) || defined(tlb_end_vma)
308340
#error Default tlb_flush() relies on default tlb_start_vma() and tlb_end_vma()
309341
#endif
310342

343+
/*
344+
* When an architecture does not provide its own tlb_flush() implementation
345+
* but does have a reasonably efficient flush_vma_range() implementation
346+
* use that.
347+
*/
311348
static inline void tlb_flush(struct mmu_gather *tlb)
312349
{
313350
if (tlb->fullmm || tlb->need_flush_all) {
@@ -348,6 +385,8 @@ tlb_update_vma_flags(struct mmu_gather *tlb, struct vm_area_struct *vma) { }
348385

349386
#endif
350387

388+
#endif /* CONFIG_MMU_GATHER_NO_RANGE */
389+
351390
static inline void tlb_flush_mmu_tlbonly(struct mmu_gather *tlb)
352391
{
353392
if (!tlb->end)

0 commit comments

Comments
 (0)