Blame SOURCES/kvm-mc146818rtc-fix-timer-interrupt-reinjection-again.patch

8b1478
From 224a226b03d2c0503915bd1c1139b37b56afd62d Mon Sep 17 00:00:00 2001
8b1478
From: Marcelo Tosatti <mtosatti@redhat.com>
8b1478
Date: Wed, 4 Dec 2019 15:21:09 +0100
8b1478
Subject: [PATCH 3/3] mc146818rtc: fix timer interrupt reinjection again
8b1478
8b1478
RH-Author: Marcelo Tosatti <mtosatti@redhat.com>
8b1478
Message-id: <20191204152436.823942711@amt.cnet>
8b1478
Patchwork-id: 92887
8b1478
O-Subject: [RHEL-7.8 qemu-kvm-rhev PATCH 3/3] mc146818rtc: fix timer interrupt reinjection again
8b1478
Bugzilla: 1639098
8b1478
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
8b1478
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
8b1478
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
8b1478
8b1478
BZ: 1639098
8b1478
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=24854309
8b1478
BRANCH: rhv7/master-2.12.0
8b1478
Upstream: 7a3e29b12f5afe0106a5713bb4db6e23dc66ef91
8b1478
of pbonzini's for-upstream tree.
8b1478
8b1478
Commit 369b41359af46bded5799c9ef8be2b641d92e043 broke timer interrupt
8b1478
reinjection when there is no period change by the guest.  In that
8b1478
case, old_period is 0, which ends up zeroing irq_coalesced (counter of
8b1478
reinjected interrupts).
8b1478
8b1478
The consequence is Windows 7 is unable to synchronize time via NTP.
8b1478
Easily reproducible by playing a fullscreen video with cirrus and VNC.
8b1478
8b1478
Fix by passing s->period when periodic_timer_update is called due to
8b1478
expiration of the timer.  With this change, old_period == 0 only
8b1478
means that the periodic timer was off.
8b1478
8b1478
Reported-by: Marcelo Tosatti <mtosatti@redhat.com>
8b1478
Co-developed-by: Marcelo Tosatti <mtosatti@redhat.com>
8b1478
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
8b1478
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
8b1478
---
8b1478
 hw/timer/mc146818rtc.c | 18 ++++++++++--------
8b1478
 1 file changed, 10 insertions(+), 8 deletions(-)
8b1478
8b1478
diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c
8b1478
index d848911..7459040 100644
8b1478
--- a/hw/timer/mc146818rtc.c
8b1478
+++ b/hw/timer/mc146818rtc.c
8b1478
@@ -190,12 +190,14 @@ static uint32_t rtc_periodic_clock_ticks(RTCState *s)
8b1478
  * is just due to period adjustment.
8b1478
  */
8b1478
 static void
8b1478
-periodic_timer_update(RTCState *s, int64_t current_time, uint32_t old_period)
8b1478
+periodic_timer_update(RTCState *s, int64_t current_time, uint32_t old_period, bool period_change)
8b1478
 {
8b1478
     uint32_t period;
8b1478
     int64_t cur_clock, next_irq_clock, lost_clock = 0;
8b1478
 
8b1478
     period = rtc_periodic_clock_ticks(s);
8b1478
+    s->period = period;
8b1478
+
8b1478
     if (!period) {
8b1478
         s->irq_coalesced = 0;
8b1478
         timer_del(s->periodic_timer);
8b1478
@@ -210,7 +212,7 @@ periodic_timer_update(RTCState *s, int64_t current_time, uint32_t old_period)
8b1478
      * if the periodic timer's update is due to period re-configuration,
8b1478
      * we should count the clock since last interrupt.
8b1478
      */
8b1478
-    if (old_period) {
8b1478
+    if (old_period && period_change) {
8b1478
         int64_t last_periodic_clock, next_periodic_clock;
8b1478
 
8b1478
         next_periodic_clock = muldiv64(s->next_periodic_time,
8b1478
@@ -237,7 +239,6 @@ periodic_timer_update(RTCState *s, int64_t current_time, uint32_t old_period)
8b1478
     if (s->lost_tick_policy == LOST_TICK_POLICY_SLEW) {
8b1478
         uint32_t old_irq_coalesced = s->irq_coalesced;
8b1478
 
8b1478
-        s->period = period;
8b1478
         lost_clock += old_irq_coalesced * old_period;
8b1478
         s->irq_coalesced = lost_clock / s->period;
8b1478
         lost_clock %= s->period;
8b1478
@@ -267,7 +268,7 @@ static void rtc_periodic_timer(void *opaque)
8b1478
 {
8b1478
     RTCState *s = opaque;
8b1478
 
8b1478
-    periodic_timer_update(s, s->next_periodic_time, 0);
8b1478
+    periodic_timer_update(s, s->next_periodic_time, s->period, false);
8b1478
     s->cmos_data[RTC_REG_C] |= REG_C_PF;
8b1478
     if (s->cmos_data[RTC_REG_B] & REG_B_PIE) {
8b1478
         s->cmos_data[RTC_REG_C] |= REG_C_IRQF;
8b1478
@@ -533,7 +534,7 @@ static void cmos_ioport_write(void *opaque, hwaddr addr,
8b1478
 
8b1478
             if (update_periodic_timer) {
8b1478
                 periodic_timer_update(s, qemu_clock_get_ns(rtc_clock),
8b1478
-                                      old_period);
8b1478
+                                      old_period, true);
8b1478
             }
8b1478
 
8b1478
             check_update_timer(s);
8b1478
@@ -572,7 +573,7 @@ static void cmos_ioport_write(void *opaque, hwaddr addr,
8b1478
 
8b1478
             if (update_periodic_timer) {
8b1478
                 periodic_timer_update(s, qemu_clock_get_ns(rtc_clock),
8b1478
-                                      old_period);
8b1478
+                                      old_period, true);
8b1478
             }
8b1478
 
8b1478
             check_update_timer(s);
8b1478
@@ -816,6 +817,7 @@ static int rtc_post_load(void *opaque, int version_id)
8b1478
         s->offset = 0;
8b1478
         check_update_timer(s);
8b1478
     }
8b1478
+    s->period = rtc_periodic_clock_ticks(s);
8b1478
 
8b1478
     /* The periodic timer is deterministic in record/replay mode,
8b1478
      * so there is no need to update it after loading the vmstate.
8b1478
@@ -825,7 +827,7 @@ static int rtc_post_load(void *opaque, int version_id)
8b1478
         uint64_t now = qemu_clock_get_ns(rtc_clock);
8b1478
         if (now < s->next_periodic_time ||
8b1478
             now > (s->next_periodic_time + get_max_clock_jump())) {
8b1478
-            periodic_timer_update(s, qemu_clock_get_ns(rtc_clock), 0);
8b1478
+            periodic_timer_update(s, qemu_clock_get_ns(rtc_clock), s->period, false);
8b1478
         }
8b1478
     }
8b1478
 
8b1478
@@ -893,7 +895,7 @@ static void rtc_notify_clock_reset(Notifier *notifier, void *data)
8b1478
     int64_t now = *(int64_t *)data;
8b1478
 
8b1478
     rtc_set_date_from_host(ISA_DEVICE(s));
8b1478
-    periodic_timer_update(s, now, 0);
8b1478
+    periodic_timer_update(s, now, s->period, false);
8b1478
     check_update_timer(s);
8b1478
 
8b1478
     if (s->lost_tick_policy == LOST_TICK_POLICY_SLEW) {
8b1478
-- 
8b1478
1.8.3.1
8b1478