From: Tim Chen <tim.c.chen@linux.intel.com>
To: Thomas Gleixner <tglx@linutronix.de>,
Andy Lutomirski <luto@kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Greg KH <gregkh@linuxfoundation.org>
Cc: Tim Chen <tim.c.chen@linux.intel.com>,
Dave Hansen <dave.hansen@intel.com>,
Andrea Arcangeli <aarcange@redhat.com>,
Andi Kleen <ak@linux.intel.com>,
Arjan Van De Ven <arjan.van.de.ven@intel.com>,
David Woodhouse <dwmw@amazon.co.uk>,
Peter Zijlstra <peterz@infradead.org>,
Dan Williams <dan.j.williams@intel.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Ashok Raj <ashok.raj@intel.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH v3 4/5] x86/ibrs: Create boot option for IBRS
Date: Tue, 9 Jan 2018 18:26:48 -0800 [thread overview]
Message-ID: <5dc30f02254606d9f60569659139f90f9d5e1d44.1515542293.git.tim.c.chen@linux.intel.com> (raw)
In-Reply-To: <cover.1515542293.git.tim.c.chen@linux.intel.com>
In-Reply-To: <cover.1515542293.git.tim.c.chen@linux.intel.com>
When "spectre_v2=ibrs" is set in kernel boot option, the kernel will
enable IBRS on entry to kernel and disable IBRS on kernel exit.
The X86_FEATURE_SPEC_CTRL_IBRS will be set on the cpu
if the user opt in to use IBRS against SPECTRE V2 attack.
It is only for cases where the user require maximum level
of security.
Signed-off-by: Tim Chen <tim.c.chen@linux.intel.com>
---
Documentation/admin-guide/kernel-parameters.txt | 3 +++
arch/x86/include/asm/spec_ctrl.h | 22 ++++++++++++++++++++++
arch/x86/kernel/cpu/Makefile | 1 +
arch/x86/kernel/cpu/scattered.c | 2 ++
arch/x86/kernel/cpu/spec_ctrl.c | 23 +++++++++++++++++++++++
5 files changed, 51 insertions(+)
create mode 100644 arch/x86/include/asm/spec_ctrl.h
create mode 100644 arch/x86/kernel/cpu/spec_ctrl.c
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 8122b5f..c611700 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -3920,6 +3920,9 @@
off - unconditionally disable
auto - kernel detects whether your CPU model is
vulnerable
+ ibrs - Use indirect branch restricted speculation
+ (IBRS) to restrict speculation in kernel. For
+ use cases requiring maximum security.
Selecting 'on' will, and 'auto' may, choose a
mitigation method at run time according to the
diff --git a/arch/x86/include/asm/spec_ctrl.h b/arch/x86/include/asm/spec_ctrl.h
new file mode 100644
index 0000000..948959b
--- /dev/null
+++ b/arch/x86/include/asm/spec_ctrl.h
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef _ASM_X86_SPEC_CTRL_H
+#define _ASM_X86_SPEC_CTRL_H
+
+#include <asm/microcode.h>
+
+void spec_ctrl_scan_feature(struct cpuinfo_x86 *c);
+void spec_ctrl_unprotected_begin(void);
+void spec_ctrl_unprotected_end(void);
+
+static inline void __disable_indirect_speculation(void)
+{
+ native_wrmsrl(MSR_IA32_SPEC_CTRL, SPEC_CTRL_ENABLE_IBRS);
+}
+
+static inline void __enable_indirect_speculation(void)
+{
+ native_wrmsrl(MSR_IA32_SPEC_CTRL, SPEC_CTRL_DISABLE_IBRS);
+}
+
+#endif /* _ASM_X86_SPEC_CTRL_H */
diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
index 90cb82d..a25f1ab 100644
--- a/arch/x86/kernel/cpu/Makefile
+++ b/arch/x86/kernel/cpu/Makefile
@@ -24,6 +24,7 @@ obj-y += match.o
obj-y += bugs.o
obj-$(CONFIG_CPU_FREQ) += aperfmperf.o
obj-y += cpuid-deps.o
+obj-y += spec_ctrl.o
obj-$(CONFIG_PROC_FS) += proc.o
obj-$(CONFIG_X86_FEATURE_NAMES) += capflags.o powerflags.o
diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattered.c
index bc50c40..5b01487 100644
--- a/arch/x86/kernel/cpu/scattered.c
+++ b/arch/x86/kernel/cpu/scattered.c
@@ -8,6 +8,7 @@
#include <asm/processor.h>
#include <asm/apic.h>
+#include <asm/spec_ctrl.h>
struct cpuid_bit {
u16 feature;
@@ -57,6 +58,7 @@ void init_scattered_cpuid_features(struct cpuinfo_x86 *c)
if (regs[cb->reg] & (1 << cb->bit))
set_cpu_cap(c, cb->feature);
}
+ spec_ctrl_scan_feature(c);
}
u32 get_scattered_cpuid_leaf(unsigned int level, unsigned int sub_leaf,
diff --git a/arch/x86/kernel/cpu/spec_ctrl.c b/arch/x86/kernel/cpu/spec_ctrl.c
new file mode 100644
index 0000000..2f3d6ca
--- /dev/null
+++ b/arch/x86/kernel/cpu/spec_ctrl.c
@@ -0,0 +1,23 @@
+#include <linux/string.h>
+
+#include <asm/spec_ctrl.h>
+#include <asm/cpufeature.h>
+
+static bool ibrs_admin_enabled;
+
+void spec_ctrl_scan_feature(struct cpuinfo_x86 *c)
+{
+ if (boot_cpu_has(X86_FEATURE_SPEC_CTRL)) {
+ if (ibrs_admin_enabled)
+ set_cpu_cap(c, X86_FEATURE_SPEC_CTRL_IBRS);
+ }
+}
+
+static int __init check_ibrs_param(char *str)
+{
+ if (strcmp(str, "ibrs") == 0)
+ ibrs_admin_enabled = true;
+
+ return 0;
+}
+early_param("spectre_v2", check_ibrs_param);
--
2.9.4
next prev parent reply other threads:[~2018-01-10 2:47 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-10 2:26 [PATCH v3 0/5] IBRS patch series Tim Chen
2018-01-10 2:26 ` [PATCH v3 1/5] x86/feature: Detect the x86 IBRS feature to control Speculation Tim Chen
2018-01-10 2:26 ` [PATCH v3 2/5] x86/enter: Create macros to set/clear IBRS Tim Chen
2018-01-11 16:04 ` Thomas Gleixner
2018-01-11 21:05 ` Tim Chen
2018-01-11 21:24 ` Tim Chen
2018-01-10 2:26 ` [PATCH v3 3/5] x86/enter: Use IBRS on syscall and interrupts Tim Chen
2018-01-10 10:04 ` Peter Zijlstra
2018-01-10 11:27 ` Paolo Bonzini
2018-01-10 18:16 ` Tim Chen
2018-01-10 18:28 ` Peter Zijlstra
2018-01-10 18:44 ` Tim Chen
2018-01-10 18:47 ` Van De Ven, Arjan
2018-01-11 12:45 ` Woodhouse, David
2018-01-10 2:26 ` Tim Chen [this message]
2018-01-10 2:26 ` [PATCH v3 5/5] x86/idle: Disable IBRS entering idle and enable it on wakeup Tim Chen
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=5dc30f02254606d9f60569659139f90f9d5e1d44.1515542293.git.tim.c.chen@linux.intel.com \
--to=tim.c.chen@linux.intel.com \
--cc=aarcange@redhat.com \
--cc=ak@linux.intel.com \
--cc=arjan.van.de.ven@intel.com \
--cc=ashok.raj@intel.com \
--cc=dan.j.williams@intel.com \
--cc=dave.hansen@intel.com \
--cc=dwmw@amazon.co.uk \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.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
all inboxes | Powered by JetHome®