Received: from eggs.gnu.org ([2001:4830:134:3::10]:46929) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WiUXN-0000zP-6x for qemu-devel@nongnu.org; Thu, 08 May 2014 16:03:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WiUXH-00018l-JG for qemu-devel@nongnu.org; Thu, 08 May 2014 16:03:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49474) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WiUXD-00016P-Er for qemu-devel@nongnu.org; Thu, 08 May 2014 16:03:19 -0400 From: Eduardo Habkost Date: Thu, 8 May 2014 17:02:59 -0300 Message-Id: <1399579379-8370-1-git-send-email-ehabkost@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v2] vl.c: Unify MAX_CPUMASK_BITS and machine->max_cpus checks List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Anthony Liguori Cc: Peter Maydell , Marcelo Tosatti , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Igor Mammedov 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 <=3D max_cpus) outside smp_parse(), to keep all checks in the same place. With those changes, the new code ensures that: 1 <=3D smp_cpus <=3D max_cpus <=3D machine->max_cpus <=3D MAX_CPUMASK_B= ITS Signed-off-by: Eduardo Habkost Cc: Peter Maydell Cc: Andreas F=C3=A4rber 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 73e0661..434cdc3 100644 --- a/vl.c +++ b/vl.c @@ -1425,15 +1425,6 @@ static void smp_parse(QemuOpts *opts) max_cpus =3D smp_cpus; } =20 - 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); - } - } =20 static void configure_realtime(QemuOpts *opts) @@ -4055,13 +4046,24 @@ int main(int argc, char **argv, char **envp) smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL)); =20 machine_class->max_cpus =3D 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 =3D 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); } =20 + assert(1 <=3D smp_cpus); + assert(smp_cpus <=3D max_cpus); + assert(max_cpus <=3D machine_class->max_cpus); + assert(machine_class->max_cpus <=3D MAX_CPUMASK_BITS); + /* * Get the default machine options from the machine if it is not alr= eady * specified either by the configuration file or by the command line. --=20 1.9.0