Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752758AbbHGL17 (ORCPT ); Fri, 7 Aug 2015 07:27:59 -0400 Received: from mail-wi0-f180.google.com ([209.85.212.180]:34406 "EHLO mail-wi0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751978AbbHGL16 (ORCPT ); Fri, 7 Aug 2015 07:27:58 -0400 Subject: Re: [PATCH] KVM: x86: Use adjustment in guest cycles when handling MSR_IA32_TSC_ADJUST To: Haozhong Zhang , kvm@vger.kernel.org References: <1438917872-23908-1-git-send-email-haozhong.zhang@intel.com> Cc: Gleb Natapov , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org From: Paolo Bonzini Message-ID: <55C49638.3060508@redhat.com> Date: Fri, 7 Aug 2015 13:27:52 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: <1438917872-23908-1-git-send-email-haozhong.zhang@intel.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2092 Lines: 52 On 07/08/2015 05:24, Haozhong Zhang wrote: > When kvm_set_msr_common() handles a guest's write to > MSR_IA32_TSC_ADJUST, it will calcuate an adjustment based on the data > written by guest and then use it to adjust TSC offset by calling a > call-back adjust_tsc_offset(). The 3rd parameter of adjust_tsc_offset() > indicates whether the adjustment is in host TSC cycles or in guest TSC > cycles. If SVM TSC scaling is enabled, adjust_tsc_offset() > [i.e. svm_adjust_tsc_offset()] will first scale the adjustment; > otherwise, it will just use the unscaled one. As the MSR write here > comes from the guest, the adjustment is in guest TSC cycles. However, > the current kvm_set_msr_common() uses it as a value in host TSC > cycles (by using true as the 3rd parameter of adjust_tsc_offset()), > which can result in an incorrect adjustment of TSC offset if SVM TSC > scaling is enabled. This patch fixes this problem. > > Signed-off-by: Haozhong Zhang > --- > arch/x86/kvm/x86.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 5ef2560..3cd6cd2 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -2105,7 +2105,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) > if (guest_cpuid_has_tsc_adjust(vcpu)) { > if (!msr_info->host_initiated) { > s64 adj = data - vcpu->arch.ia32_tsc_adjust_msr; > - kvm_x86_ops->adjust_tsc_offset(vcpu, adj, true); > + adjust_tsc_offset_guest(vcpu, adj); > } > vcpu->arch.ia32_tsc_adjust_msr = data; > } > -- > 1.7.9.5 > > -- > 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 > Thanks, applied! Paolo -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/