From nobody Sun Feb 8 16:31:12 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=1666174694; cv=none; d=zohomail.com; s=zohoarc; b=gHvpF2XUtQPAGRc2WnQDayOncgbeE54IKd3/sPIYfCCHfZab45GKgd7ZL8e1wYBZvSJcXC2SGF26fsMKhM5CRKhbhljaxy0BS3ND1NC9I8XVV/N/xC5q8Uo3fOXGZRzes8llZfNFPi511DgqyNtn7TV94tLCWtbcy/9XaI/kZDE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666174694; 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=6zZzlnLaXzayhKeAFxizwPVRhhb5Xfbwh7YWAxHfpps=; b=O29fdsMJChE7Uqq+VI7+fUjM06W//uT5H/CEqR1SeTA5qZ67u5uNSPWTVVGtfZYDDkr2eW2SxAolD9bWFLjncmvWErqHxT5fF1vDRb2aAQgzpBHIXC4GSTmnNzB/HWvNayIOUAHDasP5sYK7+x6nkEcma+/TB8hgivF80GerYyA= 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 1666174694369730.0472079669182; Wed, 19 Oct 2022 03:18:14 -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-447-WO2d2libM_G35Hjt4IzzZg-1; Wed, 19 Oct 2022 06:17:36 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 729851802CE0; Wed, 19 Oct 2022 10:17:29 +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 4F89B2166BBA; Wed, 19 Oct 2022 10:17:29 +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 40CFF19465B3; Wed, 19 Oct 2022 10:17:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 891DF194704A for ; Wed, 19 Oct 2022 10:17:23 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 6E7F81468703; Wed, 19 Oct 2022 10:17:23 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.33.36.69]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0730F1468702; Wed, 19 Oct 2022 10:17:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666174693; 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=6zZzlnLaXzayhKeAFxizwPVRhhb5Xfbwh7YWAxHfpps=; b=NB+vfhdfrsBhMmBiK/iLwMONJBnaH8njfcQi57wsR8ZSfilMqNQMhStOUh0Za0SNSD6Gyw 0CCu9Q5IBP1URwifUB4VaOonACOFOKuRMyR1nPOlbOaO8ElKKEWxG76U/bPSmNqYyrc5gd Qb7xto5EBD3wlKsAjaEqhqzb0U5WlJQ= X-MC-Unique: WO2d2libM_G35Hjt4IzzZg-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 v2 08/12] tools: load CPU count and CPU SKU from libvirt Date: Wed, 19 Oct 2022 11:17:08 +0100 Message-Id: <20221019101712.2231862-9-berrange@redhat.com> In-Reply-To: <20221019101712.2231862-1-berrange@redhat.com> References: <20221019101712.2231862-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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.6 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: 1666174696156100002 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 | 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 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 b/tools/virt-qemu-sev-validate index 716149e6df..5ce5763d5b 100755 --- a/tools/virt-qemu-sev-validate +++ b/tools/virt-qemu-sev-validate @@ -862,6 +862,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( @@ -907,6 +915,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