Received: by 10.223.176.46 with SMTP id f43csp1118370wra; Fri, 26 Jan 2018 12:09:53 -0800 (PST) X-Google-Smtp-Source: AH8x225hbQtFFgMfcYn5IStXZVdogh08G8UWA3Zg3OZyG4GKCrm6RiRi4jWt4XgbT8mRElOtwhkm X-Received: by 10.98.19.137 with SMTP id 9mr19915509pft.5.1516997393421; Fri, 26 Jan 2018 12:09:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516997393; cv=none; d=google.com; s=arc-20160816; b=B5VEAQaX6a7cUClNzfin9D39JXi6zU4HrGzcsS5ATPoE4Lsue5+27FfGzecrGo865V qmO5S2IjfsQP9eNvTwIi8DBgDlzSluapXndl3hZb37goQmLzyVSv4jwns0S2lEVsWC0c Ma84HgO9BKBE6q51FAACnW5Ycljwdjtx4BbmaU5ta0rWxyLXx3uaA2EOOgQGJ8DD3VC+ MgG8gb5lAIvR4Jg/sNYOdRmhFSl+UMDFK5VdFHzia0RJSwf6KkgIf23oNmDigp0SBgOV 7/oEd6/KEnQv1RU1w8+WUKZTckpMeHlaW8tgNXIvpKuAHQbP0ve8xpRYUjsgQ3mRJAmT M2hA== 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=CvBe3qd8/F8FT2yaPBz24dJ6hfaONKEwFfgeV2ILUOI=; b=GzAvpVuYuHZhpi7jSQFIv1kWdY2T9V8UeQ249vERIttWxbCeXjSGH2GCP9NKk8h7kq ImViNWLGTFSzr5b2ScHpBSJ+XrVBwKoXI1QeS/X5OGtSiLYA7gfRWHdUD2d3IF0poyTf V2Hlba3sfck/dkRBhxXnRKH308sWWLnlAayX0wPcc9iB07A4a57w9vf/52wTzrymhDTz VcdFNlS3RAvEOukugBloLCeKYXlznKVlBultCWs4v8tBVcR1vcJCm5KnzSQ3t5Ifn6gn pTJV1KHmX4s3Ddkt1FC5/tyuD00Ede6C0yfyEUXjl+F4GXtQBakBhRbhqPDQOsbiPvkw 6J3g== 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 l13si3414224pgs.451.2018.01.26.12.09.39; Fri, 26 Jan 2018 12:09:53 -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 S1752315AbeAZUIZ (ORCPT + 99 others); Fri, 26 Jan 2018 15:08:25 -0500 Received: from mail.skyhub.de ([5.9.137.197]:47644 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751734AbeAZUIY (ORCPT ); Fri, 26 Jan 2018 15:08:24 -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 oIPZEvF9GI_o; Fri, 26 Jan 2018 21:08:23 +0100 (CET) Received: from pd.tnic (p200300EC2BCF3A0024194793E6CFFC7A.dip0.t-ipconnect.de [IPv6:2003:ec:2bcf:3a00: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 462A51EC02AD; Fri, 26 Jan 2018 21:08:23 +0100 (CET) Date: Fri, 26 Jan 2018 21:08:13 +0100 From: Borislav Petkov To: David Woodhouse Cc: X86 ML , LKML , Josh Poimboeuf , tim.c.chen@linux.intel.com, pjt@google.com, jikos@kernel.org, gregkh@linux-foundation.org, dave.hansen@intel.com, riel@redhat.com, luto@amacapital.net, torvalds@linux-foundation.org, ak@linux.intel.com, keescook@google.com, peterz@infradead.org Subject: [PATCH 2/2] x86/speculation: Simplify indirect_branch_prediction_barrier() Message-ID: <20180126200813.cignvfovk2dhlzbh@pd.tnic> References: <20180126121139.31959-1-bp@alien8.de> <20180126121139.31959-4-bp@alien8.de> <1516970011.30244.223.camel@infradead.org> <20180126132431.fsbd3c3g2yreazy6@pd.tnic> <1516983879.30244.236.camel@infradead.org> <20180126164746.dpo7dswid5tjk2tz@pd.tnic> <20180126200616.5xfn244uzeu7ptyo@pd.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20180126200616.5xfn244uzeu7ptyo@pd.tnic> 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 Make it all a function which does the WRMSR instead of having a hairy inline asm. Signed-off-by: Borislav Petkov --- arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/include/asm/nospec-branch.h | 13 ++++--------- arch/x86/include/asm/processor.h | 4 ++++ arch/x86/kernel/cpu/bugs.c | 7 +++++++ 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index 6c6d862d66a1..6c033f6adc24 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -211,7 +211,7 @@ #define X86_FEATURE_MBA ( 7*32+18) /* Memory Bandwidth Allocation */ #define X86_FEATURE_RSB_CTXSW ( 7*32+19) /* Fill RSB on context switches */ -#define X86_FEATURE_IBPB ( 7*32+21) /* Indirect Branch Prediction Barrier enabled*/ +#define X86_FEATURE_IBPB ( 7*32+21) /* Indirect Branch Prediction Barrier enabled */ /* Virtualization flags: Linux defined, word 8 */ #define X86_FEATURE_TPR_SHADOW ( 8*32+ 0) /* Intel TPR Shadow */ diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h index 4f88e1b2599f..71ae2dd65259 100644 --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -183,15 +183,10 @@ static inline void vmexit_fill_RSB(void) 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"); + alternative_input("", + "call __ibp_barrier", + X86_FEATURE_IBPB, + ASM_NO_INPUT_CLOBBER("eax", "ecx", "edx", "memory")); } #endif /* __ASSEMBLY__ */ diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h index d3a67fba200a..4d372f1cea5a 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -971,4 +971,8 @@ bool xen_set_default_idle(void); void stop_this_cpu(void *dummy); void df_debug(struct pt_regs *regs, long error_code); + +#ifdef CONFIG_RETPOLINE +void __ibp_barrier(void); +#endif #endif /* _ASM_X86_PROCESSOR_H */ diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index be068aea6bda..448410fcffcf 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -304,3 +304,10 @@ ssize_t cpu_show_spectre_v2(struct device *dev, spectre_v2_bad_module ? " - vulnerable module loaded" : ""); } #endif + +#ifdef CONFIG_RETPOLINE +void __ibp_barrier(void) +{ + __wrmsr(MSR_IA32_PRED_CMD, PRED_CMD_IBPB, 0); +} +#endif -- 2.13.0 -- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.