netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Shailend Chand <shailend@google.com>
To: netdev@vger.kernel.org
Cc: almasrymina@google.com, davem@davemloft.net, edumazet@google.com,
	 kuba@kernel.org, pabeni@redhat.com, willemb@google.com,
	 Shailend Chand <shailend@google.com>
Subject: [RFC PATCH net-next 8/9] gve: Account for stopped queues when reading NIC stats
Date: Thu, 18 Apr 2024 19:51:58 +0000	[thread overview]
Message-ID: <20240418195159.3461151-9-shailend@google.com> (raw)
In-Reply-To: <20240418195159.3461151-1-shailend@google.com>

We now account for the fact that the NIC might send us stats for a
subset of queues. Without this change, gve_get_ethtool_stats might make
an invalid access on the priv->stats_report->stats array.

Signed-off-by: Shailend Chand <shailend@google.com>
---
 drivers/net/ethernet/google/gve/gve_ethtool.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/google/gve/gve_ethtool.c b/drivers/net/ethernet/google/gve/gve_ethtool.c
index 299206d15c73..2a451aba8328 100644
--- a/drivers/net/ethernet/google/gve/gve_ethtool.c
+++ b/drivers/net/ethernet/google/gve/gve_ethtool.c
@@ -181,12 +181,17 @@ gve_get_ethtool_stats(struct net_device *netdev,
 					    sizeof(int), GFP_KERNEL);
 	if (!rx_qid_to_stats_idx)
 		return;
+	for (ring = 0; ring < priv->rx_cfg.num_queues; ring++)
+		rx_qid_to_stats_idx[ring] = -1;
 	tx_qid_to_stats_idx = kmalloc_array(num_tx_queues,
 					    sizeof(int), GFP_KERNEL);
 	if (!tx_qid_to_stats_idx) {
 		kfree(rx_qid_to_stats_idx);
 		return;
 	}
+	for (ring = 0; ring < num_tx_queues; ring++)
+		tx_qid_to_stats_idx[ring] = -1;
+
 	for (rx_pkts = 0, rx_bytes = 0, rx_hsplit_pkt = 0,
 	     rx_skb_alloc_fail = 0, rx_buf_alloc_fail = 0,
 	     rx_desc_err_dropped_pkt = 0, rx_hsplit_unsplit_pkt = 0,
@@ -308,11 +313,11 @@ gve_get_ethtool_stats(struct net_device *netdev,
 			data[i++] = rx->rx_copybreak_pkt;
 			data[i++] = rx->rx_copied_pkt;
 			/* stats from NIC */
-			if (skip_nic_stats) {
+			stats_idx = rx_qid_to_stats_idx[ring];
+			if (skip_nic_stats || stats_idx == -1) {
 				/* skip NIC rx stats */
 				i += NIC_RX_STATS_REPORT_NUM;
 			} else {
-				stats_idx = rx_qid_to_stats_idx[ring];
 				for (j = 0; j < NIC_RX_STATS_REPORT_NUM; j++) {
 					u64 value =
 						be64_to_cpu(report_stats[stats_idx + j].value);
@@ -383,11 +388,11 @@ gve_get_ethtool_stats(struct net_device *netdev,
 			data[i++] = gve_tx_load_event_counter(priv, tx);
 			data[i++] = tx->dma_mapping_error;
 			/* stats from NIC */
-			if (skip_nic_stats) {
+			stats_idx = tx_qid_to_stats_idx[ring];
+			if (skip_nic_stats || stats_idx == -1) {
 				/* skip NIC tx stats */
 				i += NIC_TX_STATS_REPORT_NUM;
 			} else {
-				stats_idx = tx_qid_to_stats_idx[ring];
 				for (j = 0; j < NIC_TX_STATS_REPORT_NUM; j++) {
 					u64 value =
 						be64_to_cpu(report_stats[stats_idx + j].value);
-- 
2.44.0.769.g3c40516874-goog


  parent reply	other threads:[~2024-04-18 19:52 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-18 19:51 [RFC PATCH net-next 0/9] gve: Implement netdev queue api Shailend Chand
2024-04-18 19:51 ` [RFC PATCH net-next 1/9] queue_api: define " Shailend Chand
2024-04-18 19:51 ` [RFC PATCH net-next 2/9] gve: Make the RX free queue funcs idempotent Shailend Chand
2024-04-18 19:51 ` [RFC PATCH net-next 3/9] gve: Add adminq funcs to add/remove a single Rx queue Shailend Chand
2024-04-18 19:51 ` [RFC PATCH net-next 4/9] gve: Make gve_turn(up|down) ignore stopped queues Shailend Chand
2024-04-18 19:51 ` [RFC PATCH net-next 5/9] gve: Make gve_turnup work for nonempty queues Shailend Chand
2024-04-18 19:51 ` [RFC PATCH net-next 6/9] gve: Avoid rescheduling napi if on wrong cpu Shailend Chand
2024-04-18 19:51 ` [RFC PATCH net-next 7/9] gve: Reset Rx ring state in the ring-stop funcs Shailend Chand
2024-04-18 19:51 ` Shailend Chand [this message]
2024-04-18 19:51 ` [RFC PATCH net-next 9/9] gve: Implement queue api Shailend Chand
2024-04-19  1:48   ` Jakub Kicinski
2024-04-19 16:10     ` Mina Almasry
2024-04-20  3:25       ` Jakub Kicinski
2024-04-22 16:58         ` Mina Almasry
2024-04-22 18:41           ` Jakub Kicinski
2024-04-19 22:23   ` Shailend Chand
2024-04-23 17:55     ` David Wei
2024-04-23 17:33   ` David Wei
2024-04-18 21:55 ` [RFC PATCH net-next 0/9] gve: Implement netdev " Mina Almasry

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=20240418195159.3461151-9-shailend@google.com \
    --to=shailend@google.com \
    --cc=almasrymina@google.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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;
as well as URLs for NNTP newsgroup(s).