Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp372224rdb; Thu, 19 Oct 2023 07:03:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGI/XhsiiN9y0zhyL09Q6BjiwjboqjaesaIoOSRC4ruaa3REXQqiT4lMgyilBtO7mvI/SXJ X-Received: by 2002:a05:6a20:9191:b0:13d:d5bd:7593 with SMTP id v17-20020a056a20919100b0013dd5bd7593mr2366722pzd.12.1697724200258; Thu, 19 Oct 2023 07:03:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697724200; cv=none; d=google.com; s=arc-20160816; b=giG85F4dNZpiilHa4itYJyCkv17PQQSC3099Er5OsVlr8BOTRaGVTwbeV5OiQe3yfY XwuFeRD//Dl/M2ow0b45kBox5D8GcN1RpC27mcQY/CE7pSeFdJhBbMEiHlzEWMxjxq8D 4JRuVxvPejrM+a/NOjOW1vsLUFNe/PvPA9deZDIRfCtqrRBg2z+jM9OaejL5w6yfAudu 1QSeOyajklPqQs0ywu8JNElkQl5ZxabTMFTatIK+I2Ei0Vm/DMMZ/VF3mdcfrt/AUcbe Y1N6cHStxYFkS/mbO2tIiw0We58qS79YPs6BOrDNMiarqo1/LMnQ3E0hCUy0h9aY5la3 +KCQ== 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=hd/FLevx18XhR5UIn9smwlv93JRL3lzcOo0hNfovrwU=; fh=Msqif+UQLyOzxpVENyTdjibc5nrDp1YLp7sPKN63EPU=; b=CY0iK/dlbLwBIullNOyWF0tDiTMP2sb8MRRrmHd4Bt6pogVTO2Gmc0JcxwXLS1w0Ow 3mXl9f1/hGpMDde2EetA+sRgIn9Csj2SYi9FyoopTGWTIPYFoYC0GgcUubHGtDD9EjR9 7RodXt12P+8x/SLvT348gePykFatXKfmh9Eb7R8q+TR8N+29FURE9ZBS2XlWT/Hp8hgG rrGicOcnPaemDikgzbpX5APX3A9GQLSCBOUOI7f2sTl0IzoRjhPlXRMh3/5Dw5+v09Gn MwY+f0CsOhgD8705nQhPzx/EMVLlpQjBsJDWfzgaWbtOYI5REmiLXu8ftDsM8DtvFcb+ Imwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=HJA5HuLt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id ca27-20020a056a02069b00b005ac44f928e4si5154211pgb.152.2023.10.19.07.03.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 07:03:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=HJA5HuLt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id BB126829FDF2; Thu, 19 Oct 2023 07:03:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345904AbjJSODJ (ORCPT + 99 others); Thu, 19 Oct 2023 10:03:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235321AbjJSODH (ORCPT ); Thu, 19 Oct 2023 10:03:07 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4A97130 for ; Thu, 19 Oct 2023 07:03:05 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-507a29c7eefso7526232e87.1 for ; Thu, 19 Oct 2023 07:03:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1697724184; x=1698328984; 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=hd/FLevx18XhR5UIn9smwlv93JRL3lzcOo0hNfovrwU=; b=HJA5HuLtYTVxlQIRyWzG0OniQP7/8a/98VFXx8BMT6kiyddDWdcgpjUv8Hhhi9WJ/d vH5FtT476kx7pJgzASWxniUxPI8bFBWDvZqVaM/F5ghyDUN75bd6nZb3vqkwE4xBWNwR B/QmK/J6n8SfkpcQxtNMCsslSMm2LfHQsyLlB3+z/s3Kwx5D08zg+SaTEg4+4fbem7NU AY71ChGTOHp37IVr9qW5wrrglTpRKWlNsfg3fBiohFvr33t/uzJK1dNIFClKj3YuVxkO NBb4hoLa/G5do/qgGzMhswR32jvlL3So6wAo8h8hj0C4yTlA9wV3aZoQa3lORdGsY4OI zhjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697724184; x=1698328984; 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=hd/FLevx18XhR5UIn9smwlv93JRL3lzcOo0hNfovrwU=; b=pWyJys5fpjezksPrbIL2Uf02EHx4whMGMvp1LYUKpcyEL5fhEiSPyZqGYbIzTWK1gT yYlLMl90roOVv2RIBnWPET+YOKupb5SAVyPmFolM5a1Y2prYFZ7lrKFGuwROAvg+EbQB pIDkyZWjrbODV3qqnTtkI5Xcmg3U1OYFng+KnfKOvTEPkVyIimcNiYOW1Qs0Y+mAKFGm wymrEwozVEKFJBpN4WUYW3GrGAjnkptQdqwHJTx8hOiFEKxrdyCAmVBhaIAdm/YXZqPF 0rcW+wTJ0GIiVrLt7E3HJOqWWLsisvCPh4RwDeB64ax8Fj1RzKgaZbQ60kfU1XtaxhWD Y/gQ== X-Gm-Message-State: AOJu0Yw7S3AzhiU9w5IKoJnmsxhKQzirR6V0dhSfXKNXoGN0jfHN1+On WdO8KkwZyRg/gh6vpDUC6vS6MA== X-Received: by 2002:ac2:5a04:0:b0:507:b993:bb86 with SMTP id q4-20020ac25a04000000b00507b993bb86mr1486713lfn.66.1697724183683; Thu, 19 Oct 2023 07:03:03 -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 q9-20020a05600000c900b0032d8eecf901sm4567033wrx.3.2023.10.19.07.03.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 07:03:03 -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 , Samuel Holland , Lad Prabhakar Subject: [PATCH v5 1/4] riscv: Improve tlb_flush() Date: Thu, 19 Oct 2023 16:01:48 +0200 Message-Id: <20231019140151.21629-2-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019140151.21629-1-alexghiti@rivosinc.com> References: <20231019140151.21629-1-alexghiti@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 19 Oct 2023 07:03:17 -0700 (PDT) For now, tlb_flush() 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 Reviewed-by: Samuel Holland Tested-by: Lad Prabhakar # On RZ/Five SMARC --- 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