From patchwork Fri Mar 10 10:31:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dylan Jhong X-Patchwork-Id: 67341 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp793041wrd; Fri, 10 Mar 2023 02:34:04 -0800 (PST) X-Google-Smtp-Source: AK7set99T5KDBqRIPnAqWZFkNfbSEZX/l9AP67wtgGKueSG+4v+E6vEWWYA3We++kuiPjuAuP/al X-Received: by 2002:a17:903:11c9:b0:19e:e39b:6da2 with SMTP id q9-20020a17090311c900b0019ee39b6da2mr11746619plh.29.1678444444032; Fri, 10 Mar 2023 02:34:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678444444; cv=none; d=google.com; s=arc-20160816; b=wMCryBHwbszvVCrCAvTblHvNlNuFGsWF+hkHpRpN5EaJiGN47HUh2N0n0vCf+Plfho DakiRdgwx5si0Hwq8z6khXiafCGLTY58+Skp/h6JncSQAOXtGV9iIz4cjnktg37KAmO0 hmd05zwnBWSSrnDmJyWZ1QtF4sDgGXxeiRxuLbZJ8tTHTevcEISDzejkvryJHuE8fkgG SePRGNHC7fOF7zC67oBS8arr6IwQDnU3ljJimf7Qd3vy/rPAxyRWGsx8+QtjJZzZ0Sjj ZwZOu/Na0hno7B5RLDyRZ7ggHHNuMMfo1+cw/8uz7r2uSIpNJGSHXgrbz8+umHxAAJj1 gEFA== 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=d30iAe9nvqPCaIAa+tLieB83AyGPMs9O4fPdSb65fZg=; b=qvdX5UU+6drdE/oGLpwLuLAtMsoCxGvFMsdXufh4/8bPBmEaPgLbsgZItfYN6m1Zms cC1TjIhQumNUwqov4w7ehLuhRrMonM2Pt5m//9PMUYRFiqJLfWIhIkW3+q4qfaClupsZ LsAJ6se25XiW0LYeSe/SLFpTmAqvBskXVRLeeDe7H4DBjDJ9WonNA9UyR+vRg7SShWTz XiCR269HGIVdigH57DFuyIUq8vIftmV5AqlDU4/wqq1g72p7SrkRMCGOfSA8GmPCWRGX uZtcb2NB8vXu3+yqoyw4GskHMwMovJaRqfAuibaOPjioU5KUXb2BZKFf6uOS2zTxVLth clDQ== 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 kh6-20020a170903064600b0017ae43612d9si1761019plb.324.2023.03.10.02.33.50; Fri, 10 Mar 2023 02:34:04 -0800 (PST) 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 S231208AbjCJKcU (ORCPT + 99 others); Fri, 10 Mar 2023 05:32:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229612AbjCJKcN (ORCPT ); Fri, 10 Mar 2023 05:32:13 -0500 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 278B3D33E for ; Fri, 10 Mar 2023 02:32:09 -0800 (PST) Received: from mail.andestech.com (ATCPCS16.andestech.com [10.0.1.222]) by Atcsqr.andestech.com with ESMTP id 32AAVxRf040881; Fri, 10 Mar 2023 18:32:01 +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; Fri, 10 Mar 2023 18:32:01 +0800 From: Dylan Jhong To: , CC: , , , , , , , , , Dylan Jhong Subject: [PATCH] riscv: mm: Fix incorrect ASID argument when flushing TLB Date: Fri, 10 Mar 2023 18:31:44 +0800 Message-ID: <20230310103144.396214-1-dylan@andestech.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.0.15.173] X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 32AAVxRf040881 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: 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?1759976561437112213?= 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 --- 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(-) 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 #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..a6b76b33e377 100644 --- a/arch/riscv/mm/context.c +++ b/arch/riscv/mm/context.c @@ -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; 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