From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42279) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X73yU-0008E1-1r for qemu-devel@nongnu.org; Tue, 15 Jul 2014 10:45:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X73yL-0000Qz-35 for qemu-devel@nongnu.org; Tue, 15 Jul 2014 10:44:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:18919) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X73yK-0000Qe-Qf for qemu-devel@nongnu.org; Tue, 15 Jul 2014 10:44:48 -0400 From: Stefan Hajnoczi Date: Tue, 15 Jul 2014 16:44:26 +0200 Message-Id: <1405435466-20801-3-git-send-email-stefanha@redhat.com> In-Reply-To: <1405435466-20801-1-git-send-email-stefanha@redhat.com> References: <1405435466-20801-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PATCH v2 2/2] thread-pool: avoid deadlock in nested aio_poll() calls List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Christian Borntraeger 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 --- 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; -- 1.9.3