Skip to content

Commit 26acfb6

Browse files
konradwilkKAGA-KOKO
authored andcommitted
x86/KVM: Warn user if KVM is loaded SMT and L1TF CPU bug being present
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-3620 and as such they are the ones that should set nosmt to one. Setting 'nosmt' 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 05736e4 ("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. Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent 0cc3cd2 commit 26acfb6

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,6 +1946,12 @@
19461946
[KVM,ARM] Allow use of GICv4 for direct injection of
19471947
LPIs.
19481948

1949+
kvm-intel.nosmt=[KVM,Intel] If the L1TF CPU bug is present (CVE-2018-3620)
1950+
and the system has SMT (aka Hyper-Threading) enabled then
1951+
don't allow guests to be created.
1952+
1953+
Default is 0 (allow guests to be created).
1954+
19491955
kvm-intel.ept= [KVM,Intel] Disable extended page tables
19501956
(virtualized MMU) support on capable Intel chips.
19511957
Default is 1 (enabled)

arch/x86/kvm/vmx.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ static const struct x86_cpu_id vmx_cpu_id[] = {
7171
};
7272
MODULE_DEVICE_TABLE(x86cpu, vmx_cpu_id);
7373

74+
static bool __read_mostly nosmt;
75+
module_param(nosmt, bool, S_IRUGO);
76+
7477
static bool __read_mostly enable_vpid = 1;
7578
module_param_named(vpid, enable_vpid, bool, 0444);
7679

@@ -10370,10 +10373,20 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
1037010373
return ERR_PTR(err);
1037110374
}
1037210375

10376+
#define L1TF_MSG "SMT enabled with L1TF CPU bug present. Refer to CVE-2018-3620 for details.\n"
10377+
1037310378
static int vmx_vm_init(struct kvm *kvm)
1037410379
{
1037510380
if (!ple_gap)
1037610381
kvm->arch.pause_in_guest = true;
10382+
10383+
if (boot_cpu_has(X86_BUG_L1TF) && cpu_smt_control == CPU_SMT_ENABLED) {
10384+
if (nosmt) {
10385+
pr_err(L1TF_MSG);
10386+
return -EOPNOTSUPP;
10387+
}
10388+
pr_warn(L1TF_MSG);
10389+
}
1037710390
return 0;
1037810391
}
1037910392

kernel/cpu.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ EXPORT_SYMBOL_GPL(cpu_hotplug_enable);
345345

346346
#ifdef CONFIG_HOTPLUG_SMT
347347
enum cpuhp_smt_control cpu_smt_control __read_mostly = CPU_SMT_ENABLED;
348+
EXPORT_SYMBOL_GPL(cpu_smt_control);
348349

349350
static int __init smt_cmdline_disable(char *str)
350351
{

0 commit comments

Comments
 (0)