From patchwork Thu Aug 22 06:56:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11108517 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 47326912 for ; Thu, 22 Aug 2019 06:56:25 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 25ADE233FE for ; Thu, 22 Aug 2019 06:56:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Neb1+SEl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 25ADE233FE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kJHgMMCHfulH9VaME+gqizFTF2aT8BBCa2FRP0zYqgU=; b=Neb1+SEleJa1r4 cufzg9UcB2pdapXR9fqexFSV4z78S1c/jQk/kbBJIqnenVxUKAXxK8wwAkFq1rfuGEyYsvsJzZp8l Hm/0Qya/Xi9NT8Vs8H10gnLuN0ihARr/Q9QPf4fJ0pmxlxP44kOMqw6tQwWVsC93ClAn3StJkMQYA NYgDZuFRssiFEdE9R9h0Ydg0J+3Y/paUrJ8tYLAlqWY5OqSkTRg5W+3KyqixETQ+ip6DzuV5hMZxp 8f1+NCyiBj4LPhj0+rRHW/yhC+k0hfupepy3nDJkqh/1NBkoIu6B3y6DHPbL4Z+aafJcz4rmtuOU/ oEvS3ykPhgdwshHWcjng==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i0h1A-0008ID-U7; Thu, 22 Aug 2019 06:56:20 +0000 Received: from rap-us.hgst.com ([199.255.44.250] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1i0h16-0008GU-Rq; Thu, 22 Aug 2019 06:56:17 +0000 From: Christoph Hellwig To: Palmer Dabbelt , Paul Walmsley Subject: [PATCH 1/8] riscv: fix the flags argument type for riscv_riscv_flush_icache Date: Thu, 22 Aug 2019 15:56:05 +0900 Message-Id: <20190822065612.28634-2-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190822065612.28634-1-hch@lst.de> References: <20190822065612.28634-1-hch@lst.de> MIME-Version: 1.0 X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-riscv@lists.infradead.org Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org While uinptr_t is identical to unsigned long for all Linux platforms, defining a flags argument as an uinptr_t doesn't make any sense, so change it to an unsigned long instead. Signed-off-by: Christoph Hellwig --- arch/riscv/include/asm/vdso.h | 2 +- arch/riscv/kernel/sys_riscv.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/vdso.h b/arch/riscv/include/asm/vdso.h index 7a7fce63c474..a87a9d106220 100644 --- a/arch/riscv/include/asm/vdso.h +++ b/arch/riscv/include/asm/vdso.h @@ -27,6 +27,6 @@ struct vdso_data { (void __user *)((unsigned long)(base) + __vdso_##name); \ }) -asmlinkage long sys_riscv_flush_icache(uintptr_t, uintptr_t, uintptr_t); +asmlinkage long sys_riscv_flush_icache(uintptr_t, uintptr_t, unsigned long); #endif /* _ASM_RISCV_VDSO_H */ diff --git a/arch/riscv/kernel/sys_riscv.c b/arch/riscv/kernel/sys_riscv.c index f3619f59d85c..61f100acbd4c 100644 --- a/arch/riscv/kernel/sys_riscv.c +++ b/arch/riscv/kernel/sys_riscv.c @@ -55,7 +55,7 @@ SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len, * in there for forwards compatibility. */ SYSCALL_DEFINE3(riscv_flush_icache, uintptr_t, start, uintptr_t, end, - uintptr_t, flags) + unsigned long, flags) { /* Check the reserved flags. */ if (unlikely(flags & ~SYS_RISCV_FLUSH_ICACHE_ALL)) From patchwork Thu Aug 22 06:56:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11108519 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5CFE0912 for ; Thu, 22 Aug 2019 06:56:28 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3BCD223400 for ; Thu, 22 Aug 2019 06:56:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="giN0gHxN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3BCD223400 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sJP6eYq4nHvzWBCJoIlvkU2WBQ4uYy4g0icnmcJlpiI=; b=giN0gHxNzYyMcp Kl1q5aBmq9zUPDhGADQUhbTPxvHUF/ZYTEonMqY1O/N5kDpXt7dRFgVGqFFqehnU6pt2js6v4BZiW dD52zL3JB/xbsJ1Lf92teBJ1vCkqNa9P/kVszhRANOmHRXXSbJJU/k0adW6TGvqVZL1w1AoML/7TK YZCmaCqoyRqWzHesK5/9qWypW9pqAA9iab6VZC+UMCoa3O5HcqOhPHZkyImurXi0lTfh0Z9d/aS3D QpsdEaseJS2aCr0ksJLHuUcGtiKuSKvWr1YxElItU1mr1mYkcFG8uLbxiBL4EjB1K05gP2nRPRii3 hFj6QD0hi5lIE3MsIbWg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i0h1D-0008Kz-R9; Thu, 22 Aug 2019 06:56:23 +0000 Received: from rap-us.hgst.com ([199.255.44.250] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1i0h1A-0008Hm-Nl; Thu, 22 Aug 2019 06:56:21 +0000 From: Christoph Hellwig To: Palmer Dabbelt , Paul Walmsley Subject: [PATCH 2/8] riscv: remove SYS_RISCV_FLUSH_ICACHE_LOCAL #define Date: Thu, 22 Aug 2019 15:56:06 +0900 Message-Id: <20190822065612.28634-3-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190822065612.28634-1-hch@lst.de> References: <20190822065612.28634-1-hch@lst.de> MIME-Version: 1.0 X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-riscv@lists.infradead.org Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org It is much better to just check for the supporte flags directly rather than hiding them behind a flag. Signed-off-by: Christoph Hellwig --- arch/riscv/include/asm/cacheflush.h | 1 - arch/riscv/kernel/sys_riscv.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/cacheflush.h b/arch/riscv/include/asm/cacheflush.h index 555b20b11dc3..c8f159740c38 100644 --- a/arch/riscv/include/asm/cacheflush.h +++ b/arch/riscv/include/asm/cacheflush.h @@ -103,6 +103,5 @@ void flush_icache_mm(struct mm_struct *mm, bool local); * Bits in sys_riscv_flush_icache()'s flags argument. */ #define SYS_RISCV_FLUSH_ICACHE_LOCAL 1UL -#define SYS_RISCV_FLUSH_ICACHE_ALL (SYS_RISCV_FLUSH_ICACHE_LOCAL) #endif /* _ASM_RISCV_CACHEFLUSH_H */ diff --git a/arch/riscv/kernel/sys_riscv.c b/arch/riscv/kernel/sys_riscv.c index 61f100acbd4c..5bad71078b61 100644 --- a/arch/riscv/kernel/sys_riscv.c +++ b/arch/riscv/kernel/sys_riscv.c @@ -58,7 +58,7 @@ SYSCALL_DEFINE3(riscv_flush_icache, uintptr_t, start, uintptr_t, end, unsigned long, flags) { /* Check the reserved flags. */ - if (unlikely(flags & ~SYS_RISCV_FLUSH_ICACHE_ALL)) + if (unlikely(flags & ~SYS_RISCV_FLUSH_ICACHE_LOCAL)) return -EINVAL; flush_icache_mm(current->mm, flags & SYS_RISCV_FLUSH_ICACHE_LOCAL); From patchwork Thu Aug 22 06:56:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11108521 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 76A3B912 for ; Thu, 22 Aug 2019 06:56:32 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 55560233A1 for ; Thu, 22 Aug 2019 06:56:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="SUYQTSwD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 55560233A1 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=QTAMTNOInG+C6N3ADkc/eP6DzTtK8uUhZtnLWpvtIQo=; b=SUYQTSwD+c6LzP vRFx1npW/ugG4GMnT2LPkY+qyuFmR2mEWygYEIq3hU+H0w1X77S/N8BIR17mY7JEtk7S4qo4U99Qy DXs34IpwkAPb94rFeQ0PUpGw2Gu78uazFH+EH6oxb6EsrNMfgaFBXjKxg/Drh2OSlMrOfFUdLhidl 3pWVhwhpoPv7oXS6uhBR/cuMHe3ZXkVB6lBpObNnDVvUAsYEcwo6gvwTVzocthHmaJnughm1gh5e6 WjqZVcwFmv+vs+l/XlI3rL6TvY3owX6OhgMpkkcX+BfrNM6jII5ldzIIW1fOAieLxLA07zG77dbV+ 8GzJsWwgAjNw/V/KZ0VQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i0h1H-0008OM-6n; Thu, 22 Aug 2019 06:56:27 +0000 Received: from rap-us.hgst.com ([199.255.44.250] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1i0h1C-0008Iw-M8; Thu, 22 Aug 2019 06:56:22 +0000 From: Christoph Hellwig To: Palmer Dabbelt , Paul Walmsley Subject: [PATCH 3/8] riscv: move sys_riscv_flush_icache to cacheflush.c Date: Thu, 22 Aug 2019 15:56:07 +0900 Message-Id: <20190822065612.28634-4-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190822065612.28634-1-hch@lst.de> References: <20190822065612.28634-1-hch@lst.de> MIME-Version: 1.0 X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-riscv@lists.infradead.org Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org No real need to split this over to files. This allows marking flush_icache_mm static and dropping a superflous argument to it, as well as consolidating the documentation. Signed-off-by: Christoph Hellwig --- arch/riscv/include/asm/cacheflush.h | 2 -- arch/riscv/kernel/sys_riscv.c | 27 --------------- arch/riscv/mm/cacheflush.c | 53 +++++++++++++++++++++-------- 3 files changed, 38 insertions(+), 44 deletions(-) diff --git a/arch/riscv/include/asm/cacheflush.h b/arch/riscv/include/asm/cacheflush.h index c8f159740c38..b86ac3a4653a 100644 --- a/arch/riscv/include/asm/cacheflush.h +++ b/arch/riscv/include/asm/cacheflush.h @@ -90,12 +90,10 @@ static inline void flush_dcache_page(struct page *page) #ifndef CONFIG_SMP #define flush_icache_all() local_flush_icache_all() -#define flush_icache_mm(mm, local) flush_icache_all() #else /* CONFIG_SMP */ void flush_icache_all(void); -void flush_icache_mm(struct mm_struct *mm, bool local); #endif /* CONFIG_SMP */ diff --git a/arch/riscv/kernel/sys_riscv.c b/arch/riscv/kernel/sys_riscv.c index 5bad71078b61..d13e03de3e1a 100644 --- a/arch/riscv/kernel/sys_riscv.c +++ b/arch/riscv/kernel/sys_riscv.c @@ -7,7 +7,6 @@ #include #include -#include static long riscv_sys_mmap(unsigned long addr, unsigned long len, unsigned long prot, unsigned long flags, @@ -39,29 +38,3 @@ SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len, return riscv_sys_mmap(addr, len, prot, flags, fd, offset, 12); } #endif /* !CONFIG_64BIT */ - -/* - * Allows the instruction cache to be flushed from userspace. Despite RISC-V - * having a direct 'fence.i' instruction available to userspace (which we - * can't trap!), that's not actually viable when running on Linux because the - * kernel might schedule a process on another hart. There is no way for - * userspace to handle this without invoking the kernel (as it doesn't know the - * thread->hart mappings), so we've defined a RISC-V specific system call to - * flush the instruction cache. - * - * sys_riscv_flush_icache() is defined to flush the instruction cache over an - * address range, with the flush applying to either all threads or just the - * caller. We don't currently do anything with the address range, that's just - * in there for forwards compatibility. - */ -SYSCALL_DEFINE3(riscv_flush_icache, uintptr_t, start, uintptr_t, end, - unsigned long, flags) -{ - /* Check the reserved flags. */ - if (unlikely(flags & ~SYS_RISCV_FLUSH_ICACHE_LOCAL)) - return -EINVAL; - - flush_icache_mm(current->mm, flags & SYS_RISCV_FLUSH_ICACHE_LOCAL); - - return 0; -} diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c index 3f15938dec89..4f78d6552476 100644 --- a/arch/riscv/mm/cacheflush.c +++ b/arch/riscv/mm/cacheflush.c @@ -3,8 +3,10 @@ * Copyright (C) 2017 SiFive */ +#include #include #include +#include #ifdef CONFIG_SMP @@ -15,17 +17,7 @@ void flush_icache_all(void) sbi_remote_fence_i(NULL); } -/* - * Performs an icache flush for the given MM context. RISC-V has no direct - * mechanism for instruction cache shoot downs, so instead we send an IPI that - * informs the remote harts they need to flush their local instruction caches. - * To avoid pathologically slow behavior in a common case (a bunch of - * single-hart processes on a many-hart machine, ie 'make -j') we avoid the - * IPIs for harts that are not currently executing a MM context and instead - * schedule a deferred local instruction cache flush to be performed before - * execution resumes on each hart. - */ -void flush_icache_mm(struct mm_struct *mm, bool local) +static void flush_icache_mm(bool local) { unsigned int cpu; cpumask_t others, hmask, *mask; @@ -33,7 +25,7 @@ void flush_icache_mm(struct mm_struct *mm, bool local) preempt_disable(); /* Mark every hart's icache as needing a flush for this MM. */ - mask = &mm->context.icache_stale_mask; + mask = ¤t->mm->context.icache_stale_mask; cpumask_setall(mask); /* Flush this hart's I$ now, and mark it as flushed. */ cpu = smp_processor_id(); @@ -44,9 +36,9 @@ void flush_icache_mm(struct mm_struct *mm, bool local) * Flush the I$ of other harts concurrently executing, and mark them as * flushed. */ - cpumask_andnot(&others, mm_cpumask(mm), cpumask_of(cpu)); + cpumask_andnot(&others, mm_cpumask(current->mm), cpumask_of(cpu)); local |= cpumask_empty(&others); - if (mm != current->active_mm || !local) { + if (current->mm != current->active_mm || !local) { riscv_cpuid_to_hartid_mask(&others, &hmask); sbi_remote_fence_i(hmask.bits); } else { @@ -63,9 +55,40 @@ void flush_icache_mm(struct mm_struct *mm, bool local) preempt_enable(); } - +#else +#define flush_icache_mm(local) flush_icache_all() #endif /* CONFIG_SMP */ +/* + * Allows the instruction cache to be flushed from userspace. Despite RISC-V + * having a direct 'fence.i' instruction available to userspace (which we + * can't trap!), that's not actually viable when running on Linux because the + * kernel might schedule a process on another hart. There is no way for + * userspace to handle this without invoking the kernel (as it doesn't know the + * thread->hart mappings), so we've defined a RISC-V specific system call to + * flush the instruction cache. + * + * sys_riscv_flush_icache() is defined to flush the instruction cache over an + * address range, with the flush applying to either all threads or just the + * caller. We don't currently do anything with the address range, that's just + * in there for forwards compatibility. + * + * To avoid pathologically slow behavior in a common case (a bunch of + * single-hart processes on a many-hart machine, ie 'make -j') we avoid the + * remove flush for harts that are not currently executing a MM context and + * instead schedule a deferred local instruction cache flush to be performed + * before execution resumes on each hart. + */ +SYSCALL_DEFINE3(riscv_flush_icache, uintptr_t, start, uintptr_t, end, + unsigned long, flags) +{ + /* Check the reserved flags. */ + if (unlikely(flags & ~SYS_RISCV_FLUSH_ICACHE_LOCAL)) + return -EINVAL; + flush_icache_mm(flags & SYS_RISCV_FLUSH_ICACHE_LOCAL); + return 0; +} + void flush_icache_pte(pte_t pte) { struct page *page = pte_page(pte); From patchwork Thu Aug 22 06:56:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11108523 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D635314F7 for ; Thu, 22 Aug 2019 06:56:35 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B53B1233FE for ; Thu, 22 Aug 2019 06:56:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="PPSYD/iX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B53B1233FE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=F8zosLt3glZ52Njwljko77U0FaX0oFoNR5RuDfGTCgM=; b=PPSYD/iXokCPFy kHLiZCCRW7r0weyp7xGbCGGIWM/D3iDSKlIttSOCF4xuRJmHZlNOeXldltbr3FqCfQOFezGqlkiSv q6/RxM6t08n/wT+aXhRGqwr7OWrePBtJoG8UahWrhpbAADtKhq+UTl9QVRqOlzEWz+9WN4h8A1Nw9 m4e9T7Hy63DZdIKNDSwIWWlsxV1R+f4cZkr5zGTDfcag1H1RO8rUcV25fEr+UnHvZeMwpaHIyA+xD G2mTJFrvZBB0zSS92zMTQlaukHySGa6seUQ7q1e9SN3+p4nSMhy0/cIJYPF7MwUNCDRUlFnopRq71 oPEbNnW8AhlNGBQbuFnw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i0h1K-0008S0-PB; Thu, 22 Aug 2019 06:56:30 +0000 Received: from rap-us.hgst.com ([199.255.44.250] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1i0h1E-0008Kj-Cq; Thu, 22 Aug 2019 06:56:24 +0000 From: Christoph Hellwig To: Palmer Dabbelt , Paul Walmsley Subject: [PATCH 4/8] riscv: remove the active_mm check in sys_riscv_flush_icache Date: Thu, 22 Aug 2019 15:56:08 +0900 Message-Id: <20190822065612.28634-5-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190822065612.28634-1-hch@lst.de> References: <20190822065612.28634-1-hch@lst.de> MIME-Version: 1.0 X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-riscv@lists.infradead.org Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org current->active_mm is always the same as current->mm for user processes (see Documentation/vm/active_mm.rst for details), and given that we are directly in a syscall handler this is obviously the case here. Signed-off-by: Christoph Hellwig --- arch/riscv/mm/cacheflush.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c index 4f78d6552476..eed715de4795 100644 --- a/arch/riscv/mm/cacheflush.c +++ b/arch/riscv/mm/cacheflush.c @@ -38,7 +38,7 @@ static void flush_icache_mm(bool local) */ cpumask_andnot(&others, mm_cpumask(current->mm), cpumask_of(cpu)); local |= cpumask_empty(&others); - if (current->mm != current->active_mm || !local) { + if (!local) { riscv_cpuid_to_hartid_mask(&others, &hmask); sbi_remote_fence_i(hmask.bits); } else { From patchwork Thu Aug 22 06:56:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11108525 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B490014F7 for ; Thu, 22 Aug 2019 06:56:37 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 923FB233A1 for ; Thu, 22 Aug 2019 06:56:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="fGXQ+B3c" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 923FB233A1 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6s6yhIeKowiMIbF7h62ESFq0r+ccvHlU5CfKXkE2ZIk=; b=fGXQ+B3c9fIBWA apdifkGCsH1Najn1mxq3Lt2QvpWGZsn2MhlKcda9ByyDqfBmZzKmkLywAXsISvs0vCLohH98weid9 sk9hUo5MN9lcLLm6W7HOGJ/k2BPvGOYGmD1H3uoudCFFV9Dmo+p3UMGCyGTiGkFnKgOvBE7yK7zqh TmcAQDHVdpQBL9V3sKybkT+fbtAyNp4iI8AeqhyjszWW2jB+zC038/s4Ek7i9QqCxU+/b81UuKqb2 c9P10XviiV9BuPeocuzogb6+q9I70Uh1pgNvrvdWzJMf14WcF/XGO4cmFQ1hIDy/uM49InUMNzA3s TdEjDX5A3lVjDDjlLC8Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i0h1O-0008VC-AV; Thu, 22 Aug 2019 06:56:34 +0000 Received: from rap-us.hgst.com ([199.255.44.250] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1i0h1G-0008Mp-F2; Thu, 22 Aug 2019 06:56:26 +0000 From: Christoph Hellwig To: Palmer Dabbelt , Paul Walmsley Subject: [PATCH 5/8] riscv: actually clear icache_stale_mask for all harts in mm_cpumask Date: Thu, 22 Aug 2019 15:56:09 +0900 Message-Id: <20190822065612.28634-6-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190822065612.28634-1-hch@lst.de> References: <20190822065612.28634-1-hch@lst.de> MIME-Version: 1.0 X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-riscv@lists.infradead.org Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org The comment in flush_icache_mm claim that we mark all harts that we are sending the remote sfence.i to are marked as flushed, but we only actually do this for the current one. Fix the code to actually mark all. Signed-off-by: Christoph Hellwig Reviewed-by: Atish Patra --- arch/riscv/mm/cacheflush.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c index eed715de4795..dacf72f94d12 100644 --- a/arch/riscv/mm/cacheflush.c +++ b/arch/riscv/mm/cacheflush.c @@ -20,21 +20,23 @@ void flush_icache_all(void) static void flush_icache_mm(bool local) { unsigned int cpu; - cpumask_t others, hmask, *mask; + cpumask_t others, hmask; preempt_disable(); - /* Mark every hart's icache as needing a flush for this MM. */ - mask = ¤t->mm->context.icache_stale_mask; - cpumask_setall(mask); + /* + * Mark the I$ for all harts not concurrently executing as needing a + * flush for this MM. + */ + cpumask_andnot(¤t->mm->context.icache_stale_mask, + cpu_possible_mask, mm_cpumask(current->mm)); + /* Flush this hart's I$ now, and mark it as flushed. */ cpu = smp_processor_id(); - cpumask_clear_cpu(cpu, mask); local_flush_icache_all(); /* - * Flush the I$ of other harts concurrently executing, and mark them as - * flushed. + * Flush the I$ of other harts concurrently executing. */ cpumask_andnot(&others, mm_cpumask(current->mm), cpumask_of(cpu)); local |= cpumask_empty(&others); From patchwork Thu Aug 22 06:56:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11108527 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 87A12184E for ; Thu, 22 Aug 2019 06:56:41 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 65CD5233FE for ; Thu, 22 Aug 2019 06:56:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="L80DPNzK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 65CD5233FE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=r4Et63ing9nPvY5S/VsMogEljt7qFK5LefiHZzZpenc=; b=L80DPNzK0BIFNB W9123ig4cpeAYe2baJ7vAj4/jumbQYuPtKuDzp6RGNNS/3oupw78xdMGmDpAi39c+fgrcgRvqSWgx BZ/qhCC2+H1L5JGalNQctoVlKNZbsPDlnyF+82ukczf+SSHmGqBTQfTiu6gMpCrHy07c3DhIqHEsB ounT2Pc6ok3RDwAsCxCYeTuLgA9Lzf3CVZz0biOsLrDOqBY8ieXgAYLhI5EUqGUywwITkni31hgX4 T0nxNlRpCJZeD/hNp/+4NSV5SfvJr3WcySXM5Q3dpUYGQEe6LeSPCzT4o4qrEwFHhKrMwlRJQM11Y Y13u78aQS4JrEiX80vcQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i0h1R-00006m-9h; Thu, 22 Aug 2019 06:56:37 +0000 Received: from rap-us.hgst.com ([199.255.44.250] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1i0h1I-0008Ov-9f; Thu, 22 Aug 2019 06:56:28 +0000 From: Christoph Hellwig To: Palmer Dabbelt , Paul Walmsley Subject: [PATCH 6/8] riscv: use get_cpu and put_cpu in sys_riscv_flush_icache Date: Thu, 22 Aug 2019 15:56:10 +0900 Message-Id: <20190822065612.28634-7-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190822065612.28634-1-hch@lst.de> References: <20190822065612.28634-1-hch@lst.de> MIME-Version: 1.0 X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-riscv@lists.infradead.org Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org Use get_cpu/put_cpu instead of opencoding them. Signed-off-by: Christoph Hellwig Reviewed-by: Atish Patra --- arch/riscv/mm/cacheflush.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c index dacf72f94d12..9180b2e93058 100644 --- a/arch/riscv/mm/cacheflush.c +++ b/arch/riscv/mm/cacheflush.c @@ -19,11 +19,9 @@ void flush_icache_all(void) static void flush_icache_mm(bool local) { - unsigned int cpu; + unsigned int cpu = get_cpu(); cpumask_t others, hmask; - preempt_disable(); - /* * Mark the I$ for all harts not concurrently executing as needing a * flush for this MM. @@ -32,7 +30,6 @@ static void flush_icache_mm(bool local) cpu_possible_mask, mm_cpumask(current->mm)); /* Flush this hart's I$ now, and mark it as flushed. */ - cpu = smp_processor_id(); local_flush_icache_all(); /* @@ -55,7 +52,7 @@ static void flush_icache_mm(bool local) smp_mb(); } - preempt_enable(); + put_cpu(); } #else #define flush_icache_mm(local) flush_icache_all() From patchwork Thu Aug 22 06:56:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11108529 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C183A14F7 for ; Thu, 22 Aug 2019 06:56:43 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9D41E233FF for ; Thu, 22 Aug 2019 06:56:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="SL0J/cUA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9D41E233FF Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4Lq/7Y2PiEU0JG0ImFFM8FQJvoLE7HVs+v4f5zxqLlQ=; b=SL0J/cUAGdhudu ITpwVej9S6rS/MVQ+p5MsGrTvllXIQ5G4EC1eZ1tz9fSSc2p7vKlK07pqtpJ/dAZjqV6/3IlQ/NDc wg13CbKGEyPfv2A6uMiiKhhNOokxZDYdnPwt7NsVyRXpLv06StcrcD7w7a/GbtqPBjkwTbNah3HvK iKDUrfKx0LJqZt+q9MtvgbyJzq3ZaXPWXblYurlg5yWt57tWcwSO77ptHCfpMxgoJeKNWfHjo4f/0 0xm1wF262ly4KmVV+V13eKo3b/ocpnBYJXPQdnhnd3TJqznxMLqBe3Tdmx5Wo+2LL0wQH7GFp/ozj dzX/sy1+1XgSrqZH1OCw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i0h1U-00009t-8r; Thu, 22 Aug 2019 06:56:40 +0000 Received: from rap-us.hgst.com ([199.255.44.250] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1i0h1J-0008Qm-Vp; Thu, 22 Aug 2019 06:56:30 +0000 From: Christoph Hellwig To: Palmer Dabbelt , Paul Walmsley Subject: [PATCH 7/8] riscv: improve the local flushing logic in sys_riscv_flush_icache Date: Thu, 22 Aug 2019 15:56:11 +0900 Message-Id: <20190822065612.28634-8-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190822065612.28634-1-hch@lst.de> References: <20190822065612.28634-1-hch@lst.de> MIME-Version: 1.0 X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-riscv@lists.infradead.org Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org If we have to offload any remote sfence the SBI we might as well let it handle the local one as well. This significantly simplifies the cpumask operations and streamlines the code. Signed-off-by: Christoph Hellwig Reviewed-by: Atish Patra --- arch/riscv/mm/cacheflush.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c index 9180b2e93058..8f1134715fec 100644 --- a/arch/riscv/mm/cacheflush.c +++ b/arch/riscv/mm/cacheflush.c @@ -20,7 +20,6 @@ void flush_icache_all(void) static void flush_icache_mm(bool local) { unsigned int cpu = get_cpu(); - cpumask_t others, hmask; /* * Mark the I$ for all harts not concurrently executing as needing a @@ -29,27 +28,23 @@ static void flush_icache_mm(bool local) cpumask_andnot(¤t->mm->context.icache_stale_mask, cpu_possible_mask, mm_cpumask(current->mm)); - /* Flush this hart's I$ now, and mark it as flushed. */ - local_flush_icache_all(); - /* - * Flush the I$ of other harts concurrently executing. + * It's assumed that at least one strongly ordered operation is + * performed on this hart between setting a hart's cpumask bit and + * scheduling this MM context on that hart. Sending an SBI remote + * message will do this, but in the case where no messages are sent we + * still need to order this hart's writes with flush_icache_deferred(). */ - cpumask_andnot(&others, mm_cpumask(current->mm), cpumask_of(cpu)); - local |= cpumask_empty(&others); - if (!local) { - riscv_cpuid_to_hartid_mask(&others, &hmask); - sbi_remote_fence_i(hmask.bits); - } else { - /* - * It's assumed that at least one strongly ordered operation is - * performed on this hart between setting a hart's cpumask bit - * and scheduling this MM context on that hart. Sending an SBI - * remote message will do this, but in the case where no - * messages are sent we still need to order this hart's writes - * with flush_icache_deferred(). - */ + cpu = get_cpu(); + if (local || + cpumask_any_but(mm_cpumask(current->mm), cpu) >= nr_cpu_ids) { + local_flush_icache_all(); smp_mb(); + } else { + cpumask_t hmask; + + riscv_cpuid_to_hartid_mask(mm_cpumask(current->mm), &hmask); + sbi_remote_fence_i(cpumask_bits(&hmask)); } put_cpu(); From patchwork Thu Aug 22 06:56:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11108531 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 96ECC14F7 for ; Thu, 22 Aug 2019 06:56:46 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7562D233A1 for ; Thu, 22 Aug 2019 06:56:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Jr+W3ZgO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7562D233A1 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RZ8Pv2rfPTWx8jPLsecOiwNFq9+eAWLY2bJcu/gDFGw=; b=Jr+W3ZgOhC4gBW 0DUzT/5snFc/MNbDCk2dAx79fYgDEpEkm64jo0BrtnflMBkaqaAdzu/YE43wtGPo6AtdNvsYyWLmX OEsW+rp7fJrsln9pRuut3zY43oOWsWD6IWNdmLM3CmF2OgSMp3q+ArEYhNw3CmeIxKLHl2wZh/wYi 6fFr/2caFUKiBZRILZErY9BweBMIDQSoF9WdTxtt49WInCu8sHqvBJ+Wb2BcvyY2bSPWha/1LlazN LCz1yHOVMW3Z9x915ka2zFkKT+OC50yD25bzCTtUb6NXq7nxcJmPDqGDdAYKBR+Zdzz8YDz1Z+P9A Ta8s9JotC0TjATUWVQBA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i0h1X-0000DA-5s; Thu, 22 Aug 2019 06:56:43 +0000 Received: from rap-us.hgst.com ([199.255.44.250] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1i0h1L-0008SA-Lq; Thu, 22 Aug 2019 06:56:31 +0000 From: Christoph Hellwig To: Palmer Dabbelt , Paul Walmsley Subject: [PATCH 8/8] riscv: ignore the SYS_RISCV_FLUSH_ICACHE_LOCAL flag Date: Thu, 22 Aug 2019 15:56:12 +0900 Message-Id: <20190822065612.28634-9-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190822065612.28634-1-hch@lst.de> References: <20190822065612.28634-1-hch@lst.de> MIME-Version: 1.0 X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-riscv@lists.infradead.org Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org The SYS_RISCV_FLUSH_ICACHE_LOCAL is built on the flawed assumption that there is such a thing as a local cpu outside of in-kernel preemption disabled sections. Just ignore the flag as it can't be used in a safe way. Signed-off-by: Christoph Hellwig --- arch/riscv/include/asm/cacheflush.h | 2 +- arch/riscv/mm/cacheflush.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/arch/riscv/include/asm/cacheflush.h b/arch/riscv/include/asm/cacheflush.h index b86ac3a4653a..3c18d956c970 100644 --- a/arch/riscv/include/asm/cacheflush.h +++ b/arch/riscv/include/asm/cacheflush.h @@ -100,6 +100,6 @@ void flush_icache_all(void); /* * Bits in sys_riscv_flush_icache()'s flags argument. */ -#define SYS_RISCV_FLUSH_ICACHE_LOCAL 1UL +#define SYS_RISCV_FLUSH_ICACHE_LOCAL 1UL /* ignored */ #endif /* _ASM_RISCV_CACHEFLUSH_H */ diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c index 8f1134715fec..4b6ecc3431e2 100644 --- a/arch/riscv/mm/cacheflush.c +++ b/arch/riscv/mm/cacheflush.c @@ -17,7 +17,7 @@ void flush_icache_all(void) sbi_remote_fence_i(NULL); } -static void flush_icache_mm(bool local) +static void flush_icache_mm(void) { unsigned int cpu = get_cpu(); @@ -36,8 +36,7 @@ static void flush_icache_mm(bool local) * still need to order this hart's writes with flush_icache_deferred(). */ cpu = get_cpu(); - if (local || - cpumask_any_but(mm_cpumask(current->mm), cpu) >= nr_cpu_ids) { + if (cpumask_any_but(mm_cpumask(current->mm), cpu) >= nr_cpu_ids) { local_flush_icache_all(); smp_mb(); } else { @@ -50,7 +49,7 @@ static void flush_icache_mm(bool local) put_cpu(); } #else -#define flush_icache_mm(local) flush_icache_all() +#define flush_icache_mm() flush_icache_all() #endif /* CONFIG_SMP */ /* @@ -72,6 +71,10 @@ static void flush_icache_mm(bool local) * remove flush for harts that are not currently executing a MM context and * instead schedule a deferred local instruction cache flush to be performed * before execution resumes on each hart. + * + * Note that we ignore the SYS_RISCV_FLUSH_ICACHE_LOCAL flag, as there is + * absolutely not way to ensure the local CPU is still the same by the time we + * return from the syscall. */ SYSCALL_DEFINE3(riscv_flush_icache, uintptr_t, start, uintptr_t, end, unsigned long, flags) @@ -79,7 +82,7 @@ SYSCALL_DEFINE3(riscv_flush_icache, uintptr_t, start, uintptr_t, end, /* Check the reserved flags. */ if (unlikely(flags & ~SYS_RISCV_FLUSH_ICACHE_LOCAL)) return -EINVAL; - flush_icache_mm(flags & SYS_RISCV_FLUSH_ICACHE_LOCAL); + flush_icache_mm(); return 0; }