netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] gve: handle overflow when reporting TX consumed descriptors
@ 2025-04-02  0:10 Harshitha Ramamurthy
  2025-04-02  5:10 ` Michal Swiatkowski
  2025-04-03 22:20 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 4+ messages in thread
From: Harshitha Ramamurthy @ 2025-04-02  0:10 UTC (permalink / raw)
  To: netdev
  Cc: jeroendb, hramamurthy, andrew+netdev, davem, edumazet, kuba,
	pabeni, pkaligineedi, willemb, joshwash, horms, shailend, jrkim,
	linux-kernel, stable

From: Joshua Washington <joshwash@google.com>

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.

Cc: stable@vger.kernel.org
Fixes: 2c9198356d56 ("gve: Add consumed counts to ethtool stats")
Signed-off-by: Joshua Washington <joshwash@google.com>
Signed-off-by: Harshitha Ramamurthy <hramamurthy@google.com>
---
 drivers/net/ethernet/google/gve/gve_ethtool.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/google/gve/gve_ethtool.c b/drivers/net/ethernet/google/gve/gve_ethtool.c
index 31a21ccf4863..4dea1fdce748 100644
--- a/drivers/net/ethernet/google/gve/gve_ethtool.c
+++ b/drivers/net/ethernet/google/gve/gve_ethtool.c
@@ -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 =
-- 
2.49.0.472.ge94155a9ec-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net] gve: handle overflow when reporting TX consumed descriptors
  2025-04-02  0:10 [PATCH net] gve: handle overflow when reporting TX consumed descriptors Harshitha Ramamurthy
@ 2025-04-02  5:10 ` Michal Swiatkowski
  2025-04-02 10:20   ` Simon Horman
  2025-04-03 22:20 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 4+ messages in thread
From: Michal Swiatkowski @ 2025-04-02  5:10 UTC (permalink / raw)
  To: Harshitha Ramamurthy
  Cc: netdev, jeroendb, andrew+netdev, davem, edumazet, kuba, pabeni,
	pkaligineedi, willemb, joshwash, horms, shailend, jrkim,
	linux-kernel, stable

On Wed, Apr 02, 2025 at 12:10:37AM +0000, Harshitha Ramamurthy wrote:
> From: Joshua Washington <joshwash@google.com>
> 
> 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.
> 
> Cc: stable@vger.kernel.org
> Fixes: 2c9198356d56 ("gve: Add consumed counts to ethtool stats")
> Signed-off-by: Joshua Washington <joshwash@google.com>
> Signed-off-by: Harshitha Ramamurthy <hramamurthy@google.com>
> ---
>  drivers/net/ethernet/google/gve/gve_ethtool.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/google/gve/gve_ethtool.c b/drivers/net/ethernet/google/gve/gve_ethtool.c
> index 31a21ccf4863..4dea1fdce748 100644
> --- a/drivers/net/ethernet/google/gve/gve_ethtool.c
> +++ b/drivers/net/ethernet/google/gve/gve_ethtool.c
> @@ -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;

Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>

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

>  			}
>  			do {
>  				start =
> -- 
> 2.49.0.472.ge94155a9ec-goog

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] gve: handle overflow when reporting TX consumed descriptors
  2025-04-02  5:10 ` Michal Swiatkowski
@ 2025-04-02 10:20   ` Simon Horman
  0 siblings, 0 replies; 4+ messages in thread
From: Simon Horman @ 2025-04-02 10:20 UTC (permalink / raw)
  To: Michal Swiatkowski
  Cc: Harshitha Ramamurthy, netdev, jeroendb, andrew+netdev, davem,
	edumazet, kuba, pabeni, pkaligineedi, willemb, joshwash, shailend,
	jrkim, linux-kernel, stable

On Wed, Apr 02, 2025 at 07:10:18AM +0200, Michal Swiatkowski wrote:
> On Wed, Apr 02, 2025 at 12:10:37AM +0000, Harshitha Ramamurthy wrote:
> > From: Joshua Washington <joshwash@google.com>
> > 
> > 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.
> > 
> > Cc: stable@vger.kernel.org
> > Fixes: 2c9198356d56 ("gve: Add consumed counts to ethtool stats")
> > Signed-off-by: Joshua Washington <joshwash@google.com>
> > Signed-off-by: Harshitha Ramamurthy <hramamurthy@google.com>
> > ---
> >  drivers/net/ethernet/google/gve/gve_ethtool.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/net/ethernet/google/gve/gve_ethtool.c b/drivers/net/ethernet/google/gve/gve_ethtool.c
> > index 31a21ccf4863..4dea1fdce748 100644
> > --- a/drivers/net/ethernet/google/gve/gve_ethtool.c
> > +++ b/drivers/net/ethernet/google/gve/gve_ethtool.c
> > @@ -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;
> 
> Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
> 
> 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.

Reviewed-by: Simon Horman <horms@kernel.org>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] gve: handle overflow when reporting TX consumed descriptors
  2025-04-02  0:10 [PATCH net] gve: handle overflow when reporting TX consumed descriptors Harshitha Ramamurthy
  2025-04-02  5:10 ` Michal Swiatkowski
@ 2025-04-03 22:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-04-03 22:20 UTC (permalink / raw)
  To: Harshitha Ramamurthy
  Cc: netdev, jeroendb, andrew+netdev, davem, edumazet, kuba, pabeni,
	pkaligineedi, willemb, joshwash, horms, shailend, jrkim,
	linux-kernel, stable

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed,  2 Apr 2025 00:10:37 +0000 you wrote:
> From: Joshua Washington <joshwash@google.com>
> 
> 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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-04-03 22:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-02  0:10 [PATCH net] gve: handle overflow when reporting TX consumed descriptors Harshitha Ramamurthy
2025-04-02  5:10 ` Michal Swiatkowski
2025-04-02 10:20   ` Simon Horman
2025-04-03 22:20 ` patchwork-bot+netdevbpf

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).