Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2446235yba; Mon, 15 Apr 2019 11:48:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqwcgmhi0aZH95Nwgh06xGe+g4RNc0MtUDvjk6afKxAYzFVgiAz6dy1y5VetwG2Sb1ZYmVJC X-Received: by 2002:a63:ed48:: with SMTP id m8mr57904859pgk.104.1555354112496; Mon, 15 Apr 2019 11:48:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555354112; cv=none; d=google.com; s=arc-20160816; b=yCxU06AhCk+e9Psym1iE0CY07HE0wgGE+AmedCFTvhrTiQ7GSn8rtofLRFDuR5LZsn rdyrnwH4TxH0JSYhiLT++o++86oDZNi6dIGKsjngorVBXwxdPTqdskxl6X3W1bICrWu0 PtBQZYWOkvwJjXujSJgOy87e/VbCeP0LQi3Wm24ze7uVilW0L3HX4rtKPcoG3VibL9U7 YqzEZn74wnbW09cKy4qPwif8hQp0ciBTdtGB22GTf9mEuqnkxqW9Ne7xdCHehSCGZMSJ XVO4tk8zKVjoqDFcCmGVWCLR1c8rkAtbRNl1nkfFhtq6W13bX9xZ+EgTepb5EQ3ltk40 Q/mg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Br7hOcoZcwk5T+UTYxA8JYRnunovBdmERxiPwCZEol8=; b=rmzClZq6qerxvm75B2Lrg5gQ3AfSN4ckwbPmWv9YMYGgmzRUt0w+XZYajzLbQKI0ou zWUm2RvrCS6SqGQWAM7a4gRsq3pceQnYJKpDfUKy4SJGfhKtoA5hiuGhbOnGSyRFqMHq 9S1ktZhNjC7pXUmzx0VdsjYNiW2YHbVbqq+81jy5t+mxq2ftqTlMEu25F9lgj1+6xNKz vFpAfcICr91t+0GGV/lcxDspbJAePcf39kJ3O9tUGfpXHbm2uq4CLbWRUwJydOnnrJRd cwCyWkDGTpRl3TkuQBr6kBEsYQNthraCGwvLAqffSmEAytZUdJlYjj0UGXmTWSaOkxwz WujA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QitcmDqk; 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 k1si37799856pgq.219.2019.04.15.11.48.15; Mon, 15 Apr 2019 11:48:32 -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=pass header.i=@kernel.org header.s=default header.b=QitcmDqk; 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 S1728506AbfDOSqB (ORCPT + 99 others); Mon, 15 Apr 2019 14:46:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:48528 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728488AbfDOSp7 (ORCPT ); Mon, 15 Apr 2019 14:45:59 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BA10C2073F; Mon, 15 Apr 2019 18:45:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555353958; bh=s9sMv9axfHEuQry7PzFl/m9OJPt+qzYJvn/BBtTOB6E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QitcmDqk3RtFhbDh7eonHjxG5JEaxORb1+VphH3RuzvONgT8wVVhT8VTmbAznV94v rIsw9KtkPLVrWHJ14C2RJwBjhgdLTYvGTOnOduo9QEr0uE9ACe2xTETnKcZxShzVLq gHuGjkMjB9Urnbh0lm7R5+6qJSJVhOGKnBW0VqYs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Diana Craciun , Michael Ellerman , Sasha Levin Subject: [PATCH 4.9 25/76] powerpc/fsl: Add barrier_nospec implementation for NXP PowerPC Book3E Date: Mon, 15 Apr 2019 20:43:49 +0200 Message-Id: <20190415183714.201156164@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190415183707.712011689@linuxfoundation.org> References: <20190415183707.712011689@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org commit ebcd1bfc33c7a90df941df68a6e5d4018c022fba upstream. Implement the barrier_nospec as a isync;sync instruction sequence. The implementation uses the infrastructure built for BOOK3S 64. Signed-off-by: Diana Craciun [mpe: Split out of larger patch] Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin --- arch/powerpc/Kconfig | 2 +- arch/powerpc/include/asm/barrier.h | 8 +++++++- arch/powerpc/lib/feature-fixups.c | 31 ++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index a238698178fc..fa8f2aa88189 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -167,7 +167,7 @@ config PPC config PPC_BARRIER_NOSPEC bool default y - depends on PPC_BOOK3S_64 + depends on PPC_BOOK3S_64 || PPC_FSL_BOOK3E config GENERIC_CSUM def_bool CPU_LITTLE_ENDIAN diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h index 465a64316897..80024c4f2093 100644 --- a/arch/powerpc/include/asm/barrier.h +++ b/arch/powerpc/include/asm/barrier.h @@ -77,12 +77,18 @@ do { \ #define smp_mb__before_spinlock() smp_mb() +#ifdef CONFIG_PPC_BOOK3S_64 +#define NOSPEC_BARRIER_SLOT nop +#elif defined(CONFIG_PPC_FSL_BOOK3E) +#define NOSPEC_BARRIER_SLOT nop; nop +#endif + #ifdef CONFIG_PPC_BARRIER_NOSPEC /* * Prevent execution of subsequent instructions until preceding branches have * been fully resolved and are no longer executing speculatively. */ -#define barrier_nospec_asm NOSPEC_BARRIER_FIXUP_SECTION; nop +#define barrier_nospec_asm NOSPEC_BARRIER_FIXUP_SECTION; NOSPEC_BARRIER_SLOT // This also acts as a compiler barrier due to the memory clobber. #define barrier_nospec() asm (stringify_in_c(barrier_nospec_asm) ::: "memory") diff --git a/arch/powerpc/lib/feature-fixups.c b/arch/powerpc/lib/feature-fixups.c index 5df57f7bae0a..b3e362437ec4 100644 --- a/arch/powerpc/lib/feature-fixups.c +++ b/arch/powerpc/lib/feature-fixups.c @@ -318,6 +318,37 @@ void do_barrier_nospec_fixups(bool enable) } #endif /* CONFIG_PPC_BARRIER_NOSPEC */ +#ifdef CONFIG_PPC_FSL_BOOK3E +void do_barrier_nospec_fixups_range(bool enable, void *fixup_start, void *fixup_end) +{ + unsigned int instr[2], *dest; + long *start, *end; + int i; + + start = fixup_start; + end = fixup_end; + + instr[0] = PPC_INST_NOP; + instr[1] = PPC_INST_NOP; + + if (enable) { + pr_info("barrier-nospec: using isync; sync as speculation barrier\n"); + instr[0] = PPC_INST_ISYNC; + instr[1] = PPC_INST_SYNC; + } + + for (i = 0; start < end; start++, i++) { + dest = (void *)start + *start; + + pr_devel("patching dest %lx\n", (unsigned long)dest); + patch_instruction(dest, instr[0]); + patch_instruction(dest + 1, instr[1]); + } + + printk(KERN_DEBUG "barrier-nospec: patched %d locations\n", i); +} +#endif /* CONFIG_PPC_FSL_BOOK3E */ + void do_lwsync_fixups(unsigned long value, void *fixup_start, void *fixup_end) { long *start, *end; -- 2.19.1