[This is not for 9.2 release, but for 10.0] QEMU defines a frequently used helper container_get(), which (from its name implies) should return a container object of a specific path, normally starting from object_get_root() (aka, the root of QOM tree, "/"), or some sub-directory of root.
We mostly use it correctly across the tree, except two use cases that may abuse the helper to be similar to object_resolve_path_component(): - qdev_get_machine() - e500_pcihost_bridge_realize() In the two cases, container_get() might accidentally create a container even if the goal of the caller is trying to fetch some non-container object. This series cleans this up by firstly remove these two abuses, replacing the container_get() usages with object_resolve_path_component(). Meanwhile, the last patch adds not only rich comment explaining container_get() usages, but also added a lightweight assertion to make sure container_get() will always walk on container objects, and always return container objects. There's another implicit side effect that container_get() may silently create missing container objects while walking the path. We could switch to an explicit way of using containers in the future, but now leaving that behavior as-is. Note, patch 3,4 were picked up from the previous singleton series [1], even if the vIOMMU patch wasn't present. It's because they're still required in this cleanup series to either clean up container_get() user, or to avoid breaking test_static_prop_subprocess() similarly there. Looks like that test is so far the only test that can try to realize() a qdev without a machine object. [1] https://lore.kernel.org/r/20241029211607.2114845-1-pet...@redhat.com Thanks, Peter Xu (5): qom: Add TYPE_CONTAINER macro ppc/e500: Avoid abuse of container_get() qdev: Make device_set_realized() always safe in tests qdev: Make qdev_get_machine() not use container_get() qom: Make container_get() strict to always walk or return container include/qom/object.h | 3 ++- hw/arm/stellaris.c | 2 +- hw/core/qdev.c | 20 +++++++++++++++++--- hw/pci-host/ppce500.c | 4 ++-- qom/container.c | 25 +++++++++++++++++++++++-- qom/object.c | 4 ++-- 6 files changed, 47 insertions(+), 11 deletions(-) -- 2.45.0