Skip to content

Commit 86ffc25

Browse files
maciejsszmigieroMichael Tokarev
authored andcommitted
target/i386: Reset parked vCPUs together with the online ones
Commit 3f2a05b ("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: 3f2a05b ("target/i386: Reset TSCs of parked vCPUs too on VM reset") Signed-off-by: Maciej S. Szmigiero <[email protected]> Link: https://lore.kernel.org/r/e8b85a5915f79aa177ca49eccf0e9b534470c1cd.1743099810.git.maciej.szmigiero@oracle.com Cc: [email protected] Signed-off-by: Paolo Bonzini <[email protected]> (cherry picked from commit f6b5f71) Signed-off-by: Michael Tokarev <[email protected]>
1 parent 3af56fc commit 86ffc25

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

accel/kvm/kvm-all.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,8 @@ int kvm_unpark_vcpu(KVMState *s, unsigned long vcpu_id)
437437
return kvm_fd;
438438
}
439439

440-
static void kvm_reset_parked_vcpus(void *param)
440+
static void kvm_reset_parked_vcpus(KVMState *s)
441441
{
442-
KVMState *s = param;
443442
struct KVMParkedVcpu *cpu;
444443

445444
QLIST_FOREACH(cpu, &s->kvm_parked_vcpus, node) {
@@ -2738,7 +2737,6 @@ static int kvm_init(MachineState *ms)
27382737
}
27392738

27402739
qemu_register_reset(kvm_unpoison_all, NULL);
2741-
qemu_register_reset(kvm_reset_parked_vcpus, s);
27422740

27432741
if (s->kernel_irqchip_allowed) {
27442742
kvm_irqchip_create(s);
@@ -2908,6 +2906,10 @@ static void do_kvm_cpu_synchronize_post_reset(CPUState *cpu, run_on_cpu_data arg
29082906
void kvm_cpu_synchronize_post_reset(CPUState *cpu)
29092907
{
29102908
run_on_cpu(cpu, do_kvm_cpu_synchronize_post_reset, RUN_ON_CPU_NULL);
2909+
2910+
if (cpu == first_cpu) {
2911+
kvm_reset_parked_vcpus(kvm_state);
2912+
}
29112913
}
29122914

29132915
static void do_kvm_cpu_synchronize_post_init(CPUState *cpu, run_on_cpu_data arg)

0 commit comments

Comments
 (0)