From: Peter Xu <peterx@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: qemu-devel@nongnu.org,
"Richard Henderson" <richard.henderson@linaro.org>,
"Markus Armbruster" <armbru@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Juraj Marcin" <jmarcin@redhat.com>,
"Daniel P . Berrangé" <berrange@redhat.com>,
"Fabiano Rosas" <farosas@suse.de>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Cédric Le Goater" <clg@redhat.com>,
"Eduardo Habkost" <eduardo@habkost.net>
Subject: Re: [PATCH v2 08/13] qdev: Make qdev_get_machine() not use container_get()
Date: Fri, 20 Dec 2024 12:24:39 -0500 [thread overview]
Message-ID: <Z2WoVxB8GfdJj6KM@x1n> (raw)
In-Reply-To: <fe9d34bf-5a68-42e3-ad00-c8f22551865c@linaro.org>
On Fri, Dec 20, 2024 at 12:25:44PM +0100, Philippe Mathieu-Daudé wrote:
> On 19/12/24 19:27, Philippe Mathieu-Daudé wrote:
> > On 19/12/24 19:20, Philippe Mathieu-Daudé wrote:
> > > On 21/11/24 20:21, Peter Xu wrote:
> > > > Currently, qdev_get_machine() has a slight misuse on container_get(), as
> > > > the helper says "get a container" but in reality the goal is to get the
> > > > machine object. It is still a "container" but not strictly.
> > > >
> > > > Note that it _may_ get a container (at "/machine") in our
> > > > current unit test
> > > > of test-qdev-global-props.c before all these changes, but it's probably
> > > > unexpected and worked by accident.
> > > >
> > > > Switch to an explicit object_resolve_path_component(), with a
> > > > side benefit
> > > > that qdev_get_machine() can happen a lot, and we don't need to split the
> > > > string ("/machine") every time. This also paves way for making
> > > > the helper
> > > > container_get() never try to return a non-container at all.
> > > >
> > > > Signed-off-by: Peter Xu <peterx@redhat.com>
> > > > ---
> > > > hw/core/qdev.c | 7 ++++++-
> > > > 1 file changed, 6 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> > > > index 5f13111b77..b622be15ee 100644
> > > > --- a/hw/core/qdev.c
> > > > +++ b/hw/core/qdev.c
> > > > @@ -817,7 +817,12 @@ Object *qdev_get_machine(void)
> > > > static Object *dev;
> > > > if (dev == NULL) {
> > > > - dev = container_get(object_get_root(), "/machine");
> > > > + dev = object_resolve_path_component(object_get_root(),
> > > > "machine");
> > > > + /*
> > > > + * Any call to this function before machine is created
> > > > is treated
> > > > + * as a programming error as of now.
> > > > + */
> > > > + assert(dev);
> > >
> > > This fails for user-emulation:
> > >
> > > ./qemu-x86_64 /bin/echo foo
> > > qemu-x86_64: ../../hw/core/qdev.c:825: qdev_get_machine: Assertion
> > > `dev' failed.
>
> OK so I guess I might have found a "fix" which is to simply not
> call qdev_get_machine() for user emulation, but this involves some
> invasive refactoring -- so will take time --.
Thanks for taking a look, Phil. Yes this sounds clean.
>
> I'm dropping this series for now, planning to merge it again on top
> of my refactor once it is ready. Any clever / simpler fix is
> obviously welcomed first.
I initially thought about this, which could also be clean but I then
noticed LINUX_USER is poisoned..
===8<===
diff --git a/qom/object.c b/qom/object.c
index 58897a79a7..da26e8d69b 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1729,7 +1729,19 @@ const char *object_property_get_type(Object *obj, const char *name, Error **errp
return prop->type;
}
+/*
+ * Create all QEMU default containers.
+ *
+ * For system emulations, "machine" and its sub-containers are only created
+ * when machine initializes (qemu_create_machine()).
+ *
+ * For user emulations, create "machine" before hand to make qdev realize()
+ * work by default.
+ */
static const char *const root_containers[] = {
+#ifdef CONFIG_LINUX_USER
+ "machine",
+#endif
"chardevs",
"objects",
"backend"
@@ -1740,10 +1752,6 @@ static Object *object_root_initialize(void)
Object *root = object_new(TYPE_CONTAINER);
int i;
- /*
- * Create all QEMU system containers. "machine" and its sub-containers
- * are only created when machine initializes (qemu_create_machine()).
- */
for (i = 0; i < ARRAY_SIZE(root_containers); i++) {
object_property_add_new_container(root, root_containers[i]);
}
===8<===
Maybe we could still move it somewhere that LINUX_USER is not poisoned
(plus "unattached" be created too, more below)?
OTOH, this works for me:
===8<===
diff --git a/linux-user/main.c b/linux-user/main.c
index b09af8d436..009b7695f2 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -819,6 +819,11 @@ int main(int argc, char **argv, char **envp)
set_preferred_target_page_bits(ctz32(host_page_size));
finalize_target_page_bits();
+ Object *fake_obj = object_property_add_new_container(object_get_root(),
+ "machine");
+ object_property_add_new_container(fake_obj, "unattached");
+
cpu = cpu_create(cpu_type);
env = cpu_env(cpu);
cpu_reset(cpu);
===8<===
So we need both "/machine" and "/machine/unattached" so far to make
linux-user work. Not sure if bsd-user/main.c needs similar care, but none
of these look as clean.
Thanks,
--
Peter Xu
next prev parent reply other threads:[~2024-12-20 17:25 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-21 19:21 [PATCH v2 00/13] QOM: container_get() removal Peter Xu
2024-11-21 19:21 ` [PATCH v2 01/13] qom: Add TYPE_CONTAINER macro Peter Xu
2024-11-21 19:21 ` [PATCH v2 02/13] qom: New object_property_add_new_container() Peter Xu
2024-11-21 20:21 ` Philippe Mathieu-Daudé
2024-11-22 14:12 ` Markus Armbruster
2024-11-21 19:21 ` [PATCH v2 03/13] tests: Fix test-qdev-global-props on anonymous qdev realize() Peter Xu
2024-11-21 19:21 ` [PATCH v2 04/13] tests: Explicitly create containers in test_qom_partial_path() Peter Xu
2024-11-21 19:21 ` [PATCH v2 05/13] ppc/e500: Avoid abuse of container_get() Peter Xu
2024-11-21 19:21 ` [PATCH v2 06/13] hw/ppc: Explicitly create the drc container Peter Xu
2024-11-21 20:20 ` Philippe Mathieu-Daudé
2024-11-21 19:21 ` [PATCH v2 07/13] qom: Create system containers explicitly Peter Xu
2024-11-21 20:19 ` Philippe Mathieu-Daudé
2024-11-21 19:21 ` [PATCH v2 08/13] qdev: Make qdev_get_machine() not use container_get() Peter Xu
2024-11-21 20:21 ` Philippe Mathieu-Daudé
2024-12-19 18:20 ` Philippe Mathieu-Daudé
2024-12-19 18:27 ` Philippe Mathieu-Daudé
2024-12-20 11:25 ` Philippe Mathieu-Daudé
2024-12-20 17:24 ` Peter Xu [this message]
2024-12-20 21:38 ` Philippe Mathieu-Daudé
2024-12-23 17:29 ` Peter Xu
2024-11-21 19:21 ` [PATCH v2 09/13] qdev: Add machine_get_container() Peter Xu
2024-11-21 19:21 ` [PATCH v2 10/13] qom: Use machine_get_container() Peter Xu
2024-11-21 20:16 ` Philippe Mathieu-Daudé
2025-01-02 13:58 ` Philippe Mathieu-Daudé
2024-11-21 19:22 ` [PATCH v2 11/13] qom: Add object_get_container() Peter Xu
2024-11-21 19:22 ` [PATCH v2 12/13] qom: Use object_get_container() Peter Xu
2024-11-21 20:15 ` Philippe Mathieu-Daudé
2024-11-21 19:22 ` [PATCH v2 13/13] qom: Remove container_get() Peter Xu
2024-11-21 20:14 ` Philippe Mathieu-Daudé
2024-12-19 17:29 ` [PATCH v2 00/13] QOM: container_get() removal Philippe Mathieu-Daudé
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=Z2WoVxB8GfdJj6KM@x1n \
--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 \
--cc=richard.henderson@linaro.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).