public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: kvm@vger.kernel.org
Subject: [PATCH 08/35] KVM: x86: Harden against cpufreq
Date: Thu, 19 Nov 2009 15:34:44 +0200	[thread overview]
Message-ID: <1258637711-11674-9-git-send-email-avi@redhat.com> (raw)
In-Reply-To: <1258637711-11674-1-git-send-email-avi@redhat.com>

From: Zachary Amsden <zamsden@redhat.com>

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>
---
 arch/x86/kvm/x86.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 098e7f8..3cffa2c 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1348,8 +1348,12 @@ out:
 void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 {
 	kvm_x86_ops->vcpu_load(vcpu, cpu);
-	if (unlikely(per_cpu(cpu_tsc_khz, cpu) == 0))
-		per_cpu(cpu_tsc_khz, cpu) = cpufreq_quick_get(cpu);
+	if (unlikely(per_cpu(cpu_tsc_khz, cpu) == 0)) {
+		unsigned long khz = cpufreq_quick_get(cpu);
+		if (!khz)
+			khz = tsc_khz;
+		per_cpu(cpu_tsc_khz, cpu) = khz;
+	}
 	kvm_request_guest_time_update(vcpu);
 }
 
@@ -3144,8 +3148,12 @@ static void kvm_timer_init(void)
 	if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC)) {
 		cpufreq_register_notifier(&kvmclock_cpufreq_notifier_block,
 					  CPUFREQ_TRANSITION_NOTIFIER);
-		for_each_online_cpu(cpu)
-			per_cpu(cpu_tsc_khz, cpu) = cpufreq_get(cpu);
+		for_each_online_cpu(cpu) {
+			unsigned long khz = cpufreq_get(cpu);
+			if (!khz)
+				khz = tsc_khz;
+			per_cpu(cpu_tsc_khz, cpu) = khz;
+		}
 	} else {
 		for_each_possible_cpu(cpu)
 			per_cpu(cpu_tsc_khz, cpu) = tsc_khz;
-- 
1.6.5.2


  parent reply	other threads:[~2009-11-19 13:35 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-19 13:34 [PATCH 00/35] KVM updates for the 2.6.33 merge window (batch 2/2) Avi Kivity
2009-11-19 13:34 ` [PATCH 01/35] KVM: SVM: Add tracepoint for #vmexit because intr pending Avi Kivity
2009-11-19 13:34 ` [PATCH 02/35] KVM: SVM: Add tracepoint for invlpga instruction Avi Kivity
2009-11-19 13:34 ` [PATCH 03/35] KVM: SVM: Add tracepoint for skinit instruction Avi Kivity
2009-11-19 13:34 ` [PATCH 04/35] KVM: SVM: Remove nsvm_printk debugging code Avi Kivity
2009-11-19 13:34 ` [PATCH 05/35] KVM: introduce kvm_vcpu_on_spin Avi Kivity
2009-11-19 13:34 ` [PATCH 06/35] KVM: VMX: Add support for Pause-Loop Exiting Avi Kivity
2009-11-19 13:34 ` [PATCH 07/35] KVM: SVM: Support Pause Filter in AMD processors Avi Kivity
2009-11-19 13:34 ` Avi Kivity [this message]
2009-11-19 13:34 ` [PATCH 09/35] KVM: VMX: fix handle_pause declaration Avi Kivity
2009-11-19 13:34 ` [PATCH 10/35] KVM: x86: Drop unneeded CONFIG_HAS_IOMEM check Avi Kivity
2009-11-19 13:34 ` [PATCH 11/35] KVM: Xen PV-on-HVM guest support Avi Kivity
2009-11-19 13:34 ` [PATCH 12/35] KVM: x86: Fix guest single-stepping while interruptible Avi Kivity
2009-11-19 13:34 ` [PATCH 13/35] KVM: SVM: Cleanup NMI singlestep Avi Kivity
2009-11-19 13:34 ` [PATCH 14/35] KVM: fix irq_source_id size verification Avi Kivity
2009-11-19 13:34 ` [PATCH 15/35] KVM: allow userspace to adjust kvmclock offset Avi Kivity
2010-01-29 13:32   ` Alexander Graf
2010-02-01 18:54     ` Marcelo Tosatti
2010-02-01 21:42       ` patch kvm-allow-userspace-to-adjust-kvmclock-offset.patch added to 2.6.32-stable tree gregkh
2009-11-19 13:34 ` [PATCH 16/35] KVM: Enable 32bit dirty log pointers on 64bit host Avi Kivity
2009-11-19 13:34 ` [PATCH 17/35] KVM: VMX: Use macros instead of hex value on cr0 initialization Avi Kivity
2009-11-19 13:34 ` [PATCH 18/35] KVM: SVM: Reset cr0 properly on vcpu reset Avi Kivity
2009-11-19 13:34 ` [PATCH 19/35] KVM: SVM: init_vmcb(): remove redundant save->cr0 initialization Avi Kivity
2009-11-19 13:34 ` [PATCH 20/35] KVM: VMX: Move MSR_KERNEL_GS_BASE out of the vmx autoload msr area Avi Kivity
2009-11-19 13:34 ` [PATCH 21/35] KVM: x86 shared msr infrastructure Avi Kivity
2009-11-19 13:34 ` [PATCH 22/35] KVM: VMX: Use " Avi Kivity
2009-11-19 13:34 ` [PATCH 23/35] KVM: powerpc: Fix BUILD_BUG_ON condition Avi Kivity
2009-11-19 13:35 ` [PATCH 24/35] KVM: remove duplicated task_switch check Avi Kivity
2009-11-19 13:35 ` [PATCH 25/35] KVM: VMX: move CR3/PDPTR update to vmx_set_cr3 Avi Kivity
2009-11-19 13:35 ` [PATCH 26/35] KVM: MMU: update invlpg handler comment Avi Kivity
2009-11-19 13:35 ` [PATCH 27/35] KVM: VMX: Remove vmx->msr_offset_efer Avi Kivity
2009-11-19 13:35 ` [PATCH 28/35] KVM: x86: disallow multiple KVM_CREATE_IRQCHIP Avi Kivity
2009-11-19 13:35 ` [PATCH 29/35] KVM: x86: disallow KVM_{SET,GET}_LAPIC without allocated in-kernel lapic Avi Kivity
2009-11-19 13:35 ` [PATCH 30/35] KVM: only clear irq_source_id if irqchip is present Avi Kivity
2009-11-19 13:35 ` [PATCH 31/35] KVM: x86: Polish exception injection via KVM_SET_GUEST_DEBUG Avi Kivity
2009-11-19 13:35 ` [PATCH 32/35] KVM: Reorder IOCTLs in main kvm.h Avi Kivity
2009-11-19 13:35 ` [PATCH 33/35] KVM: Allow internal errors reported to userspace to carry extra data Avi Kivity
2009-11-19 13:35 ` [PATCH 34/35] KVM: VMX: Report unexpected simultaneous exceptions as internal errors Avi Kivity
2009-11-19 13:35 ` [PATCH 35/35] KVM: x86: Add KVM_GET/SET_VCPU_EVENTS Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1258637711-11674-9-git-send-email-avi@redhat.com \
    --to=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox