From: "Michael S. Tsirkin" <mst@redhat.com>
To: Samuel Moelius <sam.moelius@trailofbits.com>
Cc: "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>,
"open list:VIRTIO NET DRIVER" <netdev@vger.kernel.org>,
"open list:VIRTIO NET DRIVER" <virtualization@lists.linux.dev>,
"open list" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] virtio_net: normalize non-positive napi_weight values
Date: Sat, 6 Jun 2026 04:40:09 -0400 [thread overview]
Message-ID: <20260606043757-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20260605194045.2625610-1-sam.moelius@trailofbits.com>
On Fri, Jun 05, 2026 at 07:40:44PM +0000, Samuel Moelius wrote:
> 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>
Why should we bother working around admin errors in the kernel?
Leave it for the userspace tooling which can at least provide
useful diagnostics.
> ---
> 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
prev parent reply other threads:[~2026-06-06 8:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-05 19:40 [PATCH] virtio_net: normalize non-positive napi_weight values Samuel Moelius
2026-06-06 8:40 ` Michael S. Tsirkin [this message]
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=20260606043757-mutt-send-email-mst@kernel.org \
--to=mst@redhat.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=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sam.moelius@trailofbits.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.