Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1983053rdh; Sat, 28 Oct 2023 16:14:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHaYiW/bOhYpGm9Bb5/3trho1JtgXKAD5D47yBPoVKknrz8PMHh8zYGyR3Cz/5Qqk2tQGFg X-Received: by 2002:a05:6870:11cc:b0:1e9:ba42:76bb with SMTP id 12-20020a05687011cc00b001e9ba4276bbmr6100714oav.39.1698534873404; Sat, 28 Oct 2023 16:14:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698534873; cv=none; d=google.com; s=arc-20160816; b=kBwlFxyGgRZIH6bg/2Bmvors8h/GaJAfVjj7729FBJL0XVUwa/BN7jaMwKeKa/34EE /t3xkHYoyoSuSxGf7WuZLJjYoaA+qLanuIPmUFj+FD76fkb4S7jzBkp5n3BoBrQLeZHP ufR3R6Ewmilkc3im0eL+YGVkergsB/vEs6paoATP6cC/lECQgfHK4a8f/Odkw97aR3Ek GkY9ttqKoD1/IesDbQYSq+5mWBEKa/eZOHy0GWOKx2QQTO8X0zjRX/zUXj2DuKLWlB1t ISykIvO6wN7MJqjZps4rj2yaNIbhZbcdr8bBmsspWU3wB0K+vV39ffx2GJtcSloo7kPM x8JA== 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=h4NRNhpDELMiOf33wYuzLfhwPwCzaIpnJue9EEzIQdY=; fh=9K4IlIICZaNW+K3e6o3g6KPBoLBMkIMAK+rlB58927I=; b=MvXf/n0nYe3F0Q+3q3Bd5qXqxODU4OZODPNPzeYc2drcITna52cyylyX5tRFbTjk1q yVWzLZWYndaWer4g1uSbqlz5shJ3wkde1jzOBFyoGjt3fGiAcWqZ/f8er/U6nMmko8JL zJPy1FWAjSiy5cnJuHrNMtvvN/A4d+fcFQ5dBVE5ao6d/C/BgBw1X32bbPkBm8KqU10F VnLOxgKp8uLYcHmZJPQy7kwvpL4PmZ2BS5CWp1JUCaSk/0AczP2DyyzoFYILJp3f2B+b zuX6Sdp7K0gjA6CYxnT9GgzkXEwlxEnXRn+08p0TQtCRcBMwiyv0mnmYIDqVhkpTIaFi NmuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=cYexk+t4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id t190-20020a6381c7000000b005b8ececd69esi1009885pgd.670.2023.10.28.16.14.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Oct 2023 16:14:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=cYexk+t4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 69E36809659C; Sat, 28 Oct 2023 16:14:20 -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 S229447AbjJ1XNu (ORCPT + 99 others); Sat, 28 Oct 2023 19:13:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229846AbjJ1XNr (ORCPT ); Sat, 28 Oct 2023 19:13:47 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 357D2CF for ; Sat, 28 Oct 2023 16:13:45 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6be0277c05bso2898763b3a.0 for ; Sat, 28 Oct 2023 16:13:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1698534824; x=1699139624; 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=h4NRNhpDELMiOf33wYuzLfhwPwCzaIpnJue9EEzIQdY=; b=cYexk+t4MDdaGS9C/G7GEcnAquNdYT4h4DJmHyfN939k5hS/3v5peyIsTse7ItTDSN 5cWTIjiFsIm23ptts5Lgkq3tYwc3QPfqB+rlm2QlYkLpYd50euh1FI5bLNAUZEKOqKQz g+VQJEeVs6c/2xakEfffs9xVHllio+LN8xZg1LXXcq13pSLHnG6WRXFq0IbJC+f8OSDR PuF9cu8ivJXUaojwfrjg6r/CWH5AF6SebaZ53xIsePzRyPr3ETdf5XZx684Vorh5nD3O 694by1kg720Sz99E7eVFl7WwwwJyGM/rPIeikiGpJXD1raNdsZuNQpEBeXirFExd7alQ Jdsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698534824; x=1699139624; 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=h4NRNhpDELMiOf33wYuzLfhwPwCzaIpnJue9EEzIQdY=; b=QiiTr8WfYK0032zI16vHpynfApRDKZnq4qmYluFbg4XzSmFSLAi0QcalTQoQWJnZJy bVSEzAEN1L0EbSl5AO8LU5hyIR/gALANo+al/+xTlpxORn7vASrYw4uEJntIkDJBnzKU rrzYacQQzaxXWR7dzyM7n16ZxPH3VDWgArgFD/itnaGmH74PRCiWgPeCT9LQ9Xtw+4wi jnJdL52k0qA2aacG+txyIGCgMwZFmTPI8AY2S0hMdThB5cI8g31YvwZJmriOuljp/XTu /8/NB0mjFDZ4TD/O6fujg05KtxJaVlLiKDZIAXaN8it3qruQH8mJZSUfDmqpnm3gzHGS wIZg== X-Gm-Message-State: AOJu0YxGTn4MDkKwcd6wd1tP3gsA16oyJeCV7OPuA32+O9Vp+witCvJ3 +8L9EchMKnBNTS1r0uw/YIit0A== X-Received: by 2002:a05:6a21:3b45:b0:16b:a5fb:eee5 with SMTP id zy5-20020a056a213b4500b0016ba5fbeee5mr5984191pzb.28.1698534824609; Sat, 28 Oct 2023 16:13:44 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id u17-20020a17090341d100b001b8622c1ad2sm3679345ple.130.2023.10.28.16.13.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Oct 2023 16:13:43 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt , Alexandre Ghiti , linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Samuel Holland Subject: [PATCH v2 02/11] riscv: Improve flush_tlb_range() for hugetlb pages Date: Sat, 28 Oct 2023 16:12:00 -0700 Message-ID: <20231028231339.3116618-3-samuel.holland@sifive.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231028231339.3116618-1-samuel.holland@sifive.com> References: <20231028231339.3116618-1-samuel.holland@sifive.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,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]); Sat, 28 Oct 2023 16:14:20 -0700 (PDT) From: Alexandre Ghiti 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 [Samuel: Removed CONFIG_RISCV_ISA_SVNAPOT check] Signed-off-by: Samuel Holland --- Changes in v2: - Rebase on Alexandre's "riscv: tlb flush improvements" series v5 arch/riscv/mm/tlbflush.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c index fa03289853d8..b6d712a82306 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,33 @@ 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; + + if (!is_vm_hugetlb_page(vma)) { + stride_size = PAGE_SIZE; + } else { + stride_size = huge_page_size(hstate_vma(vma)); + + /* + * 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()) { + if (stride_size >= PGDIR_SIZE) + stride_size = PGDIR_SIZE; + else if (stride_size >= P4D_SIZE) + stride_size = P4D_SIZE; + else if (stride_size >= PUD_SIZE) + stride_size = PUD_SIZE; + else if (stride_size >= PMD_SIZE) + stride_size = PMD_SIZE; + else + stride_size = PAGE_SIZE; + } + } + + __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.42.0