All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] replay: split long instruction gaps into several EVENT_INSTRUCTION
@ 2026-12-02 13:20 Arkadiusz Grzelka via qemu development
  2026-12-02 15:35 ` Alex Bennée
  0 siblings, 1 reply; 2+ messages in thread
From: Arkadiusz Grzelka via qemu development @ 2026-12-02 13:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, alex.bennee

In record mode the instruction count is written only when a replay
event happens. A guest that spins with no timer, interrupt or I/O
(and with -icount sleep=off, so no warp checkpoint is taken) produces
no event, and the gap since the last one grows without bound.

replay_advance_current_icount() truncates that gap to an int. Past
2^31 instructions the final replay_save_instructions() from
replay_finish() sees a negative value and aborts on
assert(diff >= 0), leaving an empty log. Past 2^32 the value wraps
positive again and the log silently holds a count 2^32 too small, so
the replay ends early.

Compute the gap as int64_t and write it as several EVENT_INSTRUCTION
records of at most INT32_MAX each; the reader keeps the count in an
int. Replay already consumes consecutive EVENT_INSTRUCTION records:
when one is used up, replay_finish_event() fetches the next one. The
log format and REPLAY_VERSION are unchanged.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/5067
Fixes: 26bc60ac82f8 ("replay: introduce icount event")
Signed-off-by: Arkadiusz Grzelka <arkadiusz.grzelka@arivemb.com>
---
Reproduced:

aarch64 -M virt -cpu cortex-a57, guest 00 00 00 14 (b .) as -bios,
-icount shift=0,sleep=off,rr=record, stopped past 2^31 + 2^27.

Checked after the fix:

- SIGTERM and QMP quit: exit 0, logs of 144 and 155 bytes.
- Replay with replay-break 2^20 before the end, and on the 2^31 and 2^32
  record boundaries: STOP at the exact count.
- An unpatched binary replays a split log correctly; log format and
  REPLAY_VERSION unchanged.
- Not tested: snapshots or replay-seek inside a split gap.

 replay/replay-internal.c | 11 +++++++----
 replay/trace-events      |  2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/replay/replay-internal.c b/replay/replay-internal.c
index 4839f2b632..89ca98389c 100644
--- a/replay/replay-internal.c
+++ b/replay/replay-internal.c
@@ -278,17 +278,20 @@ void replay_mutex_unlock(void)
 
 void replay_advance_current_icount(uint64_t current_icount)
 {
-    int diff = (int)(current_icount - replay_state.current_icount);
+    int64_t diff = current_icount - replay_state.current_icount;
 
     /* Time can only go forward */
     trace_replay_advance_current_icount(replay_state.current_icount, diff);
     assert(diff >= 0);
 
     if (replay_mode == REPLAY_MODE_RECORD) {
-        if (diff > 0) {
+        while (diff > 0) {
+            int32_t step = MIN(diff, INT32_MAX);
+
             replay_put_event(EVENT_INSTRUCTION);
-            replay_put_dword(diff);
-            replay_state.current_icount += diff;
+            replay_put_dword(step);
+            replay_state.current_icount += step;
+            diff -= step;
         }
     } else if (replay_mode == REPLAY_MODE_PLAY) {
         if (diff > 0) {
diff --git a/replay/trace-events b/replay/trace-events
index e9c887a6c5..290c08809f 100644
--- a/replay/trace-events
+++ b/replay/trace-events
@@ -9,4 +9,4 @@ replay_get_dword(uint32_t dword) "%08x"
 replay_get_qword(uint64_t qword) "%016" PRIx64
 replay_fetch_data_kind(void) ""
 replay_get_event(uint32_t current, uint8_t data) "#%u data=%02x"
-replay_advance_current_icount(uint64_t current_icount, int diff) "current=%" PRIu64 " diff=%d"
+replay_advance_current_icount(uint64_t current_icount, int64_t diff) "current=%" PRIu64 " diff=%" PRId64

base-commit: 3c061218fcf37a98c944ecb88cff56f94f5c0a43
-- 
2.43.0




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

* Re: [PATCH] replay: split long instruction gaps into several EVENT_INSTRUCTION
  2026-12-02 13:20 [PATCH] replay: split long instruction gaps into several EVENT_INSTRUCTION Arkadiusz Grzelka via qemu development
@ 2026-12-02 15:35 ` Alex Bennée
  0 siblings, 0 replies; 2+ messages in thread
From: Alex Bennée @ 2026-12-02 15:35 UTC (permalink / raw)
  To: Arkadiusz Grzelka; +Cc: qemu-devel, pbonzini

Arkadiusz Grzelka <arkadiusz.grzelka@arivemb.com> writes:

> In record mode the instruction count is written only when a replay
> event happens. A guest that spins with no timer, interrupt or I/O
> (and with -icount sleep=off, so no warp checkpoint is taken) produces
> no event, and the gap since the last one grows without bound.

What sort of guest has no timers, IRQ or I/O?

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


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

end of thread, other threads:[~2026-12-02 15:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 13:20 [PATCH] replay: split long instruction gaps into several EVENT_INSTRUCTION Arkadiusz Grzelka via qemu development
2026-12-02 15:35 ` Alex Bennée

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.