From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [patch 3/3] KVM: VMX: initialize TSC offset relative to vm creation time Date: Wed, 10 Dec 2008 12:19:28 +0200 Message-ID: <493F97B0.2060104@redhat.com> References: <20081209011247.570596925@localhost.localdomain> <20081209012212.171143870@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, Benjamin Serebrin To: Marcelo Tosatti Return-path: Received: from mx2.redhat.com ([66.187.237.31]:33962 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754567AbYLJKTe (ORCPT ); Wed, 10 Dec 2008 05:19:34 -0500 In-Reply-To: <20081209012212.171143870@localhost.localdomain> Sender: kvm-owner@vger.kernel.org List-ID: Marcelo Tosatti wrote: > VMX initializes the TSC offset for each vcpu at different times, and > also reinitializes it for vcpus other than 0 on APIC SIPI message. > > This bug causes the TSC's to appear unsynchronized in the guest, even if > the host is good. > > Older Linux kernels don't handle the situation very well, so > gettimeofday is likely to go backwards in time: > > http://www.mail-archive.com/kvm@vger.kernel.org/msg02955.html > http://sourceforge.net/tracker/index.php?func=detail&aid=2025534&group_id=180599&atid=893831 > > Fix it by initializating the offset of each vcpu relative to vm creation > time, and moving it from vmx_vcpu_reset to vmx_vcpu_setup, out of the > APIC MP init path. > This looks fine, but have you tested it on a host with unsync tsc? I'm worried that we'll get regressions there even on uniprocessor guest. I'd like to keep the current behaviour for the special case of uniprocessor guest on unsync tsc host. There's a further improvement possible: treating the tsc as shared among all vcpus, so that a guest write to one will update all of them, like on a hyperthreaded core. This will prevent the unsyncing caused by the host trying to sync tscs, and the vcpu being scheduled away at the same time. -- error compiling committee.c: too many arguments to function