From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Cc: Marcelo Tosatti <mtosatti@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
kvm@vger.kernel.org, Haozhong Zhang <haozhong.zhang@intel.com>
Subject: [Qemu-devel] [PATCH 4/4] kvm: Allow migration with invtsc
Date: Tue, 27 Dec 2016 17:21:20 -0200 [thread overview]
Message-ID: <1482866480-26208-5-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1482866480-26208-1-git-send-email-ehabkost@redhat.com>
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 <ehabkost@redhat.com>
---
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);
--
2.7.4
next prev parent reply other threads:[~2016-12-27 19:21 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-27 19:21 [Qemu-devel] [PATCH 0/4] Allow migration with invtsc if there's no frequency mismatch Eduardo Habkost
2016-12-27 19:21 ` [Qemu-devel] [PATCH 1/4] kvm: Simplify invtsc check Eduardo Habkost
2016-12-29 18:57 ` Marcelo Tosatti
2016-12-27 19:21 ` [Qemu-devel] [PATCH 2/4] kvm: Allow invtsc migration if tsc-khz is set explicitly Eduardo Habkost
2017-01-04 11:44 ` Marcelo Tosatti
2017-01-04 11:57 ` Marcelo Tosatti
2017-01-04 13:40 ` Eduardo Habkost
2017-01-04 13:45 ` Marcelo Tosatti
2017-01-04 13:51 ` Eduardo Habkost
2016-12-27 19:21 ` [Qemu-devel] [PATCH 3/4] pc: Add 2.9 machine-types Eduardo Habkost
2016-12-30 13:38 ` Igor Mammedov
2017-01-04 14:01 ` Laszlo Ersek
2017-01-04 14:20 ` Eduardo Habkost
2017-01-04 16:40 ` Laszlo Ersek
2017-01-04 17:46 ` Eduardo Habkost
2016-12-27 19:21 ` Eduardo Habkost [this message]
2017-01-04 11:56 ` [Qemu-devel] [PATCH 4/4] kvm: Allow migration with invtsc Marcelo Tosatti
2017-01-04 13:39 ` Eduardo Habkost
2017-01-04 19:59 ` [Qemu-devel] TSC frequency configuration & invtsc migration (was Re: [PATCH 4/4] kvm: Allow migration with invtsc) Eduardo Habkost
2017-01-04 22:26 ` Marcelo Tosatti
2017-01-05 1:36 ` Eduardo Habkost
2017-01-05 10:48 ` Marcelo Tosatti
2017-01-05 10:50 ` Marcelo Tosatti
2017-01-05 12:19 ` Eduardo Habkost
2017-01-05 12:33 ` [Qemu-devel] [libvirt] " Daniel P. Berrange
2017-01-05 12:48 ` Eduardo Habkost
2017-01-05 13:00 ` Daniel P. Berrange
2017-01-05 13:11 ` Eduardo Habkost
2017-01-10 16:38 ` Paolo Bonzini
2017-01-06 10:31 ` [Qemu-devel] " Marcelo Tosatti
2017-01-08 15:49 ` [Qemu-devel] How to make dest host abort migration safely " Eduardo Habkost
2017-01-09 10:04 ` Dr. David Alan Gilbert
2017-01-08 20:28 ` [Qemu-devel] Exporting kvm_max_guest_tsc_khz to userspace " Eduardo Habkost
2017-01-09 14:58 ` Paolo Bonzini
2017-01-11 13:26 ` Eduardo Habkost
2017-01-11 14:06 ` Paolo Bonzini
2017-01-10 16:36 ` [Qemu-devel] TSC frequency configuration & invtsc migration " Paolo Bonzini
2017-01-11 11:58 ` Eduardo Habkost
2017-01-18 11:55 ` Marcelo Tosatti
2017-01-18 12:43 ` Eduardo Habkost
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1482866480-26208-5-git-send-email-ehabkost@redhat.com \
--to=ehabkost@redhat.com \
--cc=haozhong.zhang@intel.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).