From nobody Sun Apr 28 21:36:19 2024 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 1507717640943841.5936762973591; Wed, 11 Oct 2017 03:27:20 -0700 (PDT) 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 7D1A55114F; Wed, 11 Oct 2017 10:27:19 +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 5AFE718EF6; Wed, 11 Oct 2017 10:27:19 +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 0FD4B410B2; Wed, 11 Oct 2017 10:27:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v9BABLfw029564 for ; Wed, 11 Oct 2017 06:11:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7F6FB68B2B; Wed, 11 Oct 2017 10:11:21 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.105]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 544B168B39 for ; Wed, 11 Oct 2017 10:11:19 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 4E60D10050D; Wed, 11 Oct 2017 12:11:18 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7D1A55114F Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 11 Oct 2017 12:11:14 +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.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/4] qemu: Separate CPU updating code from qemuProcessReconnect 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 11 Oct 2017 10:27:20 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The new function is called qemuProcessRefreshCPU. Signed-off-by: Jiri Denemark Reviewed-by: Pavel Hrdina --- src/qemu/qemu_process.c | 66 ++++++++++++++++++++++++++++++++-------------= ---- 1 file changed, 43 insertions(+), 23 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 0cb023095b..5ed6b68eb8 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6876,6 +6876,47 @@ qemuProcessRefreshDisks(virQEMUDriverPtr driver, } =20 =20 +static int +qemuProcessRefreshCPU(virQEMUDriverPtr driver, + virDomainObjPtr vm) +{ + virCapsPtr caps =3D virQEMUDriverGetCapabilities(driver, false); + virCPUDefPtr host =3D NULL; + int ret =3D -1; + + if (!virQEMUCapsGuestIsNative(caps->host.arch, vm->def->os.arch) || + !caps->host.cpu || + !vm->def->cpu) + return 0; + + if (!caps) + goto cleanup; + + /* If the domain with a host-model CPU was started by an old libvirt + * (< 2.3) which didn't replace the CPU with a custom one, let's do it= now + * since the rest of our code does not really expect a host-model CPU = in a + * running domain. + */ + if (vm->def->cpu->mode =3D=3D VIR_CPU_MODE_HOST_MODEL) { + if (!(host =3D virCPUCopyMigratable(caps->host.cpu->arch, caps->ho= st.cpu))) + goto cleanup; + + if (virCPUUpdate(vm->def->os.arch, vm->def->cpu, host) < 0) + goto cleanup; + + if (qemuProcessUpdateCPU(driver, vm, QEMU_ASYNC_JOB_NONE) < 0) + goto cleanup; + } + + ret =3D 0; + + cleanup: + virCPUDefFree(host); + virObjectUnref(caps); + return ret; +} + + struct qemuProcessReconnectData { virConnectPtr conn; virQEMUDriverPtr driver; @@ -7042,29 +7083,8 @@ qemuProcessReconnect(void *opaque) ignore_value(qemuSecurityCheckAllLabel(driver->securityManager, obj->def)); =20 - /* If the domain with a host-model CPU was started by an old libvirt - * (< 2.3) which didn't replace the CPU with a custom one, let's do it= now - * since the rest of our code does not really expect a host-model CPU = in a - * running domain. - */ - if (virQEMUCapsGuestIsNative(caps->host.arch, obj->def->os.arch) && - caps->host.cpu && - obj->def->cpu && - obj->def->cpu->mode =3D=3D VIR_CPU_MODE_HOST_MODEL) { - virCPUDefPtr host; - - if (!(host =3D virCPUCopyMigratable(caps->host.cpu->arch, caps->ho= st.cpu))) - goto error; - - if (virCPUUpdate(obj->def->os.arch, obj->def->cpu, host) < 0) { - virCPUDefFree(host); - goto error; - } - virCPUDefFree(host); - - if (qemuProcessUpdateCPU(driver, obj, QEMU_ASYNC_JOB_NONE) < 0) - goto error; - } + if (qemuProcessRefreshCPU(driver, obj) < 0) + goto error; =20 if (qemuDomainRefreshVcpuInfo(driver, obj, QEMU_ASYNC_JOB_NONE, true) = < 0) goto error; --=20 2.14.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 21:36:19 2024 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 1507717454515332.05030959386363; Wed, 11 Oct 2017 03:24:14 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 462AD7E456; Wed, 11 Oct 2017 10:24:13 +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 E2A5768B3B; Wed, 11 Oct 2017 10:24:12 +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 B568518355DA; Wed, 11 Oct 2017 10:24:11 +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 v9BABMQt029589 for ; Wed, 11 Oct 2017 06:11:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 97C8918952; Wed, 11 Oct 2017 10:11:22 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.105]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6B03C69555 for ; Wed, 11 Oct 2017 10:11:19 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 51AFF104217; Wed, 11 Oct 2017 12:11:18 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 462AD7E456 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 11 Oct 2017 12:11:15 +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 2/4] conf: Introduce virCPUDefFindFeature 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 11 Oct 2017 10:24:13 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jiri Denemark Reviewed-by: Pavel Hrdina --- src/conf/cpu_conf.c | 40 +++++++++++++++++++++++++++------------- src/conf/cpu_conf.h | 4 ++++ src/libvirt_private.syms | 1 + 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 76f04c3531..669935acf8 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -773,24 +773,22 @@ virCPUDefUpdateFeatureInternal(virCPUDefPtr def, int policy, bool update) { - size_t i; + virCPUFeatureDefPtr feat; =20 if (def->type =3D=3D VIR_CPU_TYPE_HOST) policy =3D -1; =20 - for (i =3D 0; i < def->nfeatures; i++) { - if (STREQ(name, def->features[i].name)) { - if (update) { - def->features[i].policy =3D policy; - return 0; - } - - virReportError(VIR_ERR_INTERNAL_ERROR, - _("CPU feature '%s' specified more than once"), - name); - - return -1; + if ((feat =3D virCPUDefFindFeature(def, name))) { + if (update) { + feat->policy =3D policy; + return 0; } + + virReportError(VIR_ERR_INTERNAL_ERROR, + _("CPU feature '%s' specified more than once"), + name); + + return -1; } =20 if (VIR_RESIZE_N(def->features, def->nfeatures_max, @@ -822,6 +820,22 @@ virCPUDefAddFeature(virCPUDefPtr def, return virCPUDefUpdateFeatureInternal(def, name, policy, false); } =20 + +virCPUFeatureDefPtr +virCPUDefFindFeature(virCPUDefPtr def, + const char *name) +{ + size_t i; + + for (i =3D 0; i < def->nfeatures; i++) { + if (STREQ(name, def->features[i].name)) + return def->features + i; + } + + return NULL; +} + + bool virCPUDefIsEqual(virCPUDefPtr src, virCPUDefPtr dst, diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h index b1a512b19a..d1983f5d4f 100644 --- a/src/conf/cpu_conf.h +++ b/src/conf/cpu_conf.h @@ -215,6 +215,10 @@ virCPUDefUpdateFeature(virCPUDefPtr cpu, const char *name, int policy); =20 +virCPUFeatureDefPtr +virCPUDefFindFeature(virCPUDefPtr def, + const char *name); + virCPUDefPtr * virCPUDefListParse(const char **xmlCPUs, unsigned int ncpus, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 26b1ae2850..7e116b19c4 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -75,6 +75,7 @@ virCPUDefCopy; virCPUDefCopyModel; virCPUDefCopyModelFilter; virCPUDefCopyWithoutModel; +virCPUDefFindFeature; virCPUDefFormat; virCPUDefFormatBuf; virCPUDefFormatBufFull; --=20 2.14.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 21:36:19 2024 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 1507717679334718.4279664243616; Wed, 11 Oct 2017 03:27:59 -0700 (PDT) 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 EEAA2C04B31B; Wed, 11 Oct 2017 10:27:57 +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 D077E5279C; Wed, 11 Oct 2017 10:27:57 +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 9B0E11806103; Wed, 11 Oct 2017 10:27:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v9BABMvw029584 for ; Wed, 11 Oct 2017 06:11:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 43FA94DC; Wed, 11 Oct 2017 10:11:22 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.105]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 18A1E5C552 for ; Wed, 11 Oct 2017 10:11:19 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 54F17104218; Wed, 11 Oct 2017 12:11:18 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EEAA2C04B31B Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 11 Oct 2017 12:11:16 +0200 Message-Id: <2458a0a225419711da23fa1b8db507dce9361432.1507710167.git.jdenemar@redhat.com> 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.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/4] qemu: Filter CPU features when using host CPU 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 11 Oct 2017 10:27:58 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The host CPU definition from host capabilities may contain features unknown to QEMU. Thus whenever we want to use this CPU definition, we have to filter the unknown features. https://bugzilla.redhat.com/show_bug.cgi?id=3D1495171 Signed-off-by: Jiri Denemark Reviewed-by: Pavel Hrdina --- src/qemu/qemu_process.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 5ed6b68eb8..8553c5126f 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6882,6 +6882,7 @@ qemuProcessRefreshCPU(virQEMUDriverPtr driver, { virCapsPtr caps =3D virQEMUDriverGetCapabilities(driver, false); virCPUDefPtr host =3D NULL; + virCPUDefPtr cpu =3D NULL; int ret =3D -1; =20 if (!virQEMUCapsGuestIsNative(caps->host.arch, vm->def->os.arch) || @@ -6901,7 +6902,13 @@ qemuProcessRefreshCPU(virQEMUDriverPtr driver, if (!(host =3D virCPUCopyMigratable(caps->host.cpu->arch, caps->ho= st.cpu))) goto cleanup; =20 - if (virCPUUpdate(vm->def->os.arch, vm->def->cpu, host) < 0) + if (!(cpu =3D virCPUDefCopyWithoutModel(host)) || + virCPUDefCopyModelFilter(cpu, host, false, + virQEMUCapsCPUFilterFeatures, + &caps->host.cpu->arch) < 0) + goto cleanup; + + if (virCPUUpdate(vm->def->os.arch, vm->def->cpu, cpu) < 0) goto cleanup; =20 if (qemuProcessUpdateCPU(driver, vm, QEMU_ASYNC_JOB_NONE) < 0) @@ -6911,6 +6918,7 @@ qemuProcessRefreshCPU(virQEMUDriverPtr driver, ret =3D 0; =20 cleanup: + virCPUDefFree(cpu); virCPUDefFree(host); virObjectUnref(caps); return ret; --=20 2.14.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 21:36:19 2024 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 1507717115642558.6023759330396; Wed, 11 Oct 2017 03:18:35 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DA47F25BAF; Wed, 11 Oct 2017 10:18:33 +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 D4F5F6293F; Wed, 11 Oct 2017 10:18:32 +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 2636218355D8; Wed, 11 Oct 2017 10:18:30 +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 v9BABLYr029574 for ; Wed, 11 Oct 2017 06:11:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id CFA836248F; Wed, 11 Oct 2017 10:11:21 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.105]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7D60563BA6 for ; Wed, 11 Oct 2017 10:11:19 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 58663104219; Wed, 11 Oct 2017 12:11:18 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DA47F25BAF Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 11 Oct 2017 12:11:17 +0200 Message-Id: <1ab8d96dc6c46650dc4ecdaabf1edc04d18c8f43.1507710167.git.jdenemar@redhat.com> 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.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/4] qemu: Fix CPU model broken by older libvirt 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 11 Oct 2017 10:18:34 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When libvirt older than 3.9.0 reconnected to a running domain started by old libvirt it could have messed up the expansion of host-model by adding features QEMU does not support (such as cmt). Thus whenever we reconnect to a running domain, revert to an active snapshot, or restore a saved domain we need to check the guest CPU model and remove the CPU features unknown to QEMU. We can do this because we know the domain was successfully started, which means the CPU did not contain the features when libvirt started the domain. https://bugzilla.redhat.com/show_bug.cgi?id=3D1495171 Signed-off-by: Jiri Denemark Reviewed-by: Pavel Hrdina --- src/qemu/qemu_domain.c | 76 +++++++++++++++++++++++++++++++++++++++++++++= ++++ src/qemu/qemu_domain.h | 4 +++ src/qemu/qemu_driver.c | 14 +++++++++ src/qemu/qemu_process.c | 9 ++++++ 4 files changed, 103 insertions(+) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index f621cf7afc..29b6618a56 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -10021,6 +10021,82 @@ qemuDomainUpdateCPU(virDomainObjPtr vm, return 0; } =20 + +/** + * qemuDomainFixupCPUS: + * @vm: domain object + * @origCPU: original CPU used when the domain was started + * + * Libvirt older than 3.9.0 could have messed up the expansion of host-mod= el + * CPU when reconnecting to a running domain by adding features QEMU does = not + * support (such as cmt). This API fixes both the actual CPU provided by Q= EMU + * (stored in the domain object) and the @origCPU used when starting the + * domain. + * + * This is safe even if the original CPU definition used mode=3D'custom' (= rather + * than host-model) since we know QEMU was able to start the domain and th= us + * the CPU definitions do not contain any features unknown to QEMU. + * + * This function can only be used on an active domain or when restoring a + * domain which was running. + * + * Returns 0 on success, -1 on error. + */ +int +qemuDomainFixupCPUs(virDomainObjPtr vm, + virCPUDefPtr *origCPU) +{ + virCPUDefPtr fixedCPU =3D NULL; + virCPUDefPtr fixedOrig =3D NULL; + virArch arch =3D vm->def->os.arch; + int ret =3D 0; + + if (!ARCH_IS_X86(arch)) + return 0; + + if (!vm->def->cpu || + vm->def->cpu->mode !=3D VIR_CPU_MODE_CUSTOM || + !vm->def->cpu->model) + return 0; + + /* Missing origCPU means QEMU created exactly the same virtual CPU whi= ch + * we asked for or libvirt was too old to mess up the translation from + * host-model. + */ + if (!*origCPU) + return 0; + + if (virCPUDefFindFeature(vm->def->cpu, "cmt") && + (!(fixedCPU =3D virCPUDefCopyWithoutModel(vm->def->cpu)) || + virCPUDefCopyModelFilter(fixedCPU, vm->def->cpu, false, + virQEMUCapsCPUFilterFeatures, &arch) < 0= )) + goto cleanup; + + if (virCPUDefFindFeature(*origCPU, "cmt") && + (!(fixedOrig =3D virCPUDefCopyWithoutModel(*origCPU)) || + virCPUDefCopyModelFilter(fixedOrig, *origCPU, false, + virQEMUCapsCPUFilterFeatures, &arch) < 0= )) + goto cleanup; + + if (fixedCPU) { + virCPUDefFree(vm->def->cpu); + VIR_STEAL_PTR(vm->def->cpu, fixedCPU); + } + + if (fixedOrig) { + virCPUDefFree(*origCPU); + VIR_STEAL_PTR(*origCPU, fixedOrig); + } + + ret =3D 0; + + cleanup: + virCPUDefFree(fixedCPU); + virCPUDefFree(fixedOrig); + return ret; +} + + char * qemuDomainGetMachineName(virDomainObjPtr vm) { diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index c34cd37fc4..e430302519 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -971,6 +971,10 @@ qemuDomainUpdateCPU(virDomainObjPtr vm, virCPUDefPtr cpu, virCPUDefPtr *origCPU); =20 +int +qemuDomainFixupCPUs(virDomainObjPtr vm, + virCPUDefPtr *origCPU); + char * qemuDomainGetMachineName(virDomainObjPtr vm); =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 842e088519..2715d86615 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6551,6 +6551,13 @@ qemuDomainSaveImageStartVM(virConnectPtr conn, } } =20 + /* No cookie means libvirt which saved the domain was too old to mess = up + * the CPU definitions. + */ + if (cookie && + qemuDomainFixupCPUs(vm, &cookie->cpu) < 0) + goto cleanup; + if (qemuProcessStart(conn, driver, vm, cookie ? cookie->cpu : NULL, asyncJob, "stdio", *fd, path, NULL, VIR_NETDEV_VPORT_PROFILE_OP_RESTORE, @@ -15754,6 +15761,13 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr sn= apshot, if (config) virDomainObjAssignDef(vm, config, false, NULL); =20 + /* No cookie means libvirt which saved the domain was too old = to + * mess up the CPU definitions. + */ + if (cookie && + qemuDomainFixupCPUs(vm, &cookie->cpu) < 0) + goto cleanup; + rc =3D qemuProcessStart(snapshot->domain->conn, driver, vm, cookie ? cookie->cpu : NULL, QEMU_ASYNC_JOB_START, NULL, -1, NULL, sn= ap, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 8553c5126f..780af5bd78 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6881,6 +6881,7 @@ qemuProcessRefreshCPU(virQEMUDriverPtr driver, virDomainObjPtr vm) { virCapsPtr caps =3D virQEMUDriverGetCapabilities(driver, false); + qemuDomainObjPrivatePtr priv =3D vm->privateData; virCPUDefPtr host =3D NULL; virCPUDefPtr cpu =3D NULL; int ret =3D -1; @@ -6913,6 +6914,14 @@ qemuProcessRefreshCPU(virQEMUDriverPtr driver, =20 if (qemuProcessUpdateCPU(driver, vm, QEMU_ASYNC_JOB_NONE) < 0) goto cleanup; + } else if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_E= XPANSION)) { + /* We only try to fix CPUs when the libvirt/QEMU combo used to sta= rt + * the domain did not know about query-cpu-model-expansion in which + * case the host-model is known to not contain features which QEMU + * doesn't know about. + */ + if (qemuDomainFixupCPUs(vm, &priv->origCPU) < 0) + goto cleanup; } =20 ret =3D 0; --=20 2.14.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list