From nobody Fri Dec 19 04:03:15 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9799CCA0ED0 for ; Mon, 11 Sep 2023 21:48:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351652AbjIKVn2 (ORCPT ); Mon, 11 Sep 2023 17:43:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237822AbjIKNOg (ORCPT ); Mon, 11 Sep 2023 09:14:36 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E293EB for ; Mon, 11 Sep 2023 06:14:31 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-31f7638be6eso3657658f8f.3 for ; Mon, 11 Sep 2023 06:14:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1694438070; x=1695042870; darn=vger.kernel.org; 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=jTDHLs2EOQtTQ3uvgmHng/nVHNHrVDMEJR/1UpGvkHQ=; b=ih6fPiRWhM99VrBO0xtdVabZtcF3TW2H5hp05fL/b+8o7zmdj83CqaYN2x10JxMXGQ 7qIufL1278dXyWIQSCiNclIAWyM7CMI+iwzTWyMK/0GoB09o48J1og4BNFBoEJV/A448 PkJUR4EnjhKvJewbs6znbbNEA4xXzf2bgInHzCxXydQXHghG7GphlssY0V4aYLMqdPiA tstIjQqVGnOJ2OT6SDXnWvdZmG715KT2fN5tUVUOxVqXaSlqmK3lfoFUzll/lnnaMMBS K+fPXmwlJzxH57ElatLF6llJ55HbJJowhI2kQqyyF2Tbb0t+j6rghUXlDvscOrKHdCUZ eBOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694438070; x=1695042870; 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=jTDHLs2EOQtTQ3uvgmHng/nVHNHrVDMEJR/1UpGvkHQ=; b=pNlkPgwZ4ea9ScHxk5iq8uLB5gFvcmvhIowIQT6wHENz2sR+d77up15Eyk4ZXIm2CQ F2zPUN/U1ForeJn64hD+UkobEjphftf0DXZJ6tuP3gS2touATLKfC45rlnqq2PDxV+lO c4s/LuCD1bpeV6u//ODaA9qOwgFT07WKeJUIVRBJDM9MYfS5rcbybOUVGpgNtz98YW9o R0OJwPvvFoP9PuK3VtATQGBtqr3F3uQhJDNtPZ8DZYumNaSPWQc8Fuln/B8aXpkWpYra 6eoHg8nEfH5xdaNtpnkZCyU5qBgRCwZSgkQOCRHcNSNuW+VkIr85gnsXuszmGyDIWzun iclw== X-Gm-Message-State: AOJu0Yx/SCrtNS3EkbWOTLpECYGSancdiZw/Oiyg3zEttBJMknosserk 2HzIcuZ+qVAxvMMbfee9TR3ouw== X-Google-Smtp-Source: AGHT+IGYcFnpNiP+FLLZHYSCC5nHXUyn1lvxXozVLynaGkKKRW3cVE8D6L3lkbbcr2jik100ZVPpZw== X-Received: by 2002:a5d:6510:0:b0:317:ec04:ee0c with SMTP id x16-20020a5d6510000000b00317ec04ee0cmr8022431wru.47.1694438069661; Mon, 11 Sep 2023 06:14:29 -0700 (PDT) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id v11-20020a1cf70b000000b00401d8810c8bsm13230128wmh.15.2023.09.11.06.14.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 06:14:29 -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, Samuel Holland , Lad Prabhakar Cc: Alexandre Ghiti , Andrew Jones Subject: [PATCH v4 2/4] riscv: Improve flush_tlb_range() for hugetlb pages Date: Mon, 11 Sep 2023 15:12:22 +0200 Message-Id: <20230911131224.61924-3-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230911131224.61924-1-alexghiti@rivosinc.com> References: <20230911131224.61924-1-alexghiti@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Tested-by: Lad Prabhakar # --- 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 =20 @@ -147,7 +148,43 @@ void flush_tlb_page(struct vm_area_struct *vma, unsign= ed 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 NAPOT + * 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, --=20 2.39.2