linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andi Kleen <andi@firstfloor.org>
To: tglx@linutronix.de
Cc: dwmw@amazon.co.uk, thomas.lendacky@amd.com, peterz@infradead.org,
	torvalds@linux-foundation.org, luto@amacapital.net,
	x86@kernel.org, gregkh@linux-foundation.org,
	linux-kernel@vger.kernel.org, Andi Kleen <ak@linux.intel.com>
Subject: [PATCH 1/2] x86/retpoline: Add feature bit for additional return buffer protections
Date: Tue, 23 Jan 2018 14:39:15 -0800	[thread overview]
Message-ID: <20180123223916.26904-2-andi@firstfloor.org> (raw)
In-Reply-To: <20180123223916.26904-1-andi@firstfloor.org>

From: Andi Kleen <ak@linux.intel.com>

On Skylake we want additional protections against spectre_v2
over the normal RETPOLINE against underflowing return buffers.

On return buffer underflow the CPU could fall back to
the poisoned indirect branch predictor.

This patch adds a feature bit, only enabled on Skylake,
to enable additional return buffer underflow protections

This will be used in the next patches

Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 arch/x86/include/asm/cpufeatures.h | 1 +
 arch/x86/kernel/cpu/bugs.c         | 5 +++++
 2 files changed, 6 insertions(+)

diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
index 25b9375c1484..85108eb1876b 100644
--- a/arch/x86/include/asm/cpufeatures.h
+++ b/arch/x86/include/asm/cpufeatures.h
@@ -211,6 +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_RSB_UNDERFLOW	( 7*32+20) /* Avoid return stack underflows */
 
 /* Virtualization flags: Linux defined, word 8 */
 #define X86_FEATURE_TPR_SHADOW		( 8*32+ 0) /* Intel TPR Shadow */
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 390b3dc3d438..68d449d51673 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -249,6 +249,11 @@ static void __init spectre_v2_select_mitigation(void)
 		setup_force_cpu_cap(X86_FEATURE_RSB_CTXSW);
 		pr_info("Filling RSB on context switch\n");
 	}
+
+	if (is_skylake_era()) {
+		setup_force_cpu_cap(X86_FEATURE_RSB_UNDERFLOW);
+		pr_info("Enabling return buffer underflow protections");
+	}
 }
 
 #undef pr_fmt
-- 
2.14.3

  reply	other threads:[~2018-01-23 22:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-23 22:39 Support interrupt stuffing for Skylake Andi Kleen
2018-01-23 22:39 ` Andi Kleen [this message]
2018-01-23 22:39 ` [PATCH 2/2] x86/retpoline: Fill return buffer on interrupt return to kernel Andi Kleen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180123223916.26904-2-andi@firstfloor.org \
    --to=andi@firstfloor.org \
    --cc=ak@linux.intel.com \
    --cc=dwmw@amazon.co.uk \
    --cc=gregkh@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --cc=torvalds@linux-foundation.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).