Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5310468rwb; Mon, 14 Nov 2022 02:37:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf7VmDuXrsfkM3QVUu1sYt1zRejnKw2Oeq8e/Avu6YGtINlzVI/2RPa7ZZ3ijQ1nbh8Y/vGy X-Received: by 2002:a63:b14:0:b0:470:18d4:f18d with SMTP id 20-20020a630b14000000b0047018d4f18dmr11346869pgl.295.1668422262467; Mon, 14 Nov 2022 02:37:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668422262; cv=none; d=google.com; s=arc-20160816; b=xhrWJTYprshSkFiZzo/SCY+b7jsHeEhgUWcmwCq6oQwaYroR2UZh86zNQ6En5m6aJs Gk2adFuYQwhKMoedZxa/qbMG0hJ4xcusTtZsiFyfjMwCoNkqdkGB6TiJinkY1gFg0UcS 2wfqy3tzrN4LRfjaCbWyxim1drbd+qJDRjBb1MAFhhXJ/2bvwFXEa+sxeqMcUf7K+X9P H7ePz9R9HFYyZ3ZR1tIODhBnGPj+IUQ92jiIe75ywISGJlwGUdTpDFDudAY4QR5QUc7j rruiqzb3GIbOCcTy45DjZ1waMdFr/ccxmptGmpWxIiDH+tP/PHJN65Bg/eAXiEREGifv TAvg== 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=VNX+kjVhMhX5VoYybP3139VvqCRfxFdbzBQcW99N11z3te0GlJwwxkz/xI85l3oz1F p7OAurBj9f3NMqbA///r1EhMVq+pm8020hgdCmzkRSMhmYgjKF1wtTmOe1/axJRavO7L WarXZwZldlDFGMh4jGwlV5GInXaSqWYNW4wGnMWWpxRBa6dZtzrDyGOudNyZxO5F/ApG 7+SjiOc5DRznT+0VoiCnxTwHDHytfHvieMrvqkwVdvXMjRuXOgXNGSWpGRQFs2TuHelW rSB77WqkmRxXSJxza86GRYc+0131dn8w90Cxz2iFkmaXApcGiaYLFEK9+pmhkMEYCHCU plsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=pIeJdYZa; 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 w14-20020a17090a8a0e00b002135a4d80d7si9029683pjn.188.2022.11.14.02.37.30; Mon, 14 Nov 2022 02:37:42 -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=pIeJdYZa; 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 S236458AbiKNJkc (ORCPT + 88 others); Mon, 14 Nov 2022 04:40:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236961AbiKNJkE (ORCPT ); Mon, 14 Nov 2022 04:40:04 -0500 Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F401C1DF1F for ; Mon, 14 Nov 2022 01:40:02 -0800 (PST) Received: by mail-ot1-x336.google.com with SMTP id t19-20020a9d7753000000b0066d77a3d474so2458204otl.10 for ; Mon, 14 Nov 2022 01:40:02 -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=pIeJdYZakHi7GAoDhC1GVD0l+jd/af5d1dGGCnJRrX02hypPpX46Utk9tM/kk8W9CT E/l6nvp/cbLGdqMnMaOA3jTg+BQVYQGVFrTPJ8dNwxFrwbU3OTgYcGvriStNrbQfuyTS QOFZev0T0SFvcrMIP3G9W4w2YVX/1OyjkYkx/Xh2oGFw68682z+hESm/tTrIGSKhyfBJ d+RO464tYxW/UUnUWQYYyNO400X1pK8QsRtoc8nHlfugFqkVccBE4KStp1VeyxBb8ooK MHGX666DIaLdqhJLbXW/YtqJshuhUAGGCujL01coqalW9Wz7wrl+Ldc/TbpqbYfglxTP qViA== 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=mmS7TNgckmo25JJqOno6M5/uw9+CVZ+StiGOwKg6L97Xcdk1WcsbirrcSjtiX0NyIg yJrDPH+vbwTd9Ck5YAKAbs6MkDJ4XhLoeGs4BWO+4xSXGvSPyECToFQJT1JU2B8VFIYM XUmiBg2n53y+vOtIY3qmzEQdWp7s6r/m23J+PA+bwRtXK0Foj4sKryKBwJfoWbWPrwum baJn6ooLhsbp2TCQnMH4RpoJ5PZ62gYTb9muK5PQijQnpp4ZqV/vs04eom9OYy4NokeU Du2m4NoJkH+7CVot6I2UKDRtgYLXew2zNOT1UPtJws58o5JeR/u1P4TFRoUjAAjU1edM OV5w== X-Gm-Message-State: ANoB5pmq0rDp4qlZ10ElAf/1d96T21z9wENjCxPJ3NqMGZL9vAmGTkqs dT6mz7zJJjlmWJ64Foo0AbHUow== X-Received: by 2002:a9d:61cc:0:b0:663:d3ce:ca26 with SMTP id h12-20020a9d61cc000000b00663d3ceca26mr6052295otk.67.1668418802169; Mon, 14 Nov 2022 01:40:02 -0800 (PST) Received: from anup-ubuntu64-vm.. ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id l12-20020a4ae38c000000b0049f3bdd791esm3222677oov.26.2022.11.14.01.39.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 01:40:01 -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 v11 6/7] RISC-V: Use IPIs for remote TLB flush when possible Date: Mon, 14 Nov 2022 15:09:03 +0530 Message-Id: <20221114093904.1669461-7-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221114093904.1669461-1-apatel@ventanamicro.com> References: <20221114093904.1669461-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