Skip to contentSkip to conversation

qdev: Use GList for global properties

PATCH In review Eduardo Habkost 2 participants 5 messages Jan 28, 2016 – May 18, 2016 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qdev: Use GList for global properties

If the same GlobalProperty struct is registered twice, the list entry gets corrupted, making tqe_next points to itself, and qdev_prop_set_globals() gets stuck in a loop. The bug can be easily reproduced by running:

  $ qemu-system-x86_64 -rtc-td-hack -rtc-td-hack

Change global_props to use GList instead of queue.h, making the code simpler and able to deal with properties being registered twice.

---
 hw/core/qdev-properties.c | 17 ++++++++++-------
 include/hw/qdev-core.h    |  1 -
 2 files changed, 10 insertions(+), 8 deletions(-)
hw/core/qdev-properties.c +10 -7
index aacad66..180e0da 100644
@@ -1,3 +1,5 @@
+#include <glib.h>
+
 #include "net/net.h"
 #include "hw/qdev.h"
 #include "qapi/qmp/qerror.h"
@@ -1009,12 +1011,11 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
     *ptr = value;
 }
 
-static QTAILQ_HEAD(, GlobalProperty) global_props =
-        QTAILQ_HEAD_INITIALIZER(global_props);
+static GList *global_props;
 
 void qdev_prop_register_global(GlobalProperty *prop)
 {
-    QTAILQ_INSERT_TAIL(&global_props, prop, next);
+    global_props = g_list_append(global_props, prop);
 }
 
 void qdev_prop_register_global_list(GlobalProperty *props)
@@ -1028,10 +1029,11 @@ void qdev_prop_register_global_list(GlobalProperty *props)
 
 int qdev_prop_check_globals(void)
 {
-    GlobalProperty *prop;
+    GList *l;
     int ret = 0;
 
-    QTAILQ_FOREACH(prop, &global_props, next) {
+    for (l = global_props; l; l = l->next) {
+        GlobalProperty *prop = l->data;
         ObjectClass *oc;
         DeviceClass *dc;
         if (prop->used) {
@@ -1062,9 +1064,10 @@ int qdev_prop_check_globals(void)
 static void qdev_prop_set_globals_for_type(DeviceState *dev,
                                 const char *typename)
 {
-    GlobalProperty *prop;
+    GList *l;
 
-    QTAILQ_FOREACH(prop, &global_props, next) {
+    for (l = global_props; l; l = l->next) {
+        GlobalProperty *prop = l->data;
         Error *err = NULL;
 
         if (strcmp(typename, prop->driver) != 0) {
include/hw/qdev-core.h +0 -1
index abcdee8..1fdbaaa 100644
@@ -268,7 +268,6 @@ typedef struct GlobalProperty {
     const char *value;
     bool user_provided;
     bool used;
-    QTAILQ_ENTRY(GlobalProperty) next;
 } GlobalProperty;
 
 /*** Board API.  This should go away once we have a machine config file.  ***/
Signature · 1 line
2.1.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Eduardo Habkost

If the same GlobalProperty struct is registered twice, the list entry gets corrupted, making tqe_next points to itself, and qdev_prop_set_globals() gets stuck in a loop. The bug can be easily reproduced by running:

Quoted 7 lines
  $ qemu-system-x86_64 -rtc-td-hack -rtc-td-hack

Change global_props to use GList instead of queue.h, making the code simpler and able to deal with properties being registered twice.

Quoted 71 lines
---
 hw/core/qdev-properties.c | 17 ++++++++++-------
 include/hw/qdev-core.h    |  1 -
 2 files changed, 10 insertions(+), 8 deletions(-)
hw/core/qdev-properties.c +10 -7
index aacad66..180e0da 100644
@@ -1,3 +1,5 @@
+#include <glib.h>
+
 #include "net/net.h"
 #include "hw/qdev.h"
 #include "qapi/qmp/qerror.h"
@@ -1009,12 +1011,11 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
     *ptr = value;
 }
 
-static QTAILQ_HEAD(, GlobalProperty) global_props =
-        QTAILQ_HEAD_INITIALIZER(global_props);
+static GList *global_props;
 
 void qdev_prop_register_global(GlobalProperty *prop)
 {
-    QTAILQ_INSERT_TAIL(&global_props, prop, next);
+    global_props = g_list_append(global_props, prop);
 }
 
 void qdev_prop_register_global_list(GlobalProperty *props)
@@ -1028,10 +1029,11 @@ void qdev_prop_register_global_list(GlobalProperty *props)
 
 int qdev_prop_check_globals(void)
 {
-    GlobalProperty *prop;
+    GList *l;
     int ret = 0;
 
-    QTAILQ_FOREACH(prop, &global_props, next) {
+    for (l = global_props; l; l = l->next) {
+        GlobalProperty *prop = l->data;
         ObjectClass *oc;
         DeviceClass *dc;
         if (prop->used) {
@@ -1062,9 +1064,10 @@ int qdev_prop_check_globals(void)
 static void qdev_prop_set_globals_for_type(DeviceState *dev,
                                 const char *typename)
 {
-    GlobalProperty *prop;
+    GList *l;
 
-    QTAILQ_FOREACH(prop, &global_props, next) {
+    for (l = global_props; l; l = l->next) {
+        GlobalProperty *prop = l->data;
         Error *err = NULL;
 
         if (strcmp(typename, prop->driver) != 0) {
include/hw/qdev-core.h +0 -1
index abcdee8..1fdbaaa 100644
@@ -268,7 +268,6 @@ typedef struct GlobalProperty {
     const char *value;
     bool user_provided;
     bool used;
-    QTAILQ_ENTRY(GlobalProperty) next;
 } GlobalProperty;
 
 /*** Board API.  This should go away once we have a machine config file.  ***/
Signature · 1 line
2.1.0
#2 lore raw
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Eduardo Habkost

If the same GlobalProperty struct is registered twice, the list entry gets corrupted, making tqe_next points to itself, and qdev_prop_set_globals() gets stuck in a loop. The bug can be easily reproduced by running:

  $ qemu-system-x86_64 -rtc-td-hack -rtc-td-hack
Quoted 7 lines
Quoted 5 lines

Change global_props to use GList instead of queue.h, making the code simpler and able to deal with properties being registered twice.

Thanks! It seems we don't have a maintainer for hw/core/qdev*. Who should merge this?

Signature · 1 line
Eduardo
#3 lore raw
Quoted 13 lines · Eduardo Habkost
Quoted 12 lines · Michael S. Tsirkin
Quoted 11 lines · Eduardo Habkost

If the same GlobalProperty struct is registered twice, the list entry gets corrupted, making tqe_next points to itself, and qdev_prop_set_globals() gets stuck in a loop. The bug can be easily reproduced by running:

  $ qemu-system-x86_64 -rtc-td-hack -rtc-td-hack

Change global_props to use GList instead of queue.h, making the code simpler and able to deal with properties being registered twice.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Thanks! It seems we don't have a maintainer for hw/core/qdev*. Who should merge this?

I've just noticed that this didn't get included. Andreas, is it OK if I merge this through the machine core tree?

Signature · 1 line
Eduardo

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw
Quoted 22 lines · Andreas Färber

Am 12.05.2016 um 14:26 schrieb Eduardo Habkost:

Quoted 21 lines · Eduardo Habkost
Quoted 19 lines · Michael S. Tsirkin
Quoted 8 lines · Eduardo Habkost
Quoted 7 lines

If the same GlobalProperty struct is registered twice, the list entry gets corrupted, making tqe_next points to itself, and qdev_prop_set_globals() gets stuck in a loop. The bug can be easily reproduced by running:

  $ qemu-system-x86_64 -rtc-td-hack -rtc-td-hack
Quoted 7 lines
Quoted 5 lines

Change global_props to use GList instead of queue.h, making the code simpler and able to deal with properties being registered twice.

Thanks! It seems we don't have a maintainer for hw/core/qdev*. Who should merge this?

Quoted 8 lines
Quoted 2 lines

I've just noticed that this didn't get included. Andreas, is it OK if I merge this through the machine core tree?

In general I don't mind about those lists, but I still have the bus refactoring sitting in my tree that didn't make it into 2.6 because someone made last-minute changes to osdep.h that resulted in hundreds of errors in my tree... If you make sure it doesn't conflict, feel free to take it.

Which branch should I look at, to ensure it doesn't conflict?

Signature · 1 line
Eduardo