All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v6 0/2] qmp: 'wakeup-suspend-support' in query-target
@ 2018-05-15 14:09 Daniel Henrique Barboza
  2018-05-15 14:09 ` [Qemu-devel] [PATCH v6 1/2] qmp: adding " Daniel Henrique Barboza
  2018-05-15 14:09 ` [Qemu-devel] [PATCH v6 2/2] qga: update guest-suspend-ram and guest-suspend-hybrid descriptions Daniel Henrique Barboza
  0 siblings, 2 replies; 10+ messages in thread
From: Daniel Henrique Barboza @ 2018-05-15 14:09 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, dgilbert, eblake, Daniel Henrique Barboza

v6:
- rebased with current master after being buried for a few months
- previous version link:
https://lists.gnu.org/archive/html/qemu-devel/2018-02/msg04882.html

v5:
- removed a paragraph in the recently added qemu_register_wakeup_notifier
comment that was added. That paragraph was adding too much in-depth
information about the current design of the system_wakeup, making it
harder to understand the whole point (suggested by Mike Roth).
- previous version link:
https://lists.nongnu.org/archive/html/qemu-devel/2018-01/msg00879.html 

v4:
- added a comment in 'qemu_register_wakeup_notifier' about the effects
of adding a wakeup notifier without proper suspend/wakeup support in the
logic of the new wakeup-suspend-support flag, as suggested by Mike Roth
- previous version link:
https://lists.gnu.org/archive/html/qemu-devel/2018-01/msg00358.html

v3:
- added a "(since 2.12)" notation in the new flag, as suggested by
Eric Blake
- added a "backwards compatible" note in the commit msg
- previous version link:
https://lists.gnu.org/archive/html/qemu-devel/2018-01/msg00093.html

v2:
- changed the approach based on v1 discussions: instead of a new API, add
the required flag in QMP query-target
- dropped patch 2 since query-target does not have an HMP counterpart
- previous version link:
https://lists.gnu.org/archive/html/qemu-devel/2017-12/msg00889.html


Daniel Henrique Barboza (2):
  qmp: adding 'wakeup-suspend-support' in query-target
  qga: update guest-suspend-ram and guest-suspend-hybrid descriptions

 arch_init.c             |  1 +
 include/sysemu/sysemu.h |  1 +
 qapi/misc.json          |  4 +++-
 qga/qapi-schema.json    | 14 ++++++++++----
 vl.c                    | 21 +++++++++++++++++++++
 5 files changed, 36 insertions(+), 5 deletions(-)

-- 
2.14.3

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Qemu-devel] [PATCH v6 1/2] qmp: adding 'wakeup-suspend-support' in query-target
  2018-05-15 14:09 [Qemu-devel] [PATCH v6 0/2] qmp: 'wakeup-suspend-support' in query-target Daniel Henrique Barboza
@ 2018-05-15 14:09 ` Daniel Henrique Barboza
  2018-05-15 15:45   ` Markus Armbruster
  2018-05-15 14:09 ` [Qemu-devel] [PATCH v6 2/2] qga: update guest-suspend-ram and guest-suspend-hybrid descriptions Daniel Henrique Barboza
  1 sibling, 1 reply; 10+ messages in thread
From: Daniel Henrique Barboza @ 2018-05-15 14:09 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, dgilbert, eblake, Daniel Henrique Barboza

When issuing the qmp/hmp 'system_wakeup' command, what happens in a
nutshell is:

- qmp_system_wakeup_request set runstate to RUNNING, sets a wakeup_reason
and notify the event
- in the main_loop, all vcpus are paused, a system reset is issued, all
subscribers of wakeup_notifiers receives a notification, vcpus are then
resumed and the wake up QAPI event is fired

Note that this procedure alone doesn't ensure that the guest will awake
from SUSPENDED state - the subscribers of the wake up event must take
action to resume the guest, otherwise the guest will simply reboot.

At this moment there are only two subscribers of the wake up event: one
in hw/acpi/core.c and another one in hw/i386/xen/xen-hvm.c. This means
that system_wakeup does not work as intended with other architectures.

However, only the presence of 'system_wakeup' is required for QGA to
support 'guest-suspend-ram' and 'guest-suspend-hybrid' at this moment.
This means that the user/management will expect to suspend the guest using
one of those suspend commands and then resume execution using system_wakeup,
regardless of the support offered in system_wakeup in the first place.

This patch adds a new flag called 'wakeup-suspend-support' in TargetInfo
that allows the caller to query if the guest supports wake up from
suspend via system_wakeup. It goes over the subscribers of the wake up
event and, if it's empty, it assumes that the guest does not support
wake up from suspend (and thus, pm-suspend itself).

This is the expected output of query-target when running a x86 guest:

{"execute" : "query-target"}
{"return": {"arch": "x86_64", "wakeup-suspend-support": true}}

This is the output when running a pseries guest:

{"execute" : "query-target"}
{"return": {"arch": "ppc64", "wakeup-suspend-support": false}}

Given that the TargetInfo structure is read-only, adding a new flag to
it is backwards compatible. There is no need to deprecate the old
TargetInfo format.

With this extra tool, management can avoid situations where a guest
that does not have proper suspend/wake capabilities ends up in
inconsistent state (e.g.
https://github.com/open-power-host-os/qemu/issues/31).

Reported-by: Balamuruhan S <bala24@linux.vnet.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb@linux.ibm.com>
---
 arch_init.c             |  1 +
 include/sysemu/sysemu.h |  1 +
 qapi/misc.json          |  4 +++-
 vl.c                    | 21 +++++++++++++++++++++
 4 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/arch_init.c b/arch_init.c
index 9597218ced..67bdf27528 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -115,6 +115,7 @@ TargetInfo *qmp_query_target(Error **errp)
 
     info->arch = qapi_enum_parse(&SysEmuTarget_lookup, TARGET_NAME, -1,
                                  &error_abort);
+    info->wakeup_suspend_support = !qemu_wakeup_notifier_is_empty();
 
     return info;
 }
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 544ab77a2b..fbe2a3373e 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -69,6 +69,7 @@ typedef enum WakeupReason {
 void qemu_system_reset_request(ShutdownCause reason);
 void qemu_system_suspend_request(void);
 void qemu_register_suspend_notifier(Notifier *notifier);
+bool qemu_wakeup_notifier_is_empty(void);
 void qemu_system_wakeup_request(WakeupReason reason);
 void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
 void qemu_register_wakeup_notifier(Notifier *notifier);
diff --git a/qapi/misc.json b/qapi/misc.json
index f5988cc0b5..a385d897ae 100644
--- a/qapi/misc.json
+++ b/qapi/misc.json
@@ -2484,11 +2484,13 @@
 # Information describing the QEMU target.
 #
 # @arch: the target architecture
+# @wakeup-suspend-support: true if the target supports wake up from
+#                          suspend (since 2.13)
 #
 # Since: 1.2.0
 ##
 { 'struct': 'TargetInfo',
-  'data': { 'arch': 'SysEmuTarget' } }
+  'data': { 'arch': 'SysEmuTarget', 'wakeup-suspend-support': 'bool' } }
 
 ##
 # @query-target:
diff --git a/vl.c b/vl.c
index 3b39bbd7a8..ab6bd7e090 100644
--- a/vl.c
+++ b/vl.c
@@ -1832,11 +1832,32 @@ void qemu_system_wakeup_enable(WakeupReason reason, bool enabled)
     }
 }
 
+/* The existence of a wake-up notifier is being checked in the function
+ * qemu_wakeup_notifier_is_empty and it's used in the logic of the
+ * wakeup-suspend-support flag of QMP 'query-target' command. The idea
+ * of this flag is to indicate whether the guest supports wake-up from
+ * suspend (via system_wakeup QMP/HMP call for example), warning the user
+ * that the guest can't handle both wake-up from suspend and the suspend
+ * itself via QGA guest-suspend-ram and guest-suspend-hybrid (if it
+ * can't wake up, it can't be suspended safely).
+ *
+ * An assumption is made by the wakeup-suspend-support flag that only the
+ * guests that can go to RUN_STATE_SUSPENDED and wake up properly would
+ * be interested in this wakeup_notifier. Adding a wakeup_notifier for
+ * any other reason will break the logic of the wakeup-suspend-support
+ * flag and can lead to user/management confusion about the suspend/wake-up
+ * support of the guest.
+ */
 void qemu_register_wakeup_notifier(Notifier *notifier)
 {
     notifier_list_add(&wakeup_notifiers, notifier);
 }
 
+bool qemu_wakeup_notifier_is_empty(void)
+{
+    return QLIST_EMPTY(&wakeup_notifiers.notifiers);
+}
+
 void qemu_system_killed(int signal, pid_t pid)
 {
     shutdown_signal = signal;
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Qemu-devel] [PATCH v6 2/2] qga: update guest-suspend-ram and guest-suspend-hybrid descriptions
  2018-05-15 14:09 [Qemu-devel] [PATCH v6 0/2] qmp: 'wakeup-suspend-support' in query-target Daniel Henrique Barboza
  2018-05-15 14:09 ` [Qemu-devel] [PATCH v6 1/2] qmp: adding " Daniel Henrique Barboza
@ 2018-05-15 14:09 ` Daniel Henrique Barboza
  2018-05-15 15:35   ` Markus Armbruster
  1 sibling, 1 reply; 10+ messages in thread
From: Daniel Henrique Barboza @ 2018-05-15 14:09 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, armbru, dgilbert, eblake, Daniel Henrique Barboza

This patch updates the descriptions of 'guest-suspend-ram' and
'guest-suspend-hybrid' to mention that both commands relies now
on the existence of 'system_wakeup' and also on the proper support
for wake up from suspend, retrieved by the 'wakeup-suspend-support'
attribute of the 'query-target' QMP command.

Reported-by: Balamuruhan S <bala24@linux.vnet.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb@linux.ibm.com>
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 qga/qapi-schema.json | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
index 17884c7c70..e3fb8adfce 100644
--- a/qga/qapi-schema.json
+++ b/qga/qapi-schema.json
@@ -566,8 +566,11 @@
 # package installed in the guest.
 #
 # IMPORTANT: guest-suspend-ram requires QEMU to support the 'system_wakeup'
-# command.  Thus, it's *required* to query QEMU for the presence of the
-# 'system_wakeup' command before issuing guest-suspend-ram.
+# command and the guest to support wake up from suspend. Thus, it's
+# *required* to query QEMU for the presence of the 'system_wakeup' command
+# and to verify that wake up from suspend is enabled by checking the
+# 'wakeup-suspend-support' flag of 'query-target' QMP command, before issuing
+# guest-suspend-ram.
 #
 # This command does NOT return a response on success. There are two options
 # to check for success:
@@ -593,8 +596,11 @@
 # This command requires the pm-utils package to be installed in the guest.
 #
 # IMPORTANT: guest-suspend-hybrid requires QEMU to support the 'system_wakeup'
-# command.  Thus, it's *required* to query QEMU for the presence of the
-# 'system_wakeup' command before issuing guest-suspend-hybrid.
+# command and the guest to support wake up from suspend. Thus, it's
+# *required* to query QEMU for the presence of the 'system_wakeup' command
+# and to verify that wake up from suspend is enabled by checking the
+# 'wakeup-suspend-support' flag of 'query-target' QMP command, before issuing
+# guest-suspend-hybrid.
 #
 # This command does NOT return a response on success. There are two options
 # to check for success:
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH v6 2/2] qga: update guest-suspend-ram and guest-suspend-hybrid descriptions
  2018-05-15 14:09 ` [Qemu-devel] [PATCH v6 2/2] qga: update guest-suspend-ram and guest-suspend-hybrid descriptions Daniel Henrique Barboza
@ 2018-05-15 15:35   ` Markus Armbruster
  2018-05-16 13:49     ` Daniel Henrique Barboza
  0 siblings, 1 reply; 10+ messages in thread
From: Markus Armbruster @ 2018-05-15 15:35 UTC (permalink / raw)
  To: Daniel Henrique Barboza; +Cc: qemu-devel, mdroth, dgilbert

Daniel Henrique Barboza <danielhb@linux.ibm.com> writes:

> This patch updates the descriptions of 'guest-suspend-ram' and
> 'guest-suspend-hybrid' to mention that both commands relies now
> on the existence of 'system_wakeup' and also on the proper support
> for wake up from suspend, retrieved by the 'wakeup-suspend-support'
> attribute of the 'query-target' QMP command.
>
> Reported-by: Balamuruhan S <bala24@linux.vnet.ibm.com>
> Signed-off-by: Daniel Henrique Barboza <danielhb@linux.ibm.com>
> Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
> ---
>  qga/qapi-schema.json | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
> index 17884c7c70..e3fb8adfce 100644
> --- a/qga/qapi-schema.json
> +++ b/qga/qapi-schema.json
> @@ -566,8 +566,11 @@
>  # package installed in the guest.
>  #
>  # IMPORTANT: guest-suspend-ram requires QEMU to support the 'system_wakeup'
> -# command.  Thus, it's *required* to query QEMU for the presence of the
> -# 'system_wakeup' command before issuing guest-suspend-ram.
> +# command and the guest to support wake up from suspend. Thus, it's
> +# *required* to query QEMU for the presence of the 'system_wakeup' command
> +# and to verify that wake up from suspend is enabled by checking the
> +# 'wakeup-suspend-support' flag of 'query-target' QMP command, before issuing
> +# guest-suspend-ram.

Isn't checking for presence of system_wakeup redundant?

When query-target tells us "system_wakeup works" by returning
wakeup-suspend-support: true, we surely have system_wakeup (or else
query-target would be lying to us).

When it returns wakeup-suspend-support: false, it doesn't matter whether
we have system_wakeup.

Unless I'm wrong, we can simplify this to something like

   # IMPORTANT: guest-suspend-ram requires working wakeup support in
   # QEMU.  You *must* check QMP command query-target returns
   # wakeup-suspend-support: true before issuing this command.

>  #
>  # This command does NOT return a response on success. There are two options
>  # to check for success:
> @@ -593,8 +596,11 @@
>  # This command requires the pm-utils package to be installed in the guest.
>  #
>  # IMPORTANT: guest-suspend-hybrid requires QEMU to support the 'system_wakeup'
> -# command.  Thus, it's *required* to query QEMU for the presence of the
> -# 'system_wakeup' command before issuing guest-suspend-hybrid.
> +# command and the guest to support wake up from suspend. Thus, it's
> +# *required* to query QEMU for the presence of the 'system_wakeup' command
> +# and to verify that wake up from suspend is enabled by checking the
> +# 'wakeup-suspend-support' flag of 'query-target' QMP command, before issuing
> +# guest-suspend-hybrid.
>  #
>  # This command does NOT return a response on success. There are two options
>  # to check for success:

Likewise.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH v6 1/2] qmp: adding 'wakeup-suspend-support' in query-target
  2018-05-15 14:09 ` [Qemu-devel] [PATCH v6 1/2] qmp: adding " Daniel Henrique Barboza
@ 2018-05-15 15:45   ` Markus Armbruster
  2018-05-16 13:13     ` Daniel Henrique Barboza
  0 siblings, 1 reply; 10+ messages in thread
From: Markus Armbruster @ 2018-05-15 15:45 UTC (permalink / raw)
  To: Daniel Henrique Barboza; +Cc: qemu-devel, mdroth, dgilbert

Daniel Henrique Barboza <danielhb@linux.ibm.com> writes:

> When issuing the qmp/hmp 'system_wakeup' command, what happens in a
> nutshell is:
>
> - qmp_system_wakeup_request set runstate to RUNNING, sets a wakeup_reason
> and notify the event
> - in the main_loop, all vcpus are paused, a system reset is issued, all
> subscribers of wakeup_notifiers receives a notification, vcpus are then
> resumed and the wake up QAPI event is fired
>
> Note that this procedure alone doesn't ensure that the guest will awake
> from SUSPENDED state - the subscribers of the wake up event must take
> action to resume the guest, otherwise the guest will simply reboot.
>
> At this moment there are only two subscribers of the wake up event: one
> in hw/acpi/core.c and another one in hw/i386/xen/xen-hvm.c. This means
> that system_wakeup does not work as intended with other architectures.
>
> However, only the presence of 'system_wakeup' is required for QGA to
> support 'guest-suspend-ram' and 'guest-suspend-hybrid' at this moment.
> This means that the user/management will expect to suspend the guest using
> one of those suspend commands and then resume execution using system_wakeup,
> regardless of the support offered in system_wakeup in the first place.
>
> This patch adds a new flag called 'wakeup-suspend-support' in TargetInfo
> that allows the caller to query if the guest supports wake up from
> suspend via system_wakeup. It goes over the subscribers of the wake up
> event and, if it's empty, it assumes that the guest does not support
> wake up from suspend (and thus, pm-suspend itself).
>
> This is the expected output of query-target when running a x86 guest:
>
> {"execute" : "query-target"}
> {"return": {"arch": "x86_64", "wakeup-suspend-support": true}}
>
> This is the output when running a pseries guest:
>
> {"execute" : "query-target"}
> {"return": {"arch": "ppc64", "wakeup-suspend-support": false}}
>
> Given that the TargetInfo structure is read-only, adding a new flag to
> it is backwards compatible. There is no need to deprecate the old
> TargetInfo format.
>
> With this extra tool, management can avoid situations where a guest
> that does not have proper suspend/wake capabilities ends up in
> inconsistent state (e.g.
> https://github.com/open-power-host-os/qemu/issues/31).
>
> Reported-by: Balamuruhan S <bala24@linux.vnet.ibm.com>
> Signed-off-by: Daniel Henrique Barboza <danielhb@linux.ibm.com>
> ---
>  arch_init.c             |  1 +
>  include/sysemu/sysemu.h |  1 +
>  qapi/misc.json          |  4 +++-
>  vl.c                    | 21 +++++++++++++++++++++
>  4 files changed, 26 insertions(+), 1 deletion(-)
>
> diff --git a/arch_init.c b/arch_init.c
> index 9597218ced..67bdf27528 100644
> --- a/arch_init.c
> +++ b/arch_init.c
> @@ -115,6 +115,7 @@ TargetInfo *qmp_query_target(Error **errp)
>  
>      info->arch = qapi_enum_parse(&SysEmuTarget_lookup, TARGET_NAME, -1,
>                                   &error_abort);
> +    info->wakeup_suspend_support = !qemu_wakeup_notifier_is_empty();

Huh?  Hmm, see "hack" below.

>  
>      return info;
>  }
> diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
> index 544ab77a2b..fbe2a3373e 100644
> --- a/include/sysemu/sysemu.h
> +++ b/include/sysemu/sysemu.h
> @@ -69,6 +69,7 @@ typedef enum WakeupReason {
>  void qemu_system_reset_request(ShutdownCause reason);
>  void qemu_system_suspend_request(void);
>  void qemu_register_suspend_notifier(Notifier *notifier);
> +bool qemu_wakeup_notifier_is_empty(void);
>  void qemu_system_wakeup_request(WakeupReason reason);
>  void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
>  void qemu_register_wakeup_notifier(Notifier *notifier);
> diff --git a/qapi/misc.json b/qapi/misc.json
> index f5988cc0b5..a385d897ae 100644
> --- a/qapi/misc.json
> +++ b/qapi/misc.json
> @@ -2484,11 +2484,13 @@
>  # Information describing the QEMU target.
>  #
>  # @arch: the target architecture
> +# @wakeup-suspend-support: true if the target supports wake up from
> +#                          suspend (since 2.13)
>  #
>  # Since: 1.2.0
>  ##
>  { 'struct': 'TargetInfo',
> -  'data': { 'arch': 'SysEmuTarget' } }
> +  'data': { 'arch': 'SysEmuTarget', 'wakeup-suspend-support': 'bool' } }
>  
>  ##
>  # @query-target:

Does the documentation of system_wakeup need fixing?

   ##
   # @system_wakeup:
   #
   # Wakeup guest from suspend.  Does nothing in case the guest isn't suspended.
   #
   # Since:  1.1
   #
   # Returns:  nothing.
   #
   # Example:
   #
   # -> { "execute": "system_wakeup" }
   # <- { "return": {} }
   #
   ##
   { 'command': 'system_wakeup' }

I figure we better explain right here what the command does, both for
wakeup-suspend-support: false and true.

> diff --git a/vl.c b/vl.c
> index 3b39bbd7a8..ab6bd7e090 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -1832,11 +1832,32 @@ void qemu_system_wakeup_enable(WakeupReason reason, bool enabled)
>      }
>  }
>  
> +/* The existence of a wake-up notifier is being checked in the function

Please wing both ends of this comment:

   /*
    * The existence of a wake-up notifier is being checked in the function

> + * qemu_wakeup_notifier_is_empty and it's used in the logic of the
> + * wakeup-suspend-support flag of QMP 'query-target' command. The idea
> + * of this flag is to indicate whether the guest supports wake-up from
> + * suspend (via system_wakeup QMP/HMP call for example), warning the user
> + * that the guest can't handle both wake-up from suspend and the suspend
> + * itself via QGA guest-suspend-ram and guest-suspend-hybrid (if it
> + * can't wake up, it can't be suspended safely).
> + *
> + * An assumption is made by the wakeup-suspend-support flag that only the
> + * guests that can go to RUN_STATE_SUSPENDED and wake up properly would
> + * be interested in this wakeup_notifier. Adding a wakeup_notifier for
> + * any other reason will break the logic of the wakeup-suspend-support
> + * flag and can lead to user/management confusion about the suspend/wake-up
> + * support of the guest.
> + */

The assumption is a bit of a hack, but I don't have better ideas.
Thanks for commenting it clearly.  However, ...

>  void qemu_register_wakeup_notifier(Notifier *notifier)
>  {
>      notifier_list_add(&wakeup_notifiers, notifier);
>  }
>  
> +bool qemu_wakeup_notifier_is_empty(void)
> +{
> +    return QLIST_EMPTY(&wakeup_notifiers.notifiers);
> +}
> +
>  void qemu_system_killed(int signal, pid_t pid)
>  {
>      shutdown_signal = signal;

... I'd recommend to rename qemu_wakeup_notifier_is_empty() to
qemu_wakeup_suspend_support(), because then the hack is a bit more
isolated.  With the current name, it spills into qmp_query_target(),
which doesn't have such a helpful comment.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH v6 1/2] qmp: adding 'wakeup-suspend-support' in query-target
  2018-05-15 15:45   ` Markus Armbruster
@ 2018-05-16 13:13     ` Daniel Henrique Barboza
  2018-05-17  8:44       ` Markus Armbruster
  0 siblings, 1 reply; 10+ messages in thread
From: Daniel Henrique Barboza @ 2018-05-16 13:13 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: qemu-devel, mdroth, dgilbert



On 05/15/2018 12:45 PM, Markus Armbruster wrote:
> Daniel Henrique Barboza <danielhb@linux.ibm.com> writes:
>
>> When issuing the qmp/hmp 'system_wakeup' command, what happens in a
>> nutshell is:
>>
>> - qmp_system_wakeup_request set runstate to RUNNING, sets a wakeup_reason
>> and notify the event
>> - in the main_loop, all vcpus are paused, a system reset is issued, all
>> subscribers of wakeup_notifiers receives a notification, vcpus are then
>> resumed and the wake up QAPI event is fired
>>
>> Note that this procedure alone doesn't ensure that the guest will awake
>> from SUSPENDED state - the subscribers of the wake up event must take
>> action to resume the guest, otherwise the guest will simply reboot.
>>
>> At this moment there are only two subscribers of the wake up event: one
>> in hw/acpi/core.c and another one in hw/i386/xen/xen-hvm.c. This means
>> that system_wakeup does not work as intended with other architectures.
>>
>> However, only the presence of 'system_wakeup' is required for QGA to
>> support 'guest-suspend-ram' and 'guest-suspend-hybrid' at this moment.
>> This means that the user/management will expect to suspend the guest using
>> one of those suspend commands and then resume execution using system_wakeup,
>> regardless of the support offered in system_wakeup in the first place.
>>
>> This patch adds a new flag called 'wakeup-suspend-support' in TargetInfo
>> that allows the caller to query if the guest supports wake up from
>> suspend via system_wakeup. It goes over the subscribers of the wake up
>> event and, if it's empty, it assumes that the guest does not support
>> wake up from suspend (and thus, pm-suspend itself).
>>
>> This is the expected output of query-target when running a x86 guest:
>>
>> {"execute" : "query-target"}
>> {"return": {"arch": "x86_64", "wakeup-suspend-support": true}}
>>
>> This is the output when running a pseries guest:
>>
>> {"execute" : "query-target"}
>> {"return": {"arch": "ppc64", "wakeup-suspend-support": false}}
>>
>> Given that the TargetInfo structure is read-only, adding a new flag to
>> it is backwards compatible. There is no need to deprecate the old
>> TargetInfo format.
>>
>> With this extra tool, management can avoid situations where a guest
>> that does not have proper suspend/wake capabilities ends up in
>> inconsistent state (e.g.
>> https://github.com/open-power-host-os/qemu/issues/31).
>>
>> Reported-by: Balamuruhan S <bala24@linux.vnet.ibm.com>
>> Signed-off-by: Daniel Henrique Barboza <danielhb@linux.ibm.com>
>> ---
>>   arch_init.c             |  1 +
>>   include/sysemu/sysemu.h |  1 +
>>   qapi/misc.json          |  4 +++-
>>   vl.c                    | 21 +++++++++++++++++++++
>>   4 files changed, 26 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch_init.c b/arch_init.c
>> index 9597218ced..67bdf27528 100644
>> --- a/arch_init.c
>> +++ b/arch_init.c
>> @@ -115,6 +115,7 @@ TargetInfo *qmp_query_target(Error **errp)
>>   
>>       info->arch = qapi_enum_parse(&SysEmuTarget_lookup, TARGET_NAME, -1,
>>                                    &error_abort);
>> +    info->wakeup_suspend_support = !qemu_wakeup_notifier_is_empty();
> Huh?  Hmm, see "hack" below.
>
>>   
>>       return info;
>>   }
>> diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
>> index 544ab77a2b..fbe2a3373e 100644
>> --- a/include/sysemu/sysemu.h
>> +++ b/include/sysemu/sysemu.h
>> @@ -69,6 +69,7 @@ typedef enum WakeupReason {
>>   void qemu_system_reset_request(ShutdownCause reason);
>>   void qemu_system_suspend_request(void);
>>   void qemu_register_suspend_notifier(Notifier *notifier);
>> +bool qemu_wakeup_notifier_is_empty(void);
>>   void qemu_system_wakeup_request(WakeupReason reason);
>>   void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
>>   void qemu_register_wakeup_notifier(Notifier *notifier);
>> diff --git a/qapi/misc.json b/qapi/misc.json
>> index f5988cc0b5..a385d897ae 100644
>> --- a/qapi/misc.json
>> +++ b/qapi/misc.json
>> @@ -2484,11 +2484,13 @@
>>   # Information describing the QEMU target.
>>   #
>>   # @arch: the target architecture
>> +# @wakeup-suspend-support: true if the target supports wake up from
>> +#                          suspend (since 2.13)
>>   #
>>   # Since: 1.2.0
>>   ##
>>   { 'struct': 'TargetInfo',
>> -  'data': { 'arch': 'SysEmuTarget' } }
>> +  'data': { 'arch': 'SysEmuTarget', 'wakeup-suspend-support': 'bool' } }
>>   
>>   ##
>>   # @query-target:
> Does the documentation of system_wakeup need fixing?
>
>     ##
>     # @system_wakeup:
>     #
>     # Wakeup guest from suspend.  Does nothing in case the guest isn't suspended.
>     #
>     # Since:  1.1
>     #
>     # Returns:  nothing.
>     #
>     # Example:
>     #
>     # -> { "execute": "system_wakeup" }
>     # <- { "return": {} }
>     #
>     ##
>     { 'command': 'system_wakeup' }
>
> I figure we better explain right here what the command does, both for
> wakeup-suspend-support: false and true.

Hmm, I've re-sent a patch that changes a bit the behavior of system_wakeup
yesterday. The command should now fail with an error if the VM isn't in
SUSPENDED state. However, I failed to update this documentation
in that patch.

What if I resend that system_wakeup patch with the updated documentation 
such
as:


    ##
    # @system_wakeup:
    #
    # Wakeup guest from suspend.  Throws an error in case the guest isn't suspended.
    #
    # Since:  1.1
    #
    # Returns:  nothing if succeed
    #


And then I believe we don't need to update this doc again - if the guest 
isn't suspended,
  system_wakeup will still fire up an error.

In fact, I could have added that patch in this series too since it kind 
of relates with these
changes as well. Let me know if you think it helps and I'll respin it 
together with this
series.

>> diff --git a/vl.c b/vl.c
>> index 3b39bbd7a8..ab6bd7e090 100644
>> --- a/vl.c
>> +++ b/vl.c
>> @@ -1832,11 +1832,32 @@ void qemu_system_wakeup_enable(WakeupReason reason, bool enabled)
>>       }
>>   }
>>   
>> +/* The existence of a wake-up notifier is being checked in the function
> Please wing both ends of this comment:
>
>     /*
>      * The existence of a wake-up notifier is being checked in the function

ok!

>
>> + * qemu_wakeup_notifier_is_empty and it's used in the logic of the
>> + * wakeup-suspend-support flag of QMP 'query-target' command. The idea
>> + * of this flag is to indicate whether the guest supports wake-up from
>> + * suspend (via system_wakeup QMP/HMP call for example), warning the user
>> + * that the guest can't handle both wake-up from suspend and the suspend
>> + * itself via QGA guest-suspend-ram and guest-suspend-hybrid (if it
>> + * can't wake up, it can't be suspended safely).
>> + *
>> + * An assumption is made by the wakeup-suspend-support flag that only the
>> + * guests that can go to RUN_STATE_SUSPENDED and wake up properly would
>> + * be interested in this wakeup_notifier. Adding a wakeup_notifier for
>> + * any other reason will break the logic of the wakeup-suspend-support
>> + * flag and can lead to user/management confusion about the suspend/wake-up
>> + * support of the guest.
>> + */
> The assumption is a bit of a hack, but I don't have better ideas.
> Thanks for commenting it clearly.  However, ...
>
>>   void qemu_register_wakeup_notifier(Notifier *notifier)
>>   {
>>       notifier_list_add(&wakeup_notifiers, notifier);
>>   }
>>   
>> +bool qemu_wakeup_notifier_is_empty(void)
>> +{
>> +    return QLIST_EMPTY(&wakeup_notifiers.notifiers);
>> +}
>> +
>>   void qemu_system_killed(int signal, pid_t pid)
>>   {
>>       shutdown_signal = signal;
> ... I'd recommend to rename qemu_wakeup_notifier_is_empty() to
> qemu_wakeup_suspend_support(), because then the hack is a bit more
> isolated.  With the current name, it spills into qmp_query_target(),
> which doesn't have such a helpful comment.

I'll rename it in the next spin.

>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH v6 2/2] qga: update guest-suspend-ram and guest-suspend-hybrid descriptions
  2018-05-15 15:35   ` Markus Armbruster
@ 2018-05-16 13:49     ` Daniel Henrique Barboza
  2018-05-17  8:26       ` Markus Armbruster
  0 siblings, 1 reply; 10+ messages in thread
From: Daniel Henrique Barboza @ 2018-05-16 13:49 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: qemu-devel, mdroth, dgilbert



On 05/15/2018 12:35 PM, Markus Armbruster wrote:
> Daniel Henrique Barboza <danielhb@linux.ibm.com> writes:
>
>> This patch updates the descriptions of 'guest-suspend-ram' and
>> 'guest-suspend-hybrid' to mention that both commands relies now
>> on the existence of 'system_wakeup' and also on the proper support
>> for wake up from suspend, retrieved by the 'wakeup-suspend-support'
>> attribute of the 'query-target' QMP command.
>>
>> Reported-by: Balamuruhan S <bala24@linux.vnet.ibm.com>
>> Signed-off-by: Daniel Henrique Barboza <danielhb@linux.ibm.com>
>> Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
>> ---
>>   qga/qapi-schema.json | 14 ++++++++++----
>>   1 file changed, 10 insertions(+), 4 deletions(-)
>>
>> diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
>> index 17884c7c70..e3fb8adfce 100644
>> --- a/qga/qapi-schema.json
>> +++ b/qga/qapi-schema.json
>> @@ -566,8 +566,11 @@
>>   # package installed in the guest.
>>   #
>>   # IMPORTANT: guest-suspend-ram requires QEMU to support the 'system_wakeup'
>> -# command.  Thus, it's *required* to query QEMU for the presence of the
>> -# 'system_wakeup' command before issuing guest-suspend-ram.
>> +# command and the guest to support wake up from suspend. Thus, it's
>> +# *required* to query QEMU for the presence of the 'system_wakeup' command
>> +# and to verify that wake up from suspend is enabled by checking the
>> +# 'wakeup-suspend-support' flag of 'query-target' QMP command, before issuing
>> +# guest-suspend-ram.
> Isn't checking for presence of system_wakeup redundant?
>
> When query-target tells us "system_wakeup works" by returning
> wakeup-suspend-support: true, we surely have system_wakeup (or else
> query-target would be lying to us).
>
> When it returns wakeup-suspend-support: false, it doesn't matter whether
> we have system_wakeup.
>
> Unless I'm wrong, we can simplify this to something like
>
>     # IMPORTANT: guest-suspend-ram requires working wakeup support in
>     # QEMU.  You *must* check QMP command query-target returns
>     # wakeup-suspend-support: true before issuing this command.

It is worth noticing that this API isn't checking for the existence of
system_wakeup. It is checking whether there are notifiers added in
the wakeup_notifiers QLIST.

However, I think we can simplify the text as you suggested because that
part seems outdated anyway. Is there any relevant scenario where
system_wakeup will not be present?



>>   #
>>   # This command does NOT return a response on success. There are two options
>>   # to check for success:
>> @@ -593,8 +596,11 @@
>>   # This command requires the pm-utils package to be installed in the guest.
>>   #
>>   # IMPORTANT: guest-suspend-hybrid requires QEMU to support the 'system_wakeup'
>> -# command.  Thus, it's *required* to query QEMU for the presence of the
>> -# 'system_wakeup' command before issuing guest-suspend-hybrid.
>> +# command and the guest to support wake up from suspend. Thus, it's
>> +# *required* to query QEMU for the presence of the 'system_wakeup' command
>> +# and to verify that wake up from suspend is enabled by checking the
>> +# 'wakeup-suspend-support' flag of 'query-target' QMP command, before issuing
>> +# guest-suspend-hybrid.
>>   #
>>   # This command does NOT return a response on success. There are two options
>>   # to check for success:
> Likewise.
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH v6 2/2] qga: update guest-suspend-ram and guest-suspend-hybrid descriptions
  2018-05-16 13:49     ` Daniel Henrique Barboza
@ 2018-05-17  8:26       ` Markus Armbruster
  0 siblings, 0 replies; 10+ messages in thread
From: Markus Armbruster @ 2018-05-17  8:26 UTC (permalink / raw)
  To: Daniel Henrique Barboza; +Cc: qemu-devel, dgilbert, mdroth

Daniel Henrique Barboza <danielhb@linux.ibm.com> writes:

> On 05/15/2018 12:35 PM, Markus Armbruster wrote:
>> Daniel Henrique Barboza <danielhb@linux.ibm.com> writes:
>>
>>> This patch updates the descriptions of 'guest-suspend-ram' and
>>> 'guest-suspend-hybrid' to mention that both commands relies now
>>> on the existence of 'system_wakeup' and also on the proper support
>>> for wake up from suspend, retrieved by the 'wakeup-suspend-support'
>>> attribute of the 'query-target' QMP command.
>>>
>>> Reported-by: Balamuruhan S <bala24@linux.vnet.ibm.com>
>>> Signed-off-by: Daniel Henrique Barboza <danielhb@linux.ibm.com>
>>> Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
>>> ---
>>>   qga/qapi-schema.json | 14 ++++++++++----
>>>   1 file changed, 10 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
>>> index 17884c7c70..e3fb8adfce 100644
>>> --- a/qga/qapi-schema.json
>>> +++ b/qga/qapi-schema.json
>>> @@ -566,8 +566,11 @@
>>>   # package installed in the guest.
>>>   #
>>>   # IMPORTANT: guest-suspend-ram requires QEMU to support the 'system_wakeup'
>>> -# command.  Thus, it's *required* to query QEMU for the presence of the
>>> -# 'system_wakeup' command before issuing guest-suspend-ram.
>>> +# command and the guest to support wake up from suspend. Thus, it's
>>> +# *required* to query QEMU for the presence of the 'system_wakeup' command
>>> +# and to verify that wake up from suspend is enabled by checking the
>>> +# 'wakeup-suspend-support' flag of 'query-target' QMP command, before issuing
>>> +# guest-suspend-ram.
>> Isn't checking for presence of system_wakeup redundant?
>>
>> When query-target tells us "system_wakeup works" by returning
>> wakeup-suspend-support: true, we surely have system_wakeup (or else
>> query-target would be lying to us).
>>
>> When it returns wakeup-suspend-support: false, it doesn't matter whether
>> we have system_wakeup.
>>
>> Unless I'm wrong, we can simplify this to something like
>>
>>     # IMPORTANT: guest-suspend-ram requires working wakeup support in
>>     # QEMU.  You *must* check QMP command query-target returns
>>     # wakeup-suspend-support: true before issuing this command.
>
> It is worth noticing that this API isn't checking for the existence of
> system_wakeup. It is checking whether there are notifiers added in
> the wakeup_notifiers QLIST.
>
> However, I think we can simplify the text as you suggested because that
> part seems outdated anyway. Is there any relevant scenario where
> system_wakeup will not be present?

I doubt it: we have system_wakeup since 1.1, and we've even backported
it to RHEL-6.

But even if there *was* a relevant scenario involving a QEMU that
doesn't provide system_wakeup, that QEMU will also not provide member
wakeup-suspend-support, let alone tell us wakeup-suspend-support: true,
unless somebody set out to break things on purpose.  That somebody would
get to keep the pieces then.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH v6 1/2] qmp: adding 'wakeup-suspend-support' in query-target
  2018-05-16 13:13     ` Daniel Henrique Barboza
@ 2018-05-17  8:44       ` Markus Armbruster
  2018-05-17 12:35         ` Daniel Henrique Barboza
  0 siblings, 1 reply; 10+ messages in thread
From: Markus Armbruster @ 2018-05-17  8:44 UTC (permalink / raw)
  To: Daniel Henrique Barboza; +Cc: qemu-devel, dgilbert, mdroth

Daniel Henrique Barboza <danielhb@linux.ibm.com> writes:

> On 05/15/2018 12:45 PM, Markus Armbruster wrote:
>> Daniel Henrique Barboza <danielhb@linux.ibm.com> writes:
>>
>>> When issuing the qmp/hmp 'system_wakeup' command, what happens in a
>>> nutshell is:
>>>
>>> - qmp_system_wakeup_request set runstate to RUNNING, sets a wakeup_reason
>>> and notify the event
>>> - in the main_loop, all vcpus are paused, a system reset is issued, all
>>> subscribers of wakeup_notifiers receives a notification, vcpus are then
>>> resumed and the wake up QAPI event is fired
>>>
>>> Note that this procedure alone doesn't ensure that the guest will awake
>>> from SUSPENDED state - the subscribers of the wake up event must take
>>> action to resume the guest, otherwise the guest will simply reboot.
>>>
>>> At this moment there are only two subscribers of the wake up event: one
>>> in hw/acpi/core.c and another one in hw/i386/xen/xen-hvm.c. This means
>>> that system_wakeup does not work as intended with other architectures.
>>>
>>> However, only the presence of 'system_wakeup' is required for QGA to
>>> support 'guest-suspend-ram' and 'guest-suspend-hybrid' at this moment.
>>> This means that the user/management will expect to suspend the guest using
>>> one of those suspend commands and then resume execution using system_wakeup,
>>> regardless of the support offered in system_wakeup in the first place.
>>>
>>> This patch adds a new flag called 'wakeup-suspend-support' in TargetInfo
>>> that allows the caller to query if the guest supports wake up from
>>> suspend via system_wakeup. It goes over the subscribers of the wake up
>>> event and, if it's empty, it assumes that the guest does not support
>>> wake up from suspend (and thus, pm-suspend itself).
>>>
>>> This is the expected output of query-target when running a x86 guest:
>>>
>>> {"execute" : "query-target"}
>>> {"return": {"arch": "x86_64", "wakeup-suspend-support": true}}
>>>
>>> This is the output when running a pseries guest:
>>>
>>> {"execute" : "query-target"}
>>> {"return": {"arch": "ppc64", "wakeup-suspend-support": false}}
>>>
>>> Given that the TargetInfo structure is read-only, adding a new flag to
>>> it is backwards compatible. There is no need to deprecate the old
>>> TargetInfo format.
>>>
>>> With this extra tool, management can avoid situations where a guest
>>> that does not have proper suspend/wake capabilities ends up in
>>> inconsistent state (e.g.
>>> https://github.com/open-power-host-os/qemu/issues/31).
>>>
>>> Reported-by: Balamuruhan S <bala24@linux.vnet.ibm.com>
>>> Signed-off-by: Daniel Henrique Barboza <danielhb@linux.ibm.com>
>>> ---
>>>   arch_init.c             |  1 +
>>>   include/sysemu/sysemu.h |  1 +
>>>   qapi/misc.json          |  4 +++-
>>>   vl.c                    | 21 +++++++++++++++++++++
>>>   4 files changed, 26 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/arch_init.c b/arch_init.c
>>> index 9597218ced..67bdf27528 100644
>>> --- a/arch_init.c
>>> +++ b/arch_init.c
>>> @@ -115,6 +115,7 @@ TargetInfo *qmp_query_target(Error **errp)
>>>         info->arch = qapi_enum_parse(&SysEmuTarget_lookup,
>>> TARGET_NAME, -1,
>>>                                    &error_abort);
>>> +    info->wakeup_suspend_support = !qemu_wakeup_notifier_is_empty();
>> Huh?  Hmm, see "hack" below.
>>
>>>         return info;
>>>   }
>>> diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
>>> index 544ab77a2b..fbe2a3373e 100644
>>> --- a/include/sysemu/sysemu.h
>>> +++ b/include/sysemu/sysemu.h
>>> @@ -69,6 +69,7 @@ typedef enum WakeupReason {
>>>   void qemu_system_reset_request(ShutdownCause reason);
>>>   void qemu_system_suspend_request(void);
>>>   void qemu_register_suspend_notifier(Notifier *notifier);
>>> +bool qemu_wakeup_notifier_is_empty(void);
>>>   void qemu_system_wakeup_request(WakeupReason reason);
>>>   void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
>>>   void qemu_register_wakeup_notifier(Notifier *notifier);
>>> diff --git a/qapi/misc.json b/qapi/misc.json
>>> index f5988cc0b5..a385d897ae 100644
>>> --- a/qapi/misc.json
>>> +++ b/qapi/misc.json
>>> @@ -2484,11 +2484,13 @@
>>>   # Information describing the QEMU target.
>>>   #
>>>   # @arch: the target architecture
>>> +# @wakeup-suspend-support: true if the target supports wake up from
>>> +#                          suspend (since 2.13)
>>>   #
>>>   # Since: 1.2.0
>>>   ##
>>>   { 'struct': 'TargetInfo',
>>> -  'data': { 'arch': 'SysEmuTarget' } }
>>> +  'data': { 'arch': 'SysEmuTarget', 'wakeup-suspend-support': 'bool' } }
>>>     ##
>>>   # @query-target:
>> Does the documentation of system_wakeup need fixing?
>>
>>     ##
>>     # @system_wakeup:
>>     #
>>     # Wakeup guest from suspend.  Does nothing in case the guest isn't suspended.
>>     #
>>     # Since:  1.1
>>     #
>>     # Returns:  nothing.
>>     #
>>     # Example:
>>     #
>>     # -> { "execute": "system_wakeup" }
>>     # <- { "return": {} }
>>     #
>>     ##
>>     { 'command': 'system_wakeup' }
>>
>> I figure we better explain right here what the command does, both for
>> wakeup-suspend-support: false and true.
>
> Hmm, I've re-sent a patch that changes a bit the behavior of system_wakeup
> yesterday. The command should now fail with an error if the VM isn't in
> SUSPENDED state. However, I failed to update this documentation
> in that patch.
>
> What if I resend that system_wakeup patch with the updated
> documentation such
> as:
>
>
>    ##
>    # @system_wakeup:
>    #
>    # Wakeup guest from suspend.  Throws an error in case the guest isn't suspended.
>    #
>    # Since:  1.1
>    #
>    # Returns:  nothing if succeed
>    #
>
>
> And then I believe we don't need to update this doc again - if the
> guest isn't suspended,
>  system_wakeup will still fire up an error.

What about a guest that is suspended under a QEMU that isn't capable of
waking it?

Shouldn't system_wakeup's documentation point to query-target's
wakeup-suspend-support?

> In fact, I could have added that patch in this series too since it
> kind of relates with these
> changes as well. Let me know if you think it helps and I'll respin it
> together with this
> series.

Respinning in a single series is the simplest way to ensure the patches
get committed in a sane order.  I'd appreciate that.

[...]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH v6 1/2] qmp: adding 'wakeup-suspend-support' in query-target
  2018-05-17  8:44       ` Markus Armbruster
@ 2018-05-17 12:35         ` Daniel Henrique Barboza
  0 siblings, 0 replies; 10+ messages in thread
From: Daniel Henrique Barboza @ 2018-05-17 12:35 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: qemu-devel, dgilbert, mdroth



On 05/17/2018 05:44 AM, Markus Armbruster wrote:
> Daniel Henrique Barboza <danielhb@linux.ibm.com> writes:
>
>> On 05/15/2018 12:45 PM, Markus Armbruster wrote:
>>> Daniel Henrique Barboza <danielhb@linux.ibm.com> writes:
>>>
>>>> When issuing the qmp/hmp 'system_wakeup' command, what happens in a
>>>> nutshell is:
>>>>
>>>> - qmp_system_wakeup_request set runstate to RUNNING, sets a wakeup_reason
>>>> and notify the event
>>>> - in the main_loop, all vcpus are paused, a system reset is issued, all
>>>> subscribers of wakeup_notifiers receives a notification, vcpus are then
>>>> resumed and the wake up QAPI event is fired
>>>>
>>>> Note that this procedure alone doesn't ensure that the guest will awake
>>>> from SUSPENDED state - the subscribers of the wake up event must take
>>>> action to resume the guest, otherwise the guest will simply reboot.
>>>>
>>>> At this moment there are only two subscribers of the wake up event: one
>>>> in hw/acpi/core.c and another one in hw/i386/xen/xen-hvm.c. This means
>>>> that system_wakeup does not work as intended with other architectures.
>>>>
>>>> However, only the presence of 'system_wakeup' is required for QGA to
>>>> support 'guest-suspend-ram' and 'guest-suspend-hybrid' at this moment.
>>>> This means that the user/management will expect to suspend the guest using
>>>> one of those suspend commands and then resume execution using system_wakeup,
>>>> regardless of the support offered in system_wakeup in the first place.
>>>>
>>>> This patch adds a new flag called 'wakeup-suspend-support' in TargetInfo
>>>> that allows the caller to query if the guest supports wake up from
>>>> suspend via system_wakeup. It goes over the subscribers of the wake up
>>>> event and, if it's empty, it assumes that the guest does not support
>>>> wake up from suspend (and thus, pm-suspend itself).
>>>>
>>>> This is the expected output of query-target when running a x86 guest:
>>>>
>>>> {"execute" : "query-target"}
>>>> {"return": {"arch": "x86_64", "wakeup-suspend-support": true}}
>>>>
>>>> This is the output when running a pseries guest:
>>>>
>>>> {"execute" : "query-target"}
>>>> {"return": {"arch": "ppc64", "wakeup-suspend-support": false}}
>>>>
>>>> Given that the TargetInfo structure is read-only, adding a new flag to
>>>> it is backwards compatible. There is no need to deprecate the old
>>>> TargetInfo format.
>>>>
>>>> With this extra tool, management can avoid situations where a guest
>>>> that does not have proper suspend/wake capabilities ends up in
>>>> inconsistent state (e.g.
>>>> https://github.com/open-power-host-os/qemu/issues/31).
>>>>
>>>> Reported-by: Balamuruhan S <bala24@linux.vnet.ibm.com>
>>>> Signed-off-by: Daniel Henrique Barboza <danielhb@linux.ibm.com>
>>>> ---
>>>>    arch_init.c             |  1 +
>>>>    include/sysemu/sysemu.h |  1 +
>>>>    qapi/misc.json          |  4 +++-
>>>>    vl.c                    | 21 +++++++++++++++++++++
>>>>    4 files changed, 26 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/arch_init.c b/arch_init.c
>>>> index 9597218ced..67bdf27528 100644
>>>> --- a/arch_init.c
>>>> +++ b/arch_init.c
>>>> @@ -115,6 +115,7 @@ TargetInfo *qmp_query_target(Error **errp)
>>>>          info->arch = qapi_enum_parse(&SysEmuTarget_lookup,
>>>> TARGET_NAME, -1,
>>>>                                     &error_abort);
>>>> +    info->wakeup_suspend_support = !qemu_wakeup_notifier_is_empty();
>>> Huh?  Hmm, see "hack" below.
>>>
>>>>          return info;
>>>>    }
>>>> diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
>>>> index 544ab77a2b..fbe2a3373e 100644
>>>> --- a/include/sysemu/sysemu.h
>>>> +++ b/include/sysemu/sysemu.h
>>>> @@ -69,6 +69,7 @@ typedef enum WakeupReason {
>>>>    void qemu_system_reset_request(ShutdownCause reason);
>>>>    void qemu_system_suspend_request(void);
>>>>    void qemu_register_suspend_notifier(Notifier *notifier);
>>>> +bool qemu_wakeup_notifier_is_empty(void);
>>>>    void qemu_system_wakeup_request(WakeupReason reason);
>>>>    void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
>>>>    void qemu_register_wakeup_notifier(Notifier *notifier);
>>>> diff --git a/qapi/misc.json b/qapi/misc.json
>>>> index f5988cc0b5..a385d897ae 100644
>>>> --- a/qapi/misc.json
>>>> +++ b/qapi/misc.json
>>>> @@ -2484,11 +2484,13 @@
>>>>    # Information describing the QEMU target.
>>>>    #
>>>>    # @arch: the target architecture
>>>> +# @wakeup-suspend-support: true if the target supports wake up from
>>>> +#                          suspend (since 2.13)
>>>>    #
>>>>    # Since: 1.2.0
>>>>    ##
>>>>    { 'struct': 'TargetInfo',
>>>> -  'data': { 'arch': 'SysEmuTarget' } }
>>>> +  'data': { 'arch': 'SysEmuTarget', 'wakeup-suspend-support': 'bool' } }
>>>>      ##
>>>>    # @query-target:
>>> Does the documentation of system_wakeup need fixing?
>>>
>>>      ##
>>>      # @system_wakeup:
>>>      #
>>>      # Wakeup guest from suspend.  Does nothing in case the guest isn't suspended.
>>>      #
>>>      # Since:  1.1
>>>      #
>>>      # Returns:  nothing.
>>>      #
>>>      # Example:
>>>      #
>>>      # -> { "execute": "system_wakeup" }
>>>      # <- { "return": {} }
>>>      #
>>>      ##
>>>      { 'command': 'system_wakeup' }
>>>
>>> I figure we better explain right here what the command does, both for
>>> wakeup-suspend-support: false and true.
>> Hmm, I've re-sent a patch that changes a bit the behavior of system_wakeup
>> yesterday. The command should now fail with an error if the VM isn't in
>> SUSPENDED state. However, I failed to update this documentation
>> in that patch.
>>
>> What if I resend that system_wakeup patch with the updated
>> documentation such
>> as:
>>
>>
>>     ##
>>     # @system_wakeup:
>>     #
>>     # Wakeup guest from suspend.  Throws an error in case the guest isn't suspended.
>>     #
>>     # Since:  1.1
>>     #
>>     # Returns:  nothing if succeed
>>     #
>>
>>
>> And then I believe we don't need to update this doc again - if the
>> guest isn't suspended,
>>   system_wakeup will still fire up an error.
> What about a guest that is suspended under a QEMU that isn't capable of
> waking it?
>
> Shouldn't system_wakeup's documentation point to query-target's
> wakeup-suspend-support?

Fair enough.

>
>> In fact, I could have added that patch in this series too since it
>> kind of relates with these
>> changes as well. Let me know if you think it helps and I'll respin it
>> together with this
>> series.
> Respinning in a single series is the simplest way to ensure the patches
> get committed in a sane order.  I'd appreciate that.

I'll respin all together.


Thanks,


Daniel

> [...]
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-05-17 12:35 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-15 14:09 [Qemu-devel] [PATCH v6 0/2] qmp: 'wakeup-suspend-support' in query-target Daniel Henrique Barboza
2018-05-15 14:09 ` [Qemu-devel] [PATCH v6 1/2] qmp: adding " Daniel Henrique Barboza
2018-05-15 15:45   ` Markus Armbruster
2018-05-16 13:13     ` Daniel Henrique Barboza
2018-05-17  8:44       ` Markus Armbruster
2018-05-17 12:35         ` Daniel Henrique Barboza
2018-05-15 14:09 ` [Qemu-devel] [PATCH v6 2/2] qga: update guest-suspend-ram and guest-suspend-hybrid descriptions Daniel Henrique Barboza
2018-05-15 15:35   ` Markus Armbruster
2018-05-16 13:49     ` Daniel Henrique Barboza
2018-05-17  8:26       ` Markus Armbruster

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.