aboutsummaryrefslogtreecommitdiff
path: root/migration/migration.c
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2023-02-13 11:54:05 +0000
committerPeter Maydell <peter.maydell@linaro.org>2023-02-13 11:54:05 +0000
commitf670b3eec7f5d1ed8c4573ef244e7b8c6b32001b (patch)
treed114324ea2c5912e7858ec4f0d6e9d3c3615ef49 /migration/migration.c
parent3b33ae48ec28e1e0d1bc28a85c7423724bcb1a2c (diff)
parent7b548761e5d084f2fc0fc4badebab227b51a8a84 (diff)
Merge tag 'migration-20230213-pull-request' of https://gitlab.com/juan.quintela/qemu into staging
Migration Pull request (take3) Hi In this PULL request: - Added to leonardo fixes: Fixes: b5eea99ec2 ("migration: Add yank feature") Reported-by: Li Xiaohui <xiaohli@redhat.com> Please apply. [take 2] - rebase to latest upstream - fix compilation of linux-user (if have_system was missing) (me) - cleanup multifd_load_cleanup(leonardo) - Document RAM flags (me) Please apply. [take 1] This are all the reviewed patches for migration: - AVX512 support for xbzrle (Ling Xu) - /dev/userfaultd support (Peter Xu) - Improve ordering of channels (Peter Xu) - multifd cleanups (Li Zhang) - Remove spurious files from last merge (me) Rebase makes that to you - Fix mixup between state_pending_{exact,estimate} (me) - Cache RAM size during migration (me) - cleanup several functions (me) Please apply. # -----BEGIN PGP SIGNATURE----- # # iQIzBAABCAAdFiEEGJn/jt6/WMzuA0uC9IfvGFhy1yMFAmPppZYACgkQ9IfvGFhy # 1yPLvQ//f8D6txzFawaxrfzpSAHnq70Gx+B5GkIwgwB8nlPIC3QELEf5uooM/RGA # nSaUctUNOJUWqVGK3vp3jDIep02DzdIUrlOfy96h+pnTMpyMWFC2BexDfveVMUId # dw8WCWZkGCFDfIWuKF+GA8eTu6HM1ouzgCJrRmPtCqsikzAPkogPm60hQSTAQxm9 # Kzdp1SXV1HmyA440vy8rtYf71BKpvb9OJFmwgZ+ICy0rc1aUmgJbKxkwyOgiI2lq # ONekpbOg7lzlFVAQu1QHTmYN13bsn4uzwUgdifn1PixFQyRE3AVs4jdTmqeLnoPe # Ac6j8v3pDOw/Xf4kpRWUmhkqTMEJt8/lyneJzu1mQkw0wwiUtDvknFgPG8wJsa+J # ZQr1cBXQj4IjtkN6+ixF7XYvx3T6pWz0L+/w2+TbFBdLWIrPgFH0yPYjhx7FdDid # cjUHyS1a0w9ngnXOxRG8+UNHWCpPOUhXeeiyNioogYZNKu77PFxJVDMe3eB6dXAB # pDfl4P129PloKAPafcz9E6Sxr+lIgrETZmsRJlRz4czg18TxlIukMlDtyrepNWti # GtIf9xTpP3JKjpHnKbWLaxP5VeFC7kQd0qas4VxD+tDjbJdUZdZMfHcOSS0SMRGe # q5LVEzMMIPCQJQIqiLEJ0HTUUOtB8i+bGoirNEbDqhLa/oZwPP8= # =TDnO # -----END PGP SIGNATURE----- # gpg: Signature made Mon 13 Feb 2023 02:51:02 GMT # gpg: using RSA key 1899FF8EDEBF58CCEE034B82F487EF185872D723 # gpg: Good signature from "Juan Quintela <quintela@redhat.com>" [full] # gpg: aka "Juan Quintela <quintela@trasno.org>" [full] # Primary key fingerprint: 1899 FF8E DEBF 58CC EE03 4B82 F487 EF18 5872 D723 * tag 'migration-20230213-pull-request' of https://gitlab.com/juan.quintela/qemu: (22 commits) ram: Document migration ram flags migration/multifd: Move load_cleanup inside incoming_state_destroy migration/multifd: Join all multifd threads in order to avoid leaks migration/multifd: Remove unnecessary assignment on multifd_load_cleanup() migration/multifd: Change multifd_load_cleanup() signature and usage migration: Postpone postcopy preempt channel to be after main migration: Add a semaphore to count PONGs migration: Cleanup postcopy_preempt_setup() migration: Rework multi-channel checks on URI Update bench-code for addressing CI problem AVX512 support for xbzrle_encode_buffer migration: I messed state_pending_exact/estimate migration: Make ram_save_target_page() a pointer migration: Calculate ram size once migration: Split ram_bytes_total_common() in two functions migration: Make find_dirty_block() return a single parameter migration: Simplify ram_find_and_save_block() util/userfaultfd: Support /dev/userfaultfd linux-headers: Update to v6.1 multifd: Remove some redundant code ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'migration/migration.c')
-rw-r--r--migration/migration.c138
1 files changed, 87 insertions, 51 deletions
diff --git a/migration/migration.c b/migration/migration.c
index 7a14aa98d8..90fca70cb7 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -184,16 +184,27 @@ static int migration_maybe_pause(MigrationState *s,
int new_state);
static void migrate_fd_cancel(MigrationState *s);
-static bool migrate_allow_multi_channels = true;
+static bool migration_needs_multiple_sockets(void)
+{
+ return migrate_use_multifd() || migrate_postcopy_preempt();
+}
-void migrate_protocol_allow_multi_channels(bool allow)
+static bool uri_supports_multi_channels(const char *uri)
{
- migrate_allow_multi_channels = allow;
+ return strstart(uri, "tcp:", NULL) || strstart(uri, "unix:", NULL) ||
+ strstart(uri, "vsock:", NULL);
}
-bool migrate_multi_channels_is_allowed(void)
+static bool
+migration_channels_and_uri_compatible(const char *uri, Error **errp)
{
- return migrate_allow_multi_channels;
+ if (migration_needs_multiple_sockets() &&
+ !uri_supports_multi_channels(uri)) {
+ error_setg(errp, "Migration requires multi-channel URIs (e.g. tcp)");
+ return false;
+ }
+
+ return true;
}
static gint page_request_addr_cmp(gconstpointer ap, gconstpointer bp)
@@ -224,6 +235,8 @@ void migration_object_init(void)
qemu_sem_init(&current_incoming->postcopy_pause_sem_dst, 0);
qemu_sem_init(&current_incoming->postcopy_pause_sem_fault, 0);
qemu_sem_init(&current_incoming->postcopy_pause_sem_fast_load, 0);
+ qemu_sem_init(&current_incoming->postcopy_qemufile_dst_done, 0);
+
qemu_mutex_init(&current_incoming->page_request_mutex);
current_incoming->page_requested = g_tree_new(page_request_addr_cmp);
@@ -302,6 +315,8 @@ void migration_incoming_state_destroy(void)
{
struct MigrationIncomingState *mis = migration_incoming_get_current();
+ multifd_load_cleanup();
+
if (mis->to_src_file) {
/* Tell source that we are done */
migrate_send_rp_shut(mis, qemu_file_get_error(mis->from_src_file) != 0);
@@ -493,12 +508,15 @@ static void qemu_start_incoming_migration(const char *uri, Error **errp)
{
const char *p = NULL;
- migrate_protocol_allow_multi_channels(false); /* reset it anyway */
+ /* URI is not suitable for migration? */
+ if (!migration_channels_and_uri_compatible(uri, errp)) {
+ return;
+ }
+
qapi_event_send_migration(MIGRATION_STATUS_SETUP);
if (strstart(uri, "tcp:", &p) ||
strstart(uri, "unix:", NULL) ||
strstart(uri, "vsock:", NULL)) {
- migrate_protocol_allow_multi_channels(true);
socket_start_incoming_migration(p ? p : uri, errp);
#ifdef CONFIG_RDMA
} else if (strstart(uri, "rdma:", &p)) {
@@ -543,13 +561,7 @@ static void process_incoming_migration_bh(void *opaque)
*/
qemu_announce_self(&mis->announce_timer, migrate_announce_params());
- if (multifd_load_cleanup(&local_err) != 0) {
- error_report_err(local_err);
- autostart = false;
- }
- /* If global state section was not received or we are in running
- state, we need to obey autostart. Any other state is set with
- runstate_set. */
+ multifd_load_shutdown();
dirty_bitmap_mig_before_vm_start();
@@ -649,9 +661,9 @@ fail:
migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE,
MIGRATION_STATUS_FAILED);
qemu_fclose(mis->from_src_file);
- if (multifd_load_cleanup(&local_err) != 0) {
- error_report_err(local_err);
- }
+
+ multifd_load_cleanup();
+
exit(EXIT_FAILURE);
}
@@ -723,9 +735,29 @@ void migration_fd_process_incoming(QEMUFile *f, Error **errp)
migration_incoming_process();
}
-static bool migration_needs_multiple_sockets(void)
+/*
+ * Returns true when we want to start a new incoming migration process,
+ * false otherwise.
+ */
+static bool migration_should_start_incoming(bool main_channel)
{
- return migrate_use_multifd() || migrate_postcopy_preempt();
+ /* Multifd doesn't start unless all channels are established */
+ if (migrate_use_multifd()) {
+ return migration_has_all_channels();
+ }
+
+ /* Preempt channel only starts when the main channel is created */
+ if (migrate_postcopy_preempt()) {
+ return main_channel;
+ }
+
+ /*
+ * For all the rest types of migration, we should only reach here when
+ * it's the main channel that's being created, and we should always
+ * proceed with this channel.
+ */
+ assert(main_channel);
+ return true;
}
void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp)
@@ -789,7 +821,7 @@ void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp)
}
}
- if (migration_has_all_channels()) {
+ if (migration_should_start_incoming(default_channel)) {
/* If it's a recovery, we're done */
if (postcopy_try_recover()) {
return;
@@ -1378,15 +1410,6 @@ static bool migrate_caps_check(bool *cap_list,
}
#endif
-
- /* incoming side only */
- if (runstate_check(RUN_STATE_INMIGRATE) &&
- !migrate_multi_channels_is_allowed() &&
- cap_list[MIGRATION_CAPABILITY_MULTIFD]) {
- error_setg(errp, "multifd is not supported by current protocol");
- return false;
- }
-
if (cap_list[MIGRATION_CAPABILITY_POSTCOPY_PREEMPT]) {
if (!cap_list[MIGRATION_CAPABILITY_POSTCOPY_RAM]) {
error_setg(errp, "Postcopy preempt requires postcopy-ram");
@@ -2471,6 +2494,11 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
MigrationState *s = migrate_get_current();
const char *p = NULL;
+ /* URI is not suitable for migration? */
+ if (!migration_channels_and_uri_compatible(uri, errp)) {
+ return;
+ }
+
if (!migrate_prepare(s, has_blk && blk, has_inc && inc,
has_resume && resume, errp)) {
/* Error detected, put into errp */
@@ -2483,11 +2511,9 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
}
}
- migrate_protocol_allow_multi_channels(false);
if (strstart(uri, "tcp:", &p) ||
strstart(uri, "unix:", NULL) ||
strstart(uri, "vsock:", NULL)) {
- migrate_protocol_allow_multi_channels(true);
socket_start_outgoing_migration(s, p ? p : uri, &local_err);
#ifdef CONFIG_RDMA
} else if (strstart(uri, "rdma:", &p)) {
@@ -3022,6 +3048,7 @@ retry:
case MIG_RP_MSG_PONG:
tmp32 = ldl_be_p(buf);
trace_source_return_path_thread_pong(tmp32);
+ qemu_sem_post(&ms->rp_state.rp_pong_acks);
break;
case MIG_RP_MSG_REQ_PAGES:
@@ -3155,6 +3182,13 @@ static int await_return_path_close_on_source(MigrationState *ms)
return ms->rp_state.error;
}
+static inline void
+migration_wait_main_channel(MigrationState *ms)
+{
+ /* Wait until one PONG message received */
+ qemu_sem_wait(&ms->rp_state.rp_pong_acks);
+}
+
/*
* Switch from normal iteration to postcopy
* Returns non-0 on error
@@ -3169,9 +3203,12 @@ static int postcopy_start(MigrationState *ms)
bool restart_block = false;
int cur_state = MIGRATION_STATUS_ACTIVE;
- if (postcopy_preempt_wait_channel(ms)) {
- migrate_set_state(&ms->state, ms->state, MIGRATION_STATUS_FAILED);
- return -1;
+ if (migrate_postcopy_preempt()) {
+ migration_wait_main_channel(ms);
+ if (postcopy_preempt_establish_channel(ms)) {
+ migrate_set_state(&ms->state, ms->state, MIGRATION_STATUS_FAILED);
+ return -1;
+ }
}
if (!migrate_pause_before_switchover()) {
@@ -3583,6 +3620,20 @@ static int postcopy_do_resume(MigrationState *s)
}
/*
+ * If preempt is enabled, re-establish the preempt channel. Note that
+ * we do it after resume prepare to make sure the main channel will be
+ * created before the preempt channel. E.g. with weak network, the
+ * dest QEMU may get messed up with the preempt and main channels on
+ * the order of connection setup. This guarantees the correct order.
+ */
+ ret = postcopy_preempt_establish_channel(s);
+ if (ret) {
+ error_report("%s: postcopy_preempt_establish_channel(): %d",
+ __func__, ret);
+ return ret;
+ }
+
+ /*
* Last handshake with destination on the resume (destination will
* switch to postcopy-active afterwards)
*/
@@ -3643,14 +3694,6 @@ static MigThrError postcopy_pause(MigrationState *s)
if (s->state == MIGRATION_STATUS_POSTCOPY_RECOVER) {
/* Woken up by a recover procedure. Give it a shot */
- if (postcopy_preempt_wait_channel(s)) {
- /*
- * Preempt enabled, and new channel create failed; loop
- * back to wait for another recovery.
- */
- continue;
- }
-
/*
* Firstly, let's wake up the return path now, with a new
* return path channel.
@@ -4343,15 +4386,6 @@ void migrate_fd_connect(MigrationState *s, Error *error_in)
}
}
- /* This needs to be done before resuming a postcopy */
- if (postcopy_preempt_setup(s, &local_err)) {
- error_report_err(local_err);
- migrate_set_state(&s->state, MIGRATION_STATUS_SETUP,
- MIGRATION_STATUS_FAILED);
- migrate_fd_cleanup(s);
- return;
- }
-
if (resume) {
/* Wakeup the main migration thread to do the recovery */
migrate_set_state(&s->state, MIGRATION_STATUS_POSTCOPY_PAUSED,
@@ -4525,6 +4559,7 @@ static void migration_instance_finalize(Object *obj)
qemu_sem_destroy(&ms->postcopy_pause_sem);
qemu_sem_destroy(&ms->postcopy_pause_rp_sem);
qemu_sem_destroy(&ms->rp_state.rp_sem);
+ qemu_sem_destroy(&ms->rp_state.rp_pong_acks);
qemu_sem_destroy(&ms->postcopy_qemufile_src_sem);
error_free(ms->error);
}
@@ -4571,6 +4606,7 @@ static void migration_instance_init(Object *obj)
qemu_sem_init(&ms->postcopy_pause_sem, 0);
qemu_sem_init(&ms->postcopy_pause_rp_sem, 0);
qemu_sem_init(&ms->rp_state.rp_sem, 0);
+ qemu_sem_init(&ms->rp_state.rp_pong_acks, 0);
qemu_sem_init(&ms->rate_limit_sem, 0);
qemu_sem_init(&ms->wait_unplug_sem, 0);
qemu_sem_init(&ms->postcopy_qemufile_src_sem, 0);