Skip to contentSkip to conversation

BUG: disabling SMT from BIOS

MODERATED Josh Poimboeuf 5 participants 15 messages Jul 22, 2018 – Jul 30, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

When SMT is disabled from BIOS, sysfs confusingly reports that SMT is enabled:

  $ cat /sys/devices/system/cpu/smt/control 
  on

And it allows turning it 'off' and 'on', though those don't seem to have any effect. (Though at least the 'active' file always shows '0'.)

And the 'l1tf' file reports that SMT is vulnerable:

  $ cat /sys/devices/system/cpu/vulnerabilities/l1tf 
  Mitigation: PTE Inversion; VMX: SMT vulnerable, L1D conditional cache flushes

which is obviously incorrect.

Signature · 1 line
Josh
#1 lore raw
Quoted 9 lines · speck for Josh Poimboeuf

When SMT is disabled from BIOS, sysfs confusingly reports that SMT is enabled:

  $ cat /sys/devices/system/cpu/smt/control 
  on

And it allows turning it 'off' and 'on', though those don't seem to have any effect. (Though at least the 'active' file always shows '0'.)

Quoted 6 lines

And the 'l1tf' file reports that SMT is vulnerable:

  $ cat /sys/devices/system/cpu/vulnerabilities/l1tf 
  Mitigation: PTE Inversion; VMX: SMT vulnerable, L1D conditional cache flushes

which is obviously incorrect.

I might not have time to test this properly today, but I think this should cure it, right?

From: Jiri Kosina <[email protected]>
Subject: [PATCH] x86, cpu/hotplug: fix topology_smt_supported()

Make sure topology_smt_supported() takes into account the detection performed by set_cpu_sibling_map() in order to properly report whether the current platform really does support SMT.

---
 arch/x86/kernel/smpboot.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/smpboot.c +1 -1
index 7f7def989fb0..afe4d1ee8c87 100644
@@ -279,7 +279,7 @@ bool topology_is_primary_thread(unsigned int cpu)
  */
 bool topology_smt_supported(void)
 {
-	return smp_num_siblings > 1;
+	return topology_max_smt_threads() > 1;
 }
 
 /**
Signature · 2 lines
Jiri Kosina
SUSE Labs
maintainer
#2 lore raw
Quoted 13 lines · speck for Jiri Kosina
Quoted 11 lines · speck for Josh Poimboeuf

When SMT is disabled from BIOS, sysfs confusingly reports that SMT is enabled:

  $ cat /sys/devices/system/cpu/smt/control 
  on

And it allows turning it 'off' and 'on', though those don't seem to have any effect. (Though at least the 'active' file always shows '0'.)

And the 'l1tf' file reports that SMT is vulnerable:

Quoted 7 lines
Quoted 4 lines
  $ cat /sys/devices/system/cpu/vulnerabilities/l1tf 
  Mitigation: PTE Inversion; VMX: SMT vulnerable, L1D conditional cache flushes

which is obviously incorrect.

I might not have time to test this properly today, but I think this should cure it, right?

Yes that looks about right, smp_num_siblings is the max number of siblings the CPUID topology information _can_ tell is about. topology_max_smt_threads() is howver many we've actually seen during enumeration.

If someone could confirm, I'll see if I can work this magic Thomas left me :-)

#3 lore raw
Quoted 2 lines · speck for Peter Zijlstra

Yes that looks about right, smp_num_siblings is the max number of siblings the CPUID topology information _can_ tell is about.

Exactly. And I think that's pretty much constant on a given system no matter the BIOS settings, contrary to the dynamically performed topology enumeration.

Quoted 5 lines

topology_max_smt_threads() is howver many we've actually seen during enumeration.

If someone could confirm, I'll see if I can work this magic Thomas left me :-)

Thanks; please also add

	Fixes: f048c399e0f74 ("x86/topology: Provide topology_smt_supported()")

once/if applying, I forgot to include that in a rush.

Signature · 2 lines
Jiri Kosina
SUSE Labs
author NAK
#4 lore raw
In reply to Peter Zijlstra
Quoted 22 lines · speck for Peter Zijlstra
Quoted 13 lines · speck for Jiri Kosina
Quoted 11 lines · speck for Josh Poimboeuf

When SMT is disabled from BIOS, sysfs confusingly reports that SMT is enabled:

  $ cat /sys/devices/system/cpu/smt/control 
  on

And it allows turning it 'off' and 'on', though those don't seem to have any effect. (Though at least the 'active' file always shows '0'.)

And the 'l1tf' file reports that SMT is vulnerable:

Quoted 7 lines
Quoted 4 lines
  $ cat /sys/devices/system/cpu/vulnerabilities/l1tf 
  Mitigation: PTE Inversion; VMX: SMT vulnerable, L1D conditional cache flushes

which is obviously incorrect.

I might not have time to test this properly today, but I think this should cure it, right?

Quoted 7 lines

Yes that looks about right, smp_num_siblings is the max number of siblings the CPUID topology information _can_ tell is about. topology_max_smt_threads() is howver many we've actually seen during enumeration.

If someone could confirm, I'll see if I can work this magic Thomas left me :-)

NACK, this permanently disables SMT on my system, regardless of the BIOS settings. I suspect it needs to be called later, after the other CPUs have been brought online.

Signature · 1 line
Josh
#5 lore raw
Quoted 2 lines · speck for Josh Poimboeuf

This permanently disables SMT on my system, regardless of the BIOS settings.

I see, we're setting _NOT_SUPPORTED before the sibling map has been established.

Quoted 2 lines

I suspect it needs to be called later, after the other CPUs have been brought online.

Either that, but that will basically mean redefining the CPU_SMT_ENABLED meaning, and I actually think the current semantics makes more sense.

How about this instead? (still untested)

From: Jiri Kosina <[email protected]>
Subject: [PATCH] x86/speculation/l1tf: properly report SMT vulnerable status

Even if SMT has not been disabled from the OS and CPUID indicates it's supported, we should report as SMT-vulnerable iff there really is more than one SMT sibling (consider "HT disabled in BIOS" case).

---
 arch/x86/kernel/cpu/bugs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/bugs.c +2 -1
index fa6123bdd032..023bcb4b8244 100644
@@ -760,7 +760,8 @@ static ssize_t l1tf_show_state(char *buf)
 		return sprintf(buf, "%s\n", L1TF_DEFAULT_MSG);
 
 	return sprintf(buf, "%s; VMX: SMT %s, L1D %s\n", L1TF_DEFAULT_MSG,
-		       cpu_smt_control == CPU_SMT_ENABLED ? "vulnerable" : "disabled",
+		       (cpu_smt_control == CPU_SMT_ENABLED && topology_max_smt_threads() > 1)
+			? "vulnerable" : "disabled",
 		       l1tf_vmx_states[l1tf_vmx_mitigation]);
 }
 #else
Signature · 2 lines
Jiri Kosina
SUSE Labs
#6 lore raw
Quoted 8 lines · speck for Jiri Kosina
Quoted 2 lines · speck for Josh Poimboeuf

This permanently disables SMT on my system, regardless of the BIOS settings.

I see, we're setting _NOT_SUPPORTED before the sibling map has been established.

Quoted 7 lines
Quoted 2 lines

I suspect it needs to be called later, after the other CPUs have been brought online.

Either that, but that will basically mean redefining the CPU_SMT_ENABLED meaning, and I actually think the current semantics makes more sense.

How about this instead? (still untested)

That seems like only half the fix, because the 'control' file still allows you to pretend to turn SMT off and on.

How about this one?

-----

From: Josh Poimboeuf <[email protected]>
Subject: [PATCH] cpu/hotplug: detect SMT disabled by BIOS

If SMT is disabled in BIOS, the CPU code doesn't properly detect it. The /sys/devices/system/cpu/smt/control file shows 'on', and the 'l1tf' vulnerabilities file shows SMT as vulnerable.

Fix it by forcing 'cpu_smt_control' to CPU_SMT_NOT_SUPPORTED in such a case. Unfortunately the detection can only be done after bringing all the CPUs online, so we have to overwrite any previous writes to the variable.

Fixes f048c399e0f7 ("x86/topology: Provide topology_smt_supported()")
---
 kernel/cpu.c | 9 +++++++++
 1 file changed, 9 insertions(+)
kernel/cpu.c +9 -0
index 37eec872042b..2bc3d2f5b2a5 100644
@@ -2125,6 +2125,15 @@ static const struct attribute_group cpuhp_smt_attr_group = {
 
 static int __init cpu_smt_state_init(void)
 {
+	/*
+	 * If SMT was disabled by BIOS, detect it here, after the CPUs have
+	 * been brought online.  This ensures the smt/l1tf sysfs entries are
+	 * consistent with reality.  Note this may overwrite cpu_smt_control's
+	 * previous setting.
+	 */
+	if (topology_max_smt_threads() == 1)
+		cpu_smt_control = CPU_SMT_NOT_SUPPORTED;
+
 	return sysfs_create_group(&cpu_subsys.dev_root->kobj,
 				  &cpuhp_smt_attr_group);
 }
Signature · 1 line
2.17.0
Tested-by
#7 lore raw
Quoted 7 lines · speck for Josh Poimboeuf

From: Josh Poimboeuf <[email protected]>
Subject: [PATCH] cpu/hotplug: detect SMT disabled by BIOS

If SMT is disabled in BIOS, the CPU code doesn't properly detect it. The /sys/devices/system/cpu/smt/control file shows 'on', and the 'l1tf' vulnerabilities file shows SMT as vulnerable.

Quoted 8 lines

Fix it by forcing 'cpu_smt_control' to CPU_SMT_NOT_SUPPORTED in such a case. Unfortunately the detection can only be done after bringing all the CPUs online, so we have to overwrite any previous writes to the variable.

Fixes f048c399e0f7 ("x86/topology: Provide topology_smt_supported()")

Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs
maintainer
#8 lore raw
Quoted 14 lines · speck for Jiri Kosina
Quoted 12 lines · speck for Josh Poimboeuf

From: Josh Poimboeuf <[email protected]>
Subject: [PATCH] cpu/hotplug: detect SMT disabled by BIOS

If SMT is disabled in BIOS, the CPU code doesn't properly detect it. The /sys/devices/system/cpu/smt/control file shows 'on', and the 'l1tf' vulnerabilities file shows SMT as vulnerable.

Fix it by forcing 'cpu_smt_control' to CPU_SMT_NOT_SUPPORTED in such a case. Unfortunately the detection can only be done after bringing all the CPUs online, so we have to overwrite any previous writes to the variable.

Quoted 5 lines
Quoted 3 lines
Fixes f048c399e0f7 ("x86/topology: Provide topology_smt_supported()")

Thanks guys!

I've pushed this out to speck/{master,linux-4.1[764].y}. In specific, I've not touched the 4.9 branch since that is dwmw2's baby and I didn't know if I was supposed to touch that.

If there's anything funny, that's because I'm basically useless at this git thing, but let me know and I'll try and fix it ;-)

maintainer
#9 lore raw
Quoted 21 lines · Peter Zijlstra
Quoted 14 lines · speck for Jiri Kosina
Quoted 12 lines · speck for Josh Poimboeuf

From: Josh Poimboeuf <[email protected]>
Subject: [PATCH] cpu/hotplug: detect SMT disabled by BIOS

If SMT is disabled in BIOS, the CPU code doesn't properly detect it. The /sys/devices/system/cpu/smt/control file shows 'on', and the 'l1tf' vulnerabilities file shows SMT as vulnerable.

Fix it by forcing 'cpu_smt_control' to CPU_SMT_NOT_SUPPORTED in such a case. Unfortunately the detection can only be done after bringing all the CPUs online, so we have to overwrite any previous writes to the variable.

Quoted 5 lines
Quoted 3 lines
Fixes f048c399e0f7 ("x86/topology: Provide topology_smt_supported()")
Quoted 8 lines

Thanks guys!

I've pushed this out to speck/{master,linux-4.1[764].y}. In specific, I've not touched the 4.9 branch since that is dwmw2's baby and I didn't know if I was supposed to touch that.

If there's anything funny, that's because I'm basically useless at this git thing, but let me know and I'll try and fix it ;-)

As Josh noted, I messed up and created new branches instead of updating the old. I've since deleted these new branches, but every time I try and push into the existing branches the git thing complains about non-fast-forward crud and I've given up trying to figure this thing out for the day.

I'll try again tomorrow..

git and me just ain't gonna be friends it seems.

maintainer
#10 lore raw
Quoted 3 lines · Peter Zijlstra

I'll try again tomorrow..

git and me just ain't gonna be friends it seems.

Jikos enlightened me and figured out the push command I should've used.

The result is that speck/master is now one commit ahead of the rest. I will update the stable branches in the morning for fear of messing things up (again) this late.

maintainer
#11 lore raw
Quoted 10 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

I'll try again tomorrow..

git and me just ain't gonna be friends it seems.

Jikos enlightened me and figured out the push command I should've used.

The result is that speck/master is now one commit ahead of the rest. I will update the stable branches in the morning for fear of messing things up (again) this late.

With exception of the linux-4.9 branch (still waiting for dwmw2 to get back -- apparently he's on holidays too), they're now all in-sync.

maintainer
#12 lore raw
Quoted 6 lines · speck for Peter Zijlstra
Quoted 5 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

I'll try again tomorrow..

git and me just ain't gonna be friends it seems.

Quoted 8 lines
Quoted 5 lines

Jikos enlightened me and figured out the push command I should've used.

The result is that speck/master is now one commit ahead of the rest. I will update the stable branches in the morning for fear of messing things up (again) this late.

With exception of the linux-4.9 branch (still waiting for dwmw2 to get back -- apparently he's on holidays too), they're now all in-sync.

At David's reqest I've also updated the 4.9 branch, so they should all be in-sync now.

#13 lore raw
Quoted 13 lines · speck for Peter Zijlstra
Quoted 12 lines · speck for Peter Zijlstra
Quoted 10 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

I'll try again tomorrow..

git and me just ain't gonna be friends it seems.

Jikos enlightened me and figured out the push command I should've used.

The result is that speck/master is now one commit ahead of the rest. I will update the stable branches in the morning for fear of messing things up (again) this late.

Quoted 5 lines
Quoted 2 lines

With exception of the linux-4.9 branch (still waiting for dwmw2 to get back -- apparently he's on holidays too), they're now all in-sync.

At David's reqest I've also updated the 4.9 branch, so they should all be in-sync now.

I just checked and they all look good to me, thanks for doing the backports.

greg k-h

#14 lore raw
In reply to Josh Poimboeuf
Quoted 11 lines · speck for Josh Poimboeuf

From: Josh Poimboeuf <[email protected]>
Subject: [PATCH] cpu/hotplug: detect SMT disabled by BIOS

If SMT is disabled in BIOS, the CPU code doesn't properly detect it. The /sys/devices/system/cpu/smt/control file shows 'on', and the 'l1tf' vulnerabilities file shows SMT as vulnerable.

Fix it by forcing 'cpu_smt_control' to CPU_SMT_NOT_SUPPORTED in such a case. Unfortunately the detection can only be done after bringing all the CPUs online, so we have to overwrite any previous writes to the variable.

Bah, this whole CPU enumeration on x86 sucks.

Quoted 3 lines
Fixes f048c399e0f7 ("x86/topology: Provide topology_smt_supported()")

Belated Acked-by-me.