KVM: nSVM: Skip writes to MSR_AMD64_TSC_RATIO if guest state isn't loaded
authorSean Christopherson <seanjc@google.com>
Sat, 29 Jul 2023 01:15:53 +0000 (18:15 -0700)
committerSean Christopherson <seanjc@google.com>
Fri, 4 Aug 2023 00:16:30 +0000 (17:16 -0700)
commit223f93d4d88aedc02bdcc92b3734e76f707812f3
treef3214c17c39f1abcf11f90a2f187900e9fc96bc0
parent2d63699099ac1fad13a0dbf8538faf4127c062e8
KVM: nSVM: Skip writes to MSR_AMD64_TSC_RATIO if guest state isn't loaded

Skip writes to MSR_AMD64_TSC_RATIO that are done in the context of a vCPU
if guest state isn't loaded, i.e. if KVM will update MSR_AMD64_TSC_RATIO
during svm_prepare_switch_to_guest() before entering the guest.  Checking
guest_state_loaded may or may not be a net positive for performance as
the current_tsc_ratio cache will optimize away duplicate WRMSRs in the
vast majority of scenarios.  However, the cost of the check is negligible,
and the real motivation is to document that KVM needs to load the vCPU's
value only when running the vCPU.

Link: https://lore.kernel.org/r/20230729011608.1065019-7-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/svm/svm.c