From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 87751C87FCF for ; Mon, 4 Aug 2025 13:57:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uiveP-0008FI-Tp; Mon, 04 Aug 2025 09:54:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uirte-0006c9-E4 for qemu-devel@nongnu.org; Mon, 04 Aug 2025 05:54:22 -0400 Received: from mail-yw1-x1134.google.com ([2607:f8b0:4864:20::1134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uirtb-0001Xl-S1 for qemu-devel@nongnu.org; Mon, 04 Aug 2025 05:54:22 -0400 Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-71a3935fa8dso21677297b3.0 for ; Mon, 04 Aug 2025 02:54:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1754301258; x=1754906058; darn=nongnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=d35v01zl8S6rDQ3Kca2SzSIHkB/du7cfCRcpcWcGXhM=; b=TqfYEaeve0O7mp23yInxUXmlomaBbnlruw+3DRFWveJHTIUV/CT3++jW9g67lCtBNG eDW+4NXWlmI9icAR5eTBa6NEMqVce7r0XC69tdQDZ1iHpG2Qo1RlQMhUjMtKKOqiO5p5 ZEAiLhpHl7KsDKDnU5Sr+wBdvm+oMh/GOpQaCu6wQGMQ9T9W7OnydvNPR3hYcBgxlD6+ CGj7n9ukkps7DIsz27aBQA5csjfySzP/DdlWUJKmJ+VI33mJlBU+FITc6JnQCXovwlYA ZA2VyKH34GIw2vzqJjtTxLHWAjNQXEF58eEdkZeOxFIeGD1w35jkr0B+7pC03hgpwRSg qQQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754301258; x=1754906058; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=d35v01zl8S6rDQ3Kca2SzSIHkB/du7cfCRcpcWcGXhM=; b=ZTVVKDILAyQMrSfur6cvZAVnU9HTprDiMAf1dPtWtDcGite3Da+rum+89gR2rm2s/S k02PUbU0xlgi+JE4X7G/KI2tPxsaMxHruiXqEPXoeILTd+TxQk8CFi2WIntZbOqTaLT3 e3+9NwNP7o8ooDvw6Giu84OBFBS+ugN0fYg3MDPeeYuUzwfEz1iXIaX7t9SoiPJHjsxm OvPD6mV+AW9Vwjtde3QxDtnJefmR4JczRrTJj8pwM1HuIdJySJPWDEHefbmCGcAZoDl7 tAENJuAgWXdV/f6F4O6+vCLUCHizi1l2suCdiOZXcLMTbVtNqBNt9xF0c/++iiFu88xE n8rw== X-Gm-Message-State: AOJu0Yx3SZAHTOdSNwn0tZ6DKfPU6perZXN9KDHC2azhbl/nDPvYfV2s MOJs9CsioXz020Bi/UivQZQVWq29fIiKo+1gr2vTokiycmAsZSJQYFVTzTcS8DWiBwizu/Bd/s6 EK4db4WV9xdxzt4BnjhnFxztqAvFGIXI= X-Gm-Gg: ASbGncvNqMftJnodYP2WxpTWwC+l8WDJfh+3QzpSby/Y2upde+oC9ijxc3ueRf61hK0 T2gbPegJiHe1VI6ud/+T6JHZkvGDe4OcWeUs29/zcLiTC5Kog1/jVXxdF7UhQGaO/8N/V4oaHZ4 4Ns5PfMqEhjAI39Oer9SA5oOCISS4KBG1khNOLHfYMu+N7zBv8uJNTh7B4pQ8M9iqgzYwjjhkXI wDxuUadWJBS57G2IQ== X-Google-Smtp-Source: AGHT+IFkHmSmQ70TMQ/FkmuIp8D6E+CLzwOFuNjM/YajXTMtp+/ZbNKgEDu2CMFwYVFD4NTeRsQG/9Mf/ahhow40ZBQ= X-Received: by 2002:a05:690c:f91:b0:712:c14a:a388 with SMTP id 00721157ae682-71b7ed127abmr100892717b3.7.1754301258458; Mon, 04 Aug 2025 02:54:18 -0700 (PDT) MIME-Version: 1.0 References: <20250804074641.6021-1-zhengnici@gmail.com> In-Reply-To: From: nici zheng Date: Mon, 4 Aug 2025 17:54:07 +0800 X-Gm-Features: Ac12FXwFpEOpbOoqJzqN6oFji_8cdx1AoyY99Dv_FHfqBAAWN-NoNlF4Q7j5ee0 Message-ID: Subject: Re: [PATCH] qga: Fix error handling in system suspend mode causing libvirt to hold lock indefinitely To: Kostiantyn Kostiuk Cc: qemu-devel@nongnu.org, michael.roth@amd.com, panzerzheng , =?UTF-8?Q?Daniel_Berrang=C3=A9?= Content-Type: multipart/alternative; boundary="00000000000056ec36063b87177d" Received-SPF: pass client-ip=2607:f8b0:4864:20::1134; envelope-from=zhengnici@gmail.com; helo=mail-yw1-x1134.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 04 Aug 2025 09:13:47 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org --00000000000056ec36063b87177d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Kostiantyn, Thank you again for your valuable feedback. I've conducted further tests to address your questions, and here are the details: 1. Regarding exit code 1: I performed an experiment with the kernel configuration: When CONFIG_HIBERNATION is disabled in the kernel: [root@VM-23-13-opencloudos OpenCloudOS-Kernel]# grep -i HIBERNATION /boot/config-6.6.47-12.oc9.x86_64 CONFIG_ARCH_HIBERNATION_POSSIBLE=3Dy # CONFIG_HIBERNATION is not set The /sys/power/state shows no "disk" support: [root@VM-0-94-opencloudos patch]# cat /sys/power/state freeze mem While "systemctl status systemd-hibernate" returns code 3: [root@VM-0-94-opencloudos patch]# systemctl status systemd-hibernate =E2=97=8B systemd-hibernate.service - Hibernate Loaded: loaded (/usr/lib/systemd/system/systemd-hibernate.service; stat= ic) Active: inactive (dead) Docs: man:systemd-hibernate.service(8) [root@VM-0-94-opencloudos patch]# echo $? 3 The actual hibernation command returns code 1 due to kernel incompatibil= ity: [root@VM-0-94-opencloudos patch]# systemctl hibernate Call to Hibernate failed: Sleep verb 'hibernate' is not configured or configuration is not supported by kernel [root@VM-0-94-opencloudos patch]# echo $? 1 This confirms exit code 1 indicates actual hibernation support failure in this scenario. 2. Regarding mode_supported logic: I understand your confusion about the check in systemd_supports_mode(mode, &local_err). Another experiment illustrates the issue: On a system with hibernation enabled: [opencloudos@VM-23-13-opencloudos ~]$ grep -i HIBERNATION /boot/config-6.6.92+ CONFIG_ARCH_HIBERNATION_POSSIBLE=3Dy CONFIG_ARCH_HIBERNATION_HEADER=3Dy CONFIG_HIBERNATION=3Dy CONFIG_HIBERNATION_SNAPSHOT_DEV=3Dy /sys/power/state includes "disk": [opencloudos@VM-23-13-opencloudos ~]$ cat /sys/power/state freeze mem disk However, "systemctl status systemd-hibernate" still returns code 3 regardless of actual support: [opencloudos@VM-23-13-opencloudos ~]$ sudo systemctl status systemd-hibe= rnate =E2=97=8B systemd-hibernate.service - Hibernate Loaded: loaded (/usr/lib/systemd/system/systemd-hibernate.service; static) Active: inactive (dead) Docs: man:systemd-hibernate.service(8) [output truncated for brevity] [opencloudos@VM-23-13-opencloudos ~]$ echo $? 3 This shows "systemctl status" isn't reliable for determining support. The actual execution result of "systemctl hibernate" is necessary to accurately verify suspend-to-disk capability. Thanks again for your patience and guidance. I'll revise the patch accordingly and resubmit as v2. Best regards, panzerzheng Kostiantyn Kostiuk =E4=BA=8E2025=E5=B9=B48=E6=9C=884= =E6=97=A5=E5=91=A8=E4=B8=80 16:18=E5=86=99=E9=81=93=EF=BC=9A > > > On Mon, Aug 4, 2025 at 10:47=E2=80=AFAM wrote: > >> From: panzerzheng >> >> When "/sys/power/state" does not contain "disk", the operating system >> does not support hibernation. Executing "sudo systemctl hibernate" will >> return an exit code of 1 with the stderr output: "Call to Hibernate >> failed: >> Sleep verb 'hibernate' is not configured or configuration is not >> supported by kernel". >> > >> This patch adds handling for exit code 1 in the systemd_suspend function= , >> setting appropriate error messages when the kernel does not support >> standby. >> It also adds local_err handling in the guest_suspend function to set >> mode_supported to false. >> >> Without these fixes, libvirt would hold the lock indefinitely. >> >> Signed-off-by: panzerzheng >> --- >> qga/commands-linux.c | 8 ++++++++ >> 1 file changed, 8 insertions(+) >> >> diff --git a/qga/commands-linux.c b/qga/commands-linux.c >> index 9e8a934b9a..26229396c3 100644 >> --- a/qga/commands-linux.c >> +++ b/qga/commands-linux.c >> @@ -1300,6 +1300,12 @@ static void systemd_suspend(SuspendMode mode, >> Error **errp) >> return; >> } >> >> + if ((status =3D=3D 1) && !local_err) { >> > > Is there any documentation that explains that exit code =3D 1 is an error= ? > If you look into systemd_supports_mode, you can see that exit code =3D 1 = is > detected > as a supported mode. > > >> + error_setg(errp, "'systemctl %s' not suspend", >> + systemctl_args[mode]); >> + return; >> + } >> + >> if (local_err) { >> error_propagate(errp, local_err); >> } else { >> @@ -1428,6 +1434,8 @@ static void guest_suspend(SuspendMode mode, Error >> **errp) >> >> if (!local_err) { >> return; >> + } else { >> + mode_supported =3D false; >> } >> > > This is very confusing. We check that the mode is supported, but after > running suspend, > we find that it is unsupported. I think we should fix > systemd_supports_mode instead. > > Also, setting mode_supported =3D false does not change anything. > In the next step, we will check pmutils_supports_mode and > linux_sys_state_supports_mode, > and I think this check will pass, so we set mode_supported =3D true again= . > > Best Regards, > Kostiantyn Kostiuk. > > >> } >> >> -- >> 2.43.7 >> >> --00000000000056ec36063b87177d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Kostiantyn,

Thank you again for your valuable feedback. I've conducted further test=
s to address your questions, and here are the details:

1. Regarding exit code 1:
   I performed an experiment with the kernel configuration:
  =20
   When CONFIG_HIBERNATION is disabled in the kernel:
   [root@VM-23-13-opencloudos OpenCloudOS-Kernel]# grep -i HIBERNATION /boo=
t/config-6.6.47-12.oc9.x86_64=20
   CONFIG_ARCH_HIBERNATION_POSSIBLE=3Dy
   # CONFIG_HIBERNATION is not set
  =20
   The /sys/power/state shows no "disk" support:
   [root@VM-0-94-opencloudos patch]# cat /sys/power/state
   freeze mem
  =20
   While "systemctl status systemd-hibernate" returns code 3:
   [root@VM-0-94-opencloudos patch]# systemctl status systemd-hibernate
   =E2=97=8B systemd-hibernate.service - Hibernate
    Loaded: loaded (/usr/lib/systemd/system/systemd-hibernate.service; stat=
ic)
        Active: inactive (dead)
      Docs: man:systemd-hibernate.service(8)
   [root@VM-0-94-opencloudos patch]# echo $?
   3
  =20
   The actual hibernation command returns code 1 due to kernel incompatibil=
ity:
   [root@VM-0-94-opencloudos patch]# systemctl hibernate
       Call to Hibernate failed: Sleep verb 'hibernate' is not conf=
igured or configuration is not supported by kernel
   [root@VM-0-94-opencloudos patch]# echo $?
   1
  =20
   This confirms exit code 1 indicates actual hibernation support failure i=
n this scenario.

2. Regarding mode_supported logic:
   I understand your confusion about the check in systemd_supports_mode(mod=
e, &local_err). Another experiment illustrates the issue:
  =20
   On a system with hibernation enabled:
   [opencloudos@VM-23-13-opencloudos ~]$ grep -i HIBERNATION /boot/config-6=
.6.92+=20
   CONFIG_ARCH_HIBERNATION_POSSIBLE=3Dy
   CONFIG_ARCH_HIBERNATION_HEADER=3Dy
   CONFIG_HIBERNATION=3Dy
   CONFIG_HIBERNATION_SNAPSHOT_DEV=3Dy =20
  =20
   /sys/power/state includes "disk":
   [opencloudos@VM-23-13-opencloudos ~]$ cat /sys/power/state
   freeze mem disk
  =20
   However, "systemctl status systemd-hibernate" still returns co=
de 3 regardless of actual support:
   [opencloudos@VM-23-13-opencloudos ~]$ sudo systemctl status systemd-hibe=
rnate
   =E2=97=8B systemd-hibernate.service - Hibernate
        Loaded: loaded (/usr/lib/systemd/system/systemd-hibernate.service; =
static)
        Active: inactive (dead)
          Docs: man:systemd-hibernate.service(8)
  =20
   [output truncated for brevity]
  =20
   [opencloudos@VM-23-13-opencloudos ~]$ echo $?
   3
  =20
   This shows "systemctl status" isn't reliable for determini=
ng support. The actual execution result of "systemctl hibernate" =
is necessary to accurately verify suspend-to-disk capability.

Thanks again for your patience and guidance. I'll revise the patch acco=
rdingly and resubmit as v2.

Best regards,
panzerzheng

Kostiantyn Kostiuk <kkostiuk@redhat.com> =E4=BA=8E2025= =E5=B9=B48=E6=9C=884=E6=97=A5=E5=91=A8=E4=B8=80 16:18=E5=86=99=E9=81=93=EF= =BC=9A


On Mon, Aug 4, 2025 at 10:47=E2=80=AFAM <<= a href=3D"mailto:zhengnici@gmail.com" target=3D"_blank">zhengnici@gmail.com= > wrote:
= From: panzerzheng <panzerzheng@tencent.com>

When "/sys/power/state" does not contain "disk", the op= erating system
does not support hibernation. Executing "sudo systemctl hibernate"= ; will
return an exit code of 1 with the stderr output: "Call to Hibernate fa= iled:
Sleep verb 'hibernate' is not configured or configuration is not su= pported by kernel".

This patch adds handling for exit code 1 in the systemd_suspend function, setting appropriate error messages when the kernel does not support standby= .
It also adds local_err handling in the guest_suspend function to set
mode_supported to false.

Without these fixes, libvirt would hold the lock indefinitely.

Signed-off-by: panzerzheng <panzerzheng@tencent.com>
---
=C2=A0qga/commands-linux.c | 8 ++++++++
=C2=A01 file changed, 8 insertions(+)

diff --git a/qga/commands-linux.c b/qga/commands-linux.c
index 9e8a934b9a..26229396c3 100644
--- a/qga/commands-linux.c
+++ b/qga/commands-linux.c
@@ -1300,6 +1300,12 @@ static void systemd_suspend(SuspendMode mode, Error = **errp)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return;
=C2=A0 =C2=A0 =C2=A0}

+=C2=A0 =C2=A0 if ((status =3D=3D 1) && !local_err) {

Is there any documentation that explains that e= xit code =3D 1 is an error?
If you look into systemd_supports_mod= e, you can see that exit code =3D 1 is detected
as a support= ed mode.
=C2=A0
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 error_setg(errp, "'systemctl %s' = not suspend",
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0syste= mctl_args[mode]);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 return;
+=C2=A0 =C2=A0 }
+
=C2=A0 =C2=A0 =C2=A0if (local_err) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0error_propagate(errp, local_err);
=C2=A0 =C2=A0 =C2=A0} else {
@@ -1428,6 +1434,8 @@ static void guest_suspend(SuspendMode mode, Error **e= rrp)

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!local_err) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 } else {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 mode_supported =3D false;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}

Thi= s is very confusing. We check that the mode is supported, but after running= suspend,
we find that it is unsupported. I think we should fix systemd= _supports_mode instead.

Also, setting mode_su= pported =3D false does not change anything.
In the next step= , we will check pmutils_supports_mode and linux_sys_state_supports_mode,
and I think this check will pass, so we set mode_supported =3D = true again.

Best Regards,
Kostiantyn Kostiuk.
=C2=A0
=C2=A0 =C2=A0 =C2=A0}

--
2.43.7

--00000000000056ec36063b87177d--