Skip to contentSkip to conversation

Add another sanity check to smp_parse() function

PATCH Applied Thomas Huth 5 participants 9 messages Jul 22, 2015 – Aug 26, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add another sanity check to smp_parse() function

The code in smp_parse already checks the topology information for sockets * cores * threads < cpus and bails out with an error in that case. However, it is still possible to supply a bad configuration the other way round, e.g. with:

qemu-system-xxx -smp 4,sockets=1,cores=4,threads=2

QEMU then still starts the guest, with topology configuration that is rather incomprehensible and likely not what the user wanted. So let's add another check to refuse such wrong configurations.

---
 vl.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
vl.c +7 -1
index 5856396..c8d24b1 100644
@@ -1224,7 +1224,13 @@ static void smp_parse(QemuOpts *opts)
             exit(1);
         }
 
-        max_cpus = qemu_opt_get_number(opts, "maxcpus", 0);
+        max_cpus = qemu_opt_get_number(opts, "maxcpus", cpus);
+        if (sockets * cores * threads > max_cpus) {
+            fprintf(stderr, "cpu topology: error: "
+                    "sockets (%u) * cores (%u) * threads (%u) > maxcpus (%u)\n",
+                    sockets, cores, threads, max_cpus);
+            exit(1);
+        }
 
         smp_cpus = cpus;
         smp_cores = cores > 0 ? cores : 1;
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 21 lines · On Wed, 22 Jul 2015 15:59:50 +0200 Thomas Huth <[email protected]> wrote:

The code in smp_parse already checks the topology information for sockets * cores * threads < cpus and bails out with an error in that case. However, it is still possible to supply a bad configuration the other way round, e.g. with:

qemu-system-xxx -smp 4,sockets=1,cores=4,threads=2

QEMU then still starts the guest, with topology configuration that is rather incomprehensible and likely not what the user wanted. So let's add another check to refuse such wrong configurations.

---
 vl.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
vl.c +0 -0
index 5856396..c8d24b1 100644

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

Quoted 9 lines
vl.c +4 -1
@@ -1224,7 +1224,13 @@ static void smp_parse(QemuOpts *opts)
             exit(1);
         }
 
-        max_cpus = qemu_opt_get_number(opts, "maxcpus", 0);
+        max_cpus = qemu_opt_get_number(opts, "maxcpus", cpus);
+        if (sockets * cores * threads > max_cpus) {
+            fprintf(stderr, "cpu topology: error: "
+                    "sockets (%u) * cores (%u) * threads (%u) >
 maxcpus (%u)\n",

just a nit, maybe s/maxcpus/[max]cpus/

Quoted 6 lines
vl.c +3 -0
+                    sockets, cores, threads, max_cpus);
+            exit(1);
+        }
 
         smp_cpus = cpus;
         smp_cores = cores > 0 ? cores : 1;
#2 lore raw
Quoted 27 lines · Igor Mammedov
Quoted 24 lines · On Wed, 22 Jul 2015 15:59:50 +0200 Thomas Huth <[email protected]> wrote:

The code in smp_parse already checks the topology information for sockets * cores * threads < cpus and bails out with an error in that case. However, it is still possible to supply a bad configuration the other way round, e.g. with:

qemu-system-xxx -smp 4,sockets=1,cores=4,threads=2

QEMU then still starts the guest, with topology configuration that is rather incomprehensible and likely not what the user wanted. So let's add another check to refuse such wrong configurations.

---
 vl.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
vl.c +0 -0
index 5856396..c8d24b1 100644
@@ -1224,7 +1224,13 @@ static void smp_parse(QemuOpts *opts)
             exit(1);
         }
 
Quoted 7 lines

vl.c static void smp_parse(QemuOpts *opts)

Quoted 6 lines
vl.c +4 -1
-        max_cpus = qemu_opt_get_number(opts, "maxcpus", 0);
+        max_cpus = qemu_opt_get_number(opts, "maxcpus", cpus);
+        if (sockets * cores * threads > max_cpus) {
+            fprintf(stderr, "cpu topology: error: "
+                    "sockets (%u) * cores (%u) * threads (%u) >
 maxcpus (%u)\n",

just a nit, maybe s/maxcpus/[max]cpus/

I think it should be pretty obvious for the user that maxcpus = cpus when the "maxcpus" option has not been specified but only the "cpus" option. So I'd prefer to keep it the way without the square brackets, it's IMHO easier to read.

Thomas

#3 lore raw
In reply to Thomas Huth
Quoted 25 lines · Thomas Huth

The code in smp_parse already checks the topology information for sockets * cores * threads < cpus and bails out with an error in that case. However, it is still possible to supply a bad configuration the other way round, e.g. with:

qemu-system-xxx -smp 4,sockets=1,cores=4,threads=2

QEMU then still starts the guest, with topology configuration that is rather incomprehensible and likely not what the user wanted. So let's add another check to refuse such wrong configurations.

---
 vl.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
vl.c +0 -1
index 5856396..c8d24b1 100644
@@ -1224,7 +1224,13 @@ static void smp_parse(QemuOpts *opts)
             exit(1);
         }
 
-        max_cpus = qemu_opt_get_number(opts, "maxcpus", 0);

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

Quoted 10 lines
vl.c +7 -0
+        max_cpus = qemu_opt_get_number(opts, "maxcpus", cpus);
+        if (sockets * cores * threads > max_cpus) {
+            fprintf(stderr, "cpu topology: error: "
+                    "sockets (%u) * cores (%u) * threads (%u) > maxcpus (%u)\n",
+                    sockets, cores, threads, max_cpus);
+            exit(1);
+        }
 
         smp_cpus = cpus;
         smp_cores = cores > 0 ? cores : 1;

*ping*

Thomas

Reviewed-by on v1 1/1
#4 lore raw
In reply to Thomas Huth
Quoted 22 lines · Thomas Huth

The code in smp_parse already checks the topology information for sockets * cores * threads < cpus and bails out with an error in that case. However, it is still possible to supply a bad configuration the other way round, e.g. with:

qemu-system-xxx -smp 4,sockets=1,cores=4,threads=2

QEMU then still starts the guest, with topology configuration that is rather incomprehensible and likely not what the user wanted. So let's add another check to refuse such wrong configurations.

---
 vl.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
vl.c +0 -0
index 5856396..c8d24b1 100644
@@ -1224,7 +1224,13 @@ static void smp_parse(QemuOpts *opts)
             exit(1);

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

Quoted 10 lines
vl.c +7 -1
         }
 
-        max_cpus = qemu_opt_get_number(opts, "maxcpus", 0);
+        max_cpus = qemu_opt_get_number(opts, "maxcpus", cpus);
+        if (sockets * cores * threads > max_cpus) {
+            fprintf(stderr, "cpu topology: error: "
+                    "sockets (%u) * cores (%u) * threads (%u) > maxcpus (%u)\n",
+                    sockets, cores, threads, max_cpus);
+            exit(1);
+        }

I am always afraid of breaking existing setups when we do that, because there may be existing VMs running with these weird configurations, and people won't be able to live-migrate them to a newer QEMU.

But I think we really have to start refusing to run obviously broken configurations one day, or we will never fix this mess, so:

I want to apply this through the x86 tree, but I would like to get some Acked-by from other maintainers first.

Signature · 1 line
Eduardo
#5 lore raw
Quoted 38 lines · Eduardo Habkost
Quoted 22 lines · Thomas Huth

The code in smp_parse already checks the topology information for sockets * cores * threads < cpus and bails out with an error in that case. However, it is still possible to supply a bad configuration the other way round, e.g. with:

qemu-system-xxx -smp 4,sockets=1,cores=4,threads=2

QEMU then still starts the guest, with topology configuration that is rather incomprehensible and likely not what the user wanted. So let's add another check to refuse such wrong configurations.

---
 vl.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
vl.c +0 -0
index 5856396..c8d24b1 100644
@@ -1224,7 +1224,13 @@ static void smp_parse(QemuOpts *opts)
             exit(1);

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

Quoted 10 lines
vl.c +7 -1
         }
 
-        max_cpus = qemu_opt_get_number(opts, "maxcpus", 0);
+        max_cpus = qemu_opt_get_number(opts, "maxcpus", cpus);
+        if (sockets * cores * threads > max_cpus) {
+            fprintf(stderr, "cpu topology: error: "
+                    "sockets (%u) * cores (%u) * threads (%u) > maxcpus (%u)\n",
+                    sockets, cores, threads, max_cpus);
+            exit(1);
+        }

I am always afraid of breaking existing setups when we do that, because there may be existing VMs running with these weird configurations, and people won't be able to live-migrate them to a newer QEMU.

Quoted 7 lines

But I think we really have to start refusing to run obviously broken configurations one day, or we will never fix this mess, so:

I want to apply this through the x86 tree, but I would like to get some Acked-by from other maintainers first.

Ok, thanks!

So *ping* to the other CPU core maintainers here ... could I get some more ACKs, please?

Thomas

Acked-by
#6 lore raw
Quoted 44 lines · On Tue, 25 Aug 2015 15:25:00 +0200 Thomas Huth <[email protected]> wrote:
Quoted 43 lines · Eduardo Habkost
Quoted 22 lines · Thomas Huth

The code in smp_parse already checks the topology information for sockets * cores * threads < cpus and bails out with an error in that case. However, it is still possible to supply a bad configuration the other way round, e.g. with:

qemu-system-xxx -smp 4,sockets=1,cores=4,threads=2

QEMU then still starts the guest, with topology configuration that is rather incomprehensible and likely not what the user wanted. So let's add another check to refuse such wrong configurations.

---
 vl.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
vl.c +0 -0
index 5856396..c8d24b1 100644
@@ -1224,7 +1224,13 @@ static void smp_parse(QemuOpts *opts)
             exit(1);

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

Quoted 10 lines
vl.c +7 -1
         }
 
-        max_cpus = qemu_opt_get_number(opts, "maxcpus", 0);
+        max_cpus = qemu_opt_get_number(opts, "maxcpus", cpus);
+        if (sockets * cores * threads > max_cpus) {
+            fprintf(stderr, "cpu topology: error: "
+                    "sockets (%u) * cores (%u) * threads (%u) > maxcpus (%u)\n",
+                    sockets, cores, threads, max_cpus);
+            exit(1);
+        }

I am always afraid of breaking existing setups when we do that, because there may be existing VMs running with these weird configurations, and people won't be able to live-migrate them to a newer QEMU.

But I think we really have to start refusing to run obviously broken configurations one day, or we will never fix this mess, so:

Quoted 7 lines
Quoted 2 lines

I want to apply this through the x86 tree, but I would like to get some Acked-by from other maintainers first.

Ok, thanks!

So *ping* to the other CPU core maintainers here ... could I get some more ACKs, please?

Looks reasonable.

#7 lore raw
In reply to Thomas Huth

Am 25.08.2015 um 15:25 schrieb Thomas Huth:

Quoted 43 lines · Eduardo Habkost
Quoted 42 lines · Thomas Huth
Quoted 22 lines

The code in smp_parse already checks the topology information for sockets * cores * threads < cpus and bails out with an error in that case. However, it is still possible to supply a bad configuration the other way round, e.g. with:

qemu-system-xxx -smp 4,sockets=1,cores=4,threads=2

QEMU then still starts the guest, with topology configuration that is rather incomprehensible and likely not what the user wanted. So let's add another check to refuse such wrong configurations.

---
  vl.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
vl.c +0 -0
index 5856396..c8d24b1 100644
@@ -1224,7 +1224,13 @@ static void smp_parse(QemuOpts *opts)
              exit(1);

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

Quoted 10 lines
vl.c +7 -1
          }
 
-        max_cpus = qemu_opt_get_number(opts, "maxcpus", 0);
+        max_cpus = qemu_opt_get_number(opts, "maxcpus", cpus);
+        if (sockets * cores * threads > max_cpus) {
+            fprintf(stderr, "cpu topology: error: "
+                    "sockets (%u) * cores (%u) * threads (%u) > maxcpus (%u)\n",
+                    sockets, cores, threads, max_cpus);
+            exit(1);
+        }

I am always afraid of breaking existing setups when we do that, because there may be existing VMs running with these weird configurations, and people won't be able to live-migrate them to a newer QEMU.

But I think we really have to start refusing to run obviously broken configurations one day, or we will never fix this mess, so:

Quoted 10 lines
Quoted 2 lines

I want to apply this through the x86 tree, but I would like to get some Acked-by from other maintainers first.

Ok, thanks!

So *ping* to the other CPU core maintainers here ... could I get some more ACKs, please?

Thomas

#8 lore raw
In reply to Thomas Huth
Quoted 5 lines · Thomas Huth

The code in smp_parse already checks the topology information for sockets * cores * threads < cpus and bails out with an error in that case. However, it is still possible to supply a bad configuration the other way round, e.g. with:

Quoted 7 lines

qemu-system-xxx -smp 4,sockets=1,cores=4,threads=2

QEMU then still starts the guest, with topology configuration that is rather incomprehensible and likely not what the user wanted. So let's add another check to refuse such wrong configurations.

Applied to the x86 tree. Thanks!

Signature · 1 line
Eduardo