From nobody Sun Dec 14 12:17:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail header.i=@intel.com; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1751264909538100.17016598169562; Sun, 29 Jun 2025 23:28:29 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 902311583; Mon, 30 Jun 2025 02:28:28 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id AA6A91571; Mon, 30 Jun 2025 02:22:47 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id B808D1352; Mon, 30 Jun 2025 02:22:40 -0400 (EDT) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 748E3141E for ; Mon, 30 Jun 2025 02:22:18 -0400 (EDT) Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jun 2025 23:22:18 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jun 2025 23:22:16 -0700 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1751264538; x=1782800538; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FJCb1uzUb8FtBHPfLfgx7ljIBSw8/ja3pIkQRczshrs=; b=WFEzwgp+Vq1wQ5b9ekwmByle94U6oi18yGrPfMYxORanmef2o6HxMrwd zklqEjiGXFXqnSUZa5o0SJ5MfsIb6zU4bFoaUVbw9VK0zqxVf2QLc5jYc b0FhYlX3dJAN1l7OOboo9ispCo594SsGi9ksF5X9SkGlv61Sgy1I1dDqi ey2gRbNL8o7l0pSismYl56j+DHMo8kkD3+dVoDJxff5JVfQfZUOTXBl8z aGM2u3NAsbIhtbM4khEGBtr/q+/melY3uzx7Jg190iYEbaI5kj5+3568d nqiHbUdTDd8B7z6Cr2xIuXO+dE526Jp657hJDfwC3nPX2UzBtY07Fsr0y w==; X-CSE-ConnectionGUID: HdhZvh5oTuCNetMUH6Gy/A== X-CSE-MsgGUID: DtyYMigQTsGnmRHxsJPKaA== X-IronPort-AV: E=McAfee;i="6800,10657,11479"; a="70912559" X-IronPort-AV: E=Sophos;i="6.16,277,1744095600"; d="scan'208";a="70912559" X-CSE-ConnectionGUID: VeawCjCjRMWYwyQUQkdY1Q== X-CSE-MsgGUID: fXIJi5sQQ6GJfCe9GSo4rQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,277,1744095600"; d="scan'208";a="153549382" From: Zhenzhong Duan To: devel@lists.libvirt.org Subject: [PATCH v3 15/21] qemu: Support reboot command in guest Date: Mon, 30 Jun 2025 14:17:26 +0800 Message-Id: <20250630061732.303374-16-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250630061732.303374-1-zhenzhong.duan@intel.com> References: <20250630061732.303374-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: YD56U55ZIRAZYFDGJZHURJPCUWQLPAW4 X-Message-ID-Hash: YD56U55ZIRAZYFDGJZHURJPCUWQLPAW4 X-MailFrom: zhenzhong.duan@intel.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 CC: phrdina@redhat.com, pkrempa@redhat.com, jjongsma@redhat.com, jsuchane@redhat.com, chenyi.qiang@intel.com, isaku.yamahata@intel.com, xiaoyao.li@intel.com, chao.p.peng@intel.com, Zhenzhong Duan X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1751264911145116600 Content-Type: text/plain; charset="utf-8" We can reboot a TDX guest with 'virsh reboot' or 'virsh shutdown' if action for onPoweroff is 'restart'. But running reboot command in guest shell will always lead to shutdown. This behavior is not consistent with normal guest, fix it by checking shutdown reason and action configuration to trigger FakeReboot. Signed-off-by: Zhenzhong Duan Reviewed-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_monitor.c | 18 +++++++++++++++++- src/qemu/qemu_monitor.h | 2 +- src/qemu/qemu_monitor_json.c | 6 +++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 95c88fd5e8..1608fa86cd 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -1060,10 +1060,26 @@ qemuMonitorEmitEvent(qemuMonitor *mon, const char *= event, =20 =20 void -qemuMonitorEmitShutdown(qemuMonitor *mon, virTristateBool guest) +qemuMonitorEmitShutdown(qemuMonitor *mon, virTristateBool guest, + const char *reason) { + virDomainObj *vm =3D mon->vm; + VIR_DEBUG("mon=3D%p guest=3D%u", mon, guest); =20 + /* This isn't best place to set FakeReboot but we need to access + * mon->vm which is defined in this file. Reboot command in guest + * will trigger SHUTDOWN event for TDX guest, so we has to deal + * with it here. */ + if (vm->def->sec && + vm->def->sec->sectype =3D=3D VIR_DOMAIN_LAUNCH_SECURITY_TDX) { + if ((STREQ_NULLABLE(reason, "guest-shutdown") && + vm->def->onPoweroff =3D=3D VIR_DOMAIN_LIFECYCLE_ACTION_RESTAR= T) || + (STREQ_NULLABLE(reason, "guest-reset") && + vm->def->onReboot =3D=3D VIR_DOMAIN_LIFECYCLE_ACTION_RESTART)) + qemuDomainSetFakeReboot(vm, true); + } + QEMU_MONITOR_CALLBACK(mon, domainShutdown, mon->vm, guest); } =20 diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 6030c31598..5ab5f66741 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -449,7 +449,7 @@ int qemuMonitorUpdateVideoVram64Size(qemuMonitor *mon, void qemuMonitorEmitEvent(qemuMonitor *mon, const char *event, long long seconds, unsigned int micros, const char *details); -void qemuMonitorEmitShutdown(qemuMonitor *mon, virTristateBool guest); +void qemuMonitorEmitShutdown(qemuMonitor *mon, virTristateBool guest, cons= t char *reason); void qemuMonitorEmitReset(qemuMonitor *mon); void qemuMonitorEmitStop(qemuMonitor *mon); void qemuMonitorEmitResume(qemuMonitor *mon); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 5297ffb027..a7989bb897 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -548,12 +548,16 @@ qemuMonitorJSONMakeCommand(const char *cmdname, static void qemuMonitorJSONHandleShutdown(qemuMonitor *mon, virJSONValue *= data) { bool guest =3D false; + const char *reason =3D NULL; virTristateBool guest_initiated =3D VIR_TRISTATE_BOOL_ABSENT; =20 if (data && virJSONValueObjectGetBoolean(data, "guest", &guest) =3D=3D= 0) guest_initiated =3D virTristateBoolFromBool(guest); =20 - qemuMonitorEmitShutdown(mon, guest_initiated); + if (data) + reason =3D virJSONValueObjectGetString(data, "reason"); + + qemuMonitorEmitShutdown(mon, guest_initiated, reason); } =20 static void qemuMonitorJSONHandleReset(qemuMonitor *mon, virJSONValue *dat= a G_GNUC_UNUSED) --=20 2.34.1