From nobody Sun Feb 8 13:24:43 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6396423D2B1 for ; Wed, 21 May 2025 09:22:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747819368; cv=none; b=ao2QpC30SgEgn+cj7bPJh6988tTvSIRXwx6KU1yoWE0QJz89U6PdFCXLt+5xidfV//fTV1OyaFMxu1fy4qquFlMx/P0yGh+jlcnPKYB0vrZ0ePdf01VO9hPGKMb+ygbu5FzEJLjthPMc9bX5XO42uH06zV7DE1LA9TR0Nz0JeeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747819368; c=relaxed/simple; bh=yk/3MKALOEYeKqVKhUIAAn8SXbS+jf00AOomxrFgLpg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ywg5mY8eOetLtrbqfoZuwNHsEIXiV7T7Y2nBFrCvqiRrEgqPTPT37RNKfPiODm4oZ04RPGnvOTHD0BX/qvTR5co1KvYitWcjTpEXNRDxYIx2UEALtftSbsRL7VPyubVIhDxnz4mfyMm4gRCx+ywf+Zi8WPP20bhuIpDYdr6hkho= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=EmShdhTr; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EmShdhTr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747819365; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=88rZqcHfyQL70LO9q5pA/dk/SVH44MpHD6BYGbaF9Sw=; b=EmShdhTry2PVgqMsmArF8/g1ac4n42SwDJzJdFTK7lltEHkDPfhxtDsIM/oHt7M6ynejuf 7HaPsjJdyXqpfTTe7fBQbBhG5m3PtZaTlYwuhHDmZp+lgQ6q1ZpvO/qlub462nnVTtZYe2 qaNjHD2dB+Ny8Qx4DUEKiYNvHHM3v+E= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-107-orLpTRb5O2K5J7NVD2KzCw-1; Wed, 21 May 2025 05:22:44 -0400 X-MC-Unique: orLpTRb5O2K5J7NVD2KzCw-1 X-Mimecast-MFC-AGG-ID: orLpTRb5O2K5J7NVD2KzCw_1747819363 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DB1201956050; Wed, 21 May 2025 09:22:42 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.44.33.64]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CC57D195608F; Wed, 21 May 2025 09:22:40 +0000 (UTC) From: Laurent Vivier To: linux-kernel@vger.kernel.org Cc: "Michael S. Tsirkin" , netdev@vger.kernel.org, Jason Wang , Xuan Zhuo Subject: [PATCH v2 1/3] virtio_ring: Fix error reporting in virtqueue_resize Date: Wed, 21 May 2025 11:22:34 +0200 Message-ID: <20250521092236.661410-2-lvivier@redhat.com> In-Reply-To: <20250521092236.661410-1-lvivier@redhat.com> References: <20250521092236.661410-1-lvivier@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Type: text/plain; charset="utf-8" The virtqueue_resize() function was not correctly propagating error codes from its internal resize helper functions, specifically virtqueue_resize_packet() and virtqueue_resize_split(). If these helpers returned an error, but the subsequent call to virtqueue_enable_after_reset() succeeded, the original error from the resize operation would be masked. Consequently, virtqueue_resize() could incorrectly report success to its caller despite an underlying resize failure. This change restores the original code behavior: if (vdev->config->enable_vq_after_reset(_vq)) return -EBUSY; return err; Fix: commit ad48d53b5b3f ("virtio_ring: separate the logic of reset/enable = from virtqueue_resize") Cc: xuanzhuo@linux.alibaba.com Signed-off-by: Laurent Vivier Acked-by: Jason Wang Acked-by: Michael S. Tsirkin Tested-by: Lei Yang --- drivers/virtio/virtio_ring.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index b784aab66867..4397392bfef0 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -2797,7 +2797,7 @@ int virtqueue_resize(struct virtqueue *_vq, u32 num, void (*recycle_done)(struct virtqueue *vq)) { struct vring_virtqueue *vq =3D to_vvq(_vq); - int err; + int err, err_reset; =20 if (num > vq->vq.num_max) return -E2BIG; @@ -2819,7 +2819,11 @@ int virtqueue_resize(struct virtqueue *_vq, u32 num, else err =3D virtqueue_resize_split(_vq, num); =20 - return virtqueue_enable_after_reset(_vq); + err_reset =3D virtqueue_enable_after_reset(_vq); + if (err_reset) + return err_reset; + + return err; } EXPORT_SYMBOL_GPL(virtqueue_resize); =20 --=20 2.49.0 From nobody Sun Feb 8 13:24:43 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB0EC240604 for ; Wed, 21 May 2025 09:22:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747819373; cv=none; b=JiKhF9Cms8pscvtyNxWG9AaFqvFJA2QyNR8wa0+iWIj51CeHnLW2mq7r8iiODi3jGSp6RIgZUhx20AIEv1sgqACrRoKDhS0v2fmEOm4+XXTNbJ5KoH73JkmoOl/weeMVb7/RTbh8zHXHEbs6z8VU3GCbKTkhp0G7IzNL9iAMohU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747819373; c=relaxed/simple; bh=VluP8qpCkS3H4WO+0xV1NzMW93mtebEWW0WnxKY06kw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EuHOAB+MMMJZbPXIHr1vmaFrS2Ucz8szs3XM+m04FafKE8naqSpx4DG+teKQ2vGxIDV4s3c6EyFUdbBe1jk0LWOcNaXJG9OWmtH/mqG9MZHoJVhQHidV3VpQET4JW6G+LFtiUVAIVTuqxbKraQoN1PCjQ4iy8s4QYQ+f+sbQ+Sk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=CX+O1uwm; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CX+O1uwm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747819369; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DCjXdTR4Wx9dhjp6rerToyVYaVci27rrR2sB2aTajX8=; b=CX+O1uwmbn9xWPzxkxiny2eenimaq/DmJjr6UjHwWsAIlOnNOQZaEP6QR84B5hVoPlZMOV Lg1KnP8owpXX89IcQzCVOvzfNm2BzUycKyYQeb6Lo+Cw7U2422BA90ucmG2YCOoIRMsrZT OXrHDV1FA+r/J3YsYQ7mmzaboOqHfLU= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-573-HUAiizX9PKqv0gXXtfkSXQ-1; Wed, 21 May 2025 05:22:46 -0400 X-MC-Unique: HUAiizX9PKqv0gXXtfkSXQ-1 X-Mimecast-MFC-AGG-ID: HUAiizX9PKqv0gXXtfkSXQ_1747819365 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 43E2C195608A; Wed, 21 May 2025 09:22:45 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.44.33.64]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 62927195608F; Wed, 21 May 2025 09:22:43 +0000 (UTC) From: Laurent Vivier To: linux-kernel@vger.kernel.org Cc: "Michael S. Tsirkin" , netdev@vger.kernel.org, Jason Wang , Xuan Zhuo Subject: [PATCH v2 2/3] virtio_net: Cleanup '2+MAX_SKB_FRAGS' Date: Wed, 21 May 2025 11:22:35 +0200 Message-ID: <20250521092236.661410-3-lvivier@redhat.com> In-Reply-To: <20250521092236.661410-1-lvivier@redhat.com> References: <20250521092236.661410-1-lvivier@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Type: text/plain; charset="utf-8" Improve consistency by using everywhere it is needed 'MAX_SKB_FRAGS + 2' rather than '2+MAX_SKB_FRAGS' or '2 + MAX_SKB_FRAGS'. No functional change. Signed-off-by: Laurent Vivier Acked-by: Jason Wang Acked-by: Michael S. Tsirkin Reviewed-by: Xuan Zhuo Tested-by: Lei Yang --- drivers/net/virtio_net.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index e53ba600605a..ff4160243538 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -1084,7 +1084,7 @@ static bool tx_may_stop(struct virtnet_info *vi, * Since most packets only take 1 or 2 ring slots, stopping the queue * early means 16 slots are typically wasted. */ - if (sq->vq->num_free < 2+MAX_SKB_FRAGS) { + if (sq->vq->num_free < MAX_SKB_FRAGS + 2) { struct netdev_queue *txq =3D netdev_get_tx_queue(dev, qnum); =20 netif_tx_stop_queue(txq); @@ -1116,7 +1116,7 @@ static void check_sq_full_and_disable(struct virtnet_= info *vi, } else if (unlikely(!virtqueue_enable_cb_delayed(sq->vq))) { /* More just got used, free them then recheck. */ free_old_xmit(sq, txq, false); - if (sq->vq->num_free >=3D 2+MAX_SKB_FRAGS) { + if (sq->vq->num_free >=3D MAX_SKB_FRAGS + 2) { netif_start_subqueue(dev, qnum); u64_stats_update_begin(&sq->stats.syncp); u64_stats_inc(&sq->stats.wake); @@ -2998,7 +2998,7 @@ static void virtnet_poll_cleantx(struct receive_queue= *rq, int budget) free_old_xmit(sq, txq, !!budget); } while (unlikely(!virtqueue_enable_cb_delayed(sq->vq))); =20 - if (sq->vq->num_free >=3D 2 + MAX_SKB_FRAGS) { + if (sq->vq->num_free >=3D MAX_SKB_FRAGS + 2) { if (netif_tx_queue_stopped(txq)) { u64_stats_update_begin(&sq->stats.syncp); u64_stats_inc(&sq->stats.wake); @@ -3195,7 +3195,7 @@ static int virtnet_poll_tx(struct napi_struct *napi, = int budget) else free_old_xmit(sq, txq, !!budget); =20 - if (sq->vq->num_free >=3D 2 + MAX_SKB_FRAGS) { + if (sq->vq->num_free >=3D MAX_SKB_FRAGS + 2) { if (netif_tx_queue_stopped(txq)) { u64_stats_update_begin(&sq->stats.syncp); u64_stats_inc(&sq->stats.wake); --=20 2.49.0 From nobody Sun Feb 8 13:24:43 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4438C241122 for ; Wed, 21 May 2025 09:22:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747819374; cv=none; b=H/ex8lKpL3hVQa5tXG7ujMj+S03H2/o3kvFVMC4v5ZKSOrkco0fQPXf8sGXtdYwueB7bcvA0AIo6FLRiDEaPDFryTKlODa20xnYyDQgwhzBfnwDjYmCIhraJ0PRmWnpEvapky+dyXSdb8OJaGPgyp8WYVVpJvDhT0Cj/QSAhPzc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747819374; c=relaxed/simple; bh=jlqjkVr9S+fhQc/GQZSnUfDxqzxMGUWnuuXyXkSebJo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TllogfiKwd0+9StbFh/st6InKNcwS/8q6thzNZ1gt8CnTuYQUIk08LP7Yierd4azbvMt3w3+YDeaL3HomkhlsSUzFdRiKzHmqfUlAg2Aa+CU7OHT0n63WLu9bNb4nDL9Jc0+SZWoR3ppbj/vk91P1rx95i9TLyx4A163jF5+JNQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=g6i7xHhf; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="g6i7xHhf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747819372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S01OyqRbOfmEw1jQdPVa38jcFNsvoKjej6vSXSbTUcg=; b=g6i7xHhf2QICun4CJ8U5E9+QWMs4hqL2OokmRB3+99L4z/7FM0Cdqheh/qczP9mRhAuI2S cdOv5VsSHaQ2J9uc2UGSVAb4cnrOpu2Ge/N37McWEzigJtZrDUrDRd+d6YTq8w5Fxpka2H W/nzVF/vosgA11v8D9oONzvuGYImGQY= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-32-cPZKKRWmO-W7Nf7TD4DkwA-1; Wed, 21 May 2025 05:22:48 -0400 X-MC-Unique: cPZKKRWmO-W7Nf7TD4DkwA-1 X-Mimecast-MFC-AGG-ID: cPZKKRWmO-W7Nf7TD4DkwA_1747819367 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A52161954B17; Wed, 21 May 2025 09:22:47 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.44.33.64]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BEE8C1956096; Wed, 21 May 2025 09:22:45 +0000 (UTC) From: Laurent Vivier To: linux-kernel@vger.kernel.org Cc: "Michael S. Tsirkin" , netdev@vger.kernel.org, Jason Wang , Xuan Zhuo Subject: [PATCH v2 3/3] virtio_net: Enforce minimum TX ring size for reliability Date: Wed, 21 May 2025 11:22:36 +0200 Message-ID: <20250521092236.661410-4-lvivier@redhat.com> In-Reply-To: <20250521092236.661410-1-lvivier@redhat.com> References: <20250521092236.661410-1-lvivier@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Laurent Vivier Acked-by: Jason Wang Acked-by: Michael S. Tsirkin Reviewed-by: Xuan Zhuo Tested-by: Lei Yang --- drivers/net/virtio_net.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index ff4160243538..50b851834ae2 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -3481,6 +3481,12 @@ static int virtnet_tx_resize(struct virtnet_info *vi= , struct send_queue *sq, { int qindex, err; =20 + if (ring_num <=3D MAX_SKB_FRAGS + 2) { + netdev_err(vi->dev, "tx size (%d) cannot be smaller than %d\n", + ring_num, MAX_SKB_FRAGS + 2); + return -EINVAL; + } + qindex =3D sq - vi->sq; =20 virtnet_tx_pause(vi, sq); --=20 2.49.0