(cc'd the people listed for this file in MAINTAINERS) On Tue, 9 Jan 2024 at 13:53, Kai Kang <kai.k...@windriver.com> wrote: > > 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.
What are the problems being caused by the the list items being added in reverse order? Your commit message doesn't say what specific bug or problem it's trying to fix. In general this kind of patch is something I'm very cautious about, because it seems very likely that various bits of the code where order does matter will currently be expecting (and working around) the reverse-order behaviour, because that's what has been done by bus_add_child() for the last 20-plus years. (As one concrete example, see the big comment at the top of create_virtio_devices() in hw/arm/virt.c. There are probably others where we didn't comment on the ordering but just assume it.) > diff --git a/hw/core/qdev.c b/hw/core/qdev.c > index 43d863b0c5..5e2ff43715 100644 > --- a/hw/core/qdev.c > +++ b/hw/core/qdev.c > @@ -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); thanks -- PMM