From: Marcel Apfelbaum <marcel.a@redhat.com>
To: Luiz Capitulino <lcapitulino@redhat.com>
Cc: Gal Hammer <ghammer@redhat.com>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] hmp: fix regression of HMP device_del auto-completion
Date: Wed, 26 Nov 2014 21:32:50 +0200 [thread overview]
Message-ID: <1417030370.2807.14.camel@localhost.localdomain> (raw)
In-Reply-To: <20141126130528.50835019@redhat.com>
On Wed, 2014-11-26 at 13:05 -0500, Luiz Capitulino wrote:
> On Wed, 26 Nov 2014 13:50:01 +0200
> Marcel Apfelbaum <marcel.a@redhat.com> wrote:
>
> > The commits:
> > - 6a1fa9f5 (monitor: add del completion for peripheral device)
> > - 66e56b13 (qdev: add qdev_build_hotpluggable_device_list helper)
> >
> > cause a QEMU crash when trying to use HMP device_del auto-completion.
> > It can be easily reproduced by:
> > <qemu-bin> -enable-kvm ~/images/fedora.qcow2 -monitor stdio -device virtio-net-pci,id=vnet
> >
> > (qemu) device_del
> > /home/mapfelba/git/upstream/qemu/hw/core/qdev.c:941:qdev_build_hotpluggable_device_list: Object 0x7f6ce04e4fe0 is not an instance of type device
> > Aborted (core dumped)
> >
> > The root cause is qdev_build_hotpluggable_device_list going recursively over
> > all peripherals and their children assuming all are devices. It doesn't work
> > since PCI devices have at least on child which is a memory region (bus master).
> >
> > Solved by observing that all devices appear as direct children of
> > /machine/peripheral container. No need of going recursively
> > over all the children.
> >
> > Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
>
> Peter, can you apply this patch directly to master to avoid me a pull
> request? Maybe it's a good idea to wait until tomorrow for more
> reviewers though.
Yes, another review would be welcomed, especially a QOM reviewer.
>
> Marcel, thanks a lot for taking care of this!
No problem, glad to do it.
I forgot to add:
Reported-by: Gal Hammer <ghammer@redhat.com>
Thanks,
Marcel
>
> > ---
> > hw/core/qdev.c | 12 ++++++++++--
> > include/hw/qdev-core.h | 2 +-
> > monitor.c | 11 ++++-------
> > 3 files changed, 15 insertions(+), 10 deletions(-)
> >
> > diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> > index 413b413..35fd00d 100644
> > --- a/hw/core/qdev.c
> > +++ b/hw/core/qdev.c
> > @@ -935,7 +935,7 @@ void qdev_alias_all_properties(DeviceState *target, Object *source)
> > } while (class != object_class_by_name(TYPE_DEVICE));
> > }
> >
> > -int qdev_build_hotpluggable_device_list(Object *obj, void *opaque)
> > +static int qdev_add_hotpluggable_device(Object *obj, void *opaque)
> > {
> > GSList **list = opaque;
> > DeviceState *dev = DEVICE(obj);
> > @@ -944,10 +944,18 @@ int qdev_build_hotpluggable_device_list(Object *obj, void *opaque)
> > *list = g_slist_append(*list, dev);
> > }
> >
> > - object_child_foreach(obj, qdev_build_hotpluggable_device_list, opaque);
> > return 0;
> > }
> >
> > +GSList *qdev_build_hotpluggable_device_list(Object *peripheral)
> > +{
> > + GSList *list = NULL;
> > +
> > + object_child_foreach(peripheral, qdev_add_hotpluggable_device, &list);
> > +
> > + return list;
> > +}
> > +
> > static bool device_get_realized(Object *obj, Error **errp)
> > {
> > DeviceState *dev = DEVICE(obj);
> > diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
> > index d3a2940..589bbe7 100644
> > --- a/include/hw/qdev-core.h
> > +++ b/include/hw/qdev-core.h
> > @@ -365,7 +365,7 @@ extern int qdev_hotplug;
> >
> > char *qdev_get_dev_path(DeviceState *dev);
> >
> > -int qdev_build_hotpluggable_device_list(Object *obj, void *opaque);
> > +GSList *qdev_build_hotpluggable_device_list(Object *peripheral);
> >
> > void qbus_set_hotplug_handler(BusState *bus, DeviceState *handler,
> > Error **errp);
> > diff --git a/monitor.c b/monitor.c
> > index fa00594..f1031a1 100644
> > --- a/monitor.c
> > +++ b/monitor.c
> > @@ -4321,17 +4321,14 @@ void object_add_completion(ReadLineState *rs, int nb_args, const char *str)
> > static void peripheral_device_del_completion(ReadLineState *rs,
> > const char *str, size_t len)
> > {
> > - Object *peripheral;
> > - GSList *list = NULL, *item;
> > + Object *peripheral = container_get(qdev_get_machine(), "/peripheral");
> > + GSList *list, *item;
> >
> > - peripheral = object_resolve_path("/machine/peripheral/", NULL);
> > - if (peripheral == NULL) {
> > + list = qdev_build_hotpluggable_device_list(peripheral);
> > + if (!list) {
> > return;
> > }
> >
> > - object_child_foreach(peripheral, qdev_build_hotpluggable_device_list,
> > - &list);
> > -
> > for (item = list; item; item = g_slist_next(item)) {
> > DeviceState *dev = item->data;
> >
>
next prev parent reply other threads:[~2014-11-26 19:34 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-26 11:50 [Qemu-devel] [PATCH] hmp: fix regression of HMP device_del auto-completion Marcel Apfelbaum
2014-11-26 12:21 ` Igor Mammedov
2014-11-26 18:05 ` Luiz Capitulino
2014-11-26 19:09 ` Peter Maydell
2014-11-26 19:32 ` Marcel Apfelbaum [this message]
2014-11-27 11:11 ` Marcel Apfelbaum
2014-11-27 11:26 ` Marcel Apfelbaum
2014-11-27 11:35 ` Zhu Guihua
2014-11-27 11:41 ` Marcel Apfelbaum
2014-11-27 12:08 ` Zhu Guihua
2014-11-27 12:15 ` Marcel Apfelbaum
2014-11-28 1:23 ` Zhu Guihua
2014-11-27 12:38 ` Igor Mammedov
2014-11-27 13:48 ` Marcel Apfelbaum
2014-11-28 1:50 ` Zhu Guihua
2014-11-28 5:53 ` Marcel Apfelbaum
2014-11-28 14:33 ` Igor Mammedov
2014-11-27 14:04 ` Luiz Capitulino
2014-11-27 14:13 ` Peter Maydell
2014-11-27 14:49 ` Marcel Apfelbaum
2014-11-27 15:53 ` Peter Maydell
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=1417030370.2807.14.camel@localhost.localdomain \
--to=marcel.a@redhat.com \
--cc=ghammer@redhat.com \
--cc=lcapitulino@redhat.com \
--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).