From nobody Mon Feb 9 17:56:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1665143053; cv=none; d=zohomail.com; s=zohoarc; b=bjVP0I5mhgA7P4RRDp9IUctg+auBWI1Yot/dy4d0CyJjflR7PRhKNpj8qr51+z8fctKNaFiq71JHkHiBChpvGZWUk3R2VWhfvfvbTmSVnyoj+BUkRbpPwShXcG10+uVeXwPGmQMeey5L8yWfsCCXZaK8KNco2GQNSEGNZML1WOM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665143053; 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=Dc9cOpnnuM21dEiP++Mgpx0EmcC5hwzmYQEMEiF1sKY=; b=e+POjg7fUZYvovAs54chVaWFnYtOdPSHJBDalNl+Kh3uNPN1VnphYqCmFkETa4ccPb3sHlvsN0ujezTpG6RLeBfUl7lZ8+Vxf2MT6RIjBKnUwtwa0PAx7USZ0G6ZeCEk7+zY5Ymz9aSg+ie8EZZgCN00j9CsPRuB5yHaRzHiOYg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1665143053658451.0391903199659; Fri, 7 Oct 2022 04:44:13 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-647-DLF8ozMeM5WNSxHrbMVTeQ-1; Fri, 07 Oct 2022 07:44:09 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 960E395E3A3; Fri, 7 Oct 2022 11:44:06 +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 81AB8C0297B; Fri, 7 Oct 2022 11:44:06 +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 A626D1946A79; Fri, 7 Oct 2022 11:43:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6A6051946A66 for ; Fri, 7 Oct 2022 11:43:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 658B8C04482; Fri, 7 Oct 2022 11:43:14 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.33.36.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC478C15BA4; Fri, 7 Oct 2022 11:43:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665143052; 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=Dc9cOpnnuM21dEiP++Mgpx0EmcC5hwzmYQEMEiF1sKY=; b=YmZLGcyBY+Bb2SA1pxLV6zOBz2ONPfuqJljcTCu5mWkmEPmnARZzkdPvJ1GfLbxKjG9Nr0 p7mJozMsBVXkS9enPgdT4dinufPCgidT/8XWQueam8IjRDVHOkydNeC1XTqBomZdnjVDlk 8eY3HQdyLnhTYwa91VzNlCDnNoZ9RrI= X-MC-Unique: DLF8ozMeM5WNSxHrbMVTeQ-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 08/12] tools: load CPU count and CPU SKU from libvirt Date: Fri, 7 Oct 2022 12:43:03 +0100 Message-Id: <20221007114307.1461861-9-berrange@redhat.com> In-Reply-To: <20221007114307.1461861-1-berrange@redhat.com> References: <20221007114307.1461861-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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.8 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: 1665143054062100001 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 --- docs/manpages/virt-qemu-sev-validate.rst | 4 ---- tools/virt-qemu-sev-validate.py | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/docs/manpages/virt-qemu-sev-validate.rst b/docs/manpages/virt-= qemu-sev-validate.rst index 7ba7323e13..fcc13d68c8 100644 --- a/docs/manpages/virt-qemu-sev-validate.rst +++ b/docs/manpages/virt-qemu-sev-validate.rst @@ -356,7 +356,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 \ @@ -369,9 +368,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.py b/tools/virt-qemu-sev-validate= .py index 2505aff07f..5da1353e60 100755 --- a/tools/virt-qemu-sev-validate.py +++ b/tools/virt-qemu-sev-validate.py @@ -869,6 +869,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( @@ -914,6 +922,21 @@ 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=3D 1: + 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