Received: by 2002:a4a:311b:0:0:0:0:0 with SMTP id k27-v6csp4800851ooa; Tue, 14 Aug 2018 10:44:05 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxI6EdoTcqvxhEtuUZF3rwCAG/hWsaA8ArjG+Plj7iVph7VCAb8jxhCQOgTXD9mDGbGHrmk X-Received: by 2002:a62:9f85:: with SMTP id v5-v6mr24404902pfk.27.1534268645502; Tue, 14 Aug 2018 10:44:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534268645; cv=none; d=google.com; s=arc-20160816; b=UXAw4pml4JVEqIvWoAyHJKAEq4XiH8wCVUII5N5isBmPqNrNVVf2wgbmQXwWfAtuWY JfeW/g0x3a/O0k+96U4gDErpMVKBnX8EKzmPDEAQ36VCAUxzNc1kvU4PyNBkWmf9fc1E Q2mBuTDTdQyqPlOPBNn/fbtvYqgnyxKaWv33gmzokQI3iSaGF9a1AIOC5lp/6A4ETgWH R7UK2iZglGNGmhxXzwYRbEQtJ37NZRZ1NZG3n2/6+awIGwC0LrxyidJStsGXnQG4/WmU RvkqiLnsg7G17Ej+NKpD01RgEAwzMzGzV5GLln1MmL5NSsIFkNq+GiHa31iG3thxRuMs EYxA== 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=jkW+6zV31lMl2IRQ5LFjcoDfpUjAfIr62PGIYjCTG0A=; b=N8dlx6WenqM/gUsz2hL648WVtOirqi1pR4UCiewYADKvQnJg3492h0jVjZreGxzyZo SFKLpXO66xgmARJVnJtt4xYr1dqm7rbHnC5hNhfjX1Kix8u1xkFAWqvWtgFQddpRPOgv Ur/rv5vLhUHm+zOR3RLW3fwlxg8B9yT+4Q0pzccM3MzUDObwHahgnBQ15AlZR8aB2CnD x8Y+UG0aP0rmHEnLqauJdrqtpXfjkUodE7JoXdx8WqXFADKwllVREYZXaFtAhL0mFBfr DEdQa3WxAgG9VtvKuYkQzE280mKRc/kLDLKN5EC9Ufgvw1nrDuD9WWBYq11K9Zr42g53 GtcQ== 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 a8-v6si21074733pgl.568.2018.08.14.10.43.50; Tue, 14 Aug 2018 10:44:05 -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 S2390483AbeHNUbJ (ORCPT + 99 others); Tue, 14 Aug 2018 16:31:09 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:59732 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728642AbeHNUbI (ORCPT ); Tue, 14 Aug 2018 16:31:08 -0400 Received: from localhost (unknown [194.244.16.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 1B0F0AF3; Tue, 14 Aug 2018 17:42:56 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , Jiri Kosina , Josh Poimboeuf , David Woodhouse Subject: [PATCH 4.9 070/107] x86/kvm: Drop L1TF MSR list approach Date: Tue, 14 Aug 2018 19:17:33 +0200 Message-Id: <20180814171525.124970724@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: Thomas Gleixner commit 2f055947ae5e2741fb2dc5bba1033c417ccf4faa upstream The VMX module parameter to control the L1D flush should become writeable. The MSR list is set up at VM init per guest VCPU, but the run time switching is based on a static key which is global. Toggling the MSR list at run time might be feasible, but for now drop this optimization and use the regular MSR write to make run-time switching possible. The default mitigation is the conditional flush anyway, so for extra paranoid setups this will add some small overhead, but the extra code executed is in the noise compared to the flush itself. Aside of that the EPT disabled case is not handled correctly at the moment and the MSR list magic is in the way for fixing that as well. If it's really providing a significant advantage, then this needs to be revisited after the code is correct and the control is writable. Signed-off-by: Thomas Gleixner Tested-by: Jiri Kosina Reviewed-by: Greg Kroah-Hartman Reviewed-by: Josh Poimboeuf Link: https://lkml.kernel.org/r/20180713142322.516940445@linutronix.de Signed-off-by: David Woodhouse Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/vmx.c | 43 +++++++------------------------------------ 1 file changed, 7 insertions(+), 36 deletions(-) --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -5263,16 +5263,6 @@ static void ept_set_mmio_spte_mask(void) kvm_mmu_set_mmio_spte_mask((0x3ull << 62) | 0x6ull); } -static bool vmx_l1d_use_msr_save_list(void) -{ - if (!enable_ept || !boot_cpu_has_bug(X86_BUG_L1TF) || - static_cpu_has(X86_FEATURE_HYPERVISOR) || - !static_cpu_has(X86_FEATURE_FLUSH_L1D)) - return false; - - return vmentry_l1d_flush == VMENTER_L1D_FLUSH_ALWAYS; -} - #define VMX_XSS_EXIT_BITMAP 0 /* * Sets up the vmcs for emulated real mode. @@ -5622,12 +5612,6 @@ static void vmx_set_nmi_mask(struct kvm_ vmcs_clear_bits(GUEST_INTERRUPTIBILITY_INFO, GUEST_INTR_STATE_NMI); } - /* - * If flushing the L1D cache on every VMENTER is enforced and the - * MSR is available, use the MSR save list. - */ - if (vmx_l1d_use_msr_save_list()) - add_atomic_switch_msr(vmx, MSR_IA32_FLUSH_CMD, L1D_FLUSH, 0, true); } static int vmx_nmi_allowed(struct kvm_vcpu *vcpu) @@ -8591,26 +8575,14 @@ static void vmx_l1d_flush(struct kvm_vcp bool always; /* - * This code is only executed when: - * - the flush mode is 'cond' - * - the flush mode is 'always' and the flush MSR is not - * available - * - * If the CPU has the flush MSR then clear the flush bit because - * 'always' mode is handled via the MSR save list. - * - * If the MSR is not avaibable then act depending on the mitigation - * mode: If 'flush always', keep the flush bit set, otherwise clear - * it. + * This code is only executed when the the flush mode is 'cond' or + * 'always' * - * The flush bit gets set again either from vcpu_run() or from one - * of the unsafe VMEXIT handlers. + * If 'flush always', keep the flush bit set, otherwise clear + * it. The flush bit gets set again either from vcpu_run() or from + * one of the unsafe VMEXIT handlers. */ - if (static_cpu_has(X86_FEATURE_FLUSH_L1D)) - always = false; - else - always = vmentry_l1d_flush == VMENTER_L1D_FLUSH_ALWAYS; - + always = vmentry_l1d_flush == VMENTER_L1D_FLUSH_ALWAYS; vcpu->arch.l1tf_flush_l1d = always; vcpu->stat.l1d_flush++; @@ -11689,8 +11661,7 @@ static int __init vmx_setup_l1d_flush(vo l1tf_vmx_mitigation = vmentry_l1d_flush; - if (vmentry_l1d_flush == VMENTER_L1D_FLUSH_NEVER || - vmx_l1d_use_msr_save_list()) + if (vmentry_l1d_flush == VMENTER_L1D_FLUSH_NEVER) return 0; if (!boot_cpu_has(X86_FEATURE_FLUSH_L1D)) {