From nobody Sun Apr 28 06:49:00 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 1513349332001640.7287359886884; Fri, 15 Dec 2017 06:48:52 -0800 (PST) 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 484CD2BDA; Fri, 15 Dec 2017 14:48:50 +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 200786683B; Fri, 15 Dec 2017 14:48:50 +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 DB4D41801215; Fri, 15 Dec 2017 14:48:49 +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 vBFEmdPS023428 for ; Fri, 15 Dec 2017 09:48:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id 87D137C3AC; Fri, 15 Dec 2017 14:48:39 +0000 (UTC) Received: from inaba.usersys.redhat.com (unknown [10.40.205.14]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B726C7C3E8 for ; Fri, 15 Dec 2017 14:48:38 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Fri, 15 Dec 2017 15:48:27 +0100 Message-Id: <20171215144828.23008-2-abologna@redhat.com> In-Reply-To: <20171215144828.23008-1-abologna@redhat.com> References: <20171215144828.23008-1-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 15 Dec 2017 14:48:50 +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; since, after this change, the 'topologycpus' variable doesn't need to have function scope, we move its declaration to the inner scope as well. The comments around the check are modified in order to explain the different QEMU versions involved. Signed-off-by: Andrea Bolognani --- src/qemu/qemu_domain.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 74b82450b..227ba32a7 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,17 @@ 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; + + /* Starting from QEMU 2.5, max vCPU count and overall vCPU topology + * must agree. We only actually enforce this with QEMU 2.7+, due + * to the capability check above */ + 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 Sun Apr 28 06:49:00 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 1513349324444116.69120156291638; Fri, 15 Dec 2017 06:48:44 -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 84B2FC037F7D; Fri, 15 Dec 2017 14:48:42 +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 53E497C3AC; Fri, 15 Dec 2017 14:48:42 +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 1A3BF1800BDF; Fri, 15 Dec 2017 14:48:42 +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 vBFEmeoT023439 for ; Fri, 15 Dec 2017 09:48:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id E40977C3C8; Fri, 15 Dec 2017 14:48:40 +0000 (UTC) Received: from inaba.usersys.redhat.com (unknown [10.40.205.14]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 086797C3AC for ; Fri, 15 Dec 2017 14:48:39 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Fri, 15 Dec 2017 15:48:28 +0100 Message-Id: <20171215144828.23008-3-abologna@redhat.com> In-Reply-To: <20171215144828.23008-1-abologna@redhat.com> References: <20171215144828.23008-1-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 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.32]); Fri, 15 Dec 2017 14:48:42 +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 227ba32a7..43bd0fff4 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 + * + * With QEMU 2.7 and newer, vCPUs can only be hotplugged in groups that + * respect the guest's hotplug granularity; because of that, QEMU will + * not allow guests to start unless the initial number of vCPUs is a + * multiple of the hotplug granularity. + * + * Returns the vCPU hotplug granularity. + */ +static unsigned int +qemuDomainDefGetVcpuHotplugGranularity(const virDomainDef *def) +{ + /* If the guest CPU topology has not been configured, assume we + * can hotplug vCPUs one at a time */ + if (!def->cpu || def->cpu->sockets =3D=3D 0) + return 1; + + /* For pSeries guests, hotplug can only be performed one core + * at a time, so the vCPU hotplug granularity is the number + * of threads per core */ + if (qemuDomainIsPSeries(def)) + return def->cpu->threads; + + /* In all other cases, we can hotplug vCPUs one at a time */ + return 1; +} + + #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 /* Starting from QEMU 2.5, max vCPU count and overall vCPU topology * must agree. We only actually enforce this with QEMU 2.7+, due @@ -3373,6 +3404,16 @@ qemuDomainDefValidate(const virDomainDef *def, _("CPU topology doesn't match maximum vcpu coun= t")); goto cleanup; } + + /* vCPU hotplug granularity must be respected */ + granularity =3D qemuDomainDefGetVcpuHotplugGranularity(def); + if ((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