From mboxrd@z Thu Jan 1 00:00:00 1970 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 8E4254071FD for ; Sat, 6 Jun 2026 08:40:18 +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=1780735220; cv=none; b=GOjZO4HzW/Vy/yVZrZ5YmR4ZzaB662/sHNIUzVECOBZhD7Lqiu5wHDMQ3LjAIWtBVQ07FeT497961MIq6QhNfGCC1xOnzo1tkOJjen3ZVBsEMJck+Vg6WWhvGUKj84kabLaH9eYQQzhitjWVInPn0a78KIOSyz+owKITbUEFyMo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780735220; c=relaxed/simple; bh=rkhKQS89b50kiu4B39caolckRfcM07Ahq3gjWequ89o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UTzD7kunaYpo4wUVNPsoywH85iD5Icwh8Mc1IihitIn3LyRnLov+GxyyKZ8hLRGgnIGm5yhppGcnO+avgo7qogRhyXFckmTnyjlRu4Qp116o1IVA9BS2i4oEZ9QD3XxkilwU4oXo3ISYhTg3zUAQWi4rfQVS233rjP+Tqcm6trs= 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=K7WVlZyZ; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=nd1Lg/Th; 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="K7WVlZyZ"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="nd1Lg/Th" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780735217; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6a8D6PKyj3T42BmGkn1gN/k2Pm8r+kvs7tG5TWxDMy0=; b=K7WVlZyZYA0Oz3OMm7AyRTcA4bsuOBHwH1Km0uPZ7EogmFtvwR6h7UfyD8OihWh6HpT0cc hW4qPeKE96+jMw5fSvbewtjzc8XqwzSFb+x6S7fYPYe85aX68vY8xy0HStrmNSOA9efO1Z L5cDyve9/q0MKY8v6IcuJm/G5K7PSmc= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-672-TnGkxoXTOpqrWntsanm64Q-1; Sat, 06 Jun 2026 04:40:16 -0400 X-MC-Unique: TnGkxoXTOpqrWntsanm64Q-1 X-Mimecast-MFC-AGG-ID: TnGkxoXTOpqrWntsanm64Q_1780735215 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-490b9cd54f3so22914395e9.2 for ; Sat, 06 Jun 2026 01:40:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780735215; x=1781340015; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=6a8D6PKyj3T42BmGkn1gN/k2Pm8r+kvs7tG5TWxDMy0=; b=nd1Lg/Th4VRA1rN24GFqrT4gTMu484r2naWxluBqdunupDttAj6cCdx6kbrc56mtS2 rrdXlGpuR8V698aF77DNCoUiNQDhhigQyKw//d8+jtuPwcbKR3u9DjovAfWe6gf2rVbL PfaHdkm0t2YW1N77PJYbC+fCIeKu6qU7YgJ3E2vMOyF6XN1WJ6YFeb2tUQ60vxBJvNeZ fdDjnfuvlPioRHhlA6rkI+agAchtPrmxZwmdazfPjUls1v3LxJa21j+WmECD7/WMLOWA NikJvFMeM3jEBbGmHs66BhCUHbLUf3rqWhDZ2BvIc3X/Xp79xXrFvphaC9bvvhDt5ymG AAbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780735215; x=1781340015; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6a8D6PKyj3T42BmGkn1gN/k2Pm8r+kvs7tG5TWxDMy0=; b=XCDEBVkrj1Vz7eok36bOylxfX0MHXt/2FqeEBpC+Ree/BMMN+rP5V6K4bZ6yP9y2pO SOIoXntXZfk9PcRFA2jqG1/MeyerBZ6ymV8Dpr0X3dSlF3ENtAkIwOji9357RixkRFXH 7Q41e1k+Wi87lhPcEIFj9A9Rma3WikgSRAzaR4pFiXr77tbnyj4hzaWHxLTiBt3f9mVI JyC4XjlKV3ObcJEzCvyLemfk8qI1hN9gmw/VzbLuzkRpEXLWKhBjgA9HVdxPGY6jxBtn o/OSa26VD9AshN/QJtT6mk+CN9fjGCWPvG12DaOcgzdQVnEHBCBuHQ0B8wmeYizy8IIw CW8g== X-Forwarded-Encrypted: i=1; AFNElJ9dde7Z0OKKK/MNtcyQxv9OQG8C1EOCHjXm6N/YfPwxaYaZ+U/+J8lSS+wovvJYdfsw+8U40pou8+QcWOc=@vger.kernel.org X-Gm-Message-State: AOJu0YwJiwhzLcKGb7b291OoRSIUBFZ09fHlB4DEj9nq07OqlA1fr9ip V4QrBJQnMp2KRA/Iqf95ym7BK3MvDOSWvU/7PGyITJTyWZM4wk0R/146qKFsHaUl7OJkjtw7cZj Bx236/YKWxDrmuVMRU4w1yCWygG3w3Wh5P811JeqbKFzsQ5AlLQ8xCExDBgRw7FCyJQ== X-Gm-Gg: Acq92OHkEOHRE4HUaRYweHzptUYcDiUwO8lYNhgqAB6mHsxkyHLVqt9wuxrfQUPdZnM rPDB/XNqz2aCIRgzY+2XjEk8H9nKrKeBIatUp43uOWWoUixbdiGcddeQ79V4QqMGfsQJ9gMWIk6 7E9FCtSPwr5Y99t1voutbgrCEJXiS9idrJ2HHJSq77Wbw5yPfI8f7/siTLl8ykmBjkhppyqocOY +qqacYQOVWfWsN2zXO2jxS7MNjWDyqw87+dF0Sscmf25UYJtuVSlNYymwKDfMEIaOkbKjDOb85S m/9m7+yodx9i0BS7Dn6f6eVMtuIPj5vqMsRXuZPL7k9GbgzBlY0AZy6a+CovhKPMvgRwT727W2v lBTKWr2RiorNmj5rvLV5zZlI= X-Received: by 2002:a05:600c:628c:b0:48f:e26a:1744 with SMTP id 5b1f17b1804b1-490c25a87f5mr107060615e9.9.1780735214988; Sat, 06 Jun 2026 01:40:14 -0700 (PDT) X-Received: by 2002:a05:600c:628c:b0:48f:e26a:1744 with SMTP id 5b1f17b1804b1-490c25a87f5mr107060075e9.9.1780735214457; Sat, 06 Jun 2026 01:40:14 -0700 (PDT) Received: from redhat.com ([31.152.37.159]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490bc3e4b5asm222765095e9.13.2026.06.06.01.40.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jun 2026 01:40:13 -0700 (PDT) Date: Sat, 6 Jun 2026 04:40:09 -0400 From: "Michael S. Tsirkin" To: Samuel Moelius Cc: Jason Wang , Xuan Zhuo , Eugenio =?iso-8859-1?Q?P=E9rez?= , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "open list:VIRTIO NET DRIVER" , "open list:VIRTIO NET DRIVER" , open list Subject: Re: [PATCH] virtio_net: normalize non-positive napi_weight values Message-ID: <20260606043757-mutt-send-email-mst@kernel.org> References: <20260605194045.2625610-1-sam.moelius@trailofbits.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 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