From: Yunye Zhao <yunye.zhao@linux.alibaba.com>
To: "Michael S. Tsirkin" <mst@redhat.com>,
Jason Wang <jasowangio@gmail.com>, Jens Axboe <axboe@kernel.dk>
Cc: "Stefan Hajnoczi" <stefanha@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"Max Gurtovoy" <mgurtovoy@nvidia.com>,
virtualization@lists.linux.dev, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org,
"Joseph Qi" <joseph.qi@linux.alibaba.com>,
"Ferry Meng" <mengferry@linux.alibaba.com>
Subject: [PATCH] virtio_blk: freeze the virtqueue layout at probe time
Date: Mon, 2 Nov 2026 21:37:40 +0800 [thread overview]
Message-ID: <20261102133740.88919-1-yunye.zhao@linux.alibaba.com> (raw)
init_vq() reads the writable num_request_queues and poll_queues module
parameters both at probe and when recreating virtqueues after suspend
or reset. However, virtio-blk does not update the blk-mq hardware queue
count or queue maps on restore.
Increasing poll_queues can therefore remove the completion callback
from a virtqueue still used for interrupt-driven I/O, leaving requests
uncompleted. Reducing the effective request queue count through
num_request_queues can instead leave existing hardware contexts
indexing beyond the reallocated vblk->vqs array.
Determine the virtqueue count and the split between interrupt-driven
and polling queues once at probe, and reuse this layout when
recreating the virtqueues. Changes to these module parameters then
affect only subsequently probed devices.
Fixes: 0989c41bed96 ("virtio-blk: add num_request_queues module parameter")
Signed-off-by: Yunye Zhao <yunye.zhao@linux.alibaba.com>
---
The functional fix was previously tested with QEMU 8.2.2 on
7be4bc52fd9e (v7.3-2415), covering:
- PCI FLR after changing poll_queues from 0 to 1 or num_request_queues
from 0 to 1 on a device with four request queues.
- Normal and polled I/O across FLR with poll_queues=1 at probe,
including a subsequent change of poll_queues to 0.
- Device suspend/resume with pm_test=devices and state=freeze (not a
full s2idle cycle), plus full S3 and S4 suspend/resume cycles.
drivers/block/virtio_blk.c | 71 +++++++++++++++++++++++++++-----------------
1 file changed, 43 insertions(+), 28 deletions(-)
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index c8bfbf8435ac..0df89f381047 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -958,42 +958,54 @@ static void virtblk_config_changed(struct virtio_device *vdev)
queue_work(virtblk_wq, &vblk->config_work);
}
+/* Keep the queue layout unchanged for the lifetime of the tag set. */
+static int virtblk_init_queue_layout(struct virtio_blk *vblk)
+{
+ struct virtio_device *vdev = vblk->vdev;
+ unsigned short num_vqs;
+ unsigned short num_poll_vqs;
+ int err;
+
+ err = virtio_cread_feature(vdev, VIRTIO_BLK_F_MQ,
+ struct virtio_blk_config, num_queues,
+ &num_vqs);
+ if (err)
+ num_vqs = 1;
+
+ if (!err && !num_vqs) {
+ dev_err(&vdev->dev, "MQ advertised but zero queues reported\n");
+ return -EINVAL;
+ }
+
+ num_vqs = blk_mq_num_possible_queues(
+ min_not_zero(num_request_queues, num_vqs));
+
+ num_poll_vqs = min_t(unsigned int, poll_queues, num_vqs - 1);
+
+ vblk->num_vqs = num_vqs;
+ vblk->io_queues[HCTX_TYPE_DEFAULT] = num_vqs - num_poll_vqs;
+ vblk->io_queues[HCTX_TYPE_READ] = 0;
+ vblk->io_queues[HCTX_TYPE_POLL] = num_poll_vqs;
+
+ dev_info(&vdev->dev, "%d/%d/%d default/read/poll queues\n",
+ vblk->io_queues[HCTX_TYPE_DEFAULT],
+ vblk->io_queues[HCTX_TYPE_READ],
+ vblk->io_queues[HCTX_TYPE_POLL]);
+
+ return 0;
+}
+
static int init_vq(struct virtio_blk *vblk)
{
int err;
unsigned short i;
struct virtqueue_info *vqs_info;
struct virtqueue **vqs;
- unsigned short num_vqs;
- unsigned short num_poll_vqs;
+ unsigned short num_vqs = vblk->num_vqs;
+ unsigned short num_poll_vqs = vblk->io_queues[HCTX_TYPE_POLL];
struct virtio_device *vdev = vblk->vdev;
struct irq_affinity desc = { 0, };
- err = virtio_cread_feature(vdev, VIRTIO_BLK_F_MQ,
- struct virtio_blk_config, num_queues,
- &num_vqs);
- if (err)
- num_vqs = 1;
-
- if (!err && !num_vqs) {
- dev_err(&vdev->dev, "MQ advertised but zero queues reported\n");
- return -EINVAL;
- }
-
- num_vqs = blk_mq_num_possible_queues(
- min_not_zero(num_request_queues, num_vqs));
-
- num_poll_vqs = min_t(unsigned int, poll_queues, num_vqs - 1);
-
- vblk->io_queues[HCTX_TYPE_DEFAULT] = num_vqs - num_poll_vqs;
- vblk->io_queues[HCTX_TYPE_READ] = 0;
- vblk->io_queues[HCTX_TYPE_POLL] = num_poll_vqs;
-
- dev_info(&vdev->dev, "%d/%d/%d default/read/poll queues\n",
- vblk->io_queues[HCTX_TYPE_DEFAULT],
- vblk->io_queues[HCTX_TYPE_READ],
- vblk->io_queues[HCTX_TYPE_POLL]);
-
vblk->vqs = kmalloc_objs(*vblk->vqs, num_vqs);
if (!vblk->vqs)
return -ENOMEM;
@@ -1025,7 +1037,6 @@ static int init_vq(struct virtio_blk *vblk)
spin_lock_init(&vblk->vqs[i].lock);
vblk->vqs[i].vq = vqs[i];
}
- vblk->num_vqs = num_vqs;
out:
kfree(vqs);
@@ -1470,6 +1481,10 @@ static int virtblk_probe(struct virtio_device *vdev)
INIT_WORK(&vblk->config_work, virtblk_config_changed_work);
+ err = virtblk_init_queue_layout(vblk);
+ if (err)
+ goto out_free_vblk;
+
err = init_vq(vblk);
if (err)
goto out_free_vblk;
base-commit: 7be4bc52fd9e0e55dc9a2e0232b89427d2c4b614
--
2.19.1.6.gb485710b
reply other threads:[~2026-11-02 13:37 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261102133740.88919-1-yunye.zhao@linux.alibaba.com \
--to=yunye.zhao@linux.alibaba.com \
--cc=axboe@kernel.dk \
--cc=eperezma@redhat.com \
--cc=jasowangio@gmail.com \
--cc=joseph.qi@linux.alibaba.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mengferry@linux.alibaba.com \
--cc=mgurtovoy@nvidia.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=stefanha@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.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
all inboxes | Powered by JetHome®