Return-Path: Received: from mail.linutronix.de (146.0.238.70:993) by crypto-ml.lab.linutronix.de with IMAP4-SSL for ; 05 Jul 2018 23:57:03 -0000 Received: from mx3-rdu2.redhat.com ([66.187.233.73] helo=mx1.redhat.com) by Galois.linutronix.de with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fbE7R-0006Yw-I6 for speck@linutronix.de; Fri, 06 Jul 2018 01:57:02 +0200 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A371077884 for ; Thu, 5 Jul 2018 23:56:55 +0000 (UTC) Received: from treble (ovpn-123-143.rdu2.redhat.com [10.10.123.143]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D47002166BA9 for ; Thu, 5 Jul 2018 23:56:54 +0000 (UTC) Date: Thu, 5 Jul 2018 18:56:53 -0500 From: Josh Poimboeuf Subject: [MODERATED] Re: [patch v5 11/10] Linux+KVM magic # 1 Message-ID: <20180705235653.b4jkfjhcc45a7xrr@treble> References: <20180702154426.910579106@linutronix.de> MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit To: speck@linutronix.de List-ID: On Tue, Jul 03, 2018 at 12:14:30AM +0200, speck for Jiri Kosina wrote: > From: Jiri Kosina > Subject: [PATCH v5] x86/bugs: introduce boot-time control of L1TF mitigations > > Introduce 'l1tf=' boot option to allow for boot-time switching of > mitigation that is used on CPUs affected by L1TF. AFAICT, this patch breaks the use case Andi was talking about, where some users will want to do the L1 flushing with SMT enabled, and instead play cpuset tricks. I think that could be solved by just passing false to cpu_smt_disable() instead of true. That way the user can re-enable SMT if they need to. Then the vulnerabilities file output should probably display something different if SMT is currently enabled. Also I think "l1tf=off" is misleading, since it's basically the same as l1tf=novirt, except with no warnings. Maybe it should be "l1tf=novirt,nowarn" [ Well, there *is* one other difference between "novirt" and "off": "off" overrides 'kvm-intel.nosmt'. But a) I disagree with that approach; I think the kvm option should rule; and b) I think 'kvm-intel.nosmt' should just be removed anyway. There's nothing kvm-specific about it. If it's useful, let's integrate it into this interface instead. ] So what do you think about the following options: l1tf=on PTEINV + flushing + nosmt l1tf=novirt PTEINV + VM warning [default] l1tf=novirt,nowarn PTEINV And if somebody needed the 'force' option, we could also have: l1tf=force PTEINV + flushing + nosmt=force > The possible values are > > full Provide all available mitigations for L1TF > vulnerability (disable HT, perform PTE bit > inversion, allow hypervisors to know that > they should provide all mitigations) A period would be good. > novirt Provide all available mitigations needed > for running on bare metal (PTE bit inversion), > while not applying mitigations needed for > VM isolation. Hypervisors will be issuing > warning when first VM is being started in > pontentially insecure configuraion "Hypervisors will issue a warning when the first VM is started in a potentially insecure configuration." > off Claim "I don't care at all about this issue". > The PTE bit inversion (bare metal mitigation) will > still be performed, but hypervisors will not be > issuing warning when VM is being started in > potentially insecure configuration "...but hypervisors will not issue a warning when a VM is started in a potentially insecure configuration." > > Let KVM adhere to this semantics, which means: s/this/these/ > > - 'l1tf=full': start performing L1D flushes > - 'l1tf=novirt': warn (or, depending on 'kvm.nosmt', refuse completely) > on VM start > - 'l1tf=off': no extra action is taken > > Also, introduce CONFIG_ option to allow vendors to chose the default "introduce *a* CONFIG_ option" .... "choose" And as we discussed before on IRC, adding a CONFIG option is actively harmful if you don't have a concrete plan to use it. Let's please wait until there's an actual user before adding it. > mitigation to be used on affected CPUs in case no l1tf= cmdline option is > present. > > Signed-off-by: Jiri Kosina > --- > > As discussed previously, this goes on top of Konard's v5 KVM patchset, and > implements the l1tf= bootparam handling as described in the changelog, > including the KVM changes. > > Documentation/admin-guide/kernel-parameters.txt | 18 ++++++++ > arch/x86/Kconfig | 18 ++++++++ > arch/x86/include/asm/processor.h | 7 ++++ > arch/x86/kernel/cpu/bugs.c | 56 +++++++++++++++++++++++-- > arch/x86/kvm/vmx.c | 46 ++++++++++++++++---- > include/linux/cpu.h | 2 + > kernel/cpu.c | 9 +++- > 7 files changed, 144 insertions(+), 12 deletions(-) > > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt > index 4f790566ad91..2f1de18f4ac0 100644 > --- a/Documentation/admin-guide/kernel-parameters.txt > +++ b/Documentation/admin-guide/kernel-parameters.txt > @@ -1989,6 +1989,24 @@ > feature (tagged TLBs) on capable Intel chips. > Default is 1 (enabled) > > + l1tf= [X86] Control mitigation of L1TF vulnerability on the > + affected CPUs "Control mitigation of the L1TF vulnerability on affected CPUS." > + full Provide all available mitigations for L1TF > + vulnerability (disable HT, perform PTE bit > + inversion, allow hypervisors to know that > + they should provide all mitigations) > + novirt Provide all available mitigations needed > + for running on bare metal (PTE bit inversion), > + while not applying mitigations needed for > + VM isolation. Hypervisors will be issuing > + warning when first VM is being started in > + pontentially insecure configuraion > + off Claim "I don't care at all about this issue". > + The PTE bit inversion (bare metal mitigation) will > + still be performed, but hypervisors will not be > + issuing warning when VM is being started in > + potentially insecure configuration > + Same grammatical comments as above. > l2cr= [PPC] > > l3cr= [PPC] > diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig > index 7a34fdf8daf0..7aa47721c664 100644 > --- a/arch/x86/Kconfig > +++ b/arch/x86/Kconfig > @@ -2390,6 +2390,24 @@ config MODIFY_LDT_SYSCALL > surface. Disabling it removes the modify_ldt(2) system call. > > Saying 'N' here may make sense for embedded or server kernels. > +choice > + prompt "Default L1TF mitigation" > + default L1TF_MITIGATION_NOVIRT > + help > + Define what the default behavior for selecting mitigation on "mitigations" > + CPUs affected by L1TF should be. The default can be overrided "overridden" > + on the kernel command-line. Refer to > + > + > +config L1TF_MITIGATION_FULL > + bool "Full available L1TF mitigation" > +config L1TF_MITIGATION_NOVIRT > + bool "Use L1TF bare metal mitigations only" > +config L1TF_MITIGATION_OFF > + bool "Ignore L1TF issue" > + > +endchoice > + > > source "kernel/livepatch/Kconfig" > > diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h > index 7e3ac5eedcd6..05471c590964 100644 > --- a/arch/x86/include/asm/processor.h > +++ b/arch/x86/include/asm/processor.h > @@ -982,4 +982,11 @@ bool xen_set_default_idle(void); > void stop_this_cpu(void *dummy); > void df_debug(struct pt_regs *regs, long error_code); > void microcode_check(void); > + > +enum l1tf_mitigations { > + L1TF_MITIGATION_OFF, > + L1TF_MITIGATION_NOVIRT, > + L1TF_MITIGATION_FULL > +}; > +enum l1tf_mitigations get_l1tf_mitigation(void); > #endif /* _ASM_X86_PROCESSOR_H */ > diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c > index 50500cea6eba..9aa8b94334d5 100644 > --- a/arch/x86/kernel/cpu/bugs.c > +++ b/arch/x86/kernel/cpu/bugs.c > @@ -657,6 +657,23 @@ void x86_spec_ctrl_setup_ap(void) > > #undef pr_fmt > #define pr_fmt(fmt) "L1TF: " fmt > +/* Default mitigation for L1TF-affected CPUs */ > +static int l1tf_mitigation = > +#ifdef CONFIG_L1TF_MITIGATION_FULL > + L1TF_MITIGATION_NOVIRT; > +#endif > +#ifdef CONFIG_L1TF_MITIGATION_NOVIRT > + L1TF_MITIGATION_NOVIRT; > +#endif > +#ifdef CONFIG_L1TF_MITIGATION_OFF > + L1TF_MITIGATION_OFF; > +#endif > +enum l1tf_mitigations get_l1tf_mitigation(void) > +{ > + return l1tf_mitigation; > +} > +EXPORT_SYMBOL(get_l1tf_mitigation); > + > static void __init l1tf_select_mitigation(void) > { > u64 half_pa; > @@ -664,6 +681,15 @@ static void __init l1tf_select_mitigation(void) > if (!boot_cpu_has_bug(X86_BUG_L1TF)) > return; > > + switch (get_l1tf_mitigation()) { > + case L1TF_MITIGATION_FULL: > + cpu_smt_disable(true); As described above, I think this should be changed to false. > + break; > + case L1TF_MITIGATION_OFF: > + case L1TF_MITIGATION_NOVIRT: > + break; > + } > + > #if CONFIG_PGTABLE_LEVELS == 2 > pr_warn("Kernel not compiled for PAE. No mitigation for L1TF\n"); > return; > @@ -682,10 +708,36 @@ static void __init l1tf_select_mitigation(void) > > setup_force_cpu_cap(X86_FEATURE_L1TF_PTEINV); > } > + > +static int __init l1tf_cmdline(char *str) > +{ > + if (!boot_cpu_has_bug(X86_BUG_L1TF)) > + return 0; > + > + if (!str) > + return 0; > + > + if (!strcmp(str, "full")) > + l1tf_mitigation = L1TF_MITIGATION_FULL; > + else if (!strcmp(str, "novirt")) > + l1tf_mitigation = L1TF_MITIGATION_NOVIRT; > + else if (!strcmp(str, "off")) > + l1tf_mitigation = L1TF_MITIGATION_OFF; > + > + return 0; > +} > +early_param("l1tf", l1tf_cmdline); > + > #undef pr_fmt > > #ifdef CONFIG_SYSFS > > +static const char *l1tf_states[] = { > + [L1TF_MITIGATION_FULL] = "Mitigation: Full", > + [L1TF_MITIGATION_NOVIRT] = "Mitigation: Page Table Inversion", > + [L1TF_MITIGATION_OFF] = "Mitigation: Page Table Inversion" > +}; > + > static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr, > char *buf, unsigned int bug) > { > @@ -712,9 +764,7 @@ static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr > return sprintf(buf, "%s\n", ssb_strings[ssb_mode]); > > case X86_BUG_L1TF: > - if (boot_cpu_has(X86_FEATURE_L1TF_PTEINV)) > - return sprintf(buf, "Mitigation: Page Table Inversion\n"); > - break; > + return sprintf(buf, "%s\n", l1tf_states[get_l1tf_mitigation()]); > > default: > break; > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index 0e53034061c1..a568efccd56f 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -10528,20 +10528,51 @@ 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" > +#define L1TF_MSG_NOVIRT "L1TF CPU bug present and virtualization mitigation disabled, data leak possible. Refer to CVE-2018-3620 for details.\n" > +#define L1TF_MSG_NOSMT "L1TF CPU bug present and SMT enabled, refusing to start VM. Refer to CVE-2018-3620 for details.\n" > + > +/* > + * Check whether we should be really strict about denying to start VM > + * with respect to current SMT status > + */ > +static bool strict_nosmt(void) > +{ > + return (cpu_smt_control == CPU_SMT_ENABLED && nosmt); > +} > > 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 (nosmt) { > - pr_err(L1TF_MSG); > - return -EOPNOTSUPP; > + if (boot_cpu_has(X86_BUG_L1TF)) { > + switch (get_l1tf_mitigation()) { > + case L1TF_MITIGATION_OFF: > + /* The 'I explicitly don't care' flag is set */ > + break; It seems odd to me that this overrides 'kvm-intel.nosmt'. I would expect the kvm option to win. But, as I said above, I'd propose we just get rid of the kvm option. > + case L1TF_MITIGATION_NOVIRT: > + /* > + * Warn if potentially insecure, deny to load > + * if insecure and 'nosmt' "refuse to load" > + */ > + if (strict_nosmt()) { > + pr_err(L1TF_MSG_NOSMT); > + return -EOPNOTSUPP; > + } else { > + pr_warn(L1TF_MSG_NOVIRT); > + } > + break; > + case L1TF_MITIGATION_FULL: > + /* Deny to load if insecure */ "refuse to load" > + if (strict_nosmt()) { > + pr_err(L1TF_MSG_NOSMT); > + return -EOPNOTSUPP; > + } I don't think this can ever happen. L1TF_MITIGATION_FULL means that SMT is permanently disabled: see l1tf_select_mitigation() where it calls cpu_smt_disable(true). (But I did propose to change that to false... then this code would make sense). -- Josh