From patchwork Tue Jun 3 16:34:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 355593 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B0119140091 for ; Wed, 4 Jun 2014 02:35:38 +1000 (EST) Received: from localhost ([::1]:54654 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrrgW-0005Hz-Mv for incoming@patchwork.ozlabs.org; Tue, 03 Jun 2014 12:35:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42551) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrrgC-0004zA-BK for qemu-devel@nongnu.org; Tue, 03 Jun 2014 12:35:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wrrg5-00063v-NG for qemu-devel@nongnu.org; Tue, 03 Jun 2014 12:35:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:27929) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wrrg5-00063f-G4 for qemu-devel@nongnu.org; Tue, 03 Jun 2014 12:35:09 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s53GZ6Y8028429 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 3 Jun 2014 12:35:06 -0400 Received: from amt.cnet (vpn1-5-234.gru2.redhat.com [10.97.5.234]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s53GZ5NJ013334; Tue, 3 Jun 2014 12:35:05 -0400 Received: from amt.cnet (localhost [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id C86731003FB; Tue, 3 Jun 2014 13:34:52 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.7/8.14.7/Submit) id s53GYojk012004; Tue, 3 Jun 2014 13:34:50 -0300 Date: Tue, 3 Jun 2014 13:34:48 -0300 From: Marcelo Tosatti To: Paolo Bonzini Message-ID: <20140603163448.GA11829@amt.cnet> References: <1400253321-9239-1-git-send-email-agraf@suse.de> <538CDF30.9050902@beyond.pl> <20140603051630.GA2289@amt.cnet> <538DADED.4040609@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <538DADED.4040609@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id s53GZ6Y8028429 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Marcin =?utf-8?Q?Gibu=C5=82a?= , Alexander Graf , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH uq/master] kvmclock: Ensure proper env->tsc value for kvmclock_current_nsec calculation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Ensure proper env->tsc value for kvmclock_current_nsec calculation. Reported-by: Marcin GibuĊ‚a Signed-off-by: Marcelo Tosatti diff --git a/hw/i386/kvm/clock.c b/hw/i386/kvm/clock.c index 6f4ed28a..bef2504 100644 --- a/hw/i386/kvm/clock.c +++ b/hw/i386/kvm/clock.c @@ -17,6 +17,7 @@ #include "qemu/host-utils.h" #include "sysemu/sysemu.h" #include "sysemu/kvm.h" +#include "sysemu/cpus.h" #include "hw/sysbus.h" #include "hw/kvm/clock.h" @@ -65,6 +66,7 @@ static uint64_t kvmclock_current_nsec(KVMClockState *s) cpu_physical_memory_read(kvmclock_struct_pa, &time, sizeof(time)); + assert(time.tsc_timestamp <= migration_tsc); delta = migration_tsc - time.tsc_timestamp; if (time.tsc_shift < 0) { delta >>= -time.tsc_shift; @@ -123,6 +125,8 @@ static void kvmclock_vm_state_change(void *opaque, int running, if (s->clock_valid) { return; } + + cpu_synchronize_all_states(); ret = kvm_vm_ioctl(kvm_state, KVM_GET_CLOCK, &data); if (ret < 0) { fprintf(stderr, "KVM_GET_CLOCK failed: %s\n", strerror(ret));