qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>, qemu-devel@nongnu.org
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Subject: Re: [Qemu-devel] [PATCH v2 2/2] thread-pool: avoid deadlock in nested aio_poll() calls
Date: Tue, 15 Jul 2014 17:18:18 +0200	[thread overview]
Message-ID: <53C5463A.8040401@redhat.com> (raw)
In-Reply-To: <1405435466-20801-3-git-send-email-stefanha@redhat.com>

Il 15/07/2014 16:44, Stefan Hajnoczi ha scritto:
> The thread pool has a race condition if two elements complete before
> thread_pool_completion_bh() runs:
>
>   If element A's callback waits for element B using aio_poll() it will
>   deadlock since pool->completion_bh is not marked scheduled when the
>   nested aio_poll() runs.
>
> Fix this by marking the BH scheduled while thread_pool_completion_bh()
> is executing.  This way any nested aio_poll() loops will enter
> thread_pool_completion_bh() and complete the remaining elements.
>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  thread-pool.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/thread-pool.c b/thread-pool.c
> index 4cfd078..23888dc 100644
> --- a/thread-pool.c
> +++ b/thread-pool.c
> @@ -185,6 +185,12 @@ restart:
>              QLIST_REMOVE(elem, all);
>              /* Read state before ret.  */
>              smp_rmb();
> +
> +            /* Schedule ourselves in case elem->common.cb() calls aio_poll() to
> +             * wait for another request that completed at the same time.
> +             */
> +            qemu_bh_schedule(pool->completion_bh);
> +
>              elem->common.cb(elem->common.opaque, elem->ret);
>              qemu_aio_release(elem);
>              goto restart;

Please make this "return" instead, so that it is clearer that the next 
invocation of the BH is a continuation of this one.

Paolo

  reply	other threads:[~2014-07-15 15:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-15 14:44 [Qemu-devel] [PATCH v2 0/2] thread-pool: avoid fd usage and fix nested aio_poll() deadlock Stefan Hajnoczi
2014-07-15 14:44 ` [Qemu-devel] [PATCH v2 1/2] thread-pool: avoid per-thread-pool EventNotifier Stefan Hajnoczi
2014-07-15 14:44 ` [Qemu-devel] [PATCH v2 2/2] thread-pool: avoid deadlock in nested aio_poll() calls Stefan Hajnoczi
2014-07-15 15:18   ` Paolo Bonzini [this message]
2014-07-15 15:17 ` [Qemu-devel] [PATCH v2 0/2] thread-pool: avoid fd usage and fix nested aio_poll() deadlock Paolo Bonzini
2014-07-15 20:15   ` Marcin Gibuła
2014-08-05 15:08   ` Marcin Gibuła
2014-08-01 13:41 ` Stefan Hajnoczi

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=53C5463A.8040401@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=borntraeger@de.ibm.com \
    --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).