qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hw/ptimer: Assert next_event is newer than last_event
@ 2019-09-21 10:17 Philippe Mathieu-Daudé
  2019-09-23 14:40 ` Peter Maydell
  0 siblings, 1 reply; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-09-21 10:17 UTC (permalink / raw)
  To: qemu-trivial, qemu-devel
  Cc: Peter Maydell, Dmitry Osipenko, Philippe Mathieu-Daudé,
	Paolo Bonzini

If the period is too big, the 'delta * period' product result
might overflow, resulting in a negative number, then the
next_event ends before the last_event. This is buggy, as there
is no forward progress. Assert this can not happen.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/core/ptimer.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c
index d58e2dfdb0..88085d4c81 100644
--- a/hw/core/ptimer.c
+++ b/hw/core/ptimer.c
@@ -125,6 +125,9 @@ static void ptimer_reload(ptimer_state *s, int delta_adjust)
 
     s->last_event = s->next_event;
     s->next_event = s->last_event + delta * period;
+    /* Verify forward progress */
+    g_assert(s->next_event > s->last_event);
+
     if (period_frac) {
         s->next_event += ((int64_t)period_frac * delta) >> 32;
     }
-- 
2.20.1



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

end of thread, other threads:[~2019-09-23 15:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-09-21 10:17 [PATCH] hw/ptimer: Assert next_event is newer than last_event Philippe Mathieu-Daudé
2019-09-23 14:40 ` Peter Maydell
2019-09-23 14:54   ` Philippe Mathieu-Daudé
2019-09-23 15:08     ` Peter Maydell
2019-09-23 15:11       ` Philippe Mathieu-Daudé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).