mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Glauber Costa <glommer@redhat.com>
To: kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Avi Kivity <avi@redhat.com>
Subject: [PATCH v2] use guest value of version field in kvmclock
Date: Wed,  2 Feb 2011 08:27:56 -0500	[thread overview]
Message-ID: <1296653276-31931-1-git-send-email-glommer@redhat.com> (raw)

Avi noticed that we have to use guest's value for the version field,
instead of keeping track of it ourselves. If we don't do that,
the following situation can arise:

 vcpu->arch.hv_clock.version is initialized to zero.
 Guest reads version (result: 2)
 Guest starts reading data
 Live migration; vcpu->arch.hv_clock.version is zeroed
 Steal time update; vcpu->arch.hv_clock.version += 2; write to guest
 Guest continues reading data
 Guest reads version (result: 2)

Signed-off-by: Glauber Costa <glommer@redhat.com>
CC: Avi Kivity <avi@redhat.com>

---
v2: don't get rid of the actual values =)
---
 arch/x86/kvm/x86.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index c39ab4a..5707405 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1151,15 +1151,18 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
 	vcpu->last_guest_tsc = tsc_timestamp;
 	vcpu->hv_clock.flags = 0;
 
+	shared_kaddr = kmap_atomic(vcpu->time_page, KM_USER0);
+
 	/*
 	 * The interface expects us to write an even number signaling that the
 	 * update is finished. Since the guest won't see the intermediate
-	 * state, we just increase by 2 at the end.
+	 * state, we just increase by 2 at the end. We use the guest's value as
+	 * a basis to make it migration-safe.
 	 */
+	memcpy(&vcpu->hv_clock.version, shared_kaddr + vcpu->time_offset,
+	       sizeof(vcpu->hv_clock.version));
 	vcpu->hv_clock.version += 2;
 
-	shared_kaddr = kmap_atomic(vcpu->time_page, KM_USER0);
-
 	memcpy(shared_kaddr + vcpu->time_offset, &vcpu->hv_clock,
 	       sizeof(vcpu->hv_clock));
 
-- 
1.7.2.3


                 reply	other threads:[~2011-02-02 13:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1296653276-31931-1-git-send-email-glommer@redhat.com \
    --to=glommer@redhat.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®