[PATCH] Fix QEMU crash caused when NUMA nodes exceed available CPUs

Yin Wang posted 1 patch 11 months, 3 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20230509064452.759834-1-yin.wang@intel.com
Maintainers: Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Yanan Wang <wangyanan55@huawei.com>
hw/core/numa.c | 7 +++++++
1 file changed, 7 insertions(+)
[PATCH] Fix QEMU crash caused when NUMA nodes exceed available CPUs
Posted by Yin Wang 11 months, 3 weeks ago
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.

Signed-off-by: Yin Wang <yin.wang@intel.com>
---
 hw/core/numa.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/hw/core/numa.c b/hw/core/numa.c
index d8d36b16d8..ff249369be 100644
--- a/hw/core/numa.c
+++ b/hw/core/numa.c
@@ -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
-- 
2.34.1
Re: [PATCH] Fix QEMU crash caused when NUMA nodes exceed available CPUs
Posted by Igor Mammedov 11 months, 3 weeks ago
On Tue,  9 May 2023 14:44:52 +0800
Yin Wang <yin.wang@intel.com> 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.

> 
> Signed-off-by: Yin Wang <yin.wang@intel.com>
> ---
>  hw/core/numa.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/hw/core/numa.c b/hw/core/numa.c
> index d8d36b16d8..ff249369be 100644
> --- a/hw/core/numa.c
> +++ b/hw/core/numa.c
> @@ -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