From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH 3/6] KVM: X86: Make tsc_delta calculation a function of guest tsc Date: Sun, 27 Mar 2011 12:57:03 +0200 Message-ID: <4D8F17FF.8020807@redhat.com> References: <1301042691-22929-1-git-send-email-joerg.roedel@amd.com> <1301042691-22929-4-git-send-email-joerg.roedel@amd.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Marcelo Tosatti , Zachary Amsden , kvm@vger.kernel.org To: Joerg Roedel Return-path: Received: from mx1.redhat.com ([209.132.183.28]:48680 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753227Ab1C0K5J (ORCPT ); Sun, 27 Mar 2011 06:57:09 -0400 In-Reply-To: <1301042691-22929-4-git-send-email-joerg.roedel@amd.com> Sender: kvm-owner@vger.kernel.org List-ID: On 03/25/2011 10:44 AM, Joerg Roedel wrote: > The calculation of the tsc_delta value to ensure a > forward-going tsc for the guest is a function of the > host-tsc. This works as long as the guests tsc_khz is equal > to the hosts tsc_khz. With tsc-scaling hardware support this > is not longer true and the tsc_delta needs to be calculated > > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -2126,8 +2126,13 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) > kvm_x86_ops->vcpu_load(vcpu, cpu); > if (unlikely(vcpu->cpu != cpu) || check_tsc_unstable()) { > /* Make sure TSC doesn't go backwards */ > - s64 tsc_delta = !vcpu->arch.last_host_tsc ? 0 : > - native_read_tsc() - vcpu->arch.last_host_tsc; > + s64 tsc_delta; > + u64 tsc; > + > + kvm_get_msr(vcpu, MSR_IA32_TSC,&tsc); > + tsc_delta = !vcpu->arch.last_guest_tsc ? 0 : > + tsc - vcpu->arch.last_guest_tsc; > + > if (tsc_delta< 0) > mark_tsc_unstable("KVM discovered backwards TSC"); > if (check_tsc_unstable()) { Patch is correct, but can this really happen? Won't all machines with scaled tsc also be stable? Perhaps not multi-board machines. -- error compiling committee.c: too many arguments to function