Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1199191ybl; Tue, 13 Aug 2019 08:51:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqyiz53TR8ApRLhLLqqEeQ43LcxB++K2utHUAz79GbbqaBHkq4slMTUpVwusr3Vm5gatki4/ X-Received: by 2002:a63:cc14:: with SMTP id x20mr35461123pgf.142.1565711509155; Tue, 13 Aug 2019 08:51:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565711509; cv=none; d=google.com; s=arc-20160816; b=mhbdgJTpP6QszaLMFBgRz9ngTiSqJFBkBcRQ2JTAjNunfrEfc91RVnCgHBe0opyLsX 4JOeAv/K4AKE//P+EkRKy73+Z1b8hEx2cwsyQERRZ1z+MMaiwdVCsVGVYhliNRqn5/Nv FKpijIGAlUotw8XSJJpVlbXXJ0FedSJWodGPSskjd1LsnXa/OxF2eb5F+Df1bap71BWs R4u5kTvZRPv30iMez80CxAr1EQvvCpkpmFmHsMziPpfY+5iG+rFNysWeEB6WApZKHS75 0u3za70ep7q7BohnadB5mdexpiVppcoUQIQuGEOXVJCbVJjvxRjEnofB5+K9iNTbKRVc LyUQ== 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=QKrZKqm9xX7/gKntli3kjDV0bZW8VwVWFoBUswi6ZbI=; b=pCRpAhzBZUA61wmZUBTJwpo8OiASJfc4+Yy+v6Z+ubPq4PLpiDzHUb8wAs22LfjmT8 sA2VYJ0OIDfmvCihfgDAsNmuWiOSOvOLwylKq4vxdrzDFdOvB1l1hu6mz5IxJblPyGq9 N+pTpYJwq45Zkc9SRll9kroZqQMiEvg9taFl0OsiGZRYSwU6nfqvs/cbYknf0KD0hS4H BhM7m9gVYuIx5425Fz3vIWoeOXuUZkO/kkE/c+YasNNIJLH7AfXwDsT/3wLExKPBgmJl NxOOQ+DB4CYYYu54/dSCZArIrkFYwbyiRRm+CwDv8PkDMLZ5RHnmFM9pvg0XyP2mIDQe 9dpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=EteqEOXI; 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 z186si64846111pgd.162.2019.08.13.08.51.33; Tue, 13 Aug 2019 08:51:49 -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=EteqEOXI; 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 S1730216AbfHMPsQ (ORCPT + 99 others); Tue, 13 Aug 2019 11:48:16 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:45240 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730209AbfHMPsQ (ORCPT ); Tue, 13 Aug 2019 11:48:16 -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=QKrZKqm9xX7/gKntli3kjDV0bZW8VwVWFoBUswi6ZbI=; b=EteqEOXIET0tWjttOs8yG7q9iP WiRAJsSgjVccNRZwrHedX1TPYLHuuMafbM7Odac45JrZI/jyTR7s5nAu+f0OL0NF801jMg+cJxUIO RjZrmSEX48zI5QNs/XDKWf0KjxHbUvmbW/Jf6M9XtqirEDuwcrjzcj/TZHXjhTf3UvHsrE6Y9YL5P ++Ynr2cz8F3Frnmrsh/nFTR5mjv9m/DGi2IWnQzQQ5NEs5v8HNpHdw2r9JEwAmcVZukpiVGk7q0e1 lVSJN2neYYD+I1lMLiXue2JvQqneOiWljiUUAOSSf/v6Axmk+wO50Hyq5kxIW2J4f3fCGyFS4JiZD 2P52qeiA==; Received: from [2001:4bb8:180:1ec3:c70:4a89:bc61:2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1hxZ1y-00056s-1s; Tue, 13 Aug 2019 15:48:14 +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 09/15] riscv: implement remote sfence.i natively for M-mode Date: Tue, 13 Aug 2019 17:47:41 +0200 Message-Id: <20190813154747.24256-10-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190813154747.24256-1-hch@lst.de> References: <20190813154747.24256-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. For normal S-mode Linux remote flushing is offloaded to machine mode using ecalls, but for M-mode Linux we'll have to do it ourselves. Use the same implementation as all the existing open source SBI implementations by just doing an IPI to all remote cores to execute th sfence.i instruction on every live core. Signed-off-by: Christoph Hellwig --- arch/riscv/mm/cacheflush.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c index 9ebcff8ba263..10875ea1065e 100644 --- a/arch/riscv/mm/cacheflush.c +++ b/arch/riscv/mm/cacheflush.c @@ -10,10 +10,35 @@ #include +#ifdef CONFIG_M_MODE +static void ipi_remote_fence_i(void *info) +{ + return local_flush_icache_all(); +} + +void flush_icache_all(void) +{ + on_each_cpu(ipi_remote_fence_i, NULL, 1); +} + +static void flush_icache_cpumask(const cpumask_t *mask) +{ + on_each_cpu_mask(mask, ipi_remote_fence_i, NULL, 1); +} +#else /* CONFIG_M_MODE */ void flush_icache_all(void) { sbi_remote_fence_i(NULL); } +static void flush_icache_cpumask(const cpumask_t *mask) +{ + cpumask_t hmask; + + cpumask_clear(&hmask); + riscv_cpuid_to_hartid_mask(mask, &hmask); + sbi_remote_fence_i(hmask.bits); +} +#endif /* CONFIG_M_MODE */ /* * Performs an icache flush for the given MM context. RISC-V has no direct @@ -28,7 +53,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(); @@ -47,9 +72,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) { - cpumask_clear(&hmask); - riscv_cpuid_to_hartid_mask(&others, &hmask); - sbi_remote_fence_i(hmask.bits); + flush_icache_cpumask(&others); } else { /* * It's assumed that at least one strongly ordered operation is -- 2.20.1