Commit b429de73 authored by Marcelo Tosatti's avatar Marcelo Tosatti Committed by Paolo Bonzini
Browse files

mc146818rtc: fix timer interrupt reinjection



commit 369b4135 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: default avatarMarcelo Tosatti <mtosatti@redhat.com>

Message-Id: <20191010123008.GA19158@amt.cnet>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 73284563
Loading
Loading
Loading
Loading
+27 −26
Original line number Diff line number Diff line
@@ -203,7 +203,12 @@ periodic_timer_update(RTCState *s, int64_t current_time, uint32_t old_period)

    period = rtc_periodic_clock_ticks(s);

    if (period) {
    if (!period) {
        s->irq_coalesced = 0;
        timer_del(s->periodic_timer);
        return;
    }

    /* compute 32 khz clock */
    cur_clock =
        muldiv64(current_time, RTC_CLOCK_RATE, NANOSECONDS_PER_SECOND);
@@ -220,7 +225,6 @@ periodic_timer_update(RTCState *s, int64_t current_time, uint32_t old_period)
        last_periodic_clock = next_periodic_clock - old_period;
        lost_clock = cur_clock - last_periodic_clock;
        assert(lost_clock >= 0);
        }

        /*
         * s->irq_coalesced can change for two reasons:
@@ -257,16 +261,13 @@ periodic_timer_update(RTCState *s, int64_t current_time, uint32_t old_period)
             */
            lost_clock = MIN(lost_clock, period);
        }
    }

    assert(lost_clock >= 0 && lost_clock <= period);

    next_irq_clock = cur_clock + period - lost_clock;
    s->next_periodic_time = periodic_clock_to_ns(next_irq_clock) + 1;
    timer_mod(s->periodic_timer, s->next_periodic_time);
    } else {
        s->irq_coalesced = 0;
        timer_del(s->periodic_timer);
    }
}

static void rtc_periodic_timer(void *opaque)