Hi!
This is the second version of the work to make TSC migration more accurate, as was defined by Paulo at: https://www.spinics.net/lists/kvm/msg225525.html
I omitted most of the semi-offtopic points I raised related to TSC in the previous RFC where we can continue the discussion.
I do want to raise another thing that I almost forgot.
On AMD systems, the Linux kernel will mark the guest tsc as unstable unless invtsc is set which is set on recent AMD hardware.
Take a look at 'unsynchronized_tsc()' to verify this.
This is another thing that IMHO should be fixed at least when running under KVM.
Note that I forgot to mention that X86_FEATURE_TSC_RELIABLE also short-circuits this code, thus giving another reason to enable it under KVM.
Changes from V1:
- added KVM_TSC_STATE_TIMESTAMP_VALID instead of testing ns == 0 - allow diff < 0, because it is still better that capping it to 0 - updated tsc_msr_test unit test to cover this feature - refactoring
Patches to enable this feature in qemu are in the process of being sent to qemu-devel mailing list.
Best regards, Maxim Levitsky
Maxim Levitsky (3): KVM: x86: implement KVM_{GET|SET}_TSC_STATE KVM: x86: introduce KVM_X86_QUIRK_TSC_HOST_ACCESS kvm/selftests: update tsc_msrs_test to cover KVM_X86_QUIRK_TSC_HOST_ACCESS
Documentation/virt/kvm/api.rst | 65 +++++++++++++ arch/x86/include/uapi/asm/kvm.h | 1 + arch/x86/kvm/x86.c | 92 ++++++++++++++++++- include/uapi/linux/kvm.h | 15 +++ .../selftests/kvm/x86_64/tsc_msrs_test.c | 79 ++++++++++++++-- 5 files changed, 237 insertions(+), 15 deletions(-)