From patchwork Wed Jul 6 05:10:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9215369 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 158FD6048B for ; Wed, 6 Jul 2016 05:13:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F26A3286A1 for ; Wed, 6 Jul 2016 05:13:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E407D286A7; Wed, 6 Jul 2016 05:13:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77E8C286A1 for ; Wed, 6 Jul 2016 05:13:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750879AbcGFFNc (ORCPT ); Wed, 6 Jul 2016 01:13:32 -0400 Received: from mga09.intel.com ([134.134.136.24]:56921 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750738AbcGFFNb (ORCPT ); Wed, 6 Jul 2016 01:13:31 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 05 Jul 2016 22:13:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,317,1464678000"; d="scan'208";a="1011591417" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.148]) by orsmga002.jf.intel.com with ESMTP; 05 Jul 2016 22:13:28 -0700 From: Haozhong Zhang To: kvm@vger.kernel.org Cc: Paolo Bonzini , rkrcmar@redhat.com, Yunhong Jiang , Wanpeng Li , linux-kernel@vger.kernel.org, Haozhong Zhang Subject: [PATCH] KVM: VMX: switch to hrtimer for TSC deadline timer when L2 guest is running Date: Wed, 6 Jul 2016 13:10:51 +0800 Message-Id: <20160706051051.7869-1-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.9.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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)) {