From: Thomas Gleixner <tglx@linutronix.de>
To: speck@linutronix.de
Subject: [patch V2 06/10] MDS basics+ 6
Date: Wed, 20 Feb 2019 16:07:59 +0100 [thread overview]
Message-ID: <20190220151400.501811184@linutronix.de> (raw)
In-Reply-To: 20190220150753.665964899@linutronix.de
Subject: [patch V2 06/10] x86/speculation/mds: Add mitigation control for MDS
From: Thomas Gleixner <tglx@linutronix.de>
Now that the mitigations are in place, add a command line parameter to
control the mitigation, a mitigation selector function and a SMT update
mechanism.
This is the minimal straight forward initial implementation which just
provides an always on/off mode. The command line parameter is:
mds=[full|off|auto]
This is consistent with the existing mitigations for other speculative
hardware vulnerabilities.
The idle invocation is dynamically updated according to the SMT state of
the system similar to the dynamic update of the STIBP mitigation.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
Documentation/admin-guide/kernel-parameters.txt | 27 ++++++++
arch/x86/include/asm/processor.h | 6 +
arch/x86/kernel/cpu/bugs.c | 76 ++++++++++++++++++++++++
3 files changed, 109 insertions(+)
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -2362,6 +2362,33 @@
Format: <first>,<last>
Specifies range of consoles to be captured by the MDA.
+ mds= [X86,INTEL]
+ Control mitigation for the Micro-architectural Data
+ Sampling (MDS) vulnerability.
+
+ Certain CPUs are vulnerable to an exploit against CPU
+ internal buffers which can forward information to a
+ disclosure gadget under certain conditions.
+
+ In vulnerable processors, the speculatively
+ forwarded data can be used in a cache side channel
+ attack, to access data to which the attacker does
+ not have direct access.
+
+ This parameter controls the MDS mitigation. The the
+ options are:
+
+ full - Unconditionally enable MDS mitigation
+ off - Unconditionally disable MDS mitigation
+ auto - Kernel detects whether the CPU model is
+ vulnerable to MDS and picks the most
+ appropriate mitigation. If the CPU is not
+ vulnerable, "off" is selected. If the CPU
+ is vulnerable "full" is selected.
+
+ Not specifying this option is equivalent to
+ mds=auto.
+
mem=nn[KMG] [KNL,BOOT] Force usage of a specific amount of memory
Amount of memory to be used when the kernel is not able
to see the whole system memory or for test.
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -991,4 +991,10 @@ enum l1tf_mitigations {
extern enum l1tf_mitigations l1tf_mitigation;
+enum mds_mitigations {
+ MDS_MITIGATION_OFF,
+ MDS_MITIGATION_AUTO,
+ MDS_MITIGATION_FULL,
+};
+
#endif /* _ASM_X86_PROCESSOR_H */
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -37,6 +37,7 @@
static void __init spectre_v2_select_mitigation(void);
static void __init ssb_select_mitigation(void);
static void __init l1tf_select_mitigation(void);
+static void __init mds_select_mitigation(void);
/* The base value of the SPEC_CTRL MSR that always has to be preserved. */
u64 x86_spec_ctrl_base;
@@ -105,6 +106,8 @@ void __init check_bugs(void)
l1tf_select_mitigation();
+ mds_select_mitigation();
+
#ifdef CONFIG_X86_32
/*
* Check whether we are able to run this kernel safely on SMP.
@@ -211,6 +214,59 @@ static void x86_amd_ssb_disable(void)
}
#undef pr_fmt
+#define pr_fmt(fmt) "MDS: " fmt
+
+/* Default mitigation for L1TF-affected CPUs */
+static enum mds_mitigations mds_mitigation __ro_after_init = MDS_MITIGATION_AUTO;
+
+static const char * const mds_strings[] = {
+ [MDS_MITIGATION_OFF] = "Vulnerable",
+ [MDS_MITIGATION_FULL] = "Mitigation: Clear CPU buffers"
+};
+
+static void mds_select_mitigation(void)
+{
+ if (!boot_cpu_has_bug(X86_BUG_MDS)) {
+ mds_mitigation = MDS_MITIGATION_OFF;
+ return;
+ }
+
+ switch (mds_mitigation) {
+ case MDS_MITIGATION_OFF:
+ break;
+ case MDS_MITIGATION_AUTO:
+ case MDS_MITIGATION_FULL:
+ if (boot_cpu_has(X86_FEATURE_MD_CLEAR)) {
+ mds_mitigation = MDS_MITIGATION_FULL;
+ static_branch_enable(&mds_user_clear_always);
+ } else {
+ mds_mitigation = MDS_MITIGATION_OFF;
+ }
+ break;
+ }
+ pr_info("%s\n", mds_strings[mds_mitigation]);
+}
+
+static int __init mds_cmdline(char *str)
+{
+ if (!boot_cpu_has_bug(X86_BUG_MDS))
+ return 0;
+
+ if (!str)
+ return -EINVAL;
+
+ if (!strcmp(str, "off"))
+ mds_mitigation = MDS_MITIGATION_OFF;
+ else if (!strcmp(str, "auto"))
+ mds_mitigation = MDS_MITIGATION_AUTO;
+ else if (!strcmp(str, "full"))
+ mds_mitigation = MDS_MITIGATION_FULL;
+
+ return 0;
+}
+early_param("mds", mds_cmdline);
+
+#undef pr_fmt
#define pr_fmt(fmt) "Spectre V2 : " fmt
static enum spectre_v2_mitigation spectre_v2_enabled __ro_after_init =
@@ -614,6 +670,15 @@ static void update_indir_branch_cond(voi
static_branch_disable(&switch_to_cond_stibp);
}
+/* Update the static key controlling the MDS CPU buffer clear in idle */
+static void update_mds_branch_idle(void)
+{
+ if (sched_smt_active())
+ static_branch_enable(&mds_idle_clear);
+ else
+ static_branch_disable(&mds_idle_clear);
+}
+
void arch_smt_update(void)
{
/* Enhanced IBRS implies STIBP. No update required. */
@@ -635,6 +700,17 @@ void arch_smt_update(void)
break;
}
+ switch (mds_mitigation) {
+ case MDS_MITIGATION_OFF:
+ break;
+ case MDS_MITIGATION_FULL:
+ update_mds_branch_idle();
+ break;
+ /* Keep GCC happy */
+ case MDS_MITIGATION_AUTO:
+ break;
+ }
+
mutex_unlock(&spec_ctrl_mutex);
}
next prev parent reply other threads:[~2019-02-20 15:18 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-20 15:07 [patch V2 00/10] MDS basics+ 0 Thomas Gleixner
2019-02-20 15:07 ` [patch V2 01/10] MDS basics+ 1 Thomas Gleixner
2019-02-20 16:27 ` [MODERATED] " Borislav Petkov
2019-02-20 16:46 ` Greg KH
2019-02-20 15:07 ` [patch V2 02/10] MDS basics+ 2 Thomas Gleixner
2019-02-20 16:47 ` [MODERATED] " Borislav Petkov
2019-02-20 16:48 ` Greg KH
2019-02-20 15:07 ` [patch V2 03/10] MDS basics+ 3 Thomas Gleixner
2019-02-20 16:54 ` [MODERATED] " mark gross
2019-02-20 16:57 ` Thomas Gleixner
2019-02-20 18:08 ` [MODERATED] " mark gross
2019-02-20 21:40 ` Thomas Gleixner
2019-02-20 17:14 ` [MODERATED] " Borislav Petkov
2019-02-20 21:31 ` Thomas Gleixner
2019-02-21 2:12 ` [MODERATED] " Andrew Cooper
2019-02-21 9:27 ` Peter Zijlstra
2019-02-21 9:33 ` [MODERATED] " Borislav Petkov
2019-02-21 10:04 ` Thomas Gleixner
2019-02-21 10:18 ` [MODERATED] Re: " Borislav Petkov
2019-02-20 15:07 ` [patch V2 04/10] MDS basics+ 4 Thomas Gleixner
2019-02-20 16:52 ` [MODERATED] " Greg KH
2019-02-20 17:10 ` mark gross
2019-02-21 19:26 ` [MODERATED] Encrypted Message Tim Chen
2019-02-21 20:32 ` Thomas Gleixner
2019-02-21 21:07 ` [MODERATED] " Jiri Kosina
2019-02-20 18:43 ` [MODERATED] Re: [patch V2 04/10] MDS basics+ 4 Borislav Petkov
2019-02-20 19:26 ` Jiri Kosina
2019-02-20 21:42 ` Thomas Gleixner
2019-02-20 15:07 ` [patch V2 05/10] MDS basics+ 5 Thomas Gleixner
2019-02-20 20:05 ` [MODERATED] " Borislav Petkov
2019-02-21 2:24 ` Andrew Cooper
2019-02-21 10:36 ` Thomas Gleixner
2019-02-21 11:22 ` Thomas Gleixner
2019-02-21 11:51 ` [MODERATED] Attack Surface [Was [patch V2 05/10] MDS basics+ 5] Andrew Cooper
2019-02-21 18:41 ` Thomas Gleixner
2019-02-20 15:07 ` Thomas Gleixner [this message]
2019-02-21 10:18 ` [MODERATED] Re: [patch V2 06/10] MDS basics+ 6 Borislav Petkov
2019-02-20 15:08 ` [patch V2 07/10] MDS basics+ 7 Thomas Gleixner
2019-02-21 12:47 ` [MODERATED] " Borislav Petkov
2019-02-21 13:48 ` Thomas Gleixner
2019-02-20 15:08 ` [patch V2 08/10] MDS basics+ 8 Thomas Gleixner
2019-02-21 14:04 ` [MODERATED] " Borislav Petkov
2019-02-21 14:11 ` Thomas Gleixner
2019-02-20 15:08 ` [patch V2 09/10] MDS basics+ 9 Thomas Gleixner
2019-02-20 16:21 ` [MODERATED] " Peter Zijlstra
2019-02-20 22:32 ` Thomas Gleixner
2019-02-20 22:50 ` [MODERATED] " Jiri Kosina
2019-02-20 23:22 ` Thomas Gleixner
2019-02-21 11:04 ` [MODERATED] " Peter Zijlstra
2019-02-21 11:50 ` Peter Zijlstra
2019-02-21 14:18 ` Borislav Petkov
2019-02-21 18:00 ` Kees Cook
2019-02-21 19:46 ` Thomas Gleixner
2019-02-21 20:56 ` Thomas Gleixner
2019-02-20 15:08 ` [patch V2 10/10] MDS basics+ 10 Thomas Gleixner
2019-02-22 16:05 ` [MODERATED] Re: [patch V2 00/10] MDS basics+ 0 mark gross
2019-02-22 17:12 ` Thomas Gleixner
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=20190220151400.501811184@linutronix.de \
--to=tglx@linutronix.de \
--cc=speck@linutronix.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.