Skip to content

Commit

Permalink
thread-pool: avoid deadlock in nested aio_poll() calls
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
stefanhaRH authored and kevmw committed Aug 15, 2014
1 parent c2e50e3 commit 3c80ca1
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions thread-pool.c
Expand Up @@ -185,6 +185,12 @@ static void thread_pool_completion_bh(void *opaque)
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;
Expand Down

0 comments on commit 3c80ca1

Please sign in to comment.