Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp12480576rwb; Sat, 26 Nov 2022 09:40:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf60domzS85JZvHmsu/jZw7bk3wJ2N2lQKQF06U+nwPZYRpOSSWPTDZX8c2g2g3KQ9iKCUD5 X-Received: by 2002:a05:6402:41:b0:467:3ea2:3ec4 with SMTP id f1-20020a056402004100b004673ea23ec4mr41645869edu.351.1669484448440; Sat, 26 Nov 2022 09:40:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669484448; cv=none; d=google.com; s=arc-20160816; b=rGo6wf3Q90dLsSthNYY7vMSK2k7/BP8ACug0F1WjH+diAiCDV2g3dDXsqbLe29YOZS OMzFVzngrMQjKkf7Vm3Mz1lGG3J8feg8Vq4lezhs15+5DmrTunssb3W4AOTJdWs19Jtw 4xOgacpD8sSCjPtCBQfgz3HzjZl2iQvWK7qEOBKsCc40X6nGfDZhmgi5QMmhy9lUOQRX gIRX+sVFsCSzc57KXWNfB/mMHotmhX/MPdX0o+o72gWRu8GCq4RTRLetmR9i/DckbJVP jGgPUBP0/VFEBQgKwQsZ5yCFX0QjDEPG0mSs78eJJjtK2sON4Vy3fvlCoV8oIaj7tg1V Fd+g== 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=PXYoHLXQCavco5NNh0sXuOKKVYR0blfrb+/AP/qt1J8=; b=t8+8PEFu4MatU9fEeFql8Mkb+/cMFXCaqUesJYhVJye7JIoV0VuqZUy8TnfXYxaq0n KJO+oIlFkOtcmMO+e3z8315vMH5/MEajSvXTVKv2wjrByzXxYKOP2XNbSNnbEckAysz3 eugMGdQB4h0tvPk6pe0neMLp8tRIsrmqlPME61wWmlSOJ9ySTe1TlMK/sZ/Bdd3KsEzg rOD6JkP7f+0Rjb6tUMh5tYx3a1JgylFVZJHxUVYeM46MYVanuKu4tcAifIB2b2xi6niI NKGlRUdrMGclK7nbe2in3DkEO301p4UxnnuodWhlqejfqsD0xAjzJfCAD2E0npHFn/73 WgJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b="BoFO/pdp"; 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 hv11-20020a17090760cb00b0077b4248b138si7102660ejc.127.2022.11.26.09.40.27; Sat, 26 Nov 2022 09:40:48 -0800 (PST) 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="BoFO/pdp"; 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 S229818AbiKZRfu (ORCPT + 84 others); Sat, 26 Nov 2022 12:35:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229822AbiKZRfj (ORCPT ); Sat, 26 Nov 2022 12:35:39 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 746561DF28 for ; Sat, 26 Nov 2022 09:35:33 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id w4-20020a17090ac98400b002186f5d7a4cso10317493pjt.0 for ; Sat, 26 Nov 2022 09:35:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=PXYoHLXQCavco5NNh0sXuOKKVYR0blfrb+/AP/qt1J8=; b=BoFO/pdpkF4220ArqSyT7Fef2z9AiCHP6F7W9lWvdlGPiU00YBGm7wHJLjYJHmo4Lb Trzl6LKgcMpejbttoEv/1hXeg/1kXrG1EzQcu4xfCZ8swc9LSLfsLnmm3qW9FTAnVql5 7BSKiUU/+wIpPC7FeVuBj1O4lr1Iq2+W8Y+uR0TR/V/ARPlSHdrxbyEbvO/KR18QRBKQ 4LUSUZ1ZKNPd89mMroefjyUp3YMsgntT/3RHOaF+CuLof61mf8cKHoJBoUDRwFPg3Jyk DtGNyX+SSRbVFwZigk4/nwgwUkjw644SSAePdqZhF7VvSnYDaGpchZUe3GrLTrhcVKrR Sk8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=PXYoHLXQCavco5NNh0sXuOKKVYR0blfrb+/AP/qt1J8=; b=K/q0OwbThL0DxXV4kh5UYkgtGRaz7L78UQdWuyctSo/aYxdEYDpkwYNuh1kyz4DV/G yEs6C4qM6bykGISUQ9kkcKXg0UJwmDPkEPyZnPsEQdG/65YOpu7BwoXlFtefuXnO4sY4 nDKvdSdyG/H9gpmDMK/9pIWjDEiaWfkhzoIz7NJyq58aYyl/sp4ZnLaV9nru1cGuhKQ6 +TA42dQvv62XSoaVJBF82yQKraOyy3OxavqZks6kD8NueLMet8W9KfodeLMebx90e0y9 Pw86ukt1jOS2wofzgnS/G00oU8N1nXDfpzVocdGUf+Knqm7dUSlcJ3ot138V7C+rrPW2 yYeA== X-Gm-Message-State: ANoB5pmfPsTcBdxuLKqqbwsf5zX0uhQHdCDsyaONdoyc4J5jEe7TYmTE RDVJmvweJORezRXms4aJCtY4fQ== X-Received: by 2002:a17:902:934b:b0:189:78db:12be with SMTP id g11-20020a170902934b00b0018978db12bemr2604216plp.8.1669484132869; Sat, 26 Nov 2022 09:35:32 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id u11-20020a170902bf4b00b0017f7c4e260fsm5639813pls.150.2022.11.26.09.35.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Nov 2022 09:35:32 -0800 (PST) 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 Subject: [PATCH v12 6/7] RISC-V: Use IPIs for remote TLB flush when possible Date: Sat, 26 Nov 2022 23:04:52 +0530 Message-Id: <20221126173453.306088-7-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221126173453.306088-1-apatel@ventanamicro.com> References: <20221126173453.306088-1-apatel@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 --- 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 37ed760d007c..27a7db8eb2c4 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); 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