* [PATCH] virtio_blk: freeze the virtqueue layout at probe time
@ 2026-11-02 13:37 Yunye Zhao
0 siblings, 0 replies; only message in thread
From: Yunye Zhao @ 2026-11-02 13:37 UTC (permalink / raw)
To: Michael S. Tsirkin, Jason Wang, Jens Axboe
Cc: Stefan Hajnoczi, Paolo Bonzini, Eugenio Pérez, Xuan Zhuo,
Max Gurtovoy, virtualization, linux-block, linux-kernel,
Joseph Qi, Ferry Meng
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-02 13:37 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-02 13:37 [PATCH] virtio_blk: freeze the virtqueue layout at probe time Yunye Zhao
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®