Skip to contentSkip to conversation

Validate NUMA node IDs (reject duplicate/missing node IDs properly)

PATCH Applied Eduardo Habkost 4 participants 10 messages Jun 26, 2014 – Jun 29, 2014

lore
Share & tools
lore
#0 lore raw

cover Validate NUMA node IDs (reject duplicate/missing node IDs properly)

This is just a cleanup to make sure QEMU validate the NUMA node IDs on the command-line. After that, we may eventually change the code to accept sparse node IDs under some circumstances (but I am not sure that would be material for QEMU 2.1).

Cc Nishanth Aravamudan <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc Alexey Kardashevskiy <[email protected]>
Cc Hu Tao <[email protected]>
Cc Anton Blanchard <[email protected]>
Cc David Rientjes <[email protected]>
Cc Igor Mammedov <[email protected]>

Eduardo Habkost (3):
numa: Keep track of NUMA nodes present on the command-line
numa: Reject duplicate node IDs
numa: Reject configuration if not all node IDs are present

 include/sysemu/sysemu.h |  7 ++++++-
 numa.c                  | 24 +++++++++++++++++++++++-
 vl.c                    |  3 +++
 3 files changed, 32 insertions(+), 2 deletions(-)
Signature · 1 line
1.9.3
#1 lore raw

PATCH 1/3 numa: Keep track of NUMA nodes present on the command-line

Based on "enable sparse node numbering" patch from Nishanth Aravamudan, but without the code to actually support sparse node IDs. This just adds the code to keep track of present/non-present nodes on the command-line, without changing any behavior.

[Rename max_numa_node to max_numa_nodeid -Eduardo]
[Initialize max_numa_nodeid to 0 -Eduardo]
[Use MAX() macro when setting max_numa_nodeid -Eduardo]
---
 include/sysemu/sysemu.h | 7 ++++++-
 numa.c                  | 2 ++
 vl.c                    | 3 +++
 3 files changed, 11 insertions(+), 1 deletion(-)
include/sysemu/sysemu.h +6 -1
index 285c45b..d8539fd 100644
@@ -146,11 +146,16 @@ extern int mem_prealloc;
  */
 #define MAX_CPUMASK_BITS 255
 
-extern int nb_numa_nodes;
+extern int nb_numa_nodes;   /* Number of NUMA nodes */
+extern int max_numa_nodeid; /* Highest specified NUMA node ID, plus one.
+                             * For all nodes, nodeid < max_numa_nodeid
+                             */
+
 typedef struct node_info {
     uint64_t node_mem;
     DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS);
     struct HostMemoryBackend *node_memdev;
+    bool present;
 } NodeInfo;
 extern NodeInfo numa_info[MAX_NODES];
 void set_numa_nodes(void);
numa.c +2 -0
index e471afe..3de9116 100644
@@ -106,6 +106,8 @@ static void numa_node_parse(NumaNodeOptions *node, QemuOpts *opts, Error **errp)
         numa_info[nodenr].node_mem = object_property_get_int(o, "size", NULL);
         numa_info[nodenr].node_memdev = MEMORY_BACKEND(o);
     }
+    numa_info[nodenr].present = true;
+    max_numa_nodeid = MAX(max_numa_nodeid, nodenr + 1);
 }
 
 int numa_init_func(QemuOpts *opts, void *opaque)
vl.c +3 -0
index a1686ef..41ddcd2 100644
@@ -196,6 +196,7 @@ static QTAILQ_HEAD(, FWBootEntry) fw_boot_order =
     QTAILQ_HEAD_INITIALIZER(fw_boot_order);
 
 int nb_numa_nodes;
+int max_numa_nodeid;
 NodeInfo numa_info[MAX_NODES];
 
 uint8_t qemu_uuid[16];
@@ -2984,10 +2985,12 @@ int main(int argc, char **argv, char **envp)
 
     for (i = 0; i < MAX_NODES; i++) {
         numa_info[i].node_mem = 0;
+        numa_info[i].present = false;
         bitmap_zero(numa_info[i].node_cpu, MAX_CPUMASK_BITS);
     }
 
     nb_numa_nodes = 0;
+    max_numa_nodeid = 0;
     nb_nics = 0;
 
     bdrv_init_with_whitelist();
Signature · 1 line
1.9.3
Reviewed-by on v1 1/3
#2 lore raw

Re: [Qemu-devel] [PATCH 1/3] numa: Keep track of NUMA nodes present on the command-line

Quoted 10 lines · Eduardo Habkost

Based on "enable sparse node numbering" patch from Nishanth Aravamudan, but without the code to actually support sparse node IDs. This just adds the code to keep track of present/non-present nodes on the command-line, without changing any behavior.

[Rename max_numa_node to max_numa_nodeid -Eduardo]
[Initialize max_numa_nodeid to 0 -Eduardo]
[Use MAX() macro when setting max_numa_nodeid -Eduardo]
Quoted 68 lines
---
 include/sysemu/sysemu.h | 7 ++++++-
 numa.c                  | 2 ++
 vl.c                    | 3 +++
 3 files changed, 11 insertions(+), 1 deletion(-)
include/sysemu/sysemu.h +6 -1
index 285c45b..d8539fd 100644
@@ -146,11 +146,16 @@ extern int mem_prealloc;
  */
 #define MAX_CPUMASK_BITS 255
 
-extern int nb_numa_nodes;
+extern int nb_numa_nodes;   /* Number of NUMA nodes */
+extern int max_numa_nodeid; /* Highest specified NUMA node ID, plus one.
+                             * For all nodes, nodeid < max_numa_nodeid
+                             */
+
 typedef struct node_info {
     uint64_t node_mem;
     DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS);
     struct HostMemoryBackend *node_memdev;
+    bool present;
 } NodeInfo;
 extern NodeInfo numa_info[MAX_NODES];
 void set_numa_nodes(void);
numa.c +2 -0
index e471afe..3de9116 100644
@@ -106,6 +106,8 @@ static void numa_node_parse(NumaNodeOptions *node, QemuOpts *opts, Error **errp)
         numa_info[nodenr].node_mem = object_property_get_int(o, "size", NULL);
         numa_info[nodenr].node_memdev = MEMORY_BACKEND(o);
     }
+    numa_info[nodenr].present = true;
+    max_numa_nodeid = MAX(max_numa_nodeid, nodenr + 1);
 }
 
 int numa_init_func(QemuOpts *opts, void *opaque)
vl.c +3 -0
index a1686ef..41ddcd2 100644
@@ -196,6 +196,7 @@ static QTAILQ_HEAD(, FWBootEntry) fw_boot_order =
     QTAILQ_HEAD_INITIALIZER(fw_boot_order);
 
 int nb_numa_nodes;
+int max_numa_nodeid;
 NodeInfo numa_info[MAX_NODES];
 
 uint8_t qemu_uuid[16];
@@ -2984,10 +2985,12 @@ int main(int argc, char **argv, char **envp)
 
     for (i = 0; i < MAX_NODES; i++) {
         numa_info[i].node_mem = 0;
+        numa_info[i].present = false;
         bitmap_zero(numa_info[i].node_cpu, MAX_CPUMASK_BITS);
     }
 
     nb_numa_nodes = 0;
+    max_numa_nodeid = 0;
     nb_nics = 0;
 
     bdrv_init_with_whitelist();
Signature · 1 line
1.9.3
#3 lore raw

PATCH 2/3 numa: Reject duplicate node IDs

In reply to Eduardo Habkost

The same nodeid shouldn't appear multiple times in the command-line.

In addition to detecting command-line mistakes, this will fix a bug where nb_numa_nodes may become larger than MAX_NODES (and cause out-of-bounds access on the numa_info array).

---
 numa.c | 5 +++++
 1 file changed, 5 insertions(+)
numa.c +5 -0
index 3de9116..e93407a 100644
@@ -62,6 +62,11 @@ static void numa_node_parse(NumaNodeOptions *node, QemuOpts *opts, Error **errp)
         return;
     }
 
+    if (numa_info[nodenr].present) {
+        error_setg(errp, "Duplicate NUMA nodeid: %" PRIu16, nodenr);
+        return;
+    }
+
     for (cpus = node->cpus; cpus; cpus = cpus->next) {
         if (cpus->value > MAX_CPUMASK_BITS) {
             error_setg(errp, "CPU number %" PRIu16 " is bigger than %d",
Signature · 1 line
1.9.3
Reviewed-by on v1 2/3
#4 lore raw

Re: [Qemu-devel] [PATCH 2/3] numa: Reject duplicate node IDs

Quoted 7 lines · Eduardo Habkost

The same nodeid shouldn't appear multiple times in the command-line.

In addition to detecting command-line mistakes, this will fix a bug where nb_numa_nodes may become larger than MAX_NODES (and cause out-of-bounds access on the numa_info array).

This patch makes me remembering the same problem for cpus, like -numa ..cpus=1,.. -numa ..cpus=1,.., in the case one node has cpu, the other doesn't. Maybe we should eject it too.

Quoted 22 lines
---
 numa.c | 5 +++++
 1 file changed, 5 insertions(+)
numa.c +5 -0
index 3de9116..e93407a 100644
@@ -62,6 +62,11 @@ static void numa_node_parse(NumaNodeOptions *node, QemuOpts *opts, Error **errp)
         return;
     }
 
+    if (numa_info[nodenr].present) {
+        error_setg(errp, "Duplicate NUMA nodeid: %" PRIu16, nodenr);
+        return;
+    }
+
     for (cpus = node->cpus; cpus; cpus = cpus->next) {
         if (cpus->value > MAX_CPUMASK_BITS) {
             error_setg(errp, "CPU number %" PRIu16 " is bigger than %d",
Signature · 1 line
1.9.3
#5 lore raw

PATCH 3/3 numa: Reject configuration if not all node IDs are present

In reply to Eduardo Habkost

We don't support sparse NUMA node IDs yet, so this changes QEMU to reject configs where not all nodes are present.

---
 numa.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
numa.c +16 -1
index e93407a..96fe5dd 100644
@@ -160,9 +160,24 @@ error:
 
 void set_numa_nodes(void)
 {
+    int i;
+
+    assert(max_numa_nodeid <= MAX_NODES);
+
+    /* No support for sparse NUMA node IDs yet: */
+    for (i = max_numa_nodeid - 1; i >= 0; i--) {
+        /* Report large node IDs first, to make mistakes easier to spot */
+        if (!numa_info[i].present) {
+            error_report("numa: Node ID missing: %d", i);
+            exit(1);
+        }
+    }
+
+    /* This must be always true if all nodes are present: */
+    assert(nb_numa_nodes == max_numa_nodeid);
+
     if (nb_numa_nodes > 0) {
         uint64_t numa_total;
-        int i;
 
         if (nb_numa_nodes > MAX_NODES) {
             nb_numa_nodes = MAX_NODES;
Signature · 1 line
1.9.3
#6 lore raw

Re: [Qemu-devel] [PATCH 3/3] numa: Reject configuration if not all node IDs are present

Quoted 16 lines · Eduardo Habkost

We don't support sparse NUMA node IDs yet, so this changes QEMU to reject configs where not all nodes are present.

---
 numa.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
numa.c +0 -0
index e93407a..96fe5dd 100644
@@ -160,9 +160,24 @@ error:
 
 void set_numa_nodes(void)
 {

numa.c error: · line 172

Quoted 10 lines
numa.c +10 -0
+    int i;
+
+    assert(max_numa_nodeid <= MAX_NODES);
+
+    /* No support for sparse NUMA node IDs yet: */
+    for (i = max_numa_nodeid - 1; i >= 0; i--) {
+        /* Report large node IDs first, to make mistakes easier to spot */
+        if (!numa_info[i].present) {
+            error_report("numa: Node ID missing: %d", i);
+            exit(1);

This reports only one missing node id. Dont' we report all missing ids?

Quoted 14 lines
numa.c +6 -1
+        }
+    }
+
+    /* This must be always true if all nodes are present: */
+    assert(nb_numa_nodes == max_numa_nodeid);
+
     if (nb_numa_nodes > 0) {
         uint64_t numa_total;
-        int i;
 
         if (nb_numa_nodes > MAX_NODES) {
             nb_numa_nodes = MAX_NODES;
Signature · 1 line
1.9.3
#7 lore raw

Re: [Qemu-devel] [PATCH 3/3] numa: Reject configuration if not all node IDs are present

Quoted 15 lines · Hu Tao
Quoted 14 lines · Eduardo Habkost

We don't support sparse NUMA node IDs yet, so this changes QEMU to reject configs where not all nodes are present.

---
 numa.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
numa.c +0 -0
index e93407a..96fe5dd 100644
@@ -160,9 +160,24 @@ error:
 
Quoted 14 lines

numa.c error: · line 172

Quoted 12 lines
numa.c +10 -0
 void set_numa_nodes(void)
 {
+    int i;
+
+    assert(max_numa_nodeid <= MAX_NODES);
+
+    /* No support for sparse NUMA node IDs yet: */
+    for (i = max_numa_nodeid - 1; i >= 0; i--) {
+        /* Report large node IDs first, to make mistakes easier to spot */
+        if (!numa_info[i].present) {
+            error_report("numa: Node ID missing: %d", i);
+            exit(1);

This reports only one missing node id. Dont' we report all missing ids?

I considered that, but then a simple user mistake could make QEMU spit more than 100 lines of error messages.

I expect this error code to go away soon, anyway (as soon as we implement sparse node ID support).

Signature · 1 line
Eduardo
Reviewed-by on the v1 series
#8 lore raw
In reply to Eduardo Habkost
Quoted 1 line · Eduardo Habkost

This is just a cleanup to make sure QEMU validate the NUMA node IDs on the

Yay - this counts as a bug fix, so good for inclusion in 2.1.

Quoted 3 lines

command-line. After that, we may eventually change the code to accept sparse node IDs under some circumstances (but I am not sure that would be material for QEMU 2.1).

I _am_ sure; accepting sparse nodes is NOT 2.1 material (it's a new feature, and we're in soft freeze).

Series:

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#9 lore raw
In reply to Eduardo Habkost
Quoted 5 lines · Eduardo Habkost

This is just a cleanup to make sure QEMU validate the NUMA node IDs on the command-line. After that, we may eventually change the code to accept sparse node IDs under some circumstances (but I am not sure that would be material for QEMU 2.1).

Quoted 8 lines
Cc Nishanth Aravamudan <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc Alexey Kardashevskiy <[email protected]>
Cc Hu Tao <[email protected]>
Cc Anton Blanchard <[email protected]>
Cc David Rientjes <[email protected]>
Cc Igor Mammedov <[email protected]>

Applied, thanks!

Quoted 12 lines

Eduardo Habkost (3):
numa: Keep track of NUMA nodes present on the command-line
numa: Reject duplicate node IDs
numa: Reject configuration if not all node IDs are present

 include/sysemu/sysemu.h |  7 ++++++-
 numa.c                  | 24 +++++++++++++++++++++++-
 vl.c                    |  3 +++
 3 files changed, 32 insertions(+), 2 deletions(-)
Signature · 1 line
1.9.3