migration: Two migration bug fixes
cover migration: Two migration bug fixes
Hello,
This small series fixes two migration bugs I stumbled upon recently. Comments are welcome, thanks for reviewing.
Avihai Horon (2):
migration: Set migration error in migration_completion() migration/postcopy: Ensure postcopy_start() sets errp if it fails
migration/migration.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
Signature · 1 line
2.26.3
PATCH 1/2 migration: Set migration error in migration_completion()
After commit 9425ef3f990a ("migration: Use migrate_has_error() in close_return_path_on_source()"), close_return_path_on_source() assumes that migration error is set if an error occurs during migration.
This may not be true if migration errors in migration_completion(). For example, if qemu_savevm_state_complete_precopy() errors, migration error will not be set.
This in turn, will cause a migration hang bug, similar to the bug that was fixed by commit 22b04245f0d5 ("migration: Join the return path thread before releasing to_dst_file"), as shutdown() will not be issued for the return-path channel.
Fix it by ensuring migration error is set in case of error in migration_completion().
--- migration/migration.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
migration/migration.c +10 -0
@@ -2799,6 +2799,7 @@ static void migration_completion(MigrationState *s) {int ret =0 ;int current_active_state = s->state; +Error *local_err =NULL ;if (s->state ==MIGRATION_STATUS_ACTIVE ) { ret =migration_completion_precopy (s, ¤t_active_state);
@@ -2832,6 +2833,15 @@ static void migration_completion(MigrationState *s)return ; fail: +if (qemu_file_get_error_obj (s->to_dst_file, &local_err)) { +migrate_set_error (s, local_err); +error_free (local_err); + }else if (ret) { +error_setg_errno (&local_err, -ret,"Error in migration completion" ); +migrate_set_error (s, local_err); +error_free (local_err); + } +migration_completion_failed (s, current_active_state); }
Signature · 1 line
2.26.3
Re: [PATCH for-9.0 1/2] migration: Set migration error in migration_completion()
Quoted 13 lines · Avihai Horon
After commit
9425ef3f990a("migration: Usemigrate_has_error()inclose_return_path_on_source()"),close_return_path_on_source()assumes that migration error is set if an error occurs during migration.This may not be true if migration errors in
migration_completion(). For example, ifqemu_savevm_state_complete_precopy()errors, migration error will not be set.This in turn, will cause a migration hang bug, similar to the bug that was fixed by commit
22b04245f0d5("migration: Join the return path thread before releasingto_dst_file"), asshutdown()will not be issued for the return-path channel.
Quoted 4 lines
Fix it by ensuring migration error is set in case of error in
migration_completion().Signed-off-by Avihai Horon <[email protected]>
I'll attach this if it looks all right to you:
Thanks,
Quoted 36 lines
--- migration/migration.c | 10 ++++++++++ 1 file changed, 10 insertions(+)migration/migration.c +10
-0@@ -2799,6 +2799,7 @@ static void migration_completion(MigrationState *s) {int ret =0 ;int current_active_state = s->state; +Error *local_err =NULL ;if (s->state ==MIGRATION_STATUS_ACTIVE ) { ret =migration_completion_precopy (s, ¤t_active_state);@@ -2832,6 +2833,15 @@ static void migration_completion(MigrationState *s)return ; fail: +if (qemu_file_get_error_obj (s->to_dst_file, &local_err)) { +migrate_set_error (s, local_err); +error_free (local_err); + }else if (ret) { +error_setg_errno (&local_err, -ret,"Error in migration completion" ); +migrate_set_error (s, local_err); +error_free (local_err); + } +migration_completion_failed (s, current_active_state); }Signature · 1 line
2.26.3
Signature · 1 line
Peter Xu
Re: [PATCH for-9.0 1/2] migration: Set migration error in migration_completion()
Quoted 20 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 16 lines · Avihai Horon
After commit
9425ef3f990a("migration: Usemigrate_has_error()inclose_return_path_on_source()"),close_return_path_on_source()assumes that migration error is set if an error occurs during migration.This may not be true if migration errors in
migration_completion(). For example, ifqemu_savevm_state_complete_precopy()errors, migration error will not be set.This in turn, will cause a migration hang bug, similar to the bug that was fixed by commit
22b04245f0d5("migration: Join the return path thread before releasingto_dst_file"), asshutdown()will not be issued for the return-path channel.Fix it by ensuring migration error is set in case of error in
migration_completion().
Quoted 6 lines
Quoted 1 line
Signed-off-by Avihai Horon <[email protected]>Reviewed-by Peter Xu <[email protected]>I'll attach this if it looks all right to you:
Fixes 9425ef3f990a ("migration: Use migrate_has_error() in close_return_path_on_source()")
Yes, sure, go ahead.
Thanks.
Quoted 42 lines
Thanks,
Quoted 33 lines
--- migration/migration.c | 10 ++++++++++ 1 file changed, 10 insertions(+)migration/migration.c +10
-1@@ -2799,6 +2799,7 @@ static void migration_completion(MigrationState *s) {int ret =0 ;int current_active_state = s->state; +Error *local_err =NULL ;if (s->state ==MIGRATION_STATUS_ACTIVE ) { ret =migration_completion_precopy (s, ¤t_active_state);@@ -2832,6 +2833,15 @@ static void migration_completion(MigrationState *s)return ; fail: +if (qemu_file_get_error_obj (s->to_dst_file, &local_err)) { +migrate_set_error (s, local_err); +error_free (local_err); + }else if (ret) { +error_setg_errno (&local_err, -ret,"Error in migration completion" ); +migrate_set_error (s, local_err); +error_free (local_err); + } +migration_completion_failed (s, current_active_state); } --Quoted 3 lines
2.26.3
--
Peter Xu
Re: [PATCH for-9.0 1/2] migration: Set migration error in migration_completion()
In reply to Avihai HoronHello Avihai,
Quoted 7 lines · Avihai Horon
After commit
9425ef3f990a("migration: Usemigrate_has_error()inclose_return_path_on_source()"),close_return_path_on_source()assumes that migration error is set if an error occurs during migration.This may not be true if migration errors in
migration_completion(). For example, ifqemu_savevm_state_complete_precopy()errors, migration error will not be set
Out of curiosity, could you describe a bit more the context ? Did vfio_save_complete_precopy() fail ? why ?
We should propagate errors of .save_live_complete_precopy() handlers as it was done .save_setup handlers(). For 9.1.
Quoted 4 lines
This in turn, will cause a migration hang bug, similar to the bug that was fixed by commit
22b04245f0d5("migration: Join the return path thread before releasingto_dst_file"), asshutdown()will not be issued for the return-path channel.
yes, but this test :
if (ret < 0) {
goto fail;
}will skip the close_return_path_on_source() call. Won't it ? So I don't understand how it can be an issue. Am I missing something ?
Quoted 2 lines
Fix it by ensuring migration error is set in case of error in
migration_completion().
Why didn't you add a reference to commit 9425ef3f990a ?
Quoted 18 lines
Signed-off-by Avihai Horon <[email protected]>--- migration/migration.c | 10 ++++++++++ 1 file changed, 10 insertions(+)migration/migration.c +1
-0@@ -2799,6 +2799,7 @@ static void migration_completion(MigrationState *s) {int ret =0 ;int current_active_state = s->state; +Error *local_err =NULL ;if (s->state ==MIGRATION_STATUS_ACTIVE ) { ret =migration_completion_precopy (s, ¤t_active_state);
migration/migration.c static void migration_completion(MigrationState *s) · line 2840
Quoted 8 lines
migration/migration.c +5
-0@@ -2832,6 +2833,15 @@ static void migration_completion(MigrationState *s)return ; fail: +if (qemu_file_get_error_obj (s->to_dst_file, &local_err)) { +migrate_set_error (s, local_err); +error_free (local_err); + }else if (ret) { +error_setg_errno (&local_err, -ret,"Error in migration completion" );
The 'ret = -1' case could be improved with error_setg(). As a followup.
Thanks,
C.
Quoted 7 lines
migration/migration.c +4
-0+migrate_set_error (s, local_err); +error_free (local_err); + } +migration_completion_failed (s, current_active_state); }
Re: [PATCH for-9.0 1/2] migration: Set migration error in migration_completion()
Quoted 10 lines · Cédric Le Goater
External email: Use caution opening links or attachments
Hello Avihai,
Quoted 4 lines · Avihai Horon
After commit
9425ef3f990a("migration: Usemigrate_has_error()inclose_return_path_on_source()"),close_return_path_on_source()assumes that migration error is set if an error occurs during migration.
Quoted 6 lines
Quoted 3 lines
This may not be true if migration errors in
migration_completion(). For example, ifqemu_savevm_state_complete_precopy()errors, migration error will not be setOut of curiosity, could you describe a bit more the context ? Did
vfio_save_complete_precopy()fail ? why ?
Yep, vfio_save_complete_precopy() failed (but it failed while I was experimenting with an unofficial debug FW).
Quoted 3 lines
We should propagate errors of .save_live_complete_precopy() handlers as it was done .save_setup
handlers(). For 9.1.
Agreed.
Quoted 6 lines
Quoted 5 lines
This in turn, will cause a migration hang bug, similar to the bug that was fixed by commit
22b04245f0d5("migration: Join the return path thread before releasingto_dst_file"), asshutdown()will not be issued for the return-path channel.
Quoted 8 lines
yes, but this test :
if (ret < 0) {
goto fail;
}will skip the
close_return_path_on_source()call. Won't it ? So I don't understand how it can be an issue. Am I missing something ?
It will skip the close_return_path_on_source() call in migration_completion(), but there is another close_return_path_on_source() call in migrate_fd_cleanup().
Quoted 5 lines
Quoted 3 lines
Fix it by ensuring migration error is set in case of error in
migration_completion().Why didn't you add a reference to commit
9425ef3f990a?
I thought this commit didn't introduce this bug, but looking again in the mailing list [1], it kinda did:
The hang bug was fully fixed by commit 22b04245f0d ("migration: Join the return path thread before releasing to_dst_file") and then 9425ef3f990a re-introduced the bug, but only for migration_completion() case. So, you are right, a fixes line with 9425ef3f990a should be added.
Thanks.
[1] https://lore.kernel.org/all/[email protected]/
Quoted 49 lines
Quoted 24 lines
Signed-off-by Avihai Horon <[email protected]>---
migration/migration.c| 10 ++++++++++1 file changed, 10 insertions(+)migration/migration.c +1
-0@@ -2799,6 +2799,7 @@ static void migration_completion(MigrationState *s) { int ret = 0; int current_active_state = s->state; + Error *local_err = NULL; if (s->state == MIGRATION_STATUS_ACTIVE) {ret =
migration_completion_precopy(s, ¤t_active_state);migration/migration.c +0
-0@@ -2832,6 +2833,15 @@ static voidmigration_completion (MigrationState *s) return;Quoted 7 lines
fail:
+ if (qemu_file_get_error_obj(s->to_dst_file, &local_err)) { +migrate_set_error(s, local_err);
+error_free(local_err);
+ } else if (ret) {
+error_setg_errno(&local_err, -ret, "Error in migration completion");The 'ret = -1' case could be improved with
error_setg(). As a followup.Thanks,
C.
Quoted 7 lines
+
migrate_set_error(s, local_err);
+error_free(local_err);
+ }
+
migration_completion_failed(s, current_active_state); }
Cédric Le Goater
Acked-byRe: [PATCH for-9.0 1/2] migration: Set migration error in migration_completion()
Quoted 35 lines · Avihai Horon
Quoted 10 lines · Cédric Le Goater
External email: Use caution opening links or attachments
Hello Avihai,
Quoted 4 lines · Avihai Horon
After commit
9425ef3f990a("migration: Usemigrate_has_error()inclose_return_path_on_source()"),close_return_path_on_source()assumes that migration error is set if an error occurs during migration.Quoted 6 lines
Quoted 3 lines
This may not be true if migration errors in
migration_completion(). For example, ifqemu_savevm_state_complete_precopy()errors, migration error will not be setOut of curiosity, could you describe a bit more the context ? Did
vfio_save_complete_precopy()fail ? why ?Yep,
vfio_save_complete_precopy()failed (but it failed while I was experimenting with an unofficial debug FW).Quoted 3 lines
We should propagate errors of .save_live_complete_precopy() handlers as it was done .save_setup
handlers(). For 9.1.Agreed.
Quoted 8 lines
Quoted 5 lines
This in turn, will cause a migration hang bug, similar to the bug that was fixed by commit
22b04245f0d5("migration: Join the return path thread before releasingto_dst_file"), asshutdown()will not be issued for the return-path channel.yes, but this test :
Quoted 8 lines
Quoted 6 lines
if (ret < 0) {
goto fail;
}will skip the
close_return_path_on_source()call. Won't it ? So I don't understand how it can be an issue. Am I missing something ?It will skip the
close_return_path_on_source()call inmigration_completion(), but there is anotherclose_return_path_on_source()call inmigrate_fd_cleanup().
OK. Found it. This is a code path I hadn't explored yet.
Thanks,
C.
Quoted 62 lines
Quoted 6 lines
Quoted 4 lines
Fix it by ensuring migration error is set in case of error in
migration_completion().Why didn't you add a reference to commit
9425ef3f990a?I thought this commit didn't introduce this bug, but looking again in the mailing list [1], it kinda did:
The hang bug was fully fixed by commit22b04245f0d("migration: Join the return path thread before releasingto_dst_file") and then9425ef3f990are-introduced the bug, but only formigration_completion()case. So, you are right, a fixes line with9425ef3f990ashould be added.Thanks.
[1] https://lore.kernel.org/all/[email protected]/
Quoted 46 lines
Quoted 22 lines
Signed-off-by Avihai Horon <[email protected]>---
migration/migration.c| 10 ++++++++++1 file changed, 10 insertions(+)migration/migration.c +1
-0@@ -2799,6 +2799,7 @@ static void migration_completion(MigrationState *s) { int ret = 0; int current_active_state = s->state; + Error *local_err = NULL; if (s->state == MIGRATION_STATUS_ACTIVE) { ret = migration_completion_precopy(s, ¤t_active_state);@@ -2832,6 +2833,15 @@ static void migration_completion(MigrationState *s) return;Quoted 6 lines
fail:
+ if (qemu_file_get_error_obj(s->to_dst_file, &local_err)) {
+migrate_set_error(s, local_err);
+error_free(local_err);
+ } else if (ret) {
+error_setg_errno(&local_err, -ret, "Error in migration completion");The 'ret = -1' case could be improved with
error_setg(). As a followup.Thanks,
C.
Quoted 7 lines
+
migrate_set_error(s, local_err);
+error_free(local_err);
+ }
+
migration_completion_failed(s, current_active_state); }
PATCH 2/2 migration/postcopy: Ensure postcopy_start() sets errp if it fails
In reply to Avihai HoronThere are several places where postcopy_start() fails without setting errp. This can cause a null pointer de-reference, as in case of error, the caller of postcopy_start() copies/prints the error set in errp.
Fix it by setting errp in all of postcopy_start() error paths.
--- migration/migration.c | 8 ++++++++ 1 file changed, 8 insertions(+)
migration/migration.c +8 -0
@@ -2510,6 +2510,8 @@ static int postcopy_start(MigrationState *ms, Error **errp)migration_wait_main_channel (ms);if (postcopy_preempt_establish_channel (ms)) {migrate_set_state (&ms->state, ms->state,MIGRATION_STATUS_FAILED ); +error_setg (errp,"%s: Failed to establish preempt channel" , + __func__);return -1 ; } }
@@ -2525,17 +2527,22 @@ static int postcopy_start(MigrationState *ms, Error **errp) ret =migration_stop_vm (ms,RUN_STATE_FINISH_MIGRATE );if (ret <0 ) { +error_setg_errno (errp, -ret,"%s: Failed to stop the VM" , __func__); goto fail; } ret =migration_maybe_pause (ms, &cur_state,MIGRATION_STATUS_POSTCOPY_ACTIVE );if (ret <0 ) { +error_setg_errno (errp, -ret,"%s: Failed in migration_maybe_pause()" , + __func__); goto fail; } ret =bdrv_inactivate_all ();if (ret <0 ) { +error_setg_errno (errp, -ret,"%s: Failed in bdrv_inactivate_all()" , + __func__); goto fail; } restart_block = true;
@@ -2612,6 +2619,7 @@ static int postcopy_start(MigrationState *ms, Error **errp)/* Now send that blob */ if (qemu_savevm_send_packaged (ms->to_dst_file, bioc->data, bioc->usage)) { +error_setg (errp,"%s: Failed to send packaged data" , __func__); goto fail_closefb; }qemu_fclose (fb);
Signature · 1 line
2.26.3
Re: [PATCH for-9.0 2/2] migration/postcopy: Ensure postcopy_start() sets errp if it fails
Quoted 8 lines · Avihai Horon
There are several places where
postcopy_start()fails without setting errp. This can cause a null pointer de-reference, as in case of error, the caller ofpostcopy_start()copies/prints the error set in errp.Fix it by setting errp in all of
postcopy_start()error paths.Fixes 908927db28ea ("migration: Update error description whenever migration fails")Signed-off-by Avihai Horon <[email protected]>
Thanks,
C.
Quoted 48 lines
--- migration/migration.c | 8 ++++++++ 1 file changed, 8 insertions(+)migration/migration.c +8
-0@@ -2510,6 +2510,8 @@ static int postcopy_start(MigrationState *ms, Error **errp)migration_wait_main_channel (ms);if (postcopy_preempt_establish_channel (ms)) {migrate_set_state (&ms->state, ms->state,MIGRATION_STATUS_FAILED ); +error_setg (errp,"%s: Failed to establish preempt channel" , + __func__);return -1 ; } }@@ -2525,17 +2527,22 @@ static int postcopy_start(MigrationState *ms, Error **errp) ret =migration_stop_vm (ms,RUN_STATE_FINISH_MIGRATE );if (ret <0 ) { +error_setg_errno (errp, -ret,"%s: Failed to stop the VM" , __func__); goto fail; } ret =migration_maybe_pause (ms, &cur_state,MIGRATION_STATUS_POSTCOPY_ACTIVE );if (ret <0 ) { +error_setg_errno (errp, -ret,"%s: Failed in migration_maybe_pause()" , + __func__); goto fail; } ret =bdrv_inactivate_all ();if (ret <0 ) { +error_setg_errno (errp, -ret,"%s: Failed in bdrv_inactivate_all()" , + __func__); goto fail; } restart_block = true;@@ -2612,6 +2619,7 @@ static int postcopy_start(MigrationState *ms, Error **errp)/* Now send that blob */ if (qemu_savevm_send_packaged (ms->to_dst_file, bioc->data, bioc->usage)) { +error_setg (errp,"%s: Failed to send packaged data" , __func__); goto fail_closefb; }qemu_fclose (fb);
Re: [PATCH for-9.0 2/2] migration/postcopy: Ensure postcopy_start() sets errp if it fails
In reply to Avihai HoronQuoted 7 lines · Avihai Horon
There are several places where
postcopy_start()fails without setting errp. This can cause a null pointer de-reference, as in case of error, the caller ofpostcopy_start()copies/prints the error set in errp.Fix it by setting errp in all of
postcopy_start()error paths.Fixes 908927db28ea ("migration: Update error description whenever migration fails")
I think this should need:
Quoted 1 line
Signed-off-by Avihai Horon <[email protected]>
Signature · 1 line
Peter Xu
Peter Xu
AppliedQuoted 8 lines · Avihai Horon
Hello,
This small series fixes two migration bugs I stumbled upon recently. Comments are welcome, thanks for reviewing.
Avihai Horon (2):
migration: Set migration error inmigration_completion()migration/postcopy: Ensurepostcopy_start()sets errp if it fails
queued for 9.0-rc2, thanks.
Signature · 1 line
Peter Xu