From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756153AbbI1FjA (ORCPT ); Mon, 28 Sep 2015 01:39:00 -0400 Received: from mga11.intel.com ([192.55.52.93]:12829 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756090AbbI1Fi5 (ORCPT ); Mon, 28 Sep 2015 01:38:57 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,601,1437462000"; d="scan'208";a="814258344" From: Haozhong Zhang To: kvm@vger.kernel.org Cc: Gleb Natapov , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Joerg Roedel , Wanpeng Li , Xiao Guangrong , =?UTF-8?q?Mihai=20Don=C8=9Bu?= , Andy Lutomirski , Kai Huang , linux-kernel@vger.kernel.org, Haozhong Zhang Subject: [PATCH 06/12] KVM: x86: Move TSC scaling logic out of call-back adjust_tsc_offset() Date: Mon, 28 Sep 2015 13:38:05 +0800 Message-Id: <1443418691-24050-7-git-send-email-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.4.8 In-Reply-To: <1443418691-24050-1-git-send-email-haozhong.zhang@intel.com> References: <1443418691-24050-1-git-send-email-haozhong.zhang@intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For both VMX and SVM, if the 2nd argument of call-back adjust_tsc_offset() is the host TSC, then adjust_tsc_offset() will scale it first. This patch moves this common TSC scaling logic to its caller adjust_tsc_offset_host(). Signed-off-by: Haozhong Zhang --- arch/x86/include/asm/kvm_host.h | 13 ------------- arch/x86/kvm/svm.c | 6 ------ include/linux/kvm_host.h | 15 +++++++++++++++ 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 0bbb2a7..67b4a96 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -895,19 +895,6 @@ struct kvm_arch_async_pf { bool direct_map; }; -extern struct kvm_x86_ops *kvm_x86_ops; - -static inline void adjust_tsc_offset_guest(struct kvm_vcpu *vcpu, - s64 adjustment) -{ - kvm_x86_ops->adjust_tsc_offset(vcpu, adjustment, false); -} - -static inline void adjust_tsc_offset_host(struct kvm_vcpu *vcpu, s64 adjustment) -{ - kvm_x86_ops->adjust_tsc_offset(vcpu, adjustment, true); -} - int kvm_mmu_module_init(void); void kvm_mmu_module_exit(void); diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index c49cd28..239263f3 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -1045,12 +1045,6 @@ static void svm_adjust_tsc_offset(struct kvm_vcpu *vcpu, s64 adjustment, bool ho { struct vcpu_svm *svm = to_svm(vcpu); - if (host) { - if (vcpu->arch.tsc_scaling_ratio != TSC_RATIO_DEFAULT) - WARN_ON(adjustment < 0); - adjustment = kvm_scale_tsc(vcpu, (u64)adjustment); - } - svm->vmcb->control.tsc_offset += adjustment; if (is_guest_mode(vcpu)) svm->nested.hsave->control.tsc_offset += adjustment; diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 3c43e3e..2a21845 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1146,5 +1146,20 @@ static inline void kvm_vcpu_set_dy_eligible(struct kvm_vcpu *vcpu, bool val) #endif /* CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT */ u64 kvm_scale_tsc(struct kvm_vcpu *vcpu, u64 tsc); +extern struct kvm_x86_ops *kvm_x86_ops; + +static inline void adjust_tsc_offset_guest(struct kvm_vcpu *vcpu, + s64 adjustment) +{ + kvm_x86_ops->adjust_tsc_offset(vcpu, adjustment, false); +} + +static inline void adjust_tsc_offset_host(struct kvm_vcpu *vcpu, s64 adjustment) +{ + if (vcpu->arch.tsc_scaling_ratio != kvm_default_tsc_scaling_ratio) + WARN_ON(adjustment < 0); + adjustment = kvm_scale_tsc(vcpu, (u64) adjustment); + kvm_x86_ops->adjust_tsc_offset(vcpu, adjustment, true); +} #endif -- 2.4.8