Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3329854rdb; Wed, 13 Sep 2023 08:51:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHirSZw9VQUpB6Jnc6JjdtXFqTMgUmfx7cTVaJGvbl3fNC1i8lpTvsWAXM9Z6fOPppjdaxy X-Received: by 2002:a17:90a:9b10:b0:26d:5cd0:979f with SMTP id f16-20020a17090a9b1000b0026d5cd0979fmr2685154pjp.43.1694620296964; Wed, 13 Sep 2023 08:51:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694620296; cv=none; d=google.com; s=arc-20160816; b=fiFJj54rXhtmQIKD+wNx6EgyEKv1S+s6dUGbUg+2WOq7JrpzXMkLesh6nzCTfxmMp4 ilestQV+mg7sw4bEhM0KGHXn6wSeLNwqvnDACU8QOtV9fI/AdngE1K/NI/zJLbJ2Ikt3 q6ok2pgHt6ev/wmVbRwRlFITExMjapJ3Hz9OHyclkViSuQEGSDsTVkp/oXYYIU5nCUWk LhWxnxE29FEX6Vdah3Cad7Nx8C07u6dR1jURVuP7bm5MclE/3rLMIwHDeb8d8KdD/RUn PGQGGmBaIcUYMK0Ir8EiVLSSq44vczO1twu0HbNj54yWHxQ+0VLFTn3p0DY4/aG3g1D9 NEwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=pvSkwLLGuwL6+FzTiaUPYz7u0MiA133oxHxQzz8keyY=; fh=c8XmAFyDXFvO410xILxamWybBQblPbH0CTkpHCRK068=; b=mIDBgRBX3r31tqU0NTItI2fPFzjQKazprXyDluE7PPMdHb7uKZNhp2u54veGKLcvXI 8AKPzDrYZ2FYXNzBaWlju2wmz/RX5slK+CqHBQ4ZDRo0JrBfJWGJPJ/0LNuyvMPuRdfB 2EZVvjOg2meZ+M8q0d9nMW8Bqg+YVZNTc75kUTMzPH2gGA28a8VWIdqXsDoYaK6GpWQh hoNv35fVa0O+OR/V0tWpg4G8v+h4N/oZ5ahB3JUh8G2Je9IwZ8q1h6CA534vTXtXYNeE qTj/R/zbnAc6DgdFOHitrn9kIX7JmoIdgX5/fBt2AM7mm7d7PxqJO/uInoyQgIr5IyFN lrkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=f3NkL39q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id mu17-20020a17090b389100b00263deaac48esi1951354pjb.8.2023.09.13.08.51.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 08:51:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=f3NkL39q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 952988228818; Wed, 13 Sep 2023 01:24:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238705AbjIMIYY (ORCPT + 99 others); Wed, 13 Sep 2023 04:24:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231301AbjIMIYY (ORCPT ); Wed, 13 Sep 2023 04:24:24 -0400 Received: from mail-vk1-xa36.google.com (mail-vk1-xa36.google.com [IPv6:2607:f8b0:4864:20::a36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4937010C0; Wed, 13 Sep 2023 01:24:20 -0700 (PDT) Received: by mail-vk1-xa36.google.com with SMTP id 71dfb90a1353d-49032a0ff13so2382666e0c.0; Wed, 13 Sep 2023 01:24:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694593459; x=1695198259; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=pvSkwLLGuwL6+FzTiaUPYz7u0MiA133oxHxQzz8keyY=; b=f3NkL39qpplvUFN3+/u9KzP5YUp4KczTSkjEUNDgN4Yu4Hf+c2FY3qNsl6Wskwbxlg sh3SpIqQIJ5jbm/mfU8gBKRSuijxsL8Hk7BjfGie6zGm0/pumK1k+JR+JS9VwWbOl9Ix z7n8gzVL7pe/K7TOwx14Am6ietoIn2FFf5E3Mx2CDrLuSDUnHGzdjl2hUoW7pBtWB7CU pLUwfp+KVyomlTHUCw3f5uPOYeGcIQyLhMdhYSQ7aLjMQkgjlYFo5aUlPA6lR4geY89q 5zK+kCYcqcIAlF7u75dxzuVg+S1xjtBxz4VBYwpHz1N7guIJx0mY6Swxr3bqvNDHNS99 Nhcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694593459; x=1695198259; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pvSkwLLGuwL6+FzTiaUPYz7u0MiA133oxHxQzz8keyY=; b=ilEQKFqftNMuQISc3rV9+RU2RiIYrTKuMdD6J9qkHOhDjETWKrqS4Je4/1ltzieoMv Dd4vQuDWPp/xcb3gknoD7jOppkh6QaBN2O8O3CVE292zMJvOk2bZXoMeOpsKvzHN5UOy h7Bf1jIx9BURCjvff0N3iZLTAPZ0Z12JKWWKjcJDDQnREHfJIZjSyHPHH57nnWCzjZ7/ oTUt3teBfPob5ktRQsRAVXGpKKqmsTIzrI0AF1cT9YTaJeSlYGExWSk/++50SzBD4sXd QrbQ2caXKlMQvxUSyswTlHEefk+PuspANwV3OkF8TCM/N5OOAnxSxmzu2o8sStc27SGd bEow== X-Gm-Message-State: AOJu0YxPqM7q4SiLCUqLvkF7xpyfmaOMPLg+TE3033sdu0/vmY+Guhaj vlG481g70oT/b/A4FzNfaZhLOiOrrLEA3o2O5SM= X-Received: by 2002:a1f:6d03:0:b0:48d:2a1:5d26 with SMTP id i3-20020a1f6d03000000b0048d02a15d26mr2126287vkc.4.1694593459187; Wed, 13 Sep 2023 01:24:19 -0700 (PDT) MIME-Version: 1.0 References: <20230911131224.61924-1-alexghiti@rivosinc.com> <20230911131224.61924-5-alexghiti@rivosinc.com> In-Reply-To: From: "Lad, Prabhakar" Date: Wed, 13 Sep 2023 09:23:08 +0100 Message-ID: Subject: Re: [PATCH v4 4/4] riscv: Improve flush_tlb_kernel_range() 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, Samuel Holland , Andrew Jones Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 (pete.vger.email [0.0.0.0]); Wed, 13 Sep 2023 01:24:31 -0700 (PDT) X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 pete.vger.email Hi Alexandre, On Wed, Sep 13, 2023 at 9:04=E2=80=AFAM Alexandre Ghiti wrote: > > @Lad, Prabhakar Any chance you give a try to this new patchset? So > that we make sure Samuel found your issue :) > I have given the patches a try and not seen the module load failures as seen previously. I have some rigorous tests which test the complete platform. I'm just waiting for it to complete before I give Tested by. Cheers, Prabhakar > On Mon, Sep 11, 2023 at 3:16=E2=80=AFPM 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 impro= ved > > only if the size of the region to flush is < threshold * PAGE_SIZE. > > > > Signed-off-by: Alexandre Ghiti > > Reviewed-by: Andrew Jones > > --- > > 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, unsigne= d 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 sta= rt, > > @@ -56,15 +57,15 @@ static inline void flush_tlb_range(struct vm_area_s= truct *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 2c1136d73411..28cd8539b575 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 =3D mm_cpumask(mm); > > + struct cpumask *cmask, full_cmask; > > unsigned long asid =3D FLUSH_TLB_NO_ASID; > > - unsigned int cpuid; > > bool broadcast; > > > > - if (cpumask_empty(cmask)) > > - return; > > + if (mm) { > > + unsigned int cpuid; > > + > > + cmask =3D mm_cpumask(mm); > > + if (cpumask_empty(cmask)) > > + return; > > > > - cpuid =3D get_cpu(); > > - /* check if the tlbflush needs to be sent to other CPUs */ > > - broadcast =3D cpumask_any_but(cmask, cpuid) < nr_cpu_ids; > > + cpuid =3D get_cpu(); > > + /* check if the tlbflush needs to be sent to other CPUs= */ > > + broadcast =3D cpumask_any_but(cmask, cpuid) < nr_cpu_id= s; > > + } else { > > + cpumask_setall(&full_cmask); > > + cmask =3D &full_cmask; > > + broadcast =3D true; > > + } > > > > - if (static_branch_unlikely(&use_asid_allocator)) > > + if (static_branch_unlikely(&use_asid_allocator) && mm) > > asid =3D atomic_long_read(&mm->context.id) & asid_mask; > > > > 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) > > @@ -189,6 +198,12 @@ void flush_tlb_range(struct vm_area_struct *vma, u= nsigned 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 sta= rt, > > unsigned long end) > > -- > > 2.39.2 > >