From patchwork Wed May 14 19:18:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 348935 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1D373140088 for ; Thu, 15 May 2014 05:19:32 +1000 (EST) Received: from localhost ([::1]:53919 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wkei9-0005DJ-VC for incoming@patchwork.ozlabs.org; Wed, 14 May 2014 15:19:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60827) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wkehr-0004u3-Pu for qemu-devel@nongnu.org; Wed, 14 May 2014 15:19:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wkehm-0005Lr-Oi for qemu-devel@nongnu.org; Wed, 14 May 2014 15:19:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32746) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wkehm-0005LT-Hb for qemu-devel@nongnu.org; Wed, 14 May 2014 15:19:06 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s4EJJ0kS012453 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 14 May 2014 15:19:01 -0400 Received: from localhost (ovpn-113-115.phx2.redhat.com [10.3.113.115]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s4EJIxEv024913; Wed, 14 May 2014 15:18:59 -0400 From: Eduardo Habkost To: qemu-devel@nongnu.org, Anthony Liguori Date: Wed, 14 May 2014 16:18:42 -0300 Message-Id: <1400095122-24736-1-git-send-email-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id s4EJJ0kS012453 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell , Marcelo Tosatti , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Igor Mammedov Subject: [Qemu-devel] [PATCH v2 RESEND] vl.c: Unify MAX_CPUMASK_BITS and machine->max_cpus checks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org If a given machine have max_cpus set, not just smp_cpus needs to be limited, but the total number of CPUs (considering CPU hotplug) for the machine. We also had yet another max_cpus limit check at smp_parse(), ensuring that max_cpus < MAX_CPUMASK_BITS. This patch unifies the machine->max_cpus and MAX_CPUMASK_BITS checks, and also moves the (smp_cpus <= max_cpus) outside smp_parse(), to keep all checks in the same place. With those changes, the new code ensures that: 1 <= smp_cpus <= max_cpus <= machine->max_cpus <= MAX_CPUMASK_BITS Signed-off-by: Eduardo Habkost Cc: Peter Maydell Cc: Andreas Färber Cc: Igor Mammedov Cc: Marcelo Tosatti --- Changes v1 -> v2: * v1 was: [PATCH] vl.c: Check max_cpus limit instead of smp_cpus * Unify machine->max_cpus and MAX_CPUMASK_BITS check * Move all checks outside smp_parse() * Add assert() lines ensuring the results are consistent * s/machine/machine_class/, after rebase to latest qemu.git (commit 6b342cc) --- vl.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/vl.c b/vl.c index 709d8cd..749abbd 100644 --- a/vl.c +++ b/vl.c @@ -1425,15 +1425,6 @@ static void smp_parse(QemuOpts *opts) max_cpus = smp_cpus; } - if (max_cpus > MAX_CPUMASK_BITS) { - fprintf(stderr, "Unsupported number of maxcpus\n"); - exit(1); - } - if (max_cpus < smp_cpus) { - fprintf(stderr, "maxcpus must be equal to or greater than smp\n"); - exit(1); - } - } static void configure_realtime(QemuOpts *opts) @@ -4054,13 +4045,24 @@ int main(int argc, char **argv, char **envp) smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL)); machine_class->max_cpus = machine_class->max_cpus ?: 1; /* Default to UP */ - if (smp_cpus > machine_class->max_cpus) { - fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus " - "supported by machine `%s' (%d)\n", smp_cpus, + machine_class->max_cpus = MIN(machine_class->max_cpus, MAX_CPUMASK_BITS); + + if (max_cpus < smp_cpus) { + fprintf(stderr, "maxcpus must be equal to or greater than smp\n"); + exit(1); + } + if (max_cpus > machine_class->max_cpus) { + fprintf(stderr, "Total number of CPUs (%d), exceeds maximum " + "supported by machine `%s' (%d)\n", max_cpus, machine_class->name, machine_class->max_cpus); exit(1); } + assert(1 <= smp_cpus); + assert(smp_cpus <= max_cpus); + assert(max_cpus <= machine_class->max_cpus); + assert(machine_class->max_cpus <= MAX_CPUMASK_BITS); + /* * Get the default machine options from the machine if it is not already * specified either by the configuration file or by the command line.