octeontx2-af: npc: cn20k: Fix subbank free list indexing for search order
Ratheesh Kannoth
maintainerPATCH v2 1/1 octeontx2-af: npc: cn20k: Fix subbank free list indexing for search order
subbank_srch_order[i] is the physical subbank at search-order slot i, so each subbank's arr_idx must be i (its slot), not subbank_srch_order[sb->idx]. The old logic mis-keyed xa_sb_free and broke allocation traversal order.
Populate arr_idx and xa_sb_free in a single pass over the search order after subbank structs are initialized.
---
v1 -> v2: Addressed simon comments
https://lore.kernel.org/netdev/[email protected]/ --- .../ethernet/marvell/octeontx2/af/cn20k/npc.c | 51 ++++++++++++++----- 1 file changed, 39 insertions(+), 12 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +39 -12
@@ -3423,6 +3423,36 @@ static int npc_create_srch_order(int cnt)return 0 ; } +static int npc_subbanks_srch_order_init (struct rvu *rvu) +{ +struct npc_subbank *sb; +int sb_idx; +int i, j; +int rc; + +for (i =0 ; i < npc_priv->num_subbanks; i++) { + sb_idx = subbank_srch_order[i]; + sb = &npc_priv->sb[sb_idx]; + sb->arr_idx = i; + +dev_dbg (rvu->dev,"%s: sb->idx=%u sb->arr_idx=%u\n" , + __func__, sb->idx, sb->arr_idx); + + rc =xa_err (xa_store (&npc_priv->xa_sb_free, sb->arr_idx, +xa_mk_value (sb->idx),GFP_KERNEL )); +if (rc) { +dev_err (rvu->dev, +"%s: xa_store(xa_sb_free) failed at slot %d (sb=%d): %d\n" , + __func__, i, sb_idx, rc); +for (j =0 ; j < i; j++) +xa_erase (&npc_priv->xa_sb_free, j); +return rc; + } + } + +return 0 ; +} +static void npc_subbank_init (struct rvu *rvu,struct npc_subbank *sb,int idx) {mutex_init (&sb->lock);
@@ -3435,16 +3465,6 @@ static void npc_subbank_init(struct rvu *rvu, struct npc_subbank *sb, int idx) sb->flags =NPC_SUBBANK_FLAG_FREE ; sb->idx = idx; - sb->arr_idx = subbank_srch_order[idx]; - -dev_dbg (rvu->dev,"%s: sb->idx=%u sb->arr_idx=%u\n" , - __func__, sb->idx, sb->arr_idx); - -/* Keep first and last subbank at end of free array; so that -* it will be used at last -*/ -xa_store (&npc_priv->xa_sb_free, sb->arr_idx, -xa_mk_value (sb->idx),GFP_KERNEL ); }static int npc_pcifunc_map_create (struct rvu *rvu)
@@ -4635,6 +4655,7 @@ static int npc_priv_init(struct rvu *rvu)int num_subbanks, subbank_depth;u64 npc_const1, npc_const2 =0 ;struct npc_subbank *sb; +int ret = -ENOMEM ;u64 cfg;int i;
@@ -4727,13 +4748,19 @@ static int npc_priv_init(struct rvu *rvu)for (i =0 , sb = npc_priv->sb; i < num_subbanks; i++, sb++)npc_subbank_init (rvu, sb, i); + ret =npc_subbanks_srch_order_init (rvu); +if (ret) + goto fail3; +/* Get number of pcifuncs in the system */ npc_priv->pf_cnt =npc_pcifunc_map_create (rvu); npc_priv->xa_pf2idx_map =kcalloc (npc_priv->pf_cnt,sizeof (struct xarray ),GFP_KERNEL ); -if (!npc_priv->xa_pf2idx_map) +if (!npc_priv->xa_pf2idx_map) { + ret = -ENOMEM ; goto fail3; + }for (i =0 ; i < npc_priv->pf_cnt; i++)xa_init_flags (&npc_priv->xa_pf2idx_map[i],XA_FLAGS_ALLOC );
@@ -4760,7 +4787,7 @@ static int npc_priv_init(struct rvu *rvu) fail1:kfree (npc_priv); npc_priv =NULL ; -return -ENOMEM ; +return ret; }void npc_cn20k_deinit (struct rvu *rvu)
Signature · 1 line
2.43.0
Quoted 8 lines · Ratheesh Kannoth
subbank_srch_order[i] is the physical subbank at search-order slot i, so each subbank's
arr_idxmust be i (its slot), not subbank_srch_order[sb->idx]. The old logic mis-keyedxa_sb_freeand broke allocation traversal order.Populate
arr_idxandxa_sb_freein a single pass over the search order after subbank structs are initialized.
Quoted 6 lines
Fixes 7ac9d4c4075c ("octeontx2-af: npc: cn20k: add subbank search order control")Signed-off-by Ratheesh Kannoth <[email protected]>---
v1 -> v2: Addressed simon commentshttps://lore.kernel.org/netdev/[email protected]/
Thanks for the update.
FTR, I think the issue flagged in the AI-generated review of this patch on sashiko.org can be treated in the context of possible follow-up. I don' think it should impede the progress of this patch.
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 9 lines · On Fri, 19 Jun 2026 15:21:00 +0530 you wrote:
subbank_srch_order[i] is the physical subbank at search-order slot i, so each subbank's
arr_idxmust be i (its slot), not subbank_srch_order[sb->idx]. The old logic mis-keyedxa_sb_freeand broke allocation traversal order.Populate
arr_idxandxa_sb_freein a single pass over the search order after subbank structs are initialized.[...]
Here is the summary with links:
- [net,v2] octeontx2-af: npc: cn20k: Fix subbank free list indexing for search order
https://git.kernel.org/netdev/net/c/429ef02895db
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html