public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* FAILED: patch "[PATCH] x86/speculation: Enable cross-hyperthread spectre v2 STIBP" failed to apply to 4.4-stable tree
@ 2018-11-10 18:37 gregkh
  2018-11-10 20:47 ` Jiri Kosina
  0 siblings, 1 reply; 5+ messages in thread
From: gregkh @ 2018-11-10 18:37 UTC (permalink / raw)
  To: jkosina, aarcange, ak, casey.schaufler, dwmw, jpoimboe, peterz,
	tglx, tim.c.chen
  Cc: stable


The patch below does not apply to the 4.4-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

>From 53c613fe6349994f023245519265999eed75957f Mon Sep 17 00:00:00 2001
From: Jiri Kosina <jkosina@suse.cz>
Date: Tue, 25 Sep 2018 14:38:55 +0200
Subject: [PATCH] x86/speculation: Enable cross-hyperthread spectre v2 STIBP
 mitigation

STIBP is a feature provided by certain Intel ucodes / CPUs. This feature
(once enabled) prevents cross-hyperthread control of decisions made by
indirect branch predictors.

Enable this feature if

- the CPU is vulnerable to spectre v2
- the CPU supports SMT and has SMT siblings online
- spectre_v2 mitigation autoselection is enabled (default)

After some previous discussion, this leaves STIBP on all the time, as wrmsr
on crossing kernel boundary is a no-no. This could perhaps later be a bit
more optimized (like disabling it in NOHZ, experiment with disabling it in
idle, etc) if needed.

Note that the synchronization of the mask manipulation via newly added
spec_ctrl_mutex is currently not strictly needed, as the only updater is
already being serialized by cpu_add_remove_lock, but let's make this a
little bit more future-proof.

Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc:  "WoodhouseDavid" <dwmw@amazon.co.uk>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Tim Chen <tim.c.chen@linux.intel.com>
Cc:  "SchauflerCasey" <casey.schaufler@intel.com>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/nycvar.YFH.7.76.1809251438240.15880@cbobk.fhfr.pm

diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 40bdaea97fe7..53eb14a65610 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -35,12 +35,10 @@ static void __init spectre_v2_select_mitigation(void);
 static void __init ssb_select_mitigation(void);
 static void __init l1tf_select_mitigation(void);
 
-/*
- * Our boot-time value of the SPEC_CTRL MSR. We read it once so that any
- * writes to SPEC_CTRL contain whatever reserved bits have been set.
- */
-u64 __ro_after_init x86_spec_ctrl_base;
+/* The base value of the SPEC_CTRL MSR that always has to be preserved. */
+u64 x86_spec_ctrl_base;
 EXPORT_SYMBOL_GPL(x86_spec_ctrl_base);
+static DEFINE_MUTEX(spec_ctrl_mutex);
 
 /*
  * The vendor and possibly platform specific bits which can be modified in
@@ -325,6 +323,46 @@ static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void)
 	return cmd;
 }
 
+static bool stibp_needed(void)
+{
+	if (spectre_v2_enabled == SPECTRE_V2_NONE)
+		return false;
+
+	if (!boot_cpu_has(X86_FEATURE_STIBP))
+		return false;
+
+	return true;
+}
+
+static void update_stibp_msr(void *info)
+{
+	wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base);
+}
+
+void arch_smt_update(void)
+{
+	u64 mask;
+
+	if (!stibp_needed())
+		return;
+
+	mutex_lock(&spec_ctrl_mutex);
+	mask = x86_spec_ctrl_base;
+	if (cpu_smt_control == CPU_SMT_ENABLED)
+		mask |= SPEC_CTRL_STIBP;
+	else
+		mask &= ~SPEC_CTRL_STIBP;
+
+	if (mask != x86_spec_ctrl_base) {
+		pr_info("Spectre v2 cross-process SMT mitigation: %s STIBP\n",
+				cpu_smt_control == CPU_SMT_ENABLED ?
+				"Enabling" : "Disabling");
+		x86_spec_ctrl_base = mask;
+		on_each_cpu(update_stibp_msr, NULL, 1);
+	}
+	mutex_unlock(&spec_ctrl_mutex);
+}
+
 static void __init spectre_v2_select_mitigation(void)
 {
 	enum spectre_v2_mitigation_cmd cmd = spectre_v2_parse_cmdline();
@@ -424,6 +462,9 @@ static void __init spectre_v2_select_mitigation(void)
 		setup_force_cpu_cap(X86_FEATURE_USE_IBRS_FW);
 		pr_info("Enabling Restricted Speculation for firmware calls\n");
 	}
+
+	/* Enable STIBP if appropriate */
+	arch_smt_update();
 }
 
 #undef pr_fmt
@@ -814,6 +855,8 @@ static ssize_t l1tf_show_state(char *buf)
 static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr,
 			       char *buf, unsigned int bug)
 {
+	int ret;
+
 	if (!boot_cpu_has_bug(bug))
 		return sprintf(buf, "Not affected\n");
 
@@ -831,10 +874,12 @@ static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr
 		return sprintf(buf, "Mitigation: __user pointer sanitization\n");
 
 	case X86_BUG_SPECTRE_V2:
-		return sprintf(buf, "%s%s%s%s\n", spectre_v2_strings[spectre_v2_enabled],
+		ret = sprintf(buf, "%s%s%s%s%s\n", spectre_v2_strings[spectre_v2_enabled],
 			       boot_cpu_has(X86_FEATURE_USE_IBPB) ? ", IBPB" : "",
 			       boot_cpu_has(X86_FEATURE_USE_IBRS_FW) ? ", IBRS_FW" : "",
+			       (x86_spec_ctrl_base & SPEC_CTRL_STIBP) ? ", STIBP" : "",
 			       spectre_v2_module_string());
+		return ret;
 
 	case X86_BUG_SPEC_STORE_BYPASS:
 		return sprintf(buf, "%s\n", ssb_strings[ssb_mode]);
diff --git a/kernel/cpu.c b/kernel/cpu.c
index aa7fe85ad62e..2fb49916ea56 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -2025,6 +2025,12 @@ static void cpuhp_online_cpu_device(unsigned int cpu)
 	kobject_uevent(&dev->kobj, KOBJ_ONLINE);
 }
 
+/*
+ * Architectures that need SMT-specific errata handling during SMT hotplug
+ * should override this.
+ */
+void __weak arch_smt_update(void) { };
+
 static int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval)
 {
 	int cpu, ret = 0;
@@ -2051,8 +2057,10 @@ static int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval)
 		 */
 		cpuhp_offline_cpu_device(cpu);
 	}
-	if (!ret)
+	if (!ret) {
 		cpu_smt_control = ctrlval;
+		arch_smt_update();
+	}
 	cpu_maps_update_done();
 	return ret;
 }
@@ -2063,6 +2071,7 @@ static int cpuhp_smt_enable(void)
 
 	cpu_maps_update_begin();
 	cpu_smt_control = CPU_SMT_ENABLED;
+	arch_smt_update();
 	for_each_present_cpu(cpu) {
 		/* Skip online CPUs and CPUs on offline nodes */
 		if (cpu_online(cpu) || !node_online(cpu_to_node(cpu)))

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: FAILED: patch "[PATCH] x86/speculation: Enable cross-hyperthread spectre v2 STIBP" failed to apply to 4.4-stable tree
  2018-11-10 18:37 FAILED: patch "[PATCH] x86/speculation: Enable cross-hyperthread spectre v2 STIBP" failed to apply to 4.4-stable tree gregkh
@ 2018-11-10 20:47 ` Jiri Kosina
  2018-11-17 14:50   ` Sasha Levin
  0 siblings, 1 reply; 5+ messages in thread
From: Jiri Kosina @ 2018-11-10 20:47 UTC (permalink / raw)
  To: gregkh
  Cc: aarcange, ak, casey.schaufler, dwmw, jpoimboe, peterz,
	Thomas Gleixner, tim.c.chen, Borislav Petkov, stable

On Sat, 10 Nov 2018, gregkh@linuxfoundation.org wrote:

> The patch below does not apply to the 4.4-stable tree.
> If someone wants it applied there, or to any other stable or longterm
> tree, then please email the backport, including the original git commit
> id to <stable@vger.kernel.org>.

Boris backported all my three patches in that series (dbfe2953f, 53c613fe6 
and bb4b3b776 in Linus' tree) to our 4.4-based SLE12-SP3 kernel, so those 
ports might come handy to whoever will be doing the 4.4-stable backport:

http://kernel.suse.com/cgit/kernel/commit/?h=SLE12-SP3&id=f0d6957cb012ef72c9628511a75be40083865dd9
http://kernel.suse.com/cgit/kernel/commit/?h=SLE12-SP3&id=8b222bcb27ae6a628aa2dad5050e1d5dcbbbcecb
http://kernel.suse.com/cgit/kernel/commit/?h=SLE12-SP3&id=f04ca7131a830e8be2cf0742bed0a15533c35a93

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: FAILED: patch "[PATCH] x86/speculation: Enable cross-hyperthread spectre v2 STIBP" failed to apply to 4.4-stable tree
  2018-11-10 20:47 ` Jiri Kosina
@ 2018-11-17 14:50   ` Sasha Levin
  2018-11-17 16:20     ` Borislav Petkov
  0 siblings, 1 reply; 5+ messages in thread
From: Sasha Levin @ 2018-11-17 14:50 UTC (permalink / raw)
  To: Jiri Kosina
  Cc: gregkh, aarcange, ak, casey.schaufler, dwmw, jpoimboe, peterz,
	Thomas Gleixner, tim.c.chen, Borislav Petkov, stable

On Sat, Nov 10, 2018 at 09:47:13PM +0100, Jiri Kosina wrote:
>On Sat, 10 Nov 2018, gregkh@linuxfoundation.org wrote:
>
>> The patch below does not apply to the 4.4-stable tree.
>> If someone wants it applied there, or to any other stable or longterm
>> tree, then please email the backport, including the original git commit
>> id to <stable@vger.kernel.org>.
>
>Boris backported all my three patches in that series (dbfe2953f, 53c613fe6
>and bb4b3b776 in Linus' tree) to our 4.4-based SLE12-SP3 kernel, so those
>ports might come handy to whoever will be doing the 4.4-stable backport:
>
>http://kernel.suse.com/cgit/kernel/commit/?h=SLE12-SP3&id=f0d6957cb012ef72c9628511a75be40083865dd9
>http://kernel.suse.com/cgit/kernel/commit/?h=SLE12-SP3&id=8b222bcb27ae6a628aa2dad5050e1d5dcbbbcecb
>http://kernel.suse.com/cgit/kernel/commit/?h=SLE12-SP3&id=f04ca7131a830e8be2cf0742bed0a15533c35a93

Boris,

Can I get your Signed-off-by on these 3 backported commits?

--
Thanks,
Sasha

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: FAILED: patch "[PATCH] x86/speculation: Enable cross-hyperthread spectre v2 STIBP" failed to apply to 4.4-stable tree
  2018-11-17 14:50   ` Sasha Levin
@ 2018-11-17 16:20     ` Borislav Petkov
  2018-11-19 10:49       ` Borislav Petkov
  0 siblings, 1 reply; 5+ messages in thread
From: Borislav Petkov @ 2018-11-17 16:20 UTC (permalink / raw)
  To: Sasha Levin
  Cc: Jiri Kosina, gregkh, aarcange, ak, casey.schaufler, dwmw,
	jpoimboe, peterz, Thomas Gleixner, tim.c.chen, Borislav Petkov,
	stable

On Sat, Nov 17, 2018 at 09:50:52AM -0500, Sasha Levin wrote:
> > http://kernel.suse.com/cgit/kernel/commit/?h=SLE12-SP3&id=f0d6957cb012ef72c9628511a75be40083865dd9
> > http://kernel.suse.com/cgit/kernel/commit/?h=SLE12-SP3&id=8b222bcb27ae6a628aa2dad5050e1d5dcbbbcecb
> > http://kernel.suse.com/cgit/kernel/commit/?h=SLE12-SP3&id=f04ca7131a830e8be2cf0742bed0a15533c35a93
> 
> Boris,
>
> Can I get your Signed-off-by on these 3 backported commits?

If you click on the respective suse-commit link, for example:

suse-commit: a0dce2e59b0edd366a0d7f1ece099d94496385ba

for the first one, you'll see my Acked-by:

You probably should use those anyway as they have header and commit
message and so on...

HTH.

-- 
Regards/Gruss,
    Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: FAILED: patch "[PATCH] x86/speculation: Enable cross-hyperthread spectre v2 STIBP" failed to apply to 4.4-stable tree
  2018-11-17 16:20     ` Borislav Petkov
@ 2018-11-19 10:49       ` Borislav Petkov
  0 siblings, 0 replies; 5+ messages in thread
From: Borislav Petkov @ 2018-11-19 10:49 UTC (permalink / raw)
  To: Sasha Levin
  Cc: Jiri Kosina, gregkh, aarcange, ak, casey.schaufler, dwmw,
	jpoimboe, peterz, Thomas Gleixner, tim.c.chen, Borislav Petkov,
	stable

On Sat, Nov 17, 2018 at 05:20:52PM +0100, Borislav Petkov wrote:
> On Sat, Nov 17, 2018 at 09:50:52AM -0500, Sasha Levin wrote:
> > > http://kernel.suse.com/cgit/kernel/commit/?h=SLE12-SP3&id=f0d6957cb012ef72c9628511a75be40083865dd9
> > > http://kernel.suse.com/cgit/kernel/commit/?h=SLE12-SP3&id=8b222bcb27ae6a628aa2dad5050e1d5dcbbbcecb
> > > http://kernel.suse.com/cgit/kernel/commit/?h=SLE12-SP3&id=f04ca7131a830e8be2cf0742bed0a15533c35a93
> > 
> > Boris,
> >
> > Can I get your Signed-off-by on these 3 backported commits?
> 
> If you click on the respective suse-commit link, for example:
> 
> suse-commit: a0dce2e59b0edd366a0d7f1ece099d94496385ba
> 
> for the first one, you'll see my Acked-by:
> 
> You probably should use those anyway as they have header and commit
> message and so on...

Heads up: you might wanna hold off on that backporting - see

https://lkml.kernel.org/r/CAHk-=wg-9FUGU=grF4gKDq1sm1m39Jbs3A_iyLbSSntU47ncwg@mail.gmail.com

-- 
Regards/Gruss,
    Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-11-19 10:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-10 18:37 FAILED: patch "[PATCH] x86/speculation: Enable cross-hyperthread spectre v2 STIBP" failed to apply to 4.4-stable tree gregkh
2018-11-10 20:47 ` Jiri Kosina
2018-11-17 14:50   ` Sasha Levin
2018-11-17 16:20     ` Borislav Petkov
2018-11-19 10:49       ` Borislav Petkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox