Skip to contentSkip to conversation

runstate: do not force prelaunch on reset during save-vm

PATCH In review Erik Fastermann 2 participants 5 messages Sep 16 – Nov 9

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 runstate: do not force prelaunch on reset during save-vm

A reset processed while the VM sits in 'save-vm' aborts QEMU:

    invalid runstate transition: 'save-vm' -> 'prelaunch'

The window is reachable over QMP. dump-guest-memory with detach=true stops the VM with vm_stop(RUN_STATE_SAVE_VM) in dump_init() and then returns once dump_thread has been spawned, so the main loop keeps running with the VM in 'save-vm' for the whole duration of the dump. A system_reset in that window kills the guest, as main_loop_should_exit() forces the run state to 'prelaunch'.

'save-vm' needs the same treatment as 'finish-migrate' in commit 1bd71dce4b ("runstate: ignore exit request in finish migrate state"). The reset cannot be applied to a run state whose only exits are back to 'running' or 'suspended', so leave it alone: dump_cleanup() ends it with vm_start() once the dump thread is done.

---
 system/runstate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
system/runstate.c +2 -1
index d3e64d2b62..1d65a4d444 100644
@@ -1075,7 +1075,8 @@ static bool main_loop_should_exit(int *status)
          */
         if (!runstate_check(RUN_STATE_RUNNING) &&
                 !runstate_check(RUN_STATE_INMIGRATE) &&
-                !runstate_check(RUN_STATE_FINISH_MIGRATE)) {
+                !runstate_check(RUN_STATE_FINISH_MIGRATE) &&
+                !runstate_check(RUN_STATE_SAVE_VM)) {
             runstate_set(RUN_STATE_PRELAUNCH);
         }
     }
Signature · 1 line
2.47.3
#4 lore raw
In reply to Erik Fastermann

Hi Erik,

Quoted 10 lines · Erik Fastermann

A reset processed while the VM sits in 'save-vm' aborts QEMU:

     invalid runstate transition: 'save-vm' -> 'prelaunch'

The window is reachable over QMP. dump-guest-memory with detach=true stops the VM with vm_stop(RUN_STATE_SAVE_VM) in dump_init() and then returns once dump_thread has been spawned, so the main loop keeps running with the VM in 'save-vm' for the whole duration of the dump. A system_reset in that window kills the guest, as main_loop_should_exit() forces the run state to 'prelaunch'.

Since this is in rebuild_guest() path, Cc'ing Ani in case the dump thread could read an unmapped or stale block list on confidential guest.

Quoted 4 lines

'save-vm' needs the same treatment as 'finish-migrate' in commit 1bd71dce4b ("runstate: ignore exit request in finish migrate state"). The reset cannot be applied to a run state whose only exits are back to 'running' or 'suspended',

The reset is applied; only the runstate is kept at SAVE_VM.

Quoted 2 lines

so leave it alone: dump_cleanup() ends it
with vm_start() once the dump thread is done.

I haven't checked in which state are devices during a detached dump, pre- or post-reset, do you happent to know? (could the reset be deferred / rejected in that case?)

The abort fix is reasonable but could you add a qtest?

Quoted 10 lines
---
  system/runstate.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
system/runstate.c +0 -0
index d3e64d2b62..1d65a4d444 100644

system/runstate.c static bool main_loop_should_exit(int *status) · line 1079

Quoted 6 lines
system/runstate.c +2 -1
@@ -1075,7 +1075,8 @@ static bool main_loop_should_exit(int *status)
           */
          if (!runstate_check(RUN_STATE_RUNNING) &&
                  !runstate_check(RUN_STATE_INMIGRATE) &&
-                !runstate_check(RUN_STATE_FINISH_MIGRATE)) {
+                !runstate_check(RUN_STATE_FINISH_MIGRATE) &&
+                !runstate_check(RUN_STATE_SAVE_VM)) {

Side note, it seems we reached the usefulness of runstate_check() calls here; adding another local helper would help readability.

Quoted 3 lines
system/runstate.c +0 -0
              runstate_set(RUN_STATE_PRELAUNCH);
          }
      }