From nobody Fri Oct 18 08:48:55 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 171930918748343.03341319956712; Tue, 25 Jun 2024 02:53:07 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 4A39A9A5; Tue, 25 Jun 2024 05:53:06 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 70242BF9; Tue, 25 Jun 2024 05:49:35 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 807FB13B3; Tue, 25 Jun 2024 05:49:25 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 DBDAD140F for ; Tue, 25 Jun 2024 05:49:07 -0400 (EDT) Received: from mx-prod-mc-05.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-70-qTVXBHMdPp-CvqZqvJqwKw-1; Tue, 25 Jun 2024 05:49:05 -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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1DAE91956089 for ; Tue, 25 Jun 2024 09:49:05 +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 333EF300021A for ; Tue, 25 Jun 2024 09:49:03 +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=1719308947; 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=1gADpXJ9hsLYwgw0u+37q35bQ/aXrB1pHC06+/5od1w=; b=TLx3HO7168g9HmGAjADl+uKvnRFgcGFMigf8zljGttD12j2qDXJmeXM4hS7fY0T6Z+WGy3 6Ft8wDSSpVwodOY+58fJkCntGhPxbYX+r6b8Cml8IH6qeJZVD/P6LFz0yefbuIOgdQEQ7y d9LrStlr+d0Y8CZEhG+nAVqb7lTStJ8= X-MC-Unique: qTVXBHMdPp-CvqZqvJqwKw-1 From: Michal Privoznik To: devel@lists.libvirt.org Subject: [PATCH 7/8] virt-host-validate: Move AMD SEV into a separate func Date: Tue, 25 Jun 2024 11:48:52 +0200 Message-ID: <3a6736316f815c4440d90347cf6028ab23f473bc.1719308850.git.mprivozn@redhat.com> 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: IZ577CVV6OLF3EQBHXY2Z23KM4OMA5IG X-Message-ID-Hash: IZ577CVV6OLF3EQBHXY2Z23KM4OMA5IG 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: 1719309188996100001 Content-Type: text/plain; charset="utf-8"; x-default="true" The code that validates AMD SEV is going to be expanded soon. Move it into its own function to avoid lengthening virHostValidateSecureGuests() where the code lives now, even more. Signed-off-by: Michal Privoznik --- tools/virt-host-validate-common.c | 54 ++++++++++++++++++------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-c= ommon.c index ad06dfb245..7dca1d795b 100644 --- a/tools/virt-host-validate-common.c +++ b/tools/virt-host-validate-common.c @@ -379,6 +379,35 @@ bool virHostKernelModuleIsLoaded(const char *module) } =20 =20 +static int +virHostValidateAMDSev(virValidateLevel level) +{ + g_autofree char *mod_value =3D NULL; + + if (virFileReadValueString(&mod_value, "/sys/module/kvm_amd/parameters= /sev") < 0) { + virValidateFail(level, "AMD Secure Encrypted Virtualization not " + "supported by the currently used kernel"); + return VIR_VALIDATE_FAILURE(level); + } + + if (mod_value[0] !=3D '1' && mod_value[0] !=3D 'Y' && mod_value[0] != =3D 'y') { + virValidateFail(level, + "AMD Secure Encrypted Virtualization appears to be= " + "disabled in kernel. Add kvm_amd.sev=3D1 " + "to the kernel cmdline arguments"); + return VIR_VALIDATE_FAILURE(level); + } + + if (!virFileExists("/dev/sev")) { + virValidateFail(level, + "AMD Secure Encrypted Virtualization appears to be= " + "disabled in firmware."); + return VIR_VALIDATE_FAILURE(level); + } + + return 1; +} + int virHostValidateSecureGuests(const char *hvname, virValidateLevel level) { @@ -388,7 +417,6 @@ int virHostValidateSecureGuests(const char *hvname, virArch arch =3D virArchFromHost(); g_autofree char *cmdline =3D NULL; static const char *kIBMValues[] =3D {"y", "Y", "on", "ON", "oN", "On",= "1"}; - g_autofree char *mod_value =3D NULL; =20 flags =3D virHostValidateGetCPUFlags(); =20 @@ -430,29 +458,11 @@ int virHostValidateSecureGuests(const char *hvname, return VIR_VALIDATE_FAILURE(level); } } else if (hasAMDSev) { - if (virFileReadValueString(&mod_value, "/sys/module/kvm_amd/parame= ters/sev") < 0) { - virValidateFail(level, "AMD Secure Encrypted Virtualization no= t " - "supported by the currently used kernel"); - return VIR_VALIDATE_FAILURE(level); - } + int rc =3D virHostValidateAMDSev(level); =20 - if (mod_value[0] !=3D '1' && mod_value[0] !=3D 'Y' && mod_value[0]= !=3D 'y') { - virValidateFail(level, - "AMD Secure Encrypted Virtualization appears t= o be " - "disabled in kernel. Add kvm_amd.sev=3D1 " - "to the kernel cmdline arguments"); - return VIR_VALIDATE_FAILURE(level); - } - - if (virFileExists("/dev/sev")) { + if (rc > 0) virValidatePass(); - return 1; - } else { - virValidateFail(level, - "AMD Secure Encrypted Virtualization appears t= o be " - "disabled in firmware."); - return VIR_VALIDATE_FAILURE(level); - } + return rc; } =20 virValidateFail(level, --=20 2.44.2