mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-24 03:59:52 +00:00
4c315c2766
Several devices don't survive object_unref(object_new(T)): they crash or hang during cleanup, or they leave dangling pointers behind. This breaks at least device-list-properties, because qmp_device_list_properties() needs to create a device to find its properties. Broken in commitf4eb32b
"qmp: show QOM properties in device-list-properties", v2.1. Example reproducer: $ qemu-system-aarch64 -nodefaults -display none -machine none -S -qmp stdio {"QMP": {"version": {"qemu": {"micro": 50, "minor": 4, "major": 2}, "package": ""}, "capabilities": []}} { "execute": "qmp_capabilities" } {"return": {}} { "execute": "device-list-properties", "arguments": { "typename": "pxa2xx-pcmcia" } } qemu-system-aarch64: /home/armbru/work/qemu/memory.c:1307: memory_region_finalize: Assertion `((&mr->subregions)->tqh_first == ((void *)0))' failed. Aborted (core dumped) [Exit 134 (SIGABRT)] Unfortunately, I can't fix the problems in these devices right now. Instead, add DeviceClass member cannot_destroy_with_object_finalize_yet to mark them: * Hang during cleanup (didn't debug, so I can't say why): "realview_pci", "versatile_pci". * Dangling pointer in cpus: most CPUs, plus "allwinner-a10", "digic", "fsl,imx25", "fsl,imx31", "xlnx,zynqmp", because they create such CPUs * Assert kvm_enabled(): "host-x86_64-cpu", host-i386-cpu", "host-powerpc64-cpu", "host-embedded-powerpc-cpu", "host-powerpc-cpu" (the powerpc ones can't currently reach the assertion, because the CPUs are only registered when KVM is enabled, but the assertion is arguably in the wrong place all the same) Make qmp_device_list_properties() fail cleanly when the device is so marked. This improves device-list-properties from "crashes, hangs or leaves dangling pointers behind" to "fails". Not a complete fix, just a better-than-nothing work-around. In the above reproducer, device-list-properties now fails with "Can't list properties of device 'pxa2xx-pcmcia'". This also protects -device FOO,help, which uses the same machinery since commitef52358
"qdev-monitor: include QOM properties in -device FOO, help output", v2.2. Example reproducer: $ qemu-system-aarch64 -machine none -device pxa2xx-pcmcia,help Before: qemu-system-aarch64: .../memory.c:1307: memory_region_finalize: Assertion `((&mr->subregions)->tqh_first == ((void *)0))' failed. After: Can't list properties of device 'pxa2xx-pcmcia' Cc: "Andreas Färber" <afaerber@suse.de> Cc: "Edgar E. Iglesias" <edgar.iglesias@gmail.com> Cc: Alexander Graf <agraf@suse.de> Cc: Anthony Green <green@moxielogic.com> Cc: Aurelien Jarno <aurelien@aurel32.net> Cc: Bastian Koppelmann <kbastian@mail.uni-paderborn.de> Cc: Blue Swirl <blauwirbel@gmail.com> Cc: Eduardo Habkost <ehabkost@redhat.com> Cc: Guan Xuetao <gxt@mprc.pku.edu.cn> Cc: Jia Liu <proljc@gmail.com> Cc: Leon Alrae <leon.alrae@imgtec.com> Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> Cc: Max Filippov <jcmvbkbc@gmail.com> Cc: Michael Walle <michael@walle.cc> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Peter Maydell <peter.maydell@linaro.org> Cc: Richard Henderson <rth@twiddle.net> Cc: qemu-ppc@nongnu.org Cc: qemu-stable@nongnu.org Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Message-Id: <1443689999-12182-10-git-send-email-armbru@redhat.com>
125 lines
2.8 KiB
C
125 lines
2.8 KiB
C
/*
|
|
* Device introspection test cases
|
|
*
|
|
* Copyright (c) 2015 Red Hat Inc.
|
|
*
|
|
* Authors:
|
|
* Markus Armbruster <armbru@redhat.com>,
|
|
*
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
* See the COPYING file in the top-level directory.
|
|
*/
|
|
|
|
/*
|
|
* Covers QMP device-list-properties and HMP device_add help. We
|
|
* currently don't check that their output makes sense, only that QEMU
|
|
* survives. Useful since we've had an astounding number of crash
|
|
* bugs around here.
|
|
*/
|
|
|
|
#include <glib.h>
|
|
#include <stdarg.h>
|
|
#include "qemu-common.h"
|
|
#include "qapi/qmp/qstring.h"
|
|
#include "libqtest.h"
|
|
|
|
const char common_args[] = "-nodefaults -machine none";
|
|
|
|
static QList *device_type_list(bool abstract)
|
|
{
|
|
QDict *resp;
|
|
QList *ret;
|
|
|
|
resp = qmp("{'execute': 'qom-list-types',"
|
|
" 'arguments': {'implements': 'device', 'abstract': %i}}",
|
|
abstract);
|
|
g_assert(qdict_haskey(resp, "return"));
|
|
ret = qdict_get_qlist(resp, "return");
|
|
QINCREF(ret);
|
|
QDECREF(resp);
|
|
return ret;
|
|
}
|
|
|
|
static void test_one_device(const char *type)
|
|
{
|
|
QDict *resp;
|
|
char *help, *qom_tree;
|
|
|
|
resp = qmp("{'execute': 'device-list-properties',"
|
|
" 'arguments': {'typename': %s}}",
|
|
type);
|
|
QDECREF(resp);
|
|
|
|
help = hmp("device_add \"%s,help\"", type);
|
|
g_free(help);
|
|
|
|
/*
|
|
* Some devices leave dangling pointers in QOM behind.
|
|
* "info qom-tree" has a good chance at crashing then
|
|
*/
|
|
qom_tree = hmp("info qom-tree");
|
|
g_free(qom_tree);
|
|
}
|
|
|
|
static void test_device_intro_list(void)
|
|
{
|
|
QList *types;
|
|
char *help;
|
|
|
|
qtest_start(common_args);
|
|
|
|
types = device_type_list(true);
|
|
QDECREF(types);
|
|
|
|
help = hmp("device_add help");
|
|
g_free(help);
|
|
|
|
qtest_end();
|
|
}
|
|
|
|
static void test_device_intro_none(void)
|
|
{
|
|
qtest_start(common_args);
|
|
test_one_device("nonexistent");
|
|
qtest_end();
|
|
}
|
|
|
|
static void test_device_intro_abstract(void)
|
|
{
|
|
qtest_start(common_args);
|
|
test_one_device("device");
|
|
qtest_end();
|
|
}
|
|
|
|
static void test_device_intro_concrete(void)
|
|
{
|
|
QList *types;
|
|
QListEntry *entry;
|
|
const char *type;
|
|
|
|
qtest_start(common_args);
|
|
types = device_type_list(false);
|
|
|
|
QLIST_FOREACH_ENTRY(types, entry) {
|
|
type = qdict_get_try_str(qobject_to_qdict(qlist_entry_obj(entry)),
|
|
"name");
|
|
g_assert(type);
|
|
test_one_device(type);
|
|
}
|
|
|
|
QDECREF(types);
|
|
qtest_end();
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
g_test_init(&argc, &argv, NULL);
|
|
|
|
qtest_add_func("device/introspect/list", test_device_intro_list);
|
|
qtest_add_func("device/introspect/none", test_device_intro_none);
|
|
qtest_add_func("device/introspect/abstract", test_device_intro_abstract);
|
|
qtest_add_func("device/introspect/concrete", test_device_intro_concrete);
|
|
|
|
return g_test_run();
|
|
}
|