migration: Make from_dst_file accesses thread-safe
authorPeter Xu <peterx@redhat.com>
Thu, 22 Jul 2021 17:58:38 +0000 (13:58 -0400)
committerDr. David Alan Gilbert <dgilbert@redhat.com>
Mon, 26 Jul 2021 11:44:46 +0000 (12:44 +0100)
commit43044ac0ee5758d92b639843c045123c2de578d1
tree96306626794702162548c8f6feab71ca24821b37
parent53021ea1659b8a9074c6f5eb6c65a4e5dddddaec
migration: Make from_dst_file accesses thread-safe

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>
Reviewed-by: Lukas Straub <lukasstraub2@web.de>
Message-Id: <20210722175841.938739-3-peterx@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
  with Peter's fixup
migration/migration.c
migration/migration.h
migration/ram.c