Skip to content

Commit e8cad25

Browse files
Merge branch 'next/tlb-opt' into for-next
2 parents 9acfd6f + 6efb16b commit e8cad25

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

arch/riscv/mm/tlbflush.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,41 @@
22

33
#include <linux/mm.h>
44
#include <linux/smp.h>
5+
#include <linux/sched.h>
56
#include <asm/sbi.h>
67

78
void flush_tlb_all(void)
89
{
910
sbi_remote_sfence_vma(NULL, 0, -1);
1011
}
1112

13+
/*
14+
* This function must not be called with cmask being null.
15+
* Kernel may panic if cmask is NULL.
16+
*/
1217
static void __sbi_tlb_flush_range(struct cpumask *cmask, unsigned long start,
1318
unsigned long size)
1419
{
1520
struct cpumask hmask;
21+
unsigned int cpuid;
1622

17-
riscv_cpuid_to_hartid_mask(cmask, &hmask);
18-
sbi_remote_sfence_vma(hmask.bits, start, size);
23+
if (cpumask_empty(cmask))
24+
return;
25+
26+
cpuid = get_cpu();
27+
28+
if (cpumask_any_but(cmask, cpuid) >= nr_cpu_ids) {
29+
/* local cpu is the only cpu present in cpumask */
30+
if (size <= PAGE_SIZE)
31+
local_flush_tlb_page(start);
32+
else
33+
local_flush_tlb_all();
34+
} else {
35+
riscv_cpuid_to_hartid_mask(cmask, &hmask);
36+
sbi_remote_sfence_vma(cpumask_bits(&hmask), start, size);
37+
}
38+
39+
put_cpu();
1940
}
2041

2142
void flush_tlb_mm(struct mm_struct *mm)

0 commit comments

Comments
 (0)