fix migration of suspended runstate
v7 cover fix migration of suspended runstate
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, after saving a snapshot in the suspended state and loading it, the vm_start 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
Changes in V3:
* rebase to tip
* fix hang in new function migrate_wait_for_dirty_mem
Changes in V4:
* rebase to tip
* add patch for vm_prepare_start (thanks Peter)
* add patch to preserve cpu ticks
Changes in V5:
* rebase to tip
* added patches to completely stop vm in suspended state:
cpus: refactor vm_stop
cpus: stop vm in suspended state
* added patch to partially resume vm in suspended state:
cpus: start vm in suspended state
* modified "preserve suspended ..." patches to use the above.
* deleted patch "preserve cpu ticks if suspended". stop ticks in vm_stop_force_state instead.
* deleted patch "add runstate function". defined new helper function migrate_new_runstate in "preserve suspended runstate"
* Added some RB's, but removed other RB's because the patches changed.
Changes in V6:
* all vm_stop calls completely stop the suspended state
* refactored and updated the "cpus" patches
* simplified the "preserve suspended" patches
* added patch "bootfile per vm"
Changes in V7:
* rebase to tip, add RB-s
* fix backwards compatibility for global_state.vm_was_suspended
* delete vm_prepare_start state argument, and rename patch "pass runstate to vm_prepare_start" to
"check running not RUN_STATE_RUNNING"
* drop patches:
tests/qtest: bootfile per vm
tests/qtest: background migration with suspend
* rename runstate_is_started to runstate_is_live
* move wait_for_suspend in tests
Steve Sistare (12):
cpus: vm_was_suspended
cpus: stop vm in suspended runstate
cpus: check running not RUN_STATE_RUNNING
cpus: vm_resume
migration: propagate suspended runstate
migration: preserve suspended runstate
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
backends/tpm/tpm_emulator.c | 2 +- hw/usb/hcd-ehci.c | 2 +- hw/usb/redirect.c | 2 +- hw/xen/xen-hvm-common.c | 2 +- include/migration/snapshot.h | 7 ++ include/sysemu/runstate.h | 16 ++++ migration/global_state.c | 35 ++++++- migration/migration-hmp-cmds.c | 8 +- migration/migration.c | 15 +-- migration/savevm.c | 23 +++-- qapi/misc.json | 10 +- system/cpus.c | 47 +++++++-- system/runstate.c | 9 ++ system/vl.c | 2 + tests/migration/i386/Makefile | 5 +- tests/migration/i386/a-b-bootblock.S | 50 +++++++++- tests/migration/i386/a-b-bootblock.h | 26 +++-- tests/qtest/migration-helpers.c | 27 ++---- tests/qtest/migration-helpers.h | 11 ++- tests/qtest/migration-test.c | 181 +++++++++++++++++++++++++---------- 20 files changed, 354 insertions(+), 126 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v7 1/12 cpus: vm_was_suspended
Add a state variable to remember if a vm previously transitioned into a suspended state.
--- include/sysemu/runstate.h | 2 ++ system/cpus.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+)
include/sysemu/runstate.h +2 -0
@@ -51,6 +51,8 @@ int vm_prepare_start(bool step_pending);int vm_stop (RunState state);int vm_stop_force_state (RunState state);int vm_shutdown (void ); +void vm_set_suspended (bool suspended); +bool vm_get_suspended (void ); typedef enum WakeupReason { /* Always keep QEMU_WAKEUP_REASON_NONE = 0 */
system/cpus.c +15 -0
@@ -259,6 +259,21 @@ void cpu_interrupt(CPUState *cpu, int mask) } } +/* +* True if the vm was previously suspended, and has not been woken or reset. +*/ +static int vm_was_suspended; + +void vm_set_suspended (bool suspended) +{ + vm_was_suspended = suspended; +} + +bool vm_get_suspended (void ) +{ +return vm_was_suspended; +} +static int do_vm_stop (RunState state,bool send_stop) {int ret =0 ;
Signature · 1 line
1.8.3.1
PATCH v7 2/12 cpus: stop vm in suspended runstate
In reply to Steve SistareCurrently, a vm in the suspended state is not completely stopped. The VCPUs have been paused, but the cpu clock still runs, and runstate notifiers for the transition to stopped have not been called. This causes problems for live migration. Stale cpu timers_state is saved to the migration stream, causing time errors in the guest when it wakes from suspend, and state that would have been modified by runstate notifiers is wrong.
Modify vm_stop to completely stop the vm if the current state is suspended, transition to RUN_STATE_PAUSED, and remember that the machine was suspended. Modify vm_start to restore the suspended state.
This affects all callers of vm_stop and vm_start, notably, the qapi stop and cont commands. For example:
(qemu) info status
VM status: paused (suspended)
(qemu) stop
(qemu) info status
VM status: paused
(qemu) system_wakeup
Error: Unable to wake up: guest is not in suspended state
(qemu) cont
(qemu) info status
VM status: paused (suspended)
(qemu) system_wakeup
(qemu) info status
VM status: running
--- include/sysemu/runstate.h | 5 +++++ qapi/misc.json | 10 ++++++++-- system/cpus.c | 23 +++++++++++++++-------- system/runstate.c | 3 +++ 4 files changed, 31 insertions(+), 10 deletions(-)
include/sysemu/runstate.h +5 -0
@@ -40,6 +40,11 @@ static inline bool shutdown_caused_by_guest(ShutdownCause cause)return cause >=SHUTDOWN_CAUSE_GUEST_SHUTDOWN ; } +static inline bool runstate_is_live (RunState state) +{ +return state ==RUN_STATE_RUNNING || state ==RUN_STATE_SUSPENDED ; +} +void vm_start (void );/**
qapi/misc.json +8 -2
@@ -134,7 +134,7 @@ ## # @stop: # -# Stop all guest VCPU execution. +# Stop all guest VCPU and VM execution. # # Since: 0.14 #
@@ -143,6 +143,9 @@ # the guest remains paused once migration finishes, as if the -S # option was passed on the command line. # +# In the "suspended" state, it will completely stop the VM and +# cause a transition to the "paused" state. (Since 9.0) +# # Example: # # -> { "execute": "stop" }
@@ -153,7 +156,7 @@ ## # @cont: # -# Resume guest VCPU execution. +# Resume guest VCPU and VM execution. # # Since: 0.14 #
@@ -165,6 +168,9 @@ # guest starts once migration finishes, removing the effect of the # -S command line option if it was passed. # +# If the VM was previously suspended, and not been reset or woken, +# this command will transition back to the "suspended" state. (Since 9.0) +# # Example: # # -> { "execute": "cont" }
system/cpus.c +15 -8
@@ -277,11 +277,15 @@ bool vm_get_suspended(void)static int do_vm_stop (RunState state,bool send_stop) {int ret =0 ; +RunState oldstate =runstate_get (); -if (runstate_is_running ()) { +if (runstate_is_live (oldstate)) { + vm_was_suspended = (oldstate ==RUN_STATE_SUSPENDED );runstate_set (state);cpu_disable_ticks (); -pause_all_vcpus (); +if (oldstate ==RUN_STATE_RUNNING ) { +pause_all_vcpus (); + }vm_state_notify (0 , state);if (send_stop) {qapi_event_send_stop ();
@@ -694,11 +698,13 @@ int vm_stop(RunState state)/** * Prepare for (re)starting the VM. -* Returns -1 if the vCPUs are not to be restarted (e.g. if they are already -* running or in case of an error condition), 0 otherwise. +* Returns 0 if the vCPUs should be restarted, -1 on an error condition, +* and 1 otherwise. */ int vm_prepare_start (bool step_pending) { +int ret = vm_was_suspended ?1 :0 ; +RunState state = vm_was_suspended ?RUN_STATE_SUSPENDED :RUN_STATE_RUNNING ;RunState requested;qemu_vmstop_requested (&requested);
@@ -729,9 +735,10 @@ int vm_prepare_start(bool step_pending)qapi_event_send_resume ();cpu_enable_ticks (); -runstate_set (RUN_STATE_RUNNING ); -vm_state_notify (1 ,RUN_STATE_RUNNING ); -return 0 ; +runstate_set (state); +vm_state_notify (1 , state); + vm_was_suspended = false; +return ret; }void vm_start (void )
@@ -745,7 +752,7 @@ void vm_start(void)current state is forgotten forever */ int vm_stop_force_state (RunState state) { -if (runstate_is_running ()) { +if (runstate_is_live (runstate_get ())) {return vm_stop (state); }else {int ret;
system/runstate.c +3 -0
@@ -108,6 +108,7 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_PAUSED, RUN_STATE_POSTMIGRATE }, { RUN_STATE_PAUSED, RUN_STATE_PRELAUNCH }, { RUN_STATE_PAUSED, RUN_STATE_COLO}, + { RUN_STATE_PAUSED, RUN_STATE_SUSPENDED}, { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING }, { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE },
@@ -161,6 +162,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 },
@@ -502,6 +504,7 @@ void qemu_system_reset(ShutdownCause reason)qapi_event_send_reset (shutdown_caused_by_guest (reason), reason); }cpu_synchronize_all_post_reset (); +vm_set_suspended (false); }/*
Signature · 1 line
1.8.3.1
Re: [PATCH V7 02/12] cpus: stop vm in suspended runstate
Hi Steve,
Quoted 47 lines · Steve Sistare
Currently, a vm in the suspended state is not completely stopped. The VCPUs have been paused, but the cpu clock still runs, and runstate notifiers for the transition to stopped have not been called. This causes problems for live migration. Stale cpu
timers_stateis saved to the migration stream, causing time errors in the guest when it wakes from suspend, and state that would have been modified by runstate notifiers is wrong.Modify
vm_stopto completely stop the vm if the current state is suspended, transition toRUN_STATE_PAUSED, and remember that the machine was suspended. Modifyvm_startto restore the suspended state.This affects all callers of
vm_stopandvm_start, notably, the qapi stop and cont commands. For example:(qemu) info status
VM status: paused (suspended)(qemu) stop
(qemu) info status
VM status: paused(qemu)
system_wakeup
Error: Unable to wake up: guest is not in suspended state(qemu) cont
(qemu) info status
VM status: paused (suspended)(qemu)
system_wakeup
(qemu) info status
VM status: runningSuggested-by Peter Xu <[email protected]>Signed-off-by Steve Sistare <[email protected]>Reviewed-by Peter Xu <[email protected]>--- include/sysemu/runstate.h | 5 +++++ qapi/misc.json | 10 ++++++++-- system/cpus.c | 23 +++++++++++++++-------- system/runstate.c | 3 +++ 4 files changed, 31 insertions(+), 10 deletions(-)include/sysemu/runstate.h +0
-0
include/sysemu/runstate.h static inline bool shutdown_caused_by_guest(ShutdownCause cause) · line 46
Quoted 7 lines
include/sysemu/runstate.h +4
-0@@ -40,6 +40,11 @@ static inline bool shutdown_caused_by_guest(ShutdownCause cause)return cause >=SHUTDOWN_CAUSE_GUEST_SHUTDOWN ; } +static inline bool runstate_is_live (RunState state) +{ +return state ==RUN_STATE_RUNNING || state ==RUN_STATE_SUSPENDED ; +}
Not being familiar with (live) migration, from a generic vCPU PoV I don't get what "runstate_is_live" means. Can we add a comment explaining what this helper is for?
Since this is a migration particular case, maybe we can be verbose in vm_resume() and keep runstate_is_live() -- eventually undocumented -- in migration/migration.c.
void vm_resume(RunState state)
{
switch (state) {
case RUN_STATE_RUNNING:
case RUN_STATE_SUSPENDED:
vm_start();
break;
default:
runstate_set(state);
}}
Regards,
Phil.
Re: [PATCH V7 02/12] cpus: stop vm in suspended runstate
Quoted 45 lines · Philippe Mathieu-Daudé
Hi Steve,
Quoted 42 lines · Steve Sistare
Currently, a vm in the suspended state is not completely stopped. The VCPUs have been paused, but the cpu clock still runs, and runstate notifiers for the transition to stopped have not been called. This causes problems for live migration. Stale cpu
timers_stateis saved to the migration stream, causing time errors in the guest when it wakes from suspend, and state that would have been modified by runstate notifiers is wrong.Modify
vm_stopto completely stop the vm if the current state is suspended, transition toRUN_STATE_PAUSED, and remember that the machine was suspended. Modifyvm_startto restore the suspended state.This affects all callers of
vm_stopandvm_start, notably, the qapi stop and cont commands. For example:(qemu) info status
VM status: paused (suspended)(qemu) stop
(qemu) info status
VM status: paused(qemu)
system_wakeup
Error: Unable to wake up: guest is not in suspended state(qemu) cont
(qemu) info status
VM status: paused (suspended)(qemu)
system_wakeup
(qemu) info status
VM status: runningSuggested-by Peter Xu <[email protected]>Signed-off-by Steve Sistare <[email protected]>Reviewed-by Peter Xu <[email protected]>---
include/sysemu/runstate.h| 5 +++++ qapi/misc.json | 10 ++++++++-- system/cpus.c | 23 +++++++++++++++-------- system/runstate.c | 3 +++4 files changed, 31 insertions(+), 10 deletions(-)
Quoted 15 lines
include/sysemu/runstate.h static inline bool shutdown_caused_by_guest(ShutdownCause cause) · line 45
Quoted 11 lines
include/sysemu/runstate.h +3
-0@@ -40,6 +40,11 @@ static inline bool shutdown_caused_by_guest(ShutdownCause cause) return cause >= SHUTDOWN_CAUSE_GUEST_SHUTDOWN; } +static inline bool runstate_is_live(RunState state) +{ + return state == RUN_STATE_RUNNING || state == RUN_STATE_SUSPENDED; +}Not being familiar with (live) migration, from a generic vCPU PoV I don't get what "
runstate_is_live" means. Can we add a comment explaining what this helper is for?
Sure. "live" means the cpu clock is ticking, and the runstate notifiers think we are running. It is everything that is enabled in vm_start except for starting the vcpus.
Quoted 3 lines
Since this is a migration particular case, maybe we can be verbose in
vm_resume()and keeprunstate_is_live()-- eventually undocumented -- inmigration/migration.c.
runstate_is_live is about cpu and vm state, not migration state (the "live" is not live migration), and is used in multiple places in cpus code and elsewhere, so I would like to keep it in runstate.h. It has a specific meaning, and it is useful to search for it to see who handles "liveness", and distinguish it from code that checks the running and suspended states for other reasons.
- Steve
Quoted 11 lines
void
vm_resume(RunState state)
{
switch (state) {
caseRUN_STATE_RUNNING:
caseRUN_STATE_SUSPENDED:
vm_start();
break;
default:
runstate_set(state);
}
}
Re: [PATCH V7 02/12] cpus: stop vm in suspended runstate
Quoted 70 lines · Steven Sistare
Quoted 45 lines · Philippe Mathieu-Daudé
Hi Steve,
Quoted 42 lines · Steve Sistare
Currently, a vm in the suspended state is not completely stopped. The VCPUs have been paused, but the cpu clock still runs, and runstate notifiers for the transition to stopped have not been called. This causes problems for live migration. Stale cpu
timers_stateis saved to the migration stream, causing time errors in the guest when it wakes from suspend, and state that would have been modified by runstate notifiers is wrong.Modify
vm_stopto completely stop the vm if the current state is suspended, transition toRUN_STATE_PAUSED, and remember that the machine was suspended. Modifyvm_startto restore the suspended state.This affects all callers of
vm_stopandvm_start, notably, the qapi stop and cont commands. For example:(qemu) info status
VM status: paused (suspended)(qemu) stop
(qemu) info status
VM status: paused(qemu)
system_wakeup
Error: Unable to wake up: guest is not in suspended state(qemu) cont
(qemu) info status
VM status: paused (suspended)(qemu)
system_wakeup
(qemu) info status
VM status: runningSuggested-by Peter Xu <[email protected]>Signed-off-by Steve Sistare <[email protected]>Reviewed-by Peter Xu <[email protected]>--- include/sysemu/runstate.h | 5 +++++ qapi/misc.json | 10 ++++++++-- system/cpus.c | 23 +++++++++++++++-------- system/runstate.c | 3 +++ 4 files changed, 31 insertions(+), 10 deletions(-)Quoted 15 lines
include/sysemu/runstate.h static inline bool shutdown_caused_by_guest(ShutdownCause cause) · line 45
Quoted 11 lines
include/sysemu/runstate.h +3
-0@@ -40,6 +40,11 @@ static inline bool shutdown_caused_by_guest(ShutdownCause cause) return cause >= SHUTDOWN_CAUSE_GUEST_SHUTDOWN; } +static inline bool runstate_is_live(RunState state) +{ + return state == RUN_STATE_RUNNING || state == RUN_STATE_SUSPENDED; +}Not being familiar with (live) migration, from a generic vCPU PoV I don't get what "
runstate_is_live" means. Can we add a comment explaining what this helper is for?Sure. "live" means the cpu clock is ticking, and the runstate notifiers think we are running. It is everything that is enabled in
vm_startexcept for starting the vcpus.Quoted 3 lines
Since this is a migration particular case, maybe we can be verbose in
vm_resume()and keeprunstate_is_live()-- eventually undocumented -- inmigration/migration.c.
Quoted 5 lines
runstate_is_liveis about cpu and vm state, not migration state (the "live" is not live migration), and is used in multiple places in cpus code and elsewhere, so I would like to keep it inrunstate.h. It has a specific meaning, and it is useful to search for it to see who handles "liveness", and distinguish it from code that checks the running and suspended states for other reasons.
OK then, no objection, but please add a comment describing.
Thanks,
Phil.
Re: [PATCH V7 02/12] cpus: stop vm in suspended runstate
Quoted 64 lines · Philippe Mathieu-Daudé
Quoted 63 lines · Steven Sistare
Quoted 61 lines · Philippe Mathieu-Daudé
Hi Steve,
Quoted 47 lines · Steve Sistare
Currently, a vm in the suspended state is not completely stopped. The VCPUs have been paused, but the cpu clock still runs, and runstate notifiers for the transition to stopped have not been called. This causes problems for live migration. Stale cpu
timers_stateis saved to the migration stream, causing time errors in the guest when it wakes from suspend, and state that would have been modified by runstate notifiers is wrong.Modify
vm_stopto completely stop the vm if the current state is suspended, transition toRUN_STATE_PAUSED, and remember that the machine was suspended. Modifyvm_startto restore the suspended state.This affects all callers of
vm_stopandvm_start, notably, the qapi stop and cont commands. For example:(qemu) info status
VM status: paused (suspended)(qemu) stop
(qemu) info status
VM status: paused(qemu)
system_wakeup
Error: Unable to wake up: guest is not in suspended state(qemu) cont
(qemu) info status
VM status: paused (suspended)(qemu)
system_wakeup
(qemu) info status
VM status: runningSuggested-by Peter Xu <[email protected]>Signed-off-by Steve Sistare <[email protected]>Reviewed-by Peter Xu <[email protected]>---
include/sysemu/runstate.h| 5 +++++ qapi/misc.json | 10 ++++++++-- system/cpus.c | 23 +++++++++++++++-------- system/runstate.c | 3 +++4 files changed, 31 insertions(+), 10 deletions(-)include/sysemu/runstate.h +0
-0include/sysemu/runstate.h static inline bool · line 46
Quoted 7 lines
include/sysemu/runstate.h +3
-0@@ -40,6 +40,11 @@ static inline bool shutdown_caused_by_guest(ShutdownCause cause) return cause >= SHUTDOWN_CAUSE_GUEST_SHUTDOWN; } +static inline bool runstate_is_live(RunState state) +{ + return state == RUN_STATE_RUNNING || state == RUN_STATE_SUSPENDED; +}Not being familiar with (live) migration, from a generic vCPU PoV I don't get what "
runstate_is_live" means. Can we add a comment explaining what this helper is for?
Quoted 3 lines
Quoted 3 lines
Sure. "live" means the cpu clock is ticking, and the runstate notifiers think we are running. It is everything that is enabled in
vm_startexcept for starting the vcpus.
What about runstate_is_vcpu_clock_ticking() then?
Quoted 15 lines
Quoted 9 lines
Quoted 3 lines
Since this is a migration particular case, maybe we can be verbose in
vm_resume()and keeprunstate_is_live()-- eventually undocumented -- inmigration/migration.c.
runstate_is_liveis about cpu and vm state, not migration state (the "live" is not live migration), and is used in multiple places in cpus code and elsewhere, so I would like to keep it in runstate.h. It has a specific meaning, and it is useful to search for it to see who handles "liveness", and distinguish it from code that checks the running and suspended states for other reasons.OK then, no objection, but please add a comment describing.
Thanks,
Phil.
Re: [PATCH V7 02/12] cpus: stop vm in suspended runstate
Quoted 1 line · Philippe Mathieu-Daudé
What about
runstate_is_vcpu_clock_ticking()then?
The problem is vCPU clock ticks can only be one part of "VM is running" state (no matter whether vCPUs are running or not). I'm even thinking whether cpu_enable_ticks() should one day be put into a vm state change notifier instead to be even clearer that it's not special (I hope I didn't overlook its specialty..).
Thanks,
Signature · 1 line
Peter Xu
Re: [PATCH V7 02/12] cpus: stop vm in suspended runstate
In reply to Steve SistareHi Markus, Eric, any comment about this change in stop/cont behavior before it gets pulled? There is no change since V6.
- Steve
Quoted 189 lines · Steve Sistare
Currently, a vm in the suspended state is not completely stopped. The VCPUs have been paused, but the cpu clock still runs, and runstate notifiers for the transition to stopped have not been called. This causes problems for live migration. Stale cpu
timers_stateis saved to the migration stream, causing time errors in the guest when it wakes from suspend, and state that would have been modified by runstate notifiers is wrong.Modify
vm_stopto completely stop the vm if the current state is suspended, transition toRUN_STATE_PAUSED, and remember that the machine was suspended. Modifyvm_startto restore the suspended state.This affects all callers of
vm_stopandvm_start, notably, the qapi stop and cont commands. For example:(qemu) info status
VM status: paused (suspended)(qemu) stop
(qemu) info status
VM status: paused(qemu)
system_wakeup
Error: Unable to wake up: guest is not in suspended state(qemu) cont
(qemu) info status
VM status: paused (suspended)(qemu)
system_wakeup
(qemu) info status
VM status: runningSuggested-by Peter Xu <[email protected]>Signed-off-by Steve Sistare <[email protected]>Reviewed-by Peter Xu <[email protected]>--- include/sysemu/runstate.h | 5 +++++ qapi/misc.json | 10 ++++++++-- system/cpus.c | 23 +++++++++++++++-------- system/runstate.c | 3 +++ 4 files changed, 31 insertions(+), 10 deletions(-)include/sysemu/runstate.h +5
-0@@ -40,6 +40,11 @@ static inline bool shutdown_caused_by_guest(ShutdownCause cause)return cause >=SHUTDOWN_CAUSE_GUEST_SHUTDOWN ; } +static inline bool runstate_is_live (RunState state) +{ +return state ==RUN_STATE_RUNNING || state ==RUN_STATE_SUSPENDED ; +} +void vm_start (void );/** qapi/misc.json +8
-2@@ -134,7 +134,7 @@ ## # @stop: # -# Stop all guest VCPU execution. +# Stop all guest VCPU and VM execution. # # Since: 0.14 #@@ -143,6 +143,9 @@ # the guest remains paused once migration finishes, as if the -S # option was passed on the command line. # +# In the "suspended" state, it will completely stop the VM and +# cause a transition to the "paused" state. (Since 9.0) +# # Example: # # -> { "execute": "stop" }@@ -153,7 +156,7 @@ ## # @cont: # -# Resume guest VCPU execution. +# Resume guest VCPU and VM execution. # # Since: 0.14 #@@ -165,6 +168,9 @@ # guest starts once migration finishes, removing the effect of the # -S command line option if it was passed. # +# If the VM was previously suspended, and not been reset or woken, +# this command will transition back to the "suspended" state. (Since 9.0) +# # Example: # # -> { "execute": "cont" }system/cpus.c +15
-8@@ -277,11 +277,15 @@ bool vm_get_suspended(void)static int do_vm_stop (RunState state,bool send_stop) {int ret =0 ; +RunState oldstate =runstate_get (); -if (runstate_is_running ()) { +if (runstate_is_live (oldstate)) { + vm_was_suspended = (oldstate ==RUN_STATE_SUSPENDED );runstate_set (state);cpu_disable_ticks (); -pause_all_vcpus (); +if (oldstate ==RUN_STATE_RUNNING ) { +pause_all_vcpus (); + }vm_state_notify (0 , state);if (send_stop) {qapi_event_send_stop ();@@ -694,11 +698,13 @@ int vm_stop(RunState state)/** * Prepare for (re)starting the VM. -* Returns -1 if the vCPUs are not to be restarted (e.g. if they are already -* running or in case of an error condition), 0 otherwise. +* Returns 0 if the vCPUs should be restarted, -1 on an error condition, +* and 1 otherwise. */ int vm_prepare_start (bool step_pending) { +int ret = vm_was_suspended ?1 :0 ; +RunState state = vm_was_suspended ?RUN_STATE_SUSPENDED :RUN_STATE_RUNNING ;RunState requested;qemu_vmstop_requested (&requested);@@ -729,9 +735,10 @@ int vm_prepare_start(bool step_pending)qapi_event_send_resume ();cpu_enable_ticks (); -runstate_set (RUN_STATE_RUNNING ); -vm_state_notify (1 ,RUN_STATE_RUNNING ); -return 0 ; +runstate_set (state); +vm_state_notify (1 , state); + vm_was_suspended = false; +return ret; }void vm_start (void )@@ -745,7 +752,7 @@ void vm_start(void)current state is forgotten forever */ int vm_stop_force_state (RunState state) { -if (runstate_is_running ()) { +if (runstate_is_live (runstate_get ())) {return vm_stop (state); }else {int ret;system/runstate.c +3
-0@@ -108,6 +108,7 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_PAUSED, RUN_STATE_POSTMIGRATE }, { RUN_STATE_PAUSED, RUN_STATE_PRELAUNCH }, { RUN_STATE_PAUSED, RUN_STATE_COLO}, + { RUN_STATE_PAUSED, RUN_STATE_SUSPENDED}, { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING }, { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE },@@ -161,6 +162,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 },@@ -502,6 +504,7 @@ void qemu_system_reset(ShutdownCause reason)qapi_event_send_reset (shutdown_caused_by_guest (reason), reason); }cpu_synchronize_all_post_reset (); +vm_set_suspended (false); }/*
PATCH v7 3/12 cpus: check running not RUN_STATE_RUNNING
In reply to Steve SistareWhen a vm transitions from running to suspended, runstate notifiers are not called, so the notifiers still think the vm is running. Hence, when we call vm_start to restore the suspended state, we call vm_state_notify with running=1. However, some notifiers check for RUN_STATE_RUNNING. They must check the running boolean instead.
No functional change.
--- backends/tpm/tpm_emulator.c | 2 +- hw/usb/hcd-ehci.c | 2 +- hw/usb/redirect.c | 2 +- hw/xen/xen-hvm-common.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
backends/tpm/tpm_emulator.c +1 -1
@@ -904,7 +904,7 @@ static void tpm_emulator_vm_state_change(void *opaque, bool running,trace_tpm_emulator_vm_state_change (running, state); -if (!running || state !=RUN_STATE_RUNNING || !tpm_emu->relock_storage) { +if (!running || !tpm_emu->relock_storage) {return ; }
hw/usb/hcd-ehci.c +1 -1
@@ -2451,7 +2451,7 @@ static void usb_ehci_vm_state_change(void *opaque, bool running, RunState state)* USB-devices which have async handled packages have a packet in the * ep queue to match the completion with. */ -if (state ==RUN_STATE_RUNNING ) { +if (running) {ehci_advance_async_state (ehci); }
hw/usb/redirect.c +1 -1
@@ -1403,7 +1403,7 @@ static void usbredir_vm_state_change(void *priv, bool running, RunState state) {USBRedirDevice *dev = priv; -if (state ==RUN_STATE_RUNNING && dev->parser !=NULL ) { +if (running && dev->parser !=NULL ) {usbredirparser_do_write (dev->parser);/* Flush any pending writes */ } }
hw/xen/xen-hvm-common.c +1 -1
@@ -623,7 +623,7 @@ void xen_hvm_change_state_handler(void *opaque, bool running,xen_set_ioreq_server_state (xen_domid, state->ioservid, - (rstate ==RUN_STATE_RUNNING )); + running); }void xen_exit_notifier (Notifier *n,void *data)
Signature · 1 line
1.8.3.1
PATCH v7 4/12 cpus: vm_resume
In reply to Steve SistareDefine the vm_resume helper, for use in subsequent patches.
--- include/sysemu/runstate.h | 9 +++++++++ system/cpus.c | 9 +++++++++ 2 files changed, 18 insertions(+)
include/sysemu/runstate.h +9 -0
@@ -53,6 +53,15 @@ void vm_start(void);* @step_pending: whether any of the CPUs is about to be single-stepped by gdb */ int vm_prepare_start (bool step_pending); + +/** +* vm_resume: If @state is a live state, start the vm and set the state, +* else just set the state. +* +* @state: the state to restore +*/ +void vm_resume (RunState state); +int vm_stop (RunState state);int vm_stop_force_state (RunState state);int vm_shutdown (void );
system/cpus.c +9 -0
@@ -748,6 +748,15 @@ void vm_start(void) } } +void vm_resume (RunState state) +{ +if (runstate_is_live (state)) { +vm_start (); + }else { +runstate_set (state); + } +} +/* does a state transition even if the VM is already stopped, current state is forgotten forever */ int vm_stop_force_state (RunState state)
Signature · 1 line
1.8.3.1
PATCH v7 5/12 migration: propagate suspended runstate
In reply to Steve SistareIf the outgoing machine was previously suspended, propagate that to the incoming side via global_state, so a subsequent vm_start restores the suspended state. To maintain backward and forward compatibility, reclaim some space from the runstate member.
--- migration/global_state.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)
migration/global_state.c +33 -2
@@ -22,7 +22,16 @@typedef struct {uint32_t size; -uint8_t runstate[100 ]; + +/* +* runstate was 100 bytes, zero padded, but we trimmed it to add a +* few fields and maintain backwards compatibility. +*/ +uint8_t runstate[32 ]; +uint8_t has_vm_was_suspended; +uint8_t vm_was_suspended; +uint8_t unused[66 ]; +RunState state;bool received; }GlobalState ;
@@ -35,6 +44,10 @@ static void global_state_do_store(RunState state)assert (strlen (state_str) <sizeof (global_state.runstate));strpadcpy ((char *)global_state.runstate,sizeof (global_state.runstate), state_str,'\0' ); + global_state.has_vm_was_suspended = true; + global_state.vm_was_suspended =vm_get_suspended (); + +memset (global_state.unused,0 ,sizeof (global_state.unused)); }void global_state_store (void )
@@ -68,6 +81,12 @@ static bool global_state_needed(void *opaque)return true; } +/* If the suspended state must be remembered, it is needed */ + +if (vm_get_suspended ()) { +return true; + } +/* If state is running or paused, it is not needed */ if (strcmp(runstate, "running") == 0 ||
@@ -85,6 +104,7 @@ static int global_state_post_load(void *opaque, int version_id)Error *local_err =NULL ;int r;char *runstate = (char *)s->runstate; +bool vm_was_suspended = s->has_vm_was_suspended && s->vm_was_suspended; s->received = true;trace_migrate_global_state_post_load (runstate);
@@ -93,7 +113,7 @@ static int global_state_post_load(void *opaque, int version_id) sizeof(s->runstate)) == sizeof(s->runstate)) {/* * This condition should never happen during migration, because -* all runstate names are shorter than 100 bytes (the size of +* all runstate names are shorter than 32 bytes (the size of * s->runstate). However, a malicious stream could overflow * the qapi_enum_parse() call, so we force the last character * to a NUL byte.
@@ -110,6 +130,14 @@ static int global_state_post_load(void *opaque, int version_id) } s->state = r; +/* +* global_state is saved on the outgoing side before forcing a stopped +* state, so it may have saved state=suspended and vm_was_suspended=0. +* Now we are in a paused state, and when we later call vm_start, it must +* restore the suspended state, so we must set vm_was_suspended=1 here. +*/ +vm_set_suspended (vm_was_suspended || r ==RUN_STATE_SUSPENDED ); +return 0 ; }
@@ -134,6 +162,9 @@ static const VMStateDescription vmstate_globalstate = { .fields = (VMStateField[]) {VMSTATE_UINT32 (size, GlobalState),VMSTATE_BUFFER (runstate, GlobalState), +VMSTATE_UINT8 (has_vm_was_suspended, GlobalState), +VMSTATE_UINT8 (vm_was_suspended, GlobalState), +VMSTATE_BUFFER (unused, GlobalState),VMSTATE_END_OF_LIST () }, };
Signature · 1 line
1.8.3.1
Re: [PATCH V7 05/12] migration: propagate suspended runstate
Quoted 57 lines · Steve Sistare
If the outgoing machine was previously suspended, propagate that to the incoming side via
global_state, so a subsequentvm_startrestores the suspended state. To maintain backward and forward compatibility, reclaim some space from the runstate member.Signed-off-by Steve Sistare <[email protected]>--- migration/global_state.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)migration/global_state.c +20
-1@@ -22,7 +22,16 @@typedef struct {uint32_t size; -uint8_t runstate[100 ]; + +/* +* runstate was 100 bytes, zero padded, but we trimmed it to add a +* few fields and maintain backwards compatibility. +*/ +uint8_t runstate[32 ]; +uint8_t has_vm_was_suspended; +uint8_t vm_was_suspended; +uint8_t unused[66 ]; +RunState state;bool received; }GlobalState ;@@ -35,6 +44,10 @@ static void global_state_do_store(RunState state)assert (strlen (state_str) <sizeof (global_state.runstate));strpadcpy ((char *)global_state.runstate,sizeof (global_state.runstate), state_str,'\0' ); + global_state.has_vm_was_suspended = true; + global_state.vm_was_suspended =vm_get_suspended (); + +memset (global_state.unused,0 ,sizeof (global_state.unused)); }void global_state_store (void )@@ -68,6 +81,12 @@ static bool global_state_needed(void *opaque)return true; } +/* If the suspended state must be remembered, it is needed */ + +if (vm_get_suspended ()) { +return true; + } +/* If state is running or paused, it is not needed */ if (strcmp(runstate, "running") == 0 ||
migration/global_state.c static int global_state_post_load(void *opaque, int version_id) · line 107
Quoted 4 lines
migration/global_state.c +1
-0@@ -85,6 +104,7 @@ static int global_state_post_load(void *opaque, int version_id)Error *local_err =NULL ;int r;char *runstate = (char *)s->runstate; +bool vm_was_suspended = s->has_vm_was_suspended && s->vm_was_suspended;
Why do you need has_vm_was_suspended? If they're always read like this, then one flag should do, no?
Quoted 37 lines
migration/global_state.c +12
-1s->received = true;trace_migrate_global_state_post_load (runstate);@@ -93,7 +113,7 @@ static int global_state_post_load(void *opaque, int version_id) sizeof(s->runstate)) == sizeof(s->runstate)) {/* * This condition should never happen during migration, because -* all runstate names are shorter than 100 bytes (the size of +* all runstate names are shorter than 32 bytes (the size of * s->runstate). However, a malicious stream could overflow * the qapi_enum_parse() call, so we force the last character * to a NUL byte. @@ -110,6 +130,14 @@ static int global_state_post_load(void *opaque, int version_id) } s->state = r; +/* +* global_state is saved on the outgoing side before forcing a stopped +* state, so it may have saved state=suspended and vm_was_suspended=0. +* Now we are in a paused state, and when we later call vm_start, it must +* restore the suspended state, so we must set vm_was_suspended=1 here. +*/ +vm_set_suspended (vm_was_suspended || r ==RUN_STATE_SUSPENDED ); +return 0 ; }@@ -134,6 +162,9 @@ static const VMStateDescription vmstate_globalstate = { .fields = (VMStateField[]) {VMSTATE_UINT32 (size, GlobalState),VMSTATE_BUFFER (runstate, GlobalState), +VMSTATE_UINT8 (has_vm_was_suspended, GlobalState), +VMSTATE_UINT8 (vm_was_suspended, GlobalState), +VMSTATE_BUFFER (unused, GlobalState),VMSTATE_END_OF_LIST () }, };
Re: [PATCH V7 05/12] migration: propagate suspended runstate
Quoted 57 lines · Fabiano Rosas
Quoted 55 lines · Steve Sistare
If the outgoing machine was previously suspended, propagate that to the incoming side via
global_state, so a subsequentvm_startrestores the suspended state. To maintain backward and forward compatibility, reclaim some space from the runstate member.Signed-off-by Steve Sistare <[email protected]>--- migration/global_state.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)migration/global_state.c +20
-1@@ -22,7 +22,16 @@typedef struct {uint32_t size; -uint8_t runstate[100 ]; + +/* +* runstate was 100 bytes, zero padded, but we trimmed it to add a +* few fields and maintain backwards compatibility. +*/ +uint8_t runstate[32 ]; +uint8_t has_vm_was_suspended; +uint8_t vm_was_suspended; +uint8_t unused[66 ]; +RunState state;bool received; }GlobalState ;@@ -35,6 +44,10 @@ static void global_state_do_store(RunState state)assert (strlen (state_str) <sizeof (global_state.runstate));strpadcpy ((char *)global_state.runstate,sizeof (global_state.runstate), state_str,'\0' ); + global_state.has_vm_was_suspended = true; + global_state.vm_was_suspended =vm_get_suspended (); + +memset (global_state.unused,0 ,sizeof (global_state.unused)); }void global_state_store (void )@@ -68,6 +81,12 @@ static bool global_state_needed(void *opaque)return true; } +/* If the suspended state must be remembered, it is needed */ + +if (vm_get_suspended ()) { +return true; + } +/* If state is running or paused, it is not needed */
Quoted 9 lines
migration/global_state.c static int global_state_post_load(void *opaque, int version_id) · line 107
Quoted 6 lines
migration/global_state.c +1
-0if (strcmp(runstate, "running") == 0 ||@@ -85,6 +104,7 @@ static int global_state_post_load(void *opaque, int version_id)Error *local_err =NULL ;int r;char *runstate = (char *)s->runstate; +bool vm_was_suspended = s->has_vm_was_suspended && s->vm_was_suspended;Why do you need
has_vm_was_suspended? If they're always read like this, then one flag should do, no?
has_vm_was_suspended=0 means a legacy qemu. Currently the dest has no reason to care, and we treat that as a vm_was_suspended=0 case, but I want to keep that field in case we ever need to know. But you are correct that this line can simply be:
bool vm_was_suspended = s->vm_was_suspended;
- Steve
Quoted 36 lines
Quoted 36 lines
migration/global_state.c +12
-1s->received = true;trace_migrate_global_state_post_load (runstate);@@ -93,7 +113,7 @@ static int global_state_post_load(void *opaque, int version_id) sizeof(s->runstate)) == sizeof(s->runstate)) {/* * This condition should never happen during migration, because -* all runstate names are shorter than 100 bytes (the size of +* all runstate names are shorter than 32 bytes (the size of * s->runstate). However, a malicious stream could overflow * the qapi_enum_parse() call, so we force the last character * to a NUL byte. @@ -110,6 +130,14 @@ static int global_state_post_load(void *opaque, int version_id) } s->state = r; +/* +* global_state is saved on the outgoing side before forcing a stopped +* state, so it may have saved state=suspended and vm_was_suspended=0. +* Now we are in a paused state, and when we later call vm_start, it must +* restore the suspended state, so we must set vm_was_suspended=1 here. +*/ +vm_set_suspended (vm_was_suspended || r ==RUN_STATE_SUSPENDED ); +return 0 ; }@@ -134,6 +162,9 @@ static const VMStateDescription vmstate_globalstate = { .fields = (VMStateField[]) {VMSTATE_UINT32 (size, GlobalState),VMSTATE_BUFFER (runstate, GlobalState), +VMSTATE_UINT8 (has_vm_was_suspended, GlobalState), +VMSTATE_UINT8 (vm_was_suspended, GlobalState), +VMSTATE_BUFFER (unused, GlobalState),VMSTATE_END_OF_LIST () }, };
Re: [PATCH V7 05/12] migration: propagate suspended runstate
In reply to Steve SistareQuoted 6 lines · Steve Sistare
If the outgoing machine was previously suspended, propagate that to the incoming side via
global_state, so a subsequentvm_startrestores the suspended state. To maintain backward and forward compatibility, reclaim some space from the runstate member.Signed-off-by Steve Sistare <[email protected]>
One nitpick below.
Quoted 38 lines
--- migration/global_state.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)migration/global_state.c +14
-1@@ -22,7 +22,16 @@typedef struct {uint32_t size; -uint8_t runstate[100 ]; + +/* +* runstate was 100 bytes, zero padded, but we trimmed it to add a +* few fields and maintain backwards compatibility. +*/ +uint8_t runstate[32 ]; +uint8_t has_vm_was_suspended; +uint8_t vm_was_suspended; +uint8_t unused[66 ]; +RunState state;bool received; }GlobalState ;@@ -35,6 +44,10 @@ static void global_state_do_store(RunState state)assert (strlen (state_str) <sizeof (global_state.runstate));strpadcpy ((char *)global_state.runstate,sizeof (global_state.runstate), state_str,'\0' ); + global_state.has_vm_was_suspended = true; + global_state.vm_was_suspended =vm_get_suspended (); + +memset (global_state.unused,0 ,sizeof (global_state.unused)); }void global_state_store (void )
migration/global_state.c static bool global_state_needed(void *opaque) · line 88
Quoted 8 lines
migration/global_state.c +5
-0@@ -68,6 +81,12 @@ static bool global_state_needed(void *opaque)return true; } +/* If the suspended state must be remembered, it is needed */ + +if (vm_get_suspended ()) { +return true; + }
Can we drop this section?
I felt unsafe when QEMU can overwrite the option even if user explicitly specified store-global-state=off but we still send this.. Ideally I think it's better if it's as simple as:
static bool global_state_needed(void *opaque)
{
return migrate_get_current()->store_global_state;
}I don't think we can remove the old trick due to compatibility reasons, but maybe nice to not add new ones to make this section more unpredictable in the migration stream?
IMHO it shouldn't matter in reality for the current use case even dropping it, as I don't expect any non-Xen QEMU VMs migrates without having the option turned on (store-global-state=on) after QEMU 2.4.
Thanks,
Signature · 1 line
Peter Xu
Re: [PATCH V7 05/12] migration: propagate suspended runstate
Quoted 61 lines · Peter Xu
Quoted 6 lines · Steve Sistare
If the outgoing machine was previously suspended, propagate that to the incoming side via
global_state, so a subsequentvm_startrestores the suspended state. To maintain backward and forward compatibility, reclaim some space from the runstate member.Signed-off-by Steve Sistare <[email protected]>Reviewed-by Peter Xu <[email protected]>One nitpick below.
Quoted 38 lines
--- migration/global_state.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)migration/global_state.c +14
-1@@ -22,7 +22,16 @@typedef struct {uint32_t size; -uint8_t runstate[100 ]; + +/* +* runstate was 100 bytes, zero padded, but we trimmed it to add a +* few fields and maintain backwards compatibility. +*/ +uint8_t runstate[32 ]; +uint8_t has_vm_was_suspended; +uint8_t vm_was_suspended; +uint8_t unused[66 ]; +RunState state;bool received; }GlobalState ;@@ -35,6 +44,10 @@ static void global_state_do_store(RunState state)assert (strlen (state_str) <sizeof (global_state.runstate));strpadcpy ((char *)global_state.runstate,sizeof (global_state.runstate), state_str,'\0' ); + global_state.has_vm_was_suspended = true; + global_state.vm_was_suspended =vm_get_suspended (); + +memset (global_state.unused,0 ,sizeof (global_state.unused)); }void global_state_store (void )migration/global_state.c static bool global_state_needed(void *opaque) · line 88
Quoted 8 lines
migration/global_state.c +5
-0@@ -68,6 +81,12 @@ static bool global_state_needed(void *opaque)return true; } +/* If the suspended state must be remembered, it is needed */ + +if (vm_get_suspended ()) { +return true; + }Can we drop this section?
Quoted 8 lines
I felt unsafe when QEMU can overwrite the option even if user explicitly specified store-global-state=off but we still send this.. Ideally I think it's better if it's as simple as:
static bool
global_state_needed(void *opaque){ return migrate_get_current()->store_global_state; }
I agree, I also did not see the point of dropping global_state for some states. I will simplify it to this.
- Steve
Quoted 10 lines
I don't think we can remove the old trick due to compatibility reasons, but maybe nice to not add new ones to make this section more unpredictable in the migration stream?
IMHO it shouldn't matter in reality for the current use case even dropping it, as I don't expect any non-Xen QEMU VMs migrates without having the option turned on (store-global-state=on) after QEMU 2.4.
Thanks,
PATCH v7 6/12 migration: preserve suspended runstate
In reply to Steve SistareA 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 cause 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, delete the call to qemu_system_wakeup_request(). Now that vm_stop completely stops a vm in the suspended state (from the preceding patches), the existing call to vm_stop_force_state is sufficient to correctly migrate all vmstate.
On the incoming side, call vm_start if the pre-migration state was running or suspended. For the latter, vm_start correctly restores the suspended state, and a future system_wakeup monitor request will cause the vm to resume running.
--- migration/migration.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
migration/migration.c +3 -5
@@ -604,7 +604,7 @@ static void process_incoming_migration_bh(void *opaque)*/ if (!migrate_late_block_activate () || (autostart && (!global_state_received () || -global_state_get_runstate () ==RUN_STATE_RUNNING ))) { +runstate_is_live (global_state_get_runstate ())))) {/* Make sure all file formats throw away their mutable metadata. * If we get an error here, just don't restart the VM yet. */ bdrv_activate_all (&local_err);
@@ -628,7 +628,7 @@ static void process_incoming_migration_bh(void *opaque)dirty_bitmap_mig_before_vm_start ();if (!global_state_received () || -global_state_get_runstate () ==RUN_STATE_RUNNING ) { +runstate_is_live (global_state_get_runstate ())) {if (autostart) {vm_start (); }else {
@@ -2416,7 +2416,6 @@ static int postcopy_start(MigrationState *ms, Error **errp)migration_downtime_start (ms); -qemu_system_wakeup_request (QEMU_WAKEUP_REASON_OTHER ,NULL );global_state_store (); ret =migration_stop_vm (RUN_STATE_FINISH_MIGRATE );if (ret <0 ) {
@@ -2615,7 +2614,6 @@ static int migration_completion_precopy(MigrationState *s,qemu_mutex_lock_iothread ();migration_downtime_start (s); -qemu_system_wakeup_request (QEMU_WAKEUP_REASON_OTHER ,NULL ); s->vm_old_state =runstate_get ();global_state_store ();
@@ -3136,7 +3134,7 @@ static void migration_iteration_finish(MigrationState *s)case MIGRATION_STATUS_FAILED :case MIGRATION_STATUS_CANCELLED :case MIGRATION_STATUS_CANCELLING : -if (s->vm_old_state ==RUN_STATE_RUNNING ) { +if (runstate_is_live (s->vm_old_state)) {if (!runstate_check (RUN_STATE_SHUTDOWN )) {vm_start (); }
Signature · 1 line
1.8.3.1
PATCH v7 7/12 migration: preserve suspended for snapshot
In reply to Steve SistareRestoring a snapshot can break a suspended guest. Snapshots suffer from the same suspended-state issues that affect live migration, plus they must handle an additional problematic scenario, which is that a running vm must remain running if it loads a suspended snapshot.
To save, the existing vm_stop call now completely stops the suspended state. Finish with vm_resume to leave the vm in the state it had prior to the save, correctly restoring the suspended state.
To load, if the snapshot is not suspended, then vm_stop + vm_resume correctly handles all states, and leaves the vm in the state it had prior to the load. However, if the snapshot is suspended, restoration is trickier. First, call vm_resume to restore the state to suspended so the current state matches the saved state. Then, if the pre-load state is running, call wakeup to resume running.
Prior to these changes, the vm_stop to RUN_STATE_SAVE_VM and RUN_STATE_RESTORE_VM did not change runstate if the current state was suspended, but now it does, so allow these transitions.
--- include/migration/snapshot.h | 7 +++++++ migration/migration-hmp-cmds.c | 8 +++++--- migration/savevm.c | 23 +++++++++++++---------- system/runstate.c | 5 +++++ system/vl.c | 2 ++ 5 files changed, 32 insertions(+), 13 deletions(-)
include/migration/snapshot.h +7 -0
@@ -16,6 +16,7 @@#define QEMU_MIGRATION_SNAPSHOT_H #include "qapi/qapi-builtin-types.h" +#include "qapi/qapi-types-run-state.h" /** * save_snapshot: Save an internal snapshot.
@@ -61,4 +62,10 @@ bool delete_snapshot(const char *name, bool has_devices, strList *devices, Error **errp); +/** +* load_snapshot_resume: Restore runstate after loading snapshot. +* @state: state to restore +*/ +void load_snapshot_resume (RunState state); +#endif
migration/migration-hmp-cmds.c +5 -3
@@ -399,15 +399,17 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)void hmp_loadvm (Monitor *mon,const QDict *qdict) { -int saved_vm_running =runstate_is_running (); +RunState saved_state =runstate_get (); +const char *name =qdict_get_str (qdict,"name" );Error *err =NULL ;vm_stop (RUN_STATE_RESTORE_VM ); -if (load_snapshot (name,NULL , false,NULL , &err) && saved_vm_running) { -vm_start (); +if (load_snapshot (name,NULL , false,NULL , &err)) { +load_snapshot_resume (saved_state); } +hmp_handle_error (mon, err); }
migration/savevm.c +13 -10
@@ -3046,7 +3046,7 @@ bool save_snapshot(const char *name, bool overwrite, const char *vmstate,QEMUSnapshotInfo sn1, *sn = &sn1;int ret =-1 , ret2;QEMUFile *f; -int saved_vm_running; +RunState saved_state =runstate_get ();uint64_t vm_state_size;g_autoptr (GDateTime) now =g_date_time_new_now_local ();AioContext *aio_context;
@@ -3094,8 +3094,6 @@ bool save_snapshot(const char *name, bool overwrite, const char *vmstate, } aio_context =bdrv_get_aio_context (bs); - saved_vm_running =runstate_is_running (); -global_state_store ();vm_stop (RUN_STATE_SAVE_VM );
@@ -3163,9 +3161,7 @@ bool save_snapshot(const char *name, bool overwrite, const char *vmstate,bdrv_drain_all_end (); -if (saved_vm_running) { -vm_start (); - } +vm_resume (saved_state);return ret ==0 ; }
@@ -3339,6 +3335,14 @@ err_drain:return false; } +void load_snapshot_resume (RunState state) +{ +vm_resume (state); +if (state ==RUN_STATE_RUNNING &&runstate_get () ==RUN_STATE_SUSPENDED ) { +qemu_system_wakeup_request (QEMU_WAKEUP_REASON_OTHER , &error_abort); + } +} +bool delete_snapshot (const char *name,bool has_devices,strList *devices,Error **errp) {
@@ -3403,16 +3407,15 @@ static void snapshot_load_job_bh(void *opaque) {Job *job = opaque;SnapshotJob *s =container_of (job, SnapshotJob, common); -int orig_vm_running; +RunState orig_state =runstate_get ();job_progress_set_remaining (&s->common,1 ); - orig_vm_running =runstate_is_running ();vm_stop (RUN_STATE_RESTORE_VM ); s->ret =load_snapshot (s->tag, s->vmstate, true, s->devices, s->errp); -if (s->ret && orig_vm_running) { -vm_start (); +if (s->ret) { +load_snapshot_resume (orig_state); }job_progress_update (&s->common,1 );
system/runstate.c +5 -0
@@ -77,6 +77,7 @@ typedef struct {static const RunStateTransition runstate_transitions_def[] = { {RUN_STATE_PRELAUNCH ,RUN_STATE_INMIGRATE }, + {RUN_STATE_PRELAUNCH ,RUN_STATE_SUSPENDED }, {RUN_STATE_DEBUG ,RUN_STATE_RUNNING }, {RUN_STATE_DEBUG ,RUN_STATE_FINISH_MIGRATE },
@@ -132,6 +133,7 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING }, { RUN_STATE_RESTORE_VM, RUN_STATE_PRELAUNCH }, + { RUN_STATE_RESTORE_VM, RUN_STATE_SUSPENDED }, { RUN_STATE_COLO, RUN_STATE_RUNNING }, { RUN_STATE_COLO, RUN_STATE_PRELAUNCH },
@@ -150,6 +152,7 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_RUNNING, RUN_STATE_COLO}, { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING }, + { RUN_STATE_SAVE_VM, RUN_STATE_SUSPENDED }, { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED }, { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE },
@@ -163,6 +166,8 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_SUSPENDED, RUN_STATE_PRELAUNCH }, { RUN_STATE_SUSPENDED, RUN_STATE_COLO}, { RUN_STATE_SUSPENDED, RUN_STATE_PAUSED}, + { RUN_STATE_SUSPENDED, RUN_STATE_SAVE_VM }, + { RUN_STATE_SUSPENDED, RUN_STATE_RESTORE_VM }, { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING }, { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE },
system/vl.c +2 -0
@@ -2706,7 +2706,9 @@ void qmp_x_exit_preconfig(Error **errp)qemu_machine_creation_done ();if (loadvm) { +RunState state = autostart ?RUN_STATE_RUNNING :runstate_get ();load_snapshot (loadvm,NULL , false,NULL , &error_fatal); +load_snapshot_resume (state); }if (replay_mode !=REPLAY_MODE_NONE ) {replay_vmstate_init ();
Signature · 1 line
1.8.3.1
PATCH v7 8/12 migration: preserve suspended for bg_migration
In reply to Steve SistareDo not wake a suspended guest during bg_migration, and restore the prior state at finish rather than unconditionally running. Allow the additional state transitions that occur.
--- migration/migration.c | 7 +------ system/runstate.c | 1 + 2 files changed, 2 insertions(+), 6 deletions(-)
migration/migration.c +1 -6
@@ -3390,7 +3390,7 @@ static void bg_migration_vm_start_bh(void *opaque)qemu_bh_delete (s->vm_start_bh); s->vm_start_bh =NULL ; -vm_start (); +vm_resume (s->vm_old_state);migration_downtime_end (s); }
@@ -3462,11 +3462,6 @@ 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 ();
system/runstate.c +1 -0
@@ -168,6 +168,7 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_SUSPENDED, RUN_STATE_PAUSED}, { RUN_STATE_SUSPENDED, RUN_STATE_SAVE_VM }, { RUN_STATE_SUSPENDED, RUN_STATE_RESTORE_VM }, + { RUN_STATE_SUSPENDED, RUN_STATE_SHUTDOWN }, { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING }, { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE },
Signature · 1 line
1.8.3.1
PATCH v7 9/12 tests/qtest: migration events
In reply to Steve SistareDefine 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.
--- tests/qtest/migration-helpers.c | 24 ++++------- tests/qtest/migration-helpers.h | 9 ++-- tests/qtest/migration-test.c | 91 +++++++++++++++++++---------------------- 3 files changed, 56 insertions(+), 68 deletions(-)
tests/qtest/migration-helpers.c +7 -17
@@ -24,26 +24,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; }
tests/qtest/migration-helpers.h +6 -3
@@ -15,9 +15,12 @@#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; +bool resume_seen; +}QTestMigrationState ; + +bool migrate_watch_for_events (QTestState *who,const char *name,QDict *event,void *opaque);G_GNUC_PRINTF (3 ,4 )
tests/qtest/migration-test.c +43 -48
204 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v7 10/12 tests/qtest: option to suspend during migration
In reply to Steve SistareAdd 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. Generate the bootblock for each test, because suspend_me may differ for each.
--- tests/migration/i386/Makefile | 5 ++-- tests/migration/i386/a-b-bootblock.S | 50 +++++++++++++++++++++++++++++++++--- tests/migration/i386/a-b-bootblock.h | 26 +++++++++++++------ tests/qtest/migration-test.c | 12 ++++++--- 4 files changed, 77 insertions(+), 16 deletions(-)
tests/migration/i386/Makefile +3 -2
@@ -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
tests/migration/i386/a-b-bootblock.S +47 -3
74 lines not on this page · raw message
tests/migration/i386/a-b-bootblock.h +18 -8
@@ -4,7 +4,7 @@* the header and the assembler differences in your patch submission. */ unsigned char x86_bootsect[] = { -0xfa ,0x0f ,0x01 ,0x16 ,0x8c ,0x7c ,0x66 ,0xb8 ,0x01 ,0x00 ,0x00 ,0x00 , +0xfa ,0x0f ,0x01 ,0x16 ,0xb8 ,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 ,
@@ -13,13 +13,13 @@ unsigned char x86_bootsect[] = {0x40 ,0x06 ,0x7c ,0xf1 ,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 ,0x74 ,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 ,0x00 ,0x00 ,0x00 ,0x00 , +0xf8 ,0x03 ,0xee ,0xa1 ,0xbe ,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 ,0xa0 ,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,
@@ -49,3 +49,13 @@ unsigned char x86_bootsect[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa }; +#define SYM_do_zero 0x00007c3d +#define SYM_gdt 0x00007ca0 +#define SYM_gdtdesc 0x00007cb8 +#define SYM_innerloop 0x00007c51 +#define SYM_mainloop 0x00007c4c +#define SYM_pre_zero 0x00007c38 +#define SYM_start 0x00007c00 +#define SYM_suspend_me 0x00007cbe +#define SYM_TEST_MEM_END 0x06400000 +#define SYM_TEST_MEM_START 0x00100000
tests/qtest/migration-test.c +9 -3
@@ -133,7 +133,7 @@ static char *bootpath;#include "tests/migration/aarch64/a-b-kernel.h" #include "tests/migration/s390x/a-b-bios.h" -static void bootfile_create (char *dir) +static void bootfile_create (char *dir,bool suspend_me) {const char *arch =qtest_get_arch ();unsigned char *content;
@@ -143,6 +143,7 @@ static void bootfile_create(char *dir)if (strcmp (arch,"i386" ) ==0 ||strcmp (arch,"x86_64" ) ==0 ) {/* the assembled x86 boot sector should be exactly one sector large */ g_assert (sizeof (x86_bootsect) ==512 ); + x86_bootsect[SYM_suspend_me - SYM_start] = suspend_me; content = x86_bootsect; len =sizeof (x86_bootsect); }else if (g_str_equal (arch,"s390x" )) {
@@ -646,6 +647,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;/*
@@ -767,6 +770,8 @@ static int test_migrate_start(QTestState **from, QTestState **to, dst_state = (QTestMigrationState ) { }; src_state = (QTestMigrationState ) { }; +bootfile_create (tmpfs, args->suspend_me); +if (strcmp (arch,"i386" ) ==0 ||strcmp (arch,"x86_64" ) ==0 ) { memory_size ="150M" ;
@@ -2980,7 +2985,9 @@ static int64_t get_limit_rate(QTestState *who)static QTestState *dirtylimit_start_vm (void ) {QTestState *vm =NULL ; - g_autofree gchar * + g_autofree gchar *cmd = NULL; + +bootfile_create (tmpfs, false); cmd =g_strdup_printf ("-accel kvm,dirty-ring-size=4096 " "-name dirtylimit-test,debug-threads=on " "-m 150M -smp 1 "
@@ -3329,7 +3336,6 @@ int main(int argc, char **argv) g_get_tmp_dir(), err->message); }g_assert (tmpfs); -bootfile_create (tmpfs);module_call_init (MODULE_INIT_QOM );
Signature · 1 line
1.8.3.1
PATCH v7 11/12 tests/qtest: precopy migration with suspend
In reply to Steve SistareAdd 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.
--- tests/qtest/migration-helpers.c | 3 ++ tests/qtest/migration-helpers.h | 2 ++ tests/qtest/migration-test.c | 62 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 64 insertions(+), 3 deletions(-)
tests/qtest/migration-helpers.c +3 -0
@@ -32,6 +32,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;
tests/qtest/migration-helpers.h +2 -0
@@ -18,6 +18,8 @@typedef struct QTestMigrationState {bool stop_seen;bool resume_seen; +bool suspend_seen; +bool suspend_me; }QTestMigrationState ; bool migrate_watch_for_events(QTestState *who, const char *name,
tests/qtest/migration-test.c +59 -3
128 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [PATCH V7 11/12] tests/qtest: precopy migration with suspend
Quoted 5 lines · 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 <[email protected]>
Re: [PATCH V7 11/12] tests/qtest: precopy migration with suspend
In reply to Steve SistareQuoted 5 lines · 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 <[email protected]>
Signature · 1 line
Peter Xu
PATCH v7 12/12 tests/qtest: postcopy migration with suspend
In reply to Steve SistareAdd 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.
--- tests/qtest/migration-test.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
tests/qtest/migration-test.c +19 -1
@@ -1347,6 +1347,7 @@ static int migrate_postcopy_prepare(QTestState **from_ptr,/* Wait for the first serial output from the source */ wait_for_serial ("src_serial" ); +wait_for_suspend (from, &src_state); g_autofree char *uri = migrate_get_socket_address(to, "socket-address");migrate_qmp (from, uri,"{}" );
@@ -1364,6 +1365,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" );
@@ -1397,6 +1403,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 = {
@@ -3412,7 +3427,10 @@ int main(int argc, char **argv)qtest_add_func ("/migration/postcopy/recovery/double-failures" , test_postcopy_recovery_double_fail);#endif /* _WIN32 */ - +if (is_x86) { +qtest_add_func ("/migration/postcopy/suspend" , + test_postcopy_suspend); + } }qtest_add_func ("/migration/bad_dest" , test_baddest);
Signature · 1 line
1.8.3.1
Re: [PATCH V7 12/12] tests/qtest: postcopy migration with suspend
Quoted 5 lines · 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 <[email protected]>
Signature · 1 line
Peter Xu
FYI, these patches still need RB:
migration: propagate suspended runstate
tests/qtest: precopy migration with suspend
tests/qtest: postcopy migration with suspend
This has RB, but the interaction between vm_start and vm_prepare_start changed, so needs another look.
cpus: stop vm in suspended runstate
- Steve
Quoted 92 lines · 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, after saving a snapshot in the suspended state and loading it, the
vm_startfails. 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 migrationChanges in V3:
* rebase to tip
* fix hang in new functionmigrate_wait_for_dirty_memChanges in V4:
* rebase to tip
* add patch forvm_prepare_start(thanks Peter)
* add patch to preserve cpu ticksChanges in V5:
* rebase to tip
* added patches to completely stop vm in suspended state:
cpus: refactorvm_stop
cpus: stop vm in suspended state
* added patch to partially resume vm in suspended state:
cpus: start vm in suspended state
* modified "preserve suspended ..." patches to use the above.
* deleted patch "preserve cpu ticks if suspended". stop ticks invm_stop_force_stateinstead.
* deleted patch "add runstate function". defined new helper functionmigrate_new_runstatein "preserve suspended runstate"
* Added some RB's, but removed other RB's because the patches changed.Changes in V6:
* allvm_stopcalls completely stop the suspended state
* refactored and updated the "cpus" patches
* simplified the "preserve suspended" patches
* added patch "bootfile per vm"Changes in V7:
* rebase to tip, add RB-s
* fix backwards compatibility for global_state.vm_was_suspended
* deletevm_prepare_startstate argument, and rename patch "pass runstate tovm_prepare_start" to
"check running notRUN_STATE_RUNNING"
* drop patches:
tests/qtest: bootfile per vm
tests/qtest: background migration with suspend
* renamerunstate_is_startedtorunstate_is_live
* movewait_for_suspendin testsSteve Sistare (12):
cpus:vm_was_suspended
cpus: stop vm in suspended runstate
cpus: check running notRUN_STATE_RUNNING
cpus:vm_resume
migration: propagate suspended runstate
migration: preserve suspended runstate
migration: preserve suspended for snapshot
migration: preserve suspended forbg_migration
tests/qtest: migration events
tests/qtest: option to suspend during migration
tests/qtest: precopy migration with suspend
tests/qtest: postcopy migration with suspendbackends/tpm/tpm_emulator.c | 2 +- hw/usb/hcd-ehci.c | 2 +- hw/usb/redirect.c | 2 +- hw/xen/xen-hvm-common.c | 2 +- include/migration/snapshot.h | 7 ++ include/sysemu/runstate.h | 16 ++++ migration/global_state.c | 35 ++++++- migration/migration-hmp-cmds.c | 8 +- migration/migration.c | 15 +-- migration/savevm.c | 23 +++-- qapi/misc.json | 10 +- system/cpus.c | 47 +++++++-- system/runstate.c | 9 ++ system/vl.c | 2 + tests/migration/i386/Makefile | 5 +- tests/migration/i386/a-b-bootblock.S | 50 +++++++++- tests/migration/i386/a-b-bootblock.h | 26 +++-- tests/qtest/migration-helpers.c | 27 ++---- tests/qtest/migration-helpers.h | 11 ++- tests/qtest/migration-test.c | 181 +++++++++++++++++++++++++---------- 20 files changed, 354 insertions(+), 126 deletions(-)
Quoted 1 line · Steven Sistare
cpus: stop vm in suspended runstate
This patch still didn't copy the QAPI maintainers, please remember to do so in a new post.
Maybe it would be easier to move the QAPI doc changes into a separate patch?
Thanks,
Signature · 1 line
Peter Xu
Quoted 8 lines · Peter Xu
Quoted 1 line · Steven Sistare
cpus: stop vm in suspended runstate
This patch still didn't copy the QAPI maintainers, please remember to do so in a new post.
Maybe it would be easier to move the QAPI doc changes into a separate patch?
This was intentional. I did not cc them for the whole series to spare them from excess email. You cc'd them for "[PATCH V6 03/14] cpus: stop vm in suspended runstate" they had no comments, and there is no change for V7, so I assumed we are OK, but I will cc them again for that patch to be sure.
- Steve
Quoted 7 lines · Steven Sistare
Quoted 6 lines · Peter Xu
Quoted 1 line · Steven Sistare
cpus: stop vm in suspended runstate
This patch still didn't copy the QAPI maintainers, please remember to do so in a new post.
Quoted 7 lines
Quoted 2 lines
Maybe it would be easier to move the QAPI doc changes into a separate patch?
This was intentional. I did not cc them for the whole series to spare them from excess email. You cc'd them for "[PATCH V6 03/14] cpus: stop vm in suspended runstate" they had no comments, and there is no change for V7, so I assumed we are OK, but I will cc them again for that patch to be sure.
Yes, please do so. Per my experience on QEMU, we normally need an ACK from all sides to merge a patch. There can be outliers if the changes are very trivial so one maintainer may just pull that in, but it'll always be good to always copy relevant maintainers.
Thanks,
Signature · 1 line
Peter Xu