[PATCH net] octeontx2-af: mcs: Fix unsupported secy stats read

Subbaraya Sundeep posted 1 patch 1 week, 2 days ago
drivers/net/ethernet/marvell/octeontx2/af/mcs.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[PATCH net] octeontx2-af: mcs: Fix unsupported secy stats read
Posted by Subbaraya Sundeep 1 week, 2 days ago
From: Geetha sowjanya <gakula@marvell.com>

Secy control stats counter doesn't exist for CNF10KB platform.
Skip reading this respective register for CNF10KB silicon while
fetching secy stats.

Fixes: 9312150af8da ("octeontx2-af: cn10k: mcs: Support for stats collection")
Signed-off-by: Geetha sowjanya <gakula@marvell.com>
Signed-off-by: Subbaraya Sundeep <sbhatta@marvell.com>
---
 drivers/net/ethernet/marvell/octeontx2/af/mcs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/af/mcs.c b/drivers/net/ethernet/marvell/octeontx2/af/mcs.c
index c1775bd01c2b..a07e0b3d8d00 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/mcs.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/mcs.c
@@ -120,13 +120,13 @@ void mcs_get_rx_secy_stats(struct mcs *mcs, struct mcs_secy_stats *stats, int id
 	reg = MCSX_CSE_RX_MEM_SLAVE_INPKTSSECYUNTAGGEDX(id);
 	stats->pkt_untaged_cnt = mcs_reg_read(mcs, reg);
 
-	reg = MCSX_CSE_RX_MEM_SLAVE_INPKTSSECYCTLX(id);
-	stats->pkt_ctl_cnt = mcs_reg_read(mcs, reg);
-
 	if (mcs->hw->mcs_blks > 1) {
 		reg = MCSX_CSE_RX_MEM_SLAVE_INPKTSSECYNOTAGX(id);
 		stats->pkt_notag_cnt = mcs_reg_read(mcs, reg);
+		return;
 	}
+	reg = MCSX_CSE_RX_MEM_SLAVE_INPKTSSECYCTLX(id);
+	stats->pkt_ctl_cnt = mcs_reg_read(mcs, reg);
 }
 
 void mcs_get_flowid_stats(struct mcs *mcs, struct mcs_flowid_stats *stats,
-- 
2.48.1
Re: [PATCH net] octeontx2-af: mcs: Fix unsupported secy stats read
Posted by Simon Horman 4 days, 18 hours ago
From: 'Simon Horman' <horms@kernel.org>

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
Full review at: https://sashiko.dev
---
octeontx2-af: mcs: Fix unsupported secy stats read

This commit updates mcs_get_rx_secy_stats() to skip reading the Secy
control stats counter on CNF10KB platforms, since the register does
not exist.

> diff --git a/drivers/net/ethernet/marvell/octeontx2/af/mcs.c b/drivers/net/ethernet/marvell/octeontx2/af/mcs.c
> index c1775bd01c2b4..a07e0b3d8d000 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/af/mcs.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/af/mcs.c
> @@ -120,13 +120,13 @@ void mcs_get_rx_secy_stats(struct mcs *mcs, struct mcs_secy_stats *stats, int id
>  	reg = MCSX_CSE_RX_MEM_SLAVE_INPKTSSECYUNTAGGEDX(id);
>  	stats->pkt_untaged_cnt = mcs_reg_read(mcs, reg);
>  
> -	reg = MCSX_CSE_RX_MEM_SLAVE_INPKTSSECYCTLX(id);
> -	stats->pkt_ctl_cnt = mcs_reg_read(mcs, reg);
> -
>  	if (mcs->hw->mcs_blks > 1) {
>  		reg = MCSX_CSE_RX_MEM_SLAVE_INPKTSSECYNOTAGX(id);
>  		stats->pkt_notag_cnt = mcs_reg_read(mcs, reg);
> +		return;

[Severity: Medium]
Will this early return cause an uninitialized memory leak in debugfs?

In rvu_debugfs.c, rvu_dbg_mcs_rx_secy_stats_display() allocates the stats
structure on the stack without zero-initializing it, and passes it to
mcs_get_rx_secy_stats() to be populated.

Since the early return now skips setting stats->pkt_ctl_cnt, and the caller
unconditionally prints it via seq_printf(), could this result in leaking
uninitialized stack memory to userspace when the debugfs file is read?

>  	}
> +	reg = MCSX_CSE_RX_MEM_SLAVE_INPKTSSECYCTLX(id);
> +	stats->pkt_ctl_cnt = mcs_reg_read(mcs, reg);
>  }