Skip to contentSkip to conversation

hw/misc/vmcoreinfo: Convert from QDev to plain Object

RFC PATCH In review Philippe Mathieu-Daudé 4 participants 22 messages Dec 19, 2024 – Dec 20, 2024

lore
Share & tools
lore
#0 lore raw

cover hw/misc/vmcoreinfo: Convert from QDev to plain Object

No reason for vmcoreinfo to be based on QDev, since it doesn't use any QDev API. Demote to plain Object.

Since we can only register one type, introduce a new one for object: 'vmcore-info' (dash separator), keeping 'vmcoreinfo' device during the deprecation period.

Philippe Mathieu-Daudé (10):
hw/misc/vmcoreinfo: Declare QOM type using DEFINE_TYPES macro hw/misc/vmcoreinfo: Rename opaque pointer as 'opaque' hw/misc/vmcoreinfo: Un-inline vmcoreinfo_find() hw/misc/vmcoreinfo: Rename VMCOREINFO_DEVICE -> TYPE_VMCOREINFO_DEVICE hw/misc/vmcoreinfo: Convert to three-phase reset interface hw/misc/vmcoreinfo: Move vmstate_vmcoreinfo[] around hw/misc/vmcoreinfo: Factor vmcoreinfo_device_realize() out hw/misc/vmcoreinfo: Implement 'vmcore-info' object hw/misc/vmcoreinfo: Deprecate '-device vmcoreinfo' hw/misc/vmcoreinfo: Remove legacy '-device vmcoreinfo'

 docs/about/removed-features.rst |   5 +
 include/hw/misc/vmcoreinfo.h    |  26 ++---
 hw/misc/vmcoreinfo.c            | 167 +++++++++++++++++++-------------
 3 files changed, 116 insertions(+), 82 deletions(-)
Signature · 1 line
2.47.1
#1 lore raw

RFC PATCH 1/10 hw/misc/vmcoreinfo: Declare QOM type using DEFINE_TYPES macro

---
 hw/misc/vmcoreinfo.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
hw/misc/vmcoreinfo.c +8 -11
index 833773ade52..84b211e9117 100644
@@ -93,16 +93,13 @@ static void vmcoreinfo_device_class_init(ObjectClass *klass, void *data)
     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
 }
 
-static const TypeInfo vmcoreinfo_device_info = {
-    .name          = VMCOREINFO_DEVICE,
-    .parent        = TYPE_DEVICE,
-    .instance_size = sizeof(VMCoreInfoState),
-    .class_init    = vmcoreinfo_device_class_init,
+static const TypeInfo vmcoreinfo_types[] = {
+    {
+        .name           = VMCOREINFO_DEVICE,
+        .parent         = TYPE_DEVICE,
+        .instance_size  = sizeof(VMCoreInfoState),
+        .class_init     = vmcoreinfo_device_class_init,
+    }
 };
 
-static void vmcoreinfo_register_types(void)
-{
-    type_register_static(&vmcoreinfo_device_info);
-}
-
-type_init(vmcoreinfo_register_types)
+DEFINE_TYPES(vmcoreinfo_types)
Signature · 1 line
2.47.1
Reviewed-by on v1 1/10
#2 lore raw

Re: [RFC PATCH 01/10] hw/misc/vmcoreinfo: Declare QOM type using DEFINE_TYPES macro

Quoted 4 lines · Philippe Mathieu-Daudé
---
 hw/misc/vmcoreinfo.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#3 lore raw

RFC PATCH 2/10 hw/misc/vmcoreinfo: Rename opaque pointer as 'opaque'

In reply to Philippe Mathieu-Daudé

Both QEMUResetHandler and FWCfgWriteCallback take an opaque pointer argument, no need to cast.

---
 hw/misc/vmcoreinfo.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
hw/misc/vmcoreinfo.c +5 -5
index 84b211e9117..ad5a4dec596 100644
@@ -18,17 +18,17 @@
 #include "migration/vmstate.h"
 #include "hw/misc/vmcoreinfo.h"
 
-static void fw_cfg_vmci_write(void *dev, off_t offset, size_t len)
+static void fw_cfg_vmci_write(void *opaque, off_t offset, size_t len)
 {
-    VMCoreInfoState *s = VMCOREINFO(dev);
+    VMCoreInfoState *s = opaque;
 
     s->has_vmcoreinfo = offset == 0 && len == sizeof(s->vmcoreinfo)
         && s->vmcoreinfo.guest_format != FW_CFG_VMCOREINFO_FORMAT_NONE;
 }
 
-static void vmcoreinfo_reset(void *dev)
+static void vmcoreinfo_reset(void *opaque)
 {
-    VMCoreInfoState *s = VMCOREINFO(dev);
+    VMCoreInfoState *s = opaque;
 
     s->has_vmcoreinfo = false;
     memset(&s->vmcoreinfo, 0, sizeof(s->vmcoreinfo));
@@ -65,7 +65,7 @@ static void vmcoreinfo_realize(DeviceState *dev, Error **errp)
      * This device requires to register a global reset because it is
      * not plugged to a bus (which, as its QOM parent, would reset it).
      */
-    qemu_register_reset(vmcoreinfo_reset, dev);
+    qemu_register_reset(vmcoreinfo_reset, s);
     vmcoreinfo_state = s;
 }
 
Signature · 1 line
2.47.1
Reviewed-by on v1 2/10
#4 lore raw

Re: [RFC PATCH 02/10] hw/misc/vmcoreinfo: Rename opaque pointer as 'opaque'

Quoted 7 lines · Philippe Mathieu-Daudé

Both QEMUResetHandler and FWCfgWriteCallback take an opaque pointer argument, no need to cast.

---
 hw/misc/vmcoreinfo.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#5 lore raw

RFC PATCH 3/10 hw/misc/vmcoreinfo: Un-inline vmcoreinfo_find()

In reply to Philippe Mathieu-Daudé
---
 include/hw/misc/vmcoreinfo.h | 13 ++++++-------
 hw/misc/vmcoreinfo.c         | 16 +++++++++++++---
 2 files changed, 19 insertions(+), 10 deletions(-)
include/hw/misc/vmcoreinfo.h +6 -7
index 0b7b55d400a..da1066d540c 100644
@@ -30,12 +30,11 @@ struct VMCoreInfoState {
     FWCfgVMCoreInfo vmcoreinfo;
 };
 
-/* returns NULL unless there is exactly one device */
-static inline VMCoreInfoState *vmcoreinfo_find(void)
-{
-    Object *o = object_resolve_path_type("", VMCOREINFO_DEVICE, NULL);
-
-    return o ? VMCOREINFO(o) : NULL;
-}
+/**
+ * vmcoreinfo_find:
+ *
+ * Returns NULL unless there is exactly one instance.
+ */
+VMCoreInfoState *vmcoreinfo_find(void);
 
 #endif
hw/misc/vmcoreinfo.c +13 -3
index ad5a4dec596..c5bb5c9fa52 100644
@@ -42,11 +42,12 @@ static void vmcoreinfo_realize(DeviceState *dev, Error **errp)
     /* for gdb script dump-guest-memory.py */
     static VMCoreInfoState * volatile vmcoreinfo_state G_GNUC_UNUSED;
 
-    /* Given that this function is executing, there is at least one VMCOREINFO
-     * device. Check if there are several.
+    /*
+     * Given that this function is executing, there is at least one
+     * VMCOREINFO instance. Check if there are several.
      */
     if (!vmcoreinfo_find()) {
-        error_setg(errp, "at most one %s device is permitted",
+        error_setg(errp, "at most one %s instance is permitted",
                    VMCOREINFO_DEVICE);
         return;
     }
@@ -103,3 +104,12 @@ static const TypeInfo vmcoreinfo_types[] = {
 };
 
 DEFINE_TYPES(vmcoreinfo_types)
+
+VMCoreInfoState *vmcoreinfo_find(void)
+{
+    Object *obj;
+
+    obj = object_resolve_path_type("", TYPE_VMCOREINFO_DEVICE, NULL);
+
+    return obj ? (VMCoreInfoState *)obj : NULL;
+}
Signature · 1 line
2.47.1
Reviewed-by Reviewed-by on v1 3/10
#6 lore raw

Re: [RFC PATCH 03/10] hw/misc/vmcoreinfo: Un-inline vmcoreinfo_find()

Quoted 5 lines · Philippe Mathieu-Daudé
---
 include/hw/misc/vmcoreinfo.h | 13 ++++++-------
 hw/misc/vmcoreinfo.c         | 16 +++++++++++++---
 2 files changed, 19 insertions(+), 10 deletions(-)
Quoted 10 lines
hw/misc/vmcoreinfo.c +0 -2
index ad5a4dec596..c5bb5c9fa52 100644
@@ -42,11 +42,12 @@ static void vmcoreinfo_realize(DeviceState *dev, Error **errp)
     /* for gdb script dump-guest-memory.py */
     static VMCoreInfoState * volatile vmcoreinfo_state G_GNUC_UNUSED;
 
-    /* Given that this function is executing, there is at least one VMCOREINFO
-     * device. Check if there are several.

hw/misc/vmcoreinfo.c static void vmcoreinfo_realize(DeviceState *dev, Error **errp) · line 53

Quoted 10 lines
hw/misc/vmcoreinfo.c +4 -1
+    /*
+     * Given that this function is executing, there is at least one
+     * VMCOREINFO instance. Check if there are several.
      */
     if (!vmcoreinfo_find()) {
-        error_setg(errp, "at most one %s device is permitted",
+        error_setg(errp, "at most one %s instance is permitted",
                    VMCOREINFO_DEVICE);
         return;
     }

This chunk is unrelated to the claimed goal of this commit. It makes sense as a change though, so feel free to add my R-B when splitting into a separate commit.

hw/misc/vmcoreinfo.c static const TypeInfo vmcoreinfo_types[] = { · line 115

Quoted 13 lines
hw/misc/vmcoreinfo.c +9 -0
@@ -103,3 +104,12 @@ static const TypeInfo vmcoreinfo_types[] = {
 };
 
 DEFINE_TYPES(vmcoreinfo_types)
+
+VMCoreInfoState *vmcoreinfo_find(void)
+{
+    Object *obj;
+
+    obj = object_resolve_path_type("", TYPE_VMCOREINFO_DEVICE, NULL);
+
+    return obj ? (VMCoreInfoState *)obj : NULL;
+}
Quoted 3 lines
Signature · 1 line
2.47.1

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#7 lore raw

RFC PATCH 4/10 hw/misc/vmcoreinfo: Rename VMCOREINFO_DEVICE -> TYPE_VMCOREINFO_DEVICE

In reply to Philippe Mathieu-Daudé

Follow the assumed QOM type definition style, prefixing with 'TYPE_'.

---
 include/hw/misc/vmcoreinfo.h | 6 +++---
 hw/misc/vmcoreinfo.c         | 8 ++++----
 2 files changed, 7 insertions(+), 7 deletions(-)
include/hw/misc/vmcoreinfo.h +3 -3
index da1066d540c..122c69686b0 100644
@@ -16,10 +16,10 @@
 #include "standard-headers/linux/qemu_fw_cfg.h"
 #include "qom/object.h"
 
-#define VMCOREINFO_DEVICE "vmcoreinfo"
+#define TYPE_VMCOREINFO_DEVICE "vmcoreinfo"
 typedef struct VMCoreInfoState VMCoreInfoState;
-DECLARE_INSTANCE_CHECKER(VMCoreInfoState, VMCOREINFO,
-                         VMCOREINFO_DEVICE)
+DECLARE_INSTANCE_CHECKER(VMCoreInfoState, VMCOREINFO_DEVICE,
+                         TYPE_VMCOREINFO_DEVICE)
 
 typedef struct fw_cfg_vmcoreinfo FWCfgVMCoreInfo;
 
hw/misc/vmcoreinfo.c +4 -4
index c5bb5c9fa52..9822615cfed 100644
@@ -37,7 +37,7 @@ static void vmcoreinfo_reset(void *opaque)
 
 static void vmcoreinfo_realize(DeviceState *dev, Error **errp)
 {
-    VMCoreInfoState *s = VMCOREINFO(dev);
+    VMCoreInfoState *s = VMCOREINFO_DEVICE(dev);
     FWCfgState *fw_cfg = fw_cfg_find();
     /* for gdb script dump-guest-memory.py */
     static VMCoreInfoState * volatile vmcoreinfo_state G_GNUC_UNUSED;
@@ -48,13 +48,13 @@ static void vmcoreinfo_realize(DeviceState *dev, Error **errp)
      */
     if (!vmcoreinfo_find()) {
         error_setg(errp, "at most one %s instance is permitted",
-                   VMCOREINFO_DEVICE);
+                   TYPE_VMCOREINFO_DEVICE);
         return;
     }
 
     if (!fw_cfg || !fw_cfg->dma_enabled) {
         error_setg(errp, "%s device requires fw_cfg with DMA",
-                   VMCOREINFO_DEVICE);
+                   TYPE_VMCOREINFO_DEVICE);
         return;
     }
 
@@ -96,7 +96,7 @@ static void vmcoreinfo_device_class_init(ObjectClass *klass, void *data)
 
 static const TypeInfo vmcoreinfo_types[] = {
     {
-        .name           = VMCOREINFO_DEVICE,
+        .name           = TYPE_VMCOREINFO_DEVICE,
         .parent         = TYPE_DEVICE,
         .instance_size  = sizeof(VMCoreInfoState),
         .class_init     = vmcoreinfo_device_class_init,
Signature · 1 line
2.47.1
#8 lore raw

Re: [RFC PATCH 04/10] hw/misc/vmcoreinfo: Rename VMCOREINFO_DEVICE -> TYPE_VMCOREINFO_DEVICE

Quoted 13 lines · Philippe Mathieu-Daudé

Follow the assumed QOM type definition style, prefixing with 'TYPE_'.

---
 include/hw/misc/vmcoreinfo.h | 6 +++---
 hw/misc/vmcoreinfo.c         | 8 ++++----
 2 files changed, 7 insertions(+), 7 deletions(-)
include/hw/misc/vmcoreinfo.h +0 -0
index da1066d540c..122c69686b0 100644

include/hw/misc/vmcoreinfo.h line 19

Quoted 5 lines
include/hw/misc/vmcoreinfo.h +1 -1
@@ -16,10 +16,10 @@
 #include "standard-headers/linux/qemu_fw_cfg.h"
 #include "qom/object.h"
 
-#define VMCOREINFO_DEVICE "vmcoreinfo"
+#define TYPE_VMCOREINFO_DEVICE "vmcoreinfo"

Yes to adding TYPE_, but while there would also drop _DEVICE. IMHO the best practice is for TYPE_<NNNN> where NNNN matches the "nnnn" name. An extra suffix doesn't add value, unless we've got some other symbol clashing which is almost never the case.

Quoted 49 lines
include/hw/misc/vmcoreinfo.h +2 -2
 typedef struct VMCoreInfoState VMCoreInfoState;
-DECLARE_INSTANCE_CHECKER(VMCoreInfoState, VMCOREINFO,
-                         VMCOREINFO_DEVICE)
+DECLARE_INSTANCE_CHECKER(VMCoreInfoState, VMCOREINFO_DEVICE,
+                         TYPE_VMCOREINFO_DEVICE)
 
 typedef struct fw_cfg_vmcoreinfo FWCfgVMCoreInfo;
 
hw/misc/vmcoreinfo.c +4 -4
index c5bb5c9fa52..9822615cfed 100644
@@ -37,7 +37,7 @@ static void vmcoreinfo_reset(void *opaque)
 
 static void vmcoreinfo_realize(DeviceState *dev, Error **errp)
 {
-    VMCoreInfoState *s = VMCOREINFO(dev);
+    VMCoreInfoState *s = VMCOREINFO_DEVICE(dev);
     FWCfgState *fw_cfg = fw_cfg_find();
     /* for gdb script dump-guest-memory.py */
     static VMCoreInfoState * volatile vmcoreinfo_state G_GNUC_UNUSED;
@@ -48,13 +48,13 @@ static void vmcoreinfo_realize(DeviceState *dev, Error **errp)
      */
     if (!vmcoreinfo_find()) {
         error_setg(errp, "at most one %s instance is permitted",
-                   VMCOREINFO_DEVICE);
+                   TYPE_VMCOREINFO_DEVICE);
         return;
     }
 
     if (!fw_cfg || !fw_cfg->dma_enabled) {
         error_setg(errp, "%s device requires fw_cfg with DMA",
-                   VMCOREINFO_DEVICE);
+                   TYPE_VMCOREINFO_DEVICE);
         return;
     }
 
@@ -96,7 +96,7 @@ static void vmcoreinfo_device_class_init(ObjectClass *klass, void *data)
 
 static const TypeInfo vmcoreinfo_types[] = {
     {
-        .name           = VMCOREINFO_DEVICE,
+        .name           = TYPE_VMCOREINFO_DEVICE,
         .parent         = TYPE_DEVICE,
         .instance_size  = sizeof(VMCoreInfoState),
         .class_init     = vmcoreinfo_device_class_init,
Signature · 1 line
2.47.1

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#9 lore raw

Re: [RFC PATCH 04/10] hw/misc/vmcoreinfo: Rename VMCOREINFO_DEVICE -> TYPE_VMCOREINFO_DEVICE

Quoted 17 lines · Daniel P. Berrangé
Quoted 16 lines · Philippe Mathieu-Daudé

Follow the assumed QOM type definition style, prefixing with 'TYPE_'.

---
  include/hw/misc/vmcoreinfo.h | 6 +++---
  hw/misc/vmcoreinfo.c         | 8 ++++----
  2 files changed, 7 insertions(+), 7 deletions(-)
include/hw/misc/vmcoreinfo.h +0 -0
index da1066d540c..122c69686b0 100644
@@ -16,10 +16,10 @@
  #include "standard-headers/linux/qemu_fw_cfg.h"
  #include "qom/object.h"
 
Quoted 9 lines

include/hw/misc/vmcoreinfo.h line 19

Quoted 2 lines
include/hw/misc/vmcoreinfo.h +1 -1
-#define VMCOREINFO_DEVICE "vmcoreinfo"
+#define TYPE_VMCOREINFO_DEVICE "vmcoreinfo"

Yes to adding TYPE_, but while there would also drop _DEVICE. IMHO the best practice is for TYPE_<NNNN> where NNNN matches the "nnnn" name. An extra suffix doesn't add value, unless we've got some other symbol clashing which is almost never the case.

Yeah, I added the _DEVICE suffix in preparation of the plain object implementation.

Quoted 53 lines
Quoted 50 lines
include/hw/misc/vmcoreinfo.h +2 -2
  typedef struct VMCoreInfoState VMCoreInfoState;
-DECLARE_INSTANCE_CHECKER(VMCoreInfoState, VMCOREINFO,
-                         VMCOREINFO_DEVICE)
+DECLARE_INSTANCE_CHECKER(VMCoreInfoState, VMCOREINFO_DEVICE,
+                         TYPE_VMCOREINFO_DEVICE)
 
  typedef struct fw_cfg_vmcoreinfo FWCfgVMCoreInfo;
 
hw/misc/vmcoreinfo.c +4 -4
index c5bb5c9fa52..9822615cfed 100644
@@ -37,7 +37,7 @@ static void vmcoreinfo_reset(void *opaque)
 
  static void vmcoreinfo_realize(DeviceState *dev, Error **errp)
  {
-    VMCoreInfoState *s = VMCOREINFO(dev);
+    VMCoreInfoState *s = VMCOREINFO_DEVICE(dev);
      FWCfgState *fw_cfg = fw_cfg_find();
      /* for gdb script dump-guest-memory.py */
      static VMCoreInfoState * volatile vmcoreinfo_state G_GNUC_UNUSED;
@@ -48,13 +48,13 @@ static void vmcoreinfo_realize(DeviceState *dev, Error **errp)
       */
      if (!vmcoreinfo_find()) {
          error_setg(errp, "at most one %s instance is permitted",
-                   VMCOREINFO_DEVICE);
+                   TYPE_VMCOREINFO_DEVICE);
          return;
      }
 
      if (!fw_cfg || !fw_cfg->dma_enabled) {
          error_setg(errp, "%s device requires fw_cfg with DMA",
-                   VMCOREINFO_DEVICE);
+                   TYPE_VMCOREINFO_DEVICE);
          return;
      }
 
@@ -96,7 +96,7 @@ static void vmcoreinfo_device_class_init(ObjectClass *klass, void *data)
 
  static const TypeInfo vmcoreinfo_types[] = {
      {
-        .name           = VMCOREINFO_DEVICE,
+        .name           = TYPE_VMCOREINFO_DEVICE,
          .parent         = TYPE_DEVICE,
          .instance_size  = sizeof(VMCoreInfoState),
          .class_init     = vmcoreinfo_device_class_init,
Signature · 1 line
2.47.1

With regards,
Daniel

#10 lore raw

RFC PATCH 5/10 hw/misc/vmcoreinfo: Convert to three-phase reset interface

In reply to Philippe Mathieu-Daudé
---
 hw/misc/vmcoreinfo.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
hw/misc/vmcoreinfo.c +5 -3
index 9822615cfed..093bede655e 100644
@@ -26,9 +26,9 @@ static void fw_cfg_vmci_write(void *opaque, off_t offset, size_t len)
         && s->vmcoreinfo.guest_format != FW_CFG_VMCOREINFO_FORMAT_NONE;
 }
 
-static void vmcoreinfo_reset(void *opaque)
+static void vmcoreinfo_reset_hold(Object *obj, ResetType type)
 {
-    VMCoreInfoState *s = opaque;
+    VMCoreInfoState *s = (VMCoreInfoState *)obj;
 
     s->has_vmcoreinfo = false;
     memset(&s->vmcoreinfo, 0, sizeof(s->vmcoreinfo));
@@ -66,7 +66,7 @@ static void vmcoreinfo_realize(DeviceState *dev, Error **errp)
      * This device requires to register a global reset because it is
      * not plugged to a bus (which, as its QOM parent, would reset it).
      */
-    qemu_register_reset(vmcoreinfo_reset, s);
+    qemu_register_resettable(OBJECT(s));
     vmcoreinfo_state = s;
 }
 
@@ -87,11 +87,13 @@ static const VMStateDescription vmstate_vmcoreinfo = {
 static void vmcoreinfo_device_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
     dc->vmsd = &vmstate_vmcoreinfo;
     dc->realize = vmcoreinfo_realize;
     dc->hotpluggable = false;
     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+    rc->phases.hold = vmcoreinfo_reset_hold;
 }
 
 static const TypeInfo vmcoreinfo_types[] = {
Signature · 1 line
2.47.1
Reviewed-by on v1 5/10
#11 lore raw

Re: [RFC PATCH 05/10] hw/misc/vmcoreinfo: Convert to three-phase reset interface

Quoted 4 lines · Philippe Mathieu-Daudé
---
 hw/misc/vmcoreinfo.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#12 lore raw

RFC PATCH 6/10 hw/misc/vmcoreinfo: Move vmstate_vmcoreinfo[] around

In reply to Philippe Mathieu-Daudé

In order to simplify the next commit,
move vmstate_vmcoreinfo[] around.

---
 hw/misc/vmcoreinfo.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
hw/misc/vmcoreinfo.c +14 -14
index 093bede655e..55f9d437a94 100644
@@ -18,6 +18,20 @@
 #include "migration/vmstate.h"
 #include "hw/misc/vmcoreinfo.h"
 
+static const VMStateDescription vmstate_vmcoreinfo = {
+    .name = "vmcoreinfo",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields = (const VMStateField[]) {
+        VMSTATE_BOOL(has_vmcoreinfo, VMCoreInfoState),
+        VMSTATE_UINT16(vmcoreinfo.host_format, VMCoreInfoState),
+        VMSTATE_UINT16(vmcoreinfo.guest_format, VMCoreInfoState),
+        VMSTATE_UINT32(vmcoreinfo.size, VMCoreInfoState),
+        VMSTATE_UINT64(vmcoreinfo.paddr, VMCoreInfoState),
+        VMSTATE_END_OF_LIST()
+    },
+};
+
 static void fw_cfg_vmci_write(void *opaque, off_t offset, size_t len)
 {
     VMCoreInfoState *s = opaque;
@@ -70,20 +84,6 @@ static void vmcoreinfo_realize(DeviceState *dev, Error **errp)
     vmcoreinfo_state = s;
 }
 
-static const VMStateDescription vmstate_vmcoreinfo = {
-    .name = "vmcoreinfo",
-    .version_id = 1,
-    .minimum_version_id = 1,
-    .fields = (const VMStateField[]) {
-        VMSTATE_BOOL(has_vmcoreinfo, VMCoreInfoState),
-        VMSTATE_UINT16(vmcoreinfo.host_format, VMCoreInfoState),
-        VMSTATE_UINT16(vmcoreinfo.guest_format, VMCoreInfoState),
-        VMSTATE_UINT32(vmcoreinfo.size, VMCoreInfoState),
-        VMSTATE_UINT64(vmcoreinfo.paddr, VMCoreInfoState),
-        VMSTATE_END_OF_LIST()
-    },
-};
-
 static void vmcoreinfo_device_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
Signature · 1 line
2.47.1
#13 lore raw

RFC PATCH 7/10 hw/misc/vmcoreinfo: Factor vmcoreinfo_device_realize() out

In reply to Philippe Mathieu-Daudé

In preparation of implementing a UserCreatable callback in the next commit, factor vmcoreinfo_device_realize() out.

---
 hw/misc/vmcoreinfo.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
hw/misc/vmcoreinfo.c +7 -3
index 55f9d437a94..a0511ea0da4 100644
@@ -49,9 +49,8 @@ static void vmcoreinfo_reset_hold(Object *obj, ResetType type)
     s->vmcoreinfo.host_format = cpu_to_le16(FW_CFG_VMCOREINFO_FORMAT_ELF);
 }
 
-static void vmcoreinfo_realize(DeviceState *dev, Error **errp)
+static void vmcoreinfo_realize(VMCoreInfoState *s, Error **errp)
 {
-    VMCoreInfoState *s = VMCOREINFO_DEVICE(dev);
     FWCfgState *fw_cfg = fw_cfg_find();
     /* for gdb script dump-guest-memory.py */
     static VMCoreInfoState * volatile vmcoreinfo_state G_GNUC_UNUSED;
@@ -84,13 +83,18 @@ static void vmcoreinfo_realize(DeviceState *dev, Error **errp)
     vmcoreinfo_state = s;
 }
 
+static void vmcoreinfo_device_realize(DeviceState *dev, Error **errp)
+{
+    vmcoreinfo_realize(VMCOREINFO_DEVICE(dev), errp);
+}
+
 static void vmcoreinfo_device_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     ResettableClass *rc = RESETTABLE_CLASS(klass);
 
     dc->vmsd = &vmstate_vmcoreinfo;
-    dc->realize = vmcoreinfo_realize;
+    dc->realize = vmcoreinfo_device_realize;
     dc->hotpluggable = false;
     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
     rc->phases.hold = vmcoreinfo_reset_hold;
Signature · 1 line
2.47.1
#14 lore raw

RFC PATCH 8/10 hw/misc/vmcoreinfo: Implement 'vmcore-info' object

In reply to Philippe Mathieu-Daudé

'vmcore-info' object allow to transition from '-device' to 'object', following the deprecation process.

No need to modify VMCoreInfoState since DeviceState already inherits from Object state.

---
 include/hw/misc/vmcoreinfo.h |  4 ++-
 hw/misc/vmcoreinfo.c         | 48 +++++++++++++++++++++++++++++++++++-
 2 files changed, 50 insertions(+), 2 deletions(-)
include/hw/misc/vmcoreinfo.h +3 -1
index 122c69686b0..d4cce42cee6 100644
@@ -16,8 +16,10 @@
 #include "standard-headers/linux/qemu_fw_cfg.h"
 #include "qom/object.h"
 
+#define TYPE_VMCOREINFO "vmcore-info"
+OBJECT_DECLARE_SIMPLE_TYPE(VMCoreInfoState, VMCOREINFO)
+
 #define TYPE_VMCOREINFO_DEVICE "vmcoreinfo"
-typedef struct VMCoreInfoState VMCoreInfoState;
 DECLARE_INSTANCE_CHECKER(VMCoreInfoState, VMCOREINFO_DEVICE,
                          TYPE_VMCOREINFO_DEVICE)
 
hw/misc/vmcoreinfo.c +47 -1

82 lines not on this page · raw message

Signature · 1 line
2.47.1
#15 lore raw

Re: [RFC PATCH 08/10] hw/misc/vmcoreinfo: Implement 'vmcore-info' object

Hi

Quoted 4 lines · Philippe Mathieu-Daudé

'vmcore-info' object allow to transition from '-device' to 'object', following the deprecation process.

Is there a strong motivation behind this? just replacing -device with -object doesn't really give anything, does it?

Also I'd rather keep the name "vmcoreinfo" since that's how it used to be, and also the name used by the kernel ELF etc.

Quoted 119 lines

No need to modify VMCoreInfoState since DeviceState already inherits from Object state.

---
 include/hw/misc/vmcoreinfo.h |  4 ++-
 hw/misc/vmcoreinfo.c         | 48 +++++++++++++++++++++++++++++++++++-
 2 files changed, 50 insertions(+), 2 deletions(-)
include/hw/misc/vmcoreinfo.h +3 -1
index 122c69686b0..d4cce42cee6 100644
@@ -16,8 +16,10 @@
 #include "standard-headers/linux/qemu_fw_cfg.h"
 #include "qom/object.h"
 
+#define TYPE_VMCOREINFO "vmcore-info"
+OBJECT_DECLARE_SIMPLE_TYPE(VMCoreInfoState, VMCOREINFO)
+
 #define TYPE_VMCOREINFO_DEVICE "vmcoreinfo"
-typedef struct VMCoreInfoState VMCoreInfoState;
 DECLARE_INSTANCE_CHECKER(VMCoreInfoState, VMCOREINFO_DEVICE,
                          TYPE_VMCOREINFO_DEVICE)
 
hw/misc/vmcoreinfo.c +47 -2
index a0511ea0da4..e2258e08fb1 100644
@@ -12,11 +12,11 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
-#include "qemu/module.h"
 #include "sysemu/reset.h"
 #include "hw/nvram/fw_cfg.h"
 #include "migration/vmstate.h"
 #include "hw/misc/vmcoreinfo.h"
+#include "qom/object_interfaces.h"
 
 static const VMStateDescription vmstate_vmcoreinfo = {
     .name = "vmcoreinfo",
@@ -32,6 +32,11 @@ static const VMStateDescription vmstate_vmcoreinfo = {
     },
 };
 
+static char *vmcoreinfo_get_vmstate_id(VMStateIf *vmif)
+{
+    return g_strdup(TYPE_VMCOREINFO);
+}
+
 static void fw_cfg_vmci_write(void *opaque, off_t offset, size_t len)
 {
     VMCoreInfoState *s = opaque;
@@ -88,6 +93,32 @@ static void vmcoreinfo_device_realize(DeviceState *dev, Error **errp)
     vmcoreinfo_realize(VMCOREINFO_DEVICE(dev), errp);
 }
 
+static bool vmcoreinfo_can_be_deleted(UserCreatable *uc)
+{
+    return false;
+}
+
+static void vmcoreinfo_complete(UserCreatable *uc, Error **errp)
+{
+    if (vmstate_register_any(VMSTATE_IF(uc), &vmstate_vmcoreinfo, uc) < 0) {
+        error_setg(errp, "%s: Failed to register vmstate", TYPE_VMCOREINFO);
+    }
+
+    vmcoreinfo_realize(VMCOREINFO(uc), errp);
+}
+
+static void vmcoreinfo_class_init(ObjectClass *oc, void *data)
+{
+    UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
+    VMStateIfClass *vc = VMSTATE_IF_CLASS(oc);
+    ResettableClass *rc = RESETTABLE_CLASS(oc);
+
+    ucc->complete = vmcoreinfo_complete;
+    ucc->can_be_deleted = vmcoreinfo_can_be_deleted;
+    vc->get_id = vmcoreinfo_get_vmstate_id;
+    rc->phases.hold = vmcoreinfo_reset_hold;
+}
+
 static void vmcoreinfo_device_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -106,6 +137,18 @@ static const TypeInfo vmcoreinfo_types[] = {
         .parent         = TYPE_DEVICE,
         .instance_size  = sizeof(VMCoreInfoState),
         .class_init     = vmcoreinfo_device_class_init,
+    },
+    {
+        .name           = TYPE_VMCOREINFO,
+        .parent         = TYPE_OBJECT,
+        .instance_size  = sizeof(VMCoreInfoState),
+        .class_init     = vmcoreinfo_class_init,
+        .interfaces = (InterfaceInfo[]) {
+            { TYPE_RESETTABLE_INTERFACE },
+            { TYPE_USER_CREATABLE },
+            { TYPE_VMSTATE_IF },
+            { }
+        }
     }
 };
 
@@ -116,6 +159,9 @@ VMCoreInfoState *vmcoreinfo_find(void)
     Object *obj;
 
     obj = object_resolve_path_type("", TYPE_VMCOREINFO_DEVICE, NULL);
+    if (!obj) {
+        obj = object_resolve_path_type("", TYPE_VMCOREINFO, NULL);
+    }
 
     return obj ? (VMCoreInfoState *)obj : NULL;
 }
--

2.47.1

#16 lore raw

Re: [RFC PATCH 08/10] hw/misc/vmcoreinfo: Implement 'vmcore-info' object

Quoted 11 lines · Marc-André Lureau

Hi

Quoted 4 lines · Philippe Mathieu-Daudé

'vmcore-info' object allow to transition from '-device' to 'object', following the deprecation process.

Is there a strong motivation behind this? just replacing -device with -object doesn't really give anything, does it?

No. (Daniel mentioned the same on the cover letter:
https://lore.kernel.org/qemu-devel/[email protected]/)

Sorry for wasting review cycles.

Quoted 11 lines

Also I'd rather keep the name "vmcoreinfo" since that's how it used to be, and also the name used by the kernel ELF etc.

Quoted 8 lines

No need to modify VMCoreInfoState since DeviceState already inherits from Object state.

---
  include/hw/misc/vmcoreinfo.h |  4 ++-
  hw/misc/vmcoreinfo.c         | 48 +++++++++++++++++++++++++++++++++++-
  2 files changed, 50 insertions(+), 2 deletions(-)
#17 lore raw

RFC PATCH 9/10 hw/misc/vmcoreinfo: Deprecate '-device vmcoreinfo'

In reply to Philippe Mathieu-Daudé

'-device vmcoreinfo' is replaced by '-object vmcore-info'.

---
 docs/about/deprecated.rst | 5 +++++
 1 file changed, 5 insertions(+)
docs/about/deprecated.rst +5 -0
index d6809f94ea1..57a3d734081 100644
@@ -79,6 +79,11 @@ described with -smp are supported by the target machine.
 
 Use ``-run-with user=..`` instead.
 
+``-device vmcoreinfo`` (since 10.0)
+'''''''''''''''''''''''''''''''''''
+
+Use ``-object vmcore-info`` instead.
+
 
 User-mode emulator command line arguments
 -----------------------------------------
Signature · 1 line
2.47.1
#18 lore raw

RFC 10/10 hw/misc/vmcoreinfo: Remove legacy '-device vmcoreinfo'

In reply to Philippe Mathieu-Daudé
---
 docs/about/deprecated.rst       |  5 ----
 docs/about/removed-features.rst |  5 ++++
 include/hw/misc/vmcoreinfo.h    |  3 +--
 hw/misc/vmcoreinfo.c            | 44 ++++++---------------------------
 4 files changed, 13 insertions(+), 44 deletions(-)
docs/about/deprecated.rst +0 -5
index 57a3d734081..d6809f94ea1 100644
@@ -79,11 +79,6 @@ described with -smp are supported by the target machine.
 
 Use ``-run-with user=..`` instead.
 
-``-device vmcoreinfo`` (since 10.0)
-'''''''''''''''''''''''''''''''''''
-
-Use ``-object vmcore-info`` instead.
-
 
 User-mode emulator command line arguments
 -----------------------------------------
docs/about/removed-features.rst +5 -0
index cb1388049a8..6fedf13c133 100644
@@ -555,6 +555,11 @@ to produce an odd effect (rotating input but not display output). But
 this was never intended or documented behaviour, so we have dropped
 the options along with the machine models they were intended for.
 
+``-device vmcoreinfo`` (removed in 10.2)
+''''''''''''''''''''''''''''''''''''''''
+
+``-device vmcoreinfo`` has been replaced by ``-object vmcore-info``.
+
 User-mode emulator command line arguments
 -----------------------------------------
 
include/hw/misc/vmcoreinfo.h +1 -2
index d4cce42cee6..56af12d33a4 100644
@@ -12,7 +12,6 @@
 #ifndef VMCOREINFO_H
 #define VMCOREINFO_H
 
-#include "hw/qdev-core.h"
 #include "standard-headers/linux/qemu_fw_cfg.h"
 #include "qom/object.h"
 
@@ -26,7 +25,7 @@ DECLARE_INSTANCE_CHECKER(VMCoreInfoState, VMCOREINFO_DEVICE,
 typedef struct fw_cfg_vmcoreinfo FWCfgVMCoreInfo;
 
 struct VMCoreInfoState {
-    DeviceState parent_obj;
+    Object parent_obj;
 
     bool has_vmcoreinfo;
     FWCfgVMCoreInfo vmcoreinfo;
hw/misc/vmcoreinfo.c +7 -37

81 lines not on this page · raw message

Signature · 1 line
2.47.1
#19 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 2 lines · Philippe Mathieu-Daudé

No reason for vmcoreinfo to be based on QDev, since it doesn't use any QDev API. Demote to plain Object.

I'm not especially convinced by that rationale, at least in the short term[1].

As a user of QEMU, I would tend to view -device as being the way to create devices that are visible to the guest, and -object as being for dealing with host backends.

vmcoreinfo is quite an unusal device, in that if only exists as a fwcfg field, but that's an internal impl detail from a user's POV, and it is still a guest visible device type.

So while it may not leverage QDev API, I still feel it is more of a fit for -device, than -object. Is there any functional benefit to moving it to -object, that outweighs the disruption ?

With regards,
Daniel

[1] I say "short term", because overall I'm of the opinion that -device, -machine, -cpu, -chardev, etc should not exist, and -object ought to be made capable of instantiating any type of object whatever subclass it might be. I doubt that will change any time in the forseeable future though, so it is more of a hypothetical point.

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#20 lore raw
Quoted 11 lines · Daniel P. Berrangé,
Quoted 2 lines · Philippe Mathieu-Daudé

No reason for vmcoreinfo to be based on QDev, since it doesn't use any QDev API. Demote to plain Object.

I'm not especially convinced by that rationale, at least in the short term[1].

As a user of QEMU, I would tend to view -device as being the way to create devices that are visible to the guest, and -object as being for dealing with host backends.

Quoted 6 lines

vmcoreinfo is quite an unusal device, in that if only exists as a fwcfg field, but that's an internal impl detail from a user's POV, and it is still a guest visible device type.

So while it may not leverage QDev API, I still feel it is more of a fit for -device, than -object.

+1 to this.

Is there any functional benefit

Quoted 4 lines

to moving it to -object, that outweighs the disruption ?

#21 lore raw
In reply to Daniel P. Berrangé
Quoted 10 lines · Daniel P. Berrangé
Quoted 2 lines · Philippe Mathieu-Daudé

No reason for vmcoreinfo to be based on QDev, since it doesn't use any QDev API. Demote to plain Object.

I'm not especially convinced by that rationale, at least in the short term[1].

As a user of QEMU, I would tend to view -device as being the way to create devices that are visible to the guest, and -object as being for dealing with host backends.

Hmm.

Quoted 7 lines

vmcoreinfo is quite an unusal device, in that if only exists as a fwcfg field, but that's an internal impl detail from a user's POV, and it is still a guest visible device type.

So while it may not leverage QDev API, I still feel it is more of a fit for -device, than -object. Is there any functional benefit to moving it to -object, that outweighs the disruption ?

No.

Patches 1-5 are still useful cleanups although.

Quoted 6 lines

[1] I say "short term", because overall I'm of the opinion that

(quoted diff) +0 -2
-device, -machine, -cpu, -chardev, etc should not exist, and
-object ought to be made capable of instantiating any type of

object whatever subclass it might be. I doubt that will change any time in the forseeable future though, so it is more of a hypothetical point.

Agreed.