Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1921318rdh; Sat, 28 Oct 2023 12:43:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFNA7WYCI1X1xrY3QXbS+g0cxxs9vlUrCXh4u88jo0+r4oGFgEMwI+xG9SlzxLdfH8QbTUs X-Received: by 2002:a17:902:7898:b0:1c3:4565:22f with SMTP id q24-20020a170902789800b001c34565022fmr4933787pll.21.1698522184029; Sat, 28 Oct 2023 12:43:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698522184; cv=none; d=google.com; s=arc-20160816; b=TX/r+UT5g97IW6xSImqQX1MZj+mdTePpsVIqcnVn13zB5OsHC3tQ+JKtTB5q2uCFwL hAGFUJcgTt5CUjaVDhNokLDxOzfAbe+xWmwPXDR7SKCh3t9RNPsB3w0ziKAMehEp/ibP qWvLegukrGeoF/41UICi0cAA49bldzKyBZ9dNmMBCADhQKNRV0Sa7W8Kib7TUkcgN8P7 HJIoiL3w2xYcUn/pQ4M8rUyYEINE6ff5zfM+z/b24BgQflL73B143aCXt9Bnlv9aOTSx B6ZX+BfQx2djT0i4TPfNgj8iQnRCQJ+Yp+EX9cClHoBiUKcT7KpR5WDgAHRRioTaWHYT XHsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=Qq6x4Nq7vuXjfz7tKTCkE6tm57DtbpxomcSKCh+LPx0=; fh=LeYqmiSqLmC0Mq4ml11y5+VAZrgiUwc+rL1SyWOdips=; b=P+TsuU47MygE+oB7rSyqJ2lG10vb2rgMS/PCZ8Pruq/AMODX0cy9cN9PuzWm1H/K57 3bvaI95LYk21MLffp92L9ngkNBKgDxFmhAKOa4CAsYmlrI/KAY/Fny+RLsxkxOHqRfCi LcKxUuIkM2SWZPd9qe4cRWjzlajzPvq+CwDpunICostFE8m0kOi02ECHVm80G8sEwLxg +u79b0KdVJq/cjaMiZCnQjBzYoLWmb+LpPGTvd2V59znad5aHuOfCjyaq9GiDsoNKwn2 mCCU3ROhbKBZqhKVLRiRasTi1GlAo+IMW4+PABOEqwTN9qpElRTjGjWlZUULM4/OksLj fEyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=JcqMxQRQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id u12-20020a170902e5cc00b001c74ae78c7bsi2951925plf.377.2023.10.28.12.43.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Oct 2023 12:43:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=JcqMxQRQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id A7C65808987E; Sat, 28 Oct 2023 12:42:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229865AbjJ1Tm2 (ORCPT + 99 others); Sat, 28 Oct 2023 15:42:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229597AbjJ1Tm0 (ORCPT ); Sat, 28 Oct 2023 15:42:26 -0400 Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8488DF1 for ; Sat, 28 Oct 2023 12:42:22 -0700 (PDT) Received: by mail-qv1-xf31.google.com with SMTP id 6a1803df08f44-66d0169cf43so21916606d6.3 for ; Sat, 28 Oct 2023 12:42:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1698522141; x=1699126941; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Qq6x4Nq7vuXjfz7tKTCkE6tm57DtbpxomcSKCh+LPx0=; b=JcqMxQRQ8YIOi+Rzn6HDLik/suyzEhoSbiu8bGyrvZAPeASXFOXN+IpuTTyygV1/Fc kfNEwkJuWW0v67TGqYMm7FLM5IGJy25SNA+NjnpemG4kZe6Vx8PWmXWpIiR47TRJcVPg 6PZbC9gMc3dVeYnbNw9n2xTbzYM5Wq2kyE1qZL6MQLxMuZu43+UuNmRdCS09/ldV2J5A OP5O7ZjRI9AP4CT5dKC+gJl9xVPv4VRxMHSYjsUQw7U6Cm7ytFoh3vID1jya4rj8SPZ+ qg3ywwZ+4vYVAMRg1u2VXttGuyoENYYLsEn1D8WKK/ptfqYqRlvTFN7AgMYc2WZV5gH7 PRUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698522141; x=1699126941; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Qq6x4Nq7vuXjfz7tKTCkE6tm57DtbpxomcSKCh+LPx0=; b=MD2qVsrVk0YkVFh+MrRBaNbHylCEDm5Z4gg/WgYAfS0oYTbh9odlvl3BxM6e9V2bNt 8HBCkRaArWBQQiUQ7raXZzbrsYnUPyLFZ7cJ59ca2QZkEhQqsUKxaBBNP4/Prxiig1wh FbMdplmC1iPUxwUNMpWHyIttb+OyaN6rxpiAziPNo+bHlk+lFvZL3Ce01QHVQYT62j5w Rk6/1kzh6MOqYeqS5PHwuXSG8QOIkuo44D5YPKaAYPcil2CqHPakgiIoy4WFnAwpQTsn gZRfrAcFvtgncMOK7V71kh3qu7YBXsLRNzWzGf/I/gUjfW5pwmGsHWDU50ao35DzRxR4 O5rQ== X-Gm-Message-State: AOJu0YzTj3gFv6GlrgCzHRJ/jO7LjO1zl2Db/z74RKGbMQgq/mJOtYsb 8IoWgetfFhPRW7taQ4CZ8VesqA== X-Received: by 2002:ad4:4ee3:0:b0:66d:49aa:6844 with SMTP id dv3-20020ad44ee3000000b0066d49aa6844mr9472629qvb.19.1698522141362; Sat, 28 Oct 2023 12:42:21 -0700 (PDT) Received: from ?IPV6:2600:1700:2000:b002:c988:e7b9:36ab:57c6? ([2600:1700:2000:b002:c988:e7b9:36ab:57c6]) by smtp.gmail.com with ESMTPSA id l4-20020a056214104400b0065afe284b3csm1853091qvr.125.2023.10.28.12.42.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 28 Oct 2023 12:42:20 -0700 (PDT) Message-ID: <65d7ea77-35fa-4aa2-9431-8f7f218cae57@sifive.com> Date: Sat, 28 Oct 2023 14:42:19 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 4/4] riscv: Improve flush_tlb_kernel_range() Content-Language: en-US To: Alexandre Ghiti Cc: Andrew Jones , Lad Prabhakar , 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 References: <20231019140151.21629-1-alexghiti@rivosinc.com> <20231019140151.21629-5-alexghiti@rivosinc.com> From: Samuel Holland In-Reply-To: <20231019140151.21629-5-alexghiti@rivosinc.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,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 agentk.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 (agentk.vger.email [0.0.0.0]); Sat, 28 Oct 2023 12:42:41 -0700 (PDT) On 2023-10-19 9:01 AM, 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 > Reviewed-by: Andrew Jones > Tested-by: Lad Prabhakar # On RZ/Five SMARC > --- > arch/riscv/include/asm/tlbflush.h | 11 ++++++----- > arch/riscv/mm/tlbflush.c | 33 ++++++++++++++++++++++--------- > 2 files changed, 30 insertions(+), 14 deletions(-) > > diff --git a/arch/riscv/include/asm/tlbflush.h b/arch/riscv/include/asm/tlbflush.h > index 170a49c531c6..8f3418c5f172 100644 > --- a/arch/riscv/include/asm/tlbflush.h > +++ b/arch/riscv/include/asm/tlbflush.h > @@ -40,6 +40,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, > @@ -56,15 +57,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 c27ba720e35f..7e182f2bc0ab 100644 > --- a/arch/riscv/mm/tlbflush.c > +++ b/arch/riscv/mm/tlbflush.c > @@ -97,19 +97,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); > + struct cpumask *cmask, full_cmask; > unsigned long asid = FLUSH_TLB_NO_ASID; > - unsigned int cpuid; > 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; > + 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; on_each_cpu_mask() only considers CPUs in cpu_online_mask anyway, so you can more efficiently use: cmask = cpu_online_mask; here (after making cmask const). > + } > > - if (static_branch_unlikely(&use_asid_allocator)) > + if (static_branch_unlikely(&use_asid_allocator) && mm) > asid = atomic_long_read(&mm->context.id) & asid_mask; Instead of adding another check, please move this inside "if (mm)" above. Those are both non-functional changes, so: Reviewed-by: Samuel Holland Tested-by: Samuel Holland > > if (broadcast) { > @@ -128,7 +136,8 @@ static void __flush_tlb_range(struct mm_struct *mm, unsigned long start, > local_flush_tlb_range_asid(start, size, stride, asid); > } > > - put_cpu(); > + if (mm) > + put_cpu(); > } > > void flush_tlb_mm(struct mm_struct *mm) > @@ -181,6 +190,12 @@ void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, > > __flush_tlb_range(vma->vm_mm, start, end - start, stride_size); > } > + > +void flush_tlb_kernel_range(unsigned long start, unsigned long end) > +{ > + __flush_tlb_range(NULL, start, end - start, PAGE_SIZE); > +} > + > #ifdef CONFIG_TRANSPARENT_HUGEPAGE > void flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start, > unsigned long end)