From patchwork Thu Oct 19 14:01: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: 13429274 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 B74F3CDB465 for ; Thu, 19 Oct 2023 14:06:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F46B8D0097; Thu, 19 Oct 2023 10:06:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3A3E78D0006; Thu, 19 Oct 2023 10:06:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 26CA58D0097; Thu, 19 Oct 2023 10:06:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 16A578D0006 for ; Thu, 19 Oct 2023 10:06:18 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E84CD1CAD1E for ; Thu, 19 Oct 2023 14:06:17 +0000 (UTC) X-FDA: 81362385594.06.3430C3D Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by imf29.hostedemail.com (Postfix) with ESMTP id 05F8A12000D for ; Thu, 19 Oct 2023 14:06:15 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=GAA2WsRh; dmarc=none; spf=pass (imf29.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.52 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697724376; 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=kwR/Ke20NAcUS81IhTmctZxyEuc+6gPtGwlWuG8Kglw=; b=5a2eDOk7JdmA7poqRu+0ETRyUxA0bkOMPUbPovCdn3QxuZgA2MRAwjMoH7uaS0wINFP+34 IStygt2GuSYr0W1zLHHKfIXHdUKZaMiNIELsAjV+UbbPkaQeVHLlncDkMcZptya7jQeL5M bTjhtj1ISMUdtN9Kvwv1UiGrQ6d3sTc= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=GAA2WsRh; dmarc=none; spf=pass (imf29.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.52 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697724376; a=rsa-sha256; cv=none; b=XxJANJS302/bmEPRso7gHM0uAKZcX8bCdf0rwI4Fe/jVrUaYGUONNFzxh4o9EUcKhAkl7R C0uqpT15ay5dDAeupmcTpjRGnpGCWbySn6caUOuyNP20zcxvXAz8jKez0rU+qQxT+e+RC3 xjZ7qPce1OIAtSWUF1zG7UzhqgGTzIs= Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-32d9552d765so6219070f8f.2 for ; Thu, 19 Oct 2023 07:06:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1697724375; x=1698329175; darn=kvack.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=kwR/Ke20NAcUS81IhTmctZxyEuc+6gPtGwlWuG8Kglw=; b=GAA2WsRhRtHNqYAdDDo1b0AYiLKc2PTj4WTfZ4Ji9p5dOi5QLVLr2gexfYve5jNoid bXGjXvXvph5MmQmUJJahFWDZgTQSHduqt7g+CcpqJEeRE43JWII4DmbyxwCYg92Qrav1 OBfOZgumACjtTtObLg0BI2dJWjgMNNy1Xhpb4LubGzuianxleIwo2+43q+wQddY9tiSU FvIY9nND/Hoxf+OiOOqYvkUlxh5en0CYyLF9Y/qDLE+zNmNaJp5vvaFhf7ST2Qr9PM53 zt1Qg2f2I6LAv+AlnRyTmBXobz/c1BFhmXRHm2A6Yr/ZrgSJay2ICfnyY1XbkepgW/5R cmdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697724375; x=1698329175; 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=kwR/Ke20NAcUS81IhTmctZxyEuc+6gPtGwlWuG8Kglw=; b=D6ezSreQKES/Yadux0/NijeiLdKSGymdOgJ9TmwmZtXRvigvUS5FTBGyXOpUZVKNJY WBDucyhGq+wquK/fYNFhbnDUSBMI8ZGT7CPa9ChQECzygj7LLf0PMz51qbU3cG2Q5FFa JRWwEK83HmYWQdHeEmnM8oGidWcJk0Bw5Ka5lXgh3S4Ge9IiO5+yi1RKCe4IS7OYNCOe CUOWrtM7M58FdxDMItqcAdZ4YBuuro+UAql0nO943k3FNziwx3MJ2pDFnSjMudQGSBg6 WymQOV3qrm13RrAtRiEqL8E98Q+z2jpKC5cU4CuS8vypLCKeYBXa70GYGgnou22E9Cnx 1eOA== X-Gm-Message-State: AOJu0YwFgZfe1/04uToEXOLXOSkQkJhXRtMvOpGVifYDLnO3DruQKp70 mGM0yQNqsj5Anhz7FlXaKeniXkV4gPdU5ddLXFc= X-Google-Smtp-Source: AGHT+IEj56EYfD3VGGct58Hoxz0IsXjkWxjSdBpSEK26F7D/MeS2KrVfdBwf1rOZcSIiBfUvUcP6qg== X-Received: by 2002:a5d:6e0b:0:b0:32d:8505:b9d7 with SMTP id h11-20020a5d6e0b000000b0032d8505b9d7mr1610093wrz.43.1697724374647; Thu, 19 Oct 2023 07:06:14 -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 u11-20020a5d514b000000b0032db4825495sm4572197wrt.22.2023.10.19.07.06.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 07:06:14 -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 , Lad Prabhakar Subject: [PATCH v5 4/4] riscv: Improve flush_tlb_kernel_range() Date: Thu, 19 Oct 2023 16:01:51 +0200 Message-Id: <20231019140151.21629-5-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019140151.21629-1-alexghiti@rivosinc.com> References: <20231019140151.21629-1-alexghiti@rivosinc.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 05F8A12000D X-Stat-Signature: io59x68xgcrq5334i3cys6hh8i1orf8w X-HE-Tag: 1697724375-578185 X-HE-Meta: U2FsdGVkX189DFhF4kipS2oc7mS88LwgfzWC01FeQKGLrjjZlivx/XikYpcSr7fMuv1jNzLKrZHkrs2YLlZ5arEGreK57GNYsUIw9mmMeNNUsy1ypggGMtY3M4GAUJKvZu+QdsAW/FzfmlBN/k8AJ1TlDD3fa+XJjyY2Y/oC9agj+B3baj4/GmPAKAwl0OrWpiOyG6MmeFCNtlEZqwAtZqTk+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PhGQXIOFwIioo4UZIZb8yNzgEQQDYikrhNJwHZG62ceMhlDY1LCgiG5Mbm3JLDNKux5n0YnS4Egad8NES/m8MS3OntmyKxiknwvsX/YmoSPzUf0yvTyBxpv9dtZQIn5i6gJ308T8/7w2qNAACq6PwDyAB2H60Q+gNfd01A7epOl1I57zB8iuaPYsHztm+MO1vjuGlu9yOXOXwJ+l0U07nw1PAkz5GpYpHwHTIfu57Dp1raGOQATOn34ng1hK+IiTGRUDF/4Kv5ERBtpnQdL5ARQVYmPAvq4RueMUf8bhJRBywAndwQxS0dPtlJnIphiYLuwkzVVSz9cAsI= 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: This function used to simply flush the whole tlb of all harts, be more subtile and try to only flush the range. The problem is that we can only use PAGE_SIZE as stride since we don't know the size of the underlying mapping and then this function will be improved only if the size of the region to flush is < threshold * PAGE_SIZE. Signed-off-by: Alexandre Ghiti Reviewed-by: Andrew Jones Tested-by: Lad Prabhakar # On RZ/Five SMARC Reviewed-by: Samuel Holland Tested-by: Samuel Holland --- arch/riscv/include/asm/tlbflush.h | 11 ++++++----- arch/riscv/mm/tlbflush.c | 33 ++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/arch/riscv/include/asm/tlbflush.h b/arch/riscv/include/asm/tlbflush.h index 170a49c531c6..8f3418c5f172 100644 --- a/arch/riscv/include/asm/tlbflush.h +++ b/arch/riscv/include/asm/tlbflush.h @@ -40,6 +40,7 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, 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); +void flush_tlb_kernel_range(unsigned long start, unsigned long end); #ifdef CONFIG_TRANSPARENT_HUGEPAGE #define __HAVE_ARCH_FLUSH_PMD_TLB_RANGE void flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start, @@ -56,15 +57,15 @@ static inline void flush_tlb_range(struct vm_area_struct *vma, local_flush_tlb_all(); } -#define flush_tlb_mm(mm) flush_tlb_all() -#define flush_tlb_mm_range(mm, start, end, page_size) flush_tlb_all() -#endif /* !CONFIG_SMP || !CONFIG_MMU */ - /* Flush a range of kernel pages */ static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end) { - flush_tlb_all(); + local_flush_tlb_all(); } +#define flush_tlb_mm(mm) flush_tlb_all() +#define flush_tlb_mm_range(mm, start, end, page_size) flush_tlb_all() +#endif /* !CONFIG_SMP || !CONFIG_MMU */ + #endif /* _ASM_RISCV_TLBFLUSH_H */ diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c index c27ba720e35f..7e182f2bc0ab 100644 --- a/arch/riscv/mm/tlbflush.c +++ b/arch/riscv/mm/tlbflush.c @@ -97,19 +97,27 @@ static void __flush_tlb_range(struct mm_struct *mm, unsigned long start, unsigned long size, unsigned long stride) { struct flush_tlb_range_data ftd; - struct cpumask *cmask = mm_cpumask(mm); + struct cpumask *cmask, full_cmask; unsigned long asid = FLUSH_TLB_NO_ASID; - unsigned int cpuid; bool broadcast; - if (cpumask_empty(cmask)) - return; + if (mm) { + unsigned int cpuid; + + cmask = mm_cpumask(mm); + if (cpumask_empty(cmask)) + return; - cpuid = get_cpu(); - /* check if the tlbflush needs to be sent to other CPUs */ - broadcast = cpumask_any_but(cmask, cpuid) < nr_cpu_ids; + cpuid = get_cpu(); + /* check if the tlbflush needs to be sent to other CPUs */ + broadcast = cpumask_any_but(cmask, cpuid) < nr_cpu_ids; + } else { + cpumask_setall(&full_cmask); + cmask = &full_cmask; + broadcast = true; + } - if (static_branch_unlikely(&use_asid_allocator)) + if (static_branch_unlikely(&use_asid_allocator) && mm) asid = atomic_long_read(&mm->context.id) & asid_mask; if (broadcast) { @@ -128,7 +136,8 @@ static void __flush_tlb_range(struct mm_struct *mm, unsigned long start, local_flush_tlb_range_asid(start, size, stride, asid); } - put_cpu(); + if (mm) + put_cpu(); } void flush_tlb_mm(struct mm_struct *mm) @@ -181,6 +190,12 @@ void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, __flush_tlb_range(vma->vm_mm, start, end - start, stride_size); } + +void flush_tlb_kernel_range(unsigned long start, unsigned long end) +{ + __flush_tlb_range(NULL, start, end - start, PAGE_SIZE); +} + #ifdef CONFIG_TRANSPARENT_HUGEPAGE void flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)