Skip to contentSkip to conversation

runstate: ignore finishmigrate -> prelaunch transition

PATCH In review Laurent Vivier 3 participants 6 messages Nov 29, 2019 – Jan 8, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 runstate: ignore finishmigrate -> prelaunch transition

Commit 1bd71dce4bf2 tries to prevent a finishmigrate -> prelaunch transition by exiting at the beginning of the main_loop_should_exit() function if the state is already finishmigrate.

As the finishmigrate state is set in the migration thread it can happen concurrently to the function. The migration thread and the function are normally protected by the iothread mutex and thus the state should no evolve between the start of the function and its end.

Unfortunately during the function life the lock is released by pause_all_vcpus() just before the point we need to be sure we are not in finishmigrate state and if the migration thread is waiting for the lock it will take the opportunity to change the state to finishmigrate.

The only way to be sure we are not in the finishmigrate state when we need is to check the state after the pause_all_vcpus() function.

Fixes 1bd71dce4bf2 ("runstate: ignore exit request in finish migrate state")
---
 vl.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
vl.c +6 -4
index 6a65a64bfd64..bf0a6345d239 100644
@@ -1745,9 +1745,6 @@ static bool main_loop_should_exit(void)
     RunState r;
     ShutdownCause request;
 
-    if (runstate_check(RUN_STATE_FINISH_MIGRATE)) {
-        return false;
-    }
     if (preconfig_exit_requested) {
         if (runstate_check(RUN_STATE_PRECONFIG)) {
             runstate_set(RUN_STATE_PRELAUNCH);
@@ -1776,8 +1773,13 @@ static bool main_loop_should_exit(void)
         pause_all_vcpus();
         qemu_system_reset(request);
         resume_all_vcpus();
+        /*
+         * runstate can change in pause_all_vcpus()
+         * as iothread mutex is unlocked
+         */
         if (!runstate_check(RUN_STATE_RUNNING) &&
-                !runstate_check(RUN_STATE_INMIGRATE)) {
+                !runstate_check(RUN_STATE_INMIGRATE) &&
+                !runstate_check(RUN_STATE_FINISH_MIGRATE)) {
             runstate_set(RUN_STATE_PRELAUNCH);
         }
     }
Signature · 1 line
2.23.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · * Laurent Vivier ([email protected]) wrote:

Commit 1bd71dce4bf2 tries to prevent a finishmigrate -> prelaunch transition by exiting at the beginning of the main_loop_should_exit() function if the state is already finishmigrate.

As the finishmigrate state is set in the migration thread it can happen concurrently to the function. The migration thread and the function are normally protected by the iothread mutex and thus the state should no evolve between the start of the function and its end.

Quoted 5 lines

Unfortunately during the function life the lock is released by pause_all_vcpus() just before the point we need to be sure we are not in finishmigrate state and if the migration thread is waiting for the lock it will take the opportunity to change the state to finishmigrate.

Ewww.
I hate those short wakeups for pause_all_vcpus; I'm sure there are loads more corners that break.

Still, I _think_ this is an improvement, so:

Quoted 41 lines

The only way to be sure we are not in the finishmigrate state when we need is to check the state after the pause_all_vcpus() function.

Fixes 1bd71dce4bf2 ("runstate: ignore exit request in finish migrate state")
---
 vl.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
vl.c +6 -4
index 6a65a64bfd64..bf0a6345d239 100644
@@ -1745,9 +1745,6 @@ static bool main_loop_should_exit(void)
     RunState r;
     ShutdownCause request;
 
-    if (runstate_check(RUN_STATE_FINISH_MIGRATE)) {
-        return false;
-    }
     if (preconfig_exit_requested) {
         if (runstate_check(RUN_STATE_PRECONFIG)) {
             runstate_set(RUN_STATE_PRELAUNCH);
@@ -1776,8 +1773,13 @@ static bool main_loop_should_exit(void)
         pause_all_vcpus();
         qemu_system_reset(request);
         resume_all_vcpus();
+        /*
+         * runstate can change in pause_all_vcpus()
+         * as iothread mutex is unlocked
+         */
         if (!runstate_check(RUN_STATE_RUNNING) &&
-                !runstate_check(RUN_STATE_INMIGRATE)) {
+                !runstate_check(RUN_STATE_INMIGRATE) &&
+                !runstate_check(RUN_STATE_FINISH_MIGRATE)) {
             runstate_set(RUN_STATE_PRELAUNCH);
         }
     }
Signature · 1 line
2.23.0

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#2 lore raw
Quoted 16 lines · Dr. David Alan Gilbert
Quoted 9 lines · * Laurent Vivier ([email protected]) wrote:

Commit 1bd71dce4bf2 tries to prevent a finishmigrate -> prelaunch transition by exiting at the beginning of the main_loop_should_exit() function if the state is already finishmigrate.

As the finishmigrate state is set in the migration thread it can happen concurrently to the function. The migration thread and the function are normally protected by the iothread mutex and thus the state should no evolve between the start of the function and its end.

Quoted 5 lines

Unfortunately during the function life the lock is released by pause_all_vcpus() just before the point we need to be sure we are not in finishmigrate state and if the migration thread is waiting for the lock it will take the opportunity to change the state to finishmigrate.

Quoted 8 lines

Ewww.
I hate those short wakeups for pause_all_vcpus; I'm sure there are loads more corners that break.

Still, I _think_ this is an improvement, so:

Who volunteers to take this in his queue?

Thanks,
Laurent

#3 lore raw

Ping?

Thanks,
Laurent

Quoted 32 lines · Laurent Vivier
Quoted 16 lines · Dr. David Alan Gilbert
Quoted 9 lines · * Laurent Vivier ([email protected]) wrote:

Commit 1bd71dce4bf2 tries to prevent a finishmigrate -> prelaunch transition by exiting at the beginning of the main_loop_should_exit() function if the state is already finishmigrate.

As the finishmigrate state is set in the migration thread it can happen concurrently to the function. The migration thread and the function are normally protected by the iothread mutex and thus the state should no evolve between the start of the function and its end.

Quoted 5 lines

Unfortunately during the function life the lock is released by pause_all_vcpus() just before the point we need to be sure we are not in finishmigrate state and if the migration thread is waiting for the lock it will take the opportunity to change the state to finishmigrate.

Quoted 8 lines

Ewww.
I hate those short wakeups for pause_all_vcpus; I'm sure there are loads more corners that break.

Still, I _think_ this is an improvement, so:

Who volunteers to take this in his queue?

Thanks,
Laurent

#4 lore raw
Quoted 1 line · * Laurent Vivier ([email protected]) wrote:

Ping?

Juan says he's doing a migration pull soon - this seems like a good one for it.

Dave

Quoted 37 lines

Thanks,
Laurent

Quoted 32 lines · Laurent Vivier
Quoted 16 lines · Dr. David Alan Gilbert
Quoted 9 lines · * Laurent Vivier ([email protected]) wrote:

Commit 1bd71dce4bf2 tries to prevent a finishmigrate -> prelaunch transition by exiting at the beginning of the main_loop_should_exit() function if the state is already finishmigrate.

As the finishmigrate state is set in the migration thread it can happen concurrently to the function. The migration thread and the function are normally protected by the iothread mutex and thus the state should no evolve between the start of the function and its end.

Quoted 5 lines

Unfortunately during the function life the lock is released by pause_all_vcpus() just before the point we need to be sure we are not in finishmigrate state and if the migration thread is waiting for the lock it will take the opportunity to change the state to finishmigrate.

Quoted 8 lines

Ewww.
I hate those short wakeups for pause_all_vcpus; I'm sure there are loads more corners that break.

Still, I _think_ this is an improvement, so:

Who volunteers to take this in his queue?

Thanks,
Laurent

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

Reviewed-by
#5 lore raw
In reply to Laurent Vivier
Quoted 33 lines · Laurent Vivier

Ping?

Thanks,
Laurent

Quoted 27 lines · Laurent Vivier
Quoted 16 lines · Dr. David Alan Gilbert
Quoted 9 lines · * Laurent Vivier ([email protected]) wrote:

Commit 1bd71dce4bf2 tries to prevent a finishmigrate -> prelaunch transition by exiting at the beginning of the main_loop_should_exit() function if the state is already finishmigrate.

As the finishmigrate state is set in the migration thread it can happen concurrently to the function. The migration thread and the function are normally protected by the iothread mutex and thus the state should no evolve between the start of the function and its end.

Quoted 5 lines

Unfortunately during the function life the lock is released by pause_all_vcpus() just before the point we need to be sure we are not in finishmigrate state and if the migration thread is waiting for the lock it will take the opportunity to change the state to finishmigrate.

Quoted 8 lines

Ewww.
I hate those short wakeups for pause_all_vcpus; I'm sure there are loads more corners that break.

Still, I _think_ this is an improvement, so:

Who volunteers to take this in his queue?

queued