From: Paolo Abeni <pabeni@redhat.com>
To: rkannoth@marvell.com
Cc: jiri@resnulli.us, cjubran@nvidia.com, edumazet@google.com,
mbloch@nvidia.com, kuba@kernel.org, horms@kernel.org,
sgoutham@marvell.com, dtatulea@nvidia.com, pabeni@redhat.com,
saeedm@nvidia.com, matttbe@kernel.org, chuck.lever@oracle.com,
tariqt@nvidia.com, linux-rdma@vger.kernel.org,
andrew+netdev@lunn.ch, donald.hunter@gmail.com,
netdev@vger.kernel.org, leon@kernel.org, davem@davemloft.net,
linux-kernel@vger.kernel.org
Subject: Re: [v9,net-next,5/6] octeontx2-af: npc: cn20k: dynamically allocate and free default MCAM entries
Date: Thu, 2 Apr 2026 10:48:40 +0200 [thread overview]
Message-ID: <20260402084840.128387-1-pabeni@redhat.com> (raw)
In-Reply-To: <20260330053105.2722453-6-rkannoth@marvell.com>
This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
octeontx2-af: npc: cn20k: dynamically allocate and free default MCAM entries
Improve MCAM utilization by tying default (broadcast, multicast,
promisc, ucast) entry lifetime to NIX LF usage. On NIX LF alloc,
allocate default MCAM entries if missing; on NIX LF free, release
them so they return to the pool.
> diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c
> index ef5b081162eb..1f2128c61ade 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c
[ ... ]
> @@ -1566,8 +1567,8 @@ int rvu_mbox_handler_nix_lf_alloc(struct rvu *rvu,
>
> /* Alloc NIX RQ HW context memory and config the base */
> hwctx_size = 1UL << ((ctx_cfg >> 4) & 0xF);
> - err = qmem_alloc(rvu->dev, &pfvf->rq_ctx, req->rq_cnt, hwctx_size);
> - if (err)
> + rc = qmem_alloc(rvu->dev, &pfvf->rq_ctx, req->rq_cnt, hwctx_size);
> + if (rc)
> goto free_mem;
>
> pfvf->rq_bmap = kcalloc(req->rq_cnt, sizeof(long), GFP_KERNEL);
> @@ -1583,8 +1584,8 @@ int rvu_mbox_handler_nix_lf_alloc(struct rvu *rvu,
>
> /* Alloc NIX SQ HW context memory and config the base */
> hwctx_size = 1UL << (ctx_cfg & 0xF);
> - err = qmem_alloc(rvu->dev, &pfvf->sq_ctx, req->sq_cnt, hwctx_size);
> - if (err)
> + rc = qmem_alloc(rvu->dev, &pfvf->sq_ctx, req->sq_cnt, hwctx_size);
> + if (rc)
> goto free_mem;
>
> pfvf->sq_bmap = kcalloc(req->sq_cnt, sizeof(long), GFP_KERNEL);
> @@ -1599,8 +1600,8 @@ int rvu_mbox_handler_nix_lf_alloc(struct rvu *rvu,
>
> /* Alloc NIX CQ HW context memory and config the base */
> hwctx_size = 1UL << ((ctx_cfg >> 8) & 0xF);
> - err = qmem_alloc(rvu->dev, &pfvf->cq_ctx, req->cq_cnt, hwctx_size);
> - if (err)
> + rc = qmem_alloc(rvu->dev, &pfvf->cq_ctx, req->cq_cnt, hwctx_size);
> + if (rc)
> goto free_mem;
>
> pfvf->cq_bmap = kcalloc(req->cq_cnt, sizeof(long), GFP_KERNEL);
[ ... ]
> @@ -1699,9 +1706,12 @@ int rvu_mbox_handler_nix_lf_alloc(struct rvu *rvu,
>
> goto exit;
>
> +free_dft:
> + if (is_cn20k(rvu->pdev))
> + npc_cn20k_dft_rules_free(rvu, pcifunc);
> +
> free_mem:
> nix_ctx_free(rvu, pfvf);
> - rc = -ENOMEM;
>
> exit:
> /* Set macaddr of this PF/VF */
Does the removal of `rc = -ENOMEM;` cause the function to return success
when kcalloc() fails?
Looking at the kcalloc calls for rq_bmap, sq_bmap, and cq_bmap:
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c:rvu_mbox_handler_nix_lf_alloc() {
...
rc = qmem_alloc(rvu->dev, &pfvf->rq_ctx, req->rq_cnt, hwctx_size);
if (rc)
goto free_mem;
pfvf->rq_bmap = kcalloc(req->rq_cnt, sizeof(long), GFP_KERNEL);
if (!pfvf->rq_bmap)
goto free_mem;
...
}
These three kcalloc failure paths reach free_mem with rc == 0 because the
preceding qmem_alloc() succeeded and set rc = 0. Previously, the code set
rc = -ENOMEM at the free_mem label, ensuring that any path reaching it
would return an error.
With the removal of this assignment, don't these paths now fall through
to exit: and return rc == 0, falsely indicating success?
The caller would believe NIX LF allocation succeeded with a partially
torn-down pfvf structure (NULL bitmaps, freed contexts), potentially
leading to NULL pointer dereferences on subsequent NIX LF operations.
Should the kcalloc failure paths set rc = -ENOMEM before jumping to
free_mem?
next prev parent reply other threads:[~2026-04-02 8:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-30 5:30 [PATCH v9 net-next 0/6] octeontx2-af: npc: Enhancements Ratheesh Kannoth
2026-03-30 5:31 ` [PATCH v9 net-next 1/6] octeontx2-af: npc: cn20k: debugfs enhancements Ratheesh Kannoth
2026-03-30 5:31 ` [PATCH v9 net-next 2/6] net/mlx5e: heap-allocate devlink param values Ratheesh Kannoth
2026-03-30 5:31 ` [PATCH v9 net-next 3/6] devlink: Implement devlink param multi attribute nested data values Ratheesh Kannoth
2026-03-30 5:31 ` [PATCH v9 net-next 4/6] octeontx2-af: npc: cn20k: add subbank search order control Ratheesh Kannoth
2026-03-30 5:31 ` [PATCH v9 net-next 5/6] octeontx2-af: npc: cn20k: dynamically allocate and free default MCAM entries Ratheesh Kannoth
2026-04-02 8:48 ` Paolo Abeni [this message]
2026-03-30 5:31 ` [PATCH v9 net-next 6/6] octeontx2-af: npc: Support for custom KPU profile from filesystem Ratheesh Kannoth
2026-04-02 8:54 ` Paolo Abeni
2026-04-03 2:05 ` Ratheesh Kannoth
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=20260402084840.128387-1-pabeni@redhat.com \
--to=pabeni@redhat.com \
--cc=andrew+netdev@lunn.ch \
--cc=chuck.lever@oracle.com \
--cc=cjubran@nvidia.com \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=dtatulea@nvidia.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=matttbe@kernel.org \
--cc=mbloch@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=rkannoth@marvell.com \
--cc=saeedm@nvidia.com \
--cc=sgoutham@marvell.com \
--cc=tariqt@nvidia.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