Skip to contentSkip to conversation

vl: remove (max_cpus > 255) check from smp_parse

PATCH In review Alexey Kardashevskiy 7 participants 13 messages Nov 25, 2013 – Feb 14, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vl: remove (max_cpus > 255) check from smp_parse

Since modern POWER7/POWER8 chips can have more that 256 CPU threads (>2000 actually), remove this check from smp_parse.

The CPUs number is still checked against machine->max_cpus and this check should be enough not to break other archs.

---
 vl.c | 4 ----
 1 file changed, 4 deletions(-)
vl.c +0 -4
index 8d5d874..e6ed260 100644
@@ -1420,10 +1420,6 @@ static void smp_parse(QemuOpts *opts)
         max_cpus = smp_cpus;
     }
 
-    if (max_cpus > 255) {
-        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);
Signature · 1 line
1.8.4.rc4
#1 lore raw
Quoted 5 lines · Alexey Kardashevskiy

Since modern POWER7/POWER8 chips can have more that 256 CPU threads (>2000 actually), remove this check from smp_parse.

The CPUs number is still checked against machine->max_cpus and this check should be enough not to break other archs.

[]

vl.c static void smp_parse(QemuOpts *opts) · line 1426

Quoted 4 lines
vl.c +0 -4
-    if (max_cpus > 255) {
-        fprintf(stderr, "Unsupported number of maxcpus\n");
-        exit(1);
-    }

I don't know whenever this is actually safe. Do we have any static arrays of size 255 somewhere, which will be overflowed without this check? :)

Thanks,

/mjt

#2 lore raw

Am 02.12.2013 18:06, schrieb Michael Tokarev:

Quoted 6 lines
Quoted 5 lines · Alexey Kardashevskiy

Since modern POWER7/POWER8 chips can have more that 256 CPU threads (>2000 actually), remove this check from smp_parse.

The CPUs number is still checked against machine->max_cpus and this check should be enough not to break other archs.

"should be" is not exactly the highest level of confidence for a "trivial" patch... :/

Quoted 5 lines

[]

Quoted 4 lines
vl.c +0 -4
-    if (max_cpus > 255) {
-        fprintf(stderr, "Unsupported number of maxcpus\n");
-        exit(1);
-    }

I believe Eduardo touched that code last for NUMA, so let's CC him.

Quoted 2 lines

I don't know whenever this is actually safe. Do we have any static arrays of size 255 somewhere, which will be overflowed without this check? :)

s390 has the ipi_states[] array, but not fixed to that size.

x86 APIC IDs I think have or had a limitation to 255 rather than 16-bit? Igor?

Alexey, did you actually check that, e.g., x86 machines don't break with 256 or 257 CPUs now?

Adding a qtest would be one way to prove that at least the QEMU code of all other architectures doesn't break with the ppc change.

Regards,
Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#3 lore raw
Quoted 17 lines · Andreas Färber

Am 02.12.2013 18:06, schrieb Michael Tokarev:

Quoted 6 lines
Quoted 5 lines · Alexey Kardashevskiy

Since modern POWER7/POWER8 chips can have more that 256 CPU threads (>2000 actually), remove this check from smp_parse.

The CPUs number is still checked against machine->max_cpus and this check should be enough not to break other archs.

"should be" is not exactly the highest level of confidence for a "trivial" patch... :/

Quoted 5 lines

[]

Quoted 4 lines
vl.c +0 -4
-    if (max_cpus > 255) {
-        fprintf(stderr, "Unsupported number of maxcpus\n");
-        exit(1);
-    }
Quoted 6 lines

I believe Eduardo touched that code last for NUMA, so let's CC him.

Quoted 2 lines

I don't know whenever this is actually safe. Do we have any static arrays of size 255 somewhere, which will be overflowed without this check? :)

s390 has the ipi_states[] array, but not fixed to that size.

s390 machines have QemuMachine::max_cpus == 255.

Quoted 5 lines

x86 APIC IDs I think have or had a limitation to 255 rather than 16-bit? Igor?

Alexey, did you actually check that, e.g., x86 machines don't break with 256 or 257 CPUs now?

PC_DEFAULT_MACHINE_OPTIONS sets it to 255. And I cannot find any machine which would not define max_cpus, have I missed any?

Signature · 1 line
Alexey
#4 lore raw

Alexey Kardashevskiy <[email protected]> writes:

[...]

Quoted 2 lines

And I cannot find any machine
which would not define max_cpus, have I missed any?

If a machine lacks an explicit initializer for max_cpus, it'll remain zero, which its users will interpret as 1.

#5 lore raw
In reply to Alexey Kardashevskiy

Am 03.12.2013 00:03, schrieb Alexey Kardashevskiy:

Quoted 11 lines · Andreas Färber
Quoted 10 lines

Am 02.12.2013 18:06, schrieb Michael Tokarev:

Quoted 6 lines
Quoted 5 lines · Alexey Kardashevskiy

Since modern POWER7/POWER8 chips can have more that 256 CPU threads (>2000 actually), remove this check from smp_parse.

The CPUs number is still checked against machine->max_cpus and this check should be enough not to break other archs.

"should be" is not exactly the highest level of confidence for a "trivial" patch... :/

[...]

Quoted 5 lines
Quoted 2 lines

Alexey, did you actually check that, e.g., x86 machines don't break with 256 or 257 CPUs now?

PC_DEFAULT_MACHINE_OPTIONS sets it to 255. And I cannot find any machine which would not define max_cpus, have I missed any?

If you've actually *checked* the other machines' code then fine with me, just say so in the commit message. :)

Cheers,
Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#6 lore raw
Quoted 13 lines · Andreas Färber

Am 03.12.2013 00:03, schrieb Alexey Kardashevskiy:

Quoted 11 lines · Andreas Färber
Quoted 10 lines

Am 02.12.2013 18:06, schrieb Michael Tokarev:

Quoted 6 lines
Quoted 5 lines · Alexey Kardashevskiy

Since modern POWER7/POWER8 chips can have more that 256 CPU threads (>2000 actually), remove this check from smp_parse.

The CPUs number is still checked against machine->max_cpus and this check should be enough not to break other archs.

"should be" is not exactly the highest level of confidence for a "trivial" patch... :/

[...]

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Alexey, did you actually check that, e.g., x86 machines don't break with 256 or 257 CPUs now?

PC_DEFAULT_MACHINE_OPTIONS sets it to 255. And I cannot find any machine which would not define max_cpus, have I missed any?

If you've actually *checked* the other machines' code then fine with me, just say so in the commit message. :)

I just grepped for "max_cpus" and checked every match. The largest values I found were:

hw/ppc/spapr.c: 256
s390: 255
pc: 255

All the rest had values <= 32.

Machines with missing max_cpus value shouldn't be a problem, as max_cpus==0 is interpreted as 1 by the vl.c code.

But we still need to add a check for max_cpus > machine->max_cpus to vl.c, before we eliminate the smp_parse() check.

There's also this, at main():

        if (i == nb_numa_nodes) {
            for (i = 0; i < max_cpus; i++) {
                set_bit(i, node_cpumask[i % nb_numa_nodes]);
            }
        }

node_cpumask[] is initialized using bitmap_new(MAX_CPUMASK_BITS), and MAX_CPUMASK_BITS is 255. To fix this, we can initialize node_cpumask[] using max_cpus instead, if we initialize it after smp_parse().

Signature · 1 line
Eduardo
#7 lore raw
Quoted 30 lines · Eduardo Habkost
Quoted 13 lines · Andreas Färber

Am 03.12.2013 00:03, schrieb Alexey Kardashevskiy:

Quoted 11 lines · Andreas Färber
Quoted 10 lines

Am 02.12.2013 18:06, schrieb Michael Tokarev:

Quoted 6 lines
Quoted 5 lines · Alexey Kardashevskiy

Since modern POWER7/POWER8 chips can have more that 256 CPU threads (>2000 actually), remove this check from smp_parse.

The CPUs number is still checked against machine->max_cpus and this check should be enough not to break other archs.

"should be" is not exactly the highest level of confidence for a "trivial" patch... :/

[...]

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Alexey, did you actually check that, e.g., x86 machines don't break with 256 or 257 CPUs now?

PC_DEFAULT_MACHINE_OPTIONS sets it to 255. And I cannot find any machine which would not define max_cpus, have I missed any?

If you've actually *checked* the other machines' code then fine with me, just say so in the commit message. :)

I just grepped for "max_cpus" and checked every match. The largest values I found were:

hw/ppc/spapr.c: 256
s390: 255
pc: 255

Quoted 7 lines

All the rest had values <= 32.

Machines with missing max_cpus value shouldn't be a problem, as max_cpus==0 is interpreted as 1 by the vl.c code.

But we still need to add a check for max_cpus > machine->max_cpus to vl.c, before we eliminate the smp_parse() check.

Since smp_parse() checks if (max_cpus >= smp_cpus), this should just work:

vl.c +2 -2
index e6ed260..544165a 100644
@@ -3882,9 +3882,9 @@ int main(int argc, char **argv, char **envp)
     smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL));
 
     machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
-    if (smp_cpus > machine->max_cpus) {
+    if (max_cpus > machine->max_cpus) {
         fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
-                "supported by machine `%s' (%d)\n", smp_cpus,  machine->name,
+                "supported by machine `%s' (%d)\n", max_cpus,  machine->name,
                 machine->max_cpus);
         exit(1);
     }
Quoted 11 lines

There's also this, at main():

        if (i == nb_numa_nodes) {
            for (i = 0; i < max_cpus; i++) {
                set_bit(i, node_cpumask[i % nb_numa_nodes]);
            }
        }

node_cpumask[] is initialized using bitmap_new(MAX_CPUMASK_BITS), and MAX_CPUMASK_BITS is 255. To fix this, we can initialize node_cpumask[] using max_cpus instead, if we initialize it after smp_parse().

Nope. At the moment when we parse -numa in vl.c, we may not know yet what machine is going to be used and machines can have different max_cpus.

For now, I would simply change MAX_CPUMASK_BITS to something crazy, like 16384 (2KB per numa node), I hope QEMU can survive such a memory waste :)

Ok?

Signature · 1 line
Alexey
#8 lore raw
Quoted 68 lines · Alexey Kardashevskiy
Quoted 30 lines · Eduardo Habkost
Quoted 13 lines · Andreas Färber

Am 03.12.2013 00:03, schrieb Alexey Kardashevskiy:

Quoted 11 lines · Andreas Färber
Quoted 10 lines

Am 02.12.2013 18:06, schrieb Michael Tokarev:

Quoted 6 lines
Quoted 5 lines · Alexey Kardashevskiy

Since modern POWER7/POWER8 chips can have more that 256 CPU threads (>2000 actually), remove this check from smp_parse.

The CPUs number is still checked against machine->max_cpus and this check should be enough not to break other archs.

"should be" is not exactly the highest level of confidence for a "trivial" patch... :/

[...]

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Alexey, did you actually check that, e.g., x86 machines don't break with 256 or 257 CPUs now?

PC_DEFAULT_MACHINE_OPTIONS sets it to 255. And I cannot find any machine which would not define max_cpus, have I missed any?

If you've actually *checked* the other machines' code then fine with me, just say so in the commit message. :)

I just grepped for "max_cpus" and checked every match. The largest values I found were:

hw/ppc/spapr.c: 256
s390: 255
pc: 255

Quoted 7 lines

All the rest had values <= 32.

Machines with missing max_cpus value shouldn't be a problem, as max_cpus==0 is interpreted as 1 by the vl.c code.

But we still need to add a check for max_cpus > machine->max_cpus to vl.c, before we eliminate the smp_parse() check.

Since smp_parse() checks if (max_cpus >= smp_cpus), this should just work:

vl.c +2 -2
index e6ed260..544165a 100644
@@ -3882,9 +3882,9 @@ int main(int argc, char **argv, char **envp)
     smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL));
 
     machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
-    if (smp_cpus > machine->max_cpus) {
+    if (max_cpus > machine->max_cpus) {
         fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
-                "supported by machine `%s' (%d)\n", smp_cpus,  machine->name,
+                "supported by machine `%s' (%d)\n", max_cpus,  machine->name,
                 machine->max_cpus);
         exit(1);
     }
Quoted 10 lines

There's also this, at main():

        if (i == nb_numa_nodes) {
            for (i = 0; i < max_cpus; i++) {
                set_bit(i, node_cpumask[i % nb_numa_nodes]);
            }
        }
Quoted 7 lines
Quoted 3 lines

node_cpumask[] is initialized using bitmap_new(MAX_CPUMASK_BITS), and MAX_CPUMASK_BITS is 255. To fix this, we can initialize node_cpumask[] using max_cpus instead, if we initialize it after smp_parse().

Nope. At the moment when we parse -numa in vl.c, we may not know yet what machine is going to be used and machines can have different max_cpus.

This will be changed by:

Subject: [PATCH V17 04/11] NUMA: convert -numa option to use OptsVisitor
Message-Id: <[email protected]>
http://article.gmane.org/gmane.comp.emulators.qemu/244826

Quoted 5 lines

For now, I would simply change MAX_CPUMASK_BITS to something crazy, like 16384 (2KB per numa node), I hope QEMU can survive such a memory waste :)

Ok?

I'm OK with that as long the code has proper checks in case max_cpus gets set to a crazily large value (larger than MAX_CPUMASK_BITS) in the far future, or if we prevent max_cpus from being larger than MAX_CPUMASK_BITS.

Signature · 1 line
Eduardo
#9 lore raw
Quoted 74 lines · Eduardo Habkost
Quoted 73 lines · Alexey Kardashevskiy
Quoted 30 lines · Eduardo Habkost
Quoted 13 lines · Andreas Färber

Am 03.12.2013 00:03, schrieb Alexey Kardashevskiy:

Quoted 11 lines · Andreas Färber
Quoted 10 lines

Am 02.12.2013 18:06, schrieb Michael Tokarev:

Quoted 6 lines
Quoted 5 lines · Alexey Kardashevskiy

Since modern POWER7/POWER8 chips can have more that 256 CPU threads (>2000 actually), remove this check from smp_parse.

The CPUs number is still checked against machine->max_cpus and this check should be enough not to break other archs.

"should be" is not exactly the highest level of confidence for a "trivial" patch... :/

[...]

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Alexey, did you actually check that, e.g., x86 machines don't break with 256 or 257 CPUs now?

PC_DEFAULT_MACHINE_OPTIONS sets it to 255. And I cannot find any machine which would not define max_cpus, have I missed any?

If you've actually *checked* the other machines' code then fine with me, just say so in the commit message. :)

I just grepped for "max_cpus" and checked every match. The largest values I found were:

hw/ppc/spapr.c: 256
s390: 255
pc: 255

Quoted 7 lines

All the rest had values <= 32.

Machines with missing max_cpus value shouldn't be a problem, as max_cpus==0 is interpreted as 1 by the vl.c code.

But we still need to add a check for max_cpus > machine->max_cpus to vl.c, before we eliminate the smp_parse() check.

Since smp_parse() checks if (max_cpus >= smp_cpus), this should just work:

vl.c +2 -2
index e6ed260..544165a 100644
@@ -3882,9 +3882,9 @@ int main(int argc, char **argv, char **envp)
     smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL));
 
     machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
-    if (smp_cpus > machine->max_cpus) {
+    if (max_cpus > machine->max_cpus) {
         fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
-                "supported by machine `%s' (%d)\n", smp_cpus,  machine->name,
+                "supported by machine `%s' (%d)\n", max_cpus,  machine->name,
                 machine->max_cpus);
         exit(1);
     }
Quoted 13 lines

There's also this, at main():

        if (i == nb_numa_nodes) {
            for (i = 0; i < max_cpus; i++) {
                set_bit(i, node_cpumask[i % nb_numa_nodes]);
            }
        }

node_cpumask[] is initialized using bitmap_new(MAX_CPUMASK_BITS), and MAX_CPUMASK_BITS is 255. To fix this, we can initialize node_cpumask[] using max_cpus instead, if we initialize it after smp_parse().

Quoted 8 lines
Quoted 2 lines

Nope. At the moment when we parse -numa in vl.c, we may not know yet what machine is going to be used and machines can have different max_cpus.

This will be changed by:

Subject: [PATCH V17 04/11] NUMA: convert -numa option to use OptsVisitor
Message-Id: <[email protected]>
http://article.gmane.org/gmane.comp.emulators.qemu/244826

Any progress with this? Thanks.

Quoted 11 lines
Quoted 5 lines

For now, I would simply change MAX_CPUMASK_BITS to something crazy, like 16384 (2KB per numa node), I hope QEMU can survive such a memory waste :)

Ok?

I'm OK with that as long the code has proper checks in case max_cpus gets set to a crazily large value (larger than MAX_CPUMASK_BITS) in the far future, or if we prevent max_cpus from being larger than MAX_CPUMASK_BITS.

Signature · 1 line
Alexey
#10 lore raw

Il 14/02/2014 07:56, Alexey Kardashevskiy ha scritto:

Quoted 5 lines
Quoted 3 lines
Quoted 3 lines

Subject: [PATCH V17 04/11] NUMA: convert -numa option to use OptsVisitor
Message-Id: <[email protected]>
http://article.gmane.org/gmane.comp.emulators.qemu/244826

Any progress with this? Thanks.

Yes, there was some progress though for some reason it happened onlist.

Igor/Wanlong, can you send the first patches of the "common" NUMA/memory series, i.e. excluding the memdev backend?

Paolo

#11 lore raw
In reply to Andreas Färber
Quoted 19 lines · On Mon, 02 Dec 2013 23:09:55 +0100 Andreas Färber <[email protected]> wrote:

Am 02.12.2013 18:06, schrieb Michael Tokarev:

Quoted 6 lines
Quoted 5 lines · Alexey Kardashevskiy

Since modern POWER7/POWER8 chips can have more that 256 CPU threads (>2000 actually), remove this check from smp_parse.

The CPUs number is still checked against machine->max_cpus and this check should be enough not to break other archs.

"should be" is not exactly the highest level of confidence for a "trivial" patch... :/

Quoted 5 lines

[]

Quoted 4 lines
vl.c +0 -4
-    if (max_cpus > 255) {
-        fprintf(stderr, "Unsupported number of maxcpus\n");
-        exit(1);
-    }

I believe Eduardo touched that code last for NUMA, so let's CC him.

Quoted 7 lines
Quoted 2 lines

I don't know whenever this is actually safe. Do we have any static arrays of size 255 somewhere, which will be overflowed without this check? :)

s390 has the ipi_states[] array, but not fixed to that size.

x86 APIC IDs I think have or had a limitation to 255 rather than 16-bit? Igor?

it's still fixed size array:
hw/intc/apic.c: static APICCommonState *local_apics[MAX_APICS + 1];
with: #define MAX_APICS 255

Quoted 3 lines

Alexey, did you actually check that, e.g., x86 machines don't break with 256 or 257 CPUs now?

patch shouldn't hurt x86 machines since
there is check later
vl.c:

    if (smp_cpus > machine->max_cpus) {
           fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
                "supported by machine `%s' (%d)\n", smp_cpus,  machine->name,
                machine->max_cpus);
        exit(1);
    }

and both piix4/q35 machines have machine->max_cpus initialized to 255 or lower(isa/xen).

Quoted 7 lines

Adding a qtest would be one way to prove that at least the QEMU code of all other architectures doesn't break with the ppc change.

Regards,
Andreas

#12 lore raw
Quoted 39 lines · Igor Mammedov
Quoted 19 lines · On Mon, 02 Dec 2013 23:09:55 +0100 Andreas Färber <[email protected]> wrote:

Am 02.12.2013 18:06, schrieb Michael Tokarev:

Quoted 6 lines
Quoted 5 lines · Alexey Kardashevskiy

Since modern POWER7/POWER8 chips can have more that 256 CPU threads (>2000 actually), remove this check from smp_parse.

The CPUs number is still checked against machine->max_cpus and this check should be enough not to break other archs.

"should be" is not exactly the highest level of confidence for a "trivial" patch... :/

Quoted 5 lines

[]

Quoted 4 lines
vl.c +0 -4
-    if (max_cpus > 255) {
-        fprintf(stderr, "Unsupported number of maxcpus\n");
-        exit(1);
-    }

I believe Eduardo touched that code last for NUMA, so let's CC him.

Quoted 7 lines
Quoted 2 lines

I don't know whenever this is actually safe. Do we have any static arrays of size 255 somewhere, which will be overflowed without this check? :)

s390 has the ipi_states[] array, but not fixed to that size.

x86 APIC IDs I think have or had a limitation to 255 rather than 16-bit? Igor?

it's still fixed size array:
hw/intc/apic.c: static APICCommonState *local_apics[MAX_APICS + 1];
with: #define MAX_APICS 255

Quoted 3 lines

Alexey, did you actually check that, e.g., x86 machines don't break with 256 or 257 CPUs now?

patch shouldn't hurt x86 machines since
there is check later
vl.c:

Quoted 8 lines
    if (smp_cpus > machine->max_cpus) {
           fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
                "supported by machine `%s' (%d)\n", smp_cpus,  machine->name,
                machine->max_cpus);
        exit(1);
    }

and both piix4/q35 machines have machine->max_cpus initialized to 255 or lower(isa/xen).

This ensures smp_cpus <= machine->max_cpus, but doesn't ensure max_cpus <= machine->max_cpus. We need to check max_cpus against machine->max_cpus, too, then we can eliminate the hardcoded max_cpus > 255 check.

Quoted 9 lines
Quoted 8 lines

Adding a qtest would be one way to prove that at least the QEMU code of all other architectures doesn't break with the ppc change.

Regards,
Andreas

Signature · 1 line
Eduardo