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; 5+ 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] 5+ 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; 5+ 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] 5+ 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; 5+ 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] 5+ 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; 5+ 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] 5+ 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; 5+ 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] 5+ messages in thread

end of thread, other threads:[~2026-12-03 19:14 UTC | newest]

Thread overview: 5+ 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 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