Received: by 10.223.176.46 with SMTP id f43csp1668942wra; Sun, 21 Jan 2018 01:51:16 -0800 (PST) X-Google-Smtp-Source: AH8x2271gsnHtpqiNRrsKe3x/Qy+sVpqY7X86V+mkoU7PfrzXfJsvOule+M1sJ0Itrg8H87EvcvZ X-Received: by 10.101.82.205 with SMTP id z13mr4109190pgp.29.1516528276732; Sun, 21 Jan 2018 01:51:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516528276; cv=none; d=google.com; s=arc-20160816; b=z3LZhaXQVFHAOh0Kn+mH+6oetzgbdamgYgPusiNo7vRxBPHDrzYb6C9uK7lCuuWK7Y ve1CCvEUZ1e28yrjKRZKy4LzG38U5ZHwldfGBATPkoh1MI8NRqnw1h4gzfX5Mdxa7hUw Vd+uH+IwmHXfRBjFuwjW3wZS28uB2GMxSm4gQ1MfS1w1cgXSFnow15JYwILlEto14CN9 JzCtDGo9rPFbMqiKRbLk7nGWhNFtZfdweDjaq3B0G55GFrWXhdckESsPxqzxQFHvjc0l LCUBVNpgVeFlsrsLxtoEdE/PUnJ4DnvhxBbRFxGywXf/ditJJ2Oowo5b1df7exsTx3TT DWkA== 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:message-id:date :subject:to:from:dkim-signature:arc-authentication-results; bh=dW10x3+hNGuf/UM0WLcozgm0Zy7cpv6xBdneotzrm+g=; b=G6czsa8cXZ1yNUH0rI2lE/a1N0w/VRGuwOclRwKDHS5QLrDWivmNj8Tr/i9/SqK/Sp zcSFHgCIyvkwX30VEK2otzdhlI3DRZks6L1mg3lhh7dG6ZlNJHmGKoS+brpDljJCbRFc VfQlYqNudKdN0MvwnJ2l5OOK4lM1vRd7C/KQWptfJCzTazKvcj/06Ha0RGs/BxyLvrCU cNK4IZ+vS7U4J5L22lh8Az8dY17C5tCt8Z4dtccIIYEZJBvKZQd47ByxoMqXVy5LeKBi tMbXwYfyeDeuDmUL1z28ELYHNZMN5i3J4/U1akknK7MxzXFqxzOgR/KLkpkRdxdUek4h CJKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.co.uk header.s=amazon201209 header.b=BmgK1Xd4; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.co.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b15si1541219pfe.31.2018.01.21.01.51.03; Sun, 21 Jan 2018 01:51:16 -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=pass header.i=@amazon.co.uk header.s=amazon201209 header.b=BmgK1Xd4; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.co.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751204AbeAUJti (ORCPT + 99 others); Sun, 21 Jan 2018 04:49:38 -0500 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]:59988 "EHLO smtp-fw-33001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751107AbeAUJtf (ORCPT ); Sun, 21 Jan 2018 04:49:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.co.uk; i=@amazon.co.uk; q=dns/txt; s=amazon201209; t=1516528175; x=1548064175; h=from:to:subject:date:message-id:in-reply-to:references; bh=dW10x3+hNGuf/UM0WLcozgm0Zy7cpv6xBdneotzrm+g=; b=BmgK1Xd4erPH7XjEbHVrJvW6t2EQ+TXXV971i7ogRTYuxwnHx9oG9W9+ YFgK/DuVfYK/KOom4DzvQFEzgfD7DS5y3ixOiz+jlg8vkY3fI13h6/Qrw H8ADQsMUdlkrVy8DFA2Uvy+1AmWmuiKZVgOsFm52oQ/XwLSV4tifUJmuS I=; X-IronPort-AV: E=Sophos;i="5.46,390,1511827200"; d="scan'208";a="716493969" Received: from sea3-co-svc-lb6-vlan2.sea.amazon.com (HELO email-inbound-relay-1a-e34f1ddc.us-east-1.amazon.com) ([10.47.22.34]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 21 Jan 2018 09:49:34 +0000 Received: from uc8d3ff76b9bc5848a9cc.ant.amazon.com (iad1-ws-svc-lb91-vlan2.amazon.com [10.0.103.146]) by email-inbound-relay-1a-e34f1ddc.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id w0L9nPF5115012 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 21 Jan 2018 09:49:27 GMT Received: from uc8d3ff76b9bc5848a9cc.ant.amazon.com (localhost [127.0.0.1]) by uc8d3ff76b9bc5848a9cc.ant.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTP id w0L9nOd4010305; Sun, 21 Jan 2018 09:49:24 GMT Received: (from dwmw@localhost) by uc8d3ff76b9bc5848a9cc.ant.amazon.com (8.15.2/8.15.2/Submit) id w0L9nORq010304; Sun, 21 Jan 2018 09:49:24 GMT From: David Woodhouse To: 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: [PATCH v2 5/8] x86/speculation: Add basic support for IBPB Date: Sun, 21 Jan 2018 09:49:06 +0000 Message-Id: <1516528149-9370-6-git-send-email-dwmw@amazon.co.uk> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516528149-9370-1-git-send-email-dwmw@amazon.co.uk> References: <1516528149-9370-1-git-send-email-dwmw@amazon.co.uk> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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"); + } } #undef pr_fmt -- 2.7.4