Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 8fc21cc

Browse files
SiFiveHollandpalmer-dabbelt
authored andcommitted
riscv: mm: Preserve global TLB entries when switching contexts
If the CPU does not support multiple ASIDs, all MM contexts use ASID 0. In this case, it is still beneficial to flush the TLB by ASID, as the single-ASID variant of the sfence.vma instruction preserves TLB entries for global (kernel) pages. This optimization is recommended by the RISC-V privileged specification: If the implementation does not provide ASIDs, or software chooses to always use ASID 0, then after every satp write, software should execute SFENCE.VMA with rs1=x0. In the common case that no global translations have been modified, rs2 should be set to a register other than x0 but which contains the value zero, so that global translations are not flushed. It is not possible to apply this optimization when using the ASID allocator, because that code must flush the TLB for all ASIDs at once when incrementing the version number. Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com> Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Link: https://lore.kernel.org/r/20240327045035.368512-13-samuel.holland@sifive.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 8d3e761 commit 8fc21cc

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

arch/riscv/mm/context.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ static void set_mm_noasid(struct mm_struct *mm)
200200
{
201201
/* Switch the page table and blindly nuke entire local TLB */
202202
csr_write(CSR_SATP, virt_to_pfn(mm->pgd) | satp_mode);
203-
local_flush_tlb_all();
203+
local_flush_tlb_all_asid(0);
204204
}
205205

206206
static inline void set_mm(struct mm_struct *prev,

0 commit comments

Comments
 (0)