Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3569962pxm; Tue, 1 Mar 2022 00:36:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJxmxKYsC77H+qjsOGucAsJs6TjwC+dnzBb75f1/Gqf6K5DTXuqi/V+YoTjqRWW2mdFnfCbx X-Received: by 2002:a17:906:fa9a:b0:6d5:dc74:8f4 with SMTP id lt26-20020a170906fa9a00b006d5dc7408f4mr17998275ejb.88.1646123777280; Tue, 01 Mar 2022 00:36:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646123777; cv=none; d=google.com; s=arc-20160816; b=J8lWG7s7Oz0WtyMnFHodCcHEAnVoIXH6nLjNjgpVTWql3T6702lrLFl5ySEvYvKyhE FTi1SllnrUHGXOraZ2IcFC8D05EPMqqQjAR/bztkvHTThg0F3a2vqqupe6/XPQA9INML pK7F7ZMd7km+cVdJwfjqwMh2zBttk/Qv97ikhWMhdgA3zBICh+T6Kkz7ayshoEfDlAzG M2Kvzf3KCP+D308MmAO6R4Z49b5E4yryaXKwVtcrVEtiy+lGnk4oV4fC71IOWb7n4ILq XbhpKQyTYDI3w+SpWmNGBgPGBg6k8v09nkuMLYG/0ypuiFCcYYgrIR4PsDfGG5kf+wtZ G7pw== 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=gulBS1a3GDwTjV3gPNI1Ld+RqIL2YPtNwx+Ha/YsDb0=; b=NccyHBiZ6myUp/Q43af64Zubt1KfQqHGXNMxjpjvT6mtcJL4gAPSbALUfR3ysc0aBd AwrVF9jofouovwReuiPCom2NiB11SMpWk4KHb1pknYl5FHN5dNk9UQkbVV8cRWo/Q+vU gKUEwabQr6A0kdHBiset+mKEGzoFZ4rDUuj1Pv2qfjj5ioXymQ4D6pQ+ktGB+Q+Zem9L vrfDgjCn11sTw/WMK9UUUJpTeax2xxOaTzuuJHohOi2EJ/O7VdPrmqq9/3mBBkVsvwni GO1nBAuS7lzYHBUilLi62XkhYns8xl2NnayPAUk6MUgTftUlCbCGI/5ABYO879L4+W4/ fweQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=Puv3jS3y; 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 z8-20020a170906714800b006d6e97cce4bsi319326ejj.296.2022.03.01.00.35.53; Tue, 01 Mar 2022 00:36:17 -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=Puv3jS3y; 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 S232296AbiCAE31 (ORCPT + 99 others); Mon, 28 Feb 2022 23:29:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232297AbiCAE3T (ORCPT ); Mon, 28 Feb 2022 23:29:19 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 198F14E395 for ; Mon, 28 Feb 2022 20:28:39 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id d17so18434114wrc.9 for ; Mon, 28 Feb 2022 20:28:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gulBS1a3GDwTjV3gPNI1Ld+RqIL2YPtNwx+Ha/YsDb0=; b=Puv3jS3yxYrmy/Wq1z55hOwBixDPaWB5vIsJA4yUcPkgKDUfxuUneL//cTo6BYz6W0 fjaokoL7mTjnxa3jrd7iXtqi67wMGZSiPLkTZKJpV7987CzhUOxERZ2PvLKxM+gwe8Ku ZGNQrKEySnzIQg+6dqrc06N4+hH2foqVE9RZHs9PK9Ac+Q6AJJxFxextFCypPGvZdDBS EdKnMjOJWJDjS75e1JGInEYgt7uULhpYLx8yS/+Mu4I/QA2A5ss9fhp4VnzxZ2a+nwj5 Yia9Fj0izkecTCaYt+aMGrTQv6pRGUPA1ZTnI9hhr+w3MYX51mBBegLYxDJHyLF4n+Ae 6a3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gulBS1a3GDwTjV3gPNI1Ld+RqIL2YPtNwx+Ha/YsDb0=; b=wmE2HskCEEfZqIWm7/6lfIxNrhc2DzkuAia87Tzax/PvwN4O88Auq+fo0LZ5U5OzAs p6i8py04Jusvz7EMd8z0SRyQzPQFFxA9d4CDDfF+bIN8tw+C2dV9Bua1jYBSAjkPo0XP 134qNlQNld2XFiC5JQR69N3GNeYIH+RoSaCi2rlihj+l+wzZkICl/8VU3fPcz7gFpDZf XvQaZACkSHoISuiHUfasdVV2TFRwSUV3/KOaTe6H0c8/NjjJ/hsMEbeFJQBavsY8PRMd bJcNxx61/bQ1AxZByEZrdQ4ph01rGgVslYkwtvJ/h5vcq8v1PKjcAuIpOKUOpUlT9RTA gd2A== X-Gm-Message-State: AOAM530knm3RslGDrj3HCEDjVC4RJKcIOfdEDtIA9W53IHKx7MIpmwe4 sDOQ1bF7woKmFFjGBl2b4XgCuw== X-Received: by 2002:a5d:50c5:0:b0:1f0:2111:8f74 with SMTP id f5-20020a5d50c5000000b001f021118f74mr2051wrt.211.1646108917693; Mon, 28 Feb 2022 20:28:37 -0800 (PST) Received: from localhost.localdomain ([122.179.35.69]) by smtp.gmail.com with ESMTPSA id 2-20020a1c1902000000b00380d3873d6asm1209107wmz.43.2022.02.28.20.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 20:28:37 -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 Subject: [PATCH v4 5/6] RISC-V: Use IPIs for remote TLB flush when possible Date: Tue, 1 Mar 2022 09:57:21 +0530 Message-Id: <20220301042722.401113-6-apatel@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220301042722.401113-1-apatel@ventanamicro.com> References: <20220301042722.401113-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,T_SCC_BODY_TEXT_LINE 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 --- 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.25.1