[PATCH] soc: fsl: qbman: fix race between finding and filling an RCR entry

From: Vladimir Oltean

Date: Fri Dec 04 2026 - 10:18:40 EST


Software interacts with the BMan through a thing called Software Portal
(struct bm_portal). There are enough such portals that the driver keeps one
affine to each CPU, and the locking scheme is such that get_affine_portal()
calls get_cpu_var() (this disables task preemption and thus migration) and
local_irq_save() avoids hardirq/softirq context from trying to acquire the same
portal, resulting in a deadlock. The created context ensures nobody else may
concurrently interact with the portal as long as they keep using the same
affine scheme.

One of the things that the BMan software portal contains is the Release Command
Ring (RCR) with 8 entries, used by bman_release(). Software is the producer and
QMan the consumer, so bman_release() has logic to wait for rcr->available to be
updated, indicating that the ring may hold the new RCR entry. If the RCR is not
available, bman_release() relinquishes the software portal before retrying. If
available, bm_rcr_start() gives the RCR entry that is available for writing.

The problem is that bman_release() relinquishes the software portal even if a
RCR entry is available, to quickly re-enter another atomic section which
actually performs the RCR write outside the "do {} while (--timeout)" loop.

In the window between the first and the second atomic sections, another
bman_release() call on the same software portal can run concurrently (the
calling context may be from the task that runs dpaa_eth_probe() -> ... ->
dpaa_bp_seed(), so both preemptible and interruptible). This second
bman_release() will find the same RCR entry "r" to be available, as returned by
bm_rcr_start().

The preempt/interrupt train can continue ad infinitum, but let's assume the
second bman_release() call, which interrupted the first, manages to enter the
second critical section, populate and commit the RCR entry. bm_rcr_pvb_commit()
increments rcr->cursor by calling rcr_inc().

Execution resumes in the first bman_release() context, and this still has a hold
on the 'r' local variable (representing a RCR entry already committed). What's
really problematic is that bm_rcr_pvb_commit() does not take this 'r' local
variable, but it re-reads rcr->cursor, which was already advanced earlier
rcr_inc()!!

So a RCR entry that nobody wrote anything valid to got committed to BMan.

If the race condition happens quickly after boot (like, during the first 8
dpaa_bp_add_8_bufs() calls), the rcr->cursor committed by the preempted
bman_release() call will probably be all zeroes, so this will release 8 buffers
with address zero to BMan. If the race happens later than that, the stale
contents of rcr->cursor, from 8 bman_release() calls ago, will be recommitted
to BMan, resulting in even more hard-to-debug chaos.

The fix seems to be rather simple: if bm_rcr_start() gave us a valid RCR entry,
keep a tight grip onto the atomic context until we commit it to hardware. No
two-step nonsense. The vaguely-similar-in-principle qman_enqueue() does the
same thing when "eq" is non-NULL.

Fixes: 1f9c0a77278b ("soc/fsl: Introduce DPAA 1.x BMan device driver")
Signed-off-by: Vladimir Oltean <vladimir.oltean@xxxxxxx>
---
drivers/soc/fsl/qbman/bman.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/soc/fsl/qbman/bman.c b/drivers/soc/fsl/qbman/bman.c
index f22eff294122..d929c2ce8a5e 100644
--- a/drivers/soc/fsl/qbman/bman.c
+++ b/drivers/soc/fsl/qbman/bman.c
@@ -752,19 +752,17 @@ int bman_release(struct bman_pool *pool, const struct bm_buffer *bufs, u8 num)
if (avail < 2)
update_rcr_ci(p, avail);
r = bm_rcr_start(&p->p);
- local_irq_restore(irqflags);
- put_affine_portal();
if (likely(r))
break;

+ local_irq_restore(irqflags);
+ put_affine_portal();
udelay(1);
} while (--timeout);

if (unlikely(!timeout))
return -ETIMEDOUT;

- p = get_affine_portal();
- local_irq_save(irqflags);
/*
* we can copy all but the first entry, as this can trigger badness
* with the valid-bit
--
2.53.0
------------------------ >8 ------------------------