From patchwork Fri Dec 31 12:01:52 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 77069 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 A39BA1007D4 for ; Fri, 31 Dec 2010 23:08:30 +1100 (EST) Received: from localhost ([127.0.0.1]:39406 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PYdmT-00026c-3i for incoming@patchwork.ozlabs.org; Fri, 31 Dec 2010 07:08:25 -0500 Received: from [140.186.70.92] (port=35864 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PYdgL-0006ps-Qv for qemu-devel@nongnu.org; Fri, 31 Dec 2010 07:02:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PYdgJ-0006hE-KH for qemu-devel@nongnu.org; Fri, 31 Dec 2010 07:02:05 -0500 Received: from fmmailgate01.web.de ([217.72.192.221]:33101) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PYdgJ-0006gv-6n for qemu-devel@nongnu.org; Fri, 31 Dec 2010 07:02:03 -0500 Received: from smtp08.web.de ( [172.20.5.216]) by fmmailgate01.web.de (Postfix) with ESMTP id 15BE0184BB00D; Fri, 31 Dec 2010 13:02:02 +0100 (CET) Received: from [88.64.22.98] (helo=localhost.localdomain) by smtp08.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #2) id 1PYdgH-0007EU-00; Fri, 31 Dec 2010 13:02:01 +0100 From: Jan Kiszka To: Avi Kivity , Marcelo Tosatti Date: Fri, 31 Dec 2010 13:01:52 +0100 Message-Id: X-Mailer: git-send-email 1.7.1 In-Reply-To: References: In-Reply-To: References: X-Sender: jan.kiszka@web.de X-Provags-ID: V01U2FsdGVkX19tT1lyAbktlaQxLuQ5CiXfhPpc+lXUBgYyR2s+ geTifqObjuFxejYog9hVA6WKnHyowz6ih8vtqBLHspqtXrLQyB B8zDHIh0g= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 Cc: Jan Kiszka , Glauber Costa , qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [Qemu-devel] [PATCH 5/5] kvm: x86: Introduce kvmclock device to save/restore its state 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 From: Jan Kiszka If kvmclock is used, which implies the kernel supports it, register a kvmclock device with the sysbus. Its main purpose is to save and restore the kernel state on migration, but this will also allow to visualize it one day. Signed-off-by: Jan Kiszka CC: Glauber Costa --- target-i386/kvm.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 70 insertions(+), 1 deletions(-) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index a4ccc7f..32310fa 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -29,6 +29,7 @@ #include "hw/apic.h" #include "ioport.h" #include "kvm_x86.h" +#include "hw/sysbus.h" #ifdef CONFIG_KVM_PARA #include @@ -309,6 +310,64 @@ void kvm_inject_x86_mce(CPUState *cenv, int bank, uint64_t status, #endif } +#ifdef KVM_CAP_ADJUST_CLOCK +typedef struct KVMClockState { + SysBusDevice busdev; + uint64_t clock; + struct kvm_clock_data data; +} KVMClockState; + +static void kvmclock_pre_save(void *opaque) +{ + KVMClockState *s = opaque; + struct kvm_clock_data data; + int ret; + + ret = kvm_vm_ioctl(KVM_GET_CLOCK, &data); + if (ret < 0) { + fprintf(stderr, "KVM_GET_CLOCK failed: %s\n", strerror(ret)); + data.clock = 0; + } + s->clock = data.clock; +} + +static int kvmclock_post_load(void *opaque, int version_id) +{ + KVMClockState *s = opaque; + struct kvm_clock_data data; + + data.clock = s->clock; + data.flags = 0; + return kvm_vm_ioctl(KVM_SET_CLOCK, &data); +} + +static int kvmclock_init(SysBusDevice *dev) +{ + return 0; +} + +static const VMStateDescription kvmclock_vmsd= { + .name = "kvmclock", + .version_id = 1, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .pre_save = kvmclock_pre_save, + .post_load = kvmclock_post_load, + .fields = (VMStateField []) { + VMSTATE_UINT64(clock, KVMClockState), + VMSTATE_END_OF_LIST() + } +}; + +static SysBusDeviceInfo kvmclock_info = { + .qdev.name = "kvmclock", + .qdev.size = sizeof(KVMClockState), + .qdev.vmsd = &kvmclock_vmsd, + .qdev.no_user = 1, + .init = kvmclock_init, +}; +#endif /* KVM_CAP_ADJUST_CLOCK */ + int kvm_arch_init_vcpu(CPUState *env) { struct { @@ -337,7 +396,6 @@ int kvm_arch_init_vcpu(CPUState *env) env->cpuid_svm_features &= kvm_x86_get_supported_cpuid(0x8000000A, 0, R_EDX); - cpuid_i = 0; #ifdef CONFIG_KVM_PARA @@ -444,6 +502,13 @@ int kvm_arch_init_vcpu(CPUState *env) } #endif +#ifdef KVM_CAP_ADJUST_CLOCK + if (cpu_is_bsp(env) && + (env->cpuid_kvm_features & (1ULL << KVM_FEATURE_CLOCKSOURCE))) { + sysbus_create_simple("kvmclock", -1, NULL); + } +#endif + return kvm_vcpu_ioctl(env, KVM_SET_CPUID2, &cpuid_data); } @@ -535,6 +600,10 @@ int kvm_arch_init(int smp_cpus) int ret; struct utsname utsname; +#ifdef KVM_CAP_ADJUST_CLOCK + sysbus_register_withprop(&kvmclock_info); +#endif + ret = kvm_get_supported_msrs(); if (ret < 0) { return ret;