Netdev List
 help / color / mirror / Atom feed
From: mingming cao <mmc@linux.ibm.com>
To: netdev-bot+sashiko@kernel.org
Cc: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org,
	horms@kernel.org, edumazet@kernel.org, pabeni@redhat.com,
	andrew+netdev@lunn.ch, nnac123@linux.ibm.com,
	maddy@linux.ibm.com, mpe@ellerman.id.au,
	linuxppc-dev@lists.ozlabs.org, npiggin@gmail.com,
	chleroy@kernel.org, ritesh.list@gmail.com, sshegde@linux.ibm.com,
	haren@linux.ibm.com, ricklind@linux.ibm.com,
	davemarq@linux.ibm.com, bjking1@linux.ibm.com,
	shaik.abdulla1@ibm.com
Subject: Re: [PATCH net-next v8 11/15] ibmveth: Add per-queue RX and TX statistics collection
Date: Fri, 13 Nov 2026 11:00:39 -0800	[thread overview]
Message-ID: <bb29cbf9-20dc-4574-b084-0c3832849645@linux.ibm.com> (raw)
In-Reply-To: <179452783113.2199510.7647821675893385517@kernel.org>


On 11/12/26 3:57 PM, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
>
> Critical: 0 · High: 0 · Medium: 1 · Low: 0
>
> 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] Statistics readers now take every RX queue's replenish_lock
>    with spin_lock_bh().
>
> --
>
> ibmveth: Add per-queue RX and TX statistics collection
>
> This patch moves the adapter-wide RX and TX counters into per-queue
> ibmveth_rx_queue_stats and ibmveth_tx_queue_stats arrays allocated at
> probe. It exports packets, bytes and hardware drops through
> netdev_stat_ops, adds ndo_get_stats64(), and keeps the existing ethtool -S
> keys by summing the per-queue slots. It also adds a per-queue
> no_buffer_retired carry so that rx_no_buffer never goes backwards across a
> reopen.
>
>> diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c
>> index a0c3c06d2b9d9..45adf6e9be09b 100644
>> --- a/drivers/net/ethernet/ibm/ibmveth.c
>> +++ b/drivers/net/ethernet/ibm/ibmveth.c
> [ ... ]
>
>> @@ -1063,7 +1197,45 @@ static void ibmveth_update_rx_no_buffer(struct ibmveth_adapter *adapter,
>>   	p = adapter->buffer_list_addr[queue_index] + 4096 - 8;
>>   	drops = be64_to_cpup(p);
>>   
>> -	adapter->rx_no_buffer = drops;
>> +	qstats = &adapter->rx_qstats[queue_index];
>> +
>> +	if (drops < qstats->no_buffer_drops)
>> +		IBMVETH_STAT_ADD(qstats->no_buffer_retired,
>> +				 qstats->no_buffer_drops);
>> +	WRITE_ONCE(qstats->no_buffer_drops, drops);
>> +}
>> +
>> +/* Snapshot live+retired under replenish_lock; see retire_rx_no_buffer(). */
>> +static u64 ibmveth_rx_no_buffer_pair(struct ibmveth_adapter *adapter, int i)
>> +{
>> +	struct ibmveth_rx_q *rxq = &adapter->rx_queue[i];
>> +	struct ibmveth_rx_queue_stats *qstats = &adapter->rx_qstats[i];
>> +	u64 drops, retired;
>> +
>> +	spin_lock_bh(&rxq->replenish_lock);
>> +	drops = qstats->no_buffer_drops;
>> +	retired = qstats->no_buffer_retired;
>> +	spin_unlock_bh(&rxq->replenish_lock);
>> +	return drops + retired;
>> +}
> [Severity: Medium]
> Should the stats readers be taking replenish_lock here?
>
> This lock sits on the RX datapath. ibmveth_remove_buffer_from_pool() takes
> it from NAPI for every received frame. ibmveth_replenish_task() holds it
> for a whole multi-pool refill, which includes netdev_alloc_skb(),
> dma_map_single_attrs() and the h_add_logical_lan_buffers*() hcalls.
>
> The new ndo_get_stats64 calls this helper for every slot, whether the
> queue is live or not:
>
> ibmveth_get_stats64() {
> 	for (i = 0; i < IBMVETH_MAX_RX_QUEUES; i++) {
> 		...
> 		stats->rx_missed_errors +=
> 			ibmveth_rx_no_buffer_pair(adapter, i);
> 	}
> }
>
> The rx_no_buffer ethtool -S key, ibmveth_get_queue_stats_rx() and
> ibmveth_get_base_stats() also call it.
>
> As a result, every /proc/net/dev read, RTM_GETLINK dump or bonding/team
> stats poll takes up to 16 BH-disabling spinlocks. Unprivileged users can
> trigger these reads.
>
> Each acquisition pulls the lock cacheline away from the NAPI CPUs. A
> reader can also spin with BH disabled for as long as a refill takes, for
> example during the initial replenish in ibmveth_open().
>
> Before this patch the driver had no ndo_get_stats64, and netdev->stats was
> read without taking any lock.
>
> Writers already hold replenish_lock. Could they keep a single combined
> monotonic value (retired plus live drops) updated with WRITE_ONCE()? Then
> readers could use READ_ONCE() and skip the lock.
>
> This also looks unchanged at the end of the series, in "ibmveth: Complete
> set_channels down-path". There, ibmveth_rx_no_buffer_pair() still uses
> spin_lock_bh() and ibmveth_get_stats64() still calls it for every slot.
>
> [ ... ]
The lock is only there to get a consistent snapshot of the live and
retired no-buffer counts. The retire path moves the live count into the
retired one and clears it, so without the lock a reader could see a
mixed pair and report a transient double count or a lower
rx_missed_errors.

It's a cost on the stats readers, not a correctness problem in the RX
path. The reader holds each per-queue lock just for two loads, with no
allocation, DMA mapping or hcalls under it. It can still contend with a
refill that holds replenish_lock though, so I agree a lockless counter
is the better shape.

I don't think that should block the series. If there's a respin I'll
fold in a single combined monotonic value that the writers update and
readers load with READ_ONCE(); otherwise I'll send it as a follow-up
cleanup.

Thanks,
Mingming


  reply	other threads:[~2026-11-13 19:01 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09 23:55 [PATCH net-next v8 00/15] ibmveth: Add multi-queue RX support Mingming Cao
2026-11-09 23:55 ` [PATCH net-next v8 01/15] ibmveth: Add MQ RX hypercall wrappers and call definitions Mingming Cao
2026-11-09 23:55 ` [PATCH net-next v8 02/15] ibmveth: Prepare MQ RX adapter data structures Mingming Cao
2026-11-09 23:55 ` [PATCH net-next v8 03/15] ibmveth: Refactor RX resource allocation for MQ RX bring-up Mingming Cao
2026-11-09 23:55 ` [PATCH net-next v8 04/15] ibmveth: Refactor buffer pool management for per-queue MQ RX Mingming Cao
2026-11-09 23:55 ` [PATCH net-next v8 05/15] ibmveth: Refactor RX interrupt control for MQ RX queues Mingming Cao
2026-11-12 23:57   ` netdev-bot+sashiko
2026-11-13 18:46     ` mingming cao
2026-11-09 23:55 ` [PATCH net-next v8 06/15] ibmveth: Refactor TX resource allocation in open/close paths Mingming Cao
2026-11-12 23:57   ` netdev-bot+sashiko
2026-11-13 18:54     ` mingming cao
2026-11-09 23:55 ` [PATCH net-next v8 07/15] ibmveth: Add RX queue register helpers for MQ Mingming Cao
2026-11-12 23:57   ` netdev-bot+sashiko
2026-11-09 23:55 ` [PATCH net-next v8 08/15] ibmveth: Add queue-aware RX buffer submit helper " Mingming Cao
2026-11-12 23:57   ` netdev-bot+sashiko
2026-11-09 23:55 ` [PATCH net-next v8 09/15] ibmveth: Split RX poll into per-slot helpers " Mingming Cao
2026-11-12 23:57   ` netdev-bot+sashiko
2026-11-09 23:55 ` [PATCH net-next v8 10/15] ibmveth: Enable multi-queue RX receive path Mingming Cao
2026-11-12 23:57   ` netdev-bot+sashiko
2026-11-13 18:59     ` mingming cao
2026-11-09 23:55 ` [PATCH net-next v8 11/15] ibmveth: Add per-queue RX and TX statistics collection Mingming Cao
2026-11-12 23:57   ` netdev-bot+sashiko
2026-11-13 19:00     ` mingming cao [this message]
2026-11-09 23:55 ` [PATCH net-next v8 12/15] ibmveth: Report MQ-aware RX counts in ethtool get_channels Mingming Cao
2026-11-09 23:55 ` [PATCH net-next v8 13/15] ibmveth: Expose per-queue buffer pool details via debugfs Mingming Cao
2026-11-09 23:55 ` [PATCH net-next v8 14/15] ibmveth: Implement incremental MQ RX queue resize Mingming Cao
2026-11-12 23:57   ` netdev-bot+sashiko
2026-11-13 19:07     ` mingming cao
2026-11-09 23:55 ` [PATCH net-next v8 15/15] ibmveth: Complete set_channels down-path Mingming Cao
2026-11-12 23:57   ` netdev-bot+sashiko

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=bb29cbf9-20dc-4574-b084-0c3832849645@linux.ibm.com \
    --to=mmc@linux.ibm.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=bjking1@linux.ibm.com \
    --cc=chleroy@kernel.org \
    --cc=davem@davemloft.net \
    --cc=davemarq@linux.ibm.com \
    --cc=edumazet@kernel.org \
    --cc=haren@linux.ibm.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=netdev-bot+sashiko@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nnac123@linux.ibm.com \
    --cc=npiggin@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=ricklind@linux.ibm.com \
    --cc=ritesh.list@gmail.com \
    --cc=shaik.abdulla1@ibm.com \
    --cc=sshegde@linux.ibm.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