From: Zhenzhong Duan Date: Thu, 10 Jul 2025 07:21:09 +0000 (-0400) Subject: conf: Add tdx as launch security type X-Git-Tag: v11.6.0-rc1~28 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e919a4dd374535511d962bee2cd64f22f1ac3fa1;p=thirdparty%2Flibvirt.git conf: Add tdx as launch security type When 'tdx' is used, the VM will be launched with Intel TDX feature enabled. TDX feature supports running encrypted VM (Trust Domain, TD) under the control of KVM. A TD runs in a CPU model which protects the confidentiality of its memory and its CPU state from other software. There are four optional child elements. Element policy is 64bit hex, bit 0 is set to enable TDX debug, bit 28 is set to enable sept-ve-disable, other bits are reserved currently. When policy isn't specified, QEMU will use its own default value 0x10000000. mrConfigId, mrOwner and mrOwnerConfig are base64 encoded SHA384 digest string. For example: 0x10000001 xxx xxx xxx Signed-off-by: Zhenzhong Duan Reviewed-by: Daniel P. Berrangé --- diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 23feb2f4da..37d9e2bf72 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1543,6 +1543,7 @@ VIR_ENUM_IMPL(virDomainLaunchSecurity, "sev", "sev-snp", "s390-pv", + "tdx", ); VIR_ENUM_IMPL(virDomainPstoreBackend, @@ -3958,6 +3959,11 @@ virDomainSecDefFree(virDomainSecDef *def) g_free(def->data.sev_snp.id_auth); g_free(def->data.sev_snp.host_data); break; + case VIR_DOMAIN_LAUNCH_SECURITY_TDX: + g_free(def->data.tdx.mrconfigid); + g_free(def->data.tdx.mrowner); + g_free(def->data.tdx.mrownerconfig); + break; case VIR_DOMAIN_LAUNCH_SECURITY_PV: case VIR_DOMAIN_LAUNCH_SECURITY_NONE: case VIR_DOMAIN_LAUNCH_SECURITY_LAST: @@ -14167,6 +14173,29 @@ virDomainSEVSNPDefParseXML(virDomainSEVSNPDef *def, } +static int +virDomainTDXDefParseXML(virDomainTDXDef *def, + xmlXPathContextPtr ctxt) +{ + int rc; + + rc = virXPathULongLongBase("string(./policy)", ctxt, 16, &def->policy); + if (rc == 0) { + def->havePolicy = true; + } else if (rc == -2) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("failed to get launch security policy for launch security type TDX")); + return -1; + } + + def->mrconfigid = virXPathString("string(./mrConfigId)", ctxt); + def->mrowner = virXPathString("string(./mrOwner)", ctxt); + def->mrownerconfig = virXPathString("string(./mrOwnerConfig)", ctxt); + + return 0; +} + + static virDomainSecDef * virDomainSecDefParseXML(xmlNodePtr lsecNode, xmlXPathContextPtr ctxt) @@ -14190,6 +14219,10 @@ virDomainSecDefParseXML(xmlNodePtr lsecNode, if (virDomainSEVSNPDefParseXML(&sec->data.sev_snp, ctxt) < 0) return NULL; break; + case VIR_DOMAIN_LAUNCH_SECURITY_TDX: + if (virDomainTDXDefParseXML(&sec->data.tdx, ctxt) < 0) + return NULL; + break; case VIR_DOMAIN_LAUNCH_SECURITY_PV: break; case VIR_DOMAIN_LAUNCH_SECURITY_NONE: @@ -27663,6 +27696,18 @@ virDomainSEVSNPDefFormat(virBuffer *attrBuf, } +static void +virDomainTDXDefFormat(virBuffer *childBuf, virDomainTDXDef *def) +{ + if (def->havePolicy) + virBufferAsprintf(childBuf, "0x%llx\n", def->policy); + + virBufferEscapeString(childBuf, "%s\n", def->mrconfigid); + virBufferEscapeString(childBuf, "%s\n", def->mrowner); + virBufferEscapeString(childBuf, "%s\n", def->mrownerconfig); +} + + static void virDomainSecDefFormat(virBuffer *buf, virDomainSecDef *sec) { @@ -27684,6 +27729,10 @@ virDomainSecDefFormat(virBuffer *buf, virDomainSecDef *sec) virDomainSEVSNPDefFormat(&attrBuf, &childBuf, &sec->data.sev_snp); break; + case VIR_DOMAIN_LAUNCH_SECURITY_TDX: + virDomainTDXDefFormat(&childBuf, &sec->data.tdx); + break; + case VIR_DOMAIN_LAUNCH_SECURITY_PV: break; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 6008ec66d3..5c4e02fb16 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2965,6 +2965,7 @@ typedef enum { VIR_DOMAIN_LAUNCH_SECURITY_SEV, VIR_DOMAIN_LAUNCH_SECURITY_SEV_SNP, VIR_DOMAIN_LAUNCH_SECURITY_PV, + VIR_DOMAIN_LAUNCH_SECURITY_TDX, VIR_DOMAIN_LAUNCH_SECURITY_LAST, } virDomainLaunchSecurity; @@ -2999,11 +3000,21 @@ struct _virDomainSEVSNPDef { }; +struct _virDomainTDXDef { + bool havePolicy; + unsigned long long policy; + char *mrconfigid; + char *mrowner; + char *mrownerconfig; +}; + + struct _virDomainSecDef { virDomainLaunchSecurity sectype; union { virDomainSEVDef sev; virDomainSEVSNPDef sev_snp; + virDomainTDXDef tdx; } data; }; diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index c7afdbf7fd..9b7418ccb5 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -1936,6 +1936,7 @@ virDomainDefLaunchSecurityValidate(const virDomainDef *def) case VIR_DOMAIN_LAUNCH_SECURITY_NONE: case VIR_DOMAIN_LAUNCH_SECURITY_SEV: case VIR_DOMAIN_LAUNCH_SECURITY_PV: + case VIR_DOMAIN_LAUNCH_SECURITY_TDX: case VIR_DOMAIN_LAUNCH_SECURITY_LAST: break; } diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincommon.rng index 2d6e15f144..bb40e1d439 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -550,6 +550,9 @@ s390-pv + + + @@ -645,6 +648,35 @@ + + + + tdx + + + + + + + + + + + + + + + + + + + + + + + + +