|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v13 09/26] KVM: x86: Stop TSC catchup when a frequency change no longer needs it
From: David Woodhouse <dwmw@xxxxxxxxxxxx>
On hardware without TSC scaling, KVM_SET_TSC_KHZ with a frequency above
the host's puts the vCPU into always-catchup mode. Nothing ever takes
it back out: a later KVM_SET_TSC_KHZ restoring a frequency within
tsc_tolerance_ppm of the host's, where no scaling or catchup is needed,
leaves the vCPU paying the catchup overhead on every clock update for
the rest of its life — and KVM_HC_CLOCK_PAIRING stays disabled, since
it rejects always-catchup mode.
Clear the pairing whenever set_tsc_khz() succeeds with a frequency
which does not need it. Only that pairing: tsc_catchup alone also
serves the unstable-host-TSC compensation in kvm_arch_vcpu_load(),
which must not be disturbed.
Fixes: cc578287e322 ("KVM: Infrastructure for software and hardware based TSC
rate scaling")
Signed-off-by: David Woodhouse <dwmw@xxxxxxxxxxxx>
---
arch/x86/kvm/x86.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 0b3b04a156da..1d4b66257b35 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1031,7 +1031,7 @@ static int set_tsc_khz(struct kvm_vcpu *vcpu, u32
user_tsc_khz, bool scale)
/* Guest TSC same frequency as host TSC? */
if (!scale) {
kvm_vcpu_write_tsc_multiplier(vcpu,
kvm_caps.default_tsc_scaling_ratio);
- return 0;
+ goto clear_catchup;
}
/* TSC scaling supported? */
@@ -1057,6 +1057,19 @@ static int set_tsc_khz(struct kvm_vcpu *vcpu, u32
user_tsc_khz, bool scale)
}
kvm_vcpu_write_tsc_multiplier(vcpu, ratio);
+
+clear_catchup:
+ /*
+ * A frequency which no longer needs catchup must also stop it: a
+ * previous above-host-rate setting on scaling-less hardware set
+ * the always-catchup flags, and nothing else ever clears them.
+ * Only undo that pairing — tsc_catchup alone also serves the
+ * unstable-host-TSC compensation in kvm_arch_vcpu_load().
+ */
+ if (vcpu->arch.tsc_always_catchup) {
+ vcpu->arch.tsc_always_catchup = 0;
+ vcpu->arch.tsc_catchup = 0;
+ }
return 0;
}
--
2.43.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |