From: Sergii Ushakov <sergiiushakov@google.com>
To: virtualization@lists.linux.dev, linux-block@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
"Michael S . Tsirkin" <mst@redhat.com>,
"Jason Wang" <jasowangio@gmail.com>,
"Jens Axboe" <axboe@kernel.dk>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Sergii Ushakov" <sergiiushakov@google.com>
Subject: [PATCH] virtio-blk: clamp max_segments when indirect descriptors are disabled
Date: Fri, 14 Aug 2026 12:59:54 +0200 [thread overview]
Message-ID: <20260814105954.4060627-1-sergiiushakov@google.com> (raw)
When VIRTIO_RING_F_INDIRECT_DESC is not negotiated by the host, every
scatter-gather segment in a request must consume a physical slot in
the virtqueue ring.
If the host does not advertise VIRTIO_BLK_F_SEG_MAX and provides a small
virtqueue (e.g. 128 descriptors on QNX Hypervisor), the block layer
defaults max_segments to BLK_MAX_SEGMENTS (1024). When a multi-page
compound bio arrives from the page cache, virtqueue_add_split() rejects
the request with -ENOSPC and triggers:
WARNING: at drivers/virtio/virtio_ring.c:1493 virtqueue_add+...
WARN_ON_ONCE(total_sg > vq->split.vring.num && !vq->indirect);
This permanently wedges the blk-mq queue and blocks all subsequent disk
I/O in uninterruptible sleep (D state).
Add a virtio_blk.max_segments module parameter to allow runtime cmdline
overrides, and automatically clamp sg_elems to
(virtqueue_get_vring_size - 2) when indirect descriptors are disabled.
Signed-off-by: Sergii Ushakov <sergiiushakov@google.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 32bf3ba07a9d..082acd90a02d 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -41,6 +41,10 @@ static unsigned int poll_queues;
module_param(poll_queues, uint, 0644);
MODULE_PARM_DESC(poll_queues, "The number of dedicated virtqueues for polling I/O");
+static unsigned int max_segments;
+module_param(max_segments, uint, 0644);
+MODULE_PARM_DESC(max_segments, "Override maximum number of segments per request");
+
static int major;
static DEFINE_IDA(vd_index_ida);
@@ -1267,6 +1271,12 @@ 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);
+ if (max_segments)
+ sg_elems = min_t(u32, sg_elems, max_segments);
+ else if (!virtio_has_feature(vdev, VIRTIO_RING_F_INDIRECT_DESC))
+ sg_elems = min_t(u32, sg_elems,
+ virtqueue_get_vring_size(vblk->vqs[0].vq) - 2);
+
/* We can handle whatever the host told us to handle. */
lim->max_segments = sg_elems;
--
2.55.0.691.gc56d675ccc-goog
next reply other threads:[~2026-08-14 11:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-14 10:59 Sergii Ushakov [this message]
2026-08-17 7:47 ` [PATCH] virtio-blk: clamp max_segments when indirect descriptors are disabled Christoph Hellwig
2026-08-17 8:08 ` Sergii Ushakov
2026-08-17 12:41 ` Michael S. Tsirkin
2026-08-17 13:42 ` [PATCH v2] " Sergii Ushakov
2026-08-17 17:28 ` Stefan Hajnoczi
2026-08-19 5:52 ` Christoph Hellwig
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=20260814105954.4060627-1-sergiiushakov@google.com \
--to=sergiiushakov@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.