Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3728339rdg; Wed, 18 Oct 2023 04:33:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGcBn0UguGFJQl2k72aonvDdILcLvmQyZwltCuu6716EUEgpB/SAJo/n+4RHyUgo4wdZmJ0 X-Received: by 2002:a17:902:db0b:b0:1ca:87a1:cdf1 with SMTP id m11-20020a170902db0b00b001ca87a1cdf1mr6002330plx.27.1697628804784; Wed, 18 Oct 2023 04:33:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697628804; cv=none; d=google.com; s=arc-20160816; b=x1VtNlRID06W5q6n0/cyhXoXzCrLpkqfTHVXNkHNrSFqUwiUlkOy8B9sqMqPTHB1YO RqecrAdyosfnA8CHkP6os7wLsPyWTESZ/KFlsSSH/9ukefRuqwBihmXUKfTk82JXSBB4 ueFNhkdNowQ941k1354WA19RTJiW36jwN2vDgyuQora/BYxbSEbN3apip8UzXWXKpswg 1ngGklRB1oAHzjt7j3eFRkVJjaibuMao+XUI/0JkxBfWdWbWxB2RpIpSjTkiDJkJV5WD /901mOpdqW+TNInTryyjVBXtgJ00HVTTxpBFdOv7j3eZU8ac6ETSUSeLrp6mmEeRXy96 Ugig== 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=ZHg4mM71KXb5DEEj0eqsenmzI1spOu0jlYYbZtbcLDI=; fh=fdXw2BUuYdbIZ+UzkvOUlmq84Ghb45HBZI0KkPpcEn8=; b=woC6DHBQsHK2JcH3mUUHHjewtA73lbgFuEDee5KHMGTTMe7a+2BQpzhFZqM8jqxQFI bgE8efX0FxkEkCiIRnHhz9J4tAw+5DSJiuaB2PX3Ey5quljpHs4DHpC3DZZ0aKxyyXR+ tAJuXik7uk+/H8Y79R2F6cjIcqr0MLfn2rM9ebgPN2uPOmebUPixU/mJHidpYq7FVdnw iEYXEBQTvhLySfjHOVDaViaXHOXhDYBQaEvmfzDWJHsXU339yoHn4qokqNJNNoQVlDH+ QFM2tqxz3+s+6o8akeFtaLLEYkGK4jrlAJUGO5HmUWK7U5yLBEyBYIsqGtuYcrRS/Ap0 N28Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=Rb7AoKmq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id b3-20020a170903228300b001c32fe6cdf9si3898034plh.386.2023.10.18.04.33.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 04:33:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=Rb7AoKmq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id E28BF802AA28; Wed, 18 Oct 2023 04:33:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231208AbjJRLcr (ORCPT + 99 others); Wed, 18 Oct 2023 07:32:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231189AbjJRLcn (ORCPT ); Wed, 18 Oct 2023 07:32:43 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88870189 for ; Wed, 18 Oct 2023 04:32:37 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-317c3ac7339so5827089f8f.0 for ; Wed, 18 Oct 2023 04:32:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1697628755; x=1698233555; 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=ZHg4mM71KXb5DEEj0eqsenmzI1spOu0jlYYbZtbcLDI=; b=Rb7AoKmqxPkjisuOjJrROZLZW3sWUFlo5t7cigeAb2dy/ppJTK0m1R9yMnT43yYgha D0IhrtQJP2EffAqOHDZYg/PHvFWPMi4tX3WePuZBR+nHSS3wL7KYgENIqtZjfCoUI1rS gW51HnDaskOiPkisgvUHVhkj3yf0ryKsomGKULwHDEm5hTcs3Yd1twFYMqCNyqoCzGrL kIPH3uagFtsCMSSODSLkUY1UqLKY0o0f2MCdPu8Q4JOvcboaiZHpZrSjuZN918DY6Vsr 8cDAw3aNbmggm1FYCyruT2uZeHaB418jtxTuKi0t52aIFtWIIkFBwUOm1pyb7/LWang+ 23hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697628755; x=1698233555; 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=ZHg4mM71KXb5DEEj0eqsenmzI1spOu0jlYYbZtbcLDI=; b=wO1fWENimaBunt02sYWeTYFu+qNOyzuAhs1roij2ryKK5Pl4QwHXvarAyx8d3elVTx jG+EnBWK/0DldoXYCcdxWu9QOMLEFIOiarBAuqGY7p+TzBA/9Td2FEY+vgKLq0FRoTbr McvFs67bbbZV6PcT1ZmAuweV27Vksy344Zdl5PP+t9x/JGjOq3jCnMeYYhx3y75K56Qv 7wupWJj0aoimZ059GKiDZGEWU6x/dctWr7KmHmFs8xoJgLMw1cG4sy3bzqeJE+ji1DGo 6PauVTxunl6APOON7/4VOFGmEmxi9ZMnnz8VMqAe53/tBj8Farwziv9p/MRUWxE7vS4s +dAA== X-Gm-Message-State: AOJu0Ywcq8NfFm0EVUA86hZCgCPmfqevYmTLeyA7ui+H7KTOuO3UTcth jm4dJaORQ9f/fMz4u0diSlV7LpbhfRpWF1mT6e3NiQ== X-Received: by 2002:a5d:668d:0:b0:32d:9789:6066 with SMTP id l13-20020a5d668d000000b0032d97896066mr4216230wru.5.1697628755552; Wed, 18 Oct 2023 04:32:35 -0700 (PDT) MIME-Version: 1.0 References: <20230911131224.61924-1-alexghiti@rivosinc.com> <20230911131224.61924-3-alexghiti@rivosinc.com> <79d8ca23-478d-4f88-afb3-343a85ed0fe6@sifive.com> In-Reply-To: <79d8ca23-478d-4f88-afb3-343a85ed0fe6@sifive.com> From: Alexandre Ghiti Date: Wed, 18 Oct 2023 13:32:24 +0200 Message-ID: Subject: Re: [PATCH v4 2/4] riscv: Improve flush_tlb_range() for hugetlb pages To: Samuel Holland Cc: Andrew Jones , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 groat.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 (groat.vger.email [0.0.0.0]); Wed, 18 Oct 2023 04:33:22 -0700 (PDT) On Mon, Oct 9, 2023 at 7:53=E2=80=AFPM Samuel Holland wrote: > > Hi Alex, > > On 2023-09-11 8:12 AM, Alexandre Ghiti wrote: > > flush_tlb_range() uses a fixed stride of PAGE_SIZE and in its current f= orm, > > when a hugetlb mapping needs to be flushed, flush_tlb_range() flushes t= he > > whole tlb: so set a stride of the size of the hugetlb mapping in order = to > > only flush the hugetlb mapping. However, if the hugepage is a NAPOT reg= ion, > > all PTEs that constitute this mapping must be invalidated, so the strid= e > > size must actually be the size of the PTE. > > > > Note that THPs are directly handled by flush_pmd_tlb_range(). > > > > Signed-off-by: Alexandre Ghiti > > Reviewed-by: Andrew Jones > > --- > > arch/riscv/mm/tlbflush.c | 39 ++++++++++++++++++++++++++++++++++++++- > > 1 file changed, 38 insertions(+), 1 deletion(-) > > > > diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c > > index fa03289853d8..5bda6d4fed90 100644 > > --- a/arch/riscv/mm/tlbflush.c > > +++ b/arch/riscv/mm/tlbflush.c > > @@ -3,6 +3,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > > > @@ -147,7 +148,43 @@ void flush_tlb_page(struct vm_area_struct *vma, un= signed long addr) > > void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, > > unsigned long end) > > { > > - __flush_tlb_range(vma->vm_mm, start, end - start, PAGE_SIZE); > > + unsigned long stride_size; > > + > > + stride_size =3D is_vm_hugetlb_page(vma) ? > > + huge_page_size(hstate_vma(vma)) : > > + PAGE_SIZE; > > + > > +#ifdef CONFIG_RISCV_ISA_SVNAPOT > > + /* > > + * As stated in the privileged specification, every PTE in a NAPO= T > > + * region must be invalidated, so reset the stride in that case. > > + */ > > + if (has_svnapot()) { > > This whole block should probably go inside the is_vm_hugetlb_page(vma) ch= eck, > since we have to perform that check anyway. Yes, you're right. > > > + unsigned long order, napot_size; > > + > > + for_each_napot_order(order) { > > + napot_size =3D napot_cont_size(order); > > + > > + if (stride_size !=3D napot_size) > > + continue; > > + > > + if (napot_size >=3D PGDIR_SIZE) > > Can you check stride_size here directly, and drop the loop? We should be = able to > assume that the huge page size is valid. Non-NAPOT hugepages will hit one= of the > equal-to cases below, which is fine. Yes, again, you're right. I'll respin a new version now, let it go through our CI and send it tomorro= w, Thanks, Alex > > Regards, > Samuel > > > + stride_size =3D PGDIR_SIZE; > > + else if (napot_size >=3D P4D_SIZE) > > + stride_size =3D P4D_SIZE; > > + else if (napot_size >=3D PUD_SIZE) > > + stride_size =3D PUD_SIZE; > > + else if (napot_size >=3D PMD_SIZE) > > + stride_size =3D PMD_SIZE; > > + else > > + stride_size =3D PAGE_SIZE; > > + > > + break; > > + } > > + } > > +#endif > > + > > + __flush_tlb_range(vma->vm_mm, start, end - start, stride_size); > > } > > #ifdef CONFIG_TRANSPARENT_HUGEPAGE > > void flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long sta= rt, >