[Qemu-devel] [PATCH] migration: savevm: consult migration blockers

Paolo Bonzini posted 1 patch 6 years, 11 months ago
Test asan passed
Test checkpatch passed
Test docker-quick@centos7 passed
Test docker-mingw@fedora passed
Test docker-clang@ubuntu passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20181116164806.26929-2-pbonzini@redhat.com
migration/savevm.c | 4 ++++
target/i386/kvm.c  | 3 ---
2 files changed, 4 insertions(+), 3 deletions(-)
[Qemu-devel] [PATCH] migration: savevm: consult migration blockers
Posted by Paolo Bonzini 6 years, 11 months ago
There is really no difference between live migration and savevm, except
that savevm does not require bdrv_invalidate_cache to be implemented
by all disks.  However, it is unlikely that savevm is used with anything
except qcow2 disks, so the penalty is small and worth the improvement
in catching bad usage of savevm.

Only one place was taking care of savevm when adding a migration blocker,
and it can be removed.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 migration/savevm.c | 4 ++++
 target/i386/kvm.c  | 3 ---
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/migration/savevm.c b/migration/savevm.c
index ef707b8c43..1c49776a91 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -2455,6 +2455,10 @@ int save_snapshot(const char *name, Error **errp)
     struct tm tm;
     AioContext *aio_context;
 
+    if (migration_is_blocked(errp)) {
+        return false;
+    }
+
     if (!replay_can_snapshot()) {
         error_setg(errp, "Record/replay does not allow making snapshot "
                    "right now. Try once more later.");
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index 3b6fbd3f20..d222b68fe4 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -1284,7 +1284,6 @@ int kvm_arch_init_vcpu(CPUState *cs)
     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)");
@@ -1294,8 +1293,6 @@ int kvm_arch_init_vcpu(CPUState *cs)
                 error_free(invtsc_mig_blocker);
                 return r;
             }
-            /* for savevm */
-            vmstate_x86_cpu.unmigratable = 1;
         }
     }
 
-- 
2.19.1


Re: [Qemu-devel] [PATCH] migration: savevm: consult migration blockers
Posted by Dr. David Alan Gilbert 6 years, 11 months ago
* Paolo Bonzini (pbonzini@redhat.com) wrote:
> There is really no difference between live migration and savevm, except
> that savevm does not require bdrv_invalidate_cache to be implemented
> by all disks.  However, it is unlikely that savevm is used with anything
> except qcow2 disks, so the penalty is small and worth the improvement
> in catching bad usage of savevm.
> 
> Only one place was taking care of savevm when adding a migration blocker,
> and it can be removed.

OK, I'm not sure if it was actually a split between savevm and migration
or just that the migration blockers were added later.

> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  migration/savevm.c | 4 ++++
>  target/i386/kvm.c  | 3 ---
>  2 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/migration/savevm.c b/migration/savevm.c
> index ef707b8c43..1c49776a91 100644
> --- a/migration/savevm.c
> +++ b/migration/savevm.c
> @@ -2455,6 +2455,10 @@ int save_snapshot(const char *name, Error **errp)
>      struct tm tm;
>      AioContext *aio_context;
>  
> +    if (migration_is_blocked(errp)) {
> +        return false;
> +    }
> +
>      if (!replay_can_snapshot()) {
>          error_setg(errp, "Record/replay does not allow making snapshot "
>                     "right now. Try once more later.");
> diff --git a/target/i386/kvm.c b/target/i386/kvm.c
> index 3b6fbd3f20..d222b68fe4 100644
> --- a/target/i386/kvm.c
> +++ b/target/i386/kvm.c
> @@ -1284,7 +1284,6 @@ int kvm_arch_init_vcpu(CPUState *cs)
>      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)");
> @@ -1294,8 +1293,6 @@ int kvm_arch_init_vcpu(CPUState *cs)
>                  error_free(invtsc_mig_blocker);
>                  return r;
>              }
> -            /* for savevm */
> -            vmstate_x86_cpu.unmigratable = 1;

So that means vmstate_x86_cpu can be static now - but why does it live
in machine.c rather than cpu.c ?

Dave

>          }
>      }
>  
> -- 
> 2.19.1
> 
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

Re: [Qemu-devel] [PATCH] migration: savevm: consult migration blockers
Posted by Paolo Bonzini 6 years, 11 months ago
On 16/11/18 18:12, Dr. David Alan Gilbert wrote:
> * Paolo Bonzini (pbonzini@redhat.com) wrote:
>> There is really no difference between live migration and savevm, except
>> that savevm does not require bdrv_invalidate_cache to be implemented
>> by all disks.  However, it is unlikely that savevm is used with anything
>> except qcow2 disks, so the penalty is small and worth the improvement
>> in catching bad usage of savevm.
>>
>> Only one place was taking care of savevm when adding a migration blocker,
>> and it can be removed.
> 
> OK, I'm not sure if it was actually a split between savevm and migration
> or just that the migration blockers were added later.

Just the latter, I think.

>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>>  migration/savevm.c | 4 ++++
>>  target/i386/kvm.c  | 3 ---
>>  2 files changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/migration/savevm.c b/migration/savevm.c
>> index ef707b8c43..1c49776a91 100644
>> --- a/migration/savevm.c
>> +++ b/migration/savevm.c
>> @@ -2455,6 +2455,10 @@ int save_snapshot(const char *name, Error **errp)
>>      struct tm tm;
>>      AioContext *aio_context;
>>  
>> +    if (migration_is_blocked(errp)) {
>> +        return false;
>> +    }
>> +
>>      if (!replay_can_snapshot()) {
>>          error_setg(errp, "Record/replay does not allow making snapshot "
>>                     "right now. Try once more later.");
>> diff --git a/target/i386/kvm.c b/target/i386/kvm.c
>> index 3b6fbd3f20..d222b68fe4 100644
>> --- a/target/i386/kvm.c
>> +++ b/target/i386/kvm.c
>> @@ -1284,7 +1284,6 @@ int kvm_arch_init_vcpu(CPUState *cs)
>>      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)");
>> @@ -1294,8 +1293,6 @@ int kvm_arch_init_vcpu(CPUState *cs)
>>                  error_free(invtsc_mig_blocker);
>>                  return r;
>>              }
>> -            /* for savevm */
>> -            vmstate_x86_cpu.unmigratable = 1;
> 
> So that means vmstate_x86_cpu can be static now - but why does it live
> in machine.c rather than cpu.c ?

Generally all vmstate lives in machine.c.  Just historical reasons, it
was moved out of vl.c (!) many moons ago.

Paolo


Re: [Qemu-devel] [PATCH] migration: savevm: consult migration blockers
Posted by Wang, Wei W 6 years, 11 months ago
On Saturday, November 17, 2018 12:48 AM, Paolo Bonzini wrote:
> To: qemu-devel@nongnu.org
> Subject: [Qemu-devel] [PATCH] migration: savevm: consult migration
> blockers
> 
> There is really no difference between live migration and savevm, except that
> savevm does not require bdrv_invalidate_cache to be implemented by all
> disks.  However, it is unlikely that savevm is used with anything except qcow2
> disks, so the penalty is small and worth the improvement in catching bad
> usage of savevm.
> 
> Only one place was taking care of savevm when adding a migration blocker,
> and it can be removed.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  migration/savevm.c | 4 ++++
>  target/i386/kvm.c  | 3 ---
>  2 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/migration/savevm.c b/migration/savevm.c index
> ef707b8c43..1c49776a91 100644
> --- a/migration/savevm.c
> +++ b/migration/savevm.c
> @@ -2455,6 +2455,10 @@ int save_snapshot(const char *name, Error
> **errp)
>      struct tm tm;
>      AioContext *aio_context;
> 
> +    if (migration_is_blocked(errp)) {
> +        return false;

Just curious why returning false here when the returning type is "int"

Best,
Wei