All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: "Cédric Le Goater" <clg@kaod.org>
Cc: "Emmanuel Blot" <emmanuel.blot@free.fr>,
	qemu-devel@nongnu.org,
	"Philippe Mathieu-Daudé" <philmd@mailo.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Steven Lee" <steven_lee@aspeedtech.com>,
	"Jamin Lin" <jamin_lin@aspeedtech.com>,
	"Kane Chen" <kane_chen@aspeedtech.com>,
	"Andrew Jeffery" <andrew@codeconstruct.com.au>,
	"Joel Stanley" <joel@jms.id.au>,
	qemu-arm@nongnu.org, "Fabiano Rosas" <farosas@suse.de>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Thomas Huth" <th.huth+qemu@posteo.eu>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Emmanuel Blot" <eblot@meta.com>
Subject: Re: Adding /machines/labels (was Re: [PATCH v2 18/25] tests/functional: add a pure-Python device-locator resolver)
Date: Fri, 04 Sep 2026 10:22:42 +0200	[thread overview]
Message-ID: <87a4pxh1d9.fsf@pond.sub.org> (raw)
In-Reply-To: <cb1b5ec3-d7ba-42fe-a8ab-da7c236b1660@kaod.org> ("Cédric Le Goater"'s message of "Thu, 3 Sep 2026 16:21:55 +0200")

Cédric Le Goater <clg@kaod.org> writes:

> On 7/31/26 12:45, Emmanuel Blot wrote:
>> Add DeviceLocator, a helper that addresses a device by its position on
>> the bus -- bus, address, type or index -- rather than by a QOM path. A
>> QOM path locates a device under the object that owns it, by enumeration
>> order, and so says nothing about where the device actually sits in the
>> bus topology. From a QOM anchor DeviceLocator instead walks the bus and
>> device hierarchy, alternating bus and device hops, to reach the target.
>> It relies only on standard QOM queries over QMP, needing no custom
>> commands or changes to QEMU.
>
> Let's recap first :
>
> Several recent threads have touched the same topic: QOM
> composition-tree paths encode ownership, but developers and tests
> regularly need to identify devices by their position in the bus
> topology. The threads in question:
>
>   - "[PATCH v5 0/8] hw/sensor: Add new device emulation for TI ADC128D818" [1]
>   - "Call to clean up QOM onboard devices lacking a parent" [2]
>   - "[PATCH RFC 001/134] qom: Introduce object_new_child()" [3]
>   - "[PATCH RFC v2 0/137] qom: Make composition-tree parenting mandatory" [4]
>   - "[PATCH v2 0/25] hw/arm: Facebook SanMiguel BMC and TMP75-family sensors" [5]
>
>
> * The problem
>
> QEMU has two device hierarchies serving different purposes:
>
>   - The QOM composition tree describes parent/child ownership.  Every
>     object has exactly one parent. Paths look like:
>     /machine/soc/i2c-controller/child-device.
>   - The bus topology describes electrical connectivity (visible
>     through "info qtree"). A device sits on a bus at an address.

Yes.

*Composition* tree means the children are *components* of their parent.
At least that's the intended use.

The qtree predates QOM and is a bit of a relic.  Its design is too
simplistic to match electric reality: it's a *tree*, whereas real wires
form a *graph*.

Tree is fine for ordinary devices plugging into something a hardware
dude would recognize as a bus, say PCI or USB.

Caveat: as long as they plug into exactly one such thing; "multi-master
I2C" was mentiond as a counter-example.

Many (most?) of our devices are sysbus devices.  Sysbus is not a bus,
it's a cop out: it doesn't actually describe electrical connections
beyond "there are some to other parts of 'the system'".

And then there are funny devices like certain PCI VGA devices that plug
into a PCI but also bypass PCI for mapping their frame buffer.

I guess (the saner parts of) qtree may still provide some value.  I'm
curious: do people use it in programs?  Management applications in
particular.

QOM provides a mechanism that is suitable for modeling electrical
connections other than the ones to the parent: links.  These do form a
graph.

> Devices created without an explicit QOM parent fall into
> /machine/unattached/device[N], the "orphanage", with names that depend
> on enumeration order and are therefore unstable. Markus identified
> 380+ such devices across all QEMU machines [2]. Even with a stable QOM
> path, the path says nothing about where the device sits in the bus
> topology or what purpose it serves.

Yes, and that can be a problem.

> * Three approaches on the table
>
>   1. Mandatory QOM parenting (Graf [3][4] / Armbruster [2])
>      object_new_child() and per-bus creators enforce parenting at
>      creation time. Deletes the orphanage. Scope: 440 files, 137
>      patches.
>
>   2. Bus-child parenting (Blot [1], rejected)
>      i2c_slave_create_simple() would parent slaves to their bus,
>      named by hex address (e.g. /machine/i2c[0]/i2c-bus/0x6f).
>
>   3. DeviceLocator (Blot [5])
>      Pure-Python helper that resolves devices by bus-position
>      descriptors like:
>
>        /machine/soc::aspeed.i2c-ast2600[0]~i2c[9]~tmp75@0x4b
>
>      It walks the bus/device hierarchy using only qom-list/qom-get
>      over QMP, no QEMU code changes needed. 600 lines of python.
>
>
> * /machine/labels: DT-style alias container for QOM
>
> The idea: add a flat container /machine/labels under the machine, where
> board code registers link<> properties pointing to devices by
> purpose name. Like device tree /aliases (serial0  > /soc/uart@9000000).

This general idea has been sloshing around in my head for a long time, I
just haven't had a compelling reason to flesh it out.

> Container creation is one line in qemu_create_machine_containers().
> QMP introspection works today: qom-get /machine/labels/rtc returns the
> target's canonical path.
>
> A small helper is all that is needed:
>
>   void machine_add_label(const char *label, Object *target)
>   {
>       object_property_add_const_link(
>           machine_get_container("labels"), label, target);
>   }
>
> Board code registers one label per well-known device:
>
>   machine_add_label("rtc", OBJECT(dev));
>   machine_add_label("tmp75-bus9-0x4b", OBJECT(sensor));
>
> Tests resolve devices with a single QMP call instead of walking
> the bus hierarchy.  For the common case, functional tests targeting
> specific board devices (SanMiguel TMP75s, Catalina PCA9555s, Anacapa
> ADC128D818s), the board author already knows which devices matter.
>
> Thoughts?

To get the most value out of /machine/labels/, we'd want

* Documented naming conventions such as "/machine/label/serial0 always
  refers to the machine's first serial device"

* Reliability, i.e. if /machine/label/ exists, then
  /machine/label/serial0 exists unless the machine has no first serial
  device

* /machine/label/ to exist for the machines we actually care about :)

> Thanks,
>
> C.
>
> [1] https://lore.kernel.org/qemu-devel/20260701-i2c-adc128d818-anacapa-v5-6-fe8292d86b38@free.fr
> [2] https://lore.kernel.org/qemu-devel/87se5scipx.fsf@pond.sub.org
> [3] https://lore.kernel.org/qemu-devel/20260711223707.42139-1-graf@amazon.com
> [4] https://lore.kernel.org/qemu-devel/20260718213652.37673-1-graf@amazon.com
> [5] https://lore.kernel.org/qemu-devel/20260731-sanmiguel-bmc-locator-v2-0-1266926ba769@free.fr



  reply	other threads:[~2026-09-04  8:23 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-31 10:44 [PATCH v2 00/25] hw/arm: Facebook SanMiguel BMC and TMP75-family sensors Emmanuel Blot via
2026-07-31 10:44 ` Emmanuel Blot via qemu development
2026-07-31 10:45 ` [PATCH v2 01/25] hw/sensor: tmp105: make device state private to the implementation Emmanuel Blot via
2026-07-31 10:45   ` Emmanuel Blot via qemu development
2026-09-01  6:58   ` Cédric Le Goater
2026-07-31 10:45 ` [PATCH v2 02/25] hw/sensor: tmp105: name the parent object field parent_obj Emmanuel Blot via
2026-07-31 10:45   ` Emmanuel Blot via qemu development
2026-09-01  6:58   ` Cédric Le Goater
2026-07-31 10:45 ` [PATCH v2 03/25] hw/sensor: tmp105: implement Resettable reset Emmanuel Blot via
2026-07-31 10:45   ` Emmanuel Blot via qemu development
2026-09-01  6:58   ` Cédric Le Goater
2026-07-31 10:45 ` [PATCH v2 04/25] hw/sensor: tmp105: enforce the configurable fault queue Emmanuel Blot via qemu development
2026-07-31 10:45   ` Emmanuel Blot via
2026-09-01  6:59   ` Cédric Le Goater
2026-07-31 10:45 ` [PATCH v2 05/25] hw/sensor: tmp105: describe the temperature property Emmanuel Blot via
2026-07-31 10:45   ` Emmanuel Blot via qemu development
2026-09-01  6:59   ` Cédric Le Goater
2026-07-31 10:45 ` [PATCH v2 06/25] hw/arm: aspeed: guard board-local temperature-sensor aliases Emmanuel Blot via qemu development
2026-07-31 10:45   ` Emmanuel Blot via
2026-09-01  6:59   ` Cédric Le Goater
2026-07-31 10:45 ` [PATCH v2 07/25] hw/sensor: tmp105: add TMP75, TMP175 and LM75B variants Emmanuel Blot via qemu development
2026-07-31 10:45   ` Emmanuel Blot via
2026-09-01  6:59   ` Cédric Le Goater
2026-07-31 10:45 ` [PATCH v2 08/25] tests/qtest: tmp105: cover the ALERT fault queue Emmanuel Blot via
2026-07-31 10:45   ` Emmanuel Blot via qemu development
2026-09-01  6:59   ` Cédric Le Goater
2026-07-31 10:45 ` [PATCH v2 09/25] tests/qtest: tmp105: cover the TMP75, TMP175 and LM75B variants Emmanuel Blot via
2026-07-31 10:45   ` Emmanuel Blot via qemu development
2026-09-01  6:59   ` Cédric Le Goater
2026-07-31 10:45 ` [PATCH v2 10/25] tests/qtest: tmp105: cover one-shot and fault-queue write immunity Emmanuel Blot via
2026-07-31 10:45   ` Emmanuel Blot via qemu development
2026-09-01  6:59   ` Cédric Le Goater
2026-07-31 10:45 ` [PATCH v2 11/25] tests/qtest: tmp105: cover shutdown clearing the ALERT across variants Emmanuel Blot via qemu development
2026-07-31 10:45   ` Emmanuel Blot via
2026-09-01  7:00   ` Cédric Le Goater
2026-07-31 10:45 ` [PATCH v2 12/25] hw/arm: sanmiguel: add Facebook SanMiguel BMC machine Emmanuel Blot via
2026-07-31 10:45   ` Emmanuel Blot via qemu development
2026-07-31 10:45 ` [PATCH v2 13/25] hw/arm: sanmiguel: populate EEPROM data Emmanuel Blot via qemu development
2026-07-31 10:45   ` Emmanuel Blot via
2026-09-02  5:50   ` Cédric Le Goater
2026-07-31 10:45 ` [PATCH v2 14/25] hw/arm: catalina: use the real TMP75 model Emmanuel Blot via qemu development
2026-07-31 10:45   ` Emmanuel Blot via
2026-09-02  5:50   ` Cédric Le Goater
2026-07-31 10:45 ` [PATCH v2 15/25] hw/arm: fuji: use the real TMP75 and LM75B temperature sensors Emmanuel Blot via qemu development
2026-07-31 10:45   ` Emmanuel Blot via
2026-09-02  5:50   ` Cédric Le Goater
2026-07-31 10:45 ` [PATCH v2 16/25] tests/functional: aspeed: optionally check the device tree model on boot Emmanuel Blot via
2026-07-31 10:45   ` Emmanuel Blot via qemu development
2026-09-02  5:50   ` Cédric Le Goater
2026-07-31 10:45 ` [PATCH v2 17/25] tests/functional: give the set_machine probe VM the test workdir Emmanuel Blot via
2026-07-31 10:45   ` Emmanuel Blot via qemu development
2026-09-02  5:51   ` Cédric Le Goater
2026-07-31 10:45 ` [PATCH v2 18/25] tests/functional: add a pure-Python device-locator resolver Emmanuel Blot via
2026-07-31 10:45   ` Emmanuel Blot via qemu development
2026-09-03 14:21   ` Adding /machines/labels (was Re: [PATCH v2 18/25] tests/functional: add a pure-Python device-locator resolver) Cédric Le Goater
2026-09-04  8:22     ` Markus Armbruster [this message]
2026-09-05 12:45     ` Mark Cave-Ayland
2026-09-05 15:20       ` Cédric Le Goater
2026-07-31 10:45 ` [PATCH v2 19/25] tests/functional: add a device-locator self-check Emmanuel Blot via qemu development
2026-07-31 10:45   ` Emmanuel Blot via
2026-07-31 10:45 ` [PATCH v2 20/25] tests/functional: aspeed: add hwmon sensor read helpers Emmanuel Blot via qemu development
2026-07-31 10:45   ` Emmanuel Blot via
2026-07-31 10:45 ` [PATCH v2 21/25] tests/functional/arm: sanmiguel: add BMC boot test Emmanuel Blot via
2026-07-31 10:45   ` Emmanuel Blot via qemu development
2026-07-31 10:45 ` [PATCH v2 22/25] tests/functional/arm: catalina: test TMP75 Emmanuel Blot via
2026-07-31 10:45   ` Emmanuel Blot via qemu development
2026-07-31 10:45 ` [PATCH v2 23/25] tests/functional/arm: catalina: test PCA9555 IO expander via QOM Emmanuel Blot via qemu development
2026-07-31 10:45   ` Emmanuel Blot via
2026-07-31 10:45 ` [PATCH v2 24/25] hw/arm: catalina: drive pca9554 io expander input pins externally Emmanuel Blot via qemu development
2026-07-31 10:45   ` Emmanuel Blot via
2026-07-31 10:45 ` [PATCH v2 25/25] tests/functional/arm: catalina: test PCA9554 IO expander via QOM Emmanuel Blot via qemu development
2026-07-31 10:45   ` Emmanuel Blot via
2026-08-31 14:42 ` [PING] Re: [PATCH v2 00/25] hw/arm: Facebook SanMiguel BMC and TMP75-family sensors Emmanuel Blot
2026-09-02  6:19 ` Cédric Le Goater

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a4pxh1d9.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=andrew@codeconstruct.com.au \
    --cc=berrange@redhat.com \
    --cc=clg@kaod.org \
    --cc=eblot@meta.com \
    --cc=emmanuel.blot@free.fr \
    --cc=farosas@suse.de \
    --cc=jamin_lin@aspeedtech.com \
    --cc=joel@jms.id.au \
    --cc=kane_chen@aspeedtech.com \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@mailo.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=steven_lee@aspeedtech.com \
    --cc=th.huth+qemu@posteo.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.