From nobody Fri Oct 18 08:50:40 2024 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1719309236667152.67914459843985; Tue, 25 Jun 2024 02:53:56 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 9ADAE9B0; Tue, 25 Jun 2024 05:53:55 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id A981713A6; Tue, 25 Jun 2024 05:49:40 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E86B913E9; Tue, 25 Jun 2024 05:49:26 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 75B60137F for ; Tue, 25 Jun 2024 05:49:10 -0400 (EDT) Received: from mx-prod-mc-04.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-13-QDIHPfUoPtKxGy6KTlW7mg-1; Tue, 25 Jun 2024 05:49:06 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1530619560B4 for ; Tue, 25 Jun 2024 09:49:06 +0000 (UTC) Received: from maggie.brq.redhat.com (unknown [10.43.3.102]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 543F0300021A for ; Tue, 25 Jun 2024 09:49:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: *** X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,RCVD_IN_SBL_CSS,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719308950; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LUsSctNd6mB9dCYrkKTI0Oc6p9f8k8DLu/AuVt6aoc4=; b=VOmOzeq0dtRUKZcJMEh+zm1zuHPyeFKhX2tymKbw3GC/agH/0+lDZ1v0wE+Nh8lmJV9t/r pWHjF1VX4PXdq4ZNUm6cSj2zftVzRtwfMofG0FXyG+dgjz8vhJ1e+2aXGfWD56wWNG4Sgv RFwBf7GN+a0Ng0DaicFFEMLD7sAHBDQ= X-MC-Unique: QDIHPfUoPtKxGy6KTlW7mg-1 From: Michal Privoznik To: devel@lists.libvirt.org Subject: [PATCH 8/8] virt-host-validate: Detect SEV-ES and SEV-SNP Date: Tue, 25 Jun 2024 11:48:53 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: LW75T2AMYJIPBDQPKS2H3BMOQ3OFAELA X-Message-ID-Hash: LW75T2AMYJIPBDQPKS2H3BMOQ3OFAELA X-MailFrom: mprivozn@redhat.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 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: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1719309237128100001 Content-Type: text/plain; charset="utf-8" With a simple cpuid (Section "E.4.17 Function 8000_001Fh=E2=80=94Encrypted Memory Capabilities" in "AMD64 Architecture Programmer=E2=80=99s Manual Vol. 3") we can detect whether CPU is capable of running SEV-ES and/or SEV-SNP guests. Report these in virt-host-validate tool. Signed-off-by: Michal Privoznik --- tools/virt-host-validate-common.c | 33 +++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-c= ommon.c index 7dca1d795b..2985c0c826 100644 --- a/tools/virt-host-validate-common.c +++ b/tools/virt-host-validate-common.c @@ -34,6 +34,7 @@ #include "virstring.h" #include "virarch.h" #include "virutil.h" +#include "virhostcpu.h" =20 #define VIR_FROM_THIS VIR_FROM_NONE =20 @@ -380,9 +381,11 @@ bool virHostKernelModuleIsLoaded(const char *module) =20 =20 static int -virHostValidateAMDSev(virValidateLevel level) +virHostValidateAMDSev(const char *hvname, + virValidateLevel level) { g_autofree char *mod_value =3D NULL; + uint32_t eax, ebx; =20 if (virFileReadValueString(&mod_value, "/sys/module/kvm_amd/parameters= /sev") < 0) { virValidateFail(level, "AMD Secure Encrypted Virtualization not " @@ -405,6 +408,32 @@ virHostValidateAMDSev(virValidateLevel level) return VIR_VALIDATE_FAILURE(level); } =20 + virValidatePass(); + + virValidateCheck(hvname, "%s", + _("Checking for AMD Secure Encrypted Virtualization-E= ncrypted State (SEV-ES)")); + + virHostCPUX86GetCPUID(0x8000001F, 0, &eax, &ebx, NULL, NULL); + + if (eax & (1U << 3)) { + virValidatePass(); + } else { + virValidateFail(level, + "AMD SEV-ES is not supported"); + return VIR_VALIDATE_FAILURE(level); + } + + virValidateCheck(hvname, "%s", + _("Checking for AMD Secure Encrypted Virtualization-S= ecure Nested Paging (SEV-SNP)")); + + if (eax & (1U << 4)) { + virValidatePass(); + } else { + virValidateFail(level, + "AMD SEV-SNP is not supported"); + return VIR_VALIDATE_FAILURE(level); + } + return 1; } =20 @@ -458,7 +487,7 @@ int virHostValidateSecureGuests(const char *hvname, return VIR_VALIDATE_FAILURE(level); } } else if (hasAMDSev) { - int rc =3D virHostValidateAMDSev(level); + int rc =3D virHostValidateAMDSev(hvname, level); =20 if (rc > 0) virValidatePass(); --=20 2.44.2