DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH dpdk] ring: bound wraparound enqueue by input length
@ 2026-11-30 12:31 Robin Jarry
  2026-11-30 14:00 ` Morten Brørup
  2026-12-01  9:00 ` [PATCH dpdk v2] ring: assert wraparound enqueue stays within input Robin Jarry
  0 siblings, 2 replies; 4+ messages in thread
From: Robin Jarry @ 2026-11-30 12:31 UTC (permalink / raw)
  To: dev, Konstantin Ananyev, Wathsala Vithanage, Morten Brørup,
	Stephen Hemminger
  Cc: stable

GCC 13 at -O2 reports -Wmaybe-uninitialized for a fully initialized
24-byte item passed to rte_ring_enqueue_elem():

    struct item item = { .callback = cb, .obj = obj, .priv = priv };
    rte_ring_enqueue_elem(ring, &item, sizeof(item));

In DPDK 25.11, the single-thread head update uses rte_smp_rmb(), which
expands to empty assembly with a memory clobber on x86.

Commit f2f3cf6d098a ("ring: replace SMP barrier with acquire fence")
replaces it with an acquire fence. Neither needs a CPU instruction on
x86, but GCC 13 analyzes the inlined copy differently: the warning
appears with the acquire fence and disappears when the compiler barrier
is restored.

The item is initialized. For a valid wrap, size - idx < n, so the first
copy loop cannot read more than n input words. GCC 13 fails to establish
that bound from the ring indices. State it in the loop condition instead
of relying on the barrier to hide the warning. This does not change the
copy for valid ring indices.

Fixes: f2f3cf6d098a ("ring: replace SMP barrier with acquire fence")
Cc: stable@dpdk.org
Signed-off-by: Robin Jarry <rjarry@redhat.com>
---
 lib/ring/rte_ring_elem_pvt.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/ring/rte_ring_elem_pvt.h b/lib/ring/rte_ring_elem_pvt.h
index 3d680749ad96..404bf1d8d24e 100644
--- a/lib/ring/rte_ring_elem_pvt.h
+++ b/lib/ring/rte_ring_elem_pvt.h
@@ -47,7 +47,7 @@ __rte_ring_enqueue_elems_32(void *ring_table, const void *obj_table,
 			ring[idx++] = obj[i++]; /* fallthrough */
 		}
 	} else {
-		for (i = 0; idx < size; i++, idx++)
+		for (i = 0; idx < size && i < n; i++, idx++)
 			ring[idx] = obj[i];
 		/* Start at the beginning */
 		for (idx = 0; i < n; i++, idx++)
-- 
2.56.1


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

* RE: [PATCH dpdk] ring: bound wraparound enqueue by input length
  2026-11-30 12:31 [PATCH dpdk] ring: bound wraparound enqueue by input length Robin Jarry
@ 2026-11-30 14:00 ` Morten Brørup
  2026-12-01  9:00 ` [PATCH dpdk v2] ring: assert wraparound enqueue stays within input Robin Jarry
  1 sibling, 0 replies; 4+ messages in thread
From: Morten Brørup @ 2026-11-30 14:00 UTC (permalink / raw)
  To: Robin Jarry, dev, Konstantin Ananyev, Wathsala Vithanage,
	Stephen Hemminger
  Cc: stable

> diff --git a/lib/ring/rte_ring_elem_pvt.h
> b/lib/ring/rte_ring_elem_pvt.h
> index 3d680749ad96..404bf1d8d24e 100644
> --- a/lib/ring/rte_ring_elem_pvt.h
> +++ b/lib/ring/rte_ring_elem_pvt.h
> @@ -47,7 +47,7 @@ __rte_ring_enqueue_elems_32(void *ring_table, const
> void *obj_table,
>  			ring[idx++] = obj[i++]; /* fallthrough */
>  		}
>  	} else {
> -		for (i = 0; idx < size; i++, idx++)
> +		for (i = 0; idx < size && i < n; i++, idx++)
>  			ring[idx] = obj[i];

It looks confusing comparing to n here. How about:

	for (i = 0; idx < size; i++, idx++) {
		__rte_assume(i < n);
		ring[idx] = obj[i];
	}

>  		/* Start at the beginning */
>  		for (idx = 0; i < n; i++, idx++)
> --
> 2.56.1


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

* [PATCH dpdk v2] ring: assert wraparound enqueue stays within input
  2026-11-30 12:31 [PATCH dpdk] ring: bound wraparound enqueue by input length Robin Jarry
  2026-11-30 14:00 ` Morten Brørup
@ 2026-12-01  9:00 ` Robin Jarry
  2026-12-01  9:09   ` Morten Brørup
  1 sibling, 1 reply; 4+ messages in thread
From: Robin Jarry @ 2026-12-01  9:00 UTC (permalink / raw)
  To: dev, Konstantin Ananyev, Wathsala Vithanage, Morten Brørup,
	Stephen Hemminger
  Cc: stable

GCC 13 at -O2 reports -Wmaybe-uninitialized for a fully initialized
24-byte item passed to rte_ring_enqueue_elem(). The acquire fence
introduced by commit f2f3cf6d098a ("ring: replace SMP barrier with
acquire fence") exposes GCC's inability to infer that a valid wrap
consumes fewer than n input words before restarting.

State that invariant with __rte_assume() inside the wrap loop instead of
adding a condition to the loop.

Fixes: f2f3cf6d098a ("ring: replace SMP barrier with acquire fence")
Cc: stable@dpdk.org
Signed-off-by: Robin Jarry <rjarry@redhat.com>
---

Notes:
    v2: replaced loop condition with __rte_assume()

 lib/ring/rte_ring_elem_pvt.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/ring/rte_ring_elem_pvt.h b/lib/ring/rte_ring_elem_pvt.h
index 3d680749ad96..77a2efafe119 100644
--- a/lib/ring/rte_ring_elem_pvt.h
+++ b/lib/ring/rte_ring_elem_pvt.h
@@ -47,8 +47,10 @@ __rte_ring_enqueue_elems_32(void *ring_table, const void *obj_table,
 			ring[idx++] = obj[i++]; /* fallthrough */
 		}
 	} else {
-		for (i = 0; idx < size; i++, idx++)
+		for (i = 0; idx < size; i++, idx++) {
+			__rte_assume(i < n);
 			ring[idx] = obj[i];
+		}
 		/* Start at the beginning */
 		for (idx = 0; i < n; i++, idx++)
 			ring[idx] = obj[i];
-- 
2.56.1


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

* RE: [PATCH dpdk v2] ring: assert wraparound enqueue stays within input
  2026-12-01  9:00 ` [PATCH dpdk v2] ring: assert wraparound enqueue stays within input Robin Jarry
@ 2026-12-01  9:09   ` Morten Brørup
  0 siblings, 0 replies; 4+ messages in thread
From: Morten Brørup @ 2026-12-01  9:09 UTC (permalink / raw)
  To: Robin Jarry, dev, Konstantin Ananyev, Wathsala Vithanage,
	Stephen Hemminger
  Cc: stable

> From: Robin Jarry [mailto:rjarry@redhat.com]
> Sent: Tuesday, 1 December 2026 10.01
> 
> GCC 13 at -O2 reports -Wmaybe-uninitialized for a fully initialized
> 24-byte item passed to rte_ring_enqueue_elem(). The acquire fence
> introduced by commit f2f3cf6d098a ("ring: replace SMP barrier with
> acquire fence") exposes GCC's inability to infer that a valid wrap
> consumes fewer than n input words before restarting.
> 
> State that invariant with __rte_assume() inside the wrap loop instead
> of
> adding a condition to the loop.
> 
> Fixes: f2f3cf6d098a ("ring: replace SMP barrier with acquire fence")
> Cc: stable@dpdk.org
> Signed-off-by: Robin Jarry <rjarry@redhat.com>
> ---
> 
> Notes:
>     v2: replaced loop condition with __rte_assume()
> 
>  lib/ring/rte_ring_elem_pvt.h | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/ring/rte_ring_elem_pvt.h
> b/lib/ring/rte_ring_elem_pvt.h
> index 3d680749ad96..77a2efafe119 100644
> --- a/lib/ring/rte_ring_elem_pvt.h
> +++ b/lib/ring/rte_ring_elem_pvt.h
> @@ -47,8 +47,10 @@ __rte_ring_enqueue_elems_32(void *ring_table, const
> void *obj_table,
>  			ring[idx++] = obj[i++]; /* fallthrough */
>  		}
>  	} else {
> -		for (i = 0; idx < size; i++, idx++)
> +		for (i = 0; idx < size; i++, idx++) {
> +			__rte_assume(i < n);
>  			ring[idx] = obj[i];
> +		}
>  		/* Start at the beginning */
>  		for (idx = 0; i < n; i++, idx++)
>  			ring[idx] = obj[i];
> --
> 2.56.1

Reviewed-by: Morten Brørup <mb@smartsharesystems.com>


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

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

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 12:31 [PATCH dpdk] ring: bound wraparound enqueue by input length Robin Jarry
2026-11-30 14:00 ` Morten Brørup
2026-12-01  9:00 ` [PATCH dpdk v2] ring: assert wraparound enqueue stays within input Robin Jarry
2026-12-01  9:09   ` Morten Brørup

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