From nobody Tue Feb 10 03:37:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571929687; cv=none; d=zoho.com; s=zohoarc; b=PieZq++XHShkm8+eX+lF5XKUzYbMka4aosewGHjFUNbiZ5/YXnReFiAU2qqWCLxYmOE9augtmFlDyzwwfx+zwgNQ/+Hrsn8LACooOrdhhD8oTJN0jeoTOixLYw6JSUCQL5yBPzpDqEAnYew917f6/DBV1Hp1EZ0Sm2HnpaYNUCk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571929687; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=iGmswL4U/5XW7ql7Ew8zQ48E5AkJVaBYfQW9kZ657mI=; b=AlNaVXWNTl679MX7CGXFaQDPa3+F3RdHk6zvbSoZC3V4865UUsmzf0N0IutXCablhVEKnQckjmMYpbNBCukrvRqIHZMzglVDA0frEKVlUHeHIWtMsAUSomFbFa+eRex6pvbAVXj8Ua+G8ZZTVAx7WamuLGbJfBlGaYNwTLr5/pI= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571929687382558.7284808179019; Thu, 24 Oct 2019 08:08:07 -0700 (PDT) Received: from localhost ([::1]:45151 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNeic-0001Qq-4w for importer@patchew.org; Thu, 24 Oct 2019 11:08:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34607) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNdig-0006t8-St for qemu-devel@nongnu.org; Thu, 24 Oct 2019 10:04:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNdib-0007a3-Hs for qemu-devel@nongnu.org; Thu, 24 Oct 2019 10:04:06 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:40867) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iNdib-0007ZZ-3O for qemu-devel@nongnu.org; Thu, 24 Oct 2019 10:04:01 -0400 Received: by mail-wm1-x343.google.com with SMTP id w9so1561263wmm.5 for ; Thu, 24 Oct 2019 07:04:01 -0700 (PDT) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id b7sm10610155wrn.53.2019.10.24.07.03.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Oct 2019 07:03:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=iGmswL4U/5XW7ql7Ew8zQ48E5AkJVaBYfQW9kZ657mI=; b=ps38OElF2RwitS8r3osFXr8symM/iIehe0wXdlIb3ctYk1BNZrHA0bR0eMFzp5+hPP RxPs0TNWiIQFoIaf7dRLZpfTD6CFmtJgxhcaj3lsGsLrrU4XcPgsg/Hs39YPoUpRfH8R c741xxkW87CXl5sVmhSUtXUIqVwzVp+WzsIbMqeqZowSv8+/NMg82kz7l36hUnea5mGL iJU9K0ahgTI0hgpivTpwqVjAGZKNk0PuGFMTbLwk8gw8NquQJRCQ7OJ9Rc6z9GhE7RGk rUA8gqt/4vS0NdPqJxXIZuNe1tKCFLEj1QUbs37eFnuICqT0VLE8LyuWskrxt7FjWtls Hh6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=iGmswL4U/5XW7ql7Ew8zQ48E5AkJVaBYfQW9kZ657mI=; b=DzRkVQ5rADWzRuSv974YPbYlZrWu2y6INKqf+nJsyHlpW+HS6tDh3e5nsL4qxUV4lE Dni8PSs1n880wxhpGLdA6PrPUrDYJIyPlts3bHSaj2OpTMGbhdFNSAhep9APuk6gzJX8 zOrKoghR5mhq5UM4XB9wHpCAQJjXEi0zpXtMd4sVeLAgZ+66Y6Np8Qrq7HpBqM4597C7 sIXkbuzJ3E5Z596e201PR/xWLOxENojZUNxp4O8mNFWPu1WF86LD2nIHPmPLpZad4H4D WyYKV7ZmzZ1E2ShKdpbrUSDLZMW9YTZgH51h1diJafahqJ1AAgohukMGEybgsIEe7VA1 AsJA== X-Gm-Message-State: APjAAAVFjyGFOqQJ7IT8rCuPKtzCStcaQqjheiXbDgEChkyUEkt0iHuC s/PPQqAMwKX7tQlpnfU9k/qYN8US X-Google-Smtp-Source: APXvYqxV6x/LUk/FGWOTOI4l7+8LG8EaHqdcHV1pkWRoOOYvdchHy1F001MLq6RepbdnpeI92C0Ptg== X-Received: by 2002:a1c:e404:: with SMTP id b4mr5555773wmh.90.1571925839703; Thu, 24 Oct 2019 07:03:59 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 02/39] mc146818rtc: fix timer interrupt reinjection Date: Thu, 24 Oct 2019 16:03:18 +0200 Message-Id: <1571925835-31930-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1571925835-31930-1-git-send-email-pbonzini@redhat.com> References: <1571925835-31930-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 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: Marcelo Tosatti Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Marcelo Tosatti 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. V2: reorganize code (Paolo Bonzini) Signed-off-by: Marcelo Tosatti Message-Id: <20191010123008.GA19158@amt.cnet> Signed-off-by: Paolo Bonzini --- hw/timer/mc146818rtc.c | 53 +++++++++++++++++++++++++---------------------= ---- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index 6cb3787..0e7cf97 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -203,24 +203,28 @@ periodic_timer_update(RTCState *s, int64_t current_ti= me, uint32_t old_period) =20 period =3D rtc_periodic_clock_ticks(s); =20 - if (period) { - /* compute 32 khz clock */ - cur_clock =3D - muldiv64(current_time, RTC_CLOCK_RATE, NANOSECONDS_PER_SECOND); + if (!period) { + s->irq_coalesced =3D 0; + timer_del(s->periodic_timer); + return; + } =20 - /* - * if the periodic timer's update is due to period re-configuration, - * we should count the clock since last interrupt. - */ - if (old_period) { - int64_t last_periodic_clock, next_periodic_clock; - - next_periodic_clock =3D muldiv64(s->next_periodic_time, - RTC_CLOCK_RATE, NANOSECONDS_PER_SECOND= ); - last_periodic_clock =3D next_periodic_clock - old_period; - lost_clock =3D cur_clock - last_periodic_clock; - assert(lost_clock >=3D 0); - } + /* compute 32 khz clock */ + cur_clock =3D + muldiv64(current_time, RTC_CLOCK_RATE, NANOSECONDS_PER_SECOND); + + /* + * if the periodic timer's update is due to period re-configuration, + * we should count the clock since last interrupt. + */ + if (old_period) { + int64_t last_periodic_clock, next_periodic_clock; + + next_periodic_clock =3D muldiv64(s->next_periodic_time, + RTC_CLOCK_RATE, NANOSECONDS_PER_SECOND); + last_periodic_clock =3D next_periodic_clock - old_period; + lost_clock =3D cur_clock - last_periodic_clock; + assert(lost_clock >=3D 0); =20 /* * s->irq_coalesced can change for two reasons: @@ -251,22 +255,19 @@ periodic_timer_update(RTCState *s, int64_t current_ti= me, uint32_t old_period) rtc_coalesced_timer_update(s); } } else { - /* + /* * no way to compensate the interrupt if LOST_TICK_POLICY_SLEW * is not used, we should make the time progress anyway. */ lost_clock =3D MIN(lost_clock, period); } + } =20 - assert(lost_clock >=3D 0 && lost_clock <=3D period); + assert(lost_clock >=3D 0 && lost_clock <=3D period); =20 - next_irq_clock =3D cur_clock + period - lost_clock; - s->next_periodic_time =3D periodic_clock_to_ns(next_irq_clock) + 1; - timer_mod(s->periodic_timer, s->next_periodic_time); - } else { - s->irq_coalesced =3D 0; - timer_del(s->periodic_timer); - } + next_irq_clock =3D cur_clock + period - lost_clock; + s->next_periodic_time =3D periodic_clock_to_ns(next_irq_clock) + 1; + timer_mod(s->periodic_timer, s->next_periodic_time); } =20 static void rtc_periodic_timer(void *opaque) --=20 1.8.3.1