Skip to content

Commit 2680d6d

Browse files
Owen Hofmannbonzini
authored andcommitted
kvm: x86: Update tsc multiplier on change.
vmx.c writes the TSC_MULTIPLIER field in vmx_vcpu_load, but only when a vcpu has migrated physical cpus. Record the last value written and update in vmx_vcpu_load on any change, otherwise a cpu migration must occur for TSC frequency scaling to take effect. Cc: stable@vger.kernel.org Fixes: ff2c3a1 Signed-off-by: Owen Hofmann <osh@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 0178fd7 commit 2680d6d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

arch/x86/kvm/vmx.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,8 @@ struct vcpu_vmx {
596596
/* Support for PML */
597597
#define PML_ENTITY_NUM 512
598598
struct page *pml_pg;
599+
600+
u64 current_tsc_ratio;
599601
};
600602

601603
enum segment_cache_field {
@@ -2127,14 +2129,16 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
21272129
rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
21282130
vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
21292131

2130-
/* Setup TSC multiplier */
2131-
if (cpu_has_vmx_tsc_scaling())
2132-
vmcs_write64(TSC_MULTIPLIER,
2133-
vcpu->arch.tsc_scaling_ratio);
2134-
21352132
vmx->loaded_vmcs->cpu = cpu;
21362133
}
21372134

2135+
/* Setup TSC multiplier */
2136+
if (kvm_has_tsc_control &&
2137+
vmx->current_tsc_ratio != vcpu->arch.tsc_scaling_ratio) {
2138+
vmx->current_tsc_ratio = vcpu->arch.tsc_scaling_ratio;
2139+
vmcs_write64(TSC_MULTIPLIER, vmx->current_tsc_ratio);
2140+
}
2141+
21382142
vmx_vcpu_pi_load(vcpu, cpu);
21392143
}
21402144

0 commit comments

Comments
 (0)