All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH for-11.2 v3 00/15] qdev: Clarify and enforce the device realization lifecycle
@ 2026-07-21  8:16 Akihiko Odaki
  2026-07-21  8:16 ` [PATCH for-11.2 v3 01/15] qdev: Clarify instantiation and realization Akihiko Odaki
                   ` (16 more replies)
  0 siblings, 17 replies; 40+ messages in thread
From: Akihiko Odaki @ 2026-07-21  8:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: BALATON Zoltan, Paolo Bonzini, Daniel P. Berrangé,
	Eduardo Habkost, Maciej S. Szmigiero, Michael S. Tsirkin,
	David Hildenbrand, Igor Mammedov, FangSheng Huang,
	Alistair Francis, Edgar E. Iglesias, Peter Maydell, qemu-arm,
	Nicholas Piggin, Aditya Gupta, Glenn Miles, Harsh Prateek Bora,
	qemu-ppc, Alex Williamson, Cédric Le Goater, Zhao Liu,
	Hendrik Brueckner, Richard Henderson, Ilya Leoshkevich,
	Cornelia Huck, Eric Farman, Matthew Rosato, qemu-s390x,
	Luc Michel, Fam Zheng, Eric Blake, Markus Armbruster,
	Akihiko Odaki

qdev currently represents a device's realization state with a single
boolean. This cannot distinguish a device that has never been realized
from one whose realization has failed or that has been unrealized, nor
can it represent realization in progress. Consequently, the same device
can enter DeviceClass::realize() reentrantly or more than once.
Supporting that complicates device implementations, and the behavior is
untested and likely broken.

This series first clarifies the division of work between
TypeInfo.instance_init, pre-realize property setting, and
DeviceClass::realize, including the implications of device introspection
and property-dependent child creation.

The remaining direct reads of DeviceState::realized are then converted
to qdev_is_realized(). Keeping users behind this accessor allows the
underlying lifecycle representation to change without exposing it; the
accessor is also made const so callers with a const DeviceState can use
it.

Before changing that representation, the series fixes an existing
qdev invariant. qdev_realize() can attach an unparented device to a
bus before giving it a QOM parent. A failure between those operations
leaves a bus child that object_unparent() cannot remove, causing
bus_unparent() to loop indefinitely. qdev_realize() now establishes
the QOM parent before attaching the device to its bus and rolls the
parent back on failure.

Finally, DeviceState::realized and the QOM realized property are
replaced with four explicit phases: initialized, realizing, realized,
and retired.
Entering the realizing phase before invoking callbacks prevents
reentrant realization. A failure after realization starts, or the start
of unrealization, moves the device to the terminal retired phase, so a
device's realize method is invoked at most once.

Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
---
Changes in v3:
- Ensured devices are QOM-parented before attaching them to a bus,
  avoiding unparentable bus children when realization fails.
- Clarified property-dependent child creation.
- Removed documentation references to the QOM realized property.
- Replaced DeviceState::realized and the QOM realized property with
  device phases. The realizing phase prevents reentrant realization, and
  the terminal retired phase prevents another attempt after realization
  fails or unrealization begins.
- Link to v2: https://lore.kernel.org/qemu-devel/20260629-qdev-v2-1-8cd1d9be0d8d@rsg.ci.i.u-tokyo.ac.jp

Changes in v2:
- Clarified the ordering of #TypeInfo.instance_init, pre-realize
  property setting, and realization.
- Clarified that #TypeInfo.instance_init is for per-instance properties,
  not class properties.
- Link to v1: https://lore.kernel.org/qemu-devel/20250908-qdev-v1-1-df236f7ce5bd@rsg.ci.i.u-tokyo.ac.jp

---
Akihiko Odaki (15):
      qdev: Clarify instantiation and realization
      qdev: Make qdev_is_realized() take a const DeviceState *
      hw/hyperv/balloon: Use qdev_is_realized()
      hw/intc/apic: Use qdev_is_realized()
      hw/mem/memory-device: Use qdev_is_realized()
      hw/mem/pc-dimm: Use qdev_is_realized()
      hw/nvram: Use qdev_is_realized()
      hw/ppc/pnv_xscom: Use qdev_is_realized()
      hw/vfio: Use qdev_is_realized()
      hw/virtio/virtio-mem: Use qdev_is_realized()
      hw/virtio/virtio-qmp: Use qdev_is_realized()
      target/i386/cpu: Use qdev_is_realized()
      target/s390x: Use qdev_is_realized()
      hw/qdev: Parent device before setting parent bus
      hw/qdev: Prevent devices from being realized more than once

 qapi/common.json           |  19 ++++++
 include/hw/core/qdev.h     |  62 ++++++++++---------
 hw/core/qdev-clock.c       |   4 +-
 hw/core/qdev-properties.c  |   4 +-
 hw/core/qdev.c             | 147 ++++++++++++++++++++++++++++-----------------
 hw/hyperv/hv-balloon.c     |   2 +-
 hw/intc/apic_common.c      |   2 +-
 hw/mem/memory-device.c     |   4 +-
 hw/mem/pc-dimm.c           |   2 +-
 hw/nvram/xlnx-bbram.c      |   2 +-
 hw/nvram/xlnx-efuse.c      |   2 +-
 hw/ppc/pnv_xscom.c         |   2 +-
 hw/scsi/scsi-bus.c         |   4 +-
 hw/vfio/container-legacy.c |   4 +-
 hw/vfio/device.c           |   4 +-
 hw/vfio/iommufd.c          |   2 +-
 hw/virtio/virtio-mem.c     |   4 +-
 hw/virtio/virtio-qmp.c     |   4 +-
 qom/qom-qmp-cmds.c         |   2 +-
 system/qdev-monitor.c      |   5 +-
 target/i386/cpu.c          |   2 +-
 target/s390x/cpu_models.c  |   4 +-
 tests/unit/test-qdev.c     | 125 +++++++++++++++++++++++++++++++++++++-
 23 files changed, 301 insertions(+), 111 deletions(-)
---
base-commit: 499039798cdad7d86b787fec0eaf1da4151c0f05
change-id: 20250906-qdev-9e5cb7c06ffa

Best regards,
--  
Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>



^ permalink raw reply	[flat|nested] 40+ messages in thread

end of thread, other threads:[~2026-08-16 14:34 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-21  8:16 [PATCH for-11.2 v3 00/15] qdev: Clarify and enforce the device realization lifecycle Akihiko Odaki
2026-07-21  8:16 ` [PATCH for-11.2 v3 01/15] qdev: Clarify instantiation and realization Akihiko Odaki
2026-07-21 11:14   ` BALATON Zoltan
2026-07-21 11:38     ` Akihiko Odaki
2026-07-21  8:16 ` [PATCH for-11.2 v3 02/15] qdev: Make qdev_is_realized() take a const DeviceState * Akihiko Odaki
2026-07-21 19:49   ` Philippe Mathieu-Daudé
2026-07-21  8:16 ` [PATCH for-11.2 v3 03/15] hw/hyperv/balloon: Use qdev_is_realized() Akihiko Odaki
2026-07-21 19:56   ` Philippe Mathieu-Daudé
2026-07-21  8:16 ` [PATCH for-11.2 v3 04/15] hw/intc/apic: " Akihiko Odaki
2026-07-21 19:51   ` Philippe Mathieu-Daudé
2026-07-21  8:16 ` [PATCH for-11.2 v3 05/15] hw/mem/memory-device: " Akihiko Odaki
2026-07-21 19:56   ` Philippe Mathieu-Daudé
2026-07-21  8:16 ` [PATCH for-11.2 v3 06/15] hw/mem/pc-dimm: " Akihiko Odaki
2026-07-21 19:52   ` Philippe Mathieu-Daudé
2026-07-21  8:16 ` [PATCH for-11.2 v3 07/15] hw/nvram: " Akihiko Odaki
2026-07-21 19:53   ` Philippe Mathieu-Daudé
2026-07-21  8:16 ` [PATCH for-11.2 v3 08/15] hw/ppc/pnv_xscom: " Akihiko Odaki
2026-07-21 19:53   ` Philippe Mathieu-Daudé
2026-07-21  8:16 ` [PATCH for-11.2 v3 09/15] hw/vfio: " Akihiko Odaki
2026-07-21 19:55   ` Philippe Mathieu-Daudé
2026-07-21  8:17 ` [PATCH for-11.2 v3 10/15] hw/virtio/virtio-mem: " Akihiko Odaki
2026-07-21 19:55   ` Philippe Mathieu-Daudé
2026-07-21  8:17 ` [PATCH for-11.2 v3 11/15] hw/virtio/virtio-qmp: " Akihiko Odaki
2026-07-21 19:52   ` Philippe Mathieu-Daudé
2026-07-21  8:17 ` [PATCH for-11.2 v3 12/15] target/i386/cpu: " Akihiko Odaki
2026-07-21 19:52   ` Philippe Mathieu-Daudé
2026-07-21  8:17 ` [PATCH for-11.2 v3 13/15] target/s390x: " Akihiko Odaki
2026-07-21 19:52   ` Philippe Mathieu-Daudé
2026-07-21  8:17 ` [PATCH for-11.2 v3 14/15] hw/qdev: Parent device before setting parent bus Akihiko Odaki
2026-07-21 20:15   ` Philippe Mathieu-Daudé
2026-07-21  8:17 ` [PATCH for-11.2 v3 15/15] hw/qdev: Prevent devices from being realized more than once Akihiko Odaki
2026-07-21 20:11   ` Philippe Mathieu-Daudé
2026-07-22  5:12     ` Akihiko Odaki
2026-07-22  9:57       ` Philippe Mathieu-Daudé
2026-07-22 11:08         ` Akihiko Odaki
2026-07-22 12:05           ` Philippe Mathieu-Daudé
2026-07-24 11:44 ` [PATCH for-11.2 v3 00/15] qdev: Clarify and enforce the device realization lifecycle Markus Armbruster
2026-07-25  8:20   ` Akihiko Odaki
2026-08-15 13:59 ` Philippe Mathieu-Daudé
2026-08-16 14:33   ` Philippe Mathieu-Daudé

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.