Skip to contentSkip to conversation

Misc HW patches for 2026-08-16

GIT PULL Applied Philippe Mathieu-Daudé 2 participants 58 messages Aug 16

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

The following changes since commit af06b5df2610fe5de6c02d17c17bced9e9f0d47d:

Merge tag 'qom-qdev-20260814' of https://gitlab.com/mcayland-ntx/qemu into staging (2026-08-14 08:44:51 -0700)

are available in the Git repository at:

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

for you to fetch changes up to b409523587c49a08b1ddadd51212a320092347b1:

hw/core/machine: Move EHCI migration compat properties to 11.1 (2026-08-16 16:35:27 +0200)

----------------------------------------------------------------
Misc HW and Monitor patch queue

- Bug fixes

. Reinstate x86/pc 'xenfv' machine alias
. Defend against malformed ELF headers to prevent underflows . Restore ROMD mode after migration for Intel PFlash (CFI01) . Fix VLAN tag handling on incoming packets on RTL8139 model

- Refactoring (Monitor, common CPU, NMI)

. Add missing inclusions and remove unnecessary ones . Use qdev_is_realized() consistently (no direct field access) . Remove deprecated DEFINE_PROP_DMAADDR() macro
. Renaming churn around cpu_{exec,common}* helpers
. Simplify NMI API hanlding
. Move QMP handlers (physmem, nmi) to appropriate subsystems . Replace container_of() casts with HMP typed accessors . Rename @mon to @hmp in MonitorHMP for clarity

----------------------------------------------------------------

Akihiko Odaki (13):
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

Alex Bennée (1):
hw/elf_ops: defend against weird elf headers

Bin Guo (1):
hw/block/pflash_cfi01: Restore ROMD mode after migration

Dario Faggioli (1):
hw/i386/pc: xen: reinstate the "xenfv" machine alias

Jamin Lin (1):
hw/core/machine: Move EHCI migration compat properties to 11.1

Marc-André Lureau (1):
hw/mem/nvdimm: fix "size" property typename

Peter Maydell (2):
hw/net/rtl8139: Fix handling of VLAN tags on incoming short packets hw/net/rtl8139: Send whole of vlan-tagged packet when doing loopback

Philippe Mathieu-Daudé (35):
hw/qdev: Remove DEFINE_PROP_DMAADDR() and 'hw/qdev-dma.h' hw/cpu: Correct CPU_GET_CLASS() comment
hw/cpu: Include missing 'qemu/accel.h' header
hw/cpu: Move internal declarations to new 'cpu-internal.h' header hw/cpu: Rename cpu_common_realizefn() -> cpu_exec_realize() hw/cpu: Rename cpu_exec_realizefn() -> cpu_common_realize() hw/cpu: Rename cpu_exec_unrealizefn() -> cpu_common_unrealize() hw/cpu: Extract cpu_exec_realize() out of cpu_common_realizefn() hw/cpu: Move system-specific cpu_exec_realize() to cpu-system.c hw/nmi: Use object_child_foreach_recursive() in nmi_children() hw/s390x/virtio-ccw: Always inject NMI to first CPU hw/nmi: Remove @cpu_index argument from
NMIClass::nmi_monitor_handler()
hw/nmi: Remove @cpu_index argument from nmi_inject() hw/nmi: Rename nmi_monitor_handler() -> raise_nmi() hw/nmi: Remove unused @errp argument from raise_nmi() hw/nmi: Raise NMI line only once
hexagon: Remove unnecessary 'monitor/monitor.h' header net/vhost-vdpa: Include missing 'qemu/iov.h' header tests/unit: Include 'qemu/main-loop.h' header in test-util-sockets.c qapi/qmp-dispatch: Include 'qemu/aio-wait.h' and 'monitor/monitor.h' qapi/qmp-registry: Remove unnecessary 'monitor/monitor.h' header migration/hmp-cmds: Include 'block/block-global-state.h' header
monitor: Include missing 'qemu/aio-wait.h' header
monitor: Include missing 'qemu/lockable.h' header
monitor: Include missing 'qemu/coroutine-core.h' header
monitor: Reduce inclusion of 'qapi/qapi-emit-events.h' header
monitor: Remove unnecessary 'block/block.h' header
system: Remove unnecessary 'monitor/monitor.h' header system/dirtylimit: Extract HMP code to dirtylimit-hmp-cmds.c
system: Move qmp_inject_nmi() to hw/core/machine-qmp-cmds.c
system: Extract QMP memsave/pmemsave commands to physmem-qmp-cmds.c
system: Move runstate-related code from cpus.c to runstate.c
monitor: Rename MonitorHMP @mon -> @hmp
monitor: Better express monitor_read()'s opaque arg is of Monitor type
monitor: Replace container_of(MonitorHMP, parent_obj) -> MONITOR_HMP()

Stefan Hajnoczi (1):
hw/nvme: add SPDM_SOCKET Kconfig dependency

 MAINTAINERS                      |   3 +
 qapi/machine.json                |   7 +-
 qapi/run-state.json              |   6 +-
 hw/core/cpu-internal.h           |  23 +++
 include/hw/core/cpu.h            |  15 +-
 include/hw/core/nmi.h            |  33 +++-
 include/hw/core/qdev-dma.h       |  16 --
 include/hw/core/qdev.h           |   2 +-
 include/hw/hexagon/hexagon_tlb.h |   2 +-
 include/monitor/monitor.h        |   7 +-
 include/qapi/qmp-registry.h      |   1 -
 monitor/monitor-internal.h       |   3 +-
 target/hexagon/hex_mmu.h         |   3 +-
 include/hw/elf_ops.h.inc         |   5 +
 hw/block/pflash_cfi01.c          |  10 ++
 hw/core/cpu-common.c             |  32 +---
 hw/core/cpu-system.c             |  30 +++-
 hw/core/cpu-user.c               |   8 +-
 hw/core/machine-qmp-cmds.c       |   6 +
 hw/core/machine.c                |   7 +-
 hw/core/nmi.c                    |  48 ++----
 hw/core/qdev.c                   |  51 ++++---
 hw/hppa/machine.c                |   4 +-
 hw/hyperv/hv-balloon.c           |   2 +-
 hw/i386/pc_piix.c                |   1 +
 hw/i386/x86.c                    |   4 +-
 hw/intc/apic_common.c            |   2 +-
 hw/intc/m68k_irqc.c              |   4 +-
 hw/ipmi/ipmi.c                   |   3 +-
 hw/m68k/q800-glue.c              |   4 +-
 hw/mem/memory-device.c           |   4 +-
 hw/mem/nvdimm.c                  |   2 +-
 hw/mem/pc-dimm.c                 |   2 +-
 hw/misc/macio/gpio.c             |   4 +-
 hw/net/rtl8139.c                 |   6 +-
 hw/nvram/xlnx-bbram.c            |   2 +-
 hw/nvram/xlnx-efuse.c            |   2 +-
 hw/ppc/pnv.c                     |   4 +-
 hw/ppc/pnv_xscom.c               |   2 +-
 hw/ppc/spapr.c                   |   4 +-
 hw/s390x/s390-virtio-ccw.c       |   8 +-
 hw/usb/hcd-ohci-pci.c            |   1 -
 hw/usb/hcd-ohci-sysbus.c         |   3 +-
 hw/usb/hcd-ohci.c                |   1 -
 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 +-
 hw/watchdog/watchdog.c           |   2 +-
 migration/migration-hmp-cmds.c   |   1 +
 monitor/fds.c                    |   1 +
 monitor/hmp-cmds.c               |   6 +-
 monitor/hmp.c                    | 136 ++++++++---------
 monitor/monitor.c                |   2 +
 monitor/qmp.c                    |   3 +-
 net/vhost-vdpa.c                 |   1 +
 qapi/qmp-dispatch.c              |   2 +
 system/cpus.c                    | 248 -------------------------------
 system/device_tree.c             |   1 -
 system/dirtylimit-hmp-cmds.c     |  74 +++++++++
 system/dirtylimit.c              |  60 --------
 system/physmem-qmp-cmds.c        | 107 +++++++++++++
 system/physmem.c                 |   2 -
 system/runstate.c                | 154 +++++++++++++++++++
 target/alpha/cpu.c               |   2 +-
 target/arm/cpu.c                 |   2 +-
 target/avr/cpu.c                 |   2 +-
 target/hexagon/cpu.c             |   2 +-
 target/hppa/cpu.c                |   2 +-
 target/i386/cpu.c                |  12 +-
 target/i386/kvm/kvm-cpu.c        |   4 +-
 target/loongarch/cpu.c           |   2 +-
 target/m68k/cpu.c                |   2 +-
 target/microblaze/cpu.c          |   2 +-
 target/mips/cpu.c                |   2 +-
 target/or1k/cpu.c                |   2 +-
 target/ppc/cpu_init.c            |   4 +-
 target/riscv/cpu.c               |   2 +-
 target/riscv/kvm/kvm-cpu.c       |   2 +-
 target/riscv/tcg/tcg-cpu.c       |   2 +-
 target/rx/cpu.c                  |   2 +-
 target/s390x/cpu.c               |   2 +-
 target/s390x/cpu_models.c        |   4 +-
 target/sh4/cpu.c                 |   2 +-
 target/sparc/cpu.c               |   2 +-
 target/tricore/cpu.c             |   2 +-
 target/xtensa/cpu.c              |   2 +-
 tests/unit/test-qdev.c           |  13 ++
 tests/unit/test-util-sockets.c   |   1 +
 ui/ui-hmp-cmds.c                 |   6 +-
 hmp-commands.hx                  |   7 +-
 hw/nvme/Kconfig                  |   1 +
 system/meson.build               |   2 +
 94 files changed, 702 insertions(+), 595 deletions(-)
 create mode 100644 hw/core/cpu-internal.h
 delete mode 100644 include/hw/core/qdev-dma.h
 create mode 100644 system/dirtylimit-hmp-cmds.c
 create mode 100644 system/physmem-qmp-cmds.c
Signature · 1 line
2.53.0
#1 lore raw

[PULL 01/56] hw/qdev: Remove DEFINE_PROP_DMAADDR() and 'hw/qdev-dma.h'

From: Philippe Mathieu-Daudé <[email protected]>

DEFINE_PROP_DMAADDR() is only used once. Since it doesn't add much value, simply remove it, along with the header defining it.

Message-Id: <[email protected]>

---
 include/hw/core/qdev-dma.h | 16 ----------------
 hw/usb/hcd-ohci-pci.c      |  1 -
 hw/usb/hcd-ohci-sysbus.c   |  3 +--
 hw/usb/hcd-ohci.c          |  1 -
 4 files changed, 1 insertion(+), 20 deletions(-)
 delete mode 100644 include/hw/core/qdev-dma.h
include/hw/core/qdev-dma.h deleted +0 -16
deleted file mode 100644
index b00391aa0c3..00000000000
@@ -1,16 +0,0 @@
-/*
- * Support for dma_addr_t typed properties
- *
- * Copyright (C) 2012 David Gibson, IBM Corporation.
- *
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
- * See the COPYING file in the top-level directory.
- */
-
-#ifndef HW_QDEV_DMA_H
-#define HW_QDEV_DMA_H
-
-#define DEFINE_PROP_DMAADDR(_n, _s, _f, _d)                               \
-    DEFINE_PROP_UINT64(_n, _s, _f, _d)
-
-#endif
hw/usb/hcd-ohci-pci.c +0 -1
index 18b58f5fcbc..70c9e9ac4f5 100644
@@ -25,7 +25,6 @@
 #include "migration/vmstate.h"
 #include "hw/pci/pci_device.h"
 #include "hw/core/sysbus.h"
-#include "hw/core/qdev-dma.h"
 #include "hw/core/qdev-properties.h"
 #include "trace.h"
 #include "hcd-ohci.h"
hw/usb/hcd-ohci-sysbus.c +1 -2
index 1a2cf29bed8..4f51eebccb2 100644
@@ -26,7 +26,6 @@
 #include "hw/usb/usb.h"
 #include "migration/vmstate.h"
 #include "hw/core/sysbus.h"
-#include "hw/core/qdev-dma.h"
 #include "hw/core/qdev-properties.h"
 #include "trace.h"
 #include "hcd-ohci.h"
@@ -61,7 +60,7 @@ static const Property ohci_sysbus_properties[] = {
     DEFINE_PROP_STRING("masterbus", OHCISysBusState, masterbus),
     DEFINE_PROP_UINT32("num-ports", OHCISysBusState, num_ports, 3),
     DEFINE_PROP_UINT32("firstport", OHCISysBusState, firstport, 0),
-    DEFINE_PROP_DMAADDR("dma-offset", OHCISysBusState, dma_offset, 0),
+    DEFINE_PROP_UINT64("dma-offset", OHCISysBusState, dma_offset, 0),
 };
 
 static void ohci_sysbus_class_init(ObjectClass *klass, const void *data)
hw/usb/hcd-ohci.c +0 -1
index c4a9741bd42..23990115abe 100644
@@ -34,7 +34,6 @@
 #include "hw/usb/usb.h"
 #include "migration/vmstate.h"
 #include "hw/core/sysbus.h"
-#include "hw/core/qdev-dma.h"
 #include "hw/core/qdev-properties.h"
 #include "trace.h"
 #include "hcd-ohci.h"
Signature · 1 line
2.53.0
#2 lore raw

[PULL 04/56] hw/hyperv/balloon: Use qdev_is_realized()

In reply to Philippe Mathieu-Daudé

From: Akihiko Odaki <[email protected]>

DeviceState fields should be accessed through qdev helpers rather than directly. Use qdev_is_realized() instead of reading DeviceState::realized directly.

Message-ID: <[email protected]>

---
 hw/hyperv/hv-balloon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/hyperv/hv-balloon.c +1 -1
index 9dd759f11e8..b8664a246b4 100644
@@ -197,7 +197,7 @@ static int build_dimm_list(Object *obj, void *opaque)
 
     if (object_dynamic_cast(obj, TYPE_PC_DIMM)) {
         DeviceState *dev = DEVICE(obj);
-        if (dev->realized) { /* only realized DIMMs matter */
+        if (qdev_is_realized(dev)) { /* only realized DIMMs matter */
             *list = g_slist_prepend(*list, dev);
         }
     }
Signature · 1 line
2.53.0
#3 lore raw

[PULL 03/56] qdev: Make qdev_is_realized() take a const DeviceState *

In reply to Philippe Mathieu-Daudé

From: Akihiko Odaki <[email protected]>

qdev_is_realized() only reads DeviceState. Make its parameter const so a later caller with a const DeviceState * can use it.

Message-ID: <[email protected]>

---
 include/hw/core/qdev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/hw/core/qdev.h +1 -1
index e1476223411..37f7d335519 100644
@@ -437,7 +437,7 @@ DeviceState *qdev_try_new(const char *name);
  * Context: May be called outside big qemu lock.
  * Return: true if the device has been fully constructed, false otherwise.
  */
-static inline bool qdev_is_realized(DeviceState *dev)
+static inline bool qdev_is_realized(const DeviceState *dev)
 {
     return qatomic_load_acquire(&dev->realized);
 }
Signature · 1 line
2.53.0
#4 lore raw

[PULL 05/56] hw/intc/apic: Use qdev_is_realized()

In reply to Philippe Mathieu-Daudé

From: Akihiko Odaki <[email protected]>

DeviceState fields should be accessed through qdev helpers rather than directly. Use qdev_is_realized() instead of reading DeviceState::realized directly.

Message-ID: <[email protected]>

---
 hw/intc/apic_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/intc/apic_common.c +1 -1
index 49c03a5bcee..0f0f37d4573 100644
@@ -424,7 +424,7 @@ static void apic_common_set_id(Object *obj, Visitor *v, const char *name,
     DeviceState *dev = DEVICE(obj);
     uint32_t value;
 
-    if (dev->realized) {
+    if (qdev_is_realized(dev)) {
         qdev_prop_set_after_realize(dev, name, errp);
         return;
     }
Signature · 1 line
2.53.0
#5 lore raw

[PULL 06/56] hw/mem/memory-device: Use qdev_is_realized()

In reply to Philippe Mathieu-Daudé

From: Akihiko Odaki <[email protected]>

DeviceState fields should be accessed through qdev helpers rather than directly. Use qdev_is_realized() instead of reading DeviceState::realized directly.

Message-ID: <[email protected]>

---
 hw/mem/memory-device.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/mem/memory-device.c +2 -2
index 9cf82b84cf4..24bebfb6b31 100644
@@ -59,7 +59,7 @@ static int memory_device_build_list(Object *obj, void *opaque)
 
     if (object_dynamic_cast(obj, TYPE_MEMORY_DEVICE)) {
         DeviceState *dev = DEVICE(obj);
-        if (dev->realized) { /* only realized memory devices matter */
+        if (qdev_is_realized(dev)) {
             *list = g_slist_insert_sorted(*list, dev, memory_device_addr_sort);
         }
     }
@@ -326,7 +326,7 @@ static int memory_device_plugged_size(Object *obj, void *opaque)
         const MemoryDeviceState *md = MEMORY_DEVICE(obj);
         const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(obj);
 
-        if (dev->realized && !memory_device_is_empty(md)) {
+        if (qdev_is_realized(dev) && !memory_device_is_empty(md)) {
             *size += mdc->get_plugged_size(md, &error_abort);
         }
     }
Signature · 1 line
2.53.0
#6 lore raw

[PULL 02/56] hw/mem/nvdimm: fix "size" property typename

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

The getter/setter use visit_type_size().

Message-ID: <[email protected]>

---
 hw/mem/nvdimm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/mem/nvdimm.c +1 -1
index b7032525271..cf8a4d8c5f2 100644
@@ -99,7 +99,7 @@ static void nvdimm_set_uuid(Object *obj, Visitor *v, const char *name,
 
 static void nvdimm_init(Object *obj)
 {
-    object_property_add(obj, NVDIMM_LABEL_SIZE_PROP, "int",
+    object_property_add(obj, NVDIMM_LABEL_SIZE_PROP, "size",
                         nvdimm_get_label_size, nvdimm_set_label_size, NULL,
                         NULL);
 
Signature · 1 line
2.53.0
#7 lore raw

[PULL 08/56] hw/nvram: Use qdev_is_realized()

In reply to Philippe Mathieu-Daudé

From: Akihiko Odaki <[email protected]>

DeviceState fields should be accessed through qdev helpers rather than directly. Use qdev_is_realized() instead of reading DeviceState::realized directly.

Message-ID: <[email protected]>

---
 hw/nvram/xlnx-bbram.c | 2 +-
 hw/nvram/xlnx-efuse.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
hw/nvram/xlnx-bbram.c +1 -1
index edfb592a5ec..e336874bdef 100644
@@ -468,7 +468,7 @@ static void bbram_prop_set_drive(Object *obj, Visitor *v, const char *name,
     qdev_prop_drive.set(obj, v, name, opaque, errp);
 
     /* Fill initial data if backend is attached after realized */
-    if (dev->realized) {
+    if (qdev_is_realized(dev)) {
         bbram_bdrv_read(XLNX_BBRAM(obj), errp);
     }
 }
hw/nvram/xlnx-efuse.c +1 -1
index 1a9650ba128..03c9fbc0d07 100644
@@ -233,7 +233,7 @@ static void efuse_prop_set_drive(Object *obj, Visitor *v, const char *name,
     qdev_prop_drive.set(obj, v, name, opaque, errp);
 
     /* Fill initial data if backend is attached after realized */
-    if (dev->realized) {
+    if (qdev_is_realized(dev)) {
         efuse_bdrv_read(XLNX_EFUSE(obj), errp);
     }
 }
Signature · 1 line
2.53.0
#8 lore raw

[PULL 10/56] hw/vfio: Use qdev_is_realized()

In reply to Philippe Mathieu-Daudé

From: Akihiko Odaki <[email protected]>

DeviceState fields should be accessed through qdev helpers rather than directly. Use qdev_is_realized() instead of reading DeviceState::realized directly.

Message-ID: <[email protected]>

---
 hw/vfio/container-legacy.c | 4 ++--
 hw/vfio/device.c           | 4 ++--
 hw/vfio/iommufd.c          | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
hw/vfio/container-legacy.c +2 -2
index d301b27aa65..7ac7b372145 100644
@@ -1075,7 +1075,7 @@ static int vfio_legacy_pci_hot_reset(VFIODevice *vbasedev, bool single)
 
         /* Prep dependent devices for reset and clear our marker. */
         QLIST_FOREACH(vbasedev_iter, &group->device_list, next) {
-            if (!vbasedev_iter->dev->realized ||
+            if (!qdev_is_realized(vbasedev_iter->dev) ||
                 !vfio_pci_from_vfio_device(vbasedev_iter)) {
                 continue;
             }
@@ -1160,7 +1160,7 @@ out:
         }
 
         QLIST_FOREACH(vbasedev_iter, &group->device_list, next) {
-            if (!vbasedev_iter->dev->realized ||
+            if (!qdev_is_realized(vbasedev_iter->dev) ||
                 !vfio_pci_from_vfio_device(vbasedev_iter)) {
                 continue;
             }
hw/vfio/device.c +2 -2
index 1a7f8088aad..4f119596336 100644
@@ -59,13 +59,13 @@ void vfio_device_reset_handler(void *opaque)
 
     trace_vfio_device_reset_handler();
     QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
-        if (vbasedev->dev->realized) {
+        if (qdev_is_realized(vbasedev->dev)) {
             vbasedev->ops->vfio_compute_needs_reset(vbasedev);
         }
     }
 
     QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
-        if (vbasedev->dev->realized && vbasedev->needs_reset) {
+        if (qdev_is_realized(vbasedev->dev) && vbasedev->needs_reset) {
             vbasedev->ops->vfio_hot_reset_multi(vbasedev);
         }
     }
hw/vfio/iommufd.c +1 -1
index 6ff668d2597..242644aa001 100644
@@ -829,7 +829,7 @@ iommufd_cdev_dep_get_realized_vpdev(struct vfio_pci_dependent_device *dep_dev,
 
     vbasedev_tmp = iommufd_cdev_pci_find_by_devid(dep_dev->devid);
     if (!vfio_pci_from_vfio_device(vbasedev_tmp) ||
-        !vbasedev_tmp->dev->realized) {
+        !qdev_is_realized(vbasedev_tmp->dev)) {
         return NULL;
     }
 
Signature · 1 line
2.53.0
#9 lore raw

[PULL 09/56] hw/ppc/pnv_xscom: Use qdev_is_realized()

In reply to Philippe Mathieu-Daudé

From: Akihiko Odaki <[email protected]>

DeviceState fields should be accessed through qdev helpers rather than directly. Use qdev_is_realized() instead of reading DeviceState::realized directly.

Message-ID: <[email protected]>

---
 hw/ppc/pnv_xscom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/pnv_xscom.c +1 -1
index dc1ffc6c014..7af722584e2 100644
@@ -253,7 +253,7 @@ static int xscom_dt_child(Object *child, void *opaque)
         /*
          * Only "realized" devices should be configured in the DT
          */
-        if (xc->dt_xscom && DEVICE(child)->realized) {
+        if (xc->dt_xscom && qdev_is_realized(DEVICE(child))) {
             _FDT((xc->dt_xscom(xd, args->fdt, args->xscom_offset)));
         }
     }
Signature · 1 line
2.53.0
#10 lore raw

[PULL 07/56] hw/mem/pc-dimm: Use qdev_is_realized()

In reply to Philippe Mathieu-Daudé

From: Akihiko Odaki <[email protected]>

DeviceState fields should be accessed through qdev helpers rather than directly. Use qdev_is_realized() instead of reading DeviceState::realized directly.

Message-ID: <[email protected]>

---
 hw/mem/pc-dimm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/mem/pc-dimm.c +1 -1
index 3efe47f499a..68862926ee2 100644
@@ -103,7 +103,7 @@ static int pc_dimm_slot2bitmap(Object *obj, void *opaque)
 
     if (object_dynamic_cast(obj, TYPE_PC_DIMM)) {
         DeviceState *dev = DEVICE(obj);
-        if (dev->realized) { /* count only realized DIMMs */
+        if (qdev_is_realized(dev)) { /* count only realized DIMMs */
             PCDIMMDevice *d = PC_DIMM(obj);
             set_bit(d->slot, bitmap);
         }
Signature · 1 line
2.53.0
#11 lore raw

[PULL 12/56] hw/virtio/virtio-qmp: Use qdev_is_realized()

In reply to Philippe Mathieu-Daudé

From: Akihiko Odaki <[email protected]>

DeviceState fields should be accessed through qdev helpers rather than directly. Use qdev_is_realized() instead of reading DeviceState::realized directly.

Message-ID: <[email protected]>

---
 hw/virtio/virtio-qmp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/virtio/virtio-qmp.c +2 -2
index 57cc03828c2..5aaeebdd96a 100644
@@ -659,7 +659,7 @@ static int query_dev_child(Object *child, void *opaque)
 {
     VirtioInfoList **vdevs = opaque;
     Object *dev = object_dynamic_cast(child, TYPE_VIRTIO_DEVICE);
-    if (dev != NULL && DEVICE(dev)->realized) {
+    if (dev != NULL && qdev_is_realized(DEVICE(dev))) {
         VirtIODevice *vdev = VIRTIO_DEVICE(dev);
         VirtioInfo *info = g_new(VirtioInfo, 1);
 
@@ -688,7 +688,7 @@ VirtIODevice *qmp_find_virtio_device(const char *path)
     /* Verify the canonical path is a realized virtio device */
     Object *dev = object_dynamic_cast(object_resolve_path(path, NULL),
                                       TYPE_VIRTIO_DEVICE);
-    if (!dev || !DEVICE(dev)->realized) {
+    if (!dev || !qdev_is_realized(DEVICE(dev))) {
         return NULL;
     }
     return VIRTIO_DEVICE(dev);
Signature · 1 line
2.53.0
#12 lore raw

[PULL 11/56] hw/virtio/virtio-mem: Use qdev_is_realized()

In reply to Philippe Mathieu-Daudé

From: Akihiko Odaki <[email protected]>

DeviceState fields should be accessed through qdev helpers rather than directly. Use qdev_is_realized() instead of reading DeviceState::realized directly.

Message-ID: <[email protected]>

---
 hw/virtio/virtio-mem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/virtio/virtio-mem.c +2 -2
index 35e03ed7599..7130ed852d9 100644
@@ -1453,7 +1453,7 @@ static void virtio_mem_set_requested_size(Object *obj, Visitor *v,
      * The block size and memory backend are not fixed until the device was
      * realized. realize() will verify these properties then.
      */
-    if (DEVICE(obj)->realized) {
+    if (qdev_is_realized(DEVICE(obj))) {
         if (!QEMU_IS_ALIGNED(value, vmem->block_size)) {
             error_setg(errp, "'%s' has to be multiples of '%s' (0x%" PRIx64
                        ")", name, VIRTIO_MEM_BLOCK_SIZE_PROP,
@@ -1507,7 +1507,7 @@ static void virtio_mem_set_block_size(Object *obj, Visitor *v, const char *name,
     VirtIOMEM *vmem = VIRTIO_MEM(obj);
     uint64_t value;
 
-    if (DEVICE(obj)->realized) {
+    if (qdev_is_realized(DEVICE(obj))) {
         error_setg(errp, "'%s' cannot be changed", name);
         return;
     }
Signature · 1 line
2.53.0
#13 lore raw

[PULL 13/56] target/i386/cpu: Use qdev_is_realized()

In reply to Philippe Mathieu-Daudé

From: Akihiko Odaki <[email protected]>

DeviceState fields should be accessed through qdev helpers rather than directly. Use qdev_is_realized() instead of reading DeviceState::realized directly.

Message-ID: <[email protected]>

---
 target/i386/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/cpu.c +1 -1
index 5805d33ab92..7a2c3cf358d 100644
@@ -10387,7 +10387,7 @@ static void x86_cpu_set_bit_prop(Object *obj, Visitor *v, const char *name,
     BitProperty *fp = opaque;
     bool value;
 
-    if (dev->realized) {
+    if (qdev_is_realized(dev)) {
         qdev_prop_set_after_realize(dev, name, errp);
         return;
     }
Signature · 1 line
2.53.0
#14 lore raw

[PULL 14/56] target/s390x: Use qdev_is_realized()

In reply to Philippe Mathieu-Daudé

From: Akihiko Odaki <[email protected]>

DeviceState fields should be accessed through qdev helpers rather than directly. Use qdev_is_realized() instead of reading DeviceState::realized directly.

Message-ID: <[email protected]>

---
 target/s390x/cpu_models.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/s390x/cpu_models.c +2 -2
index 2dd9aac8078..f292af7ad01 100644
@@ -714,7 +714,7 @@ static void set_feature(Object *obj, Visitor *v, const char *name,
     S390CPU *cpu = S390_CPU(obj);
     bool value;
 
-    if (dev->realized) {
+    if (qdev_is_realized(dev)) {
         error_setg(errp, "Attempt to set property '%s' on '%s' after "
                    "it was realized", name, object_get_typename(obj));
         return;
@@ -770,7 +770,7 @@ static void set_feature_group(Object *obj, Visitor *v, const char *name,
     S390CPU *cpu = S390_CPU(obj);
     bool value;
 
-    if (dev->realized) {
+    if (qdev_is_realized(dev)) {
         error_setg(errp, "Attempt to set property '%s' on '%s' after "
                    "it was realized", name, object_get_typename(obj));
         return;
Signature · 1 line
2.53.0
#15 lore raw

[PULL 17/56] hw/net/rtl8139: Fix handling of VLAN tags on incoming short packets

In reply to Philippe Mathieu-Daudé

From: Peter Maydell <[email protected]>

The rtl8139 receive code handles VLAN tags in incoming packets by copying the VLAN tag to a special field in the receive descriptor, and copying only the actual payload data to the receive buffer. This code tries to ensure that it pads out the payload to at least MIN_BUF_SIZE bytes.

In commit 63b901bfd30 we removed the main "pad short frames" code from this device because we switched to requiring net backends to do the padding. However we didn't notice that this broke the VLAN tag handling, which relied on the old code making the buffer at least MIN_BUF_SIZE + VLAN_HLEN bytes so that it could copy MIN_BUF_SIZE bytes into the receive buffer even after removing the VLAN tag. The result is that the guest can make us read 4 bytes off the end of a buffer by feeding itself a suitable short packet in loopback mode.

The old behaviour is actually not correct, because the IEEE802.1Q standard says that the minimum ethernet frame size remains 64 bytes including the 4 checksum bytes, and so when a tag is present the payload data only needs to be 56 bytes. (A bridge implementation can choose to pad tagged frames out to 68 bytes, but it doesn't have to, and so all devices have to correctly handle incoming tagged frames that are 64 bytes long.)

The RTL8139 datasheet isn't very communicative on this topic, but there's nothing that suggests it adds extra padding on receive that didn't exist in the incoming packet.

Drop the last remnants of the padding handling from this device; this avoids overcopying into the guest when we receive a short VLAN tagged packet.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3518

Message-ID: <[email protected]>

---
 hw/net/rtl8139.c | 5 -----
 1 file changed, 5 deletions(-)
hw/net/rtl8139.c +0 -5
index 424af73a18f..2b61c171f2a 100644
@@ -778,7 +778,6 @@ static void rtl8139_write_buffer(RTL8139State *s, const void *buf, int size)
     s->RxBufAddr += size;
 }
 
-#define MIN_BUF_SIZE 60
 static inline dma_addr_t rtl8139_addr64(uint32_t low, uint32_t high)
 {
     return low | ((uint64_t)high << 32);
@@ -1007,10 +1006,6 @@ static ssize_t rtl8139_receive(NetClientState *nc,
             lduw_be_p(&buf[ETH_ALEN * 2]) == ETH_P_VLAN) {
             dot1q_buf = &buf[ETH_ALEN * 2];
             size -= VLAN_HLEN;
-            /* if too small buffer, use the tailroom added duing expansion */
-            if (size < MIN_BUF_SIZE) {
-                size = MIN_BUF_SIZE;
-            }
 
             rxdw1 &= ~CP_RX_VLAN_TAG_MASK;
             /* BE + ~le_to_cpu()~ + cpu_to_le() = BE */
Signature · 1 line
2.53.0
#16 lore raw

[PULL 18/56] hw/net/rtl8139: Send whole of vlan-tagged packet when doing loopback

In reply to Philippe Mathieu-Daudé

From: Peter Maydell <[email protected]>

In rtl8139_transfer_frame(), if we are transmitting a frame over loopback then we do this by calling qemu_receive_packet(). If we have an iovec rather than a simple buffer (which happens only when we're sending a packet where we are inserting a vlan tag), we have to convert this into a simple buffer first using iov_to_buf(). However, when we do this we forget to also update the 'size' local variable to the size of the new simple buffer, so we will truncate the packet by 4 bytes (the size of the vlan tag).

Correct the logic so we don't truncate vlan-tagged packets when sending them over loopback.

Message-ID: <[email protected]>

---
 hw/net/rtl8139.c | 1 +
 1 file changed, 1 insertion(+)
hw/net/rtl8139.c +1 -0
index 2b61c171f2a..16479284eea 100644
@@ -1765,6 +1765,7 @@ static void rtl8139_transfer_frame(RTL8139State *s, uint8_t *buf, int size,
             buf2 = g_malloc(buf2_size);
             iov_to_buf(iov, 3, 0, buf2, buf2_size);
             buf = buf2;
+            size = buf2_size;
         }
 
         DPRINTF("+++ transmit loopback mode\n");
Signature · 1 line
2.53.0
#17 lore raw

[PULL 24/56] hw/cpu: Rename cpu_common_realizefn() -> cpu_exec_realize()

In reply to Philippe Mathieu-Daudé

Keep cpu_common_*() pattern for publicly exposed common methods used by target code. Use cpu_exec_*() pattern for internal ones, mostly to distinct between system / user mode.

Message-Id: <[email protected]>

---
 hw/core/cpu-common.c      | 4 ++--
 target/i386/kvm/kvm-cpu.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
hw/core/cpu-common.c +2 -2
index 17d76580930..33e349d4402 100644
@@ -246,7 +246,7 @@ bool cpu_exec_realizefn(CPUState *cpu, Error **errp)
     return true;
 }
 
-static void cpu_common_realizefn(DeviceState *dev, Error **errp)
+static void cpu_exec_realize(DeviceState *dev, Error **errp)
 {
     CPUState *cpu = CPU(dev);
     Object *machine = qdev_get_machine();
@@ -379,7 +379,7 @@ static void cpu_common_class_init(ObjectClass *klass, const void *data)
     k->gdb_read_register = cpu_common_gdb_read_register;
     k->gdb_write_register = cpu_common_gdb_write_register;
     set_bit(DEVICE_CATEGORY_CPU, dc->categories);
-    dc->realize = cpu_common_realizefn;
+    dc->realize = cpu_exec_realize;
     dc->unrealize = cpu_common_unrealizefn;
     rc->phases.hold = cpu_common_reset_hold;
     rc->phases.exit = cpu_common_reset_exit;
target/i386/kvm/kvm-cpu.c +1 -1
index c34d9f15c7e..e164cef2036 100644
@@ -63,7 +63,7 @@ static bool kvm_cpu_realizefn(CPUState *cs, Error **errp)
      *          host_cpu_realizefn()
      *          kvm_set_guest_phys_bits()
      *   check/update ucode_rev, phys_bits, guest_phys_bits, mwait
-     *   cpu_common_realizefn() (via xcc->parent_realize)
+     *   cpu_exec_realize() (via xcc->parent_realize)
      */
     if (xcc->max_features) {
         if (enable_cpu_pm) {
Signature · 1 line
2.53.0
#18 lore raw

[PULL 23/56] hw/cpu: Move internal declarations to new 'cpu-internal.h' header

In reply to Philippe Mathieu-Daudé

Some declarations are only used within hw/core/, in particular by the 3 cpu-{common,user,system}.c. Restrict the declarations scope by moving them to a new "cpu-internal.h" local header.

Rename cpu_exec_initfn() -> cpu_exec_init() because we usually have the 'fn' suffix for handler, not API entry point methods.

Message-Id: <[email protected]>

---
 MAINTAINERS            |  1 +
 hw/core/cpu-internal.h | 22 ++++++++++++++++++++++
 include/hw/core/cpu.h  |  6 ------
 hw/core/cpu-common.c   |  3 ++-
 hw/core/cpu-system.c   |  3 ++-
 hw/core/cpu-user.c     |  3 ++-
 6 files changed, 29 insertions(+), 9 deletions(-)
 create mode 100644 hw/core/cpu-internal.h
MAINTAINERS +1 -0
index f249be744e9..c296dd5abfd 100644
@@ -2093,6 +2093,7 @@ Machine core
 M: Philippe Mathieu-Daudé <[email protected]>
 R: Zhao Liu <[email protected]>
 S: Maintained
+F: hw/core/cpu-internal.h
 F: hw/core/cpu-common.c
 F: hw/core/cpu-system.c
 F: hw/core/machine-qmp-cmds.c
hw/core/cpu-internal.h new file +22 -0
new file mode 100644
index 00000000000..ae6a31bca2d
@@ -0,0 +1,22 @@
+/*
+ * QEMU private CPU interface between user / system modes)
+ *
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef HW_CORE_CPU_INTERNAL_H
+#define HW_CORE_CPU_INTERNAL_H
+
+#include "hw/core/qdev.h"
+#include "hw/core/cpu.h"
+
+void cpu_class_init_props(DeviceClass *dc);
+void cpu_exec_class_post_init(CPUClass *cc);
+
+void cpu_exec_init(CPUState *cpu);
+
+void cpu_vmstate_register(CPUState *cpu);
+void cpu_vmstate_unregister(CPUState *cpu);
+
+#endif
include/hw/core/cpu.h +0 -6
index c5064a5449b..6490fb070f2 100644
@@ -1178,12 +1178,6 @@ G_NORETURN void cpu_abort(CPUState *cpu, const char *fmt, ...)
  */
 void qemu_process_cpu_events(CPUState *cpu);
 
-/* $(top_srcdir)/cpu.c */
-void cpu_class_init_props(DeviceClass *dc);
-void cpu_exec_class_post_init(CPUClass *cc);
-void cpu_exec_initfn(CPUState *cpu);
-void cpu_vmstate_register(CPUState *cpu);
-void cpu_vmstate_unregister(CPUState *cpu);
 bool cpu_exec_realizefn(CPUState *cpu, Error **errp);
 void cpu_exec_unrealizefn(CPUState *cpu);
 void cpu_exec_reset_hold(CPUState *cpu);
hw/core/cpu-common.c +2 -1
index 8c9ff25e04a..17d76580930 100644
@@ -39,6 +39,7 @@
 #ifdef CONFIG_PLUGIN
 #include "qemu/plugin.h"
 #endif
+#include "cpu-internal.h"
 
 CPUState *cpu_by_arch_id(int64_t id)
 {
@@ -326,7 +327,7 @@ static void cpu_common_initfn(Object *obj)
     QTAILQ_INIT(&cpu->breakpoints);
     QTAILQ_INIT(&cpu->watchpoints);
 
-    cpu_exec_initfn(cpu);
+    cpu_exec_init(cpu);
 
     /*
      * Plugin initialization must wait until the cpu start executing
hw/core/cpu-system.c +2 -1
index 14eb4ed87f8..8a9f2fcea84 100644
@@ -30,6 +30,7 @@
 #include "hw/core/sysemu-cpu-ops.h"
 #include "migration/vmstate.h"
 #include "system/tcg.h"
+#include "cpu-internal.h"
 
 bool cpu_has_work(CPUState *cpu)
 {
@@ -188,7 +189,7 @@ void cpu_exec_class_post_init(CPUClass *cc)
     g_assert(cc->sysemu_ops->has_work);
 }
 
-void cpu_exec_initfn(CPUState *cpu)
+void cpu_exec_init(CPUState *cpu)
 {
     cpu->memory = get_system_memory();
     object_ref(OBJECT(cpu->memory));
hw/core/cpu-user.c +2 -1
index 25aa25ad240..c2cb00a85d3 100644
@@ -11,6 +11,7 @@
 #include "hw/core/qdev-properties.h"
 #include "hw/core/cpu.h"
 #include "migration/vmstate.h"
+#include "cpu-internal.h"
 
 static const Property cpu_user_props[] = {
     /*
@@ -32,7 +33,7 @@ void cpu_exec_class_post_init(CPUClass *cc)
     /* nothing to do */
 }
 
-void cpu_exec_initfn(CPUState *cpu)
+void cpu_exec_init(CPUState *cpu)
 {
     /* nothing to do */
 }
Signature · 1 line
2.53.0
#19 lore raw

[PULL 20/56] hw/nvme: add SPDM_SOCKET Kconfig dependency

In reply to Philippe Mathieu-Daudé

From: Stefan Hajnoczi <[email protected]>

The NVMe emulation code unconditionally calls spdm_socket_*() APIs. Add a Kconfig dependency to avoid build errors when NVME_PCI is enabled without SPDM_SOCKET.

Fixes 4f947b10d52 ("hw/nvme: Add SPDM over DOE support")

Message-ID: <[email protected]>

---
 hw/nvme/Kconfig | 1 +
 1 file changed, 1 insertion(+)
hw/nvme/Kconfig +1 -0
index cfa2ab0f9d5..cfeeed64cd7 100644
@@ -2,3 +2,4 @@ config NVME_PCI
     bool
     default y if PCI_DEVICES || PCIE_DEVICES
     depends on PCI
+    select SPDM_SOCKET
Signature · 1 line
2.53.0
#20 lore raw

[PULL 21/56] hw/cpu: Correct CPU_GET_CLASS() comment

In reply to Philippe Mathieu-Daudé

commit 0e86d7a71e8 ("cpus: Cache CPUClass early in instance_init() handler") renamed cpu_exec_realizefn() -> cpu_common_initfn(); update the comment.

Message-Id: <[email protected]>

---
 include/hw/core/cpu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/hw/core/cpu.h +1 -1
index b54035fb13b..c5064a5449b 100644
@@ -60,7 +60,7 @@ typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size,
  * expensive given the eventual call to
  * object_class_dynamic_cast_assert(). Because of this the CPUState
  * has a cached value for the class in cs->cc which is set up in
- * cpu_exec_realizefn() for use in hot code paths.
+ * cpu_common_initfn() for use in hot code paths.
  */
 typedef struct CPUClass CPUClass;
 DECLARE_CLASS_CHECKERS(CPUClass, CPU,
Signature · 1 line
2.53.0
#21 lore raw

[PULL 25/56] hw/cpu: Rename cpu_exec_realizefn() -> cpu_common_realize()

In reply to Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Keep cpu_common_*() pattern for publicly exposed common methods used by target code. Use cpu_exec_*() pattern for internal ones, mostly to distinct between system / user mode.

Message-Id: <[email protected]>

---
 include/hw/core/cpu.h      |  3 ++-
 hw/core/cpu-common.c       |  2 +-
 target/alpha/cpu.c         |  2 +-
 target/arm/cpu.c           |  2 +-
 target/avr/cpu.c           |  2 +-
 target/hexagon/cpu.c       |  2 +-
 target/hppa/cpu.c          |  2 +-
 target/i386/cpu.c          | 10 +++++-----
 target/i386/kvm/kvm-cpu.c  |  2 +-
 target/loongarch/cpu.c     |  2 +-
 target/m68k/cpu.c          |  2 +-
 target/microblaze/cpu.c    |  2 +-
 target/mips/cpu.c          |  2 +-
 target/or1k/cpu.c          |  2 +-
 target/ppc/cpu_init.c      |  2 +-
 target/riscv/cpu.c         |  2 +-
 target/riscv/kvm/kvm-cpu.c |  2 +-
 target/riscv/tcg/tcg-cpu.c |  2 +-
 target/rx/cpu.c            |  2 +-
 target/s390x/cpu.c         |  2 +-
 target/sh4/cpu.c           |  2 +-
 target/sparc/cpu.c         |  2 +-
 target/tricore/cpu.c       |  2 +-
 target/xtensa/cpu.c        |  2 +-
 24 files changed, 29 insertions(+), 28 deletions(-)
include/hw/core/cpu.h +2 -1
index 6490fb070f2..7b7cf330cde 100644
@@ -1178,7 +1178,8 @@ G_NORETURN void cpu_abort(CPUState *cpu, const char *fmt, ...)
  */
 void qemu_process_cpu_events(CPUState *cpu);
 
-bool cpu_exec_realizefn(CPUState *cpu, Error **errp);
+/** cpu_common_realize: CPU DeviceRealize common handler */
+bool cpu_common_realize(CPUState *cpu, Error **errp);
 void cpu_exec_unrealizefn(CPUState *cpu);
 void cpu_exec_reset_hold(CPUState *cpu);
 
hw/core/cpu-common.c +1 -1
index 33e349d4402..732e32fade2 100644
@@ -230,7 +230,7 @@ const char *parse_cpu_option(const char *cpu_option)
     return cpu_type;
 }
 
-bool cpu_exec_realizefn(CPUState *cpu, Error **errp)
+bool cpu_common_realize(CPUState *cpu, Error **errp)
 {
     if (!accel_cpu_common_realize(cpu, errp)) {
         return false;
target/alpha/cpu.c +1 -1
index 0c35067b202..12e86021663 100644
@@ -117,7 +117,7 @@ static void alpha_cpu_realizefn(DeviceState *dev, Error **errp)
     cs->tcg_cflags |= CF_PCREL;
 #endif
 
-    cpu_exec_realizefn(cs, &local_err);
+    cpu_common_realize(cs, &local_err);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
         return;
target/arm/cpu.c +1 -1
index 787e4dc7ab2..77aa78f00e2 100644
@@ -1891,7 +1891,7 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
     }
 #endif
 
-    cpu_exec_realizefn(cs, &local_err);
+    cpu_common_realize(cs, &local_err);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
         return;
target/avr/cpu.c +1 -1
index 35912192126..f8409f32ab9 100644
@@ -131,7 +131,7 @@ static void avr_cpu_realizefn(DeviceState *dev, Error **errp)
     AVRCPUClass *mcc = AVR_CPU_GET_CLASS(dev);
     Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
+    cpu_common_realize(cs, &local_err);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
         return;
target/hexagon/cpu.c +1 -1
index 0ddd898e6e9..7067e5b70f7 100644
@@ -457,7 +457,7 @@ static void hexagon_cpu_realize(DeviceState *dev, Error **errp)
     HexagonCPUClass *mcc = HEXAGON_CPU_GET_CLASS(dev);
     Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
+    cpu_common_realize(cs, &local_err);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
         return;
target/hppa/cpu.c +1 -1
index a68152f9682..07b49e51326 100644
@@ -181,7 +181,7 @@ static void hppa_cpu_realizefn(DeviceState *dev, Error **errp)
     HPPACPUClass *acc = HPPA_CPU_GET_CLASS(dev);
     Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
+    cpu_common_realize(cs, &local_err);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
         return;
target/i386/cpu.c +5 -5
index 7a2c3cf358d..e5ffb10d156 100644
@@ -10164,7 +10164,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
      * These may be set by the accel-specific code,
      * and the results are subsequently checked / assumed in this function.
      */
-    cpu_exec_realizefn(cs, &local_err);
+    cpu_common_realize(cs, &local_err);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
         return;
@@ -10179,7 +10179,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
     if (cpu->guest_phys_bits == -1) {
         /*
          * If it was not set by the user, or by the accelerator via
-         * cpu_exec_realizefn, clear.
+         * cpu_common_realize, clear.
          */
         cpu->guest_phys_bits = 0;
     }
@@ -10188,7 +10188,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
         /*
          * The default is the same as KVM's. Note that this check
          * needs to happen after the evenual setting of ucode_rev in
-         * accel-specific code in cpu_exec_realizefn.
+         * accel-specific code in cpu_common_realize.
          */
         if (IS_AMD_CPU(env)) {
             cpu->ucode_rev = 0x01000065;
@@ -10201,7 +10201,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
      * mwait extended info: needed for Core compatibility
      * We always wake on interrupt even if host does not have the capability.
      *
-     * requires the accel-specific code in cpu_exec_realizefn to
+     * requires the accel-specific code in cpu_common_realize to
      * have already acquired the CPUID data into cpu->mwait.
      */
     cpu->mwait.ecx |= CPUID_MWAIT_EMX | CPUID_MWAIT_IBE;
@@ -10230,7 +10230,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
      * Note that this code assumes features expansion has already been done
      * (as it checks for CPUID_EXT2_LM), and also assumes that potential
      * phys_bits adjustments to match the host have been already done in
-     * accel-specific code in cpu_exec_realizefn.
+     * accel-specific code in cpu_common_realize.
      */
     if (env->features[FEAT_8000_0001_EDX] & CPUID_EXT2_LM) {
         if (cpu->phys_bits && cpu->phys_bits < 32) {
target/i386/kvm/kvm-cpu.c +1 -1
index e164cef2036..da8d77ade06 100644
@@ -57,7 +57,7 @@ static bool kvm_cpu_realizefn(CPUState *cs, Error **errp)
      *
      * x86_cpu_realizefn():
      *   x86_cpu_expand_features()
-     *   cpu_exec_realizefn():
+     *   cpu_common_realize():
      *      accel_cpu_common_realize()
      *        kvm_cpu_realizefn()
      *          host_cpu_realizefn()
target/loongarch/cpu.c +1 -1
index fb03424ffa8..cb07f15110f 100644
@@ -704,7 +704,7 @@ static void loongarch_cpu_realizefn(DeviceState *dev, Error **errp)
     LoongArchCPUClass *lacc = LOONGARCH_CPU_GET_CLASS(dev);
     Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
+    cpu_common_realize(cs, &local_err);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
         return;
target/m68k/cpu.c +1 -1
index 9ad3057d91c..ce2707dee5a 100644
@@ -389,7 +389,7 @@ static void m68k_cpu_realizefn(DeviceState *dev, Error **errp)
 
     register_m68k_insns(&cpu->env);
 
-    cpu_exec_realizefn(cs, &local_err);
+    cpu_common_realize(cs, &local_err);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
         return;
target/microblaze/cpu.c +1 -1
index a97c92a7b68..389a5124b12 100644
@@ -251,7 +251,7 @@ static void mb_cpu_realizefn(DeviceState *dev, Error **errp)
     int i = 0;
     Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
+    cpu_common_realize(cs, &local_err);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
         return;
target/mips/cpu.c +1 -1
index d72044aef61..669c7d99bb7 100644
@@ -544,7 +544,7 @@ static void mips_cpu_realizefn(DeviceState *dev, Error **errp)
     }
     mips_cp0_period_set(cpu);
 
-    cpu_exec_realizefn(cs, &local_err);
+    cpu_common_realize(cs, &local_err);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
         return;
target/or1k/cpu.c +1 -1
index ea29b2e01fa..66c00c0930c 100644
@@ -170,7 +170,7 @@ static void openrisc_cpu_realizefn(DeviceState *dev, Error **errp)
     OpenRISCCPUClass *occ = OPENRISC_CPU_GET_CLASS(dev);
     Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
+    cpu_common_realize(cs, &local_err);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
         return;
target/ppc/cpu_init.c +1 -1
index f404c7e549d..b07e9c3ff9c 100644
@@ -6921,7 +6921,7 @@ static void ppc_cpu_realize(DeviceState *dev, Error **errp)
     PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
     Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
+    cpu_common_realize(cs, &local_err);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
         return;
target/riscv/cpu.c +1 -1
index 5a82e6563bf..23b5023dd37 100644
@@ -1226,7 +1226,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
     RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(dev);
     Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
+    cpu_common_realize(cs, &local_err);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
         return;
target/riscv/kvm/kvm-cpu.c +1 -1
index 495cb42dc89..97069bf597a 100644
@@ -2006,7 +2006,7 @@ static void kvm_cpu_instance_init(CPUState *cs)
  * We'll get here via the following path:
  *
  * riscv_cpu_realize()
- *   -> cpu_exec_realizefn()
+ *   -> cpu_common_realize()
  *      -> kvm_cpu_realize() (via accel_cpu_common_realize())
  */
 static bool kvm_cpu_realize(CPUState *cs, Error **errp)
target/riscv/tcg/tcg-cpu.c +1 -1
index 4af5cd9c731..9e3cc87f8a3 100644
@@ -1304,7 +1304,7 @@ static void riscv_cpu_set_profile(RISCVCPU *cpu,
  * We'll get here via the following path:
  *
  * riscv_cpu_realize()
- *   -> cpu_exec_realizefn()
+ *   -> cpu_common_realize()
  *      -> tcg_cpu_realize() (via accel_cpu_common_realize())
  */
 static bool riscv_tcg_cpu_realize(CPUState *cs, Error **errp)
target/rx/cpu.c +1 -1
index 20b188c24cd..9b8473d71cf 100644
@@ -147,7 +147,7 @@ static void rx_cpu_realize(DeviceState *dev, Error **errp)
     RXCPUClass *rcc = RX_CPU_GET_CLASS(dev);
     Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
+    cpu_common_realize(cs, &local_err);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
         return;
target/s390x/cpu.c +1 -1
index c074e12ba2d..641ea96c8ea 100644
@@ -249,7 +249,7 @@ static void s390_cpu_realizefn(DeviceState *dev, Error **errp)
     }
 #endif
 
-    cpu_exec_realizefn(cs, &err);
+    cpu_common_realize(cs, &err);
     if (err != NULL) {
         goto out;
     }
target/sh4/cpu.c +1 -1
index 763424695c6..ad2ec28c1b7 100644
@@ -250,7 +250,7 @@ static void superh_cpu_realizefn(DeviceState *dev, Error **errp)
     SuperHCPUClass *scc = SUPERH_CPU_GET_CLASS(dev);
     Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
+    cpu_common_realize(cs, &local_err);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
         return;
target/sparc/cpu.c +1 -1
index 13ebb122a38..1bc14b586bb 100644
@@ -892,7 +892,7 @@ static void sparc_cpu_realizefn(DeviceState *dev, Error **errp)
     /* Default NaN value: sign bit clear, all frac bits set */
     set_float_default_nan_pattern(0b01111111, &env->fp_status);
 
-    cpu_exec_realizefn(cs, &local_err);
+    cpu_common_realize(cs, &local_err);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
         return;
target/tricore/cpu.c +1 -1
index 472c24ae32d..96e2817dee7 100644
@@ -99,7 +99,7 @@ static void tricore_cpu_realizefn(DeviceState *dev, Error **errp)
     CPUTriCoreState *env = &cpu->env;
     Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
+    cpu_common_realize(cs, &local_err);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
         return;
target/xtensa/cpu.c +1 -1
index 2015a4e3d0d..7c25b9ab707 100644
@@ -257,7 +257,7 @@ static void xtensa_cpu_realizefn(DeviceState *dev, Error **errp)
     xtensa_irq_init(&XTENSA_CPU(dev)->env);
 #endif
 
-    cpu_exec_realizefn(cs, &local_err);
+    cpu_common_realize(cs, &local_err);
     if (local_err != NULL) {
         error_propagate(errp, local_err);
         return;
Signature · 1 line
2.53.0
#22 lore raw

[PULL 16/56] hw/i386/pc: xen: reinstate the "xenfv" machine alias

In reply to Philippe Mathieu-Daudé

From: Dario Faggioli <[email protected]>

Commit 7d2778dea32a4924a469f1cc5767042c8f5b4eea ("hw/i386/pc:
Remove deprecated pc-q35/pc-i440fx/xenfv 3.1 machines") removed the Xen machine type that was providing the "xenfv" alias. As a consequence, since the tools are apparently relying on such alias, we're getting this, as soon as one tries to start a Xen (HVM) VM:

qemu-system-i386: unsupported machine type: "xenfv" Use -machine help to list supported machines

Reinstate the alias and let it point to the only Xen machine we still have.

Fixes 7d2778dea3 Remove deprecated pc-q35/pc-i440fx/xenfv 3.1 machines

Message-ID: <[email protected]>

---
 hw/i386/pc_piix.c | 1 +
 1 file changed, 1 insertion(+)
hw/i386/pc_piix.c +1 -0
index 223a19cc4bb..a929cc4decd 100644
@@ -667,6 +667,7 @@ static void xenfv_machine_4_2_options(MachineClass *m)
 {
     pc_i440fx_machine_4_2_options(m);
     m->desc = "Xen Fully-virtualized PC";
+    m->alias = "xenfv";
     m->max_cpus = HVM_MAX_VCPUS;
     m->default_machine_opts = "accel=xen,suppress-vmdesc=on";
 }
Signature · 1 line
2.53.0
#23 lore raw

[PULL 22/56] hw/cpu: Include missing 'qemu/accel.h' header

In reply to Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

cpu_common_realize() calls accel_cpu_common_realize(), itself declared in "qemu/accel.h". Include the latter, otherwise we get when refactoring unrelated headers:

hw/core/cpu-common.c:233:10: error: implicit declaration of function ‘accel_cpu_common_realize’

    233 |     if (!accel_cpu_common_realize(cpu, errp)) {
        |          ^~~~~~~~~~~~~~~~~~~~~~~~

Message-Id: <[email protected]>

---
 hw/core/cpu-common.c | 1 +
 1 file changed, 1 insertion(+)
hw/core/cpu-common.c +1 -0
index e314f916f84..8c9ff25e04a 100644
@@ -23,6 +23,7 @@
 #include "qapi/error.h"
 #include "hw/core/cpu.h"
 #include "system/hw_accel.h"
+#include "qemu/accel.h"
 #include "qemu/log.h"
 #include "qemu/main-loop.h"
 #include "qemu/lockcnt.h"
Signature · 1 line
2.53.0
#24 lore raw

[PULL 15/56] hw/qdev: Parent device before setting parent bus

In reply to Philippe Mathieu-Daudé

From: Akihiko Odaki <[email protected]>

Commit 9940b2cfbc05 ("qdev: New qdev_new(), qdev_realize(), etc.") says "device state 'no QOM parent, but plugged into bus' is dangerous". In such a case, unrealizing the bus will hang in bus_unparent():

    while ((kid = QTAILQ_FIRST(&bus->children)) != NULL) {
        DeviceState *dev = kid->child;
        object_unparent(OBJECT(dev));
    }

object_unparent() does nothing when its argument has no QOM parent, and the loop spins forever.

However, that commit did not completely eliminate such a situation. When the device is not parented, device_set_realized() lets /machine/unattached parent it, but it happens after setting parent bus. Therefore, any failure between the two operations can leave the device in a dangerous state.

qdev_realize() at least asserts that the device is not already realized and prevents one realization failure pattern, but it is not comprehensive. Besides, it will trip with a command line like the following:

    qemu-system-x86_64 -M none -nodefaults -nographic \
        -device ipmi-bmc-sim,realized=on

Eliminate the dangerous state by ensuring that the device is parented before calling qdev_set_parent_bus(). Also, stop asserting that the device is not already realized in qdev_realize(); it is broken and no longer serves any purpose.

Fixes 9940b2cfbc05 ("qdev: New qdev_new(), qdev_realize(), etc.")

Message-ID: <[email protected]>

---
 hw/core/qdev.c         | 51 ++++++++++++++++++++++++------------------
 tests/unit/test-qdev.c | 13 +++++++++++
 2 files changed, 42 insertions(+), 22 deletions(-)
hw/core/qdev.c +29 -22
index e2aab3d1fc6..0b0f2f47fa7 100644
@@ -264,17 +264,43 @@ static void device_reset_child_foreach(Object *obj, ResettableChildCallback cb,
 
 bool qdev_realize(DeviceState *dev, BusState *bus, Error **errp)
 {
-    assert(!dev->realized && !dev->parent_bus);
+    static int unattached_count;
+    bool unattached_parent = false;
+
+    assert(!dev->parent_bus);
+
+    if (!OBJECT(dev)->parent) {
+        gchar *name = g_strdup_printf("device[%d]", unattached_count++);
+
+        object_property_add_child(machine_get_container("unattached"),
+                                  name, OBJECT(dev));
+        unattached_parent = true;
+        g_free(name);
+    }
 
     if (bus) {
         if (!qdev_set_parent_bus(dev, bus, errp)) {
-            return false;
+            goto fail;
         }
     } else {
         assert(!DEVICE_GET_CLASS(dev)->bus_type);
     }
 
-    return object_property_set_bool(OBJECT(dev), "realized", true, errp);
+    if (object_property_set_bool(OBJECT(dev), "realized", true, errp)) {
+        return true;
+    }
+
+fail:
+    if (unattached_parent) {
+        /*
+         * Beware, this doesn't just revert
+         * object_property_add_child(), it also runs bus_remove()!
+         */
+        object_unparent(OBJECT(dev));
+        unattached_count--;
+    }
+
+    return false;
 }
 
 bool qdev_realize_and_unref(DeviceState *dev, BusState *bus, Error **errp)
@@ -479,8 +505,6 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
     BusState *bus;
     NamedClockList *ncl;
     Error *local_err = NULL;
-    bool unattached_parent = false;
-    static int unattached_count;
 
     if (dev->hotplugged && !dc->hotpluggable) {
         error_setg(errp, "Device '%s' does not support hotplugging",
@@ -493,15 +517,6 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
             goto fail;
         }
 
-        if (!obj->parent) {
-            gchar *name = g_strdup_printf("device[%d]", unattached_count++);
-
-            object_property_add_child(machine_get_container("unattached"),
-                                      name, obj);
-            unattached_parent = true;
-            g_free(name);
-        }
-
         hotplug_ctrl = qdev_get_hotplug_handler(dev);
         if (hotplug_ctrl) {
             hotplug_handler_pre_plug(hotplug_ctrl, dev, &local_err);
@@ -627,14 +642,6 @@ post_realize_fail:
 
 fail:
     error_propagate(errp, local_err);
-    if (unattached_parent) {
-        /*
-         * Beware, this doesn't just revert
-         * object_property_add_child(), it also runs bus_remove()!
-         */
-        object_unparent(OBJECT(dev));
-        unattached_count--;
-    }
 }
 
 static bool device_get_hotpluggable(Object *obj, Error **errp)
tests/unit/test-qdev.c +13 -0
index 20eae38e03f..77c3eee7171 100644
@@ -78,6 +78,16 @@ static void test_qdev_free_properties(void)
     object_unref(mt);
 }
 
+static void test_qdev_double_realization(void)
+{
+    MyDev *mt = STATIC_TYPE(object_new(TYPE_MY_DEV));
+
+    qdev_realize(DEVICE(mt), NULL, &error_fatal);
+    qdev_realize(DEVICE(mt), NULL, &error_fatal);
+    object_unparent(OBJECT(mt));
+    object_unref(OBJECT(mt));
+}
+
 
 int main(int argc, char **argv)
 {
@@ -90,6 +100,9 @@ int main(int argc, char **argv)
     g_test_add_func("/qdev/free-properties",
                     test_qdev_free_properties);
 
+    g_test_add_func("/qdev/double-realization",
+                    test_qdev_double_realization);
+
     g_test_run();
 
     return 0;
Signature · 1 line
2.53.0
#25 lore raw

[PULL 27/56] hw/cpu: Extract cpu_exec_realize() out of cpu_common_realizefn()

In reply to Philippe Mathieu-Daudé

cpu_common_realizefn() contains code only used by system mode emulation. Extract it to a new cpu_exec_realize() helper. In the next commit this helper will be moved to cpu-system.c where it belongs.

Message-Id: <[email protected]>

---
 hw/core/cpu-common.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
hw/core/cpu-common.c +8 -4
index 59cd489b713..cd7c8763cf5 100644
@@ -246,9 +246,8 @@ bool cpu_common_realize(CPUState *cpu, Error **errp)
     return true;
 }
 
-static void cpu_exec_realize(DeviceState *dev, Error **errp)
+static void cpu_exec_realize(CPUState *cpu, Error **errp)
 {
-    CPUState *cpu = CPU(dev);
     Object *machine = qdev_get_machine();
 
     /* qdev_get_machine() can return something that's not TYPE_MACHINE
@@ -264,10 +263,15 @@ static void cpu_exec_realize(DeviceState *dev, Error **errp)
         }
     }
 
-    if (dev->hotplugged) {
+    if (DEVICE(cpu)->hotplugged) {
         cpu_synchronize_post_init(cpu);
         cpu_resume(cpu);
     }
+}
+
+static void cpu_common_realizefn(DeviceState *dev, Error **errp)
+{
+    cpu_exec_realize(CPU(dev), errp);
 
     /* NOTE: latest generic point where the cpu is fully realized */
 }
@@ -379,7 +383,7 @@ static void cpu_common_class_init(ObjectClass *klass, const void *data)
     k->gdb_read_register = cpu_common_gdb_read_register;
     k->gdb_write_register = cpu_common_gdb_write_register;
     set_bit(DEVICE_CATEGORY_CPU, dc->categories);
-    dc->realize = cpu_exec_realize;
+    dc->realize = cpu_common_realizefn;
     dc->unrealize = cpu_common_unrealizefn;
     rc->phases.hold = cpu_common_reset_hold;
     rc->phases.exit = cpu_common_reset_exit;
Signature · 1 line
2.53.0
#26 lore raw

[PULL 19/56] hw/block/pflash_cfi01: Restore ROMD mode after migration

In reply to Philippe Mathieu-Daudé

From: Bin Guo <[email protected]>

pflash_post_load() did not restore the ROMD mode of the memory region. Although cmd and wcycle are migrated, the destination retains the default ROMD = true from realize. When the source was in a non-array mode (e.g. ID read, cmd = 0x90), reads on the destination bypass pflash_read() via the ROM fast path and return raw storage bytes instead of the command-specific response.

Derive ROMD from the migrated cmd/wcycle in pflash_post_load.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4042

[PMD: Including review comments from
https://lore.kernel.org/qemu-devel/CAFEAcA-P6RH7nJK0KQ1H8576ULFA7nocB0EkhhZf6Rw3g0WCag@mail.gmail.com/

Confirming that this is correct is a bit tricky. It relies on:
* when we set romd mode to true we also set wcycle = 0, cmd = 0 (which we do, in reset and in the mode_read_array code)
* when we set romd mode to false at the top of pflash_write(), all paths out of that function either go through the mode_read_array path, or else update pfl->cmd to something non-zero
* nowhere outside pflash_write() udpates cmd or wcycle except for the "clear them to 0 and set romd mode" places

This is almost but not quite true. In pflash_read(), the default case for the pfl->cmd switch sets wcycle = 0 cmd = 0 but doesn't change the romd state. Luckily the "this should never happen" comment is true -- there's no way to get a pfl->cmd that falls into the default (except for being deliberately fed a bogus value via inbound migration).
]
Message-ID: <[email protected]>

---
 hw/block/pflash_cfi01.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
hw/block/pflash_cfi01.c +10 -0
index 5b9ddb20b18..a13b91967ed 100644
@@ -1030,6 +1030,16 @@ static int pflash_post_load(void *opaque, int version_id)
 {
     PFlashCFI01 *pfl = opaque;
 
+    /*
+     * ROMD mode is not in the VMState; derive it from the migrated
+     * cmd and wcycle.  Only (wcycle == 0, cmd == 0x00) is read-array.
+     */
+    if (pfl->wcycle == 0 && pfl->cmd == 0x00) {
+        memory_region_rom_device_set_romd(&pfl->mem, true);
+    } else {
+        memory_region_rom_device_set_romd(&pfl->mem, false);
+    }
+
     if (!pfl->ro) {
         pfl->vmstate = qemu_add_vm_change_state_handler(postload_update_cb,
                                                         pfl);
Signature · 1 line
2.53.0
#27 lore raw

[PULL 30/56] hw/s390x/virtio-ccw: Always inject NMI to first CPU

In reply to Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

We can trigger NMI from HMP or QMP.

QEMU maps the NMI to the s390x per-CPU 'RESTART' interrupt. Linux guests usually setup this interrupt to trigger kdump or crash. Such crashdump can be triggered in QEMU by HMP "nmi" or QMP "inject-nmi" commands.

Using QMP, since we can not select a particular CPU, the first CPU is used (CPU#0). See the documentation from commit 795dc6e4 ("watchdog: Add new Virtual Watchdog action INJECT-NMI"):

@inject-nmi: a non-maskable interrupt is injected into the
first VCPU (all VCPUS on x86) (since 2.4)

While we can select a particular CPU on HMP, the guest behavior is expected to be the same if using CPU #N or CPU #0. Since always using CPU#0 simplifies API maintenance , update s390_nmi() to inject NMI to the first CPU.

Message-Id: <[email protected]>

---
 qapi/machine.json          | 7 ++++---
 qapi/run-state.json        | 6 ++++--
 hw/s390x/s390-virtio-ccw.c | 4 +---
 hmp-commands.hx            | 5 +++--
 4 files changed, 12 insertions(+), 10 deletions(-)
qapi/machine.json +4 -3
index 9b2248038fc..2d63c1bac3b 100644
@@ -432,9 +432,10 @@
 ##
 # @inject-nmi:
 #
-# Injects a Non-Maskable Interrupt into the default CPU (x86/s390) or
-# all CPUs (ppc64).  The command fails when the guest doesn't support
-# injecting.
+# Injects a Non-Maskable Interrupt (machine specific: for example on
+# s390x CCW only the first vCPU receives the NMI, but on x86 machines
+# all vCPUs receive it).  The command fails when the guest doesn't
+# support injecting.
 #
 # Since: 0.14
 #
qapi/run-state.json +4 -2
index a5771ad4681..e4fdead1e0b 100644
@@ -317,8 +317,10 @@
 #
 # @none: nothing is done
 #
-# @inject-nmi: a non-maskable interrupt is injected into the first
-#     VCPU (all VCPUS on x86) (since 2.4)
+# @inject-nmi: a non-maskable interrupt is injected (machine
+#     specific: for example on s390x CCW only the first vCPU
+#     receives the NMI, but on x86 machines all vCPUs receive
+#     it).  (since 2.4)
 #
 # Since: 2.1
 ##
hw/s390x/s390-virtio-ccw.c +1 -3
index 55131c1a444..a2f373b1190 100644
@@ -727,9 +727,7 @@ static HotplugHandler *s390_get_hotplug_handler(MachineState *machine,
 
 static void s390_nmi(NMIState *n, int cpu_index, Error **errp)
 {
-    CPUState *cs = qemu_get_cpu(cpu_index);
-
-    s390_cpu_restart(S390_CPU(cs));
+    s390_cpu_restart(S390_CPU(first_cpu));
 }
 
 static inline bool machine_get_aes_key_wrap(Object *obj, Error **errp)
hmp-commands.hx +3 -2
index 7f43cf537fc..a29f02b623e 100644
@@ -865,12 +865,13 @@ ERST
         .name       = "nmi",
         .args_type  = "",
         .params     = "",
-        .help       = "inject an NMI",
+        .help       = "Inject an NMI, in a machine-specific way",
         .cmd        = hmp_nmi,
     },
 SRST
 ``nmi`` *cpu*
-  Inject an NMI on the default CPU (x86/s390) or all CPUs (ppc64).
+  Inject an NMI, in a machine-specific way.
+  Not all machines implement NMI handling.
 ERST
 
     {
Signature · 1 line
2.53.0
#28 lore raw

[PULL 28/56] hw/cpu: Move system-specific cpu_exec_realize() to cpu-system.c

In reply to Philippe Mathieu-Daudé

Current cpu_exec_realize() body only contains system-mode related code. Move that method out of cpu-common.c to cpu-system.c, removing the system / machine mentions in this common file. Add an empty stub for user-mode.

Message-Id: <[email protected]>

---
 hw/core/cpu-internal.h |  1 +
 hw/core/cpu-common.c   | 24 ------------------------
 hw/core/cpu-system.c   | 27 +++++++++++++++++++++++++++
 hw/core/cpu-user.c     |  5 +++++
 4 files changed, 33 insertions(+), 24 deletions(-)
hw/core/cpu-internal.h +1 -0
index ae6a31bca2d..44715b44329 100644
@@ -15,6 +15,7 @@ void cpu_class_init_props(DeviceClass *dc);
 void cpu_exec_class_post_init(CPUClass *cc);
 
 void cpu_exec_init(CPUState *cpu);
+void cpu_exec_realize(CPUState *cpu, Error **errp);
 
 void cpu_vmstate_register(CPUState *cpu);
 void cpu_vmstate_unregister(CPUState *cpu);
hw/core/cpu-common.c +0 -24
index cd7c8763cf5..4f4c87f33a0 100644
@@ -33,7 +33,6 @@
 #include "exec/log.h"
 #include "exec/gdbstub.h"
 #include "system/tcg.h"
-#include "hw/core/boards.h"
 #include "hw/core/qdev-properties.h"
 #include "trace.h"
 #ifdef CONFIG_PLUGIN
@@ -246,29 +245,6 @@ bool cpu_common_realize(CPUState *cpu, Error **errp)
     return true;
 }
 
-static void cpu_exec_realize(CPUState *cpu, Error **errp)
-{
-    Object *machine = qdev_get_machine();
-
-    /* qdev_get_machine() can return something that's not TYPE_MACHINE
-     * if this is one of the user-only emulators; in that case there's
-     * no need to check the ignore_memory_transaction_failures board flag.
-     */
-    if (object_dynamic_cast(machine, TYPE_MACHINE)) {
-        MachineClass *mc = MACHINE_GET_CLASS(machine);
-
-        if (mc) {
-            cpu->ignore_memory_transaction_failures =
-                mc->ignore_memory_transaction_failures;
-        }
-    }
-
-    if (DEVICE(cpu)->hotplugged) {
-        cpu_synchronize_post_init(cpu);
-        cpu_resume(cpu);
-    }
-}
-
 static void cpu_common_realizefn(DeviceState *dev, Error **errp)
 {
     cpu_exec_realize(CPU(dev), errp);
hw/core/cpu-system.c +27 -0
index 8a9f2fcea84..a64e8c2b687 100644
@@ -25,10 +25,12 @@
 #include "exec/target_page.h"
 #include "system/memory.h"
 #include "qemu/target-info.h"
+#include "hw/core/boards.h"
 #include "hw/core/qdev.h"
 #include "hw/core/qdev-properties.h"
 #include "hw/core/sysemu-cpu-ops.h"
 #include "migration/vmstate.h"
+#include "system/hw_accel.h"
 #include "system/tcg.h"
 #include "cpu-internal.h"
 
@@ -221,6 +223,31 @@ static int cpu_common_pre_load(void *opaque)
     return 0;
 }
 
+void cpu_exec_realize(CPUState *cpu, Error **errp)
+{
+    Object *machine = qdev_get_machine();
+
+    /*
+     * qdev_get_machine() can return something that's not TYPE_MACHINE
+     * if this is one of the user-only emulators; in that case there's
+     * no need to check the ignore_memory_transaction_failures board flag.
+     */
+    if (object_dynamic_cast(machine, TYPE_MACHINE)) {
+        MachineClass *mc = MACHINE_GET_CLASS(machine);
+
+        if (mc) {
+            cpu->ignore_memory_transaction_failures =
+                mc->ignore_memory_transaction_failures;
+        }
+    }
+
+    if (DEVICE(cpu)->hotplugged) {
+        cpu_synchronize_post_init(cpu);
+        cpu_resume(cpu);
+    }
+
+}
+
 static bool cpu_common_exception_index_needed(void *opaque)
 {
     CPUState *cpu = opaque;
hw/core/cpu-user.c +5 -0
index c2cb00a85d3..1e38c88f9bd 100644
@@ -38,6 +38,11 @@ void cpu_exec_init(CPUState *cpu)
     /* nothing to do */
 }
 
+void cpu_exec_realize(CPUState *cpu, Error **errp)
+{
+    /* nothing to do */
+}
+
 void cpu_vmstate_register(CPUState *cpu)
 {
     assert(qdev_get_vmsd(DEVICE(cpu)) == NULL ||
Signature · 1 line
2.53.0
#29 lore raw

[PULL 26/56] hw/cpu: Rename cpu_exec_unrealizefn() -> cpu_common_unrealize()

In reply to Philippe Mathieu-Daudé

Keep cpu_common_*() pattern for publicly exposed common methods used by target code. Use cpu_exec_*() pattern for internal ones, mostly to distinct between system / user mode.

Message-Id: <[email protected]>

---
 include/hw/core/cpu.h | 4 +++-
 hw/core/cpu-common.c  | 4 ++--
 target/ppc/cpu_init.c | 2 +-
 3 files changed, 6 insertions(+), 4 deletions(-)
include/hw/core/cpu.h +3 -1
index 7b7cf330cde..81af7b9ee1a 100644
@@ -1180,7 +1180,9 @@ void qemu_process_cpu_events(CPUState *cpu);
 
 /** cpu_common_realize: CPU DeviceRealize common handler */
 bool cpu_common_realize(CPUState *cpu, Error **errp);
-void cpu_exec_unrealizefn(CPUState *cpu);
+/** cpu_common_realize: CPU DeviceUnrealize common handler */
+void cpu_common_unrealize(CPUState *cpu);
+
 void cpu_exec_reset_hold(CPUState *cpu);
 
 extern const VMStateDescription vmstate_cpu_common;
hw/core/cpu-common.c +2 -2
index 732e32fade2..59cd489b713 100644
@@ -284,10 +284,10 @@ static void cpu_common_unrealizefn(DeviceState *dev)
 #endif
 
     /* NOTE: latest generic point before the cpu is fully unrealized */
-    cpu_exec_unrealizefn(cpu);
+    cpu_common_unrealize(cpu);
 }
 
-void cpu_exec_unrealizefn(CPUState *cpu)
+void cpu_common_unrealize(CPUState *cpu)
 {
     cpu_vmstate_unregister(cpu);
 
target/ppc/cpu_init.c +1 -1
index b07e9c3ff9c..e3a1075aad3 100644
@@ -6956,7 +6956,7 @@ static void ppc_cpu_realize(DeviceState *dev, Error **errp)
     return;
 
 unrealize:
-    cpu_exec_unrealizefn(cs);
+    cpu_common_unrealize(cs);
 }
 
 static void ppc_cpu_unrealize(DeviceState *dev)
Signature · 1 line
2.53.0
#30 lore raw

[PULL 29/56] hw/nmi: Use object_child_foreach_recursive() in nmi_children()

In reply to Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Replace object_child_foreach() and recursion by a single object_child_foreach_recursive() call. Propagate the returned value so callers can check it.

Message-Id: <[email protected]>

---
 hw/core/nmi.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
hw/core/nmi.c +4 -8
index 4b447e126ba..22724046575 100644
@@ -31,8 +31,6 @@ struct do_nmi_s {
     bool handled;
 };
 
-static void nmi_children(Object *o, struct do_nmi_s *ns);
-
 static int do_nmi(Object *o, void *opaque)
 {
     struct do_nmi_s *ns = opaque;
@@ -47,14 +45,13 @@ static int do_nmi(Object *o, void *opaque)
             return -1;
         }
     }
-    nmi_children(o, ns);
 
     return 0;
 }
 
-static void nmi_children(Object *o, struct do_nmi_s *ns)
+static int nmi_children(Object *o, struct do_nmi_s *ns)
 {
-    object_child_foreach(o, do_nmi, ns);
+    return object_child_foreach_recursive(o, do_nmi, ns);
 }
 
 void nmi_monitor_handle(int cpu_index, Error **errp)
@@ -65,10 +62,9 @@ void nmi_monitor_handle(int cpu_index, Error **errp)
         .handled = false
     };
 
-    nmi_children(object_get_root(), &ns);
-    if (ns.handled) {
+    if (nmi_children(object_get_root(), &ns)) {
         error_propagate(errp, ns.err);
-    } else {
+    } else if (!ns.handled) {
         error_setg(errp, "machine does not provide NMIs");
     }
 }
Signature · 1 line
2.53.0
#31 lore raw

[PULL 32/56] hw/nmi: Remove @cpu_index argument from nmi_inject()

In reply to Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

nmi_monitor_handle() is not related to the monitor, rename it as nmi_inject().

Return a boolean value indicating success / failure as recommended by the Error API since commit e3fe3988d7 ("error: Document Error API usage rules").

The 'cpu_index' argument is not used, remove it. This officially drops the current CPU for HMP command.

Document nmi_inject() as suggested by Peter Maydell in
https://lore.kernel.org/qemu-devel/CAFEAcA-yALySmCJLbitCmYpiZKUXJNOavGJG9RYeo8fKqz7gcw@mail.gmail.com/.

Message-Id: <[email protected]>

---
 include/hw/core/nmi.h  | 24 +++++++++++++++++++++++-
 hw/core/nmi.c          |  9 ++++-----
 hw/ipmi/ipmi.c         |  3 +--
 hw/watchdog/watchdog.c |  2 +-
 system/cpus.c          |  3 +--
 hmp-commands.hx        |  2 +-
 6 files changed, 31 insertions(+), 12 deletions(-)
include/hw/core/nmi.h +23 -1
index 4c4ce79071d..851be28257e 100644
@@ -46,6 +46,28 @@ struct NMIClass {
     void (*nmi_monitor_handler)(NMIState *ns, Error **errp);
 };
 
-void nmi_monitor_handle(int cpu_index, Error **errp);
+/**
+ * nmi_inject: Inject an NMI, in a machine-specific way
+ * @errp: pointer to error object
+ *
+ * This function injects an NMI, in a machine-specific way. The
+ * intention is that this should typically trigger a guest kernel
+ * dump or reboot, and might happen as a result of user request
+ * from the monitor, watchdog timeouts, and similar events.
+ * (For example on the x86 PC it triggers an NMI on all CPUs,
+ * and on s390 it triggers the RESTART interrupt on the first CPU.)
+ *
+ * The NMI is injected by looking for a QOM object which implements
+ * the TYPE_NMI interface, and calling its nmi_monitor_handler method. Usually
+ * it is the machine model class that implements this interface.
+ *
+ * Not all machines implement NMI handling; this function
+ * will return an error if used on a machine which does not
+ * implement NMIs.
+ *
+ * On success, return %true.
+ * On failure, store an error through @errp and return %false.
+ */
+bool nmi_inject(Error **errp);
 
 #endif /* NMI_H */
hw/core/nmi.c +4 -5
index ff6454437c1..2d890f2995d 100644
@@ -22,11 +22,8 @@
 #include "qemu/osdep.h"
 #include "hw/core/nmi.h"
 #include "qapi/error.h"
-#include "qemu/module.h"
-#include "monitor/monitor.h"
 
 struct do_nmi_s {
-    int cpu_index;
     Error *err;
     bool handled;
 };
@@ -54,19 +51,21 @@ static int nmi_children(Object *o, struct do_nmi_s *ns)
     return object_child_foreach_recursive(o, do_nmi, ns);
 }
 
-void nmi_monitor_handle(int cpu_index, Error **errp)
+bool nmi_inject(Error **errp)
 {
     struct do_nmi_s ns = {
-        .cpu_index = cpu_index,
         .err = NULL,
         .handled = false
     };
 
     if (nmi_children(object_get_root(), &ns)) {
         error_propagate(errp, ns.err);
+        return false;
     } else if (!ns.handled) {
         error_setg(errp, "machine does not provide NMIs");
+        return false;
     }
+    return true;
 }
 
 static const TypeInfo nmi_info = {
hw/ipmi/ipmi.c +1 -2
index 74818ff3cea..dedf23cb997 100644
@@ -59,8 +59,7 @@ static int ipmi_do_hw_op(IPMIInterface *s, enum ipmi_op op, int checkonly)
         if (checkonly) {
             return 0;
         }
-        /* We don't care what CPU we use. */
-        nmi_monitor_handle(0, NULL);
+        nmi_inject(NULL);
         return 0;
 
     case IPMI_SHUTDOWN_VIA_ACPI_OVERTEMP:
hw/watchdog/watchdog.c +1 -1
index 0842fe373ae..5f764a0c1b8 100644
@@ -81,7 +81,7 @@ void watchdog_perform_action(void)
 
     case WATCHDOG_ACTION_INJECT_NMI:
         qapi_event_send_watchdog(WATCHDOG_ACTION_INJECT_NMI);
-        nmi_monitor_handle(0, NULL);
+        nmi_inject(NULL);
         break;
 
     default:
system/cpus.c +1 -2
index 97e5a5edee2..9758cda4636 100644
@@ -23,7 +23,6 @@
  */
 
 #include "qemu/osdep.h"
-#include "monitor/monitor.h"
 #include "qemu/coroutine-tls.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-machine.h"
@@ -926,6 +925,6 @@ exit:
 
 void qmp_inject_nmi(Error **errp)
 {
-    nmi_monitor_handle(monitor_get_cpu_index(monitor_cur()), errp);
+    nmi_inject(errp);
 }
 
hmp-commands.hx +1 -1
index a29f02b623e..43ff220b5fe 100644
@@ -869,7 +869,7 @@ ERST
         .cmd        = hmp_nmi,
     },
 SRST
-``nmi`` *cpu*
+``nmi``
   Inject an NMI, in a machine-specific way.
   Not all machines implement NMI handling.
 ERST
Signature · 1 line
2.53.0
#32 lore raw

[PULL 31/56] hw/nmi: Remove @cpu_index argument from NMIClass::nmi_monitor_handler()

In reply to Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Only s390x was using the 'cpu_index' argument, but since the previous commit it isn't anymore (it use the first cpu). Since this argument is now completely unused, remove it.

Message-Id: <[email protected]>

---
 include/hw/core/nmi.h      | 8 +++++++-
 hw/core/nmi.c              | 2 +-
 hw/hppa/machine.c          | 2 +-
 hw/i386/x86.c              | 2 +-
 hw/intc/m68k_irqc.c        | 2 +-
 hw/m68k/q800-glue.c        | 2 +-
 hw/misc/macio/gpio.c       | 2 +-
 hw/ppc/pnv.c               | 2 +-
 hw/ppc/spapr.c             | 2 +-
 hw/s390x/s390-virtio-ccw.c | 2 +-
 10 files changed, 16 insertions(+), 10 deletions(-)
include/hw/core/nmi.h +7 -1
index fff41bebc69..4c4ce79071d 100644
@@ -37,7 +37,13 @@ typedef struct NMIState NMIState;
 struct NMIClass {
     InterfaceClass parent_class;
 
-    void (*nmi_monitor_handler)(NMIState *n, int cpu_index, Error **errp);
+    /**
+     * nmi_monitor_handler: Callback to handle NMI notifications.
+     *
+     * @ns: Class #NMIState state
+     * @errp: pointer to error object
+     */
+    void (*nmi_monitor_handler)(NMIState *ns, Error **errp);
 };
 
 void nmi_monitor_handle(int cpu_index, Error **errp);
hw/core/nmi.c +1 -1
index 22724046575..ff6454437c1 100644
@@ -40,7 +40,7 @@ static int do_nmi(Object *o, void *opaque)
         NMIClass *nc = NMI_GET_CLASS(n);
 
         ns->handled = true;
-        nc->nmi_monitor_handler(n, ns->cpu_index, &ns->err);
+        nc->nmi_monitor_handler(n, &ns->err);
         if (ns->err) {
             return -1;
         }
hw/hppa/machine.c +1 -1
index d762163ddf5..2b44debc388 100644
@@ -829,7 +829,7 @@ static void hppa_machine_reset(MachineState *ms, ResetType type)
     cpu[0]->env.cmdline_or_bootorder = 'c';
 }
 
-static void hppa_nmi(NMIState *n, int cpu_index, Error **errp)
+static void hppa_nmi(NMIState *ns, Error **errp)
 {
     CPUState *cs;
 
hw/i386/x86.c +1 -1
index dc7f0d56b01..0ea5453403d 100644
@@ -147,7 +147,7 @@ static const CPUArchIdList *x86_possible_cpu_arch_ids(MachineState *ms)
     return ms->possible_cpus;
 }
 
-static void x86_nmi(NMIState *n, int cpu_index, Error **errp)
+static void x86_nmi(NMIState *ns, Error **errp)
 {
     /* cpu index isn't used */
     CPUState *cs;
hw/intc/m68k_irqc.c +1 -1
index 68ddb5351be..bc41b44d455 100644
@@ -70,7 +70,7 @@ static void m68k_irqc_instance_init(Object *obj)
     qdev_init_gpio_in(DEVICE(obj), m68k_set_irq, M68K_IRQC_LEVEL_NUM);
 }
 
-static void m68k_nmi(NMIState *n, int cpu_index, Error **errp)
+static void m68k_nmi(NMIState *n, Error **errp)
 {
     m68k_set_irq(n, M68K_IRQC_LEVEL_7, 1);
 }
hw/m68k/q800-glue.c +1 -1
index ac9062c6488..b13e5ef95f1 100644
@@ -159,7 +159,7 @@ static void glue_auxmode_set_irq(void *opaque, int irq, int level)
     s->auxmode = level;
 }
 
-static void glue_nmi(NMIState *n, int cpu_index, Error **errp)
+static void glue_nmi(NMIState *n, Error **errp)
 {
     GLUEState *s = GLUE(n);
 
hw/misc/macio/gpio.c +1 -1
index 1a7c534d652..1bdca728f97 100644
@@ -188,7 +188,7 @@ static void macio_gpio_reset(DeviceState *dev)
     macio_set_gpio(s, 1, true);
 }
 
-static void macio_gpio_nmi(NMIState *n, int cpu_index, Error **errp)
+static void macio_gpio_nmi(NMIState *n, Error **errp)
 {
     macio_set_gpio(MACIO_GPIO(n), 9, true);
     macio_set_gpio(MACIO_GPIO(n), 9, false);
hw/ppc/pnv.c +1 -1
index c0cb45dbfbc..8676be7bbb1 100644
@@ -3552,7 +3552,7 @@ static void pnv_cpu_do_nmi(PnvChip *chip, PowerPCCPU *cpu, void *opaque)
     async_run_on_cpu(CPU(cpu), pnv_cpu_do_nmi_on_cpu, RUN_ON_CPU_HOST_INT(0));
 }
 
-static void pnv_nmi(NMIState *n, int cpu_index, Error **errp)
+static void pnv_nmi(NMIState *ns, Error **errp)
 {
     PnvMachineState *pnv = PNV_MACHINE(qdev_get_machine());
     int i;
hw/ppc/spapr.c +1 -1
index 7e284edd7d0..c376a588720 100644
@@ -3550,7 +3550,7 @@ void spapr_do_system_reset_on_cpu(CPUState *cs, run_on_cpu_data arg)
     }
 }
 
-static void spapr_nmi(NMIState *n, int cpu_index, Error **errp)
+static void spapr_nmi(NMIState *ns, Error **errp)
 {
     CPUState *cs;
 
hw/s390x/s390-virtio-ccw.c +1 -1
index a2f373b1190..ac04245d65b 100644
@@ -725,7 +725,7 @@ static HotplugHandler *s390_get_hotplug_handler(MachineState *machine,
     return NULL;
 }
 
-static void s390_nmi(NMIState *n, int cpu_index, Error **errp)
+static void s390_nmi(NMIState *ns, Error **errp)
 {
     s390_cpu_restart(S390_CPU(first_cpu));
 }
Signature · 1 line
2.53.0
#33 lore raw

[PULL 34/56] hw/nmi: Remove unused @errp argument from raise_nmi()

In reply to Philippe Mathieu-Daudé

Not a single handler update @errp. The single user is nmi_inject() filling with "machine does not provide NMIs". Remove the unused argument from the raise_nmi() callback, simplifying the methods in hw/core/nmi.c.

Message-Id: <[email protected]>

---
 include/hw/core/nmi.h      |  3 +--
 hw/core/nmi.c              | 32 ++++++--------------------------
 hw/hppa/machine.c          |  2 +-
 hw/i386/x86.c              |  2 +-
 hw/intc/m68k_irqc.c        |  2 +-
 hw/m68k/q800-glue.c        |  2 +-
 hw/misc/macio/gpio.c       |  2 +-
 hw/ppc/pnv.c               |  2 +-
 hw/ppc/spapr.c             |  2 +-
 hw/s390x/s390-virtio-ccw.c |  2 +-
 10 files changed, 15 insertions(+), 36 deletions(-)
include/hw/core/nmi.h +1 -2
index a8feac3b67e..d71d92dfbb9 100644
@@ -40,12 +40,11 @@ struct NMIClass {
     /**
      * raise_nmi: Callback to handle NMI notifications.
      * @ns: Class #NMIState state
-     * @errp: pointer to error object
      *
      * Called by nmi_inject() to perform the machine-specific
      * action when a NMI is requested.
      */
-    void (*raise_nmi)(NMIState *ns, Error **errp);
+    void (*raise_nmi)(NMIState *ns);
 };
 
 /**
hw/core/nmi.c +6 -26
index a6edf4fbf01..c44b0cf892d 100644
@@ -23,45 +23,25 @@
 #include "hw/core/nmi.h"
 #include "qapi/error.h"
 
-struct do_nmi_s {
-    Error *err;
-    bool handled;
-};
-
 static int do_nmi(Object *o, void *opaque)
 {
-    struct do_nmi_s *ns = opaque;
+    bool *handled = opaque;
     NMIState *n = (NMIState *) object_dynamic_cast(o, TYPE_NMI);
 
     if (n) {
-        NMIClass *nc = NMI_GET_CLASS(n);
-
-        ns->handled = true;
-        nc->raise_nmi(n, &ns->err);
-        if (ns->err) {
-            return -1;
-        }
+        *handled = true;
+        NMI_GET_CLASS(n)->raise_nmi(n);
     }
 
     return 0;
 }
 
-static int nmi_children(Object *o, struct do_nmi_s *ns)
-{
-    return object_child_foreach_recursive(o, do_nmi, ns);
-}
-
 bool nmi_inject(Error **errp)
 {
-    struct do_nmi_s ns = {
-        .err = NULL,
-        .handled = false
-    };
+    bool handled = false;
 
-    if (nmi_children(object_get_root(), &ns)) {
-        error_propagate(errp, ns.err);
-        return false;
-    } else if (!ns.handled) {
+    object_child_foreach_recursive(object_get_root(), do_nmi, &handled);
+    if (!handled) {
         error_setg(errp, "machine does not provide NMIs");
         return false;
     }
hw/hppa/machine.c +1 -1
index 717cfde61da..98931481b20 100644
@@ -829,7 +829,7 @@ static void hppa_machine_reset(MachineState *ms, ResetType type)
     cpu[0]->env.cmdline_or_bootorder = 'c';
 }
 
-static void hppa_nmi(NMIState *ns, Error **errp)
+static void hppa_nmi(NMIState *ns)
 {
     CPUState *cs;
 
hw/i386/x86.c +1 -1
index d1414ff63db..f8ba3244e22 100644
@@ -147,7 +147,7 @@ static const CPUArchIdList *x86_possible_cpu_arch_ids(MachineState *ms)
     return ms->possible_cpus;
 }
 
-static void x86_nmi(NMIState *ns, Error **errp)
+static void x86_nmi(NMIState *ns)
 {
     /* cpu index isn't used */
     CPUState *cs;
hw/intc/m68k_irqc.c +1 -1
index 29f758dafd1..47f626c0fa0 100644
@@ -70,7 +70,7 @@ static void m68k_irqc_instance_init(Object *obj)
     qdev_init_gpio_in(DEVICE(obj), m68k_set_irq, M68K_IRQC_LEVEL_NUM);
 }
 
-static void m68k_nmi(NMIState *n, Error **errp)
+static void m68k_nmi(NMIState *n)
 {
     m68k_set_irq(n, M68K_IRQC_LEVEL_7, 1);
 }
hw/m68k/q800-glue.c +1 -1
index 265af90a8e6..223e7d9019c 100644
@@ -159,7 +159,7 @@ static void glue_auxmode_set_irq(void *opaque, int irq, int level)
     s->auxmode = level;
 }
 
-static void glue_nmi(NMIState *n, Error **errp)
+static void glue_nmi(NMIState *n)
 {
     GLUEState *s = GLUE(n);
 
hw/misc/macio/gpio.c +1 -1
index db0c4ecb3cf..ba001f7b206 100644
@@ -188,7 +188,7 @@ static void macio_gpio_reset(DeviceState *dev)
     macio_set_gpio(s, 1, true);
 }
 
-static void macio_gpio_nmi(NMIState *n, Error **errp)
+static void macio_gpio_nmi(NMIState *n)
 {
     macio_set_gpio(MACIO_GPIO(n), 9, true);
     macio_set_gpio(MACIO_GPIO(n), 9, false);
hw/ppc/pnv.c +1 -1
index a9f74245866..f0413639f98 100644
@@ -3552,7 +3552,7 @@ static void pnv_cpu_do_nmi(PnvChip *chip, PowerPCCPU *cpu, void *opaque)
     async_run_on_cpu(CPU(cpu), pnv_cpu_do_nmi_on_cpu, RUN_ON_CPU_HOST_INT(0));
 }
 
-static void pnv_nmi(NMIState *ns, Error **errp)
+static void pnv_nmi(NMIState *ns)
 {
     PnvMachineState *pnv = PNV_MACHINE(qdev_get_machine());
     int i;
hw/ppc/spapr.c +1 -1
index 1bc90ceed35..20e024907b1 100644
@@ -3550,7 +3550,7 @@ void spapr_do_system_reset_on_cpu(CPUState *cs, run_on_cpu_data arg)
     }
 }
 
-static void spapr_nmi(NMIState *ns, Error **errp)
+static void spapr_nmi(NMIState *ns)
 {
     CPUState *cs;
 
hw/s390x/s390-virtio-ccw.c +1 -1
index 21d9f51ddcc..06e5def9092 100644
@@ -725,7 +725,7 @@ static HotplugHandler *s390_get_hotplug_handler(MachineState *machine,
     return NULL;
 }
 
-static void s390_nmi(NMIState *ns, Error **errp)
+static void s390_nmi(NMIState *ns)
 {
     s390_cpu_restart(S390_CPU(first_cpu));
 }
Signature · 1 line
2.53.0
#34 lore raw

[PULL 35/56] hw/nmi: Raise NMI line only once

In reply to Philippe Mathieu-Daudé

We only expect one device in the system to implement the TYPE_NMI interface (typically the machine, but in a few cases for e.g. m68k and ppc this is an interrupt controller or similar device); so we don't need to keep walking the whole QOM tree once we've found it. As no machine type creates more than one object implementing TYPE_NMI, this is not a behaviour change.

Message-Id: <[email protected]>

---
 hw/core/nmi.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/core/nmi.c +5 -0
index c44b0cf892d..84f21665987 100644
@@ -31,6 +31,11 @@ static int do_nmi(Object *o, void *opaque)
     if (n) {
         *handled = true;
         NMI_GET_CLASS(n)->raise_nmi(n);
+        /*
+         * We expect only one object to implement TYPE_NMI, so once
+         * we've asked it to deliver the NMI we can stop looking.
+         */
+        return 1;
     }
 
     return 0;
Signature · 1 line
2.53.0
#35 lore raw

[PULL 33/56] hw/nmi: Rename nmi_monitor_handler() -> raise_nmi()

In reply to Philippe Mathieu-Daudé

nmi_monitor_handler() is not related to the monitor, rename it as raise_nmi().

Message-Id: <[email protected]>

---
 include/hw/core/nmi.h      | 10 ++++++----
 hw/core/nmi.c              |  2 +-
 hw/hppa/machine.c          |  2 +-
 hw/i386/x86.c              |  2 +-
 hw/intc/m68k_irqc.c        |  2 +-
 hw/m68k/q800-glue.c        |  2 +-
 hw/misc/macio/gpio.c       |  2 +-
 hw/ppc/pnv.c               |  2 +-
 hw/ppc/spapr.c             |  2 +-
 hw/s390x/s390-virtio-ccw.c |  2 +-
 10 files changed, 15 insertions(+), 13 deletions(-)
include/hw/core/nmi.h +6 -4
index 851be28257e..a8feac3b67e 100644
@@ -38,12 +38,14 @@ struct NMIClass {
     InterfaceClass parent_class;
 
     /**
-     * nmi_monitor_handler: Callback to handle NMI notifications.
-     *
+     * raise_nmi: Callback to handle NMI notifications.
      * @ns: Class #NMIState state
      * @errp: pointer to error object
+     *
+     * Called by nmi_inject() to perform the machine-specific
+     * action when a NMI is requested.
      */
-    void (*nmi_monitor_handler)(NMIState *ns, Error **errp);
+    void (*raise_nmi)(NMIState *ns, Error **errp);
 };
 
 /**
@@ -58,7 +60,7 @@ struct NMIClass {
  * and on s390 it triggers the RESTART interrupt on the first CPU.)
  *
  * The NMI is injected by looking for a QOM object which implements
- * the TYPE_NMI interface, and calling its nmi_monitor_handler method. Usually
+ * the TYPE_NMI interface, and calling its raise_nmi method. Usually
  * it is the machine model class that implements this interface.
  *
  * Not all machines implement NMI handling; this function
hw/core/nmi.c +1 -1
index 2d890f2995d..a6edf4fbf01 100644
@@ -37,7 +37,7 @@ static int do_nmi(Object *o, void *opaque)
         NMIClass *nc = NMI_GET_CLASS(n);
 
         ns->handled = true;
-        nc->nmi_monitor_handler(n, &ns->err);
+        nc->raise_nmi(n, &ns->err);
         if (ns->err) {
             return -1;
         }
hw/hppa/machine.c +1 -1
index 2b44debc388..717cfde61da 100644
@@ -851,7 +851,7 @@ static void hppa_machine_common_class_init(ObjectClass *oc, const void *data)
     mc->default_ram_id = "hppa.ram";
     mc->default_nic = "tulip";
 
-    nc->nmi_monitor_handler = hppa_nmi;
+    nc->raise_nmi = hppa_nmi;
 }
 
 static void HP_B160L_machine_init_class_init(ObjectClass *oc, const void *data)
hw/i386/x86.c +1 -1
index 0ea5453403d..d1414ff63db 100644
@@ -389,7 +389,7 @@ static void x86_machine_class_init(ObjectClass *oc, const void *data)
     mc->get_default_cpu_node_id = x86_get_default_cpu_node_id;
     mc->possible_cpu_arch_ids = x86_possible_cpu_arch_ids;
     mc->kvm_type = x86_kvm_type;
-    nc->nmi_monitor_handler = x86_nmi;
+    nc->raise_nmi = x86_nmi;
 
     object_class_property_add(oc, X86_MACHINE_SMM, "OnOffAuto",
         x86_machine_get_smm, x86_machine_set_smm,
hw/intc/m68k_irqc.c +1 -1
index bc41b44d455..29f758dafd1 100644
@@ -97,7 +97,7 @@ static void m68k_irqc_class_init(ObjectClass *oc, const void *data)
     InterruptStatsProviderClass *ic = INTERRUPT_STATS_PROVIDER_CLASS(oc);
 
     device_class_set_props(dc, m68k_irqc_properties);
-    nc->nmi_monitor_handler = m68k_nmi;
+    nc->raise_nmi = m68k_nmi;
     device_class_set_legacy_reset(dc, m68k_irqc_reset);
     dc->vmsd = &vmstate_m68k_irqc;
     ic->get_statistics = m68k_irqc_get_statistics;
hw/m68k/q800-glue.c +1 -1
index b13e5ef95f1..265af90a8e6 100644
@@ -237,7 +237,7 @@ static void glue_class_init(ObjectClass *klass, const void *data)
     dc->vmsd = &vmstate_glue;
     device_class_set_props(dc, glue_properties);
     rc->phases.hold = glue_reset_hold;
-    nc->nmi_monitor_handler = glue_nmi;
+    nc->raise_nmi = glue_nmi;
 }
 
 static const TypeInfo glue_info_types[] = {
hw/misc/macio/gpio.c +1 -1
index 1bdca728f97..db0c4ecb3cf 100644
@@ -201,7 +201,7 @@ static void macio_gpio_class_init(ObjectClass *oc, const void *data)
 
     device_class_set_legacy_reset(dc, macio_gpio_reset);
     dc->vmsd = &vmstate_macio_gpio;
-    nc->nmi_monitor_handler = macio_gpio_nmi;
+    nc->raise_nmi = macio_gpio_nmi;
 }
 
 static const TypeInfo macio_gpio_init_info = {
hw/ppc/pnv.c +1 -1
index 8676be7bbb1..a9f74245866 100644
@@ -3583,7 +3583,7 @@ static void pnv_machine_class_init(ObjectClass *oc, const void *data)
     mc->default_ram_size = 1 * GiB;
     mc->default_ram_id = "pnv.ram";
     ispc->print_info = pnv_pic_print_info;
-    nc->nmi_monitor_handler = pnv_nmi;
+    nc->raise_nmi = pnv_nmi;
 
     object_class_property_add_bool(oc, "hb-mode",
                                    pnv_machine_get_hb, pnv_machine_set_hb);
hw/ppc/spapr.c +1 -1
index c376a588720..1bc90ceed35 100644
@@ -4652,7 +4652,7 @@ static void spapr_machine_class_init(ObjectClass *oc, const void *data)
     mc->nvdimm_supported = true;
     smc->resize_hpt_default = SPAPR_RESIZE_HPT_ENABLED;
     fwc->get_dev_path = spapr_get_fw_dev_path;
-    nc->nmi_monitor_handler = spapr_nmi;
+    nc->raise_nmi = spapr_nmi;
     vhc->cpu_in_nested = spapr_cpu_in_nested;
     vhc->deliver_hv_excp = spapr_exit_nested;
     vhc->hypercall = emulate_spapr_hypercall;
hw/s390x/s390-virtio-ccw.c +1 -1
index ac04245d65b..21d9f51ddcc 100644
@@ -830,7 +830,7 @@ static void ccw_machine_class_init(ObjectClass *oc, const void *data)
     hc->plug = s390_machine_device_plug;
     hc->unplug_request = s390_machine_device_unplug_request;
     hc->unplug = s390_machine_device_unplug;
-    nc->nmi_monitor_handler = s390_nmi;
+    nc->raise_nmi = s390_nmi;
     mc->default_ram_id = "s390.ram";
     mc->default_nic = "virtio-net-ccw";
     dsi->qmp_dump_skeys = s390_qmp_dump_skeys;
Signature · 1 line
2.53.0
#36 lore raw

[PULL 36/56] hexagon: Remove unnecessary 'monitor/monitor.h' header

In reply to Philippe Mathieu-Daudé

The Monitor type is used in these 2 files, as a pointer. Since the type is forward-declared in "qemu/typedefs.h", which all source files include via "qemu/osdep.h", we do not need to include it.

Do however include "exec/hwaddr.h" and "exec/mmu-access-type.h" which declare the types used by hex_tlb_find_match prototype:

extern bool hex_tlb_find_match(CPUHexagonState *env, uint32_t VA,

                                 MMUAccessType access_type, hwaddr *PA, int *prot,
                                 ^^^^^^^^^^^^^              ^^^^^^
                                 uint64_t *size, int32_t *excp, int mmu_idx);

Message-Id: <[email protected]>

---
 include/hw/hexagon/hexagon_tlb.h | 2 +-
 target/hexagon/hex_mmu.h         | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
include/hw/hexagon/hexagon_tlb.h +1 -1
index 90d9ed84043..760dc1ea811 100644
@@ -12,7 +12,7 @@
 #include "qom/object.h"
 #include "exec/hwaddr.h"
 #include "exec/mmu-access-type.h"
-#include "monitor/monitor.h"
+
 #define TYPE_HEXAGON_TLB "hexagon-tlb"
 OBJECT_DECLARE_SIMPLE_TYPE(HexagonTLBState, HEXAGON_TLB)
 
target/hexagon/hex_mmu.h +2 -1
index 4f556c715a9..6aa450b9413 100644
@@ -7,8 +7,9 @@
 #ifndef HEXAGON_MMU_H
 #define HEXAGON_MMU_H
 
+#include "exec/hwaddr.h"
+#include "exec/mmu-access-type.h"
 #include "cpu.h"
-#include "monitor/monitor.h"
 
 extern void hex_tlbw(CPUHexagonState *env, uint32_t index, uint64_t value);
 extern uint32_t hex_tlb_lookup(CPUHexagonState *env, uint32_t ssr, uint32_t VA);
Signature · 1 line
2.53.0
#37 lore raw

[PULL 37/56] net/vhost-vdpa: Include missing 'qemu/iov.h' header

In reply to Philippe Mathieu-Daudé

vhost-vdpa.c uses methods declared in the "qemu/iov." header. Include it otherwise we get when refactoring unrelated headers:

../net/vhost-vdpa.c: In function ‘vhost_vdpa_net_load_cmd’:
../net/vhost-vdpa.c:714:24: error: implicit declaration of function ‘iov_size’

    714 |     size_t data_size = iov_size(data_sg, data_num), cmd_size;
        |                        ^~~~~~~~
  ../net/vhost-vdpa.c:714:24: error: nested extern declaration of ‘iov_size’
  ../net/vhost-vdpa.c:742:5: error: implicit declaration of function ‘iov_from_buf’
    742 |     iov_from_buf(out_cursor, 1, 0, &ctrl, sizeof(ctrl));
        |     ^~~~~~~~~~~~
  ../net/vhost-vdpa.c:742:5: error: nested extern declaration of ‘iov_from_buf’
  ../net/vhost-vdpa.c:744:5: error: implicit declaration of function ‘iov_to_buf’
    744 |     iov_to_buf(data_sg, data_num, 0,
        |     ^~~~~~~~~~
  ../net/vhost-vdpa.c:744:5: error: nested extern declaration of ‘iov_to_buf’
  ../net/vhost-vdpa.c:748:5: error: implicit declaration of function ‘iov_copy’
    748 |     iov_copy(&out, 1, out_cursor, 1, 0, cmd_size);
        |     ^~~~~~~~
Fixes bd907ae4b00 ("vdpa: manual forward CVQ buffers")

Message-Id: <[email protected]>

---
 net/vhost-vdpa.c | 1 +
 1 file changed, 1 insertion(+)
net/vhost-vdpa.c +1 -0
index c526c2b2dc0..1052361a4ab 100644
@@ -17,6 +17,7 @@
 #include "hw/virtio/vhost-vdpa.h"
 #include "qemu/config-file.h"
 #include "qemu/error-report.h"
+#include "qemu/iov.h"
 #include "qemu/log.h"
 #include "qemu/memalign.h"
 #include "qemu/option.h"
Signature · 1 line
2.53.0
#38 lore raw

[PULL 38/56] tests/unit: Include 'qemu/main-loop.h' header in test-util-sockets.c

In reply to Philippe Mathieu-Daudé

test-util-sockets.c calls qemu_init_main_loop(), itself declared in the "qemu/main-loop.h" header. Include the latter to avoid when refactoring unrelated headers:

../tests/unit/test-util-sockets.c:553:5: error: call to undeclared function 'qemu_init_main_loop'

  553 |     qemu_init_main_loop(&error_abort);
      |     ^

Message-Id: <[email protected]>

---
 tests/unit/test-util-sockets.c | 1 +
 1 file changed, 1 insertion(+)
tests/unit/test-util-sockets.c +1 -0
index ee66d727c38..ab3f39c3efb 100644
@@ -19,6 +19,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/main-loop.h"
 #include "qemu/sockets.h"
 #include "qapi/error.h"
 #include "socket-helpers.h"
Signature · 1 line
2.53.0
#39 lore raw

[PULL 39/56] qapi/qmp-dispatch: Include 'qemu/aio-wait.h' and 'monitor/monitor.h'

In reply to Philippe Mathieu-Daudé

qmp-dispatch.c calls aio_wait_kick() and monitor_cur(). Include the header declaring them in order to avoid the following build failure when refactoring unrelated headers:

../qapi/qmp-dispatch.c:126:12: error: call to undeclared function 'monitor_cur'

    126 |     assert(monitor_cur() == NULL);
        |            ^
  ../qapi/qmp-dispatch.c:141:5: error: call to undeclared function 'aio_wait_kick'
    141 |     aio_wait_kick();
        |     ^
Fixes 41725fa7eda ("qmp: Call monitor_set_cur() only in qmp_dispatch()")
Fixes fc1a2ec7da5 ("monitor: Fix deadlock in monitor_cleanup")

Message-Id: <[email protected]>

---
 qapi/qmp-dispatch.c | 2 ++
 1 file changed, 2 insertions(+)
qapi/qmp-dispatch.c +2 -0
index e3897d51977..965cad64998 100644
@@ -14,6 +14,7 @@
 #include "qemu/osdep.h"
 
 #include "qemu/aio.h"
+#include "qemu/aio-wait.h"
 #include "qapi/compat-policy.h"
 #include "qapi/error.h"
 #include "qapi/qmp-registry.h"
@@ -24,6 +25,7 @@
 #include "qobject/qbool.h"
 #include "qemu/coroutine.h"
 #include "qemu/main-loop.h"
+#include "monitor/monitor.h"
 
 Visitor *qobject_input_visitor_new_qmp(QObject *obj)
 {
Signature · 1 line
2.53.0
#40 lore raw

[PULL 40/56] qapi/qmp-registry: Remove unnecessary 'monitor/monitor.h' header

In reply to Philippe Mathieu-Daudé

Message-Id: <[email protected]>

---
 include/qapi/qmp-registry.h | 1 -
 1 file changed, 1 deletion(-)
include/qapi/qmp-registry.h +0 -1
index e0ee1ad3ac6..6146306a3a1 100644
@@ -14,7 +14,6 @@
 #ifndef QAPI_QMP_DISPATCH_H
 #define QAPI_QMP_DISPATCH_H
 
-#include "monitor/monitor.h"
 #include "qemu/queue.h"
 
 typedef void (QmpCommandFunc)(QDict *, QObject **, Error **);
Signature · 1 line
2.53.0
#41 lore raw

[PULL 41/56] migration/hmp-cmds: Include 'block/block-global-state.h' header

In reply to Philippe Mathieu-Daudé

migration-hmp-cmds.c uses types / methods declared in "block/block-global-state.h". Include the latter otherwise we get when refactoring unrelated headers:

../migration/migration-hmp-cmds.c:911:5: error: use of undeclared identifier 'BdrvNextIterator'

    911 |     BdrvNextIterator it;
        |     ^
  ../migration/migration-hmp-cmds.c:918:15: error: call to undeclared function 'bdrv_first'
    918 |     for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
        |               ^

Message-Id: <[email protected]>

---
 migration/migration-hmp-cmds.c | 1 +
 1 file changed, 1 insertion(+)
migration/migration-hmp-cmds.c +1 -0
index b5eb27467cd..ad68fa23aa4 100644
@@ -15,6 +15,7 @@
 
 #include "qemu/osdep.h"
 #include "block/qapi.h"
+#include "block/block-global-state.h"
 #include "migration/snapshot.h"
 #include "monitor/hmp.h"
 #include "monitor/hmp-completion.h"
Signature · 1 line
2.53.0
#42 lore raw

[PULL 42/56] monitor: Include missing 'qemu/aio-wait.h' header

In reply to Philippe Mathieu-Daudé

Both monitor.c and qmp.c use types / methods declared in "qemu/aio-wait.h". Include the latter to avoid the following errors when refactoring unrelated headers:

../monitor/monitor.c:648:5: error: call to undeclared function 'AIO_WAIT_WHILE_UNLOCKED'

    648 |     AIO_WAIT_WHILE_UNLOCKED(NULL,
        |     ^
  ../monitor/qmp.c:792:9: error: call to undeclared function 'aio_wait_bh_oneshot'
    792 |         aio_wait_bh_oneshot(iothread_get_aio_context(mon_iothread),
        |         ^
Fixes 9ce44e2ce26 ("qmp: Move dispatcher to a coroutine")
Fixes a5df506e129 ("monitor: implement support for deleting QMP objects")

Message-Id: <[email protected]>

---
 monitor/monitor.c | 1 +
 monitor/qmp.c     | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
monitor/monitor.c +1 -0
index ed195fd97bb..c75ae815343 100644
@@ -30,6 +30,7 @@
 #include "qapi/qapi-visit-control.h"
 #include "qobject/qdict.h"
 #include "qom/object_interfaces.h"
+#include "qemu/aio-wait.h"
 #include "qemu/error-report.h"
 #include "qemu/option.h"
 #include "system/qtest.h"
monitor/qmp.c +1 -1
index 338d37cb7e5..6ae1098d39f 100644
@@ -23,7 +23,7 @@
  */
 
 #include "qemu/osdep.h"
-
+#include "qemu/aio-wait.h"
 #include "chardev/char-io.h"
 #include "monitor-internal.h"
 #include "qapi/error.h"
Signature · 1 line
2.53.0
#43 lore raw

[PULL 43/56] monitor: Include missing 'qemu/lockable.h' header

In reply to Philippe Mathieu-Daudé

Files in monitor/ use the QEMU_LOCK_GUARD() macros, which are declared in "qemu/lockable.h". Include the latter to avoid when refactoring unrelated headers:

../monitor/fds.c:146:5: error: call to undeclared function 'QEMU_LOCK_GUARD'

    146 |     QEMU_LOCK_GUARD(&mon->mon_lock);
        |     ^
  ../monitor/monitor.c:176:5: error: call to undeclared function 'QEMU_LOCK_GUARD'
    176 |     QEMU_LOCK_GUARD(&mon->mon_lock);
        |     ^
  ../monitor/qmp.c:164:5: error: call to undeclared function 'WITH_QEMU_LOCK_GUARD'
    164 |     WITH_QEMU_LOCK_GUARD(&mon->mon_lock) {
        |     ^
Fixes 0210c3b39be ("monitor: Use LOCK_GUARD macros")

Message-Id: <[email protected]>

---
 monitor/fds.c     | 1 +
 monitor/monitor.c | 1 +
 monitor/qmp.c     | 1 +
 3 files changed, 3 insertions(+)
monitor/fds.c +1 -0
index cc35d2ec334..abe5f13487d 100644
@@ -29,6 +29,7 @@
 #include "qapi/qmp/qerror.h"
 #include "qemu/ctype.h"
 #include "qemu/cutils.h"
+#include "qemu/lockable.h"
 #include "system/runstate.h"
 
 /* file descriptors passed via SCM_RIGHTS */
monitor/monitor.c +1 -0
index c75ae815343..6af09f2f6ea 100644
@@ -32,6 +32,7 @@
 #include "qom/object_interfaces.h"
 #include "qemu/aio-wait.h"
 #include "qemu/error-report.h"
+#include "qemu/lockable.h"
 #include "qemu/option.h"
 #include "system/qtest.h"
 #include "trace.h"
monitor/qmp.c +1 -0
index 6ae1098d39f..aec03157750 100644
@@ -24,6 +24,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu/aio-wait.h"
+#include "qemu/lockable.h"
 #include "chardev/char-io.h"
 #include "monitor-internal.h"
 #include "qapi/error.h"
Signature · 1 line
2.53.0
#44 lore raw

[PULL 45/56] monitor: Reduce inclusion of 'qapi/qapi-emit-events.h' header

In reply to Philippe Mathieu-Daudé

"monitor/monitor.h" don't use anything declared in the generated "qapi/qapi-emit-events.h" header.
However the "monitor/monitor-internal.h" do:

107 struct MonitorClass {
...
116 /*

  117      * If non-NULL, the monitor is able to send event
  118      * notifications back to the client
  119      */
  120     void (*emit_event)(Monitor *mon, QAPIEvent event, QDict *qdict);
                                           ^^^^^^^^^

Move the header inclusion to "monitor/monitor-internal.h" to avoid including / re-exposing unnecessary declarations in the global "monitor/monitor.h" header.

Message-Id: <[email protected]>

---
 include/monitor/monitor.h  | 1 -
 monitor/monitor-internal.h | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)
include/monitor/monitor.h +0 -1
index efdd2165aa9..fa9f4a8a75a 100644
@@ -3,7 +3,6 @@
 
 #include "block/block.h"
 #include "qapi/qapi-types-misc.h"
-#include "qapi/qapi-emit-events.h"
 #include "qemu/coroutine-core.h"
 #include "qemu/readline.h"
 #include "exec/hwaddr.h"
monitor/monitor-internal.h +1 -0
index 23829f32f9a..bc0932c425a 100644
@@ -27,6 +27,7 @@
 
 #include "chardev/char-fe.h"
 #include "monitor/monitor.h"
+#include "qapi/qapi-emit-events.h"
 #include "qapi/qapi-types-control.h"
 #include "qapi/qapi-types-qom.h"
 #include "qapi/qmp-registry.h"
Signature · 1 line
2.53.0
#45 lore raw

[PULL 44/56] monitor: Include missing 'qemu/coroutine-core.h' header

In reply to Philippe Mathieu-Daudé

"monitor/monitor.h" declares monitor_set_cur() which use the 'Coroutine' type, itself declared in "qemu/coroutine-core.h". Include the latter to avoid when refactoring unrelated headers:

In file included from ../../target/sh4/monitor.c:26:
qemu/include/monitor/monitor.h:32:26: error: unknown type name 'Coroutine'

     32 | Monitor *monitor_set_cur(Coroutine *co, Monitor *mon);
        |                          ^
Fixes e69ee454b5f ("monitor: Make current monitor a per-coroutine property")

Message-Id: <[email protected]>

---
 include/monitor/monitor.h | 1 +
 1 file changed, 1 insertion(+)
include/monitor/monitor.h +1 -0
index 890497b0d22..efdd2165aa9 100644
@@ -4,6 +4,7 @@
 #include "block/block.h"
 #include "qapi/qapi-types-misc.h"
 #include "qapi/qapi-emit-events.h"
+#include "qemu/coroutine-core.h"
 #include "qemu/readline.h"
 #include "exec/hwaddr.h"
 #include "qom/object.h"
Signature · 1 line
2.53.0
#46 lore raw

[PULL 46/56] monitor: Remove unnecessary 'block/block.h' header

In reply to Philippe Mathieu-Daudé

Nothing here requires declarations from "block/block.h" anymore.

Message-Id: <[email protected]>

---
 include/monitor/monitor.h | 1 -
 1 file changed, 1 deletion(-)
include/monitor/monitor.h +0 -1
index fa9f4a8a75a..fd98ee2c71d 100644
@@ -1,7 +1,6 @@
 #ifndef MONITOR_H
 #define MONITOR_H
 
-#include "block/block.h"
 #include "qapi/qapi-types-misc.h"
 #include "qemu/coroutine-core.h"
 #include "qemu/readline.h"
Signature · 1 line
2.53.0
#47 lore raw

[PULL 48/56] system/dirtylimit: Extract HMP code to dirtylimit-hmp-cmds.c

In reply to Philippe Mathieu-Daudé

Message-Id: <[email protected]>

---
 MAINTAINERS                  |  1 +
 system/dirtylimit-hmp-cmds.c | 74 ++++++++++++++++++++++++++++++++++++
 system/dirtylimit.c          | 60 -----------------------------
 system/meson.build           |  1 +
 4 files changed, 76 insertions(+), 60 deletions(-)
 create mode 100644 system/dirtylimit-hmp-cmds.c
MAINTAINERS +1 -0
index c296dd5abfd..bad65aeda50 100644
@@ -3875,6 +3875,7 @@ Migration dirty limit and dirty page rate
 M: Hyman Huang <[email protected]>
 S: Maintained
 F: system/dirtylimit.c
+F: system/dirtylimit-hmp-cmds.c
 F: include/system/dirtylimit.h
 F: migration/dirtyrate.c
 F: migration/dirtyrate.h
system/dirtylimit-hmp-cmds.c new file +74 -0

74 lines not on this page · raw message

system/dirtylimit.c +0 -60

81 lines not on this page · raw message

system/meson.build +1 -0
index cd3193d170b..377adce8035 100644
@@ -9,6 +9,7 @@ system_ss.add(files(
   'cpus.c',
   'cpu-timers.c',
   'dirtylimit.c',
+  'dirtylimit-hmp-cmds.c',
   'dma-helpers.c',
   'exit-with-parent.c',
   'globals.c',
Signature · 1 line
2.53.0
#48 lore raw

[PULL 47/56] system: Remove unnecessary 'monitor/monitor.h' header

In reply to Philippe Mathieu-Daudé

No code in device_tree.c or physmem.c require declarations from "monitor/monitor.h".

Message-Id: <[email protected]>

---
 system/device_tree.c | 1 -
 system/physmem.c     | 2 --
 2 files changed, 3 deletions(-)
system/device_tree.c +0 -1
index 1ea19629841..48365435ea0 100644
@@ -29,7 +29,6 @@
 #include "qemu/config-file.h"
 #include "qapi/qapi-commands-machine.h"
 #include "qobject/qdict.h"
-#include "monitor/hmp.h"
 
 #include <libfdt.h>
 
system/physmem.c +0 -2
index 2f37cbeb071..362a00f76c0 100644
@@ -84,8 +84,6 @@
 #include "qemu/mmap-alloc.h"
 #endif
 
-#include "monitor/monitor.h"
-
 #ifdef CONFIG_LIBDAXCTL
 #include <daxctl/libdaxctl.h>
 #endif
Signature · 1 line
2.53.0
#49 lore raw

[PULL 49/56] system: Move qmp_inject_nmi() to hw/core/machine-qmp-cmds.c

In reply to Philippe Mathieu-Daudé

We figured NMI relates to machines (for their machine-specific handling), so move the 'inject-nmi' QMP handler with the rest of machine ones, in hw/core/machine-qmp-cmds.c.

Message-Id: <[email protected]>

---
 hw/core/machine-qmp-cmds.c | 6 ++++++
 system/cpus.c              | 8 --------
 2 files changed, 6 insertions(+), 8 deletions(-)
hw/core/machine-qmp-cmds.c +6 -0
index e62cb4ec888..1aa5f262298 100644
@@ -10,6 +10,7 @@
 #include "qemu/osdep.h"
 #include "hw/acpi/vmgenid.h"
 #include "hw/core/boards.h"
+#include "hw/core/nmi.h"
 #include "hw/intc/intc.h"
 #include "hw/mem/memory-device.h"
 #include "qapi/error.h"
@@ -448,3 +449,8 @@ void qmp_dump_skeys(const char *filename, Error **errp)
     }
     DUMP_SKEYS_INTERFACE_CLASS(oc)->qmp_dump_skeys(filename, errp);
 }
+
+void qmp_inject_nmi(Error **errp)
+{
+    nmi_inject(errp);
+}
system/cpus.c +0 -8
index 9758cda4636..aa2510bf8fc 100644
@@ -26,7 +26,6 @@
 #include "qemu/coroutine-tls.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-machine.h"
-#include "qapi/qapi-commands-misc.h"
 #include "qapi/qapi-events-run-state.h"
 #include "qapi/qmp/qerror.h"
 #include "exec/gdbstub.h"
@@ -38,7 +37,6 @@
 #include "qemu/plugin.h"
 #include "system/cpus.h"
 #include "qemu/guest-random.h"
-#include "hw/core/nmi.h"
 #include "system/physmem.h"
 #include "system/replay.h"
 #include "system/runstate.h"
@@ -922,9 +920,3 @@ void qmp_pmemsave(uint64_t addr, uint64_t size, const char *filename,
 exit:
     fclose(f);
 }
-
-void qmp_inject_nmi(Error **errp)
-{
-    nmi_inject(errp);
-}
-
Signature · 1 line
2.53.0
#50 lore raw

[PULL 50/56] system: Extract QMP memsave/pmemsave commands to physmem-qmp-cmds.c

In reply to Philippe Mathieu-Daudé

Keep cpus.c related to vCPU scheduling, move the QMP handlers related to dumping physical memory to file to their own unit. Fix a pair of checkpatch.pl errors doing so:

ERROR: braces {} are necessary for all arms of this statement #185: FILE: system/physmem-qmp-cmds.c:51:
+ if (l > size)
[...]

Message-Id: <[email protected]>

---
 MAINTAINERS               |   1 +
 system/cpus.c             |  92 --------------------------------
 system/physmem-qmp-cmds.c | 107 ++++++++++++++++++++++++++++++++++++++
 system/meson.build        |   1 +
 4 files changed, 109 insertions(+), 92 deletions(-)
 create mode 100644 system/physmem-qmp-cmds.c
MAINTAINERS +1 -0
index bad65aeda50..b51f5c3e602 100644
@@ -3436,6 +3436,7 @@ F: system/ioport.c
 F: system/memory.c
 F: system/memory_mapping.c
 F: system/physmem.c
+F: system/physmem-qmp-cmds.c
 F: system/memory_ldst*
 F: system/memory-internal.h
 F: system/ram-block-attributes.c
system/cpus.c +0 -92

108 lines not on this page · raw message

system/physmem-qmp-cmds.c new file +107 -0

107 lines not on this page · raw message

system/meson.build +1 -0
index 377adce8035..64e06e7abcc 100644
@@ -19,6 +19,7 @@ system_ss.add(files(
   'memory_mapping.c',
   'memory.c',
   'physmem.c',
+  'physmem-qmp-cmds.c',
   'qdev-monitor.c',
   'qtest.c',
   'rtc.c',
Signature · 1 line
2.53.0
#51 lore raw

[PULL 51/56] system: Move runstate-related code from cpus.c to runstate.c

In reply to Philippe Mathieu-Daudé

Keep cpus.c focused on vCPUs handling, move code related to VM state to runstate.c where similar code lives.

Fix few checkpatch.pl warnings:

WARNING: Block comments use a leading /* on a separate line
WARNING: Block comments use * on subsequent lines #327: FILE: system/runstate.c:541:
+/* does a state transition even if the VM is already stopped,
+ current state is forgotten forever */

Message-Id: <[email protected]>

---
 system/cpus.c     | 147 -------------------------------------------
 system/runstate.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 154 insertions(+), 147 deletions(-)
system/cpus.c +0 -147
index 43ff10cf008..f37e215c586 100644
@@ -25,7 +25,6 @@
 #include "qemu/osdep.h"
 #include "qemu/coroutine-tls.h"
 #include "qapi/error.h"
-#include "qapi/qapi-events-run-state.h"
 #include "exec/gdbstub.h"
 #include "accel/accel-cpu-ops.h"
 #include "system/hw_accel.h"
@@ -272,58 +271,6 @@ void cpu_interrupt(CPUState *cpu, int mask)
     cpus_accel->handle_interrupt(cpu, mask);
 }
 
-/*
- * True if the vm was previously suspended, and has not been woken or reset.
- */
-static int vm_was_suspended;
-
-void vm_set_suspended(bool suspended)
-{
-    vm_was_suspended = suspended;
-}
-
-bool vm_get_suspended(void)
-{
-    return vm_was_suspended;
-}
-
-static int do_vm_stop(RunState state, bool send_stop)
-{
-    int ret = 0;
-    RunState oldstate = runstate_get();
-
-    if (runstate_is_live(oldstate)) {
-        vm_was_suspended = (oldstate == RUN_STATE_SUSPENDED);
-        runstate_set(state);
-        cpu_disable_ticks();
-        if (oldstate == RUN_STATE_RUNNING) {
-            pause_all_vcpus();
-        }
-        ret = vm_state_notify(0, state);
-        if (send_stop) {
-            qapi_event_send_stop();
-        }
-    }
-
-    bdrv_drain_all();
-    /*
-     * Even if vm_state_notify() return failure,
-     * it would be better to flush as before.
-     */
-    ret |= bdrv_flush_all();
-    trace_vm_stop_flush_all(ret);
-
-    return ret;
-}
-
-/* Special vm_stop() variant for terminating the process.  Historically clients
- * did not expect a QMP STOP event and so we need to retain compatibility.
- */
-int vm_shutdown(void)
-{
-    return do_vm_stop(RUN_STATE_SHUTDOWN, false);
-}
-
 bool cpu_can_run(CPUState *cpu)
 {
     if (cpu->stop) {
@@ -734,97 +681,3 @@ void cpu_stop_current(void)
         cpu_exit(current_cpu);
     }
 }
-
-int vm_stop(RunState state)
-{
-    if (qemu_in_vcpu_thread()) {
-        qemu_system_vmstop_request_prepare();
-        qemu_system_vmstop_request(state);
-        /*
-         * FIXME: should not return to device code in case
-         * vm_stop() has been requested.
-         */
-        cpu_stop_current();
-        return 0;
-    }
-
-    return do_vm_stop(state, true);
-}
-
-/**
- * Prepare for (re)starting the VM.
- * Returns 0 if the vCPUs should be restarted, -1 on an error condition,
- * and 1 otherwise.
- */
-int vm_prepare_start(bool step_pending)
-{
-    int ret = vm_was_suspended ? 1 : 0;
-    RunState state = vm_was_suspended ? RUN_STATE_SUSPENDED : RUN_STATE_RUNNING;
-    RunState requested;
-
-    qemu_vmstop_requested(&requested);
-    if (runstate_is_running() && requested == RUN_STATE__MAX) {
-        return -1;
-    }
-
-    /* Ensure that a STOP/RESUME pair of events is emitted if a
-     * vmstop request was pending.  The BLOCK_IO_ERROR event, for
-     * example, according to documentation is always followed by
-     * the STOP event.
-     */
-    if (runstate_is_running()) {
-        qapi_event_send_stop();
-        qapi_event_send_resume();
-        return -1;
-    }
-
-    /*
-     * WHPX accelerator needs to know whether we are going to step
-     * any CPUs, before starting the first one.
-     */
-    accel_pre_resume(MACHINE(qdev_get_machine()), step_pending);
-
-    /* We are sending this now, but the CPUs will be resumed shortly later */
-    qapi_event_send_resume();
-
-    cpu_enable_ticks();
-    runstate_set(state);
-    vm_state_notify(1, state);
-    vm_was_suspended = false;
-    return ret;
-}
-
-void vm_start(void)
-{
-    if (!vm_prepare_start(false)) {
-        resume_all_vcpus();
-    }
-}
-
-void vm_resume(RunState state)
-{
-    if (runstate_is_live(state)) {
-        vm_start();
-    } else {
-        runstate_set(state);
-    }
-}
-
-/* does a state transition even if the VM is already stopped,
-   current state is forgotten forever */
-int vm_stop_force_state(RunState state)
-{
-    if (runstate_is_live(runstate_get())) {
-        return vm_stop(state);
-    } else {
-        int ret;
-        runstate_set(state);
-
-        bdrv_drain_all();
-        /* Make sure to return an error if the flush in a previous vm_stop()
-         * failed. */
-        ret = bdrv_flush_all();
-        trace_vm_stop_flush_all(ret);
-        return ret;
-    }
-}
system/runstate.c +154 -0

166 lines not on this page · raw message

Signature · 1 line
2.53.0
#52 lore raw

[PULL 52/56] monitor: Rename MonitorHMP @mon -> @hmp

In reply to Philippe Mathieu-Daudé

Mechanical change to sanitize using the following patterns:

MonitorQMP *qmp
MonitorHMP *hmp
Monitor *mon

Rename @mon (and @hmp_mon) as @hmp when the type is MonitorHMP.

Message-Id: <[email protected]>

---
 include/monitor/monitor.h  |   4 +-
 monitor/monitor-internal.h |   2 +-
 monitor/hmp-cmds.c         |   6 +-
 monitor/hmp.c              | 135 +++++++++++++++++++------------------
 ui/ui-hmp-cmds.c           |   4 +-
 5 files changed, 76 insertions(+), 75 deletions(-)
include/monitor/monitor.h +2 -2
index fd98ee2c71d..54134f2aa4f 100644
@@ -55,8 +55,8 @@ void monitor_flush_locked(Monitor *mon);
 
 void *gpa2hva(MemoryRegion **p_mr, hwaddr addr, uint64_t size, Error **errp);
 
-void monitor_read_command(MonitorHMP *mon, int show_prompt);
-int monitor_read_password(MonitorHMP *mon, ReadLineFunc *readline_func,
+void monitor_read_command(MonitorHMP *hmp, int show_prompt);
+int monitor_read_password(MonitorHMP *hmp, ReadLineFunc *readline_func,
                           void *opaque);
 
 AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
monitor/monitor-internal.h +1 -1
index bc0932c425a..e0a124a317a 100644
@@ -221,7 +221,7 @@ void monitor_data_destroy_qmp(MonitorQMP *mon);
 void coroutine_fn monitor_qmp_dispatcher_co(void *data);
 void qmp_dispatcher_co_wake(void);
 
-void handle_hmp_command(MonitorHMP *mon, const char *cmdline);
+void handle_hmp_command(MonitorHMP *hmp, const char *cmdline);
 int hmp_compare_cmd(const char *name, const char *list);
 
 /*
monitor/hmp-cmds.c +3 -3
index e9fb8d827a0..bcd0a1fc878 100644
@@ -290,16 +290,16 @@ void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
 
 void hmp_info_history(Monitor *mon, const QDict *qdict)
 {
-    MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, parent_obj);
+    MonitorHMP *hmp = container_of(mon, MonitorHMP, parent_obj);
     int i;
     const char *str;
 
-    if (!hmp_mon->rs) {
+    if (!hmp->rs) {
         return;
     }
     i = 0;
     for(;;) {
-        str = readline_get_history(hmp_mon->rs, i);
+        str = readline_get_history(hmp->rs, i);
         if (!str) {
             break;
         }
monitor/hmp.c +68 -67

353 lines not on this page · raw message

ui/ui-hmp-cmds.c +2 -2
index 06f4030ce4f..24cf3a67104 100644
@@ -343,8 +343,8 @@ void hmp_change_vnc(Monitor *mon, const char *device, const char *target,
         return;
     }
     if (!arg) {
-        MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, parent_obj);
-        monitor_read_password(hmp_mon, hmp_change_read_arg, NULL);
+        MonitorHMP *hmp = container_of(mon, MonitorHMP, parent_obj);
+        monitor_read_password(hmp, hmp_change_read_arg, NULL);
     } else {
         qmp_change_vnc_password(arg, errp);
     }
Signature · 1 line
2.53.0
#53 lore raw

[PULL 54/56] monitor: Replace container_of(MonitorHMP, parent_obj) -> MONITOR_HMP()

In reply to Philippe Mathieu-Daudé

By replacing the container_of(MonitorHMP) use in ui/ui-hmp-cmds.c we can remove its incorrect inclusion of "monitor/monitor-internal.h" header, using the public "monitor/monitor.h" instead.

Message-Id: <[email protected]>

---
 monitor/hmp-cmds.c | 2 +-
 monitor/hmp.c      | 2 +-
 ui/ui-hmp-cmds.c   | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
monitor/hmp-cmds.c +1 -1
index bcd0a1fc878..4e8d996dbb5 100644
@@ -290,7 +290,7 @@ void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
 
 void hmp_info_history(Monitor *mon, const QDict *qdict)
 {
-    MonitorHMP *hmp = container_of(mon, MonitorHMP, parent_obj);
+    MonitorHMP *hmp = MONITOR_HMP(mon);
     int i;
     const char *str;
 
monitor/hmp.c +1 -1
index 46f8d4a6ede..22b1972d346 100644
@@ -1520,7 +1520,7 @@ cleanup:
 static void monitor_read(void *opaque, const uint8_t *buf, int size)
 {
     Monitor *mon = opaque;
-    MonitorHMP *hmp = container_of(mon, MonitorHMP, parent_obj);
+    MonitorHMP *hmp = MONITOR_HMP(mon);
     int i;
 
     if (hmp->rs) {
ui/ui-hmp-cmds.c +2 -2
index 24cf3a67104..806a7bece7c 100644
@@ -19,7 +19,7 @@
 #endif
 #include "monitor/hmp.h"
 #include "monitor/hmp-completion.h"
-#include "monitor/monitor-internal.h"
+#include "monitor/monitor.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-ui.h"
 #include "qobject/qdict.h"
@@ -343,7 +343,7 @@ void hmp_change_vnc(Monitor *mon, const char *device, const char *target,
         return;
     }
     if (!arg) {
-        MonitorHMP *hmp = container_of(mon, MonitorHMP, parent_obj);
+        MonitorHMP *hmp = MONITOR_HMP(mon);
         monitor_read_password(hmp, hmp_change_read_arg, NULL);
     } else {
         qmp_change_vnc_password(arg, errp);
Signature · 1 line
2.53.0
#54 lore raw

[PULL 53/56] monitor: Better express monitor_read()'s opaque arg is of Monitor type

In reply to Philippe Mathieu-Daudé

monitor_read() is a IOReadHandler handler, called by qemu_chr_fe_set_handlers() with a Monitor* opaque argument.

Message-Id: <[email protected]>

---
 monitor/hmp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
monitor/hmp.c +2 -1
index cbf7a114c0c..46f8d4a6ede 100644
@@ -1519,7 +1519,8 @@ cleanup:
 
 static void monitor_read(void *opaque, const uint8_t *buf, int size)
 {
-    MonitorHMP *hmp = container_of(opaque, MonitorHMP, parent_obj);
+    Monitor *mon = opaque;
+    MonitorHMP *hmp = container_of(mon, MonitorHMP, parent_obj);
     int i;
 
     if (hmp->rs) {
Signature · 1 line
2.53.0
#55 lore raw

[PULL 55/56] hw/elf_ops: defend against weird elf headers

In reply to Philippe Mathieu-Daudé

From: Alex Bennée <[email protected]>

According to the ELF spec:

PT_LOAD

The array element specifies a loadable segment, described by p_filesz and p_memsz. The bytes from the file are mapped to the beginning of the memory segment. If the segment's memory size (p_memsz) is larger than the file size (p_filesz), the ``extra'' bytes are defined to hold the value 0 and to follow the segment's initialized area. The file size may not be larger than the memory size. Loadable segment entries in the program header table appear in ascending order, sorted on the p_vaddr member.

which implies while both p_filesz and p_memsz can be zero we should never see a case where p_filesz is greater than the in memory size. Indeed it has been reported such a hand crafted ELF can blow up, for example during rom_reset():

address_space_set(rom->as, rom->addr + rom->datasize, 0,

                    rom->romsize - rom->datasize,
                    MEMTXATTRS_UNSPECIFIED);

which could trigger and underflow leaving QEMU slowly filling a very large buffer.

Message-ID: <[email protected]>

---
 include/hw/elf_ops.h.inc | 5 +++++
 1 file changed, 5 insertions(+)
include/hw/elf_ops.h.inc +5 -0
index 9c35d1b9da6..044e72de2a2 100644
@@ -427,6 +427,11 @@ static ssize_t glue(load_elf, SZ)(const char *name, int fd,
             file_size = ph->p_filesz; /* Size of the allocated data */
             data_offset = ph->p_offset; /* Offset where the data is located */
 
+            if (file_size > mem_size) {
+                ret = ELF_LOAD_TOO_BIG;
+                goto fail;
+            }
+
             if (file_size > 0) {
                 if (g_mapped_file_get_length(mapped_file) <
                     file_size + data_offset) {
Signature · 1 line
2.53.0
#56 lore raw

[PULL 56/56] hw/core/machine: Move EHCI migration compat properties to 11.1

In reply to Philippe Mathieu-Daudé

From: Jamin Lin <[email protected]>

The x-migrate-fetch-addr-64bit compatibility properties for sysbus-ehci-usb and pci-ehci-usb were reviewed before the QEMU 11.1 release and were therefore initially added to hw_compat_11_0.

However, the EHCI migration change was merged after the QEMU 11.1 release. As a result, these compatibility properties belong in hw_compat_11_1 rather than hw_compat_11_0.

Move both properties to hw_compat_11_1 so that migration compatibility is associated with the correct machine version.

Fixes 38ed803aebb2 ("usb/hcd-ehci: Change descriptor addresses to 64-bit")

Message-ID: <[email protected]>

---
 hw/core/machine.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/core/machine.c +4 -3
index 4e551194465..e617f7804d4 100644
@@ -40,7 +40,10 @@
 #include "qemu/audio.h"
 #include "hw/arm/smmuv3.h"
 
-GlobalProperty hw_compat_11_1[] = {};
+GlobalProperty hw_compat_11_1[] = {
+    { "sysbus-ehci-usb", "x-migrate-fetch-addr-64bit", "off" },
+    { "pci-ehci-usb", "x-migrate-fetch-addr-64bit", "off" },
+};
 const size_t hw_compat_11_1_len = G_N_ELEMENTS(hw_compat_11_1);
 
 GlobalProperty hw_compat_11_0[] = {
@@ -54,8 +57,6 @@ GlobalProperty hw_compat_11_0[] = {
     { TYPE_ARM_SMMUV3, "ssidsize", "0" },
     { TYPE_ARM_SMMUV3, "oas", "44" },
     { "migration", "switchover-ack-legacy", "on" },
-    { "sysbus-ehci-usb", "x-migrate-fetch-addr-64bit", "off" },
-    { "pci-ehci-usb", "x-migrate-fetch-addr-64bit", "off" },
 };
 const size_t hw_compat_11_0_len = G_N_ELEMENTS(hw_compat_11_0);
 
Signature · 1 line
2.53.0
#57 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 24 lines · Philippe Mathieu-Daudé

The following changes since commit af06b5df2610fe5de6c02d17c17bced9e9f0d47d:

   Merge tag 'qom-qdev-20260814' ofhttps://gitlab.com/mcayland-ntx/qemu into staging (2026-08-14 08:44:51 -0700)

are available in the Git repository at:

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

for you to fetch changes up to b409523587c49a08b1ddadd51212a320092347b1:

   hw/core/machine: Move EHCI migration compat properties to 11.1 (2026-08-16 16:35:27 +0200)

----------------------------------------------------------------
Misc HW and Monitor patch queue

- Bug fixes

. Reinstate x86/pc 'xenfv' machine alias
. Defend against malformed ELF headers to prevent underflows . Restore ROMD mode after migration for Intel PFlash (CFI01) . Fix VLAN tag handling on incoming packets on RTL8139 model

- Refactoring (Monitor, common CPU, NMI)

Quoted 8 lines

. Add missing inclusions and remove unnecessary ones . Use qdev_is_realized() consistently (no direct field access) . Remove deprecated DEFINE_PROP_DMAADDR() macro
. Renaming churn around cpu_{exec,common}* helpers
. Simplify NMI API hanlding
. Move QMP handlers (physmem, nmi) to appropriate subsystems . Replace container_of() casts with HMP typed accessors . Rename @mon to @hmp in MonitorHMP for clarity

Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/11.2 as appropriate.

r~