Received: by 10.213.65.68 with SMTP id h4csp519108imn; Tue, 13 Mar 2018 11:36:51 -0700 (PDT) X-Google-Smtp-Source: AG47ELtz6oddU+6ovoQeY5aPK0VpPS/VRqB8hoqCOnTLWJ0nmv7nqFuP5jQG0bfcLCZQmZOoUy7H X-Received: by 10.99.109.136 with SMTP id i130mr1296269pgc.380.1520966211244; Tue, 13 Mar 2018 11:36:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520966211; cv=none; d=google.com; s=arc-20160816; b=AQk/mBPLblJkID9Cr9gW8pU6aIVDseQyDU2Spq+74fZixu3Qu1eBg16oQzJpcqpXrd 4DK4Cog5ABCVBTVFQTlgQcJuGv0a5kzZFOPu7GGrcIGYiqTjZDRjFEAnM6N/fqd6QIsZ 5KpCldR3k7vI/KQWU2dzVj1EeJC07dKssJ51OVQl+0bnfu9fsjHHAjz1zRfBpo0EtiJ9 TH/j5ZYqwV/Fvw+3GU+Q1G7h2gAofs/BKXpEFsbAykypx9LLRgV5QUav6Evzl0Gp0gRQ VPxi2SSOmBWVxvTgOM382zNeyToOx6o1mHPUWksDMKywnS1H9yel9RKnh/1zlBSHaN+9 TBew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Fld6uJP5Aqml4QRfrvX0U7CWn18jOY4Hw1l5s3NUfUw=; b=K8q+a4M2WRfYoRMwQfM8joHTJM6GiQ1GC/xXo0nZ8SOMU533Q50Kib4rjIW+CR/myg acBKHAUOnmFBVUrfPQAZHtQdSax5h1zq1NnNy9k1r7PWowyopstDAprL2ljRo+1ARB1j TuI7XI1Y4bPOl7KjKR21XvG5phi9L01I3XZdRd8uOnFXJRueXUyD9DJ7tGnHY0Cdy/0E 1JOo0TKXz5PzIx3OXNlJOP/dEiJvpG/1mPLhih/0jc1y0vgcfdJU8xMKgX2+rNkLiHso 3OO4l7Ti9ysYMZmOoPwvuEQxK7IBc/RvDq0CWVKg48EYAiBQbB7/vCECEwyoTiP+iCsF 7ZyQ== ARC-Authentication-Results: i=1; mx.google.com; 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 u86si549926pfa.69.2018.03.13.11.36.36; Tue, 13 Mar 2018 11:36:51 -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; 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 S1752750AbeCMSfD (ORCPT + 99 others); Tue, 13 Mar 2018 14:35:03 -0400 Received: from mx2.suse.de ([195.135.220.15]:53540 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752402AbeCMSdx (ORCPT ); Tue, 13 Mar 2018 14:33:53 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 32464AF53; Tue, 13 Mar 2018 18:33:52 +0000 (UTC) From: Michal Suchanek To: linuxppc-dev@lists.ozlabs.org Cc: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Peter Zijlstra , Michal Suchanek , Kate Stewart , Greg Kroah-Hartman , Philippe Ombredanne , Nicholas Piggin , "Tobin C. Harding" , Mahesh Salgaonkar , David Gibson , Al Viro , Michael Neuling , "Oliver O'Halloran" , "Naveen N. Rao" , Madhavan Srinivasan , Masami Hiramatsu , Andrew Morton , Balbir Singh , Sergey Senozhatsky , Christophe Leroy , Andrew Donnellan , Daniel Axtens , Russell Currey , Joe Perches , "Bryant G. Ly" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , linux-kernel@vger.kernel.org Subject: [PATCH RFC 4/8] powerpc/64s: Add support for ori barrier_nospec Date: Tue, 13 Mar 2018 19:33:02 +0100 Message-Id: <50e3f58ffadc2ffdda68df768610816734b30ddd.1520965380.git.msuchanek@suse.de> X-Mailer: git-send-email 2.13.6 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Copypasta from rfi implementation Signed-off-by: Michal Suchanek --- arch/powerpc/include/asm/barrier.h | 4 ++-- arch/powerpc/include/asm/feature-fixups.h | 9 +++++++++ arch/powerpc/include/asm/setup.h | 8 ++++++++ arch/powerpc/kernel/setup_64.c | 29 +++++++++++++++++++++++++++++ arch/powerpc/kernel/vmlinux.lds.S | 7 +++++++ arch/powerpc/lib/feature-fixups.c | 27 +++++++++++++++++++++++++++ 6 files changed, 82 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h index 8e47b3abe405..4079a95e84c2 100644 --- a/arch/powerpc/include/asm/barrier.h +++ b/arch/powerpc/include/asm/barrier.h @@ -75,9 +75,9 @@ do { \ ___p1; \ }) -/* TODO: add patching so this can be disabled */ /* Prevent speculative execution past this barrier. */ -#define barrier_nospec_asm ori 31,31,0 +#define barrier_nospec_asm SPEC_BARRIER_FIXUP_SECTION; \ + nop #ifdef __ASSEMBLY__ #define barrier_nospec barrier_nospec_asm #else diff --git a/arch/powerpc/include/asm/feature-fixups.h b/arch/powerpc/include/asm/feature-fixups.h index 1e82eb3caabd..9d3382618ffd 100644 --- a/arch/powerpc/include/asm/feature-fixups.h +++ b/arch/powerpc/include/asm/feature-fixups.h @@ -195,11 +195,20 @@ label##3: \ FTR_ENTRY_OFFSET 951b-952b; \ .popsection; +#define SPEC_BARRIER_FIXUP_SECTION \ +953: \ + .pushsection __spec_barrier_fixup,"a"; \ + .align 2; \ +954: \ + FTR_ENTRY_OFFSET 953b-954b; \ + .popsection; + #ifndef __ASSEMBLY__ #include extern long __start___rfi_flush_fixup, __stop___rfi_flush_fixup; +extern long __start___spec_barrier_fixup, __stop___spec_barrier_fixup; void apply_feature_fixups(void); void setup_feature_keys(void); diff --git a/arch/powerpc/include/asm/setup.h b/arch/powerpc/include/asm/setup.h index 469b7fdc9be4..486d02e4a310 100644 --- a/arch/powerpc/include/asm/setup.h +++ b/arch/powerpc/include/asm/setup.h @@ -49,8 +49,16 @@ enum l1d_flush_type { L1D_FLUSH_MTTRIG = 0x8, }; +/* These are bit flags */ +enum spec_barrier_type { + SPEC_BARRIER_NONE = 0x1, + SPEC_BARRIER_ORI = 0x2, +}; + void __init setup_rfi_flush(enum l1d_flush_type, bool enable); void do_rfi_flush_fixups(enum l1d_flush_type types); +void __init setup_barrier_nospec(enum spec_barrier_type, bool enable); +void do_barrier_nospec_fixups(enum spec_barrier_type type); #endif /* !__ASSEMBLY__ */ diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c index c388cc3357fa..09f21a954bfc 100644 --- a/arch/powerpc/kernel/setup_64.c +++ b/arch/powerpc/kernel/setup_64.c @@ -815,6 +815,10 @@ static enum l1d_flush_type enabled_flush_types; static void *l1d_flush_fallback_area; static bool no_rfi_flush; bool rfi_flush; +enum spec_barrier_type powerpc_barrier_nospec; +static enum spec_barrier_type barrier_nospec_type; +static bool no_nospec; +bool barrier_nospec_enabled; static int __init handle_no_rfi_flush(char *p) { @@ -899,6 +903,31 @@ void __init setup_rfi_flush(enum l1d_flush_type types, bool enable) rfi_flush_enable(enable); } +void barrier_nospec_enable(bool enable) +{ + barrier_nospec_enabled = enable; + + if (enable) { + powerpc_barrier_nospec = barrier_nospec_type; + do_barrier_nospec_fixups(powerpc_barrier_nospec); + on_each_cpu(do_nothing, NULL, 1); + } else { + powerpc_barrier_nospec = SPEC_BARRIER_NONE; + do_barrier_nospec_fixups(powerpc_barrier_nospec); + } +} + +void __init setup_barrier_nospec(enum spec_barrier_type type, bool enable) +{ + if (type & SPEC_BARRIER_ORI) + pr_info("barrier_nospec: Using ori type flush\n"); + + barrier_nospec_type = type; + + if (!no_nospec) + barrier_nospec_enable(enable); +} + #ifdef CONFIG_DEBUG_FS static int rfi_flush_set(void *data, u64 val) { diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S index c8af90ff49f0..744b58ff77f1 100644 --- a/arch/powerpc/kernel/vmlinux.lds.S +++ b/arch/powerpc/kernel/vmlinux.lds.S @@ -139,6 +139,13 @@ SECTIONS *(__rfi_flush_fixup) __stop___rfi_flush_fixup = .; } + + . = ALIGN(8); + __spec_barrier_fixup : AT(ADDR(__spec_barrier_fixup) - LOAD_OFFSET) { + __start___spec_barrier_fixup = .; + *(__spec_barrier_fixup) + __stop___spec_barrier_fixup = .; + } #endif EXCEPTION_TABLE(0) diff --git a/arch/powerpc/lib/feature-fixups.c b/arch/powerpc/lib/feature-fixups.c index 73697c4e3468..000e153184ad 100644 --- a/arch/powerpc/lib/feature-fixups.c +++ b/arch/powerpc/lib/feature-fixups.c @@ -155,6 +155,33 @@ void do_rfi_flush_fixups(enum l1d_flush_type types) printk(KERN_DEBUG "rfi-flush: patched %d locations\n", i); } + +void do_barrier_nospec_fixups(enum spec_barrier_type type) +{ + unsigned int instr, *dest; + long *start, *end; + int i; + + start = PTRRELOC(&__start___spec_barrier_fixup), + end = PTRRELOC(&__stop___spec_barrier_fixup); + + instr = 0x60000000; /* nop */ + + if (type == SPEC_BARRIER_ORI) { + pr_info("barrier_nospec: using ORI speculation barrier\n"); + instr = 0x63ff0000; /* ori 31,31,0 speculation barrier */ + } + + for (i = 0; start < end; start++, i++) { + dest = (void *)start + *start; + + pr_devel("patching dest %lx\n", (unsigned long)dest); + patch_instruction(dest, instr); + } + + printk(KERN_DEBUG "barrier-nospec: patched %d locations\n", i); +} + #endif /* CONFIG_PPC_BOOK3S_64 */ void do_lwsync_fixups(unsigned long value, void *fixup_start, void *fixup_end) -- 2.13.6