From: Greg Kurz <groug@kaod.org>
To: Igor Mammedov <imammedo@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org,
Markus Armbruster <armbru@redhat.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] monitor: fix dangling CPU pointer
Date: Mon, 16 Oct 2017 13:24:20 +0200 [thread overview]
Message-ID: <20171016132420.3accb7b4@bahia.lan> (raw)
In-Reply-To: <20171016104139.5f7afa6c@nial.brq.redhat.com>
On Mon, 16 Oct 2017 10:41:39 +0200
Igor Mammedov <imammedo@redhat.com> wrote:
> On Fri, 13 Oct 2017 13:47:51 +0200
> Greg Kurz <groug@kaod.org> wrote:
>
> [...]
>
> > Note that the resolution should really return a CPU object, otherwise
> > we have a bug. This is achieved by relying on object_resolve_path()
> > and CPU() instead of calling object_resolve_path_type(path, TYPE_CPU).
> I'm not sure what you are trying to say here, could you explain
> a bit more why CPU(object_resolve_path()) is chosen vs
> object_resolve_path_type(path, TYPE_CPU)
>
IIUC, if we use object_resolve_path_type(path, TYPE_CPU) and path doesn't
point to a CPU object, it will return NULL (see object_resolve_abs_path())
just like if the CPU got hot-unplugged.
My point is that the path we got from object_get_canonical_path() did
point to a CPU: if later on this path resolves to an object that isn't
a CPU, then some code somewhere used the same QOM path for some unrelated
object. I tend to think this is a bug in QEMU and we shouldn't silently
ignore it.
Makes sense ?
>
> > Suggested-by: Igor Mammedov <imammedo@redhat.com>
> > Signed-off-by: Greg Kurz <groug@kaod.org>
> > ---
> > monitor.c | 25 ++++++++++++++++++++-----
> > 1 file changed, 20 insertions(+), 5 deletions(-)
> >
> > diff --git a/monitor.c b/monitor.c
> > index fe0d1bdbb461..8489b2ad99c0 100644
> > --- a/monitor.c
> > +++ b/monitor.c
> > @@ -200,7 +200,7 @@ struct Monitor {
> >
> > ReadLineState *rs;
> > MonitorQMP qmp;
> > - CPUState *mon_cpu;
> > + gchar *mon_cpu_path;
> > BlockCompletionFunc *password_completion_cb;
> > void *password_opaque;
> > mon_cmd_t *cmd_table;
> > @@ -579,6 +579,7 @@ static void monitor_data_init(Monitor *mon)
> >
> > static void monitor_data_destroy(Monitor *mon)
> > {
> > + g_free(mon->mon_cpu_path);
> > qemu_chr_fe_deinit(&mon->chr, false);
> > if (monitor_is_qmp(mon)) {
> > json_message_parser_destroy(&mon->qmp.parser);
> > @@ -1047,20 +1048,34 @@ int monitor_set_cpu(int cpu_index)
> > if (cpu == NULL) {
> > return -1;
> > }
> > - cur_mon->mon_cpu = cpu;
> > + g_free(cur_mon->mon_cpu_path);
> > + cur_mon->mon_cpu_path = object_get_canonical_path(OBJECT(cpu));
> > return 0;
> > }
> >
> > CPUState *mon_get_cpu(void)
> > {
> > - if (!cur_mon->mon_cpu) {
> > + CPUState *cpu;
> > +
> > + if (cur_mon->mon_cpu_path) {
> > + Object *obj = object_resolve_path(cur_mon->mon_cpu_path, NULL);
> > +
> > + if (!obj) {
> > + g_free(cur_mon->mon_cpu_path);
> > + cur_mon->mon_cpu_path = NULL;
> > + } else {
> > + cpu = CPU(obj);
> this potentially might abort if obj couldn't be cast to TYPE_CPU
>
This is deliberate... is there a case where cur_mon->mon_cpu_path would
legitimately point to something that isn't of type TYPE_CPU ?
>
> > + }
> > + }
> > + if (!cur_mon->mon_cpu_path) {
> > if (!first_cpu) {
> > return NULL;
> > }
> > monitor_set_cpu(first_cpu->cpu_index);
> > + cpu = first_cpu;
> > }
> > - cpu_synchronize_state(cur_mon->mon_cpu);
> > - return cur_mon->mon_cpu;
> > + cpu_synchronize_state(cpu);
> > + return cpu;
> > }
> >
> > CPUArchState *mon_get_cpu_env(void)
> >
> >
>
next prev parent reply other threads:[~2017-10-16 11:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-13 11:47 [Qemu-devel] [PATCH] monitor: fix dangling CPU pointer Greg Kurz
2017-10-13 13:26 ` Greg Kurz
2017-10-16 8:41 ` Igor Mammedov
2017-10-16 11:24 ` Greg Kurz [this message]
2017-10-16 14:31 ` Igor Mammedov
2017-10-16 15:59 ` Greg Kurz
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=20171016132420.3accb7b4@bahia.lan \
--to=groug@kaod.org \
--cc=armbru@redhat.com \
--cc=dgilbert@redhat.com \
--cc=imammedo@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@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).