From: Mingming Cao <mmc@linux.ibm.com>
To: netdev@vger.kernel.org
Cc: Mingming Cao <mmc@linux.ibm.com>,
maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com,
chleroy@kernel.org, ritesh.list@gmail.com, sshegde@linux.ibm.com,
nnac123@linux.ibm.com, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, linuxppc-dev@lists.ozlabs.org,
horms@kernel.org, davemarq@linux.ibm.com, haren@linux.ibm.com,
ricklind@linux.ibm.com, bjking1@linux.ibm.com,
shaik.abdulla1@ibm.com, willemb@google.com
Subject: [PATCH net-next v9 10/13] ibmveth: Keep rx_no_buffer across ifdown/up
Date: Tue, 1 Dec 2026 11:02:13 -0800 [thread overview]
Message-ID: <20261201190216.62407-11-mmc@linux.ibm.com> (raw)
In-Reply-To: <20261201190216.62407-1-mmc@linux.ibm.com>
rx_no_buffer counts frames PHYP dropped because the queue had no
buffer posted. PHYP keeps the count in each queue's buffer-list page,
which H_FREE_LOGICAL_LAN zeroes, and close() reads it after the free,
so it goes back to 0 on every close/open. The next patch reports it
as per-queue hw_drops, which must not go backwards.
Read each queue's count just before H_FREE_LOGICAL_LAN and add it to a
per-queue running total. Replenish and close store the running total
plus the live count as one precomputed sum, and readers use only that
sum, so a count moving into the total is never seen twice. Between
those updates the sum does not move, including while a queue out of
buffers gets no polls.
Report the sum as rx_missed_errors, which if_link.h defines as drops
for lack of buffer space, so ip -s link now shows these drops as
missed; ethtool -S keeps calling it rx_no_buffer. Both changes apply
to single-queue adapters too.
Signed-off-by: Mingming Cao <mmc@linux.ibm.com>
---
drivers/net/ethernet/ibm/ibmveth.c | 74 +++++++++++++++++++++++++++---
drivers/net/ethernet/ibm/ibmveth.h | 6 ++-
2 files changed, 73 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c
index e36c25609c62..56b645ffb18c 100644
--- a/drivers/net/ethernet/ibm/ibmveth.c
+++ b/drivers/net/ethernet/ibm/ibmveth.c
@@ -79,6 +79,8 @@ MODULE_PARM_DESC(old_large_send,
* @IBMVETH_STAT_ADAPTER: plain u64 in struct ibmveth_adapter
* @IBMVETH_STAT_RX_QSUM: per-queue u64, summed over rx_qstats[]
* @IBMVETH_STAT_TX_QSUM: per-queue u64, summed over tx_qstats[]
+ * @IBMVETH_STAT_RX_NO_BUFFER: running total plus the value from the
+ * queue's last replenish pass (see ibmveth_sum_rx_no_buffer())
*
* Counters live per queue so that queues never share a field.
*/
@@ -86,6 +88,7 @@ enum ibmveth_stat_src {
IBMVETH_STAT_ADAPTER,
IBMVETH_STAT_RX_QSUM,
IBMVETH_STAT_TX_QSUM,
+ IBMVETH_STAT_RX_NO_BUFFER,
};
struct ibmveth_stat {
@@ -120,7 +123,8 @@ static struct ibmveth_stat ibmveth_stats[] = {
IBMVETH_RXQ_STAT("replenish_add_buff_success",
replenish_add_buff_success),
IBMVETH_RXQ_STAT("rx_invalid_buffer", invalid_buffers),
- IBMVETH_RXQ_STAT("rx_no_buffer", no_buffer_drops),
+ /* off unused; summed in ibmveth_ethtool_adapter_stat() */
+ { "rx_no_buffer", IBMVETH_STAT_RX_NO_BUFFER, 0 },
IBMVETH_ADAPTER_STAT("tx_map_failed", tx_map_failed),
IBMVETH_TXQ_STAT("tx_send_failed", send_failures),
IBMVETH_ADAPTER_STAT("fw_enabled_ipv4_csum", fw_ipv4_csum_support),
@@ -934,15 +938,49 @@ hcall_failure:
static void ibmveth_update_rx_no_buffer(struct ibmveth_adapter *adapter,
int queue_index)
{
+ struct ibmveth_rx_queue_stats *qstats;
__be64 *p;
+ u64 drops;
/* NULL after ibmveth_leak_rx_memory(). */
if (!adapter->buffer_list_addr[queue_index])
return;
p = adapter->buffer_list_addr[queue_index] + 4096 - 8;
- WRITE_ONCE(adapter->rx_qstats[queue_index].no_buffer_drops,
- be64_to_cpu(READ_ONCE(*p)));
+ drops = be64_to_cpu(READ_ONCE(*p));
+
+ qstats = &adapter->rx_qstats[queue_index];
+
+ /* PHYP's count only grows while the queue is registered, and the
+ * free path retires it; if it ever reads lower, keep what was seen.
+ */
+ if (drops < qstats->no_buffer_drops)
+ IBMVETH_STAT_ADD(qstats->no_buffer_retired,
+ qstats->no_buffer_drops);
+ WRITE_ONCE(qstats->no_buffer_drops, drops);
+ WRITE_ONCE(qstats->no_buffer_total,
+ qstats->no_buffer_retired + drops);
+}
+
+static u64 ibmveth_rx_no_buffer_total(struct ibmveth_adapter *adapter,
+ int queue_index)
+{
+ return READ_ONCE(adapter->rx_qstats[queue_index].no_buffer_total);
+}
+
+/*
+ * Fold the last sample into retired once the queue is freed: the next
+ * registration restarts PHYP's counter at 0. The fold leaves
+ * no_buffer_total unchanged.
+ */
+static void ibmveth_retire_rx_no_buffer(struct ibmveth_adapter *adapter,
+ int queue_index)
+{
+ struct ibmveth_rx_queue_stats *qstats;
+
+ qstats = &adapter->rx_qstats[queue_index];
+ IBMVETH_STAT_ADD(qstats->no_buffer_retired, qstats->no_buffer_drops);
+ WRITE_ONCE(qstats->no_buffer_drops, 0);
}
/* replenish routine */
@@ -1430,16 +1468,26 @@ static void ibmveth_leak_rx_memory(struct ibmveth_adapter *adapter)
* CMO partitions are single-queue and must not keep it mapped at
* remove, and the unmap clears the adapter's TCEs before the pages are
* freed.
+ *
+ * PHYP zeroes the buffer-list pages on free, so each queue's no-buffer
+ * counter is sampled before H_FREE_LOGICAL_LAN and retired after it.
*/
static void ibmveth_free_all_queues(struct ibmveth_adapter *adapter)
{
long lpar_rc;
+ int i;
+
+ for (i = 0; i < adapter->num_rx_queues; i++)
+ ibmveth_update_rx_no_buffer(adapter, i);
lpar_rc = ibmveth_free_logical_lan(adapter);
if (lpar_rc != H_SUCCESS)
netdev_err(adapter->netdev,
"h_free_logical_lan failed: %ld\n", lpar_rc);
+ for (i = 0; i < adapter->num_rx_queues; i++)
+ ibmveth_retire_rx_no_buffer(adapter, i);
+
if (lpar_rc != H_SUCCESS && lpar_rc != H_PARAMETER &&
adapter->multi_queue)
ibmveth_leak_rx_memory(adapter);
@@ -1651,7 +1699,6 @@ out:
static int ibmveth_close(struct net_device *netdev)
{
struct ibmveth_adapter *adapter = netdev_priv(netdev);
- int i;
/* change_mtu, pool sysfs, set_csum and set_tso call close() and
* open() directly. If that open() fails, IFF_UP stays set and
@@ -1670,8 +1717,6 @@ static int ibmveth_close(struct net_device *netdev)
adapter->mq_hfunc_reopened = false;
ibmveth_free_all_queues(adapter);
- for (i = 0; i < adapter->num_rx_queues; i++)
- ibmveth_update_rx_no_buffer(adapter, i);
ibmveth_free_buffer_pools(adapter);
ibmveth_cleanup_rx_resources(adapter);
ibmveth_free_filter_list(adapter);
@@ -1966,6 +2011,17 @@ static u64 ibmveth_sum_rx_qstat(struct ibmveth_adapter *adapter, size_t off)
return total;
}
+static u64 ibmveth_sum_rx_no_buffer(struct ibmveth_adapter *adapter)
+{
+ u64 total = 0;
+ int i;
+
+ for (i = 0; i < IBMVETH_MAX_RX_QUEUES; i++)
+ total += ibmveth_rx_no_buffer_total(adapter, i);
+
+ return total;
+}
+
static u64 ibmveth_sum_tx_qstat(struct ibmveth_adapter *adapter, size_t off)
{
u64 total = 0;
@@ -1990,6 +2046,8 @@ static u64 ibmveth_ethtool_adapter_stat(struct ibmveth_adapter *adapter,
return ibmveth_sum_rx_qstat(adapter, stat->off);
case IBMVETH_STAT_TX_QSUM:
return ibmveth_sum_tx_qstat(adapter, stat->off);
+ case IBMVETH_STAT_RX_NO_BUFFER:
+ return ibmveth_sum_rx_no_buffer(adapter);
case IBMVETH_STAT_ADAPTER:
break;
}
@@ -2843,6 +2901,9 @@ static netdev_features_t ibmveth_features_check(struct sk_buff *skb,
* @stats: rtnl link statistics storage
*
* Sums per-queue rx_qstats and tx_qstats into the rtnl counters.
+ * rx_missed_errors is the PHYP no-buffer sum (retired plus the value
+ * from the last replenish pass), which if_link.h counts separately
+ * from rx_dropped.
* Walk the full allocated arrays (not the live queue count) so shrinking
* channels cannot make the totals go backwards.
*/
@@ -2857,6 +2918,7 @@ static void ibmveth_get_stats64(struct net_device *dev,
stats->rx_bytes += READ_ONCE(adapter->rx_qstats[i].bytes);
stats->rx_dropped += READ_ONCE(adapter->rx_qstats[i].dropped);
}
+ stats->rx_missed_errors = ibmveth_sum_rx_no_buffer(adapter);
for (i = 0; i < IBMVETH_MAX_QUEUES; i++) {
stats->tx_packets += READ_ONCE(adapter->tx_qstats[i].packets);
diff --git a/drivers/net/ethernet/ibm/ibmveth.h b/drivers/net/ethernet/ibm/ibmveth.h
index d45f173edda2..d6d28b75dd99 100644
--- a/drivers/net/ethernet/ibm/ibmveth.h
+++ b/drivers/net/ethernet/ibm/ibmveth.h
@@ -250,8 +250,12 @@ struct ibmveth_rx_queue_stats {
u64 large_packets;
u64 invalid_buffers;
u64 dropped;
- /* PHYP's drop count from the buffer-list page. */
+ /* PHYP's per-page absolute drop count for the live page. */
u64 no_buffer_drops;
+ /* Absolutes from retired pages or seen before a lower reading. */
+ u64 no_buffer_retired;
+ /* no_buffer_retired + no_buffer_drops, for lockless readers. */
+ u64 no_buffer_total;
u64 replenish_task_cycles;
u64 replenish_no_mem;
u64 replenish_add_buff_failure;
--
2.50.1 (Apple Git-155)
next prev parent reply other threads:[~2026-12-01 19:03 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 19:02 [PATCH net-next v9 00/13] ibmveth: Add multi-queue RX support Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 01/13] ibmveth: Keep a buffer pool enabled after its allocation fails Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 02/13] ibmveth: Keep TX statistics per queue Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 03/13] powerpc/pseries: Add hcall numbers for multi-queue virtual ethernet Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 04/13] ibmveth: Add RX queue handles Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 05/13] ibmveth: Register subordinate RX queues Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 06/13] ibmveth: Add subordinate RX queue interrupt control Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 07/13] ibmveth: Add the MQ RX buffer submit hypercall Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 08/13] ibmveth: Start every RX queue on open and resume Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 09/13] ibmveth: Keep RX statistics per queue Mingming Cao
2026-12-01 19:02 ` Mingming Cao [this message]
2026-12-01 19:02 ` [PATCH net-next v9 11/13] ibmveth: Report per-queue statistics through netdev_stat_ops Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 12/13] ibmveth: Enable multi-queue RX Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 13/13] ibmveth: Allow changing the RX queue count Mingming Cao
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=20261201190216.62407-11-mmc@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@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 \
--cc=willemb@google.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