qemu/accel
Maciej S. Szmigiero f6b5f71f04 target/i386: Reset parked vCPUs together with the online ones
Commit 3f2a05b31e ("target/i386: Reset TSCs of parked vCPUs too on VM
reset") introduced a way to reset TSCs of parked vCPUs during VM reset to
prevent them getting desynchronized with the online vCPUs and therefore
causing the KVM PV clock to lose PVCLOCK_TSC_STABLE_BIT.

The way this was done was by registering a parked vCPU-specific QEMU reset
callback via qemu_register_reset().

However, it turns out that on particularly device-rich VMs QEMU reset
callbacks can take a long time to execute (which isn't surprising,
considering that they involve resetting all of VM devices).

In particular, their total runtime can exceed the 1-second TSC
synchronization window introduced in KVM commit 5d3cb0f6a8e3 ("KVM:
Improve TSC offset matching").
Since the TSCs of online vCPUs are only reset from "synchronize_post_reset"
AccelOps handler (which runs after all qemu_register_reset() handlers) this
essentially makes that fix ineffective on these VMs.

The easiest way to guarantee that these parked vCPUs are reset at the same
time as the online ones (regardless how long it takes for VM devices to
reset) is to piggyback on post-reset vCPU synchronization handler for one
of online vCPUs - as there is no generic post-reset AccelOps handler that
isn't per-vCPU.

The first online vCPU was selected for that since it is easily available
under "first_cpu" define.
This does not create an ordering issue since the order of vCPU TSC resets
does not matter.

Fixes: 3f2a05b31e ("target/i386: Reset TSCs of parked vCPUs too on VM reset")
Signed-off-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com>
Link: https://lore.kernel.org/r/e8b85a5915f79aa177ca49eccf0e9b534470c1cd.1743099810.git.maciej.szmigiero@oracle.com
Cc: qemu-stable@nongnu.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-17 18:23:26 +02:00
..
hvf accel: Forward-declare AccelOpsClass in 'qemu/typedefs.h' 2025-03-06 15:46:18 +01:00
kvm target/i386: Reset parked vCPUs together with the online ones 2025-04-17 18:23:26 +02:00
qtest accel: Forward-declare AccelOpsClass in 'qemu/typedefs.h' 2025-03-06 15:46:18 +01:00
stubs gdbstub: Check for TCG before calling tb_flush() 2025-03-06 15:46:17 +01:00
tcg accel: Prefer cached CpuClass over CPU_GET_CLASS() macro 2025-03-09 17:00:47 +01:00
xen accel: Forward-declare AccelOpsClass in 'qemu/typedefs.h' 2025-03-06 15:46:18 +01:00
accel-blocker.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
accel-system.c accel: Forward-declare AccelOpsClass in 'qemu/typedefs.h' 2025-03-06 15:46:18 +01:00
accel-system.h accel: Rename accel_init_ops_interfaces() to include 'system' 2024-01-19 12:28:59 +01:00
accel-target.c accel: Prefer cached CpuClass over CPU_GET_CLASS() macro 2025-03-09 17:00:47 +01:00
accel-user.c accel: extend AccelState and AccelClass to user-mode 2021-02-05 10:24:15 -10:00
dummy-cpus.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
Kconfig hw/xen: Link XenPVH with GPEX PCIe bridge 2025-03-04 14:45:34 +01:00
meson.build accel: Rename accel_softmmu* -> accel_system* 2023-10-07 19:02:57 +02:00