All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukas Straub <lukasstraub2@web.de>
To: Peter Xu <peterx@redhat.com>
Cc: qemu-devel@nongnu.org, Fabiano Rosas <farosas@suse.de>,
	Laurent Vivier <lvivier@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Zhang Chen <zhangckid@gmail.com>,
	Hailiang Zhang <zhanghailiang@xfusion.com>,
	Markus Armbruster <armbru@redhat.com>,
	Li Zhijian <lizhijian@fujitsu.com>,
	"Dr. David Alan Gilbert" <dave@treblig.org>
Subject: Re: [PATCH v9 19/19] colo: Fix a rare crash during shutdown
Date: Thu, 26 Feb 2026 11:43:19 +0100	[thread overview]
Message-ID: <20260226114319.17f11f9b@penguin> (raw)
In-Reply-To: <aZeBn2MBKvQQYEAx@x1.local>

[-- Attachment #1: Type: text/plain, Size: 3945 bytes --]

On Thu, 19 Feb 2026 16:33:19 -0500
Peter Xu <peterx@redhat.com> wrote:

> On Wed, Feb 18, 2026 at 10:29:39PM +0100, Lukas Straub wrote:
> > In the colo migration unit test, we shutdown all sockets with yank and
> > then stop qemu with SIGTERM. During shutdown migration_shutdown() calls
> > migration_cancel(). Now the colo thread frees s->rp_state.from_dst_file
> > which races with migration_cancel() checking for NULL and potentially calling
> > qemu_file_shutdown() on it.
> > 
> > Fix this by taking the s->qemu_file_lock.
> > 
> > Signed-off-by: Lukas Straub <lukasstraub2@web.de>  
> 
> The whole patch taking the mutex is reasonable, but it didn't explain one
> thing, on why COLO is special here on managing the return path channel..
> 
> colo_process_checkpoint() does re-opening of rp channel even if it was
> partially shutdown before:
> 
> colo_process_checkpoint():
>     s->rp_state.from_dst_file = qemu_file_get_return_path(s->to_dst_file);
> 
> Should we instead leave all these to migration core?
> E.g. migration_completion() will do close_return_path_on_source(), but I
> wonder if that should only shutdown & close the return path channel when
> without COLO running.  Then IIUC we can also leave the cleanup of the
> qemufiles to migration_cleanup(), as it's also not special to COLO IIUC.
> 
> What do you think?

It is a bit more involved since the return path needs to be always
opened for this. I implemented this in my current patchset.

Regards,
Lukas Straub

> 
> Thanks,
> 
> > ---
> >  migration/colo.c | 23 +++++++++++++++--------
> >  1 file changed, 15 insertions(+), 8 deletions(-)
> > 
> > diff --git a/migration/colo.c b/migration/colo.c
> > index ce02c71d8857d470be434bdf3a9cacad3baab0d5..180793fe3f25140fa10887acc3d87515ebf43ac9 100644
> > --- a/migration/colo.c
> > +++ b/migration/colo.c
> > @@ -173,11 +173,13 @@ static void primary_vm_do_failover(void)
> >       * The s->rp_state.from_dst_file and s->to_dst_file may use the
> >       * same fd, but we still shutdown the fd for twice, it is harmless.
> >       */
> > -    if (s->to_dst_file) {
> > -        qemu_file_shutdown(s->to_dst_file);
> > -    }
> > -    if (s->rp_state.from_dst_file) {
> > -        qemu_file_shutdown(s->rp_state.from_dst_file);
> > +    WITH_QEMU_LOCK_GUARD(&s->qemu_file_lock) {
> > +        if (s->to_dst_file) {
> > +            qemu_file_shutdown(s->to_dst_file);
> > +        }
> > +        if (s->rp_state.from_dst_file) {
> > +            qemu_file_shutdown(s->rp_state.from_dst_file);
> > +        }
> >      }
> >  
> >      old_state = failover_set_state(FAILOVER_STATUS_ACTIVE,
> > @@ -544,11 +546,14 @@ static void colo_process_checkpoint(MigrationState *s)
> >  
> >      failover_init_state();
> >  
> > +    qemu_mutex_lock(&s->qemu_file_lock);
> >      s->rp_state.from_dst_file = qemu_file_get_return_path(s->to_dst_file);
> >      if (!s->rp_state.from_dst_file) {
> > +        qemu_mutex_unlock(&s->qemu_file_lock);
> >          error_report("Open QEMUFile from_dst_file failed");
> >          goto out;
> >      }
> > +    qemu_mutex_unlock(&s->qemu_file_lock);
> >  
> >      packets_compare_notifier.notify = colo_compare_notify_checkpoint;
> >      colo_compare_register_notifier(&packets_compare_notifier);
> > @@ -640,9 +645,11 @@ out:
> >       * Or the failover BH may shutdown the wrong fd that
> >       * re-used by other threads after we release here.
> >       */
> > -    if (s->rp_state.from_dst_file) {
> > -        qemu_fclose(s->rp_state.from_dst_file);
> > -        s->rp_state.from_dst_file = NULL;
> > +    WITH_QEMU_LOCK_GUARD(&s->qemu_file_lock) {
> > +        if (s->rp_state.from_dst_file) {
> > +            qemu_fclose(s->rp_state.from_dst_file);
> > +            s->rp_state.from_dst_file = NULL;
> > +        }
> >      }
> >  }
> >  
> > 
> > -- 
> > 2.39.5
> >   
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      reply	other threads:[~2026-02-26 10:44 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-18 21:29 [PATCH v9 00/19] migration: Add COLO multifd support and COLO migration unit test Lukas Straub
2026-02-18 21:29 ` [PATCH v9 01/19] MAINTAINERS: Add myself as maintainer for COLO migration framework Lukas Straub
2026-02-18 21:29 ` [PATCH v9 02/19] MAINTAINERS: Remove Hailiang Zhang from " Lukas Straub
2026-02-18 21:29 ` [PATCH v9 03/19] colo: Setup ram cache in normal migration path Lukas Straub
2026-02-18 21:29 ` [PATCH v9 04/19] colo: Replace migration_incoming_colo_enabled() with migrate_colo() Lukas Straub
2026-02-18 21:29 ` [PATCH v9 05/19] colo: Remove ENABLE_COLO savevm command and mark it as deprecated Lukas Straub
2026-02-18 21:29 ` [PATCH v9 06/19] ram: Remove colo special-casing Lukas Straub
2026-02-18 21:29 ` [PATCH v9 07/19] multifd: Move ram state receive into multifd_ram_state_recv() Lukas Straub
2026-02-18 21:29 ` [PATCH v9 08/19] multifd: Add COLO support Lukas Straub
2026-02-18 21:29 ` [PATCH v9 09/19] Call colo_release_ram_cache() after multifd threads terminate Lukas Straub
2026-02-18 21:29 ` [PATCH v9 10/19] colo: Fix crash during device vmstate load Lukas Straub
2026-02-18 21:29 ` [PATCH v9 11/19] colo: Hold the BQL while sending ram state Lukas Straub
2026-02-18 21:29 ` [PATCH v9 12/19] colo: Do not hold the BQL while receiving " Lukas Straub
2026-02-18 21:29 ` [PATCH v9 13/19] migration-test: Add COLO migration unit test Lukas Straub
2026-02-18 21:29 ` [PATCH v9 14/19] Convert colo main documentation to restructuredText Lukas Straub
2026-02-18 21:29 ` [PATCH v9 15/19] qemu-colo.rst: Miscellaneous changes Lukas Straub
2026-02-18 21:29 ` [PATCH v9 16/19] qemu-colo.rst: Add my copyright Lukas Straub
2026-02-18 21:29 ` [PATCH v9 17/19] qemu-colo.rst: Simplify the block replication setup Lukas Straub
2026-02-18 21:29 ` [PATCH v9 18/19] multifd: Fix hang if send thread errors during sync Lukas Straub
2026-02-19 21:23   ` Peter Xu
2026-02-18 21:29 ` [PATCH v9 19/19] colo: Fix a rare crash during shutdown Lukas Straub
2026-02-19 21:33   ` Peter Xu
2026-02-26 10:43     ` Lukas Straub [this message]

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=20260226114319.17f11f9b@penguin \
    --to=lukasstraub2@web.de \
    --cc=armbru@redhat.com \
    --cc=dave@treblig.org \
    --cc=farosas@suse.de \
    --cc=lizhijian@fujitsu.com \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=zhangckid@gmail.com \
    --cc=zhanghailiang@xfusion.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.