qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Lukáš Doktor" <ldoktor@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>, qemu-devel@nongnu.org
Cc: "Hanna Reitz" <hreitz@redhat.com>,
	qemu-block@nongnu.org, "Kevin Wolf" <kwolf@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Fam Zheng" <fam@euphon.net>
Subject: Re: [PATCH] block/nvme: invoke blk_io_plug_call() outside q->lock
Date: Mon, 17 Jul 2023 12:38:42 +0200	[thread overview]
Message-ID: <b0fd9e8b-445d-6301-bb38-f93cbe0abda1@redhat.com> (raw)
In-Reply-To: <20230712191628.252806-1-stefanha@redhat.com>


[-- Attachment #1.1.1: Type: text/plain, Size: 2247 bytes --]

Thank you, Stefan, I tested this one as well and it boots now and seems to behave correctly under the load as well.

Regards,
Lukáš

Tested-by: Lukas Doktor <ldoktor@redhat.com>

Dne 12. 07. 23 v 21:16 Stefan Hajnoczi napsal(a):
> 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.
> 
> Reported-by: Lukáš Doktor <ldoktor@redhat.com>
> Fixes: f2e590002bd6 ("block/nvme: convert to blk_io_plug_call() API")
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  block/nvme.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/block/nvme.c b/block/nvme.c
> index 7ca85bc44a..b6e95f0b7e 100644
> --- a/block/nvme.c
> +++ b/block/nvme.c
> @@ -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)

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 12925 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

      reply	other threads:[~2023-07-17 10:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-12 19:16 [PATCH] block/nvme: invoke blk_io_plug_call() outside q->lock Stefan Hajnoczi
2023-07-17 10:38 ` Lukáš Doktor [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b0fd9e8b-445d-6301-bb38-f93cbe0abda1@redhat.com \
    --to=ldoktor@redhat.com \
    --cc=fam@euphon.net \
    --cc=hreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).