hw/i386/microvm: Fix crash that occurs when introspecting the microvm machine
A message that is not in the archive (sent off-list or not yet received): [email protected]
Sergio Lopez Pascual
Reviewed-byQuoted 35 lines · Thomas Huth
QEMU currently crashes when you try to inspect the properties of the microvm machine:
$ echo '{ "execute": "qmp_capabilities" } { "execute": "qom-list-properties","arguments": { "typename": "microvm-machine"}}' | \ ./qemu-system-x86_64 -qmp stdio {"QMP": {"version": {"qemu": {"micro": 50, "minor": 2, "major": 9}, "package": "v9.2.0-1072-g60af367187-dirty"}, "capabilities": ["oob"]}} {"return": {}} qemu-system-x86_64: ../qemu/hw/i386/acpi-microvm.c:250: void acpi_setup_microvm(MicrovmMachineState *): Assertion `x86ms->fw_cfg' failed. Aborted (core dumped)This happens because the microvm machine adds a
machine_done(and apowerdown_req) notifier in theirinstance_initfunction - however, theinstance_initof machines are not only called for machines that are realized, but also for machines that are introspected, so in this case the listener is added for a microvm machine that is never realized. And since there is already a running machine, the listener function is triggered immediately, causing a crash since it was not for the right machine it was meant for.Such listener functions must never be installed from an
instance_initfunction. Let's do it frommicrovm_machine_state_init()instead - this function is theMachineClass->init()function instead, i.e. guaranteed to be only called once in the lifetime of a QEMU process.Since the
microvm_machine_done()andmicrovm_powerdown_req()were defined quite late in themicrovm.cfile, we have to move them now also earlier, so that we can get their function pointers frommicrovm_machine_state_init()without having to introduce a separate prototype for those functions earlier.
Quoted 4 lines
Signed-off-by Thomas Huth <[email protected]>--- hw/i386/microvm.c | 66 +++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 33 deletions(-)
Thanks, Thomas!
Sergio.