Received: by 10.223.176.46 with SMTP id f43csp2019865wra; Thu, 25 Jan 2018 03:43:25 -0800 (PST) X-Google-Smtp-Source: AH8x226iBv0MARO9ytPURLWgZ15NaFoju52i+WYMaGt0KGdsoBC+UYgj+KzvpAZtlZmEbT7jHmZ1 X-Received: by 2002:a17:902:650e:: with SMTP id b14-v6mr10935357plk.451.1516880605739; Thu, 25 Jan 2018 03:43:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516880605; cv=none; d=google.com; s=arc-20160816; b=I3Z0NnL5JCk3sYKvVEZXL5PWk3pNIZ9h5fhgQu14VoImS2QxxZjkKwcJ01h40YVUWc 2n8Q546tV4exc3YeydYWR3TOshOChL5C96BXs30RTmZfGH9cmi4b9VEeUzYdGjFLil6A DlO+YqndwrM6q8qFouM0yCaNllvqf6NYK8v9aWjRJ+yxRPMLDv6E6I93I8snAn8xQR7N bos7xtTpktCw9eCjyzvOX5B43EMjN9FUAs/3Rhr8L51EZfxYkLU21xzSg+PcEs30W3JF XJx9JKj6VgdYTSCLhUzTlseCiDVMwkShEJtH1XuGyjgCdxBnp8BUuxSSnlQFj3C+tjUm jXbA== 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:arc-authentication-results; bh=dqOfbCDK9fVDMaYZD3neKZKck75nNgmBnWrbWAZvNYw=; b=YgBGxShZGhEiR6ASjrgkgnR99XchAbtmrNqArLcYeWL7VPtSUELa0eHfjjSUMMCpBT beZUevbrt1oawpFBUnDAYtEF05BxQn7BwiCxMNr+KC8KqAetC7T2qMcpwj/uL65AoXoV LbYVEUzY9d0hmwWQc8I9iLQm3UqwHo2LqKEcBpTk39ZylYAyu1jejt5GVR7tgjm689fo GPJhG4ZLdu/MlJCGb2l2Lmt5b8Csgam+GrQCrOVPb72Z4lCyj46y4CS8+wt6DP3QFx9n Y5ukZuhyA1khzNWCBFGHjBZfejuc1ZwDGOaAe/HEUddAUryJNSIAd6J0SJ4WeRTX4xaw A2Ug== 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 s2si4474288pfj.279.2018.01.25.03.43.11; Thu, 25 Jan 2018 03:43:25 -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; 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 S1751852AbeAYLlj (ORCPT + 99 others); Thu, 25 Jan 2018 06:41:39 -0500 Received: from mail.skyhub.de ([5.9.137.197]:37358 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750769AbeAYLli (ORCPT ); Thu, 25 Jan 2018 06:41:38 -0500 X-Virus-Scanned: Nedap ESD1 at mail.skyhub.de Received: from mail.skyhub.de ([127.0.0.1]) by localhost (blast.alien8.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id gMEPwAgUV-X8; Thu, 25 Jan 2018 12:41:37 +0100 (CET) Received: from pd.tnic (p200300EC2BD0EE0024194793E6CFFC7A.dip0.t-ipconnect.de [IPv6:2003:ec:2bd0:ee00:2419:4793:e6cf:fc7a]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 0A0361EC03DB; Thu, 25 Jan 2018 12:41:37 +0100 (CET) Date: Thu, 25 Jan 2018 12:41:27 +0100 From: Borislav Petkov 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, peterz@infradead.org, pbonzini@redhat.com, ak@linux.intel.com, torvalds@linux-foundation.org, gregkh@linux-foundation.org, dave.hansen@intel.com, gnomes@lxorguk.ukuu.org.uk, ashok.raj@intel.com, mingo@kernel.org Subject: Re: [PATCH v4 7/7] x86/speculation: Add basic IBPB (Indirect Branch Prediction Barrier) support Message-ID: <20180125114127.5iw4vy56bb2cs5mr@pd.tnic> References: <1516872189-16577-1-git-send-email-dwmw@amazon.co.uk> <1516872189-16577-8-git-send-email-dwmw@amazon.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1516872189-16577-8-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 On Thu, Jan 25, 2018 at 09:23:09AM +0000, David Woodhouse wrote: > 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 | 13 +++++++++++++ > arch/x86/kernel/cpu/bugs.c | 7 +++++++ > 3 files changed, 21 insertions(+) > > diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h > index ae3212f..6b988278 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_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..34e384c 100644 > --- a/arch/x86/include/asm/nospec-branch.h > +++ b/arch/x86/include/asm/nospec-branch.h > @@ -218,5 +218,18 @@ static inline void vmexit_fill_RSB(void) > #endif > } > > +static inline void indirect_branch_prediction_barrier(void) > +{ > + asm volatile(ALTERNATIVE("", > + "movl %[msr], %%ecx\n\t" > + "movl %[val], %%eax\n\t" > + "movl $0, %%edx\n\t" > + "wrmsr", > + X86_FEATURE_IBPB) > + : : [msr] "i" (MSR_IA32_PRED_CMD), > + [val] "i" (PRED_CMD_IBPB) > + : "eax", "ecx", "edx", "memory"); Lemme paste my simplification suggestion from the other day: "Btw, we can simplify this a bit by dropping the inputs and marking the 3 GPRs as clobbered: alternative_input("", "mov $0x49, %%ecx\n\t" "mov $1, %%eax\n\t" "xor %%edx, %%edx\n\t" "wrmsr\n\t", X86_FEATURE_IBPB, ASM_NO_INPUT_CLOBBER("eax", "ecx", "edx", "memory")); " -- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.