Return-Path: Received: from mail.linutronix.de (146.0.238.70:993) by crypto-ml.lab.linutronix.de with IMAP4-SSL for ; 23 Jun 2018 14:05:09 -0000 Received: from userp2120.oracle.com ([156.151.31.85]) by Galois.linutronix.de with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fWj4J-00066n-98 for speck@linutronix.de; Sat, 23 Jun 2018 15:59:12 +0200 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w5NDtbVo179792 for ; Sat, 23 Jun 2018 13:59:04 GMT Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2jsfg0rh7e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sat, 23 Jun 2018 13:59:04 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w5NDx3eR015489 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sat, 23 Jun 2018 13:59:04 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w5NDx3R9030297 for ; Sat, 23 Jun 2018 13:59:03 GMT Message-Id: <20180623135446.010873334@localhost.localdomain> Date: Sat, 23 Jun 2018 09:54:22 -0400 From: konrad.wilk@oracle.com Subject: [MODERATED] [PATCH v4 8/8] [PATCH v4 8/8] Linux Patch #8 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit To: speck@linutronix.de List-ID: If the module parameter is to flush the L1D cache on every VMENTER then we can optimize by using the MSR save list to have the CPU poke the MSR with the proper value right at VMENTER boundary. Signed-off-by: Konrad Rzeszutek Wilk --- v3: Actually engage the MSR save list Move it to function that frobs VMCS --- arch/x86/kvm/vmx.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 9b18848ccaba..020145adc546 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -2649,15 +2649,22 @@ static void vmx_save_host_state(struct kvm_vcpu *vcpu) vmx->guest_msrs[i].mask); } -static void vmx_prepare_guest_switch(struct kvm_vcpu *vcpu) +static bool vmx_l1d_cache_flush_req(struct kvm_vcpu *vcpu) { - vmx_save_host_state(vcpu); - if (!enable_ept || static_cpu_has(X86_FEATURE_HYPERVISOR) || !static_cpu_has(X86_BUG_L1TF)) { vcpu->arch.flush_cache_req = false; - return; + return false; } + return true; +} + +static void vmx_prepare_guest_switch(struct kvm_vcpu *vcpu) +{ + vmx_save_host_state(vcpu); + + if (!vmx_l1d_cache_flush_req(vcpu)) + return; switch (vmentry_l1d_flush) { case 0: @@ -6352,6 +6359,15 @@ static void vmx_vcpu_setup(struct vcpu_vmx *vmx) vmcs_write64(PML_ADDRESS, page_to_phys(vmx->pml_pg)); vmcs_write16(GUEST_PML_INDEX, PML_ENTITY_NUM - 1); } + + /* + * If we enforce flushing the L1D cache on every VMENTER lets use the + * MSR save list. + */ + if (vmx_l1d_cache_flush_req(&vmx->vcpu)) + if (vmentry_l1d_flush == 2) + add_atomic_switch_msr(vmx, MSR_IA32_FLUSH_CMD, + L1D_FLUSH, 0, true); } static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) @@ -10079,7 +10095,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu) evmcs_rsp = static_branch_unlikely(&enable_evmcs) ? (unsigned long)¤t_evmcs->host_rsp : 0; - if (vcpu->arch.flush_cache_req) + if (vcpu->arch.flush_cache_req && vmentry_l1d_flush != 1) kvm_l1d_flush(); asm( -- 2.14.3