From: Samuel Moelius <sam.moelius@trailofbits.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: "Samuel Moelius" <sam.moelius@trailofbits.com>,
"Jason Wang" <jasowang@redhat.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
netdev@vger.kernel.org (open list:VIRTIO NET DRIVER),
virtualization@lists.linux.dev (open list:VIRTIO NET DRIVER),
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] virtio_net: normalize non-positive napi_weight values
Date: Fri, 5 Jun 2026 19:40:44 +0000 [thread overview]
Message-ID: <20260605194045.2625610-1-sam.moelius@trailofbits.com> (raw)
The virtio_net.napi_weight module parameter is signed and is copied
directly into the RX NAPI weight after netif_napi_add_config().
A value of -1 lets virtnet_poll() run with a negative budget. The RX
loop processes no packets, the unsigned received-vs-budget comparison
completes NAPI, and the NAPI core reports:
NAPI poll function virtnet_poll returned 0, exceeding its budget of -1
The device then repeatedly drops receive progress under stock QEMU
virtio-net traffic.
Normalize non-positive values to the default NAPI weight before
assigning the RX and TX NAPI weights. TX NAPI can still be disabled
through the separate napi_tx parameter, which intentionally sets the TX
weight to zero.
Assisted-by: Codex:gpt-5.5-cyber-preview
Signed-off-by: Samuel Moelius <sam.moelius@trailofbits.com>
---
drivers/net/virtio_net.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index f4adcfee7a80..667026607cfa 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -6481,6 +6481,7 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
static int virtnet_alloc_queues(struct virtnet_info *vi)
{
int i;
+ int weight = napi_weight > 0 ? napi_weight : NAPI_POLL_WEIGHT;
if (vi->has_cvq) {
vi->ctrl = kzalloc_obj(*vi->ctrl);
@@ -6500,10 +6501,10 @@ static int virtnet_alloc_queues(struct virtnet_info *vi)
vi->rq[i].pages = NULL;
netif_napi_add_config(vi->dev, &vi->rq[i].napi, virtnet_poll,
i);
- vi->rq[i].napi.weight = napi_weight;
+ vi->rq[i].napi.weight = weight;
netif_napi_add_tx_weight(vi->dev, &vi->sq[i].napi,
virtnet_poll_tx,
- napi_tx ? napi_weight : 0);
+ napi_tx ? weight : 0);
sg_init_table(vi->rq[i].sg, ARRAY_SIZE(vi->rq[i].sg));
ewma_pkt_len_init(&vi->rq[i].mrg_avg_pkt_len);
--
2.43.0
reply other threads:[~2026-06-05 19:40 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260605194045.2625610-1-sam.moelius@trailofbits.com \
--to=sam.moelius@trailofbits.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=eperezma@redhat.com \
--cc=jasowang@redhat.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@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