Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp2227455rdb; Mon, 11 Sep 2023 15:16:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFS+vjCf1/X6zI8YqB+54Ha2/qGj7Bco+Ga1v2AA8Hd5eyLeJBB+3c2AdmthiG9GAjcPdQM X-Received: by 2002:a05:6a20:4401:b0:147:ecf6:c4e6 with SMTP id ce1-20020a056a20440100b00147ecf6c4e6mr12424979pzb.0.1694470611674; Mon, 11 Sep 2023 15:16:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694470611; cv=none; d=google.com; s=arc-20160816; b=IJypgxKBqnA7ldhWXgWBzJiTfsqjKhs/aDwdkHTTOnATNwRD+O3tGBwVSfdMMXKjhW 8Fvb66v5xcdvyefdpVVpVinlvoNAHqpQKkbaPi019bTzHDGxs48I3krIEHvOdghpuwH4 07LG+qmvWpChoHxgf8J4BHEOYk+G+hlwD0EmmbkdQcKMqxSkF66pmfjfTOZZFu1S0r+f DG8Q2a47etz3rGi/UmRW/xBwuZsHNBIPiN/QjIPYR8l+8Yc4hAkh/Fjp2hJMc5YIudPT solRetjp8DQoE4wXc3Wd0Yqcb7Fgxz3E8WM1lqIhdH20rVrzoXZ1Kiz7Dw6p6QTqX/q3 KC3Q== 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=VJvQhuwass6T7QyQKJFHTMKHPeCPiB8wQ+ZaCt6WMq4=; fh=llnQh9XmRM6fH7W2EHepFoDsyaQ6DpvzYGUfU5j4hCE=; b=YBWdWapYdd3xbAp2DbtIczmPdKILk/Ynwj/w/WaQp7B62k0OdPFcRyjNKY8iwXiL3V IoXTl4Gc2xxG91ZS8QM5T1efeX5OXpy5fuyDxKLkVgURD5Gu3FaCiL0m2ifsY3gpXdWx wDiioec7aWlGdH176WuJjQooud+QUNzJiSA27Nr8SsSIawSxxUZjwqFEaPRkjGNU9u+y /tBsZ1bgXPd3DTTchDJ5QJ6ZixV1kpkPyVAb2gAo0mikyff2XX0JDbPmkHDHLPLjPJem A0BbIHjEsur342yOLHtu4ZfFWe8VW0YCpt/O8mhV9veAbW3J45Xyj2/3paVQ5S3DVa9T KLKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=HMVF18wQ; 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 cv20-20020a17090afd1400b00262ef440ed4si8403686pjb.27.2023.09.11.15.16.37; Mon, 11 Sep 2023 15:16:51 -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.20230601.gappssmtp.com header.s=20230601 header.b=HMVF18wQ; 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 S1358554AbjIKWL4 (ORCPT + 99 others); Mon, 11 Sep 2023 18:11:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237741AbjIKNNe (ORCPT ); Mon, 11 Sep 2023 09:13:34 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0D0FEB for ; Mon, 11 Sep 2023 06:13:29 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40037db2fe7so47471435e9.0 for ; Mon, 11 Sep 2023 06:13:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1694438008; x=1695042808; darn=vger.kernel.org; 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=VJvQhuwass6T7QyQKJFHTMKHPeCPiB8wQ+ZaCt6WMq4=; b=HMVF18wQjc6DGqjgcRT56k/Qc7TQBLsEFQr/u/7CslBI5TL9VDmxEfG21MuDQ1mqQ0 MzzAuSioeSPUXqwoxRJSWH/BHJL2cRO0R1D1W2iq7cXpubvpnbHetCIYce4Yrs1DzNDc 6ujewR7F2CvE/Xtpqo7IPTDtcQRSwjN400/wWye8QRxGlCK9EG9b6TjWRCHzw1PWssl2 6VjNe2sf5H4VXL0JbUP3ejfCorRb2KPuoovBtaenVugdLiPQO2xR4CMDeiZAIAhe54T/ P0BdYZIgJ/ruTOzDVnPLj/GWPs/2MLgFVd2acSFqE9udG3d1kPuxhoLt6FTncTdedCuZ qbVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694438008; x=1695042808; 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=VJvQhuwass6T7QyQKJFHTMKHPeCPiB8wQ+ZaCt6WMq4=; b=Y6oaePZKvIBv5lVYsJslOL1mwv94Uqi0o35j4jEI8RbcHt4n8ptCKlePSUCfRRL+PN ZGGdPfIfcghwib1G1sr1Je78eCp5mWHjYB14vWQrK3hcWey6rNdl+JzRr1Mz9QeaoAXT n7TYueQO5moHJvF7LZUytgdkW9bfcMHNrBE76/r60xJU+mWbDmVe6lQI6Uf0YEdW6fO1 9cSO/93BPBzPfH0WqjQt/zOR4VS1ptsHw2s9pEmEJDcJqNF2B2DkXfzCHcPivx10y0ec b7eaSiWMTJHYPLwp8E6Kr0ZiH8CiCGCNoBzUpO2Dg/l9dDFdcER86HFaf3eOlDLAmdgg toBA== X-Gm-Message-State: AOJu0YyHtnT3dW9pyNIQTHYEycwD5fjXNt3H73uDmOTxsdurzIuHOOR8 XlmPejvdpEk1H8On5P2Yq53ebw== X-Received: by 2002:a05:6000:118f:b0:317:6d9d:1250 with SMTP id g15-20020a056000118f00b003176d9d1250mr7674314wrx.61.1694438008262; Mon, 11 Sep 2023 06:13:28 -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 b14-20020a5d550e000000b0031f34a395e7sm10072174wrv.45.2023.09.11.06.13.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 06:13:27 -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, Samuel Holland , Lad Prabhakar Cc: Alexandre Ghiti , Andrew Jones Subject: [PATCH v4 1/4] riscv: Improve flush_tlb() Date: Mon, 11 Sep 2023 15:12:21 +0200 Message-Id: <20230911131224.61924-2-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230911131224.61924-1-alexghiti@rivosinc.com> References: <20230911131224.61924-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 autolearn=ham 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 Reviewed-by: Andrew Jones --- 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