Received: by 2002:a4a:311b:0:0:0:0:0 with SMTP id k27-v6csp4803190ooa; Tue, 14 Aug 2018 10:45:56 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxP/R+twferxPu4UGmEKP/f0MxdU34eKt+w0b8KlysMT5cN1hzaqUx6tPCuoFh8acPdnFje X-Received: by 2002:a65:57c9:: with SMTP id q9-v6mr22304869pgr.128.1534268756141; Tue, 14 Aug 2018 10:45:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534268756; cv=none; d=google.com; s=arc-20160816; b=cHPbOmsu5Tb8V/5ivzt/4i9KZLMfSE65e0vxddBdc1ZWJHRGhqc+k7E14j6m53Xaq1 4KXwDXBS5B/aEhUDb+dNL7vJ0xqd80hIi5GrT9Wo3GWSzc726T34eePyNkVpKo3lDGzG 115eQP4uEq2AO+wisYvKlL/ZsC7fh2oG6/0UKE4rdmRunHEpsZy3in1953V63Gd/pfE+ iRlxCl++k6CYM2bHIQ7io/+lBCOhdTDRQReG4KgM9A8USmmg/IL8Icjgrk5eGpsWZ4w4 Y0NdgEzORsze2MGXJnEgLNNeigeSxeCCAqK+WwBGfyKyVl/mnKGoMSQWjJrL1kHYcgj5 nK4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=yOlFtY2rIV7S5CWfIsaFBep1OM1jzpfSpDL9ROPAUU8=; b=NDQbd5cSDEjmR3gmJ1Po0vgnHzBoFj0ss+SOpYoIjkMcGMdWdg5GHtY7mZeWydaIEj x0EI/OUN9B8zbNp+aopjQBshmRI0O+aNTPfadjCo6SQatedHKP9NCk59Zp8CWKo8rynn e6u8vJlKy29ljmEzuBXAL1As7+GGiJt0+nVdSwA09nR3nAHOYxu8Fa0VsYiLizsafP+s ggfWCt8Jm2F7wCwotUWqQsdby6Eo6IoNjUvYOGDu8qdg5sQcR0Y5iaD5m0r8pph4ob6V Pgdi20ES9mY7ms5uJgZLUQHpOTmElvvHLHESwFVKiE8qkwkw1w5SSMassWQtUGbKVvs9 OSFQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m3-v6si21364755pgr.108.2018.08.14.10.45.41; Tue, 14 Aug 2018 10:45:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390790AbeHNUcy (ORCPT + 99 others); Tue, 14 Aug 2018 16:32:54 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:60080 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728642AbeHNUcx (ORCPT ); Tue, 14 Aug 2018 16:32:53 -0400 Received: from localhost (unknown [194.244.16.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C59ABAF3; Tue, 14 Aug 2018 17:44:41 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Konrad Rzeszutek Wilk , Thomas Gleixner , David Woodhouse Subject: [PATCH 4.9 058/107] x86/KVM/VMX: Add module argument for L1TF mitigation Date: Tue, 14 Aug 2018 19:17:21 +0200 Message-Id: <20180814171524.613353356@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180814171520.883143803@linuxfoundation.org> References: <20180814171520.883143803@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Konrad Rzeszutek Wilk commit a399477e52c17e148746d3ce9a483f681c2aa9a0 upstream Add a mitigation mode parameter "vmentry_l1d_flush" for CVE-2018-3620, aka L1 terminal fault. The valid arguments are: - "always" L1D cache flush on every VMENTER. - "cond" Conditional L1D cache flush, explained below - "never" Disable the L1D cache flush mitigation "cond" is trying to avoid L1D cache flushes on VMENTER if the code executed between VMEXIT and VMENTER is considered safe, i.e. is not bringing any interesting information into L1D which might exploited. [ tglx: Split out from a larger patch ] Signed-off-by: Konrad Rzeszutek Wilk Signed-off-by: Thomas Gleixner Signed-off-by: David Woodhouse Signed-off-by: Greg Kroah-Hartman --- Documentation/kernel-parameters.txt | 12 ++++++ arch/x86/kvm/vmx.c | 65 ++++++++++++++++++++++++++++++++++-- 2 files changed, 75 insertions(+), 2 deletions(-) --- a/Documentation/kernel-parameters.txt +++ b/Documentation/kernel-parameters.txt @@ -2016,6 +2016,18 @@ bytes respectively. Such letter suffixes (virtualized real and unpaged mode) on capable Intel chips. Default is 1 (enabled) + kvm-intel.vmentry_l1d_flush=[KVM,Intel] Mitigation for L1 Terminal Fault + CVE-2018-3620. + + Valid arguments: never, cond, always + + always: L1D cache flush on every VMENTER. + cond: Flush L1D on VMENTER only when the code between + VMEXIT and VMENTER can leak host memory. + never: Disables the mitigation + + Default is cond (do L1 cache flush in specific instances) + kvm-intel.vpid= [KVM,Intel] Disable Virtual Processor Identification feature (tagged TLBs) on capable Intel chips. Default is 1 (enabled) --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -192,6 +192,54 @@ module_param(ple_window_max, int, S_IRUG extern const ulong vmx_return; +static DEFINE_STATIC_KEY_FALSE(vmx_l1d_should_flush); + +/* These MUST be in sync with vmentry_l1d_param order. */ +enum vmx_l1d_flush_state { + VMENTER_L1D_FLUSH_NEVER, + VMENTER_L1D_FLUSH_COND, + VMENTER_L1D_FLUSH_ALWAYS, +}; + +static enum vmx_l1d_flush_state __read_mostly vmentry_l1d_flush = VMENTER_L1D_FLUSH_COND; + +static const struct { + const char *option; + enum vmx_l1d_flush_state cmd; +} vmentry_l1d_param[] = { + {"never", VMENTER_L1D_FLUSH_NEVER}, + {"cond", VMENTER_L1D_FLUSH_COND}, + {"always", VMENTER_L1D_FLUSH_ALWAYS}, +}; + +static int vmentry_l1d_flush_set(const char *s, const struct kernel_param *kp) +{ + unsigned int i; + + if (!s) + return -EINVAL; + + for (i = 0; i < ARRAY_SIZE(vmentry_l1d_param); i++) { + if (!strcmp(s, vmentry_l1d_param[i].option)) { + vmentry_l1d_flush = vmentry_l1d_param[i].cmd; + return 0; + } + } + + return -EINVAL; +} + +static int vmentry_l1d_flush_get(char *s, const struct kernel_param *kp) +{ + return sprintf(s, "%s\n", vmentry_l1d_param[vmentry_l1d_flush].option); +} + +static const struct kernel_param_ops vmentry_l1d_flush_ops = { + .set = vmentry_l1d_flush_set, + .get = vmentry_l1d_flush_get, +}; +module_param_cb(vmentry_l1d_flush, &vmentry_l1d_flush_ops, &vmentry_l1d_flush, S_IRUGO); + #define NR_AUTOLOAD_MSRS 8 struct vmcs { @@ -11505,10 +11553,23 @@ static struct kvm_x86_ops vmx_x86_ops __ .setup_mce = vmx_setup_mce, }; +static void __init vmx_setup_l1d_flush(void) +{ + if (vmentry_l1d_flush == VMENTER_L1D_FLUSH_NEVER || + !boot_cpu_has_bug(X86_BUG_L1TF)) + return; + + static_branch_enable(&vmx_l1d_should_flush); +} + static int __init vmx_init(void) { - int r = kvm_init(&vmx_x86_ops, sizeof(struct vcpu_vmx), - __alignof__(struct vcpu_vmx), THIS_MODULE); + int r; + + vmx_setup_l1d_flush(); + + r = kvm_init(&vmx_x86_ops, sizeof(struct vcpu_vmx), + __alignof__(struct vcpu_vmx), THIS_MODULE); if (r) return r;