riscv: mm: Fix incorrect ASID argument when flushing TLB
PATCH 1/1 riscv: mm: Fix incorrect ASID argument when flushing TLB
Currently, we pass the CONTEXTID instead of the ASID to the TLB flush function. We should only take the ASID field to prevent from touching the reserved bit field.
--- arch/riscv/include/asm/tlbflush.h | 2 ++ arch/riscv/mm/context.c | 3 ++- arch/riscv/mm/tlbflush.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-)
arch/riscv/include/asm/tlbflush.h +2 -0
@@ -12,6 +12,8 @@#include <asm/errata_list.h> #ifdef CONFIG_MMU +extern unsigned long asid_mask; +static inline void local_flush_tlb_all (void ) { __asm__ __volatile__ ("sfence.vma" : : :"memory" );
arch/riscv/mm/context.c +2 -1
@@ -22,7 +22,8 @@ DEFINE_STATIC_KEY_FALSE(use_asid_allocator);static unsigned long asid_bits;static unsigned long num_asids; -static unsigned long asid_mask; +unsigned long asid_mask; +EXPORT_SYMBOL (asid_mask);static atomic_long_t current_version;
arch/riscv/mm/tlbflush.c +1 -1
@@ -27,7 +27,7 @@ static void __sbi_tlb_flush_range(struct mm_struct *mm, unsigned long start,/* check if the tlbflush needs to be sent to other CPUs */ broadcast =cpumask_any_but (cmask, cpuid) < nr_cpu_ids;if (static_branch_unlikely (&use_asid_allocator)) { -unsigned long asid =atomic_long_read (&mm->context.id); +unsigned long asid =atomic_long_read (&mm->context.id) & asid_mask;/* * TLB will be immediately flushed on harts concurrently
Signature · 1 line
2.34.1
Quoted 31 lines · Dylan Jhong
Currently, we pass the CONTEXTID instead of the ASID to the TLB flush function. We should only take the ASID field to prevent from touching the reserved bit field.
Fixes 3f1e782998cd ("riscv: add ASID-based tlbflushing methods")Signed-off-by Dylan Jhong <[email protected]>--- arch/riscv/include/asm/tlbflush.h | 2 ++ arch/riscv/mm/context.c | 3 ++- arch/riscv/mm/tlbflush.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-)arch/riscv/include/asm/tlbflush.h +2
-0@@ -12,6 +12,8 @@#include <asm/errata_list.h> #ifdef CONFIG_MMU +extern unsigned long asid_mask; +static inline void local_flush_tlb_all (void ) { __asm__ __volatile__ ("sfence.vma" : : :"memory" );arch/riscv/mm/context.c +0
-0
arch/riscv/mm/context.c DEFINE_STATIC_KEY_FALSE(use_asid_allocator); · line 26
Quoted 6 lines
arch/riscv/mm/context.c +2
-1@@ -22,7 +22,8 @@ DEFINE_STATIC_KEY_FALSE(use_asid_allocator);static unsigned long asid_bits;static unsigned long num_asids; -static unsigned long asid_mask; +unsigned long asid_mask; +EXPORT_SYMBOL (asid_mask);
Why EXPORT_SYMBOL? (No module would use it by your patch.)
Quoted 19 lines
arch/riscv/mm/context.c +0
-0static atomic_long_t current_version;arch/riscv/mm/tlbflush.c +1
-2@@ -27,7 +27,7 @@ static void __sbi_tlb_flush_range(struct mm_struct *mm, unsigned long start,/* check if the tlbflush needs to be sent to other CPUs */ broadcast =cpumask_any_but (cmask, cpuid) < nr_cpu_ids;if (static_branch_unlikely (&use_asid_allocator)) { -unsigned long asid =atomic_long_read (&mm->context.id); +unsigned long asid =atomic_long_read (&mm->context.id) & asid_mask;/* * TLB will be immediately flushed on harts concurrently -- 2.34.1
Signature · 2 lines
Best Regards Guo Ren
Quoted 33 lines · Guo Ren
Quoted 32 lines · Dylan Jhong
Currently, we pass the CONTEXTID instead of the ASID to the TLB flush function. We should only take the ASID field to prevent from touching the reserved bit field.
Fixes 3f1e782998cd ("riscv: add ASID-based tlbflushing methods")Signed-off-by Dylan Jhong <[email protected]>--- arch/riscv/include/asm/tlbflush.h | 2 ++ arch/riscv/mm/context.c | 3 ++- arch/riscv/mm/tlbflush.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-)arch/riscv/include/asm/tlbflush.h +2
-0@@ -12,6 +12,8 @@#include <asm/errata_list.h> #ifdef CONFIG_MMU +extern unsigned long asid_mask; +static inline void local_flush_tlb_all (void ) { __asm__ __volatile__ ("sfence.vma" : : :"memory" );arch/riscv/mm/context.c +0
-0@@ -22,7 +22,8 @@ DEFINE_STATIC_KEY_FALSE(use_asid_allocator);
Quoted 7 lines
arch/riscv/mm/context.c DEFINE_STATIC_KEY_FALSE(use_asid_allocator); · line 26
Quoted 5 lines
arch/riscv/mm/context.c +2
-1static unsigned long asid_bits;static unsigned long num_asids; -static unsigned long asid_mask; +unsigned long asid_mask; +EXPORT_SYMBOL (asid_mask);Why
EXPORT_SYMBOL? (No module would use it by your patch.)
OK. I'll remove EXPORT_SYMBOL in v2.
Thanks.
Quoted 24 lines
Quoted 19 lines
arch/riscv/mm/context.c +0
-0static atomic_long_t current_version;arch/riscv/mm/tlbflush.c +1
-2@@ -27,7 +27,7 @@ static void __sbi_tlb_flush_range(struct mm_struct *mm, unsigned long start,/* check if the tlbflush needs to be sent to other CPUs */ broadcast =cpumask_any_but (cmask, cpuid) < nr_cpu_ids;if (static_branch_unlikely (&use_asid_allocator)) { -unsigned long asid =atomic_long_read (&mm->context.id); +unsigned long asid =atomic_long_read (&mm->context.id) & asid_mask;/* * TLB will be immediately flushed on harts concurrently -- 2.34.1
Signature · 2 lines
Best Regards Guo Ren