All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Glauber Costa <glommer@redhat.com>
Cc: kvm@vger.kernel.org, avi@redhat.com
Subject: Re: [PATCH] remove static declaration from wall clock version
Date: Fri, 27 Feb 2009 13:44:05 -0300	[thread overview]
Message-ID: <20090227164405.GA10181@amt.cnet> (raw)
In-Reply-To: <1235677340-3139-1-git-send-email-glommer@redhat.com>


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 <glommer@redhat.com>
Acked-by: Marcelo Tosatti <mtosatti@redhat.com>

---
 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));
 
 	/*
-- 
1.5.6.5


  parent reply	other threads:[~2009-02-27 16:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-26 19:42 [PATCH] remove static declaration from wall clock version Glauber Costa
2009-02-26 19:50 ` Arnd Bergmann
2009-02-27  1:22   ` Glauber Costa
2009-02-27  1:28     ` Arnd Bergmann
2009-02-27 16:44 ` Marcelo Tosatti [this message]
2009-03-03 11:21 ` Marcelo Tosatti
2009-03-08 12:15 ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090227164405.GA10181@amt.cnet \
    --to=mtosatti@redhat.com \
    --cc=avi@redhat.com \
    --cc=glommer@redhat.com \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.