From nobody Sun Feb 8 14:12:24 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.ibm.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 16257778735306.749797582276756; Thu, 8 Jul 2021 13:57:53 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-32-8EWc_3w_NRy3V1K6pn3IsA-1; Thu, 08 Jul 2021 16:57:50 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5B143192D786; Thu, 8 Jul 2021 20:57:45 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0F2C010016FD; Thu, 8 Jul 2021 20:57:45 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B25844EA37; Thu, 8 Jul 2021 20:57:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 168KvgBJ014117 for ; Thu, 8 Jul 2021 16:57:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id C641120B899F; Thu, 8 Jul 2021 20:57:42 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C101F20B8998 for ; Thu, 8 Jul 2021 20:57:37 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D0909107846A for ; Thu, 8 Jul 2021 20:57:37 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-545-bHPW72t7Mw6fBQz0cl_jQQ-1; Thu, 08 Jul 2021 16:57:33 -0400 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 168KoN8m115717; Thu, 8 Jul 2021 16:57:33 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 39nrfhjb07-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Jul 2021 16:57:33 -0400 Received: from m0098413.ppops.net (m0098413.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 168KrA9M125107; Thu, 8 Jul 2021 16:57:32 -0400 Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0b-001b2d01.pphosted.com with ESMTP id 39nrfhjayv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Jul 2021 16:57:32 -0400 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 168KoK24019581; Thu, 8 Jul 2021 20:57:30 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma06ams.nl.ibm.com with ESMTP id 39jf5hac7t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Jul 2021 20:57:30 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 168KvRPR31719878 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 8 Jul 2021 20:57:27 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7C6A54C04A; Thu, 8 Jul 2021 20:57:27 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 438EC4C04E; Thu, 8 Jul 2021 20:57:27 +0000 (GMT) Received: from localhost.localdomain (unknown [9.145.9.182]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 8 Jul 2021 20:57:27 +0000 (GMT) X-MC-Unique: 8EWc_3w_NRy3V1K6pn3IsA-1 X-MC-Unique: bHPW72t7Mw6fBQz0cl_jQQ-1 From: Boris Fiuczynski To: libvir-list@redhat.com, danielhb413@gmail.com Subject: [PATCH v4 2/8] conf: rework SEV XML parse and format methods Date: Thu, 8 Jul 2021 22:57:18 +0200 Message-Id: <20210708205724.14643-3-fiuczy@linux.ibm.com> In-Reply-To: <20210708205724.14643-1-fiuczy@linux.ibm.com> References: <20210708205724.14643-1-fiuczy@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: VqSiRb_DpWmajlJtXTevJUwwP8OO05LD X-Proofpoint-ORIG-GUID: FGQYFVH88zTqV4h9tZgzWfH1HB6hBhDB X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-08_11:2021-07-08, 2021-07-08 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 lowpriorityscore=0 suspectscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 adultscore=0 impostorscore=0 priorityscore=1501 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107080104 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: phrdina@redhat.com, pasic@linux.ibm.com, pkrempa@redhat.com, mhartmay@linux.ibm.com, shalini@linux.ibm.com, bwalk@linux.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1625777875244100001 Content-Type: text/plain; charset="utf-8" Make use of virDomainLaunchSecurity enum. Signed-off-by: Boris Fiuczynski Reviewed-by: Daniel Henrique Barboza --- src/conf/domain_conf.c | 110 ++++++++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 45 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 103bb47566..99414cc4cd 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14732,41 +14732,51 @@ virDomainSEVDefParseXML(xmlNodePtr sevNode, &def->sectype) < 0) return NULL; =20 - if (virXPathULongHex("string(./policy)", ctxt, &policy) < 0) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("failed to get launch security policy for " - "launch security type SEV")); - return NULL; - } + switch ((virDomainLaunchSecurity) def->sectype) { + case VIR_DOMAIN_LAUNCH_SECURITY_SEV: + if (virXPathULongHex("string(./policy)", ctxt, &policy) < 0) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("failed to get launch security policy for " + "launch security type SEV")); + return NULL; + } =20 - /* the following attributes are platform dependent and if missing, we = can - * autofill them from domain capabilities later - */ - rc =3D virXPathUInt("string(./cbitpos)", ctxt, &def->cbitpos); - if (rc =3D=3D 0) { - def->haveCbitpos =3D true; - } else if (rc =3D=3D -2) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Invalid format for launch security cbitpos")); - return NULL; - } + /* the following attributes are platform dependent and if missing,= we can + * autofill them from domain capabilities later + */ + rc =3D virXPathUInt("string(./cbitpos)", ctxt, &def->cbitpos); + if (rc =3D=3D 0) { + def->haveCbitpos =3D true; + } else if (rc =3D=3D -2) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Invalid format for launch security cbitpos")= ); + return NULL; + } =20 - rc =3D virXPathUInt("string(./reducedPhysBits)", ctxt, - &def->reduced_phys_bits); - if (rc =3D=3D 0) { - def->haveReducedPhysBits =3D true; - } else if (rc =3D=3D -2) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Invalid format for launch security " - "reduced-phys-bits")); - return NULL; - } + rc =3D virXPathUInt("string(./reducedPhysBits)", ctxt, + &def->reduced_phys_bits); + if (rc =3D=3D 0) { + def->haveReducedPhysBits =3D true; + } else if (rc =3D=3D -2) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Invalid format for launch security " + "reduced-phys-bits")); + return NULL; + } =20 - def->policy =3D policy; - def->dh_cert =3D virXPathString("string(./dhCert)", ctxt); - def->session =3D virXPathString("string(./session)", ctxt); + def->policy =3D policy; + def->dh_cert =3D virXPathString("string(./dhCert)", ctxt); + def->session =3D virXPathString("string(./session)", ctxt); =20 - return g_steal_pointer(&def); + return g_steal_pointer(&def); + case VIR_DOMAIN_LAUNCH_SECURITY_NONE: + case VIR_DOMAIN_LAUNCH_SECURITY_LAST: + default: + virReportError(VIR_ERR_XML_ERROR, + _("unsupported launch security type '%s'"), + virDomainLaunchSecurityTypeToString(def->sectype)); + return NULL; + } } =20 =20 @@ -26857,28 +26867,38 @@ virDomainKeyWrapDefFormat(virBuffer *buf, virDoma= inKeyWrapDef *keywrap) static void virDomainSEVDefFormat(virBuffer *buf, virDomainSEVDef *sev) { + g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); + if (!sev) return; =20 - virBufferAsprintf(buf, "\n", + virBufferAsprintf(&attrBuf, " type=3D'%s'", virDomainLaunchSecurityTypeToString(sev->sectype)); - virBufferAdjustIndent(buf, 2); =20 - if (sev->haveCbitpos) - virBufferAsprintf(buf, "%d\n", sev->cbitpos); + switch ((virDomainLaunchSecurity) sev->sectype) { + case VIR_DOMAIN_LAUNCH_SECURITY_SEV: { + if (sev->haveCbitpos) + virBufferAsprintf(&childBuf, "%d\n", sev->c= bitpos); =20 - if (sev->haveReducedPhysBits) - virBufferAsprintf(buf, "%d\n", - sev->reduced_phys_bits); - virBufferAsprintf(buf, "0x%04x\n", sev->policy); - if (sev->dh_cert) - virBufferEscapeString(buf, "%s\n", sev->dh_cert); + if (sev->haveReducedPhysBits) + virBufferAsprintf(&childBuf, "%d\n", + sev->reduced_phys_bits); + virBufferAsprintf(&childBuf, "0x%04x\n", sev->pol= icy); + if (sev->dh_cert) + virBufferEscapeString(&childBuf, "%s\n", sev-= >dh_cert); =20 - if (sev->session) - virBufferEscapeString(buf, "%s\n", sev->session= ); + if (sev->session) + virBufferEscapeString(&childBuf, "%s\n", se= v->session); =20 - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); + break; + } + case VIR_DOMAIN_LAUNCH_SECURITY_NONE: + case VIR_DOMAIN_LAUNCH_SECURITY_LAST: + return; + } + + virXMLFormatElement(buf, "launchSecurity", &attrBuf, &childBuf); } =20 =20 --=20 2.31.1