Skip to content

Commit 114d5c8

Browse files
Alexandre Ghitipalmer-dabbelt
authored andcommitted
riscv: Improve tlb_flush()
For now, tlb_flush() simply calls flush_tlb_mm() which results in a flush of the whole TLB. So let's use mmu_gather fields to provide a more fine-grained flush of the TLB. Signed-off-by: Alexandre Ghiti <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Samuel Holland <[email protected]> Tested-by: Lad Prabhakar <[email protected]> # On RZ/Five SMARC Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 0bb80ec commit 114d5c8

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

arch/riscv/include/asm/tlb.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ static void tlb_flush(struct mmu_gather *tlb);
1515

1616
static inline void tlb_flush(struct mmu_gather *tlb)
1717
{
18-
flush_tlb_mm(tlb->mm);
18+
#ifdef CONFIG_MMU
19+
if (tlb->fullmm || tlb->need_flush_all)
20+
flush_tlb_mm(tlb->mm);
21+
else
22+
flush_tlb_mm_range(tlb->mm, tlb->start, tlb->end,
23+
tlb_get_unmap_size(tlb));
24+
#endif
1925
}
2026

2127
#endif /* _ASM_RISCV_TLB_H */

arch/riscv/include/asm/tlbflush.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ static inline void local_flush_tlb_page(unsigned long addr)
3232
#if defined(CONFIG_SMP) && defined(CONFIG_MMU)
3333
void flush_tlb_all(void);
3434
void flush_tlb_mm(struct mm_struct *mm);
35+
void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start,
36+
unsigned long end, unsigned int page_size);
3537
void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr);
3638
void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
3739
unsigned long end);
@@ -52,6 +54,7 @@ static inline void flush_tlb_range(struct vm_area_struct *vma,
5254
}
5355

5456
#define flush_tlb_mm(mm) flush_tlb_all()
57+
#define flush_tlb_mm_range(mm, start, end, page_size) flush_tlb_all()
5558
#endif /* !CONFIG_SMP || !CONFIG_MMU */
5659

5760
/* Flush a range of kernel pages */

arch/riscv/mm/tlbflush.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ void flush_tlb_mm(struct mm_struct *mm)
132132
__flush_tlb_range(mm, 0, -1, PAGE_SIZE);
133133
}
134134

135+
void flush_tlb_mm_range(struct mm_struct *mm,
136+
unsigned long start, unsigned long end,
137+
unsigned int page_size)
138+
{
139+
__flush_tlb_range(mm, start, end - start, page_size);
140+
}
141+
135142
void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)
136143
{
137144
__flush_tlb_range(vma->vm_mm, addr, PAGE_SIZE, PAGE_SIZE);

0 commit comments

Comments
 (0)