Skip to contentSkip to conversation

riscv: mm: Fix incorrect ASID argument when flushing TLB

PATCH Superseded Dylan Jhong 2 participants 3 messages Mar 10, 2023 – Mar 13, 2023 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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.

Fixes 3f1e782998cd ("riscv: add ASID-based tlbflushing methods")
---
 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
index 907b9efd39a8..597d6d8aec28 100644
@@ -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
index 80ce9caba8d2..a6b76b33e377 100644
@@ -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
index ce7dfc81bb3f..ba4c27187c95 100644
@@ -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
#1 lore raw
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")
---
 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
index 907b9efd39a8..597d6d8aec28 100644
@@ -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
index 80ce9caba8d2..a6b76b33e377 100644

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 -0
 static atomic_long_t current_version;
 
arch/riscv/mm/tlbflush.c +1 -2
index ce7dfc81bb3f..ba4c27187c95 100644
@@ -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
#2 lore raw
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")
---
 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
index 907b9efd39a8..597d6d8aec28 100644
@@ -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
index 80ce9caba8d2..a6b76b33e377 100644
@@ -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 -1
 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.)

OK. I'll remove EXPORT_SYMBOL in v2.
Thanks.

Quoted 24 lines
Quoted 19 lines
arch/riscv/mm/context.c +0 -0
 static atomic_long_t current_version;
 
arch/riscv/mm/tlbflush.c +1 -2
index ce7dfc81bb3f..ba4c27187c95 100644
@@ -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