From patchwork Thu Jul 27 18:55:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13330587 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7FDEDC001DC for ; Thu, 27 Jul 2023 18:58:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 26C196B0072; Thu, 27 Jul 2023 14:58:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F5BF6B0074; Thu, 27 Jul 2023 14:58:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0BDFE6B0075; Thu, 27 Jul 2023 14:58:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id EF3D86B0072 for ; Thu, 27 Jul 2023 14:58:06 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id CB4CA4056A for ; Thu, 27 Jul 2023 18:58:06 +0000 (UTC) X-FDA: 81058301772.07.7DA59B9 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) by imf03.hostedemail.com (Postfix) with ESMTP id CE21B20005 for ; Thu, 27 Jul 2023 18:58:04 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=KnDd+Vx9; spf=pass (imf03.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.50 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690484284; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FofimiyN+7gyzGEdPyrBP2skR/4a1H3RZbKcHwnJwCU=; b=FRZQrVy70MAFbqjyY7CJDMnV/RExFN8e6TE/qIHKrkn0Wa9hBK7mXET3LRthFk8LFy1ghv wVESfN29G/6q8EB9pSJpFR3GGG7HBntgziIWVciJshtV0HfuyKmsL0vKUYENisWUPf23CD h8gtYcLDT8DDVJqAXJT09Fz85cSuHv8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690484284; a=rsa-sha256; cv=none; b=pk/jyDOt1A25lNsVnvjGb3/iNB6P8xLxSUuCGlb+rCaVXr94i6FrnrjnOZAQBo1WZlQcF2 qK3mi9+YfpNGDb2/kmPMYOPEgb+H4ov3ZYtxmEZm0qWd/xh+hFsRgZZ4Coob1+u94rsdD3 Eb4edqHBvrQYuYkw+B3aPO25wNI956g= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=KnDd+Vx9; spf=pass (imf03.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.50 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-3fbea14700bso13225055e9.3 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=MQdSq8kPdfqp3GPTV/9SGZGQWjJk8JTKNRRnGDMwUYW226YVi7nRmIwf7dDOe7qOzP 57/SUSu7EDBakwszuvH3ca7yql1iY9mkUbW+5rq+AfJIZt7k259ngnoJ1k4P6JlQ7cjz 1/4cWRJM6MdLfwDjOjpLYPhUe3RmPe8VrQLf0F+Wum7HcFT+H2Xe5aEZwvdF1JexFDMk cgsu/CXkOTDUx/diyMAGcjJ56jvC4Z8YlDceIHpyf9VcryKunS1X0G+6FRYF1oIpU1NT Qgmd9t7ZNETDdIJcOxZHViK6T0f1HrvM4ByPcTE6s8B0YPI/ryuABoR8dURUqdtEd7gh WqEQ== X-Gm-Message-State: ABy/qLYN1mR0CYMmyXhaRo8e0jSPW7bZAI9RwMBuwQJWQXvbXeuojx9Q qTVlm64kuQh+VU3DLxnQLd0wZg== X-Google-Smtp-Source: APBJJlE5yuP6dOyuWEfbshqESX2eaPb5FXyTM6wUkhll2KdkxuRc6Y2JvvBqcbIkk0EYV+e5ssUWbw== 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 X-Rspamd-Queue-Id: CE21B20005 X-Rspam-User: X-Stat-Signature: e63iocgeny4bwmypydajt5y8amhpaqx3 X-Rspamd-Server: rspam03 X-HE-Tag: 1690484284-811590 X-HE-Meta: U2FsdGVkX19HaklObAFCV48bCCZMTDCzGhyuOs80qo9fGc6K4m/m9o4W5fY0XarLhQGBLJjXGRULjPFmLJa3+uZZ0hPPJxmtW+UrCgyTfJN9ujY1YpDpBrz9Gui7Ehxi6afRMHI+PLm/CrEiS8SsB8nJdifaduWDhAF7sTttDCq8C2aIr0IKhh2aE65GsYk+HVU6t6JgGW4ooQYnqrBixK+Q7jCD/kfLmafcBUd6/VDCrxLUnWt2TOc9h0Ip68BEmGcHawyiczgj2rXzuL7E2bRJ/QgZF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opzUchSaZWdA4x5BBSy2MbBD9sn39eXnQoEBpdFSTvnFXtvu8zGZg+S+aPZvx2yLeX6QNLxRpV7i4KZswRzgQ3/QE9Zo2gXUZg+azpXUkWEIUgwIpsN6Y4/aJ4Yr0dajnPQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Reviewed-by: Andrew Jones --- 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,