From nobody Wed May 1 22:18:21 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 1513269007552584.2748492892474; Thu, 14 Dec 2017 08:30:07 -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 72CC98618; Thu, 14 Dec 2017 16:30:06 +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 31C2017CDB; Thu, 14 Dec 2017 16:30:06 +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 A7EE91801215; Thu, 14 Dec 2017 16:30:04 +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 vBEGU3fR017416 for ; Thu, 14 Dec 2017 11:30:03 -0500 Received: by smtp.corp.redhat.com (Postfix) id 44A5371923; Thu, 14 Dec 2017 16:30:03 +0000 (UTC) Received: from inaba.usersys.redhat.com (ovpn-204-182.brq.redhat.com [10.40.204.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 53CE87191F for ; Thu, 14 Dec 2017 16:30:01 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Thu, 14 Dec 2017 17:29:50 +0100 Message-Id: <20171214162951.2856-2-abologna@redhat.com> In-Reply-To: <20171214162951.2856-1-abologna@redhat.com> References: <20171214162951.2856-1-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/2] qemu: Invert condition nesting in qemuDomainDefValidate() 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.38]); Thu, 14 Dec 2017 16:30:06 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" While at the moment we're only performing a single check that is connected to vCPU hotplugging, we're going to introduce a second one soon. Move the topology check underneath the capability check to make that easier; as a bonus, doing so allows us to reduce the scope of the 'topologycpus' variable. Signed-off-by: Andrea Bolognani --- src/qemu/qemu_domain.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 74b82450b..e93333669 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -3299,7 +3299,6 @@ qemuDomainDefValidate(const virDomainDef *def, { virQEMUDriverPtr driver =3D opaque; virQEMUCapsPtr qemuCaps =3D NULL; - unsigned int topologycpus; int ret =3D -1; =20 if (!(qemuCaps =3D virQEMUCapsCacheLookup(driver->qemuCapsCache, @@ -3359,11 +3358,15 @@ qemuDomainDefValidate(const virDomainDef *def, } } =20 - /* qemu as of 2.5.0 rejects SMP topologies that don't match the cpu co= unt */ - if (virDomainDefGetVcpusTopology(def, &topologycpus) =3D=3D 0 && - topologycpus !=3D virDomainDefGetVcpusMax(def)) { - /* presence of query-hotpluggable-cpus should be a good enough wit= ness */ - if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_HOTPLUGGABLE_CPUS)) { + /* QEMU 2.7 (detected via the availability of query-hotpluggable-cpus) + * enforces stricter rules than previous versions when it comes to gue= st + * CPU topology. Verify known constraints are respected */ + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_HOTPLUGGABLE_CPUS)) { + unsigned int topologycpus; + + /* Max vCPU count and overall vCPU topology must agree */ + if (virDomainDefGetVcpusTopology(def, &topologycpus) =3D=3D 0 && + topologycpus !=3D virDomainDefGetVcpusMax(def)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("CPU topology doesn't match maximum vcpu coun= t")); goto cleanup; --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 22:18:21 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 1513269027196568.3447089472446; Thu, 14 Dec 2017 08:30:27 -0800 (PST) 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 339F62D1B4; Thu, 14 Dec 2017 16:30:26 +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 0AF2A7C359; Thu, 14 Dec 2017 16:30:26 +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 C98924BB79; Thu, 14 Dec 2017 16:30:25 +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 vBEGU7Gm017427 for ; Thu, 14 Dec 2017 11:30:07 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4FF8C71923; Thu, 14 Dec 2017 16:30:07 +0000 (UTC) Received: from inaba.usersys.redhat.com (ovpn-204-182.brq.redhat.com [10.40.204.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7EAFD7982D for ; Thu, 14 Dec 2017 16:30:03 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Thu, 14 Dec 2017 17:29:51 +0100 Message-Id: <20171214162951.2856-3-abologna@redhat.com> In-Reply-To: <20171214162951.2856-1-abologna@redhat.com> References: <20171214162951.2856-1-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/2] qemu: Enforce vCPU hotplug granularity constraints 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.38]); Thu, 14 Dec 2017 16:30:26 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" QEMU 2.7 and newer don't allow guests to start unless the initial vCPUs count is a multiple of the vCPU hotplug granularity, so validate it and report an error if needed. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1283700 Signed-off-by: Andrea Bolognani --- src/qemu/qemu_domain.c | 41 ++++++++++++++++++= ++++ tests/qemuxml2argvdata/cpu-hotplug-granularity.xml | 18 ++++++++++ tests/qemuxml2argvtest.c | 3 ++ 3 files changed, 62 insertions(+) create mode 100644 tests/qemuxml2argvdata/cpu-hotplug-granularity.xml diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index e93333669..632f330f7 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -3289,6 +3289,36 @@ qemuDomainDefValidateVideo(const virDomainDef *def) } =20 =20 +/** + * qemuDomainDefGetVcpuHotplugGranularity: + * @def: domain definition + * @granularity: return location for vCPU hotplug granularity + * + * With QEMU 2.7 and newer, vCPUs can only be hotplugged @granularity at + * a time; because of that, QEMU will not allow guests to start unless the + * initial number of vCPUs is a multiple of @granularity. + * + * Returns 0 on success, 1 if topology is not configured and -1 on error. + */ +static int +qemuDomainDefGetVcpuHotplugGranularity(const virDomainDef *def, + unsigned int *granularity) +{ + if (!granularity) + return -1; + + if (!def->cpu || def->cpu->sockets =3D=3D 0) + return 1; + + if (qemuDomainIsPSeries(def)) + *granularity =3D def->cpu->threads; + else + *granularity =3D 1; + + return 0; +} + + #define QEMU_MAX_VCPUS_WITHOUT_EIM 255 =20 =20 @@ -3363,6 +3393,7 @@ qemuDomainDefValidate(const virDomainDef *def, * CPU topology. Verify known constraints are respected */ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_HOTPLUGGABLE_CPUS)) { unsigned int topologycpus; + unsigned int granularity; =20 /* Max vCPU count and overall vCPU topology must agree */ if (virDomainDefGetVcpusTopology(def, &topologycpus) =3D=3D 0 && @@ -3371,6 +3402,16 @@ qemuDomainDefValidate(const virDomainDef *def, _("CPU topology doesn't match maximum vcpu coun= t")); goto cleanup; } + + /* vCPU hotplug granularity must be respected */ + if (qemuDomainDefGetVcpuHotplugGranularity(def, &granularity) =3D= =3D 0 && + (virDomainDefGetVcpus(def) % granularity) !=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("vCPUs count must be a multiple of the vCPU " + "hotplug granularity (%u)"), + granularity); + goto cleanup; + } } =20 if (ARCH_IS_X86(def->os.arch) && diff --git a/tests/qemuxml2argvdata/cpu-hotplug-granularity.xml b/tests/qem= uxml2argvdata/cpu-hotplug-granularity.xml new file mode 100644 index 000000000..a94f41e46 --- /dev/null +++ b/tests/qemuxml2argvdata/cpu-hotplug-granularity.xml @@ -0,0 +1,18 @@ + + guest + 1ccfd97d-5eb4-478a-bbe6-88d254c16db7 + 524288 + 8 + + hvm + + + + + + /usr/bin/qemu-system-ppc64 + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index ca24e0bbb..10ab8d787 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -2900,6 +2900,9 @@ mymain(void) QEMU_CAPS_DEVICE_INTEL_IOMMU); =20 DO_TEST("cpu-hotplug-startup", QEMU_CAPS_QUERY_HOTPLUGGABLE_CPUS); + DO_TEST_PARSE_ERROR("cpu-hotplug-granularity", + QEMU_CAPS_QUERY_HOTPLUGGABLE_CPUS); + DO_TEST("virtio-options", QEMU_CAPS_VIRTIO_SCSI, QEMU_CAPS_VIRTIO_KEYB= OARD, QEMU_CAPS_VIRTIO_MOUSE, QEMU_CAPS_VIRTIO_TABLET, QEMU_CAPS_VIRTIO_INPUT_HOST, --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list