Received: by 10.223.176.46 with SMTP id f43csp1694464wra; Sun, 21 Jan 2018 02:27:06 -0800 (PST) X-Google-Smtp-Source: AH8x226r8mDOWdjm+E+di6pCA5j1iPTpYDbbXR0Uu8b3TZxyf/z9aeu7a+gxdYcVEMDV3Q58vWZ5 X-Received: by 10.98.65.13 with SMTP id o13mr4816843pfa.97.1516530425994; Sun, 21 Jan 2018 02:27:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516530425; cv=none; d=google.com; s=arc-20160816; b=PNjgsSlxTu0gCoSu1Bvo1SPL1ocjIZDrMhafqNywOaQKuwE7FZge6+2BU6ErWQfNG8 sAufwuEdjPD2V1an/I7INyPIU3fLbpFNtrBOsba9ztfGwVE6DXQ/3VGriP4xZ57D3mro mPE0G7C9ufzW8vws9ZiLI5ozMxRScdZlRPYRM/JSDMvSMCTjd40tdzVX/nVq5uIun0pK DSLi5zHut6SL0Z+wUIcZYiG8Zpg2YpoK6FnXEMumKGsF42Pb6f3d869RfMZt4e52IlYT 7cURfhUiJMgM/S0FQmk+OrKEzwsLh4odgUHzznCF0Bjwe0hIlTtEu6yoADkf4MwB81Jq NZqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=eP9Ql7Q769KxIl5cVdsCXNfQGIYa0+KPa0iiSAtlOzY=; b=bN82DSRGWUFlNR7wUD5dTy2HBOPbMtkxpPr/5QlZwEiZqQcUBAXSptC5q2BdpraAin kssyFhe5qf9bRu6xnbwRDYDVNPHUYszbcYZix5iiRcD0zSLWzSkT0v6DnNQYq+2Kg9vx dbGPUd+P+SBricVnxhLnxvHjBpYux6AyU9bWa7jdRhcvwqc08jkqk7mTHLh/FDSsM7rC cH1KYhs+IkEqxSP4g/CtssHA68kN2sowAwqFbhazTvHYl8gZDCaRfwjjb5dBnyBXNqRE SdegXNFQK/0MWF67/isb+wtRrkuaDSL7QUqIyk+irFjxmWvTSap+ykiIx2IjzYagZ+li xtEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=UC897lGy; 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 w10-v6si2456156plz.107.2018.01.21.02.26.52; Sun, 21 Jan 2018 02:27:05 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=UC897lGy; 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 S1750997AbeAUK02 (ORCPT + 99 others); Sun, 21 Jan 2018 05:26:28 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:36001 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750877AbeAUK00 (ORCPT ); Sun, 21 Jan 2018 05:26:26 -0500 Received: by mail-wr0-f196.google.com with SMTP id d9so5469240wre.3 for ; Sun, 21 Jan 2018 02:26:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=eP9Ql7Q769KxIl5cVdsCXNfQGIYa0+KPa0iiSAtlOzY=; b=UC897lGypea8e1qoI4WH+utAuFEceGdnsAtge9Xoa6Gr3atuAdiuybd+u6itk7KKjo Roi6zRDXNsXj5IH3jgGmb2jVfJbE7r/u4qOExkMb95DzwfsXsU8NNEgEpUYyCbgkVcjm z5nuLXmHaaYXJd5wPis1Yj8fNjTV1b77pSD7BCuAiTbi0knnU+uWerce4eooVyTnvR9C w9iNZISbHKhtz68SoCWl5W0TfuVjwL1cEn+8Fr5xjtJzaOT1+TfpOql9RMFsuY0j+5NE ixrzzOR1/0vD6muEqN3SP1z6MxkOEOdKELztbDxLPmafvtFMJCcat2TnExuK6NwiIgtO XQdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=eP9Ql7Q769KxIl5cVdsCXNfQGIYa0+KPa0iiSAtlOzY=; b=l11rhmMuGvCaeJtqp2bavoptc3G5uhm/f6cTxvlp349XXXF7vspTr5WdSgO+t+pcZ/ BkfWQmpmTMY4lM6HqWof70XucqYR/xmgS54F2PTREBsSsARcbiQz9uWwQGMnetOuYrOe 7ljlHbbvWPPdC5ffSHkdbrY+yOQ16HJpL2mGZroKjKq0spqRDK9bIK4GnC8rj6F4HeF9 aDNJTKkm0crTDFhuKDqkU+v85rOCCQH5+aESqI9IwGnc2VUO1yZxw4fRxeKsrftDl0UB bwxwJFGJe/bP752u5qGe5ys4g/6NAecOtxWm//oy+CC66XFChMDxC8JLImJ6RSgpCUkD ncVQ== X-Gm-Message-State: AKwxyte+sIOdIx/EpYri/0l4GspBsvAqzjMXs6strxh7kwCl50gqT+zD Am1ng5KqU/dWnUDzpHEtafw= X-Received: by 10.223.173.165 with SMTP id w34mr3513558wrc.75.1516530385458; Sun, 21 Jan 2018 02:26:25 -0800 (PST) Received: from gmail.com (2E8B0CD5.catv.pool.telekom.hu. [46.139.12.213]) by smtp.gmail.com with ESMTPSA id r64sm3597795wma.15.2018.01.21.02.26.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 21 Jan 2018 02:26:24 -0800 (PST) Date: Sun, 21 Jan 2018 11:26:22 +0100 From: Ingo Molnar To: David Woodhouse Cc: arjan@linux.intel.com, tglx@linutronix.de, karahmed@amazon.de, x86@kernel.org, linux-kernel@vger.kernel.org, tim.c.chen@linux.intel.com, bp@alien8.de, peterz@infradead.org, pbonzini@redhat.com, ak@linux.intel.com, torvalds@linux-foundation.org, gregkh@linux-foundation.org Subject: Re: [PATCH v2 5/8] x86/speculation: Add basic support for IBPB Message-ID: <20180121102622.xujqxfliksoe75pm@gmail.com> References: <1516528149-9370-1-git-send-email-dwmw@amazon.co.uk> <1516528149-9370-6-git-send-email-dwmw@amazon.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1516528149-9370-6-git-send-email-dwmw@amazon.co.uk> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * David Woodhouse wrote: > From: Thomas Gleixner > > Expose indirect_branch_prediction_barrier() for use in subsequent patches. > > [karahmed: remove the special-casing of skylake for using IBPB (wtf?), > switch to using ALTERNATIVES instead of static_cpu_has] > [dwmw2: set up ax/cx/dx in the asm too so it gets NOP'd out] > > Signed-off-by: Thomas Gleixner > Signed-off-by: KarimAllah Ahmed > Signed-off-by: David Woodhouse > --- > arch/x86/include/asm/cpufeatures.h | 1 + > arch/x86/include/asm/nospec-branch.h | 16 ++++++++++++++++ > arch/x86/kernel/cpu/bugs.c | 7 +++++++ > 3 files changed, 24 insertions(+) > > diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h > index 8c9e5c0..cf28399 100644 > --- a/arch/x86/include/asm/cpufeatures.h > +++ b/arch/x86/include/asm/cpufeatures.h > @@ -207,6 +207,7 @@ > #define X86_FEATURE_RETPOLINE_AMD ( 7*32+13) /* AMD Retpoline mitigation for Spectre variant 2 */ > #define X86_FEATURE_INTEL_PPIN ( 7*32+14) /* Intel Processor Inventory Number */ > > +#define X86_FEATURE_IBPB ( 7*32+16) /* Using Indirect Branch Prediction Barrier */ > #define X86_FEATURE_AMD_PRED_CMD ( 7*32+17) /* Prediction Command MSR (AMD) */ > #define X86_FEATURE_MBA ( 7*32+18) /* Memory Bandwidth Allocation */ > #define X86_FEATURE_RSB_CTXSW ( 7*32+19) /* Fill RSB on context switches */ > diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h > index 4ad4108..c333c95 100644 > --- a/arch/x86/include/asm/nospec-branch.h > +++ b/arch/x86/include/asm/nospec-branch.h > @@ -218,5 +218,21 @@ static inline void vmexit_fill_RSB(void) > #endif > } > > +static inline void indirect_branch_prediction_barrier(void) > +{ > + unsigned long ax, cx, dx; > + > + asm volatile(ALTERNATIVE("", > + "movl %[msr], %%ecx\n\t" > + "movl %[val], %%eax\n\t" > + "movl $0, %%edx\n\t" > + "wrmsr", > + X86_FEATURE_IBPB) > + : "=a" (ax), "=c" (cx), "=d" (dx) > + : [msr] "i" (MSR_IA32_PRED_CMD), > + [val] "i" (PRED_CMD_IBPB) > + : "memory"); > +} > + > #endif /* __ASSEMBLY__ */ > #endif /* __NOSPEC_BRANCH_H__ */ > diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c > index 390b3dc..96548ff 100644 > --- a/arch/x86/kernel/cpu/bugs.c > +++ b/arch/x86/kernel/cpu/bugs.c > @@ -249,6 +249,13 @@ static void __init spectre_v2_select_mitigation(void) > setup_force_cpu_cap(X86_FEATURE_RSB_CTXSW); > pr_info("Filling RSB on context switch\n"); > } > + > + /* Initialize Indirect Branch Prediction Barrier if supported */ > + if (boot_cpu_has(X86_FEATURE_SPEC_CTRL) || > + boot_cpu_has(X86_FEATURE_AMD_PRED_CMD)) { > + setup_force_cpu_cap(X86_FEATURE_IBPB); > + pr_info("Enabling Indirect Branch Prediction Barrier\n"); > + } > } I'd suggest writing out the common 'IBPB' acronym in the messages as well: pr_info("Enabling Indirect Branch Prediction Barrier (IBPB)\n"); Also, the kernel's barrier*() namespace as it exists today is: barrier() barrier_data() I think the better name to introduce would be: barrier_indirect_branch_prediction() to maintain barrier_ as a prefix. Thanks, Ingo