Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1908617rwl; Sat, 8 Apr 2023 04:31:04 -0700 (PDT) X-Google-Smtp-Source: AKy350b+OTgmMz5ml+FPRZoL5pcAAcKU+TifC7yhRvjry/JIW8FzqtI8lZryfqIXZtviJxFPh1Ly X-Received: by 2002:a17:906:db08:b0:870:58ae:842e with SMTP id xj8-20020a170906db0800b0087058ae842emr2532358ejb.24.1680953464223; Sat, 08 Apr 2023 04:31:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680953464; cv=none; d=google.com; s=arc-20160816; b=DRlP9OxxrgK4X7TGGcDEttdKsR7WqxsaLEa1Xk+d0xcah4A6w3KPao/3DJXQcnb/nR mtqa8DzJYELIkb3B24nCEiEyPlczjvrnSHQBTeO4yku6WSdHxRqQXbIh3th2VvzP2Ni5 hyy+LsuVnSszOiQv8Q+Bi/OQG8UMN1Sw3j8y1i+e06BiTTFA4njruMqu8mldpm+1a+6e d7KuggK66yDnIazhjnEh784r7V8jqkgOIIaUXzKt5Ptqh65iHxNVYzzHFEa+GJ8uRAQY I/LHihc+Z+zOQl9nEgE/aZ7jjNEijRFAg45aZayuE3pVEz6jJpmiscAcDX3wxO93+BM+ q1xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=ayGvbRTCswSwC99PgN1n1uhvyXBASTcVcAl7M3jFjhY=; b=Etm3YGqf4+hvQAODYeIMwHjUkcWdRnF82fvGZflS1RByExiEs1oZOUptz7+tAtrRmb YZbwSKXsamwm8QYkOKJclaVVp9tr1ULyRL+SLbCAGuodJ7KMzyOnP906dXTvODSrq5v7 pUjpYxFZwU+iTy6bzHbFpWSDWt6ETIRUn7Db0M1OPLTshwAEGGiIJarz8PxwocRYAWrf dgkOJJ/h6y4fFRghpkfOfqKSIDlaDPaY9KnBszx2oMByBG9G2D84Hd7MZETaE+jPyy5y SlsLFPO91HfR5TFShKoOLTrFromyJnP8nQWRGxADRQhMoqFYgiCurynkFAiWlUQXemiv 7GwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dqOCOgY+; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i17-20020a1709064fd100b008d7fab1c562si6370966ejw.115.2023.04.08.04.30.23; Sat, 08 Apr 2023 04:31:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dqOCOgY+; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229640AbjDHLAV (ORCPT + 99 others); Sat, 8 Apr 2023 07:00:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229570AbjDHLAU (ORCPT ); Sat, 8 Apr 2023 07:00:20 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA102E41 for ; Sat, 8 Apr 2023 04:00:18 -0700 (PDT) Date: Sat, 08 Apr 2023 10:45:17 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1680950717; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ayGvbRTCswSwC99PgN1n1uhvyXBASTcVcAl7M3jFjhY=; b=dqOCOgY+SzsabsKwIwTfy+srULg7dvMuJ02SVVcjM6A6CgU/pHXLTb0OYpqxvtFxlabNfS ybCKreGVJjKr78ZSiK1xdluQJSCbj6eKmMG8i15Z0QVMkGXpbWw1cnUsEJFWxg+Vzu/V2Y Ywury98V7oeq8lg1JPARwyakX3wsmOOhVG09nfLWafuKfnFMtVgSVT2yN/XFeCNbmJHCSy +k5BQm18yc5YnxDQWa6F9MXJK63X8WKOAtX55lBACxeWQv0A+zfgDyzVVO7/WT8TN7xzMB zMZOyT6Qj0ZAR/D9QzhvYoJpRTQY32TkmNXROdcvGmXjw1BSZqCXZu0ukWmmcQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1680950717; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ayGvbRTCswSwC99PgN1n1uhvyXBASTcVcAl7M3jFjhY=; b=sY1JdN1xC7uE+7an1UeNDBYTRkAzdn5r8K0T90BM4u8McfUeRFRZ9k+ysz/Vp4VlLZavga u0izMoMCQV9FqnCg== From: "irqchip-bot for Anup Patel" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-kernel@vger.kernel.org Subject: [irqchip: irq/irqchip-next] RISC-V: Use IPIs for remote TLB flush when possible Cc: Anup Patel , Atish Patra , Palmer Dabbelt , Marc Zyngier , tglx@linutronix.de In-Reply-To: <20230328035223.1480939-6-apatel@ventanamicro.com> References: <20230328035223.1480939-6-apatel@ventanamicro.com> MIME-Version: 1.0 Message-ID: <168095071741.404.18009750298069050198.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the irq/irqchip-next branch of irqchip: Commit-ID: 18d2199d81054f44e6d2a51177cc80566f43bf23 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/18d2199d81054f44e6d2a51177cc80566f43bf23 Author: Anup Patel AuthorDate: Tue, 28 Mar 2023 09:22:21 +05:30 Committer: Marc Zyngier CommitterDate: Sat, 08 Apr 2023 11:26:24 +01:00 RISC-V: Use IPIs for remote TLB flush when possible If we have specialized interrupt controller (such as AIA IMSIC) which allows supervisor mode to directly inject IPIs without any assistance from M-mode or HS-mode then using such specialized interrupt controller, we can do remote TLB flushes directly from supervisor mode instead of using the SBI RFENCE calls. This patch extends remote TLB flush functions to use supervisor mode IPIs whenever direct supervisor mode IPIs.are supported by interrupt controller. Signed-off-by: Anup Patel Reviewed-by: Atish Patra Acked-by: Palmer Dabbelt Signed-off-by: Marc Zyngier Link: https://lore.kernel.org/r/20230328035223.1480939-6-apatel@ventanamicro.com --- arch/riscv/mm/tlbflush.c | 93 ++++++++++++++++++++++++++++++++------- 1 file changed, 78 insertions(+), 15 deletions(-) diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c index ef701fa..77be59a 100644 --- a/arch/riscv/mm/tlbflush.c +++ b/arch/riscv/mm/tlbflush.c @@ -23,14 +23,62 @@ static inline void local_flush_tlb_page_asid(unsigned long addr, : "memory"); } +static inline void local_flush_tlb_range(unsigned long start, + unsigned long size, unsigned long stride) +{ + if (size <= stride) + local_flush_tlb_page(start); + else + local_flush_tlb_all(); +} + +static inline void local_flush_tlb_range_asid(unsigned long start, + unsigned long size, unsigned long stride, unsigned long asid) +{ + if (size <= stride) + local_flush_tlb_page_asid(start, asid); + else + local_flush_tlb_all_asid(asid); +} + +static void __ipi_flush_tlb_all(void *info) +{ + local_flush_tlb_all(); +} + void flush_tlb_all(void) { - sbi_remote_sfence_vma(NULL, 0, -1); + if (riscv_use_ipi_for_rfence()) + on_each_cpu(__ipi_flush_tlb_all, NULL, 1); + else + sbi_remote_sfence_vma(NULL, 0, -1); +} + +struct flush_tlb_range_data { + unsigned long asid; + unsigned long start; + unsigned long size; + unsigned long stride; +}; + +static void __ipi_flush_tlb_range_asid(void *info) +{ + struct flush_tlb_range_data *d = info; + + local_flush_tlb_range_asid(d->start, d->size, d->stride, d->asid); +} + +static void __ipi_flush_tlb_range(void *info) +{ + struct flush_tlb_range_data *d = info; + + local_flush_tlb_range(d->start, d->size, d->stride); } -static void __sbi_tlb_flush_range(struct mm_struct *mm, unsigned long start, - unsigned long size, unsigned long stride) +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); unsigned int cpuid; bool broadcast; @@ -45,19 +93,34 @@ static void __sbi_tlb_flush_range(struct mm_struct *mm, unsigned long start, unsigned long asid = atomic_long_read(&mm->context.id) & asid_mask; if (broadcast) { - sbi_remote_sfence_vma_asid(cmask, start, size, asid); - } else if (size <= stride) { - local_flush_tlb_page_asid(start, asid); + if (riscv_use_ipi_for_rfence()) { + ftd.asid = asid; + ftd.start = start; + ftd.size = size; + ftd.stride = stride; + on_each_cpu_mask(cmask, + __ipi_flush_tlb_range_asid, + &ftd, 1); + } else + sbi_remote_sfence_vma_asid(cmask, + start, size, asid); } else { - local_flush_tlb_all_asid(asid); + local_flush_tlb_range_asid(start, size, stride, asid); } } else { if (broadcast) { - sbi_remote_sfence_vma(cmask, start, size); - } else if (size <= stride) { - local_flush_tlb_page(start); + if (riscv_use_ipi_for_rfence()) { + ftd.asid = 0; + ftd.start = start; + ftd.size = size; + ftd.stride = stride; + on_each_cpu_mask(cmask, + __ipi_flush_tlb_range, + &ftd, 1); + } else + sbi_remote_sfence_vma(cmask, start, size); } else { - local_flush_tlb_all(); + local_flush_tlb_range(start, size, stride); } } @@ -66,23 +129,23 @@ static void __sbi_tlb_flush_range(struct mm_struct *mm, unsigned long start, void flush_tlb_mm(struct mm_struct *mm) { - __sbi_tlb_flush_range(mm, 0, -1, PAGE_SIZE); + __flush_tlb_range(mm, 0, -1, PAGE_SIZE); } void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr) { - __sbi_tlb_flush_range(vma->vm_mm, addr, PAGE_SIZE, PAGE_SIZE); + __flush_tlb_range(vma->vm_mm, addr, PAGE_SIZE, PAGE_SIZE); } void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end) { - __sbi_tlb_flush_range(vma->vm_mm, start, end - start, PAGE_SIZE); + __flush_tlb_range(vma->vm_mm, 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) { - __sbi_tlb_flush_range(vma->vm_mm, start, end - start, PMD_SIZE); + __flush_tlb_range(vma->vm_mm, start, end - start, PMD_SIZE); } #endif