From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH] KVM: Fix wallclock version writing race Date: Tue, 04 May 2010 19:21:32 +0300 Message-ID: <4BE0498C.9040703@redhat.com> References: <1272974544-19452-1-git-send-email-avi@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, Naphtali Sprei To: Glauber Costa , Marcelo Tosatti Return-path: Received: from mx1.redhat.com ([209.132.183.28]:26727 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932960Ab0EDQVe (ORCPT ); Tue, 4 May 2010 12:21:34 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o44GLYtN005645 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 4 May 2010 12:21:34 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o44GLXsY003847 for ; Tue, 4 May 2010 12:21:33 -0400 In-Reply-To: <1272974544-19452-1-git-send-email-avi@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 05/04/2010 03:02 PM, Avi Kivity wrote: > Wallclock writing uses an unprotected global variable to hold the version; > this can cause one guest to interfere with another if both write their > wallclock at the same time. > > Signed-off-by: Avi Kivity > This was pointed out by Naphtali. > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index f6f8dad..c3152d7 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -754,14 +754,22 @@ 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; > + int r; > struct pvclock_wall_clock wc; > struct timespec boot; > > if (!wall_clock) > return; > > - version++; > + r = kvm_read_guest(kvm, wall_clock,&version, sizeof(version)); > + if (r) > + return; > + > + if (version& 1) > + ++version; /* first time write, random junk */ > + > + ++version; > > kvm_write_guest(kvm, wall_clock,&version, sizeof(version)); > > -- error compiling committee.c: too many arguments to function