From patchwork Mon Mar 13 03:49:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dylan Jhong X-Patchwork-Id: 68630 Return-Path: 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 + 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 ); 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 ; 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 To: , CC: , , , , , , , , , Dylan Jhong 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 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: 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?= 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 Reviewed-by: Sergey Matyukevich --- 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 #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