Skip to content

Commit 223f93d

Browse files
committed
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/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 2d63699 commit 223f93d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,8 @@ static void svm_write_tsc_offset(struct kvm_vcpu *vcpu)
11491149
void svm_write_tsc_multiplier(struct kvm_vcpu *vcpu)
11501150
{
11511151
preempt_disable();
1152-
__svm_write_tsc_multiplier(vcpu->arch.tsc_scaling_ratio);
1152+
if (to_svm(vcpu)->guest_state_loaded)
1153+
__svm_write_tsc_multiplier(vcpu->arch.tsc_scaling_ratio);
11531154
preempt_enable();
11541155
}
11551156

0 commit comments

Comments
 (0)