]> www.infradead.org Git - users/dwmw2/linux.git/commit
KVM: x86/xen: Prevent runstate times from becoming negative
authorDavid Woodhouse <dwmw@amazon.co.uk>
Wed, 15 May 2024 11:54:57 +0000 (12:54 +0100)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Fri, 2 Aug 2024 14:52:55 +0000 (15:52 +0100)
commit3a8d18d5948c294455a60461f183ff550bbfc620
treed4586b59b1037c49567f5b657401b0b3a70edd0e
parentf1dbff578a60f6d0619b2e641ac10cc7a9ddfcf9
KVM: x86/xen: Prevent runstate times from becoming negative

When kvm_xen_update_runstate() is invoked to set a vCPU's runstate, the
time spent in the previous runstate is accounted. This is based on the
delta between the current KVM clock time, and the previous value stored
in vcpu->arch.xen.runstate_entry_time.

If the KVM clock goes backwards, that delta will be negative. Or, since
it's an unsigned 64-bit integer, very *large*. Linux guests deal with
that particularly badly, reporting 100% steal time for ever more (well,
for *centuries* at least, until the delta has been consumed).

So when a negative delta is detected, just refrain from updating the
runstates until the KVM clock catches up with runstate_entry_time again.

The userspace APIs for setting the runstate times do not allow them to
be set past the current KVM clock, but userspace can still adjust the
KVM clock *after* setting the runstate times, which would cause this
situation to occur.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Paul Durrant <paul@xen.org>
arch/x86/kvm/xen.c