From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DEACF606A323 for ; Wed, 2 Dec 2026 16:35:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=SQ/f7wP2 Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xYnIl-0003rQ-Sb; Wed, 02 Dec 2026 11:35:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xYnIj-0003pz-Od for qemu-devel@nongnu.org; Wed, 02 Dec 2026 11:35:25 -0500 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xYnIh-0004LL-F9 for qemu-devel@nongnu.org; Wed, 02 Dec 2026 11:35:25 -0500 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4bba5e17cbeso70964085e9.1 for ; Wed, 02 Dec 2026 08:35:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1796229321; x=1796834121; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:message-id:date :user-agent:references:in-reply-to:subject:cc:to:from:from:to:cc :subject:date:message-id:reply-to:content-type; bh=R7v2069F08qOWzdOZfTMnhjgX3mpJ68zk6eWAj0gQ5A=; b=SQ/f7wP2aFvaBW+Qpy3jI2iEA2lw1884XWP/5MzbbSQQdEw6WglPh+mBCKkMdLIjUb NV0Lu3RXPBgmJ5jutfVBPbQJtQGhq2OYAxGj5PyAbR5CTuwhaTV/jIykCNM/bF8zCZYb H2ldDDDLZsG3MD+LaE89zQToxtOetL0+CV5XWZsBC6Xmimgzz7yKRiMgu0ENQgs3TIMs BcwEsxYdgg43lpOkdujTgP89aOQMXi0n4loxbolftX4iUCYTRVr/uKyIHXeLV3GqQor7 qCfJvuGwZ5NxKdLTEUJSb1h7SEfemDKbvkNngdRcan6bZl241aLOMgWvZw0vCM5Kt25R 7aBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796229321; x=1796834121; h=content-transfer-encoding:content-type:mime-version:message-id:date :user-agent:references:in-reply-to:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=R7v2069F08qOWzdOZfTMnhjgX3mpJ68zk6eWAj0gQ5A=; b=mLytrUeIPMS5tIQKscR/yroBQ4i72ci7CuGCu3b66pjo/U10m6DWXuRT5NpiCTNe5O +tre+klfpcMh6M8E3iJpW+kwOWqvPMVfBB9IO52iINjvJ/bjIgf1RPT/kidHenedAeaK CxYnH4w+/ktXRlF/JgbbdEcBFZ/J0e12LYu0+M9fKpKRi16osccvjeAoMU2rMsGKXjKz 469GzN9EwXZkuUJIl3zY1P1+JrzqyOikLyepK52Ym1MBQJxx4TyqxMVwGiY5zKnOfmIU uO28Ie1DJ1s8F1sd2ri6aSSK6GkL4hFYxgoK5k24DB4Ovzmui8KUsBoLyHdfQ75ydB5j onzA== X-Gm-Message-State: APuU4Z9RyWSRu+jYctYdXDqCWk33f96rwBNLeCGrW7NlWuyFAqjw9Ilt h1qm4YE8Oh+QTwURH+TE0vYgSBu3+64CJkfwSqssr/+wnh1kH0GA7SV7vOfxbfgp1Ck= X-Gm-Gg: AZFdTZdN+5cNgX3KvmGFbvn6HPxx7YxVOT6NjgR17hVJULs3CsM7rTF8TbC/0oenbq1 vn9cHUNxKxjeQcjXsl/sVQUBblfMPQpwrgawwObWWCZKKbncypaYp0ly2FUz6xAuAvkvwnEasDS b5BP6meI3ZLLoPVmyDy1CwH5BUILeHruq+PRM+GiyWkzOjJbj+V23WCH00VuoY487Wk6sgDZZ6C iNRcgms9uL/zrZpK8vAWC2ib8T8tZ0NJXw+GPZslo4oUji0WX7qAqxtsnYIGX+WiVg/wCZwrRlZ 6ksrxO2FfvGMY+PaLHyVut+x1jrkZrsCohU+QsHIClDfJls6U4n9avwGZPqdKNF/7z2o43rtviJ KRx+C1/MJSaG4pDnnzpjmilyS8LbvdZFSs+j1yu6FHSm3V4EaljrMPcwmYjp8ENukTgYXMmJus9 yxNpmn9OBM6x0K/oNIcfxqMhgWRBO5ypPJh8bDNPIhQt7I9lfHApydM9ZYmgmrCYKHrWHF+vEPJ 9En6czlOSUIdDjAaKclIS0YFzYpe/G6HKGSqxrwlzS1jelfAi0ri68WDkc/p5oyxy+a09Lz5eCs ix6mH40CzP1xIxdcR9FFt+CNp//a X-Received: by 2002:a05:600c:83ca:b0:4a1:9661:14b5 with SMTP id 5b1f17b1804b1-4bb888176eamr865955695e9.29.1796229320737; Wed, 02 Dec 2026 08:35:20 -0800 (PST) Received: from draig.lan ([185.124.0.158]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbcf2c9e64sm56648005e9.3.2026.12.02.08.35.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 08:35:20 -0800 (PST) Received: from draig (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id D55915F9CE; Wed, 02 Dec 2026 16:35:18 +0000 (GMT) From: =?utf-8?Q?Alex_Benn=C3=A9e?= To: Arkadiusz Grzelka via qemu development Cc: Arkadiusz Grzelka , pbonzini@redhat.com, peterx@redhat.com, farosas@suse.de, iii@linux.ibm.com, qemu-stable@nongnu.org Subject: Re: [PATCH] util/qemu-timer: restore expired timers into the list on snapshot load In-Reply-To: <20261202132036.7-1-arkadiusz.grzelka@arivemb.com> (Arkadiusz Grzelka via qemu development's message of "Wed, 2 Dec 2026 13:20:36 +0000") References: <20261202132036.7-1-arkadiusz.grzelka@arivemb.com> User-Agent: mu4e 1.14.5-pre2; emacs 30.1 Date: Wed, 02 Dec 2026 16:35:18 +0000 Message-ID: <87o6b31vzt.fsf@draig.linaro.org> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x332.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org X-Spam-Status: No, score=-20.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Arkadiusz Grzelka via qemu development writes: > Since commit f098c32db487, timer_mod_ns() turns a QEMU_CLOCK_VIRTUAL timer > armed already expired into CPU work when record/replay is active, so > that its callback is ordered against CPU work deterministically. > > timer_get() restores timers from a snapshot through timer_mod_ns() as > well. A snapshot taken in replay at the exact instruction count where a > virtual timer is due holds that timer pending and expired, and the log > at that point expects the CHECKPOINT_CLOCK_VIRTUAL at which it fires. > On load the timer is converted to CPU work, its callback runs without > consuming the checkpoint, and nothing is left to consume it: the vCPU > gets no instruction budget and the replay hangs. Reverse debugging hits > this whenever reverse-step or reverse-continue loads such a snapshot. > > Such a timer is not armed anew; it was pending when the state was saved > and fired from the timer list in the original run. Add > timer_restore_ns(), which puts the timer back in the list as it was, > and use it in timer_get(). Timers armed by device code, including from > post_load hooks as in the s390x case, still go through timer_mod_ns(). > > Resolves: https://gitlab.com/qemu-project/qemu/-/issues/5068 > Fixes: f098c32db487 ("target/s390x: Fix infinite loop during replay") > Signed-off-by: Arkadiusz Grzelka > --- > Reproduced: > > aarch64 -M virt -cpu cortex-a57, bare-metal guest with the CNTV timer > every 1 ms through the GICv2. Snapshot at a timer checkpoint count: > replay from it killed after 30 s. One instruction later: finishes in 32 > ms. I think this would benefit with a test case that replicates the failure and could be kept as a regression test. It would probably be a functional test although you could probably create a softmmu tcg test instead if the code for the guest isn't overly complex. > > Checked after the fix: > > - Replay from the same snapshot: exit 0 in 31 ms. > - gdb: bs and bc across the snapshots work; register state at the > breakpoint identical in all 6 runs (before and after, snapshot offset > 0, 1 and init only). > - Not tested: s390x (the case f098c32db487 fixed), upstream functional > replay tests. > > include/qemu/timer.h | 15 +++++++++++++++ > migration/savevm.c | 2 +- > util/qemu-timer.c | 24 ++++++++++++++++++++---- > 3 files changed, 36 insertions(+), 5 deletions(-) > > diff --git a/include/qemu/timer.h b/include/qemu/timer.h > index 9a62ac8cde..2f16865ccc 100644 > --- a/include/qemu/timer.h > +++ b/include/qemu/timer.h > @@ -652,6 +652,21 @@ static inline void timer_free(QEMUTimer *ts) > */ > void timer_mod_ns(QEMUTimer *ts, int64_t expire_time); >=20=20 > +/** > + * timer_restore_ns: > + * @ts: the timer > + * @expire_time: the expiry time in nanoseconds > + * > + * Re-arm a timer from saved state to expire at @expire_time. Unlike > + * timer_mod_ns(), a timer that has already expired stays in the timer > + * list in record/replay mode, so that it fires at its recorded > + * checkpoint. > + * > + * This function is thread-safe but the timer and its timer list must no= t be > + * freed while this function is running. > + */ > +void timer_restore_ns(QEMUTimer *ts, int64_t expire_time); > + > /** > * timer_mod_anticipate_ns: > * @ts: the timer > diff --git a/migration/savevm.c b/migration/savevm.c > index fe94ba96e4..13a4898b28 100644 > --- a/migration/savevm.c > +++ b/migration/savevm.c > @@ -199,7 +199,7 @@ void timer_get(QEMUFile *f, QEMUTimer *ts) >=20=20 > expire_time =3D qemu_get_be64(f); > if (expire_time !=3D -1) { > - timer_mod_ns(ts, expire_time); > + timer_restore_ns(ts, expire_time); > } else { > timer_del(ts); > } > diff --git a/util/qemu-timer.c b/util/qemu-timer.c > index d93a020064..e4e32caff9 100644 > --- a/util/qemu-timer.c > +++ b/util/qemu-timer.c > @@ -396,7 +396,8 @@ static void timer_fire(CPUState *cpu, run_on_cpu_data= data) > } >=20=20 > static bool timer_mod_ns_locked(QEMUTimerList *timer_list, > - QEMUTimer *ts, int64_t expire_time) > + QEMUTimer *ts, int64_t expire_time, > + bool restore) > { > QEMUTimer **pt, *t; >=20=20 > @@ -413,7 +414,7 @@ static bool timer_mod_ns_locked(QEMUTimerList *timer_= list, > * > * Convert such timers to CPU work in order to avoid it. > */ > - if (replay_mode !=3D REPLAY_MODE_NONE && > + if (!restore && replay_mode !=3D REPLAY_MODE_NONE && > timer_list->clock->type =3D=3D QEMU_CLOCK_VIRTUAL && > !(ts->attributes & QEMU_TIMER_ATTR_EXTERNAL) && > expire_time <=3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)) { > @@ -464,7 +465,22 @@ void timer_mod_ns(QEMUTimer *ts, int64_t expire_time) >=20=20 > qemu_mutex_lock(&timer_list->active_timers_lock); > timer_del_locked(timer_list, ts); > - rearm =3D timer_mod_ns_locked(timer_list, ts, expire_time); > + rearm =3D timer_mod_ns_locked(timer_list, ts, expire_time, false); > + qemu_mutex_unlock(&timer_list->active_timers_lock); > + > + if (rearm) { > + timerlist_rearm(timer_list); > + } > +} > + > +void timer_restore_ns(QEMUTimer *ts, int64_t expire_time) > +{ > + QEMUTimerList *timer_list =3D ts->timer_list; > + bool rearm; > + > + qemu_mutex_lock(&timer_list->active_timers_lock); > + timer_del_locked(timer_list, ts); > + rearm =3D timer_mod_ns_locked(timer_list, ts, expire_time, true); > qemu_mutex_unlock(&timer_list->active_timers_lock); >=20=20 > if (rearm) { > @@ -485,7 +501,7 @@ void timer_mod_anticipate_ns(QEMUTimer *ts, int64_t e= xpire_time) > if (ts->expire_time !=3D -1) { > timer_del_locked(timer_list, ts); > } > - rearm =3D timer_mod_ns_locked(timer_list, ts, expire_time); > + rearm =3D timer_mod_ns_locked(timer_list, ts, expire_time, f= alse); > } else { > rearm =3D false; > } > > base-commit: 3c061218fcf37a98c944ecb88cff56f94f5c0a43 --=20 Alex Benn=C3=A9e Virtualisation Tech Lead @ Linaro