Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp2378336rdh; Sun, 29 Oct 2023 13:18:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG5edOXp8yI2NUg0K1YwNKkAQJrjAIbu00Vgw+SahfbtACSpgVTowj/KFxmGiqHQSzYVYle X-Received: by 2002:a17:902:dac4:b0:1cc:51b8:80f7 with SMTP id q4-20020a170902dac400b001cc51b880f7mr194700plx.26.1698610693274; Sun, 29 Oct 2023 13:18:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698610693; cv=none; d=google.com; s=arc-20160816; b=iNrdEwb6z82sZQa2ZYjVsMygT54OJpeNFCBzmb2CoyT2183bs8Bb7flgJUQyD+OgIp 6NUHhWeTmcImn5QnHgGH3ytTNua/ikn20Hs8534AeOfMXWCBlJEdtCXGbbz6GriSKu8Q aSrvFfo1KY83DE4ZpnhEFzIq9p4xm58PtlzmY15ozoN5/x+fqicDOLtNtJuWF+R8FoOL deZ1Hz66CXdepkpeGeVDb0yDT7K3bugbyIKP8OuJq7D0vZ6iWFfE+ftDahByTzbxt+Mt 5PBEHzL7OvknRvPuJVVgGcDiWTmdFqfIB7HgpIA8rx5hTJ8lW7QmRpiRxW/j+lZwT7M0 bVVQ== 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=qknPkF/GhioNTqsfL8PFnCh2jVNaQR/cXCoqmSLii5U=; fh=oMu0fTmnArTBDK8jl03IHOdnhjX9vbR80J2+6eqAYMw=; b=W+mPC2ab5ypCrxKbmSY54sSRPqtiMWuglhUXndhRmvKsc393JZm9g3t4kMTUQthLCD nKnsRg/8ROqmy3hWndeYHIjXdwhLY3RG6Evnvtk3+JMAu7uWcn6nlIW+QoAbS0Oa54Yk xK3OCY00xw3ZpdI2mhphS49XpMT0mumyxnz8ue71jW4B1f1zUpqeQXnb0VLxNl+dIpj+ Zb+tBYizBjSGjU4CRsQDYe88tx7ZoH5/jY0T2IiIBNyGNUOLIeZktCY2bZz9OtU+EUkU PQB/JsCjgfw4MTXWijo6cEYrcQZs4gmPsn/ko2cERU7QN8zLUuLwZlZ357CumZNLgbza vHpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Z9OAnama; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id q17-20020a17090311d100b001c7347e993esi4110880plh.17.2023.10.29.13.18.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Oct 2023 13:18:13 -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=@gmail.com header.s=20230601 header.b=Z9OAnama; 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; 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 groat.vger.email (Postfix) with ESMTP id E23108076E63; Sun, 29 Oct 2023 13:18:10 -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 S230145AbjJ2UR7 (ORCPT + 99 others); Sun, 29 Oct 2023 16:17:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229778AbjJ2UR6 (ORCPT ); Sun, 29 Oct 2023 16:17:58 -0400 Received: from mail-vk1-xa2a.google.com (mail-vk1-xa2a.google.com [IPv6:2607:f8b0:4864:20::a2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8EBBC0; Sun, 29 Oct 2023 13:17:52 -0700 (PDT) Received: by mail-vk1-xa2a.google.com with SMTP id 71dfb90a1353d-4a8158e8613so1519222e0c.3; Sun, 29 Oct 2023 13:17:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698610672; x=1699215472; 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=qknPkF/GhioNTqsfL8PFnCh2jVNaQR/cXCoqmSLii5U=; b=Z9OAnamaTVxuXra/pe9fhAzYBshFIaCM+iras58b9g5+2cEnmoPZ+RR8ARDGBurSRS itJoKxwIsUkLp1KsNOV3IX+hhuAdcQ9LXGAQ1PkpRqz1dYLimNzZnewG5WRkIQgOXMK2 6717RtEhQy317zQggd87hh0+mLSyv8+SPEn7uegjmdFDopywGD/t4G8S2oAzb8a+SWDp GmZOBOD/YdmYyugAK+8MTEV3Xb4UlVQqUwNhdhoy1HylhAJCQcEJCKc3Mgc2+bTPKc8s 1PNMcAySOESJTp47Z1lbKy5ByHMXkUcf/OQcHhSP1YQUfBoUIabER80NsTsdSHXg9Nam +a/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698610672; x=1699215472; 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=qknPkF/GhioNTqsfL8PFnCh2jVNaQR/cXCoqmSLii5U=; b=UMI0W+Gb963cUxik2VxgQn8KkaZofbKK4nFTRKlna6jW1o6DiGzW8d4BksKk+Js9uM e4YUHBdOuYMhnLSsQc2qqKZCPxIW+doG/NP6h8TFzt/EAgb0b1unsRzILvrNpciDjhsJ qR9aJcb5WWGNZC5XVT/dNyzkJrsGFbn3TV7qkqhYaC36J+PmgE1JJbF35k4jSBjFyYSR 8PyS8NfdIY1fuojNCK682+7p9ia+toSpSjKkxx3zzPoJEil0tXHN1mdVydInLYYX8gBy Z/knsQrr7fkergb869xkBNp5mM29xkg21qU6RPc7StOaufvLzLnWoQKVIM6oRWUm2fxl 56DQ== X-Gm-Message-State: AOJu0YyJQv6PbJ656WLJXKUgQ8FRAve1KEB4+b2LzU3WS03+YO+NuHlz 69gUuj+rqN7mcJ7ZFVDJxl9cXom36tQEkMdrnlU= X-Received: by 2002:a1f:ad04:0:b0:495:cace:d59c with SMTP id w4-20020a1fad04000000b00495caced59cmr6820612vke.0.1698610671799; Sun, 29 Oct 2023 13:17:51 -0700 (PDT) MIME-Version: 1.0 References: <20231019140151.21629-1-alexghiti@rivosinc.com> <20231019140151.21629-3-alexghiti@rivosinc.com> In-Reply-To: <20231019140151.21629-3-alexghiti@rivosinc.com> From: "Lad, Prabhakar" Date: Sun, 29 Oct 2023 20:17:25 +0000 Message-ID: Subject: Re: [PATCH v5 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 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]); Sun, 29 Oct 2023 13:18:11 -0700 (PDT) On Thu, Oct 19, 2023 at 3:04=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 > --- > arch/riscv/mm/tlbflush.c | 31 ++++++++++++++++++++++++++++++- > 1 file changed, 30 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..5933744df91a 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,35 @@ 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; > + > + if (!is_vm_hugetlb_page(vma)) { > + stride_size =3D PAGE_SIZE; > + } else { > + stride_size =3D huge_page_size(hstate_vma(vma)); > + > +#ifdef CONFIG_RISCV_ISA_SVNAPOT > + /* > + * As stated in the privileged specification, every PTE i= n a > + * NAPOT region must be invalidated, so reset the stride = in that > + * case. > + */ > + if (has_svnapot()) { > + if (stride_size >=3D PGDIR_SIZE) > + stride_size =3D PGDIR_SIZE; > + else if (stride_size >=3D P4D_SIZE) > + stride_size =3D P4D_SIZE; > + else if (stride_size >=3D PUD_SIZE) > + stride_size =3D PUD_SIZE; > + else if (stride_size >=3D PMD_SIZE) > + stride_size =3D PMD_SIZE; > + else > + stride_size =3D PAGE_SIZE; > + } > +#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 >