From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Peter Maydell <peter.maydell@linaro.org>
Cc: QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [PULL v2 00/61] Misc patches for soft freeze
Date: Tue, 17 Mar 2020 16:42:34 +0100 [thread overview]
Message-ID: <8f1f0486-2ad6-0d16-b423-bc09110b31a0@redhat.com> (raw)
In-Reply-To: <4685b090-c480-0061-6cae-f29cc8cbd717@redhat.com>
On 3/17/20 3:47 PM, Paolo Bonzini wrote:
> On 17/03/20 15:26, Stefan Hajnoczi wrote:
>> Yes, looks like the compiler can't figure out the control flow on
>> NetBSD.
>>
>> We could drop the WITH_QEMU_LOCK_GUARD() macro and use this idiom
>> instead:
>>
>> {
>> QEMU_LOCK_GUARD(&mutex);
>> ...
>> }
>>
>> But it's unusual for C code to create scopes without a statement (for,
>> if, while).
>
> After staring at compiler dumps for a while I have just concluded that
> this could actually be considered a bug in WITH_QEMU_LOCK_GUARD.
>
> QEMU_MAKE_LOCKABLE returns NULL if passed a NULL argument. This is the
> root cause of the NetBSD failure, as the compiler doesn't figure out
> that &timer_list->active_timers_lock is non-NULL and therefore doesn't
> simplify the qemu_make_lockable function.
>
> But why does that cause an uninitialized variable warning? Because if
> WITH_QEMU_LOCK_GUARD were passed NULL, it would not execute its body!
>
> So I'm going to squash the following in the series, mostly through a new
> patch "lockable: introduce QEMU_MAKE_LOCKABLE_NONNULL":
>
> diff --git a/include/qemu/lockable.h b/include/qemu/lockable.h
> index 44b3f4b..1aeb2cb 100644
> --- a/include/qemu/lockable.h
> +++ b/include/qemu/lockable.h
> @@ -67,7 +67,7 @@ qemu_make_lockable(void *x, QemuLockable *lockable)
> * In C++ it would be different, but then C++ wouldn't need QemuLockable
> * either...
> */
> -#define QEMU_MAKE_LOCKABLE_(x) qemu_make_lockable((x), &(QemuLockable) { \
> +#define QEMU_MAKE_LOCKABLE_(x) (&(QemuLockable) { \
> .object = (x), \
> .lock = QEMU_LOCK_FUNC(x), \
> .unlock = QEMU_UNLOCK_FUNC(x), \
> @@ -75,14 +75,27 @@ qemu_make_lockable(void *x, QemuLockable *lockable)
>
> /* QEMU_MAKE_LOCKABLE - Make a polymorphic QemuLockable
> *
> - * @x: a lock object (currently one of QemuMutex, CoMutex, QemuSpin).
> + * @x: a lock object (currently one of QemuMutex, QemuRecMutex, CoMutex, QemuSpin).
> *
> * Returns a QemuLockable object that can be passed around
> - * to a function that can operate with locks of any kind.
> + * to a function that can operate with locks of any kind, or
> + * NULL if @x is %NULL.
> */
> #define QEMU_MAKE_LOCKABLE(x) \
> QEMU_GENERIC(x, \
> (QemuLockable *, (x)), \
> + qemu_make_lockable((x), QEMU_MAKE_LOCKABLE_(x)))
> +
> +/* QEMU_MAKE_LOCKABLE_NONNULL - Make a polymorphic QemuLockable
> + *
> + * @x: a lock object (currently one of QemuMutex, QemuRecMutex, CoMutex, QemuSpin).
> + *
> + * Returns a QemuLockable object that can be passed around
> + * to a function that can operate with locks of any kind.
> + */
> +#define QEMU_MAKE_LOCKABLE_NONNULL(x) \
> + QEMU_GENERIC(x, \
> + (QemuLockable *, (x)), \
> QEMU_MAKE_LOCKABLE_(x))
>
> static inline void qemu_lockable_lock(QemuLockable *x)
> @@ -112,7 +125,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(QemuLockable, qemu_lockable_auto_unlock)
>
> #define WITH_QEMU_LOCK_GUARD_(x, var) \
> for (g_autoptr(QemuLockable) var = \
> - qemu_lockable_auto_lock(QEMU_MAKE_LOCKABLE((x))); \
> + qemu_lockable_auto_lock(QEMU_MAKE_LOCKABLE_NONNULL((x))); \
> var; \
> qemu_lockable_auto_unlock(var), var = NULL)
>
>
> So thank you NetBSD compiler, I guess. :P
Yep, new patch looks good.
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>
> Paolo
>
prev parent reply other threads:[~2020-03-17 15:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-16 22:06 [PULL v2 00/61] Misc patches for soft freeze Paolo Bonzini
2020-03-16 22:06 ` [PULL 06/61] util: add util function buffer_zero_avx512() Paolo Bonzini
2020-03-17 11:03 ` [PULL v2 00/61] Misc patches for soft freeze Peter Maydell
2020-03-17 12:02 ` Philippe Mathieu-Daudé
2020-03-17 14:26 ` Stefan Hajnoczi
2020-03-17 14:47 ` Paolo Bonzini
2020-03-17 15:42 ` Philippe Mathieu-Daudé [this message]
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=8f1f0486-2ad6-0d16-b423-bc09110b31a0@redhat.com \
--to=philmd@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).