From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50303) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFo9v-0004SO-QU for qemu-devel@nongnu.org; Fri, 08 Aug 2014 13:41:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XFo9o-0006jG-GN for qemu-devel@nongnu.org; Fri, 08 Aug 2014 13:40:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:62581) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFo9o-0006iy-9X for qemu-devel@nongnu.org; Fri, 08 Aug 2014 13:40:48 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s78HeltT001582 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 8 Aug 2014 13:40:47 -0400 From: Kevin Wolf Date: Fri, 8 Aug 2014 19:39:31 +0200 Message-Id: <1407519603-6635-31-git-send-email-kwolf@redhat.com> In-Reply-To: <1407519603-6635-1-git-send-email-kwolf@redhat.com> References: <1407519603-6635-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 30/62] 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: kwolf@redhat.com 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 --- 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.8.3.1