Skip to contentSkip to conversation

memory/hmp: Print owners/parents in "info mtree"

PATCH Superseded Alexey Kardashevskiy 2 participants 4 messages May 30, 2018

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover memory/hmp: Print owners/parents in "info mtree"

This is a debug extension to "into mtree" to print a memory region owner/parent.

This is based on sha1
e609fa7 Peter Maydell "Merge remote-tracking branch 'remotes/edgar/tags/edgar/xilinx-next-2018-05-29-v1.for-upstream' into staging".

Please comment. Thanks.

Alexey Kardashevskiy (2):
object: Handle objects with no parents memory/hmp: Print owners/parents in "info mtree"

 include/exec/memory.h |  2 +-
 memory.c              | 68 +++++++++++++++++++++++++++++++++++++++++++--------
 monitor.c             |  4 ++-
 qom/object.c          | 10 ++++++--
 hmp-commands-info.hx  |  7 +++---
 5 files changed, 74 insertions(+), 17 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH v3 1/2 object: Handle objects with no parents

At the moment object_get_canonical_path() crashes if the object or one of its parents does not have a parent, for example, a KVM accelerator object.

This adds a check for obj!=NULL in a loop to prevent the crash. In order not to return a wrong path, this checks for currently resolved partial path and does not add a leading slash to tell the reader that the path is partial as the owner object is detached.

---

I have not tested the case with obj==NULL and path!=NULL as this is for objects which have parents which are not attached to the root and we do not have such objects in current QEMU afaict but I kept it just in case.

---
Changes:
v3:
* do not check for obj->parent
* return NULL or incomplete path depending on the situation

---
 qom/object.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
qom/object.c +8 -2
index 0fc9720..05138ba 100644
@@ -1669,7 +1669,7 @@ gchar *object_get_canonical_path(Object *obj)
     Object *root = object_get_root();
     char *newpath, *path = NULL;
 
-    while (obj != root) {
+    while (obj && obj != root) {
         char *component = object_get_canonical_path_component(obj);
 
         if (path) {
@@ -1684,7 +1684,13 @@ gchar *object_get_canonical_path(Object *obj)
         obj = obj->parent;
     }
 
-    newpath = g_strdup_printf("/%s", path ? path : "");
+    if (obj && path) {
+        newpath = g_strdup_printf("/%s", path);
+    } else if (path) {
+        newpath = g_strdup(path);
+    } else {
+        newpath = NULL;
+    }
     g_free(path);
 
     return newpath;
Signature · 1 line
2.11.0
#2 lore raw

Re: [Qemu-devel] [PATCH qemu v3 1/2] object: Handle objects with no parents

Quoted 44 lines · Alexey Kardashevskiy

At the moment object_get_canonical_path() crashes if the object or one of its parents does not have a parent, for example, a KVM accelerator object.

This adds a check for obj!=NULL in a loop to prevent the crash. In order not to return a wrong path, this checks for currently resolved partial path and does not add a leading slash to tell the reader that the path is partial as the owner object is detached.

---

I have not tested the case with obj==NULL and path!=NULL as this is for objects which have parents which are not attached to the root and we do not have such objects in current QEMU afaict but I kept it just in case.

---
Changes:
v3:
* do not check for obj->parent
* return NULL or incomplete path depending on the situation

---
 qom/object.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
qom/object.c +1 -2
index 0fc9720..05138ba 100644
@@ -1669,7 +1669,7 @@ gchar *object_get_canonical_path(Object *obj)
     Object *root = object_get_root();
     char *newpath, *path = NULL;
 
-    while (obj != root) {
+    while (obj && obj != root) {
         char *component = object_get_canonical_path_component(obj);
 
         if (path) {
@@ -1684,7 +1684,13 @@ gchar *object_get_canonical_path(Object *obj)
         obj = obj->parent;
     }
 
-    newpath = g_strdup_printf("/%s", path ? path : "");

qom/object.c gchar *object_get_canonical_path(Object *obj) · line 1696

Quoted 10 lines
qom/object.c +7 -0
+    if (obj && path) {
+        newpath = g_strdup_printf("/%s", path);
+    } else if (path) {
+        newpath = g_strdup(path);
+    } else {
+        newpath = NULL;
+    }
     g_free(path);
 
     return newpath;

I think this is still wrong, as you wouldn't be able to get back these objects later (e.g. by assigning the result to a link<> property). I've posted an alternative patch.

Paolo

#3 lore raw

PATCH v3 2/2 memory/hmp: Print owners/parents in "info mtree"

In reply to Alexey Kardashevskiy

This adds owners/parents (which are the same, just occasionally owner==NULL) printing for memory regions; a new '-o' flag enabled new output.

---
Changes:
v3:
* removed QOM's "id" property as there are no objects left which would have this property and own an MR

v2:
* cleanups

---
 include/exec/memory.h |  2 +-
 memory.c              | 68 +++++++++++++++++++++++++++++++++++++++++++--------
 monitor.c             |  4 ++-
 hmp-commands-info.hx  |  7 +++---
 4 files changed, 66 insertions(+), 15 deletions(-)
include/exec/memory.h +1 -1
index 525619a..b98e918 100644
@@ -1541,7 +1541,7 @@ void memory_global_dirty_log_start(void);
 void memory_global_dirty_log_stop(void);
 
 void mtree_info(fprintf_function mon_printf, void *f, bool flatview,
-                bool dispatch_tree);
+                bool dispatch_tree, bool owner);
 
 /**
  * memory_region_request_mmio_ptr: request a pointer to an mmio
memory.c +58 -10

151 lines not on this page · raw message

monitor.c +3 -1
index 46814af..443460e 100644
@@ -1966,8 +1966,10 @@ static void hmp_info_mtree(Monitor *mon, const QDict *qdict)
 {
     bool flatview = qdict_get_try_bool(qdict, "flatview", false);
     bool dispatch_tree = qdict_get_try_bool(qdict, "dispatch_tree", false);
+    bool owner = qdict_get_try_bool(qdict, "owner", false);
 
-    mtree_info((fprintf_function)monitor_printf, mon, flatview, dispatch_tree);
+    mtree_info((fprintf_function)monitor_printf, mon, flatview, dispatch_tree,
+               owner);
 }
 
 static void hmp_info_numa(Monitor *mon, const QDict *qdict)
hmp-commands-info.hx +4 -3
index ddfcd5a..5956495 100644
@@ -250,10 +250,11 @@ ETEXI
 
     {
         .name       = "mtree",
-        .args_type  = "flatview:-f,dispatch_tree:-d",
-        .params     = "[-f][-d]",
+        .args_type  = "flatview:-f,dispatch_tree:-d,owner:-o",
+        .params     = "[-f][-d][-o]",
         .help       = "show memory tree (-f: dump flat view for address spaces;"
-                      "-d: dump dispatch tree, valid with -f only)",
+                      "-d: dump dispatch tree, valid with -f only);"
+                      "-o: dump region owners/parents",
         .cmd        = hmp_info_mtree,
     },
 
Signature · 1 line
2.11.0