Skip to contentSkip to conversation

spice: delay starting until display are initialized

PATCH Superseded [email protected] 3 participants 11 messages Jan 28, 2021 – Jan 29, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spice: delay starting until display are initialized

From: Marc-André Lureau <[email protected]>

QEMU used to run qemu_spice.display_init() before vm_start(), and QXL/display interfaces where started then. Now, vm_start() happens before QXL/display interfaces are added and Spice server doesn't automatically start them in this case (fixed in spice git)

Fixes Spice regression introduced after 5.2, with refactoring commits b4e1a34211 ("vl: remove separate preconfig main_loop") and facf7c60ee ("vl: initialize displays _after_ exiting preconfiguration"), probably others.

---
 include/sysemu/runstate.h | 1 +
 include/ui/qemu-spice.h   | 1 +
 softmmu/runstate.c        | 5 +++++
 ui/spice-core.c           | 9 ++++++++-
 ui/spice-display.c        | 2 ++
 5 files changed, 17 insertions(+), 1 deletion(-)
include/sysemu/runstate.h +1 -0
index e557f470d4..40b3083008 100644
@@ -6,6 +6,7 @@
 
 bool runstate_check(RunState state);
 void runstate_set(RunState new_state);
+RunState runstate_get(void);
 int runstate_is_running(void);
 bool runstate_needs_reset(void);
 bool runstate_store(char *str, size_t size);
include/ui/qemu-spice.h +1 -0
index 2beb792972..71ecd6cfd1 100644
@@ -28,6 +28,7 @@
 
 void qemu_spice_input_init(void);
 void qemu_spice_display_init(void);
+void qemu_spice_display_init_done(void);
 bool qemu_spice_have_display_interface(QemuConsole *con);
 int qemu_spice_add_display_interface(QXLInstance *qxlin, QemuConsole *con);
 int qemu_spice_migrate_info(const char *hostname, int port, int tls_port,
softmmu/runstate.c +5 -0
index beee050815..92ef7444d0 100644
@@ -195,6 +195,11 @@ static void runstate_init(void)
     qemu_mutex_init(&vmstop_lock);
 }
 
+RunState runstate_get(void)
+{
+    return current_run_state;
+}
+
 /* This function will abort() on invalid state transitions */
 void runstate_set(RunState new_state)
 {
ui/spice-core.c +8 -1
index 5746d0aae7..b621dd86b6 100644
@@ -46,6 +46,7 @@ static const char *auth = "spice";
 static char *auth_passwd;
 static time_t auth_expires = TIME_MAX;
 static int spice_migration_completed;
+static int spice_display_init_done;
 static int spice_display_is_running;
 static int spice_have_target_host;
 
@@ -625,13 +626,19 @@ static int add_channel(void *opaque, const char *name, const char *value,
 static void vm_change_state_handler(void *opaque, int running,
                                     RunState state)
 {
-    if (running) {
+    if (running && spice_display_init_done) {
         qemu_spice_display_start();
     } else if (state != RUN_STATE_PAUSED) {
         qemu_spice_display_stop();
     }
 }
 
+void qemu_spice_display_init_done(void)
+{
+    spice_display_init_done = true;
+    vm_change_state_handler(NULL, runstate_is_running(), runstate_get());
+}
+
 static void qemu_spice_init(void)
 {
     QemuOpts *opts = QTAILQ_FIRST(&qemu_spice_opts.head);
ui/spice-display.c +2 -0
index 0178d5766d..3d3e3bcb22 100644
@@ -1188,4 +1188,6 @@ void qemu_spice_display_init(void)
         }
         qemu_spice_display_init_one(con);
     }
+
+    qemu_spice_display_init_done();
 }
Signature · 1 line
2.29.0
#1 lore raw

Hi,

ui/spice-display.c void qemu_spice_display_init(void) · line 1190

Quoted 8 lines
ui/spice-display.c +0 -0
index 0178d5766d..3d3e3bcb22 100644
@@ -1188,4 +1188,6 @@ void qemu_spice_display_init(void)
         }
         qemu_spice_display_init_one(con);
     }
       if (runstate_is_running()) {
            qemu_spice_display_start();
       }

Isn't that enough?

take care,
Gerd

#2 lore raw

Hi

Quoted 15 lines · Gerd Hoffmann

Hi,

ui/spice-display.c void qemu_spice_display_init(void) · line 1190

Quoted 8 lines
ui/spice-display.c +0 -0
index 0178d5766d..3d3e3bcb22 100644
@@ -1188,4 +1188,6 @@ void qemu_spice_display_init(void)
         }
         qemu_spice_display_init_one(con);
     }
       if (runstate_is_running()) {
            qemu_spice_display_start();
       }
Quoted 2 lines

Isn't that enough?

That should be fine too, I'll update the patch. thanks

#3 lore raw

Hi

Quoted 19 lines · Marc-André Lureau

Hi

Quoted 15 lines · Gerd Hoffmann

Hi,

ui/spice-display.c void qemu_spice_display_init(void) · line 1190

Quoted 8 lines
ui/spice-display.c +0 -0
index 0178d5766d..3d3e3bcb22 100644
@@ -1188,4 +1188,6 @@ void qemu_spice_display_init(void)
         }
         qemu_spice_display_init_one(con);
     }
       if (runstate_is_running()) {
            qemu_spice_display_start();
       }
Quoted 5 lines
Quoted 2 lines

Isn't that enough?

That should be fine too, I'll update the patch. thanks

Actually no, we still need to prevent the initial qemu_spice_display_start(), and do a single call when everything is ready (since spice server doesn't handle adding interfaces dynamically when running).

#4 lore raw
Quoted 27 lines · Marc-André Lureau

Hi

Quoted 22 lines · Marc-André Lureau

Hi

Quoted 17 lines · Gerd Hoffmann

Hi,

ui/spice-display.c void qemu_spice_display_init(void) · line 1190

Quoted 8 lines
ui/spice-display.c +0 -0
index 0178d5766d..3d3e3bcb22 100644
@@ -1188,4 +1188,6 @@ void qemu_spice_display_init(void)
         }
         qemu_spice_display_init_one(con);
     }
       if (runstate_is_running()) {
            qemu_spice_display_start();
       }

Isn't that enough?

Quoted 7 lines
Quoted 2 lines

That should be fine too, I'll update the patch. thanks

Actually no, we still need to prevent the initial qemu_spice_display_start(), and do a single call when everything is ready (since spice server doesn't handle adding interfaces dynamically when running).

I still think that moving these three lines to the correct place is enough. Maybe even just qemu_spice_display_start() as it keeps track of the state and you can safely call this twice.

take care,
Gerd

#5 lore raw

Hi

Quoted 32 lines · Gerd Hoffmann
Quoted 30 lines · Marc-André Lureau

Hi

Quoted 24 lines · Marc-André Lureau

Hi

Quoted 15 lines · Gerd Hoffmann

Hi,

ui/spice-display.c void qemu_spice_display_init(void) · line 1190

Quoted 8 lines
ui/spice-display.c +0 -0
index 0178d5766d..3d3e3bcb22 100644
@@ -1188,4 +1188,6 @@ void qemu_spice_display_init(void)
         }
         qemu_spice_display_init_one(con);
     }
       if (runstate_is_running()) {
            qemu_spice_display_start();
       }
Quoted 2 lines

Isn't that enough?

That should be fine too, I'll update the patch. thanks

Quoted 9 lines
Quoted 4 lines

Actually no, we still need to prevent the initial qemu_spice_display_start(), and do a single call when everything is ready (since spice server doesn't handle adding interfaces dynamically when running).

I still think that moving these three lines to the correct place is enough. Maybe even just qemu_spice_display_start() as it keeps track of the state and you can safely call this twice.

It's not enough, since the first time qemu_spice_display_start() is called (on vm_start) the display interfaces aren't yet registered. And spice server doesn't automatically start the newly added interfaces.

Signature · 1 line
Marc-André Lureau
#6 lore raw
Quoted 7 lines
Quoted 3 lines

I still think that moving these three lines to the correct place is enough. Maybe even just qemu_spice_display_start() as it keeps track of the state and you can safely call this twice.

It's not enough, since the first time qemu_spice_display_start() is called (on vm_start) the display interfaces aren't yet registered. And spice server doesn't automatically start the newly added interfaces.

So move the vmstate handler registration call too?
I'd prefer to not add more state variables if we can avoid it ...

take care,
Gerd

#7 lore raw

Hi

Quoted 5 lines · Gerd Hoffmann
Quoted 5 lines
Quoted 4 lines

I still think that moving these three lines to the correct place is enough. Maybe even just qemu_spice_display_start() as it keeps track of the state and you can safely call this twice.

Quoted 7 lines
Quoted 3 lines

It's not enough, since the first time qemu_spice_display_start() is called (on vm_start) the display interfaces aren't yet registered. And spice server doesn't automatically start the newly added interfaces.

So move the vmstate handler registration call too?
I'd prefer to not add more state variables if we can avoid it ...

Does that seem right to you?

ui/spice-core.c +0 -1
index b621dd86b6..f592331ce4 100644
@@ -46,7 +46,6 @@ static const char *auth = "spice";
 static char *auth_passwd;
 static time_t auth_expires = TIME_MAX;
 static int spice_migration_completed;
-static int spice_display_init_done;
 static int spice_display_is_running;
 static int spice_have_target_host;
 
@@ -626,7 +625,7 @@ static int add_channel(void *opaque, const char

*name, const char *value,
static void vm_change_state_handler(void *opaque, int running,
RunState state)
{
- if (running && spice_display_init_done) {

+    if (running) {
         qemu_spice_display_start();
     } else if (state != RUN_STATE_PAUSED) {
         qemu_spice_display_stop();

@@ -635,7 +634,7 @@ static void vm_change_state_handler(void *opaque, int running,

void qemu_spice_display_init_done(void)
{
- spice_display_init_done = true;

+    qemu_add_vm_change_state_handler(vm_change_state_handler, NULL);
     vm_change_state_handler(NULL, runstate_is_running(), runstate_get());

}

@@ -810,7 +809,6 @@ static void qemu_spice_init(void)

     qemu_spice_input_init();
-    qemu_add_vm_change_state_handler(vm_change_state_handler, NULL);
     qemu_spice_display_stop();

     g_free(x509_key_file);
Signature · 1 line
Marc-André Lureau
#8 lore raw

Hi,

Quoted 16 lines
Quoted 2 lines

So move the vmstate handler registration call too?
I'd prefer to not add more state variables if we can avoid it ...

Does that seem right to you?

(quoted diff) +1 -1
@@ -626,7 +625,7 @@ static int add_channel(void *opaque, const char
 *name, const char *value,
 static void vm_change_state_handler(void *opaque, int running,
                                     RunState state)
 {
-    if (running && spice_display_init_done) {
+    if (running) {
         qemu_spice_display_start();
     } else if (state != RUN_STATE_PAUSED) {
         qemu_spice_display_stop();

Review static void vm_change_state_handler(void *opaque, · line 639

Quoted 7 lines
(quoted diff) +1 -1
@@ -635,7 +634,7 @@ static void vm_change_state_handler(void *opaque,
 int running,
 
 void qemu_spice_display_init_done(void)
 {
-    spice_display_init_done = true;
+    qemu_add_vm_change_state_handler(vm_change_state_handler, NULL);
     vm_change_state_handler(NULL, runstate_is_running(), runstate_get());

I'd just call qemu_spice_display_start() directly here, the need for runstate_get() goes away then. Otherwise looks good to me.

take care,
Gerd

#9 lore raw
Quoted 21 lines · Gerd Hoffmann

Hi,

Quoted 18 lines
Quoted 2 lines

So move the vmstate handler registration call too?
I'd prefer to not add more state variables if we can avoid it ...

Does that seem right to you?

(quoted diff) +1 -1
@@ -626,7 +625,7 @@ static int add_channel(void *opaque, const char
 *name, const char *value,
 static void vm_change_state_handler(void *opaque, int running,
                                     RunState state)
 {
-    if (running && spice_display_init_done) {
+    if (running) {
         qemu_spice_display_start();
     } else if (state != RUN_STATE_PAUSED) {
         qemu_spice_display_stop();
(quoted diff) +0 -0
@@ -635,7 +634,7 @@ static void vm_change_state_handler(void *opaque,
 int running,
 
Quoted 8 lines

Review static void vm_change_state_handler(void *opaque, · line 639

Quoted 5 lines
(quoted diff) +1 -1
 void qemu_spice_display_init_done(void)
 {
-    spice_display_init_done = true;
+    qemu_add_vm_change_state_handler(vm_change_state_handler, NULL);
     vm_change_state_handler(NULL, runstate_is_running(), runstate_get());

I'd just call qemu_spice_display_start() directly here, the need for runstate_get() goes away then. Otherwise looks good to me.

Hmm, that could work, but it will behave differently as we will start spice even if the VM is not running then.

Signature · 1 line
Marc-André Lureau
#10 lore raw
Quoted 11 lines
Quoted 8 lines

Review

Quoted 5 lines

void qemu_spice_display_init_done(void)
{

(quoted diff) +1 -1
-    spice_display_init_done = true;
+    qemu_add_vm_change_state_handler(vm_change_state_handler, NULL);
     vm_change_state_handler(NULL, runstate_is_running(), runstate_get());

I'd just call qemu_spice_display_start() directly here, the need for runstate_get() goes away then. Otherwise looks good to me.

Hmm, that could work, but it will behave differently as we will start spice even if the VM is not running then.

if (runstate_is_running())
qemu_spice_display_start()

take care,
Gerd