Skip to contentSkip to conversation

fix assertion in "info memory-devices" if memdev isn't accessible

PATCH In review Igor Mammedov 3 participants 7 messages Mar 26, 2015 – Mar 27, 2015 Arm STM32

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix assertion in "info memory-devices" if memdev isn't accessible

showing a memory device whose memdev is removed leads to an assert:

(qemu) object_add memory-backend-ram,id=ram0,size=128M (qemu) device_add pc-dimm,id=d0,memdev=ram0 (qemu) object_del ram0
(qemu) info memory-devices
**

ERROR:qom/object.c:1274:object_get_canonical_path_component:\
                            assertion failed: (obj->parent != NULL)

Aborted

so check if memdev is present before calling object_get_canonical_path() and in case it's not assign to "memdev:" field "removed" value.

---
alternative more generic solution:
http://patchwork.ozlabs.org/patch/453343/

---
 backends/hostmem.c       | 23 +++++++++++++++++++++++
 hw/mem/pc-dimm.c         | 15 ++++++++++++++-
 include/sysemu/hostmem.h |  1 +
 qmp.c                    |  1 +
 4 files changed, 39 insertions(+), 1 deletion(-)
backends/hostmem.c +23 -0
index 99e8f99..aa88691 100644
@@ -227,6 +227,26 @@ static void host_memory_backend_set_prealloc(Object *obj, bool value,
     }
 }
 
+static void host_memory_backend_set_id(Object *obj, const char *id,
+                                       Error **errp)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+
+    if (backend->id) {
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "id",
+                  "can't change already set value");
+        return;
+    }
+    backend->id = g_strdup(id);
+}
+
+static char *host_memory_backend_get_id(Object *obj, Error **errp)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+
+    return g_strdup(backend->id);
+}
+
 static void host_memory_backend_init(Object *obj)
 {
     HostMemoryBackend *backend = MEMORY_BACKEND(obj);
@@ -237,6 +257,9 @@ static void host_memory_backend_init(Object *obj)
                                       "dump-guest-core", true);
     backend->prealloc = mem_prealloc;
 
+    object_property_add_str(obj, "id",
+                            host_memory_backend_get_id,
+                            host_memory_backend_set_id, NULL);
     object_property_add_bool(obj, "merge",
                         host_memory_backend_get_merge,
                         host_memory_backend_set_merge, NULL);
hw/mem/pc-dimm.c +14 -1
index 39f0c97..482a7a0 100644
@@ -69,6 +69,8 @@ int qmp_pc_dimm_device_list(Object *obj, void *opaque)
         DeviceState *dev = DEVICE(obj);
 
         if (dev->realized) {
+            char *mdevid, *mdevpath;
+            Object *mdev;
             MemoryDeviceInfoList *elem = g_new0(MemoryDeviceInfoList, 1);
             MemoryDeviceInfo *info = g_new0(MemoryDeviceInfo, 1);
             PCDIMMDeviceInfo *di = g_new0(PCDIMMDeviceInfo, 1);
@@ -86,7 +88,18 @@ int qmp_pc_dimm_device_list(Object *obj, void *opaque)
             di->node = dimm->node;
             di->size = object_property_get_int(OBJECT(dimm), PC_DIMM_SIZE_PROP,
                                                NULL);
-            di->memdev = object_get_canonical_path(OBJECT(dimm->hostmem));
+            mdevid = object_property_get_str(OBJECT(dimm->hostmem), "id",
+                                             &error_abort);
+            mdevpath = g_strdup_printf("/objects/%s", mdevid);
+            g_free(mdevid);
+            mdev = object_resolve_path_type(mdevpath, TYPE_MEMORY_BACKEND,
+                                            NULL);
+            if (mdev == OBJECT(dimm->hostmem)) {
+                di->memdev = object_get_canonical_path(OBJECT(dimm->hostmem));
+            } else {
+                di->memdev = g_strdup("removed");
+            }
+            g_free(mdevpath);
 
             info->dimm = di;
             elem->value = info;
include/sysemu/hostmem.h +1 -0
index 1ce4394..63918aa 100644
@@ -53,6 +53,7 @@ struct HostMemoryBackend {
     Object parent;
 
     /* protected */
+    char *id;
     uint64_t size;
     bool merge, dump;
     bool prealloc, force_prealloc;
qmp.c +1 -0
index c479e77..6f1cca7 100644
@@ -649,6 +649,7 @@ void object_add(const char *type, const char *id, const QDict *qdict,
             }
         }
     }
+    object_property_set_str(obj, id, "id", NULL);
 
     object_property_add_child(container_get(object_get_root(), "/objects"),
                               id, obj, &local_err);
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 9 lines · On Thu, 26 Mar 2015 16:42:54 +0000 Igor Mammedov <[email protected]> wrote:

showing a memory device whose memdev is removed leads to an assert:

(qemu) object_add memory-backend-ram,id=ram0,size=128M (qemu) device_add pc-dimm,id=d0,memdev=ram0 (qemu) object_del ram0
(qemu) info memory-devices
**

ERROR:qom/object.c:1274:object_get_canonical_path_component:\
                            assertion failed: (obj->parent != NULL)
Quoted 7 lines

Aborted

so check if memdev is present before calling object_get_canonical_path() and in case it's not assign to "memdev:" field "removed" value.

Igor, do you want to go in through my tree?

Quoted 108 lines

---
alternative more generic solution:

   http://patchwork.ozlabs.org/patch/453343/
---
 backends/hostmem.c       | 23 +++++++++++++++++++++++
 hw/mem/pc-dimm.c         | 15 ++++++++++++++-
 include/sysemu/hostmem.h |  1 +
 qmp.c                    |  1 +
 4 files changed, 39 insertions(+), 1 deletion(-)
backends/hostmem.c +23 -0
index 99e8f99..aa88691 100644
@@ -227,6 +227,26 @@ static void host_memory_backend_set_prealloc(Object *obj, bool value,
     }
 }
 
+static void host_memory_backend_set_id(Object *obj, const char *id,
+                                       Error **errp)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+
+    if (backend->id) {
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "id",
+                  "can't change already set value");
+        return;
+    }
+    backend->id = g_strdup(id);
+}
+
+static char *host_memory_backend_get_id(Object *obj, Error **errp)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+
+    return g_strdup(backend->id);
+}
+
 static void host_memory_backend_init(Object *obj)
 {
     HostMemoryBackend *backend = MEMORY_BACKEND(obj);
@@ -237,6 +257,9 @@ static void host_memory_backend_init(Object *obj)
                                       "dump-guest-core", true);
     backend->prealloc = mem_prealloc;
 
+    object_property_add_str(obj, "id",
+                            host_memory_backend_get_id,
+                            host_memory_backend_set_id, NULL);
     object_property_add_bool(obj, "merge",
                         host_memory_backend_get_merge,
                         host_memory_backend_set_merge, NULL);
hw/mem/pc-dimm.c +14 -1
index 39f0c97..482a7a0 100644
@@ -69,6 +69,8 @@ int qmp_pc_dimm_device_list(Object *obj, void *opaque)
         DeviceState *dev = DEVICE(obj);
 
         if (dev->realized) {
+            char *mdevid, *mdevpath;
+            Object *mdev;
             MemoryDeviceInfoList *elem = g_new0(MemoryDeviceInfoList, 1);
             MemoryDeviceInfo *info = g_new0(MemoryDeviceInfo, 1);
             PCDIMMDeviceInfo *di = g_new0(PCDIMMDeviceInfo, 1);
@@ -86,7 +88,18 @@ int qmp_pc_dimm_device_list(Object *obj, void *opaque)
             di->node = dimm->node;
             di->size = object_property_get_int(OBJECT(dimm), PC_DIMM_SIZE_PROP,
                                                NULL);
-            di->memdev = object_get_canonical_path(OBJECT(dimm->hostmem));
+            mdevid = object_property_get_str(OBJECT(dimm->hostmem), "id",
+                                             &error_abort);
+            mdevpath = g_strdup_printf("/objects/%s", mdevid);
+            g_free(mdevid);
+            mdev = object_resolve_path_type(mdevpath, TYPE_MEMORY_BACKEND,
+                                            NULL);
+            if (mdev == OBJECT(dimm->hostmem)) {
+                di->memdev = object_get_canonical_path(OBJECT(dimm->hostmem));
+            } else {
+                di->memdev = g_strdup("removed");
+            }
+            g_free(mdevpath);
 
             info->dimm = di;
             elem->value = info;
include/sysemu/hostmem.h +1 -0
index 1ce4394..63918aa 100644
@@ -53,6 +53,7 @@ struct HostMemoryBackend {
     Object parent;
 
     /* protected */
+    char *id;
     uint64_t size;
     bool merge, dump;
     bool prealloc, force_prealloc;
qmp.c +1 -0
index c479e77..6f1cca7 100644
@@ -649,6 +649,7 @@ void object_add(const char *type, const char *id, const QDict *qdict,
             }
         }
     }
+    object_property_set_str(obj, id, "id", NULL);
 
     object_property_add_child(container_get(object_get_root(), "/objects"),
                               id, obj, &local_err);
#2 lore raw
Quoted 14 lines · On Thu, 26 Mar 2015 15:59:25 -0400 Luiz Capitulino <[email protected]>…
Quoted 11 lines · On Thu, 26 Mar 2015 16:42:54 +0000 Igor Mammedov <[email protected]> wrote:

showing a memory device whose memdev is removed leads to an assert:

(qemu) object_add memory-backend-ram,id=ram0,size=128M (qemu) device_add pc-dimm,id=d0,memdev=ram0 (qemu) object_del ram0
(qemu) info memory-devices
**

ERROR:qom/object.c:1274:object_get_canonical_path_component:\
                            assertion failed: (obj->parent != NULL)

Aborted

Quoted 7 lines
Quoted 5 lines

so check if memdev is present before calling object_get_canonical_path() and in case it's not assign to "memdev:" field "removed" value.

Igor, do you want to go in through my tree?

What about the patch, btw? :)

Quoted 110 lines
Quoted 109 lines

---
alternative more generic solution:

   http://patchwork.ozlabs.org/patch/453343/
---
 backends/hostmem.c       | 23 +++++++++++++++++++++++
 hw/mem/pc-dimm.c         | 15 ++++++++++++++-
 include/sysemu/hostmem.h |  1 +
 qmp.c                    |  1 +
 4 files changed, 39 insertions(+), 1 deletion(-)
backends/hostmem.c +23 -0
index 99e8f99..aa88691 100644
@@ -227,6 +227,26 @@ static void host_memory_backend_set_prealloc(Object *obj, bool value,
     }
 }
 
+static void host_memory_backend_set_id(Object *obj, const char *id,
+                                       Error **errp)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+
+    if (backend->id) {
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "id",
+                  "can't change already set value");
+        return;
+    }
+    backend->id = g_strdup(id);
+}
+
+static char *host_memory_backend_get_id(Object *obj, Error **errp)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+
+    return g_strdup(backend->id);
+}
+
 static void host_memory_backend_init(Object *obj)
 {
     HostMemoryBackend *backend = MEMORY_BACKEND(obj);
@@ -237,6 +257,9 @@ static void host_memory_backend_init(Object *obj)
                                       "dump-guest-core", true);
     backend->prealloc = mem_prealloc;
 
+    object_property_add_str(obj, "id",
+                            host_memory_backend_get_id,
+                            host_memory_backend_set_id, NULL);
     object_property_add_bool(obj, "merge",
                         host_memory_backend_get_merge,
                         host_memory_backend_set_merge, NULL);
hw/mem/pc-dimm.c +14 -1
index 39f0c97..482a7a0 100644
@@ -69,6 +69,8 @@ int qmp_pc_dimm_device_list(Object *obj, void *opaque)
         DeviceState *dev = DEVICE(obj);
 
         if (dev->realized) {
+            char *mdevid, *mdevpath;
+            Object *mdev;
             MemoryDeviceInfoList *elem = g_new0(MemoryDeviceInfoList, 1);
             MemoryDeviceInfo *info = g_new0(MemoryDeviceInfo, 1);
             PCDIMMDeviceInfo *di = g_new0(PCDIMMDeviceInfo, 1);
@@ -86,7 +88,18 @@ int qmp_pc_dimm_device_list(Object *obj, void *opaque)
             di->node = dimm->node;
             di->size = object_property_get_int(OBJECT(dimm), PC_DIMM_SIZE_PROP,
                                                NULL);
-            di->memdev = object_get_canonical_path(OBJECT(dimm->hostmem));
+            mdevid = object_property_get_str(OBJECT(dimm->hostmem), "id",
+                                             &error_abort);
+            mdevpath = g_strdup_printf("/objects/%s", mdevid);
+            g_free(mdevid);
+            mdev = object_resolve_path_type(mdevpath, TYPE_MEMORY_BACKEND,
+                                            NULL);
+            if (mdev == OBJECT(dimm->hostmem)) {
+                di->memdev = object_get_canonical_path(OBJECT(dimm->hostmem));
+            } else {
+                di->memdev = g_strdup("removed");
+            }
+            g_free(mdevpath);
 
             info->dimm = di;
             elem->value = info;
include/sysemu/hostmem.h +1 -0
index 1ce4394..63918aa 100644
@@ -53,6 +53,7 @@ struct HostMemoryBackend {
     Object parent;
 
     /* protected */
+    char *id;
     uint64_t size;
     bool merge, dump;
     bool prealloc, force_prealloc;
qmp.c +1 -0
index c479e77..6f1cca7 100644
@@ -649,6 +649,7 @@ void object_add(const char *type, const char *id, const QDict *qdict,
             }
         }
     }
+    object_property_set_str(obj, id, "id", NULL);
 
     object_property_add_child(container_get(object_get_root(), "/objects"),
                               id, obj, &local_err);
#3 lore raw
Quoted 21 lines · On Thu, 26 Mar 2015 16:26:17 -0400 Luiz Capitulino <[email protected]>…
Quoted 18 lines · On Thu, 26 Mar 2015 15:59:25 -0400 Luiz Capitulino <[email protected]>…
Quoted 15 lines · On Thu, 26 Mar 2015 16:42:54 +0000 Igor Mammedov <[email protected]> wrote:

showing a memory device whose memdev is removed leads to an assert:

(qemu) object_add memory-backend-ram,id=ram0,size=128M (qemu) device_add pc-dimm,id=d0,memdev=ram0 (qemu) object_del ram0
(qemu) info memory-devices
**

ERROR:qom/object.c:1274:object_get_canonical_path_component:\
                            assertion failed: (obj->parent != NULL)

Aborted

so check if memdev is present before calling object_get_canonical_path() and in case it's not assign to "memdev:" field "removed" value.

Quoted 118 lines
Quoted 3 lines
Quoted 1 line

Igor, do you want to go in through my tree?

What about the patch, btw? :)

Quoted 110 lines
Quoted 109 lines

---
alternative more generic solution:

   http://patchwork.ozlabs.org/patch/453343/
---
 backends/hostmem.c       | 23 +++++++++++++++++++++++
 hw/mem/pc-dimm.c         | 15 ++++++++++++++-
 include/sysemu/hostmem.h |  1 +
 qmp.c                    |  1 +
 4 files changed, 39 insertions(+), 1 deletion(-)
backends/hostmem.c +23 -0
index 99e8f99..aa88691 100644
@@ -227,6 +227,26 @@ static void host_memory_backend_set_prealloc(Object *obj, bool value,
     }
 }
 
+static void host_memory_backend_set_id(Object *obj, const char *id,
+                                       Error **errp)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+
+    if (backend->id) {
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "id",
+                  "can't change already set value");
+        return;
+    }
+    backend->id = g_strdup(id);
+}
+
+static char *host_memory_backend_get_id(Object *obj, Error **errp)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+
+    return g_strdup(backend->id);
+}
+
 static void host_memory_backend_init(Object *obj)
 {
     HostMemoryBackend *backend = MEMORY_BACKEND(obj);
@@ -237,6 +257,9 @@ static void host_memory_backend_init(Object *obj)
                                       "dump-guest-core", true);
     backend->prealloc = mem_prealloc;
 
+    object_property_add_str(obj, "id",
+                            host_memory_backend_get_id,
+                            host_memory_backend_set_id, NULL);
     object_property_add_bool(obj, "merge",
                         host_memory_backend_get_merge,
                         host_memory_backend_set_merge, NULL);
hw/mem/pc-dimm.c +14 -1
index 39f0c97..482a7a0 100644
@@ -69,6 +69,8 @@ int qmp_pc_dimm_device_list(Object *obj, void *opaque)
         DeviceState *dev = DEVICE(obj);
 
         if (dev->realized) {
+            char *mdevid, *mdevpath;
+            Object *mdev;
             MemoryDeviceInfoList *elem = g_new0(MemoryDeviceInfoList, 1);
             MemoryDeviceInfo *info = g_new0(MemoryDeviceInfo, 1);
             PCDIMMDeviceInfo *di = g_new0(PCDIMMDeviceInfo, 1);
@@ -86,7 +88,18 @@ int qmp_pc_dimm_device_list(Object *obj, void *opaque)
             di->node = dimm->node;
             di->size = object_property_get_int(OBJECT(dimm), PC_DIMM_SIZE_PROP,
                                                NULL);
-            di->memdev = object_get_canonical_path(OBJECT(dimm->hostmem));
+            mdevid = object_property_get_str(OBJECT(dimm->hostmem), "id",
+                                             &error_abort);
+            mdevpath = g_strdup_printf("/objects/%s", mdevid);
+            g_free(mdevid);
+            mdev = object_resolve_path_type(mdevpath, TYPE_MEMORY_BACKEND,
+                                            NULL);
+            if (mdev == OBJECT(dimm->hostmem)) {
+                di->memdev = object_get_canonical_path(OBJECT(dimm->hostmem));
+            } else {
+                di->memdev = g_strdup("removed");
+            }
+            g_free(mdevpath);
 
             info->dimm = di;
             elem->value = info;
include/sysemu/hostmem.h +1 -0
index 1ce4394..63918aa 100644
@@ -53,6 +53,7 @@ struct HostMemoryBackend {
     Object parent;
 
     /* protected */
+    char *id;
     uint64_t size;
     bool merge, dump;
     bool prealloc, force_prealloc;
qmp.c +1 -0
index c479e77..6f1cca7 100644
@@ -649,6 +649,7 @@ void object_add(const char *type, const char *id, const QDict *qdict,
             }
         }
     }
+    object_property_set_str(obj, id, "id", NULL);
 
     object_property_add_child(container_get(object_get_root(), "/objects"),
                               id, obj, &local_err);

pls, ignore it there is a better alternative patch on list

#4 lore raw
In reply to Igor Mammedov

hw/mem/pc-dimm.c int qmp_pc_dimm_device_list(Object *obj, void *opaque) · line 96

Quoted 6 lines · Igor Mammedov
hw/mem/pc-dimm.c +6 -0
+            mdevid = object_property_get_str(OBJECT(dimm->hostmem), "id",
+                                             &error_abort);
+            mdevpath = g_strdup_printf("/objects/%s", mdevid);
+            g_free(mdevid);
+            mdev = object_resolve_path_type(mdevpath, TYPE_MEMORY_BACKEND,
+                                            NULL);

You can add a backend with id xyz, remove it, and add another with the same id, right?

I think the can_be_deleted solution is better and not more invasive, even for 2.3.

Paolo

#5 lore raw
Quoted 10 lines · On Thu, 26 Mar 2015 21:33:19 +0100 Paolo Bonzini <[email protected]> wrote:

hw/mem/pc-dimm.c int qmp_pc_dimm_device_list(Object *obj, void *opaque) · line 96

Quoted 6 lines · Igor Mammedov
hw/mem/pc-dimm.c +6 -0
+            mdevid = object_property_get_str(OBJECT(dimm->hostmem), "id",
+                                             &error_abort);
+            mdevpath = g_strdup_printf("/objects/%s", mdevid);
+            g_free(mdevid);
+            mdev = object_resolve_path_type(mdevpath, TYPE_MEMORY_BACKEND,
+                                            NULL);
Quoted 5 lines

You can add a backend with id xyz, remove it, and add another with the same id, right?

I think the can_be_deleted solution is better and not more invasive, even for 2.3.

yep, it's better.

Quoted 2 lines

Paolo

#6 lore raw
In reply to Paolo Bonzini
Quoted 10 lines · On Thu, 26 Mar 2015 21:33:19 +0100 Paolo Bonzini <[email protected]> wrote:

hw/mem/pc-dimm.c int qmp_pc_dimm_device_list(Object *obj, void *opaque) · line 96

Quoted 6 lines · Igor Mammedov
hw/mem/pc-dimm.c +6 -0
+            mdevid = object_property_get_str(OBJECT(dimm->hostmem), "id",
+                                             &error_abort);
+            mdevpath = g_strdup_printf("/objects/%s", mdevid);
+            g_free(mdevid);
+            mdev = object_resolve_path_type(mdevpath, TYPE_MEMORY_BACKEND,
+                                            NULL);
Quoted 2 lines

You can add a backend with id xyz, remove it, and add another with the same id, right?

right, but in the end it compares pointers to hostmem so it safe. but can_be_deleted() is more generic hence more preferred.

Quoted 6 lines

I think the can_be_deleted solution is better and not more invasive, even for 2.3.

Paolo