Skip to content

Commit be81ba6

Browse files
philmdmstsirkin
authored andcommitted
hw/mem/pc-dimm: Restrict NUMA-specific code to NUMA machines
When trying to use the pc-dimm device on a non-NUMA machine, we get: $ qemu-system-arm -M none -cpu max -S \ -object memory-backend-file,id=mem1,size=1M,mem-path=/tmp/1m \ -device pc-dimm,id=dimm1,memdev=mem1 Segmentation fault (core dumped) (gdb) bt #0 pc_dimm_realize (dev=0x555556da3e90, errp=0x7fffffffcd10) at hw/mem/pc-dimm.c:184 #1 0x0000555555fe1f8f in device_set_realized (obj=0x555556da3e90, value=true, errp=0x7fffffffce18) at hw/core/qdev.c:531 #2 0x0000555555feb4a9 in property_set_bool (obj=0x555556da3e90, v=0x555556e54420, name=0x5555563c3c41 "realized", opaque=0x555556a704f0, errp=0x7fffffffce18) at qom/object.c:2257 To avoid that crash, restrict the pc-dimm NUMA check to machines supporting NUMA, and do not allow the use of 'node' property on non-NUMA machines. Suggested-by: Igor Mammedov <[email protected]> Signed-off-by: Philippe Mathieu-Daudé <[email protected]> Message-Id: <[email protected]> Reviewed-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 14c81b2 commit be81ba6

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

hw/mem/pc-dimm.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,21 @@ static void pc_dimm_realize(DeviceState *dev, Error **errp)
181181
PCDIMMDevice *dimm = PC_DIMM(dev);
182182
PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
183183
MachineState *ms = MACHINE(qdev_get_machine());
184-
int nb_numa_nodes = ms->numa_state->num_nodes;
184+
185+
if (ms->numa_state) {
186+
int nb_numa_nodes = ms->numa_state->num_nodes;
187+
188+
if (((nb_numa_nodes > 0) && (dimm->node >= nb_numa_nodes)) ||
189+
(!nb_numa_nodes && dimm->node)) {
190+
error_setg(errp, "'DIMM property " PC_DIMM_NODE_PROP " has value %"
191+
PRIu32 "' which exceeds the number of numa nodes: %d",
192+
dimm->node, nb_numa_nodes ? nb_numa_nodes : 1);
193+
return;
194+
}
195+
} else if (dimm->node > 0) {
196+
error_setg(errp, "machine doesn't support NUMA");
197+
return;
198+
}
185199

186200
if (!dimm->hostmem) {
187201
error_setg(errp, "'" PC_DIMM_MEMDEV_PROP "' property is not set");
@@ -191,13 +205,6 @@ static void pc_dimm_realize(DeviceState *dev, Error **errp)
191205
object_get_canonical_path_component(OBJECT(dimm->hostmem)));
192206
return;
193207
}
194-
if (((nb_numa_nodes > 0) && (dimm->node >= nb_numa_nodes)) ||
195-
(!nb_numa_nodes && dimm->node)) {
196-
error_setg(errp, "'DIMM property " PC_DIMM_NODE_PROP " has value %"
197-
PRIu32 "' which exceeds the number of numa nodes: %d",
198-
dimm->node, nb_numa_nodes ? nb_numa_nodes : 1);
199-
return;
200-
}
201208

202209
if (ddc->realize) {
203210
ddc->realize(dimm, errp);

0 commit comments

Comments
 (0)