Skip to content

qdev: Clarify and enforce the device realization lifecycle

Akihiko Odaki qemu-arm qemu-devel 4 versions – In review

Get series with b4
b4 am [email protected] change-id 20250906-qdev-9e5cb7c06ffa

Versions newest first

  1. v4 Latest4 patches 3 repliesIn review
  2. v315 patches 26 repliesSuperseded
  3. v21 patch 8 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v11 patch0 repliesSuperseded

Changes in v4 from the cover letter

- Dropped the merged accessor conversions, const qualification, and
QOM-parenting fix.
- Split the phase conversion into three patches.
- Clarified automatic child-bus realization and explicit child-device
realization, and removed the obsolete plan for recursive realization
propagation.
- Documented that properties added during realization are neither
configurable nor introspectable beforehand.
- Initialized DeviceState::phase explicitly.
- Updated the DevicePhase introduction version to 11.2.
- Link to v3: https://lore.kernel.org/qemu-devel/[email protected]

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4qdev: Clarify instantiation and realizationinclude/hw/core/qdev.h+20 -221 reply
2/4hw/qdev: Introduce DevicePhasehw/core/qdev-clock.c hw/core/qdev-properties.c hw/core/qdev.c +5 more+51 -342 replies
3/4hw/qdev: Introduce the initialized and retired phaseshw/core/qdev.c include/hw/core/qdev.h qapi/common.json +1 more+121 -200 replies
4/4hw/qdev: Introduce the realizing phasehw/core/qdev.c include/hw/core/qdev.h qapi/common.json +1 more+52 -50 replies

Reviews trailers per patch

1 of 4 patches has a Reviewed-by or Acked-by.

PatchPeter Maydell
1/4R-b
2/4
3/4
4/4

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH v4 0/4] qdev: Clarify and enforce the device realization lifecycle

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.

The accessor conversions, const qualification of qdev_is_realized(), and QOM-parenting fix from earlier revisions have already been merged. This revision contains the four remaining patches.

The first patch 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 other three patches replace DeviceState::realized and the QOM realized property 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.

---
Changes in v4:
- Dropped the merged accessor conversions, const qualification, and
QOM-parenting fix.
- Split the phase conversion into three patches.
- Clarified automatic child-bus realization and explicit child-device
realization, and removed the obsolete plan for recursive realization
propagation.
- Documented that properties added during realization are neither
configurable nor introspectable beforehand.
- Initialized DeviceState::phase explicitly.
- Updated the DevicePhase introduction version to 11.2.
- Link to v3: https://lore.kernel.org/qemu-devel/[email protected]

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/[email protected]

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/[email protected]

---
Akihiko Odaki (4):
qdev: Clarify instantiation and realization hw/qdev: Introduce DevicePhase
hw/qdev: Introduce the initialized and retired phases hw/qdev: Introduce the realizing phase

 qapi/common.json          |  19 ++++++++
 include/hw/core/qdev.h    |  50 ++++++++++-----------
 hw/core/qdev-clock.c      |   4 +-
 hw/core/qdev-properties.c |   4 +-
 hw/core/qdev.c            |  99 ++++++++++++++++++++++++++--------------
 hw/scsi/scsi-bus.c        |   4 +-
 qom/qom-qmp-cmds.c        |   2 +-
 system/qdev-monitor.c     |   5 ++-
 tests/unit/test-qdev.c    | 112 +++++++++++++++++++++++++++++++++++++++++++++-
 9 files changed, 231 insertions(+), 68 deletions(-)

---
base-commit: 209b2afaface001c7d4d981e38f186afe7b24a50
change-id: 20250906-qdev-9e5cb7c06ffa

Best regards,

Signature · 1 line
Akihiko Odaki <[email protected]>