Skip to content

Commit 24b2f5d

Browse files
vivierPaolo Abeni
authored andcommitted
virtio_net: Enforce minimum TX ring size for reliability
The `tx_may_stop()` logic stops TX queues if free descriptors (`sq->vq->num_free`) fall below the threshold of (`MAX_SKB_FRAGS` + 2). If the total ring size (`ring_num`) is not strictly greater than this value, queues can become persistently stopped or stop after minimal use, severely degrading performance. A single sk_buff transmission typically requires descriptors for: - The virtio_net_hdr (1 descriptor) - The sk_buff's linear data (head) (1 descriptor) - Paged fragments (up to MAX_SKB_FRAGS descriptors) This patch enforces that the TX ring size ('ring_num') must be strictly greater than (MAX_SKB_FRAGS + 2). This ensures that the ring is always large enough to hold at least one maximally-fragmented packet plus at least one additional slot. Reported-by: Lei Yang <[email protected]> Signed-off-by: Laurent Vivier <[email protected]> Reviewed-by: Xuan Zhuo <[email protected]> Acked-by: Jason Wang <[email protected]> Link: https://patch.msgid.link/[email protected] Tested-by: Lei Yang <[email protected]> Acked-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent bd2948d commit 24b2f5d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

drivers/net/virtio_net.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3504,6 +3504,12 @@ static int virtnet_tx_resize(struct virtnet_info *vi, struct send_queue *sq,
35043504
{
35053505
int qindex, err;
35063506

3507+
if (ring_num <= MAX_SKB_FRAGS + 2) {
3508+
netdev_err(vi->dev, "tx size (%d) cannot be smaller than %d\n",
3509+
ring_num, MAX_SKB_FRAGS + 2);
3510+
return -EINVAL;
3511+
}
3512+
35073513
qindex = sq - vi->sq;
35083514

35093515
virtnet_tx_pause(vi, sq);

0 commit comments

Comments
 (0)