Skip to content

Commit 93fb0b1

Browse files
committed
KVM: x86: Set PVCLOCK_GUEST_STOPPED only for kvmclock, not for Xen PV clock
Handle "guest stopped" propagation only for kvmclock, as the flag is set if and only if kvmclock is "active", i.e. can only be set for Xen PV clock if kvmclock *and* Xen PV clock are in-use by the guest, which creates very bizarre behavior for the guest. Simply restrict the flag to kvmclock, e.g. instead of trying to handle Xen PV clock, as propagation of PVCLOCK_GUEST_STOPPED was unintentionally added during a refactoring, and while Xen proper defines XEN_PVCLOCK_GUEST_STOPPED, there's no evidence that Xen guests actually support the flag. Check and clear pvclock_set_guest_stopped_request if and only if kvmclock is active to preserve the original behavior, i.e. keep the flag pending if kvmclock happens to be disabled when KVM processes the initial request. Fixes: aa096aa ("KVM: x86/xen: setup pvclock updates") 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-8-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 24c1663 commit 93fb0b1

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

arch/x86/kvm/x86.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3262,20 +3262,21 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
32623262
if (use_master_clock)
32633263
vcpu->hv_clock.flags |= PVCLOCK_TSC_STABLE_BIT;
32643264

3265-
if (vcpu->pv_time.active
3266-
#ifdef CONFIG_KVM_XEN
3267-
|| vcpu->xen.vcpu_info_cache.active
3268-
|| vcpu->xen.vcpu_time_info_cache.active
3269-
#endif
3270-
) {
3265+
if (vcpu->pv_time.active) {
3266+
/*
3267+
* GUEST_STOPPED is only supported by kvmclock, and KVM's
3268+
* historic behavior is to only process the request if kvmclock
3269+
* is active/enabled.
3270+
*/
32713271
if (vcpu->pvclock_set_guest_stopped_request) {
32723272
vcpu->hv_clock.flags |= PVCLOCK_GUEST_STOPPED;
32733273
vcpu->pvclock_set_guest_stopped_request = false;
32743274
}
3275+
kvm_setup_guest_pvclock(v, &vcpu->pv_time, 0, false);
3276+
3277+
vcpu->hv_clock.flags &= ~PVCLOCK_GUEST_STOPPED;
32753278
}
32763279

3277-
if (vcpu->pv_time.active)
3278-
kvm_setup_guest_pvclock(v, &vcpu->pv_time, 0, false);
32793280
#ifdef CONFIG_KVM_XEN
32803281
if (vcpu->xen.vcpu_info_cache.active)
32813282
kvm_setup_guest_pvclock(v, &vcpu->xen.vcpu_info_cache,

0 commit comments

Comments
 (0)