From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54829) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1Hvb-0002Tn-11 for qemu-devel@nongnu.org; Tue, 24 Nov 2015 13:03:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1Hva-0006Ap-8R for qemu-devel@nongnu.org; Tue, 24 Nov 2015 13:02:54 -0500 From: Paolo Bonzini Date: Tue, 24 Nov 2015 19:01:31 +0100 Message-Id: <1448388091-117282-41-git-send-email-pbonzini@redhat.com> In-Reply-To: <1448388091-117282-1-git-send-email-pbonzini@redhat.com> References: <1448388091-117282-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 40/40] dma-helpers: avoid lock inversion with AioContext List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, qemu-block@nongnu.org Signed-off-by: Paolo Bonzini --- dma-helpers.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/dma-helpers.c b/dma-helpers.c index 68f6f07..b3e19ba 100644 --- a/dma-helpers.c +++ b/dma-helpers.c @@ -210,9 +210,25 @@ BlockAIOCB *dma_blk_io( dbs->sg_cur_byte = 0; dbs->dir = dir; dbs->io_func = io_func; - dbs->bh = NULL; qemu_iovec_init(&dbs->iov, sg->nsg); - dma_blk_cb(dbs, 0); + + /* FIXME: dma_blk_io usually is called while the thread has acquired the + * AioContext, for consistency with blk_aio_readv. However, dma_memory_map + * may acquire the iothread lock and thus requires being called with _no_ lock. + * + * The solution would be to call dma_blk_io without the AioContext lock, + * but this requires changes in the core block and SCSI layers. In the + * interest of doing things a step at a time, defer to a bottom half + * if the iothread lock isn't taken. The bottom half is called without + * the AioContext lock taken. + */ + if (qemu_mutex_iothread_locked()) { + dbs->bh = NULL; + dma_blk_cb(dbs, 0); + } else { + dbs->bh = aio_bh_new(dbs->ctx, reschedule_dma, dbs); + qemu_bh_schedule(dbs->bh); + } return &dbs->common; } -- 1.8.3.1