Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp916303rdb; Tue, 19 Sep 2023 14:22:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IExvHLi8oH2Pk0BIpJVMXZZcyh3/b0ERy6TNWMi98CHgsPjqIRhzaD9uLyJBjOVo8m6b4qs X-Received: by 2002:a17:902:ab54:b0:1c0:bcbc:d64 with SMTP id ij20-20020a170902ab5400b001c0bcbc0d64mr554807plb.51.1695158556451; Tue, 19 Sep 2023 14:22:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695158556; cv=none; d=google.com; s=arc-20160816; b=sw64Z1SBBb4c3j/GFFtxeQfCeu465rFOkUVnrKo+DA3GZlyEmsT9PbqzzUgDtckXLP dpqZlt2wrxHtVseR7uuW1d2n7XNAZEEhPbSby4Qxn2EH5dn+R+Amm6ropXmgGoAeL4jo ekXpyY9GHNSPRl2/mW5BVu+9Ar+GxwrM95Ip62hJMtfLFRNzAf2z1tIfyL6Kqu+YV8b5 iekBUBZRPXRGg4gZRPgOQJ6uZ5BAgDnCcZBDNWlB0xha1zVQsByYxcqupLny8NSeGt6F NW9wldTNEsPISzW6Qdpv7FTFDRmCqZrP0AXGxxl5RAAtEANCCrTY6xvSLy9n4fb3uOll MsEA== 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=r2iPmpjEwyRg01FPSaJcAL+Fk1h/zdCL91gxz6OrpHQ=; fh=c8XmAFyDXFvO410xILxamWybBQblPbH0CTkpHCRK068=; b=jEOmelv8pBUufIg2kCFDj1JJktnbq0xf43Yyl1h3kSYm2K3I94bujQm5qAQ9OePEa8 qlu76XaCWIYkonGoLPg5yCjjrOjZfgligFeUpa95Ltoez1YqJENOxynK8r+iIGXIWyqa M+OuemRUzSMv5fx/1qzSIhLrK84ON9SgsekZ0Zal++KB2xIRDy/JZHH28/MTQ3QfUsuY XxsA7QnV/IVRPJYCXqqQf9I2MJhkTh3XaUaTXYFnNB1iXdeNWgOg5mtUPDqW3w5jujiS 5Xkd+UBxbShW8dc7bKSmm9YGPdQ9tgJDYttaCn6rrVQ8gwOdcO0+/1E4p7TNYwHGgqqJ Jgng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QRtDcdTo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id o18-20020a170902e01200b001b9d2010c39si10218626plo.192.2023.09.19.14.22.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 14:22:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QRtDcdTo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 8A6C780190A1; Tue, 19 Sep 2023 05:08:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231318AbjISMI1 (ORCPT + 99 others); Tue, 19 Sep 2023 08:08:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229699AbjISMIY (ORCPT ); Tue, 19 Sep 2023 08:08:24 -0400 Received: from mail-vk1-xa31.google.com (mail-vk1-xa31.google.com [IPv6:2607:f8b0:4864:20::a31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49850F4; Tue, 19 Sep 2023 05:08:18 -0700 (PDT) Received: by mail-vk1-xa31.google.com with SMTP id 71dfb90a1353d-495e049a28bso2344995e0c.1; Tue, 19 Sep 2023 05:08:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695125297; x=1695730097; 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=r2iPmpjEwyRg01FPSaJcAL+Fk1h/zdCL91gxz6OrpHQ=; b=QRtDcdTofcZUtiIljqk3fgNdOhbzyePHrSeHB7Uqaeabu3awTy+5kxq2pZN9x4+Nwi C2naV6JB9LGJRR22yGtPF9UBRAfh5y12n12Evwp8e8/aXEr3wmyu8qUEzxSnF9fUEpnM z+cjuXlyFYbkf6iTdFxtpLWfFVOey0Ex+0KTwD3d/C4b0nn92kwEKR3wrOC8kEOHEKgm LJ6+q1ZFM0LiT3wOOFtzlNiLYJoec2R/IWu65N7DNtUdjzkw9SVHsrdydvdoNyeLgHsF Ymp1/fR3ME5lkPBssVkjfY1YVfwCJYtN0sSzLGa0IOpVkSAq6b4t9H0cRJ6nIpaHyEaz AGrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695125297; x=1695730097; 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=r2iPmpjEwyRg01FPSaJcAL+Fk1h/zdCL91gxz6OrpHQ=; b=v9qRWO0bS0ydMeP+jWmAZH5YbWrl5UD/Dp9wLhrl+zUj6jYlTiZEtevf4jS0nVIiHO M5MjnXUQf+IsCqHxl4RPJ7nIl6ZPHrnAdq9Cj27G6JTECiWWJyZ+/hGOziH5oCPtpUs9 B3jZa1WISfgKb4anrMsPoC+5WGqgIuBj1rG9pi0Jt8z1AOV+tRHPdu1wqSwogRDbvcdM 1a0VwTaaMiCdshOSfD8OdE0LRWfFR+L/QEgD464+MRJVMOCC+gBUnCkvqCZXBHznpM09 zMQhBilfaOFMCT1EtK0n7F6djWWLmZijjGqLt2Irv9pV8kulMo8fbwWpcJJePF5YgqJk ca+Q== X-Gm-Message-State: AOJu0YxrKghN8C74GKO6VHQ03JUS7DCoiACZgPeZJsgHamQgSGWxrKMu AO6eKcJZOayQw+6S2NSDbBQAWUxSlXm6oYdaCfE= X-Received: by 2002:a1f:cc01:0:b0:48f:e2eb:6dd9 with SMTP id c1-20020a1fcc01000000b0048fe2eb6dd9mr8987999vkg.8.1695125297222; Tue, 19 Sep 2023 05:08:17 -0700 (PDT) MIME-Version: 1.0 References: <20230911131224.61924-1-alexghiti@rivosinc.com> <20230911131224.61924-3-alexghiti@rivosinc.com> In-Reply-To: <20230911131224.61924-3-alexghiti@rivosinc.com> From: "Lad, Prabhakar" Date: Tue, 19 Sep 2023 13:07:51 +0100 Message-ID: Subject: Re: [PATCH v4 2/4] riscv: Improve flush_tlb_range() for hugetlb pages 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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 19 Sep 2023 05:08:34 -0700 (PDT) On Mon, Sep 11, 2023 at 2:14=E2=80=AFPM Alexandre Ghiti wrote: > > flush_tlb_range() uses a fixed stride of PAGE_SIZE and in its current for= m, > when a hugetlb mapping needs to be flushed, flush_tlb_range() flushes the > 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 regio= n, > all PTEs that constitute this mapping must be invalidated, so the stride > 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(-) > Tested-by: Lad Prabhakar # On RZ/Five SMARC Cheers, Prabhakar > 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, unsi= gned 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()) { > + 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) > + 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 start= , > -- > 2.39.2 >