From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: [patch 1/3] QEMU/KVM: x86: separate TSC load from kvm_arch_load_regs Date: Mon, 08 Dec 2008 23:12:48 -0200 Message-ID: <20081209012212.014302332@localhost.localdomain> References: <20081209011247.570596925@localhost.localdomain> Cc: kvm@vger.kernel.org, Benjamin Serebrin , Marcelo Tosatti To: Avi Kivity Return-path: Received: from mx2.redhat.com ([66.187.237.31]:53541 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751054AbYLIBZy (ORCPT ); Mon, 8 Dec 2008 20:25:54 -0500 Content-Disposition: inline; filename=kvm-load-tsc Sender: kvm-owner@vger.kernel.org List-ID: kvm_load_registers is a general interface to load registers, and is used by vmport, gdbstub, etc. The TSC MSR is continually counting, so it can't be simply read and written back as the other registers/MSR's (doing so overwrites the current count). Introduce kvm_load_tsc and use it for x86's migration CPU load code. Signed-off-by: Marcelo Tosatti Index: kvm-userspace.tip/qemu/qemu-kvm-x86.c =================================================================== --- kvm-userspace.tip.orig/qemu/qemu-kvm-x86.c +++ kvm-userspace.tip/qemu/qemu-kvm-x86.c @@ -257,7 +257,6 @@ void kvm_arch_load_regs(CPUState *env) set_msr_entry(&msrs[n++], MSR_IA32_SYSENTER_EIP, env->sysenter_eip); if (kvm_has_msr_star) set_msr_entry(&msrs[n++], MSR_STAR, env->star); - set_msr_entry(&msrs[n++], MSR_IA32_TSC, env->tsc); #ifdef TARGET_X86_64 if (lm_capable_kernel) { set_msr_entry(&msrs[n++], MSR_CSTAR, env->cstar); @@ -272,6 +271,18 @@ void kvm_arch_load_regs(CPUState *env) perror("kvm_set_msrs FAILED"); } +void kvm_load_tsc(CPUState *env) +{ + int rc; + struct kvm_msr_entry msr; + + set_msr_entry(&msr, MSR_IA32_TSC, env->tsc); + + rc = kvm_set_msrs(kvm_context, env->cpu_index, &msr, 1); + if (rc == -1) + perror("kvm_set_tsc FAILED.\n"); +} + void kvm_save_mpstate(CPUState *env) { #ifdef KVM_CAP_MP_STATE Index: kvm-userspace.tip/qemu/qemu-kvm-x86.h =================================================================== --- /dev/null +++ kvm-userspace.tip/qemu/qemu-kvm-x86.h @@ -0,0 +1,13 @@ +/* + * qemu/kvm integration + * + * Copyright (C) 2006-2008 Qumranet Technologies + * + * Licensed under the terms of the GNU GPL version 2 or higher. + */ +#ifndef QEMU_KVM_X86 +#define QEMU_KVM_X86 + +void kvm_load_tsc(CPUState *env); + +#endif Index: kvm-userspace.tip/qemu/target-i386/machine.c =================================================================== --- kvm-userspace.tip.orig/qemu/target-i386/machine.c +++ kvm-userspace.tip/qemu/target-i386/machine.c @@ -5,6 +5,7 @@ #include "exec-all.h" #include "qemu-kvm.h" +#include "qemu-kvm-x86.h" void register_machines(void) { @@ -328,6 +329,7 @@ int cpu_load(QEMUFile *f, void *opaque, } qemu_get_be64s(f, &env->tsc); kvm_load_registers(env); + kvm_load_tsc(env); if (version_id >= 5) { qemu_get_be32s(f, &env->mp_state); kvm_load_mpstate(env); --