From nobody Wed Dec 17 03:40:51 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 1750845577862648.320415028438; Wed, 25 Jun 2025 02:59:37 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id DF39413ED; Wed, 25 Jun 2025 05:59:36 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 5CEBC14D1; Wed, 25 Jun 2025 05:52:00 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id EF5B91394; Wed, 25 Jun 2025 05:51:52 -0400 (EDT) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 41B991486 for ; Wed, 25 Jun 2025 05:51:21 -0400 (EDT) Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2025 02:50:12 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2025 02:50:08 -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=1750845081; x=1782381081; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FJCb1uzUb8FtBHPfLfgx7ljIBSw8/ja3pIkQRczshrs=; b=V2Ed7Vl5K0c0Oz4/L1ilM8Rw870h5XnkJa9v3Lu5Y448j/aqrl+YNryz g4c3y4jTzflBHdGTkMENMg+itwrqvCSQBYxIfCLHdeUoxZiEDvN32gapC S/nXHc+EnM3y7YvGXORW+JTwHaMSCkKVdJp1OJVfd5c9Lg+zALxItH3Ce c5fleZY6BgChPJIPpxNZAUFPr4ZB+pDoBFOqawZgOdxyDBRu6PvWB2kJ+ cOGAAbMffZIqpBJOnq8WehCH2Qgaf3oxTjbgBQvhu79AbvywxdQNsnCwn 1n2bNmO4/CKNNg2ldN8VuqnK6eeJQVpVXbGlj5UKcXHKYhptKDIamUb8p w==; X-CSE-ConnectionGUID: hq0qlrh1RM2QRCCkSEBWbw== X-CSE-MsgGUID: mtAWMeW9TyuGXm4cYRHDWg== X-IronPort-AV: E=McAfee;i="6800,10657,11474"; a="70680405" X-IronPort-AV: E=Sophos;i="6.16,264,1744095600"; d="scan'208";a="70680405" X-CSE-ConnectionGUID: mqNcCNtlTbOZhesp/A2O9Q== X-CSE-MsgGUID: 5LsRMyMRSJ65qiCIMxHwiQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,264,1744095600"; d="scan'208";a="151787002" From: Zhenzhong Duan To: devel@lists.libvirt.org Subject: [PATCH v2 13/21] qemu: Support reboot command in guest Date: Wed, 25 Jun 2025 17:45:25 +0800 Message-Id: <20250625094533.234897-14-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250625094533.234897-1-zhenzhong.duan@intel.com> References: <20250625094533.234897-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 2MKLDR5FMYCYKCEOOKP3T4ANMSGAFYRF X-Message-ID-Hash: 2MKLDR5FMYCYKCEOOKP3T4ANMSGAFYRF 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: 1750845578387116600 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