[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v3 2/5] migration: Make from_dst_file accesses thread-safe
From: |
Peter Xu |
Subject: |
Re: [PATCH v3 2/5] migration: Make from_dst_file accesses thread-safe |
Date: |
Thu, 22 Jul 2021 15:32:33 -0400 |
On Thu, Jul 22, 2021 at 01:58:38PM -0400, Peter Xu wrote:
> Accessing from_dst_file is potentially racy in current code base like below:
>
> if (s->from_dst_file)
> do_something(s->from_dst_file);
>
> Because from_dst_file can be reset right after the check in another
> thread (rp_thread). One example is migrate_fd_cancel().
>
> Use the same qemu_file_lock to protect it too, just like to_dst_file.
>
> When it's safe to access without lock, comment it.
>
> There's one special reference in migration_thread() that can be replaced by
> the newly introduced rp_thread_created flag.
>
> Reported-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
(Dave should have helped fixing this which I appreciated a lot, but just make
it be together with the record..)
Below needs to be squashed into the patch:
diff --git a/migration/migration.c b/migration/migration.c
index a50330016c..041b8451a6 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -2696,7 +2696,7 @@ static void
migration_release_from_dst_file(MigrationState *ms)
{
QEMUFile *file;
- WITH_QEMU_LOCK_GUARD(&s->qemu_file_lock) {
+ WITH_QEMU_LOCK_GUARD(&ms->qemu_file_lock) {
/*
* Reset the from_dst_file pointer first before releasing it, as we
* can't block within lock section
--
Peter Xu
- [PATCH v3 0/5] migrations: Fix potential rare race of migration-test after yank, Peter Xu, 2021/07/22
- [PATCH v3 1/5] migration: Fix missing join() of rp_thread, Peter Xu, 2021/07/22
- [PATCH v3 2/5] migration: Make from_dst_file accesses thread-safe, Peter Xu, 2021/07/22
- Re: [PATCH v3 2/5] migration: Make from_dst_file accesses thread-safe,
Peter Xu <=
- [PATCH v3 3/5] migration: Introduce migration_ioc_[un]register_yank(), Peter Xu, 2021/07/22
- [PATCH v3 4/5] migration: Teach QEMUFile to be QIOChannel-aware, Peter Xu, 2021/07/22
- [PATCH v3 5/5] migration: Move the yank unregister of channel_close out, Peter Xu, 2021/07/22
- Re: [PATCH v3 0/5] migrations: Fix potential rare race of migration-test after yank, Lukas Straub, 2021/07/24
- Re: [PATCH v3 0/5] migrations: Fix potential rare race of migration-test after yank, Dr. David Alan Gilbert, 2021/07/26