From 22d73d1fe09f895bc4fef55b837a152091cbef66 Mon Sep 17 00:00:00 2001 From: Don Slutz Date: Fri, 2 May 2014 16:18:08 -0400 Subject: [PATCH] hvm/hpet: Detect comparator values in the past This statement only works using 64-bit arithmetic for the main 63 counter never changing by more then 2 . (Which is a boundary case that should not happen in my life time.) Signed-off-by: Don Slutz Acked-by: Tim Deegan --- xen/arch/x86/hvm/hpet.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/hvm/hpet.c b/xen/arch/x86/hvm/hpet.c index 2a99fed8c6..167994ed33 100644 --- a/xen/arch/x86/hvm/hpet.c +++ b/xen/arch/x86/hvm/hpet.c @@ -98,10 +98,12 @@ static uint64_t hpet_get_comparator(HPETState *h, unsigned int tn, uint64_t period = h->hpet.period[tn]; if (period) { - elapsed = hpet_read_maincounter(h, guest_time) + - period - comparator; - comparator += (elapsed / period) * period; - h->hpet.comparator64[tn] = comparator; + elapsed = hpet_read_maincounter(h, guest_time) - comparator; + if ( (int64_t)elapsed >= 0 ) + { + comparator += ((elapsed + period) / period) * period; + h->hpet.comparator64[tn] = comparator; + } } } -- 2.39.5