Skip to content

Commit 6c4927a

Browse files
committed
KVM: x86: Process "guest stopped request" once per guest time update
Handle "guest stopped" requests once per guest time update in preparation of restoring KVM's historical behavior of setting PVCLOCK_GUEST_STOPPED for kvmclock and only kvmclock. For now, simply move the code to minimize the probability of an unintentional change in functionally. Note, in practice, all clocks are guaranteed to see the request (or not) even though each PV clock processes the request individual, as KVM holds vcpu->mutex (blocks KVM_KVMCLOCK_CTRL) and it should be impossible for KVM's suspend notifier to run while KVM is handling requests. And because the helper updates the reference flags, all subsequent PV clock updates will pick up PVCLOCK_GUEST_STOPPED. Note #2, once PVCLOCK_GUEST_STOPPED is restricted to kvmclock, the horrific #ifdef will go away. Cc: Paul Durrant <pdurrant@amazon.com> Cc: David Woodhouse <dwmw@amazon.co.uk> Reviewed-by: Paul Durrant <paul@xen.org> Link: https://lore.kernel.org/r/20250201013827.680235-5-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent aceb04f commit 6c4927a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

arch/x86/kvm/x86.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3150,11 +3150,6 @@ static void kvm_setup_guest_pvclock(struct kvm_vcpu *v,
31503150
/* retain PVCLOCK_GUEST_STOPPED if set in guest copy */
31513151
vcpu->hv_clock.flags |= (guest_hv_clock->flags & PVCLOCK_GUEST_STOPPED);
31523152

3153-
if (vcpu->pvclock_set_guest_stopped_request) {
3154-
vcpu->hv_clock.flags |= PVCLOCK_GUEST_STOPPED;
3155-
vcpu->pvclock_set_guest_stopped_request = false;
3156-
}
3157-
31583153
memcpy(guest_hv_clock, &vcpu->hv_clock, sizeof(*guest_hv_clock));
31593154

31603155
if (force_tsc_unstable)
@@ -3264,6 +3259,18 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
32643259
if (use_master_clock)
32653260
vcpu->hv_clock.flags |= PVCLOCK_TSC_STABLE_BIT;
32663261

3262+
if (vcpu->pv_time.active
3263+
#ifdef CONFIG_KVM_XEN
3264+
|| vcpu->xen.vcpu_info_cache.active
3265+
|| vcpu->xen.vcpu_time_info_cache.active
3266+
#endif
3267+
) {
3268+
if (vcpu->pvclock_set_guest_stopped_request) {
3269+
vcpu->hv_clock.flags |= PVCLOCK_GUEST_STOPPED;
3270+
vcpu->pvclock_set_guest_stopped_request = false;
3271+
}
3272+
}
3273+
32673274
if (vcpu->pv_time.active)
32683275
kvm_setup_guest_pvclock(v, &vcpu->pv_time, 0, false);
32693276
#ifdef CONFIG_KVM_XEN

0 commit comments

Comments
 (0)