Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp282099rwb; Thu, 27 Jul 2023 12:38:57 -0700 (PDT) X-Google-Smtp-Source: APBJJlFlv7o09qlIjKfXUmOpbi3QRYpiM7anAUY/TRpEMRK241r6TL+N0/UvmACpfqfHRZeBJV2c X-Received: by 2002:a17:907:3e0b:b0:994:fec:e1b7 with SMTP id hp11-20020a1709073e0b00b009940fece1b7mr4422377ejc.0.1690486737059; Thu, 27 Jul 2023 12:38:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690486737; cv=none; d=google.com; s=arc-20160816; b=vYtPSgQy0fw734Kpk3CFxqlb+OoBn2O2mwOvJtEvegXiDb4NGTjj4CDK7xUF4ggoam S28mFFrLvGkuI0p695rMdnKzM9xNjBtcFj49iAmyh7yvZvi9339xypYnwd4XwpRybXwc oeCQJlEG+CzlXJs/TgE4ku/8Hg7+7UfMULikOR9SGBA2/eAhEWiRUL5M9N1RB23sHkDr amGwtvoebta++Mi8kdZ3xgWwO3MN+iTopCPzjo55varAjIozaF6pHsHuz+NSXvm+A+q8 MvgAWmvTm7Ku6VeNNQewQ8Ep1zIcq4xUbzYon8Tj/ldP8NzdMeC3qSjRB5pKdMLLgFxM 2f2A== 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=iNM2lfApDpDHo6wA+erk64IwXrZaYOnl0F5llP9QRbw=; fh=9KG1GxoJIHO8DA9/W8zOCR/cizSACkxrp9LVRbza3AA=; b=WUVR1h5UOO/YxwQlyWAcZO6iZ5JIz8R3fA/QRqXaE6n5njrRWySvdH4DlmGg5le/S0 OF4GMMTMVynJvutY7RrEU60wOldu+SJIfPd0lU1LYtV0VOi++J/u0JftvsoML5bWFrid SooThB2fukvFR0RQg+qDAEGH+IVZx7CIONGrCfb4XfLSPQ8nbtvJrXDy/k6wxtPQBgms 5NS1l7otX0OW3UnlyHYDAFv1Mw+ArNAw7YzxBq12Khze4QdyQPFmGk3T2KTDbmdNDXWA SJ/4xWxblNE4ecYNWtXzq9X0CmWT3JYUhGNdse4jjg8rbNL3MrJnYHTCUcGh4sQFHgQA /Ykw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b="rezn/W64"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga6-20020a170906b84600b0099364d9f0e0si1589022ejb.540.2023.07.27.12.38.32; Thu, 27 Jul 2023 12:38:57 -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="rezn/W64"; 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 S231407AbjG0S5G (ORCPT + 99 others); Thu, 27 Jul 2023 14:57:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229799AbjG0S5F (ORCPT ); Thu, 27 Jul 2023 14:57:05 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3D9619A7 for ; Thu, 27 Jul 2023 11:57:03 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-3177f520802so823946f8f.1 for ; Thu, 27 Jul 2023 11:57:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1690484222; x=1691089022; 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=iNM2lfApDpDHo6wA+erk64IwXrZaYOnl0F5llP9QRbw=; b=rezn/W64XZNrrJy+iA17PP4dY7NEgyDtF1IgTecXk40RddgHRKdjQdVLO3Dm1uiPer A/Ii0X04NrJUwOnHByd4OTxbucNLBTZMeUCmg0Q0dLf4NOeYY4NIOM5/xemrnEQdHqM3 3PO1vT7NS3Pz3oSI0IdeDTeUN+MRrZJlAnsoxNG5N9A0RJP7xFhKTwCS9xEYMFj4sKiK upS7cJ6ZI05fw/KrM4vQe5n5xeNNgCxUW9CbTnUp9OdMXMunKs1O9Hg3Uyk0EhlxrNcE bPoSbeW9PJMxsO5k7dAJnx7DOdPk0t+LTa6vDnZpQDrikaZlST3yBaYyPG73FlWwmYXH 6j4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690484222; x=1691089022; 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=iNM2lfApDpDHo6wA+erk64IwXrZaYOnl0F5llP9QRbw=; b=UMQvi2yzU7b+2CIjHwrhy/T0TYDi+WfAIVhQy0JoGigXhGghkrWQQgs5jqJz84fw6F G9FBmtmZHwf/es6c1iYlfFyi6+WpU+NIAqarAgzQlJm3aK7bHAvO4jcpP0J3u54gD0iY ajSH5iIou3JbOWhz8atSxHpIbISzEFXpPz3fVursdcx+uP8CFt6dufaNjxHmjlFcUI8R NzeVecuLQInXAZ425ySMaytdSqvXYHy108V6VbSQwt7PuOQYbetbiA+Acwu4ubega/kU dJYcz0M9LIrQdlosUSNXvHT6SV8CNMwm8cx3dxzg9BGnSIkPbUNyAhYyvjaZWWeLKp6J Fg0Q== X-Gm-Message-State: ABy/qLZ2G/WtKX5BcLL0QMTEprwDcj2aYYAcr2XMC0iGg2jNSgIrOkap sD9CiNwxB03eQGrIk5rN8l4gdA== X-Received: by 2002:adf:e692:0:b0:317:36d8:d6e8 with SMTP id r18-20020adfe692000000b0031736d8d6e8mr2479276wrm.25.1690484222369; Thu, 27 Jul 2023 11:57:02 -0700 (PDT) Received: from alex-rivos.home (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id z15-20020a05600c114f00b003fbb5506e54sm2443379wmz.29.2023.07.27.11.57.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 11:57:02 -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 v2 1/4] riscv: Improve flush_tlb() Date: Thu, 27 Jul 2023 20:55:50 +0200 Message-Id: <20230727185553.980262-2-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230727185553.980262-1-alexghiti@rivosinc.com> References: <20230727185553.980262-1-alexghiti@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,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 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 | 8 +++++++- arch/riscv/include/asm/tlbflush.h | 3 +++ arch/riscv/mm/tlbflush.c | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/tlb.h b/arch/riscv/include/asm/tlb.h index 120bcf2ed8a8..1eb5682b2af6 100644 --- a/arch/riscv/include/asm/tlb.h +++ b/arch/riscv/include/asm/tlb.h @@ -15,7 +15,13 @@ static void tlb_flush(struct mmu_gather *tlb); static inline void tlb_flush(struct mmu_gather *tlb) { - flush_tlb_mm(tlb->mm); +#ifdef CONFIG_MMU + 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 } #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); -- 2.39.2