Skip to contentSkip to conversation

Misc HW patches for 2026-09-27

GIT PULL Applied Philippe Mathieu-Daudé 2 participants 11 messages Sep 27

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

The following changes since commit efa3b9d5ac8024078225e1ab434411fdfe53b457:

Merge tag 'pbouvier/pr/tcg-tests-20260925' of https://gitlab.com/p-b-o/qemu into staging (2026-09-25 11:52:47 -0700)

are available in the Git repository at:

https://github.com/philmd/qemu.git tags/hw-misc-20260927

for you to fetch changes up to 8b395deb9475ca669f4ad62dd01d3ea66fdeea13:

target-info: add multi-target test binary (2026-09-27 09:30:12 +0200)

----------------------------------------------------------------
Misc HW patches

- Improve QDev documentation
- Remove non-32-bit CPUs on ISA/PC machine
- MacIO and BCM2835 CPRMAN fixes
- New multi-target test binary
----------------------------------------------------------------

Akihiko Odaki (1):
hw/qdev: Clarify instantiation and realization

Anisa Su (1):
MAINTAINERS: Add Anisa Su as a reviewer for CXL

Jonathan Gilbert (1):
hw/misc/bcm2835_cprman: correct register index in test for mux update

Mark Cave-Ayland (3):
hw/i386/isapc: reject modern x86 CPU models hw/macio/mac_dbdma: ensure only implemented DBDMA registers are
accessed
hw/ide/macio: use pmac_ide_transfer_cb() for disk DMA read callback

Pierrick Bouvier (2):
hw/xen: use stub_ss for xen_stubs
target-info: add multi-target test binary

Yonggang Luo (1):
hw/intc: use kvm_enabled() in APLIC AIA helpers

 MAINTAINERS                    |  2 ++
 meson.build                    | 23 +++++++++++++++
 include/hw/core/qdev.h         | 41 ++++++++++++--------------
 include/qemu/target-info-qom.h |  1 +
 hw/i386/isapc.c                | 53 ++++++++++++++++++++--------------
 hw/ide/macio.c                 |  2 +-
 hw/intc/riscv_aplic.c          | 14 +++++----
 hw/misc/bcm2835_cprman.c       |  2 +-
 hw/misc/macio/mac_dbdma.c      | 34 ++++++++++++----------
 target-info-qom.c              |  5 ++++
 tests/unit/test-multi-target.c | 53 ++++++++++++++++++++++++++++++++++
 hw/xen/meson.build             |  2 +-
 tests/unit/meson.build         | 12 ++++++++
 13 files changed, 176 insertions(+), 68 deletions(-)
 create mode 100644 tests/unit/test-multi-target.c
Signature · 1 line
2.53.0
#1 lore raw

[PULL 3/9] hw/i386/isapc: reject modern x86 CPU models

From: Mark Cave-Ayland <[email protected]>

It was originally intended as part of the work to split out the isapc machine from the pc machine to restrict the isapc machine to using only 32-bit CPUs. Before the 10.2 release it was decided in commit 329e36af94 ("hw/i386/isapc.c:
warn rather than reject modern x86 CPU models") to follow the official deprecation process due to concerns this would have an adverse effect on users.

Now that the deprecation period has expired and there have been no reported problems, update the isapc machine to reject modern x86 CPUs by reverting commit 329e36af94 ("hw/i386/isapc.c: warn rather than reject modern x86 CPU models").

Message-ID: <[email protected]>

---
 hw/i386/isapc.c | 53 +++++++++++++++++++++++++++++--------------------
 1 file changed, 32 insertions(+), 21 deletions(-)
hw/i386/isapc.c +32 -21
index 1ba9ae22cc3..44f4a446724 100644
@@ -41,31 +41,29 @@ static void pc_init_isa(MachineState *machine)
     DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
     int i;
 
-    bool valid_cpu_type = false;
-    static const char * const valid_cpu_types[] = {
-        X86_CPU_TYPE_NAME("486"),
-        X86_CPU_TYPE_NAME("athlon"),
-        X86_CPU_TYPE_NAME("kvm32"),
-        X86_CPU_TYPE_NAME("pentium"),
-        X86_CPU_TYPE_NAME("pentium2"),
-        X86_CPU_TYPE_NAME("pentium3"),
-        X86_CPU_TYPE_NAME("qemu32"),
-    };
-
     /*
-     * The isapc machine is supposed to represent a legacy ISA-only PC with a
-     * 32-bit processor. For historical reasons the machine can still accept
-     * almost any valid processor, but this is now deprecated in 10.2. Emit
-     * a warning if anyone tries to use a deprecated CPU.
+     * There is a small chance that someone unintentionally passes "-cpu max"
+     * for the isapc machine, which will provide a much more modern 32-bit
+     * CPU than would be expected for an ISA-era PC. If the "max" cpu type has
+     * been specified, choose the "best" 32-bit cpu possible which we consider
+     * be the pentium3 (deliberately choosing an Intel CPU given that the
+     * default 486 CPU for the isapc machine is also an Intel CPU).
      */
-    for (i = 0; i < ARRAY_SIZE(valid_cpu_types); i++) {
-        if (!strcmp(machine->cpu_type, valid_cpu_types[i])) {
-            valid_cpu_type = true;
-        }
+    if (!strcmp(machine->cpu_type, X86_CPU_TYPE_NAME("max"))) {
+        machine->cpu_type = X86_CPU_TYPE_NAME("pentium3");
+        warn_report("-cpu max is invalid for isapc machine, using pentium3");
     }
 
-    if (!valid_cpu_type) {
-        warn_report("cpu type %s is deprecated for isapc machine", machine->cpu_type);
+    /*
+     * Similarly if someone unintentionally passes "-cpu host" for the isapc
+     * machine then display a warning and also switch to the "best" 32-bit
+     * cpu possible which we consider to be the pentium3. This is because any
+     * host CPU will already be modern than this, but it also ensures any
+     * newer CPU flags/features are filtered out for older guests.
+     */
+    if (!strcmp(machine->cpu_type, X86_CPU_TYPE_NAME("host"))) {
+        machine->cpu_type = X86_CPU_TYPE_NAME("pentium3");
+        warn_report("-cpu host is invalid for isapc machine, using pentium3");
     }
 
     if (machine->ram_size > 3.5 * GiB) {
@@ -156,6 +154,18 @@ static void pc_init_isa(MachineState *machine)
 
 static void isapc_machine_options(MachineClass *m)
 {
+    static const char * const valid_cpu_types[] = {
+        X86_CPU_TYPE_NAME("486"),
+        X86_CPU_TYPE_NAME("athlon"),
+        X86_CPU_TYPE_NAME("kvm32"),
+        X86_CPU_TYPE_NAME("pentium"),
+        X86_CPU_TYPE_NAME("pentium2"),
+        X86_CPU_TYPE_NAME("pentium3"),
+        X86_CPU_TYPE_NAME("qemu32"),
+        X86_CPU_TYPE_NAME("max"),
+        X86_CPU_TYPE_NAME("host"),
+        NULL
+    };
     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
 
     m->desc = "ISA-only PC";
@@ -170,6 +180,7 @@ static void isapc_machine_options(MachineClass *m)
     pcmc->has_reserved_memory = false;
     m->default_nic = "ne2k_isa";
     m->default_cpu_type = X86_CPU_TYPE_NAME("486");
+    m->valid_cpu_types = valid_cpu_types;
     m->no_floppy = !module_object_class_by_name(TYPE_ISA_FDC);
     m->no_parallel = !module_object_class_by_name(TYPE_ISA_PARALLEL);
 }
Signature · 1 line
2.53.0
#2 lore raw

[PULL 7/9] hw/ide/macio: use pmac_ide_transfer_cb() for disk DMA read callback

In reply to Philippe Mathieu-Daudé

From: Mark Cave-Ayland <[email protected]>

Since its original implementation the disk DMA callback pmac_ide_transfer_cb() accidentally made use of the CDROM DMA read callback pmac_ide_atapi_transfer_cb() for disk DMA reads instead of itself.

Fixes be1e343995e ("macio: switch over to new byte-aligned DMA helpers")

Message-ID: <[email protected]>

---
 hw/ide/macio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ide/macio.c +1 -1
index 40fb4f3b4f3..a95e68083f4 100644
@@ -180,7 +180,7 @@ static void pmac_ide_transfer_cb(void *opaque, int ret)
     switch (s->dma_cmd) {
     case IDE_DMA_READ:
         s->bus->dma->aiocb = dma_blk_read(s->blk, &s->sg, offset, 0x1,
-                                          pmac_ide_atapi_transfer_cb, io);
+                                          pmac_ide_transfer_cb, io);
         break;
     case IDE_DMA_WRITE:
         s->bus->dma->aiocb = dma_blk_write(s->blk, &s->sg, offset, 0x1,
Signature · 1 line
2.53.0
#3 lore raw

[PULL 9/9] target-info: add multi-target test binary

In reply to Philippe Mathieu-Daudé

From: Pierrick Bouvier <[email protected]>

Now we are able to link multiple targets together, we want to make sure no build regression is introduced. For this, add a new unit test linking compatible targets.

In addition, we check QOM types can be initialized, ensuring uniqueness among all targets.

For now, supported targets are:
- arm-softmmu
- aarch64-softmmu
- microblaze-softmmu

Message-ID: <[email protected]>

---
 MAINTAINERS                    |  1 +
 meson.build                    | 23 +++++++++++++++
 include/qemu/target-info-qom.h |  1 +
 target-info-qom.c              |  5 ++++
 tests/unit/test-multi-target.c | 53 ++++++++++++++++++++++++++++++++++
 tests/unit/meson.build         | 12 ++++++++
 6 files changed, 95 insertions(+)
 create mode 100644 tests/unit/test-multi-target.c
MAINTAINERS +1 -0
index 026c11bd9b0..1b66c65f689 100644
@@ -2146,6 +2146,7 @@ S: Supported
 F: include/qemu/target-info*.h
 F: target-info*.c
 F: configs/targets/*.c
+F: tests/unit/test-multi-targets.c
 
 Xtensa Machines
 ---------------
meson.build +23 -0
index cfac634cf13..cae1591cd28 100644
@@ -4259,6 +4259,15 @@ if host_os == 'darwin'
 endif
 
 traceable = []
+multi_target_libs = []
+multi_target_deps = []
+multi_target_crates = []
+multi_target_supported_targets = [
+  'aarch64-softmmu',
+  'arm-softmmu',
+  'microblaze-softmmu',
+]
+
 emulators = {}
 foreach target : target_dirs
   config_target = config_target_mak[target]
@@ -4414,6 +4423,12 @@ foreach target : target_dirs
                  build_by_default: false)
 
   if target.endswith('-softmmu')
+    if target in multi_target_supported_targets
+      multi_target_libs += lib
+      multi_target_deps += arch_deps
+      multi_target_deps += target_stubs
+      multi_target_crates += main_rs
+    endif
     execs = [{
       'name': 'qemu-system-' + target_name,
       'win_subsystem': 'console',
@@ -4497,6 +4512,14 @@ endforeach
 
 # Other build targets
 
+multi_target_objects = []
+foreach lib: multi_target_libs
+  multi_target_objects += lib.extract_all_objects(recursive: true)
+endforeach
+
+multi_target_link_args = emulator_link_args
+multi_target_link_args += enable_modules ? ['@block.syms', '@qemu.syms'] : []
+
 if get_option('plugins')
   install_headers('include/plugins/qemu-plugin.h')
   if host_os == 'windows'
include/qemu/target-info-qom.h +1 -0
index 91be415ed33..8b6e1ece969 100644
@@ -26,5 +26,6 @@ typedef struct TargetInfoQomClass {
 OBJECT_DECLARE_TYPE(TargetInfoQom, TargetInfoQomClass, TARGET_INFO)
 
 void target_info_qom_set_target(void);
+void target_info_qom_set_target_info(const TargetInfo *ti);
 
 #endif /* QEMU_TARGET_INFO_QOM_H */
target-info-qom.c +5 -0
index 6965e4d1169..3ae1627b8fb 100644
@@ -53,3 +53,8 @@ void target_info_qom_set_target(void)
 
     target_info_ptr = TARGET_INFO_CLASS(targets->data)->target_info;
 }
+
+void target_info_qom_set_target_info(const TargetInfo *ti)
+{
+    target_info_ptr = ti;
+}
tests/unit/test-multi-target.c new file +53 -0

53 lines not on this page · raw message

tests/unit/meson.build +12 -0
index e47bc7225ab..d17435c1877 100644
@@ -215,3 +215,15 @@ foreach test_name, extra: tests
        suite: ['unit'] +
               (slow_tests.has_key(test_name) ? ['slow'] : []))
 endforeach
+
+# Multi targets test
+if multi_target_objects != []
+  test('test-multi-target',
+       executable('test-multi-target',
+                  sources: [multi_target_crates, files('test-multi-target.c')],
+                  dependencies: multi_target_deps,
+                  objects: multi_target_objects,
+                  link_depends: [block_syms, qemu_syms],
+                  link_args: multi_target_link_args),
+       suite: ['unit'])
+endif
Signature · 1 line
2.53.0
#4 lore raw

[PULL 1/9] MAINTAINERS: Add Anisa Su as a reviewer for CXL

In reply to Philippe Mathieu-Daudé

From: Anisa Su <[email protected]>

I contributed the FMAPI DCD mailbox command support in hw/cxl and also work on the Linux driver side, which is developed and tested against QEMU's CXL emulation, so I would like to be Cc'd on incoming CXL changes to help with review.

Message-ID: <[email protected]>

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index 6be9c5725b9..026c11bd9b0 100644
@@ -3338,6 +3338,7 @@ F: docs/devel/migration/CPR.rst
 Compute Express Link
 M: Jonathan Cameron <[email protected]>
 R: Junjie Cao <[email protected]>
+R: Anisa Su <[email protected]>
 L: [email protected]
 S: Supported
 F: hw/cxl/
Signature · 1 line
2.53.0
#5 lore raw

[PULL 4/9] hw/macio/mac_dbdma: ensure only implemented DBDMA registers are accessed

In reply to Philippe Mathieu-Daudé

From: Mark Cave-Ayland <[email protected]>

Whilst the DBDMA memory region is 4K in size, only the bottom 16 registers are implemented in the Power Macintosh DBDMA controller. If an attempt is made to access any unimplemented registers then an out-of-bounds array access occurs.

Rework the switch() statements in dbdma_read() and dbdma_write() to handle each individual register access, as well as providing a safe default for all other unimplemented registers.

Message-ID: <[email protected]>

---
 hw/misc/macio/mac_dbdma.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)
hw/misc/macio/mac_dbdma.c +18 -16
index a55c9c99824..d00181b9781 100644
@@ -715,22 +715,25 @@ static void dbdma_write(void *opaque, hwaddr addr,
         return;
     }
 
-    ch->regs[reg] = value;
-
     switch(reg) {
     case DBDMA_CONTROL:
+        ch->regs[DBDMA_CONTROL] = value;
         dbdma_control_write(ch);
         break;
     case DBDMA_CMDPTR_LO:
         /* 16-byte aligned */
-        ch->regs[DBDMA_CMDPTR_LO] &= ~0xf;
+        ch->regs[DBDMA_CMDPTR_LO] = value & ~0xf;
         dbdma_cmdptr_load(ch);
         break;
     case DBDMA_STATUS:
     case DBDMA_INTR_SEL:
     case DBDMA_BRANCH_SEL:
     case DBDMA_WAIT_SEL:
-        /* nothing to do */
+    case DBDMA_RES1:
+    case DBDMA_RES2:
+    case DBDMA_RES3:
+    case DBDMA_RES4:
+        ch->regs[reg] = value;
         break;
     case DBDMA_XFER_MODE:
     case DBDMA_CMDPTR_HI:
@@ -738,12 +741,11 @@ static void dbdma_write(void *opaque, hwaddr addr,
     case DBDMA_DATA2PTR_LO:
     case DBDMA_ADDRESS_HI:
     case DBDMA_BRANCH_ADDR_HI:
-    case DBDMA_RES1:
-    case DBDMA_RES2:
-    case DBDMA_RES3:
-    case DBDMA_RES4:
         /* unused */
         break;
+    default:
+        /* do nothing */
+        break;
     }
 }
 
@@ -756,8 +758,6 @@ static uint64_t dbdma_read(void *opaque, hwaddr addr,
     DBDMA_channel *ch = &s->channels[channel];
     int reg = (addr - (channel << DBDMA_CHANNEL_SHIFT)) >> 2;
 
-    value = ch->regs[reg];
-
     switch(reg) {
     case DBDMA_CONTROL:
         value = ch->regs[DBDMA_STATUS];
@@ -767,7 +767,11 @@ static uint64_t dbdma_read(void *opaque, hwaddr addr,
     case DBDMA_INTR_SEL:
     case DBDMA_BRANCH_SEL:
     case DBDMA_WAIT_SEL:
-        /* nothing to do */
+    case DBDMA_RES1:
+    case DBDMA_RES2:
+    case DBDMA_RES3:
+    case DBDMA_RES4:
+        value = ch->regs[reg];
         break;
     case DBDMA_XFER_MODE:
     case DBDMA_CMDPTR_HI:
@@ -778,11 +782,9 @@ static uint64_t dbdma_read(void *opaque, hwaddr addr,
         /* unused */
         value = 0;
         break;
-    case DBDMA_RES1:
-    case DBDMA_RES2:
-    case DBDMA_RES3:
-    case DBDMA_RES4:
-        /* reserved */
+    default:
+        /* unimplemented */
+        value = 0;
         break;
     }
 
Signature · 1 line
2.53.0
#6 lore raw

[PULL 6/9] hw/misc/bcm2835_cprman: correct register index in test for mux update

In reply to Philippe Mathieu-Daudé

From: Jonathan Gilbert <[email protected]>

After each register write handled by cprman_write, function update_mux checks each of the clocks to see whether the supplied register index applies to it, calling clock_mux_update if so. Each clock has two registers, so it needs to check the base cm_offset for CM_CTL and then the next slot for CM_DIV. But, it was checking for cm_offset plus 4, as though it were a byte offset when it's a logical index.

Fixes 7281362484a ("hw/misc/bcm2835_cprman: clock mux skeleton implementation")

Message-ID: <[email protected]>

---
 hw/misc/bcm2835_cprman.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/misc/bcm2835_cprman.c +1 -1
index 8220f7a6b4b..f9a77ff9bb0 100644
@@ -508,7 +508,7 @@ static inline void update_mux_from_cm(BCM2835CprmanState *s, size_t idx)
 
     for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) {
         if ((CLOCK_MUX_INIT_INFO[i].cm_offset == idx) ||
-            (CLOCK_MUX_INIT_INFO[i].cm_offset + 4 == idx)) {
+            (CLOCK_MUX_INIT_INFO[i].cm_offset + 1 == idx)) {
             /* matches CM_CTL or CM_DIV mux register */
             clock_mux_update(&s->clock_muxes[i]);
             return;
Signature · 1 line
2.53.0
#7 lore raw

[PULL 8/9] hw/xen: use stub_ss for xen_stubs

In reply to Philippe Mathieu-Daudé

From: Pierrick Bouvier <[email protected]>

Solves these link errors on aarch64 hosts when linking arm and aarch64 targets:

/usr/bin/ld: libsystem.a.p/hw_xen_xen_stubs.c.o: in function `xen_hvm_modified_memory':
/qemu/build/../hw/xen/xen_stubs.c:17: multiple definition of xen_hvm_modified_memory'; libsystem_arm.a.p/hw_arm_xen-stubs.c.o:/qemu/build/../hw/arm/xen-stubs.c:25: first defined here /usr/bin/ld: libsystem.a.p/hw_xen_xen_stubs.c.o: in function xen_ram_alloc':
/qemu/build/../hw/xen/xen_stubs.c:23: multiple definition of xen_ram_alloc'; libsystem.a.p/hw_xen_xen-hvm-common.c.o:/qemu/build/../hw/xen/xen-hvm-common.c:39: first defined here /usr/bin/ld: libsystem.a.p/hw_xen_xen_stubs.c.o: in function xen_mr_is_memory':
/qemu/build/../hw/xen/xen_stubs.c:28: multiple definition of xen_mr_is_memory'; libsystem.a.p/hw_xen_xen-hvm-common.c.o:/qemu/build/../hw/xen/xen-hvm-common.c:27: first defined here /usr/bin/ld: libsystem.a.p/hw_xen_xen_stubs.c.o: in function xen_map_cache_enabled':
/qemu/build/../hw/xen/xen_stubs.c:34: multiple definition of xen_map_cache_enabled'; libsystem.a.p/hw_xen_xen-mapcache.c.o:/qemu/build/../hw/xen/xen-mapcache.c:86: first defined here /usr/bin/ld: libsystem.a.p/hw_xen_xen_stubs.c.o: in function xen_invalidate_map_cache_entry':
/qemu/build/../hw/xen/xen_stubs.c:38: multiple definition of xen_invalidate_map_cache_entry'; libsystem.a.p/hw_xen_xen-mapcache.c.o:/qemu/build/../hw/xen/xen-mapcache.c:664: first defined here /usr/bin/ld: libsystem.a.p/hw_xen_xen_stubs.c.o: in function xen_ram_addr_from_mapcache':
/qemu/build/../hw/xen/xen_stubs.c:43: multiple definition of xen_ram_addr_from_mapcache'; libsystem.a.p/hw_xen_xen-mapcache.c.o:/qemu/build/../hw/xen/xen-mapcache.c:538: first defined here /usr/bin/ld: libsystem.a.p/hw_xen_xen_stubs.c.o: in function xen_map_cache':
/qemu/build/../hw/xen/xen_stubs.c:54: multiple definition of `xen_map_cache'; libsystem.a.p/hw_xen_xen-mapcache.c.o:/qemu/build/../hw/xen/xen-mapcache.c:468: first defined here

Message-ID: <[email protected]>

---
 hw/xen/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/xen/meson.build +1 -1
index dcd2b7e1df3..62767a5ea21 100644
@@ -29,4 +29,4 @@ else
 endif
 
 system_ss.add_all(when: ['CONFIG_XEN', xen], if_true: xen_common_ss)
-system_ss.add(when: ['CONFIG_XEN', xen], if_false: files('xen_stubs.c'))
+stub_ss.add(files('xen_stubs.c'))
Signature · 1 line
2.53.0
#8 lore raw

[PULL 5/9] hw/intc: use kvm_enabled() in APLIC AIA helpers

In reply to Philippe Mathieu-Daudé

From: Yonggang Luo <[email protected]>

- Replace CONFIG_KVM ifdefs in riscv_use_emulated_aplic and riscv_aplic_set_kvm_msicfgaddr with kvm_enabled().

Message-ID: <[email protected]>

---
 hw/intc/riscv_aplic.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
hw/intc/riscv_aplic.c +8 -6
index d8e25bfda14..03a0852b8b8 100644
@@ -167,7 +167,10 @@ bool riscv_is_kvm_aia_aplic_imsic(bool msimode)
 
 bool riscv_use_emulated_aplic(bool msimode)
 {
-#ifdef CONFIG_KVM
+    if (!kvm_enabled()) {
+        return true;
+    }
+
     if (tcg_enabled()) {
         return true;
     }
@@ -177,21 +180,20 @@ bool riscv_use_emulated_aplic(bool msimode)
     }
 
     return kvm_kernel_irqchip_split();
-#else
-    return true;
-#endif
 }
 
 void riscv_aplic_set_kvm_msicfgaddr(RISCVAPLICState *aplic, hwaddr addr)
 {
-#ifdef CONFIG_KVM
+    if (!kvm_enabled()) {
+        return;
+    }
+
     if (riscv_use_emulated_aplic(aplic->msimode)) {
         addr >>= APLIC_xMSICFGADDR_PPN_SHIFT;
         aplic->kvm_msicfgaddr = extract64(addr, 0, 32);
         aplic->kvm_msicfgaddrH = extract64(addr, 32, 32) &
                                  APLIC_MMSICFGADDRH_VALID_MASK;
     }
-#endif
 }
 
 /*
Signature · 1 line
2.53.0
#9 lore raw

[PULL 2/9] hw/qdev: Clarify instantiation and realization

In reply to Philippe Mathieu-Daudé

From: Akihiko Odaki <[email protected]>

The distinction of instantiation and realization was vague in the old documentation so this change clarifies it.

Quoted 6 lines · The old documentation

The former may not fail (and must not abort or exit, since it is called during device introspection already), and the latter may return error information to the caller and must be re-entrant. Trivial field initializations should go into #TypeInfo.instance_init. Operations depending on @props static properties should go into @realize.

The first problem with the old documentation is that it is unclear what "trivial field initializations" means and why triviality makes initialization appropriate for #TypeInfo.instance_init. Another problem is that the documentation is not comprehensive enough; for example, it mentions @props static properties, but it does not say anything about the other properties.

The keys to distinguish instantiation and realization are instance property setting and device introspection. The fact that initial instance property setting happens after #TypeInfo.instance_init and before realization implies that operations depending on properties should go into @realize.

The fact that instantiation happens during device introspection but realization does not implies:
- Instance properties may be added in #TypeInfo.instance_init.
- Instantiation must not have any side effect not contained in the instance.
- Any operations without special requirements should go into @realize so that they can be skipped during device introspection.
- Instance properties added during realization will not be configurable or introspectable before realization.

Note these two facts to guide appropriate instantiation and realization.

We also omit mention of the realized property because it is a QOM interface detail, not part of the device API.

The statements regarding a future prospect to propagate the realization state change are removed. Device realization is propagated to child buses, but not to the devices on those buses. The proposed recursive propagation to child devices has not been achieved after 13 years, has been questioned [1], and is not relevant with the current API usage.

[1] https://lore.kernel.org/qemu-devel/[email protected]/

Message-ID: <[email protected]>

---
 include/hw/core/qdev.h | 41 +++++++++++++++++++----------------------
 1 file changed, 19 insertions(+), 22 deletions(-)
include/hw/core/qdev.h +19 -22
index 1f6bf3fc1ab..8e91e2fcb08 100644
@@ -23,28 +23,27 @@
  * Realization
  * -----------
  *
- * Devices are constructed in two stages:
+ * Devices are constructed in the following order:
  *
- * 1) object instantiation via object_initialize() and
- * 2) device realization via the #DeviceState.realized property
+ * 1) #TypeInfo.instance_init
+ * 2) pre-realize property value setting
+ * 3) device realization
+ *
+ * #TypeInfo.instance_init may not fail. #DeviceClass.realize can
+ * fail, returning error information to the caller, and must be re-entrant.
+ *
+ * #TypeInfo.instance_init should add instance properties but must not
+ * have any side effect not contained in the instance, since it happens
+ * during device introspection. Any operations without special requirements
+ * should go into @realize so that they can be skipped during device
+ * introspection. It is possible to add properties during realization,
+ * but they will not be introspectable or configurable before realization.
+ *
+ * Child buses are automatically realized. Child devices must be manually
+ * realized (e.g. by calling qdev_realize()).
  *
- * The former may not fail (and must not abort or exit, since it is called
- * during device introspection already), and the latter may return error
- * information to the caller and must be re-entrant.
- * Trivial field initializations should go into #TypeInfo.instance_init.
- * Operations depending on @props static properties should go into @realize.
  * After successful realization, setting static properties will fail.
  *
- * As an interim step, the #DeviceState.realized property can also be
- * set with qdev_realize(). In the future, devices will propagate this
- * state change to their children and along busses they expose. The
- * point in time will be deferred to machine creation, so that values
- * set in @realize will not be introspectable beforehand. Therefore
- * devices must not create children during @realize; they should
- * initialize them via object_initialize() in their own
- * #TypeInfo.instance_init and forward the realization events
- * appropriately.
- *
  * Any type may override the @realize and/or @unrealize callbacks but needs
  * to call the parent type's implementation if keeping their functionality
  * is desired. Refer to QOM documentation for further discussion and examples.
@@ -102,10 +101,8 @@ typedef int (*DeviceSyncConfig)(DeviceState *dev, Error **errp);
 /**
  * struct DeviceClass - The base class for all devices.
  * @props: Properties accessing state fields.
- * @realize: Callback function invoked when the #DeviceState:realized
- * property is changed to %true.
- * @unrealize: Callback function invoked when the #DeviceState:realized
- * property is changed to %false.
+ * @realize: Callback function to realize the device.
+ * @unrealize: Callback function to unrealize the device.
  * @sync_config: Callback function invoked when QMP command device-sync-config
  * is called. Should synchronize device configuration from host to guest part
  * and notify the guest about the change.
Signature · 1 line
2.53.0
#10 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 12 lines · Philippe Mathieu-Daudé

The following changes since commit efa3b9d5ac8024078225e1ab434411fdfe53b457:

   Merge tag 'pbouvier/pr/tcg-tests-20260925' ofhttps://gitlab.com/p-b-o/qemu into staging (2026-09-25 11:52:47 -0700)

are available in the Git repository at:

   https://github.com/philmd/qemu.git tags/hw-misc-20260927

for you to fetch changes up to 8b395deb9475ca669f4ad62dd01d3ea66fdeea13:

   target-info: add multi-target test binary (2026-09-27 09:30:12 +0200)
Quoted 7 lines

----------------------------------------------------------------
Misc HW patches

- Improve QDev documentation
- Remove non-32-bit CPUs on ISA/PC machine
- MacIO and BCM2835 CPRMAN fixes
- New multi-target test binary

Applied, thanks.

r~