Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp2741362rdh; Mon, 30 Oct 2023 06:32:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGq56AyEIg6EO1RTqOVQ2PGB+ZmCnQDn0AC7++133+4VfSzcJCno+Y5H98CRWDpm13tC4qG X-Received: by 2002:a05:6a20:2447:b0:16b:d853:90be with SMTP id t7-20020a056a20244700b0016bd85390bemr8184494pzc.25.1698672746816; Mon, 30 Oct 2023 06:32:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698672746; cv=none; d=google.com; s=arc-20160816; b=yuJnll5l6DQ+YMunoYMHl/8BAlyz9HdIiiIhtRrcXehLoyLtxFM00A/lOkZ2/JAA4A o56K/cbVeL4cOBSFGJICntYqNLmgKkci8jpm78k+haY7SVqKcTpGNRnGAdIFMGVjN4p5 MkechAqJizJpJDGcTgJu75WZDfHzPnExlzwvMI6iVYdN0MAGg/RoK2XPII1FsRNCol6G twePF89Z+l/EwM4DOV0OJ7Zfjud8bW1jOx/1wbogSgT8C0tTmFvDgPPttFKFmRLQRFxp ic7UoLplCMCmEJlJ27a34v9xGt9BkHIxresjuD8Eqohd36Ab11BRQ4JWAeECYaIUJLeQ xXUg== 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=icRDI3JO57zBXWlWvOhtKwlHVRtg/zewR+kimkU7nexf6mfaHqC/fedJC3TDKwy1Wo d3onsi5SP9JHAOTEVhF2Uf3uJvOl0SW/GCXSafCoqeYPOqjd/c2eV8YLU7JoGmgBN2Ft /0gOTtYAxhEM0ya8zMJI4A53K/zDbDq8hbLw8xIW8mgm+DAz6tICWVb6TRafz6YuTLZ3 lVeSLiHkoKhKu+DD6TBfZkChzxMO+I3NMg7F9cNzGzCgQFJpgsU5FveRzwdnrl3IKVbu ed2S9LLPcCOiCdsjQUW0Fbt/RJx5fl+GedgwQ09ZqyZQCw5ZbAj5o5x6kcqeyvDWEvLa NKNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=rzkQjj4X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id h65-20020a636c44000000b005ab6142f1besi4965421pgc.169.2023.10.30.06.32.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 06:32:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=rzkQjj4X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 231EA80A0DEE; Mon, 30 Oct 2023 06:32:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233488AbjJ3NcK (ORCPT + 99 others); Mon, 30 Oct 2023 09:32:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233480AbjJ3NcI (ORCPT ); Mon, 30 Oct 2023 09:32:08 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5947FDF for ; Mon, 30 Oct 2023 06:32:05 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-32f7c44f6a7so1224803f8f.1 for ; Mon, 30 Oct 2023 06:32:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1698672723; x=1699277523; 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=rzkQjj4X33Z9aWXpAgwoVV8zUjyCDIDtSbXOKxc2/7TLFM1A7ALHsaVGrBVx6OA0Rk 5qUk1XJwu4GxAiZcBLygmA8yH880V8tqK/xyqmpm8+0160P+JXu7LtEb7bVmY65URdCe wLk5p4HHaiBASBFlLGTbmbcNVum4k/Ew91S69jcHHesynN1hwzt4EfoMBecGY+PkrFS3 gcQFiiMOvwjaKki8d0zyuSmttSVo1dgtR6odkR/v1D8u5/ihdUJ8H1Pzq/UfIh4+p1lu zD7LgIcn5miTSBgWN21awH3Yh7neM3R3TiasJKUPXKn2kiN7ijj620eiUZ1dkIUCHTTv T6Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698672723; x=1699277523; 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=UCQc2kXzLw8pDFbAb/mjA1JFlzmkDEN+Du5bi63Ru2AWU/PJTkujdQh6s2nTI5Z6Z5 pmxPKYykAhTw64HOMvwqk1uhsTRwRkgOMlPKR/2IfN8LQelEdexfC8/kV1HqLZ5nJo5f y8zCjjBnD+q52qLtayV5MDWdAUwWn8Uq90bxfawf2Q0pTvxQgzgwt6zrDOv7fpVMCb/0 G6Gg13zVDrf4LQvxPwT7u+qvmtz+WR7Dj9DvUkUG3Lxan/w41iGicC11HvHIxowo+8VO Z9FBjzXIZmwaaUFTUC4zvx7QMeVjjMAQkU4v77iD6/Z5Ujsl01MJrG/UHkGQjioE4tM1 iGIQ== X-Gm-Message-State: AOJu0YzyTzC1Skui2Utd5khSD4AfMpfFvWWnxJhR4ulrQQ8+kcXJ9wbz s7f9bz+JfQsGDhL6Ic5wM1zxmQ== X-Received: by 2002:a5d:4b0c:0:b0:32c:f8cb:f908 with SMTP id v12-20020a5d4b0c000000b0032cf8cbf908mr8512441wrq.59.1698672723353; Mon, 30 Oct 2023 06:32: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 a15-20020adfed0f000000b0032d88e370basm8262398wro.34.2023.10.30.06.32.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 06:32: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, Samuel Holland , Lad Prabhakar Cc: Alexandre Ghiti , Andrew Jones , Samuel Holland , Lad Prabhakar Subject: [PATCH v6 1/4] riscv: Improve tlb_flush() Date: Mon, 30 Oct 2023 14:30:25 +0100 Message-Id: <20231030133027.19542-2-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231030133027.19542-1-alexghiti@rivosinc.com> References: <20231030133027.19542-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 fry.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 (fry.vger.email [0.0.0.0]); Mon, 30 Oct 2023 06:32:24 -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