From nobody Mon May 13 05:16:48 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=oss.nttdata.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1708410981249146.0879728326522; Mon, 19 Feb 2024 22:36:21 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 029CE1A21; Tue, 20 Feb 2024 01:36:19 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 90CAA1D2C; Tue, 20 Feb 2024 01:33:04 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 8E69F1A13; Tue, 20 Feb 2024 01:32:51 -0500 (EST) Received: from oss.nttdata.com (oss.nttdata.com [49.212.34.109]) (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 6E34D19F6 for ; Tue, 20 Feb 2024 01:32:50 -0500 (EST) Received: from fedora.. (fp5ccbe197.tkyc401.ap.nuro.jp [92.203.225.151]) by oss.nttdata.com (Postfix) with ESMTPSA id AF3C961382; Tue, 20 Feb 2024 15:32:46 +0900 (JST) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at oss.nttdata.com From: Takashi Kajinami To: devel@lists.libvirt.org Subject: [PATCH v2 1/1] Expose available AMD SEV models in domain capabilities Date: Tue, 20 Feb 2024 15:31:37 +0900 Message-ID: <20240220063224.879158-2-kajinamit@oss.nttdata.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240220063224.879158-1-kajinamit@oss.nttdata.com> References: <20240220063224.879158-1-kajinamit@oss.nttdata.com> MIME-Version: 1.0 Message-ID-Hash: MUEJCPCAJEKGKS2BGM2ZKX4X5SUVKEUX X-Message-ID-Hash: MUEJCPCAJEKGKS2BGM2ZKX4X5SUVKEUX X-MailFrom: kajinamit@oss.nttdata.com 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; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Takashi Kajinami 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: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1708410982656100001 This introduces the new "model" field in sev elements, returned by domain capabilities API, so that client can ensure SEV-ES is available in this hypervisor. Signed-off-by: Takashi Kajinami --- docs/formatdomaincaps.rst | 5 ++ src/conf/domain_capabilities.c | 2 + src/conf/domain_capabilities.h | 1 + src/conf/domain_conf.c | 7 +++ src/conf/domain_conf.h | 8 ++++ src/qemu/qemu_capabilities.c | 84 +++++++++++++++++++++++++--------- 6 files changed, 85 insertions(+), 22 deletions(-) diff --git a/docs/formatdomaincaps.rst b/docs/formatdomaincaps.rst index ef752a0f3a..78a6f8736f 100644 --- a/docs/formatdomaincaps.rst +++ b/docs/formatdomaincaps.rst @@ -753,6 +753,11 @@ in domain XML `__ ``maxESGuests`` The maximum number of SEV-ES guests that can be launched on the host. T= his value may be configurable in the firmware for some hosts. +``cpu0Id`` + ID of CPU0, which is used to get the signed Chip Endorsement Key (CEK) = of + the CPU of AMD system from AMD's Key Distribution Service (KDS). +``model`` + Available SEV models. =20 SGX capabilities ^^^^^^^^^^^^^^^^ diff --git a/src/conf/domain_capabilities.c b/src/conf/domain_capabilities.c index 68eb3c9797..26d9b0a21c 100644 --- a/src/conf/domain_capabilities.c +++ b/src/conf/domain_capabilities.c @@ -654,6 +654,8 @@ virDomainCapsFeatureSEVFormat(virBuffer *buf, if (sev->cpu0_id !=3D NULL) virBufferAsprintf(buf, "%s\n", sev->cpu0_id); =20 + ENUM_PROCESS(sev, model, virDomainSevModelTypeToString); + virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); } diff --git a/src/conf/domain_capabilities.h b/src/conf/domain_capabilities.h index fadc30cdd7..1a84ea6101 100644 --- a/src/conf/domain_capabilities.h +++ b/src/conf/domain_capabilities.h @@ -213,6 +213,7 @@ struct _virSEVCapability { unsigned int reduced_phys_bits; unsigned int max_guests; unsigned int max_es_guests; + virDomainCapsEnum model; }; =20 typedef struct _virSGXSection virSGXSection; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3597959e33..cf0077d584 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1509,6 +1509,13 @@ VIR_ENUM_IMPL(virDomainLaunchSecurity, "s390-pv", ); =20 +VIR_ENUM_IMPL(virDomainSevModel, + VIR_DOMAIN_SEV_MODEL_LAST, + "", + "sev", + "sev-es", +); + typedef enum { VIR_DOMAIN_NET_VHOSTUSER_MODE_NONE, VIR_DOMAIN_NET_VHOSTUSER_MODE_CLIENT, diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index c7e5005b3b..a06fde1032 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2854,6 +2854,13 @@ typedef enum { VIR_DOMAIN_LAUNCH_SECURITY_LAST, } virDomainLaunchSecurity; =20 +typedef enum { + VIR_DOMAIN_SEV_MODEL_NONE, + VIR_DOMAIN_SEV_MODEL_SEV, + VIR_DOMAIN_SEV_MODEL_SEV_ES, + + VIR_DOMAIN_SEV_MODEL_LAST, +} virDomainSevModel; =20 struct _virDomainSEVDef { char *dh_cert; @@ -4237,6 +4244,7 @@ VIR_ENUM_DECL(virDomainCryptoType); VIR_ENUM_DECL(virDomainCryptoBackend); VIR_ENUM_DECL(virDomainShmemModel); VIR_ENUM_DECL(virDomainShmemRole); +VIR_ENUM_DECL(virDomainSevModel); VIR_ENUM_DECL(virDomainLaunchSecurity); /* from libvirt.h */ VIR_ENUM_DECL(virDomainState); diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index e383d85920..d264c3128c 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -1881,6 +1881,7 @@ virQEMUCapsSEVInfoCopy(virSEVCapability **dst, tmp->reduced_phys_bits =3D src->reduced_phys_bits; tmp->max_guests =3D src->max_guests; tmp->max_es_guests =3D src->max_es_guests; + tmp->model =3D src->model; =20 *dst =3D g_steal_pointer(&tmp); } @@ -3402,6 +3403,62 @@ virQEMUCapsGetSEVMaxGuests(virSEVCapability *caps) } } =20 + +/* + * Check whether AMD Secure Encrypted Virtualization (x86) is enabled + */ +static bool +virQEMUCapsKVMSupportsSecureGuestSEV(void) +{ + g_autofree char *modValue =3D NULL; + + if (virFileReadValueString(&modValue, "/sys/module/kvm_amd/parameters/= sev") < 0) + return false; + + if (modValue[0] !=3D '1' && modValue[0] !=3D 'Y' && modValue[0] !=3D '= y') + return false; + + if (virFileExists(QEMU_DEV_SEV)) + return true; + + return false; +} + + +/* + * Check whether AMD Secure Encrypted Virtualization-Encrypted State (x86)= is enabled + */ +static bool +virQEMUCapsKVMSupportsSecureGuestSEVES(void) +{ + g_autofree char *modValue =3D NULL; + + if (virFileReadValueString(&modValue, "/sys/module/kvm_amd/parameters/= sev_es") < 0) + return false; + + if (modValue[0] !=3D '1' && modValue[0] !=3D 'Y' && modValue[0] !=3D '= y') + return false; + + if (virFileExists(QEMU_DEV_SEV)) + return true; + + return false; +} + + +static void +virQEMUCapsGetSEVModel(virSEVCapability *caps) +{ + caps->model.report =3D true; + + if (virQEMUCapsKVMSupportsSecureGuestSEV()) + VIR_DOMAIN_CAPS_ENUM_SET(caps->model, VIR_DOMAIN_SEV_MODEL_SEV); + + if (virQEMUCapsKVMSupportsSecureGuestSEVES()) + VIR_DOMAIN_CAPS_ENUM_SET(caps->model, VIR_DOMAIN_SEV_MODEL_SEV_ES); +} + + static int virQEMUCapsProbeQMPSEVCapabilities(virQEMUCaps *qemuCaps, qemuMonitor *mon) @@ -3423,6 +3480,8 @@ virQEMUCapsProbeQMPSEVCapabilities(virQEMUCaps *qemuC= aps, =20 virQEMUCapsGetSEVMaxGuests(caps); =20 + virQEMUCapsGetSEVModel(caps); + virSEVCapabilitiesFree(qemuCaps->sevCapabilities); qemuCaps->sevCapabilities =3D caps; return 0; @@ -4219,6 +4278,8 @@ virQEMUCapsParseSEVInfo(virQEMUCaps *qemuCaps, xmlXPa= thContextPtr ctxt) */ virQEMUCapsGetSEVMaxGuests(sev); =20 + virQEMUCapsGetSEVModel(sev); + qemuCaps->sevCapabilities =3D g_steal_pointer(&sev); return 0; } @@ -5038,27 +5099,6 @@ virQEMUCapsKVMSupportsSecureGuestS390(void) } =20 =20 -/* - * Check whether AMD Secure Encrypted Virtualization (x86) is enabled - */ -static bool -virQEMUCapsKVMSupportsSecureGuestAMD(void) -{ - g_autofree char *modValue =3D NULL; - - if (virFileReadValueString(&modValue, "/sys/module/kvm_amd/parameters/= sev") < 0) - return false; - - if (modValue[0] !=3D '1' && modValue[0] !=3D 'Y' && modValue[0] !=3D '= y') - return false; - - if (virFileExists(QEMU_DEV_SEV)) - return true; - - return false; -} - - /* * Check whether the secure guest functionality is enabled. * See the specific architecture function for details on the verifications= made. @@ -5072,7 +5112,7 @@ virQEMUCapsKVMSupportsSecureGuest(void) return virQEMUCapsKVMSupportsSecureGuestS390(); =20 if (ARCH_IS_X86(arch)) - return virQEMUCapsKVMSupportsSecureGuestAMD(); + return virQEMUCapsKVMSupportsSecureGuestSEV(); =20 return false; } --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org