DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] stack: fix pile GCC memcpy warnings
@ 2026-10-20  8:49 Morten Brørup
  2026-10-20  9:18 ` Bruce Richardson
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Morten Brørup @ 2026-10-20  8:49 UTC (permalink / raw)
  To: dev, Thomas Monjalon
  Cc: Konstantin Ananyev, Andrew Rybchenko, Bruce Richardson,
	Stephen Hemminger, Morten Brørup, Ali Alnubani

On architectures where rte_memcpy() is defined as memcpy(),
GCC warns about source/destination overflow when copying more than the
source/destination size, even for code paths that are not taken in cases
where the sizes are smaller.

The relevant compiler warnings were disabled for GCC at the two
occurrences, and comments describing the reason were added.

NB:
It has not been investigated which GCC versions are affected.
GCC version 10 and up was chosen because that was what the previous
versions of x86 rte_memcpy() disabled sligthly similar warnings for.

PS:
The alternative was to obfuscate the code, but that would make the code
less readable, and might have unintended effects on architectures and
compilers not suffering by this issue.

Bugzilla ID: 2061
Fixes: ee0822a0ef41 ("stack: introduce pile")

The pile was introduce with this DPDK release, so no need to backport.

Reported-by: Ali Alnubani <alialnu@nvidia.com>
Signed-off-by: Morten Brørup <mb@smartsharesystems.com>
---
 lib/stack/rte_stack_pile.h | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/lib/stack/rte_stack_pile.h b/lib/stack/rte_stack_pile.h
index 819bd1d47a..69aa0cbf88 100644
--- a/lib/stack/rte_stack_pile.h
+++ b/lib/stack/rte_stack_pile.h
@@ -154,12 +154,25 @@ __rte_stack_pile_push(struct rte_stack *s,
 	 * Construct the bulk elements.
 	 * Copy bulks in reverse order, but ignore the object order within each bulk.
 	 */
+#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >= 100000)
+/*
+ * On architectures where rte_memcpy() is defined as memcpy(),
+ * although GCC knows that this code path is not taken when the source's size is smaller than
+ * RTE_STACK_PILE_BULK_SIZE, it still warns about memcpy() source overread.
+ * So we disable the compiler warning for this memcpy() instance.
+ */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstringop-overread"
+#endif
 	tmp = (struct rte_stack_lf_elem *)bulk_first;
 	__rte_assume(n_bulk > 0);
 	for (i = 0; i < n_bulk; i++, tmp = tmp->next)
 		rte_memcpy(((struct rte_stack_pile_bulk_elem *)tmp)->objs,
 				&obj_table[(n_bulk - i - 1) * RTE_STACK_PILE_BULK_SIZE],
 				sizeof(void *) * RTE_STACK_PILE_BULK_SIZE);
+#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >= 100000)
+#pragma GCC diagnostic pop
+#endif
 
 	/* Push them to the bulk list. */
 	__rte_stack_pile_bulk_push_elems(&pile->bulk, bulk_first, bulk_last, n_bulk);
@@ -271,7 +284,20 @@ __rte_stack_pile_pop(struct rte_stack *s,
 
 bulk:
 	/* Fetch n_bulk * RTE_STACK_PILE_BULK_SIZE objects as bulk elements. */
+#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >= 100000)
+/*
+ * On architectures where rte_memcpy() is defined as memcpy(),
+ * although GCC knows that this code path is not taken when the destination's size is smaller than
+ * RTE_STACK_PILE_BULK_SIZE, it still warns about memcpy() destination overflow.
+ * So we disable the compiler warning for this memcpy() instance.
+ */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstringop-overflow"
+#endif
 	bulk_first = __rte_stack_pile_bulk_pop_elems(&pile->bulk, n_bulk, obj_table, &bulk_last);
+#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >= 100000)
+#pragma GCC diagnostic pop
+#endif
 	if (unlikely(bulk_first == NULL)) {
 		/*
 		 * Not available.
-- 
2.43.0


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

end of thread, other threads:[~2026-10-20 15:39 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-20  8:49 [PATCH] stack: fix pile GCC memcpy warnings Morten Brørup
2026-10-20  9:18 ` Bruce Richardson
2026-10-20  9:59   ` Morten Brørup
2026-10-20 10:18 ` Ali Alnubani
2026-10-20 14:23 ` Stephen Hemminger
2026-10-20 15:16   ` Morten Brørup
2026-10-20 15:39     ` Morten Brørup
2026-10-20 14:34 ` Stephen Hemminger
2026-10-20 15:27   ` 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