Multifd fixes
cover Multifd fixes
Hi, a couple of multifd fixes to issues that Jim spotted while working on mapped-ram for libvirt.
CI run: https://gitlab.com/farosas/qemu/-/pipelines/1397467740
Fabiano Rosas (2):
migration: Fix cleanup of iochannel in file migration migration/multifd: Fix multifd_send_setup cleanup when channel
creation fails
migration/file.c | 2 -- migration/multifd.c | 26 +++++++++++++++----------- 2 files changed, 15 insertions(+), 13 deletions(-)
Signature · 1 line
2.35.3
PATCH 1/2 migration: Fix cleanup of iochannel in file migration
The QIOChannelFile object already has its reference decremented by g_autoptr. Trying to unref an extra time causes:
ERROR:../qom/object.c:1241:object_unref: assertion failed: (obj->ref > 0)
--- migration/file.c | 2 -- 1 file changed, 2 deletions(-)
migration/file.c +0 -2
@@ -112,7 +112,6 @@ void file_start_outgoing_migration(MigrationState *s,error_setg_errno (errp, errno,"failed to truncate migration file to offset %" PRIx64, offset); -object_unref (OBJECT (fioc));return ; }
@@ -120,7 +119,6 @@ void file_start_outgoing_migration(MigrationState *s, ioc =QIO_CHANNEL (fioc);if (offset &&qio_channel_io_seek (ioc, offset,SEEK_SET , errp) <0 ) { -object_unref (OBJECT (fioc));return ; }qio_channel_set_name (ioc,"migration-file-outgoing" );
Signature · 1 line
2.35.3
Re: [PATCH 1/2] migration: Fix cleanup of iochannel in file migration
Quoted 9 lines · Fabiano Rosas
The QIOChannelFile object already has its reference decremented by
g_autoptr. Trying to unref an extra time causes:ERROR:../qom/object.c:1241:object_unref: assertion failed: (
obj->ref> 0)Fixes a701c03dec ("migration: Drop reference to QIOChannel if file seeking fails")Fixes 6d3279655a ("migration: Fix file migration with fdset")Reported-by Jim Fehlig <[email protected]>Signed-off-by Fabiano Rosas <[email protected]>
Ouch..
Signature · 1 line
Peter Xu
PATCH 2/2 migration/multifd: Fix multifd_send_setup cleanup when channel creation fails
In reply to Fabiano RosasWhen a channel fails to create, the code currently just returns. This is wrong for two reasons:
1) Channel n+1 will not get to initialize it's semaphores, leading to an assert when terminate_threads tries to post to it:
qemu-system-x86_64: ../util/qemu-thread-posix.c:92:
qemu_mutex_lock_impl: Assertion `mutex->initialized' failed.
2) (theoretical) If channel n-1 already started creation it will defeat the purpose of the channels_created logic which is in place to avoid migrate_fd_cleanup() to run while channels are still being created.
This cannot really happen today because the current failure cases for multifd_new_send_channel_create() are all synchronous, resulting from qio_channel_file_new_path() getting a bad filename. This would hit all channels equally.
But I don't want to set a trap for future people, so have all channels try to create (even if failing), and only fail after the channels_created semaphore has been posted.
While here, remove the error_report_err call. There's one already at migrate_fd_cleanup later on.
--- migration/multifd.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)
migration/multifd.c +15 -11
@@ -1156,7 +1156,6 @@ static bool multifd_new_send_channel_create(gpointer opaque, Error **errp)bool multifd_send_setup (void ) {MigrationState *s =migrate_get_current (); -Error *local_err =NULL ;int thread_count, ret =0 ;uint32_t page_count =MULTIFD_PACKET_SIZE /qemu_target_page_size ();bool use_packets =multifd_use_packets ();
@@ -1177,6 +1176,7 @@ bool multifd_send_setup(void)for (i =0 ; i < thread_count; i++) {MultiFDSendParams *p = &multifd_send_state->params[i]; +Error *local_err =NULL ;qemu_sem_init (&p->sem,0 );qemu_sem_init (&p->sem_sync,0 );
@@ -1196,7 +1196,8 @@ bool multifd_send_setup(void) p->write_flags =0 ;if (!multifd_new_send_channel_create (p, &local_err)) { -return false; +migrate_set_error (s, local_err); + ret =-1 ; } }
@@ -1209,24 +1210,27 @@ bool multifd_send_setup(void)qemu_sem_wait (&multifd_send_state->channels_created); } +if (ret) { + goto err; + } +for (i =0 ; i < thread_count; i++) {MultiFDSendParams *p = &multifd_send_state->params[i]; +Error *local_err =NULL ; ret = multifd_send_state->ops->send_setup (p, &local_err);if (ret) { -break ; +migrate_set_error (s, local_err); + goto err; } } -if (ret) { -migrate_set_error (s, local_err); -error_report_err (local_err); -migrate_set_state (&s->state,MIGRATION_STATUS_SETUP , -MIGRATION_STATUS_FAILED ); -return false; - } -return true; + +err: +migrate_set_state (&s->state,MIGRATION_STATUS_SETUP , +MIGRATION_STATUS_FAILED ); +return false; }bool multifd_recv (void )
Signature · 1 line
2.35.3
Re: [PATCH 2/2] migration/multifd: Fix multifd_send_setup cleanup when channel creation fails
Quoted 23 lines · Fabiano Rosas
When a channel fails to create, the code currently just returns. This is wrong for two reasons:
1) Channel n+1 will not get to initialize it's semaphores, leading to an assert when
terminate_threadstries to post to it:qemu-system-x86_64:
../util/qemu-thread-posix.c:92:
qemu_mutex_lock_impl: Assertion `mutex->initialized' failed.2) (theoretical) If channel n-1 already started creation it will defeat the purpose of the
channels_createdlogic which is in place to avoidmigrate_fd_cleanup()to run while channels are still being created.This cannot really happen today because the current failure cases for
multifd_new_send_channel_create()are all synchronous, resulting fromqio_channel_file_new_path()getting a bad filename. This would hit all channels equally.But I don't want to set a trap for future people, so have all channels try to create (even if failing), and only fail after the
channels_createdsemaphore has been posted.
Quoted 6 lines
While here, remove the
error_report_errcall. There's one already atmigrate_fd_cleanuplater on.Reported-by Jim Fehlig <[email protected]>Fixes bd8b0a8f82 ("migration/multifd: Move multifd_send_setup error handling in to the function")
Should it be this one instead?
b7b03eb614 ("migration/multifd: Add outgoing QIOChannelFile support")
Quoted 1 line
Signed-off-by Fabiano Rosas <[email protected]>
PS: what's your plan on your other multifd SendData series? I got a bit overloaded on downstream stuff and I still have plenty review debts recently (CPR one of them.. needs follow ups), so just to say I may delay a bit on reading that one. I assume it's next-release stuff anyway, but let me know otherwise.
Thanks,
Signature · 1 line
Peter Xu
Re: [PATCH 2/2] migration/multifd: Fix multifd_send_setup cleanup when channel creation fails
Quoted 27 lines · Peter Xu
Quoted 26 lines · Fabiano Rosas
When a channel fails to create, the code currently just returns. This is wrong for two reasons:
1) Channel n+1 will not get to initialize it's semaphores, leading to an assert when
terminate_threadstries to post to it:qemu-system-x86_64:
../util/qemu-thread-posix.c:92:
qemu_mutex_lock_impl: Assertion `mutex->initialized' failed.2) (theoretical) If channel n-1 already started creation it will defeat the purpose of the
channels_createdlogic which is in place to avoidmigrate_fd_cleanup()to run while channels are still being created.This cannot really happen today because the current failure cases for
multifd_new_send_channel_create()are all synchronous, resulting fromqio_channel_file_new_path()getting a bad filename. This would hit all channels equally.But I don't want to set a trap for future people, so have all channels try to create (even if failing), and only fail after the
channels_createdsemaphore has been posted.While here, remove the
error_report_errcall. There's one already atmigrate_fd_cleanuplater on.
Quoted 7 lines
Quoted 3 lines
Reported-by Jim Fehlig <[email protected]>Fixes bd8b0a8f82 ("migration/multifd: Move multifd_send_setup error handling in to the function")Should it be this one instead?
b7b03eb614("migration/multifd: Add outgoing QIOChannelFile support")
Yep, thanks. I'll fix it up.
Quoted 10 lines
Quoted 2 lines
Signed-off-by Fabiano Rosas <[email protected]>Reviewed-by Peter Xu <[email protected]>PS: what's your plan on your other multifd SendData series? I got a bit overloaded on downstream stuff and I still have plenty review debts recently (CPR one of them.. needs follow ups), so just to say I may delay a bit on reading that one. I assume it's next-release stuff anyway, but let me know otherwise.
That one is pretty ready. From my side I don't intend to change anything else, save for review comments. And it's definitely 9.2 material.
I think CPR is more important at this point because it's been lagging behind for a while.
I have a PR to send with these fixes and catch up on that virtio-net discussion. After that I should be able to get some reviews done.
Quoted 2 lines
Thanks,
Fabiano Rosas
AppliedQuoted 10 lines · Fabiano Rosas
on mapped-ram for libvirt.
CI run: https://gitlab.com/farosas/qemu/-/pipelines/1397467740
Fabiano Rosas (2):
migration: Fix cleanup of iochannel in file migration migration/multifd: Fixmultifd_send_setupcleanup when channel
creation fails[...]
Queued, thanks!