From nobody Tue Sep 9 19:03:24 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 1752132605972234.62972526218346; Thu, 10 Jul 2025 00:30:05 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 034C411C7; Thu, 10 Jul 2025 03:30:04 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 869B51613; Thu, 10 Jul 2025 03:23:33 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 918711506; Thu, 10 Jul 2025 03:23:19 -0400 (EDT) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 2C9A013C9 for ; Thu, 10 Jul 2025 03:22:53 -0400 (EDT) Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jul 2025 00:22:40 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jul 2025 00:22:38 -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.0 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=1752132173; x=1783668173; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MQHNfNLIfXFhwO7DCRIrb26ZRzgnXr5moyjT+Q+Cy0o=; b=e1Nc+etY6xckaFNPiJWTv0BknhOvNuGFslR1uhBqU7tqhmX9GE5GLhar PwZfjWhRaqL3+M17XlmhfSQqo7Uy1DiAOyldfa/HFPl4/ylhqriWLOo7Q 3SCGJ3mqbvkQ1/FHfyp8Z8k6kAeYqPymRup8NkxImkXVqqo9kiRoFvBS0 jFl/oPc3yvtK57HiGDCcZcL+tOgC6a2JqMqgmV9Lqwja4E1EhmBiFZVsu kLzTclJi6fHkTN0CdJuKKVeN0pZ64y1i08+eUk0FL3hVxDEab3nuGSHkt c3luNlw/xOra6YxSI0Vc3KV8nDkyD3YGjPqHYuBfMIQmeUxt5gaGByjPZ g==; X-CSE-ConnectionGUID: 0soct9h/TkGN4OgmaC/8Yg== X-CSE-MsgGUID: 48QMeEcFRfSPUhHoa01yJQ== X-IronPort-AV: E=McAfee;i="6800,10657,11489"; a="54257140" X-IronPort-AV: E=Sophos;i="6.16,300,1744095600"; d="scan'208";a="54257140" X-CSE-ConnectionGUID: FSf2yqpMS76TX8s6k5o5NQ== X-CSE-MsgGUID: Ghf97EpQRniCM4BCXlQnEg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,300,1744095600"; d="scan'208";a="186997215" From: Zhenzhong Duan To: devel@lists.libvirt.org Subject: [PATCH v4 16/23] qemu: Add FakeReboot support for TDX guest Date: Thu, 10 Jul 2025 03:21:18 -0400 Message-ID: <20250710072127.695558-17-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250710072127.695558-1-zhenzhong.duan@intel.com> References: <20250710072127.695558-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: SGCVXACRA7GZS3CL23JCY2XLIP573TPD X-Message-ID-Hash: SGCVXACRA7GZS3CL23JCY2XLIP573TPD 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: 1752132607438116600 Content-Type: text/plain; charset="utf-8" Utilize the existing fake reboot mechanism to do reboot for TDX guest. Different from normal guest, TDX guest doesn't support system_reset, so have to kill the old guest and start a new one to simulate the reboot. Co-developed-by: Chenyi Qiang Signed-off-by: Zhenzhong Duan Reviewed-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_process.c | 80 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 529c65b9b0..7c8f785f32 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -446,6 +446,67 @@ qemuProcessHandleReset(qemuMonitor *mon G_GNUC_UNUSED, } =20 =20 +/* + * Secure guest doesn't support fake reboot via machine CPU reset. + * We thus fake reboot via QEMU re-creation. + */ +static void +qemuProcessFakeRebootViaRecreate(virDomainObj *vm) +{ + qemuDomainObjPrivate *priv =3D vm->privateData; + virQEMUDriver *driver =3D priv->driver; + int ret =3D -1; + + VIR_DEBUG("Handle secure guest reboot: destroy phase"); + + virObjectLock(vm); + if (qemuProcessBeginStopJob(vm, VIR_JOB_DESTROY, 0) < 0) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) { + qemuProcessEndStopJob(vm); + goto cleanup; + } + + qemuProcessStop(vm, VIR_DOMAIN_SHUTOFF_DESTROYED, VIR_ASYNC_JOB_NONE, = 0); + virDomainAuditStop(vm, "destroyed"); + + /* skip remove inactive domain from active list */ + qemuProcessEndStopJob(vm); + + VIR_DEBUG("Handle secure guest reboot: boot phase"); + + if (qemuProcessBeginJob(vm, VIR_DOMAIN_JOB_OPERATION_START, 0) < 0) { + qemuDomainRemoveInactive(vm, 0, false); + goto cleanup; + } + + if (qemuProcessStart(NULL, driver, vm, NULL, VIR_ASYNC_JOB_START, + NULL, -1, NULL, NULL, NULL, + VIR_NETDEV_VPORT_PROFILE_OP_CREATE, + 0) < 0) { + virDomainAuditStart(vm, "booted", false); + qemuDomainRemoveInactive(vm, 0, false); + goto endjob; + } + + virDomainAuditStart(vm, "booted", true); + + qemuDomainSaveStatus(vm); + ret =3D 0; + + endjob: + qemuProcessEndJob(vm); + + cleanup: + priv->pausedShutdown =3D false; + qemuDomainSetFakeReboot(vm, false); + if (ret =3D=3D -1) + ignore_value(qemuProcessKill(vm, VIR_QEMU_PROCESS_KILL_FORCE)); + virDomainObjEndAPI(&vm); +} + + /* * Since we have the '-no-shutdown' flag set, the * QEMU process will currently have guest OS shutdown @@ -455,15 +516,13 @@ qemuProcessHandleReset(qemuMonitor *mon G_GNUC_UNUSED, * guest OS booting up again */ static void -qemuProcessFakeReboot(void *opaque) +qemuProcessFakeRebootViaReset(virDomainObj *vm) { - virDomainObj *vm =3D opaque; qemuDomainObjPrivate *priv =3D vm->privateData; virQEMUDriver *driver =3D priv->driver; virDomainRunningReason reason =3D VIR_DOMAIN_RUNNING_BOOTED; int ret =3D -1, rc; =20 - VIR_DEBUG("vm=3D%p", vm); virObjectLock(vm); if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0) goto cleanup; @@ -509,6 +568,21 @@ qemuProcessFakeReboot(void *opaque) } =20 =20 +static void +qemuProcessFakeReboot(void *opaque) +{ + virDomainObj *vm =3D opaque; + + VIR_DEBUG("vm=3D%p", vm); + + if (vm->def->sec && + vm->def->sec->sectype =3D=3D VIR_DOMAIN_LAUNCH_SECURITY_TDX) + qemuProcessFakeRebootViaRecreate(vm); + else + qemuProcessFakeRebootViaReset(vm); +} + + void qemuProcessShutdownOrReboot(virDomainObj *vm) { --=20 2.47.1