From patchwork Mon Dec 6 14:03:46 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 74365 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CD66BB70DF for ; Tue, 7 Dec 2010 01:24:00 +1100 (EST) Received: from localhost ([127.0.0.1]:33930 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPbyv-0001Gf-PG for incoming@patchwork.ozlabs.org; Mon, 06 Dec 2010 09:23:57 -0500 Received: from [140.186.70.92] (port=56020 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPbjQ-0001Rr-Nl for qemu-devel@nongnu.org; Mon, 06 Dec 2010 09:07:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PPbjP-0004kY-2f for qemu-devel@nongnu.org; Mon, 06 Dec 2010 09:07:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54172) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PPbjO-0004k1-RQ for qemu-devel@nongnu.org; Mon, 06 Dec 2010 09:07:55 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oB6E7rxY004541 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 6 Dec 2010 09:07:53 -0500 Received: from virtlab1.virt.bos.redhat.com (virtlab1.virt.bos.redhat.com [10.16.72.21]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oB6E7pix006031; Mon, 6 Dec 2010 09:07:52 -0500 From: Glauber Costa To: kvm@vger.kernel.org Date: Mon, 6 Dec 2010 09:03:46 -0500 Message-Id: <1291644227-22923-2-git-send-email-glommer@redhat.com> In-Reply-To: <1291644227-22923-1-git-send-email-glommer@redhat.com> References: <1291644227-22923-1-git-send-email-glommer@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: mtosatti@redhat.com, qemu-devel@nongnu.org, avi@redhat.com Subject: [Qemu-devel] [PATCH v2 1/2] Do not register kvmclock savevm section if kvmclock is disabled. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Usually nobody usually thinks about that scenario (me included and specially), but kvmclock can be actually disabled in the host. It happens in two scenarios: 1. host too old. 2. we passed -kvmclock to our -cpu parameter. In both cases, we should not register kvmclock savevm section. This patch achives that by registering this section only if kvmclock is actually currently enabled in cpuid. The only caveat is that we have to register the savevm section a little bit later, since we won't know the final kvmclock state before cpuid gets parsed. Signed-off-by: Glauber Costa --- cpus.c | 3 +++ qemu-kvm-x86.c | 19 +++++++++++++------ qemu-kvm.h | 3 +++ target-i386/kvm.c | 7 +++++++ 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/cpus.c b/cpus.c index a55c330..a24098e 100644 --- a/cpus.c +++ b/cpus.c @@ -97,6 +97,9 @@ void cpu_synchronize_all_post_init(void) for (cpu = first_cpu; cpu; cpu = cpu->next_cpu) { cpu_synchronize_post_init(cpu); } + if (kvm_enabled()) { + kvmclock_register_savevm(); + } } int cpu_is_stopped(CPUState *env) diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c index 20b7d6d..14a52ce 100644 --- a/qemu-kvm-x86.c +++ b/qemu-kvm-x86.c @@ -504,6 +504,9 @@ static void kvmclock_pre_save(void *opaque) { struct kvm_clock_data *cl = opaque; + if (!kvmclock_enabled) + return; + kvm_vm_ioctl(kvm_state, KVM_GET_CLOCK, cl); } @@ -528,6 +531,16 @@ static const VMStateDescription vmstate_kvmclock= { }; #endif +/* This has to happen after vcpu setup*/ +void kvmclock_register_savevm(void) +{ +#ifdef KVM_CAP_ADJUST_CLOCK + if (kvmclock_enabled && kvm_check_extension(kvm_state, KVM_CAP_ADJUST_CLOCK)) { + vmstate_register(NULL, 0, &vmstate_kvmclock, &kvmclock_data); + } +#endif +} + int kvm_arch_qemu_create_context(void) { int r; @@ -545,12 +558,6 @@ int kvm_arch_qemu_create_context(void) return -1; } -#ifdef KVM_CAP_ADJUST_CLOCK - if (kvm_check_extension(kvm_state, KVM_CAP_ADJUST_CLOCK)) { - vmstate_register(NULL, 0, &vmstate_kvmclock, &kvmclock_data); - } -#endif - r = kvm_set_boot_cpu_id(0); if (r < 0 && r != -ENOSYS) { return r; diff --git a/qemu-kvm.h b/qemu-kvm.h index 0f3fb50..0a104ef 100644 --- a/qemu-kvm.h +++ b/qemu-kvm.h @@ -752,6 +752,9 @@ int handle_tpr_access(void *opaque, CPUState *env, uint64_t rip, #define qemu_kvm_cpu_stop(env) do {} while(0) #endif +extern int kvmclock_enabled; +void kvmclock_register_savevm(void); + #ifdef CONFIG_KVM typedef struct KVMSlot { diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 95e5d02..5443765 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -293,6 +293,7 @@ void kvm_inject_x86_mce(CPUState *cenv, int bank, uint64_t status, } static int _kvm_arch_init_vcpu(CPUState *env); +int kvmclock_enabled = 1; int kvm_arch_init_vcpu(CPUState *env) { @@ -350,6 +351,12 @@ int kvm_arch_init_vcpu(CPUState *env) memset(c, 0, sizeof(*c)); c->function = KVM_CPUID_FEATURES; c->eax = env->cpuid_kvm_features & get_para_features(env); + + if (!(c->eax & (1 << KVM_FEATURE_CLOCKSOURCE))) { + /* In theory cpuid is per-cpu, and this is a global variable, + * but we don't expect kvmclock enabled in some cpus only */ + kvmclock_enabled = 0; + } #endif cpu_x86_cpuid(env, 0, 0, &limit, &unused, &unused, &unused);