Set runstate to RUN_STATE_RESTORE_VM when started with "-loadvm"
cover Set runstate to RUN_STATE_RESTORE_VM when started with "-loadvm"
Previously, there was a bug in usbredir which prevented "-loadvm" from working because libusbredir's usbredirparser_unserialize() fails when a HELLO packet is sent as part of the device's initalization.
The fix was to not send HELLO when in the RUN_STATE_PRELAUNCH state. However, recently we found that this breaks when QEMU is started with "-S" because it is in the RUN_STATE_PRELAUNCH state while halted before boot as well.
This patch attempts to re-fix the issue by setting the run state to RUN_STATE_RESTORE_VM when started with "-loadvm" and recognizing that state in usbredir's initalization.
To make sure there's no unintended side effects, we searched for "RUN_STATE_RESTORE_VM" in the code base and found only references in migration/savevm.c, monitor/hmp-cmds.c, and replay/replay-debugging.c. None of these seems to be affected by RUN_STATE_RESTORE_VM before RUN_STATE_RUNNING.
Joelle van Dyne (3):
Revert "usbredir: avoid queuing hello packet on snapshot restore"
vl: on -loadvm set run state to "restore-vm"
usbredir: avoid queuing hello packet on snapshot restore
hw/usb/redirect.c | 2 +- softmmu/runstate.c | 1 + softmmu/vl.c | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-)
Signature · 1 line
2.28.0
PATCH 1/3 Revert "usbredir: avoid queuing hello packet on snapshot restore"
Run state is also in RUN_STATE_PRELAUNCH while "-S" is used.
This reverts commit 12d182898a4866e4be418e2abac286b497cfa1b2.
--- hw/usb/redirect.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
hw/usb/redirect.c +1 -2
@@ -1280,8 +1280,7 @@ static void usbredir_create_parser(USBRedirDevice *dev) }#endif -if (runstate_check (RUN_STATE_INMIGRATE ) || -runstate_check (RUN_STATE_PRELAUNCH )) { +if (runstate_check (RUN_STATE_INMIGRATE )) { flags |= usbredirparser_fl_no_hello; } usbredirparser_init(dev->parser, VERSION, caps, USB_REDIR_CAPS_SIZE,
Signature · 1 line
2.28.0
Re: [PATCH 1/3] Revert "usbredir: avoid queuing hello packet on snapshot restore"
Quoted 8 lines · Joelle van Dyne
Run state is also in
RUN_STATE_PRELAUNCHwhile "-S" is used.This reverts commit
12d182898a4866e4be418e2abac286b497cfa1b2.Signed-off-by Joelle van Dyne <[email protected]>---
hw/usb/redirect.c| 3 +--1 file changed, 1 insertion(+), 2 deletions(-)
This fixes usb redirect on VM startup for VMs started by libvirt, which uses -S:
https://bugzilla.redhat.com/show_bug.cgi?id=2144436
Jano
PATCH 2/3 vl: on -loadvm set run state to "restore-vm"
In reply to Joelle van DyneThis allows us to differentiate between a fresh boot and a restore boot.
--- softmmu/runstate.c | 1 + softmmu/vl.c | 3 +++ 2 files changed, 4 insertions(+)
softmmu/runstate.c +1 -0
@@ -76,6 +76,7 @@ typedef struct {static const RunStateTransition runstate_transitions_def[] = { {RUN_STATE_PRELAUNCH ,RUN_STATE_INMIGRATE }, + {RUN_STATE_PRELAUNCH ,RUN_STATE_RESTORE_VM }, {RUN_STATE_DEBUG ,RUN_STATE_RUNNING }, {RUN_STATE_DEBUG ,RUN_STATE_FINISH_MIGRATE },
softmmu/vl.c +3 -0
@@ -3131,6 +3131,9 @@ void qemu_init(int argc, char **argv, char **envp)add_device_config (DEV_DEBUGCON , optarg);break ;case QEMU_OPTION_loadvm: +if (!loadvm) { +runstate_set (RUN_STATE_RESTORE_VM ); + } loadvm = optarg;break ;case QEMU_OPTION_full_screen:
Signature · 1 line
2.28.0
Re: [PATCH 2/3] vl: on -loadvm set run state to "restore-vm"
Quoted 7 lines · Joelle van Dyne
This allows us to differentiate between a fresh boot and a restore boot.
Signed-off-by Joelle van Dyne <[email protected]>--- softmmu/runstate.c | 1 + softmmu/vl.c | 3 +++ 2 files changed, 4 insertions(+)
What happens if the user launches QEMU with -S and NOT -loadvm, and then uses the 'loadvm' monitor command to restore the VM state ?
Quoted 30 lines
softmmu/runstate.c +1
-0@@ -76,6 +76,7 @@ typedef struct {static const RunStateTransition runstate_transitions_def[] = { {RUN_STATE_PRELAUNCH ,RUN_STATE_INMIGRATE }, + {RUN_STATE_PRELAUNCH ,RUN_STATE_RESTORE_VM }, {RUN_STATE_DEBUG ,RUN_STATE_RUNNING }, {RUN_STATE_DEBUG ,RUN_STATE_FINISH_MIGRATE },softmmu/vl.c +3
-0@@ -3131,6 +3131,9 @@ void qemu_init(int argc, char **argv, char **envp)add_device_config (DEV_DEBUGCON , optarg);break ;case QEMU_OPTION_loadvm: +if (!loadvm) { +runstate_set (RUN_STATE_RESTORE_VM ); + } loadvm = optarg;break ;case QEMU_OPTION_full_screen:Signature · 1 line
2.28.0
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH 2/3] vl: on -loadvm set run state to "restore-vm"
Quoted 4 lines · Daniel P. Berrangé
Quoted 2 lines · Joelle van Dyne
This allows us to differentiate between a fresh boot and a restore boot.
Quoted 8 lines
Quoted 5 lines
Signed-off-by Joelle van Dyne <[email protected]>--- softmmu/runstate.c | 1 + softmmu/vl.c | 3 +++ 2 files changed, 4 insertions(+)What happens if the user launches QEMU with -S and NOT -loadvm, and then uses the 'loadvm' monitor command to restore the VM state ?
Sorry, this email totally slipped past me. The 'loadvm' monitor command does this:
vm_stop(RUN_STATE_RESTORE_VM);
Which sets the correct state.
Quoted 40 lines
Quoted 29 lines
softmmu/runstate.c +1
-0@@ -76,6 +76,7 @@ typedef struct {static const RunStateTransition runstate_transitions_def[] = { {RUN_STATE_PRELAUNCH ,RUN_STATE_INMIGRATE }, + {RUN_STATE_PRELAUNCH ,RUN_STATE_RESTORE_VM }, {RUN_STATE_DEBUG ,RUN_STATE_RUNNING }, {RUN_STATE_DEBUG ,RUN_STATE_FINISH_MIGRATE },softmmu/vl.c +3
-1@@ -3131,6 +3131,9 @@ void qemu_init(int argc, char **argv, char **envp)add_device_config (DEV_DEBUGCON , optarg);break ;case QEMU_OPTION_loadvm: +if (!loadvm) { +runstate_set (RUN_STATE_RESTORE_VM ); + } loadvm = optarg;break ;case QEMU_OPTION_full_screen: --Quoted 3 lines
2.28.0
With regards,
Daniel
--|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH 3/3 usbredir: avoid queuing hello packet on snapshot restore
In reply to Joelle van DyneWhen launching QEMU with "-loadvm", usbredir_create_parser() should avoid setting up the hello packet (just as with "-incoming". On the latest version of libusbredir, usbredirparser_unserialize() will return error if the parser is not "pristine."
--- hw/usb/redirect.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/usb/redirect.c +2 -1
@@ -1280,7 +1280,8 @@ static void usbredir_create_parser(USBRedirDevice *dev) }#endif -if (runstate_check (RUN_STATE_INMIGRATE )) { +if (runstate_check (RUN_STATE_INMIGRATE ) || +runstate_check (RUN_STATE_RESTORE_VM )) { flags |= usbredirparser_fl_no_hello; } usbredirparser_init(dev->parser, VERSION, caps, USB_REDIR_CAPS_SIZE,
Signature · 1 line
2.28.0
Re: [PATCH 3/3] usbredir: avoid queuing hello packet on snapshot restore
Hi,
Quoted 4 lines · Joelle van Dyne
When launching QEMU with "-loadvm",
usbredir_create_parser()should avoid setting up the hello packet (just as with "-incoming". On the latest version of libusbredir,usbredirparser_unserialize()will return error if the parser is not "pristine."
That was wrong in the usbredir side. The fix [0] was merged and included in the latest 0.13.0 release
[0] https://gitlab.freedesktop.org/spice/usbredir/-/merge_requests/61
Quoted 23 lines
Signed-off-by Joelle van Dyne <[email protected]>--- hw/usb/redirect.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/usb/redirect.c +2
-1@@ -1280,7 +1280,8 @@ static void usbredir_create_parser(USBRedirDevice *dev) }#endif -if (runstate_check (RUN_STATE_INMIGRATE )) { +if (runstate_check (RUN_STATE_INMIGRATE ) || +runstate_check (RUN_STATE_RESTORE_VM )) { flags |= usbredirparser_fl_no_hello; } usbredirparser_init(dev->parser, VERSION, caps, USB_REDIR_CAPS_SIZE,Signature · 1 line
2.28.0
Cheers,
Victor
Re: [PATCH 3/3] usbredir: avoid queuing hello packet on snapshot restore
Quoted 11 lines · Victor Toso
Hi,
Quoted 4 lines · Joelle van Dyne
When launching QEMU with "-loadvm",
usbredir_create_parser()should avoid setting up the hello packet (just as with "-incoming". On the latest version of libusbredir,usbredirparser_unserialize()will return error if the parser is not "pristine."That was wrong in the usbredir side. The fix [0] was merged and included in the latest 0.13.0 release
This is good to know. Should the entire runstate_check in usbredir_create_parser be removed?
Quoted 30 lines
[0] https://gitlab.freedesktop.org/spice/usbredir/-/merge_requests/61
Quoted 20 lines
Signed-off-by Joelle van Dyne <[email protected]>--- hw/usb/redirect.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/usb/redirect.c +2
-2@@ -1280,7 +1280,8 @@ static void usbredir_create_parser(USBRedirDevice *dev) }#endif -if (runstate_check (RUN_STATE_INMIGRATE )) { +if (runstate_check (RUN_STATE_INMIGRATE ) || +runstate_check (RUN_STATE_RESTORE_VM )) { flags |= usbredirparser_fl_no_hello; } usbredirparser_init(dev->parser, VERSION, caps, USB_REDIR_CAPS_SIZE, --Quoted 3 lines
2.28.0
Cheers,
Victor
Re: [PATCH 3/3] usbredir: avoid queuing hello packet on snapshot restore
Hi,
Quoted 10 lines · Joelle van Dyne
Quoted 9 lines · Victor Toso
Hi,
Quoted 4 lines · Joelle van Dyne
When launching QEMU with "-loadvm",
usbredir_create_parser()should avoid setting up the hello packet (just as with "-incoming". On the latest version of libusbredir,usbredirparser_unserialize()will return error if the parser is not "pristine."
Quoted 5 lines
Quoted 2 lines
That was wrong in the usbredir side. The fix [0] was merged and included in the latest 0.13.0 release
This is good to know. Should the entire
runstate_checkinusbredir_create_parserbe removed?
From my POV your patch looks correct and would avoid migration issues such as [1] with usbredir 0.12.0 that was not patched
[1] https://bugzilla.redhat.com/show_bug.cgi?id=2096008
So, I'd keep the check and the patch :)
Quoted 15 lines
Quoted 15 lines
[0] https://gitlab.freedesktop.org/spice/usbredir/-/merge_requests/61
Quoted 13 lines
Signed-off-by Joelle van Dyne <[email protected]>--- hw/usb/redirect.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/usb/redirect.c +0
-0@@ -1280,7 +1280,8 @@ static void usbredir_create_parser(USBRedirDevice *dev) }#endif
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
hw/usb/redirect.c +2
-2-if (runstate_check (RUN_STATE_INMIGRATE )) { +if (runstate_check (RUN_STATE_INMIGRATE ) || +runstate_check (RUN_STATE_RESTORE_VM )) { flags |= usbredirparser_fl_no_hello; } usbredirparser_init(dev->parser, VERSION, caps, USB_REDIR_CAPS_SIZE, --2.28.0
Cheers,
Victor
Re: [PATCH 3/3] usbredir: avoid queuing hello packet on snapshot restore
Quoted 20 lines · Victor Toso
Hi,
Quoted 10 lines · Joelle van Dyne
Quoted 9 lines · Victor Toso
Hi,
Quoted 4 lines · Joelle van Dyne
When launching QEMU with "-loadvm",
usbredir_create_parser()should avoid setting up the hello packet (just as with "-incoming". On the latest version of libusbredir,usbredirparser_unserialize()will return error if the parser is not "pristine."Quoted 5 lines
Quoted 2 lines
That was wrong in the usbredir side. The fix [0] was merged and included in the latest 0.13.0 release
This is good to know. Should the entire
runstate_checkinusbredir_create_parserbe removed?
Quoted 6 lines
From my POV your patch looks correct and would avoid migration issues such as [1] with usbredir 0.12.0 that was not patched
[1] https://bugzilla.redhat.com/show_bug.cgi?id=2096008
So, I'd keep the check and the patch :)
I have to admit I'm not too familiar with the inner workings of libusbredir. But is it desirable to skip the HELLO packet on "loadvm"? I wrote this on the assumption that it's correct because libusbredir enforces it, but if that's wrong, then I'm wondering if maybe we need the HELLO to re-establish communication (that was the issue I triaged with "-S", when USB devices did not work due to the HELLO packet not being sent). In a migration, it makes sense that a SPICE client has not reset the USB device. However, when re-starting QEMU with "-loadvm", it's possible the USB device has been disconnected and reconnected. Ideally, we report that to the guest and let it handle the reset. Would "usbredirparser_fl_no_hello" prevent that?
Quoted 30 lines
Quoted 16 lines
Quoted 16 lines
[0] https://gitlab.freedesktop.org/spice/usbredir/-/merge_requests/61
Quoted 13 lines
Signed-off-by Joelle van Dyne <[email protected]>--- hw/usb/redirect.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/usb/redirect.c +0
-0@@ -1280,7 +1280,8 @@ static void usbredir_create_parser(USBRedirDevice *dev) }#endif Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
hw/usb/redirect.c +2
-2-if (runstate_check (RUN_STATE_INMIGRATE )) { +if (runstate_check (RUN_STATE_INMIGRATE ) || +runstate_check (RUN_STATE_RESTORE_VM )) { flags |= usbredirparser_fl_no_hello; } usbredirparser_init(dev->parser, VERSION, caps, USB_REDIR_CAPS_SIZE, --2.28.0
Cheers,
Victor
Re: [PATCH 3/3] usbredir: avoid queuing hello packet on snapshot restore
Hi,
Quoted 24 lines · Joelle van Dyne
Quoted 23 lines · Victor Toso
Hi,
Quoted 10 lines · Joelle van Dyne
Quoted 9 lines · Victor Toso
Hi,
Quoted 4 lines · Joelle van Dyne
When launching QEMU with "-loadvm",
usbredir_create_parser()should avoid setting up the hello packet (just as with "-incoming". On the latest version of libusbredir,usbredirparser_unserialize()will return error if the parser is not "pristine."Quoted 5 lines
Quoted 2 lines
That was wrong in the usbredir side. The fix [0] was merged and included in the latest 0.13.0 release
This is good to know. Should the entire
runstate_checkinusbredir_create_parserbe removed?From my POV your patch looks correct and would avoid migration issues such as [1] with usbredir 0.12.0 that was not patched
Quoted 7 lines
Quoted 3 lines
[1] https://bugzilla.redhat.com/show_bug.cgi?id=2096008
So, I'd keep the check and the patch :)
I have to admit I'm not too familiar with the inner workings of libusbredir. But is it desirable to skip the HELLO packet on "loadvm"?
The hello package is to used for capabilities negotiation and then stablish a new connection.
Quoted 10 lines
I wrote this on the assumption that it's correct because libusbredir enforces it, but if that's wrong, then I'm wondering if maybe we need the HELLO to re-establish communication (that was the issue I triaged with "-S", when USB devices did not work due to the HELLO packet not being sent).
In a migration, it makes sense that a SPICE client has not reset the USB device. However, when re-starting QEMU with "-loadvm", it's possible the USB device has been disconnected and reconnected.
Yes, or it could be holding the device to reestablish the connection with the VM. Depends a bit on the backend? I'm not 100% sure.
If user was using a TCP backend and connecting to usbredirserver (or usbredirect running as a TCP server with --as) then I assume that QEMU would try to reconnect and keep going like migration.
Quoted 2 lines
Ideally, we report that to the guest and let it handle the reset. Would "
usbredirparser_fl_no_hello" prevent that?
usbredirparser_fl_no_hello is mainly meant for unserialization but it can also be used for the application to send/handle its own hello package too (used for emulated usb devices in spice-gtk [2]).
All in all, if the device is no longer available on loadvm(), at the point the VM is restarted, the guest should be notified similarly to when the device is being unplugged.
[2] https://gitlab.freedesktop.org/spice/spice-gtk/-/commit/78c5a2e93383bd21a121
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
[0] https://gitlab.freedesktop.org/spice/usbredir/-/merge_requests/61
Quoted 13 lines
Signed-off-by Joelle van Dyne <[email protected]>--- hw/usb/redirect.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/usb/redirect.c +0
-0@@ -1280,7 +1280,8 @@ static void usbredir_create_parser(USBRedirDevice *dev) }#endif
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
hw/usb/redirect.c +2
-2-if (runstate_check (RUN_STATE_INMIGRATE )) { +if (runstate_check (RUN_STATE_INMIGRATE ) || +runstate_check (RUN_STATE_RESTORE_VM )) { flags |= usbredirparser_fl_no_hello; } usbredirparser_init(dev->parser, VERSION, caps, USB_REDIR_CAPS_SIZE, --2.28.0
Cheers,
Victor