Igor Mammedov <[email protected]> writes: > On Thu, 19 Feb 2026 16:06:41 +0100 > Igor Mammedov <[email protected]> wrote: > >> On Tue, 17 Feb 2026 07:55:12 +0100 >> Thomas Huth <[email protected]> wrote: >> >> > From: Thomas Huth <[email protected]> >> > >> > PCI devices that are added via pci_create_simple_multifunction(), >> > pci_create_simple() or pci_init_nic_in_slot() currently show up >> > under "/machine/unattached" in the QOM tree. This is somewhat ugly, >> > the parent should rather be the PCI bus node instead, so let's add >> > the proper relation here. >> > >> > Signed-off-by: Thomas Huth <[email protected]> >> > --- >> > hw/pci/pci.c | 14 ++++++++++++++ >> > 1 file changed, 14 insertions(+) >> > >> > diff --git a/hw/pci/pci.c b/hw/pci/pci.c >> > index 90d6d71efdc..2f4d2be50fd 100644 >> > --- a/hw/pci/pci.c >> > +++ b/hw/pci/pci.c >> > @@ -2071,6 +2071,15 @@ const pci_class_desc *get_class_desc(int class) >> > return desc; >> > } >> > >> > +static void pci_dev_property_add_child(PCIBus *bus, const char *name, >> > + PCIDevice *dev) >> > +{ >> > + g_autofree char *childname = g_strdup_printf("%s[%d.%d]", name, >> > + PCI_SLOT(dev->devfn), >> > + PCI_FUNC(dev->devfn)); >> > + object_property_add_child(OBJECT(bus), childname, OBJECT(dev)); >> > +} >> > + >> > void pci_init_nic_devices(PCIBus *bus, const char *default_model) >> > { >> > qemu_create_nic_bus_devices(&bus->qbus, TYPE_PCI_DEVICE, >> > default_model, >> > @@ -2114,6 +2123,7 @@ bool pci_init_nic_in_slot(PCIBus *rootbus, const >> > char *model, >> > >> > pci_dev = pci_new(devfn, model); >> there are a few more places that have similar pattern, should we fix them to? >> >> > qdev_set_nic_properties(&pci_dev->qdev, nd); >> > + pci_dev_property_add_child(bus, model, pci_dev); >> >> > pci_realize_and_unref(pci_dev, bus, &error_fatal); >> this one also takes bus as an argument, and then goes down to >> qdev_realize_and_unref->qdev_realize->qdev_set_parent_bus->bus_add_child >> that eventually creates a link to device. >> >> wouldn't pci_dev_property_add_child() create a duplicate entry >> as a child with different name component there? >> >> another question, should we 'fix' qdev_set_parent_bus->bus_add_child >> to add a child instead of a link? That would do what patch intends >> but consistently for all devices with parent bus. > > and then this rises a question if the bus should be a parent or > the owner of the bus is the parent?
This question is about the QOM composition tree (the thing "info qom-tree" shows). There is also the qdev tree (the thing "info qtree" shows). In the qdev tree, the PCI device's parent is a PCI bus, and the PCI bus's parent is the device providing the bus. An edge from qdev to parent qbus means qdev plugs into qbus. An edge from qbus to parent qdev means qbus is provided by qdev. Example: an i440FX machine's device i440FX-pcihost is parent of PCI bus "pci.0" is parent of device PIIX3. In the QOM composition tree, an edge from child to parent means parent contains child. Example: a i440FX machine's i440FX-pcihost device object /machine/i440fx is the parent of PCI bus object /machine/i440fx/pci.0. Makes sense. i440FX-pcihost also contains a PIIX3 PCI device wired to its PCI bus. Should PIIX3 be the QOM child of the i440FX-pcihost device, or of its PCI bus? This is Igor's question. Due to sloppy modeling, it's currently neither: it's at /machine/unattached/device[3] instead. Is there any non-sloppy precedence to guide us? QOM maintainers, do you have any advice? [...]
