Skip to contentSkip to conversation

qdev: not add devices to bus in reverse order

PATCH In review [email protected] 1 participant 2 messages Jan 9, 2024 – Jan 17, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qdev: not add devices to bus in reverse order

From: Kai Kang <[email protected]>

When this section of source codes were added via commit:

* 02e2da45c4 Add common BusState

it added devices to bus with LIST_INSERT_HEAD() which operated on the single direction list. It didn't have something like LIST_INSERT_TAIL() at that time and kept that way when turned to QTAILQ.

Then it causes the fist device in qemu command line inserted at the end of the bus child link list. And when realize them, the first device will be the last one to be realized.

Replace QTAILQ_INSERT_HEAD_RCU() with QTAILQ_INSERT_TAIL_RCU() to make sure that devices are added to bus with the sequence in the command line.

---
 hw/core/qdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/core/qdev.c +1 -1
index 43d863b0c5..5e2ff43715 100644
@@ -89,7 +89,7 @@ static void bus_add_child(BusState *bus, DeviceState *child)
     kid->child = child;
     object_ref(OBJECT(kid->child));
 
-    QTAILQ_INSERT_HEAD_RCU(&bus->children, kid, sibling);
+    QTAILQ_INSERT_TAIL_RCU(&bus->children, kid, sibling);
 
     /* This transfers ownership of kid->child to the property.  */
     snprintf(name, sizeof(name), "child[%d]", kid->index);
Signature · 1 line
2.34.1
author
#1 lore raw
Quoted 10 lines · On 1/9/24 17:52, [email protected] wrote:

From: Kai Kang <[email protected]>

When this section of source codes were added via commit:

* 02e2da45c4 Add common BusState

it added devices to bus with LIST_INSERT_HEAD() which operated on the single direction list. It didn't have something like LIST_INSERT_TAIL() at that time and kept that way when turned to QTAILQ.

Quoted 7 lines

Then it causes the fist device in qemu command line inserted at the end of the bus child link list. And when realize them, the first device will be the last one to be realized.

Replace QTAILQ_INSERT_HEAD_RCU() with QTAILQ_INSERT_TAIL_RCU() to make sure that devices are added to bus with the sequence in the command line.

Ping.

Quoted 19 lines
---
  hw/core/qdev.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/core/qdev.c +1 -1
index 43d863b0c5..5e2ff43715 100644
@@ -89,7 +89,7 @@ static void bus_add_child(BusState *bus, DeviceState *child)
      kid->child = child;
      object_ref(OBJECT(kid->child));
 
-    QTAILQ_INSERT_HEAD_RCU(&bus->children, kid, sibling);
+    QTAILQ_INSERT_TAIL_RCU(&bus->children, kid, sibling);
 
      /* This transfers ownership of kid->child to the property.  */
      snprintf(name, sizeof(name), "child[%d]", kid->index);
Signature · 2 lines
Kai Kang
Wind River Linux