Received: by 10.223.176.46 with SMTP id f43csp1887623wra; Thu, 25 Jan 2018 01:29:46 -0800 (PST) X-Google-Smtp-Source: AH8x2272w7SGCvuW79mHq+Hq/gAh59XuTL3pcyR0pcIX3pxv7uL1a52sCRzoSAwPkzwRZ6wLJ7FO X-Received: by 2002:a17:902:6881:: with SMTP id i1-v6mr10961879plk.323.1516872586826; Thu, 25 Jan 2018 01:29:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516872586; cv=none; d=google.com; s=arc-20160816; b=AWVyluCzGa7CTCoF7rXTydS6ZxPA9e/c5FbM/sQz6WvW2OvHHMIQaMstGgah1/+PH4 DoqAgukcin8GpyPfm28ndRR8Hrjy0p+B+aV+sNtHqbKeQGXTRPDMM9fh5o8Q5Ov6dduh Qh7ffIKrGaw/z2fMCL5gQFdH0x5E3WXsdcqeMjCkKL4hG28NV8/aOElwBzkL1dIOeKDA bqBUoo/TAkFSZ3+2LxJllD/QJKtDoJjX6xa6Om4HXM6tXaKlB+wYAwQTSD2wD+yLcZbK JtinGFEpSPpv5y6PuXVmEQPimNPcuCXyNRECyS1cAYXAuhVC6zo48gyJIY2rdoytn0Xa vmFQ== 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=i0PeowlGk0XvN6XSWgsIg/5drQvHp3sZL2ZFPCjjWek=; b=pfZPL7ZG8JCdQ1nhn1DZ5V+O2wfR06qHDHzpROJY3sUVDz2ukhIag/QTcvMIa1Rj67 23lN6lBjTEO1mQsPwyEKZ+wGRBCOWf78OoFYm+YapiuETPNjZbeYnn+ZHAiDrITRXQbc fTWkARl6HzXgKSKDs+qs1Umqn9LDCcdmd212POov0/30JgeAMF4nm4M4KdoidEcHrPyk 7jqgVefbID4lNiGVGM5PpZNVRzSBD0fuSHIPhAScGxQOTjKt02xvq1XSqE/jUWaN5JPc ScbKYzFi2s6eo/Gff4+dB2gQSqncNEyvRPIRbApAAdFU/uOL1X0tQilgWMSwQ7grjbHj wSVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.co.uk header.s=amazon201209 header.b=LI3qCWq8; 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 x3-v6si1692049pln.340.2018.01.25.01.29.32; Thu, 25 Jan 2018 01:29:46 -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=LI3qCWq8; 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 S1751495AbeAYJ3G (ORCPT + 99 others); Thu, 25 Jan 2018 04:29:06 -0500 Received: from smtp-fw-2101.amazon.com ([72.21.196.25]:50114 "EHLO smtp-fw-2101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751380AbeAYJ3E (ORCPT ); Thu, 25 Jan 2018 04:29:04 -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=1516872544; x=1548408544; h=from:to:subject:date:message-id:in-reply-to:references; bh=i0PeowlGk0XvN6XSWgsIg/5drQvHp3sZL2ZFPCjjWek=; b=LI3qCWq87fvqrMN0AZwCqDxQPp04vLGMFlUvIuYguEnAH6OJYIJEmf0K lQnehbBJ4Ecb3OKuLDDePDASxecM0FpXno/LZmxG5s49mkcHvn6hwpmoc Q7EJ/yUczYz2zZE0vIFCNRELYR16lfxxwXrugA9/ZZrsu8VEhejHh1y4G M=; X-IronPort-AV: E=Sophos;i="5.46,411,1511827200"; d="scan'208";a="665851739" Received: from iad6-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-2a-1c1b5cdd.us-west-2.amazon.com) ([10.124.125.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 25 Jan 2018 09:24:38 +0000 Received: from uc8d3ff76b9bc5848a9cc.ant.amazon.com (pdx2-ws-svc-lb17-vlan3.amazon.com [10.247.140.70]) by email-inbound-relay-2a-1c1b5cdd.us-west-2.amazon.com (8.14.7/8.14.7) with ESMTP id w0P9ODjB025047 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 25 Jan 2018 09:24:16 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 w0P9OBKn017532; Thu, 25 Jan 2018 09:24:11 GMT Received: (from dwmw@localhost) by uc8d3ff76b9bc5848a9cc.ant.amazon.com (8.15.2/8.15.2/Submit) id w0P9O8Gr017530; Thu, 25 Jan 2018 09:24:08 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, dave.hansen@intel.com, gnomes@lxorguk.ukuu.org.uk, ashok.raj@intel.com, mingo@kernel.org Subject: [PATCH v4 7/7] x86/speculation: Add basic IBPB (Indirect Branch Prediction Barrier) support Date: Thu, 25 Jan 2018 09:23:09 +0000 Message-Id: <1516872189-16577-8-git-send-email-dwmw@amazon.co.uk> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516872189-16577-1-git-send-email-dwmw@amazon.co.uk> References: <1516872189-16577-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 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"); +} + #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