> 2026年12月1日 16:36,netd…@kernel.org 写道:
>
> 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?
>
Reading num_rx_queues and num_tx_queues before taking hw_stats_lock indeed allows
a preempted reader to walk rings with stale counts after a queue reconfiguration and fold.
I'll move both READ_ONCE() calls after spin_lock(&wx->hw_stats_lock) in v2.
---
pw-bot: cr
> pw-bot: cr
> [ ... ]
>
> --
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/2026…%40net-swift.com
>