aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorZachary Amsden <zamsden@redhat.com>2009-10-09 22:26:08 -0400
committerAvi Kivity <avi@redhat.com>2009-12-03 02:32:18 -0500
commit6b7d7e762b238f908fe4c3345c2c6eb5c3fdbd59 (patch)
treeab2a77aec71450ba11c13a8f31e505df173efd78 /arch
parent565d0998ecac8373b9a9ecd5991abe74318cd235 (diff)
KVM: x86: Harden against cpufreq
If cpufreq can't determine the CPU khz, or cpufreq is not compiled in, we should fallback to the measured TSC khz. Signed-off-by: Zachary Amsden <zamsden@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'arch')
-rw-r--r--arch/x86/kvm/x86.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 098e7f886306..3cffa2cac70b 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1348,8 +1348,12 @@ out:
1348void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) 1348void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
1349{ 1349{
1350 kvm_x86_ops->vcpu_load(vcpu, cpu); 1350 kvm_x86_ops->vcpu_load(vcpu, cpu);
1351 if (unlikely(per_cpu(cpu_tsc_khz, cpu) == 0)) 1351 if (unlikely(per_cpu(cpu_tsc_khz, cpu) == 0)) {
1352 per_cpu(cpu_tsc_khz, cpu) = cpufreq_quick_get(cpu); 1352 unsigned long khz = cpufreq_quick_get(cpu);
1353 if (!khz)
1354 khz = tsc_khz;
1355 per_cpu(cpu_tsc_khz, cpu) = khz;
1356 }
1353 kvm_request_guest_time_update(vcpu); 1357 kvm_request_guest_time_update(vcpu);
1354} 1358}
1355 1359
@@ -3144,8 +3148,12 @@ static void kvm_timer_init(void)
3144 if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC)) { 3148 if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC)) {
3145 cpufreq_register_notifier(&kvmclock_cpufreq_notifier_block, 3149 cpufreq_register_notifier(&kvmclock_cpufreq_notifier_block,
3146 CPUFREQ_TRANSITION_NOTIFIER); 3150 CPUFREQ_TRANSITION_NOTIFIER);
3147 for_each_online_cpu(cpu) 3151 for_each_online_cpu(cpu) {
3148 per_cpu(cpu_tsc_khz, cpu) = cpufreq_get(cpu); 3152 unsigned long khz = cpufreq_get(cpu);
3153 if (!khz)
3154 khz = tsc_khz;
3155 per_cpu(cpu_tsc_khz, cpu) = khz;
3156 }
3149 } else { 3157 } else {
3150 for_each_possible_cpu(cpu) 3158 for_each_possible_cpu(cpu)
3151 per_cpu(cpu_tsc_khz, cpu) = tsc_khz; 3159 per_cpu(cpu_tsc_khz, cpu) = tsc_khz;