Skip to contentSkip to conversation

Fix QEMU crash caused when NUMA nodes exceed available CPUs

PATCH Superseded Yin Wang 2 participants 2 messages May 9, 2023

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Yin Wang

author
#0 lore raw

PATCH 1/1 Fix QEMU crash caused when NUMA nodes exceed available CPUs

command "qemu-system-riscv64 -machine virt
-m 2G -smp 1 -numa node,mem=1G -numa node,mem=1G" would trigger this problem.
This commit fixes the issue by adding parameter checks.

---
 hw/core/numa.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/core/numa.c +7 -0
index d8d36b16d8..ff249369be 100644
@@ -168,6 +168,13 @@ static void parse_numa_node(MachineState *ms, NumaNodeOptions *node,
     numa_info[nodenr].present = true;
     max_numa_nodeid = MAX(max_numa_nodeid, nodenr + 1);
     ms->numa_state->num_nodes++;
+    if (ms->smp.max_cpus < ms->numa_state->num_nodes) {
+        error_setg(errp,
+                   "Number of NUMA nodes:(%d)"
+                   " is larger than number of CPUs:(%d)",
+                   ms->numa_state->num_nodes, ms->smp.max_cpus);
+        return;
+    }
 }
 
 static
Signature · 1 line
2.34.1
#1 lore raw
Quoted 4 lines · On Tue, 9 May 2023 14:44:52 +0800 Yin Wang <[email protected]> wrote:

command "qemu-system-riscv64 -machine virt
-m 2G -smp 1 -numa node,mem=1G -numa node,mem=1G" would trigger this problem.
This commit fixes the issue by adding parameter checks.

It seems wrong to apply this to all targets (that potentially excludes CPU-less nodes in some cases).

PS:
Crash backtrace should be mentioned in commit message.

Quoted 24 lines
---
 hw/core/numa.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/core/numa.c +7 -0
index d8d36b16d8..ff249369be 100644
@@ -168,6 +168,13 @@ static void parse_numa_node(MachineState *ms, NumaNodeOptions *node,
     numa_info[nodenr].present = true;
     max_numa_nodeid = MAX(max_numa_nodeid, nodenr + 1);
     ms->numa_state->num_nodes++;
+    if (ms->smp.max_cpus < ms->numa_state->num_nodes) {
+        error_setg(errp,
+                   "Number of NUMA nodes:(%d)"
+                   " is larger than number of CPUs:(%d)",
+                   ms->numa_state->num_nodes, ms->smp.max_cpus);
+        return;
+    }
 }
 
 static