From patchwork Sat Oct 10 02:26:08 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zachary Amsden X-Patchwork-Id: 52900 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n9A2UMbR001709 for ; Sat, 10 Oct 2009 02:30:22 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964835AbZJJC3M (ORCPT ); Fri, 9 Oct 2009 22:29:12 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S934743AbZJJC3M (ORCPT ); Fri, 9 Oct 2009 22:29:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6165 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934741AbZJJC3L (ORCPT ); Fri, 9 Oct 2009 22:29:11 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9A2Sjiw001555 for ; Fri, 9 Oct 2009 22:28:45 -0400 Received: from localhost.localdomain (vpn-12-47.rdu.redhat.com [10.11.12.47]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9A2SaxB009209; Fri, 9 Oct 2009 22:28:44 -0400 From: Zachary Amsden To: kvm@vger.kernel.org, avi@redhat.com Cc: Zachary Amsden Subject: [PATCH] KVM: Harden against cpufreq Date: Fri, 9 Oct 2009 16:26:08 -1000 Message-Id: <1255141569-3572-2-git-send-email-zamsden@redhat.com> In-Reply-To: <1255141569-3572-1-git-send-email-zamsden@redhat.com> References: <4ACFA178.2040203@web.de> <1255141569-3572-1-git-send-email-zamsden@redhat.com> CC: linux-kernel@kernel.vger.org X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 11a6f2f..6604f4c 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1345,8 +1345,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); } @@ -3140,8 +3144,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;