All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Peter Xu <peterx@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Lukas Straub <lukasstraub2@web.de>,
	Leonardo Bras Soares Passos <lsoaresp@redhat.com>,
	qemu-devel@nongnu.org, Juan Quintela <quintela@redhat.com>
Subject: Re: [PATCH 2/5] migration: Shutdown src in await_return_path_close_on_source()
Date: Wed, 21 Jul 2021 10:55:00 +0100	[thread overview]
Message-ID: <YPfu9N98PyTp7AKX@work-vm> (raw)
In-Reply-To: <20210721012134.792845-3-peterx@redhat.com>

* Peter Xu (peterx@redhat.com) wrote:
> We have a logic in await_return_path_close_on_source() that we will explicitly
> shutdown the socket when migration encounters errors.  However it could be racy
> because from_dst_file could have been reset right after checking it but before
> passing it to qemu_file_shutdown() by the rp_thread.
> 
> Fix it by shutdown() on the src file instead.  Since they must be a pair of
> qemu files, shutdown on either of them will work the same.
> 
> Since at it, drop the check for from_dst_file directly, which makes the
> behavior even more predictable.

So while the existing code maybe racy, I'm not sure that this change
keeps the semantics; the channel may well have dup()'d the fd's for the
two directions, and I'm not convinced that a shutdown() on one will
necessarily impact the other; and if the shutdown doesn't happen the
rp_thread might not exit, and we might block on the koin.

Why don't we solve this a different way - how about we move the:
    ms->rp_state.from_dst_file = NULL;
    qemu_fclose(rp);

out of the source_return_path_thread and put it in
await_return_path_close_on_source, immediately after the join?
Then we *know* that the the rp thread isn't messing with it.

Dave

> Reported-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>  migration/migration.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/migration/migration.c b/migration/migration.c
> index 21b94f75a3..4f48cde796 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -2882,12 +2882,15 @@ static int await_return_path_close_on_source(MigrationState *ms)
>       * rp_thread will exit, however if there's an error we need to cause
>       * it to exit.
>       */
> -    if (qemu_file_get_error(ms->to_dst_file) && ms->rp_state.from_dst_file) {
> +    if (qemu_file_get_error(ms->to_dst_file)) {
>          /*
>           * shutdown(2), if we have it, will cause it to unblock if it's stuck
> -         * waiting for the destination.
> +         * waiting for the destination.  We do shutdown on to_dst_file should
> +         * also shutdown the from_dst_file as they're in a pair. We explicilty
> +         * don't operate on from_dst_file because it's potentially racy
> +         * (rp_thread could have reset it in parallel).
>           */
> -        qemu_file_shutdown(ms->rp_state.from_dst_file);
> +        qemu_file_shutdown(ms->to_dst_file);
>          mark_source_rp_bad(ms);
>      }
>      trace_await_return_path_close_on_source_joining();
> -- 
> 2.31.1
> 
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



  reply	other threads:[~2021-07-21 10:13 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-21  1:21 [PATCH 0/5] migrations: Fix potential rare race of migration-test after yank Peter Xu
2021-07-21  1:21 ` [PATCH 1/5] migration: Fix missing join() of rp_thread Peter Xu
2021-07-21  9:49   ` Dr. David Alan Gilbert
2021-07-21  1:21 ` [PATCH 2/5] migration: Shutdown src in await_return_path_close_on_source() Peter Xu
2021-07-21  9:55   ` Dr. David Alan Gilbert [this message]
2021-07-21 15:40     ` Peter Xu
2021-07-21 18:00       ` Dr. David Alan Gilbert
2021-07-21 18:12         ` Peter Xu
2021-07-21 15:57     ` Daniel P. Berrangé
2021-07-21  1:21 ` [PATCH 3/5] migration: Introduce migration_ioc_[un]register_yank() Peter Xu
2021-07-21  9:58   ` Dr. David Alan Gilbert
2021-07-21  1:21 ` [PATCH 4/5] migration: Teach QEMUFile to be QIOChannel-aware Peter Xu
2021-07-21 10:27   ` Dr. David Alan Gilbert
2021-07-21 10:57     ` Daniel P. Berrangé
2021-07-21  1:21 ` [PATCH 5/5] migration: Move the yank unregister of channel_close out Peter Xu
2021-07-21 10:39   ` Dr. David Alan Gilbert
2021-07-21 15:45     ` 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=YPfu9N98PyTp7AKX@work-vm \
    --to=dgilbert@redhat.com \
    --cc=lsoaresp@redhat.com \
    --cc=lukasstraub2@web.de \
    --cc=peter.maydell@linaro.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.