Skip to contentSkip to conversation

Proposed cmdline improvements

RFC PATCH In review Josh Poimboeuf 3 participants 17 messages Mar 4, 2019 – Mar 6, 2019

Subsystems (7)
Documentation x86 PowerPC s390 +3 more subsystems
lore
Share & tools
lore
#0 lore raw

cover Proposed cmdline improvements

For MDS and SMT, I'd propose that we do something similar to what we did for L1TF: a) add an mds=full,nosmt option; and b) add a printk warning if SMT is enabled. That's the first three patches.

The last patch proposes a meta-option which is intended to make it easier for users to choose sane mitigation defaults for all the speculative vulnerabilities at once.

Josh Poimboeuf (4):
x86/speculation/mds: Add mds=full,nosmt cmdline option x86/speculation: Move arch_smt_update() call to after mitigation
decisions
x86/speculation/mds: Add SMT warning message x86/speculation: Add 'cpu_spec_mitigations=' cmdline options

 Documentation/admin-guide/hw-vuln/mds.rst     |  3 +
 .../admin-guide/kernel-parameters.txt         | 49 ++++++++++++-
 arch/powerpc/kernel/security.c                |  6 +-
 arch/powerpc/kernel/setup_64.c                |  2 +-
 arch/s390/kernel/nospec-branch.c              |  4 +-
 arch/x86/include/asm/processor.h              |  2 +
 arch/x86/kernel/cpu/bugs.c                    | 68 ++++++++++++++++---
 arch/x86/mm/pti.c                             |  3 +-
 include/linux/cpu.h                           |  8 +++
 kernel/cpu.c                                  | 15 ++++
 10 files changed, 144 insertions(+), 16 deletions(-)
Signature · 1 line
2.17.2
#1 lore raw

RFC PATCH 1/4 1

From: Josh Poimboeuf <[email protected]>
Subject: [PATCH RFC 1/4] x86/speculation/mds: Add mds=full,nosmt cmdline
option

Add the mds=full,nosmt cmdline option. This is like mds=full, but with SMT disabled if the CPU is vulnerable.

---
 Documentation/admin-guide/hw-vuln/mds.rst       |  3 +++
 Documentation/admin-guide/kernel-parameters.txt |  6 ++++--
 arch/x86/kernel/cpu/bugs.c                      | 10 ++++++++++
 3 files changed, 17 insertions(+), 2 deletions(-)
Documentation/admin-guide/hw-vuln/mds.rst +3 -0
index 1de29d28903d..244ab47d1fb3 100644
@@ -260,6 +260,9 @@ time with the option "mds=". The valid arguments for this option are:
 
 		It does not automatically disable SMT.
 
+  full,nosmt	The same as mds=full, with SMT disabled on vulnerable
+		CPUs.  This is the complete mitigation.
+
   off		Disables MDS mitigations completely.
 
   ============  =============================================================
Documentation/admin-guide/kernel-parameters.txt +4 -2
index dddb024eb523..55969f240f2e 100644
@@ -2372,8 +2372,10 @@
 			This parameter controls the MDS mitigation. The
 			options are:
 
-			full    - Enable MDS mitigation on vulnerable CPUs
-			off     - Unconditionally disable MDS mitigation
+			full       - Enable MDS mitigation on vulnerable CPUs
+			full,nosmt - Enable MDS mitigation and disable
+				     SMT on vulnerable CPUs
+			off        - Unconditionally disable MDS mitigation
 
 			Not specifying this option is equivalent to
 			mds=full.
arch/x86/kernel/cpu/bugs.c +10 -0
index e11654f93e71..0c71ab0d57e3 100644
@@ -221,6 +221,7 @@ static void x86_amd_ssb_disable(void)
 
 /* Default mitigation for L1TF-affected CPUs */
 static enum mds_mitigations mds_mitigation __ro_after_init = MDS_MITIGATION_FULL;
+static bool mds_nosmt __ro_after_init = false;
 
 static const char * const mds_strings[] = {
 	[MDS_MITIGATION_OFF]	= "Vulnerable",
@@ -238,8 +239,13 @@ static void mds_select_mitigation(void)
 	if (mds_mitigation == MDS_MITIGATION_FULL) {
 		if (!boot_cpu_has(X86_FEATURE_MD_CLEAR))
 			mds_mitigation = MDS_MITIGATION_VMWERV;
+
 		static_branch_enable(&mds_user_clear);
+
+		if (mds_nosmt && !boot_cpu_has(X86_BUG_MSBDS_ONLY))
+			cpu_smt_disable(false);
 	}
+
 	pr_info("%s\n", mds_strings[mds_mitigation]);
 }
 
@@ -255,6 +261,10 @@ static int __init mds_cmdline(char *str)
 		mds_mitigation = MDS_MITIGATION_OFF;
 	else if (!strcmp(str, "full"))
 		mds_mitigation = MDS_MITIGATION_FULL;
+	else if (!strcmp(str, "full,nosmt")) {
+		mds_mitigation = MDS_MITIGATION_FULL;
+		mds_nosmt = true;
+	}
 
 	return 0;
 }
Signature · 1 line
2.17.2
#2 lore raw

[MODERATED] Encrypted Message

From: Jon Masters <[email protected]>
To: speck for Josh Poimboeuf <[email protected]>
Subject: Re: [PATCH RFC 1/4] 1

Quoted 13 lines · speck for Josh Poimboeuf
arch/x86/kernel/cpu/bugs.c +1 -0
index e11654f93e71..0c71ab0d57e3 100644
@@ -221,6 +221,7 @@ static void x86_amd_ssb_disable(void)
 
 /* Default mitigation for L1TF-affected CPUs */
 static enum mds_mitigations mds_mitigation __ro_after_init = MDS_MITIGATION_FULL;
+static bool mds_nosmt __ro_after_init = false;
 
 static const char * const mds_strings[] = {
 	[MDS_MITIGATION_OFF]	= "Vulnerable",

arch/x86/kernel/cpu/bugs.c static void mds_select_mitigation(void) · line 246

Quoted 8 lines
arch/x86/kernel/cpu/bugs.c +4 -0
@@ -238,8 +239,13 @@ static void mds_select_mitigation(void)
 	if (mds_mitigation == MDS_MITIGATION_FULL) {
 		if (!boot_cpu_has(X86_FEATURE_MD_CLEAR))
 			mds_mitigation = MDS_MITIGATION_VMWERV;
+
 		static_branch_enable(&mds_user_clear);
+
+		if (mds_nosmt && !boot_cpu_has(X86_BUG_MSBDS_ONLY))
+			cpu_smt_disable(false);

Is there some logic missing here to disable SMT?

Jon.

Signature · 1 line
Computer Architect | Sent with my Fedora powered laptop
#3 lore raw

[MODERATED] Re: Encrypted Message

Quoted 12 lines · speck for Jon Masters
Quoted 10 lines · speck for Josh Poimboeuf
arch/x86/kernel/cpu/bugs.c +1 -0
index e11654f93e71..0c71ab0d57e3 100644
@@ -221,6 +221,7 @@ static void x86_amd_ssb_disable(void)
 
 /* Default mitigation for L1TF-affected CPUs */
 static enum mds_mitigations mds_mitigation __ro_after_init = MDS_MITIGATION_FULL;
+static bool mds_nosmt __ro_after_init = false;
 
Quoted 13 lines

arch/x86/kernel/cpu/bugs.c static void mds_select_mitigation(void) · line 246

Quoted 11 lines
arch/x86/kernel/cpu/bugs.c +4 -0
 static const char * const mds_strings[] = {
 	[MDS_MITIGATION_OFF]	= "Vulnerable",
@@ -238,8 +239,13 @@ static void mds_select_mitigation(void)
 	if (mds_mitigation == MDS_MITIGATION_FULL) {
 		if (!boot_cpu_has(X86_FEATURE_MD_CLEAR))
 			mds_mitigation = MDS_MITIGATION_VMWERV;
+
 		static_branch_enable(&mds_user_clear);
+
+		if (mds_nosmt && !boot_cpu_has(X86_BUG_MSBDS_ONLY))
+			cpu_smt_disable(false);

Is there some logic missing here to disable SMT?

That would be the cpu_smt_disable() call :-)

Signature · 1 line
Josh
#4 lore raw

[MODERATED] Re: [PATCH RFC 1/4] 1

In reply to Josh Poimboeuf
Quoted 19 lines · speck for Josh Poimboeuf

From: Josh Poimboeuf <[email protected]>
Subject: [PATCH RFC 1/4] x86/speculation/mds: Add mds=full,nosmt cmdline
option

Add the mds=full,nosmt cmdline option. This is like mds=full, but with SMT disabled if the CPU is vulnerable.

---
 Documentation/admin-guide/hw-vuln/mds.rst       |  3 +++
 Documentation/admin-guide/kernel-parameters.txt |  6 ++++--
 arch/x86/kernel/cpu/bugs.c                      | 10 ++++++++++
 3 files changed, 17 insertions(+), 2 deletions(-)
Documentation/admin-guide/hw-vuln/mds.rst +0 -0
index 1de29d28903d..244ab47d1fb3 100644

Documentation/admin-guide/hw-vuln/mds.rst time with the option "mds=". The valid arguments for this option are: · line 264

Quoted 5 lines
Documentation/admin-guide/hw-vuln/mds.rst +2 -0
@@ -260,6 +260,9 @@ time with the option "mds=". The valid arguments for this option are:
 
 		It does not automatically disable SMT.
 
+  full,nosmt	The same as mds=full, with SMT disabled on vulnerable
+		CPUs.  This is the complete mitigation.

While I understand the intention, the number of different combinations we are "offering" to userspace here is huge, and everyone is going to be confused as to what to do. If we really think/say that SMT is a major issue for this, why don't we just have "full" disable SMT?

thanks,

greg k-h

#5 lore raw

[MODERATED] Encrypted Message

From: Jon Masters <[email protected]>
To: speck for Greg KH <[email protected]>
Subject: Re: [PATCH RFC 1/4] 1

Quoted 23 lines · speck for Greg KH
Quoted 22 lines · speck for Josh Poimboeuf

From: Josh Poimboeuf <[email protected]>
Subject: [PATCH RFC 1/4] x86/speculation/mds: Add mds=full,nosmt cmdline
option

Add the mds=full,nosmt cmdline option. This is like mds=full, but with SMT disabled if the CPU is vulnerable.

---
 Documentation/admin-guide/hw-vuln/mds.rst       |  3 +++
 Documentation/admin-guide/kernel-parameters.txt |  6 ++++--
 arch/x86/kernel/cpu/bugs.c                      | 10 ++++++++++
 3 files changed, 17 insertions(+), 2 deletions(-)
Documentation/admin-guide/hw-vuln/mds.rst +0 -0
index 1de29d28903d..244ab47d1fb3 100644
@@ -260,6 +260,9 @@ time with the option "mds=". The valid arguments for this option are:
 
 		It does not automatically disable SMT.
 
Quoted 7 lines

Documentation/admin-guide/hw-vuln/mds.rst time with the option "mds=". The valid arguments for this option are: · line 264

Quoted 2 lines
Documentation/admin-guide/hw-vuln/mds.rst +2 -0
+  full,nosmt	The same as mds=full, with SMT disabled on vulnerable
+		CPUs.  This is the complete mitigation.

While I understand the intention, the number of different combinations we are "offering" to userspace here is huge, and everyone is going to be confused as to what to do. If we really think/say that SMT is a major issue for this, why don't we just have "full" disable SMT?

Frankly, it ought to for safety (can't be made safe). The reason cited for not doing so (Thomas and Linus can speak up on this part) was upgrades vs new installs. The concern was not to break existing folks by losing half their logical CPU count when upgrading a kernel.

Jon.

Signature · 1 line
Computer Architect | Sent with my Fedora powered laptop
#6 lore raw

RFC PATCH 2/4 2

In reply to Josh Poimboeuf

From: Josh Poimboeuf <[email protected]>
Subject: [PATCH RFC 2/4] x86/speculation: Move arch_smt_update() call to after
mitigation decisions

arch_smt_update() now has a dependency on both Spectre v2 and MDS mitigations. Move its initial call to after all the mitigation decisions have been made.

---
 arch/x86/kernel/cpu/bugs.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/bugs.c +2 -3
index 0c71ab0d57e3..9e20aef01d38 100644
@@ -111,6 +111,8 @@ void __init check_bugs(void)
 
 	mds_select_mitigation();
 
+	arch_smt_update();
+
 #ifdef CONFIG_X86_32
 	/*
 	 * Check whether we are able to run this kernel safely on SMP.
@@ -638,9 +640,6 @@ static void __init spectre_v2_select_mitigation(void)
 
 	/* Set up IBPB and STIBP depending on the general spectre V2 command */
 	spectre_v2_user_select_mitigation(cmd);
-
-	/* Enable STIBP if appropriate */
-	arch_smt_update();
 }
 
 static void update_stibp_msr(void * __unused)
Signature · 1 line
2.17.2
#7 lore raw

[MODERATED] Re: [PATCH RFC 2/4] 2

Quoted 7 lines · speck for Josh Poimboeuf

From: Josh Poimboeuf <[email protected]>
Subject: [PATCH RFC 2/4] x86/speculation: Move arch_smt_update() call to after
mitigation decisions

arch_smt_update() now has a dependency on both Spectre v2 and MDS mitigations. Move its initial call to after all the mitigation decisions have been made.

So Patch 1 doesn't work without this? If so, shouldn't this go first?

thanks,

greg k-h

#8 lore raw

[MODERATED] Re: [PATCH RFC 2/4] 2

Quoted 10 lines · speck for Greg KH
Quoted 7 lines · speck for Josh Poimboeuf

From: Josh Poimboeuf <[email protected]>
Subject: [PATCH RFC 2/4] x86/speculation: Move arch_smt_update() call to after
mitigation decisions

arch_smt_update() now has a dependency on both Spectre v2 and MDS mitigations. Move its initial call to after all the mitigation decisions have been made.

So Patch 1 doesn't work without this? If so, shouldn't this go first?

No, I think patch 1 works fine without it. It's really a prereq for patch 3 (and also a cleanup to prevent future bugs).

Signature · 1 line
Josh
#9 lore raw

RFC PATCH 3/4 3

In reply to Josh Poimboeuf

From: Josh Poimboeuf <[email protected]>
Subject: [PATCH RFC 3/4] x86/speculation/mds: Add SMT warning message

MDS is vulnerable with SMT. Make that clear with a one-time printk whenever SMT first gets enabled.

---
 arch/x86/kernel/cpu/bugs.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/kernel/cpu/bugs.c +4 -0
index 9e20aef01d38..346f0f05879d 100644
@@ -691,6 +691,8 @@ static void update_mds_branch_idle(void)
 		static_branch_disable(&mds_idle_clear);
 }
 
+#define MDS_MSG_SMT "MDS CPU bug present and SMT on, data leak possible. See https://www.kernel.org/doc/html/latest/admin-guide/hw-vuln/mds.html for more details.\n"
+
 void arch_smt_update(void)
 {
 	/* Enhanced IBRS implies STIBP. No update required. */
@@ -715,6 +717,8 @@ void arch_smt_update(void)
 	switch(mds_mitigation) {
 	case MDS_MITIGATION_FULL:
 	case MDS_MITIGATION_VMWERV:
+		if (sched_smt_active() && !boot_cpu_has(X86_BUG_MSBDS_ONLY))
+			pr_warn_once(MDS_MSG_SMT);
 		update_mds_branch_idle();
 		break;
 	case MDS_MITIGATION_OFF:
Signature · 1 line
2.17.2
#10 lore raw

[MODERATED] Encrypted Message

From: Jon Masters <[email protected]>
To: speck for Josh Poimboeuf <[email protected]>
Subject: Re: [PATCH RFC 3/4] 3

arch/x86/kernel/cpu/bugs.c void arch_smt_update(void) · line 721

Quoted 2 lines · speck for Josh Poimboeuf
arch/x86/kernel/cpu/bugs.c +2 -0
+		if (sched_smt_active() && !boot_cpu_has(X86_BUG_MSBDS_ONLY))
+			pr_warn_once(MDS_MSG_SMT);

It's never fully safe to use SMT. I get that if we only had MSBDS then it's unlikely we'll hit the e.g. power state change cases needed to exploit it but I think it would be prudent to display something anyway?

Jon.

Signature · 1 line
Computer Architect | Sent with my Fedora powered laptop
#11 lore raw

[MODERATED] Re: Encrypted Message

Quoted 8 lines · speck for Jon Masters

arch/x86/kernel/cpu/bugs.c void arch_smt_update(void) · line 721

Quoted 2 lines · speck for Josh Poimboeuf
arch/x86/kernel/cpu/bugs.c +2 -0
+		if (sched_smt_active() && !boot_cpu_has(X86_BUG_MSBDS_ONLY))
+			pr_warn_once(MDS_MSG_SMT);

It's never fully safe to use SMT. I get that if we only had MSBDS then it's unlikely we'll hit the e.g. power state change cases needed to exploit it but I think it would be prudent to display something anyway?

My understanding is that the idle state changes are mitigated elsewhere in the MDS patches, so it should be safe in theory.

Signature · 1 line
Josh
#12 lore raw

[MODERATED] Encrypted Message

From: Jon Masters <[email protected]>
To: speck for Josh Poimboeuf <[email protected]>
Subject: Re: Encrypted Message

Quoted 11 lines · speck for Josh Poimboeuf
Quoted 8 lines · speck for Jon Masters

arch/x86/kernel/cpu/bugs.c void arch_smt_update(void) · line 721

Quoted 2 lines · speck for Josh Poimboeuf
arch/x86/kernel/cpu/bugs.c +2 -0
+		if (sched_smt_active() && !boot_cpu_has(X86_BUG_MSBDS_ONLY))
+			pr_warn_once(MDS_MSG_SMT);

It's never fully safe to use SMT. I get that if we only had MSBDS then it's unlikely we'll hit the e.g. power state change cases needed to exploit it but I think it would be prudent to display something anyway?

Quoted 2 lines

My understanding is that the idle state changes are mitigated elsewhere in the MDS patches, so it should be safe in theory.

Looked at it again. Agree. Sorry about that.

Jon.

Signature · 1 line
Computer Architect | Sent with my Fedora powered laptop
#13 lore raw

[MODERATED] Re: [PATCH RFC 3/4] 3

In reply to Josh Poimboeuf
Quoted 16 lines · speck for Josh Poimboeuf

From: Josh Poimboeuf <[email protected]>
Subject: [PATCH RFC 3/4] x86/speculation/mds: Add SMT warning message

MDS is vulnerable with SMT. Make that clear with a one-time printk whenever SMT first gets enabled.

---
 arch/x86/kernel/cpu/bugs.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/kernel/cpu/bugs.c +0 -0
index 9e20aef01d38..346f0f05879d 100644

arch/x86/kernel/cpu/bugs.c static void update_mds_branch_idle(void) · line 694

Quoted 4 lines
arch/x86/kernel/cpu/bugs.c +1 -0
@@ -691,6 +691,8 @@ static void update_mds_branch_idle(void)
 		static_branch_disable(&mds_idle_clear);
 }
 
+#define MDS_MSG_SMT "MDS CPU bug present and SMT on, data leak possible. See https://www.kernel.org/doc/html/latest/admin-guide/hw-vuln/mds.html for more details.\n"

Why a #define? Just stick that string into the printk message.

thanks,

greg k-h

#14 lore raw

[MODERATED] Re: [PATCH RFC 3/4] 3

Quoted 20 lines · speck for Greg KH
Quoted 19 lines · speck for Josh Poimboeuf

From: Josh Poimboeuf <[email protected]>
Subject: [PATCH RFC 3/4] x86/speculation/mds: Add SMT warning message

MDS is vulnerable with SMT. Make that clear with a one-time printk whenever SMT first gets enabled.

---
 arch/x86/kernel/cpu/bugs.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/kernel/cpu/bugs.c +0 -0
index 9e20aef01d38..346f0f05879d 100644
@@ -691,6 +691,8 @@ static void update_mds_branch_idle(void)
 		static_branch_disable(&mds_idle_clear);
 }
 
Quoted 3 lines

arch/x86/kernel/cpu/bugs.c static void update_mds_branch_idle(void) · line 694

Quoted 1 line
arch/x86/kernel/cpu/bugs.c +1 -0
+#define MDS_MSG_SMT "MDS CPU bug present and SMT on, data leak possible. See https://www.kernel.org/doc/html/latest/admin-guide/hw-vuln/mds.html for more details.\n"

Why a #define? Just stick that string into the printk message.

The message is so long that it will really break up the flow and readability of the code IMO. We did the same thing in the vmx code for the same reasons -- see L1TF_MSG_SMT and L1TF_MSG_L1D.

Signature · 1 line
Josh
#15 lore raw

RFC PATCH 4/4 4

In reply to Josh Poimboeuf

From: Josh Poimboeuf <[email protected]>
Subject: [PATCH RFC 4/4] x86/speculation: Add 'cpu_spec_mitigations=' cmdline
options

Keeping track of the number of mitigations for all the CPU speculation bugs has become overwhelming for many users. It's getting more and more complicated to decide what mitigations are needed for a given architecture.

Most users fall into a few basic categories:

- want all mitigations off;

- want all reasonable mitigations on, with SMT enabled even if it's vulnerable; or

- want all reasonable mitigations on, with SMT disabled if vulnerable.

Define a set of curated, arch-independent options, each of which is an aggregation of existing options:

- cpu_spec_mitigations=off: Disable all mitigations.

- cpu_spec_mitigations=auto: [default] Enable all the default mitigations, but leave SMT enabled, even if it's vulnerable.

- cpu_spec_mitigations=auto,nosmt: Enable all the default mitigations, disabling SMT if needed by a mitigation.

See the documentation for more details.

---
 .../admin-guide/kernel-parameters.txt         | 43 ++++++++++++++++
 arch/powerpc/kernel/security.c                |  6 +--
 arch/powerpc/kernel/setup_64.c                |  2 +-
 arch/s390/kernel/nospec-branch.c              |  4 +-
 arch/x86/include/asm/processor.h              |  2 +
 arch/x86/kernel/cpu/bugs.c                    | 51 ++++++++++++++++---
 arch/x86/mm/pti.c                             |  3 +-
 include/linux/cpu.h                           |  8 +++
 kernel/cpu.c                                  | 15 ++++++
 9 files changed, 122 insertions(+), 12 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +43 -0
index 55969f240f2e..c2dba60630e4 100644
@@ -2537,6 +2537,49 @@
 			in the "bleeding edge" mini2440 support kernel at
 			http://repo.or.cz/w/linux-2.6/mini2440.git
 
+	cpu_spec_mitigations=
+			[KNL] Control mitigations for CPU speculation
+			vulnerabilities on affected CPUs.  This is a set of
+			curated, arch-independent options, each of which is an
+			aggregation of existing options.
+
+			off
+				Disable all speculative CPU mitigations.
+				Equivalent to: nopti
+					       nospectre_v1
+					       nospectre_v2
+					       spectre_v2_user=off
+					       nobp=0
+					       spec_store_bypass_disable=off
+					       l1tf=off
+					       mds=off
+
+			auto (default)
+				Mitigate all speculative CPU vulnerabilities,
+				but leave SMT enabled, even if it's vulnerable.
+				This is useful for users who don't want to be
+				surprised by SMT getting disabled across kernel
+				upgrades, or who have other ways of avoiding
+				SMT-based attacks.
+				Equivalent to: pti=auto
+					       spectre_v2=auto
+					       spectre_v2_user=auto
+					       spec_store_bypass_disable=auto
+					       l1tf=flush
+					       mds=full
+
+			auto,nosmt
+				Mitigate all speculative CPU vulnerabilities,
+				disabling SMT if needed.  This is for users who
+				always want to be fully mitigated, even if it
+				means losing SMT.
+				Equivalent to: pti=auto
+					       spectre_v2=auto
+					       spectre_v2_user=auto
+					       spec_store_bypass_disable=auto
+					       l1tf=flush,nosmt
+					       mds=full,nosmt
+
 	mminit_loglevel=
 			[KNL] When CONFIG_DEBUG_MEMORY_INIT is set, this
 			parameter allows control of the logging verbosity for
arch/powerpc/kernel/security.c +3 -3
index 9b8631533e02..be4266a57e54 100644
@@ -57,7 +57,7 @@ void setup_barrier_nospec(void)
 	enable = security_ftr_enabled(SEC_FTR_FAVOUR_SECURITY) &&
 		 security_ftr_enabled(SEC_FTR_BNDS_CHK_SPEC_BAR);
 
-	if (!no_nospec)
+	if (!no_nospec && cpu_spec_mitigations != CPU_SPEC_MITIGATIONS_OFF)
 		enable_barrier_nospec(enable);
 }
 
@@ -116,7 +116,7 @@ static int __init handle_nospectre_v2(char *p)
 early_param("nospectre_v2", handle_nospectre_v2);
 void setup_spectre_v2(void)
 {
-	if (no_spectrev2)
+	if (no_spectrev2 || cpu_spec_mitigations == CPU_SPEC_MITIGATIONS_OFF)
 		do_btb_flush_fixups();
 	else
 		btb_flush_enabled = true;
@@ -307,7 +307,7 @@ void setup_stf_barrier(void)
 
 	stf_enabled_flush_types = type;
 
-	if (!no_stf_barrier)
+	if (!no_stf_barrier && cpu_spec_mitigations != CPU_SPEC_MITIGATIONS_OFF)
 		stf_barrier_enable(enable);
 }
 
arch/powerpc/kernel/setup_64.c +1 -1
index 236c1151a3a7..5fe43bcde325 100644
@@ -958,7 +958,7 @@ void setup_rfi_flush(enum l1d_flush_type types, bool enable)
 
 	enabled_flush_types = types;
 
-	if (!no_rfi_flush)
+	if (!no_rfi_flush || cpu_spec_mitigations != CPU_SPEC_MITIGATIONS_OFF)
 		rfi_flush_enable(enable);
 }
 
arch/s390/kernel/nospec-branch.c +3 -1
index bdddaae96559..c40eb672b43a 100644
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <linux/module.h>
 #include <linux/device.h>
+#include <linux/cpu.h>
 #include <asm/nospec-branch.h>
 
 static int __init nobp_setup_early(char *str)
@@ -58,7 +59,8 @@ early_param("nospectre_v2", nospectre_v2_setup_early);
 
 void __init nospec_auto_detect(void)
 {
-	if (test_facility(156)) {
+	if (test_facility(156) ||
+	    cpu_spec_mitigations == CPU_SPEC_MITIGATIONS_OFF) {
 		/*
 		 * The machine supports etokens.
 		 * Disable expolines and disable nobp.
arch/x86/include/asm/processor.h +2 -0
index aca1ef8cc79f..bb2ced3a491e 100644
@@ -983,6 +983,7 @@ void microcode_check(void);
 
 enum l1tf_mitigations {
 	L1TF_MITIGATION_OFF,
+	L1TF_MITIGATION_DEFAULT,
 	L1TF_MITIGATION_FLUSH_NOWARN,
 	L1TF_MITIGATION_FLUSH,
 	L1TF_MITIGATION_FLUSH_NOSMT,
@@ -994,6 +995,7 @@ extern enum l1tf_mitigations l1tf_mitigation;
 
 enum mds_mitigations {
 	MDS_MITIGATION_OFF,
+	MDS_MITIGATION_DEFAULT,
 	MDS_MITIGATION_FULL,
 	MDS_MITIGATION_VMWERV,
 };
arch/x86/kernel/cpu/bugs.c +45 -6

106 lines not on this page · raw message

arch/x86/mm/pti.c +2 -1
index 4fee5c3003ed..943b641bc003 100644
@@ -115,7 +115,8 @@ void __init pti_check_boottime_disable(void)
 		}
 	}
 
-	if (cmdline_find_option_bool(boot_command_line, "nopti")) {
+	if (cmdline_find_option_bool(boot_command_line, "nopti") ||
+	    cpu_spec_mitigations == CPU_SPEC_MITIGATIONS_OFF) {
 		pti_mode = PTI_FORCE_OFF;
 		pti_print_if_insecure("disabled on command line.");
 		return;
include/linux/cpu.h +8 -0
index 3c87ad888ed3..6cdd3d5228d3 100644
@@ -189,4 +189,12 @@ static inline void cpu_smt_disable(bool force) { }
 static inline void cpu_smt_check_topology(void) { }
 #endif
 
+enum cpu_spec_mitigations {
+	CPU_SPEC_MITIGATIONS_OFF,
+	CPU_SPEC_MITIGATIONS_AUTO,
+	CPU_SPEC_MITIGATIONS_AUTO_NOSMT,
+};
+
+extern enum cpu_spec_mitigations cpu_spec_mitigations;
+
 #endif /* _LINUX_CPU_H_ */
kernel/cpu.c +15 -0
index d1c6d152da89..136d33fb90e5 100644
@@ -2279,3 +2279,18 @@ void __init boot_cpu_hotplug_init(void)
 #endif
 	this_cpu_write(cpuhp_state.state, CPUHP_ONLINE);
 }
+
+enum cpu_spec_mitigations cpu_spec_mitigations __ro_after_init = CPU_SPEC_MITIGATIONS_AUTO;
+
+static int __init cpu_spec_mitigations_setup(char *arg)
+{
+	if (!strcmp(arg, "off"))
+		cpu_spec_mitigations = CPU_SPEC_MITIGATIONS_OFF;
+	else if (!strcmp(arg, "auto"))
+		cpu_spec_mitigations = CPU_SPEC_MITIGATIONS_AUTO;
+	else if (!strcmp(arg, "auto,nosmt"))
+		cpu_spec_mitigations = CPU_SPEC_MITIGATIONS_AUTO_NOSMT;
+
+	return 0;
+}
+early_param("cpu_spec_mitigations", cpu_spec_mitigations_setup);
Signature · 1 line
2.17.2
#16 lore raw

[MODERATED] Encrypted Message

From: Jon Masters <[email protected]>
To: speck for Josh Poimboeuf <[email protected]>
Subject: Re: [PATCH RFC 4/4] 4

Quoted 23 lines · speck for Josh Poimboeuf

From: Josh Poimboeuf <[email protected]>
Subject: [PATCH RFC 4/4] x86/speculation: Add 'cpu_spec_mitigations=' cmdline
options

Keeping track of the number of mitigations for all the CPU speculation bugs has become overwhelming for many users. It's getting more and more complicated to decide what mitigations are needed for a given architecture.

Most users fall into a few basic categories:

- want all mitigations off;

- want all reasonable mitigations on, with SMT enabled even if it's vulnerable; or

- want all reasonable mitigations on, with SMT disabled if vulnerable.

Define a set of curated, arch-independent options, each of which is an aggregation of existing options:

- cpu_spec_mitigations=off: Disable all mitigations.

Quoted 7 lines

- cpu_spec_mitigations=auto: [default] Enable all the default mitigations, but leave SMT enabled, even if it's vulnerable.

- cpu_spec_mitigations=auto,nosmt: Enable all the default mitigations, disabling SMT if needed by a mitigation.

See the documentation for more details.

Looks good. There's an effort to upstream mitigation controls for the arm64 but that's not in place yet. They'll want to wire that up later. I actually had missed the s390x etokens work so that was fun to see here.

Jon.

Signature · 1 line
Computer Architect | Sent with my Fedora powered laptop