All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Michal Privoznik <mprivozn@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] qemu_opt_foreach: Fix crasher
Date: Wed, 17 Aug 2016 09:26:58 +0200	[thread overview]
Message-ID: <874m6jvosd.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <CAFEAcA8gpF2OAqPOWGUVVf9nCQUb+yGBbr6KaWjz4A0282p-+A@mail.gmail.com> (Peter Maydell's message of "Tue, 16 Aug 2016 17:25:49 +0100")

Peter Maydell <peter.maydell@linaro.org> writes:

> On 16 August 2016 at 16:17, Michal Privoznik <mprivozn@redhat.com> wrote:
>> The solution is to teach qemu_opt_foreach() to take a shortcut if
>> @opts is NULL.

Please provide a reproducer.  A stack backtrace wouldn't hurt.

>>
>> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>> ---
>>
>> Even after this patch I'm still unable to attach vhost-user:
>>
>> {"id": "libvirt-20", "error": {"class": "GenericError", "desc": "chardev \"charnet2\" is not a unix socket"}}
>>
>> But at least, qemu does not crash anymore.
>>
>>  util/qemu-option.c | 5 +++++
>>  1 file changed, 5 insertions(+)
>>
>> diff --git a/util/qemu-option.c b/util/qemu-option.c
>> index 3467dc2..78be7e1 100644
>> --- a/util/qemu-option.c
>> +++ b/util/qemu-option.c
>> @@ -614,6 +614,11 @@ int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
>>      QemuOpt *opt;
>>      int rc;
>>
>> +    if (!opts) {
>> +        /* Done, trivially. */
>> +        return 0;
>> +    }
>> +
>>      QTAILQ_FOREACH(opt, &opts->head, next) {
>>          rc = func(opaque, opt->name, opt->str, errp);
>>          if (rc) {
>> --
>> 2.8.4
>
> This seems plausible, but I don't understand our option
> code very well, and we seem to have a mix of "check for
> NULL" and "caller had better not pass NULL" in the various
> functions in util/qemu-option.c.
>
> Markus: how is this supposed to work?

I wouldn't say this is "supposed to work" in some specific way.
"Happens to work" would be closer to the truth.

If you want me to interpret some sense into the mess after the fact,
here's my best guess: we generally require non-null opts, except for
qemu_opts_del() and the qemu_opt_get_FOO().

Makes obvious sense for qemu_opts_del(), since when a failing
constructor returns null, the destructor should accept null.

The qemu_opt_get_FOO() feel like a (possibly misguided) attempt at
convenience to me.

> In any case something is clearly still busted in the
> vhost-user code, because it's expecting to get a non-NULL
> opts so it can properly parse the chardev, so that seems
> like the thing we really need to fix.

Probably.  If I had a reproducer or at least a stack backtrace, I'd even
know where to look.

  reply	other threads:[~2016-08-17  7:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-16 15:17 [Qemu-devel] [PATCH] qemu_opt_foreach: Fix crasher Michal Privoznik
2016-08-16 16:25 ` Peter Maydell
2016-08-17  7:26   ` Markus Armbruster [this message]
2016-08-17  7:35 ` Marc-André Lureau
2016-08-18  9:57   ` Peter Maydell
2016-08-17  8:03 ` Markus Armbruster
2016-08-17  8:11   ` Markus Armbruster

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=874m6jvosd.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=mprivozn@redhat.com \
    --cc=mst@redhat.com \
    --cc=peter.maydell@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.