From nobody Sun May 5 02:45:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1528986617519142.54325885773994; Thu, 14 Jun 2018 07:30:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1ED9F3001761; Thu, 14 Jun 2018 14:30:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B37258ECF6; Thu, 14 Jun 2018 14:30:14 +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 04B49180BACA; Thu, 14 Jun 2018 14:30:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w5EEUBGl025166 for ; Thu, 14 Jun 2018 10:30:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4E16A111AF3E; Thu, 14 Jun 2018 14:30:11 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7453111AF1C; Thu, 14 Jun 2018 14:30:10 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Thu, 14 Jun 2018 16:30:00 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [libvirt-go PATCH 1/2] Add support for AMD SEV launch security info 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 14 Jun 2018 14:30:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Erik Skultety Reviewed-by: Daniel P. Berrang=C3=A9 --- domain.go | 41 +++++++++++++++++++++++++++++++++++++++++ domain_compat.go | 13 +++++++++++++ domain_compat.h | 6 ++++++ 3 files changed, 60 insertions(+) diff --git a/domain.go b/domain.go index a3049aa..6499cfa 100644 --- a/domain.go +++ b/domain.go @@ -4573,3 +4573,44 @@ func (d *Domain) SetLifecycleAction(lifecycleType ui= nt32, action uint32, flags u =20 return nil } + +type DomainLaunchSecurityParameters struct { + SevMeasurementSet bool + SevMeasurement string +} + +func getDomainLaunchSecurityFieldInfo(params *DomainLaunchSecurityParamete= rs) map[string]typedParamsFieldInfo { + return map[string]typedParamsFieldInfo{ + C.VIR_DOMAIN_LAUNCH_SECURITY_SEV_MEASUREMENT: typedParamsFieldInfo{ + set: ¶ms.SevMeasurementSet, + s: ¶ms.SevMeasurement, + }, + } +} + +// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomain= GetLaunchSecurityInfo +func (d *Domain) GetLaunchSecurityInfo(flags uint32) (*DomainLaunchSecurit= yParameters, error) { + if C.LIBVIR_VERSION_NUMBER < 4005000 { + return nil, GetNotImplementedError("virDomainGetLaunchSecurityInfo") + } + + params :=3D &DomainLaunchSecurityParameters{} + info :=3D getDomainLaunchSecurityFieldInfo(params) + + var cparams *C.virTypedParameter + var nparams C.int + + ret :=3D C.virDomainGetLaunchSecurityInfoCompat(d.ptr, (*C.virTypedParame= terPtr)(unsafe.Pointer(&cparams)), &nparams, C.uint(flags)) + if ret =3D=3D -1 { + return nil, GetLastError() + } + + defer C.virTypedParamsFree(cparams, nparams) + + _, err :=3D typedParamsUnpackLen(cparams, int(nparams), info) + if err !=3D nil { + return nil, err + } + + return params, nil +} diff --git a/domain_compat.go b/domain_compat.go index a46a9c7..73a6db9 100644 --- a/domain_compat.go +++ b/domain_compat.go @@ -367,5 +367,18 @@ int virDomainDetachDeviceAliasCompat(virDomainPtr doma= in, return virDomainDetachDeviceAlias(domain, alias, flags); #endif } + +int virDomainGetLaunchSecurityInfoCompat(virDomainPtr domain, + virTypedParameterPtr *params, + int *nparams, + unsigned int flags) +{ +#if LIBVIR_VERSION_NUMBER < 4005000 + assert(0); // Caller should have checked version +#else + return virDomainGetLaunchSecurityInfo(domain, params, nparams, flags); +#endif +} + */ import "C" diff --git a/domain_compat.h b/domain_compat.h index 55d7e13..5c93ef5 100644 --- a/domain_compat.h +++ b/domain_compat.h @@ -1035,5 +1035,11 @@ int virDomainDetachDeviceAliasCompat(virDomainPtr do= main, const char *alias, unsigned int flags); =20 +/* 4.5.0 */ + +int virDomainGetLaunchSecurityInfoCompat(virDomainPtr domain, + virTypedParameterPtr *params, + int *nparams, + unsigned int flags); =20 #endif /* LIBVIRT_GO_DOMAIN_COMPAT_H__ */ --=20 2.14.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 02:45:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1528986617056226.3060091992371; Thu, 14 Jun 2018 07:30:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 10691307C94F; Thu, 14 Jun 2018 14:30:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B326F7A408; Thu, 14 Jun 2018 14:30:14 +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 27A691800539; Thu, 14 Jun 2018 14:30:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w5EEUCL0025171 for ; Thu, 14 Jun 2018 10:30:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0E6691117631; Thu, 14 Jun 2018 14:30:12 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8827C1117624; Thu, 14 Jun 2018 14:30:11 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Thu, 14 Jun 2018 16:30:01 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [libvirt-go PATCH 2/2] Add support for AMD SEV platform info 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 14 Jun 2018 14:30:15 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Erik Skultety Reviewed-by: Daniel P. Berrang=C3=A9 --- connect.go | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ connect_compat.go | 12 +++++++++++ connect_compat.h | 7 +++++++ 3 files changed, 78 insertions(+) diff --git a/connect.go b/connect.go index e3e643e..8bb5fe6 100644 --- a/connect.go +++ b/connect.go @@ -2765,3 +2765,62 @@ func (c *Connect) GetAllDomainStats(doms []*Domain, = statsTypes DomainStatsTypes, =20 return stats, nil } + +type NodeSEVParameters struct { + PdhSet bool + Pdh string + CertChainSet bool + CertChain string + CbitposSet bool + Cbitpos uint + ReducedPhysBitsSet bool + ReducedPhysBits uint +} + +func getNodeSEVFieldInfo(params *NodeSEVParameters) map[string]typedParams= FieldInfo { + return map[string]typedParamsFieldInfo{ + C.VIR_NODE_SEV_PDH: typedParamsFieldInfo{ + set: ¶ms.PdhSet, + s: ¶ms.Pdh, + }, + C.VIR_NODE_SEV_CERT_CHAIN: typedParamsFieldInfo{ + set: ¶ms.CertChainSet, + s: ¶ms.CertChain, + }, + C.VIR_NODE_SEV_CBITPOS: typedParamsFieldInfo{ + set: ¶ms.CbitposSet, + ui: ¶ms.Cbitpos, + }, + C.VIR_NODE_SEV_REDUCED_PHYS_BITS: typedParamsFieldInfo{ + set: ¶ms.ReducedPhysBitsSet, + ui: ¶ms.ReducedPhysBits, + }, + } +} + +// See also https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetS= EVInfo +func (c *Connect) GetSEVInfo(flags uint32) (*NodeSEVParameters, error) { + if C.LIBVIR_VERSION_NUMBER < 4005000 { + return nil, GetNotImplementedError("virNodeGetSEVInfo") + } + + params :=3D &NodeSEVParameters{} + info :=3D getNodeSEVFieldInfo(params) + + var cparams *C.virTypedParameter + var nparams C.int + + ret :=3D C.virNodeGetSEVInfoCompat(c.ptr, (*C.virTypedParameterPtr)(unsaf= e.Pointer(&cparams)), &nparams, C.uint(flags)) + if ret =3D=3D -1 { + return nil, GetLastError() + } + + defer C.virTypedParamsFree(cparams, nparams) + + _, err :=3D typedParamsUnpackLen(cparams, int(nparams), info) + if err !=3D nil { + return nil, err + } + + return params, nil +} diff --git a/connect_compat.go b/connect_compat.go index 617bc4a..544def2 100644 --- a/connect_compat.go +++ b/connect_compat.go @@ -157,5 +157,17 @@ int virConnectCompareHypervisorCPUCompat(virConnectPtr= conn, #endif } =20 +int virNodeGetSEVInfoCompat(virConnectPtr conn, + virTypedParameterPtr *params, + int *nparams, + unsigned int flags) +{ +#if LIBVIR_VERSION_NUMBER < 4005000 + assert(0); // Caller should have checked version +#else + return virNodeGetSEVInfo(conn, params, nparams, flags); +#endif +} + */ import "C" diff --git a/connect_compat.h b/connect_compat.h index 432ed0c..cd6d678 100644 --- a/connect_compat.h +++ b/connect_compat.h @@ -236,4 +236,11 @@ int virConnectCompareHypervisorCPUCompat(virConnectPtr= conn, const char *xmlCPU, unsigned int flags); =20 +/* 4.5.0 */ + +int virNodeGetSEVInfoCompat(virConnectPtr conn, + virTypedParameterPtr *params, + int *nparams, + unsigned int flags); + #endif /* LIBVIRT_GO_CONNECT_COMPAT_H__ */ --=20 2.14.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list