diff mbox

[2/4] kvm: Allow invtsc migration if tsc-khz is set explicitly

Message ID 1482866480-26208-3-git-send-email-ehabkost@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Eduardo Habkost Dec. 27, 2016, 7:21 p.m. UTC
We can safely allow a VM to be migrated with invtsc enabled if
tsc-khz is set explicitly, because QEMU already refuses to start
if it can't set the TSC frequency to the configured value.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 target/i386/kvm.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

Comments

Marcelo Tosatti Jan. 4, 2017, 11:44 a.m. UTC | #1
On Tue, Dec 27, 2016 at 05:21:18PM -0200, Eduardo Habkost wrote:
> We can safely allow a VM to be migrated with invtsc enabled if
> tsc-khz is set explicitly, because QEMU already refuses to start
> if it can't set the TSC frequency to the configured value.

On the source host, yes, but on the destination it does not.

SOURCE: -cpu kvm64,tsc-frequency=2660001000
DESTINATION: -cpu kvm64

Only prints:

qemu-system-x86_64: warning: TSC frequency mismatch between VM (2660001
kHz) and host (2893428 kHz), and TSC scaling unavailable
qemu-system-x86_64: warning: TSC frequency mismatch between VM (2660001
kHz) and host (2893428 kHz), and TSC scaling unavailable

And allows migration.

> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  target/i386/kvm.c | 19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)
> 
> diff --git a/target/i386/kvm.c b/target/i386/kvm.c
> index a26290f..6a51399 100644
> --- a/target/i386/kvm.c
> +++ b/target/i386/kvm.c
> @@ -962,15 +962,16 @@ int kvm_arch_init_vcpu(CPUState *cs)
>          has_msr_mcg_ext_ctl = has_msr_feature_control = true;
>      }
>  
> -    if ((env->features[FEAT_8000_0007_EDX] & CPUID_APM_INVTSC) &&
> -        invtsc_mig_blocker == NULL) {
> -        /* for migration */
> -        error_setg(&invtsc_mig_blocker,
> -                   "State blocked by non-migratable CPU device"
> -                   " (invtsc flag)");
> -        migrate_add_blocker(invtsc_mig_blocker);
> -        /* for savevm */
> -        vmstate_x86_cpu.unmigratable = 1;
> +    if (!env->user_tsc_khz) {
> +        if ((env->features[FEAT_8000_0007_EDX] & CPUID_APM_INVTSC) &&
> +            invtsc_mig_blocker == NULL) {
> +            /* for migration */
> +            error_setg(&invtsc_mig_blocker,
> +                       "State blocked by non-migratable CPU device"
> +                       " (invtsc flag)");
> +            migrate_add_blocker(invtsc_mig_blocker);
> +            /* for savevm */
> +            vmstate_x86_cpu.unmigratable = 1;
>      }
>  
>      cpuid_data.cpuid.padding = 0;
> -- 
> 2.7.4
Marcelo Tosatti Jan. 4, 2017, 11:57 a.m. UTC | #2
On Wed, Jan 04, 2017 at 09:44:06AM -0200, Marcelo Tosatti wrote:
> On Tue, Dec 27, 2016 at 05:21:18PM -0200, Eduardo Habkost wrote:
> > We can safely allow a VM to be migrated with invtsc enabled if
> > tsc-khz is set explicitly, because QEMU already refuses to start
> > if it can't set the TSC frequency to the configured value.
> 
> On the source host, yes, but on the destination it does not.
> 
> SOURCE: -cpu kvm64,tsc-frequency=2660001000
> DESTINATION: -cpu kvm64
> 
> Only prints:
> 
> qemu-system-x86_64: warning: TSC frequency mismatch between VM (2660001
> kHz) and host (2893428 kHz), and TSC scaling unavailable
> qemu-system-x86_64: warning: TSC frequency mismatch between VM (2660001
> kHz) and host (2893428 kHz), and TSC scaling unavailable
> 
> And allows migration.

Ignore that comment, patch 4 deals with it.
Eduardo Habkost Jan. 4, 2017, 1:40 p.m. UTC | #3
On Wed, Jan 04, 2017 at 09:44:06AM -0200, Marcelo Tosatti wrote:
> On Tue, Dec 27, 2016 at 05:21:18PM -0200, Eduardo Habkost wrote:
> > We can safely allow a VM to be migrated with invtsc enabled if
> > tsc-khz is set explicitly, because QEMU already refuses to start
> > if it can't set the TSC frequency to the configured value.
> 
> On the source host, yes, but on the destination it does not.
> 
> SOURCE: -cpu kvm64,tsc-frequency=2660001000
> DESTINATION: -cpu kvm64

This is invalid usage. Management software is responsible for
keeping the same configuration on source and destination.

> 
> Only prints:
> 
> qemu-system-x86_64: warning: TSC frequency mismatch between VM (2660001
> kHz) and host (2893428 kHz), and TSC scaling unavailable
> qemu-system-x86_64: warning: TSC frequency mismatch between VM (2660001
> kHz) and host (2893428 kHz), and TSC scaling unavailable
> 
> And allows migration.
> 
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > ---
> >  target/i386/kvm.c | 19 ++++++++++---------
> >  1 file changed, 10 insertions(+), 9 deletions(-)
> > 
> > diff --git a/target/i386/kvm.c b/target/i386/kvm.c
> > index a26290f..6a51399 100644
> > --- a/target/i386/kvm.c
> > +++ b/target/i386/kvm.c
> > @@ -962,15 +962,16 @@ int kvm_arch_init_vcpu(CPUState *cs)
> >          has_msr_mcg_ext_ctl = has_msr_feature_control = true;
> >      }
> >  
> > -    if ((env->features[FEAT_8000_0007_EDX] & CPUID_APM_INVTSC) &&
> > -        invtsc_mig_blocker == NULL) {
> > -        /* for migration */
> > -        error_setg(&invtsc_mig_blocker,
> > -                   "State blocked by non-migratable CPU device"
> > -                   " (invtsc flag)");
> > -        migrate_add_blocker(invtsc_mig_blocker);
> > -        /* for savevm */
> > -        vmstate_x86_cpu.unmigratable = 1;
> > +    if (!env->user_tsc_khz) {
> > +        if ((env->features[FEAT_8000_0007_EDX] & CPUID_APM_INVTSC) &&
> > +            invtsc_mig_blocker == NULL) {
> > +            /* for migration */
> > +            error_setg(&invtsc_mig_blocker,
> > +                       "State blocked by non-migratable CPU device"
> > +                       " (invtsc flag)");
> > +            migrate_add_blocker(invtsc_mig_blocker);
> > +            /* for savevm */
> > +            vmstate_x86_cpu.unmigratable = 1;
> >      }
> >  
> >      cpuid_data.cpuid.padding = 0;
> > -- 
> > 2.7.4
Marcelo Tosatti Jan. 4, 2017, 1:45 p.m. UTC | #4
On Wed, Jan 04, 2017 at 11:40:17AM -0200, Eduardo Habkost wrote:
> On Wed, Jan 04, 2017 at 09:44:06AM -0200, Marcelo Tosatti wrote:
> > On Tue, Dec 27, 2016 at 05:21:18PM -0200, Eduardo Habkost wrote:
> > > We can safely allow a VM to be migrated with invtsc enabled if
> > > tsc-khz is set explicitly, because QEMU already refuses to start
> > > if it can't set the TSC frequency to the configured value.
> > 
> > On the source host, yes, but on the destination it does not.
> > 
> > SOURCE: -cpu kvm64,tsc-frequency=2660001000
> > DESTINATION: -cpu kvm64
> 
> This is invalid usage. Management software is responsible for
> keeping the same configuration on source and destination.

Fine. Just to confirm: you do not expect libvirt to 
use

        -cpu XXX,tsc-frequency=ZZZZZ

On both source and destination, correct?

> > Only prints:
> > 
> > qemu-system-x86_64: warning: TSC frequency mismatch between VM (2660001
> > kHz) and host (2893428 kHz), and TSC scaling unavailable
> > qemu-system-x86_64: warning: TSC frequency mismatch between VM (2660001
> > kHz) and host (2893428 kHz), and TSC scaling unavailable
> > 
> > And allows migration.
> > 
> > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > > ---
> > >  target/i386/kvm.c | 19 ++++++++++---------
> > >  1 file changed, 10 insertions(+), 9 deletions(-)
> > > 
> > > diff --git a/target/i386/kvm.c b/target/i386/kvm.c
> > > index a26290f..6a51399 100644
> > > --- a/target/i386/kvm.c
> > > +++ b/target/i386/kvm.c
> > > @@ -962,15 +962,16 @@ int kvm_arch_init_vcpu(CPUState *cs)
> > >          has_msr_mcg_ext_ctl = has_msr_feature_control = true;
> > >      }
> > >  
> > > -    if ((env->features[FEAT_8000_0007_EDX] & CPUID_APM_INVTSC) &&
> > > -        invtsc_mig_blocker == NULL) {
> > > -        /* for migration */
> > > -        error_setg(&invtsc_mig_blocker,
> > > -                   "State blocked by non-migratable CPU device"
> > > -                   " (invtsc flag)");
> > > -        migrate_add_blocker(invtsc_mig_blocker);
> > > -        /* for savevm */
> > > -        vmstate_x86_cpu.unmigratable = 1;
> > > +    if (!env->user_tsc_khz) {
> > > +        if ((env->features[FEAT_8000_0007_EDX] & CPUID_APM_INVTSC) &&
> > > +            invtsc_mig_blocker == NULL) {
> > > +            /* for migration */
> > > +            error_setg(&invtsc_mig_blocker,
> > > +                       "State blocked by non-migratable CPU device"
> > > +                       " (invtsc flag)");
> > > +            migrate_add_blocker(invtsc_mig_blocker);
> > > +            /* for savevm */
> > > +            vmstate_x86_cpu.unmigratable = 1;
> > >      }
> > >  
> > >      cpuid_data.cpuid.padding = 0;
> > > -- 
> > > 2.7.4
> 
> -- 
> Eduardo
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Eduardo Habkost Jan. 4, 2017, 1:51 p.m. UTC | #5
On Wed, Jan 04, 2017 at 11:45:36AM -0200, Marcelo Tosatti wrote:
> On Wed, Jan 04, 2017 at 11:40:17AM -0200, Eduardo Habkost wrote:
> > On Wed, Jan 04, 2017 at 09:44:06AM -0200, Marcelo Tosatti wrote:
> > > On Tue, Dec 27, 2016 at 05:21:18PM -0200, Eduardo Habkost wrote:
> > > > We can safely allow a VM to be migrated with invtsc enabled if
> > > > tsc-khz is set explicitly, because QEMU already refuses to start
> > > > if it can't set the TSC frequency to the configured value.
> > > 
> > > On the source host, yes, but on the destination it does not.
> > > 
> > > SOURCE: -cpu kvm64,tsc-frequency=2660001000
> > > DESTINATION: -cpu kvm64
> > 
> > This is invalid usage. Management software is responsible for
> > keeping the same configuration on source and destination.
> 
> Fine. Just to confirm: you do not expect libvirt to 
> use
> 
>         -cpu XXX,tsc-frequency=ZZZZZ
> 
> On both source and destination, correct?

They can omit it, as long as it is omitted on both source and
destination.

If they do use tsc-frequency on the source, they must use it on
the destination as well. Just like they do for every device
option in QEMU.


> 
> > > Only prints:
> > > 
> > > qemu-system-x86_64: warning: TSC frequency mismatch between VM (2660001
> > > kHz) and host (2893428 kHz), and TSC scaling unavailable
> > > qemu-system-x86_64: warning: TSC frequency mismatch between VM (2660001
> > > kHz) and host (2893428 kHz), and TSC scaling unavailable
> > > 
> > > And allows migration.
> > > 
> > > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > > > ---
> > > >  target/i386/kvm.c | 19 ++++++++++---------
> > > >  1 file changed, 10 insertions(+), 9 deletions(-)
> > > > 
> > > > diff --git a/target/i386/kvm.c b/target/i386/kvm.c
> > > > index a26290f..6a51399 100644
> > > > --- a/target/i386/kvm.c
> > > > +++ b/target/i386/kvm.c
> > > > @@ -962,15 +962,16 @@ int kvm_arch_init_vcpu(CPUState *cs)
> > > >          has_msr_mcg_ext_ctl = has_msr_feature_control = true;
> > > >      }
> > > >  
> > > > -    if ((env->features[FEAT_8000_0007_EDX] & CPUID_APM_INVTSC) &&
> > > > -        invtsc_mig_blocker == NULL) {
> > > > -        /* for migration */
> > > > -        error_setg(&invtsc_mig_blocker,
> > > > -                   "State blocked by non-migratable CPU device"
> > > > -                   " (invtsc flag)");
> > > > -        migrate_add_blocker(invtsc_mig_blocker);
> > > > -        /* for savevm */
> > > > -        vmstate_x86_cpu.unmigratable = 1;
> > > > +    if (!env->user_tsc_khz) {
> > > > +        if ((env->features[FEAT_8000_0007_EDX] & CPUID_APM_INVTSC) &&
> > > > +            invtsc_mig_blocker == NULL) {
> > > > +            /* for migration */
> > > > +            error_setg(&invtsc_mig_blocker,
> > > > +                       "State blocked by non-migratable CPU device"
> > > > +                       " (invtsc flag)");
> > > > +            migrate_add_blocker(invtsc_mig_blocker);
> > > > +            /* for savevm */
> > > > +            vmstate_x86_cpu.unmigratable = 1;
> > > >      }
> > > >  
> > > >      cpuid_data.cpuid.padding = 0;
> > > > -- 
> > > > 2.7.4
> > 
> > -- 
> > Eduardo
> > --
> > To unsubscribe from this list: send the line "unsubscribe kvm" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index a26290f..6a51399 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -962,15 +962,16 @@  int kvm_arch_init_vcpu(CPUState *cs)
         has_msr_mcg_ext_ctl = has_msr_feature_control = true;
     }
 
-    if ((env->features[FEAT_8000_0007_EDX] & CPUID_APM_INVTSC) &&
-        invtsc_mig_blocker == NULL) {
-        /* for migration */
-        error_setg(&invtsc_mig_blocker,
-                   "State blocked by non-migratable CPU device"
-                   " (invtsc flag)");
-        migrate_add_blocker(invtsc_mig_blocker);
-        /* for savevm */
-        vmstate_x86_cpu.unmigratable = 1;
+    if (!env->user_tsc_khz) {
+        if ((env->features[FEAT_8000_0007_EDX] & CPUID_APM_INVTSC) &&
+            invtsc_mig_blocker == NULL) {
+            /* for migration */
+            error_setg(&invtsc_mig_blocker,
+                       "State blocked by non-migratable CPU device"
+                       " (invtsc flag)");
+            migrate_add_blocker(invtsc_mig_blocker);
+            /* for savevm */
+            vmstate_x86_cpu.unmigratable = 1;
     }
 
     cpuid_data.cpuid.padding = 0;