From nobody Tue Mar 3 03:25:04 2026 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; 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=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1771962290; cv=none; d=zohomail.com; s=zohoarc; b=UUoRfY4kDZrclC4VeGnM3O0N3cGXjgOVlCcHRxOuDRiP08HsBjWM+DCOk6UzW8TeuMHTj+c//tWNVefrYW7OR1yxEWxMiuzi3b9A7lrBsgvW8bk5UVRqBT2nERZ0RC0sxHX5ZiWRGhJ0I6fho01GL+4dqkD9ih1u9Cls8wNAuGM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771962290; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Subject:Subject:To:To:Message-Id; bh=0XSTny0dX7TEtFb+mqIIAvo5gBREdWHannN9v4gKSwk=; b=ivAk+6+J8dGpmVExfiA9kChGv2/PRXya8abg6nWHpUMRWKr57isE0VRoDiy3tGWCTsYhMomBaRskNK9K5Vrw1i7mFlsWeVL2Hm+rNM8LTLOJziSUHHtoXJVEbpkB7xMrz4gd1bZ1Qmp+41mnHSwLSZIKtwApDSFN81ueQG4mlxg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 177196229078375.42453183829048; Tue, 24 Feb 2026 11:44:50 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 53BD141D2D; Tue, 24 Feb 2026 14:44:49 -0500 (EST) Received: from [172.19.199.9] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id A127C41DA4; Tue, 24 Feb 2026 14:44:05 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 4AB5E41CE7; Tue, 24 Feb 2026 14:44:01 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id BBD4E4194A for ; Tue, 24 Feb 2026 14:43:59 -0500 (EST) Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-584-TrtpQX_5Na2a87MIw_ERVg-1; Tue, 24 Feb 2026 14:43:57 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F375A1956050 for ; Tue, 24 Feb 2026 19:43:56 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.90.25]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E8FFA1800668; Tue, 24 Feb 2026 19:43:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1771962239; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0XSTny0dX7TEtFb+mqIIAvo5gBREdWHannN9v4gKSwk=; b=FCR5BS0n5eemz5Vi8bGGBwx8/e7XqiUn1rMAzq1MO60CrynZimAK3glfqA6jYMygbbLelS /qja+YfQNh3rAzAyhZrkwMnBkA9kOPZAtwUpNP7/Aq+lAo1EI+xFge1NQMsAVpTxRpGmHX uO72HVSG6Dwmygr+JVn4XTJpr4EjQGE= X-MC-Unique: TrtpQX_5Na2a87MIw_ERVg-1 X-Mimecast-MFC-AGG-ID: TrtpQX_5Na2a87MIw_ERVg_1771962237 To: devel@lists.libvirt.org Subject: [PATCH] hyperv: report whether guests have TPM enabled Date: Tue, 24 Feb 2026 13:43:54 -0600 Message-ID: <20260224194354.3813322-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: jZ8lNwqiMrrY6WWlmzLqKMuP6GG6rBhmXO8njOdvFWk_1771962237 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 4B2COTLQCR3UDNVJBJ7ZRPR4YRZQIZWQ X-Message-ID-Hash: 4B2COTLQCR3UDNVJBJ7ZRPR4YRZQIZWQ X-MailFrom: jjongsma@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: mnecas@redhat.com, ehazan@redhat.com X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Jonathon Jongsma via Devel Reply-To: Jonathon Jongsma X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1771962293551158500 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- src/hyperv/hyperv_driver.c | 32 +++++++++++++++++++++++++++ src/hyperv/hyperv_wmi.c | 26 ++++++++++++++++++++++ src/hyperv/hyperv_wmi.h | 4 ++++ src/hyperv/hyperv_wmi_generator.input | 9 ++++++++ 4 files changed, 71 insertions(+) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index b01b4919fe..7cc67129cd 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -200,6 +200,22 @@ hypervGetOperatingSystem(hypervPrivate *priv, Win32_Op= eratingSystem **operatingS } =20 =20 +static int +hypervDomainGetTPMEnabled(hypervPrivate *priv, + const char *id, + bool *enabled) +{ + g_autoptr(Msvm_SecuritySettingData) securitySD =3D NULL; + + if (hypervGetSecuritySD(priv, id, &securitySD) < 0) + return -1; + + VIR_DEBUG("Getting TPM state for '%s': %u", id, securitySD->data->TpmE= nabled); + *enabled =3D securitySD->data->TpmEnabled; + return 0; +} + + static int hypervRequestStateChange(virDomainPtr domain, int state) { @@ -2651,6 +2667,7 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned = int flags) g_autoptr(Msvm_SerialPortSettingData) spsd =3D NULL; Msvm_ResourceAllocationSettingData *serialDevices =3D NULL; g_autoptr(Msvm_EthernetPortAllocationSettingData) nets =3D NULL; + bool tpmEnabled =3D false; =20 virCheckFlags(VIR_DOMAIN_XML_COMMON_FLAGS, NULL); =20 @@ -2791,6 +2808,21 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned= int flags) if (hypervDomainDefParseEthernet(domain, def, nets) < 0) return NULL; =20 + if (hypervDomainGetTPMEnabled(priv, virtualSystemSettingData->data->In= stanceID, &tpmEnabled) =3D=3D 0 + && tpmEnabled) { + virDomainTPMDef* tpm =3D NULL; + + if (!def->tpms) { + def->tpms =3D g_new0(virDomainTPMDef *, 1); + } + + tpm =3D g_new0(virDomainTPMDef, 1); + tpm->model =3D VIR_DOMAIN_TPM_MODEL_DEFAULT; + tpm->type =3D VIR_DOMAIN_TPM_TYPE_EMULATOR; + + def->tpms[def->ntpms++] =3D tpm; + } + /* XXX xmlopts must be non-NULL */ return virDomainDefFormat(def, NULL, virDomainDefFormatConvertXMLFlags= (flags)); } diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index 7ae3afc40a..1cf442dad3 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -1625,3 +1625,29 @@ hypervMsvmVSMSModifyResourceSettings(hypervPrivate *= priv, =20 return 0; } + + +int +hypervGetSecuritySD(hypervPrivate *priv, + const char *vssd_instanceid, + Msvm_SecuritySettingData **data) +{ + g_auto(virBuffer) query =3D VIR_BUFFER_INITIALIZER; + + virBufferEscapeSQL(&query, + "ASSOCIATORS OF {Msvm_VirtualSystemSettingData.Inst= anceID=3D'%s'} " + "WHERE ResultClass =3D Msvm_SecuritySettingData", + vssd_instanceid); + + if (hypervGetWmiClass(Msvm_SecuritySettingData, data) < 0) + return -1; + + if (!*data) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not look up security setting data with vir= tual system instance ID '%1$s'"), + vssd_instanceid); + return -1; + } + + return 0; +} diff --git a/src/hyperv/hyperv_wmi.h b/src/hyperv/hyperv_wmi.h index 65b1211b89..0f8cfb30bc 100644 --- a/src/hyperv/hyperv_wmi.h +++ b/src/hyperv/hyperv_wmi.h @@ -269,6 +269,10 @@ int hypervImageManagementServiceGetVHDSD(hypervPrivate= *priv, const char *vhdPath, WsXmlDocH *settingDataDoc); =20 +int hypervGetSecuritySD(hypervPrivate *priv, + const char *vssd_instanceid, + Msvm_SecuritySettingData **data); + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *= * * * Msvm_VirtualSystemManagementService */ diff --git a/src/hyperv/hyperv_wmi_generator.input b/src/hyperv/hyperv_wmi_= generator.input index 017b7a0fa5..b3cd9d19fb 100644 --- a/src/hyperv/hyperv_wmi_generator.input +++ b/src/hyperv/hyperv_wmi_generator.input @@ -1252,3 +1252,12 @@ class Win32_DiskDrive uint64 TotalTracks uint32 TracksPerCylinder end + +class Msvm_SecuritySettingData + boolean TpmEnabled + boolean KsdEnabled + boolean ShieldingRequested + boolean DataProtectionRequested + boolean EncryptStateAndVmMigrationTraffic + boolean VirtualizationBasedSecurityOptOut +end --=20 2.53.0