Skip to contentSkip to conversation

vl.c deprecate incorrect CPUs topology

PATCH Superseded Igor Mammedov 3 participants 3 messages Aug 27, 2018 – Aug 28, 2018

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 vl.c deprecate incorrect CPUs topology

-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] == [maxcpus]

---
v2:
- spelling&&co fixes (Andrew Jones <[email protected]>)

---
 qemu-deprecated.texi | 11 +++++++++++
 vl.c                 |  6 ++++++
 2 files changed, 17 insertions(+)
qemu-deprecated.texi +11 -0
index 87212b6..b649b2e 100644
@@ -159,6 +159,17 @@ 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.
 
+@subsection -smp X,[socket=a,core=b,thread=c],maxcpus=Y (since 3.1)
+
+CPU topology properties should describe whole machine topology including
+possible CPUs. but historically it was possible to start QEMU with
+an incorrect topology where
+  sockets * cores * threads >= X && X < maxcpus
+which could lead to incorrect topology enumeration by the guest.
+Support for invalid topology will be removed, the user must ensure
+topologies described with -smp includes all possible cpus, i.e.:
+  sockets * cores * threads == maxcpus
+
 @section QEMU Machine Protocol (QMP) commands
 
 @subsection block-dirty-bitmap-add "autoload" parameter (since 2.12.0)
vl.c +6 -0
index 5ba06ad..238f856 100644
@@ -1238,6 +1238,12 @@ static void smp_parse(QemuOpts *opts)
             exit(1);
         }
 
+        if (sockets * cores * threads != max_cpus) {
+            warn_report("Invalid CPU topology deprecated: "
+                        "sockets (%u) * cores (%u) * threads (%u) "
+                        "!= maxcpus (%u)",
+                        sockets, cores, threads, max_cpus);
+        }
         if (sockets * cores * threads > max_cpus) {
             error_report("cpu topology: "
                          "sockets (%u) * cores (%u) * threads (%u) > "
Signature · 1 line
2.7.4
#1 lore raw
Quoted 25 lines · Igor Mammedov

-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] == [maxcpus]

---
v2:
- spelling&&co fixes (Andrew Jones <[email protected]>)

---
 qemu-deprecated.texi | 11 +++++++++++
 vl.c                 |  6 ++++++
 2 files changed, 17 insertions(+)
qemu-deprecated.texi +0 -0
index 87212b6..b649b2e 100644

qemu-deprecated.texi The 'file' driver for drives is no longer appropriate for character or host · line 165

Quoted 7 lines
qemu-deprecated.texi +4 -0
@@ -159,6 +159,17 @@ 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.
 
+@subsection -smp X,[socket=a,core=b,thread=c],maxcpus=Y (since 3.1)
+
+CPU topology properties should describe whole machine topology including
+possible CPUs. but historically it was possible to start QEMU with

^ missed this correction should be a ','

qemu-deprecated.texi The 'file' driver for drives is no longer appropriate for character or host · line 168

Quoted 3 lines
qemu-deprecated.texi +3 -0
+an incorrect topology where
+  sockets * cores * threads >= X && X < maxcpus
+which could lead to incorrect topology enumeration by the guest.

an incorrect

qemu-deprecated.texi The 'file' driver for drives is no longer appropriate for character or host · line 169

Quoted 1 line
qemu-deprecated.texi +1 -0
+Support for invalid topology will be removed, the user must ensure

invalid topologies

qemu-deprecated.texi The 'file' driver for drives is no longer appropriate for character or host · line 170

Quoted 1 line
qemu-deprecated.texi +1 -0
+topologies described with -smp includes all possible cpus, i.e.:

include

no ':' after 'i.e.'

Quoted 26 lines
qemu-deprecated.texi +2 -0
+  sockets * cores * threads == maxcpus
+
 @section QEMU Machine Protocol (QMP) commands
 
 @subsection block-dirty-bitmap-add "autoload" parameter (since 2.12.0)
vl.c +6 -0
index 5ba06ad..238f856 100644
@@ -1238,6 +1238,12 @@ static void smp_parse(QemuOpts *opts)
             exit(1);
         }
 
+        if (sockets * cores * threads != max_cpus) {
+            warn_report("Invalid CPU topology deprecated: "
+                        "sockets (%u) * cores (%u) * threads (%u) "
+                        "!= maxcpus (%u)",
+                        sockets, cores, threads, max_cpus);
+        }
         if (sockets * cores * threads > max_cpus) {
             error_report("cpu topology: "
                          "sockets (%u) * cores (%u) * threads (%u) > "
Signature · 1 line
2.7.4

Thanks,
drew

#2 lore raw
In reply to Igor Mammedov
Quoted 47 lines · Igor Mammedov

-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] == [maxcpus]

---
v2:
- spelling&&co fixes (Andrew Jones <[email protected]>)

---
 qemu-deprecated.texi | 11 +++++++++++
 vl.c                 |  6 ++++++
 2 files changed, 17 insertions(+)
qemu-deprecated.texi +11 -0
index 87212b6..b649b2e 100644
@@ -159,6 +159,17 @@ 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.
 
+@subsection -smp X,[socket=a,core=b,thread=c],maxcpus=Y (since 3.1)
+
+CPU topology properties should describe whole machine topology including
+possible CPUs. but historically it was possible to start QEMU with
+an incorrect topology where
+  sockets * cores * threads >= X && X < maxcpus
+which could lead to incorrect topology enumeration by the guest.
+Support for invalid topology will be removed, the user must ensure
+topologies described with -smp includes all possible cpus, i.e.:
+  sockets * cores * threads == maxcpus
+
 @section QEMU Machine Protocol (QMP) commands
 
 @subsection block-dirty-bitmap-add "autoload" parameter (since 2.12.0)
vl.c +0 -0
index 5ba06ad..238f856 100644

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

Quoted 9 lines
vl.c +6 -0
@@ -1238,6 +1238,12 @@ static void smp_parse(QemuOpts *opts)
             exit(1);
         }
 
+        if (sockets * cores * threads != max_cpus) {
+            warn_report("Invalid CPU topology deprecated: "
+                        "sockets (%u) * cores (%u) * threads (%u) "
+                        "!= maxcpus (%u)",
+                        sockets, cores, threads, max_cpus);
+        }

We don't need to print the warning if
sockets * cores * threads > max_cpus,
because it already triggers error_report()/exit() below. I suggest reordering the checks:

    if (sockets * cores * threads > max_cpus) {
        error_report(...);
        exit(1);
    }
    if (sockets * cores * threads != max_cpus) {
        warn_report(...)
    }
Quoted 6 lines
vl.c +0 -0
         if (sockets * cores * threads > max_cpus) {
             error_report("cpu topology: "
                          "sockets (%u) * cores (%u) * threads (%u) > "
Signature · 1 line
2.7.4
Signature · 1 line
Eduardo