Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] soc: fsl: qbman: flush the private memory before enabling QMan and BMan
@ 2026-12-03 16:01 Anthony Pighin
  2026-12-03 16:41 ` Madalin Bucur
  0 siblings, 1 reply; 12+ messages in thread
From: Anthony Pighin @ 2026-12-03 16:01 UTC (permalink / raw)
  To: Christophe Leroy (CS GROUP)
  Cc: Madalin Bucur, Claudiu Manoil, Camelia Groza, linuxppc-dev,
	linux-arm-kernel, stable

QMan and BMan do not snoop the CPU caches when accessing their private
memory (FQD, PFDR and FBPR). The LS1043A DPAA reference manual describes
these as non-coherent regions owned by QMan and BMan, and says that BMan
starts writing its free list as soon as FBPR_AR[SIZE] is set.

On arm64 the driver never cleans the FBPR area from the CPU caches, so
stale dirty lines remain there. A line written back after BMan has
stored an FBPR at that address overwrites it. A zeroed FBPR yields eight
zero-address buffers and loses the link to the next one, truncating the
pool. A frame received into such a buffer crashes the DPAA Ethernet
driver (x4 is phys_to_virt(0)):

  Unable to handle kernel paging request at virtual address ffff4bcd800000f8
  Internal error: Oops: 96000005 [#1] PREEMPT SMP
  pc : rx_default_dqrr+0x30c/0x530 [fsl_dpa]
  lr : rx_default_dqrr+0x2fc/0x530 [fsl_dpa]
  x5 : 0000000000000000 x4 : ffff4bcd80000000 x3 : ffffdec2e49fe008
  Call trace:
   rx_default_dqrr+0x30c/0x530 [fsl_dpa]
   __poll_portal_fast+0x190/0x1b0
   qman_p_poll_dqrr+0x1c/0x30
   dpaa_eth_poll+0x30/0xc0 [fsl_dpa]
  PHYS_OFFSET: 0xffffb43280000000

Commit 97777078d695 ("soc/fsl/qbman: Rework QBMan private memory setup")
started zeroing FQD and PFDR through a cacheable mapping and flushed it
because QMan's accesses are non-coherent, but only on PPC. On arm64,
memunmap() leaves the dirty lines in place, so QMan is also exposed.

This was reproduced on an LS1043A by dirtying a line over a record that
BMan had just written, letting it be written back and acquiring the
buffers again. Groups of eight zero-address buffers came back and the
pool chain was cut short.

Clean and invalidate the private memory to the point of coherency before
handing it to QMan or BMan, on arm64 as well as PPC.

Fixes: e868adf21c0a ("soc/fsl/qbman: Enable FSL_LAYERSCAPE config on ARM")
Fixes: 97777078d695 ("soc/fsl/qbman: Rework QBMan private memory setup")
Cc: stable@vger.kernel.org
Signed-off-by: Anthony Pighin <anthony.pighin@nokia.com>
---
 drivers/soc/fsl/qbman/bman_ccsr.c | 10 ++++++++++
 drivers/soc/fsl/qbman/dpaa_sys.h  | 14 ++++++++++++++
 drivers/soc/fsl/qbman/qman_ccsr.c | 10 +---------
 3 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/drivers/soc/fsl/qbman/bman_ccsr.c b/drivers/soc/fsl/qbman/bman_ccsr.c
index b0f26f6f731e..788e4dcfb6f2 100644
--- a/drivers/soc/fsl/qbman/bman_ccsr.c
+++ b/drivers/soc/fsl/qbman/bman_ccsr.c
@@ -104,6 +104,7 @@ static int __bman_requires_cleanup;
 
 static int bm_set_memory(u64 ba, u32 size)
 {
+	void *ptr;
 	u32 bar, bare;
 	u32 exp = ilog2(size);
 	/* choke if size isn't within range */
@@ -127,6 +128,15 @@ static int bm_set_memory(u64 ba, u32 size)
 		return 1;
 	}
 
+	/* BMan starts writing its free list as soon as FBPR_AR is set */
+	ptr = memremap(ba, size, MEMREMAP_WB);
+	if (ptr) {
+		dpaa_flush_private_mem(ptr, size);
+		memunmap(ptr);
+	} else {
+		pr_warn("BMan private memory not flushed, buffer pools may be corrupted\n");
+	}
+
 	bm_ccsr_out(REG_FBPR_BARE, upper_32_bits(ba));
 	bm_ccsr_out(REG_FBPR_BAR, lower_32_bits(ba));
 	bm_ccsr_out(REG_FBPR_AR, exp - 1);
diff --git a/drivers/soc/fsl/qbman/dpaa_sys.h b/drivers/soc/fsl/qbman/dpaa_sys.h
index 16485bde9636..be7517c31c35 100644
--- a/drivers/soc/fsl/qbman/dpaa_sys.h
+++ b/drivers/soc/fsl/qbman/dpaa_sys.h
@@ -111,6 +111,20 @@ int qbman_init_private_mem(struct device *dev, int idx, const char *compat,
 #define QBMAN_MEMREMAP_ATTR	MEMREMAP_WC
 #endif
 
+/*
+ * QMan and BMan access their private memory without snooping the CPU
+ * caches, so no line of it may be held in a cache once the hardware is
+ * given the region.
+ */
+static inline void dpaa_flush_private_mem(void *ptr, size_t size)
+{
+#if defined(CONFIG_PPC)
+	flush_dcache_range((unsigned long)ptr, (unsigned long)ptr + size);
+#elif defined(CONFIG_ARM64)
+	dcache_clean_inval_poc((unsigned long)ptr, (unsigned long)ptr + size);
+#endif
+}
+
 static inline int dpaa_set_portal_irq_affinity(struct device *dev,
 					       int irq, int cpu)
 {
diff --git a/drivers/soc/fsl/qbman/qman_ccsr.c b/drivers/soc/fsl/qbman/qman_ccsr.c
index aa5348f4902f..04b65c49fbe6 100644
--- a/drivers/soc/fsl/qbman/qman_ccsr.c
+++ b/drivers/soc/fsl/qbman/qman_ccsr.c
@@ -375,15 +375,7 @@ static int qm_set_memory(enum qm_memory memory, u64 ba, u32 size)
 		return -ENOMEM;
 	}
 	memset(ptr, 0, size);
-
-#ifdef CONFIG_PPC
-	/*
-	 * PPC doesn't appear to flush the cache on memunmap() but the
-	 * cache must be flushed since QMan does non coherent accesses
-	 * to this memory
-	 */
-	flush_dcache_range((unsigned long) ptr, (unsigned long) ptr+size);
-#endif
+	dpaa_flush_private_mem(ptr, size);
 	memunmap(ptr);
 
 	qm_ccsr_out(offset, upper_32_bits(ba));

base-commit: 0df89587a56e0f0392a9d5380334fb87ec4f2690
-- 
2.43.0


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

* RE: [PATCH] soc: fsl: qbman: flush the private memory before enabling QMan and BMan
  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
  0 siblings, 1 reply; 12+ messages in thread
From: Madalin Bucur @ 2026-12-03 16:41 UTC (permalink / raw)
  To: Anthony Pighin, Christophe Leroy (CS GROUP), Vladimir Oltean
  Cc: Claudiu Manoil, Camelia Alexandra Groza,
	linuxppc-dev@lists.ozlabs.org,
	linux-arm-kernel@lists.infradead.org, stable@vger.kernel.org

> -----Original Message-----
> From: Anthony Pighin <anthony.pighin@nokia.com>
<snip>
> Subject: [PATCH] soc: fsl: qbman: flush the private memory before enabling
> QMan and BMan
>
> QMan and BMan do not snoop the CPU caches when accessing their private
> memory (FQD, PFDR and FBPR). The LS1043A DPAA reference manual
> describes
> these as non-coherent regions owned by QMan and BMan, and says that
> BMan
> starts writing its free list as soon as FBPR_AR[SIZE] is set.
>
> On arm64 the driver never cleans the FBPR area from the CPU caches, so
> stale dirty lines remain there. A line written back after BMan has
> stored an FBPR at that address overwrites it. A zeroed FBPR yields eight
> zero-address buffers and loses the link to the next one, truncating the
> pool. A frame received into such a buffer crashes the DPAA Ethernet
> driver (x4 is phys_to_virt(0)):
>
>   Unable to handle kernel paging request at virtual address ffff4bcd800000f8
>   Internal error: Oops: 96000005 [#1] PREEMPT SMP
>   pc : rx_default_dqrr+0x30c/0x530 [fsl_dpa]
>   lr : rx_default_dqrr+0x2fc/0x530 [fsl_dpa]
>   x5 : 0000000000000000 x4 : ffff4bcd80000000 x3 : ffffdec2e49fe008
>   Call trace:
>    rx_default_dqrr+0x30c/0x530 [fsl_dpa]
>    __poll_portal_fast+0x190/0x1b0
>    qman_p_poll_dqrr+0x1c/0x30
>    dpaa_eth_poll+0x30/0xc0 [fsl_dpa]
>   PHYS_OFFSET: 0xffffb43280000000
>
> Commit 97777078d695 ("soc/fsl/qbman: Rework QBMan private memory
> setup")
> started zeroing FQD and PFDR through a cacheable mapping and flushed it
> because QMan's accesses are non-coherent, but only on PPC. On arm64,
> memunmap() leaves the dirty lines in place, so QMan is also exposed.
>
> This was reproduced on an LS1043A by dirtying a line over a record that
> BMan had just written, letting it be written back and acquiring the
> buffers again. Groups of eight zero-address buffers came back and the
> pool chain was cut short.
>
> Clean and invalidate the private memory to the point of coherency before
> handing it to QMan or BMan, on arm64 as well as PPC.
>
> Fixes: e868adf21c0a ("soc/fsl/qbman: Enable FSL_LAYERSCAPE config on
> ARM")
> Fixes: 97777078d695 ("soc/fsl/qbman: Rework QBMan private memory
> setup")
> Cc: stable@vger.kernel.org
> Signed-off-by: Anthony Pighin <anthony.pighin@nokia.com>
> ---
>  drivers/soc/fsl/qbman/bman_ccsr.c | 10 ++++++++++
>  drivers/soc/fsl/qbman/dpaa_sys.h  | 14 ++++++++++++++
>  drivers/soc/fsl/qbman/qman_ccsr.c | 10 +---------
>  3 files changed, 25 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/soc/fsl/qbman/bman_ccsr.c
> b/drivers/soc/fsl/qbman/bman_ccsr.c
> index b0f26f6f731e..788e4dcfb6f2 100644
> --- a/drivers/soc/fsl/qbman/bman_ccsr.c
> +++ b/drivers/soc/fsl/qbman/bman_ccsr.c
> @@ -104,6 +104,7 @@ static int __bman_requires_cleanup;
>
>  static int bm_set_memory(u64 ba, u32 size)
>  {
> +     void *ptr;
>       u32 bar, bare;
>       u32 exp = ilog2(size);
>       /* choke if size isn't within range */
> @@ -127,6 +128,15 @@ static int bm_set_memory(u64 ba, u32 size)
>               return 1;
>       }
>
> +     /* BMan starts writing its free list as soon as FBPR_AR is set */
> +     ptr = memremap(ba, size, MEMREMAP_WB);
> +     if (ptr) {
> +             dpaa_flush_private_mem(ptr, size);
> +             memunmap(ptr);
> +     } else {
> +             pr_warn("BMan private memory not flushed, buffer pools
> may be corrupted\n");
> +     }
> +
>       bm_ccsr_out(REG_FBPR_BARE, upper_32_bits(ba));
>       bm_ccsr_out(REG_FBPR_BAR, lower_32_bits(ba));
>       bm_ccsr_out(REG_FBPR_AR, exp - 1);
> diff --git a/drivers/soc/fsl/qbman/dpaa_sys.h
> b/drivers/soc/fsl/qbman/dpaa_sys.h
> index 16485bde9636..be7517c31c35 100644
> --- a/drivers/soc/fsl/qbman/dpaa_sys.h
> +++ b/drivers/soc/fsl/qbman/dpaa_sys.h
> @@ -111,6 +111,20 @@ int qbman_init_private_mem(struct device *dev, int
> idx, const char *compat,
>  #define QBMAN_MEMREMAP_ATTR  MEMREMAP_WC
>  #endif
>
> +/*
> + * QMan and BMan access their private memory without snooping the CPU
> + * caches, so no line of it may be held in a cache once the hardware is
> + * given the region.
> + */
> +static inline void dpaa_flush_private_mem(void *ptr, size_t size)
> +{
> +#if defined(CONFIG_PPC)
> +     flush_dcache_range((unsigned long)ptr, (unsigned long)ptr + size);
> +#elif defined(CONFIG_ARM64)
> +     dcache_clean_inval_poc((unsigned long)ptr, (unsigned long)ptr +
> size);
> +#endif
> +}
> +
>  static inline int dpaa_set_portal_irq_affinity(struct device *dev,
>                                              int irq, int cpu)
>  {
> diff --git a/drivers/soc/fsl/qbman/qman_ccsr.c
> b/drivers/soc/fsl/qbman/qman_ccsr.c
> index aa5348f4902f..04b65c49fbe6 100644
> --- a/drivers/soc/fsl/qbman/qman_ccsr.c
> +++ b/drivers/soc/fsl/qbman/qman_ccsr.c
> @@ -375,15 +375,7 @@ static int qm_set_memory(enum qm_memory
> memory, u64 ba, u32 size)
>               return -ENOMEM;
>       }
>       memset(ptr, 0, size);
> -
> -#ifdef CONFIG_PPC
> -     /*
> -      * PPC doesn't appear to flush the cache on memunmap() but the
> -      * cache must be flushed since QMan does non coherent accesses
> -      * to this memory
> -      */
> -     flush_dcache_range((unsigned long) ptr, (unsigned long) ptr+size);
> -#endif
> +     dpaa_flush_private_mem(ptr, size);
>       memunmap(ptr);
>
>       qm_ccsr_out(offset, upper_32_bits(ba));
>
> base-commit: 0df89587a56e0f0392a9d5380334fb87ec4f2690
> --
> 2.43.0

Hello, Anthony,

adding Vladimir that was investigating something seemingly
close to the issue you are addressing here.

Best regards,
Madalin

NXP Confidential

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

* Re: [PATCH] soc: fsl: qbman: flush the private memory before enabling QMan and BMan
  2026-12-03 16:41 ` Madalin Bucur
@ 2026-12-03 17:01   ` Vladimir Oltean
  2026-12-03 18:59     ` Anthony Pighin
  2026-12-03 19:14     ` Christophe Leroy (CS GROUP)
  0 siblings, 2 replies; 12+ messages in thread
From: Vladimir Oltean @ 2026-12-03 17:01 UTC (permalink / raw)
  To: Anthony Pighin
  Cc: Madalin Bucur, Christophe Leroy (CS GROUP), Claudiu Manoil,
	Camelia Alexandra Groza, linuxppc-dev@lists.ozlabs.org,
	linux-arm-kernel@lists.infradead.org, stable@vger.kernel.org,
	lkml

Hi Anthony,

On Thu, Dec 03, 2026 at 06:41:07PM +0200, Madalin Bucur wrote:
> > -----Original Message-----
> > From: Anthony Pighin <anthony.pighin@nokia.com>
> <snip>
> > Subject: [PATCH] soc: fsl: qbman: flush the private memory before enabling
> > QMan and BMan
> >
> > QMan and BMan do not snoop the CPU caches when accessing their private
> > memory (FQD, PFDR and FBPR). The LS1043A DPAA reference manual
> > describes
> > these as non-coherent regions owned by QMan and BMan, and says that
> > BMan
> > starts writing its free list as soon as FBPR_AR[SIZE] is set.
> >
> > On arm64 the driver never cleans the FBPR area from the CPU caches, so
> > stale dirty lines remain there. A line written back after BMan has
> > stored an FBPR at that address overwrites it. A zeroed FBPR yields eight
> > zero-address buffers and loses the link to the next one, truncating the
> > pool. A frame received into such a buffer crashes the DPAA Ethernet
> > driver (x4 is phys_to_virt(0)):
> >
> >   Unable to handle kernel paging request at virtual address ffff4bcd800000f8
> >   Internal error: Oops: 96000005 [#1] PREEMPT SMP
> >   pc : rx_default_dqrr+0x30c/0x530 [fsl_dpa]
> >   lr : rx_default_dqrr+0x2fc/0x530 [fsl_dpa]
> >   x5 : 0000000000000000 x4 : ffff4bcd80000000 x3 : ffffdec2e49fe008
> >   Call trace:
> >    rx_default_dqrr+0x30c/0x530 [fsl_dpa]
> >    __poll_portal_fast+0x190/0x1b0
> >    qman_p_poll_dqrr+0x1c/0x30
> >    dpaa_eth_poll+0x30/0xc0 [fsl_dpa]
> >   PHYS_OFFSET: 0xffffb43280000000
> >
> > Commit 97777078d695 ("soc/fsl/qbman: Rework QBMan private memory
> > setup")
> > started zeroing FQD and PFDR through a cacheable mapping and flushed it
> > because QMan's accesses are non-coherent, but only on PPC. On arm64,
> > memunmap() leaves the dirty lines in place, so QMan is also exposed.
> >
> > This was reproduced on an LS1043A by dirtying a line over a record that
> > BMan had just written, letting it be written back and acquiring the
> > buffers again. Groups of eight zero-address buffers came back and the
> > pool chain was cut short.
> >
> > Clean and invalidate the private memory to the point of coherency before
> > handing it to QMan or BMan, on arm64 as well as PPC.
> >
> > Fixes: e868adf21c0a ("soc/fsl/qbman: Enable FSL_LAYERSCAPE config on
> > ARM")
> > Fixes: 97777078d695 ("soc/fsl/qbman: Rework QBMan private memory
> > setup")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Anthony Pighin <anthony.pighin@nokia.com>
> > ---
> >  drivers/soc/fsl/qbman/bman_ccsr.c | 10 ++++++++++
> >  drivers/soc/fsl/qbman/dpaa_sys.h  | 14 ++++++++++++++
> >  drivers/soc/fsl/qbman/qman_ccsr.c | 10 +---------
> >  3 files changed, 25 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/soc/fsl/qbman/bman_ccsr.c
> > b/drivers/soc/fsl/qbman/bman_ccsr.c
> > index b0f26f6f731e..788e4dcfb6f2 100644
> > --- a/drivers/soc/fsl/qbman/bman_ccsr.c
> > +++ b/drivers/soc/fsl/qbman/bman_ccsr.c
> > @@ -104,6 +104,7 @@ static int __bman_requires_cleanup;
> >
> >  static int bm_set_memory(u64 ba, u32 size)
> >  {
> > +     void *ptr;
> >       u32 bar, bare;
> >       u32 exp = ilog2(size);
> >       /* choke if size isn't within range */
> > @@ -127,6 +128,15 @@ static int bm_set_memory(u64 ba, u32 size)
> >               return 1;
> >       }
> >
> > +     /* BMan starts writing its free list as soon as FBPR_AR is set */
> > +     ptr = memremap(ba, size, MEMREMAP_WB);
> > +     if (ptr) {
> > +             dpaa_flush_private_mem(ptr, size);
> > +             memunmap(ptr);
> > +     } else {
> > +             pr_warn("BMan private memory not flushed, buffer pools
> > may be corrupted\n");
> > +     }
> > +
> >       bm_ccsr_out(REG_FBPR_BARE, upper_32_bits(ba));
> >       bm_ccsr_out(REG_FBPR_BAR, lower_32_bits(ba));
> >       bm_ccsr_out(REG_FBPR_AR, exp - 1);
> > diff --git a/drivers/soc/fsl/qbman/dpaa_sys.h
> > b/drivers/soc/fsl/qbman/dpaa_sys.h
> > index 16485bde9636..be7517c31c35 100644
> > --- a/drivers/soc/fsl/qbman/dpaa_sys.h
> > +++ b/drivers/soc/fsl/qbman/dpaa_sys.h
> > @@ -111,6 +111,20 @@ int qbman_init_private_mem(struct device *dev, int
> > idx, const char *compat,
> >  #define QBMAN_MEMREMAP_ATTR  MEMREMAP_WC
> >  #endif
> >
> > +/*
> > + * QMan and BMan access their private memory without snooping the CPU
> > + * caches, so no line of it may be held in a cache once the hardware is
> > + * given the region.
> > + */
> > +static inline void dpaa_flush_private_mem(void *ptr, size_t size)
> > +{
> > +#if defined(CONFIG_PPC)
> > +     flush_dcache_range((unsigned long)ptr, (unsigned long)ptr + size);
> > +#elif defined(CONFIG_ARM64)
> > +     dcache_clean_inval_poc((unsigned long)ptr, (unsigned long)ptr +

Technically here, dcache_clean_poc() is sufficient, correct? Cache flush
is what we need, not necessarily invalidate (there are no subsequent reads).

Note that we already have this distinction in the existing dpaa_flush()
and dpaa_invalidate() macros. These are only implemented for PPC, however.
I am not requesting you to reuse these macros on arm64, because that
would create a larger change than the minimal fix for the issue.
But once cache maintenance operations are also implemented on arm64,
dpaa_flush_private_mem() should be replaced by dpaa_flush(), not by
dpaa_invalidate(). And while on PPC they map to the same primitives
(hence the latter being mapped to the former), on arm64 they don't.

> > size);
> > +#endif
> > +}
> > +
> >  static inline int dpaa_set_portal_irq_affinity(struct device *dev,
> >                                              int irq, int cpu)
> >  {
> > diff --git a/drivers/soc/fsl/qbman/qman_ccsr.c
> > b/drivers/soc/fsl/qbman/qman_ccsr.c
> > index aa5348f4902f..04b65c49fbe6 100644
> > --- a/drivers/soc/fsl/qbman/qman_ccsr.c
> > +++ b/drivers/soc/fsl/qbman/qman_ccsr.c
> > @@ -375,15 +375,7 @@ static int qm_set_memory(enum qm_memory
> > memory, u64 ba, u32 size)
> >               return -ENOMEM;
> >       }
> >       memset(ptr, 0, size);
> > -
> > -#ifdef CONFIG_PPC
> > -     /*
> > -      * PPC doesn't appear to flush the cache on memunmap() but the
> > -      * cache must be flushed since QMan does non coherent accesses
> > -      * to this memory
> > -      */
> > -     flush_dcache_range((unsigned long) ptr, (unsigned long) ptr+size);
> > -#endif
> > +     dpaa_flush_private_mem(ptr, size);
> >       memunmap(ptr);
> >
> >       qm_ccsr_out(offset, upper_32_bits(ba));
> >
> > base-commit: 0df89587a56e0f0392a9d5380334fb87ec4f2690
> > --
> > 2.43.0
> 
> Hello, Anthony,
> 
> adding Vladimir that was investigating something seemingly
> close to the issue you are addressing here.
> 
> Best regards,
> Madalin

As Madalin said, I am investigating a QMan PFDR corruption caused by
qm_set_memory() performing a memset() on a MEMREMAP_WB mapping
(cacheable as per the memremap() comments from kernel/iomem.c), and then
calling qm_init_pfdr() without flushing the cache.

I thought I understood that mechanism by now and I myself was just
writing a patch, but now I see yours and I'm surprised to see a BMan
FBPR corruption being reported by you.

The major difference between QMan and BMan is that bm_set_memory() does
not do any memset. So what am I missing, who dirties the cache lines for
FBPR, and why is FBPR even mapped by the CPU?

Note that out of all 3 DPAA reserved memory regions, only QMan FQD needs
zero-initialization. As the DPAARM puts it:

| The correct operation of this command relies on software clearing the
| FQD memory area before first use, such that QMan will find all FQD to be
| in the Out Of Service state (State field = 0 in the FQD) the first time
| an Initialize FQ command is executed on each FQ.

With the QMan portion of the patch I don't have a problem, but the BMan
I simply don't understand.

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

* Re: [PATCH] soc: fsl: qbman: flush the private memory before enabling QMan and BMan
  2026-12-03 17:01   ` Vladimir Oltean
@ 2026-12-03 18:59     ` Anthony Pighin
  2026-12-03 21:52       ` Vladimir Oltean
  2026-12-03 19:14     ` Christophe Leroy (CS GROUP)
  1 sibling, 1 reply; 12+ messages in thread
From: Anthony Pighin @ 2026-12-03 18:59 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: Madalin Bucur, Christophe Leroy (CS GROUP), Claudiu Manoil,
	Camelia Groza, linuxppc-dev, linux-arm-kernel, stable,
	linux-kernel

Hi Vladimir, Madalin,

Thanks for the quick look.

On Thu, Dec 03, 2026 at 07:01:13PM +0200, Vladimir Oltean wrote:

> Technically here, dcache_clean_poc() is sufficient, correct? Cache flush
> is what we need, not necessarily invalidate (there are no subsequent reads).

Yes. Only a dirty line written back over data the hardware has stored
does harm. Clean lines are never written back, and the CPU does not read
these regions.

> The major difference between QMan and BMan is that bm_set_memory() does
> not do any memset. So what am I missing, who dirties the cache lines for
> FBPR, and why is FBPR even mapped by the CPU?

In Linux it is not mapped at all. The regions are no-map reserved-memory
nodes without a reg property, which early Linux places at the top of
DRAM and keeps out of the linear map. Before that, the boot chain runs
under UEFI with all of DRAM mapped cacheable, and on our LS1043A board
the EFI memory map puts all of FBPR and most of FQD inside a 32 MiB
EfiLoaderCode allocation. Cache lines outlive the mapping that brought
them in, and the arm64 boot protocol only requires the kernel image to
be clean to the PoC, so nothing ensures there is no dirty line over that
memory when BMan is given it.

I have not caught such a line, though. Counting the cached lines of each
region just before its registers are programmed found none over eight
boots, three of them power cycles, while a control of deliberately
cached lines was caught every time it ran. I have not tried kexec, but
we have hit this without it.

What I can show is the consequence. Forcing a dirty line over FBPR to be
written back after BMan is enabled makes BMan hand out zero-address
buffers. The field hits match. With an out-of-tree check that drops Rx
frames whose buffer address is zero, one board logged this burst at
boot:

  rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=97, status=0x4
  rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=342, status=0x4

Only the address is zero. The offset is the usual Rx headroom and the
lengths are real frames, so FMan received into zero-address buffers
taken from the pool. A zeroed PFDR would have cleared the whole frame
descriptor instead.

So the BMan half rests on the same requirement as the QMan half. Memory
handed to hardware that does not snoop must have no dirty line over it.

> Note that out of all 3 DPAA reserved memory regions, only QMan FQD needs
> zero-initialization.

Agreed that only FQD needs zeroing.

Thanks,
Anthony

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

* Re: [PATCH] soc: fsl: qbman: flush the private memory before enabling QMan and BMan
  2026-12-03 17:01   ` Vladimir Oltean
  2026-12-03 18:59     ` Anthony Pighin
@ 2026-12-03 19:14     ` Christophe Leroy (CS GROUP)
  1 sibling, 0 replies; 12+ messages in thread
From: Christophe Leroy (CS GROUP) @ 2026-12-03 19:14 UTC (permalink / raw)
  To: Vladimir Oltean, Anthony Pighin
  Cc: Madalin Bucur, Claudiu Manoil, Camelia Alexandra Groza,
	linuxppc-dev@lists.ozlabs.org,
	linux-arm-kernel@lists.infradead.org, stable@vger.kernel.org,
	lkml



Le 03/12/2026 à 18:01, Vladimir Oltean a écrit :
> Hi Anthony,
> 
> On Thu, Dec 03, 2026 at 06:41:07PM +0200, Madalin Bucur wrote:
>>> -----Original Message-----
>>> From: Anthony Pighin <anthony.pighin@nokia.com>
>> <snip>
>>> Subject: [PATCH] soc: fsl: qbman: flush the private memory before enabling
>>> QMan and BMan
>>>
>>> QMan and BMan do not snoop the CPU caches when accessing their private
>>> memory (FQD, PFDR and FBPR). The LS1043A DPAA reference manual
>>> describes
>>> these as non-coherent regions owned by QMan and BMan, and says that
>>> BMan
>>> starts writing its free list as soon as FBPR_AR[SIZE] is set.
>>>
>>> On arm64 the driver never cleans the FBPR area from the CPU caches, so
>>> stale dirty lines remain there. A line written back after BMan has
>>> stored an FBPR at that address overwrites it. A zeroed FBPR yields eight
>>> zero-address buffers and loses the link to the next one, truncating the
>>> pool. A frame received into such a buffer crashes the DPAA Ethernet
>>> driver (x4 is phys_to_virt(0)):
>>>
>>>    Unable to handle kernel paging request at virtual address ffff4bcd800000f8
>>>    Internal error: Oops: 96000005 [#1] PREEMPT SMP
>>>    pc : rx_default_dqrr+0x30c/0x530 [fsl_dpa]
>>>    lr : rx_default_dqrr+0x2fc/0x530 [fsl_dpa]
>>>    x5 : 0000000000000000 x4 : ffff4bcd80000000 x3 : ffffdec2e49fe008
>>>    Call trace:
>>>     rx_default_dqrr+0x30c/0x530 [fsl_dpa]
>>>     __poll_portal_fast+0x190/0x1b0
>>>     qman_p_poll_dqrr+0x1c/0x30
>>>     dpaa_eth_poll+0x30/0xc0 [fsl_dpa]
>>>    PHYS_OFFSET: 0xffffb43280000000
>>>
>>> Commit 97777078d695 ("soc/fsl/qbman: Rework QBMan private memory
>>> setup")
>>> started zeroing FQD and PFDR through a cacheable mapping and flushed it
>>> because QMan's accesses are non-coherent, but only on PPC. On arm64,
>>> memunmap() leaves the dirty lines in place, so QMan is also exposed.
>>>
>>> This was reproduced on an LS1043A by dirtying a line over a record that
>>> BMan had just written, letting it be written back and acquiring the
>>> buffers again. Groups of eight zero-address buffers came back and the
>>> pool chain was cut short.
>>>
>>> Clean and invalidate the private memory to the point of coherency before
>>> handing it to QMan or BMan, on arm64 as well as PPC.
>>>
>>> Fixes: e868adf21c0a ("soc/fsl/qbman: Enable FSL_LAYERSCAPE config on
>>> ARM")
>>> Fixes: 97777078d695 ("soc/fsl/qbman: Rework QBMan private memory
>>> setup")


>>> +/*
>>> + * QMan and BMan access their private memory without snooping the CPU
>>> + * caches, so no line of it may be held in a cache once the hardware is
>>> + * given the region.
>>> + */
>>> +static inline void dpaa_flush_private_mem(void *ptr, size_t size)
>>> +{
>>> +#if defined(CONFIG_PPC)
>>> +     flush_dcache_range((unsigned long)ptr, (unsigned long)ptr + size);
>>> +#elif defined(CONFIG_ARM64)
>>> +     dcache_clean_inval_poc((unsigned long)ptr, (unsigned long)ptr +
> 
> Technically here, dcache_clean_poc() is sufficient, correct? Cache flush
> is what we need, not necessarily invalidate (there are no subsequent reads).
> 
> Note that we already have this distinction in the existing dpaa_flush()
> and dpaa_invalidate() macros. These are only implemented for PPC, however.
> I am not requesting you to reuse these macros on arm64, because that
> would create a larger change than the minimal fix for the issue.
> But once cache maintenance operations are also implemented on arm64,
> dpaa_flush_private_mem() should be replaced by dpaa_flush(), not by
> dpaa_invalidate(). And while on PPC they map to the same primitives
> (hence the latter being mapped to the former), on arm64 they don't.

On powerpc, shouldn't dpaa_invalidate() call invalidate_dcache_range() 
instead ?

Christophe


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

* Re: [PATCH] soc: fsl: qbman: flush the private memory before enabling QMan and BMan
  2026-12-03 18:59     ` Anthony Pighin
@ 2026-12-03 21:52       ` Vladimir Oltean
  2026-12-03 23:05         ` Anthony Pighin
  0 siblings, 1 reply; 12+ messages in thread
From: Vladimir Oltean @ 2026-12-03 21:52 UTC (permalink / raw)
  To: Anthony Pighin
  Cc: Madalin Bucur, Christophe Leroy (CS GROUP), Claudiu Manoil,
	Camelia Groza, linuxppc-dev, linux-arm-kernel, stable,
	linux-kernel

Hi Anthony,

On Thu, Dec 03, 2026 at 01:59:01PM -0500, Anthony Pighin wrote:
> Yes. Only a dirty line written back over data the hardware has stored
> does harm. Clean lines are never written back, and the CPU does not read
> these regions.

You're not being clear. Does your UEFI boot firmware actually produce
such a dirty cache line for FBPR? It means the firmware has also written
in the FBPR DRAM area, it's not sufficient to have mapped it.

What problem were you actually seeing that led you to send this patch?

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

* Re: [PATCH] soc: fsl: qbman: flush the private memory before enabling QMan and BMan
  2026-12-03 21:52       ` Vladimir Oltean
@ 2026-12-03 23:05         ` Anthony Pighin
  2026-12-04 10:35           ` Vladimir Oltean
  0 siblings, 1 reply; 12+ messages in thread
From: Anthony Pighin @ 2026-12-03 23:05 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: Madalin Bucur, Christophe Leroy (CS GROUP), Claudiu Manoil,
	Camelia Groza, linuxppc-dev, linux-arm-kernel, stable,
	linux-kernel

Hi Vladimir,

On Thu, Dec 03, 2026 at 11:52:15PM +0200, Vladimir Oltean wrote:
> You're not being clear. Does your UEFI boot firmware actually produce
> such a dirty cache line for FBPR? It means the firmware has also written
> in the FBPR DRAM area, it's not sufficient to have mapped it.

No, not that I have been able to show. On our board FBPR lies inside an
EfiLoaderCode allocation, so the boot chain most likely wrote it, but in
eight boots no line of FBPR was still cached when BMan was given it.

> What problem were you actually seeing that led you to send this patch?

Rare crashes in the DPAA Rx path during boot, on a buffer at physical
address 0 (x4 is phys_to_virt(0)):

  [   20.202676] Unable to handle kernel paging request at virtual address ffff4bcd800000f8
  [   20.258552] Internal error: Oops: 96000005 [#1] PREEMPT SMP
  [   20.341545] pc : rx_default_dqrr+0x30c/0x530 [fsl_dpa]
  [   20.346687] lr : rx_default_dqrr+0x2fc/0x530 [fsl_dpa]
  [   20.412177] x5 : 0000000000000000 x4 : ffff4bcd80000000 x3 : ffffdec2e49fe008
  [   20.430868] Call trace:
  [   20.433305]  rx_default_dqrr+0x30c/0x530 [fsl_dpa]
  [   20.438095]  __poll_portal_fast+0x190/0x1b0
  [   20.442276]  qman_p_poll_dqrr+0x1c/0x30
  [   20.446105]  dpaa_eth_poll+0x30/0xc0 [fsl_dpa]

After the fact, we added a check to rx_default_dqrr() that drops any
frame whose buffer address is zero and logs the first five. One board
then logged, at boot:

  rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=97, status=0x4
  rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=342, status=0x4
  rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=342, status=0x4
  rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=342, status=0x4
  rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=342, status=0x4

The address is zero but the offset, length and status are real, so FMan
received into zero-address buffers acquired from BMan, rather than QMan
handing out a zeroed FD. I found no software path that releases a zero
address into the pool.

A zeroed FBPR fits that. It holds eight buffer addresses, so the five
logged, all within 90 ms, fit one zeroed record. What I have not found
is what zeroes it on the failing boots.

Thanks,
Anthony

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

* Re: [PATCH] soc: fsl: qbman: flush the private memory before enabling QMan and BMan
  2026-12-03 23:05         ` Anthony Pighin
@ 2026-12-04 10:35           ` Vladimir Oltean
  2026-12-04 14:03             ` Anthony Pighin
  0 siblings, 1 reply; 12+ messages in thread
From: Vladimir Oltean @ 2026-12-04 10:35 UTC (permalink / raw)
  To: Anthony Pighin
  Cc: Madalin Bucur, Christophe Leroy (CS GROUP), Claudiu Manoil,
	Camelia Groza, linuxppc-dev, linux-arm-kernel, stable,
	linux-kernel

On Thu, Dec 03, 2026 at 06:05:04PM -0500, Anthony Pighin wrote:
> Rare crashes in the DPAA Rx path during boot, on a buffer at physical
> address 0 (x4 is phys_to_virt(0)):
> 
>   [   20.202676] Unable to handle kernel paging request at virtual address ffff4bcd800000f8
>   [   20.258552] Internal error: Oops: 96000005 [#1] PREEMPT SMP
>   [   20.341545] pc : rx_default_dqrr+0x30c/0x530 [fsl_dpa]
>   [   20.346687] lr : rx_default_dqrr+0x2fc/0x530 [fsl_dpa]
>   [   20.412177] x5 : 0000000000000000 x4 : ffff4bcd80000000 x3 : ffffdec2e49fe008
>   [   20.430868] Call trace:
>   [   20.433305]  rx_default_dqrr+0x30c/0x530 [fsl_dpa]
>   [   20.438095]  __poll_portal_fast+0x190/0x1b0
>   [   20.442276]  qman_p_poll_dqrr+0x1c/0x30
>   [   20.446105]  dpaa_eth_poll+0x30/0xc0 [fsl_dpa]
> 
> After the fact, we added a check to rx_default_dqrr() that drops any
> frame whose buffer address is zero and logs the first five. One board
> then logged, at boot:
> 
>   rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=97, status=0x4
>   rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=342, status=0x4
>   rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=342, status=0x4
>   rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=342, status=0x4
>   rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=342, status=0x4
> 
> The address is zero but the offset, length and status are real, so FMan
> received into zero-address buffers acquired from BMan, rather than QMan
> handing out a zeroed FD. I found no software path that releases a zero
> address into the pool.
> 
> A zeroed FBPR fits that. It holds eight buffer addresses, so the five
> logged, all within 90 ms, fit one zeroed record. What I have not found
> is what zeroes it on the failing boots.

The fact is that I don't see how a zeroed FBPR could possibly fit your
symptoms. Did you ever reproduce this problem with the upstream driver
that you're patching?

DPAARM section 4.3.6.1 FBPR Format describes:

  Offset   Size   Field      Required value for your symptoms  Checked by BMan?
  0x00     6      BP0        0                                 no
  0x06     6      BP1        0                                 no
  0x0c     4      FBPR_BPA   X                                 yes: must match the address it was read from
  0x10     6      BP2        0                                 no
  0x16     6      BP3        0                                 no
  0x1c     4      reserved   X                                 not documented
  0x20     6      BP4        0                                 no
  0x26     6      BP5        0                                 no
  0x2c     4      BPID       X                                 yes: must match the list being walked
  0x30     6      BP6        0                                 no
  0x36     6      BP7        0                                 no
  0x3c     4      FBPR_IDX   X                                 indirectly (see below)

FBPR_IDX is the FBPR index to the next FBPR in the singly-linked list.
All-zero indicates the end of the list. So BMan would lose track of the
remaining buffers in this pool, while the driver would still think there
is no reason to refill.

BPID is this:
$ for eth in fm1-mac3 fm1-mac4 fm1-mac5 fm1-mac6 fm1-mac9 fm1-mac10; do cat /sys/class/net/$eth/bpids; done
0
1
2
3
4
5

So a corruption with an all-zero FBPR entry is only plausible for fm1-mac3,
since that's the only interface using BPID 0 with the upstream driver
(in downstream, they all use BPID 32).

But the manual also has these statements: "The BMan never uses FBPR index zero."
and:

| FBPR_BPA and BPID are intended as a crude debug check to test for memory scribbling by other entities
| or FBPR pool corruption but do not provide any guarantees that this behavior will be caught. When an
| FBPR belongs to the FBPR pool, the buffer pointer ID (BPID) is set to 0xff, and FBPR_BPA matches BP0.
| An EMCI error interrupt is raised and the linked list of the pool is dropped if, the FBPR_BPA and BPID
| on an FBPR read do not match their expected values. If BPID = 0xff (FBPR pool), then BP0 is also checked
| to confirm that it matches FBPR_BPA.

If you write an all-zero FBPR entry, it would not pass those crude debug
checks that BMan performs, and it would raise an EMCI interrupt (which I
see we don't process).

You would essentially need to craft FBPR entries with the FBPR_BPA field
written back with the exact value that BMan generated, and just the
BP0-BP7 fields zeroed out. 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.

You also didn't mention which interface was receiving traffic, and what
BPID it was using?

Do you see the message below with the port under heavy traffic and the
patch attached? Heavy traffic is needed because the on-chip stockpile
must first be exhausted in order for BMan to reach out to FBPR in DRAM.

[   55.475284] bman_ccsr 1890000.bman: ErrInt: External Memory Corruption
[   55.475322] bman_ccsr 1890000.bman: ErrInt: CECR LID=0x02 CEAR FBPR index=0x003ff57

---
diff --git a/drivers/soc/fsl/qbman/bman_ccsr.c b/drivers/soc/fsl/qbman/bman_ccsr.c
index b0f26f6f731e..17046b528d8b 100644
--- a/drivers/soc/fsl/qbman/bman_ccsr.c
+++ b/drivers/soc/fsl/qbman/bman_ccsr.c
@@ -39,6 +39,10 @@ EXPORT_SYMBOL(bman_ip_rev);
 #define REG_ECIR		0x0a04
 #define REG_EADR		0x0a08
 #define REG_EDATA(n)		(0x0a10 + ((n) * 0x04))
+#define REG_CECR		0x0a34
+#define REG_CEAR		0x0a38
+#define REG_AECR		0x0a44
+#define REG_AEAR		0x0a48
 #define REG_SBEC(n)		(0x0a80 + ((n) * 0x04))
 #define REG_IP_REV_1		0x0bf8
 #define REG_IP_REV_2		0x0bfc
@@ -52,6 +56,8 @@ EXPORT_SYMBOL(bman_ip_rev);
 #define REG_ERR_ISDR		0x0e08
 
 /* Used by all error interrupt registers except 'inhibit' */
+#define BM_EIRQ_EMAI	0x00000040	/* External Memory Access */
+#define BM_EIRQ_EMCI	0x00000020	/* External Memory Corruption */
 #define BM_EIRQ_IVCI	0x00000010	/* Invalid Command Verb */
 #define BM_EIRQ_FLWI	0x00000008	/* FBPR Low Watermark */
 #define BM_EIRQ_MBEI	0x00000004	/* Multi-bit ECC Error */
@@ -64,6 +70,8 @@ struct bman_hwerr_txt {
 };
 
 static const struct bman_hwerr_txt bman_hwerr_txts[] = {
+	{ BM_EIRQ_EMAI, "External Memory Access" },
+	{ BM_EIRQ_EMCI, "External Memory Corruption" },
 	{ BM_EIRQ_IVCI, "Invalid Command Verb" },
 	{ BM_EIRQ_FLWI, "FBPR Low Watermark" },
 	{ BM_EIRQ_MBEI, "Multi-bit ECC Error" },
@@ -161,6 +169,14 @@ static irqreturn_t bman_isr(int irq, void *ptr)
 		if (bman_hwerr_txts[i].mask & isr_mask) {
 			dev_err_ratelimited(dev, "ErrInt: %s\n",
 					    bman_hwerr_txts[i].txt);
+			if (bman_hwerr_txts[i].mask & BM_EIRQ_EMCI)
+				dev_err_ratelimited(dev, "ErrInt: CECR LID=0x%02x CEAR FBPR index=0x%07x\n",
+						    bm_ccsr_in(REG_CECR) & 0xff,
+						    bm_ccsr_in(REG_CEAR) & 0x0fffffff);
+			if (bman_hwerr_txts[i].mask & BM_EIRQ_EMAI)
+				dev_err_ratelimited(dev, "ErrInt: AECR LID=0x%02x AEAR FBPR index=0x%07x\n",
+						    bm_ccsr_in(REG_AECR) & 0xff,
+						    bm_ccsr_in(REG_AEAR) & 0x0fffffff);
 			if (bman_hwerr_txts[i].mask & ecsr_val) {
 				/* Re-arm error capture registers */
 				bm_ccsr_out(REG_ECSR, ecsr_val);
---

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

* Re: [PATCH] soc: fsl: qbman: flush the private memory before enabling QMan and BMan
  2026-12-04 10:35           ` Vladimir Oltean
@ 2026-12-04 14:03             ` Anthony Pighin
  2026-12-04 17:06               ` Vladimir Oltean
  0 siblings, 1 reply; 12+ messages in thread
From: Anthony Pighin @ 2026-12-04 14:03 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: Madalin Bucur, Christophe Leroy (CS GROUP), Claudiu Manoil,
	Camelia Groza, linuxppc-dev, linux-arm-kernel, stable,
	linux-kernel

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.

> 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.

> Do you see the message below with the port under heavy traffic and the
> patch attached?

It does not appear to be traffic load dependent. Every hit came just
after the port was brought up, and in the v6.6.52 log the first NULL
buffer line is 1.2 s after link up.

The field logs can't show EMCI, since bman_isr() clears it without
printing it, so your patch would be worth having for that alone.

Thanks,
Anthony

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

* Re: [PATCH] soc: fsl: qbman: flush the private memory before enabling QMan and BMan
  2026-12-04 14:03             ` Anthony Pighin
@ 2026-12-04 17:06               ` Vladimir Oltean
  2026-12-04 18:08                 ` Anthony Pighin
  0 siblings, 1 reply; 12+ messages in thread
From: Vladimir Oltean @ 2026-12-04 17:06 UTC (permalink / raw)
  To: Anthony Pighin
  Cc: Madalin Bucur, Christophe Leroy (CS GROUP), Claudiu Manoil,
	Camelia Groza, linuxppc-dev, linux-arm-kernel, stable,
	linux-kernel

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 ------------------------

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

* Re: [PATCH] soc: fsl: qbman: flush the private memory before enabling QMan and BMan
  2026-12-04 17:06               ` Vladimir Oltean
@ 2026-12-04 18:08                 ` Anthony Pighin
  2026-12-04 20:49                   ` Vladimir Oltean
  0 siblings, 1 reply; 12+ messages in thread
From: Anthony Pighin @ 2026-12-04 18:08 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: Madalin Bucur, Christophe Leroy (CS GROUP), Claudiu Manoil,
	Camelia Groza, linuxppc-dev, linux-arm-kernel, stable,
	linux-kernel

Hi Vladimir,

On Fri, Dec 04, 2026 at 07:06:03PM +0200, Vladimir Oltean wrote:
> If I'm right it also means your patch does not fix the bug you're
> actually trying to track down, correct?

Correct. Thanks for pushing back on the FBPR theory. It was wrong, and
your questions are what got us to the real bug.

> There is clearly a misunderstanding here. I never said an all-zero frame
> descriptor. I said the buffer address is zero.

Understood, I misread you there.

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

It is, and thanks for digging into bman_release() to find it. Your
analysis showed exactly where to force the race, which is what made
a reproducer possible.

I tested on an LS1043A board running v6.18.62 with CONFIG_PREEMPT=y,
where dpaa_bp_seed() runs during probe in udevd task context.

First, without your patch, I added a debug hook to bman_release() just
before the second get_affine_portal(), where bm_rcr_start() has already
returned an entry but the portal is no longer held. The hook acts only
on the first two releases from dpaa_bp_seed().

On the first release the hook migrated the task to another CPU.
bman_release() filled the entry in the old CPU's RCR, then committed
the current entry of the new CPU's RCR, which had never been written.

  bman-dbg: migrate udevd/125 cpu 3 -> 0 (now 0), ret 0
  bman-dbg: pool 0 filled ffff800081225000 slot 0, committing ffff800080eb9000 slot 0 on cpu 0: bpid 0 bufs 0 0 0 0 0 0 0 0

On the second it made a nested bman_release() on the same portal, the
case your commit message describes. The entry the outer call committed
was all zeroes, as you expected.

  bman-dbg: pool 0 filled ffff800080eb9040 slot 1, committing ffff800080eb9080 slot 2 on cpu 0: bpid 0 bufs 0 0 0 0 0 0 0 0

That put 16 zero addresses into BPID 0, and FMan received 16 frames
into them 1.5 s after link up.

  [   25.765468] fsl_dpaa_mac 1ae4000.ethernet mgmt: Link is Up - 1Gbps/Full - flow control off
  [   27.236335] rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=1514, status=0x4
  ... 15 more identical lines

With your patch, the hook at the same point found preemption and IRQs
disabled and could not act. Each committed entry was the one just
filled, there were no NULL buffers, and mgmt passed traffic normally.

The footprint matches our field reports. Recent hits on v6.6.59 and
v6.12.57 all come at boot, on mgmt, within a few seconds of link up,
with real lengths and parse status. For example:

  [   31.769753] fsl_dpaa_mac 1ae4000.ethernet mgmt: Link is Up - 1Gbps/Full - flow control off
  [   32.939955] rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=1514, status=0x4
  [   32.939982] rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=1514, status=0x4
  [   32.939989] rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=1514, status=0x4
  [   32.939995] rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=1514, status=0x4
  [   32.940002] rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=1514, status=0x4

Those logs can't tell which of the two cases occurred. The migration
case needs no second caller, only a preemption in the window. Nothing
else releases buffers during probe on our board, so it is the likelier
of the two. You may want to add it to your commit message.

Tested-by: Anthony Pighin <anthony.pighin@nokia.com>

That leaves the QMan part of my patch, which you said you were already
writing a fix for. Having the full PFDR fix in one commit from you may
be the better approach. Or would you prefer a v2 from me with only the
QMan change?

Thanks,
Anthony

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

* Re: [PATCH] soc: fsl: qbman: flush the private memory before enabling QMan and BMan
  2026-12-04 18:08                 ` Anthony Pighin
@ 2026-12-04 20:49                   ` Vladimir Oltean
  0 siblings, 0 replies; 12+ messages in thread
From: Vladimir Oltean @ 2026-12-04 20:49 UTC (permalink / raw)
  To: Anthony Pighin
  Cc: Madalin Bucur, Christophe Leroy (CS GROUP), Claudiu Manoil,
	Camelia Groza, linuxppc-dev, linux-arm-kernel, stable,
	linux-kernel

Hi Anthony,

On Fri, Dec 04, 2026 at 01:08:19PM -0500, Anthony Pighin wrote:
> Hi Vladimir,
> 
> On Fri, Dec 04, 2026 at 07:06:03PM +0200, Vladimir Oltean wrote:
> > If I'm right it also means your patch does not fix the bug you're
> > actually trying to track down, correct?
> 
> Correct. Thanks for pushing back on the FBPR theory. It was wrong, and
> your questions are what got us to the real bug.
> 
> > There is clearly a misunderstanding here. I never said an all-zero frame
> > descriptor. I said the buffer address is zero.
> 
> Understood, I misread you there.
> 
> > I have a suspicion that your problem may be fixed by the patch below.
> > Please try.
> 
> It is, and thanks for digging into bman_release() to find it. Your
> analysis showed exactly where to force the race, which is what made
> a reproducer possible.
> 
> I tested on an LS1043A board running v6.18.62 with CONFIG_PREEMPT=y,
> where dpaa_bp_seed() runs during probe in udevd task context.
> 
> First, without your patch, I added a debug hook to bman_release() just
> before the second get_affine_portal(), where bm_rcr_start() has already
> returned an entry but the portal is no longer held. The hook acts only
> on the first two releases from dpaa_bp_seed().
> 
> On the first release the hook migrated the task to another CPU.
> bman_release() filled the entry in the old CPU's RCR, then committed
> the current entry of the new CPU's RCR, which had never been written.
> 
>   bman-dbg: migrate udevd/125 cpu 3 -> 0 (now 0), ret 0
>   bman-dbg: pool 0 filled ffff800081225000 slot 0, committing ffff800080eb9000 slot 0 on cpu 0: bpid 0 bufs 0 0 0 0 0 0 0 0
> 
> On the second it made a nested bman_release() on the same portal, the
> case your commit message describes. The entry the outer call committed
> was all zeroes, as you expected.
> 
>   bman-dbg: pool 0 filled ffff800080eb9040 slot 1, committing ffff800080eb9080 slot 2 on cpu 0: bpid 0 bufs 0 0 0 0 0 0 0 0
> 
> That put 16 zero addresses into BPID 0, and FMan received 16 frames
> into them 1.5 s after link up.
> 
>   [   25.765468] fsl_dpaa_mac 1ae4000.ethernet mgmt: Link is Up - 1Gbps/Full - flow control off
>   [   27.236335] rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=1514, status=0x4
>   ... 15 more identical lines
> 
> With your patch, the hook at the same point found preemption and IRQs
> disabled and could not act. Each committed entry was the one just
> filled, there were no NULL buffers, and mgmt passed traffic normally.
> 
> The footprint matches our field reports. Recent hits on v6.6.59 and
> v6.12.57 all come at boot, on mgmt, within a few seconds of link up,
> with real lengths and parse status. For example:
> 
>   [   31.769753] fsl_dpaa_mac 1ae4000.ethernet mgmt: Link is Up - 1Gbps/Full - flow control off
>   [   32.939955] rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=1514, status=0x4
>   [   32.939982] rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=1514, status=0x4
>   [   32.939989] rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=1514, status=0x4
>   [   32.939995] rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=1514, status=0x4
>   [   32.940002] rx_default_dqrr(mgmt): NULL buffer! format=0, offset=256, length=1514, status=0x4
> 
> Those logs can't tell which of the two cases occurred. The migration
> case needs no second caller, only a preemption in the window. Nothing
> else releases buffers during probe on our board, so it is the likelier
> of the two. You may want to add it to your commit message.
> 
> Tested-by: Anthony Pighin <anthony.pighin@nokia.com>

Back so soon? I refuse this Tested-by tag.

Having sat on a still unfixed bug which you so confidently thought was
fixed by the patch you submitted, I would have expected you wouldn't be
making the same mistake twice, yet here we are.

The mistake, simply put, is this: the reason you are here is because you
have access to a real world system which crashes in a very obscure way.
Let's call that issue A. You've used an AI tool to get some ideas, which
is fine, and you've found issue B. You've reproduced issue B by injecting
a fault and you've AI-fooled yourself into thinking issue B is issue A.

Now somebody else has given you a hint that issue C exists, and you
happily injected another fault that confirms issue C exists. Understand
the pattern?

Unlike me, you have access to the real system with the real problem that
bothered someone. You can plug this patch into that system and run a
soak test. Granted, it is undecidable whether, after an arbitrary period
of time T, a problem with an unknown trigger no longer reproduces
because of chance or because it really was fixed. But there's no better
way than checking the reproduction interval of the issue in the original
system, and gaining a certain confidence level by soak testing in the
same conditions, say, by twice or 3 times that amount of time. So, see
you in a week from now with the tag, I expect no less.

Please don't take this as a personal attack. What I really hope to
achieve is to help you understand what Documentation/process/stable-kernel-rules.rst
means when it makes the distinction between theoretical and practical
bugs, and what you need to do to make your issue be taken seriously.
In practice, theoretical bugs bother very few people and mostly for
academical reasons. Yet the majority of submitted patches is on them,
because people can rarely discern whether they will help anybody or not.

> That leaves the QMan part of my patch, which you said you were already
> writing a fix for. Having the full PFDR fix in one commit from you may
> be the better approach. Or would you prefer a v2 from me with only the
> QMan change?

I'll wait until I have more confidence that the PFDR issue fixes the bug
I'm tracking, then I will submit it.

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

end of thread, other threads:[~2026-12-04 20:49 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-12-04 18:08                 ` Anthony Pighin
2026-12-04 20:49                   ` Vladimir Oltean
2026-12-03 19:14     ` Christophe Leroy (CS GROUP)

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