qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] QOM: Enforce container_get() to operate on containers only
@ 2024-11-18 22:13 Peter Xu
  2024-11-18 22:13 ` [PATCH 1/5] qom: Add TYPE_CONTAINER macro Peter Xu
                   ` (4 more replies)
  0 siblings, 5 replies; 19+ messages in thread
From: Peter Xu @ 2024-11-18 22:13 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P . Berrangé, Philippe Mathieu-Daudé,
	Fabiano Rosas, Juraj Marcin, peterx, Markus Armbruster,
	Eduardo Habkost, Peter Maydell, Cédric Le Goater,
	Paolo Bonzini

[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-peterx@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



^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2024-11-20 16:24 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-18 22:13 [PATCH 0/5] QOM: Enforce container_get() to operate on containers only Peter Xu
2024-11-18 22:13 ` [PATCH 1/5] qom: Add TYPE_CONTAINER macro Peter Xu
2024-11-19  9:42   ` Daniel P. Berrangé
2024-11-19 19:52     ` Peter Xu
2024-11-18 22:13 ` [PATCH 2/5] ppc/e500: Avoid abuse of container_get() Peter Xu
2024-11-18 22:13 ` [PATCH 3/5] qdev: Make device_set_realized() always safe in tests Peter Xu
2024-11-19  9:46   ` Daniel P. Berrangé
2024-11-19 20:14     ` Peter Xu
2024-11-18 22:13 ` [PATCH 4/5] qdev: Make qdev_get_machine() not use container_get() Peter Xu
2024-11-18 22:13 ` [PATCH 5/5] qom: Make container_get() strict to always walk or return container Peter Xu
2024-11-18 23:06   ` Peter Xu
2024-11-19  8:09     ` Paolo Bonzini
2024-11-19 20:06       ` Peter Xu
2024-11-19 20:30         ` Paolo Bonzini
2024-11-19 21:43           ` Peter Xu
2024-11-20 11:45             ` Paolo Bonzini
2024-11-20 16:24               ` Peter Xu
2024-11-19 10:03   ` Daniel P. Berrangé
2024-11-19 20:25     ` Peter Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).