KVM: x86: do not attempt TSC synchronization on guest writes
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 24 Sep 2020 12:45:27 +0000 (14:45 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 28 Sep 2020 11:59:52 +0000 (07:59 -0400)
commit0c899c25d754ae386940f0e1b86b31d3921480b6
treef88648c3c9ef85bbc14a3da9bb9688ebb386ccef
parenta7d5c7ce41ac1e2537d78ddb57ef0ac4f737aa19
KVM: x86: do not attempt TSC synchronization on guest writes

KVM special-cases writes to MSR_IA32_TSC so that all CPUs have
the same base for the TSC.  This logic is complicated, and we
do not want it to have any effect once the VM is started.

In particular, if any guest started to synchronize its TSCs
with writes to MSR_IA32_TSC rather than MSR_IA32_TSC_ADJUST,
the additional effect of kvm_write_tsc code would be uncharted
territory.

Therefore, this patch makes writes to MSR_IA32_TSC behave
essentially the same as writes to MSR_IA32_TSC_ADJUST when
they come from the guest.  A new selftest (which passes
both before and after the patch) checks the current semantics
of writes to MSR_IA32_TSC and MSR_IA32_TSC_ADJUST originating
from both the host and the guest.

Upcoming work to remove the special side effects
of host-initiated writes to MSR_IA32_TSC and MSR_IA32_TSC_ADJUST
will be able to build onto this test, adjusting the host side
to use the new APIs and achieve the same effect.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/x86.c
tools/testing/selftests/kvm/Makefile
tools/testing/selftests/kvm/x86_64/tsc_msrs_test.c [new file with mode: 0644]