qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Daniel P . Berrangé" <berrange@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Fabiano Rosas" <farosas@suse.de>,
	"Juraj Marcin" <jmarcin@redhat.com>,
	peterx@redhat.com, "Markus Armbruster" <armbru@redhat.com>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Cédric Le Goater" <clg@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>
Subject: [PATCH 0/5] QOM: Enforce container_get() to operate on containers only
Date: Mon, 18 Nov 2024 17:13:25 -0500	[thread overview]
Message-ID: <20241118221330.3480246-1-peterx@redhat.com> (raw)

[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



             reply	other threads:[~2024-11-18 22:15 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-18 22:13 Peter Xu [this message]
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

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=20241118221330.3480246-1-peterx@redhat.com \
    --to=peterx@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=clg@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=farosas@suse.de \
    --cc=jmarcin@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /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 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).