From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43327) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alzqT-0005ek-WD for qemu-devel@nongnu.org; Fri, 01 Apr 2016 10:14:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1alzqT-00072a-0n for qemu-devel@nongnu.org; Fri, 01 Apr 2016 10:14:41 -0400 References: <1459519058-29864-1-git-send-email-famz@redhat.com> From: Laurent Vivier Message-ID: <56FE8248.9090404@redhat.com> Date: Fri, 1 Apr 2016 16:14:32 +0200 MIME-Version: 1.0 In-Reply-To: <1459519058-29864-1-git-send-email-famz@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2] block: Fix bdrv_drain in coroutine List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng , qemu-devel@nongnu.org Cc: Kevin Wolf , pbonzini@redhat.com, qemu-block@nongnu.org, Stefan Hajnoczi On 01/04/2016 15:57, Fam Zheng wrote: > Using the nested aio_poll() in coroutine is a bad idea. This patch > replaces the aio_poll loop in bdrv_drain with a BH, if called in > coroutine. > > For example, the bdrv_drain() in mirror.c can hang when a guest issued > request is pending on it in qemu_co_mutex_lock(). > > Mirror coroutine in this case has just finished a request, and the block > job is about to complete. It calls bdrv_drain() which waits for the > other coroutine to complete. The other coroutine is a scsi-disk request. > The deadlock happens when the latter is in turn pending on the former to > yield/terminate, in qemu_co_mutex_lock(). The state flow is as below > (assuming a qcow2 image): > > mirror coroutine scsi-disk coroutine > ------------------------------------------------------------- > do last write > > qcow2:qemu_co_mutex_lock() > ... > scsi disk read > > tracked request begin > > qcow2:qemu_co_mutex_lock.enter > > qcow2:qemu_co_mutex_unlock() > > bdrv_drain > while (has tracked request) > aio_poll() > > In the scsi-disk coroutine, the qemu_co_mutex_lock() will never return > because the mirror coroutine is blocked in the aio_poll(blocking=true). > > With this patch, the added qemu_coroutine_yield() allows the scsi-disk > coroutine to make progress as expected: > > mirror coroutine scsi-disk coroutine > ------------------------------------------------------------- > do last write > > qcow2:qemu_co_mutex_lock() > ... > scsi disk read > > tracked request begin > > qcow2:qemu_co_mutex_lock.enter > > qcow2:qemu_co_mutex_unlock() > > bdrv_drain.enter >> schedule BH >> qemu_coroutine_yield() >> qcow2:qemu_co_mutex_lock.return >> ... > tracked request end > ... > (resumed from BH callback) > bdrv_drain.return > ... > > Reported-by: Laurent Vivier > Suggested-by: Paolo Bonzini > Signed-off-by: Fam Zheng Tested-by: Laurent Vivier