From patchwork Wed Oct 9 18:40:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 11182063 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 46C2F13BD for ; Wed, 9 Oct 2019 20:27:01 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 276C7206BB for ; Wed, 9 Oct 2019 20:27:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 276C7206BB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:56904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIIXz-0002KH-T0 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 09 Oct 2019 16:26:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44967) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIGtB-0004S1-Gv for qemu-devel@nongnu.org; Wed, 09 Oct 2019 14:40:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iIGtA-0004sn-H0 for qemu-devel@nongnu.org; Wed, 09 Oct 2019 14:40:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48896) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iIGtA-0004sH-BM for qemu-devel@nongnu.org; Wed, 09 Oct 2019 14:40:44 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DB6052A09AC; Wed, 9 Oct 2019 18:40:41 +0000 (UTC) Received: from amt.cnet (ovpn-112-6.gru2.redhat.com [10.97.112.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6FFAD61F24; Wed, 9 Oct 2019 18:40:41 +0000 (UTC) Received: from amt.cnet (localhost [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 7993310516E; Wed, 9 Oct 2019 15:40:23 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.7/8.14.7/Submit) id x99IeIIi027715; Wed, 9 Oct 2019 15:40:18 -0300 Date: Wed, 9 Oct 2019 15:40:14 -0300 From: Marcelo Tosatti To: qemu-devel Subject: [PATCH] mc146818rtc: fix timer interrupt reinjection Message-ID: <20191009184011.GA26234@amt.cnet> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 09 Oct 2019 18:40:42 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tai Yunfang , Xiao Guangrong , Vadim Rozenfeld , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" commit 369b41359af46bded5799c9ef8be2b641d92e043 broke timer interrupt reinjection when there is no period change by the guest. In that case, old_period is 0, which ends up zeroing irq_coalesced (counter of reinjected interrupts). The consequence is Windows 7 is unable to synchronize time via NTP. Easily reproducible by playing a fullscreen video with cirrus and VNC. Fix by not updating s->irq_coalesced when old_period is 0. Signed-off-by: Marcelo Tosatti diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index 6cb378751b..aabffa8c67 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -241,7 +241,10 @@ periodic_timer_update(RTCState *s, int64_t current_time, uint32_t old_period) s->period = period; lost_clock += old_irq_coalesced * old_period; - s->irq_coalesced = lost_clock / s->period; + if (old_period) { + s->irq_coalesced = lost_clock / s->period; + } + lost_clock %= s->period; if (old_irq_coalesced != s->irq_coalesced || old_period != s->period) {