From nobody Thu Dec 5 01:58:32 2024 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 1732311693238672.1019294157709; Fri, 22 Nov 2024 13:41:33 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id A4369164A; Fri, 22 Nov 2024 16:41:32 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 6DC3616DA; Fri, 22 Nov 2024 16:34:37 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 766C21528; Fri, 22 Nov 2024 16:34:27 -0500 (EST) 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 02CE21651 for ; Fri, 22 Nov 2024 16:33:49 -0500 (EST) Received: from mx-prod-mc-04.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-488-e9Juq9FTPPusrQaIcs6nYw-1; Fri, 22 Nov 2024 16:33:48 -0500 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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7820A197732C for ; Fri, 22 Nov 2024 21:33:47 +0000 (UTC) Received: from orkuz (unknown [10.45.224.26]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F0BA81955F43 for ; Fri, 22 Nov 2024 21:33:46 +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=-0.5 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_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732311229; 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=/cKdd23sU5NzwA755HuxzWdOKgD3z/GC75cU3K2vXg0=; b=KjHKvqcWReFhp2eDeUJVNBpLJXxGhuJ5iCYCrv2Z+eEc4fdMsN6OwTgPKebGnEfAUcaah6 id5kB9rzwkTla63iLr/8V0mm+Qd0lCtVIx49cu59teJpZuZBjaz9brV8JY2MMj7MAoGZqF RiYsw2maB50w+BI9QN9hpe6uqfHA4T4= X-MC-Unique: e9Juq9FTPPusrQaIcs6nYw-1 X-Mimecast-MFC-AGG-ID: e9Juq9FTPPusrQaIcs6nYw From: Jiri Denemark To: devel@lists.libvirt.org Subject: [PATCH v2 13/36] cpu_x86: Record relations between CPU models Date: Fri, 22 Nov 2024 22:32:53 +0100 Message-ID: <43cb30cd1998667f1b59606dfd1c1a0704b96617.1732311125.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-MFC-PROC-ID: r9TIvlCdT61YW5aNXvNAsciIlNcpajpR0IaXqAadhM8_1732311227 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: LQ2ZHVMW7VFUZNVWFPGAVOJVCELS75L6 X-Message-ID-Hash: LQ2ZHVMW7VFUZNVWFPGAVOJVCELS75L6 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: 1732311695132116600 Content-Type: text/plain; charset="utf-8" Record a fact a specific CPU model was derived from another one. The original model is also marked as an alias of the new one in case it did not change any properties of the original CPU. Signed-off-by: Jiri Denemark Reviewed-by: Daniel P. Berrang=C3=A9 --- Notes: Version 2: - new patch src/cpu/cpu_x86.c | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 285b272ce8..ce3506be55 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -180,6 +180,17 @@ struct _virCPUx86Model { * The corresponding features are a genuine part of the new model. */ GStrv addedFeatures; + + /* Pinter to the model this one was derived from. */ + virCPUx86Model *ancestor; + + /* Pointer to the canonical model if this model is just an alias. + * Because the aliases were actually added to the CPU map before their + * canonical models, we store this relation in the XML reversed. That = is, + * this model contains all the data and the canonical model is defined + * using this model as an ancestor without adding any additional data. + */ + const virCPUx86Model *canonical; }; =20 typedef struct _virCPUx86Map virCPUx86Map; @@ -1567,6 +1578,7 @@ x86ModelParseAncestor(virCPUx86Model *model, return -1; } =20 + model->ancestor =3D ancestor; model->vendor =3D ancestor->vendor; model->signatures =3D virCPUx86SignaturesCopy(ancestor->signatures); x86DataCopy(&model->data, &ancestor->data); @@ -1582,9 +1594,11 @@ x86ModelParseAncestor(virCPUx86Model *model, } =20 =20 +/* Updates @changed if signatures are set. */ static int x86ModelParseSignatures(virCPUx86Model *model, - xmlXPathContextPtr ctxt) + xmlXPathContextPtr ctxt, + bool *changed) { g_autofree xmlNodePtr *nodes =3D NULL; VIR_XPATH_NODE_AUTORESTORE(ctxt) @@ -1628,14 +1642,17 @@ x86ModelParseSignatures(virCPUx86Model *model, return -1; } =20 + *changed =3D true; return 0; } =20 =20 +/* Updates @changed if vendor changes. */ static int x86ModelParseVendor(virCPUx86Model *model, xmlXPathContextPtr ctxt, - virCPUx86Map *map) + virCPUx86Map *map, + bool *changed) { g_autofree char *vendor =3D NULL; int rc; @@ -1658,14 +1675,17 @@ x86ModelParseVendor(virCPUx86Model *model, return -1; } =20 + *changed =3D true; return 0; } =20 =20 +/* Updates @changed if features are added. */ static int x86ModelParseFeatures(virCPUx86Model *model, xmlXPathContextPtr ctxt, - virCPUx86Map *map) + virCPUx86Map *map, + bool *changed) { g_autofree xmlNodePtr *nodes =3D NULL; size_t i; @@ -1725,6 +1745,7 @@ x86ModelParseFeatures(virCPUx86Model *model, model->removedFeatures =3D g_renew(char *, model->removedFeatures, nre= moved + 1); model->addedFeatures =3D g_renew(char *, model->addedFeatures, nadded = + 1); =20 + *changed =3D true; return 0; } =20 @@ -1736,6 +1757,7 @@ x86ModelParse(xmlXPathContextPtr ctxt, { virCPUx86Map *map =3D data; g_autoptr(virCPUx86Model) model =3D NULL; + bool changed =3D false; =20 if (x86ModelFind(map, name)) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1755,15 +1777,28 @@ x86ModelParse(xmlXPathContextPtr ctxt, if (x86ModelParseAncestor(model, ctxt, map) < 0) return -1; =20 - if (x86ModelParseSignatures(model, ctxt) < 0) + if (x86ModelParseSignatures(model, ctxt, &changed) < 0) return -1; =20 - if (x86ModelParseVendor(model, ctxt, map) < 0) + if (x86ModelParseVendor(model, ctxt, map, &changed) < 0) return -1; =20 - if (x86ModelParseFeatures(model, ctxt, map) < 0) + if (x86ModelParseFeatures(model, ctxt, map, &changed) < 0) return -1; =20 + if (model->ancestor && !changed) { + if (model->ancestor->canonical) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot set CPU model '%1$s' as canonical nam= e of '%2$s' which is already an alias of '%3$s'"), + model->name, + model->ancestor->name, + model->ancestor->canonical->name); + return -1; + } + + model->ancestor->canonical =3D model; + } + VIR_APPEND_ELEMENT(map->models, map->nmodels, model); =20 return 0; --=20 2.47.0