Skip to contentSkip to conversation

Linux Patch #1

PATCH In review [email protected] 2 participants 2 messages Jun 23, 2018 – Jun 27, 2018

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

PATCH v4 1/8 Linux Patch #1

If the L1TF CPU bug is present we allow the KVM module to be loaded as the major of users that use Linux and KVM have trusted guests and do not want a broken setup.

Cloud vendors are the ones that are uncomfortable with CVE 2018-3615 and as such they are the ones that should set disallow_smt to one.

Setting disallow_smt to means that the system administrator also needs to disable SMT (Hyper-threading) in the BIOS, or via the 'nosmt' command line parameter, or via the /sys/devices/system/cpu/smt/control (see commit 05736e4ac13c cpu/hotplug: Provide knobs to control SMT).

Other mitigations are to use task affinity, cpu sets, interrupt binding, etc - anything to make sure that _only_ the same guests vCPUs are running on sibling threads.

---
v3:-Move it to vmx_vcpu_init (could also do it in kvm_vcpu_init but it seemed
more prudent to do it in VMX handler.
-Made it WARN if disallow_smt=0
-Made it ERR if disallow_smt=1
-Fixed the CVE number

---
 Documentation/admin-guide/kernel-parameters.txt |  6 ++++++
 arch/x86/kvm/vmx.c                              | 13 +++++++++++++
 kernel/cpu.c                                    |  1 +
 3 files changed, 20 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +6 -0
index 8e29c4b6756f..d59b34d4e62a 100644
@@ -1946,6 +1946,12 @@
 			[KVM,ARM] Allow use of GICv4 for direct injection of
 			LPIs.
 
+	kvm-intel.disallow_smt=[KVM] If the L1TF CPU bug is present and the
+			system has SMT (aka Hyper-Threading) enabled then
+			don't allow guests to be created.
+
+			Default is 0 (allow guests to be created).
+
 	kvm-intel.ept=	[KVM,Intel] Disable extended page tables
 			(virtualized MMU) support on capable Intel chips.
 			Default is 1 (enabled)
arch/x86/kvm/vmx.c +13 -0
index 559a12b6184d..f08e33fc28ac 100644
@@ -71,6 +71,9 @@ static const struct x86_cpu_id vmx_cpu_id[] = {
 };
 MODULE_DEVICE_TABLE(x86cpu, vmx_cpu_id);
 
+static bool __read_mostly disallow_smt = false;
+module_param(disallow_smt, bool, S_IRUGO);
+
 static bool __read_mostly enable_vpid = 1;
 module_param_named(vpid, enable_vpid, bool, 0444);
 
@@ -10370,10 +10373,20 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
 	return ERR_PTR(err);
 }
 
+#define L1TF_MSG "SMT enabled with L1TF CPU bug present. Refer to CVE-2018-3620 for details.\n"
+
 static int vmx_vm_init(struct kvm *kvm)
 {
 	if (!ple_gap)
 		kvm->arch.pause_in_guest = true;
+
+	if (boot_cpu_has(X86_BUG_L1TF) && (cpu_smt_control == CPU_SMT_ENABLED)) {
+		if (disallow_smt) {
+			pr_err(L1TF_MSG);
+			return -EOPNOTSUPP;
+		}
+		pr_warn(L1TF_MSG);
+	}
 	return 0;
 }
 
kernel/cpu.c +1 -0
index d29fdd7e57bb..2d0129f41a2b 100644
@@ -935,6 +935,7 @@ EXPORT_SYMBOL(cpu_down);
 
 #ifdef CONFIG_HOTPLUG_SMT
 enum cpuhp_smt_control cpu_smt_control __read_mostly = CPU_SMT_ENABLED;
+EXPORT_SYMBOL_GPL(cpu_smt_control);
 
 static int __init smt_cmdline_disable(char *str)
 {
Signature · 1 line
2.14.3
#1 lore raw
Quoted 1 line · speck for konrad.wilk_at_oracle.com

x86/KVM: Warn user if KVM is loaded SMT and L1TF CPU bug being present.

That commit name needs massaging.

Quoted 34 lines

If the L1TF CPU bug is present we allow the KVM module to be loaded as the major of users that use Linux and KVM have trusted guests and do not want a broken setup.

Cloud vendors are the ones that are uncomfortable with CVE 2018-3615 and as such they are the ones that should set disallow_smt to one.

Setting disallow_smt to means that the system administrator also needs to disable SMT (Hyper-threading) in the BIOS, or via the 'nosmt' command line parameter, or via the /sys/devices/system/cpu/smt/control (see commit 05736e4ac13c cpu/hotplug: Provide knobs to control SMT).

Other mitigations are to use task affinity, cpu sets, interrupt binding, etc - anything to make sure that _only_ the same guests vCPUs are running on sibling threads.

---
v3:-Move it to vmx_vcpu_init (could also do it in kvm_vcpu_init but it seemed
more prudent to do it in VMX handler.
-Made it WARN if disallow_smt=0
-Made it ERR if disallow_smt=1
-Fixed the CVE number

---
 Documentation/admin-guide/kernel-parameters.txt |  6 ++++++
 arch/x86/kvm/vmx.c                              | 13 +++++++++++++
 kernel/cpu.c                                    |  1 +
 3 files changed, 20 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +0 -0
index 8e29c4b6756f..d59b34d4e62a 100644

Documentation/admin-guide/kernel-parameters.txt line 1949

Quoted 4 lines
Documentation/admin-guide/kernel-parameters.txt +1 -0
@@ -1946,6 +1946,12 @@
 			[KVM,ARM] Allow use of GICv4 for direct injection of
 			LPIs.
 
+	kvm-intel.disallow_smt=[KVM] If the L1TF CPU bug is present and the

Why isn't this matching the "nosmt" baremetal parameter so that there's no confusion for the user?

Quoted 13 lines
Documentation/admin-guide/kernel-parameters.txt +5 -0
+			system has SMT (aka Hyper-Threading) enabled then
+			don't allow guests to be created.
+
+			Default is 0 (allow guests to be created).
+
 	kvm-intel.ept=	[KVM,Intel] Disable extended page tables
 			(virtualized MMU) support on capable Intel chips.
 			Default is 1 (enabled)
arch/x86/kvm/vmx.c +0 -0
index 559a12b6184d..f08e33fc28ac 100644

arch/x86/kvm/vmx.c static const struct x86_cpu_id vmx_cpu_id[] = { · line 75

Quoted 5 lines
arch/x86/kvm/vmx.c +2 -0
@@ -71,6 +71,9 @@ static const struct x86_cpu_id vmx_cpu_id[] = {
 };
 MODULE_DEVICE_TABLE(x86cpu, vmx_cpu_id);
 
+static bool __read_mostly disallow_smt = false;
+module_param(disallow_smt, bool, S_IRUGO);

ERROR: do not initialise statics to false
#69: FILE: arch/x86/kvm/vmx.c:74:
+static bool __read_mostly disallow_smt = false;

Quoted 3 lines
arch/x86/kvm/vmx.c +0 -0
 static bool __read_mostly enable_vpid = 1;
 module_param_named(vpid, enable_vpid, bool, 0444);
 
Signature · 5 lines
Regards/Gruss,
    Boris.

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