Skip to contentSkip to conversation

MemoryRegion QOMification

GIT PULL Applied Paolo Bonzini 2 participants 17 messages Jul 1, 2014

lore
Share & tools
lore
#0 lore raw

The following changes since commit 53a259da5697ec8a82463161e2e32ff942a08bc2:

Merge remote-tracking branch 'remotes/awilliam/tags/vfio-pci-for-qemu-20140630.0' into staging (2014-06-30 18:31:07 +0100)

are available in the git repository at:

git://github.com/bonzini/qemu.git memory

for you to fetch changes up to 352e8da743f26948cb12d0ee53c455f328f59bbe:

qdev: correctly send DEVICE_DELETED for recursively-deleted devices (2014-07-01 10:20:42 +0200)

Patch 1 is shared with Stefan's upcoming pull request. We synchronized in order to use the same commit ID and thus avoid conflicts.

----------------------------------------------------------------
Marcelo Tosatti (1):

      mc146818rtc: add "rtc-time" link to "/machine/rtc"

Paolo Bonzini (7):
qom: add a generic mechanism to resolve paths
qom: allow creating an alias of a child<> property
libqtest: escape strings in QMP commands, fix leak
memory: MemoryRegion: use /machine as default owner
memory: MemoryRegion: replace owner field with QOM parent
memory: do not give a name to the internal exec.c regions
qdev: correctly send DEVICE_DELETED for recursively-deleted devices

Peter Crosthwaite (6):
qom: object: remove parent pointer when unparenting
qom: object: Ignore refs/unrefs of NULL
memory: MemoryRegion: QOMify
memory: MemoryRegion: Add container and addr props
memory: MemoryRegion: Add may-overlap and priority props
memory: MemoryRegion: Add size property

Stefan Hajnoczi (1):
qom: add object_property_add_alias()

 exec.c                 |  12 +--
 hw/core/qdev.c         |   5 +-
 hw/timer/mc146818rtc.c |   9 ++
 include/exec/memory.h  |   9 +-
 include/hw/qdev-core.h |   1 +
 include/qom/object.h   |  54 ++++++++++--
 memory.c               | 231 +++++++++++++++++++++++++++++++++++++++++++------
 qom/object.c           | 148 ++++++++++++++++++++++++-------
 tests/fdc-test.c       |   2 +-
 tests/libqtest.c       |  47 +++++++---
 tests/qom-test.c       |   6 +-
 tests/tmp105-test.c    |   4 +-
 vl.c                   |   3 +-
 13 files changed, 442 insertions(+), 89 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

[Qemu-devel] [PULL 01/15] qom: add object_property_add_alias()

From: Stefan Hajnoczi <[email protected]>

Sometimes an object needs to present a property which is actually on another object, or it needs to provide an alias name for an existing property.

Examples:
a.foo -> b.foo
a.old_name -> a.new_name

The new object_property_add_alias() API allows objects to alias a property on the same object or another object. The source and target names can be different.

---
 include/qom/object.h | 20 ++++++++++++++++++++
 qom/object.c         | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+)
include/qom/object.h +20 -0
index b882ccc..44c513f 100644
@@ -1231,6 +1231,26 @@ void object_property_add_uint64_ptr(Object *obj, const char *name,
                                     const uint64_t *v, Error **Errp);
 
 /**
+ * object_property_add_alias:
+ * @obj: the object to add a property to
+ * @name: the name of the property
+ * @target_obj: the object to forward property access to
+ * @target_name: the name of the property on the forwarded object
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Add an alias for a property on an object.  This function will add a property
+ * of the same type as the forwarded property.
+ *
+ * The caller must ensure that <code>@target_obj</code> stays alive as long as
+ * this property exists.  In the case of a child object or an alias on the same
+ * object this will be the case.  For aliases to other objects the caller is
+ * responsible for taking a reference.
+ */
+void object_property_add_alias(Object *obj, const char *name,
+                               Object *target_obj, const char *target_name,
+                               Error **errp);
+
+/**
  * object_child_foreach:
  * @obj: the object whose children will be navigated
  * @fn: the iterator function to be called
qom/object.c +51 -0

57 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#2 lore raw

[Qemu-devel] [PULL 03/15] qom: allow creating an alias of a child<> property

In reply to Paolo Bonzini

Child properties must be unique. Fix this problem by turning their aliases into links.

The resolve function that forwards to the target property does not have any knowledge of the target property's type, so it works fine.

---
 qom/object.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
qom/object.c +11 -1
index 7a892ef..f49335f 100644
@@ -1607,22 +1607,32 @@ void object_property_add_alias(Object *obj, const char *name,
     AliasProperty *prop;
     ObjectProperty *op;
     ObjectProperty *target_prop;
+    gchar *prop_type;
 
     target_prop = object_property_find(target_obj, target_name, errp);
     if (!target_prop) {
         return;
     }
 
+    if (object_property_is_child(target_prop)) {
+        prop_type = g_strdup_printf("link%s",
+                                    target_prop->type + strlen("child"));
+    } else {
+        prop_type = g_strdup(target_prop->type);
+    }
+
     prop = g_malloc(sizeof(*prop));
     prop->target_obj = target_obj;
     prop->target_name = target_name;
 
-    op = object_property_add(obj, name, target_prop->type,
+    op = object_property_add(obj, name, prop_type,
                              property_get_alias,
                              property_set_alias,
                              property_release_alias,
                              prop, errp);
     op->resolve = property_resolve_alias;
+
+    g_free(prop_type);
 }
 
 static void object_instance_init(Object *obj)
Signature · 1 line
1.8.3.1
#3 lore raw

[Qemu-devel] [PULL 05/15] qom: object: remove parent pointer when unparenting

In reply to Paolo Bonzini

From: Peter Crosthwaite <[email protected]>

Certain parts of the QOM framework test this pointer to determine if an object is parented. Nuke it when the object is unparented to allow for reuse of an object after unparenting.

---
 qom/object.c | 1 +
 1 file changed, 1 insertion(+)
qom/object.c +1 -0
index f49335f..d5de8f6 100644
@@ -397,6 +397,7 @@ void object_unparent(Object *obj)
     }
     if (obj->parent) {
         object_property_del_child(obj->parent, obj, NULL);
+        obj->parent = NULL;
     }
     object_unref(obj);
 }
Signature · 1 line
1.8.3.1
#4 lore raw

[Qemu-devel] [PULL 02/15] qom: add a generic mechanism to resolve paths

In reply to Paolo Bonzini

It may be desirable to have custom link<> properties that do more than just store an object. Even the addition of a "check" function is not enough if setting the link has side effects or if a non-standard reference counting is preferrable.

Avoid the assumption that the opaque field of a link<> is a LinkProperty struct, by adding a generic "resolve" callback to ObjectProperty. This fixes aliases of link properties.

---
 include/qom/object.h | 34 ++++++++++++++++++----
 qom/object.c         | 82 +++++++++++++++++++++++++++++++++-------------------
 2 files changed, 82 insertions(+), 34 deletions(-)
include/qom/object.h +29 -5
index 44c513f..8a05a81 100644
@@ -304,6 +304,25 @@ typedef void (ObjectPropertyAccessor)(Object *obj,
                                       Error **errp);
 
 /**
+ * ObjectPropertyResolve:
+ * @obj: the object that owns the property
+ * @opaque: the opaque registered with the property
+ * @part: the name of the property
+ *
+ * Resolves the #Object corresponding to property @part.
+ *
+ * The returned object can also be used as a starting point
+ * to resolve a relative path starting with "@part".
+ *
+ * Returns: If @path is the path that led to @obj, the function
+ * returns the #Object corresponding to "@path/@part".
+ * If "@path/@part" is not a valid object path, it returns #NULL.
+ */
+typedef Object *(ObjectPropertyResolve)(Object *obj,
+                                        void *opaque,
+                                        const char *part);
+
+/**
  * ObjectPropertyRelease:
  * @obj: the object that owns the property
  * @name: the name of the property
@@ -321,6 +340,7 @@ typedef struct ObjectProperty
     gchar *type;
     ObjectPropertyAccessor *get;
     ObjectPropertyAccessor *set;
+    ObjectPropertyResolve *resolve;
     ObjectPropertyRelease *release;
     void *opaque;
 
@@ -787,12 +807,16 @@ void object_unref(Object *obj);
  *   destruction.  This may be NULL.
  * @opaque: an opaque pointer to pass to the callbacks for the property
  * @errp: returns an error if this function fails
+ *
+ * Returns: The #ObjectProperty; this can be used to set the @resolve
+ * callback for child and link properties.
  */
-void object_property_add(Object *obj, const char *name, const char *type,
-                         ObjectPropertyAccessor *get,
-                         ObjectPropertyAccessor *set,
-                         ObjectPropertyRelease *release,
-                         void *opaque, Error **errp);
+ObjectProperty *object_property_add(Object *obj, const char *name,
+                                    const char *type,
+                                    ObjectPropertyAccessor *get,
+                                    ObjectPropertyAccessor *set,
+                                    ObjectPropertyRelease *release,
+                                    void *opaque, Error **errp);
 
 void object_property_del(Object *obj, const char *name, Error **errp);
 
qom/object.c +53 -29

172 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#5 lore raw

[Qemu-devel] [PULL 06/15] qom: object: Ignore refs/unrefs of NULL

In reply to Paolo Bonzini

From: Peter Crosthwaite <[email protected]>

Just do nothing if passed NULL for a ref or unref. This avoids call sites that manage a combination of NULL or non-NULL pointers having to add iffery around every ref and unref.

---
 qom/object.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
qom/object.c +8 -6
index d5de8f6..0e8267b 100644
@@ -711,11 +711,17 @@ GSList *object_class_get_list(const char *implements_type,
 
 void object_ref(Object *obj)
 {
+    if (!obj) {
+        return;
+    }
      atomic_inc(&obj->ref);
 }
 
 void object_unref(Object *obj)
 {
+    if (!obj) {
+        return;
+    }
     g_assert(obj->ref > 0);
 
     /* parent always holds a reference to its children */
@@ -1160,13 +1166,9 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
         return;
     }
 
-    if (new_target) {
-        object_ref(new_target);
-    }
+    object_ref(new_target);
     *child = new_target;
-    if (old_target != NULL) {
-        object_unref(old_target);
-    }
+    object_unref(old_target);
 }
 
 static Object *object_resolve_link_property(Object *parent, void *opaque, const gchar *part)
Signature · 1 line
1.8.3.1
#6 lore raw

[Qemu-devel] [PULL 04/15] mc146818rtc: add "rtc-time" link to "/machine/rtc"

In reply to Paolo Bonzini

From: Marcelo Tosatti <[email protected]>

Add a link to rtc under /machine providing a stable location for management apps to query the value of the time. The link should be added by any object that sends RTC_TIME_CHANGE events.

{"execute":"qom-get","arguments":{"path":"/machine","property":"rtc-time"} }

Suggested by Paolo Bonzini and Andreas Faerber.

---
 hw/timer/mc146818rtc.c | 9 +++++++++
 1 file changed, 9 insertions(+)
hw/timer/mc146818rtc.c +9 -0
index 307732c..9d817ca 100644
@@ -909,6 +909,9 @@ static void rtc_realizefn(DeviceState *dev, Error **errp)
 
     object_property_add(OBJECT(s), "date", "struct tm",
                         rtc_get_date, NULL, NULL, s, NULL);
+
+    object_property_add_alias(qdev_get_machine(), "rtc-time",
+                              OBJECT(s), "date", NULL);
 }
 
 ISADevice *rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq)
@@ -950,11 +953,17 @@ static void rtc_class_initfn(ObjectClass *klass, void *data)
     dc->cannot_instantiate_with_device_add_yet = true;
 }
 
+static void rtc_finalize(Object *obj)
+{
+    object_property_del(qdev_get_machine(), "rtc", NULL);
+}
+
 static const TypeInfo mc146818rtc_info = {
     .name          = TYPE_MC146818_RTC,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(RTCState),
     .class_init    = rtc_class_initfn,
+    .instance_finalize = rtc_finalize,
 };
 
 static void mc146818rtc_register_types(void)
Signature · 1 line
1.8.3.1
#7 lore raw

[Qemu-devel] [PULL 08/15] memory: MemoryRegion: use /machine as default owner

In reply to Paolo Bonzini

This will be added (after QOMification) as the QOM parent.

---
 memory.c | 2 +-
 vl.c     | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)
memory.c +1 -1
index b91a60a..7eaa1e9 100644
@@ -849,7 +849,7 @@ void memory_region_init(MemoryRegion *mr,
 {
     mr->ops = &unassigned_mem_ops;
     mr->opaque = NULL;
-    mr->owner = owner;
+    mr->owner = owner ? owner : qdev_get_machine();
     mr->iommu_ops = NULL;
     mr->container = NULL;
     mr->size = int128_make64(size);
vl.c +1 -2
index 41ddcd2..88feeab 100644
@@ -3986,12 +3986,11 @@ int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
-    cpu_exec_init_all();
-
     current_machine = MACHINE(object_new(object_class_get_name(
                           OBJECT_CLASS(machine_class))));
     object_property_add_child(object_get_root(), "machine",
                               OBJECT(current_machine), &error_abort);
+    cpu_exec_init_all();
 
     if (machine_class->hw_version) {
         qemu_set_version(machine_class->hw_version);
Signature · 1 line
1.8.3.1
#8 lore raw

[Qemu-devel] [PULL 09/15] memory: MemoryRegion: QOMify

In reply to Paolo Bonzini

From: Peter Crosthwaite <[email protected]>

QOMify memory regions as an Object. The former init() and destroy() routines become instance_init() and instance_finalize() resp.

memory_region_init() is re-implemented to be:
object_initialize() + set fields

memory_region_destroy() is re-implemented to call unparent().

[Add newly-created MR as child, unparent on destruction. - Paolo]
---
 exec.c                |   4 +-
 include/exec/memory.h |   6 +++
 memory.c              | 121 +++++++++++++++++++++++++++++++++++++++++---------
 3 files changed, 109 insertions(+), 22 deletions(-)
exec.c +2 -2
index 18d6c35..df4a080 100644
@@ -883,7 +883,7 @@ static void phys_section_destroy(MemoryRegion *mr)
 
     if (mr->subpage) {
         subpage_t *subpage = container_of(mr, subpage_t, iomem);
-        memory_region_destroy(&subpage->iomem);
+        object_unref(OBJECT(&subpage->iomem));
         g_free(subpage);
     }
 }
@@ -1768,7 +1768,7 @@ static subpage_t *subpage_init(AddressSpace *as, hwaddr base)
     mmio->as = as;
     mmio->base = base;
     memory_region_init_io(&mmio->iomem, NULL, &subpage_ops, mmio,
-                          "subpage", TARGET_PAGE_SIZE);
+                          NULL, TARGET_PAGE_SIZE);
     mmio->iomem.subpage = true;
 #if defined(DEBUG_SUBPAGE)
     printf("%s: %p base " TARGET_FMT_plx " len %08x\n", __func__,
include/exec/memory.h +6 -0
index 3d778d7..85b56e2 100644
@@ -32,10 +32,15 @@
 #include "qemu/int128.h"
 #include "qemu/notify.h"
 #include "qapi/error.h"
+#include "qom/object.h"
 
 #define MAX_PHYS_ADDR_SPACE_BITS 62
 #define MAX_PHYS_ADDR            (((hwaddr)1 << MAX_PHYS_ADDR_SPACE_BITS) - 1)
 
+#define TYPE_MEMORY_REGION "qemu:memory-region"
+#define MEMORY_REGION(obj) \
+        OBJECT_CHECK(MemoryRegion, (obj), TYPE_MEMORY_REGION)
+
 typedef struct MemoryRegionOps MemoryRegionOps;
 typedef struct MemoryRegionMmio MemoryRegionMmio;
 
@@ -131,6 +136,7 @@ typedef struct CoalescedMemoryRange CoalescedMemoryRange;
 typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd;
 
 struct MemoryRegion {
+    Object parent_obj;
     /* All fields are private - violators will be prosecuted */
     const MemoryRegionOps *ops;
     const MemoryRegionIOMMUOps *iommu_ops;
memory.c +101 -20

170 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#9 lore raw

[Qemu-devel] [PULL 10/15] memory: MemoryRegion: replace owner field with QOM parent

In reply to Paolo Bonzini

The two are now the same.

---
 include/exec/memory.h |  1 -
 memory.c              | 35 +++++++++++++++++++++++++----------
 2 files changed, 25 insertions(+), 11 deletions(-)
include/exec/memory.h +0 -1
index 85b56e2..0c7e825 100644
@@ -141,7 +141,6 @@ struct MemoryRegion {
     const MemoryRegionOps *ops;
     const MemoryRegionIOMMUOps *iommu_ops;
     void *opaque;
-    struct Object *owner;
     MemoryRegion *container;
     Int128 size;
     hwaddr addr;
memory.c +25 -10
index 9397fec..8970081 100644
@@ -905,9 +905,11 @@ void memory_region_init(MemoryRegion *mr,
                         const char *name,
                         uint64_t size)
 {
-    object_initialize(mr, sizeof(*mr), TYPE_MEMORY_REGION);
+    if (!owner) {
+        owner = qdev_get_machine();
+    }
 
-    mr->owner = owner ? owner : qdev_get_machine();
+    object_initialize(mr, sizeof(*mr), TYPE_MEMORY_REGION);
     mr->size = int128_make64(size);
     if (size == UINT64_MAX) {
         mr->size = int128_2_64();
@@ -915,7 +917,7 @@ void memory_region_init(MemoryRegion *mr,
     mr->name = g_strdup(name);
 
     if (name) {
-        object_property_add_child_array(mr->owner, name, OBJECT(mr));
+        object_property_add_child_array(owner, name, OBJECT(mr));
         object_unref(OBJECT(mr));
     }
 }
@@ -1187,24 +1189,37 @@ void memory_region_destroy(MemoryRegion *mr)
 
 Object *memory_region_owner(MemoryRegion *mr)
 {
-    return mr->owner;
+    Object *obj = OBJECT(mr);
+    return obj->parent;
 }
 
 void memory_region_ref(MemoryRegion *mr)
 {
-    if (mr && mr->owner) {
-        object_ref(mr->owner);
+    /* MMIO callbacks most likely will access data that belongs
+     * to the owner, hence the need to ref/unref the owner whenever
+     * the memory region is in use.
+     *
+     * The memory region is a child of its owner.  As long as the
+     * owner doesn't call unparent itself on the memory region,
+     * ref-ing the owner will also keep the memory region alive.
+     * Memory regions without an owner are supposed to never go away,
+     * but we still ref/unref them for debugging purposes.
+     */
+    Object *obj = OBJECT(mr);
+    if (obj && obj->parent) {
+        object_ref(obj->parent);
     } else {
-        object_ref(OBJECT(mr));
+        object_ref(obj);
     }
 }
 
 void memory_region_unref(MemoryRegion *mr)
 {
-    if (mr && mr->owner) {
-        object_unref(mr->owner);
+    Object *obj = OBJECT(mr);
+    if (obj && obj->parent) {
+        object_unref(obj->parent);
     } else {
-        object_unref(OBJECT(mr));
+        object_unref(obj);
     }
 }
 
Signature · 1 line
1.8.3.1
#10 lore raw

[Qemu-devel] [PULL 07/15] libqtest: escape strings in QMP commands, fix leak

In reply to Paolo Bonzini

libqtest is using g_strdup_printf to format QMP commands, but this does not work if the argument strings need to be escaped. Instead, use the fancy %-formatting functionality of QObject. The only change required in tests is that strings have to be formatted as %s, not '%s' or \"%s\". Luckily this usage of parameterized QMP commands is not that frequent.

The leak is in socket_sendf. Since we are extracting the send loop to a new function, fix it now.

---
 tests/fdc-test.c    |  2 +-
 tests/libqtest.c    | 47 +++++++++++++++++++++++++++++++++++++----------
 tests/qom-test.c    |  6 +++---
 tests/tmp105-test.c |  4 ++--
 4 files changed, 43 insertions(+), 16 deletions(-)
tests/fdc-test.c +1 -1
index 37096dc..c8e1e7b 100644
@@ -291,7 +291,7 @@ static void test_media_insert(void)
     /* Insert media in drive. DSKCHK should not be reset until a step pulse
      * is sent. */
     qmp_discard_response("{'execute':'change', 'arguments':{"
-                         " 'device':'floppy0', 'target': '%s' }}",
+                         " 'device':'floppy0', 'target': %s }}",
                          test_image);
     qmp_discard_response(""); /* ignore event
                                  (FIXME open -> open transition?!) */
tests/libqtest.c +37 -10

78 lines not on this page · raw message

tests/qom-test.c +3 -3
index d8d1d8d..4246382 100644
@@ -53,7 +53,7 @@ static void test_properties(const char *path, bool recurse)
 
     g_test_message("Obtaining properties of %s", path);
     response = qmp("{ 'execute': 'qom-list',"
-                   "  'arguments': { 'path': '%s' } }", path);
+                   "  'arguments': { 'path': %s } }", path);
     g_assert(response);
 
     if (!recurse) {
@@ -76,8 +76,8 @@ static void test_properties(const char *path, bool recurse)
             const char *prop = qdict_get_str(tuple, "name");
             g_test_message("Testing property %s.%s", path, prop);
             response = qmp("{ 'execute': 'qom-get',"
-                           "  'arguments': { 'path': '%s',"
-                           "                 'property': '%s' } }",
+                           "  'arguments': { 'path': %s,"
+                           "                 'property': %s } }",
                            path, prop);
             /* qom-get may fail but should not, e.g., segfault. */
             g_assert(response);
tests/tmp105-test.c +2 -2
index 15ddaf3..99db538 100644
@@ -69,7 +69,7 @@ static int qmp_tmp105_get_temperature(const char *id)
     QDict *response;
     int ret;
 
-    response = qmp("{ 'execute': 'qom-get', 'arguments': { 'path': '%s', "
+    response = qmp("{ 'execute': 'qom-get', 'arguments': { 'path': %s, "
                    "'property': 'temperature' } }", id);
     g_assert(qdict_haskey(response, "return"));
     ret = qdict_get_int(response, "return");
@@ -81,7 +81,7 @@ static void qmp_tmp105_set_temperature(const char *id, int value)
 {
     QDict *response;
 
-    response = qmp("{ 'execute': 'qom-set', 'arguments': { 'path': '%s', "
+    response = qmp("{ 'execute': 'qom-set', 'arguments': { 'path': %s, "
                    "'property': 'temperature', 'value': %d } }", id, value);
     g_assert(qdict_haskey(response, "return"));
     QDECREF(response);
Signature · 1 line
1.8.3.1
#11 lore raw

[Qemu-devel] [PULL 11/15] memory: MemoryRegion: Add container and addr props

In reply to Paolo Bonzini

From: Peter Crosthwaite <[email protected]>

Expose the already existing .parent and .addr fields as QOM properties. .parent (i.e. the field describing the memory region that contains this one in Memory hierachy) is renamed "container". This is to avoid confusion with the QOM parent.

[Remove setters. Do not unref parent on releasing the property. Clean
up error propagation. - Paolo]

---
 memory.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
memory.c +46 -0
index 8970081..04dc933 100644
@@ -16,6 +16,7 @@
 #include "exec/memory.h"
 #include "exec/address-spaces.h"
 #include "exec/ioport.h"
+#include "qapi/visitor.h"
 #include "qemu/bitops.h"
 #include "qom/object.h"
 #include "trace.h"
@@ -922,9 +923,42 @@ void memory_region_init(MemoryRegion *mr,
     }
 }
 
+static void memory_region_get_addr(Object *obj, Visitor *v, void *opaque,
+                                   const char *name, Error **errp)
+{
+    MemoryRegion *mr = MEMORY_REGION(obj);
+    uint64_t value = mr->addr;
+
+    visit_type_uint64(v, &value, name, errp);
+}
+
+static void memory_region_get_container(Object *obj, Visitor *v, void *opaque,
+                                        const char *name, Error **errp)
+{
+    MemoryRegion *mr = MEMORY_REGION(obj);
+    gchar *path = (gchar *)"";
+
+    if (mr->container) {
+        path = object_get_canonical_path(OBJECT(mr->container));
+    }
+    visit_type_str(v, &path, name, errp);
+    if (mr->container) {
+        g_free(path);
+    }
+}
+
+static Object *memory_region_resolve_container(Object *obj, void *opaque,
+                                               const char *part)
+{
+    MemoryRegion *mr = MEMORY_REGION(obj);
+
+    return OBJECT(mr->container);
+}
+
 static void memory_region_initfn(Object *obj)
 {
     MemoryRegion *mr = MEMORY_REGION(obj);
+    ObjectProperty *op;
 
     mr->ops = &unassigned_mem_ops;
     mr->enabled = true;
@@ -932,6 +966,18 @@ static void memory_region_initfn(Object *obj)
     mr->destructor = memory_region_destructor_none;
     QTAILQ_INIT(&mr->subregions);
     QTAILQ_INIT(&mr->coalesced);
+
+    op = object_property_add(OBJECT(mr), "container",
+                             "link<" TYPE_MEMORY_REGION ">",
+                             memory_region_get_container,
+                             NULL, /* memory_region_set_container */
+                             NULL, NULL, &error_abort);
+    op->resolve = memory_region_resolve_container;
+
+    object_property_add(OBJECT(mr), "addr", "uint64",
+                        memory_region_get_addr,
+                        NULL, /* memory_region_set_addr */
+                        NULL, NULL, &error_abort);
 }
 
 static uint64_t unassigned_mem_read(void *opaque, hwaddr addr,
Signature · 1 line
1.8.3.1
#12 lore raw

[Qemu-devel] [PULL 12/15] memory: MemoryRegion: Add may-overlap and priority props

In reply to Paolo Bonzini

From: Peter Crosthwaite <[email protected]>

QOM propertyify the .may-overlap and .priority fields. The setters will re-add the memory as a subregion if needed (i.e. the values change when the memory region is already contained).

[Remove setters. - Paolo]
---
 include/exec/memory.h |  2 +-
 memory.c              | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
include/exec/memory.h +1 -1
index 0c7e825..e2c8e3e 100644
@@ -157,7 +157,7 @@ struct MemoryRegion {
     bool flush_coalesced_mmio;
     MemoryRegion *alias;
     hwaddr alias_offset;
-    int priority;
+    int32_t priority;
     bool may_overlap;
     QTAILQ_HEAD(subregions, MemoryRegion) subregions;
     QTAILQ_ENTRY(MemoryRegion) subregions_link;
memory.c +24 -0
index 04dc933..834959b 100644
@@ -955,6 +955,22 @@ static Object *memory_region_resolve_container(Object *obj, void *opaque,
     return OBJECT(mr->container);
 }
 
+static void memory_region_get_priority(Object *obj, Visitor *v, void *opaque,
+                                       const char *name, Error **errp)
+{
+    MemoryRegion *mr = MEMORY_REGION(obj);
+    int32_t value = mr->priority;
+
+    visit_type_int32(v, &value, name, errp);
+}
+
+static bool memory_region_get_may_overlap(Object *obj, Error **errp)
+{
+    MemoryRegion *mr = MEMORY_REGION(obj);
+
+    return mr->may_overlap;
+}
+
 static void memory_region_initfn(Object *obj)
 {
     MemoryRegion *mr = MEMORY_REGION(obj);
@@ -978,6 +994,14 @@ static void memory_region_initfn(Object *obj)
                         memory_region_get_addr,
                         NULL, /* memory_region_set_addr */
                         NULL, NULL, &error_abort);
+    object_property_add(OBJECT(mr), "priority", "uint32",
+                        memory_region_get_priority,
+                        NULL, /* memory_region_set_priority */
+                        NULL, NULL, &error_abort);
+    object_property_add_bool(OBJECT(mr), "may-overlap",
+                             memory_region_get_may_overlap,
+                             NULL, /* memory_region_set_may_overlap */
+                             &error_abort);
 }
 
 static uint64_t unassigned_mem_read(void *opaque, hwaddr addr,
Signature · 1 line
1.8.3.1
#13 lore raw

[Qemu-devel] [PULL 13/15] memory: MemoryRegion: Add size property

In reply to Paolo Bonzini

From: Peter Crosthwaite <[email protected]>

To allow devices to dynamically resize the device. The motivation is to allow devices with variable size to init their memory_region without size early and then correctly populate size at realize() time.

---
 memory.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
memory.c +13 -0
index 834959b..64d7176 100644
@@ -971,6 +971,15 @@ static bool memory_region_get_may_overlap(Object *obj, Error **errp)
     return mr->may_overlap;
 }
 
+static void memory_region_get_size(Object *obj, Visitor *v, void *opaque,
+                                   const char *name, Error **errp)
+{
+    MemoryRegion *mr = MEMORY_REGION(obj);
+    uint64_t value = memory_region_size(mr);
+
+    visit_type_uint64(v, &value, name, errp);
+}
+
 static void memory_region_initfn(Object *obj)
 {
     MemoryRegion *mr = MEMORY_REGION(obj);
@@ -1002,6 +1011,10 @@ static void memory_region_initfn(Object *obj)
                              memory_region_get_may_overlap,
                              NULL, /* memory_region_set_may_overlap */
                              &error_abort);
+    object_property_add(OBJECT(mr), "size", "uint64",
+                        memory_region_get_size,
+                        NULL, /* memory_region_set_size, */
+                        NULL, NULL, &error_abort);
 }
 
 static uint64_t unassigned_mem_read(void *opaque, hwaddr addr,
Signature · 1 line
1.8.3.1
#14 lore raw

[Qemu-devel] [PULL 14/15] memory: do not give a name to the internal exec.c regions

In reply to Paolo Bonzini

There is no need to have them visible under /machine.

---
 exec.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
exec.c +4 -4
index df4a080..5a2a25e 100644
@@ -1801,13 +1801,13 @@ MemoryRegion *iotlb_to_region(AddressSpace *as, hwaddr index)
 
 static void io_mem_init(void)
 {
-    memory_region_init_io(&io_mem_rom, NULL, &unassigned_mem_ops, NULL, "rom", UINT64_MAX);
+    memory_region_init_io(&io_mem_rom, NULL, &unassigned_mem_ops, NULL, NULL, UINT64_MAX);
     memory_region_init_io(&io_mem_unassigned, NULL, &unassigned_mem_ops, NULL,
-                          "unassigned", UINT64_MAX);
+                          NULL, UINT64_MAX);
     memory_region_init_io(&io_mem_notdirty, NULL, &notdirty_mem_ops, NULL,
-                          "notdirty", UINT64_MAX);
+                          NULL, UINT64_MAX);
     memory_region_init_io(&io_mem_watch, NULL, &watch_mem_ops, NULL,
-                          "watch", UINT64_MAX);
+                          NULL, UINT64_MAX);
 }
 
 static void mem_begin(MemoryListener *listener)
Signature · 1 line
1.8.3.1
#15 lore raw

[Qemu-devel] [PULL 15/15] qdev: correctly send DEVICE_DELETED for recursively-deleted devices

In reply to Paolo Bonzini

When a device is unparented (i.e. made completely hidden from management) we want to send a DEVICE_DELETED event only if the device actually was realized. This avoids raising DEVICE_DELETED events when device_add fails.

However, this does not work right for recursively-deleted
devices: the whole tree is _first_ unrealized, _then_ unparented. Then device_unparent sees realized==false and fails to trigger the event. The solution is simply to move have_realized into the DeviceState struct. If device_add fails, we never set the new field to true and DEVICE_DELETED is not sent.

Fixes qemu-iotests testcase 067 (broken by commit 5942a19, though that commit in turn fixed a possible segfault in the same test).

---
 hw/core/qdev.c         | 5 +++--
 include/hw/qdev-core.h | 1 +
 2 files changed, 4 insertions(+), 2 deletions(-)
hw/core/qdev.c +3 -2
index d1eba3c..c520415 100644
@@ -848,6 +848,7 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
         if (dev->hotplugged && local_err == NULL) {
             device_reset(dev);
         }
+        dev->pending_deleted_event = false;
     } else if (!value && dev->realized) {
         QLIST_FOREACH(bus, &dev->child_bus, sibling) {
             object_property_set_bool(OBJECT(bus), false, "realized",
@@ -862,6 +863,7 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
         if (dc->unrealize && local_err == NULL) {
             dc->unrealize(dev, &local_err);
         }
+        dev->pending_deleted_event = true;
     }
 
     if (local_err != NULL) {
@@ -972,7 +974,6 @@ static void device_unparent(Object *obj)
 {
     DeviceState *dev = DEVICE(obj);
     BusState *bus;
-    bool have_realized = dev->realized;
 
     if (dev->realized) {
         object_property_set_bool(obj, false, "realized", NULL);
@@ -988,7 +989,7 @@ static void device_unparent(Object *obj)
     }
 
     /* Only send event if the device had been completely realized */
-    if (have_realized) {
+    if (dev->pending_deleted_event) {
         gchar *path = object_get_canonical_path(OBJECT(dev));
 
         qapi_event_send_device_deleted(!!dev->id, dev->id, path, &error_abort);
include/hw/qdev-core.h +1 -0
index 9221cfc..0799ff2 100644
@@ -156,6 +156,7 @@ struct DeviceState {
 
     const char *id;
     bool realized;
+    bool pending_deleted_event;
     QemuOpts *opts;
     int hotplugged;
     BusState *parent_bus;
Signature · 1 line
1.8.3.1
#16 lore raw
In reply to Paolo Bonzini
Quoted 37 lines · Paolo Bonzini

The following changes since commit 53a259da5697ec8a82463161e2e32ff942a08bc2:

Merge remote-tracking branch 'remotes/awilliam/tags/vfio-pci-for-qemu-20140630.0' into staging (2014-06-30 18:31:07 +0100)

are available in the git repository at:

git://github.com/bonzini/qemu.git memory

for you to fetch changes up to 352e8da743f26948cb12d0ee53c455f328f59bbe:

qdev: correctly send DEVICE_DELETED for recursively-deleted devices (2014-07-01 10:20:42 +0200)

Patch 1 is shared with Stefan's upcoming pull request. We synchronized in order to use the same commit ID and thus avoid conflicts.

----------------------------------------------------------------
Marcelo Tosatti (1):

      mc146818rtc: add "rtc-time" link to "/machine/rtc"

Paolo Bonzini (7):
qom: add a generic mechanism to resolve paths
qom: allow creating an alias of a child<> property
libqtest: escape strings in QMP commands, fix leak
memory: MemoryRegion: use /machine as default owner
memory: MemoryRegion: replace owner field with QOM parent
memory: do not give a name to the internal exec.c regions
qdev: correctly send DEVICE_DELETED for recursively-deleted devices

Peter Crosthwaite (6):
qom: object: remove parent pointer when unparenting
qom: object: Ignore refs/unrefs of NULL
memory: MemoryRegion: QOMify
memory: MemoryRegion: Add container and addr props
memory: MemoryRegion: Add may-overlap and priority props
memory: MemoryRegion: Add size property

Quoted 2 lines

Stefan Hajnoczi (1):
qom: add object_property_add_alias()

Applied, thanks.

-- PMM