diff options
author | Peter Xu <peterx@redhat.com> | 2021-07-22 13:58:38 -0400 |
---|---|---|
committer | Dr. David Alan Gilbert <dgilbert@redhat.com> | 2021-07-26 12:44:46 +0100 |
commit | 43044ac0ee5758d92b639843c045123c2de578d1 (patch) | |
tree | 96306626794702162548c8f6feab71ca24821b37 /migration/ram.c | |
parent | 53021ea1659b8a9074c6f5eb6c65a4e5dddddaec (diff) | |
download | qemu-43044ac0ee5758d92b639843c045123c2de578d1.zip |
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
Diffstat (limited to 'migration/ram.c')
-rw-r--r-- | migration/ram.c | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/migration/ram.c b/migration/ram.c index b5fc454b2f..f728f5072f 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -4012,6 +4012,7 @@ static void ram_dirty_bitmap_reload_notify(MigrationState *s) int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block) { int ret = -EINVAL; + /* from_dst_file is always valid because we're within rp_thread */ QEMUFile *file = s->rp_state.from_dst_file; unsigned long *le_bitmap, nbits = block->used_length >> TARGET_PAGE_BITS; uint64_t local_size = DIV_ROUND_UP(nbits, 8); |