From patchwork Tue Aug 14 08:24:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 177186 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 116982C0091 for ; Tue, 14 Aug 2012 18:25:03 +1000 (EST) Received: from localhost ([::1]:48552 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1CQv-0000RX-5U for incoming@patchwork.ozlabs.org; Tue, 14 Aug 2012 04:25:01 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53483) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1CQm-0000RP-Lv for qemu-devel@nongnu.org; Tue, 14 Aug 2012 04:24:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T1CQk-0000nb-F3 for qemu-devel@nongnu.org; Tue, 14 Aug 2012 04:24:52 -0400 Received: from thoth.sbs.de ([192.35.17.2]:25825) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1CQk-0000nR-5P; Tue, 14 Aug 2012 04:24:50 -0400 Received: from mail1.siemens.de (localhost [127.0.0.1]) by thoth.sbs.de (8.13.6/8.13.6) with ESMTP id q7E8Oljn014889; Tue, 14 Aug 2012 10:24:48 +0200 Received: from mchn199C.mchp.siemens.de ([139.22.49.95]) by mail1.siemens.de (8.13.6/8.13.6) with SMTP id q7E8OlKN008194; Tue, 14 Aug 2012 10:24:47 +0200 Message-ID: <502A0B4F.105@siemens.com> Date: Tue, 14 Aug 2012 10:24:47 +0200 From: Jan Kiszka User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: Avi Kivity , Marcelo Tosatti References: <502A0B23.2080701@siemens.com> In-Reply-To: <502A0B23.2080701@siemens.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 192.35.17.2 Cc: kvm , Gleb Natapov , Michael Tokarev , qemu-devel , qemu-stable , Gerd Hoffmann Subject: [Qemu-devel] [PATCH uq/master 2/2] kvm: i8254: Finish time conversion fix 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 0cdd3d1444 fixed reading back the counter load time from the kernel while assuming the kernel would always update its load time on writing the state. That is only true for channel 1, and so pit_get_channel_info returned wrong output pin states for high counter values. Fix this by applying the offset also on kvm_pit_put. Now we also need to update the offset when we write the state while the VM is stopped as it keeps on changing in that state. Signed-off-by: Jan Kiszka --- hw/kvm/i8254.c | 14 ++++++++++---- 1 files changed, 10 insertions(+), 4 deletions(-) diff --git a/hw/kvm/i8254.c b/hw/kvm/i8254.c index c235d80..53d13e3 100644 --- a/hw/kvm/i8254.c +++ b/hw/kvm/i8254.c @@ -122,17 +122,23 @@ static void kvm_pit_get(PITCommonState *pit) pit_get_next_transition_time(sc, sc->count_load_time); } -static void kvm_pit_put(PITCommonState *s) +static void kvm_pit_put(PITCommonState *pit) { + KVMPITState *s = DO_UPCAST(KVMPITState, pit, pit); struct kvm_pit_state2 kpit; struct kvm_pit_channel_state *kchan; struct PITChannelState *sc; int i, ret; - kpit.flags = s->channels[0].irq_disabled ? KVM_PIT_FLAGS_HPET_LEGACY : 0; + /* The offset keeps changing as long as the VM is stopped. */ + if (s->vm_stopped) { + kvm_pit_update_clock_offset(s); + } + + kpit.flags = pit->channels[0].irq_disabled ? KVM_PIT_FLAGS_HPET_LEGACY : 0; for (i = 0; i < 3; i++) { kchan = &kpit.channels[i]; - sc = &s->channels[i]; + sc = &pit->channels[i]; kchan->count = sc->count; kchan->latched_count = sc->latched_count; kchan->count_latched = sc->count_latched; @@ -145,7 +151,7 @@ static void kvm_pit_put(PITCommonState *s) kchan->mode = sc->mode; kchan->bcd = sc->bcd; kchan->gate = sc->gate; - kchan->count_load_time = sc->count_load_time; + kchan->count_load_time = sc->count_load_time - s->kernel_clock_offset; } ret = kvm_vm_ioctl(kvm_state,