summaryrefslogtreecommitdiff
path: root/arch/x86/kvm/svm/svm.c
diff options
context:
space:
mode:
authorSean Christopherson <seanjc@google.com>2023-07-29 04:15:53 +0300
committerSean Christopherson <seanjc@google.com>2023-08-04 03:16:30 +0300
commit223f93d4d88aedc02bdcc92b3734e76f707812f3 (patch)
treef3214c17c39f1abcf11f90a2f187900e9fc96bc0 /arch/x86/kvm/svm/svm.c
parent2d63699099ac1fad13a0dbf8538faf4127c062e8 (diff)
downloadlinux-223f93d4d88aedc02bdcc92b3734e76f707812f3.tar.xz
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>
Diffstat (limited to 'arch/x86/kvm/svm/svm.c')
-rw-r--r--arch/x86/kvm/svm/svm.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 2542066652a3..6d8932e05753 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -1149,7 +1149,8 @@ static void svm_write_tsc_offset(struct kvm_vcpu *vcpu)
void svm_write_tsc_multiplier(struct kvm_vcpu *vcpu)
{
preempt_disable();
- __svm_write_tsc_multiplier(vcpu->arch.tsc_scaling_ratio);
+ if (to_svm(vcpu)->guest_state_loaded)
+ __svm_write_tsc_multiplier(vcpu->arch.tsc_scaling_ratio);
preempt_enable();
}