From patchwork Tue Jul 11 07:54:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 118312 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp321202vqm; Tue, 11 Jul 2023 01:19:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlGi6H8ee6d3KOe7LWslI0js82Wd2Nd5YJTZRgc62u65eUaPR24ik/68Ui42P5ygyeXE8ewH X-Received: by 2002:a17:907:9722:b0:97e:32e:c1e with SMTP id jg34-20020a170907972200b0097e032e0c1emr19695175ejc.55.1689063586825; Tue, 11 Jul 2023 01:19:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689063586; cv=none; d=google.com; s=arc-20160816; b=f+3NmdK6z4wuEn6cfXtnL3lXBQMfSjA1zmNOh5MWru1SWSHa++gxeUjqLUHCqfDdlv j1rQPgojo2R32wQGB2ZJWTe0diuirF6hiQ00ySx6GN8k5sosREO4OuBuPeWfZv6UjvAh pPjTE8hwVKN4JTa2uMhQwO2S6wV993mcWmMaxbvJn6UgEA+q2U0dEJSDievhuQLNGZis TBGYiXx+KKdbebNG2z0RSgQ2/AjgH2P9uCunk/t89+EB9v2FVdJoNfmtk552JowDRd/F +vJadXh4srfC6knI1M5NUbVSv7z7goXmt1ME+nc08DYRX8nCFUFHryze3Rw/LIynC8jg RWEA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/EU/iMG6yg29uBo51A2iBmY9OZkda2o1/b9d0LOiq1U=; fh=9KG1GxoJIHO8DA9/W8zOCR/cizSACkxrp9LVRbza3AA=; b=Ygz9OgcBxGFJvWtQboGO4dFq8AxTyyJG2eR7JXbiwguqRu+A/TNDbibGxTp3DeuguZ 1Dy3U1tdlXX7hEAlHJFbZb/PQ8oML7M/xj98DSRXiIzIFsMqE7Pdk+GOok98gF73i6dz SsAU4wqDEYIMkPaT10T8mzFkjBACNprz9P2mEDIU7d6fnZqzr7EJ9DH0LVr2dckCg4Yv 7P+lXA1IaIMHpSx7jMZ8xs5ITlnK9IcQ3Exc7CPsaJXf15HCZtbZPUgD9rcGiyWpNCZb I4gZj8FmAiv2gF1TjI1Df0E+gaeig9gMCBBcfgAEEThtyWGa/J2ncWDFzQdBn3e8SwcM 35vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=NCoKYaei; 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 ga15-20020a170906b84f00b0098e1efaafc5si1558320ejb.195.2023.07.11.01.19.23; Tue, 11 Jul 2023 01:19:46 -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; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=NCoKYaei; 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 S231210AbjGKHzm (ORCPT + 99 others); Tue, 11 Jul 2023 03:55:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230236AbjGKHzk (ORCPT ); Tue, 11 Jul 2023 03:55:40 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B91E8CF for ; Tue, 11 Jul 2023 00:55:39 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-3fbea14700bso55060165e9.3 for ; Tue, 11 Jul 2023 00:55:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1689062138; x=1691654138; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/EU/iMG6yg29uBo51A2iBmY9OZkda2o1/b9d0LOiq1U=; b=NCoKYaeiv1nFsZu1kkN9IKONZ0ywf8MrhYyLoYAG7Q6i/1MQkq4oT+ftSJXO49RKyX ACt2ggo37pYi+8YgPL8PJ6dxHo9tA4/bLupo3TXiy9URZ4wDKkU28wB9BygUOld8z2e/ 3zc8DUiMdWOgQtJ0Ndn4UV5Li6hfcg8Kga3ZZhjNakNirjxP7y+vfmb9LrM9PCGhIPob Hdzs0ngha48Jpks5P0qe+0HhpMg4tmNZJB4wqnH4M1bv2Zwy3CCAuPi3okrxJTIKbojW InsOcPcSYd20w6iszei4mg1pDK4LCzlrLwfCY1fjznaJUncNDxte3J8oxZxhilbHxfFV 6g/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689062138; x=1691654138; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/EU/iMG6yg29uBo51A2iBmY9OZkda2o1/b9d0LOiq1U=; b=Nf8HJZFhc+g5mpGppFD5PXujxw7TjduAh6JsROvBSrBE3hZ9M9k8YSYAFGjmyKiX7T 7OrwpYyR9a2ErjZMbGrRBMJrS7F3iqm6l1Aexe14yNoSgXKRr93O1OK6xa44qpmQXuXo YtKW50YHoQiagQRYZaPdXy4iS+v7Twh0n3zoK2V9Nm0LTbCV30RO+O6BzRZwQ87GeGdB vXTZgdfVzXYxBePx+Pf+rgQWq20WNnKuR0gM0VZsLZ+r/JN4y9ZFZXvUPF6N/tB/aWwu 6oV2aYB973X9TGyX3r4VvbzWeWNHfan90wCJDW6THj9w4i4CYEuicMiStH7QeFYL3ec7 zy4Q== X-Gm-Message-State: ABy/qLbbahB5ki+8+buTahFJ/2ybbGs70urmIfwTybiw/8/ZTvHWHWNk sL2j6u1qtENlx+mHEuglp9UZjA== X-Received: by 2002:a05:600c:b5a:b0:3fc:60:7dbf with SMTP id k26-20020a05600c0b5a00b003fc00607dbfmr9944380wmr.41.1689062138206; Tue, 11 Jul 2023 00:55:38 -0700 (PDT) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id f19-20020a7bcc13000000b003fa973e6612sm12317248wmh.44.2023.07.11.00.55.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 00:55:38 -0700 (PDT) From: Alexandre Ghiti To: Will Deacon , "Aneesh Kumar K . V" , Andrew Morton , Nick Piggin , Peter Zijlstra , Mayuresh Chitale , Vincent Chen , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexandre Ghiti Subject: [PATCH 1/4] riscv: Improve flush_tlb() Date: Tue, 11 Jul 2023 09:54:31 +0200 Message-Id: <20230711075434.10936-2-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230711075434.10936-1-alexghiti@rivosinc.com> References: <20230711075434.10936-1-alexghiti@rivosinc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: INBOX X-GMAIL-THRID: 1771111539430129751 X-GMAIL-MSGID: 1771111539430129751 For now, flush_tlb() simply calls flush_tlb_mm() which results in a flush of the whole TLB. So let's use mmu_gather fields to provide a more fine-grained flush of the TLB. Signed-off-by: Alexandre Ghiti --- arch/riscv/include/asm/tlb.h | 6 +++++- arch/riscv/include/asm/tlbflush.h | 3 +++ arch/riscv/mm/tlbflush.c | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/tlb.h b/arch/riscv/include/asm/tlb.h index 120bcf2ed8a8..3373dcf0f413 100644 --- a/arch/riscv/include/asm/tlb.h +++ b/arch/riscv/include/asm/tlb.h @@ -15,7 +15,11 @@ static void tlb_flush(struct mmu_gather *tlb); static inline void tlb_flush(struct mmu_gather *tlb) { - flush_tlb_mm(tlb->mm); + if (tlb->fullmm || tlb->need_flush_all) + flush_tlb_mm(tlb->mm); + else + flush_tlb_mm_range(tlb->mm, tlb->start, tlb->end, + tlb_get_unmap_size(tlb)); } #endif /* _ASM_RISCV_TLB_H */ diff --git a/arch/riscv/include/asm/tlbflush.h b/arch/riscv/include/asm/tlbflush.h index a09196f8de68..f5c4fb0ae642 100644 --- a/arch/riscv/include/asm/tlbflush.h +++ b/arch/riscv/include/asm/tlbflush.h @@ -32,6 +32,8 @@ static inline void local_flush_tlb_page(unsigned long addr) #if defined(CONFIG_SMP) && defined(CONFIG_MMU) void flush_tlb_all(void); void flush_tlb_mm(struct mm_struct *mm); +void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, + unsigned long end, unsigned int page_size); void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr); void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end); @@ -52,6 +54,7 @@ static inline void flush_tlb_range(struct vm_area_struct *vma, } #define flush_tlb_mm(mm) flush_tlb_all() +#define flush_tlb_mm_range(mm, start, end, page_size) flush_tlb_all() #endif /* !CONFIG_SMP || !CONFIG_MMU */ /* Flush a range of kernel pages */ diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c index 77be59aadc73..fa03289853d8 100644 --- a/arch/riscv/mm/tlbflush.c +++ b/arch/riscv/mm/tlbflush.c @@ -132,6 +132,13 @@ void flush_tlb_mm(struct mm_struct *mm) __flush_tlb_range(mm, 0, -1, PAGE_SIZE); } +void flush_tlb_mm_range(struct mm_struct *mm, + unsigned long start, unsigned long end, + unsigned int page_size) +{ + __flush_tlb_range(mm, start, end - start, page_size); +} + void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr) { __flush_tlb_range(vma->vm_mm, addr, PAGE_SIZE, PAGE_SIZE);