mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net v4] octeontx2-af: Fix BPID leaks in NIX backpressure enable/disable
@ 2026-11-19  8:54 nshettyj
  2026-11-19  8:57 ` netdev-bot+sinfo
  2026-11-23  9:08 ` netdev-bot+sashiko
  0 siblings, 2 replies; 4+ messages in thread
From: nshettyj @ 2026-11-19  8:54 UTC (permalink / raw)
  To: netdev, linux-kernel
  Cc: Rakesh Kudurumalla, Nitin Shetty J, Sunil Goutham,
	Ratheesh Kannoth, Geetha sowjanya, Subbaraya Sundeep,
	Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman

From: Rakesh Kudurumalla <rkudurumalla@marvell.com>

For LBK interfaces, rvu_nix_get_bpid() allocates a BPID from the free
pool on every call. nix_bp_enable() called it once before the channel
loop and then again after programming each channel, including the last
one, so every NIX_BP_ENABLE request leaked one BPID whose result was
never used.

Fix the leak by allocating one BPID per programmed channel. Also fix
these related problems in nix_bp_enable() and nix_bp_disable():

- In nix_bp_enable(), allocate the BPIDs up front, before touching any
  channel register. If an allocation fails, release the LBK BPIDs
  obtained so far and return, leaving the channels unmodified.
- Report the BPID actually programmed for each channel in the
  response instead of deriving it from the first channel's BPID. LBK
  BPIDs come from a shared pool and need not be contiguous.
- In nix_bp_disable(), release only the BPID read back from the
  channel, and only if it lies in the LBK free pool and is owned by
  the requesting pcifunc. Previously the BPID was freed without a
  range check, and fn_map/ref_cnt were cleared for every BPID owned
  by the function, so FLR could no longer reclaim the rest.
- Iterate over chan_cnt with a counter instead of a u16 channel
  number, which wrapped and never terminated when chan_base +
  chan_cnt went past 0xFFFF.
- Reject requests whose channels fall outside the function's RX
  channels (NIX_BPIDS_PER_LMAC for CGX, rx_chan_cnt otherwise). LBK
  had no such check.
- Keep a request with chan_cnt == 0 a successful no-op that allocates
  nothing, as SDP VFs can legitimately have 0 rings.

The per-channel release logic is factored into nix_bp_free_lbk_bpid()
and nix_bp_chan_disable().

Fixes: d6212d2e41a0 ("octeontx2-af: Create BPIDs free pool")
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
Signed-off-by: Nitin Shetty J <nshettyj@marvell.com>
---
Changes in v4:
- Address Sashiko AI review comments on v3:
  https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928065718.3378580-1-nshettyj%40marvell.com
- nix_bp_enable(): allocate all BPIDs up front and program the channels
  afterwards. On failure only the LBK BPIDs obtained so far are
  released and the channels stay untouched. This replaces the v3
  nix_bp_enable_unwind(), which disabled already-programmed channels
- nix_bp_enable(): a request with chan_cnt == 0 is a successful no-op
  (rsp->chan_cnt = 0) again instead of returning
  NIX_AF_ERR_INVALID_BPID_REQ, since SDP VFs can have 0 rings
- nix_bp_enable() and nix_bp_disable(): iterate on a counter bounded by
  chan_cnt instead of a u16 channel number, which wrapped and never
  terminated when chan_base + chan_cnt went past 0xFFFF
- Reject requests whose channels go past the function's RX channels
  (NIX_BPIDS_PER_LMAC for CGX, rx_chan_cnt otherwise). LBK had no such
  check
- nix_bp_disable(): release only the BPID read from the channel, and
  only if it is in the LBK free pool and owned by the requesting
  pcifunc. v3 still cleared fn_map/ref_cnt for every BPID owned by
  the function, so FLR could not reclaim the rest
- Factor the per-channel release logic into nix_bp_free_lbk_bpid() and
  nix_bp_chan_disable()
- Use GENMASK_ULL() for the 64-bit channel config
- Reorder local variable declarations and update comments
- Expand the commit message to cover the above

Changes in v3:
- Address Sashiko AI review comments on v2:
  https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260910031604.1045397-1-nshettyj%40marvell.com
- Free allocated BPIDs on allocation failure in nix_bp_enable()
- Report the BPID written per channel instead of reconstructing it
- Validate the BPID range in nix_bp_disable() before freeing it

Changes in v2:
- Address Sashiko AI review comments on v1:
  https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260901102500.1534911-1-nshettyj%40marvell.com
- Move the rvu_nix_get_bpid() call for LBK from before the loop into
  the loop body
- Validate req->chan_cnt before allocating BPIDs
- Update commit message and Fixes tag
---
 .../ethernet/marvell/octeontx2/af/rvu_nix.c   | 128 +++++++++++++-----
 1 file changed, 91 insertions(+), 37 deletions(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c
index 199723d5ec94..274662086d2a 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c
@@ -599,18 +599,56 @@ static u16 nix_get_channel(u16 chan, bool cpt_link)
 	return cpt_link ? chan | BIT(11) : chan;
 }
 
+static void nix_bp_free_lbk_bpid(struct rvu *rvu, struct nix_bp *bp,
+				 u16 bpid, u16 pcifunc)
+{
+	int idx;
+
+	/* Skip channels never enabled (reset value 0) or not using an LBK bpid */
+	if (bpid < bp->free_pool_base ||
+	    bpid >= bp->free_pool_base + bp->bpids.max)
+		return;
+
+	idx = bpid - bp->free_pool_base;
+
+	/* Only release the bpid if it is owned by this function. */
+	mutex_lock(&rvu->rsrc_lock);
+	if (bp->fn_map[idx] == pcifunc) {
+		rvu_free_rsrc(&bp->bpids, idx);
+		bp->fn_map[idx] = 0;
+		bp->ref_cnt[idx] = 0;
+	}
+	mutex_unlock(&rvu->rsrc_lock);
+}
+
+static void nix_bp_chan_disable(struct rvu *rvu, struct nix_bp *bp,
+				int blkaddr, u16 chan, bool cpt_link,
+				int type, u16 pcifunc)
+{
+	u16 chan_v = nix_get_channel(chan, cpt_link);
+	u64 cfg;
+
+	cfg = rvu_read64(rvu, blkaddr, NIX_AF_RX_CHANX_CFG(chan_v));
+	rvu_write64(rvu, blkaddr, NIX_AF_RX_CHANX_CFG(chan_v),
+		    cfg & ~BIT_ULL(16));
+
+	if (type != NIX_INTF_TYPE_LBK)
+		return;
+
+	nix_bp_free_lbk_bpid(rvu, bp, cfg & GENMASK_ULL(8, 0), pcifunc);
+}
+
 static int nix_bp_disable(struct rvu *rvu,
 			  struct nix_bp_cfg_req *req,
 			  struct msg_rsp *rsp, bool cpt_link)
 {
 	u16 pcifunc = req->hdr.pcifunc;
 	int blkaddr, pf, type, err;
-	u16 chan_base, chan, bpid;
 	struct rvu_pfvf *pfvf;
 	struct nix_hw *nix_hw;
 	struct nix_bp *bp;
-	u16 chan_v;
-	u64 cfg;
+	u16 chan_base;
+	int i;
 
 	pf = rvu_get_pf(rvu->pdev, pcifunc);
 	type = is_lbk_vf(rvu, pcifunc) ? NIX_INTF_TYPE_LBK : NIX_INTF_TYPE_CGX;
@@ -629,26 +667,19 @@ static int nix_bp_disable(struct rvu *rvu,
 		return err;
 
 	bp = &nix_hw->bp;
-	chan_base = pfvf->rx_chan_base + req->chan_base;
-	for (chan = chan_base; chan < (chan_base + req->chan_cnt); chan++) {
-		chan_v = nix_get_channel(chan, cpt_link);
-		cfg = rvu_read64(rvu, blkaddr, NIX_AF_RX_CHANX_CFG(chan_v));
-		rvu_write64(rvu, blkaddr, NIX_AF_RX_CHANX_CFG(chan_v),
-			    cfg & ~BIT_ULL(16));
 
-		if (type == NIX_INTF_TYPE_LBK) {
-			bpid = cfg & GENMASK(8, 0);
-			mutex_lock(&rvu->rsrc_lock);
-			rvu_free_rsrc(&bp->bpids, bpid - bp->free_pool_base);
-			for (bpid = 0; bpid < bp->bpids.max; bpid++) {
-				if (bp->fn_map[bpid] == pcifunc) {
-					bp->fn_map[bpid] = 0;
-					bp->ref_cnt[bpid] = 0;
-				}
-			}
-			mutex_unlock(&rvu->rsrc_lock);
-		}
+	/* CGX may use up to NIX_BPIDS_PER_LMAC channels (PFC) */
+	if (type == NIX_INTF_TYPE_CGX) {
+		if ((u32)req->chan_base + req->chan_cnt > NIX_BPIDS_PER_LMAC)
+			return NIX_AF_ERR_INVALID_BPID_REQ;
+	} else if ((u32)req->chan_base + req->chan_cnt > pfvf->rx_chan_cnt) {
+		return NIX_AF_ERR_INVALID_BPID_REQ;
 	}
+
+	chan_base = pfvf->rx_chan_base + req->chan_base;
+	for (i = 0; i < req->chan_cnt; i++)
+		nix_bp_chan_disable(rvu, bp, blkaddr, chan_base + i, cpt_link,
+				    type, pcifunc);
 	return 0;
 }
 
@@ -750,13 +781,17 @@ static int nix_bp_enable(struct rvu *rvu,
 			 struct nix_bp_cfg_rsp *rsp,
 			 bool cpt_link)
 {
-	int blkaddr, pf, type, chan_id = 0;
 	u16 pcifunc = req->hdr.pcifunc;
 	struct rvu_pfvf *pfvf;
+	struct nix_hw *nix_hw;
+	int blkaddr, pf, type;
 	u16 chan_base, chan;
-	s16 bpid, bpid_base;
+	struct nix_bp *bp;
 	u16 chan_v;
+	s16 bpid;
 	u64 cfg;
+	int err;
+	int i;
 
 	pf = rvu_get_pf(rvu->pdev, pcifunc);
 	type = is_lbk_vf(rvu, pcifunc) ? NIX_INTF_TYPE_LBK : NIX_INTF_TYPE_CGX;
@@ -771,35 +806,54 @@ static int nix_bp_enable(struct rvu *rvu,
 	if (cpt_link && !rvu->hw->cpt_links)
 		return 0;
 
+	if (!req->chan_cnt) {
+		rsp->chan_cnt = 0;
+		return 0;
+	}
+
 	pfvf = rvu_get_pfvf(rvu, pcifunc);
-	blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NIX, pcifunc);
+	err = nix_get_struct_ptrs(rvu, pcifunc, &nix_hw, &blkaddr);
+	if (err)
+		return err;
+
+	bp = &nix_hw->bp;
+
+	/* CGX may use up to NIX_BPIDS_PER_LMAC channels (PFC) */
+	if (type == NIX_INTF_TYPE_CGX) {
+		if ((u32)req->chan_base + req->chan_cnt > NIX_BPIDS_PER_LMAC)
+			return NIX_AF_ERR_INVALID_BPID_REQ;
+	} else if ((u32)req->chan_base + req->chan_cnt > pfvf->rx_chan_cnt) {
+		return NIX_AF_ERR_INVALID_BPID_REQ;
+	}
 
-	bpid_base = rvu_nix_get_bpid(rvu, req, type, chan_id);
 	chan_base = pfvf->rx_chan_base + req->chan_base;
-	bpid = bpid_base;
 
-	for (chan = chan_base; chan < (chan_base + req->chan_cnt); chan++) {
+	/* Get all bpids first so a failure leaves the channels untouched */
+	for (i = 0; i < req->chan_cnt; i++) {
+		bpid = rvu_nix_get_bpid(rvu, req, type, i);
 		if (bpid < 0) {
 			dev_warn(rvu->dev, "Fail to enable backpressure\n");
+			if (type == NIX_INTF_TYPE_LBK)
+				while (i--)
+					nix_bp_free_lbk_bpid(rvu, bp,
+							     rsp->chan_bpid[i] & 0x3FF,
+							     pcifunc);
 			return -EINVAL;
 		}
 
+		rsp->chan_bpid[i] = ((req->chan_base + i) & 0x7F) << 10 |
+				    (bpid & 0x3FF);
+	}
+
+	for (i = 0; i < req->chan_cnt; i++) {
+		chan = chan_base + i;
+		bpid = rsp->chan_bpid[i] & 0x3FF;
 		chan_v = nix_get_channel(chan, cpt_link);
 
 		cfg = rvu_read64(rvu, blkaddr, NIX_AF_RX_CHANX_CFG(chan_v));
 		cfg &= ~GENMASK_ULL(8, 0);
 		rvu_write64(rvu, blkaddr, NIX_AF_RX_CHANX_CFG(chan_v),
 			    cfg | (bpid & GENMASK_ULL(8, 0)) | BIT_ULL(16));
-		chan_id++;
-		bpid = rvu_nix_get_bpid(rvu, req, type, chan_id);
-	}
-
-	for (chan = 0; chan < req->chan_cnt; chan++) {
-		/* Map channel and bpid assign to it */
-		rsp->chan_bpid[chan] = ((req->chan_base + chan) & 0x7F) << 10 |
-					(bpid_base & 0x3FF);
-		if (req->bpid_per_chan)
-			bpid_base++;
 	}
 	rsp->chan_cnt = req->chan_cnt;
 
-- 
2.53.0


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

* Re: [PATCH net v4] octeontx2-af: Fix BPID leaks in NIX backpressure enable/disable
  2026-11-19  8:54 [PATCH net v4] octeontx2-af: Fix BPID leaks in NIX backpressure enable/disable nshettyj
@ 2026-11-19  8:57 ` netdev-bot+sinfo
  2026-11-20  4:42   ` Nitin Shetty J
  2026-11-23  9:08 ` netdev-bot+sashiko
  1 sibling, 1 reply; 4+ messages in thread
From: netdev-bot+sinfo @ 2026-11-19  8:57 UTC (permalink / raw)
  To: nshettyj
  Cc: netdev, linux-kernel, Rakesh Kudurumalla, Sunil Goutham,
	Ratheesh Kannoth, Geetha sowjanya, Subbaraya Sundeep,
	Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

 - What hardware the change was tested on. For driver fixes please
   mention the device (and if relevant firmware version) used for
   testing, or say that the change was not tested on real hardware.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

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

* Re: [PATCH net v4] octeontx2-af: Fix BPID leaks in NIX backpressure enable/disable
  2026-11-19  8:57 ` netdev-bot+sinfo
@ 2026-11-20  4:42   ` Nitin Shetty J
  0 siblings, 0 replies; 4+ messages in thread
From: Nitin Shetty J @ 2026-11-20  4:42 UTC (permalink / raw)
  To: netdev-bot+sinfo
  Cc: netdev, linux-kernel, Rakesh Kudurumalla, Sunil Goutham,
	Ratheesh Kannoth, Geetha sowjanya, Subbaraya Sundeep,
	Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman

On 2026-11-19 at 14:27:59, netdev-bot+sinfo@kernel.org (netdev-bot+sinfo@kernel.org) wrote:
> Hi!
> 
> This is an automated message. This series looks like a fix, but its
> commit messages seem to be missing some information:
> 
>  - How the issue was discovered, e.g. hit in production, hit during
>    development, syzbot report, manual code inspection, LLM or static
>    analysis tool scan.
> 
>  - Whether the issue was actually triggered, or is only theoretical
>    (e.g. found by LLM and not proven at runtime). If it was triggered
>    please include the symptoms, like the stack trace or kernel messages.
> 
>  - What hardware the change was tested on. For driver fixes please
>    mention the device (and if relevant firmware version) used for
>    testing, or say that the change was not tested on real hardware.
> 
> Please do not repost the series just to address the above. Instead,
> reply to this email with the missing information, so that reviewers
> can take it into account.
> 
> *IMPORTANT*: If you do repost (for other reasons) - please include
> the relevant info in the cover letter or commit messages.
> -- 
> The evaluation is done by an LLM so it may be wrong, if you think
> that is the case please reply and explain.

The original issue of calling rvu_nix_get_bpid() after the last channel
is programmed was found during internal code review the same is tested
on CN10K silicon. The other code changes in the patch were added to
address Sashiko AI review comments and compile tested only.

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

* Re: [PATCH net v4] octeontx2-af: Fix BPID leaks in NIX backpressure enable/disable
  2026-11-19  8:54 [PATCH net v4] octeontx2-af: Fix BPID leaks in NIX backpressure enable/disable nshettyj
  2026-11-19  8:57 ` netdev-bot+sinfo
@ 2026-11-23  9:08 ` netdev-bot+sashiko
  1 sibling, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23  9:08 UTC (permalink / raw)
  To: nshettyj
  Cc: netdev, linux-kernel, rkudurumalla, sgoutham, rkannoth, gakula,
	sbhatta, andrew+netdev, davem, edumazet, kuba, pabeni, horms

Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 3 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The new channel range checks in nix_bp_disable()
  (rvu_nix.c:672-677) and nix_bp_enable() (rvu_nix.c:822-827) validate…
- [Medium] nix_bp_enable() (rvu_nix.c:832-857) still leaks an LBK BPID
  whenever NIX_BP_ENABLE or NIX_CPT_BP_ENABLE is sent for a channel that…
- [Medium] nix_bp_chan_disable() (rvu_nix.c:624-639) passes 'cfg &
  GENMASK_ULL(8, 0)' to nix_bp_free_lbk_bpid() without checking that…
- [Medium] nix_bp_enable() now saves each allocated BPID in
  rsp->chan_bpid[i] (line 844) and later reads it back from rsp to…
- [Low] The commit message undersells one of the problems this patch
  fixes.

--

octeontx2-af: Fix BPID leaks in NIX backpressure enable/disable

This patch reworks nix_bp_enable() and nix_bp_disable() so that LBK BPIDs
are allocated up front, one per programmed channel. On disable, a BPID is
released per channel, and only when it is in the LBK pool and owned by the
requester. It also adds channel range checks against the function's RX
channels and iterates with a counter bounded by chan_cnt.

> octeontx2-af: Fix BPID leaks in NIX backpressure enable/disable

[ ... ]

>     - In nix_bp_disable(), release only the BPID read back from the
>       channel, and only if it lies in the LBK free pool and is owned by
>       the requesting pcifunc. Previously the BPID was freed without a
>       range check, and fn_map/ref_cnt were cleared for every BPID owned
>       by the function, so FLR could no longer reclaim the rest.

[Severity: Low]
This isn't a bug in the new code, but does the commit message undersell
what the missing range check allowed?

In the old nix_bp_disable(), an LBK channel whose BPID field was below
bp->free_pool_base reached this call directly. That includes the reset
value 0, which the new comment in nix_bp_free_lbk_bpid() names:

    rvu_free_rsrc(&bp->bpids, bpid - bp->free_pool_base);

Both operands are promoted to int, so the id is negative. rvu_free_rsrc()
then passes it to __clear_bit(id, rsrc->bmap). That is an out-of-bounds
bitmap write in the AF mbox handler, not a leak.

The in-tree path reaches it. otx2_init_hw_resources() sends
NIX_CPT_BP_DISABLE on every open, including from LBK VFs, and this call
has no !is_otx2_lbkvf() guard, unlike the NIX_BP_* calls next to it:

    /* Default disable backpressure on NIX-CPT */
    otx2_nix_cpt_config_bp(pf, false);

Any LBK VF can also send NIX_BP_DISABLE without a prior enable.

Could the subject and changelog say that this fixes an out-of-bounds write
a VF can trigger? That would help with stable selection.

> diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c
> index 199723d5ec947..274662086d2a9 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c
> @@ -599,18 +599,56 @@ static u16 nix_get_channel(u16 chan, bool cpt_link)
>  	return cpt_link ? chan | BIT(11) : chan;
>  }
>  
> +static void nix_bp_free_lbk_bpid(struct rvu *rvu, struct nix_bp *bp,
> +				 u16 bpid, u16 pcifunc)
> +{
> +	int idx;
> +
> +	/* Skip channels never enabled (reset value 0) or not using an LBK bpid */
> +	if (bpid < bp->free_pool_base ||
> +	    bpid >= bp->free_pool_base + bp->bpids.max)
> +		return;
> +
> +	idx = bpid - bp->free_pool_base;
> +
> +	/* Only release the bpid if it is owned by this function. */
> +	mutex_lock(&rvu->rsrc_lock);
> +	if (bp->fn_map[idx] == pcifunc) {
> +		rvu_free_rsrc(&bp->bpids, idx);
> +		bp->fn_map[idx] = 0;
> +		bp->ref_cnt[idx] = 0;
> +	}
> +	mutex_unlock(&rvu->rsrc_lock);
> +}
> +
> +static void nix_bp_chan_disable(struct rvu *rvu, struct nix_bp *bp,
> +				int blkaddr, u16 chan, bool cpt_link,
> +				int type, u16 pcifunc)
> +{
> +	u16 chan_v = nix_get_channel(chan, cpt_link);
> +	u64 cfg;
> +
> +	cfg = rvu_read64(rvu, blkaddr, NIX_AF_RX_CHANX_CFG(chan_v));
> +	rvu_write64(rvu, blkaddr, NIX_AF_RX_CHANX_CFG(chan_v),
> +		    cfg & ~BIT_ULL(16));
> +
> +	if (type != NIX_INTF_TYPE_LBK)
> +		return;
> +
> +	nix_bp_free_lbk_bpid(rvu, bp, cfg & GENMASK_ULL(8, 0), pcifunc);

[Severity: Medium]
Can this free a BPID that is still programmed on another channel?

Disable clears only BIT_ULL(16) and leaves the old BPID in bits 8:0. The
free here does not check whether BIT_ULL(16) was set in cfg.
nix_bp_free_lbk_bpid() then checks fn_map[idx] == pcifunc, which is
ownership by function, not by channel.

Here is a sequence from one LBK VF A on hardware with cpt_links:

  NIX_BP_ENABLE      RX chan CFG = X | BIT16, fn_map[X] = A
  NIX_BP_DISABLE     RX chan CFG = X, X freed, fn_map[X] = 0
  NIX_CPT_BP_ENABLE  X is the lowest free index again,
                     CPT chan CFG = X | BIT16, fn_map[X] = A
  NIX_BP_DISABLE     reads stale X from the RX chan, fn_map[X] == A,
                     so X is freed

X is now free while A's CPT channel still uses it. The next LBK
allocation by another VF gets X, and the two functions share one
backpressure ID.

The same can happen after FLR. rvu_nix_flr_free_bpids() frees by fn_map
only and never touches NIX_AF_RX_CHANX_CFG. The channel keeps its stale
BPID with BIT16 still set, and a later disable of that channel frees an
index that may have been given to another channel of the same function.

Should the release depend on BIT_ULL(16) having been set, so that a stale
BPID field is not treated as a live mapping?

> +}
> +

[ ... ]

> @@ -629,26 +667,19 @@ static int nix_bp_disable(struct rvu *rvu,
>  		return err;
>  
>  	bp = &nix_hw->bp;

[ ... ]

> +	/* CGX may use up to NIX_BPIDS_PER_LMAC channels (PFC) */
> +	if (type == NIX_INTF_TYPE_CGX) {
> +		if ((u32)req->chan_base + req->chan_cnt > NIX_BPIDS_PER_LMAC)
> +			return NIX_AF_ERR_INVALID_BPID_REQ;
> +	} else if ((u32)req->chan_base + req->chan_cnt > pfvf->rx_chan_cnt) {
> +		return NIX_AF_ERR_INVALID_BPID_REQ;
>  	}
> +
> +	chan_base = pfvf->rx_chan_base + req->chan_base;
> +	for (i = 0; i < req->chan_cnt; i++)
> +		nix_bp_chan_disable(rvu, bp, blkaddr, chan_base + i, cpt_link,
> +				    type, pcifunc);

[Severity: High]
Can a requester get past this new range check by changing req->chan_cnt
after it has been checked?

req lives in the BAR4 mailbox region shared with the PF/VF. The loop
condition reads req->chan_cnt again on every iteration. The loop body does
readq()/writeq() (and mutex_lock() for LBK), so the compiler cannot keep
the checked value in a register.

An LBK VF has an rx_chan_cnt of 1. It can pass the check with
chan_cnt = 1 and then rewrite chan_cnt to 255 while the loop runs. The AF
would then clear BIT(16) on up to 254 neighbouring channels owned by other
functions.

nix_bp_enable() has the same pattern. Both of its loops, and
rvu_nix_get_bpid(), read req->chan_base and req->chan_cnt again after the
check. There, one request could drain the shared LBK pool, and the
programming loop could set BIT(16) with the requester's BPIDs on other
functions' channels.

req->chan_base is also read again after the check. If the compiler does
not merge that load with the first one and the race is won, chan_v can
exceed 0x1FFF. With:

    #define NIX_AF_RX_CHANX_CFG(a)                  (0x1A30 | (a) << 15)

bits 28-30 then get set. rvu_write64() ORs the offset into (block << 28),
so the read-modify-write could land in another AF block's registers.

Processing mbox requests in place is common in this driver, and there was
no check at all before this patch, so this patch does narrow the exposure.
Still, the commit message says these out-of-range requests are now
rejected.

Would it work to copy chan_base and chan_cnt into locals, validate them
once, and use the locals in the loops and in rvu_nix_get_bpid()?

>  	return 0;
>  }

[ ... ]

> @@ -771,35 +806,54 @@ static int nix_bp_enable(struct rvu *rvu,

[ ... ]

>  	chan_base = pfvf->rx_chan_base + req->chan_base;
> -	bpid = bpid_base;
>  
> -	for (chan = chan_base; chan < (chan_base + req->chan_cnt); chan++) {
> +	/* Get all bpids first so a failure leaves the channels untouched */
> +	for (i = 0; i < req->chan_cnt; i++) {
> +		bpid = rvu_nix_get_bpid(rvu, req, type, i);
>  		if (bpid < 0) {
>  			dev_warn(rvu->dev, "Fail to enable backpressure\n");
> +			if (type == NIX_INTF_TYPE_LBK)
> +				while (i--)
> +					nix_bp_free_lbk_bpid(rvu, bp,
> +							     rsp->chan_bpid[i] & 0x3FF,
> +							     pcifunc);
>  			return -EINVAL;
>  		}
>  
> +		rsp->chan_bpid[i] = ((req->chan_base + i) & 0x7F) << 10 |
> +				    (bpid & 0x3FF);
> +	}
> +
> +	for (i = 0; i < req->chan_cnt; i++) {
> +		chan = chan_base + i;
> +		bpid = rsp->chan_bpid[i] & 0x3FF;

[Severity: Medium]
Is it safe to read the BPID back from rsp here?

rsp comes from otx2_mbox_alloc_msg() in rvu_process_mbox_msg(). It sits in
the mailbox region that rvu_get_mbox_regions() maps from the PF/VF BAR4:

    mbox_addr[region] = ioremap_wc(bar4, MBOX_SIZE);

The requesting function can therefore rewrite rsp->chan_bpid[i] between
the allocation loop and this loop. The window includes a
mutex_lock()/mutex_unlock() for every LBK allocation.

If that happens, the AF writes whatever 9-bit BPID the function chose into
NIX_AF_RX_CHANX_CFG, bypassing the allocation and range checks in
rvu_nix_get_bpid(). Disable frees whatever it reads back from the channel,
so the BPIDs that were actually allocated are never freed.

The error unwind above has the same problem. It frees whatever values are
in rsp->chan_bpid[i], not the BPIDs that were allocated.

Before this patch, the programmed BPID came from a local variable and rsp
was only written. Could the allocated BPIDs be kept in a local array, with
rsp only written from it?

>  		chan_v = nix_get_channel(chan, cpt_link);
>  
>  		cfg = rvu_read64(rvu, blkaddr, NIX_AF_RX_CHANX_CFG(chan_v));
>  		cfg &= ~GENMASK_ULL(8, 0);
>  		rvu_write64(rvu, blkaddr, NIX_AF_RX_CHANX_CFG(chan_v),
>  			    cfg | (bpid & GENMASK_ULL(8, 0)) | BIT_ULL(16));

[Severity: Medium]
Does this still leak an LBK BPID when backpressure is already on for the
channel?

For LBK, rvu_nix_get_bpid() always takes a new bit from bp->bpids and sets
fn_map/ref_cnt. This loop then overwrites the BPID field without checking
BIT_ULL(16) and without releasing the BPID that was there.

After enable (gets X), enable (gets Y), then disable,
nix_bp_chan_disable() reads back only Y and frees it. X stays allocated
until rvu_nix_flr_free_bpids() runs on FLR.

One LBK VF can repeat NIX_BP_ENABLE until the shared LBK pool is empty.
After that, rvu_nix_get_bpid() returns NIX_AF_ERR_INVALID_BPID for every
other LBK VF.

The subject says "Fix BPID leaks in NIX backpressure enable/disable".
Should the enable path check for an already enabled BPID owned by this
pcifunc before allocating a new one?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119085434.2598197-1-nshettyj%40marvell.com

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

end of thread, other threads:[~2026-11-23  9:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19  8:54 [PATCH net v4] octeontx2-af: Fix BPID leaks in NIX backpressure enable/disable nshettyj
2026-11-19  8:57 ` netdev-bot+sinfo
2026-11-20  4:42   ` Nitin Shetty J
2026-11-23  9:08 ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®