Skip to contentSkip to conversation

gve: handle overflow when reporting TX consumed descriptors

PATCH Applied Harshitha Ramamurthy 4 participants 4 messages Apr 2, 2025 – Apr 3, 2025

Subsystems (4)
lore
Share & tools
lore

Harshitha Ramamurthy

author maintainer
#0 lore raw

PATCH 1/1 gve: handle overflow when reporting TX consumed descriptors

From: Joshua Washington <[email protected]>

When the tx tail is less than the head (in cases of wraparound), the TX consumed descriptor statistic in DQ will be reported as UINT32_MAX - head + tail, which is incorrect. Mask the difference of head and tail according to the ring size when reporting the statistic.

Fixes 2c9198356d56 ("gve: Add consumed counts to ethtool stats")
---
 drivers/net/ethernet/google/gve/gve_ethtool.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/google/gve/gve_ethtool.c +3 -1
index 31a21ccf4863..4dea1fdce748 100644
@@ -392,7 +392,9 @@ gve_get_ethtool_stats(struct net_device *netdev,
 				 */
 				data[i++] = 0;
 				data[i++] = 0;
-				data[i++] = tx->dqo_tx.tail - tx->dqo_tx.head;
+				data[i++] =
+					(tx->dqo_tx.tail - tx->dqo_tx.head) &
+					tx->mask;
 			}
 			do {
 				start =
Signature · 1 line
2.49.0.472.ge94155a9ec-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines · Harshitha Ramamurthy

From: Joshua Washington <[email protected]>

When the tx tail is less than the head (in cases of wraparound), the TX consumed descriptor statistic in DQ will be reported as UINT32_MAX - head + tail, which is incorrect. Mask the difference of head and tail according to the ring size when reporting the statistic.

Fixes 2c9198356d56 ("gve: Add consumed counts to ethtool stats")
---
 drivers/net/ethernet/google/gve/gve_ethtool.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/google/gve/gve_ethtool.c +0 -0
index 31a21ccf4863..4dea1fdce748 100644

drivers/net/ethernet/google/gve/gve_ethtool.c gve_get_ethtool_stats(struct net_device *netdev, · line 397

Quoted 7 lines
drivers/net/ethernet/google/gve/gve_ethtool.c +3 -1
@@ -392,7 +392,9 @@ gve_get_ethtool_stats(struct net_device *netdev,
 				 */
 				data[i++] = 0;
 				data[i++] = 0;
-				data[i++] = tx->dqo_tx.tail - tx->dqo_tx.head;
+				data[i++] =
+					(tx->dqo_tx.tail - tx->dqo_tx.head) &
+					tx->mask;

I will add it in gve_tx_dqo.c as num_used_tx_slots() and simplify num_avail_tx_slots()

{
	return tx->mask - num_used_tx_slots();
}

but it isn't needed, even maybe unwanted as this is just fix.

Thanks

Quoted 5 lines
drivers/net/ethernet/google/gve/gve_ethtool.c +0 -0
 			}
 			do {
 				start =
Signature · 1 line
2.49.0.472.ge94155a9ec-goog
reviewer Reviewed-by
#2 lore raw
Quoted 31 lines · Michal Swiatkowski
Quoted 20 lines · Harshitha Ramamurthy

From: Joshua Washington <[email protected]>

When the tx tail is less than the head (in cases of wraparound), the TX consumed descriptor statistic in DQ will be reported as UINT32_MAX - head + tail, which is incorrect. Mask the difference of head and tail according to the ring size when reporting the statistic.

Fixes 2c9198356d56 ("gve: Add consumed counts to ethtool stats")
---
 drivers/net/ethernet/google/gve/gve_ethtool.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/google/gve/gve_ethtool.c +0 -0
index 31a21ccf4863..4dea1fdce748 100644

drivers/net/ethernet/google/gve/gve_ethtool.c gve_get_ethtool_stats(struct net_device *netdev, · line 397

Quoted 7 lines
drivers/net/ethernet/google/gve/gve_ethtool.c +3 -1
@@ -392,7 +392,9 @@ gve_get_ethtool_stats(struct net_device *netdev,
 				 */
 				data[i++] = 0;
 				data[i++] = 0;
-				data[i++] = tx->dqo_tx.tail - tx->dqo_tx.head;
+				data[i++] =
+					(tx->dqo_tx.tail - tx->dqo_tx.head) &
+					tx->mask;
Quoted 6 lines

I will add it in gve_tx_dqo.c as num_used_tx_slots() and simplify num_avail_tx_slots()

{
	return tx->mask - num_used_tx_slots();
}

but it isn't needed, even maybe unwanted as this is just fix.

I think that would be a nice cleanup, but should be as a follow-up to this minimal fix.

#3 lore raw
In reply to Harshitha Ramamurthy
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Wed, 2 Apr 2025 00:10:37 +0000 you wrote:

From: Joshua Washington <[email protected]>

When the tx tail is less than the head (in cases of wraparound), the TX consumed descriptor statistic in DQ will be reported as UINT32_MAX - head + tail, which is incorrect. Mask the difference of head and tail according to the ring size when reporting the statistic.

[...]

Here is the summary with links:
- [net] gve: handle overflow when reporting TX consumed descriptors

    https://git.kernel.org/netdev/net/c/15970e1b23f5

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html