diff mbox

KVM: vmx: restore MSR_IA32_DEBUGCTLMSR after VMEXIT

Message ID 20120812131228.GL3341@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Gleb Natapov Aug. 12, 2012, 1:12 p.m. UTC
MSR_IA32_DEBUGCTLMSR is zeroed on VMEXIT. Restore it to the correct
value.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
--
			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

Comments

Avi Kivity Aug. 12, 2012, 1:22 p.m. UTC | #1
On 08/12/2012 04:12 PM, Gleb Natapov wrote:
> MSR_IA32_DEBUGCTLMSR is zeroed on VMEXIT. Restore it to the correct
> value.
> 
> @@ -6222,6 +6222,7 @@ static void atomic_switch_perf_msrs(struct vcpu_vmx *vmx)
>  static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
>  {
>  	struct vcpu_vmx *vmx = to_vmx(vcpu);
> +	unsigned long debugctlmsr;
>  
>  	if (is_guest_mode(vcpu) && !vmx->nested.nested_run_pending) {
>  		struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
> @@ -6261,6 +6262,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
>  		vmx_set_interrupt_shadow(vcpu, 0);
>  
>  	atomic_switch_perf_msrs(vmx);
> +	debugctlmsr = get_debugctlmsr();

How expensive is this?  We may want a follow-on patch to cache it in a
per-cpu variable.
Gleb Natapov Aug. 12, 2012, 1:25 p.m. UTC | #2
On Sun, Aug 12, 2012 at 04:22:59PM +0300, Avi Kivity wrote:
> On 08/12/2012 04:12 PM, Gleb Natapov wrote:
> > MSR_IA32_DEBUGCTLMSR is zeroed on VMEXIT. Restore it to the correct
> > value.
> > 
> > @@ -6222,6 +6222,7 @@ static void atomic_switch_perf_msrs(struct vcpu_vmx *vmx)
> >  static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
> >  {
> >  	struct vcpu_vmx *vmx = to_vmx(vcpu);
> > +	unsigned long debugctlmsr;
> >  
> >  	if (is_guest_mode(vcpu) && !vmx->nested.nested_run_pending) {
> >  		struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
> > @@ -6261,6 +6262,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
> >  		vmx_set_interrupt_shadow(vcpu, 0);
> >  
> >  	atomic_switch_perf_msrs(vmx);
> > +	debugctlmsr = get_debugctlmsr();
> 
> How expensive is this?  We may want a follow-on patch to cache it in a
> per-cpu variable.
> 
I have patches ready. I couldn't measure any overhead of the
rdmsr(MSR_IA32_DEBUGCTLMSR).

--
			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
Avi Kivity Aug. 12, 2012, 1:40 p.m. UTC | #3
On 08/12/2012 04:25 PM, Gleb Natapov wrote:

>> How expensive is this?  We may want a follow-on patch to cache it in a
>> per-cpu variable.
>> 
> I have patches ready. I couldn't measure any overhead of the
> rdmsr(MSR_IA32_DEBUGCTLMSR).
> 

Do you mean while running kvm?  How about just running it in a loop?
Gleb Natapov Aug. 12, 2012, 5:28 p.m. UTC | #4
On Sun, Aug 12, 2012 at 04:40:48PM +0300, Avi Kivity wrote:
> On 08/12/2012 04:25 PM, Gleb Natapov wrote:
> 
> >> How expensive is this?  We may want a follow-on patch to cache it in a
> >> per-cpu variable.
> >> 
> > I have patches ready. I couldn't measure any overhead of the
> > rdmsr(MSR_IA32_DEBUGCTLMSR).
> > 
> 
> Do you mean while running kvm?  How about just running it in a loop?
> 
No, I mean running it in a loop. Loop with or without
rdmsr(MSR_IA32_DEBUGCTLMSR) takes the same time as measured by rdtsc.


--
			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
Avi Kivity Aug. 13, 2012, 7:55 a.m. UTC | #5
On 08/12/2012 08:28 PM, Gleb Natapov wrote:
> On Sun, Aug 12, 2012 at 04:40:48PM +0300, Avi Kivity wrote:
>> On 08/12/2012 04:25 PM, Gleb Natapov wrote:
>> 
>> >> How expensive is this?  We may want a follow-on patch to cache it in a
>> >> per-cpu variable.
>> >> 
>> > I have patches ready. I couldn't measure any overhead of the
>> > rdmsr(MSR_IA32_DEBUGCTLMSR).
>> > 
>> 
>> Do you mean while running kvm?  How about just running it in a loop?
>> 
> No, I mean running it in a loop. Loop with or without
> rdmsr(MSR_IA32_DEBUGCTLMSR) takes the same time as measured by rdtsc.

Ok, good.
Marcelo Tosatti Aug. 13, 2012, 10:07 p.m. UTC | #6
On Sun, Aug 12, 2012 at 04:12:29PM +0300, Gleb Natapov wrote:
> MSR_IA32_DEBUGCTLMSR is zeroed on VMEXIT. Restore it to the correct
> value.
> 
> Signed-off-by: Gleb Natapov <gleb@redhat.com>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c

Applied, thanks.

--
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
diff mbox

Patch

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index cc8ad98..d0f4bec 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -6222,6 +6222,7 @@  static void atomic_switch_perf_msrs(struct vcpu_vmx *vmx)
 static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
 {
 	struct vcpu_vmx *vmx = to_vmx(vcpu);
+	unsigned long debugctlmsr;
 
 	if (is_guest_mode(vcpu) && !vmx->nested.nested_run_pending) {
 		struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
@@ -6261,6 +6262,7 @@  static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
 		vmx_set_interrupt_shadow(vcpu, 0);
 
 	atomic_switch_perf_msrs(vmx);
+	debugctlmsr = get_debugctlmsr();
 
 	vmx->__launched = vmx->loaded_vmcs->launched;
 	asm(
@@ -6362,6 +6364,10 @@  static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
 #endif
 	      );
 
+	/* MSR_IA32_DEBUGCTLMSR is zeroed on vmexit. Restore it if needed */
+	if (debugctlmsr)
+		update_debugctlmsr(debugctlmsr);
+
 #ifndef CONFIG_X86_64
 	/*
 	 * The sysexit path does not restore ds/es, so we must set them to