Block patches
The following changes since commit ed8ad9728a9c0eec34db9dff61dfa2f1dd625637:
Merge tag 'pull-tpm-2023-07-14-1' of https://github.com/stefanberger/qemu-tpm into staging (2023-07-15 14:54:04 +0100)
are available in the Git repository at:
https://gitlab.com/stefanha/qemu.git tags/block-pull-request
for you to fetch changes up to 66547f416a61e0cb711dc76821890242432ba193:
block/nvme: invoke blk_io_plug_call() outside q->lock (2023-07-17 09:17:41 -0400)
----------------------------------------------------------------
Pull request
Fix the hang in the nvme:// block driver during startup.
----------------------------------------------------------------
Stefan Hajnoczi (1):
block/nvme: invoke blk_io_plug_call() outside q->lock
block/nvme.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Signature · 1 line
2.40.1
[PULL for-8.1 1/1] block/nvme: invoke blk_io_plug_call() outside q->lock
blk_io_plug_call() is invoked outside a blk_io_plug()/blk_io_unplug() section while opening the NVMe drive from:
nvme_file_open() ->
nvme_init() ->
nvme_identify() ->
nvme_admin_cmd_sync() ->
nvme_submit_command() ->
blk_io_plug_call()
blk_io_plug_call() immediately invokes the given callback when the current thread is not plugged, as is the case during nvme_file_open().
Unfortunately, nvme_submit_command() calls blk_io_plug_call() with q->lock still held:
...
q->sq.tail = (q->sq.tail + 1) % NVME_QUEUE_SIZE;
q->need_kick++;
blk_io_plug_call(nvme_unplug_fn, q);
qemu_mutex_unlock(&q->lock);
^^^^^^^^^^^^^^^^^^^^^^^^^^^nvme_unplug_fn() deadlocks trying to acquire q->lock because the lock is already acquired by the same thread. The symptom is that QEMU hangs during startup while opening the NVMe drive.
Fix this by moving the blk_io_plug_call() outside q->lock. This is safe because no other thread runs code related to this queue and blk_io_plug_call()'s internal state is immune to thread safety issues since it is thread-local.
Message-id: [email protected]
--- block/nvme.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
block/nvme.c +2 -1
@@ -501,8 +501,9 @@ static void nvme_submit_command(NVMeQueuePair *q, NVMeRequest *req, q->sq.tail * NVME_SQ_ENTRY_BYTES, cmd, sizeof(*cmd)); q->sq.tail = (q->sq.tail +1 ) %NVME_QUEUE_SIZE ; q->need_kick++; +qemu_mutex_unlock (&q->lock); +blk_io_plug_call (nvme_unplug_fn, q); -qemu_mutex_unlock (&q->lock); }static void nvme_admin_cmd_sync_cb (void *opaque,int ret)
Signature · 1 line
2.40.1
Richard Henderson
AppliedQuoted 8 lines · Stefan Hajnoczi
The following changes since commit
ed8ad9728a9c0eec34db9dff61dfa2f1dd625637:Merge tag 'pull-tpm-2023-07-14-1' ofhttps://github.com/stefanberger/qemu-tpm into staging (2023-07-15 14:54:04 +0100)are available in the Git repository at:
https://gitlab.com/stefanha/qemu.git tags/block-pull-request
Quoted 8 lines
for you to fetch changes up to
66547f416a61e0cb711dc76821890242432ba193:block/nvme: invoke blk_io_plug_call() outside q->lock (2023-07-17 09:17:41 -0400)----------------------------------------------------------------
Pull requestFix the hang in the nvme:// block driver during startup.
Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/8.1 as appropriate.
r~