mbox series

[v2,0/3] RFC: Precise TSC migration

Message ID 20201203171118.372391-1-mlevitsk@redhat.com (mailing list archive)
Headers show
Series RFC: Precise TSC migration | expand

Message

Maxim Levitsky Dec. 3, 2020, 5:11 p.m. UTC
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(-)

Comments

Marcelo Tosatti Dec. 7, 2020, 11:16 p.m. UTC | #1
On Thu, Dec 03, 2020 at 07:11:15PM +0200, Maxim Levitsky wrote:
> 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

Maxim,

Can you please make a description of what is the practical problem that is 
being fixed, preferably with instructions on how to reproduce ?

> 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(-)
> 
> -- 
> 2.26.2
>
Paolo Bonzini Dec. 10, 2020, 11:48 a.m. UTC | #2
I'm queueing patches 2 and 3 for now, since the sane MSR interface is a 
prerequisite anyway.

Paolo

On 03/12/20 18:11, Maxim Levitsky wrote:
> 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(-)
>