From patchwork Thu Feb 26 19:42:20 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 9038 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 n1QJgQ8p009252 for ; Thu, 26 Feb 2009 19:42:27 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752217AbZBZTmY (ORCPT ); Thu, 26 Feb 2009 14:42:24 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752323AbZBZTmY (ORCPT ); Thu, 26 Feb 2009 14:42:24 -0500 Received: from mx2.redhat.com ([66.187.237.31]:42795 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752217AbZBZTmX (ORCPT ); Thu, 26 Feb 2009 14:42:23 -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 n1QJgMXb027982; Thu, 26 Feb 2009 14:42:22 -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 n1QJgMtq016020; Thu, 26 Feb 2009 14:42:22 -0500 Received: from localhost.localdomain (virtlab1.virt.bos.redhat.com [10.16.72.21]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n1QJgL1c011839; Thu, 26 Feb 2009 14:42:22 -0500 From: Glauber Costa To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, avi@redhat.com Subject: [PATCH] remove static declaration from wall clock version Date: Thu, 26 Feb 2009 14:42:20 -0500 Message-Id: <1235677340-3139-1-git-send-email-glommer@redhat.com> 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 --- 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)); /*