qdev: Protect device-list-properties against broken devices

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 commit f4eb32b "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 commit ef52358 "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>
27 files changed
tree: c7eee2c3609eaf7743ed256a70c18c9d0916ca2a
  1. audio/
  2. backends/
  3. block/
  4. bsd-user/
  5. crypto/
  6. default-configs/
  7. disas/
  8. docs/
  9. fpu/
  10. fsdev/
  11. gdb-xml/
  12. hw/
  13. include/
  14. libdecnumber/
  15. linux-headers/
  16. linux-user/
  17. migration/
  18. net/
  19. pc-bios/
  20. po/
  21. qapi/
  22. qga/
  23. qobject/
  24. qom/
  25. roms/
  26. scripts/
  27. slirp/
  28. stubs/
  29. target-alpha/
  30. target-arm/
  31. target-cris/
  32. target-i386/
  33. target-lm32/
  34. target-m68k/
  35. target-microblaze/
  36. target-mips/
  37. target-moxie/
  38. target-openrisc/
  39. target-ppc/
  40. target-s390x/
  41. target-sh4/
  42. target-sparc/
  43. target-tilegx/
  44. target-tricore/
  45. target-unicore32/
  46. target-xtensa/
  47. tcg/
  48. tests/
  49. trace/
  50. ui/
  51. util/
  52. .dir-locals.el
  53. .exrc
  54. .gitignore
  55. .gitmodules
  56. .mailmap
  57. .travis.yml
  58. accel.c
  59. aio-posix.c
  60. aio-win32.c
  61. arch_init.c
  62. async.c
  63. balloon.c
  64. block.c
  65. blockdev-nbd.c
  66. blockdev.c
  67. blockjob.c
  68. bootdevice.c
  69. bt-host.c
  70. bt-vhci.c
  71. Changelog
  72. CODING_STYLE
  73. configure
  74. COPYING
  75. COPYING.LIB
  76. coroutine-gthread.c
  77. coroutine-sigaltstack.c
  78. coroutine-ucontext.c
  79. coroutine-win32.c
  80. cpu-exec-common.c
  81. cpu-exec.c
  82. cpus.c
  83. cputlb.c
  84. device-hotplug.c
  85. device_tree.c
  86. disas.c
  87. dma-helpers.c
  88. dump.c
  89. exec.c
  90. gdbstub.c
  91. HACKING
  92. hmp-commands-info.hx
  93. hmp-commands.hx
  94. hmp.c
  95. hmp.h
  96. iohandler.c
  97. ioport.c
  98. iothread.c
  99. kvm-all.c
  100. kvm-stub.c
  101. LICENSE
  102. main-loop.c
  103. MAINTAINERS
  104. Makefile
  105. Makefile.objs
  106. Makefile.target
  107. memory.c
  108. memory_mapping.c
  109. module-common.c
  110. monitor.c
  111. nbd.c
  112. numa.c
  113. os-posix.c
  114. os-win32.c
  115. page_cache.c
  116. qapi-schema.json
  117. qdev-monitor.c
  118. qdict-test-data.txt
  119. qemu-bridge-helper.c
  120. qemu-char.c
  121. qemu-coroutine-io.c
  122. qemu-coroutine-lock.c
  123. qemu-coroutine-sleep.c
  124. qemu-coroutine.c
  125. qemu-doc.texi
  126. qemu-ga.texi
  127. qemu-img-cmds.hx
  128. qemu-img.c
  129. qemu-img.texi
  130. qemu-io-cmds.c
  131. qemu-io.c
  132. qemu-log.c
  133. qemu-nbd.c
  134. qemu-nbd.texi
  135. qemu-options-wrapper.h
  136. qemu-options.h
  137. qemu-options.hx
  138. qemu-seccomp.c
  139. qemu-tech.texi
  140. qemu-timer.c
  141. qemu.nsi
  142. qemu.sasl
  143. qjson.c
  144. qmp-commands.hx
  145. qmp.c
  146. qtest.c
  147. README
  148. rules.mak
  149. softmmu_template.h
  150. spice-qemu-char.c
  151. tcg-runtime.c
  152. tci.c
  153. thread-pool.c
  154. thunk.c
  155. tpm.c
  156. trace-events
  157. translate-all.c
  158. translate-all.h
  159. translate-common.c
  160. user-exec.c
  161. VERSION
  162. version.rc
  163. vl.c
  164. xen-common-stub.c
  165. xen-common.c
  166. xen-hvm-stub.c
  167. xen-hvm.c
  168. xen-mapcache.c