All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rtc/mc146818rtc: fix QEMU crash when time runs backwards
@ 2025-11-13  3:02 shenjiatong
  2026-07-15  7:13 ` Michael S. Tsirkin
  0 siblings, 1 reply; 2+ messages in thread
From: shenjiatong @ 2025-11-13  3:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, pbonzini, shenjiatong

Loosen restriction on computed lost_tick. When QEMU's rtc_clock is set
to host, the walltime is used for mc146818rtc which requires computed
lost_tick to be strictly non-negative. But host walltime could possibly
run backwards, for example, configured by NTP service. Under such
circumstances QEMU process could crash unexpectly. This situation is
easy to reproduce for Windows 2012/2016 guests.
---
 hw/rtc/mc146818rtc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/hw/rtc/mc146818rtc.c b/hw/rtc/mc146818rtc.c
index 8631386b9f..04185eb6e9 100644
--- a/hw/rtc/mc146818rtc.c
+++ b/hw/rtc/mc146818rtc.c
@@ -173,8 +173,7 @@ static void periodic_timer_update(MC146818RtcState *s, int64_t current_time,
         next_periodic_clock = muldiv64(s->next_periodic_time,
                                 RTC_CLOCK_RATE, NANOSECONDS_PER_SECOND);
         last_periodic_clock = next_periodic_clock - old_period;
-        lost_clock = cur_clock - last_periodic_clock;
-        assert(lost_clock >= 0);
+        lost_clock = MAX(cur_clock - last_periodic_clock, 0);
     }
 
     /*
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-15  7:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-13  3:02 [PATCH] rtc/mc146818rtc: fix QEMU crash when time runs backwards shenjiatong
2026-07-15  7:13 ` Michael S. Tsirkin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.