From nobody Sat Feb 7 21:35:05 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1602708262; cv=none; d=zohomail.com; s=zohoarc; b=aKNZm6O/h/PsdTnBl07Xbo7Bg7M3oKoIV1CvzfakUuZi3lb/ucgK6YOO+AW0+Frdtnm8Upc2An8bwwGlvudH175k7bysPAtAZMmhAgdnEkhkHXdudWq5hnpcH+GzcM3Tsxr86YTF8o13b2z4odKzlYw2weJyj8fjdx29avdpVDo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602708262; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zy3VNduJGx0zmnx1OlAImWvXPlv/Jh0qASjoq2Xt28U=; b=EmrnKMbFYhYNi5LqEFUxKuZqbBCr/p4nrO3IwiUUIWOyXoyV2/bTdS+USYfi/gbladVObvMY+/8eyYWVEzoP/Rzl9BQizNwpXBuxwVfYUGc4XJztQu2hd1KdLwKbZI43htmzDF1ZJ9i0UzyNcPnlxdrql938xJfs4DM6BKtEScg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1602708262238575.3203748448205; Wed, 14 Oct 2020 13:44:22 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-459-PpCJFG9eMkOnyY0AaV1NuQ-1; Wed, 14 Oct 2020 16:44:18 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id CAFEB8015B1; Wed, 14 Oct 2020 20:44:11 +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 A343873661; Wed, 14 Oct 2020 20:44:11 +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 68AB4181A050; Wed, 14 Oct 2020 20:44:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 09EKi0Q0028880 for ; Wed, 14 Oct 2020 16:44:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 56A0210921A9; Wed, 14 Oct 2020 20:44:00 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 52A7A1092196 for ; Wed, 14 Oct 2020 20:44:00 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 245011021F7F for ; Wed, 14 Oct 2020 20:44:00 +0000 (UTC) Received: from mail-il1-f195.google.com (mail-il1-f195.google.com [209.85.166.195]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-110-9M_8Cl91MDqw1eDjsT6grA-1; Wed, 14 Oct 2020 16:43:58 -0400 Received: by mail-il1-f195.google.com with SMTP id p16so1062370ilq.5 for ; Wed, 14 Oct 2020 13:43:57 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c6:5a9b:54fc:df2a:8a5e:989b]) by smtp.gmail.com with ESMTPSA id i4sm492202ilc.27.2020.10.14.13.43.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Oct 2020 13:43:56 -0700 (PDT) X-MC-Unique: PpCJFG9eMkOnyY0AaV1NuQ-1 X-MC-Unique: 9M_8Cl91MDqw1eDjsT6grA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zy3VNduJGx0zmnx1OlAImWvXPlv/Jh0qASjoq2Xt28U=; b=obcSaUIWv9pPwckliq7FfNi3yFBQCj5kliyXQN1mEP+zZydDZ9HTZd3LF2g4zcxv2w cvQoKIZ9L5KLB0zHk/+9QPGcwRgqJ4eTRtcNQkerWAD+uMlGBrpsFFIijLD9OSwZZzXF S9QkDrViKGIlRUXIS1vp9M68jXD49BLhG2iXKya+8qfTCRx5o/JuduT1nsRb3xU/RB4G NurhR7CNlio65nbxjePDPsEQ6+8US1HAXmOAmMFBQCJhxAXpGlQDvBxg4h6OHnBSJHcf 8kaFvpDctPMN1VXVl0vBjV9WZcOBywUZFwlgmz+EN8i67bE+aapIcO6rf+gs1LIVy4DN p4rQ== X-Gm-Message-State: AOAM5303XVwbRcNgK3Dd80CBtCm3W3GSiF/TEuk+zCBqcHZP5kcj8g6i M0OBoMcz36OHeEqVnHDHnFXCveO+ezM= X-Google-Smtp-Source: ABdhPJy20ro8CA3XUOop3GcnsUilnyo2HTJytUfrQt8Ze5XZoptCsIMXoD+RgleplkoMISe5XVafdw== X-Received: by 2002:a05:6e02:106d:: with SMTP id q13mr796195ilj.304.1602708236942; Wed, 14 Oct 2020 13:43:56 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v1 23/24] qemu_validate.c: move VCPU topology checks to qemuValidateDomainCpuCount() Date: Wed, 14 Oct 2020 17:43:06 -0300 Message-Id: <20201014204307.631746-24-danielhb413@gmail.com> In-Reply-To: <20201014204307.631746-1-danielhb413@gmail.com> References: <20201014204307.631746-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rename the function to qemuValidateDomainVCpuTopology() to reflect what it is currently doing as well. Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_validate.c | 174 +++++++++++++++++++-------------------- 1 file changed, 87 insertions(+), 87 deletions(-) diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index b5bea4a0ee..5b5c2ab3dd 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -613,8 +613,38 @@ qemuValidateDomainDefBoot(const virDomainDef *def, } =20 =20 +/** + * qemuValidateDefGetVcpuHotplugGranularity: + * @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 +qemuValidateDefGetVcpuHotplugGranularity(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; +} + + static int -qemuValidateDomainCpuCount(const virDomainDef *def, virQEMUCapsPtr qemuCap= s) +qemuValidateDomainVCpuTopology(const virDomainDef *def, virQEMUCapsPtr qem= uCaps) { unsigned int maxCpus =3D virQEMUCapsGetMachineMaxCpus(qemuCaps, def->v= irtType, def->os.machine); @@ -632,6 +662,61 @@ qemuValidateDomainCpuCount(const virDomainDef *def, vi= rQEMUCapsPtr qemuCaps) return -1; } =20 + /* 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; + unsigned int granularity; + unsigned int numacpus; + + /* 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) { + if (topologycpus !=3D virDomainDefGetVcpusMax(def)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("CPU topology doesn't match maximum vcpu = count")); + return -1; + } + + numacpus =3D virDomainNumaGetCPUCountTotal(def->numa); + if ((numacpus !=3D 0) && (topologycpus !=3D numacpus)) { + VIR_WARN("CPU topology doesn't match numa CPU count; " + "partial NUMA mapping is obsoleted and will " + "be removed in future"); + } + } + + /* vCPU hotplug granularity must be respected */ + granularity =3D qemuValidateDefGetVcpuHotplugGranularity(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); + return -1; + } + } + + if (ARCH_IS_X86(def->os.arch) && + virDomainDefGetVcpusMax(def) > QEMU_MAX_VCPUS_WITHOUT_EIM) { + if (!qemuDomainIsQ35(def)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("more than %d vCPUs are only supported on " + "q35-based machine types"), + QEMU_MAX_VCPUS_WITHOUT_EIM); + return -1; + } + if (!def->iommu || def->iommu->eim !=3D VIR_TRISTATE_SWITCH_ON) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("more than %d vCPUs require extended interrup= t " + "mode enabled on the iommu device"), + QEMU_MAX_VCPUS_WITHOUT_EIM); + return -1; + } + } + return 0; } =20 @@ -823,36 +908,6 @@ qemuValidateDomainDefConsole(const virDomainDef *def, } =20 =20 -/** - * qemuValidateDefGetVcpuHotplugGranularity: - * @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 -qemuValidateDefGetVcpuHotplugGranularity(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; -} - - static int qemuValidateDomainDefSysinfo(const virSysinfoDef *def, virQEMUCapsPtr qemuCaps G_GNUC_UNUSED) @@ -1113,64 +1168,9 @@ qemuValidateDomainDef(const virDomainDef *def, if (qemuValidateDomainDefBoot(def, qemuCaps) < 0) return -1; =20 - /* 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; - unsigned int granularity; - unsigned int numacpus; - - /* 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) { - if (topologycpus !=3D virDomainDefGetVcpusMax(def)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("CPU topology doesn't match maximum vcpu = count")); - return -1; - } - - numacpus =3D virDomainNumaGetCPUCountTotal(def->numa); - if ((numacpus !=3D 0) && (topologycpus !=3D numacpus)) { - VIR_WARN("CPU topology doesn't match numa CPU count; " - "partial NUMA mapping is obsoleted and will " - "be removed in future"); - } - } - - /* vCPU hotplug granularity must be respected */ - granularity =3D qemuValidateDefGetVcpuHotplugGranularity(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); - return -1; - } - } - - if (qemuValidateDomainCpuCount(def, qemuCaps) < 0) + if (qemuValidateDomainVCpuTopology(def, qemuCaps) < 0) return -1; =20 - if (ARCH_IS_X86(def->os.arch) && - virDomainDefGetVcpusMax(def) > QEMU_MAX_VCPUS_WITHOUT_EIM) { - if (!qemuDomainIsQ35(def)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("more than %d vCPUs are only supported on " - "q35-based machine types"), - QEMU_MAX_VCPUS_WITHOUT_EIM); - return -1; - } - if (!def->iommu || def->iommu->eim !=3D VIR_TRISTATE_SWITCH_ON) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("more than %d vCPUs require extended interrup= t " - "mode enabled on the iommu device"), - QEMU_MAX_VCPUS_WITHOUT_EIM); - return -1; - } - } - if (def->nresctrls && def->virtType !=3D VIR_DOMAIN_VIRT_KVM) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", --=20 2.26.2