From nobody Wed Dec 4 18:57:09 2024 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 1716532552389597.0880487626099; Thu, 23 May 2024 23:35:52 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 6765C1CC3; Fri, 24 May 2024 02:35:51 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id BBA8A1B35; Fri, 24 May 2024 02:26:58 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id AA9BD1B1D; Fri, 24 May 2024 02:26:50 -0400 (EDT) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (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 9A6B91B1D for ; Fri, 24 May 2024 02:25:54 -0400 (EDT) Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 May 2024 23:24:53 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 May 2024 23:24:51 -0700 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, 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=1716531955; x=1748067955; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uMkf+BnxkcnJEl3E2ah7ThsoMx9pAjnMNeaoEN9xaY0=; b=lbzHXFUMfKTqZz1JCbnmKgObv3tOEgahCDG3e+LGySuN4BPsoFAPa5WB nLqug4kn8DQfUIX2OiMSYsXOovGevyr/LNdlC2dgSmqKDudJaxWZfEdNi gmv4CusCXhg2K7WkKtNxAy1459pFBo4E/KaHd7MqQKxW3AcI623UmqvSV 3Uw5GW93AfQTYrYI0x/vN1u6T7WW8ZIa9DXad0heVJM2ejus7TqNMa323 7B0o/8cf6EAgCKeANSu597RWJjvh0yorm4TdxamTo3DeYFmXAlL9jCkGP amAZSCILXVnfgBW6kl2+pBpJu3Y9bURP+PkUdgdyT92Scjt3sO/fbBCSW A==; X-CSE-ConnectionGUID: Art1svX9QGSDnrc4eSTaOw== X-CSE-MsgGUID: y+2R0dQmT+qHioWiqNp4lA== X-IronPort-AV: E=McAfee;i="6600,9927,11081"; a="13081272" X-IronPort-AV: E=Sophos;i="6.08,184,1712646000"; d="scan'208";a="13081272" X-CSE-ConnectionGUID: I6QmiBBISXarliiISfIdgA== X-CSE-MsgGUID: uJtANuIyRQOQXRCbLuI72A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,184,1712646000"; d="scan'208";a="34034013" From: Zhenzhong Duan To: devel@lists.libvirt.org Subject: [PATCH rfcv4 09/13] qemu: add FakeReboot support for TDX guest Date: Fri, 24 May 2024 14:21:24 +0800 Message-Id: <20240524062128.523820-10-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240524062128.523820-1-zhenzhong.duan@intel.com> References: <20240524062128.523820-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: DREOFEHX4L56IVGUWQMQJ5TFY42BJ6BK X-Message-ID-Hash: DREOFEHX4L56IVGUWQMQJ5TFY42BJ6BK 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: 1716532553073100001 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 --- src/qemu/qemu_process.c | 74 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index bd8624e3f6..35758d882f 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -441,6 +441,75 @@ qemuProcessHandleReset(qemuMonitor *mon G_GNUC_UNUSED, } =20 =20 +static void +qemuProcessSecFakeReboot(void *opaque) +{ + virDomainObj *vm =3D opaque; + qemuDomainObjPrivate *priv =3D vm->privateData; + virQEMUDriver *driver =3D priv->driver; + unsigned int stopFlags =3D 0; + virObjectEvent *event =3D NULL; + virObjectEvent * event2 =3D NULL; + + VIR_DEBUG("Handle secure guest reboot: destroy phase"); + + virObjectLock(vm); + if (qemuProcessBeginStopJob(vm, VIR_JOB_DESTROY, 0) < 0) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) { + virDomainObjEndJob(vm); + goto cleanup; + } + + if (vm->job->asyncJob =3D=3D VIR_ASYNC_JOB_MIGRATION_IN) + stopFlags |=3D VIR_QEMU_PROCESS_STOP_MIGRATED; + + qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_DESTROYED, + VIR_ASYNC_JOB_NONE, stopFlags); + virDomainAuditStop(vm, "destroyed"); + + event =3D virDomainEventLifecycleNewFromObj(vm, + VIR_DOMAIN_EVENT_STOPPED, + VIR_DOMAIN_EVENT_STOPPED_DESTROYED); + + virObjectEventStateQueue(driver->domainEventState, event); + /* skip remove inactive domain from active list */ + virDomainObjEndJob(vm); + + VIR_DEBUG("Handle secure guest reboot: boot phase"); + + if (qemuProcessBeginJob(vm, VIR_DOMAIN_JOB_OPERATION_START, 0) < 0) { + qemuDomainRemoveInactive(driver, vm, 0, false); + goto cleanup; + } + + if (qemuProcessStart(NULL, driver, vm, NULL, VIR_ASYNC_JOB_START, + NULL, -1, NULL, NULL, + VIR_NETDEV_VPORT_PROFILE_OP_CREATE, + 0) < 0) { + virDomainAuditStart(vm, "booted", false); + qemuDomainRemoveInactive(driver, vm, 0, false); + goto endjob; + } + + virDomainAuditStart(vm, "booted", true); + event2 =3D virDomainEventLifecycleNewFromObj(vm, + VIR_DOMAIN_EVENT_STARTED, + VIR_DOMAIN_EVENT_STARTED_BOOTED); + virObjectEventStateQueue(driver->domainEventState, event2); + + qemuDomainSaveStatus(vm); + + endjob: + qemuProcessEndJob(vm); + + cleanup: + qemuDomainSetFakeReboot(vm, false); + virDomainObjEndAPI(&vm); +} + + /* * Since we have the '-no-shutdown' flag set, the * QEMU process will currently have guest OS shutdown @@ -459,6 +528,11 @@ qemuProcessFakeReboot(void *opaque) int ret =3D -1, rc; =20 VIR_DEBUG("vm=3D%p", vm); + + if (vm->def->sec && + vm->def->sec->sectype =3D=3D VIR_DOMAIN_LAUNCH_SECURITY_TDX) + return qemuProcessSecFakeReboot(opaque); + virObjectLock(vm); if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0) goto cleanup; --=20 2.34.1