From nobody Sun Feb 8 20:03:00 2026 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 1729190690189451.7902802256409; Thu, 17 Oct 2024 11:44:50 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 1A472121C; Thu, 17 Oct 2024 14:44:49 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 8D48D12D1; Thu, 17 Oct 2024 14:40:34 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id CB3BBE02; Thu, 17 Oct 2024 14:40:31 -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 74A841224 for ; Thu, 17 Oct 2024 14:40:14 -0400 (EDT) Received: from mx-prod-mc-03.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-594-714ncHRGO4mqxpjqGieL3A-1; Thu, 17 Oct 2024 14:40:12 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1B8DE19560BD for ; Thu, 17 Oct 2024 18:40:12 +0000 (UTC) Received: from orkuz (unknown [10.45.224.13]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9580119560A3 for ; Thu, 17 Oct 2024 18:40:11 +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_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_SBL_CSS, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, 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=1729190414; 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=vU1ZzdtE0EhQyOGqfipPuAnPBGxKnuP46Gr96btipXs=; b=ZsE521Smywrm3qvU56XqJ9BOQPvT/gqt6XCm+m9GWTI9obsQPtnKDqEMF7d16aEJwStp+H S0xFq4lEkjIhQYyAk1BSyznOs3cv7vEdhGj87jClxLcBUqLoylYxOKihlWDGGMQHov3k2g qTaZeYmTtyFv4F62FfTqy1dSWU4E++Y= X-MC-Unique: 714ncHRGO4mqxpjqGieL3A-1 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [PATCH 7/9] cpu: Introduce virCPUCompareUnusable Date: Thu, 17 Oct 2024 20:39:53 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: RRBLPFFFQVLWJ62GUVDH7PGPPJSEC7WB X-Message-ID-Hash: RRBLPFFFQVLWJ62GUVDH7PGPPJSEC7WB X-MailFrom: jdenemar@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: 1729190692436116600 Content-Type: text/plain; charset="utf-8" As opposed to the existing virCPUCompare{,XML} this function does not use CPU model definitions from CPU map. It relies on CPU model usability info from a hypervisor with a list of blockers that make the selected CPU model unusable. Explicitly requested features are checked against the hypervisor's view of a host CPU. Signed-off-by: Jiri Denemark --- src/cpu/cpu.c | 73 ++++++++++++++++++++++++++++++++++++++++ src/cpu/cpu.h | 7 ++++ src/libvirt_private.syms | 1 + 3 files changed, 81 insertions(+) diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index 1734561215..2b0d641e78 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -167,6 +167,79 @@ virCPUCompare(virArch arch, } =20 =20 +/** virCPUCompareUnusable: + * @arch: CPU architecture + * @host: host CPU reported by the hypervisor + * @cpu: CPU to be compared with @host + * @blockers: NULL terminated list of features blocking usability of the C= PU model from @cpu + * @failIncompatible: return an error instead of VIR_CPU_COMPARE_INCOMPATI= BLE + * + * Check if @cpu can be run on @host when we know model used by @cpu is + * considered unusable by the hypervisor because it requires some features + * that cannot be provided on the host (the list of them is passed as + * @blockers) and/or @cpu requests additional features. The @cpu definition + * can still be compatible with @host if all @blockers are explicitly disa= bled + * and all explicitly requested features are supported by @host. + * + * Returns VIR_CPU_COMPARE_ERROR on error, VIR_CPU_COMPARE_INCOMPATIBLE wh= en + * the @cpu cannot be created on @host, or VIR_CPU_COMPARE_SUPERSET when t= he + * @cpu is compatible with @host CPU. If @failIncompatible is true, the + * function will return VIR_CPU_COMPARE_ERROR (and set VIR_ERR_CPU_INCOMPA= TIBLE + * error) when the two CPUs are incompatible. + */ +int +virCPUCompareUnusable(virArch arch, + const virCPUDef *host, + const virCPUDef *cpu, + char **blockers, + bool failIncompatible) +{ + g_autoptr(virCPUDef) expanded =3D NULL; + g_auto(virBuffer) features =3D VIR_BUFFER_INITIALIZER; + g_autofree char *str =3D NULL; + virCPUFeatureDef *feat; + char **blocker; + size_t i; + + for (blocker =3D blockers; *blocker; blocker++) { + if (!(feat =3D virCPUDefFindFeature(cpu, *blocker)) || + feat->policy !=3D VIR_CPU_FEATURE_DISABLE) { + virBufferAddStr(&features, *blocker); + virBufferAddLit(&features, ", "); + } + } + + expanded =3D virCPUDefCopy(host); + if (virCPUExpandFeatures(arch, expanded) < 0) + return VIR_CPU_COMPARE_ERROR; + + for (i =3D 0; i < cpu->nfeatures; i++) { + if (cpu->features[i].policy !=3D VIR_CPU_FEATURE_REQUIRE) + continue; + + if (!(feat =3D virCPUDefFindFeature(expanded, cpu->features[i].nam= e)) || + feat->policy !=3D VIR_CPU_FEATURE_REQUIRE) { + virBufferAddStr(&features, cpu->features[i].name); + virBufferAddLit(&features, ", "); + } + } + virBufferTrim(&features, ", "); + + if ((str =3D virBufferContentAndReset(&features))) { + if (failIncompatible) { + virReportError(VIR_ERR_CPU_INCOMPATIBLE, + _("Host CPU does not provide required features:= %1$s"), + str); + return VIR_CPU_COMPARE_ERROR; + } + + return VIR_CPU_COMPARE_INCOMPATIBLE; + } + + return VIR_CPU_COMPARE_SUPERSET; +} + + /** * cpuDecode: * diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index ceb6eb0944..ff68c5da2d 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -185,6 +185,13 @@ virCPUCompare(virArch arch, bool failIncompatible) ATTRIBUTE_NONNULL(3); =20 +int +virCPUCompareUnusable(virArch arch, + const virCPUDef *host, + const virCPUDef *cpu, + char **blockers, + bool failIncompatible); + int cpuDecode (virCPUDef *cpu, const virCPUData *data, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 551cea989b..c1542847f4 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1524,6 +1524,7 @@ virCPUBaseline; virCPUCheckFeature; virCPUCheckForbiddenFeatures; virCPUCompare; +virCPUCompareUnusable; virCPUCompareXML; virCPUConvertLegacy; virCPUCopyMigratable; --=20 2.47.0