Return-Path: Received: from mail.linutronix.de (146.0.238.70:993) by crypto-ml.lab.linutronix.de with IMAP4-SSL for ; 25 Jun 2018 14:32:42 -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 1fXSXp-0001bj-8B for speck@linutronix.de; Mon, 25 Jun 2018 16:32:41 +0200 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 191814000B8A for ; Mon, 25 Jun 2018 14:32:35 +0000 (UTC) Received: from [10.36.112.27] (ovpn-112-27.ams2.redhat.com [10.36.112.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 54D3123141 for ; Mon, 25 Jun 2018 14:32:34 +0000 (UTC) Subject: [MODERATED] Re: [PATCH v4 8/8] [PATCH v4 8/8] Linux Patch #8 References: <20180623135446.010873334@localhost.localdomain> From: Paolo Bonzini Message-ID: <48758ed2-05c0-e52b-6651-316b2c5be9cc@redhat.com> Date: Mon, 25 Jun 2018 16:32:32 +0200 MIME-Version: 1.0 In-Reply-To: <20180623135446.010873334@localhost.localdomain> Content-Type: multipart/mixed; boundary="NJTKTZgXFwMM9giR8j6psIisLNv1G739l"; protected-headers="v1" To: speck@linutronix.de List-ID: This is an OpenPGP/MIME encrypted message (RFC 4880 and 3156) --NJTKTZgXFwMM9giR8j6psIisLNv1G739l Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 23/06/2018 15:54, speck for konrad.wilk_at_oracle.com wrote: > x86/KVM/VMX: Use MSR save list for IA32_FLUSH_CMD if required. >=20 > 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. >=20 > 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(-) >=20 > 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); > } > =20 > -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 =3D false; This assignment is strange, the function would be pure if it was not for = it. Let's remove it, since vmx_vcpu_setup doesn't need it, and rename the function to vmx_has_bug_l1tf. Thanks, Paolo > - 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; > =20 > switch (vmentry_l1d_flush) { > case 0:> @@ -6352,6 +6359,15 @@ static void vmx_vcpu_setup(struct vcp= u_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 =3D=3D 2) > + add_atomic_switch_msr(vmx, MSR_IA32_FLUSH_CMD, > + L1D_FLUSH, 0, true); > } > =20 > static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) > @@ -10079,7 +10095,7 @@ static void __noclone vmx_vcpu_run(struct kvm_v= cpu *vcpu) > evmcs_rsp =3D static_branch_unlikely(&enable_evmcs) ? > (unsigned long)¤t_evmcs->host_rsp : 0; > =20 > - if (vcpu->arch.flush_cache_req) > + if (vcpu->arch.flush_cache_req && vmentry_l1d_flush !=3D 1) > kvm_l1d_flush(); > =20 --NJTKTZgXFwMM9giR8j6psIisLNv1G739l--