From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32782) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMhAO-0004Rx-O1 for qemu-devel@nongnu.org; Wed, 27 Aug 2014 13:38:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XMhAD-0003Ka-Rz for qemu-devel@nongnu.org; Wed, 27 Aug 2014 13:37:52 -0400 Received: from e33.co.us.ibm.com ([32.97.110.151]:39825) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMhAD-0003KL-Jw for qemu-devel@nongnu.org; Wed, 27 Aug 2014 13:37:41 -0400 Received: from /spool/local by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 27 Aug 2014 11:37:41 -0600 From: Michael Roth Date: Wed, 27 Aug 2014 12:36:22 -0500 Message-Id: <1409160982-16389-26-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1409160982-16389-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1409160982-16389-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 25/25] 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: qemu-stable@nongnu.org From: Stefan Hajnoczi 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 (cherry picked from commit 3c80ca158c96ff902a30883a8933e755988948b1) Signed-off-by: Michael Roth --- 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.1