From: Stjepan Poljak <stjepan.poljak@gmail.com>
To: "Michael S. Tsirkin" <mst@redhat.com>,
Jason Wang <jasowangio@gmail.com>, Jens Axboe <axboe@kernel.dk>
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
virtualization@lists.linux.dev, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] virtio_blk: fail the probe when a virtqueue is too small for a request
Date: Sun, 1 Nov 2026 17:53:06 +0100 [thread overview]
Message-ID: <20261101165307.2557421-2-stjepan.poljak@gmail.com> (raw)
In-Reply-To: <20261101165307.2557421-1-stjepan.poljak@gmail.com>
Without VIRTIO_RING_F_INDIRECT_DESC a request takes at least three ring
descriptors: the header, one segment and the status. Nothing checks
that the virtqueues hold that many, and a smaller one fails in a way
that depends on the queue depth. With the default depth, num_free / 2,
a virtqueue of one descriptor gives a depth of 0, which
blk_mq_alloc_tag_set() refuses, and the probe fails without saying why:
virtio_blk virtio0: probe with driver virtio_blk failed with error -22
With a depth of at least one, from a virtqueue of two or from
virtio_blk.queue_depth, the probe succeeds and the first request never
fits: virtqueue_add_split() warns and returns -ENOSPC, and the hardware
queue is stopped to wait for descriptors that even an empty ring does
not have.
Check the virtqueue sizes right after the virtqueues are set up, before
the queue depth is derived from them, and fail the probe with a reason
when the smallest one cannot hold a request:
virtio_blk virtio0: virtqueue size 1 is too small for a request
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Stjepan Poljak <stjepan.poljak@gmail.com>
---
drivers/block/virtio_blk.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index c8bfbf8435ac..0a2af22f2365 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -1244,6 +1244,18 @@ static const struct blk_mq_ops virtio_mq_ops = {
static unsigned int virtblk_queue_depth;
module_param_named(queue_depth, virtblk_queue_depth, uint, 0444);
+/* The size of the smallest virtqueue, which every request has to fit. */
+static unsigned int virtblk_min_vring_size(struct virtio_blk *vblk)
+{
+ unsigned int vring_size = UINT_MAX;
+ int i;
+
+ for (i = 0; i < vblk->num_vqs; i++)
+ vring_size = min(vring_size,
+ virtqueue_get_vring_size(vblk->vqs[i].vq));
+ return vring_size;
+}
+
static int virtblk_read_limits(struct virtio_blk *vblk,
struct queue_limits *lim)
{
@@ -1474,6 +1486,21 @@ static int virtblk_probe(struct virtio_device *vdev)
if (err)
goto out_free_vblk;
+ /*
+ * Without indirect descriptors the smallest request, a header, one
+ * segment and the status, takes three descriptors. Check before the
+ * queue depth is derived from the ring, which would come out as 0
+ * for a ring of one and fail without saying why.
+ */
+ if (!virtio_has_feature(vdev, VIRTIO_RING_F_INDIRECT_DESC) &&
+ virtblk_min_vring_size(vblk) < 3) {
+ dev_err(&vdev->dev,
+ "virtqueue size %u is too small for a request\n",
+ virtblk_min_vring_size(vblk));
+ err = -EINVAL;
+ goto out_free_vq;
+ }
+
/* Default queue sizing is to fill the ring. */
if (!virtblk_queue_depth) {
queue_depth = vblk->vqs[0].vq->num_free;
--
2.53.0
next prev parent reply other threads:[~2026-11-01 16:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-01 16:53 [PATCH 0/2] virtio_blk: fit requests to virtqueues without indirect descriptors Stjepan Poljak
2026-11-01 16:53 ` Stjepan Poljak [this message]
2026-11-01 16:53 ` [PATCH 2/2] virtio_blk: fit max_segments to the virtqueue " Stjepan Poljak
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=20261101165307.2557421-2-stjepan.poljak@gmail.com \
--to=stjepan.poljak@gmail.com \
--cc=axboe@kernel.dk \
--cc=eperezma@redhat.com \
--cc=jasowangio@gmail.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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®