From nobody Sun Feb 8 03:57:59 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1667390366; cv=none; d=zohomail.com; s=zohoarc; b=UpgVHfoJ81wdOOxDt7L/gw4G2F7PFLhtW8lqt5F7QgOSFWiw5ay4YwsotdM+weOFAhNR//dGAcsWkJ3t/gxFBiWDd2gmtrHi3EPjTProPjGwICj2zEmEQS7JHjnLpoA4PlcmyUkwh7vPsXutHofbR6iVnWF+GC0VX7/TcN630EM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667390366; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nWjbLMs5MLqrogQFpnG/1aMxtyJdDuZYlsgrcOt7v10=; b=nbXJP905MdVTz9dIgkIuhLVpi6z0OCi1U4Z7UV37gh0/zmizEuokWqZaHxatF2IRZf+e5Tp8Tkx9JzEZdL3BWVjJVZDAMZfmGWaLgSBD1MB2conwY0GKfSS8Pgv/HFVT1FKz4BrJFiucDeHhduMtT45AtLpOF4xJGthjbi2jk6E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) 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 1667390366760871.2517548713406; Wed, 2 Nov 2022 04:59:26 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-144-MpfLUV9zM3CH-P-vSknf7Q-1; Wed, 02 Nov 2022 07:59:17 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F34C82A59553; Wed, 2 Nov 2022 11:59:11 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0BBE111CB82; Wed, 2 Nov 2022 11:59:11 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D0B981946A45; Wed, 2 Nov 2022 11:59:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 068B71946594 for ; Wed, 2 Nov 2022 11:59:10 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id EEA93111CB82; Wed, 2 Nov 2022 11:59:09 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.33.36.154]) by smtp.corp.redhat.com (Postfix) with ESMTP id 458761121339; Wed, 2 Nov 2022 11:59:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667390364; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=nWjbLMs5MLqrogQFpnG/1aMxtyJdDuZYlsgrcOt7v10=; b=KJ8wtT90YZkrva0/e2Lsrpgu8TZ1PlPGPq9JHkBFr+ZpLtb8kWP1fseOJTidjW1Ob41jXe 4Gh2sPu2ZbePbEpIjO0zguhtEgS+igXTh7pSAS/IK/6OeCKnnGwCqEmwy2Htaoq/vfljG0 LweA0jHx77JvXwW8cRc9nNLf+veV6kg= X-MC-Unique: MpfLUV9zM3CH-P-vSknf7Q-1 X-Original-To: libvir-list@listman.corp.redhat.com From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v3 08/12] tools: load CPU count and CPU SKU from libvirt Date: Wed, 2 Nov 2022 11:58:57 +0000 Message-Id: <20221102115901.823636-9-berrange@redhat.com> In-Reply-To: <20221102115901.823636-1-berrange@redhat.com> References: <20221102115901.823636-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1667390368924100001 When validating a SEV-ES guest, we need to know the CPU count and VMSA state. We can get the CPU count directly from libvirt's guest info. The VMSA state can be constructed automatically if we query the CPU SKU from host capabilities XML. Neither of these is secure, however, so this behaviour is restricted. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- docs/manpages/virt-qemu-sev-validate.rst | 4 ---- tools/virt-qemu-sev-validate | 26 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/docs/manpages/virt-qemu-sev-validate.rst b/docs/manpages/virt-= qemu-sev-validate.rst index 4aebbb3c9b..e1e290f125 100644 --- a/docs/manpages/virt-qemu-sev-validate.rst +++ b/docs/manpages/virt-qemu-sev-validate.rst @@ -358,7 +358,6 @@ Validate the measurement of a SEV-ES SMP guest booting = from disk: =20 # virt-dom-sev-validate \ --insecure \ - --num-cpus 2 \ --vmsa-cpu0 vmsa0.bin \ --vmsa-cpu1 vmsa1.bin \ --tk this-guest-tk.bin \ @@ -371,9 +370,6 @@ automatically constructed VMSA: =20 # virt-dom-sev-validate \ --insecure \ - --cpu-family 23 \ - --cpu-model 49 \ - --cpu-stepping 0 \ --tk this-guest-tk.bin \ --domain fedora34x86_64 =20 diff --git a/tools/virt-qemu-sev-validate b/tools/virt-qemu-sev-validate index cdf6a24d46..9eb9d54258 100755 --- a/tools/virt-qemu-sev-validate +++ b/tools/virt-qemu-sev-validate @@ -868,6 +868,14 @@ class LibvirtConfidentialVM(ConfidentialVM): if self.policy is None: self.policy =3D sevinfo["sev-policy"] =20 + if self.is_sev_es() and self.num_cpus is None: + if secure: + raise InsecureUsageException( + "Using CPU count from guest is not secure") + + info =3D self.dom.info() + self.num_cpus =3D info[3] + if self.firmware is None: if remote: raise UnsupportedUsageException( @@ -913,6 +921,24 @@ class LibvirtConfidentialVM(ConfidentialVM): "Using cmdline string from XML is not secure") self.kernel_table.load_cmdline(cmdlinenodes[0].text) =20 + capsxml =3D self.conn.getCapabilities() + capsdoc =3D etree.fromstring(capsxml) + + if self.is_sev_es() and self.vmsa_cpu0 is None: + if secure: + raise InsecureUsageException( + "Using CPU SKU from capabilities is not secure") + + sig =3D capsdoc.xpath("/capabilities/host/cpu/signature") + if len(sig) !=3D 1: + raise UnsupportedUsageException( + "Libvirt is too old to report host CPU signature") + + cpu_family =3D int(sig[0].get("family")) + cpu_model =3D int(sig[0].get("model")) + cpu_stepping =3D int(sig[0].get("stepping")) + self.build_vmsas(cpu_family, cpu_model, cpu_stepping) + =20 def parse_command_line(): parser =3D argparse.ArgumentParser( --=20 2.37.3