Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp259204rwb; Thu, 27 Jul 2023 12:16:05 -0700 (PDT) X-Google-Smtp-Source: APBJJlHJvD/BPzRTbbDw2R/DAlxS7wnRIP+eBlD9bTfq+vb8C9zrD1+fMKlsZaOLfBixZ3l8xsVK X-Received: by 2002:aa7:cf8b:0:b0:522:2aba:841a with SMTP id z11-20020aa7cf8b000000b005222aba841amr2465166edx.4.1690485365508; Thu, 27 Jul 2023 12:16:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690485365; cv=none; d=google.com; s=arc-20160816; b=trJN3CDXwvbURUV74w0oDtDNZAP0GSoGIHkPLH9l14Pwp166LIixRPW/LhURosfqzA iwnCuBZ/ryqM+jcCeoEPs4p3hdSVsR4hU8CjM2f/Z+hCkNzRDYvzPpTMjtihyiiwDQnV UaMfPApjni6Fy0TaR/hHywh7IsdbHfazCYC8Y4vV2AwLFgkxJAMihKpYBdobvTDeb6zU kRJS9n+n/rkAVMdlRQqi+VnNT+mgr2beyY4dYhu1wEoF8oaZSPcNO451RJ0Gp0ohft2S G9gl49JMCKQAFgu0aeHPw76ZL2+FxVLMPTzd4PefclHZtQ2lO7MwSMVbyJWXBJ8Fl2Pd uIpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FofimiyN+7gyzGEdPyrBP2skR/4a1H3RZbKcHwnJwCU=; fh=9KG1GxoJIHO8DA9/W8zOCR/cizSACkxrp9LVRbza3AA=; b=dckl4wHsmfLuYOhKEOmc0pYP6SOJi8TJyCPJ3seal86P+IR7MLrsUoAad2dQh+Pfkz t2V0eCub1VVwUvKpyXhe8ykzB8oP2v1Fb8rGklorSz+GoDQ0yRnNkpyRXyQI+rlwrSMT psKKtx4F9MonfOmuKGGduYEnQHDQKOVKgH9D83ceElbDL51vaVhixp4wflNpChHHR52u gSZeG74GP/r1i1yq3lT5SS+W7alC4TunjM/QRbL+V5XCl04uT+fgiXHRnh+D3/8jf1XA P5OJxrSi7CQ/Ad5+CoyiJH/l4QrQJMBmBeGHMY4mTT4TS6jeJsyGrKdzDpa4sDLYGSD5 cF1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=KnDd+Vx9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x8-20020aa7d388000000b00522584a0485si1395631edq.315.2023.07.27.12.15.38; Thu, 27 Jul 2023 12:16:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=KnDd+Vx9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231744AbjG0S6J (ORCPT + 99 others); Thu, 27 Jul 2023 14:58:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231743AbjG0S6F (ORCPT ); Thu, 27 Jul 2023 14:58:05 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8E1D198A for ; Thu, 27 Jul 2023 11:58:04 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fbc54cab6fso13476795e9.0 for ; Thu, 27 Jul 2023 11:58:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1690484283; x=1691089083; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FofimiyN+7gyzGEdPyrBP2skR/4a1H3RZbKcHwnJwCU=; b=KnDd+Vx9BzShpCRzLQ631/OTf/QgBq8wCBP80Yw1l/syTWuVZd1mFQHnOFb5n/3cyE TukhFMSWwWymirfBGHC3p4wuay/d0DWPZyl+78CJlng2+dz494c+Eglij+K8qqKQf4hv 4/E+Yc7aIpJ5620zW+lx0o7XJTJtyN+voY8PiGKvUEvR8YD0spKu/4+n762sANqG9nlA JGGxpE/z8ULSbOmkC4CA3cHyh0dj8cWRd0GL1Mq0lF97VyP+Af3o43rlpnU8SYmk3Yki Pg0JAmuERUhqze5Ri32pwH1Xujl7bJXT0s3JtHSJ6deEL2dq525vEra8wG4vcpq+deNd BTNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690484283; x=1691089083; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FofimiyN+7gyzGEdPyrBP2skR/4a1H3RZbKcHwnJwCU=; b=LrrU2UNWnUesoxbXqh+qbvt2oFhN4gYsisZIE+Ay2VOit6K+L1Hy+E7m3PaozwwE47 +NptupivYOVCyid4XeWNhcwrJcoKd+Km9cpAIzZOUezFNU2WSitStsnCq4Iw4NSxMOwf k5qAX8UoBowlNY2VODjv+QFw6NddVtOpXP64IgXh4YJzQkQLcomJlOI+0weccsfbG2Lg u1DRtzdKFPUFuGX0Wtb9qplr86nervkpDQRuj++P6YtKkn2r1TEqmC41g9mEABXkE41/ cLTFiP8QlD32mot4sG2+5oALMPDWLIy+V2OgR/TQRGQMPyu7T/kDCqBbgxYQTtZQrnDl rITg== X-Gm-Message-State: ABy/qLZgaRzpovsAw/n4vYz0Q2G77arHSz9M3pqdDJuvdc9vRRPQu3VY 6G7NQxPLFtXYwA5pEY1jzBNTxQ== X-Received: by 2002:a05:600c:3652:b0:3fa:934c:8350 with SMTP id y18-20020a05600c365200b003fa934c8350mr2269763wmq.27.1690484283337; Thu, 27 Jul 2023 11:58:03 -0700 (PDT) Received: from alex-rivos.home (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id a1-20020a056000050100b003141f96ed36sm2840938wrf.0.2023.07.27.11.58.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 11:58:03 -0700 (PDT) From: Alexandre Ghiti To: 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 Cc: Alexandre Ghiti Subject: [PATCH v2 2/4] riscv: Improve flush_tlb_range() for hugetlb pages Date: Thu, 27 Jul 2023 20:55:51 +0200 Message-Id: <20230727185553.980262-3-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230727185553.980262-1-alexghiti@rivosinc.com> References: <20230727185553.980262-1-alexghiti@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 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. Note that THPs are directly handled by flush_pmd_tlb_range(). Signed-off-by: Alexandre Ghiti --- arch/riscv/mm/tlbflush.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c index fa03289853d8..3e4acef1f6bc 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,14 @@ 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_shift; + + stride_shift = is_vm_hugetlb_page(vma) ? + huge_page_shift(hstate_vma(vma)) : + PAGE_SHIFT; + + __flush_tlb_range(vma->vm_mm, + start, end - start, 1 << stride_shift); } #ifdef CONFIG_TRANSPARENT_HUGEPAGE void flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start, -- 2.39.2