* [PATCH V2 00/10] fix migration of suspended runstate
@ 2023-06-30 13:49 Steve Sistare
2023-06-30 13:49 ` [PATCH V2 01/10] vl: start on wakeup request Steve Sistare
` (9 more replies)
0 siblings, 10 replies; 15+ messages in thread
From: Steve Sistare @ 2023-06-30 13:49 UTC (permalink / raw)
To: qemu-devel
Cc: Juan Quintela, Peter Xu, Paolo Bonzini, Thomas Huth,
Daniel P. Berrangé, Steve Sistare
Migration of a guest in the suspended runstate is broken. The incoming
migration code automatically tries to wake the guest, which is wrong;
the guest should end migration in the same runstate it started. Further,
for a restored snapshot, the automatic wakeup fails. The runstate is
RUNNING, but the guest is not. See the commit messages for the details.
Changes in V2:
* simplify "start on wakeup request"
* fix postcopy, snapshot, and background migration
* refactor fixes for each type of migration
* explicitly handled suspended events and runstate in tests
* add test for postcopy and background migration
Steve Sistare (10):
vl: start on wakeup request
migration: preserve suspended runstate
migration: add runstate function
migration: preserve suspended for snapshot
migration: preserve suspended for bg_migration
tests/qtest: migration events
tests/qtest: option to suspend during migration
tests/qtest: precopy migration with suspend
tests/qtest: postcopy migration with suspend
tests/qtest: background migration with suspend
include/sysemu/runstate.h | 1 +
migration/migration.c | 28 ++++--
migration/migration.h | 1 +
migration/savevm.c | 9 +-
softmmu/cpus.c | 12 +++
softmmu/runstate.c | 5 +-
tests/migration/i386/Makefile | 5 +-
tests/migration/i386/a-b-bootblock.S | 51 +++++++++-
tests/migration/i386/a-b-bootblock.h | 22 +++--
tests/qtest/migration-helpers.c | 27 ++----
tests/qtest/migration-helpers.h | 9 +-
tests/qtest/migration-test.c | 174 +++++++++++++++++++++++++++--------
12 files changed, 256 insertions(+), 88 deletions(-)
--
1.8.3.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH V2 01/10] vl: start on wakeup request
2023-06-30 13:49 [PATCH V2 00/10] fix migration of suspended runstate Steve Sistare
@ 2023-06-30 13:49 ` Steve Sistare
2023-07-14 12:47 ` Fabiano Rosas
2023-06-30 13:49 ` [PATCH V2 02/10] migration: preserve suspended runstate Steve Sistare
` (8 subsequent siblings)
9 siblings, 1 reply; 15+ messages in thread
From: Steve Sistare @ 2023-06-30 13:49 UTC (permalink / raw)
To: qemu-devel
Cc: Juan Quintela, Peter Xu, Paolo Bonzini, Thomas Huth,
Daniel P. Berrangé, Steve Sistare
If qemu starts and loads a VM in the suspended state, then a later wakeup
request directly sets the state to running. This skips vm_start() and its
initialization steps, which is fatal for the guest. See
qemu_system_wakeup_request(), and qemu_system_wakeup() in
main_loop_should_exit().
Remember if vm_start has been called. If not, then call vm_start from
qemu_system_wakeup_request.
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
include/sysemu/runstate.h | 1 +
softmmu/cpus.c | 12 ++++++++++++
softmmu/runstate.c | 2 +-
3 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/include/sysemu/runstate.h b/include/sysemu/runstate.h
index 7beb29c..42ddf83 100644
--- a/include/sysemu/runstate.h
+++ b/include/sysemu/runstate.h
@@ -34,6 +34,7 @@ static inline bool shutdown_caused_by_guest(ShutdownCause cause)
}
void vm_start(void);
+void vm_wakeup(void);
/**
* vm_prepare_start: Prepare for starting/resuming the VM
diff --git a/softmmu/cpus.c b/softmmu/cpus.c
index fed20ff..fa9e5ba 100644
--- a/softmmu/cpus.c
+++ b/softmmu/cpus.c
@@ -66,6 +66,7 @@
#endif /* CONFIG_LINUX */
static QemuMutex qemu_global_mutex;
+static bool vm_started;
/*
* The chosen accelerator is supposed to register this.
@@ -264,6 +265,7 @@ static int do_vm_stop(RunState state, bool send_stop)
if (send_stop) {
qapi_event_send_stop();
}
+ vm_started = false;
}
bdrv_drain_all();
@@ -722,6 +724,16 @@ void vm_start(void)
{
if (!vm_prepare_start(false)) {
resume_all_vcpus();
+ vm_started = true;
+ }
+}
+
+void vm_wakeup(void)
+{
+ if (!vm_started) {
+ vm_start();
+ } else {
+ runstate_set(RUN_STATE_RUNNING);
}
}
diff --git a/softmmu/runstate.c b/softmmu/runstate.c
index 1957caf..5bbb22a 100644
--- a/softmmu/runstate.c
+++ b/softmmu/runstate.c
@@ -580,7 +580,7 @@ void qemu_system_wakeup_request(WakeupReason reason, Error **errp)
if (!(wakeup_reason_mask & (1 << reason))) {
return;
}
- runstate_set(RUN_STATE_RUNNING);
+ vm_wakeup();
wakeup_reason = reason;
qemu_notify_event();
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH V2 02/10] migration: preserve suspended runstate
2023-06-30 13:49 [PATCH V2 00/10] fix migration of suspended runstate Steve Sistare
2023-06-30 13:49 ` [PATCH V2 01/10] vl: start on wakeup request Steve Sistare
@ 2023-06-30 13:49 ` Steve Sistare
2023-07-14 12:48 ` Fabiano Rosas
2023-06-30 13:49 ` [PATCH V2 03/10] migration: add runstate function Steve Sistare
` (7 subsequent siblings)
9 siblings, 1 reply; 15+ messages in thread
From: Steve Sistare @ 2023-06-30 13:49 UTC (permalink / raw)
To: qemu-devel
Cc: Juan Quintela, Peter Xu, Paolo Bonzini, Thomas Huth,
Daniel P. Berrangé, Steve Sistare
A guest that is migrated in the suspended state automaticaly wakes and
continues execution. This is wrong; the guest should end migration in
the same state it started. The root causes is that the outgoing migration
code automatically wakes the guest, then saves the RUNNING runstate in
global_state_store(), hence the incoming migration code thinks the guest is
running and continues the guest if autostart is true.
On the outgoing side, do not call qemu_system_wakeup_request(). That
alone fixes precopy migration, as process_incoming_migration_bh correctly
sets runstate from global_state_get_runstate().
On the incoming side for postcopy, do not wake the guest, and apply the
the same logic as found in precopy: if autostart and the runstate is
RUNNING, then vm_start, else merely restore the runstate.
In both cases, if the restored state is SUSPENDED, then a later wakeup
request will resume the guest, courtesy of the previous "start on wakeup"
patch.
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
migration/migration.c | 2 --
migration/savevm.c | 13 ++++++++-----
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/migration/migration.c b/migration/migration.c
index 17b4b47..5495571 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -2101,7 +2101,6 @@ static int postcopy_start(MigrationState *ms)
qemu_mutex_lock_iothread();
trace_postcopy_start_set_run();
- qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER, NULL);
global_state_store();
ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
if (ret < 0) {
@@ -2307,7 +2306,6 @@ static void migration_completion(MigrationState *s)
if (s->state == MIGRATION_STATUS_ACTIVE) {
qemu_mutex_lock_iothread();
s->downtime_start = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
- qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER, NULL);
s->vm_old_state = runstate_get();
global_state_store();
diff --git a/migration/savevm.c b/migration/savevm.c
index bc28408..dfdbf02 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -2069,12 +2069,15 @@ static void loadvm_postcopy_handle_run_bh(void *opaque)
dirty_bitmap_mig_before_vm_start();
- if (autostart) {
- /* Hold onto your hats, starting the CPU */
- vm_start();
+ if (!global_state_received() ||
+ global_state_get_runstate() == RUN_STATE_RUNNING) {
+ if (autostart) {
+ vm_start();
+ } else {
+ runstate_set(RUN_STATE_PAUSED);
+ }
} else {
- /* leave it paused and let management decide when to start the CPU */
- runstate_set(RUN_STATE_PAUSED);
+ runstate_set(global_state_get_runstate());
}
qemu_bh_delete(mis->bh);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH V2 03/10] migration: add runstate function
2023-06-30 13:49 [PATCH V2 00/10] fix migration of suspended runstate Steve Sistare
2023-06-30 13:49 ` [PATCH V2 01/10] vl: start on wakeup request Steve Sistare
2023-06-30 13:49 ` [PATCH V2 02/10] migration: preserve suspended runstate Steve Sistare
@ 2023-06-30 13:49 ` Steve Sistare
2023-07-14 12:48 ` Fabiano Rosas
2023-06-30 13:49 ` [PATCH V2 04/10] migration: preserve suspended for snapshot Steve Sistare
` (6 subsequent siblings)
9 siblings, 1 reply; 15+ messages in thread
From: Steve Sistare @ 2023-06-30 13:49 UTC (permalink / raw)
To: qemu-devel
Cc: Juan Quintela, Peter Xu, Paolo Bonzini, Thomas Huth,
Daniel P. Berrangé, Steve Sistare
Create a subroutine for preserving the runstate after migration,
to be used in a subsequent patch. No functional change.
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
migration/migration.c | 14 ++++++++++++++
migration/migration.h | 1 +
migration/savevm.c | 11 +----------
3 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/migration/migration.c b/migration/migration.c
index 5495571..7a9218b 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1125,6 +1125,20 @@ void migrate_set_state(int *state, int old_state, int new_state)
}
}
+void migrate_set_runstate(void)
+{
+ if (!global_state_received() ||
+ global_state_get_runstate() == RUN_STATE_RUNNING) {
+ if (autostart) {
+ vm_start();
+ } else {
+ runstate_set(RUN_STATE_PAUSED);
+ }
+ } else {
+ runstate_set(global_state_get_runstate());
+ }
+}
+
static void migrate_fd_cleanup(MigrationState *s)
{
qemu_bh_delete(s->cleanup_bh);
diff --git a/migration/migration.h b/migration/migration.h
index 30c3e97..91c66b5 100644
--- a/migration/migration.h
+++ b/migration/migration.h
@@ -443,6 +443,7 @@ struct MigrationState {
};
void migrate_set_state(int *state, int old_state, int new_state);
+void migrate_set_runstate(void);
void migration_fd_process_incoming(QEMUFile *f, Error **errp);
void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp);
diff --git a/migration/savevm.c b/migration/savevm.c
index dfdbf02..e0f4972 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -2069,16 +2069,7 @@ static void loadvm_postcopy_handle_run_bh(void *opaque)
dirty_bitmap_mig_before_vm_start();
- if (!global_state_received() ||
- global_state_get_runstate() == RUN_STATE_RUNNING) {
- if (autostart) {
- vm_start();
- } else {
- runstate_set(RUN_STATE_PAUSED);
- }
- } else {
- runstate_set(global_state_get_runstate());
- }
+ migrate_set_runstate();
qemu_bh_delete(mis->bh);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH V2 04/10] migration: preserve suspended for snapshot
2023-06-30 13:49 [PATCH V2 00/10] fix migration of suspended runstate Steve Sistare
` (2 preceding siblings ...)
2023-06-30 13:49 ` [PATCH V2 03/10] migration: add runstate function Steve Sistare
@ 2023-06-30 13:49 ` Steve Sistare
2023-06-30 13:49 ` [PATCH V2 05/10] migration: preserve suspended for bg_migration Steve Sistare
` (5 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: Steve Sistare @ 2023-06-30 13:49 UTC (permalink / raw)
To: qemu-devel
Cc: Juan Quintela, Peter Xu, Paolo Bonzini, Thomas Huth,
Daniel P. Berrangé, Steve Sistare
Restoring a snapshot can break a suspended guest.
If a guest is suspended and saved to a snapshot using savevm, and qemu
is terminated and restarted with the -S option, then loadvm does not
restore the guest. The runstate is running, but the guest is not, because
vm_start was not called. The root cause is that loadvm does not restore
the runstate (eg suspended) from global_state loaded from the state file.
Restore the runstate, and allow the new state transitions that are possible.
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
migration/savevm.c | 1 +
softmmu/runstate.c | 2 ++
2 files changed, 3 insertions(+)
diff --git a/migration/savevm.c b/migration/savevm.c
index e0f4972..972d183 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -3139,6 +3139,7 @@ bool load_snapshot(const char *name, const char *vmstate,
}
aio_context_acquire(aio_context);
ret = qemu_loadvm_state(f);
+ migrate_set_runstate();
migration_incoming_state_destroy();
aio_context_release(aio_context);
diff --git a/softmmu/runstate.c b/softmmu/runstate.c
index 5bbb22a..18efe31 100644
--- a/softmmu/runstate.c
+++ b/softmmu/runstate.c
@@ -77,6 +77,8 @@ typedef struct {
static const RunStateTransition runstate_transitions_def[] = {
{ RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
+ { RUN_STATE_PRELAUNCH, RUN_STATE_PAUSED },
+ { RUN_STATE_PRELAUNCH, RUN_STATE_SUSPENDED },
{ RUN_STATE_DEBUG, RUN_STATE_RUNNING },
{ RUN_STATE_DEBUG, RUN_STATE_FINISH_MIGRATE },
--
1.8.3.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH V2 05/10] migration: preserve suspended for bg_migration
2023-06-30 13:49 [PATCH V2 00/10] fix migration of suspended runstate Steve Sistare
` (3 preceding siblings ...)
2023-06-30 13:49 ` [PATCH V2 04/10] migration: preserve suspended for snapshot Steve Sistare
@ 2023-06-30 13:49 ` Steve Sistare
2023-06-30 13:49 ` [PATCH V2 06/10] tests/qtest: migration events Steve Sistare
` (4 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: Steve Sistare @ 2023-06-30 13:49 UTC (permalink / raw)
To: qemu-devel
Cc: Juan Quintela, Peter Xu, Paolo Bonzini, Thomas Huth,
Daniel P. Berrangé, Steve Sistare
Do not wake a suspended guest during bg_migration.
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
migration/migration.c | 12 +++++-------
softmmu/runstate.c | 1 +
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/migration/migration.c b/migration/migration.c
index 7a9218b..125e060 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -3044,7 +3044,9 @@ static void bg_migration_vm_start_bh(void *opaque)
qemu_bh_delete(s->vm_start_bh);
s->vm_start_bh = NULL;
- vm_start();
+ if (!runstate_check(RUN_STATE_SUSPENDED)) {
+ vm_start();
+ }
s->downtime = qemu_clock_get_ms(QEMU_CLOCK_REALTIME) - s->downtime_start;
}
@@ -3114,16 +3116,12 @@ static void *bg_migration_thread(void *opaque)
qemu_mutex_lock_iothread();
- /*
- * If VM is currently in suspended state, then, to make a valid runstate
- * transition in vm_stop_force_state() we need to wakeup it up.
- */
- qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER, NULL);
s->vm_old_state = runstate_get();
global_state_store();
/* Forcibly stop VM before saving state of vCPUs and devices */
- if (vm_stop_force_state(RUN_STATE_PAUSED)) {
+ if (!runstate_check(RUN_STATE_SUSPENDED) &&
+ vm_stop_force_state(RUN_STATE_PAUSED)) {
goto fail;
}
/*
diff --git a/softmmu/runstate.c b/softmmu/runstate.c
index 18efe31..35ce343 100644
--- a/softmmu/runstate.c
+++ b/softmmu/runstate.c
@@ -163,6 +163,7 @@ static const RunStateTransition runstate_transitions_def[] = {
{ RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE },
{ RUN_STATE_SUSPENDED, RUN_STATE_PRELAUNCH },
{ RUN_STATE_SUSPENDED, RUN_STATE_COLO},
+ { RUN_STATE_SUSPENDED, RUN_STATE_PAUSED },
{ RUN_STATE_WATCHDOG, RUN_STATE_RUNNING },
{ RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE },
--
1.8.3.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH V2 06/10] tests/qtest: migration events
2023-06-30 13:49 [PATCH V2 00/10] fix migration of suspended runstate Steve Sistare
` (4 preceding siblings ...)
2023-06-30 13:49 ` [PATCH V2 05/10] migration: preserve suspended for bg_migration Steve Sistare
@ 2023-06-30 13:49 ` Steve Sistare
2023-07-14 12:57 ` Fabiano Rosas
2023-06-30 13:49 ` [PATCH V2 07/10] tests/qtest: option to suspend during migration Steve Sistare
` (3 subsequent siblings)
9 siblings, 1 reply; 15+ messages in thread
From: Steve Sistare @ 2023-06-30 13:49 UTC (permalink / raw)
To: qemu-devel
Cc: Juan Quintela, Peter Xu, Paolo Bonzini, Thomas Huth,
Daniel P. Berrangé, Steve Sistare
Define a state object to capture events seen by migration tests, to allow
more events to be captured in a subsequent patch, and simplify event
checking in wait_for_migration_pass. No functional change.
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
tests/qtest/migration-helpers.c | 24 +++++----------
tests/qtest/migration-helpers.h | 8 +++--
tests/qtest/migration-test.c | 68 +++++++++++++++++++----------------------
3 files changed, 44 insertions(+), 56 deletions(-)
diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helpers.c
index be00c52..b541108 100644
--- a/tests/qtest/migration-helpers.c
+++ b/tests/qtest/migration-helpers.c
@@ -23,26 +23,16 @@
*/
#define MIGRATION_STATUS_WAIT_TIMEOUT 120
-bool migrate_watch_for_stop(QTestState *who, const char *name,
- QDict *event, void *opaque)
-{
- bool *seen = opaque;
-
- if (g_str_equal(name, "STOP")) {
- *seen = true;
- return true;
- }
-
- return false;
-}
-
-bool migrate_watch_for_resume(QTestState *who, const char *name,
+bool migrate_watch_for_events(QTestState *who, const char *name,
QDict *event, void *opaque)
{
- bool *seen = opaque;
+ QTestMigrationState *state = opaque;
- if (g_str_equal(name, "RESUME")) {
- *seen = true;
+ if (g_str_equal(name, "STOP")) {
+ state->stop_seen = true;
+ return true;
+ } else if (g_str_equal(name, "RESUME")) {
+ state->resume_seen = true;
return true;
}
diff --git a/tests/qtest/migration-helpers.h b/tests/qtest/migration-helpers.h
index 009e250..59fbb83 100644
--- a/tests/qtest/migration-helpers.h
+++ b/tests/qtest/migration-helpers.h
@@ -15,9 +15,11 @@
#include "libqtest.h"
-bool migrate_watch_for_stop(QTestState *who, const char *name,
- QDict *event, void *opaque);
-bool migrate_watch_for_resume(QTestState *who, const char *name,
+typedef struct QTestMigrationState {
+ bool stop_seen, resume_seen;
+} QTestMigrationState;
+
+bool migrate_watch_for_events(QTestState *who, const char *name,
QDict *event, void *opaque);
G_GNUC_PRINTF(3, 4)
diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index b0c355b..2dde3af 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -43,8 +43,8 @@
unsigned start_address;
unsigned end_address;
static bool uffd_feature_thread_id;
-static bool got_src_stop;
-static bool got_dst_resume;
+static QTestMigrationState src_state;
+static QTestMigrationState dst_state;
/*
* Dirtylimit stop working if dirty page rate error
@@ -174,6 +174,13 @@ static void wait_for_serial(const char *side)
} while (true);
}
+static void wait_for_stop(QTestState *who, QTestMigrationState *state)
+{
+ if (!state->stop_seen) {
+ qtest_qmp_eventwait(who, "STOP");
+ }
+}
+
/*
* It's tricky to use qemu's migration event capability with qtest,
* events suddenly appearing confuse the qmp()/hmp() responses.
@@ -221,21 +228,19 @@ static void read_blocktime(QTestState *who)
qobject_unref(rsp_return);
}
+/*
+ * Wait for two changes in the migration pass count, but bail if we stop.
+ */
static void wait_for_migration_pass(QTestState *who)
{
- uint64_t initial_pass = get_migration_pass(who);
- uint64_t pass;
+ uint64_t pass, prev_pass = 0, changes = 0;
- /* Wait for the 1st sync */
- while (!got_src_stop && !initial_pass) {
- usleep(1000);
- initial_pass = get_migration_pass(who);
- }
-
- do {
+ while (changes < 2 && !src_state.stop_seen) {
usleep(1000);
pass = get_migration_pass(who);
- } while (pass == initial_pass && !got_src_stop);
+ changes += (pass != prev_pass);
+ prev_pass = pass;
+ }
}
static void check_guests_ram(QTestState *who)
@@ -487,10 +492,7 @@ static void migrate_postcopy_start(QTestState *from, QTestState *to)
{
qtest_qmp_assert_success(from, "{ 'execute': 'migrate-start-postcopy' }");
- if (!got_src_stop) {
- qtest_qmp_eventwait(from, "STOP");
- }
-
+ wait_for_stop(from, &src_state);
qtest_qmp_eventwait(to, "RESUME");
}
@@ -617,8 +619,9 @@ static int test_migrate_start(QTestState **from, QTestState **to,
}
}
- got_src_stop = false;
- got_dst_resume = false;
+ dst_state = (QTestMigrationState) { };
+ src_state = (QTestMigrationState) { };
+
bootpath = g_strdup_printf("%s/bootsect", tmpfs);
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
/* the assembled x86 boot sector should be exactly one sector large */
@@ -705,8 +708,8 @@ static int test_migrate_start(QTestState **from, QTestState **to,
if (!args->only_target) {
*from = qtest_init(cmd_source);
qtest_qmp_set_event_callback(*from,
- migrate_watch_for_stop,
- &got_src_stop);
+ migrate_watch_for_events,
+ &src_state);
}
cmd_target = g_strdup_printf("-accel kvm%s -accel tcg%s%s "
@@ -725,8 +728,8 @@ static int test_migrate_start(QTestState **from, QTestState **to,
ignore_stderr);
*to = qtest_init(cmd_target);
qtest_qmp_set_event_callback(*to,
- migrate_watch_for_resume,
- &got_dst_resume);
+ migrate_watch_for_events,
+ &dst_state);
/*
* Remove shmem file immediately to avoid memory leak in test failed case.
@@ -1422,9 +1425,7 @@ static void test_precopy_common(MigrateCommon *args)
*/
if (args->result == MIG_TEST_SUCCEED) {
qtest_qmp_assert_success(from, "{ 'execute' : 'stop'}");
- if (!got_src_stop) {
- qtest_qmp_eventwait(from, "STOP");
- }
+ wait_for_stop(from, &src_state);
migrate_ensure_converge(from);
}
}
@@ -1463,9 +1464,8 @@ static void test_precopy_common(MigrateCommon *args)
*/
wait_for_migration_complete(from);
- if (!got_src_stop) {
- qtest_qmp_eventwait(from, "STOP");
- }
+ wait_for_stop(from, &src_state);
+
} else {
wait_for_migration_complete(from);
/*
@@ -1478,7 +1478,7 @@ static void test_precopy_common(MigrateCommon *args)
qtest_qmp_assert_success(to, "{ 'execute' : 'cont'}");
}
- if (!got_dst_resume) {
+ if (!dst_state.resume_seen) {
qtest_qmp_eventwait(to, "RESUME");
}
@@ -1596,9 +1596,7 @@ static void test_ignore_shared(void)
wait_for_migration_pass(from);
- if (!got_src_stop) {
- qtest_qmp_eventwait(from, "STOP");
- }
+ wait_for_stop(from, &src_state);
qtest_qmp_eventwait(to, "RESUME");
@@ -2012,7 +2010,7 @@ static void test_migrate_auto_converge(void)
break;
}
usleep(20);
- g_assert_false(got_src_stop);
+ g_assert_false(src_state.stop_seen);
} while (true);
/* The first percentage of throttling should be at least init_pct */
g_assert_cmpint(percentage, >=, init_pct);
@@ -2351,9 +2349,7 @@ static void test_multifd_tcp_cancel(void)
wait_for_migration_pass(from);
- if (!got_src_stop) {
- qtest_qmp_eventwait(from, "STOP");
- }
+ wait_for_stop(from, &src_state);
qtest_qmp_eventwait(to2, "RESUME");
wait_for_serial("dest_serial");
--
1.8.3.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH V2 07/10] tests/qtest: option to suspend during migration
2023-06-30 13:49 [PATCH V2 00/10] fix migration of suspended runstate Steve Sistare
` (5 preceding siblings ...)
2023-06-30 13:49 ` [PATCH V2 06/10] tests/qtest: migration events Steve Sistare
@ 2023-06-30 13:49 ` Steve Sistare
2023-06-30 13:49 ` [PATCH V2 08/10] tests/qtest: precopy migration with suspend Steve Sistare
` (2 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: Steve Sistare @ 2023-06-30 13:49 UTC (permalink / raw)
To: qemu-devel
Cc: Juan Quintela, Peter Xu, Paolo Bonzini, Thomas Huth,
Daniel P. Berrangé, Steve Sistare
Add an option to suspend the src in a-b-bootblock.S, which puts the guest
in S3 state after one round of writing to memory. The option is enabled by
poking a 1 into the suspend_me word in the boot block prior to starting the
src vm. Generate symbol offsets in a-b-bootblock.h so that the suspend_me
offset is known.
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
tests/migration/i386/Makefile | 5 ++--
tests/migration/i386/a-b-bootblock.S | 51 +++++++++++++++++++++++++++++++++---
tests/migration/i386/a-b-bootblock.h | 22 ++++++++++------
tests/qtest/migration-test.c | 4 +++
4 files changed, 68 insertions(+), 14 deletions(-)
diff --git a/tests/migration/i386/Makefile b/tests/migration/i386/Makefile
index 5c03241..37a72ae 100644
--- a/tests/migration/i386/Makefile
+++ b/tests/migration/i386/Makefile
@@ -4,9 +4,10 @@
.PHONY: all clean
all: a-b-bootblock.h
-a-b-bootblock.h: x86.bootsect
+a-b-bootblock.h: x86.bootsect x86.o
echo "$$__note" > header.tmp
xxd -i $< | sed -e 's/.*int.*//' >> header.tmp
+ nm x86.o | awk '{print "#define SYM_"$$3" 0x"$$1}' >> header.tmp
mv header.tmp $@
x86.bootsect: x86.boot
@@ -16,7 +17,7 @@ x86.boot: x86.o
$(CROSS_PREFIX)objcopy -O binary $< $@
x86.o: a-b-bootblock.S
- $(CROSS_PREFIX)gcc -m32 -march=i486 -c $< -o $@
+ $(CROSS_PREFIX)gcc -I.. -m32 -march=i486 -c $< -o $@
clean:
@rm -rf *.boot *.o *.bootsect
diff --git a/tests/migration/i386/a-b-bootblock.S b/tests/migration/i386/a-b-bootblock.S
index 3d464c7..62d79b2 100644
--- a/tests/migration/i386/a-b-bootblock.S
+++ b/tests/migration/i386/a-b-bootblock.S
@@ -9,6 +9,23 @@
#
# Author: dgilbert@redhat.com
+#include "migration-test.h"
+
+#define ACPI_ENABLE 0xf1
+#define ACPI_PORT_SMI_CMD 0xb2
+#define ACPI_PM_BASE 0x600
+#define PM1A_CNT_OFFSET 4
+
+#define ACPI_SCI_ENABLE 0x0001
+#define ACPI_SLEEP_TYPE 0x0400
+#define ACPI_SLEEP_ENABLE 0x2000
+#define SLEEP (ACPI_SCI_ENABLE + ACPI_SLEEP_TYPE + ACPI_SLEEP_ENABLE)
+
+#define LOW_ADDR X86_TEST_MEM_START
+#define HIGH_ADDR X86_TEST_MEM_END
+
+/* Save the suspended status at an address that is not written in the loop. */
+#define suspended (X86_TEST_MEM_START + 4)
.code16
.org 0x7c00
@@ -41,12 +58,11 @@ start: # at 0x7c00 ?
# bl keeps a counter so we limit the output speed
mov $0, %bl
mainloop:
- # Start from 1MB
- mov $(1024*1024),%eax
+ mov $LOW_ADDR,%eax
innerloop:
incb (%eax)
add $4096,%eax
- cmp $(100*1024*1024),%eax
+ cmp $HIGH_ADDR,%eax
jl innerloop
inc %bl
@@ -57,7 +73,30 @@ innerloop:
mov $0x3f8,%dx
outb %al,%dx
- jmp mainloop
+ # should this test suspend?
+ mov (suspend_me),%eax
+ cmp $0,%eax
+ je mainloop
+
+ # are we waking after suspend? do not suspend again.
+ mov $suspended,%eax
+ mov (%eax),%eax
+ cmp $1,%eax
+ je mainloop
+
+ # enable acpi
+ mov $ACPI_ENABLE,%al
+ outb %al,$ACPI_PORT_SMI_CMD
+
+ # suspend to ram
+ mov $suspended,%eax
+ movl $1,(%eax)
+ mov $SLEEP,%ax
+ mov $(ACPI_PM_BASE + PM1A_CNT_OFFSET),%dx
+ outw %ax,%dx
+ # not reached. The wakeup causes reset and restart at 0x7c00, and we
+ # do not save and restore registers as a real kernel would do.
+
# GDT magic from old (GPLv2) Grub startup.S
.p2align 2 /* force 4-byte alignment */
@@ -83,6 +122,10 @@ gdtdesc:
.word 0x27 /* limit */
.long gdt /* addr */
+ /* test launcher can poke a 1 here to exercise suspend */
+suspend_me:
+ .int 0
+
/* I'm a bootable disk */
.org 0x7dfe
.byte 0x55
diff --git a/tests/migration/i386/a-b-bootblock.h b/tests/migration/i386/a-b-bootblock.h
index b7b0fce..4d46873 100644
--- a/tests/migration/i386/a-b-bootblock.h
+++ b/tests/migration/i386/a-b-bootblock.h
@@ -4,20 +4,20 @@
* the header and the assembler differences in your patch submission.
*/
unsigned char x86_bootsect[] = {
- 0xfa, 0x0f, 0x01, 0x16, 0x78, 0x7c, 0x66, 0xb8, 0x01, 0x00, 0x00, 0x00,
+ 0xfa, 0x0f, 0x01, 0x16, 0xa4, 0x7c, 0x66, 0xb8, 0x01, 0x00, 0x00, 0x00,
0x0f, 0x22, 0xc0, 0x66, 0xea, 0x20, 0x7c, 0x00, 0x00, 0x08, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe4, 0x92, 0x0c, 0x02,
0xe6, 0x92, 0xb8, 0x10, 0x00, 0x00, 0x00, 0x8e, 0xd8, 0x66, 0xb8, 0x41,
0x00, 0x66, 0xba, 0xf8, 0x03, 0xee, 0xb3, 0x00, 0xb8, 0x00, 0x00, 0x10,
0x00, 0xfe, 0x00, 0x05, 0x00, 0x10, 0x00, 0x00, 0x3d, 0x00, 0x00, 0x40,
0x06, 0x7c, 0xf2, 0xfe, 0xc3, 0x80, 0xe3, 0x3f, 0x75, 0xe6, 0x66, 0xb8,
- 0x42, 0x00, 0x66, 0xba, 0xf8, 0x03, 0xee, 0xeb, 0xdb, 0x8d, 0x76, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00,
- 0x00, 0x9a, 0xcf, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x92, 0xcf, 0x00,
- 0x27, 0x00, 0x60, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x42, 0x00, 0x66, 0xba, 0xf8, 0x03, 0xee, 0xa1, 0xaa, 0x7c, 0x00, 0x00,
+ 0x83, 0xf8, 0x00, 0x74, 0xd3, 0xb8, 0x04, 0x00, 0x10, 0x00, 0x8b, 0x00,
+ 0x83, 0xf8, 0x01, 0x74, 0xc7, 0xb0, 0xf1, 0xe6, 0xb2, 0xb8, 0x04, 0x00,
+ 0x10, 0x00, 0xc7, 0x00, 0x01, 0x00, 0x00, 0x00, 0x66, 0xb8, 0x01, 0x24,
+ 0x66, 0xba, 0x04, 0x06, 0x66, 0xef, 0x66, 0x90, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x9a, 0xcf, 0x00,
+ 0xff, 0xff, 0x00, 0x00, 0x00, 0x92, 0xcf, 0x00, 0x27, 0x00, 0x8c, 0x7c,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -49,3 +49,9 @@ unsigned char x86_bootsect[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa
};
+#define SYM_gdt 0x00007c8c
+#define SYM_gdtdesc 0x00007ca4
+#define SYM_innerloop 0x00007c3d
+#define SYM_mainloop 0x00007c38
+#define SYM_start 0x00007c00
+#define SYM_suspend_me 0x00007caa
diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 2dde3af..591103e 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -509,6 +509,8 @@ typedef struct {
bool use_dirty_ring;
const char *opts_source;
const char *opts_target;
+ /* suspend the src before migrating to dest. */
+ bool suspend_me;
} MigrateStart;
/*
@@ -622,6 +624,8 @@ static int test_migrate_start(QTestState **from, QTestState **to,
dst_state = (QTestMigrationState) { };
src_state = (QTestMigrationState) { };
+ x86_bootsect[SYM_suspend_me - SYM_start] = args->suspend_me;
+
bootpath = g_strdup_printf("%s/bootsect", tmpfs);
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
/* the assembled x86 boot sector should be exactly one sector large */
--
1.8.3.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH V2 08/10] tests/qtest: precopy migration with suspend
2023-06-30 13:49 [PATCH V2 00/10] fix migration of suspended runstate Steve Sistare
` (6 preceding siblings ...)
2023-06-30 13:49 ` [PATCH V2 07/10] tests/qtest: option to suspend during migration Steve Sistare
@ 2023-06-30 13:49 ` Steve Sistare
2023-06-30 13:49 ` [PATCH V2 09/10] tests/qtest: postcopy " Steve Sistare
2023-06-30 13:49 ` [PATCH V2 10/10] tests/qtest: background " Steve Sistare
9 siblings, 0 replies; 15+ messages in thread
From: Steve Sistare @ 2023-06-30 13:49 UTC (permalink / raw)
To: qemu-devel
Cc: Juan Quintela, Peter Xu, Paolo Bonzini, Thomas Huth,
Daniel P. Berrangé, Steve Sistare
Add a test case to verify that the suspended state is handled correctly
during live migration precopy. The test suspends the src, migrates, then
wakes the dest.
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
tests/qtest/migration-helpers.c | 3 ++
tests/qtest/migration-helpers.h | 3 +-
tests/qtest/migration-test.c | 69 +++++++++++++++++++++++++++++++++++++----
3 files changed, 68 insertions(+), 7 deletions(-)
diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helpers.c
index b541108..d1fec49 100644
--- a/tests/qtest/migration-helpers.c
+++ b/tests/qtest/migration-helpers.c
@@ -31,6 +31,9 @@ bool migrate_watch_for_events(QTestState *who, const char *name,
if (g_str_equal(name, "STOP")) {
state->stop_seen = true;
return true;
+ } else if (g_str_equal(name, "SUSPEND")) {
+ state->suspend_seen = true;
+ return true;
} else if (g_str_equal(name, "RESUME")) {
state->resume_seen = true;
return true;
diff --git a/tests/qtest/migration-helpers.h b/tests/qtest/migration-helpers.h
index 59fbb83..bac8699 100644
--- a/tests/qtest/migration-helpers.h
+++ b/tests/qtest/migration-helpers.h
@@ -16,7 +16,8 @@
#include "libqtest.h"
typedef struct QTestMigrationState {
- bool stop_seen, resume_seen;
+ bool suspend_me;
+ bool stop_seen, suspend_seen, resume_seen;
} QTestMigrationState;
bool migrate_watch_for_events(QTestState *who, const char *name,
diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 591103e..20f017d 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -121,7 +121,7 @@ static void init_bootfile(const char *bootpath, void *content, size_t len)
/*
* Wait for some output in the serial output file,
* we get an 'A' followed by an endless string of 'B's
- * but on the destination we won't have the A.
+ * but on the destination we won't have the A (unless we enabled suspend/resume)
*/
static void wait_for_serial(const char *side)
{
@@ -181,6 +181,13 @@ static void wait_for_stop(QTestState *who, QTestMigrationState *state)
}
}
+static void wait_for_suspend(QTestState *who, QTestMigrationState *state)
+{
+ if (!state->suspend_seen) {
+ qtest_qmp_eventwait(who, "SUSPEND");
+ }
+}
+
/*
* It's tricky to use qemu's migration event capability with qtest,
* events suddenly appearing confuse the qmp()/hmp() responses.
@@ -235,7 +242,7 @@ static void wait_for_migration_pass(QTestState *who)
{
uint64_t pass, prev_pass = 0, changes = 0;
- while (changes < 2 && !src_state.stop_seen) {
+ while (changes < 2 && !src_state.stop_seen && !src_state.suspend_seen) {
usleep(1000);
pass = get_migration_pass(who);
changes += (pass != prev_pass);
@@ -624,6 +631,7 @@ static int test_migrate_start(QTestState **from, QTestState **to,
dst_state = (QTestMigrationState) { };
src_state = (QTestMigrationState) { };
+ src_state.suspend_me = args->suspend_me;
x86_bootsect[SYM_suspend_me - SYM_start] = args->suspend_me;
bootpath = g_strdup_printf("%s/bootsect", tmpfs);
@@ -1428,8 +1436,12 @@ static void test_precopy_common(MigrateCommon *args)
* change anything.
*/
if (args->result == MIG_TEST_SUCCEED) {
- qtest_qmp_assert_success(from, "{ 'execute' : 'stop'}");
- wait_for_stop(from, &src_state);
+ if (src_state.suspend_me) {
+ wait_for_suspend(from, &src_state);
+ } else {
+ qtest_qmp_assert_success(from, "{ 'execute' : 'stop'}");
+ wait_for_stop(from, &src_state);
+ }
migrate_ensure_converge(from);
}
}
@@ -1468,7 +1480,11 @@ static void test_precopy_common(MigrateCommon *args)
*/
wait_for_migration_complete(from);
- wait_for_stop(from, &src_state);
+ if (src_state.suspend_me) {
+ wait_for_suspend(from, &src_state);
+ } else {
+ wait_for_stop(from, &src_state);
+ }
} else {
wait_for_migration_complete(from);
@@ -1482,6 +1498,11 @@ static void test_precopy_common(MigrateCommon *args)
qtest_qmp_assert_success(to, "{ 'execute' : 'cont'}");
}
+ if (args->start.suspend_me) {
+ /* wakeup succeeds only if guest is suspended */
+ qtest_qmp_assert_success(to, "{'execute': 'system_wakeup'}");
+ }
+
if (!dst_state.resume_seen) {
qtest_qmp_eventwait(to, "RESUME");
}
@@ -1512,6 +1533,34 @@ static void test_precopy_unix_plain(void)
test_precopy_common(&args);
}
+static void test_precopy_unix_suspend_live(void)
+{
+ g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
+ MigrateCommon args = {
+ .listen_uri = uri,
+ .connect_uri = uri,
+ /*
+ * despite being live, the test is fast because the src
+ * suspends immediately.
+ */
+ .live = true,
+ .start.suspend_me = true,
+ };
+
+ test_precopy_common(&args);
+}
+
+static void test_precopy_unix_suspend_notlive(void)
+{
+ g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
+ MigrateCommon args = {
+ .listen_uri = uri,
+ .connect_uri = uri,
+ .start.suspend_me = true,
+ };
+
+ test_precopy_common(&args);
+}
static void test_precopy_unix_dirty_ring(void)
{
@@ -2635,7 +2684,7 @@ static bool kvm_dirty_ring_supported(void)
int main(int argc, char **argv)
{
bool has_kvm, has_tcg;
- bool has_uffd;
+ bool has_uffd, is_x86;
const char *arch;
g_autoptr(GError) err = NULL;
int ret;
@@ -2652,6 +2701,7 @@ int main(int argc, char **argv)
has_uffd = ufd_version_check();
arch = qtest_get_arch();
+ is_x86 = !strcmp(arch, "i386") || !strcmp(arch, "x86_64");
/*
* On ppc64, the test only works with kvm-hv, but not with kvm-pr and TCG
@@ -2682,6 +2732,13 @@ int main(int argc, char **argv)
module_call_init(MODULE_INIT_QOM);
+ if (is_x86) {
+ qtest_add_func("/migration/precopy/unix/suspend/live",
+ test_precopy_unix_suspend_live);
+ qtest_add_func("/migration/precopy/unix/suspend/notlive",
+ test_precopy_unix_suspend_notlive);
+ }
+
if (has_uffd) {
qtest_add_func("/migration/postcopy/plain", test_postcopy);
qtest_add_func("/migration/postcopy/recovery/plain",
--
1.8.3.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH V2 09/10] tests/qtest: postcopy migration with suspend
2023-06-30 13:49 [PATCH V2 00/10] fix migration of suspended runstate Steve Sistare
` (7 preceding siblings ...)
2023-06-30 13:49 ` [PATCH V2 08/10] tests/qtest: precopy migration with suspend Steve Sistare
@ 2023-06-30 13:49 ` Steve Sistare
2023-06-30 13:49 ` [PATCH V2 10/10] tests/qtest: background " Steve Sistare
9 siblings, 0 replies; 15+ messages in thread
From: Steve Sistare @ 2023-06-30 13:49 UTC (permalink / raw)
To: qemu-devel
Cc: Juan Quintela, Peter Xu, Paolo Bonzini, Thomas Huth,
Daniel P. Berrangé, Steve Sistare
Add a test case to verify that the suspended state is handled correctly by
live migration postcopy. The test suspends the src, migrates, then wakes
the dest.
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
tests/qtest/migration-test.c | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 20f017d..8905595 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -499,8 +499,12 @@ static void migrate_postcopy_start(QTestState *from, QTestState *to)
{
qtest_qmp_assert_success(from, "{ 'execute': 'migrate-start-postcopy' }");
- wait_for_stop(from, &src_state);
- qtest_qmp_eventwait(to, "RESUME");
+ if (src_state.suspend_me) {
+ wait_for_suspend(from, &src_state);
+ } else {
+ wait_for_stop(from, &src_state);
+ qtest_qmp_eventwait(to, "RESUME");
+ }
}
typedef struct {
@@ -1198,6 +1202,11 @@ static void migrate_postcopy_complete(QTestState *from, QTestState *to,
{
wait_for_migration_complete(from);
+ if (args->start.suspend_me) {
+ /* wakeup succeeds only if guest is suspended */
+ qtest_qmp_assert_success(to, "{'execute': 'system_wakeup'}");
+ }
+
/* Make sure we get at least one "B" on destination */
wait_for_serial("dest_serial");
@@ -1231,6 +1240,15 @@ static void test_postcopy(void)
test_postcopy_common(&args);
}
+static void test_postcopy_suspend(void)
+{
+ MigrateCommon args = {
+ .start.suspend_me = true,
+ };
+
+ test_postcopy_common(&args);
+}
+
static void test_postcopy_compress(void)
{
MigrateCommon args = {
@@ -2752,6 +2770,10 @@ int main(int argc, char **argv)
qtest_add_func("/migration/postcopy/recovery/compress/plain",
test_postcopy_recovery_compress);
}
+ if (is_x86) {
+ qtest_add_func("/migration/postcopy/suspend",
+ test_postcopy_suspend);
+ }
}
qtest_add_func("/migration/bad_dest", test_baddest);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH V2 10/10] tests/qtest: background migration with suspend
2023-06-30 13:49 [PATCH V2 00/10] fix migration of suspended runstate Steve Sistare
` (8 preceding siblings ...)
2023-06-30 13:49 ` [PATCH V2 09/10] tests/qtest: postcopy " Steve Sistare
@ 2023-06-30 13:49 ` Steve Sistare
9 siblings, 0 replies; 15+ messages in thread
From: Steve Sistare @ 2023-06-30 13:49 UTC (permalink / raw)
To: qemu-devel
Cc: Juan Quintela, Peter Xu, Paolo Bonzini, Thomas Huth,
Daniel P. Berrangé, Steve Sistare
Add a test case to verify that the suspended state is handled correctly by
a background migration. The test suspends the src, migrates, then wakes
the dest.
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
tests/qtest/migration-test.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 8905595..4c0bc95 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -1580,6 +1580,26 @@ static void test_precopy_unix_suspend_notlive(void)
test_precopy_common(&args);
}
+static void *test_bg_suspend_start(QTestState *from, QTestState *to)
+{
+ migrate_set_capability(from, "background-snapshot", true);
+ return NULL;
+}
+
+static void test_bg_suspend(void)
+{
+ g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
+ MigrateCommon args = {
+ .listen_uri = uri,
+ .connect_uri = uri,
+ .live = true, /* runs fast, the src suspends immediately. */
+ .start.suspend_me = true,
+ .start_hook = test_bg_suspend_start
+ };
+
+ test_precopy_common(&args);
+}
+
static void test_precopy_unix_dirty_ring(void)
{
g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
@@ -2773,6 +2793,7 @@ int main(int argc, char **argv)
if (is_x86) {
qtest_add_func("/migration/postcopy/suspend",
test_postcopy_suspend);
+ qtest_add_func("/migration/bg/suspend", test_bg_suspend);
}
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH V2 01/10] vl: start on wakeup request
2023-06-30 13:49 ` [PATCH V2 01/10] vl: start on wakeup request Steve Sistare
@ 2023-07-14 12:47 ` Fabiano Rosas
0 siblings, 0 replies; 15+ messages in thread
From: Fabiano Rosas @ 2023-07-14 12:47 UTC (permalink / raw)
To: Steve Sistare, qemu-devel
Cc: Juan Quintela, Peter Xu, Paolo Bonzini, Thomas Huth,
Daniel P. Berrangé, Steve Sistare
Steve Sistare <steven.sistare@oracle.com> writes:
> If qemu starts and loads a VM in the suspended state, then a later wakeup
> request directly sets the state to running. This skips vm_start() and its
> initialization steps, which is fatal for the guest. See
> qemu_system_wakeup_request(), and qemu_system_wakeup() in
> main_loop_should_exit().
>
> Remember if vm_start has been called. If not, then call vm_start from
> qemu_system_wakeup_request.
>
> Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH V2 02/10] migration: preserve suspended runstate
2023-06-30 13:49 ` [PATCH V2 02/10] migration: preserve suspended runstate Steve Sistare
@ 2023-07-14 12:48 ` Fabiano Rosas
0 siblings, 0 replies; 15+ messages in thread
From: Fabiano Rosas @ 2023-07-14 12:48 UTC (permalink / raw)
To: Steve Sistare, qemu-devel
Cc: Juan Quintela, Peter Xu, Paolo Bonzini, Thomas Huth,
Daniel P. Berrangé, Steve Sistare
Steve Sistare <steven.sistare@oracle.com> writes:
> A guest that is migrated in the suspended state automaticaly wakes and
> continues execution. This is wrong; the guest should end migration in
> the same state it started. The root causes is that the outgoing migration
> code automatically wakes the guest, then saves the RUNNING runstate in
> global_state_store(), hence the incoming migration code thinks the guest is
> running and continues the guest if autostart is true.
>
> On the outgoing side, do not call qemu_system_wakeup_request(). That
> alone fixes precopy migration, as process_incoming_migration_bh correctly
> sets runstate from global_state_get_runstate().
>
> On the incoming side for postcopy, do not wake the guest, and apply the
> the same logic as found in precopy: if autostart and the runstate is
> RUNNING, then vm_start, else merely restore the runstate.
>
> In both cases, if the restored state is SUSPENDED, then a later wakeup
> request will resume the guest, courtesy of the previous "start on wakeup"
> patch.
>
> Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH V2 03/10] migration: add runstate function
2023-06-30 13:49 ` [PATCH V2 03/10] migration: add runstate function Steve Sistare
@ 2023-07-14 12:48 ` Fabiano Rosas
0 siblings, 0 replies; 15+ messages in thread
From: Fabiano Rosas @ 2023-07-14 12:48 UTC (permalink / raw)
To: Steve Sistare, qemu-devel
Cc: Juan Quintela, Peter Xu, Paolo Bonzini, Thomas Huth,
Daniel P. Berrangé, Steve Sistare
Steve Sistare <steven.sistare@oracle.com> writes:
> Create a subroutine for preserving the runstate after migration,
> to be used in a subsequent patch. No functional change.
>
> Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH V2 06/10] tests/qtest: migration events
2023-06-30 13:49 ` [PATCH V2 06/10] tests/qtest: migration events Steve Sistare
@ 2023-07-14 12:57 ` Fabiano Rosas
0 siblings, 0 replies; 15+ messages in thread
From: Fabiano Rosas @ 2023-07-14 12:57 UTC (permalink / raw)
To: Steve Sistare, qemu-devel
Cc: Juan Quintela, Peter Xu, Paolo Bonzini, Thomas Huth,
Daniel P. Berrangé, Steve Sistare
Steve Sistare <steven.sistare@oracle.com> writes:
> Define a state object to capture events seen by migration tests, to allow
> more events to be captured in a subsequent patch, and simplify event
> checking in wait_for_migration_pass. No functional change.
>
> Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
I'm working on top of this patch in another series and it works
fine. I have a patch adding the migration events to it (setup, active,
completed, etc).
> ---
> tests/qtest/migration-helpers.c | 24 +++++----------
> tests/qtest/migration-helpers.h | 8 +++--
> tests/qtest/migration-test.c | 68 +++++++++++++++++++----------------------
> 3 files changed, 44 insertions(+), 56 deletions(-)
>
> diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helpers.c
> index be00c52..b541108 100644
> --- a/tests/qtest/migration-helpers.c
> +++ b/tests/qtest/migration-helpers.c
> @@ -23,26 +23,16 @@
> */
> #define MIGRATION_STATUS_WAIT_TIMEOUT 120
>
> -bool migrate_watch_for_stop(QTestState *who, const char *name,
> - QDict *event, void *opaque)
> -{
> - bool *seen = opaque;
> -
> - if (g_str_equal(name, "STOP")) {
> - *seen = true;
> - return true;
> - }
> -
> - return false;
> -}
> -
> -bool migrate_watch_for_resume(QTestState *who, const char *name,
> +bool migrate_watch_for_events(QTestState *who, const char *name,
> QDict *event, void *opaque)
> {
> - bool *seen = opaque;
> + QTestMigrationState *state = opaque;
>
> - if (g_str_equal(name, "RESUME")) {
> - *seen = true;
> + if (g_str_equal(name, "STOP")) {
> + state->stop_seen = true;
> + return true;
> + } else if (g_str_equal(name, "RESUME")) {
> + state->resume_seen = true;
> return true;
> }
>
> diff --git a/tests/qtest/migration-helpers.h b/tests/qtest/migration-helpers.h
> index 009e250..59fbb83 100644
> --- a/tests/qtest/migration-helpers.h
> +++ b/tests/qtest/migration-helpers.h
> @@ -15,9 +15,11 @@
>
> #include "libqtest.h"
>
> -bool migrate_watch_for_stop(QTestState *who, const char *name,
> - QDict *event, void *opaque);
> -bool migrate_watch_for_resume(QTestState *who, const char *name,
> +typedef struct QTestMigrationState {
> + bool stop_seen, resume_seen;
> +} QTestMigrationState;
> +
> +bool migrate_watch_for_events(QTestState *who, const char *name,
> QDict *event, void *opaque);
>
> G_GNUC_PRINTF(3, 4)
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index b0c355b..2dde3af 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -43,8 +43,8 @@
> unsigned start_address;
> unsigned end_address;
> static bool uffd_feature_thread_id;
> -static bool got_src_stop;
> -static bool got_dst_resume;
> +static QTestMigrationState src_state;
> +static QTestMigrationState dst_state;
It's a bit cumbersome though to have the QTestMigrationState in
migration-test.c and having to pass it around. Could we maybe move it
inside QTestState? That way it is easily reachable from
migrate-helpers.c and we could move all the wait* functions there.
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2023-07-14 12:57 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-30 13:49 [PATCH V2 00/10] fix migration of suspended runstate Steve Sistare
2023-06-30 13:49 ` [PATCH V2 01/10] vl: start on wakeup request Steve Sistare
2023-07-14 12:47 ` Fabiano Rosas
2023-06-30 13:49 ` [PATCH V2 02/10] migration: preserve suspended runstate Steve Sistare
2023-07-14 12:48 ` Fabiano Rosas
2023-06-30 13:49 ` [PATCH V2 03/10] migration: add runstate function Steve Sistare
2023-07-14 12:48 ` Fabiano Rosas
2023-06-30 13:49 ` [PATCH V2 04/10] migration: preserve suspended for snapshot Steve Sistare
2023-06-30 13:49 ` [PATCH V2 05/10] migration: preserve suspended for bg_migration Steve Sistare
2023-06-30 13:49 ` [PATCH V2 06/10] tests/qtest: migration events Steve Sistare
2023-07-14 12:57 ` Fabiano Rosas
2023-06-30 13:49 ` [PATCH V2 07/10] tests/qtest: option to suspend during migration Steve Sistare
2023-06-30 13:49 ` [PATCH V2 08/10] tests/qtest: precopy migration with suspend Steve Sistare
2023-06-30 13:49 ` [PATCH V2 09/10] tests/qtest: postcopy " Steve Sistare
2023-06-30 13:49 ` [PATCH V2 10/10] tests/qtest: background " Steve Sistare
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).