From patchwork Thu Apr 18 02:48:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 237424 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 489C42C017F for ; Thu, 18 Apr 2013 12:50:42 +1000 (EST) Received: from localhost ([::1]:51664 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USevo-0002Fi-I9 for incoming@patchwork.ozlabs.org; Wed, 17 Apr 2013 22:50:40 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53644) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USetv-0008AY-44 for qemu-devel@nongnu.org; Wed, 17 Apr 2013 22:48:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1USett-0001Zf-Bc for qemu-devel@nongnu.org; Wed, 17 Apr 2013 22:48:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43650) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1USett-0001Ys-2X for qemu-devel@nongnu.org; Wed, 17 Apr 2013 22:48:41 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3I2mdif021939 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 17 Apr 2013 22:48:39 -0400 Received: from amt.cnet (vpn1-7-116.gru2.redhat.com [10.97.7.116]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r3I2mcnC024524; Wed, 17 Apr 2013 22:48:38 -0400 Received: from amt.cnet (localhost [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id D90221040FD; Wed, 17 Apr 2013 23:48:34 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.6/8.14.6/Submit) id r3I2mYpF014894; Wed, 17 Apr 2013 23:48:34 -0300 From: Marcelo Tosatti To: Anthony Liguori Date: Wed, 17 Apr 2013 23:48:25 -0300 Message-Id: <917367aa968fd4fef29d340e0c7ec8c608dffaab.1366253306.git.mtosatti@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Gleb Natapov , Marcelo Tosatti , qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [Qemu-devel] [PATCH 4/5] target-i386: kvm: save/restore steal time MSR X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Read and write steal time MSR, so that reporting is functional across migration. Signed-off-by: Marcelo Tosatti Signed-off-by: Gleb Natapov --- target-i386/cpu.h | 1 + target-i386/kvm.c | 13 +++++++++++++ target-i386/machine.c | 21 +++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/target-i386/cpu.h b/target-i386/cpu.h index cf1b05c..a1614e8 100644 --- a/target-i386/cpu.h +++ b/target-i386/cpu.h @@ -803,6 +803,7 @@ typedef struct CPUX86State { #endif uint64_t system_time_msr; uint64_t wall_clock_msr; + uint64_t steal_time_msr; uint64_t async_pf_en_msr; uint64_t pv_eoi_en_msr; diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 397afeb..0e7cc81 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -68,6 +68,7 @@ static bool has_msr_tsc_deadline; static bool has_msr_async_pf_en; static bool has_msr_pv_eoi_en; static bool has_msr_misc_enable; +static bool has_msr_kvm_steal_time; static int lm_capable_kernel; bool kvm_allows_irq0_override(void) @@ -507,6 +508,8 @@ int kvm_arch_init_vcpu(CPUState *cs) has_msr_pv_eoi_en = c->eax & (1 << KVM_FEATURE_PV_EOI); + has_msr_kvm_steal_time = c->eax & (1 << KVM_FEATURE_STEAL_TIME); + cpu_x86_cpuid(env, 0, 0, &limit, &unused, &unused, &unused); for (i = 0; i <= limit; i++) { @@ -1107,6 +1110,10 @@ static int kvm_put_msrs(X86CPU *cpu, int level) kvm_msr_entry_set(&msrs[n++], MSR_KVM_PV_EOI_EN, env->pv_eoi_en_msr); } + if (has_msr_kvm_steal_time) { + kvm_msr_entry_set(&msrs[n++], MSR_KVM_STEAL_TIME, + env->steal_time_msr); + } if (hyperv_hypercall_available()) { kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_GUEST_OS_ID, 0); kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_HYPERCALL, 0); @@ -1360,6 +1367,9 @@ static int kvm_get_msrs(X86CPU *cpu) if (has_msr_pv_eoi_en) { msrs[n++].index = MSR_KVM_PV_EOI_EN; } + if (has_msr_kvm_steal_time) { + msrs[n++].index = MSR_KVM_STEAL_TIME; + } if (env->mcg_cap) { msrs[n++].index = MSR_MCG_STATUS; @@ -1445,6 +1455,9 @@ static int kvm_get_msrs(X86CPU *cpu) case MSR_KVM_PV_EOI_EN: env->pv_eoi_en_msr = msrs[i].data; break; + case MSR_KVM_STEAL_TIME: + env->steal_time_msr = msrs[i].data; + break; } } diff --git a/target-i386/machine.c b/target-i386/machine.c index ee85e57..3659db9 100644 --- a/target-i386/machine.c +++ b/target-i386/machine.c @@ -292,6 +292,24 @@ static bool pv_eoi_msr_needed(void *opaque) return cpu->env.pv_eoi_en_msr != 0; } +static bool steal_time_msr_needed(void *opaque) +{ + CPUX86State *cpu = opaque; + + return cpu->steal_time_msr != 0; +} + +static const VMStateDescription vmstate_steal_time_msr = { + .name = "cpu/steal_time_msr", + .version_id = 1, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField []) { + VMSTATE_UINT64(steal_time_msr, CPUX86State), + VMSTATE_END_OF_LIST() + } +}; + static const VMStateDescription vmstate_async_pf_msr = { .name = "cpu/async_pf_msr", .version_id = 1, @@ -503,6 +521,9 @@ const VMStateDescription vmstate_x86_cpu = { .vmsd = &vmstate_pv_eoi_msr, .needed = pv_eoi_msr_needed, } , { + .vmsd = &vmstate_steal_time_msr, + .needed = steal_time_msr_needed, + } , { .vmsd = &vmstate_fpop_ip_dp, .needed = fpop_ip_dp_needed, }, {