Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1437417

[PATCH] KVM: VMX: switch to hrtimer for TSC deadline timer when L2 guest is running

From Haozhong Zhang <haozhong.zhang@intel.com>
Newsgroups linux.kernel
Subject [PATCH] KVM: VMX: switch to hrtimer for TSC deadline timer when L2 guest is running
Date 2016-07-06 07:20 +0200
Message-ID <rRNpD-4Ya-9@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


A different VMCS is loaded when L2 guest is running, so it's incorrect
to use the VMX preemption timer for L1 TSC deadline timer. This patch
switches to hrtimer for L1 TSC deadline timer when entering L2 guest,
and switches back to VMX preemption timer when nested VMEXIT from L2 to
L1.

Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
---
 arch/x86/kvm/vmx.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 85e2f0a..cc29c2a 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -10203,6 +10203,9 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch)
 	if (!vmcs02)
 		return -ENOMEM;
 
+	if (kvm_lapic_hv_timer_in_use(vcpu))
+		kvm_lapic_switch_to_sw_timer(vcpu);
+
 	enter_guest_mode(vcpu);
 
 	vmx->nested.vmcs01_tsc_offset = vmcs_read64(TSC_OFFSET);
@@ -10227,6 +10230,7 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch)
 	if (msr_entry_idx) {
 		leave_guest_mode(vcpu);
 		vmx_load_vmcs01(vcpu);
+		kvm_lapic_switch_to_hv_timer(vcpu);
 		nested_vmx_entry_failure(vcpu, vmcs12,
 				EXIT_REASON_MSR_LOAD_FAIL, msr_entry_idx);
 		return 1;
@@ -10700,6 +10704,7 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
 		nested_vmx_abort(vcpu, VMX_ABORT_SAVE_GUEST_MSR_FAIL);
 
 	vmx_load_vmcs01(vcpu);
+	kvm_lapic_switch_to_hv_timer(vcpu);
 
 	if ((exit_reason == EXIT_REASON_EXTERNAL_INTERRUPT)
 	    && nested_exit_intr_ack_set(vcpu)) {
-- 
2.9.0

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] KVM: VMX: switch to hrtimer for TSC deadline timer when L2 guest is running Haozhong Zhang <haozhong.zhang@intel.com> - 2016-07-06 07:20 +0200
  Re: [PATCH] KVM: VMX: switch to hrtimer for TSC deadline timer when  L2 guest is running Wanpeng Li <kernellwp@gmail.com> - 2016-07-06 07:40 +0200
    Re: [PATCH] KVM: VMX: switch to hrtimer for TSC deadline timer when  L2 guest is running Paolo Bonzini <pbonzini@redhat.com> - 2016-07-06 08:10 +0200
    Re: [PATCH] KVM: VMX: switch to hrtimer for TSC deadline timer when  L2 guest is running Haozhong Zhang <haozhong.zhang@intel.com> - 2016-07-06 08:10 +0200
      Re: [PATCH] KVM: VMX: switch to hrtimer for TSC deadline timer when  L2 guest is running Paolo Bonzini <pbonzini@redhat.com> - 2016-07-06 09:50 +0200
        Re: [PATCH] KVM: VMX: switch to hrtimer for TSC deadline timer when  L2 guest is running Haozhong Zhang <haozhong.zhang@intel.com> - 2016-07-06 10:10 +0200
          Re: [PATCH] KVM: VMX: switch to hrtimer for TSC deadline timer when  L2 guest is running Haozhong Zhang <haozhong.zhang@intel.com> - 2016-07-06 10:10 +0200
            Re: [PATCH] KVM: VMX: switch to hrtimer for TSC deadline timer when  L2 guest is running Paolo Bonzini <pbonzini@redhat.com> - 2016-07-06 10:20 +0200
              Re: [PATCH] KVM: VMX: switch to hrtimer for TSC deadline timer when  L2 guest is running Haozhong Zhang <haozhong.zhang@intel.com> - 2016-07-06 10:30 +0200

csiph-web