From: Gleb Natapov Subject: Re: [PATCH] call vmx_load_host_state() only if msr is cached Date: Mon, 31 Aug 2009 17:09:26 +0300 Message-ID: <20090831140926.GW30093@redhat.com> References: <20090827120730.GN30093@redhat.com> <20090831140427.GA5234@amt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: avi@redhat.com, kvm@vger.kernel.org To: Marcelo Tosatti Return-path: Received: from mx1.redhat.com ([209.132.183.28]:42515 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751302AbZHaOJZ (ORCPT ); Mon, 31 Aug 2009 10:09:25 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n7VE9RGE022275 for ; Mon, 31 Aug 2009 10:09:28 -0400 Content-Disposition: inline In-Reply-To: <20090831140427.GA5234@amt.cnet> Sender: kvm-owner@vger.kernel.org List-ID: On Mon, Aug 31, 2009 at 11:04:27AM -0300, Marcelo Tosatti wrote: > On Thu, Aug 27, 2009 at 03:07:30PM +0300, Gleb Natapov wrote: > > No need to call it before each kvm_(set|get)_msr_common() > > > > Signed-off-by: Gleb Natapov > > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > > index 6b57eed..7494ef1 100644 > > --- a/arch/x86/kvm/vmx.c > > +++ b/arch/x86/kvm/vmx.c > > @@ -1005,9 +1005,9 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata) > > data = vmcs_readl(GUEST_SYSENTER_ESP); > > break; > > default: > > - vmx_load_host_state(to_vmx(vcpu)); > > msr = find_msr_entry(to_vmx(vcpu), msr_index); > > if (msr) { > > + vmx_load_host_state(to_vmx(vcpu)); > > data = msr->data; > > break; > > } > > @@ -1064,9 +1064,9 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data) > > } > > /* Otherwise falls through to kvm_set_msr_common */ > > default: > > - vmx_load_host_state(vmx); > > msr = find_msr_entry(vmx, msr_index); > > if (msr) { > > + vmx_load_host_state(vmx); > > All is needed here save_msrs(vmx->guest_msrs), right? > Yes. Otherwise we return wrong value for cached MSR. > Looks fine to me. Do you have any numbers or just notice it out of code > review? We saw this while profiling IPI ping-pong with x2apic (which uses MSR). This patch improves numbers by ~5us IIRC. -- Gleb.