From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>, Fam Zheng <fam@euphon.net>,
qemu-devel@nongnu.org,
Emanuele Giuseppe Esposito <eesposit@redhat.com>
Subject: [PATCH 3/8] virtio_blk_process_queued_requests: always run in a bh
Date: Thu, 9 Jun 2022 10:37:22 -0400 [thread overview]
Message-ID: <20220609143727.1151816-4-eesposit@redhat.com> (raw)
In-Reply-To: <20220609143727.1151816-1-eesposit@redhat.com>
This function in virtio_blk_data_plane_start is directly
invoked, accessing the queued requests from the main loop,
while the device has already switched to the iothread context.
The only place where calling virtio_blk_process_queued_requests
from the main loop is allowed is when blk_set_aio_context fails,
and we still need to process the requests.
Since the logic of the bh is exactly the same as
virtio_blk_dma_restart, so rename the function and make it public
so that we can utilize it here too.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
hw/block/dataplane/virtio-blk.c | 10 +++++++++-
hw/block/virtio-blk.c | 4 ++--
include/hw/virtio/virtio-blk.h | 1 +
3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c
index f9224f23d2..03e10a36a4 100644
--- a/hw/block/dataplane/virtio-blk.c
+++ b/hw/block/dataplane/virtio-blk.c
@@ -234,8 +234,16 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev)
goto fail_aio_context;
}
+ blk_inc_in_flight(s->conf->conf.blk);
+ /*
+ * vblk->bh is only set in virtio_blk_dma_restart_cb, which
+ * is called only on vcpu start or stop.
+ * Therefore it must be null.
+ */
+ assert(vblk->bh == NULL);
/* Process queued requests before the ones in vring */
- virtio_blk_process_queued_requests(vblk, false);
+ vblk->bh = aio_bh_new(blk_get_aio_context(s->conf->conf.blk),
+ virtio_blk_restart_bh, vblk);
/* Kick right away to begin processing requests already in vring */
for (i = 0; i < nvqs; i++) {
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 191f75ce25..29a9c53ebc 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -855,7 +855,7 @@ void virtio_blk_process_queued_requests(VirtIOBlock *s, bool is_bh)
aio_context_release(blk_get_aio_context(s->conf.conf.blk));
}
-static void virtio_blk_dma_restart_bh(void *opaque)
+void virtio_blk_restart_bh(void *opaque)
{
VirtIOBlock *s = opaque;
@@ -882,7 +882,7 @@ static void virtio_blk_dma_restart_cb(void *opaque, bool running,
*/
if (!s->bh && !virtio_bus_ioeventfd_enabled(bus)) {
s->bh = aio_bh_new(blk_get_aio_context(s->conf.conf.blk),
- virtio_blk_dma_restart_bh, s);
+ virtio_blk_restart_bh, s);
blk_inc_in_flight(s->conf.conf.blk);
qemu_bh_schedule(s->bh);
}
diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h
index d311c57cca..c334353b5a 100644
--- a/include/hw/virtio/virtio-blk.h
+++ b/include/hw/virtio/virtio-blk.h
@@ -92,5 +92,6 @@ typedef struct MultiReqBuffer {
void virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq);
void virtio_blk_process_queued_requests(VirtIOBlock *s, bool is_bh);
+void virtio_blk_restart_bh(void *opaque);
#endif
--
2.31.1
next prev parent reply other threads:[~2022-06-09 16:03 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-09 14:37 [PATCH 0/8] virtio-blk: removal of AioContext lock Emanuele Giuseppe Esposito
2022-06-09 14:37 ` [PATCH 1/8] virtio_queue_aio_attach_host_notifier: remove " Emanuele Giuseppe Esposito
2022-07-05 14:11 ` Stefan Hajnoczi
2022-07-08 9:01 ` Emanuele Giuseppe Esposito
2022-07-12 12:47 ` Stefan Hajnoczi
2022-06-09 14:37 ` [PATCH 2/8] block-backend: enable_write_cache should be atomic Emanuele Giuseppe Esposito
2022-07-05 14:16 ` Stefan Hajnoczi
2022-06-09 14:37 ` Emanuele Giuseppe Esposito [this message]
2022-07-05 14:23 ` [PATCH 3/8] virtio_blk_process_queued_requests: always run in a bh Stefan Hajnoczi
2022-07-08 9:07 ` Emanuele Giuseppe Esposito
2022-07-12 12:18 ` Stefan Hajnoczi
2022-06-09 14:37 ` [PATCH 4/8] virtio: categorize callbacks in GS Emanuele Giuseppe Esposito
2022-06-16 16:50 ` Michael S. Tsirkin
2022-07-05 14:25 ` Stefan Hajnoczi
2022-06-09 14:37 ` [PATCH 5/8] virtio-blk: mark GLOBAL_STATE_CODE functions Emanuele Giuseppe Esposito
2022-07-05 14:27 ` Stefan Hajnoczi
2022-06-09 14:37 ` [PATCH 6/8] virtio-blk: mark IO_CODE functions Emanuele Giuseppe Esposito
2022-07-05 14:39 ` Stefan Hajnoczi
2022-07-08 9:19 ` Emanuele Giuseppe Esposito
2022-07-12 12:26 ` Stefan Hajnoczi
2022-06-09 14:37 ` [PATCH 7/8] VirtIOBlock: protect rq with its own lock Emanuele Giuseppe Esposito
2022-07-05 14:45 ` Stefan Hajnoczi
2022-07-08 9:33 ` Emanuele Giuseppe Esposito
2022-07-08 11:22 ` Emanuele Giuseppe Esposito
2022-07-12 12:34 ` Stefan Hajnoczi
2022-07-12 12:29 ` Stefan Hajnoczi
2022-06-09 14:37 ` [PATCH 8/8] virtio-blk: remove unnecessary AioContext lock from function already safe Emanuele Giuseppe Esposito
2022-07-05 14:48 ` Stefan Hajnoczi
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=20220609143727.1151816-4-eesposit@redhat.com \
--to=eesposit@redhat.com \
--cc=fam@euphon.net \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--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).