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 5/8] virtio-blk: mark GLOBAL_STATE_CODE functions
Date: Thu, 9 Jun 2022 10:37:24 -0400 [thread overview]
Message-ID: <20220609143727.1151816-6-eesposit@redhat.com> (raw)
In-Reply-To: <20220609143727.1151816-1-eesposit@redhat.com>
Just as done in the block API, mark functions in virtio-blk
that are always called in the main loop with BQL held.
We know such functions are GS because they all are callbacks
from virtio.c API that has already classified them as GS.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
hw/block/dataplane/virtio-blk.c | 4 ++++
hw/block/virtio-blk.c | 29 +++++++++++++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c
index 03e10a36a4..bda6b3e8de 100644
--- a/hw/block/dataplane/virtio-blk.c
+++ b/hw/block/dataplane/virtio-blk.c
@@ -89,6 +89,8 @@ bool virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf,
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
+ GLOBAL_STATE_CODE();
+
*dataplane = NULL;
if (conf->iothread) {
@@ -140,6 +142,8 @@ void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s)
{
VirtIOBlock *vblk;
+ GLOBAL_STATE_CODE();
+
if (!s) {
return;
}
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 4e6421c35e..2eb0408f92 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -51,6 +51,8 @@ static const VirtIOFeature feature_sizes[] = {
static void virtio_blk_set_config_size(VirtIOBlock *s, uint64_t host_features)
{
+ GLOBAL_STATE_CODE();
+
s->config_size = MAX(VIRTIO_BLK_CFG_SIZE,
virtio_feature_get_config_size(feature_sizes, host_features));
@@ -865,6 +867,10 @@ void virtio_blk_restart_bh(void *opaque)
virtio_blk_process_queued_requests(s, true);
}
+/*
+ * Only called when VM is started or stopped in cpus.c.
+ * No iothread runs in parallel
+ */
static void virtio_blk_dma_restart_cb(void *opaque, bool running,
RunState state)
{
@@ -872,6 +878,8 @@ static void virtio_blk_dma_restart_cb(void *opaque, bool running,
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(s)));
VirtioBusState *bus = VIRTIO_BUS(qbus);
+ GLOBAL_STATE_CODE();
+
if (!running) {
return;
}
@@ -894,8 +902,14 @@ static void virtio_blk_reset(VirtIODevice *vdev)
AioContext *ctx;
VirtIOBlockReq *req;
+ GLOBAL_STATE_CODE();
+
ctx = blk_get_aio_context(s->blk);
aio_context_acquire(ctx);
+ /*
+ * This drain together with ->stop_ioeventfd() in virtio_pci_reset()
+ * stops all Iothreads.
+ */
blk_drain(s->blk);
/* We drop queued requests after blk_drain() because blk_drain() itself can
@@ -1064,11 +1078,17 @@ static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)
}
}
+/*
+ * VM is stopped while doing migration, so iothread has
+ * no requests to process.
+ */
static void virtio_blk_save_device(VirtIODevice *vdev, QEMUFile *f)
{
VirtIOBlock *s = VIRTIO_BLK(vdev);
VirtIOBlockReq *req = s->rq;
+ GLOBAL_STATE_CODE();
+
while (req) {
qemu_put_sbyte(f, 1);
@@ -1082,11 +1102,17 @@ static void virtio_blk_save_device(VirtIODevice *vdev, QEMUFile *f)
qemu_put_sbyte(f, 0);
}
+/*
+ * VM is stopped while doing migration, so iothread has
+ * no requests to process.
+ */
static int virtio_blk_load_device(VirtIODevice *vdev, QEMUFile *f,
int version_id)
{
VirtIOBlock *s = VIRTIO_BLK(vdev);
+ GLOBAL_STATE_CODE();
+
while (qemu_get_sbyte(f)) {
unsigned nvqs = s->conf.num_queues;
unsigned vq_idx = 0;
@@ -1135,6 +1161,7 @@ static const BlockDevOps virtio_block_ops = {
.resize_cb = virtio_blk_resize,
};
+/* Iothread is not yet created */
static void virtio_blk_device_realize(DeviceState *dev, Error **errp)
{
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
@@ -1143,6 +1170,8 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)
Error *err = NULL;
unsigned i;
+ GLOBAL_STATE_CODE();
+
if (!conf->conf.blk) {
error_setg(errp, "drive property not set");
return;
--
2.31.1
next prev parent reply other threads:[~2022-06-09 15:57 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 ` [PATCH 3/8] virtio_blk_process_queued_requests: always run in a bh Emanuele Giuseppe Esposito
2022-07-05 14:23 ` 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 ` Emanuele Giuseppe Esposito [this message]
2022-07-05 14:27 ` [PATCH 5/8] virtio-blk: mark GLOBAL_STATE_CODE functions 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-6-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).