Message ID | 20230313034906.2401730-1-dylan@andestech.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp993562wrd; Sun, 12 Mar 2023 21:08:55 -0700 (PDT) X-Google-Smtp-Source: AK7set9YBjMd+o6eXabQeV0oFUknxrbais5nXqiggRYL3PJzzIwrkFkBN2F9Es7gOHPk2s5Trouc X-Received: by 2002:a17:90b:3810:b0:237:62f7:3106 with SMTP id mq16-20020a17090b381000b0023762f73106mr35136959pjb.17.1678680535668; Sun, 12 Mar 2023 21:08:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678680535; cv=none; d=google.com; s=arc-20160816; b=FY9km1lF2phod1pEzQhQMxpOiyIKCXUbkv70ioz36Id1hjn322GOXnL/lq4wc8bD1U //35tPDTVBKfZbpO9CM15pViWMjKEuEao0JPM6YO6zLFkA28iKs/GKkpmvrahudbaE+f rmejz1fJDSFvAhLvAmc8bzwVhmbvbzeQ1fT5pfRwNQNeDg6W4+0ggIK0ZJ4Vyz0GmUAF HyxuiVoNV6lwjl/yyLIPvwPAXaJP1FGrYDxjEPSzdz7Iwfltqpr4kMlij0jk61qZnCbz FXskhzm5WNLHzh+YctUl93TtMeutcs31vEqXjlqV07EmDZ9FlFiFswkzkyuYOXGT83Ic fCgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=cBNyAYz+2kYfo9ffCO/VMI3Ucn6lIXvyH/ghMpMVuI4=; b=d/c2zL9dDJWhNX2bYElracrjZcmf2SbYrwi/5bVJQ9QuHPe4D8Cmm8r96ZITu+Njr3 6ZOSGUlFQVbzhquOoSytZqw6ByorTSj9zCVdYLCU0D/6J+XdZ4ah1KLNEI0VWJ/S7F7M 2PIZBjV74kBiflU0tF9NufJFVf1VjX2YV6Eus77Secxe2zt5XO2bEGGKjZJI+zPRQJDk rxRbBOyusZh9u8Y3KTas8LD3sZQ8s6ssuz0XPki+PxfpEIKj8i7j/03fQGc3SB0T64nF Lx4uGcY44m5R9cUvQvMM8Fe2fSPvuKXJXlQhCKe0CxVqXyHBWCql0jaRFejHviQORvew yrtw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ca2-20020a17090af30200b0022c9cb7662csi5631201pjb.159.2023.03.12.21.08.41; Sun, 12 Mar 2023 21:08:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230237AbjCMDwA (ORCPT <rfc822;realc9580@gmail.com> + 99 others); Sun, 12 Mar 2023 23:52:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230224AbjCMDv3 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 12 Mar 2023 23:51:29 -0400 Received: from Atcsqr.andestech.com (60-248-80-70.hinet-ip.hinet.net [60.248.80.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 515892311A for <linux-kernel@vger.kernel.org>; Sun, 12 Mar 2023 20:50:09 -0700 (PDT) Received: from mail.andestech.com (ATCPCS16.andestech.com [10.0.1.222]) by Atcsqr.andestech.com with ESMTP id 32D3nEa1053318; Mon, 13 Mar 2023 11:49:14 +0800 (+08) (envelope-from dylan@andestech.com) Received: from atctrx.andestech.com (10.0.15.173) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.498.0; Mon, 13 Mar 2023 11:49:15 +0800 From: Dylan Jhong <dylan@andestech.com> To: <linux-kernel@vger.kernel.org>, <linux-riscv@lists.infradead.org> CC: <guoren@kernel.org>, <sergey.matyukevich@syntacore.com>, <aou@eecs.berkeley.edu>, <palmer@dabbelt.com>, <paul.walmsley@sifive.com>, <x5710999x@gmail.com>, <tim609@andestech.com>, <peterlin@andestech.com>, <ycliang@andestech.com>, Dylan Jhong <dylan@andestech.com> Subject: [PATCH v2] riscv: mm: Fix incorrect ASID argument when flushing TLB Date: Mon, 13 Mar 2023 11:49:06 +0800 Message-ID: <20230313034906.2401730-1-dylan@andestech.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.0.15.173] X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 32D3nEa1053318 X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,PDS_RDNS_DYNAMIC_FP, RDNS_DYNAMIC,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759976561437112213?= X-GMAIL-MSGID: =?utf-8?q?1760224121456425236?= |
Series |
[v2] riscv: mm: Fix incorrect ASID argument when flushing TLB
|
|
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
> 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 !
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 >
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 > >
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 > > >
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 >> > >
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 >>> > >
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 --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