Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Oltean <vladimir.oltean@nxp.com>
To: Anthony Pighin <anthony.pighin@nokia.com>
Cc: Madalin Bucur <madalin.bucur@nxp.com>,
	 "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
	Claudiu Manoil <claudiu.manoil@nxp.com>,
	 Camelia Groza <camelia.groza@nxp.com>,
	linuxppc-dev@lists.ozlabs.org,
	 linux-arm-kernel@lists.infradead.org, stable@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] soc: fsl: qbman: flush the private memory before enabling QMan and BMan
Date: Fri, 4 Dec 2026 19:06:03 +0200	[thread overview]
Message-ID: <axLVEuiVAv2MyZQi@lxl00025.wbi.nxp.com> (raw)
In-Reply-To: <20261204140329.2269842-1-anthony.pighin@nokia.com>

On Fri, Dec 04, 2026 at 09:03:29AM -0500, Anthony Pighin wrote:
> Hi Vladimir,
> 
> On Fri, Dec 04, 2026 at 12:35:23PM +0200, Vladimir Oltean wrote:
> > The fact is that I don't see how a zeroed FBPR could possibly fit your
> > symptoms.
> 
> You are right. I tested it on an LS1043A with a private pool (BPID 1)
> of 4096 dummy addresses. I rewrote one stored FBPR in DRAM through a
> non-cacheable mapping, then drained the pool, with EMCI masked in
> ERR_IER so its status stayed latched:
> 
>   FBPR rewrite                  zero addresses  EMCI  buffers lost
>   BP0-BP7 zeroed                8               no    0
>   BP0-BP7 and FBPR_BPA zeroed   0               yes   3200
>   BP0-BP7 and BPID zeroed       0               yes   2856
>   all 64 bytes zeroed           0               yes   2904
> 
> Each time, CEAR held the index of the FBPR I had rewritten. A zeroed
> FBPR drops the rest of the list and never yields zero addresses. The
> reproducer behind my commit message zeroed only BP0-BP7, which is the
> crafted case, so it does not support the field symptom. The BMan half
> of the patch has no basis, and I'll drop it.

If I'm right it also means your patch does not fix the bug you're
actually trying to track down, correct?

> > Did you ever reproduce this problem with the upstream driver
> > that you're patching?
> 
> We hit it with the upstream dpaa_eth driver (fsl_dpa). The oops was on
> v5.15.135. The NULL buffer log is from v6.6.52, after we added the
> check, which only drops and logs.
> 
> > You also didn't mention which interface was receiving traffic, and what
> > BPID it was using?
> 
> mgmt/eth0, which is fm1-mac3 and the only DPAA interface on the board.
> Its bpids file reads 0.
> 
> > To me, the more mundane explanation that
> > someone is handing buffers with address 0 to bman_release() seems
> > infinitely more likely than such an accidental corruption.
> 
> Releasing address 0 does reproduce the symptom, but not by any path I
> can match to the field log. One all-zero FD enqueued to mgmt/eth0's Rx
> error FQ gave:
> 
>   fsl_dpaa_mac 1ae4000.ethernet mgmt: Err FD status = 0x00000000
>   rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=590, status=0x4
> 
> dpaa_fd_release() put address 0 into pool 0, and FMan received the next
> frame into it. But that path logs "Err FD status" first, mgmt/eth0's
> message level includes hw, and the field log has only the NULL buffer
> lines. An all-zero FD on a Tx FQ was dropped without releasing
> anything. I have not found what released the zero addresses on the
> failing boot.

There is clearly a misunderstanding here. I never said an all-zero frame
descriptor. I said the buffer address is zero. They are not one and the
same data structure. The FD is a QMan data structure, and its ADDRESS
field may point towards the address of a buffer that FMan acquired from
BMan on RX, or to something else (system memory that was never in BMan; a
scatter/gather table, etc).

I have no idea what "one all-zero FD enqueued to mgmt/eth0's Rx error FQ"
means and therefore what you tested.

I meant that inside the struct bm_buffer that gets passed to bman_release(),
the "hi" and "lo" fields (in a union with "data") are zero. That was my
suspicion. This way, a buffer address of 0 enters the BMan BPID that
fm1-mac3 uses, and FMan will acquire this buffer address when it
receives frames. No all-zero frame descriptor involved - none is needed.
The important caller of bman_release() is dpaa_bp_add_8_bufs(), called
from dpaa_bp_seed() and dpaa_eth_refill_bpool(). I am ignoring the other
callers from dpaa_fd_release(), those are just some opportunistic buffer
recycling schemes added for received packets that are otherwise errored
and their underlying buffers shouldn't be delivered to the network
stack, so what else to do better with them than to send them back to
BMan right away, shunting the kernel memory allocator. I was never
suspecting these other call paths, as there would have been other signs
you would have noticed first.

Anyway, the explanation from the previous paragraph is irrelevant,
because what I didn't take into consideration in my previous email is
the fact that bman_release() itself may be buggy, not the caller. That
you may tell it to release a valid buffer address in the pool and it
puts zero instead. After reviewing bman_release() itself, that seems
even more likely.

I have a suspicion that your problem may be fixed by the patch below.
Please try.

------------------------ >8 ------------------------
From 59c6172e11768cf49f90232a97994392f503c133 Mon Sep 17 00:00:00 2001
From: Vladimir Oltean <vladimir.oltean@nxp.com>
Date: Fri, 4 Dec 2026 17:18:40 +0200
Subject: [PATCH] soc: fsl: qbman: fix race between finding and filling an RCR
 entry

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@nxp.com>
---
 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 ------------------------


  reply	other threads:[~2026-12-04 17:09 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 16:01 [PATCH] soc: fsl: qbman: flush the private memory before enabling QMan and BMan Anthony Pighin
2026-12-03 16:41 ` Madalin Bucur
2026-12-03 17:01   ` Vladimir Oltean
2026-12-03 18:59     ` Anthony Pighin
2026-12-03 21:52       ` Vladimir Oltean
2026-12-03 23:05         ` Anthony Pighin
2026-12-04 10:35           ` Vladimir Oltean
2026-12-04 14:03             ` Anthony Pighin
2026-12-04 17:06               ` Vladimir Oltean [this message]
2026-12-04 18:08                 ` Anthony Pighin
2026-12-04 20:49                   ` Vladimir Oltean
2026-12-03 19:14     ` Christophe Leroy (CS GROUP)

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=axLVEuiVAv2MyZQi@lxl00025.wbi.nxp.com \
    --to=vladimir.oltean@nxp.com \
    --cc=anthony.pighin@nokia.com \
    --cc=camelia.groza@nxp.com \
    --cc=chleroy@kernel.org \
    --cc=claudiu.manoil@nxp.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=madalin.bucur@nxp.com \
    --cc=stable@vger.kernel.org \
    /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