From nobody Wed Nov 5 18:30:56 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1536837451574456.2656015773067; Thu, 13 Sep 2018 04:17:31 -0700 (PDT) Received: from localhost ([::1]:41770 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g0Pco-0008GR-Es for importer@patchew.org; Thu, 13 Sep 2018 07:17:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50279) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g0PZU-0006Cm-St for qemu-devel@nongnu.org; Thu, 13 Sep 2018 07:14:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g0PZS-0006dY-3H for qemu-devel@nongnu.org; Thu, 13 Sep 2018 07:14:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47556) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g0PZR-0006d2-Ro for qemu-devel@nongnu.org; Thu, 13 Sep 2018 07:14:02 -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 mx1.redhat.com (Postfix) with ESMTPS id 334FE81106 for ; Thu, 13 Sep 2018 11:14:01 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.37.153.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D7A8608E0; Thu, 13 Sep 2018 11:14:00 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Date: Thu, 13 Sep 2018 13:06:01 +0200 Message-Id: <1536836762-273036-2-git-send-email-imammedo@redhat.com> In-Reply-To: <1536836762-273036-1-git-send-email-imammedo@redhat.com> References: <1536836762-273036-1-git-send-email-imammedo@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.28]); Thu, 13 Sep 2018 11:14:01 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v8 1/2] vl.c deprecate incorrect CPUs topology X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ehabkost@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" -smp [cpus],sockets/cores/threads[,maxcpus] should describe topology so that total number of logical CPUs [sockets * cores * threads] would be equal to [maxcpus], however historically we didn't have such check in QEMU and it is possible to start VM with an invalid topology. Deprecate invalid options combination so we can make sure that the topology VM started with is always correct in the future. Users with an invalid sockets/cores/threads/maxcpus values should fix their CLI to make sure that [sockets * cores * threads] =3D=3D [maxcpus] Signed-off-by: Igor Mammedov Reviewed-by: Andrew Jones Reviewed-by: Eduardo Habkost Reviewed-by: Eric Blake --- V8: - drop repetitive sentence: "In other words: ..." (Eric Blake ) v7: - add corrections to deprication doc formulas/math/section title - drop Note section (Eduardo Habkost ) v6: - s/socket/sockets/, the same for core, thread in subsection (Andrew Jones ) v5: - extend deprecation doc, adding that maxcpus should be multiple of present on CLI [sockets/cores/threads] options (Eduardo Habkost ) v4: - missed dot comment, fix it with s/./,/ (Andrew Jones ) v3: - more spelling fixes (Andrew Jones ) - place deprecation check after (sockets * cores * threads > max_cpus) ch= eck (Eduardo Habkost ) v2: - spelling&&co fixes (Andrew Jones ) --- qemu-deprecated.texi | 12 ++++++++++++ vl.c | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/qemu-deprecated.texi b/qemu-deprecated.texi index 1b9c007..df717df 100644 --- a/qemu-deprecated.texi +++ b/qemu-deprecated.texi @@ -139,6 +139,18 @@ The 'file' driver for drives is no longer appropriate = for character or host devices and will only accept regular files (S_IFREG). The correct driver for these file types is 'host_cdrom' or 'host_device' as appropriate. =20 +@subsection -smp (invalid topologies) (since 3.1) + +CPU topology properties should describe whole machine topology including +possible CPUs. + +However, historically it was possible to start QEMU with an incorrect topo= logy +where @math{@var{n} <=3D @var{sockets} * @var{cores} * @var{threads} < @va= r{maxcpus}}, +which could lead to an incorrect topology enumeration by the guest. +Support for invalid topologies will be removed, the user must ensure +topologies described with -smp include all possible cpus, i.e. + @math{@var{sockets} * @var{cores} * @var{threads} =3D @var{maxcpus}}. + @section QEMU Machine Protocol (QMP) commands =20 @subsection block-dirty-bitmap-add "autoload" parameter (since 2.12.0) diff --git a/vl.c b/vl.c index 5ba06ad..7fd700e 100644 --- a/vl.c +++ b/vl.c @@ -1246,6 +1246,13 @@ static void smp_parse(QemuOpts *opts) exit(1); } =20 + if (sockets * cores * threads !=3D max_cpus) { + warn_report("Invalid CPU topology deprecated: " + "sockets (%u) * cores (%u) * threads (%u) " + "!=3D maxcpus (%u)", + sockets, cores, threads, max_cpus); + } + smp_cpus =3D cpus; smp_cores =3D cores; smp_threads =3D threads; --=20 2.7.4 From nobody Wed Nov 5 18:30:56 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1536837339829724.9408748449164; Thu, 13 Sep 2018 04:15:39 -0700 (PDT) Received: from localhost ([::1]:41763 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g0Pb0-00079l-QQ for importer@patchew.org; Thu, 13 Sep 2018 07:15:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50276) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g0PZU-0006Ck-SW for qemu-devel@nongnu.org; Thu, 13 Sep 2018 07:14:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g0PZT-0006eC-6k for qemu-devel@nongnu.org; Thu, 13 Sep 2018 07:14:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60516) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g0PZT-0006dq-0P for qemu-devel@nongnu.org; Thu, 13 Sep 2018 07:14:03 -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 mx1.redhat.com (Postfix) with ESMTPS id 5DF0980F75 for ; Thu, 13 Sep 2018 11:14:02 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.37.153.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 76F05608E0; Thu, 13 Sep 2018 11:14:01 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Date: Thu, 13 Sep 2018 13:06:02 +0200 Message-Id: <1536836762-273036-3-git-send-email-imammedo@redhat.com> In-Reply-To: <1536836762-273036-1-git-send-email-imammedo@redhat.com> References: <1536836762-273036-1-git-send-email-imammedo@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.27]); Thu, 13 Sep 2018 11:14:02 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v8 2/2] vl:c: make sure that sockets are calculated correctly in '-smp X' case X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ehabkost@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" commit (5cdc9b76e3 vl.c: Remove dead assignment) removed sockets calculation when 'sockets' weren't provided on CLI since there wasn't any users for it back then. Exiting checks are neither reachable } else if (sockets * cores * threads < cpus) { or nor triggerable if (sockets * cores * threads > max_cpus) so we weren't noticing wrong topology since then, since users recalculate sockets adhoc on their own. However with deprecation check it becomes noticable, for example -smp 2 will start printing warning: "warning: Invalid CPU topology deprecated: sockets (1) * cores (1) * thre= ads (1) !=3D maxcpus (2)" calculating sockets if they weren't specified. Fix it by returning back sockets calculation if it's omitted on CLI. Signed-off-by: Igor Mammedov Reviewed-by: Andrew Jones --- v8: - spelling fixes in commit message (Eric Blake ) --- vl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vl.c b/vl.c index 7fd700e..9e56696 100644 --- a/vl.c +++ b/vl.c @@ -1210,11 +1210,14 @@ static void smp_parse(QemuOpts *opts) =20 /* compute missing values, prefer sockets over cores over threads = */ if (cpus =3D=3D 0 || sockets =3D=3D 0) { - sockets =3D sockets > 0 ? sockets : 1; cores =3D cores > 0 ? cores : 1; threads =3D threads > 0 ? threads : 1; if (cpus =3D=3D 0) { + sockets =3D sockets > 0 ? sockets : 1; cpus =3D cores * threads * sockets; + } else { + max_cpus =3D qemu_opt_get_number(opts, "maxcpus", cpus); + sockets =3D max_cpus / (cores * threads); } } else if (cores =3D=3D 0) { threads =3D threads > 0 ? threads : 1; --=20 2.7.4