From patchwork Wed Apr 23 21:04:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 341995 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id BF12D14011F for ; Thu, 24 Apr 2014 07:05:47 +1000 (EST) Received: from localhost ([::1]:34695 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wd4MT-0007wi-90 for incoming@patchwork.ozlabs.org; Wed, 23 Apr 2014 17:05:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56501) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wd4Ls-0007SL-1l for qemu-devel@nongnu.org; Wed, 23 Apr 2014 17:05:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wd4Ll-0006PE-OG for qemu-devel@nongnu.org; Wed, 23 Apr 2014 17:05:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:29403) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wd4Ll-0006Ms-H3 for qemu-devel@nongnu.org; Wed, 23 Apr 2014 17:05:01 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s3NL4xBb003633 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Apr 2014 17:04:59 -0400 Received: from amt.cnet (vpn1-4-123.gru2.redhat.com [10.97.4.123]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s3NL4wXI014751; Wed, 23 Apr 2014 17:04:58 -0400 Received: from amt.cnet (localhost [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 70F3A1003F5; Wed, 23 Apr 2014 18:04:46 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.7/8.14.7/Submit) id s3NL4jBj004319; Wed, 23 Apr 2014 18:04:45 -0300 Date: Wed, 23 Apr 2014 18:04:45 -0300 From: Marcelo Tosatti To: Eduardo Habkost Message-ID: <20140423210444.GA4305@amt.cnet> References: <20140423182002.441209839@amt.cnet> <20140423182539.391512909@amt.cnet> <20140423190941.GN3363@otherpad.lan.raisama.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20140423190941.GN3363@otherpad.lan.raisama.net> User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Paolo Bonzini , qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [Qemu-devel] target-i386: block migration and savevm if invariant tsc is exposed (v3) 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 Invariant TSC documentation mentions that "invariant TSC will run at a constant rate in all ACPI P-, C-. and T-states". This is not the case if migration to a host with different TSC frequency is allowed, or if savevm is performed. So block migration/savevm. Signed-off-by: Marcelo Tosatti Index: qemu-invariant-tsc/target-i386/kvm.c =================================================================== --- qemu-invariant-tsc.orig/target-i386/kvm.c +++ qemu-invariant-tsc/target-i386/kvm.c @@ -33,6 +33,8 @@ #include "exec/ioport.h" #include #include "hw/pci/pci.h" +#include "migration/migration.h" +#include "qapi/qmp/qerror.h" //#define DEBUG_KVM @@ -447,6 +449,8 @@ static bool hyperv_enabled(X86CPU *cpu) cpu->hyperv_relaxed_timing); } +Error *invtsc_mig_blocker; + #define KVM_MAX_CPUID_ENTRIES 100 int kvm_arch_init_vcpu(CPUState *cs) @@ -702,6 +706,16 @@ int kvm_arch_init_vcpu(CPUState *cs) !!(c->ecx & CPUID_EXT_SMX); } + c = cpuid_find_entry(&cpuid_data.cpuid, 0x80000007, 0); + if (c && (c->edx & 1<<8) && invtsc_mig_blocker == NULL) { + /* for migration */ + error_set(&invtsc_mig_blocker, + QERR_DEVICE_FEATURE_BLOCKS_MIGRATION, "invtsc", "cpu"); + migrate_add_blocker(invtsc_mig_blocker); + /* for savevm */ + vmstate_x86_cpu.unmigratable = 1; + } + cpuid_data.cpuid.padding = 0; r = kvm_vcpu_ioctl(cs, KVM_SET_CPUID2, &cpuid_data); if (r) { Index: qemu-invariant-tsc/target-i386/cpu-qom.h =================================================================== --- qemu-invariant-tsc.orig/target-i386/cpu-qom.h +++ qemu-invariant-tsc/target-i386/cpu-qom.h @@ -116,7 +116,7 @@ static inline X86CPU *x86_env_get_cpu(CP #define ENV_OFFSET offsetof(X86CPU, env) #ifndef CONFIG_USER_ONLY -extern const struct VMStateDescription vmstate_x86_cpu; +extern struct VMStateDescription vmstate_x86_cpu; #endif /** Index: qemu-invariant-tsc/target-i386/machine.c =================================================================== --- qemu-invariant-tsc.orig/target-i386/machine.c +++ qemu-invariant-tsc/target-i386/machine.c @@ -613,7 +613,7 @@ static const VMStateDescription vmstate_ } }; -const VMStateDescription vmstate_x86_cpu = { +VMStateDescription vmstate_x86_cpu = { .name = "cpu", .version_id = 12, .minimum_version_id = 3,