Skip to contentSkip to conversation

KVM: vmx: restore MSR_IA32_DEBUGCTLMSR after VMEXIT

PATCH Applied Gleb Natapov 3 participants 7 messages Aug 12, 2012 – Aug 13, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: vmx: restore MSR_IA32_DEBUGCTLMSR after VMEXIT

MSR_IA32_DEBUGCTLMSR is zeroed on VMEXIT. Restore it to the correct value.

arch/x86/kvm/vmx.c +6 -0
index cc8ad98..d0f4bec 100644
@@ -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

--
Gleb.

#1 lore raw
Quoted 12 lines · Gleb Natapov

MSR_IA32_DEBUGCTLMSR is zeroed on VMEXIT. Restore it to the correct value.

arch/x86/kvm/vmx.c +1 -0
@@ -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);

arch/x86/kvm/vmx.c static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu) · line 6265

Quoted 4 lines
arch/x86/kvm/vmx.c +1 -0
@@ -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.

Signature · 1 line
error compiling committee.c: too many arguments to function
#2 lore raw
Quoted 15 lines · Avi Kivity
Quoted 14 lines · Gleb Natapov

MSR_IA32_DEBUGCTLMSR is zeroed on VMEXIT. Restore it to the correct value.

arch/x86/kvm/vmx.c +1 -0
@@ -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);
 
Quoted 6 lines

arch/x86/kvm/vmx.c static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu) · line 6265

Quoted 2 lines
arch/x86/kvm/vmx.c +1 -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.

#3 lore raw
Quoted 6 lines · Gleb Natapov
Quoted 3 lines

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?

Signature · 1 line
error compiling committee.c: too many arguments to function
#4 lore raw
Quoted 11 lines · Avi Kivity
Quoted 6 lines · Gleb Natapov
Quoted 3 lines

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.

#5 lore raw
Quoted 6 lines · Gleb Natapov
Quoted 5 lines · Avi Kivity
Quoted 3 lines · Gleb Natapov
Quoted 3 lines

How expensive is this? We may want a follow-on patch to cache it in a per-cpu variable.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

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.

Signature · 1 line
error compiling committee.c: too many arguments to function