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 2/2] virtio_blk: fit max_segments to the virtqueue without indirect descriptors
Date: Sun, 1 Nov 2026 17:53:07 +0100 [thread overview]
Message-ID: <20261101165307.2557421-3-stjepan.poljak@gmail.com> (raw)
In-Reply-To: <20261101165307.2557421-1-stjepan.poljak@gmail.com>
virtblk_read_limits() takes max_segments from the device's seg_max and
only clamps it to VIRTIO_BLK_MAX_SG_ELEMS - 2, which fits the largest
virtqueue the spec allows, not the one the device has. Without
VIRTIO_RING_F_INDIRECT_DESC every segment takes a descriptor in the
ring, next to the header and the status. A device that offers a seg_max
above its queue size minus two thus lets the block layer build requests
that can never be added: virtqueue_add_split() warns that the request
is larger than the ring and returns -ENOSPC, and the hardware queue is
stopped to wait for descriptors that even an empty ring does not have.
The I/O hangs.
Seen with a device that offers seg_max 254 on a 128-entry queue without
indirect descriptors, where the boot hangs loading /sbin/init:
WARNING: drivers/virtio/virtio_ring.c:688 at virtqueue_add_split+0x6c0/0x850
...
virtqueue_add_sgs+0xd1/0x120
virtblk_add_req+0xe2/0x140
virtio_queue_rq+0x79/0x1a0
With seg_max 126 it boots, with 127 it hangs.
Without indirect descriptors, clamp max_segments to the size of the
smallest virtqueue minus two. The previous commit makes the probe fail
for a virtqueue smaller than three, so at least one segment is left.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Stjepan Poljak <stjepan.poljak@gmail.com>
---
drivers/block/virtio_blk.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 0a2af22f2365..5f05aaa079c2 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -1280,6 +1280,16 @@ static int virtblk_read_limits(struct virtio_blk *vblk,
/* Prevent integer overflows and honor max vq size */
sg_elems = min_t(u32, sg_elems, VIRTIO_BLK_MAX_SG_ELEMS - 2);
+ /*
+ * Without indirect descriptors a request takes one ring descriptor
+ * per segment, plus one for the header and one for the status, so
+ * it has to fit in the smallest of the virtqueues. A larger request
+ * would never fit and would wait for ring space forever.
+ * virtblk_probe() made sure every virtqueue holds at least three.
+ */
+ if (!virtio_has_feature(vdev, VIRTIO_RING_F_INDIRECT_DESC))
+ sg_elems = min(sg_elems, virtblk_min_vring_size(vblk) - 2);
+
/* We can handle whatever the host told us to handle. */
lim->max_segments = sg_elems;
--
2.53.0
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 " Stjepan Poljak
2026-11-01 16:53 ` [PATCH 1/2] virtio_blk: fail the probe when a virtqueue is too small for a request Stjepan Poljak
2026-11-01 16:53 ` Stjepan Poljak [this message]
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-3-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®