]> www.infradead.org Git - users/dwmw2/linux.git/commit
KVM: x86: Improve accuracy of KVM clock when TSC scaling is in force
authorDavid Woodhouse <dwmw@amazon.co.uk>
Wed, 17 Apr 2024 18:49:01 +0000 (19:49 +0100)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Fri, 19 Apr 2024 16:14:24 +0000 (17:14 +0100)
commit8a8ec4703b36fffa273b78ebf1e97a7380069b5b
treebb96a69f51600f020a935c7fa29c8384f4278454
parent76fd8f37b6705de91bdbf5193ee46eecffb1960a
KVM: x86: Improve accuracy of KVM clock when TSC scaling is in force

The kvm_guest_time_update() function scales the host TSC frequency to
the guest's using kvm_scale_tsc() and the v->arch.l1_tsc_scaling_ratio
scaling ratio previously calculated for that vCPU. Then calcuates the
scaling factors for the KVM clock itself based on that guest TSC
frequency.

However, it uses kHz as the unit when scaling, and then multiplies by
1000 only at the end.

With a host TSC frequency of 3000MHz and a guest set to 2500MHz, the
result of kvm_scale_tsc() will actually come out at 2,499,999kHz. So
the KVM clock advertised to the guest is based on a frequency of
2,499,999,000 Hz.

By using Hz as the unit from the beginning, the KVM clock would be based
on a more accurate frequency of 2,499,999,999 Hz in this example.

Fixes: 78db6a503796 ("KVM: x86: rewrite handling of scaled TSC for kvmclock")
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Paul Durrant <paul@xen.org>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/x86.c
arch/x86/kvm/xen.c