Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp5634565imw; Wed, 20 Jul 2022 09:20:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vSqSRq5Yvx4Oci3RIp0UvxgLoXwgRpJmk33pl0GQ5e+xTNdIhfnC/zpUee84tPN329+0DX X-Received: by 2002:a05:6870:a454:b0:10d:8d5c:e9a6 with SMTP id n20-20020a056870a45400b0010d8d5ce9a6mr1352023oal.88.1658334058909; Wed, 20 Jul 2022 09:20:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658334058; cv=none; d=google.com; s=arc-20160816; b=dcPtG92OZ5TuzTNItTxC2QrTVdx9ai3t6zwNMHHqVke5GlfwUtmWqQzBMjsq7UKyKJ OkjtscV4UQtYxofSqcJmNzdyp55r6ByhOcjM53K1QU3R0V7lPKCWPLZeaDNJrfmN561l dhpNDgGPc5i/j5E2nDWru/XmHB7K4Wn7hWO586EOl8nQs9Rs2I7BYQmAJ9nAPmQKhs0B U43Tyu0fhtghs8XeoPT3nrFHII7Vrh+mpFF8lSSEC7nsPSp6qVswIwrMDBLFHMyoXl16 TAe8/Mi+nrKUDjDCQPzDMHBqphDMSCfBiVPHeU/3QVAF7MTtDoe9q4puB+cWlWtYfoyG Ibcw== 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=BjmiwAV+qkEddhUojBQVUbZIbS/TIGSArMUYW9Y9o7E=; b=0wY1uR2q2UbmN00jkERi/MIC03PE/7DPTgLghCFCQ/6Ylw/0kV/5syxF4FWrFf5s5X +tikMEtZTOQqMi5HDrkNMBSSltyQwNl4y05ePBRaduf0iFs7xWnzaLcEzalKQlcNzgnH Qfazq9pdhNQA9L6pSCN6fm1Pi79xUqtrUQmuzZyztpokDNczOQRQ3YsKdwwgjCNsG/if 1pH4v+Q8IyMxkt8eut7nF9K0t0QA0JDBZyjUHtLwOiStJk2W1n4nO6ihdLrYec3q4s3K Fo+BnTf/tDozuMpSV1zjLSI6Q3xgSiefRuGAO+wBgXmBkOAa754R9uIvlq99QTWX45mZ p0lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=RMq5xdCh; 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 bo20-20020a056808229400b0032b535325c9si13667937oib.299.2022.07.20.09.20.45; Wed, 20 Jul 2022 09:20:58 -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=RMq5xdCh; 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 S241399AbiGTPY6 (ORCPT + 99 others); Wed, 20 Jul 2022 11:24:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241424AbiGTPYy (ORCPT ); Wed, 20 Jul 2022 11:24:54 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9105A6171F for ; Wed, 20 Jul 2022 08:24:47 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id q5so15252049plr.11 for ; Wed, 20 Jul 2022 08:24:47 -0700 (PDT) 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=BjmiwAV+qkEddhUojBQVUbZIbS/TIGSArMUYW9Y9o7E=; b=RMq5xdChvJISFxWl8Tqlwztq0yo22ltZhFRnXfeeWFZlnEAUmYEKuEfu6kPM8+FjPP LKnatGm/2Ea3btZVhNGlA2a4wPKSPc8dV0YBiANILzpttn5c3WQRBbghxvEz8NzQclM0 5CzwZZ9ukVPaImUntUPwNyrjXLoelBTUN271XzTA2+QqunM86zKC8PRX230jTezEZwx+ nVlB4P2AJD9jKBo2iZx31r4NSgHdJiAKYky6ripRfhGXdJ418YD1l9/N4RN99jxbutz6 PiM66bCBLxGDOzfyNHMopnR28yvedc5emKIVF/HV/4tKV7Lm0687IeByegMlSUxMdnyO WDNw== 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=BjmiwAV+qkEddhUojBQVUbZIbS/TIGSArMUYW9Y9o7E=; b=eAcBGGnxGzcMBiB3hFppnO0NU7ad5AEyVtUg4/Y2CsWZXJCPxg1XSA0f+thbx2QCGW WzaYS4vgMI6EtC0Hxk5WYmYboS6Q7iwQZNzIK1mdWYDL7frJlYNx+8mF7urh0is1iuYq 4ftfu4MJpqrb/PSZfi5ISWZsrdb0y5le+FyfQAqKuiie8fvDAQC4M12EfowmmWb0mLbY Mv4RqBAHeAELMwr4QfRmIhWEjqBYXRo2iFU8zO/Rj8xBoVk4sLR4SM9ONW+T2eGiGky4 LxgWZ8NGg0b2P6odAh2rjf5FX2cpMBr+5LjKgKlT+JHPr7LAWTkIKRpBlHr5Z6SZqAf0 K1/A== X-Gm-Message-State: AJIora+nlJInHJy2Y/SmoUyx4isJg2p01ZjWA4GPWGSa9A82/yZHanYG ZVJFoEzWuZmxzqRXhG1kuMzCd/zqNs+o9Q== X-Received: by 2002:a17:90a:7aca:b0:1f1:ff59:fe7e with SMTP id b10-20020a17090a7aca00b001f1ff59fe7emr6171945pjl.11.1658330686691; Wed, 20 Jul 2022 08:24:46 -0700 (PDT) Received: from anup-ubuntu64-vm.. ([122.179.42.230]) by smtp.gmail.com with ESMTPSA id w15-20020a1709026f0f00b0016cf8f0bdd5sm6013031plk.108.2022.07.20.08.24.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 08:24:46 -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 Subject: [PATCH v7 6/7] RISC-V: Use IPIs for remote TLB flush when possible Date: Wed, 20 Jul 2022 20:53:47 +0530 Message-Id: <20220720152348.2889109-7-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220720152348.2889109-1-apatel@ventanamicro.com> References: <20220720152348.2889109-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 --- 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