From nobody Thu May 15 13:40:20 2025 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1507918956393480.99061641502533; Fri, 13 Oct 2017 11:22:36 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2985D7E399; Fri, 13 Oct 2017 18:22:35 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0A9E71822E; Fri, 13 Oct 2017 18:22:35 +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 CB3E94EE4F; Fri, 13 Oct 2017 18:22:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v9DIF7vu014159 for ; Fri, 13 Oct 2017 14:15:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9740860BEC; Fri, 13 Oct 2017 18:15:07 +0000 (UTC) Received: from mamuti.net (ovpn-116-29.ams2.redhat.com [10.36.116.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 23A0660F84 for ; Fri, 13 Oct 2017 18:15:02 +0000 (UTC) Received: by mamuti.net (Postfix, from userid 500) id 2754E1006F0; Fri, 13 Oct 2017 20:14:56 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2985D7E399 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Jiri Denemark To: libvir-list@redhat.com Date: Fri, 13 Oct 2017 20:14:41 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 09/22] cpu_x86: Disable blockers from unusable CPU models 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: , MIME-Version: 1.0 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 13 Oct 2017 18:22:35 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When decoding CPUID data to virCPUDef we need to be careful about using a CPU model which cannot be directly used on the current host. Normally, libvirt would notice the features which prevent the model from being usable and it would disable them in the computed virCPUDef, but this won't work in case the definition of the CPU model in QEMU contains more features than what we have in cpu_map.xml. We need to count with the usability blockers we got from QEMU and explicitly disable all of them to make the computed virCPUDef usable. https://bugzilla.redhat.com/show_bug.cgi?id=3D1464832 Signed-off-by: Jiri Denemark Reviewed-by: John Ferlan --- Notes: Version 2: - use virDomainCapsCPUModelsGet instead of virCPUModelIsAllowed src/cpu/cpu_x86.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 8dff333e13..b177885f5e 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -627,7 +627,8 @@ x86DataAddSignature(virCPUx86Data *data, static virCPUDefPtr x86DataToCPU(const virCPUx86Data *data, virCPUx86ModelPtr model, - virCPUx86MapPtr map) + virCPUx86MapPtr map, + virDomainCapsCPUModelPtr hvModel) { virCPUDefPtr cpu; virCPUx86Data copy =3D VIR_CPU_X86_DATA_INIT; @@ -647,6 +648,21 @@ x86DataToCPU(const virCPUx86Data *data, x86DataSubtract(©, &modelData); x86DataSubtract(&modelData, data); =20 + /* The hypervisor's version of the CPU model (hvModel) may contain + * additional features which may be currently unavailable. Such featur= es + * block usage of the CPU model and we need to explicitly disable them. + */ + if (hvModel && hvModel->blockers) { + char **blocker; + virCPUx86FeaturePtr feature; + + for (blocker =3D hvModel->blockers; *blocker; blocker++) { + if ((feature =3D x86FeatureFind(map, *blocker)) && + !x86DataIsSubset(©, &feature->data)) + x86DataAdd(&modelData, &feature->data); + } + } + /* because feature policy is ignored for host CPU */ cpu->type =3D VIR_CPU_TYPE_GUEST; =20 @@ -1835,6 +1851,7 @@ x86Decode(virCPUDefPtr cpu, virCPUx86Data copy =3D VIR_CPU_X86_DATA_INIT; virCPUx86Data features =3D VIR_CPU_X86_DATA_INIT; virCPUx86VendorPtr vendor; + virDomainCapsCPUModelPtr hvModel =3D NULL; uint32_t signature; ssize_t i; int rc; @@ -1855,7 +1872,8 @@ x86Decode(virCPUDefPtr cpu, */ for (i =3D map->nmodels - 1; i >=3D 0; i--) { candidate =3D map->models[i]; - if (!virCPUModelIsAllowed(candidate->name, models)) { + if (models && + !(hvModel =3D virDomainCapsCPUModelsGet(models, candidate->nam= e))) { if (preferred && STREQ(candidate->name, preferred)) { if (cpu->fallback !=3D VIR_CPU_FALLBACK_ALLOW) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -1883,7 +1901,7 @@ x86Decode(virCPUDefPtr cpu, continue; } =20 - if (!(cpuCandidate =3D x86DataToCPU(&data, candidate, map))) + if (!(cpuCandidate =3D x86DataToCPU(&data, candidate, map, hvModel= ))) goto cleanup; cpuCandidate->type =3D cpu->type; =20 --=20 2.14.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list