[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH 40/40] dma-helpers: avoid lock inversion with AioCon
From: |
Paolo Bonzini |
Subject: |
[Qemu-block] [PATCH 40/40] dma-helpers: avoid lock inversion with AioContext |
Date: |
Tue, 24 Nov 2015 19:01:31 +0100 |
Signed-off-by: Paolo Bonzini <address@hidden>
---
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
- [Qemu-block] [PATCH 30/40] quorum: split quorum_fifo_aio_cb from quorum_aio_cb, (continued)
- [Qemu-block] [PATCH 30/40] quorum: split quorum_fifo_aio_cb from quorum_aio_cb, Paolo Bonzini, 2015/11/24
- [Qemu-block] [PATCH 28/40] aio: push aio_context_acquire/release down to dispatching, Paolo Bonzini, 2015/11/24
- [Qemu-block] [PATCH 31/40] qed: introduce qed_aio_start_io and qed_aio_next_io_cb, Paolo Bonzini, 2015/11/24
- [Qemu-block] [PATCH 34/40] block: explicitly acquire aiocontext in timers that need it, Paolo Bonzini, 2015/11/24
- [Qemu-block] [PATCH 33/40] block: explicitly acquire aiocontext in bottom halves that need it, Paolo Bonzini, 2015/11/24
- [Qemu-block] [PATCH 32/40] block: explicitly acquire aiocontext in callbacks that need it, Paolo Bonzini, 2015/11/24
- [Qemu-block] [PATCH 37/40] async: optimize aio_bh_poll, Paolo Bonzini, 2015/11/24
- [Qemu-block] [PATCH 36/40] aio: update locking documentation, Paolo Bonzini, 2015/11/24
- [Qemu-block] [PATCH 35/40] block: explicitly acquire aiocontext in aio callbacks that need it, Paolo Bonzini, 2015/11/24
- [Qemu-block] [PATCH 38/40] aio-posix: partially inline aio_dispatch into aio_poll, Paolo Bonzini, 2015/11/24
- [Qemu-block] [PATCH 40/40] dma-helpers: avoid lock inversion with AioContext,
Paolo Bonzini <=
- [Qemu-block] [PATCH 39/40] async: remove unnecessary inc/dec pairs, Paolo Bonzini, 2015/11/24
- Re: [Qemu-block] [Qemu-devel] [RFC PATCH 00/40] Sneak peek of virtio and dataplane changes for 2.6, Christian Borntraeger, 2015/11/26