Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2026798ybd; Sun, 23 Jun 2019 22:45:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqwB7snnKyf9KdYMpsnuvjrBYAzGckLiYj5TGxebSIu29Ikcpp05EzU24dJacpnI4/JtuJeu X-Received: by 2002:a17:90a:20c6:: with SMTP id f64mr2271642pjg.57.1561355154329; Sun, 23 Jun 2019 22:45:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561355154; cv=none; d=google.com; s=arc-20160816; b=KtXt6cdMkqbtaJ+EZNkTy8tNX2xSF9xdL6f6/PWZ3Ofotk+n1nnySJDL3NQQdHY6Bl v/sjGHLBauqhZS02VpeI8p4mQYnltpdBD2bT8Ol6RdAkc0QGvZN/T5cv2OV4wh+H3B/b 4vIr9qtLH0W6jxE0bRYXYpcoWC98U0LdaXme524Ewx2/y6ehzvAMVlD/VM99mqZjTpol fh3GeD80Y0IN9FJUvzCxb17PJZIJ30v64DmjIt8E4IUKvqWPrfUqyS52bie3celz9E+X YdxBnLRWZztsHic/t1xTMZ1k54t0Li4pQ8+HMWteBnt2rng7LibDbKzdqqHouMtCra2p igAA== 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=w0ZOGNltwfdu3muvc1SLF6vz3WkdFQMMgiXWzVd+rEOhutEUDCcwFvBhh93UTG91x/ bBLbm5Quqz5Om+3RZ5aBN+tkenIT7YFL2XyS7neb+iOji/HFDwOUkB4MFJX2BmCKZqbT Oq1bB2feMteks+0dEEMBJqZyZsOzypL3GWnTzmupc4AfcYbpB0ZXTR41KhZv+pRqpo/4 OQqjsAMB+i0API2lyi4wwNw+PWEuodACexrPrBYwVBdnThIECnkSiTvDPXizCjiKMNVq HFf/zwWNV70QVqrrCVdyjPtDn+s1k4zJ/1d87SvpHHXtyoRe8Rlv/mzs2pBKiC0+Us0A j05g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=DsBS4El+; 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 u6si10097756pjv.29.2019.06.23.22.45.38; Sun, 23 Jun 2019 22:45:54 -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=DsBS4El+; 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 S1727488AbfFXFn6 (ORCPT + 99 others); Mon, 24 Jun 2019 01:43:58 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:37630 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727463AbfFXFn5 (ORCPT ); Mon, 24 Jun 2019 01:43:57 -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=DsBS4El+mIDdDpYL3biKUdVRJ/ gRsHj2wUwnw4hOCIz4900CEw/5hNBn83QXaN/N05RmdL9tzK/1lSSI2iqYVahKMo0XaXpwbjdtPKY 6fusC2JxKNUi6Wcy0DXpKqNMuKP3VS4bgMDOkykPUY3EwbA92QOKfS/y0+A1ROpcg74mXxa1pHNsX 9CDeIJ4QBgCUmvopkpBdjN2FiVF9Xk0wvrMzGPRniCqFcnTi6ht8NvrkQmjx+LMwEtdRQIot497Y4 RLH6FazV3C/man5B6AAVTMf3gveCXvtw/C+Z1o9GZMvhIJFNTotzhkFBiUgBSrkjzl4YyRHeCmXX9 6f7Z39Vg==; Received: from 213-225-6-159.nat.highway.a1.net ([213.225.6.159] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1hfHlj-0006gQ-Me; Mon, 24 Jun 2019 05:43:56 +0000 From: Christoph Hellwig To: Palmer Dabbelt , Paul Walmsley Cc: Damien Le Moal , linux-riscv@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 12/17] riscv: implement remote sfence.i natively for M-mode Date: Mon, 24 Jun 2019 07:43:06 +0200 Message-Id: <20190624054311.30256-13-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190624054311.30256-1-hch@lst.de> References: <20190624054311.30256-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