Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1358308rwb; Fri, 28 Jul 2023 08:18:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlF7/t1xqyYeUU12xmkYJ7W34qP+pkmLj3Zu7sQhH368BOU/NR96SEbwLBgeZ6wyfk0gNVw+ X-Received: by 2002:a17:90a:9af:b0:267:a859:dfef with SMTP id 44-20020a17090a09af00b00267a859dfefmr1884278pjo.27.1690557524665; Fri, 28 Jul 2023 08:18:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690557524; cv=none; d=google.com; s=arc-20160816; b=gzGqfrmjy1Cvzz67AdrrcL97Wmx8mmI1aNsuY+ndsEuay9znS8sQEtIyYIIIX85m9K 7nL6wOk0guSVt8EuFT38oZuUp7iV/ZHRnBAcIoZlhh9m8ruv89K39X7aLFy+gwolsl1J H/DcWgz045gbEWayumlgBAofGTLSnxMXLv7ydM0Nzl0KigtF1Zo/mwvaOMXvyx7XEj6u nrPo0/nPZqah8V5v8MRNXT3dXD/QudjZayqrpXYoChy/lOarQXxdlod0z6RNpz85pWdF V4d1BL8SgJxOxc9gLS4TccSxtMF1LIv6sM7king95SDT4C6ZQ1BC1ONYVgGncQKIQuAF TDcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=xglqSrB2iPFW2I/fuXfPFH2AjeG9G8DHiCGCdZ7AftA=; fh=PT7uWiHsMDulxPw+SzAnwRDP9jn/UBIbv5TZuChOeZ4=; b=m21RZi1Dc0huqbn+lL6gSpLPm6Q+T8slXWhG4DmpAu+fdiujeo8Mtn/V64phYQKO1b LLrA13+6DvSkqpvp5P4oZk2LzZ4Tv5Vs0HK0fg4Fo+Z0/XbVVefijKSJaYkbuaYFgr/x Xc0QuiwsikJglj6hcSM4wXCrQOaonhIl0bBw6kMo74V4PWpf+H4KxOfV/hjfb4pw2Rn1 jxc9r/z7FqvUUOyrsnLVB7uAInVpdK5pQg4RXFLS7fzBzAR+G7igcFtrTonlbHxcsL55 6jjaQ+/YeuFf4IhV5piOvYPGfsk6XBNu6PGV4ozSauT0uk+5UCEG6nT32mQxv5GmHXSE qyMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=AB6+Mgpe; 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 m6-20020a17090a668600b0026349debbdfsi4793189pjj.136.2023.07.28.08.18.32; Fri, 28 Jul 2023 08:18:44 -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=@ventanamicro.com header.s=google header.b=AB6+Mgpe; 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 S236915AbjG1NtE (ORCPT + 99 others); Fri, 28 Jul 2023 09:49:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236911AbjG1Nsy (ORCPT ); Fri, 28 Jul 2023 09:48:54 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3402B3C33 for ; Fri, 28 Jul 2023 06:48:44 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-99bcd6c0282so299634066b.1 for ; Fri, 28 Jul 2023 06:48:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1690552122; x=1691156922; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=xglqSrB2iPFW2I/fuXfPFH2AjeG9G8DHiCGCdZ7AftA=; b=AB6+MgpeqsfDfT0Gtsokz5BQci7npK3FQ2KziJGiv0UyZ8bcgvhqc+jcNFZrgvptI9 AIrPkUC39/8FTuu/2fdqNt4nPY7RpvzNBpE7u/1AXmaIiKrDozV1gP+5xgOZOIjJVg14 v4JrgVF+IQYC8AW77Co4dn69YatbvqQJ1SQm5mYkHE6NZyD60qjFEj4H0s0FvdQ5X9/s ujEuMICe9jOyJ0EPcuouBIXvftZ9Tthnvhpr+wf+Bx5uPEZrkR50ZxRGeActqvJAADh7 bvgMp3mmy12GUl0qjKexge/lNeaeMf3tZsrb+qxNw4/y3M9VQ2w6+z84jeC0dMO0xJRS 5fFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690552122; x=1691156922; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=xglqSrB2iPFW2I/fuXfPFH2AjeG9G8DHiCGCdZ7AftA=; b=k62UN8w2lP2VW1eBNun0lF1rl6t9piMHfewpxuoUwe56q0A1CRawwJuFY/bntYtqgu 6Uj29Alfb06wXpEkGBKz3bi6lzIEvSajgMWL2GXFSZEMZ80kzZSqjqy5c4PaGf+4xQHG S0Kew9fMSPuF3EhNEaB72rDFBxoPkRifa4d3//dTo71zUVR1Ta/OJvXs67/4Oqgc+H/i Dk66BWJalvGv6LcbLYCUbrtQdaPiExFcr5bgqVUwb7S8tWYGdEPZABn9XQFA6UyyNez9 Grc6vH1r/G+ntXqeW5xDilXwMCgxQFAWy89rsi5NsZuzJjZYlalA1MtEnh31rYmMU/iU 2WhQ== X-Gm-Message-State: ABy/qLanDcpxYkO5hLnh/6Xf4dXGbCYzOjqkEqtFNGpM/j7GRVeZYvoJ Ez8vMxYRXfKG2ZEuZCDZoH3qiw== X-Received: by 2002:a17:907:7710:b0:988:6491:98e1 with SMTP id kw16-20020a170907771000b00988649198e1mr2173678ejc.42.1690552122403; Fri, 28 Jul 2023 06:48:42 -0700 (PDT) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id t10-20020a17090616ca00b00982a352f078sm2066763ejd.124.2023.07.28.06.48.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jul 2023 06:48:41 -0700 (PDT) Date: Fri, 28 Jul 2023 15:48:41 +0200 From: Andrew Jones To: Alexandre Ghiti Cc: 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 Subject: Re: [PATCH v2 4/4] riscv: Improve flush_tlb_kernel_range() Message-ID: <20230728-f5c389ac7f2a9aadf93939f5@orel> References: <20230727185553.980262-1-alexghiti@rivosinc.com> <20230727185553.980262-5-alexghiti@rivosinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230727185553.980262-5-alexghiti@rivosinc.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 On Thu, Jul 27, 2023 at 08:55:53PM +0200, Alexandre Ghiti wrote: > This function used to simply flush the whole tlb of all harts, be more > subtile and try to only flush the range. > > The problem is that we can only use PAGE_SIZE as stride since we don't know > the size of the underlying mapping and then this function will be improved > only if the size of the region to flush is < threshold * PAGE_SIZE. > > Signed-off-by: Alexandre Ghiti > --- > arch/riscv/include/asm/tlbflush.h | 11 +++++----- > arch/riscv/mm/tlbflush.c | 35 +++++++++++++++++++++++-------- > 2 files changed, 32 insertions(+), 14 deletions(-) > > diff --git a/arch/riscv/include/asm/tlbflush.h b/arch/riscv/include/asm/tlbflush.h > index f5c4fb0ae642..7426fdcd8ec5 100644 > --- a/arch/riscv/include/asm/tlbflush.h > +++ b/arch/riscv/include/asm/tlbflush.h > @@ -37,6 +37,7 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, > 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); > +void flush_tlb_kernel_range(unsigned long start, unsigned long end); > #ifdef CONFIG_TRANSPARENT_HUGEPAGE > #define __HAVE_ARCH_FLUSH_PMD_TLB_RANGE > void flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start, > @@ -53,15 +54,15 @@ static inline void flush_tlb_range(struct vm_area_struct *vma, > local_flush_tlb_all(); > } > > -#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 */ > static inline void flush_tlb_kernel_range(unsigned long start, > unsigned long end) > { > - flush_tlb_all(); > + local_flush_tlb_all(); > } > > +#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 */ > + > #endif /* _ASM_RISCV_TLBFLUSH_H */ > diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c > index 8017d2130e27..96aeacb269d5 100644 > --- a/arch/riscv/mm/tlbflush.c > +++ b/arch/riscv/mm/tlbflush.c > @@ -117,18 +117,27 @@ static void __flush_tlb_range(struct mm_struct *mm, unsigned long start, > unsigned long size, unsigned long stride) > { > struct flush_tlb_range_data ftd; > - struct cpumask *cmask = mm_cpumask(mm); > - unsigned int cpuid; > + struct cpumask *cmask, full_cmask; > bool broadcast; > > - if (cpumask_empty(cmask)) > - return; > + if (mm) { > + unsigned int cpuid; > + > + cmask = mm_cpumask(mm); > + if (cpumask_empty(cmask)) > + return; > + > + cpuid = get_cpu(); > + /* check if the tlbflush needs to be sent to other CPUs */ > + broadcast = cpumask_any_but(cmask, cpuid) < nr_cpu_ids; > + } else { > + cpumask_setall(&full_cmask); > + cmask = &full_cmask; > + broadcast = true; > + } > > - cpuid = get_cpu(); > - /* check if the tlbflush needs to be sent to other CPUs */ > - broadcast = cpumask_any_but(cmask, cpuid) < nr_cpu_ids; > if (static_branch_unlikely(&use_asid_allocator)) { > - unsigned long asid = atomic_long_read(&mm->context.id) & asid_mask; > + unsigned long asid = mm ? atomic_long_read(&mm->context.id) & asid_mask : 0; > > if (broadcast) { > if (riscv_use_ipi_for_rfence()) { > @@ -162,7 +171,8 @@ static void __flush_tlb_range(struct mm_struct *mm, unsigned long start, > } > } > > - put_cpu(); > + if (mm) > + put_cpu(); > } > > void flush_tlb_mm(struct mm_struct *mm) > @@ -194,6 +204,13 @@ void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, > __flush_tlb_range(vma->vm_mm, > start, end - start, 1 << stride_shift); > } > + > +void flush_tlb_kernel_range(unsigned long start, > + unsigned long end) No need to wrap this line. > +{ > + __flush_tlb_range(NULL, start, end, PAGE_SIZE); > +} > + > #ifdef CONFIG_TRANSPARENT_HUGEPAGE > void flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start, > unsigned long end) > -- > 2.39.2 > Otherwise, Reviewed-by: Andrew Jones Thanks, drew