replay: fix icount request when replaying clock access

Record/replay provides REPLAY_CLOCK_LOCKED macro to access
the clock when vm_clock_seqlock is locked. This macro is
needed because replay internals operate icount. In locked case
replay use icount_get_raw_locked for icount request, which prevents
excess locking which leads to deadlock. But previously only
record code used *_locked function and replay did not.
Therefore sometimes clock access lead to deadlocks.
This patch fixes clock access for replay too and uses *_locked
icount access function.

Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgalyuk@ispras.ru>
Message-Id: <161347990483.1313189.8371838968343494161.stgit@pasha-ThinkPad-X280>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Pavel Dovgalyuk 2021-02-16 15:51:44 +03:00 committed by Paolo Bonzini
parent 82e2756897
commit 366a85e4bb
5 changed files with 37 additions and 35 deletions

View file

@ -247,10 +247,31 @@ void replay_advance_current_icount(uint64_t current_icount)
/* Time can only go forward */
assert(diff >= 0);
if (diff > 0) {
replay_put_event(EVENT_INSTRUCTION);
replay_put_dword(diff);
replay_state.current_icount += diff;
if (replay_mode == REPLAY_MODE_RECORD) {
if (diff > 0) {
replay_put_event(EVENT_INSTRUCTION);
replay_put_dword(diff);
replay_state.current_icount += diff;
}
} else if (replay_mode == REPLAY_MODE_PLAY) {
if (diff > 0) {
replay_state.instruction_count -= diff;
replay_state.current_icount += diff;
if (replay_state.instruction_count == 0) {
assert(replay_state.data_kind == EVENT_INSTRUCTION);
replay_finish_event();
/* Wake up iothread. This is required because
timers will not expire until clock counters
will be read from the log. */
qemu_notify_event();
}
}
/* Execution reached the break step */
if (replay_break_icount == replay_state.current_icount) {
/* Cannot make callback directly from the vCPU thread */
timer_mod_ns(replay_break_timer,
qemu_clock_get_ns(QEMU_CLOCK_REALTIME));
}
}
}