From patchwork Thu May 17 19:23:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 915724 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40n1Vs1HHfz9s1w for ; Fri, 18 May 2018 05:25:57 +1000 (AEST) Received: from localhost ([::1]:34776 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJOXC-0001i4-PZ for incoming@patchwork.ozlabs.org; Thu, 17 May 2018 15:25:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43039) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJOV8-0008QI-Pf for qemu-devel@nongnu.org; Thu, 17 May 2018 15:23:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJOV4-0001J3-QP for qemu-devel@nongnu.org; Thu, 17 May 2018 15:23:46 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:43864 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fJOV4-0001Iu-JV for qemu-devel@nongnu.org; Thu, 17 May 2018 15:23:42 -0400 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4HJIwqJ112756 for ; Thu, 17 May 2018 15:23:42 -0400 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0b-001b2d01.pphosted.com with ESMTP id 2j1cc2sfcy-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 17 May 2018 15:23:41 -0400 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 17 May 2018 13:23:41 -0600 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 17 May 2018 13:23:38 -0600 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4HJNc6b12124504; Thu, 17 May 2018 12:23:38 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2CC4CBE03A; Thu, 17 May 2018 13:23:38 -0600 (MDT) Received: from localhost.localdomain (unknown [9.80.214.27]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP id 7AFDBBE03E; Thu, 17 May 2018 13:23:36 -0600 (MDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Thu, 17 May 2018 16:23:23 -0300 X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180517192325.8335-1-danielhb@linux.ibm.com> References: <20180517192325.8335-1-danielhb@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18051719-0004-0000-0000-0000141B3974 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009041; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000261; SDB=6.01033740; UDB=6.00528597; IPR=6.00812869; MB=3.00021167; MTD=3.00000008; XFM=3.00000015; UTC=2018-05-17 19:23:40 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18051719-0005-0000-0000-0000873BBE99 Message-Id: <20180517192325.8335-2-danielhb@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-05-17_10:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1805170182 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v7 1/3] qmp: adding 'wakeup-suspend-support' in query-target X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , armbru@redhat.com, dgilbert@redhat.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Signed-off-by: Daniel Henrique Barboza --- arch_init.c | 1 + include/sysemu/sysemu.h | 1 + qapi/misc.json | 8 ++++++-- vl.c | 22 ++++++++++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/arch_init.c b/arch_init.c index 9597218ced..fa5407e2de 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_suspend_support(); return info; } diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 544ab77a2b..b987e61d76 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -79,6 +79,7 @@ void qemu_system_debug_request(void); void qemu_system_vmstop_request(RunState reason); void qemu_system_vmstop_request_prepare(void); bool qemu_vmstop_requested(RunState *r); +bool qemu_wakeup_suspend_support(void); ShutdownCause qemu_shutdown_requested_get(void); ShutdownCause qemu_reset_requested_get(void); void qemu_system_killed(int signal, pid_t pid); diff --git a/qapi/misc.json b/qapi/misc.json index f5988cc0b5..efba0449a6 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -1245,7 +1245,9 @@ ## # @system_wakeup: # -# Wakeup guest from suspend. Does nothing in case the guest isn't suspended. +# If the guest has wake-up from suspend support enabled +# (wakeup-suspend-support flag from query-target), wakeup guest from +# suspend. Does nothing otherwise. # # Since: 1.1 # @@ -2484,11 +2486,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..b8fe41860a 100644 --- a/vl.c +++ b/vl.c @@ -1832,11 +1832,33 @@ void qemu_system_wakeup_enable(WakeupReason reason, bool enabled) } } +/* + * The existence of a wake-up notifier is being checked in the function + * qemu_wakeup_suspend_support 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_suspend_support(void) +{ + return !QLIST_EMPTY(&wakeup_notifiers.notifiers); +} + void qemu_system_killed(int signal, pid_t pid) { shutdown_signal = signal; From patchwork Thu May 17 19:23:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 915723 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40n1T76vPDz9s1w for ; Fri, 18 May 2018 05:24:27 +1000 (AEST) Received: from localhost ([::1]:34766 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJOVl-0008Vt-LA for incoming@patchwork.ozlabs.org; Thu, 17 May 2018 15:24:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJOVC-0008S7-Ib for qemu-devel@nongnu.org; Thu, 17 May 2018 15:23:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJOV7-0001Kc-KX for qemu-devel@nongnu.org; Thu, 17 May 2018 15:23:50 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:54642 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fJOV7-0001KR-EF for qemu-devel@nongnu.org; Thu, 17 May 2018 15:23:45 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4HJIs0u003415 for ; Thu, 17 May 2018 15:23:44 -0400 Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) by mx0b-001b2d01.pphosted.com with ESMTP id 2j1fr6g90d-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 17 May 2018 15:23:44 -0400 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 17 May 2018 13:23:43 -0600 Received: from b03cxnp08028.gho.boulder.ibm.com (9.17.130.20) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 17 May 2018 13:23:42 -0600 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4HJNfE011076020 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 17 May 2018 12:23:41 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 35EC6BE04A; Thu, 17 May 2018 13:23:41 -0600 (MDT) Received: from localhost.localdomain (unknown [9.80.214.27]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP id 87DECBE03B; Thu, 17 May 2018 13:23:39 -0600 (MDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Thu, 17 May 2018 16:23:24 -0300 X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180517192325.8335-1-danielhb@linux.ibm.com> References: <20180517192325.8335-1-danielhb@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18051719-0020-0000-0000-00000DF42DB5 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009041; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000261; SDB=6.01033740; UDB=6.00528597; IPR=6.00812869; MB=3.00021167; MTD=3.00000008; XFM=3.00000015; UTC=2018-05-17 19:23:43 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18051719-0021-0000-0000-0000616C9DA3 Message-Id: <20180517192325.8335-3-danielhb@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-05-17_10:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1805170182 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v7 2/3] qga: update guest-suspend-ram and guest-suspend-hybrid descriptions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , armbru@redhat.com, dgilbert@redhat.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This patch updates the descriptions of 'guest-suspend-ram' and 'guest-suspend-hybrid' to mention that both commands relies now 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 Signed-off-by: Daniel Henrique Barboza Reviewed-by: Michael Roth --- qga/qapi-schema.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index 17884c7c70..bc46c2d0f0 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -565,9 +565,9 @@ # For the best results it's strongly recommended to have the pm-utils # 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. +# 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: @@ -592,9 +592,9 @@ # # 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. +# IMPORTANT: guest-suspend-hybrid 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: From patchwork Thu May 17 19:23:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 915725 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40n1XD6H45z9s29 for ; Fri, 18 May 2018 05:27:08 +1000 (AEST) Received: from localhost ([::1]:34780 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJOYM-0002N1-JU for incoming@patchwork.ozlabs.org; Thu, 17 May 2018 15:27:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43087) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJOVJ-0008Va-0L for qemu-devel@nongnu.org; Thu, 17 May 2018 15:24:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJOVD-0001Mr-Uk for qemu-devel@nongnu.org; Thu, 17 May 2018 15:23:56 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:33900) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fJOVD-0001Mc-M0 for qemu-devel@nongnu.org; Thu, 17 May 2018 15:23:51 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4HJIsPP028225 for ; Thu, 17 May 2018 15:23:49 -0400 Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) by mx0a-001b2d01.pphosted.com with ESMTP id 2j1ehg3ecw-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 17 May 2018 15:23:48 -0400 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 17 May 2018 13:23:48 -0600 Received: from b03cxnp08026.gho.boulder.ibm.com (9.17.130.18) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 17 May 2018 13:23:44 -0600 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4HJNiDn10945002; Thu, 17 May 2018 12:23:44 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 55A65BE044; Thu, 17 May 2018 13:23:44 -0600 (MDT) Received: from localhost.localdomain (unknown [9.80.214.27]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP id 94B4DBE038; Thu, 17 May 2018 13:23:42 -0600 (MDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Thu, 17 May 2018 16:23:25 -0300 X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180517192325.8335-1-danielhb@linux.ibm.com> References: <20180517192325.8335-1-danielhb@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18051719-0020-0000-0000-00000DF42DBA X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009041; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000261; SDB=6.01033740; UDB=6.00528597; IPR=6.00812869; MB=3.00021167; MTD=3.00000008; XFM=3.00000015; UTC=2018-05-17 19:23:46 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18051719-0021-0000-0000-0000616C9DA9 Message-Id: <20180517192325.8335-4-danielhb@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-05-17_10:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1805170182 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH v7 3/3] qmp.c: system_wakeup: runstate and wake-up support check X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza , armbru@redhat.com, dgilbert@redhat.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The qmp/hmp command 'system_wakeup' is simply a direct call to 'qemu_system_wakeup_request' from vl.c. This function verifies if runstate is SUSPENDED and if the wake up reason is valid before proceeding. However, no error or warning is thrown if any of those pre-requirements isn't met. There is no way for the caller to differentiate between a successful wakeup or an error state caused when trying to wake up a guest that wasn't suspended. This means that system_wakeup is silently failing, which can be considered a bug. Adding error handling isn't an API break in this case - applications that didn't check the result will remain broken, the ones that check it will have a chance to deal with it. Adding to that, recent changes in query-target added a new flag called wakeup-suspend-support that indicates if the guest has the capability of waking up from suspended state. Although such guest will never reach SUSPENDED state and erroring it out in this scenario would suffice, it is more informative for the user to differentiate between a failure because the guest isn't suspended versus a failure because the guest does not have support for wake up at all. All this considered, this patch changes qmp_system_wakeup to: - check if the guest has the capability to wake-up from suspend. If not, error out informing about the lack of support; - make the runstate verification before proceeding to call qemu_system_wakeup_request, firing up an error message if the user tries to wake up a machine that isn't in SUSPENDED state. After this patch, this is the output of system_wakeup in a guest that does not have wake-up from suspend support (ppc64): (qemu) system_wakeup wake-up from suspend is not supported by this guest (qemu) And this is the output of system_wakeup in a x86 guest that has the support but isn't suspended: (qemu) system_wakeup Unable to wake up: guest is not in suspended state (qemu) Reported-by: Balamuruhan S Signed-off-by: Daniel Henrique Barboza --- hmp.c | 4 +++- qapi/misc.json | 3 ++- qmp.c | 10 ++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/hmp.c b/hmp.c index ef93f4878b..d177d14cc9 100644 --- a/hmp.c +++ b/hmp.c @@ -1156,7 +1156,9 @@ void hmp_cont(Monitor *mon, const QDict *qdict) void hmp_system_wakeup(Monitor *mon, const QDict *qdict) { - qmp_system_wakeup(NULL); + Error *err = NULL; + qmp_system_wakeup(&err); + hmp_handle_error(mon, &err); } void hmp_nmi(Monitor *mon, const QDict *qdict) diff --git a/qapi/misc.json b/qapi/misc.json index efba0449a6..73bfc3e436 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -1247,7 +1247,8 @@ # # If the guest has wake-up from suspend support enabled # (wakeup-suspend-support flag from query-target), wakeup guest from -# suspend. Does nothing otherwise. +# suspend if the guest is in SUSPENDED state. Returns an error +# otherwise. # # Since: 1.1 # diff --git a/qmp.c b/qmp.c index 25fdc9a5b2..5366e963ad 100644 --- a/qmp.c +++ b/qmp.c @@ -205,6 +205,16 @@ void qmp_cont(Error **errp) void qmp_system_wakeup(Error **errp) { + if (!qemu_wakeup_suspend_support()) { + error_setg(errp, + "wake-up from suspend is not supported by this guest"); + return; + } + if (!runstate_check(RUN_STATE_SUSPENDED)) { + error_setg(errp, + "Unable to wake up: guest is not in suspended state"); + return; + } qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER); }