Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3799816rwl; Mon, 27 Mar 2023 20:56:25 -0700 (PDT) X-Google-Smtp-Source: AKy350ZaDS1vjfc+3T5IbqbhEdzvFb33IYJBpDFSffcrtD75LON1I4DhZ7FUHfV4LD3EoLgHvSfc X-Received: by 2002:a17:906:4a55:b0:92f:a0d5:211c with SMTP id a21-20020a1709064a5500b0092fa0d5211cmr11977037ejv.35.1679975785000; Mon, 27 Mar 2023 20:56:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679975784; cv=none; d=google.com; s=arc-20160816; b=Hn8lBE74hnDXKVQvR6n5Z9DFDxr5ho52dCOs5lSHB734EclhRGacWiSiO71zW43Cwa CsId8Dq3H25eC4+XVlBbFP3vQ0RgZCN0ts3/nQDy5hRaKi63jvGQrD0eyYyhAIDRP4rQ KQ9HQi3yLf7ONxaQovdeQh1HDmBv9wXrgqLFQ83L0S+FMoFPHuD6+MMrFuCzJlHmo7ZI nh58BPQsI4AJ+dModhwRSxO721q5eFMIaU54zqGiJpxtTyPfIeNVFtnnLAY0K0FKS8Yc puLR/i2VMTGwlZtfjgAkkXKHJDwevQ9kUWmGjp5Wdmu/ml2QetxTJperc04T0GUnsiN/ qStg== 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=a2tND4+OZFie8n8iNE7DZHGFfCkqDurrEJT4noc8Afo=; b=ZOXMm+WTeM0Ed2O+z7iAr3E46IBSC3BqfBA3n626PkZkNYU/Wmk+3shNbBMESuf+d/ YhhB5yY01O9Hio2JUMyQf3BThBUoiSj75ZjcqYdlKamx54qcC9mqJBE1HLy3PZH8RYAo giEmlgcart98M1Mi/A6wFi9IrOtiotAVUaApIv5l0B5eCjov3hXsZGK6+9la8VgMARQM 1IUGp0zsXRiisBtOJqtQEupYlzivr6UqzLMaPnRuVY/DTWUBDwbE1YPjoe0NajT5FnO2 iDUHQsBsq+Kbo9jA70I8umnt38TdNMGzbuLZd35aUb3nK40Fivx0PxSbNZRDZiJ197Rc 7uPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=LUWh1K+P; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w17-20020a170906131100b009332b99a1d0si23514548ejb.857.2023.03.27.20.56.00; Mon, 27 Mar 2023 20:56:24 -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=@ventanamicro.com header.s=google header.b=LUWh1K+P; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232670AbjC1Dxq (ORCPT + 99 others); Mon, 27 Mar 2023 23:53:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232795AbjC1DxR (ORCPT ); Mon, 27 Mar 2023 23:53:17 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 904C230E2 for ; Mon, 27 Mar 2023 20:53:03 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id e15-20020a17090ac20f00b0023d1b009f52so13890370pjt.2 for ; Mon, 27 Mar 2023 20:53:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679975583; 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=a2tND4+OZFie8n8iNE7DZHGFfCkqDurrEJT4noc8Afo=; b=LUWh1K+PyVs1rXPdYzIcKHG3d2DqIoNvHunWDZ2aAsc+VJGJIscCSWu7a041Mox94H Oqb0gWGjD52jhvykiDpPYoNqWMGsAtyEGQnn6GqGkau7LNVU3RO03yUVkJHZE3bKVW/c mwD8L66sui6Qsbf/m3mRhqM+763sLzRmYglGhdEzuu0OpqfVWT/IdP+JuFETiL+hMCyq 9ztDMqz/6BFBlW2zN4iycf5U+IgKsPikbOIgq5y1yGjih21bzWwI5D6sJ2SkOy2YzE1W Q++6D+ZmMXbLzVAGMQ/ZD/0IfIi72rWaK2XsFLtrvZNRWFrlGYh7fmHM5680Xau8eSyx Efnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679975583; 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=a2tND4+OZFie8n8iNE7DZHGFfCkqDurrEJT4noc8Afo=; b=mtPMICkzBfr890V57TGdkZ6Nt5/d7GhcUd4eX79ImlRlIqrxHkse0+Fxswn3V/D+22 YScxDOe8D0S8QvgL9bfW7QiJ7xlnjTNXXJAAgBq0WHg0tj5kMtCIkafjEnoe08LwJxTZ KOpDtLV5G2/S2xm7HssTx3xSpYB0lKbfpOyD37DtZDEOZiCgdcHa0i3E9W7OWptkqFwa FCmsNMPAzXuFoDpLwmXysip3Hz9Ze+jPI6sirLZvATtmx9A+h44AZLNYTOHaE7paHHSA WtYD7Vqz9TlJYLMCt4CaLHT+f3Ii/TkljNFg3PDhcBBg8zoNQfp7cYN8ZkwSEfCKKVae rT/g== X-Gm-Message-State: AAQBX9fpFj7XTahNCoLb9EiflOds/+5RyCvRjKQAJu91+J3Th/zewMy5 5Qdnlc/f+holJaPiFuJl3Y/nDg== X-Received: by 2002:a17:902:eecc:b0:1a0:6bd4:ea78 with SMTP id h12-20020a170902eecc00b001a06bd4ea78mr12280592plb.31.1679975582804; Mon, 27 Mar 2023 20:53:02 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([171.76.82.104]) by smtp.gmail.com with ESMTPSA id g6-20020a170902740600b0019cb534a824sm19880278pll.172.2023.03.27.20.52.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 20:53:02 -0700 (PDT) From: Anup Patel To: Palmer Dabbelt , Paul Walmsley , Thomas Gleixner , Marc Zyngier , Daniel Lezcano Cc: Atish Patra , Alistair Francis , Anup Patel , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel , Atish Patra , Palmer Dabbelt Subject: [PATCH v18 5/7] RISC-V: Use IPIs for remote TLB flush when possible Date: Tue, 28 Mar 2023 09:22:21 +0530 Message-Id: <20230328035223.1480939-6-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230328035223.1480939-1-apatel@ventanamicro.com> References: <20230328035223.1480939-1-apatel@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,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 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 --- 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 ef701fa83f36..77be59aadc73 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 -- 2.34.1