From nobody Wed Dec 17 03:40:20 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 1750845662316474.8529877480671; Wed, 25 Jun 2025 03:01:02 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 452F612AE; Wed, 25 Jun 2025 06:01:01 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id A38FB9A3; Wed, 25 Jun 2025 05:52:18 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id AED1B14E3; Wed, 25 Jun 2025 05:52:13 -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 F1C36144E for ; Wed, 25 Jun 2025 05:51:27 -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:25 -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:22 -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=1750845088; x=1782381088; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=f/yhlr7Jmk0LAs5kY4ugKLYBrLj7bGOfjIukssajwb8=; b=hKmRvaWsc5zqVyx1FMBGAhGqXIYaG/cJCTo/iWSMbKc4LeqRr3dy9Hmf pt49w7raYOKt23h7ElzfdLtYkOheAcYHSUqnt3AHVVTMqWIl+oo/5gd1G LwMpCw7f0v9PtozB0dSKu6tqdQjH/32CGdzWpsL10xKOWTBxp6rqaoYOr 9Xx6lMVO4ZpbHVnU3k4jccXtlMxpUoM2YHx/yHCYOwq4feyWDGP8OzzNz 2Mkkn5Qz9uBdKb/MZXe6Snsx+FpTKlfjuL+4GIQ8pqDjoTZAcVIGH9sQ+ oFoQirBjk90nsFLhtOInYLJzsH/ChdSZdFeCQ8cSkeUVI+eGWKL0dguDN g==; X-CSE-ConnectionGUID: WxPbQOu5TCCWD7qxnJhctw== X-CSE-MsgGUID: BdhVnN7URRaqj6u4+3ehAg== X-IronPort-AV: E=McAfee;i="6800,10657,11474"; a="70680424" X-IronPort-AV: E=Sophos;i="6.16,264,1744095600"; d="scan'208";a="70680424" X-CSE-ConnectionGUID: IKWGJ6kTRuaY+EiCgC8Yrg== X-CSE-MsgGUID: XyNQUO4GToKf5MKv27Uavw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,264,1744095600"; d="scan'208";a="151787310" From: Zhenzhong Duan To: devel@lists.libvirt.org Subject: [PATCH v2 17/21] qemu: Support domain reset command for TDX guest Date: Wed, 25 Jun 2025 17:45:29 +0800 Message-Id: <20250625094533.234897-18-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: FDZ6L37RQC3OAPL4KUT6GQ3T75TTD3BF X-Message-ID-Hash: FDZ6L37RQC3OAPL4KUT6GQ3T75TTD3BF 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: 1750845663449116600 Content-Type: text/plain; charset="utf-8" TDX guest doesn't support system_reset, so have to kill the old guest and start a new one to simulate the reset. This can be achieved by calling qemuProcessFakeRebootViaRecreate(). Domain lock is already hold in qemuDomainReset() before calling qemuProcessFakeRebootViaRecreate(), so bypass locking in it. Signed-off-by: Zhenzhong Duan --- src/qemu/qemu_driver.c | 6 ++++++ src/qemu/qemu_process.c | 14 +++++++++----- src/qemu/qemu_process.h | 2 ++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a75e09b6de..c6566f65d0 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1976,6 +1976,12 @@ qemuDomainReset(virDomainPtr dom, unsigned int flags) if (virDomainResetEnsureACL(dom->conn, vm->def) < 0) goto cleanup; =20 + if (vm->def->sec && + vm->def->sec->sectype =3D=3D VIR_DOMAIN_LAUNCH_SECURITY_TDX) { + ret =3D qemuProcessFakeRebootViaRecreate(vm, true); + goto cleanup; + } + if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0) goto cleanup; =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 68c0a5b64d..e7fcace9e2 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -450,8 +450,8 @@ qemuProcessHandleReset(qemuMonitor *mon G_GNUC_UNUSED, * Secure guest doesn't support fake reboot via machine CPU reset. * We thus fake reboot via QEMU re-creation. */ -static void -qemuProcessFakeRebootViaRecreate(virDomainObj *vm) +int +qemuProcessFakeRebootViaRecreate(virDomainObj *vm, bool locked) { qemuDomainObjPrivate *priv =3D vm->privateData; virQEMUDriver *driver =3D priv->driver; @@ -460,7 +460,9 @@ qemuProcessFakeRebootViaRecreate(virDomainObj *vm) =20 VIR_DEBUG("Handle secure guest reboot: destroy phase"); =20 - virObjectLock(vm); + if (!locked) + virObjectLock(vm); + if (qemuProcessBeginStopJob(vm, VIR_JOB_DESTROY, 0) < 0) goto cleanup; =20 @@ -513,7 +515,9 @@ qemuProcessFakeRebootViaRecreate(virDomainObj *vm) qemuDomainSetFakeReboot(vm, false); if (ret =3D=3D -1) ignore_value(qemuProcessKill(vm, VIR_QEMU_PROCESS_KILL_FORCE)); - virDomainObjEndAPI(&vm); + if (!locked) + virDomainObjEndAPI(&vm); + return ret; } =20 =20 @@ -587,7 +591,7 @@ qemuProcessFakeReboot(void *opaque) =20 if (vm->def->sec && vm->def->sec->sectype =3D=3D VIR_DOMAIN_LAUNCH_SECURITY_TDX) - qemuProcessFakeRebootViaRecreate(vm); + ignore_value(qemuProcessFakeRebootViaRecreate(vm, false)); else qemuProcessFakeRebootViaReset(vm); } diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index b8c4af4aaf..9f783790ac 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -190,6 +190,8 @@ typedef enum { =20 int qemuProcessKill(virDomainObj *vm, unsigned int flags); =20 +int qemuProcessFakeRebootViaRecreate(virDomainObj *vm, bool locked); + void qemuProcessShutdownOrReboot(virDomainObj *vm); =20 void qemuProcessAutoDestroy(virDomainObj *dom, --=20 2.34.1