From nobody Mon Feb 9 02:42: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 1729190711112534.1502668208879; Thu, 17 Oct 2024 11:45:11 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id F12061297; Thu, 17 Oct 2024 14:45:09 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id BFED21315; Thu, 17 Oct 2024 14:40:57 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id D8873A65; Thu, 17 Oct 2024 14:40:52 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 8B325144C for ; Thu, 17 Oct 2024 14:40:18 -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-159-P71XHarZPYaL2Ox4Q5ZsmA-1; Thu, 17 Oct 2024 14:40:17 -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 1A01A19560BA for ; Thu, 17 Oct 2024 18:40:16 +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 9673319560A3 for ; Thu, 17 Oct 2024 18:40:15 +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=1729190418; 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=8PyugIUnUbosREBoXsgnvUuh0UHTPiDfiPcYxkXHTZE=; b=WvE+rVXXcOOxTGJxFTBL+HT3Q2CsUs1uyLJ8JzX1jr5q55wgJZCbz1bXHoXW0MorRnaRsb ui7OzS+C0f+YYnSckqdUdtMZ9wHqCr34E4kfPSi6EzCcsKPm2iQAoZvFvw93wGxFbJNHDO A1bK2fEkDMkjTNSaucd3ouxJDMj7gvc= X-MC-Unique: P71XHarZPYaL2Ox4Q5ZsmA-1 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [PATCH 9/9] qemu: Change CPU comparison algorithm for future models Date: Thu, 17 Oct 2024 20:39:55 +0200 Message-ID: <7bfefabfe8e92dc5e55572f44930c289e7d7d932.1729190350.git.jdenemar@redhat.com> 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: JH6IHMVYBHBAUQYKSWHB4DCQ2IAONC3X X-Message-ID-Hash: JH6IHMVYBHBAUQYKSWHB4DCQ2IAONC3X 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: 1729190712316116600 Content-Type: text/plain; charset="utf-8" When starting a domain we check whether the guest CPU definition is compatible with the host (i.e., when the host supports all features required both explicitly and by the specified CPU model) as long as check =3D=3D 'partial', which is the default. We are doing so by checking our definition of the CPU model in the CPU map amending it with explicitly mentioned features and comparing it to features QEMU would enabled when started with -cpu host. But since our CPU model definitions often slightly differ from QEMU we may be checking features which are not actually needed and on the other hand not checking something that is part of the CPU model in QEMU. This patch changes the algorithm for CPU models added in the future (changing it for existing models could cause them to suddenly become incompatible with the host and domains using them would fail to start). The new algorithm uses information we probe from QEMU about features that block each model from being directly usable. If all those features are explicitly disabled in the CPU definition we consider the base model compatible with the host. Then we only need to check that all explicitly required features are supported by QEMU on the host to get the result for the whole CPU definition. After this we only use the model definitions (for newly added models) from CPU map for creating a CPU definition for host-model. Signed-off-by: Jiri Denemark --- src/qemu/qemu_domain.c | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 8ada3db115..7b702cfc6b 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -13234,10 +13234,16 @@ qemuDomainStorageUpdatePhysical(virQEMUDriverConf= ig *cfg, * @compatCPU: type of CPU used for old style check * @failIncompatible: return an error instead of VIR_CPU_COMPARE_INCOMPATI= BLE * - * Perform a "partial" check of the @cpu against a "host CPU". Old style c= heck - * used with all existing CPU models uses cpu_map definition of the model = in - * @cpu and compares it to the host CPU fetched @qemuCaps according to - * @compatCPU. + * Perform a "partial" check of the @cpu against a "host CPU". + * + * Old style check used with all existing CPU models uses cpu_map definiti= on of + * the model in @cpu and compares it to the host CPU fetched @qemuCaps + * according to @compatCPU. + * + * For future CPU models (without ) only explic= itly + * requested features are checked against the host CPU definition provided= by + * QEMU and the usability (with a list of blocking features) info for the = base + * CPU model. Our definition of the mode in cpu_map is ignored completely. * * Returns VIR_CPU_COMPARE_ERROR on error, VIR_CPU_COMPARE_INCOMPATIBLE wh= en * the two CPUs are incompatible, VIR_CPU_COMPARE_IDENTICAL when the two C= PUs @@ -13254,12 +13260,31 @@ qemuDomainCheckCPU(virArch arch, virQEMUCapsHostCPUType compatCPU, bool failIncompatible) { - virCPUDef *host; + virCPUDef *hypervisorCPU; + bool compat =3D false; + char **blockers =3D NULL; =20 if (virQEMUCapsIsCPUUsable(qemuCaps, virtType, cpu)) return VIR_CPU_COMPARE_SUPERSET; =20 - host =3D virQEMUCapsGetHostModel(qemuCaps, virtType, compatCPU); + hypervisorCPU =3D virQEMUCapsGetHostModel(qemuCaps, virtType, + VIR_QEMU_CAPS_HOST_CPU_REPORTE= D); + + /* Force compat check if the CPU model is not found in qemuCaps or + * we don't have host CPU data from QEMU */ + if (!cpu->model || + hypervisorCPU->fallback !=3D VIR_CPU_FALLBACK_FORBID || + virQEMUCapsGetCPUBlockers(qemuCaps, virtType, + cpu->model, &blockers) < 0) + compat =3D true; + else if (virCPUGetCheckMode(arch, cpu, &compat) < 0) + return VIR_CPU_COMPARE_ERROR; + + if (compat) { + virCPUDef *host =3D virQEMUCapsGetHostModel(qemuCaps, virtType, co= mpatCPU); + return virCPUCompare(arch, host, cpu, failIncompatible); + } =20 - return virCPUCompare(arch, host, cpu, failIncompatible); + return virCPUCompareUnusable(arch, hypervisorCPU, cpu, + blockers, failIncompatible); } --=20 2.47.0