🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #25082

Re: [PATCH net-next v2 1/3] net: libwx: preserve queue stats across reconfiguration

#25082
From: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 08:36
182 lines
15198 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 2

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] wx_get_stats64()
  (drivers/net/ethernet/wangxun/libwx/wx_lib.c:3147-3148) reads…
- [Low] The new TX stop counter and the existing wake counter do not
  count the same events, so wake can be larger than stop.
- [Low] This feature patch also carries an unannounced fix for an
  existing bug.

--

net: libwx: preserve queue stats across reconfiguration

When queue vectors are freed, this patch keeps the per-ring packet, byte
and error counters in new qstats_base_* accumulators, protected by
hw_stats_lock. It also splits the ring u64_stats_sync into napi_syncp and
xmit_syncp, initializes both, and moves the rx/tx error counters under the
seqcounts. A new stop_queue counter is added next to restart_queue, and
the pair is reported as retained stop/wake counters.

> diff --git a/drivers/net/ethernet/wangxun/libwx/wx_lib.c b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
> index 10f095fb7085c..2868232792588 100644
> --- a/drivers/net/ethernet/wangxun/libwx/wx_lib.c
> +++ b/drivers/net/ethernet/wangxun/libwx/wx_lib.c

[ ... ]

> @@ -1021,12 +1039,18 @@ static int wx_maybe_stop_tx(struct wx_ring *tx_ring, u16 size)
>  	/* We need to check again in a case another CPU has just
>  	 * made room available.
>  	 */
> -	if (likely(wx_desc_unused(tx_ring) < size))
> +	if (likely(wx_desc_unused(tx_ring) < size)) {
> +		u64_stats_update_begin(&tx_ring->xmit_syncp);
> +		++tx_ring->tx_stats.stop_queue;
> +		u64_stats_update_end(&tx_ring->xmit_syncp);
>  		return -EBUSY;
> +	}
>  
>  	/* A reprieve! - use start_queue because it doesn't call schedule */
>  	netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
> +	u64_stats_update_begin(&tx_ring->xmit_syncp);
>  	++tx_ring->tx_stats.restart_queue;
> +	u64_stats_update_end(&tx_ring->xmit_syncp);
>  
>  	return 0;
>  }

[Severity: Low]
Can tx wake end up larger than tx stop here?

On the reprieve path, netif_stop_subqueue() has already stopped the queue
because the ring was full, and netif_start_subqueue() restarts it. That
increments restart_queue but not stop_queue. wx_ring_get_tx_stats() then
reports:

    stats->tx.stop = ring->tx_stats.stop_queue;
    stats->tx.wake = ring->tx_stats.restart_queue +
                     restart_queue_napi;

wx_free_q_vector() folds both values into qstats_base_tx_stats, so each
reprieve adds a wake with no matching stop.

The comment on struct wx_tx_retained_stats says these counters are "named
after what netdev-genl reports". The later patch "net: wangxun: expose
queue stats via netdev-genl" reports them as tx-stop and tx-wake through
wx_get_queue_stats_tx() and wx_get_base_stats(). netdev.yaml defines
tx-stop as the number of times the driver paused accepting new tx packets
because the queue was full, and the reprieve path does pause the queue.

Other drivers that use netif_subqueue_maybe_stop(), such as fbnic, count
neither a stop nor a wake for the reprieve result, so the two counters
stay paired.

The commit message states "the reprieve path only adds a wake". Should the
reprieve either count a stop as well, or not be counted as a wake?

[ ... ]

> @@ -2182,6 +2208,8 @@ static int wx_alloc_q_vector(struct wx *wx,
>  
>  		/* apply Tx specific ring traits */
>  		ring->count = wx->tx_ring_count;
> +		u64_stats_init(&ring->napi_syncp);
> +		u64_stats_init(&ring->xmit_syncp);
>  
>  		ring->queue_index = txr_idx;
>  		ring->reg_idx = wx_get_reg_idx(wx, txr_idx, false);

[Severity: Low]
This isn't a regression, but these u64_stats_init() calls, and the one
added for RX rings, seem to also fix an existing bug.

Before this patch, ring->syncp was never initialized. The rings come from
kzalloc_flex() in wx_alloc_q_vector(), and there is no u64_stats_init()
anywhere under drivers/net/ethernet/wangxun at the baseline.

On 32-bit SMP kernels with CONFIG_DEBUG_LOCK_ALLOC, the first
u64_stats_update_begin(&ring->syncp) in wx_clean_rx_irq() or
wx_clean_tx_irq() runs seqcount_acquire() on a zeroed lockdep_map. That
prints "INFO: trying to register non-static key" and turns lockdep off.

The baseline also updated the 64-bit rx_stats/tx_stats counters
(non_eop_descs, csum_err, csum_good_cnt, alloc_rx_buff_failed, rsc_*,
restart_queue, tx_busy) outside any syncp section. wx_update_stats() read
them without fetch_begin/retry, so 32-bit readers could see torn values.

Could the initialization and the move under the seqcount go into a
separate patch with a Fixes: tag? That would let them go to net and
stable instead of riding along with this feature change.

[ ... ]

> @@ -3087,39 +3146,42 @@ void wx_get_stats64(struct net_device *netdev,
>  
>  	num_rx_queues = READ_ONCE(wx->num_rx_queues);
>  	num_tx_queues = READ_ONCE(wx->num_tx_queues);
> +	/* Pair with kfree_rcu() in wx_free_q_vector(). */
>  	rcu_read_lock();
> +	/* wx_free_q_vector() folds a ring into the base values under the same
> +	 * lock, so the snapshot cannot mix a ring with its retained value.
> +	 * The lock has to span the ring walk: the base values are read after
> +	 * it, and a ring folded in between would be counted twice.
> +	 */
> +	spin_lock(&wx->hw_stats_lock);

[Severity: Medium]
Can the queue counts read here be stale by the time hw_stats_lock is
taken?

num_rx_queues and num_tx_queues are read before the lock. The ring walk
and the qstats_base_* values are only consistent under the lock. The new
counts and ring pointers are also published without hw_stats_lock:
wx_set_num_queues() sets the counts, then wx_alloc_q_vector() calls
rcu_assign_pointer().

Consider a /proc/net/dev reader, which holds only RCU and not RTNL:

CPU1
wx_get_stats64()
    num_tx_queues = READ_ONCE(wx->num_tx_queues);   /* 4 */
    <preempted>

CPU2 (ethtool -L 8 under RTNL)
wx_clear_interrupt_scheme()
    wx_free_q_vectors()      /* folds rings 0..3 into qstats_base_* */
wx_init_interrupt_scheme()
    wx_set_num_queues()      /* 8 */
    wx_alloc_q_vectors()     /* publishes rings 0..7 */
open, traffic flows on rings 4..7

CPU1 resumes
    spin_lock(&wx->hw_stats_lock);
    walks only i < 4, then adds the full qstats_base_*

The reader leaves out the live counters of rings 4..7. Its rx/tx packets
and bytes can then be lower than an earlier snapshot. The same happens if
CPU1 reads 0 just after wx_free_q_vectors().

The commit message says the ordering "keeps base plus live rings
invariant at every instant" and that "a reader which pairs the counts
with the base values cannot skip a ring". wx_get_stats64() is unchanged
later in the series.

wx_update_stats() already reads the counts after spin_lock(). Would moving
these two READ_ONCE() calls after spin_lock(&wx->hw_stats_lock) be enough
to make wx_get_stats64() match that claim?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130083407.78429-1-mengyuanlou%40net-swift.com
Technical Details
Message-ID: <179611418308.3146.8210544015669457449@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374849-linux-kernel-netdev=dewy.ru
References: <20261130083407.78429-2-mengyuanlou@net-swift.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374849-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v2 1/3] net: libwx: preserve queue stats across
 reconfiguration
Date: Tue, 01 Dec 2026 08:36:23 +0000
Organization: Usenet Network
Message-ID: <179611418308.3146.8210544015669457449@kernel.org>
References: <20261130083407.78429-2-mengyuanlou@net-swift.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1660865"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:6J9Lkf9crLXvdNnKNz1N2JB1yHk= sha256:0YkkvYV8T/AcUvOzI0eEvGEGrHE3cNiuVe6/BkUpuzQ=
	sha1:cUuB6hnmAxzhC2ViZ6gU8iQiboc= sha256:9rfHnOd6vbQwZvQFFqhIL4O2RSRDfd8PwWNgivH3M4w=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id D8E0E1172D0; Tue,  1 Dec 2026 11:36:42 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id xI7zfyUPEcDj;
	Tue,  1 Dec 2026 11:36:39 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-374849-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 998071172CC; Tue,  1 Dec 2026 11:36:29 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id B253831A1C; Tue,  1 Dec 2026 08:36:26 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796114185;
	b=dH4ZwKPI5zxS5LnPEM5mZ4dTiU3ZzTLl1++f7JjPFIfDY/F1n4dfEGlLndi4L3f+PeOq
	 tgFyRyRhH5tKwn8soTHH7M3JN3fmnerV9DxVuq2GtGrxdzuABB2CiVuCq72Zt2EMcVs1D
	 jOuWkBC/rfTYzVfHE2YUPwU17Cq4tkoe3irYWQ4KqiwOnDwuw+a2vF7UyBP67gIpHtmq/
	 f6PNHcCZipgMI4dqmNMfBY1FXWAhDNB52TiC3NenIcJhAJ+T5vsKzcZvTRGCP1BaeLBi9
	 nUohTdQpWIf+V9c3qBT9sIKRnNA1kq1xlszRLElXnBjRKGqu8Y7Fq3iyaJHZYT6g5GA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796114185;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=rjaz9jv7zKw7NwZsOb03boUNoD7hAlufdPhpVO0NzF0=;
	b=mpTyVoUeDVQKMBvmd0HDT/MtkOIWvP/LKi0D28TFXBNf7g8P/YIKnUoIhQn5r6V3DBW9
	 UWMGSA3ZxV4usY239HYmku5lop97L4XlOiG9XuVN+Feqiv+EMO/H1x1ITCbALrfNw+KBk
	 pYJwK9Z6An57Lp21AVtAN3LZZPPLzLFHDZFCyqPjf7ec9+5v7chJYjJobxWMK1vmoUz9u
	 EjKIIGSjRTL+8RDCWPWsR5pAZQgN9oLt1VWD1jdA/SitoHnWKq/MVlcGU0V3CpQoZV/al
	 SxvgratoXxTlYzeY88fvIAmr6J/GOv4Yx3oRmP+P+h4TUHQBSUKiIBDDgGgwRv5TTTg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KUVgPgKy;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id BB838606A32C;
	Tue,  1 Dec 2026 08:36:25 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KUVgPgKy
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796114184;
	b=3/TAJFX6tXr7keBZWjcZMiHBf+1cF2xwYtFstn7YvM7eUl+GHiK5CRje9ZVVgsTK54ed
	 UsCgnImOaYIG9mtGOYyKHHiz8M6pyc4cUjq0OTuv3yfAP8hOU06D+5UStkWZCTs8/gtGQ
	 SKZ14VfGOfnxcS62+z89Pi4w9lHGfrH/d4UJSDokoKMHiKsCKbMGTiiCSGBhyhzJXqvN0
	 hOFf3ffUfrv5n9ADW2bjNTUyz+g/GqIsO9UKWSseFCj3XlNewiD1pGkOcxfV5/GD6KAyM
	 MiT8ABh3mYtTofTW5003mz1Fig1dTSBVRnNgr2Jjt0euwvvWrliREMIzNDSG1UGEmwA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796114184;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=rjaz9jv7zKw7NwZsOb03boUNoD7hAlufdPhpVO0NzF0=;
	b=SRs60z1l3n703siWKZ5g/eL0zJBrR4G4KcCn/5hfHE+xJKwJEztx5lNqsDvHUEGzlCnK
	 FOEbv6C1WodDnUHbgQ0wNuOzkBk6Z0tX4X3/psfUlLPbgO16mwZWWWIJ18P7HNReCjvgO
	 Ty4g0GkeQluItx2qcOVc64fH/9/hmBNdjw0HTWF4sZPd0Jz4ntu7xoqZfEfto4zn9Smak
	 CKo7bUNUP8tRnt5fYjYrpNemiJHLMzP0IK3mg3Z12PUqlfUCGCyQB9TEoVrZGXoaJGb5x
	 k3fuhcPJ6k4VbtrVZsmyYF3pCPxeP69MURu+wNdGPsZpOOW0TsyAyI4C78SovQ17JqA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KUVgPgKy;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id D63CB606A31A
	for <netdev@vger.kernel.org>; Tue,  1 Dec 2026 08:36:24 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A8141F00893;
	Tue,  1 Dec 2026 08:36:23 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796114184;
	bh=rjaz9jv7zKw7NwZsOb03boUNoD7hAlufdPhpVO0NzF0=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=KUVgPgKy6NIBGXdMa0SfXh3MxCWGZdREYN6KWfPlLeVm4fSCbeD9we9nUHccvp/6E
	 eVIE9hjYO1mGakojiIA6DwesMyi35J9aGWqFIxvwngP72+OYHZhvFc+ZwEIDnhLgn5
	 EIRp4jB7j7B6Ll3ZBbYv5hpVIfmV4S8ByhAmZhPdb0t7B90Fjkp7lgyZGFitPGZ0Zt
	 3TaHRLbIvBZhWBtB13/O6H+Q/7t4URq++srToRe8xciPf0hA6iLhCRu2/1bBhu6Rfc
	 8sgoWIlxMk+wabxRFceSGKXsecEPthTBoDwW9gd0vGbtqhpxLOzIJ7xNBes0L4X3Qo
	 mFDR6Wpl+8V/g==
X-Cc: netdev@vger.kernel.org, jiawenwu@trustnetic.com,
 duanqiangwen@net-swift.com, linglingzhang@net-swift.com,
 andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
 kuba@kernel.org, pabeni@redhat.com
X-In-Reply-To: <20261130083407.78429-2-mengyuanlou@net-swift.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list