diff options
| author | Sergii Ushakov <sergiiushakov@google.com> | 2026-09-18 15:51:20 +0200 |
|---|---|---|
| committer | Michael S. Tsirkin <mst@redhat.com> | 2026-11-02 09:07:01 -0500 |
| commit | 434d2bc41bd0c0ac576d4d259bd9f2ab49071174 (patch) | |
| tree | 6b998baa5e6735b841a17708b67bf08553911a30 /include/linux | |
| parent | c9c1c1b7b31fc8b9a5d6c04f5f0ae647d081a39d (diff) | |
virtio-blk: clamp max_segments to virtqueue ring size
In virtblk_add_req(), each request consumes 2 extra descriptors (out_hdr
and in_hdr) in addition to the data scatter-gather segments.
When a hypervisor (e.g. QNX Hypervisor) advertises VIRTIO_BLK_F_SEG_MAX
with seg_max = 1024 alongside a 1024-entry split ring (vring.num = 1024)
and VIRTIO_RING_F_INDIRECT_DESC disabled, lim->max_segments is set to
1024. When the block layer submits requests with 1023 or 1024 data
segments, total_sg reaches 1025 or 1026. This exceeds vring.num (1024),
causing virtqueue_add_split() to return -ENOSPC and permanently wedge
the blk-mq queue.
Furthermore, the Virtio specification (2.7.5.3.1) requires that a
descriptor chain never exceed the Queue Size, and virtqueue_add_split()
falls back to direct descriptors if indirect table allocation fails.
Fix this by:
1. Rejecting queues with ring_size < 3 at probe, or
ring_size < (queue_max_segments + 2) during resume/reset recovery in
init_vq().
2. Unconditionally clamping sg_elems to (ring_size - 2) across all
virtqueues in virtblk_read_limits().
Reported-by: Stjepan Poljak <stjepan.poljak@gmail.com>
Fixes: 0864b79a1533 ("virtio: block: dynamic maximum segments")
Signed-off-by: Sergii Ushakov <sergiiushakov@google.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Message-ID: <20260918135120.1261150-1-sergiiushakov@google.com>
Diffstat (limited to 'include/linux')
0 files changed, 0 insertions, 0 deletions
