Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2053551rdb; Mon, 9 Oct 2023 10:54:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGdlfGWNG4XITjt/JltVI9cxIESAZ6Q3Pe6nMK2dpoZRPqOuOBlBzVvWISK4NgLGf8BsTWA X-Received: by 2002:a05:6358:4429:b0:143:4b0a:5f20 with SMTP id z41-20020a056358442900b001434b0a5f20mr12619890rwc.29.1696874050969; Mon, 09 Oct 2023 10:54:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696874050; cv=none; d=google.com; s=arc-20160816; b=OYx+3P+I3mlTkl5qI8l4+ijjugzo8Q7IF3s6C78Vt6HTZSyJ4ZmlqAZsQoCqSR5OfL O/KulFfjbStDPxxvEjxjtcfWaizwp8XdWVe+xI9iuiaX8EWsxAR1YKnZQkqYwLj+0c57 v/z0NDUX3yVuGAzI9Zhy14ORgzcn/kXOon1KCP+m+vTrmWjjIdb38IQ+u17fvh9ZWjc0 /VJltIC1oItdBwq8btbh4ZQ/Ik5UOw5++yPYibQxl1AHHY8G/3nUnE+x6bCgXZOS9O7T PubqnlRkZQr9RBQJjKhD/agDe98SHRBAnnxc6Oj94silkBTPFqsgUrTOtksvCpXHxHA/ ixxw== 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=/5YUwrppm/AoYHUPSKvRLI3OIQ5ZsMP8vebRQ0LmXCY=; fh=51rR4qhGrYiduECZyFD8g6KgLvkgq5qU0ylVkeOcF0M=; b=OHvyCevpIEkLa0UJ52Txn9cWsu/eQx27ay3nkDsYhKDUFI8IauJkJUAlXGUk6VDs/+ OHUXxqAdLBBVEPu8ca5yWHUobPkLf6Ylg5CTqgu2SIhu8bNfq6Ct33belRv+igqe/UeZ TXX821xP3vq2QNV88N9J8IV3/s8SAmJt6ZdvsslNcYLC7vyNvQl0QtSNO6kMskqMUysE 3D5ZDI9x8Pe4F1XpgBFHcrzH2bx04RQiiIhp84iXdccKGkR3EHel4G7W3IYVUgBuJIWD ktUwNlEDX1nCJXSbBYw4HmFCwfHPErbzKQH/jlmUTKDjzgrWCmCojghm4pSGXytslwB/ 7ZAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=DEsgq4bC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id b75-20020a63344e000000b005578c6a7672si10408039pga.90.2023.10.09.10.54.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 10:54:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=DEsgq4bC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id F1BC88039FF7; Mon, 9 Oct 2023 10:54:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377360AbjJIRxu (ORCPT + 99 others); Mon, 9 Oct 2023 13:53:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234538AbjJIRxt (ORCPT ); Mon, 9 Oct 2023 13:53:49 -0400 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F20F4C5 for ; Mon, 9 Oct 2023 10:53:46 -0700 (PDT) Received: by mail-qk1-x735.google.com with SMTP id af79cd13be357-7741c2fae49so318486585a.0 for ; Mon, 09 Oct 2023 10:53:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1696874026; x=1697478826; 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=/5YUwrppm/AoYHUPSKvRLI3OIQ5ZsMP8vebRQ0LmXCY=; b=DEsgq4bCSpn6QYrMRn1iL2MelRde9Sdwl4y6DRp9x7fl5c5LL9yvDvHtpoVhY5MWDI fAXj5+vKCej8/JSqIklOO6ga+nQppZ0i+QQzaypYevORPW9jhePNtE2LBJUHh21U6uIr 8qnZtY97/HJr1+x4nC/2ium3efbjVztn5z8gZghobiZ/buirr5r4SZSJGrFq9PeImTzQ IUPGXNClcvwbs2aPIkfOl2EJ/jbYigBji5c2RdoEGO31He5bFb72GIH8JB3qQGJUtf6R RBCmv9+2Ydx3LdmCpfbguQ8kYSO0GOWhcxEKWkNo2tAaYPFS8k7Q0hw7bYHDnMZv82Y8 IR6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696874026; x=1697478826; 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=/5YUwrppm/AoYHUPSKvRLI3OIQ5ZsMP8vebRQ0LmXCY=; b=XbvjSMINl5x2vNslMIxxsJ2zvHBBrR6DVUPmkDuLmB+HLOaxep/zKWkiku/w3FDwvP +5enokP8RPytmGyn/VS6C6KRf+Fw5IKn79B+PVdI4VuRX+uXDGEMBtVKX8ivL3PLau31 Dw8JZEbW60kK92qU2enxEkzqzLZ0P2oTWIhaZUDJ63T0BqAkXUx+3Wdr+Wggg3ff+Xu0 Y/PnfSfmnsepi/bLLETcZLCQiVRWLkvmDk7+C57VBDEQP+S1x6P/Hgo2BQt38++CZPg9 a8AHFVoWchiw0lek8f//n0O3hG0BIwU5Vl70YuuhrlQ7R8egJu8plUv62ZyB/QQ3mldQ X+pQ== X-Gm-Message-State: AOJu0Yyfk8yyw0BSYKf7MzfOrs4lwIHEcLOtmEzfZEmgEnDmU0WJPRXK fhqMKxRmJy1Fjxlbi5tVrX0q4A== X-Received: by 2002:a05:620a:1a89:b0:773:a83f:413c with SMTP id bl9-20020a05620a1a8900b00773a83f413cmr21902058qkb.30.1696874025984; Mon, 09 Oct 2023 10:53:45 -0700 (PDT) Received: from ?IPV6:2600:1700:2000:b002:41c4:1832:a984:34e2? ([2600:1700:2000:b002:41c4:1832:a984:34e2]) by smtp.gmail.com with ESMTPSA id f10-20020a05620a15aa00b007659935ce64sm3681308qkk.71.2023.10.09.10.53.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Oct 2023 10:53:45 -0700 (PDT) Message-ID: <79d8ca23-478d-4f88-afb3-343a85ed0fe6@sifive.com> Date: Mon, 9 Oct 2023 12:53:44 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 2/4] riscv: Improve flush_tlb_range() for hugetlb pages Content-Language: en-US To: Alexandre Ghiti 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 References: <20230911131224.61924-1-alexghiti@rivosinc.com> <20230911131224.61924-3-alexghiti@rivosinc.com> From: Samuel Holland In-Reply-To: <20230911131224.61924-3-alexghiti@rivosinc.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Mon, 09 Oct 2023 10:54:06 -0700 (PDT) X-Spam-Level: ** 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 form, > 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 region, > 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(-) > > 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, unsigned 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 = 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 NAPOT > + * 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) check, since we have to perform that check anyway. > + unsigned long order, napot_size; > + > + for_each_napot_order(order) { > + napot_size = napot_cont_size(order); > + > + if (stride_size != napot_size) > + continue; > + > + if (napot_size >= 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. Regards, Samuel > + stride_size = PGDIR_SIZE; > + else if (napot_size >= P4D_SIZE) > + stride_size = P4D_SIZE; > + else if (napot_size >= PUD_SIZE) > + stride_size = PUD_SIZE; > + else if (napot_size >= PMD_SIZE) > + stride_size = PMD_SIZE; > + else > + stride_size = 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,