From patchwork Mon Sep 11 13:12:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13379328 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 7F172EE57DF for ; Mon, 11 Sep 2023 13:16:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 22CE16B0299; Mon, 11 Sep 2023 09:16:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1DC6D6B029A; Mon, 11 Sep 2023 09:16:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0A54A6B029B; Mon, 11 Sep 2023 09:16:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id EEE306B0299 for ; Mon, 11 Sep 2023 09:16:35 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BB6E31CA503 for ; Mon, 11 Sep 2023 13:16:35 +0000 (UTC) X-FDA: 81224365950.26.562C456 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by imf03.hostedemail.com (Postfix) with ESMTP id BF53420018 for ; Mon, 11 Sep 2023 13:16:33 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=VTPQTeKL; spf=pass (imf03.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.41 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694438193; a=rsa-sha256; cv=none; b=KsX/dP54j6iCoRzybIjzfjCRVuN5Y0GqNsGACE1DN0TdUa/Irwk71jRvYpkMxK52Tn1AIl Y/9jGXHmnjL12driMdJmTsGzOxYKR5VkQP3n3ZPdjMVnCXJqSnJ9g54j8PYleoyY1tqJmi Q13NCMxrTBJSGe3p365rw7ykB2AsnLc= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=VTPQTeKL; spf=pass (imf03.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.41 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=1694438193; 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=JvOXQ7FYd4bs7bkUZT+Erh5aGWPCjNF5TJ6uV/v/MCg=; b=5fzBIHJsRJjMWFimt0tMs3En9QBtBCQs1WRpEvYyoGUE0iTulhfp70s3SuhqqoBT3bu7sx 0rY6TnrNRO7+1QkshdviPKOpo9lSIFG7KW8BP++mlRKahWCiasioQ4/snzQ0kfhE8MLT2m jw8JYp74Ct85iIEX8CynHQMO+3hwH2M= Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-401b0d97850so49314605e9.2 for ; Mon, 11 Sep 2023 06:16:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1694438192; x=1695042992; 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=JvOXQ7FYd4bs7bkUZT+Erh5aGWPCjNF5TJ6uV/v/MCg=; b=VTPQTeKLIrmDTVc74zCmRLQ6JefLpekz+OQ6b4s0YIoFrRm+HO6ToY8Y7vf3y1tmwP SdfNvwsU6A9yM3HGsHuzV8HHKNNdM2csVsqU4giIQMKUwbfPxL0V46+hBQtZj+VddT3w XiVue4Hh1pBeq3xSDdYrTvEG8co70d6+fqvGsGwmvepA1cpLhIqKE+rWMc3NrCeI2j4o 7HruaBz7ufln6lXYHjpe0Ba2lKGn3bmU98LhFSFsqaRtF7Bb7lxsAka296bN31IYlGMi RPA6M/ay/zl/ydk1YkmbFepTzjO1Fy3mTwQNGWweXhcRLyDzEtG8+hJzx/Gs2gokQfaQ IH1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694438192; x=1695042992; 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=JvOXQ7FYd4bs7bkUZT+Erh5aGWPCjNF5TJ6uV/v/MCg=; b=YrYGaC/ChxzYxXITXFMG/2q6F2qWeyeZ2HLhDIzAjeNOwiMmo3t0aLYWPr3EkKx+Kl JcYH6FGONlWiHO55nfqemUHRCfMbvQuXgIti+35lHbFXC1ZCXCU9bEx9QRmflymt0fdF Nctdl9UQMURq3ny0M1puNi18QPmhnoX5FDIgLgYfm1UBRfyQxMgftetXxi8LIR0SQ8BS dW9aKzRqTy/VdupYRsZz17N4qd0cQ2FScmUTGskw1zjzcxasqoOYkt6Bs2LG0T8to4xU 9M84i9QL815aGrnZx5tqkfp32tCpkVtf0BXi8P1SBeM4EcYsnwsFYPfaG5csuyDWjFgu PDGg== X-Gm-Message-State: AOJu0Yz1J111DuNjq0nFkrtkhsaNtZF6WciTWV/Q0YsFMLp5I6PQ6mLN IzgSsIEooEg6ZRSSWVbUtYLEddINka7m4gPslHI= X-Google-Smtp-Source: AGHT+IFRHd7EuaFwA1K1cfF+a13jKeLBoTHGF7TEiz4nS9tv95i5qHxXArflq3jWzwYQ4//q7JLqPw== X-Received: by 2002:a05:600c:1c8f:b0:402:f55c:faee with SMTP id k15-20020a05600c1c8f00b00402f55cfaeemr7265932wms.26.1694438192211; Mon, 11 Sep 2023 06:16:32 -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 b11-20020a5d4d8b000000b0031416362e23sm10134340wru.3.2023.09.11.06.16.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 06:16:31 -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 4/4] riscv: Improve flush_tlb_kernel_range() Date: Mon, 11 Sep 2023 15:12:24 +0200 Message-Id: <20230911131224.61924-5-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 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: BF53420018 X-Stat-Signature: orqt1wpcox7pibjbqi37hb3pjcdna9n5 X-Rspam-User: X-HE-Tag: 1694438193-546983 X-HE-Meta: U2FsdGVkX1+hQUnWKrnH5WbbidpeXfij+hvHQDWGQ9ShAVxr3c7QnPslVUa7WKw+kjhZYndp16ZnW5DZmNYlGS3rpUvHvbDDwc+N9e10T8RjK1kpcPiI8exvmpJPUizDKW8fndd81gPbG1LtqOd1Z9jCc/N29xQdPRU5guoogHUeXLFFqw71j9IwxsYe/CCi8kvuRwDqaXlX+8M/pxXVcQypn2jcVQ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5JUaGV78JUIh7BtBlI9zoHYhkr43tqEjfkTFjMsVieQiFf6TfckUFcg9K9HeKR5cvgsrOd7qtlaBhMAXdDE8iRTv7vgk3wNaVjG0VRMSS8nco6bsuIwVePcbFqV2TkPWYaDzGArRBRpUfJ7StLka6DKKONTEBt5n/spZwA6GyKSgQlmkMLFVF1j+f9SO0IpyugA8hxVj2kESRH6CJphVgP3IWiznBeGQzEDHV4EHf4cMqGS8bc6K/exeG71shvdRua6zUXh7t+Z+xX+vVD4HmP2pSqvYeU0iKbIBephhTIew3zcNd9qvy0THTra2bOXLw== 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 # --- 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 2c1136d73411..28cd8539b575 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) @@ -189,6 +198,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)