From patchwork Tue Dec 27 19:21:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 9489815 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EF28562AAF for ; Tue, 27 Dec 2016 19:26:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD2661FEBD for ; Tue, 27 Dec 2016 19:26:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C200D2094F; Tue, 27 Dec 2016 19:26:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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 mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 619D11FEBD for ; Tue, 27 Dec 2016 19:26:34 +0000 (UTC) Received: from localhost ([::1]:55689 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cLxOK-0000IG-51 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 27 Dec 2016 14:26:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53925) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cLxJb-00054L-HV for qemu-devel@nongnu.org; Tue, 27 Dec 2016 14:21:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cLxJa-0006ml-Ii for qemu-devel@nongnu.org; Tue, 27 Dec 2016 14:21:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48688) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cLxJa-0006md-AI for qemu-devel@nongnu.org; Tue, 27 Dec 2016 14:21:38 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7E70345CBA; Tue, 27 Dec 2016 19:21:37 +0000 (UTC) Received: from localhost (ovpn-116-29.gru2.redhat.com [10.97.116.29]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uBRJLaKU013535; Tue, 27 Dec 2016 14:21:36 -0500 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Tue, 27 Dec 2016 17:21:20 -0200 Message-Id: <1482866480-26208-5-git-send-email-ehabkost@redhat.com> In-Reply-To: <1482866480-26208-1-git-send-email-ehabkost@redhat.com> References: <1482866480-26208-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 27 Dec 2016 19:21:37 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 4/4] kvm: Allow migration with invtsc X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , kvm@vger.kernel.org, Haozhong Zhang Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Instead of blocking migration on the source when invtsc is enabled, rely on the migration destination to ensure there's no TSC frequency mismatch. We can't allow migration unconditionally because we don't know if the destination is a QEMU version that is really going to ensure there's no TSC frequency mismatch. To ensure we are migrating to a destination that won't ignore SET_TSC_KHZ errors, allow invtsc migration only on pc-*-2.9 and newer. Signed-off-by: Eduardo Habkost --- include/hw/i386/pc.h | 7 ++++++- target/i386/cpu.h | 1 + target/i386/cpu.c | 1 + target/i386/kvm.c | 15 +++++++++------ 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index ceeacca..4270923 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -375,7 +375,12 @@ int e820_get_num_entries(void); bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); #define PC_COMPAT_2_8 \ - HW_COMPAT_2_8 + HW_COMPAT_2_8 \ + {\ + .driver = TYPE_X86_CPU,\ + .property = "invtsc-migration",\ + .value = "off",\ + }, #define PC_COMPAT_2_7 \ HW_COMPAT_2_7 \ diff --git a/target/i386/cpu.h b/target/i386/cpu.h index a7f2f60..ec8cdbc 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1208,6 +1208,7 @@ struct X86CPU { bool expose_kvm; bool migratable; bool host_features; + bool invtsc_migration; uint32_t apic_id; /* if true the CPUID code directly forward host cache leaves to the guest */ diff --git a/target/i386/cpu.c b/target/i386/cpu.c index b0640f1..cc93b81 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -3678,6 +3678,7 @@ static Property x86_cpu_properties[] = { DEFINE_PROP_BOOL("cpuid-0xb", X86CPU, enable_cpuid_0xb, true), DEFINE_PROP_BOOL("lmce", X86CPU, enable_lmce, false), DEFINE_PROP_BOOL("l3-cache", X86CPU, enable_l3_cache, true), + DEFINE_PROP_BOOL("invtsc-migration", X86CPU, invtsc_migration, true), DEFINE_PROP_END_OF_LIST() }; diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 6a51399..2c3ee7b 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -962,7 +962,7 @@ int kvm_arch_init_vcpu(CPUState *cs) has_msr_mcg_ext_ctl = has_msr_feature_control = true; } - if (!env->user_tsc_khz) { + if (!cpu->invtsc_migration && !env->user_tsc_khz) { if ((env->features[FEAT_8000_0007_EDX] & CPUID_APM_INVTSC) && invtsc_mig_blocker == NULL) { /* for migration */ @@ -972,6 +972,7 @@ int kvm_arch_init_vcpu(CPUState *cs) migrate_add_blocker(invtsc_mig_blocker); /* for savevm */ vmstate_x86_cpu.unmigratable = 1; + } } cpuid_data.cpuid.padding = 0; @@ -2655,12 +2656,14 @@ int kvm_arch_put_registers(CPUState *cpu, int level) } if (level == KVM_PUT_FULL_STATE) { - /* We don't check for kvm_arch_set_tsc_khz() errors here, - * because TSC frequency mismatch shouldn't abort migration, - * unless the user explicitly asked for a more strict TSC - * setting (e.g. using an explicit "tsc-freq" option). + /* Migration TSC frequency mismatch is fatal only if we are + * actually reporting Invariant TSC to the guest. */ - kvm_arch_set_tsc_khz(cpu); + ret = kvm_arch_set_tsc_khz(cpu); + if ((x86_cpu->env.features[FEAT_8000_0007_EDX] & CPUID_APM_INVTSC) && + ret < 0) { + return ret; + } } ret = kvm_getput_regs(x86_cpu, 1);