From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x226wWiBiWCufli6ksI7DDZFU0qXvHHmDxDWyjR28E9wGZrGkILXRQEYtciJ2qz++F0qI/Iml ARC-Seal: i=1; a=rsa-sha256; t=1516528175; cv=none; d=google.com; s=arc-20160816; b=RYJ0VUn1Bsaj1UJFcdPADEYBhrpXX8IPM3XhJZpqP/AZpWtkGLcV1ZEKbxbN2SsLEd FC/rtPruEiBEr/hk1f3fFoaAEqGUNmB9dFvs/H4BjCQ0LrCvY47qmmlEPcVfnnFaWZaQ 8cVIcRVGcZrbhb3Cn0J0z//n/D6NHG3z3mkCsSWOoYtzJYjolwgwGPR88WTWkj4/fJUo rjfrGVhvVoYfnTlH/jZQhAzbrkOvNx1iY93ZSRfuvHWjCAceystdHZ+ttqCVztUB+Ka3 wftScRGFMQtFqbHd8mO4x+QudTUtd9LVDAf88IYtv+8vnOLDN8Ru4ZYBZfTf1h+sJYAN 9uQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-authentication-results; bh=dW10x3+hNGuf/UM0WLcozgm0Zy7cpv6xBdneotzrm+g=; b=ObqXdjOKE0wZ2wV2WKkpV+Ia6pYapoXRb5tGlyQ3ib+8UlxEMPnSkCw0ZBhTscpZdd hTCeSkq7rAecidRUfrpIG3Fe8VgRvBqQxe5VBIoTu5k507/lm1TkAyIfxa2M2cMswynQ e7xm2nqzBJCDN+i+x9/nQ6aD+gjPPuOtdnZ4sL0Norup9WSXQfa/3xYZApN4lmUKY7km jPVchznUpzdkCYmJFkleMaG7fVmDbGgNQuUC9K1PfRK5/g99pv3Xx///ie9dTnaDgt+0 +7yb2gnAt1Kc1Ohf7Ot315LdL1ativTIiLEJP6v6P+uBGJ74V6vWmc/FhEidFyuL2KCT FLig== 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: domain of prvs=552b621e3=dwmw@amazon.com designates 207.171.190.10 as permitted sender) smtp.mailfrom=prvs=552b621e3=dwmw@amazon.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.co.uk Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.co.uk header.s=amazon201209 header.b=BmgK1Xd4; spf=pass (google.com: domain of prvs=552b621e3=dwmw@amazon.com designates 207.171.190.10 as permitted sender) smtp.mailfrom=prvs=552b621e3=dwmw@amazon.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.co.uk X-IronPort-AV: E=Sophos;i="5.46,390,1511827200"; d="scan'208";a="716493969" 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> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: =?utf-8?q?1590195048808685762?= X-GMAIL-MSGID: =?utf-8?q?1590195048808685762?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: 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