Skip to content

Commit 807830e

Browse files
committed
hw/s390x: Fix crash that occurs when inspecting older versioned machines types
qemu-system-s390x currently crashes when trying to inspect older machines types, for example: $ echo '{ "execute": "qmp_capabilities" } { "execute": "qom-list-properties","arguments": { "typename": "s390-ccw-virtio-3.0-machine"}}' \ | ./qemu-system-s390x -qmp stdio -no-shutdown {"QMP": {"version": {"qemu": {"micro": 50, "minor": 2, "major": 9}, "package": "v9.2.0-1071-g81e97df3e7"}, "capabilities": ["oob"]}} {"return": {}} ** Bail out! ERROR:../target/s390x/cpu_models.c:832:s390_set_qemu_cpu_model: assertion failed: (QTAILQ_EMPTY_RCU(&cpus_queue)) Aborted (core dumped) The problem is that the versioned s390-ccw-virtio machine types use instance_init() to set global state that should be initialized before the CPUs get instantiated. But instance_init() is not called only for the machine that is finally used, it is also called for temporary instances of objects that are e.g. just created for introspection. That means that those instance_init() functions can also be called while a machine (and its CPUs) is already created, which triggers the assertion in cpu_models.c. So we must not use instance_init() for setting global state, but use the machine->init() function instead, which is really only called once when the machine comes to life. Fixes: 3b00f70 ("s390x/cpumodel: add zpci, aen and ais facilities") Message-ID: <20250120085059.239345-1-thuth@redhat.com> Reviewed-by: David Hildenbrand <david@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
1 parent 145f12e commit 807830e

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

hw/s390x/s390-virtio-ccw.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,6 @@ static void ccw_machine_class_init(ObjectClass *oc, void *data)
782782

783783
s390mc->hpage_1m_allowed = true;
784784
s390mc->max_threads = 1;
785-
mc->init = ccw_init;
786785
mc->reset = s390_machine_reset;
787786
mc->block_default_type = IF_VIRTIO;
788787
mc->no_cdrom = 1;
@@ -852,31 +851,31 @@ static const TypeInfo ccw_machine_info = {
852851
};
853852

854853
#define DEFINE_CCW_MACHINE_IMPL(latest, ...) \
854+
static void MACHINE_VER_SYM(mach_init, ccw, __VA_ARGS__)(MachineState *mach) \
855+
{ \
856+
current_mc = S390_CCW_MACHINE_CLASS(MACHINE_GET_CLASS(mach)); \
857+
MACHINE_VER_SYM(instance_options, ccw, __VA_ARGS__)(mach); \
858+
ccw_init(mach); \
859+
} \
855860
static void MACHINE_VER_SYM(class_init, ccw, __VA_ARGS__)( \
856861
ObjectClass *oc, \
857862
void *data) \
858863
{ \
859864
MachineClass *mc = MACHINE_CLASS(oc); \
860865
MACHINE_VER_SYM(class_options, ccw, __VA_ARGS__)(mc); \
861866
mc->desc = "Virtual s390x machine (version " MACHINE_VER_STR(__VA_ARGS__) ")"; \
867+
mc->init = MACHINE_VER_SYM(mach_init, ccw, __VA_ARGS__); \
862868
MACHINE_VER_DEPRECATION(__VA_ARGS__); \
863869
if (latest) { \
864870
mc->alias = "s390-ccw-virtio"; \
865871
mc->is_default = true; \
866872
} \
867873
} \
868-
static void MACHINE_VER_SYM(instance_init, ccw, __VA_ARGS__)(Object *obj) \
869-
{ \
870-
MachineState *machine = MACHINE(obj); \
871-
current_mc = S390_CCW_MACHINE_CLASS(MACHINE_GET_CLASS(machine)); \
872-
MACHINE_VER_SYM(instance_options, ccw, __VA_ARGS__)(machine); \
873-
} \
874874
static const TypeInfo MACHINE_VER_SYM(info, ccw, __VA_ARGS__) = \
875875
{ \
876876
.name = MACHINE_VER_TYPE_NAME("s390-ccw-virtio", __VA_ARGS__), \
877877
.parent = TYPE_S390_CCW_MACHINE, \
878878
.class_init = MACHINE_VER_SYM(class_init, ccw, __VA_ARGS__), \
879-
.instance_init = MACHINE_VER_SYM(instance_init, ccw, __VA_ARGS__), \
880879
}; \
881880
static void MACHINE_VER_SYM(register, ccw, __VA_ARGS__)(void) \
882881
{ \

0 commit comments

Comments
 (0)