Skip to content

Commit c0dc39b

Browse files
committed
KVM: nSVM: Use the "outer" helper for writing multiplier to MSR_AMD64_TSC_RATIO
When emulating nested SVM transitions, use the outer helper for writing the TSC multiplier for L2. Using the inner helper only for one-off cases, i.e. for paths where KVM is NOT emulating or modifying vCPU state, will allow for multiple cleanups: - Explicitly disabling preemption only in the outer helper - Getting the multiplier from the vCPU field in the outer helper - Skipping the WRMSR in the outer helper if guest state isn't loaded Opportunistically delete an extra newline. No functional change intended. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 0c94e24 commit c0dc39b

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

arch/x86/kvm/svm/nested.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ int nested_svm_vmexit(struct vcpu_svm *svm)
11031103
if (kvm_caps.has_tsc_control &&
11041104
vcpu->arch.tsc_scaling_ratio != vcpu->arch.l1_tsc_scaling_ratio) {
11051105
vcpu->arch.tsc_scaling_ratio = vcpu->arch.l1_tsc_scaling_ratio;
1106-
__svm_write_tsc_multiplier(vcpu->arch.tsc_scaling_ratio);
1106+
svm_write_tsc_multiplier(vcpu, vcpu->arch.tsc_scaling_ratio);
11071107
}
11081108

11091109
svm->nested.ctl.nested_cr3 = 0;
@@ -1536,7 +1536,7 @@ void nested_svm_update_tsc_ratio_msr(struct kvm_vcpu *vcpu)
15361536
vcpu->arch.tsc_scaling_ratio =
15371537
kvm_calc_nested_tsc_multiplier(vcpu->arch.l1_tsc_scaling_ratio,
15381538
svm->tsc_ratio_msr);
1539-
__svm_write_tsc_multiplier(vcpu->arch.tsc_scaling_ratio);
1539+
svm_write_tsc_multiplier(vcpu, vcpu->arch.tsc_scaling_ratio);
15401540
}
15411541

15421542
/* Inverse operation of nested_copy_vmcb_control_to_cache(). asid is copied too. */

arch/x86/kvm/svm/svm.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ static int svm_check_processor_compat(void)
567567
return 0;
568568
}
569569

570-
void __svm_write_tsc_multiplier(u64 multiplier)
570+
static void __svm_write_tsc_multiplier(u64 multiplier)
571571
{
572572
preempt_disable();
573573

@@ -1150,12 +1150,11 @@ static void svm_write_tsc_offset(struct kvm_vcpu *vcpu, u64 offset)
11501150
vmcb_mark_dirty(svm->vmcb, VMCB_INTERCEPTS);
11511151
}
11521152

1153-
static void svm_write_tsc_multiplier(struct kvm_vcpu *vcpu, u64 multiplier)
1153+
void svm_write_tsc_multiplier(struct kvm_vcpu *vcpu, u64 multiplier)
11541154
{
11551155
__svm_write_tsc_multiplier(multiplier);
11561156
}
11571157

1158-
11591158
/* Evaluate instruction intercepts that depend on guest CPUID features. */
11601159
static void svm_recalc_instruction_intercepts(struct kvm_vcpu *vcpu,
11611160
struct vcpu_svm *svm)

arch/x86/kvm/svm/svm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ int nested_svm_check_exception(struct vcpu_svm *svm, unsigned nr,
658658
bool has_error_code, u32 error_code);
659659
int nested_svm_exit_special(struct vcpu_svm *svm);
660660
void nested_svm_update_tsc_ratio_msr(struct kvm_vcpu *vcpu);
661-
void __svm_write_tsc_multiplier(u64 multiplier);
661+
void svm_write_tsc_multiplier(struct kvm_vcpu *vcpu, u64 multiplier);
662662
void nested_copy_vmcb_control_to_cache(struct vcpu_svm *svm,
663663
struct vmcb_control_area *control);
664664
void nested_copy_vmcb_save_to_cache(struct vcpu_svm *svm,

0 commit comments

Comments
 (0)