From: Fabiano Rosas <farosas@suse.de>
To: Peter Xu <peterx@redhat.com>
Cc: qemu-devel@nongnu.org, Juan Quintela <quintela@redhat.com>
Subject: Re: [PATCH RFC 3/7] migration: multifd_send_kick_main()
Date: Thu, 09 Nov 2023 14:00:41 -0300 [thread overview]
Message-ID: <87v8aazwsm.fsf@suse.de> (raw)
In-Reply-To: <ZU0N5UGFRFUNnH2b@x1n>
Peter Xu <peterx@redhat.com> writes:
> On Wed, Nov 08, 2023 at 07:49:53PM -0300, Fabiano Rosas wrote:
>> Peter Xu <peterx@redhat.com> writes:
>>
>> > When a multifd sender thread hit errors, it always needs to kick the main
>> > thread by kicking all the semaphores that it can be waiting upon.
>> >
>> > Provide a helper for it and deduplicate the code.
>> >
>> > Signed-off-by: Peter Xu <peterx@redhat.com>
>> > ---
>> > migration/multifd.c | 21 +++++++++++++++------
>> > 1 file changed, 15 insertions(+), 6 deletions(-)
>> >
>> > diff --git a/migration/multifd.c b/migration/multifd.c
>> > index 4afdd88602..33fb21d0e4 100644
>> > --- a/migration/multifd.c
>> > +++ b/migration/multifd.c
>> > @@ -374,6 +374,18 @@ struct {
>> > MultiFDMethods *ops;
>> > } *multifd_send_state;
>> >
>> > +/*
>> > + * The migration thread can wait on either of the two semaphores. This
>> > + * function can be used to kick the main thread out of waiting on either of
>> > + * them. Should mostly only be called when something wrong happened with
>> > + * the current multifd send thread.
>> > + */
>> > +static void multifd_send_kick_main(MultiFDSendParams *p)
>> > +{
>> > + qemu_sem_post(&p->sem_sync);
>> > + qemu_sem_post(&multifd_send_state->channels_ready);
>> > +}
>> > +
>> > /*
>> > * How we use multifd_send_state->pages and channel->pages?
>> > *
>> > @@ -746,8 +758,7 @@ out:
>> > assert(local_err);
>> > trace_multifd_send_error(p->id);
>> > multifd_send_terminate_threads(local_err);
>> > - qemu_sem_post(&p->sem_sync);
>> > - qemu_sem_post(&multifd_send_state->channels_ready);
>> > + multifd_send_kick_main(p);
>> > error_free(local_err);
>> > }
>> >
>> > @@ -787,8 +798,7 @@ static void multifd_tls_outgoing_handshake(QIOTask *task,
>> > * is not created, and then tell who pay attention to me.
>> > */
>> > p->quit = true;
>> > - qemu_sem_post(&multifd_send_state->channels_ready);
>> > - qemu_sem_post(&p->sem_sync);
>> > + multifd_send_kick_main(p);
>>
>> There's a bug here in the original code:
>>
>> It's not really safe to call any of these outside of the channel lock
>> because multifd_save_cleanup() could execute at the same time and call
>> qemu_sem_destroy() -> qemu_mutex_destroy(), which can assert because we
>> might be holding the sem_lock.
>
> If you meant "p->mutex" as the "channel lock", IIUC even holding that won't
> work? Because it'll also be freed in multifd_save_cleanup().
>
You're right, I just sent an RFC about this, please take a look.
next prev parent reply other threads:[~2023-11-09 17:02 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-22 20:12 [PATCH RFC 0/7] migration/multifd: quit unitifications and separate sync packet Peter Xu
2023-10-22 20:12 ` [PATCH RFC 1/7] migration: Drop stale comment for multifd zero copy Peter Xu
2023-10-23 14:16 ` Fabiano Rosas
2023-10-22 20:12 ` [PATCH RFC 2/7] migration: Fix error leak in multifd_tls_outgoing_handshake() Peter Xu
2023-10-23 14:17 ` Fabiano Rosas
2023-10-22 20:12 ` [PATCH RFC 3/7] migration: multifd_send_kick_main() Peter Xu
2023-10-23 14:43 ` Fabiano Rosas
2023-11-08 22:49 ` Fabiano Rosas
2023-11-09 16:50 ` Peter Xu
2023-11-09 17:00 ` Fabiano Rosas [this message]
2023-10-22 20:12 ` [PATCH RFC 4/7] migration: Drop MultiFDSendParams.quit and cleanup error paths Peter Xu
2023-10-23 14:42 ` Fabiano Rosas
2023-10-23 14:53 ` Peter Xu
2023-10-23 15:35 ` Fabiano Rosas
2023-10-23 15:54 ` Peter Xu
2023-10-22 20:12 ` [PATCH RFC 5/7] migration: Modulize multifd send threads with a few helpers Peter Xu
2023-10-22 20:12 ` [PATCH RFC 6/7] migration: Split multifd pending_job into two booleans Peter Xu
2023-10-23 15:15 ` Fabiano Rosas
2023-10-23 15:52 ` Peter Xu
2023-10-22 20:12 ` [PATCH RFC 7/7] migration: Further unify paths for multifd normal or sync requests Peter Xu
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=87v8aazwsm.fsf@suse.de \
--to=farosas@suse.de \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
/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).