From 0aeb585c430c10ba9f85eb021b16bd71039c76d8 Mon Sep 17 00:00:00 2001 From: jipengfei Date: Fri, 30 Jun 2023 21:45:27 +0800 Subject: [PATCH] icount: don't adjust virtual time backwards after warp The icount-based QEMU_CLOCK_VIRTUAL runs ahead of the RT clock at times. When warping, it is possible it is still ahead at the end of the warp, which causes icount adaptive mode to adjust it backward. This can result in the machine observing time going backwards. Prevent this by clamping adaptive adjustment to 0 at minimum. cheery-pick from 67f85346ca9305d9fb3254ceff735ceaadeb0911 Signed-off-by: jipengfei_yewu Signed-off-by: Nicholas Piggin Message-ID: <20230627061406.241847-1-npiggin@gmail.com> Cc: qemu-stable@nongnu.org Signed-off-by: Paolo Bonzini --- softmmu/icount.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/softmmu/icount.c b/softmmu/icount.c index 21341a4ce4..7cda8b6c31 100644 --- a/softmmu/icount.c +++ b/softmmu/icount.c @@ -261,10 +261,15 @@ static void icount_warp_rt(void) if (icount_enabled() == 2) { /* * In adaptive mode, do not let QEMU_CLOCK_VIRTUAL run too - * far ahead of real time. + * far ahead of real time.(it might already be ahead so careful not + * to go backwards). */ int64_t cur_icount = icount_get_locked(); int64_t delta = clock - cur_icount; + + if (delta < 0) { + delta = 0; + } warp_delta = MIN(warp_delta, delta); } qatomic_set_i64(&timers_state.qemu_icount_bias, -- Gitee