[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 14/33] migration/multifd: Make multifd_send() thread safe
From: |
Maciej S. Szmigiero |
Subject: |
[PATCH v4 14/33] migration/multifd: Make multifd_send() thread safe |
Date: |
Thu, 30 Jan 2025 11:08:35 +0100 |
From: "Maciej S. Szmigiero" <maciej.szmigiero@oracle.com>
multifd_send() function is currently not thread safe, make it thread safe
by holding a lock during its execution.
This way it will be possible to safely call it concurrently from multiple
threads.
Reviewed-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com>
---
migration/multifd.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/migration/multifd.c b/migration/multifd.c
index 810e7b1fb340..02d163fe292d 100644
--- a/migration/multifd.c
+++ b/migration/multifd.c
@@ -50,6 +50,10 @@ typedef struct {
struct {
MultiFDSendParams *params;
+
+ /* multifd_send() body is not thread safe, needs serialization */
+ QemuMutex multifd_send_mutex;
+
/*
* Global number of generated multifd packets.
*
@@ -339,6 +343,8 @@ bool multifd_send(MultiFDSendData **send_data)
return false;
}
+ QEMU_LOCK_GUARD(&multifd_send_state->multifd_send_mutex);
+
/* We wait here, until at least one channel is ready */
qemu_sem_wait(&multifd_send_state->channels_ready);
@@ -507,6 +513,7 @@ static void multifd_send_cleanup_state(void)
socket_cleanup_outgoing_migration();
qemu_sem_destroy(&multifd_send_state->channels_created);
qemu_sem_destroy(&multifd_send_state->channels_ready);
+ qemu_mutex_destroy(&multifd_send_state->multifd_send_mutex);
g_free(multifd_send_state->params);
multifd_send_state->params = NULL;
g_free(multifd_send_state);
@@ -857,6 +864,7 @@ bool multifd_send_setup(void)
thread_count = migrate_multifd_channels();
multifd_send_state = g_malloc0(sizeof(*multifd_send_state));
multifd_send_state->params = g_new0(MultiFDSendParams, thread_count);
+ qemu_mutex_init(&multifd_send_state->multifd_send_mutex);
qemu_sem_init(&multifd_send_state->channels_created, 0);
qemu_sem_init(&multifd_send_state->channels_ready, 0);
qatomic_set(&multifd_send_state->exiting, 0);
- [PATCH v4 04/33] thread-pool: Implement generic (non-AIO) pool support, (continued)
- [PATCH v4 04/33] thread-pool: Implement generic (non-AIO) pool support, Maciej S. Szmigiero, 2025/01/30
- [PATCH v4 05/33] migration: Add MIG_CMD_SWITCHOVER_START and its load handler, Maciej S. Szmigiero, 2025/01/30
- [PATCH v4 06/33] migration: Add qemu_loadvm_load_state_buffer() and its handler, Maciej S. Szmigiero, 2025/01/30
- [PATCH v4 07/33] io: tls: Allow terminating the TLS session gracefully with EOF, Maciej S. Szmigiero, 2025/01/30
- [PATCH v4 08/33] migration/multifd: Allow premature EOF on TLS incoming channels, Maciej S. Szmigiero, 2025/01/30
- [PATCH v4 09/33] migration: postcopy_ram_listen_thread() needs to take BQL for some calls, Maciej S. Szmigiero, 2025/01/30
- [PATCH v4 10/33] error: define g_autoptr() cleanup function for the Error type, Maciej S. Szmigiero, 2025/01/30
- [PATCH v4 11/33] migration: Add thread pool of optional load threads, Maciej S. Szmigiero, 2025/01/30
- [PATCH v4 12/33] migration/multifd: Split packet into header and RAM data, Maciej S. Szmigiero, 2025/01/30
- [PATCH v4 13/33] migration/multifd: Device state transfer support - receive side, Maciej S. Szmigiero, 2025/01/30
- [PATCH v4 14/33] migration/multifd: Make multifd_send() thread safe,
Maciej S. Szmigiero <=
- [PATCH v4 15/33] migration/multifd: Add an explicit MultiFDSendData destructor, Maciej S. Szmigiero, 2025/01/30
- [PATCH v4 16/33] migration/multifd: Device state transfer support - send side, Maciej S. Szmigiero, 2025/01/30
- [PATCH v4 17/33] migration/multifd: Make MultiFDSendData a struct, Maciej S. Szmigiero, 2025/01/30
- [PATCH v4 18/33] migration/multifd: Add multifd_device_state_supported(), Maciej S. Szmigiero, 2025/01/30
- [PATCH v4 19/33] migration: Add save_live_complete_precopy_thread handler, Maciej S. Szmigiero, 2025/01/30
- [PATCH v4 20/33] vfio/migration: Add x-migration-load-config-after-iter VFIO property, Maciej S. Szmigiero, 2025/01/30
- [PATCH v4 21/33] vfio/migration: Add load_device_config_state_start trace event, Maciej S. Szmigiero, 2025/01/30
- [PATCH v4 22/33] vfio/migration: Convert bytes_transferred counter to atomic, Maciej S. Szmigiero, 2025/01/30