Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1279838ybg; Fri, 18 Oct 2019 15:07:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqyjpGYbaQDNwyjqmxzkCdpB+qFlz7z2nFWehqHF10RpYEl+gYPrJ8QzCCjWHwd3Mh97DzhB X-Received: by 2002:aa7:d748:: with SMTP id a8mr12000088eds.269.1571436477905; Fri, 18 Oct 2019 15:07:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571436477; cv=none; d=google.com; s=arc-20160816; b=JW0WHfv4e7qKxXvagPF47RjCD+NOGZjNrMIibP/7GG+qnNeMSTyXUNTNWtqIYn2uOl /g+KisAGKPpwiopfp7Zmzk3COod7v9rhEY/DyrNhIzQ4FiAUaIwuhUmNGSuIBvlHlILv sHU93CpngUOVPPNkHKwszhureU5JhkeXbn8Ox1Nf1Q5RApV2+a0oDiGBbGDuMjr9erQB pjOdTPnkN75DaQtdDbZndckQTRLODgCuqd9kJoOTlp52n394rWczPnxS8OYu/4D4xhGQ rLwUDBcyHnYA4AgsUsdxbVQzhMiyix2W6vwkkIkjtx9pdjqrEMWR6eEcnPKS8merkwmZ mlmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=I+Ha505GC7EKQxF2z8v0txeI99YQY2iPA3pVF1omXZ0=; b=wzWEpRqUL27TcIpu3CoJIyVH5PxL5gEP9I5jzpbhfLXft4QiDtSqNfcRk+SPM0nqRA RnCGpkGFeEm22DU7EJkGBaXMSdYvPbECgjrx8JupgsfXbqzuQVzz2Iy5WoeOM7m2F7uP zF/L801z+7chJhw2BvjMqfiMgUZNaSRqUZ5R5m7XYGLvtDxA6SIe5yQRl611UgUxwux1 QNU1vxH30s3vtgoKn/k20NhtLEiEVnrztDP75Gu391wZ5sWGsc/ocB9OR4KSAp7uujdc 4ZLu+x0dXj5q1R0VSOm2p1quQL3LbIEnD6DF7EkKnHHkpXr9BcHXAzuY+xHdW2V0evce 0whg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=AwvVKSdb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f1si4322587ejw.217.2019.10.18.15.07.34; Fri, 18 Oct 2019 15:07:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=AwvVKSdb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2503088AbfJQRiH (ORCPT + 99 others); Thu, 17 Oct 2019 13:38:07 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:36328 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2503079AbfJQRiG (ORCPT ); Thu, 17 Oct 2019 13:38:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=I+Ha505GC7EKQxF2z8v0txeI99YQY2iPA3pVF1omXZ0=; b=AwvVKSdbvrTkq/k6Tq8JtKRvX5 oHVTKYctrzTLVNRlR6VyD48kN0iPJjWjUkidTD53lkaKRWMCqU/fj7aQMF8g79JYEJt6udtwoFlHd xHdtDluQ2CAy1MN26uZditri47VR+6Aa0OlebPKn9EJmfWvBWy0LtQ1DmVkiBdhLBWjC/d4U78fPI s2kE9ssSB30T2zZyeKo+ukhDrmL9qXvI40Z724j3mCTroQhu569wdtGfCSGFOOcvOBWnq1qPvwnck wq5me3/ke0yIxh0gpwc3MfC7q+IJRr92dq9MPl7F6/kfXTx9lXKpG7yiaZKvOKC1vxseR2HxPV3mR rcA2igPA==; Received: from [2001:4bb8:18c:d7b:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1iL9it-0007iQ-Aj; Thu, 17 Oct 2019 17:38:03 +0000 From: Christoph Hellwig To: Palmer Dabbelt , Paul Walmsley Cc: Damien Le Moal , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 07/15] riscv: implement remote sfence.i using IPIs Date: Thu, 17 Oct 2019 19:37:35 +0200 Message-Id: <20191017173743.5430-8-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191017173743.5430-1-hch@lst.de> References: <20191017173743.5430-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The RISC-V ISA only supports flushing the instruction cache for the local CPU core. Currently we always offload the remote TLB flushing to the SBI, which then issues an IPI under the hoods. But with M-mode we do not have an SBI so we have to do it ourselves. IPI to the other nodes using the existing kernel helpers instead if we have native clint support and thus can IPI directly from the kernel. Signed-off-by: Christoph Hellwig --- arch/riscv/include/asm/sbi.h | 3 +++ arch/riscv/mm/cacheflush.c | 24 ++++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index b167af3e7470..0cb74eccc73f 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -94,5 +94,8 @@ static inline void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, { SBI_CALL_4(SBI_REMOTE_SFENCE_VMA_ASID, hart_mask, start, size, asid); } +#else /* CONFIG_RISCV_SBI */ +/* stub to for code is only reachable under IS_ENABLED(CONFIG_RISCV_SBI): */ +void sbi_remote_fence_i(const unsigned long *hart_mask); #endif /* CONFIG_RISCV_SBI */ #endif /* _ASM_RISCV_SBI_H */ diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c index 3f15938dec89..794c9ab256eb 100644 --- a/arch/riscv/mm/cacheflush.c +++ b/arch/riscv/mm/cacheflush.c @@ -10,9 +10,17 @@ #include +static void ipi_remote_fence_i(void *info) +{ + return local_flush_icache_all(); +} + void flush_icache_all(void) { - sbi_remote_fence_i(NULL); + if (IS_ENABLED(CONFIG_RISCV_SBI)) + sbi_remote_fence_i(NULL); + else + on_each_cpu(ipi_remote_fence_i, NULL, 1); } /* @@ -28,7 +36,7 @@ void flush_icache_all(void) void flush_icache_mm(struct mm_struct *mm, bool local) { unsigned int cpu; - cpumask_t others, hmask, *mask; + cpumask_t others, *mask; preempt_disable(); @@ -46,10 +54,7 @@ void flush_icache_mm(struct mm_struct *mm, bool local) */ cpumask_andnot(&others, mm_cpumask(mm), cpumask_of(cpu)); local |= cpumask_empty(&others); - if (mm != current->active_mm || !local) { - riscv_cpuid_to_hartid_mask(&others, &hmask); - sbi_remote_fence_i(hmask.bits); - } else { + if (mm == current->active_mm && local) { /* * It's assumed that at least one strongly ordered operation is * performed on this hart between setting a hart's cpumask bit @@ -59,6 +64,13 @@ void flush_icache_mm(struct mm_struct *mm, bool local) * with flush_icache_deferred(). */ smp_mb(); + } else if (IS_ENABLED(CONFIG_RISCV_SBI)) { + cpumask_t hartid_mask; + + riscv_cpuid_to_hartid_mask(&others, &hartid_mask); + sbi_remote_fence_i(cpumask_bits(&hartid_mask)); + } else { + on_each_cpu_mask(&others, ipi_remote_fence_i, NULL, 1); } preempt_enable(); -- 2.20.1