All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] call vmx_load_host_state() only if msr is cached
@ 2009-08-27 12:07 Gleb Natapov
  2009-08-31 14:04 ` Marcelo Tosatti
  0 siblings, 1 reply; 3+ messages in thread
From: Gleb Natapov @ 2009-08-27 12:07 UTC (permalink / raw)
  To: avi; +Cc: kvm

No need to call it before each kvm_(set|get)_msr_common()

Signed-off-by: Gleb Natapov <gleb@redhat.com>
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);
 			msr->data = data;
 			break;
 		}
--
			Gleb.

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] call vmx_load_host_state() only if msr is cached
  2009-08-27 12:07 [PATCH] call vmx_load_host_state() only if msr is cached Gleb Natapov
@ 2009-08-31 14:04 ` Marcelo Tosatti
  2009-08-31 14:09   ` Gleb Natapov
  0 siblings, 1 reply; 3+ messages in thread
From: Marcelo Tosatti @ 2009-08-31 14:04 UTC (permalink / raw)
  To: Gleb Natapov; +Cc: avi, kvm

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 <gleb@redhat.com>
> 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?

Looks fine to me. Do you have any numbers or just notice it out of code
review?

>  			msr->data = data;
>  			break;
>  		}
> --
> 			Gleb.
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] call vmx_load_host_state() only if msr is cached
  2009-08-31 14:04 ` Marcelo Tosatti
@ 2009-08-31 14:09   ` Gleb Natapov
  0 siblings, 0 replies; 3+ messages in thread
From: Gleb Natapov @ 2009-08-31 14:09 UTC (permalink / raw)
  To: Marcelo Tosatti; +Cc: avi, kvm

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 <gleb@redhat.com>
> > 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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-08-31 14:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-27 12:07 [PATCH] call vmx_load_host_state() only if msr is cached Gleb Natapov
2009-08-31 14:04 ` Marcelo Tosatti
2009-08-31 14:09   ` Gleb Natapov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.