accel/tcg: Do not write qemu_icount from seqlock readers
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest3 patches 5 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | accel/tcg: Factor icount_running_cpu() outaccel/ | +17 | 2 replies | |
| 2/3 | accel/tcg: Factor icount_to_virtual_ns() outaccel/ | +7 | 2 replies | |
| 3/3 | accel/tcg: Do not write qemu_icount from seqlock readersaccel/ | +16 | 1 reply |
Reviews trailers per patch
2 of 3 patches have a Reviewed-by or Acked-by.
| Patch | Mohamed Mediouni | Pierrick Bouvier |
|---|---|---|
| 1/3 | R-b | R-b |
| 2/3 | R-b | R-b |
| 3/3 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH 0/3] accel/tcg: Do not write qemu_icount from seqlock readers
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(-)
Signature · 1 line
2.55.0