From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: Re: [PATCH] Fix kvmclock on !constant_tsc boxes. Date: Sat, 7 Feb 2009 05:14:03 -0200 Message-ID: <20090207071403.GA6301@amt.cnet> References: <4989C7B4.10508@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: KVM list To: Gerd Hoffmann Return-path: Received: from mx2.redhat.com ([66.187.237.31]:41176 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750836AbZBHFoI (ORCPT ); Sun, 8 Feb 2009 00:44:08 -0500 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n185i6fG026448 for ; Sun, 8 Feb 2009 00:44:07 -0500 Content-Disposition: inline In-Reply-To: <4989C7B4.10508@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Hi Gerd, On Wed, Feb 04, 2009 at 05:52:04PM +0100, Gerd Hoffmann wrote: > kvmclock currently falls apart on machines without constant tsc. > This patch fixes it. Changes: > > * keep tsc frequency in a per-cpu variable. > * handle kvmclock update using a new request flag, thus checking > whenever we need an update each time we enter guest context. > * use a cpufreq notifier to track frequency changes and force > kvmclock updates. > * send ipis to kick cpu out of guest context if needed to make > sure the guest doesn't see stale values. > > Signed-off-by: Gerd Hoffmann > --- > arch/x86/kvm/x86.c | 99 +++++++++++++++++++++++++++++++++++++++++++--- > include/linux/kvm_host.h | 1 + > 2 files changed, 94 insertions(+), 6 deletions(-) > > + spin_lock(&kvm_lock); > + list_for_each_entry(kvm, &vm_list, vm_list) { > + for (i = 0; i < KVM_MAX_VCPUS; ++i) { > + vcpu = kvm->vcpus[i]; > + if (!vcpu) > + continue; > + if (vcpu->cpu != freq->cpu) > + continue; > + if (!kvm_request_guest_time_update(vcpu)) > + continue; > + if (vcpu->cpu != smp_processor_id()) > + send_ipi++; > + } > + } > + spin_unlock(&kvm_lock); The loop is cold hearted, but Juan's cleanups can be worked for 2.6.30 merge window. Given how many people have hit the bug better have something non invasive until then. > + > + if (freq->old < freq->new && send_ipi) { Can you fix the whitespace breakage please? > + smp_call_function_single(freq->cpu, bounce_off, NULL, 1); > + } > + return 0; > +}