From patchwork Fri Feb 27 16:44:05 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 9207 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n1RGjLXu023325 for ; Fri, 27 Feb 2009 16:45:21 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758577AbZB0Qos (ORCPT ); Fri, 27 Feb 2009 11:44:48 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758567AbZB0Qos (ORCPT ); Fri, 27 Feb 2009 11:44:48 -0500 Received: from mx2.redhat.com ([66.187.237.31]:59457 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758534AbZB0Qor (ORCPT ); Fri, 27 Feb 2009 11:44:47 -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 n1RGijbF001185 for ; Fri, 27 Feb 2009 11:44:45 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n1RGijpF009040; Fri, 27 Feb 2009 11:44:45 -0500 Received: from amt.cnet (vpn-10-52.str.redhat.com [10.32.10.52]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n1RGihvj016419; Fri, 27 Feb 2009 11:44:44 -0500 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 8C0DC680001; Fri, 27 Feb 2009 13:44:06 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id n1RGi5Wp010605; Fri, 27 Feb 2009 13:44:05 -0300 Date: Fri, 27 Feb 2009 13:44:05 -0300 From: Marcelo Tosatti To: Glauber Costa Cc: kvm@vger.kernel.org, avi@redhat.com Subject: Re: [PATCH] remove static declaration from wall clock version Message-ID: <20090227164405.GA10181@amt.cnet> References: <1235677340-3139-1-git-send-email-glommer@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1235677340-3139-1-git-send-email-glommer@redhat.com> User-Agent: Mutt/1.5.18 (2008-05-17) X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Matt T. Yourst noted that we're currently having a dumb race for no reason in paravirtual wall clock. This is due to the use of a static variable to hold the counting. This can race with multiple guests reading wallclock at the same time, since the static variable value would then be accessible to all callers. This wasn't noted before because it is a rather rare scenario. Instead, just use a normal stack variable. This will mean that each caller will have it's version written separatedly. No need for a global counter. Signed-off-by: Glauber Costa Acked-by: Marcelo Tosatti --- arch/x86/kvm/x86.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 2511708..d7236f6 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -548,15 +548,13 @@ static int do_set_msr(struct kvm_vcpu *vcpu, unsigned index, u64 *data) static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock) { - static int version; + int version = 1; struct pvclock_wall_clock wc; struct timespec now, sys, boot; if (!wall_clock) return; - version++; - kvm_write_guest(kvm, wall_clock, &version, sizeof(version)); /*