From nobody Sun Feb 8 18:24:17 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551778982515143.8294472987592; Tue, 5 Mar 2019 01:43:02 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5894F5946D; Tue, 5 Mar 2019 09:43:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2B6E0611B6; Tue, 5 Mar 2019 09:43:00 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DB044181A13D; Tue, 5 Mar 2019 09:42:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x259etNF026396 for ; Tue, 5 Mar 2019 04:40:56 -0500 Received: by smtp.corp.redhat.com (Postfix) id EF0345D786; Tue, 5 Mar 2019 09:40:55 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9A1FD5D782 for ; Tue, 5 Mar 2019 09:40:52 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 3A779106FB9; Tue, 5 Mar 2019 10:40:47 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 5 Mar 2019 10:40:29 +0100 Message-Id: <3634393d98dda8fc4655648822b4be424f1f567e.1551778706.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 13/30] cpu_x86: Store CPU signature in an array X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 05 Mar 2019 09:43:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" In preparation for storing several CPU signatures in a single CPU model, we need to turn virCPUx86Model's signature into an array of signatures. The parser still hardcodes the number of signatures to 1, but the following patch will drop this limit. Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- Notes: Version 2: - separated from 11/26 cpu_x86: Allow multiple signatures for a CPU mod= el src/cpu/cpu_x86.c | 50 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 0be1b12cdb..3577f31aa0 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -147,7 +147,8 @@ typedef virCPUx86Model *virCPUx86ModelPtr; struct _virCPUx86Model { char *name; virCPUx86VendorPtr vendor; - uint32_t signature; + size_t nsignatures; + uint32_t *signatures; virCPUx86Data data; }; =20 @@ -974,6 +975,7 @@ x86ModelFree(virCPUx86ModelPtr model) return; =20 VIR_FREE(model->name); + VIR_FREE(model->signatures); virCPUx86DataClear(&model->data); VIR_FREE(model); } @@ -983,7 +985,14 @@ static int x86ModelCopySignatures(virCPUx86ModelPtr dst, virCPUx86ModelPtr src) { - dst->signature =3D src->signature; + size_t i; + + if (VIR_ALLOC_N(dst->signatures, src->nsignatures) < 0) + return -1; + + dst->nsignatures =3D src->nsignatures; + for (i =3D 0; i < src->nsignatures; i++) + dst->signatures[i] =3D src->signatures[i]; =20 return 0; } @@ -1200,12 +1209,18 @@ static int x86ModelParseSignature(virCPUx86ModelPtr model, xmlXPathContextPtr ctxt) { + /* Remove inherited signatures. */ + VIR_FREE(model->signatures); =20 if (virXPathBoolean("boolean(./signature)", ctxt)) { unsigned int sigFamily =3D 0; unsigned int sigModel =3D 0; int rc; =20 + model->nsignatures =3D 1; + if (VIR_ALLOC_N(model->signatures, 1) < 0) + return -1; + rc =3D virXPathUInt("string(./signature/@family)", ctxt, &sigFamil= y); if (rc < 0 || sigFamily =3D=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1222,7 +1237,7 @@ x86ModelParseSignature(virCPUx86ModelPtr model, return -1; } =20 - model->signature =3D x86MakeSignature(sigFamily, sigModel, 0); + model->signatures[0] =3D x86MakeSignature(sigFamily, sigModel, 0); } =20 return 0; @@ -1625,7 +1640,8 @@ x86Compute(virCPUDefPtr host, &host_model->vendor->cpuid) < 0) goto error; =20 - if (x86DataAddSignature(&guest_model->data, host_model->signature)= < 0) + if (host_model->signatures && + x86DataAddSignature(&guest_model->data, *host_model->signature= s) < 0) goto error; =20 if (cpu->type =3D=3D VIR_CPU_TYPE_GUEST @@ -1731,6 +1747,21 @@ virCPUx86Compare(virCPUDefPtr host, } =20 =20 +static bool +x86ModelHasSignature(virCPUx86ModelPtr model, + uint32_t signature) +{ + size_t i; + + for (i =3D 0; i < model->nsignatures; i++) { + if (model->signatures[i] =3D=3D signature) + return true; + } + + return false; +} + + /* * Checks whether a candidate model is a better fit for the CPU data than = the * current model. @@ -1772,8 +1803,8 @@ x86DecodeUseCandidate(virCPUx86ModelPtr current, * consider candidates with matching family/model. */ if (signature && - current->signature =3D=3D signature && - candidate->signature !=3D signature) { + x86ModelHasSignature(current, signature) && + !x86ModelHasSignature(candidate, signature)) { VIR_DEBUG("%s differs in signature from matching %s", cpuCandidate->model, cpuCurrent->model); return 0; @@ -1789,8 +1820,8 @@ x86DecodeUseCandidate(virCPUx86ModelPtr current, * result in longer list of features. */ if (signature && - candidate->signature =3D=3D signature && - current->signature !=3D signature) { + x86ModelHasSignature(candidate, signature) && + !x86ModelHasSignature(current, signature)) { VIR_DEBUG("%s provides matching signature", cpuCandidate->model); return 1; } @@ -2858,7 +2889,8 @@ virCPUx86Translate(virCPUDefPtr cpu, virCPUx86DataAddCPUIDInt(&model->data, &model->vendor->cpuid) < 0) goto cleanup; =20 - if (x86DataAddSignature(&model->data, model->signature) < 0) + if (model->signatures && + x86DataAddSignature(&model->data, model->signatures[0]) < 0) goto cleanup; =20 if (!(translated =3D virCPUDefCopyWithoutModel(cpu))) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list