icount_get() and icount_get_raw() fold the running vCPU's
executed instructions into qemu_icount inside the seqlock
read section, without holding vm_clock_lock.
In adaptive icount (-icount shift=auto), icount_adjust()
reads qemu_icount twice under the write lock; a vCPU update
landing in between is lost from QEMU_CLOCK_VIRTUAL (up to
0xffff instructions). Targets reading the clock from a
helper without the BQL can hit it, e.g. the RISC-V
cycle/instret CSRs.
(It is also a prerequisite for reading the Arm generic timer
counters without the BQL, which will follow as distinct series).
First refactor the helpers (patches 1 and 2) then performs the
update under the write lock before reading, so readers never
write (patch 3).
Reproduced on riscv64 'virt' by widening the window with an injected
delay: 7 hits in ~350 adjust windows before, none in 234 after.
Philippe Mathieu-Daudé (3):
accel/tcg: Factor icount_running_cpu() out
accel/tcg: Factor icount_to_virtual_ns() out
accel/tcg: Do not write qemu_icount from seqlock readers
accel/tcg/icount-common.c | 50 +++++++++++++++++++++++++++++++--------
1 file changed, 40 insertions(+), 10 deletions(-)
--
2.55.0