diff mbox series

[v2] riscv: mm: Fix incorrect ASID argument when flushing TLB

Message ID 20230313034906.2401730-1-dylan@andestech.com (mailing list archive)
State Accepted
Commit 9a801afd3eb95e1a89aba17321062df06fb49d98
Headers show
Series [v2] riscv: mm: Fix incorrect ASID argument when flushing TLB | expand

Checks

Context Check Description
conchuod/cover_letter success Single patches do not need cover letters
conchuod/tree_selection success Guessed tree name to be for-next
conchuod/fixes_present success Fixes tag not required for -next series
conchuod/maintainers_pattern success MAINTAINERS pattern errors before the patch: 1 and now 1
conchuod/verify_signedoff success Signed-off-by tag matches author and committer
conchuod/kdoc success Errors and warnings before: 0 this patch: 0
conchuod/build_rv64_clang_allmodconfig success Errors and warnings before: 2275 this patch: 2275
conchuod/module_param success Was 0 now: 0
conchuod/build_rv64_gcc_allmodconfig success Errors and warnings before: 17609 this patch: 17609
conchuod/alphanumeric_selects success Out of order selects before the patch: 728 and now 728
conchuod/build_rv32_defconfig success Build OK
conchuod/dtb_warn_rv64 success Errors and warnings before: 3 this patch: 3
conchuod/header_inline success No static functions without inline keyword in header files
conchuod/checkpatch success total: 0 errors, 0 warnings, 0 checks, 24 lines checked
conchuod/source_inline success Was 0 now: 0
conchuod/build_rv64_nommu_k210_defconfig success Build OK
conchuod/verify_fixes success Fixes tag looks correct
conchuod/build_rv64_nommu_virt_defconfig success Build OK

Commit Message

Dylan Jhong March 13, 2023, 3:49 a.m. UTC
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 <dylan@andestech.com>
---
Changes from v2:
- Remove unsued EXPORT_SYMBOL()
---
 arch/riscv/include/asm/tlbflush.h | 2 ++
 arch/riscv/mm/context.c           | 2 +-
 arch/riscv/mm/tlbflush.c          | 2 +-
 3 files changed, 4 insertions(+), 2 deletions(-)

Comments

Sergey Matyukevich March 13, 2023, 5:58 a.m. UTC | #1
> 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 <dylan@andestech.com>
> ---
> Changes from v2:
> - Remove unsued EXPORT_SYMBOL()
> ---
>  arch/riscv/include/asm/tlbflush.h | 2 ++
>  arch/riscv/mm/context.c           | 2 +-
>  arch/riscv/mm/tlbflush.c          | 2 +-
>  3 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/riscv/include/asm/tlbflush.h b/arch/riscv/include/asm/tlbflush.h
> index 907b9efd39a8..597d6d8aec28 100644
> --- a/arch/riscv/include/asm/tlbflush.h
> +++ b/arch/riscv/include/asm/tlbflush.h
> @@ -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");
> diff --git a/arch/riscv/mm/context.c b/arch/riscv/mm/context.c
> index 80ce9caba8d2..6d1aeb063e81 100644
> --- a/arch/riscv/mm/context.c
> +++ b/arch/riscv/mm/context.c
> @@ -22,7 +22,7 @@ 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;
>  
>  static atomic_long_t current_version;
>  
> diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c
> index ce7dfc81bb3f..ba4c27187c95 100644
> --- a/arch/riscv/mm/tlbflush.c
> +++ b/arch/riscv/mm/tlbflush.c
> @@ -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

Reviewed-by: Sergey Matyukevich <sergey.matyukevich@syntacore.com>

Thanks !
Zong Li March 14, 2023, 2:22 a.m. UTC | #2
Dylan Jhong <dylan@andestech.com> 於 2023年3月13日 週一 下午12:29寫道:
>
> 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 <dylan@andestech.com>
> ---

Hi Dylan,
Thanks for your patch, if I remember correctly, there was a patch from
Alistair Francis did the similar fix. Perhaps we should track that
patch to see why it doesn't be merged. Thanks.

http://lists.infradead.org/pipermail/linux-riscv/2022-March/013558.html

> Changes from v2:
> - Remove unsued EXPORT_SYMBOL()
> ---
>  arch/riscv/include/asm/tlbflush.h | 2 ++
>  arch/riscv/mm/context.c           | 2 +-
>  arch/riscv/mm/tlbflush.c          | 2 +-
>  3 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/arch/riscv/include/asm/tlbflush.h b/arch/riscv/include/asm/tlbflush.h
> index 907b9efd39a8..597d6d8aec28 100644
> --- a/arch/riscv/include/asm/tlbflush.h
> +++ b/arch/riscv/include/asm/tlbflush.h
> @@ -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");
> diff --git a/arch/riscv/mm/context.c b/arch/riscv/mm/context.c
> index 80ce9caba8d2..6d1aeb063e81 100644
> --- a/arch/riscv/mm/context.c
> +++ b/arch/riscv/mm/context.c
> @@ -22,7 +22,7 @@ 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;
>
>  static atomic_long_t current_version;
>
> diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c
> index ce7dfc81bb3f..ba4c27187c95 100644
> --- a/arch/riscv/mm/tlbflush.c
> +++ b/arch/riscv/mm/tlbflush.c
> @@ -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
>
Dylan Jhong March 14, 2023, 7:27 a.m. UTC | #3
On Tue, Mar 14, 2023 at 10:22:43AM +0800, Zong Li wrote:
> Dylan Jhong <dylan@andestech.com> 於 2023年3月13日 週一 下午12:29寫道:
> >
> > 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 <dylan@andestech.com>
> > ---
> 
> Hi Dylan,
> Thanks for your patch, if I remember correctly, there was a patch from
> Alistair Francis did the similar fix. Perhaps we should track that
> patch to see why it doesn't be merged. Thanks.
> 
> http://lists.infradead.org/pipermail/linux-riscv/2022-March/013558.html
>
Hi Zong,
Thanks for the reminder, I didn't notice that Alistair had sent the same patch before.

Hi Palmer, Alistair
http://lists.infradead.org/pipermail/linux-riscv/2022-March/013597.html
This patch does not seem to be cherry-picked back to the released linux kernel,
and I have not seen the v4 patch. May I ask how is the follow-up progress of this patch?

Best,
Dylan

> > Changes from v2:
> > - Remove unsued EXPORT_SYMBOL()
> > ---
> >  arch/riscv/include/asm/tlbflush.h | 2 ++
> >  arch/riscv/mm/context.c           | 2 +-
> >  arch/riscv/mm/tlbflush.c          | 2 +-
> >  3 files changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/riscv/include/asm/tlbflush.h b/arch/riscv/include/asm/tlbflush.h
> > index 907b9efd39a8..597d6d8aec28 100644
> > --- a/arch/riscv/include/asm/tlbflush.h
> > +++ b/arch/riscv/include/asm/tlbflush.h
> > @@ -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");
> > diff --git a/arch/riscv/mm/context.c b/arch/riscv/mm/context.c
> > index 80ce9caba8d2..6d1aeb063e81 100644
> > --- a/arch/riscv/mm/context.c
> > +++ b/arch/riscv/mm/context.c
> > @@ -22,7 +22,7 @@ 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;
> >
> >  static atomic_long_t current_version;
> >
> > diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c
> > index ce7dfc81bb3f..ba4c27187c95 100644
> > --- a/arch/riscv/mm/tlbflush.c
> > +++ b/arch/riscv/mm/tlbflush.c
> > @@ -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
> >
Dylan Jhong March 21, 2023, 2:42 a.m. UTC | #4
On Tue, Mar 14, 2023 at 03:27:30PM +0800, Dylan Jhong wrote:
> On Tue, Mar 14, 2023 at 10:22:43AM +0800, Zong Li wrote:
> > Dylan Jhong <dylan@andestech.com> 於 2023年3月13日 週一 下午12:29寫道:
> > >
> > > 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 <dylan@andestech.com>
> > > ---
> > 
> > Hi Dylan,
> > Thanks for your patch, if I remember correctly, there was a patch from
> > Alistair Francis did the similar fix. Perhaps we should track that
> > patch to see why it doesn't be merged. Thanks.
> > 
> > http://lists.infradead.org/pipermail/linux-riscv/2022-March/013558.html
> >
> Hi Zong,
> Thanks for the reminder, I didn't notice that Alistair had sent the same patch before.
> 
> Hi Palmer, Alistair
> http://lists.infradead.org/pipermail/linux-riscv/2022-March/013597.html
> This patch does not seem to be cherry-picked back to the released linux kernel,
> and I have not seen the v4 patch. May I ask how is the follow-up progress of this patch?
> 
> Best,
> Dylan
>

Hi Palmer,

Ping. Any update on this?

Best,
Dylan

> > > Changes from v2:
> > > - Remove unsued EXPORT_SYMBOL()
> > > ---
> > >  arch/riscv/include/asm/tlbflush.h | 2 ++
> > >  arch/riscv/mm/context.c           | 2 +-
> > >  arch/riscv/mm/tlbflush.c          | 2 +-
> > >  3 files changed, 4 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/arch/riscv/include/asm/tlbflush.h b/arch/riscv/include/asm/tlbflush.h
> > > index 907b9efd39a8..597d6d8aec28 100644
> > > --- a/arch/riscv/include/asm/tlbflush.h
> > > +++ b/arch/riscv/include/asm/tlbflush.h
> > > @@ -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");
> > > diff --git a/arch/riscv/mm/context.c b/arch/riscv/mm/context.c
> > > index 80ce9caba8d2..6d1aeb063e81 100644
> > > --- a/arch/riscv/mm/context.c
> > > +++ b/arch/riscv/mm/context.c
> > > @@ -22,7 +22,7 @@ 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;
> > >
> > >  static atomic_long_t current_version;
> > >
> > > diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c
> > > index ce7dfc81bb3f..ba4c27187c95 100644
> > > --- a/arch/riscv/mm/tlbflush.c
> > > +++ b/arch/riscv/mm/tlbflush.c
> > > @@ -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
> > >
Palmer Dabbelt March 22, 2023, 5:45 a.m. UTC | #5
On Mon, 20 Mar 2023 19:42:37 PDT (-0700), dylan@andestech.com wrote:
> On Tue, Mar 14, 2023 at 03:27:30PM +0800, Dylan Jhong wrote:
>> On Tue, Mar 14, 2023 at 10:22:43AM +0800, Zong Li wrote:
>> > Dylan Jhong <dylan@andestech.com> 於 2023年3月13日 週一 下午12:29寫道:
>> > >
>> > > 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 <dylan@andestech.com>
>> > > ---
>> >
>> > Hi Dylan,
>> > Thanks for your patch, if I remember correctly, there was a patch from
>> > Alistair Francis did the similar fix. Perhaps we should track that
>> > patch to see why it doesn't be merged. Thanks.
>> >
>> > http://lists.infradead.org/pipermail/linux-riscv/2022-March/013558.html
>> >
>> Hi Zong,
>> Thanks for the reminder, I didn't notice that Alistair had sent the same patch before.
>>
>> Hi Palmer, Alistair
>> http://lists.infradead.org/pipermail/linux-riscv/2022-March/013597.html
>> This patch does not seem to be cherry-picked back to the released linux kernel,
>> and I have not seen the v4 patch. May I ask how is the follow-up progress of this patch?

Sorry about that, I guess I left it kind of vague as to who was doing 
what.  It looks like we've ended up with enough includes that v3 
actually builds now, it's queued up and should end up in fixes tomorrow 
morning.

Thanks!

>>
>> Best,
>> Dylan
>>
>
> Hi Palmer,
>
> Ping. Any update on this?
>
> Best,
> Dylan
>
>> > > Changes from v2:
>> > > - Remove unsued EXPORT_SYMBOL()
>> > > ---
>> > >  arch/riscv/include/asm/tlbflush.h | 2 ++
>> > >  arch/riscv/mm/context.c           | 2 +-
>> > >  arch/riscv/mm/tlbflush.c          | 2 +-
>> > >  3 files changed, 4 insertions(+), 2 deletions(-)
>> > >
>> > > diff --git a/arch/riscv/include/asm/tlbflush.h b/arch/riscv/include/asm/tlbflush.h
>> > > index 907b9efd39a8..597d6d8aec28 100644
>> > > --- a/arch/riscv/include/asm/tlbflush.h
>> > > +++ b/arch/riscv/include/asm/tlbflush.h
>> > > @@ -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");
>> > > diff --git a/arch/riscv/mm/context.c b/arch/riscv/mm/context.c
>> > > index 80ce9caba8d2..6d1aeb063e81 100644
>> > > --- a/arch/riscv/mm/context.c
>> > > +++ b/arch/riscv/mm/context.c
>> > > @@ -22,7 +22,7 @@ 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;
>> > >
>> > >  static atomic_long_t current_version;
>> > >
>> > > diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c
>> > > index ce7dfc81bb3f..ba4c27187c95 100644
>> > > --- a/arch/riscv/mm/tlbflush.c
>> > > +++ b/arch/riscv/mm/tlbflush.c
>> > > @@ -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
>> > >
Palmer Dabbelt March 23, 2023, 8:47 p.m. UTC | #6
On Tue, 21 Mar 2023 22:45:17 PDT (-0700), Palmer Dabbelt wrote:
> On Mon, 20 Mar 2023 19:42:37 PDT (-0700), dylan@andestech.com wrote:
>> On Tue, Mar 14, 2023 at 03:27:30PM +0800, Dylan Jhong wrote:
>>> On Tue, Mar 14, 2023 at 10:22:43AM +0800, Zong Li wrote:
>>> > Dylan Jhong <dylan@andestech.com> 於 2023年3月13日 週一 下午12:29寫道:
>>> > >
>>> > > 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 <dylan@andestech.com>
>>> > > ---
>>> >
>>> > Hi Dylan,
>>> > Thanks for your patch, if I remember correctly, there was a patch from
>>> > Alistair Francis did the similar fix. Perhaps we should track that
>>> > patch to see why it doesn't be merged. Thanks.
>>> >
>>> > http://lists.infradead.org/pipermail/linux-riscv/2022-March/013558.html
>>> >
>>> Hi Zong,
>>> Thanks for the reminder, I didn't notice that Alistair had sent the same patch before.
>>>
>>> Hi Palmer, Alistair
>>> http://lists.infradead.org/pipermail/linux-riscv/2022-March/013597.html
>>> This patch does not seem to be cherry-picked back to the released linux kernel,
>>> and I have not seen the v4 patch. May I ask how is the follow-up progress of this patch?
>
> Sorry about that, I guess I left it kind of vague as to who was doing
> what.  It looks like we've ended up with enough includes that v3
> actually builds now, it's queued up and should end up in fixes tomorrow
> morning.

Turns out that one still fails some configs, and the one posted here 
doesn't.   So I've got the new one on fixes.

Thanks!

>
> Thanks!
>
>>>
>>> Best,
>>> Dylan
>>>
>>
>> Hi Palmer,
>>
>> Ping. Any update on this?
>>
>> Best,
>> Dylan
>>
>>> > > Changes from v2:
>>> > > - Remove unsued EXPORT_SYMBOL()
>>> > > ---
>>> > >  arch/riscv/include/asm/tlbflush.h | 2 ++
>>> > >  arch/riscv/mm/context.c           | 2 +-
>>> > >  arch/riscv/mm/tlbflush.c          | 2 +-
>>> > >  3 files changed, 4 insertions(+), 2 deletions(-)
>>> > >
>>> > > diff --git a/arch/riscv/include/asm/tlbflush.h b/arch/riscv/include/asm/tlbflush.h
>>> > > index 907b9efd39a8..597d6d8aec28 100644
>>> > > --- a/arch/riscv/include/asm/tlbflush.h
>>> > > +++ b/arch/riscv/include/asm/tlbflush.h
>>> > > @@ -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");
>>> > > diff --git a/arch/riscv/mm/context.c b/arch/riscv/mm/context.c
>>> > > index 80ce9caba8d2..6d1aeb063e81 100644
>>> > > --- a/arch/riscv/mm/context.c
>>> > > +++ b/arch/riscv/mm/context.c
>>> > > @@ -22,7 +22,7 @@ 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;
>>> > >
>>> > >  static atomic_long_t current_version;
>>> > >
>>> > > diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c
>>> > > index ce7dfc81bb3f..ba4c27187c95 100644
>>> > > --- a/arch/riscv/mm/tlbflush.c
>>> > > +++ b/arch/riscv/mm/tlbflush.c
>>> > > @@ -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
>>> > >
patchwork-bot+linux-riscv@kernel.org March 23, 2023, 9 p.m. UTC | #7
Hello:

This patch was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <palmer@rivosinc.com>:

On Mon, 13 Mar 2023 11:49:06 +0800 you wrote:
> 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 <dylan@andestech.com>
> 
> [...]

Here is the summary with links:
  - [v2] riscv: mm: Fix incorrect ASID argument when flushing TLB
    https://git.kernel.org/riscv/c/9a801afd3eb9

You are awesome, thank you!
diff mbox series

Patch

diff --git a/arch/riscv/include/asm/tlbflush.h b/arch/riscv/include/asm/tlbflush.h
index 907b9efd39a8..597d6d8aec28 100644
--- a/arch/riscv/include/asm/tlbflush.h
+++ b/arch/riscv/include/asm/tlbflush.h
@@ -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");
diff --git a/arch/riscv/mm/context.c b/arch/riscv/mm/context.c
index 80ce9caba8d2..6d1aeb063e81 100644
--- a/arch/riscv/mm/context.c
+++ b/arch/riscv/mm/context.c
@@ -22,7 +22,7 @@  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;
 
 static atomic_long_t current_version;
 
diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c
index ce7dfc81bb3f..ba4c27187c95 100644
--- a/arch/riscv/mm/tlbflush.c
+++ b/arch/riscv/mm/tlbflush.c
@@ -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