Skip to contentSkip to conversation

Migration: fix missing iothread locking

PATCH In review Emanuele Giuseppe Esposito 3 participants 6 messages Oct 5, 2021 – Nov 2, 2021

lore
Share & tools
lore
#1 lore raw

PATCH 1/2 migration: block-dirty-bitmap: add missing qemu_mutex_lock_iothread

In reply to Emanuele Giuseppe Esposito

init_dirty_bitmap_migration assumes the iothread lock (BQL) to be held, but instead it isn't.

Instead of adding the lock to qemu_savevm_state_setup(), follow the same pattern as the other ->save_setup callbacks and lock+unlock inside dirty_bitmap_save_setup().

---
 migration/block-dirty-bitmap.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
migration/block-dirty-bitmap.c +4 -1
index 35f5ef688d..9aba7d9c22 100644
@@ -1215,7 +1215,10 @@ static int dirty_bitmap_save_setup(QEMUFile *f, void *opaque)
 {
     DBMSaveState *s = &((DBMState *)opaque)->save;
     SaveBitmapState *dbms = NULL;
+
+    qemu_mutex_lock_iothread();
     if (init_dirty_bitmap_migration(s) < 0) {
+        qemu_mutex_unlock_iothread();
         return -1;
     }
 
@@ -1223,7 +1226,7 @@ static int dirty_bitmap_save_setup(QEMUFile *f, void *opaque)
         send_bitmap_start(f, s, dbms);
     }
     qemu_put_bitmap_flags(f, DIRTY_BITMAP_MIG_FLAG_EOS);
-
+    qemu_mutex_unlock_iothread();
     return 0;
 }
 
Signature · 1 line
2.27.0
#0 lore raw

cover Migration: fix missing iothread locking

Some functions (in this case qemu_savevm_state_complete_postcopy() and init_dirty_bitmap_migration()) assume and document that qemu_mutex_lock_iothread() is hold.

This seems to have been forgotten in some places, and this series aims to fix that.

Patch 1 was part of my RFC block layer series "block layer: split block APIs in graph and I/O" but I decided to do a separate series for these two bugs, as they are independent from the API split.

Emanuele Giuseppe Esposito (2):
migration: block-dirty-bitmap: add missing qemu_mutex_lock_iothread
migration: add missing qemu_mutex_lock_iothread in
migration_completion

 migration/block-dirty-bitmap.c | 5 ++++-
 migration/migration.c          | 3 +++
 2 files changed, 7 insertions(+), 1 deletion(-)
Signature · 1 line
2.27.0
#4 lore raw

PATCH 2/2 migration: add missing qemu_mutex_lock_iothread in migration_completion

qemu_savevm_state_complete_postcopy assumes the iothread lock (BQL) to be held, but instead it isn't.

---
 migration/migration.c | 3 +++
 1 file changed, 3 insertions(+)
migration/migration.c +3 -0
index 041b8451a6..215d5281f2 100644
@@ -3182,7 +3182,10 @@ static void migration_completion(MigrationState *s)
     } else if (s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE) {
         trace_migration_completion_postcopy_end();
 
+        qemu_mutex_lock_iothread();
         qemu_savevm_state_complete_postcopy(s->to_dst_file);
+        qemu_mutex_unlock_iothread();
+
         trace_migration_completion_postcopy_end_after_complete();
     } else if (s->state == MIGRATION_STATUS_CANCELLING) {
         goto fail;
Signature · 1 line
2.27.0
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH v1 2/2] migration: add missing qemu_mutex_lock_iothread in migration_completion

Quoted 4 lines · * Emanuele Giuseppe Esposito ([email protected]) wrote:

qemu_savevm_state_complete_postcopy assumes the iothread lock (BQL) to be held, but instead it isn't.

Interesting, I think you're right - and I think it's been missing it from the start.

Quoted 22 lines
---
 migration/migration.c | 3 +++
 1 file changed, 3 insertions(+)
migration/migration.c +3 -0
index 041b8451a6..215d5281f2 100644
@@ -3182,7 +3182,10 @@ static void migration_completion(MigrationState *s)
     } else if (s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE) {
         trace_migration_completion_postcopy_end();
 
+        qemu_mutex_lock_iothread();
         qemu_savevm_state_complete_postcopy(s->to_dst_file);
+        qemu_mutex_unlock_iothread();
+
         trace_migration_completion_postcopy_end_after_complete();
     } else if (s->state == MIGRATION_STATUS_CANCELLING) {
         goto fail;
Signature · 1 line
2.27.0
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH v1 1/2] migration: block-dirty-bitmap: add missing qemu_mutex_lock_iothread

In reply to Emanuele Giuseppe Esposito
Quoted 9 lines · Emanuele Giuseppe Esposito

init_dirty_bitmap_migration assumes the iothread lock (BQL) to be held, but instead it isn't.

Instead of adding the lock to qemu_savevm_state_setup(), follow the same pattern as the other ->save_setup callbacks and lock+unlock inside dirty_bitmap_save_setup().

queued.

#3 lore raw

Re: [PATCH v1 1/2] migration: block-dirty-bitmap: add missing qemu_mutex_lock_iothread

Quoted 4 lines · Juan Quintela
Quoted 3 lines · Emanuele Giuseppe Esposito

init_dirty_bitmap_migration assumes the iothread lock (BQL) to be held, but instead it isn't.

Quoted 8 lines
Quoted 6 lines

Instead of adding the lock to qemu_savevm_state_setup(), follow the same pattern as the other ->save_setup callbacks and lock+unlock inside dirty_bitmap_save_setup().

And I realized that this patch is already on the tree, just not through the migration tree.

Ignore the noise.

Later, Juan.