common/cnxk: remove dependence on VLA
Subsystems (2)
cover common/cnxk: remove dependence on VLA
While looking at LTO compile failures, it looks like the cnxk common code can be modified to not use VLA's. This fixes one of the compile problems there.
Compile tested only!
Stephen Hemminger (3):
common/cnxk: replace variable length state array common/cnxk: replace variable length array common/cnxk: re-enable vla warnings
drivers/common/cnxk/meson.build | 2 -- drivers/common/cnxk/roc_aes.c | 3 ++- drivers/common/cnxk/roc_platform.c | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-)
Signature · 1 line
2.51.0
RFC 1/3 common/cnxk: replace variable length state array
The cipher function is always called with in_len = 16 and there is an existing define for that.
--- drivers/common/cnxk/roc_aes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/common/cnxk/roc_aes.c +2 -1
@@ -157,9 +157,10 @@ static void cipher(uint8_t *in, uint8_t *out, uint32_t *ks, uint32_t key_rounds, uint8_t in_len) {uint8_t data_word_len = in_len /sizeof (uint32_t ); -uint32_t state[data_word_len]; +uint32_t state[AES_HASH_KEY_LEN /sizeof (uint32_t )];unsigned int i, round; +RTE_ASSERT (data_word_len <=AES_HASH_KEY_LEN );memcpy (state, in,sizeof (state));/* AddRoundKey(state, w[0, Nb-1]) // See Sec. 5.1.4 */
Signature · 1 line
2.51.0
RFC 2/3 common/cnxk: replace variable length array
In reply to Stephen HemmingerThis fixes errors when compiled with LTO about large VLA.../drivers/common/cnxk/roc_platform.c: In function ‘irq_init’:../drivers/common/cnxk/roc_platform.c:92:14: warning: argument to variable-length array is too large [-Wvla-larger-than=]
92 | char irq_set_buf[MSIX_IRQ_SET_BUF_LEN];
| ^
Since the number of IRQ is limited by EAL max interrupt vectors use that define that already exists rather than a function call hidden in a macro.
--- drivers/common/cnxk/roc_platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/common/cnxk/roc_platform.c +2 -2
@@ -17,8 +17,8 @@#include <sys/ioctl.h> #include <unistd.h> -#define MSIX_IRQ_SET_BUF_LEN \ - (sizeof(struct vfio_irq_set) + sizeof(int) * (plt_intr_max_intr_get(intr_handle))) +#define MSIX_IRQ_SET_BUF_LEN \ + (sizeof(struct vfio_irq_set) + sizeof(int) * PLT_MAX_RXTX_INTR_VEC_ID)static int irq_get_info (struct plt_intr_handle *intr_handle)
Signature · 1 line
2.51.0
Re: [EXTERNAL] [RFC 2/3] common/cnxk: replace variable length array
Hi Stephen,
Please find response inline.
Thanks
Harman
________________________________________
From: Stephen Hemminger <[email protected]>
Sent: Friday, October 24, 2025 01:11
To: [email protected]
Cc: Stephen Hemminger; Nithin Kumar Dabilpuram; Kiran Kumar Kokkilagadda; Sunil Kumar Kori; Satha Koteswara Rao Kottidi; Harman Kalra
Subject: [EXTERNAL] [RFC 2/3] common/cnxk: replace variable length array
This fixes errors when compiled with LTO about large VLA. .. /drivers/common/cnxk/roc_platform. c: In function ‘irq_init’: .. /drivers/common/cnxk/roc_platform. c: 92: 14: warning: argument to variable-length array is too large [-Wvla-larger-than=] ZjQcmQRYFpfptBannerStart
Prioritize security for external emails:
Confirm sender and content safety before clicking links or opening attachments
<https://us-phishalarm-ewt.proofpoint.com/EWT/v1/CRVmXkqW!tq3Z1f8UAlXatG-dmV0aDgUiMX3k-TnFTMUNNDwBiTqsiDtPNHuGKbTZiCNYBjBSFK8C-DKdl6dvUuA0rM6hZ29mZZl_Zctb5JHJ$>
Report Suspicious
ZjQcmQRYFpfptBannerEnd
This fixes errors when compiled with LTO about large VLA.../drivers/common/cnxk/roc_platform.c: In function ‘irq_init’:../drivers/common/cnxk/roc_platform.c:92:14: warning: argument to variable-length array is too large [-Wvla-larger-than=]
92 | char irq_set_buf[MSIX_IRQ_SET_BUF_LEN];
| ^
Since the number of IRQ is limited by EAL max interrupt vectors use that define that already exists rather than a function call hidden in a macro.
--- drivers/common/cnxk/roc_platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/common/cnxk/roc_platform.c +2 -2
@@ -17,8 +17,8 @@#include <sys/ioctl.h> #include <unistd.h> -#define MSIX_IRQ_SET_BUF_LEN \ - (sizeof(struct vfio_irq_set) + sizeof(int) * (plt_intr_max_intr_get(intr_handle))) +#define MSIX_IRQ_SET_BUF_LEN \ + (sizeof(struct vfio_irq_set) + sizeof(int) * PLT_MAX_RXTX_INTR_VEC_ID)
[HK] The value of MSIX_IRQ_SET_BUF_LEN should be derived from the maximum number of interrupts configured for a PCI device, as obtained via plt_intr_max_intr_get(intr_handle), which internally uses the VFIO_DEVICE_GET_IRQ_INFO ioctl. In contrast, PLT_MAX_RXTX_INTR_VEC_ID is a fixed default value representing the maximum number of interrupt vectors. This mismatch may lead to unexpected behaviour as on certain platforms (like cnxk) where the PCI device's MSIX capability may exceed PLT_MAX_RXTX_INTR_VEC_ID.
static int
irq_get_info(struct plt_intr_handle *intr_handle)
--
2.51.0
RFC 3/3 common/cnxk: re-enable vla warnings
In reply to Stephen HemmingerThe code in common/cnxk no longer uses VLA's.
--- drivers/common/cnxk/meson.build | 2 -- 1 file changed, 2 deletions(-)
drivers/common/cnxk/meson.build +0 -2
@@ -94,8 +94,6 @@ sources += files('cnxk_telemetry_bphy.c', 'cnxk_telemetry_sso.c', ) -cflags += no_wvla_cflag - if meson.is_cross_build() soc_type = meson.get_external_property('platform', '') else
Signature · 1 line
2.51.0
v2 cover common/cnxk: remove variable length arrays
In reply to Stephen HemmingerThis series removes the use of variable length arrays (VLAs) from the common/cnxk driver, allowing the VLA compiler warnings to be re-enabled.
VLAs are problematic for several reasons:
- They can cause stack overflow with large or malicious inputs
- They prevent certain compiler optimizations
- They trigger warnings when compiled with LTO (-Wvla-larger-than=)
- They are optional in C11 and removed in some C dialects
The first patch addresses the AES cipher function which always operates on 16-byte blocks. The VLA is replaced with a fixed-size array using the existing AES_HASH_KEY_LEN define, with an assertion to verify the input constraint.
The second patch fixes the MSIX IRQ set buffer allocation. The original code used a macro that expanded to a runtime function call, which the compiler could not evaluate at compile time. This is replaced with PLT_MAX_RXTX_INTR_VEC_ID, which matches the EAL's maximum interrupt vector limit (512). This is consistent with how the EAL itself handles the same buffer allocation in eal_interrupts.c.
The third patch removes the no_wvla_cflag workaround from meson.build now that the VLAs have been eliminated.
Stephen Hemminger (3):
common/cnxk: replace variable length state array common/cnxk: replace variable length array common/cnxk: re-enable vla warnings
drivers/common/cnxk/meson.build | 2 -- drivers/common/cnxk/roc_aes.c | 3 ++- drivers/common/cnxk/roc_platform.c | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-)
Signature · 1 line
2.51.0
PATCH v2 1/3 common/cnxk: replace variable length state array
The cipher function is always called with in_len = 16 and there is an existing define for that.
--- drivers/common/cnxk/roc_aes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/common/cnxk/roc_aes.c +2 -1
@@ -157,9 +157,10 @@ static void cipher(uint8_t *in, uint8_t *out, uint32_t *ks, uint32_t key_rounds, uint8_t in_len) {uint8_t data_word_len = in_len /sizeof (uint32_t ); -uint32_t state[data_word_len]; +uint32_t state[AES_HASH_KEY_LEN /sizeof (uint32_t )];unsigned int i, round; +RTE_ASSERT (in_len <=AES_HASH_KEY_LEN );memcpy (state, in,sizeof (state));/* AddRoundKey(state, w[0, Nb-1]) // See Sec. 5.1.4 */
Signature · 1 line
2.51.0
PATCH v2 2/3 common/cnxk: replace variable length array
In reply to Stephen HemmingerThis fixes errors when compiled with LTO about large VLA.../drivers/common/cnxk/roc_platform.c: In function ‘irq_init’:../drivers/common/cnxk/roc_platform.c:92:14: warning: argument to variable-length array is too large [-Wvla-larger-than=]
92 | char irq_set_buf[MSIX_IRQ_SET_BUF_LEN];
| ^
Since the number of IRQ is limited by EAL max interrupt vectors use that define that already exists rather than a function call hidden in a macro.
--- drivers/common/cnxk/roc_platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/common/cnxk/roc_platform.c +2 -2
@@ -17,8 +17,8 @@#include <sys/ioctl.h> #include <unistd.h> -#define MSIX_IRQ_SET_BUF_LEN \ - (sizeof(struct vfio_irq_set) + sizeof(int) * (plt_intr_max_intr_get(intr_handle))) +#define MSIX_IRQ_SET_BUF_LEN \ + (sizeof(struct vfio_irq_set) + sizeof(int) * PLT_MAX_RXTX_INTR_VEC_ID)static int irq_get_info (struct plt_intr_handle *intr_handle)
Signature · 1 line
2.51.0
PATCH v2 3/3 common/cnxk: re-enable vla warnings
In reply to Stephen HemmingerThe code in common/cnxk no longer uses VLAs.
--- drivers/common/cnxk/meson.build | 2 -- 1 file changed, 2 deletions(-)
drivers/common/cnxk/meson.build +0 -2
@@ -94,8 +94,6 @@ sources += files('cnxk_telemetry_bphy.c', 'cnxk_telemetry_sso.c', ) -cflags += no_wvla_cflag - if meson.is_cross_build() soc_type = meson.get_external_property('platform', '') else
Signature · 1 line
2.51.0
v3 cover fix GCC warnings when building with LTO
In reply to Stephen HemmingerThis series fixes all warnings produced by GCC when building DPDK with Link Time Optimization (LTO) enabled. LTO performs aggressive cross- compilation-unit inlining and interprocedural analysis, which exposes issues that are not visible during normal compilation.
The problems were diagnosed using AI but the fixes all look very reasonable and consistent with other code.
The fixes fall into three categories:
1. Buffer sizing for static analysis (patches 1, 6)
When LTO inlines functions across compilation units, GCC's static analyzer gains visibility into buffer sizes and all code paths. This causes warnings when the analyzer cannot prove that runtime- selected code paths stay within buffer bounds. The fixes provide either larger buffers or explicit bounds checks to satisfy the analyzer.
2. Variable Length Array (VLA) elimination (patches 2, 3, 4)
VLAs cause -Wvla-larger-than warnings with LTO because the compiler cannot determine array bounds at compile time. These patches replace VLAs with fixed-size arrays using existing defines, then remove the warning suppression flag that was masking the issue.
3. Genuine bug fix (patch 5)
The LTO analysis uncovered an actual buffer overflow bug where a 1-byte allocation was being used for an 808-byte structure. This is a real memory corruption issue, not just a false positive.
The patches have been tested with GCC 14 using -flto=auto and produce a clean build with no warnings.
v3 - add all the other stuff necessary to fix all the LTO warnings
Stephen Hemminger (6):
test/soring: fix buffer overflow warnings with LTO common/cnxk: replace variable length state array common/cnxk: replace variable length array common/cnxk: re-enable vla warnings
common/cnxk: fix buffer overflow in reassembly SA setup net/mlx5/hws: fix LTO false positive stringop-overflow warning
app/test/test_soring.c | 29 +++++++++++++++++++++------- drivers/common/cnxk/meson.build | 2 -- drivers/common/cnxk/roc_aes.c | 3 ++- drivers/common/cnxk/roc_nix_inl.c | 2 +- drivers/common/cnxk/roc_platform.c | 4 ++-- drivers/net/mlx5/hws/mlx5dr_action.c | 14 ++++++++++++++ 6 files changed, 41 insertions(+), 13 deletions(-)
Signature · 1 line
2.51.0
PATCH v3 1/6 test/soring: fix buffer overflow warnings with LTO
When building with LTO (Link Time Optimization), GCC performs aggressive cross-compilation-unit inlining. This causes the compiler to analyze all code paths in __rte_ring_do_dequeue_elems(), including the 16-byte element path (__rte_ring_dequeue_elems_128), even when the runtime element size is only 4 bytes.
The static analyzer sees that the 16-byte path would copy
32 elements * 16 bytes = 512 bytes into a 128-byte buffer (uint32_t[32]), triggering -Wstringop-overflow warnings.
The existing #pragma GCC diagnostic suppression in rte_ring_elem_pvt.h doesn't help because with LTO the warning context shifts to the test file where the inlined code is instantiated.
Fix by sizing all buffers passed to soring acquire/dequeue functions for the worst-case element size (16 bytes = 4 * sizeof(uint32_t)). This satisfies the static analyzer without changing runtime behavior.
Bugzilla ID: 1458
--- app/test/test_soring.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-)
app/test/test_soring.c +22 -7
@@ -31,6 +31,19 @@#define MAX_ACQUIRED 20 +/* +* Buffer scaling factor for static analyzer appeasement. +* +* With LTO, GCC analyzes all code paths in __rte_ring_do_dequeue_elems(), +* including the 16-byte element path, even when runtime esize is smaller. +* Buffers passed to soring acquire/dequeue must be sized for the worst-case +* element size (16 bytes) to avoid -Wstringop-overflow warnings. +* +* Scale factor of 4 converts uint32_t count to 16-byte element capacity: +* N elements * 4 * sizeof(uint32_t) = N * 16 bytes +*/ +#define SORING_TEST_BUFSIZE (n) ((n) * 4) +#define SORING_TEST_ASSERT (val, expected) do { \ RTE_TEST_ASSERT(expected == val, \ "%s: expected %u got %u\n", #val, expected, val); \
@@ -58,7 +71,8 @@ move_forward_stage(struct rte_soring *sor, {uint32_t acquired;uint32_t ftoken; -uint32_t *acquired_objs[MAX_ACQUIRED ]; +/* Sized for 16-byte elements to satisfy LTO static analysis */ +uint32_t *acquired_objs[SORING_TEST_BUFSIZE (MAX_ACQUIRED )]; acquired =rte_soring_acquire_bulk (sor, acquired_objs, stage, num_packets, &ftoken,NULL );
@@ -149,12 +163,13 @@ test_soring_stages(void) {struct rte_soring *sor =NULL ;struct rte_soring_param prm; -uint32_t objs[32 ]; -uint32_t rcs[32 ]; -uint32_t acquired_objs[32 ]; -uint32_t acquired_rcs[32 ]; -uint32_t dequeued_rcs[32 ]; -uint32_t dequeued_objs[32 ]; +/* Buffers sized for 16-byte elements to satisfy LTO static analysis */ +uint32_t objs[SORING_TEST_BUFSIZE (32 )]; +uint32_t rcs[SORING_TEST_BUFSIZE (32 )]; +uint32_t acquired_objs[SORING_TEST_BUFSIZE (32 )]; +uint32_t acquired_rcs[SORING_TEST_BUFSIZE (32 )]; +uint32_t dequeued_rcs[SORING_TEST_BUFSIZE (32 )]; +uint32_t dequeued_objs[SORING_TEST_BUFSIZE (32 )];size_t ssz;uint32_t stage, enqueued, dequeued, acquired;uint32_t i, ftoken;
Signature · 1 line
2.51.0
RE: [PATCH v3 1/6] test/soring: fix buffer overflow warnings with LTO
Quoted 14 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Friday, 16 January 2026 07.46When building with LTO (Link Time Optimization), GCC performs aggressive cross-compilation-unit inlining. This causes the compiler to analyze all code paths in
__rte_ring_do_dequeue_elems(), including the 16-byte element path (__rte_ring_dequeue_elems_128), even when the runtime element size is only 4 bytes.The static analyzer sees that the 16-byte path would copy 32 elements * 16 bytes = 512 bytes into a 128-byte buffer (uint32_t[32]),
triggering -Wstringop-overflow warnings.
Quoted 7 lines
The existing #pragma GCC diagnostic suppression in
rte_ring_elem_pvt.hdoesn't help because with LTO the warning context shifts to the test file where the inlined code is instantiated.Fix by sizing all buffers passed to soring acquire/dequeue functions for the worst-case element size (16 bytes = 4 *
sizeof(uint32_t)). This satisfies the static analyzer without changing runtime behavior.
Using wildly oversized buffers doesn't seem like a recommendable solution.
If the ring library is ever updated to support cache size elements (64 byte), the buffers would have to be oversize by factor 16.
Maybe adding __rte_assume(sor->esize == sizeof(uint32_t)); immediately before calling each of the affected soring functions would fix the problem instead?
It's only a test application, so oversized buffers as a workaround is acceptable.
But if it serves as guidance for real applications, a better solution/workaround would be preferable.
Quoted 69 lines
Bugzilla ID: 1458
Signed-off-by Stephen Hemminger <[email protected]>--- app/test/test_soring.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-)app/test/test_soring.c +5
-0@@ -31,6 +31,19 @@#define MAX_ACQUIRED 20 +/* +* Buffer scaling factor for static analyzer appeasement. +* +* With LTO, GCC analyzes all code paths in __rte_ring_do_dequeue_elems(), +* including the 16-byte element path, even when runtime esize is smaller.
+ * Buffers passed to soring acquire/dequeue must be sized for the worst-case
+ * element size (16 bytes) to avoid -Wstringop-overflow warnings.
+ *
+ * Scale factor of 4 convertsuint32_tcount to 16-byte element capacity:
+ * N elements * 4 *sizeof(uint32_t)= N * 16 bytes
+ */app/test/test_soring.c +5
-7+#define SORING_TEST_BUFSIZE (n) ((n) * 4) +#define SORING_TEST_ASSERT (val, expected) do { \ RTE_TEST_ASSERT(expected == val, \ "%s: expected %u got %u\n", #val, expected, val); \@@ -58,7 +71,8 @@ move_forward_stage(struct rte_soring *sor, {uint32_t acquired;uint32_t ftoken; -uint32_t *acquired_objs[MAX_ACQUIRED ]; +/* Sized for 16-byte elements to satisfy LTO static analysis */ +uint32_t *acquired_objs[SORING_TEST_BUFSIZE (MAX_ACQUIRED )]; acquired =rte_soring_acquire_bulk (sor, acquired_objs, stage, num_packets, &ftoken,NULL );@@ -149,12 +163,13 @@ test_soring_stages(void) {struct rte_soring *sor =NULL ;struct rte_soring_param prm; -uint32_t objs[32 ]; -uint32_t rcs[32 ]; -uint32_t acquired_objs[32 ]; -uint32_t acquired_rcs[32 ]; -uint32_t dequeued_rcs[32 ]; -uint32_t dequeued_objs[32 ]; +/* Buffers sized for 16-byte elements to satisfy LTO static analysis */
app/test/test_soring.c +6
-1+uint32_t objs[SORING_TEST_BUFSIZE (32 )]; +uint32_t rcs[SORING_TEST_BUFSIZE (32 )]; +uint32_t acquired_objs[SORING_TEST_BUFSIZE (32 )]; +uint32_t acquired_rcs[SORING_TEST_BUFSIZE (32 )]; +uint32_t dequeued_rcs[SORING_TEST_BUFSIZE (32 )]; +uint32_t dequeued_objs[SORING_TEST_BUFSIZE (32 )];size_t ssz;uint32_t stage, enqueued, dequeued, acquired;uint32_t i, ftoken; --2.51.0
Re: [PATCH v3 1/6] test/soring: fix buffer overflow warnings with LTO
Quoted 18 lines · On Fri, 16 Jan 2026 10:32:52 +0100 Morten Brørup <[email protected]>…
Quoted 18 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Friday, 16 January 2026 07.46When building with LTO (Link Time Optimization), GCC performs aggressive cross-compilation-unit inlining. This causes the compiler to analyze all code paths in
__rte_ring_do_dequeue_elems(), including the 16-byte element path (__rte_ring_dequeue_elems_128), even when the runtime element size is only 4 bytes.The static analyzer sees that the 16-byte path would copy 32 elements * 16 bytes = 512 bytes into a 128-byte buffer (uint32_t[32]),
triggering -Wstringop-overflow warnings.The existing #pragma GCC diagnostic suppression in
rte_ring_elem_pvt.hdoesn't help because with LTO the warning context shifts to the test file where the inlined code is instantiated.
Quoted 6 lines
Quoted 3 lines
Fix by sizing all buffers passed to soring acquire/dequeue functions for the worst-case element size (16 bytes = 4 *
sizeof(uint32_t)). This satisfies the static analyzer without changing runtime behavior.Using wildly oversized buffers doesn't seem like a recommendable solution.
If the ring library is ever updated to support cache size elements (64 byte), the buffers would have to be oversize by factor 16.
The analysis (from AI) is that compiler is getting confused. Since there is no good way other than turning of LTO for the test to tell the compiler
Quoted 6 lines
Maybe adding
__rte_assume(sor->esize == sizeof(uint32_t)); immediately before calling each of the affected soring functions would fix the problem instead?It's only a test application, so oversized buffers as a workaround is acceptable.
But if it serves as guidance for real applications, a better solution/workaround would be preferable.
RE: [PATCH v3 1/6] test/soring: fix buffer overflow warnings with LTO
Quoted 6 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, 19 January 2026 23.48On Fri, 16 Jan 2026 10:32:52 +0100
Morten Brørup <[email protected]> wrote:
Quoted 15 lines
Quoted 5 lines
Quoted 5 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Friday, 16 January 2026 07.46When building with LTO (Link Time Optimization), GCC performs aggressive cross-compilation-unit inlining. This causes the
compiler
Quoted 1 line
Quoted 1 line
to analyze all code paths in
__rte_ring_do_dequeue_elems(),including
Quoted 7 lines
Quoted 7 lines
the 16-byte element path (
__rte_ring_dequeue_elems_128), even when the runtime element size is only 4 bytes.The static analyzer sees that the 16-byte path would copy 32 elements * 16 bytes = 512 bytes into a 128-byte buffer (uint32_t[32]),
triggering -Wstringop-overflow warnings.
The element size is not an inline function parameter, but fetched from the "esize" field in the rte_soring structure, so the compiler cannot see that the element size is 4 bytes. And thus it needs to consider all possible element sizes.
Quoted 11 lines
Quoted 2 lines
Quoted 2 lines
The existing #pragma GCC diagnostic suppression in
rte_ring_elem_pvt.hQuoted 1 line
Quoted 1 line
doesn't help because with LTO the warning context shifts to the
test
Quoted 3 lines
Quoted 3 lines
file where the inlined code is instantiated.
Fix by sizing all buffers passed to soring acquire/dequeue
functions
Quoted 2 lines
Quoted 2 lines
for the worst-case element size (16 bytes = 4 *
sizeof(uint32_t)). This satisfies the static analyzer without changing runtime
Quoted 8 lines
behavior.
Quoted 2 lines
Using wildly oversized buffers doesn't seem like a recommendable
solution.
Quoted 1 line
If the ring library is ever updated to support cache size elements
(64 byte), the buffers would have to be oversize by factor 16.
The analysis (from AI) is that compiler is getting confused.
That would be my analysis too.
Quoted 2 lines
Since there is no good
way other than turning of LTO for the test to tell the compiler
There is another way to tell the compiler: __rte_assume()
Quoted 5 lines
Quoted 3 lines
Maybe adding
__rte_assume(sor->esize == sizeof(uint32_t));immediately before calling each of the affected soring functions would fix the problem instead?
The soring functions are inline, so adding __rte_assume(sor->esize == sizeof(uint32_t)) before calling them tells the compiler that only the code path for 4 byte element size is relevant, so the compiler can eliminate the code paths for other element sizes.
Using __rte_assume() has worked for me in other cases, not just for optimization purposes, but also when the compiler gets confused about potential buffer overruns (that we know cannot occur, i.e. false positives).
It might solve this problem too.
IMO, it is generally preferable to help the compiler (by providing hints) rather than implementing workarounds (using oversized buffers in this case).
Quoted 6 lines
Quoted 2 lines
It's only a test application, so oversized buffers as a workaround is
acceptable.
Quoted 2 lines
But if it serves as guidance for real applications, a better
solution/workaround would be preferable.
Re: [PATCH v3 1/6] test/soring: fix buffer overflow warnings with LTO
Quoted 42 lines · On Tue, 20 Jan 2026 09:49:44 +0100 Morten Brørup <[email protected]>…
Quoted 6 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, 19 January 2026 23.48On Fri, 16 Jan 2026 10:32:52 +0100
Morten Brørup <[email protected]> wrote:Quoted 15 lines
Quoted 5 lines
Quoted 5 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Friday, 16 January 2026 07.46When building with LTO (Link Time Optimization), GCC performs aggressive cross-compilation-unit inlining. This causes the
compiler
Quoted 1 line
Quoted 1 line
to analyze all code paths in
__rte_ring_do_dequeue_elems(),including
Quoted 7 lines
Quoted 7 lines
the 16-byte element path (
__rte_ring_dequeue_elems_128), even when the runtime element size is only 4 bytes.The static analyzer sees that the 16-byte path would copy 32 elements * 16 bytes = 512 bytes into a 128-byte buffer (uint32_t[32]),
triggering -Wstringop-overflow warnings.The element size is not an inline function parameter, but fetched from the "esize" field in the
rte_soringstructure, so the compiler cannot see that the element size is 4 bytes. And thus it needs to consider all possible element sizes.Quoted 18 lines
Quoted 2 lines
Quoted 2 lines
The existing #pragma GCC diagnostic suppression in
rte_ring_elem_pvt.hQuoted 1 line
Quoted 1 line
doesn't help because with LTO the warning context shifts to the
test
Quoted 3 lines
Quoted 3 lines
file where the inlined code is instantiated.
Fix by sizing all buffers passed to soring acquire/dequeue
functions
Quoted 2 lines
Quoted 2 lines
for the worst-case element size (16 bytes = 4 *
sizeof(uint32_t)). This satisfies the static analyzer without changing runtimebehavior.
Quoted 2 lines
Using wildly oversized buffers doesn't seem like a recommendable
solution.
Quoted 1 line
If the ring library is ever updated to support cache size elements
(64 byte), the buffers would have to be oversize by factor 16.
Quoted 8 lines
Quoted 1 line
The analysis (from AI) is that compiler is getting confused.
That would be my analysis too.
Quoted 2 lines
Since there is no good
way other than turning of LTO for the test to tell the compilerThere is another way to tell the compiler:
__rte_assume()
Tried that but it doesn't work because doesn't get propagated deep enough to impact here.
RE: [PATCH v3 1/6] test/soring: fix buffer overflow warnings with LTO
Quoted 58 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, 20 January 2026 15.34Quoted 9 lines · On Tue, 20 Jan 2026 09:49:44 +0100 Morten Brørup <[email protected]>…
Quoted 9 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, 19 January 2026 23.48Quoted 3 lines · On Fri, 16 Jan 2026 10:32:52 +0100 Morten Brørup <[email protected]>…
Quoted 3 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Friday, 16 January 2026 07.46Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
When building with LTO (Link Time Optimization), GCC performs aggressive cross-compilation-unit inlining. This causes the
compiler
Quoted 1 line
Quoted 1 line
to analyze all code paths in
__rte_ring_do_dequeue_elems(),including
Quoted 1 line
Quoted 1 line
the 16-byte element path (
__rte_ring_dequeue_elems_128), evenwhen
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
the runtime element size is only 4 bytes.
The static analyzer sees that the 16-byte path would copy 32 elements * 16 bytes = 512 bytes into a 128-byte buffer (uint32_t[32]),
triggering -Wstringop-overflow warnings.The element size is not an inline function parameter, but fetched
from the "esize" field in the
rte_soringstructure, so the compiler cannot see that the element size is 4 bytes. And thus it needs to consider all possible element sizes.Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Quoted 3 lines
The existing #pragma GCC diagnostic suppression in
rte_ring_elem_pvt.hQuoted 1 line
Quoted 1 line
doesn't help because with LTO the warning context shifts to the
test
Quoted 3 lines
Quoted 3 lines
file where the inlined code is instantiated.
Fix by sizing all buffers passed to soring acquire/dequeue
functions
Quoted 1 line
Quoted 1 line
for the worst-case element size (16 bytes = 4 *
sizeof(uint32_t)).Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
This satisfies the static analyzer without changing runtime
behavior.
Quoted 2 lines
Using wildly oversized buffers doesn't seem like a recommendable
solution.
Quoted 1 line
If the ring library is ever updated to support cache size
elements
Quoted 6 lines
Quoted 3 lines
(64 byte), the buffers would have to be oversize by factor 16.
The analysis (from AI) is that compiler is getting confused.
That would be my analysis too.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Since there is no good
way other than turning of LTO for the test to tell the compilerThere is another way to tell the compiler:
__rte_assume()Tried that but it doesn't work because doesn't get propagated deep enough to impact here.
Does this fix generally imply that when using LTO, using an SORING with elements smaller than 16 bytes requires oversize buffers? That's not good. :-(
The SORING is still experimental.
Maybe the element size and metadata size need to be passed as parameters to the SORING functions, like the RING functions take element size as parameter (except the functions that are hardcoded for using pointers as element size).
RE: [PATCH v3 1/6] test/soring: fix buffer overflow warnings with LTO
Quoted 68 lines
Quoted 60 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, 20 January 2026 15.34Quoted 9 lines · On Tue, 20 Jan 2026 09:49:44 +0100 Morten Brørup <[email protected]>…
Quoted 9 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, 19 January 2026 23.48Quoted 3 lines · On Fri, 16 Jan 2026 10:32:52 +0100 Morten Brørup <[email protected]>…
Quoted 3 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Friday, 16 January 2026 07.46Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
When building with LTO (Link Time Optimization), GCC performs aggressive cross-compilation-unit inlining. This causes the
compiler
Quoted 1 line
Quoted 1 line
to analyze all code paths in
__rte_ring_do_dequeue_elems(),including
Quoted 1 line
Quoted 1 line
the 16-byte element path (
__rte_ring_dequeue_elems_128), evenwhen
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
the runtime element size is only 4 bytes.
The static analyzer sees that the 16-byte path would copy 32 elements * 16 bytes = 512 bytes into a 128-byte buffer (uint32_t[32]),
triggering -Wstringop-overflow warnings.The element size is not an inline function parameter, but fetched
from the "esize" field in the
rte_soringstructure, so the compiler cannot see that the element size is 4 bytes. And thus it needs to consider all possible element sizes.Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Quoted 3 lines
The existing #pragma GCC diagnostic suppression in
rte_ring_elem_pvt.hQuoted 1 line
Quoted 1 line
doesn't help because with LTO the warning context shifts to the
test
Quoted 3 lines
Quoted 3 lines
file where the inlined code is instantiated.
Fix by sizing all buffers passed to soring acquire/dequeue
functions
Quoted 1 line
Quoted 1 line
for the worst-case element size (16 bytes = 4 *
sizeof(uint32_t)).Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
This satisfies the static analyzer without changing runtime
behavior.
Quoted 2 lines
Using wildly oversized buffers doesn't seem like a recommendable
solution.
Quoted 1 line
If the ring library is ever updated to support cache size
elements
Quoted 6 lines
Quoted 3 lines
(64 byte), the buffers would have to be oversize by factor 16.
The analysis (from AI) is that compiler is getting confused.
That would be my analysis too.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Since there is no good
way other than turning of LTO for the test to tell the compilerThere is another way to tell the compiler:
__rte_assume()Tried that but it doesn't work because doesn't get propagated deep enough to impact here.
Quoted 8 lines
Does this fix generally imply that when using LTO, using an SORING with elements smaller than 16 bytes requires oversize buffers?
That's not good. :-(The SORING is still experimental.
Maybe the element size and metadata size need to be passed as parameters to the SORING functions, like the RING functions take element size as parameter (except the functions that are hardcoded for using pointers as element size).
Personally, I am not a big fan of such idea...
Wonder is that possible just to disable LTO for soring.o?
Another thought - if all the problems come from 128 bit version of enque/dequeue, would using memcpy() instead of specific functions help to mitigate the problem?
Re: [PATCH v3 1/6] test/soring: fix buffer overflow warnings with LTO
Quoted 75 lines · On Tue, 20 Jan 2026 15:40:21 +0000 Konstantin Ananyev…
Quoted 66 lines
Quoted 58 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, 20 January 2026 15.34Quoted 9 lines · On Tue, 20 Jan 2026 09:49:44 +0100 Morten Brørup <[email protected]>…
Quoted 9 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, 19 January 2026 23.48Quoted 3 lines · On Fri, 16 Jan 2026 10:32:52 +0100 Morten Brørup <[email protected]>…
Quoted 3 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Friday, 16 January 2026 07.46Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
When building with LTO (Link Time Optimization), GCC performs aggressive cross-compilation-unit inlining. This causes the
compiler
Quoted 1 line
Quoted 1 line
to analyze all code paths in
__rte_ring_do_dequeue_elems(),including
Quoted 1 line
Quoted 1 line
the 16-byte element path (
__rte_ring_dequeue_elems_128), evenwhen
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
the runtime element size is only 4 bytes.
The static analyzer sees that the 16-byte path would copy 32 elements * 16 bytes = 512 bytes into a 128-byte buffer (uint32_t[32]),
triggering -Wstringop-overflow warnings.The element size is not an inline function parameter, but fetched
from the "esize" field in the
rte_soringstructure, so the compiler cannot see that the element size is 4 bytes. And thus it needs to consider all possible element sizes.Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Quoted 3 lines
The existing #pragma GCC diagnostic suppression in
rte_ring_elem_pvt.hQuoted 1 line
Quoted 1 line
doesn't help because with LTO the warning context shifts to the
test
Quoted 3 lines
Quoted 3 lines
file where the inlined code is instantiated.
Fix by sizing all buffers passed to soring acquire/dequeue
functions
Quoted 1 line
Quoted 1 line
for the worst-case element size (16 bytes = 4 *
sizeof(uint32_t)).Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
This satisfies the static analyzer without changing runtime
behavior.
Quoted 2 lines
Using wildly oversized buffers doesn't seem like a recommendable
solution.
Quoted 1 line
If the ring library is ever updated to support cache size
elements
Quoted 6 lines
Quoted 3 lines
(64 byte), the buffers would have to be oversize by factor 16.
The analysis (from AI) is that compiler is getting confused.
That would be my analysis too.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Since there is no good
way other than turning of LTO for the test to tell the compilerThere is another way to tell the compiler:
__rte_assume()Tried that but it doesn't work because doesn't get propagated deep enough to impact here.
Quoted 8 lines
Does this fix generally imply that when using LTO, using an SORING with elements smaller than 16 bytes requires oversize buffers?
That's not good. :-(The SORING is still experimental.
Maybe the element size and metadata size need to be passed as parameters to the SORING functions, like the RING functions take element size as parameter (except the functions that are hardcoded for using pointers as element size).
Quoted 6 lines
Personally, I am not a big fan of such idea...
Wonder is that possible just to disable LTO for soring.o?
Another thought - if all the problems come from 128 bit version of enque/dequeue, would usingmemcpy()instead of specific functions help to mitigate the problem?
Not sure if disabling for single file works.
My goal is just to make LTO build work without any warnings. LTO has proved useful in finding bugs where arrays are overwritten.
Re: [PATCH v3 1/6] test/soring: fix buffer overflow warnings with LTO
In reply to Konstantin AnanyevQuoted 75 lines · On Tue, 20 Jan 2026 15:40:21 +0000 Konstantin Ananyev…
Quoted 66 lines
Quoted 58 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, 20 January 2026 15.34Quoted 9 lines · On Tue, 20 Jan 2026 09:49:44 +0100 Morten Brørup <[email protected]>…
Quoted 9 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, 19 January 2026 23.48Quoted 3 lines · On Fri, 16 Jan 2026 10:32:52 +0100 Morten Brørup <[email protected]>…
Quoted 3 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Friday, 16 January 2026 07.46Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
When building with LTO (Link Time Optimization), GCC performs aggressive cross-compilation-unit inlining. This causes the
compiler
Quoted 1 line
Quoted 1 line
to analyze all code paths in
__rte_ring_do_dequeue_elems(),including
Quoted 1 line
Quoted 1 line
the 16-byte element path (
__rte_ring_dequeue_elems_128), evenwhen
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
the runtime element size is only 4 bytes.
The static analyzer sees that the 16-byte path would copy 32 elements * 16 bytes = 512 bytes into a 128-byte buffer (uint32_t[32]),
triggering -Wstringop-overflow warnings.The element size is not an inline function parameter, but fetched
from the "esize" field in the
rte_soringstructure, so the compiler cannot see that the element size is 4 bytes. And thus it needs to consider all possible element sizes.Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Quoted 3 lines
The existing #pragma GCC diagnostic suppression in
rte_ring_elem_pvt.hQuoted 1 line
Quoted 1 line
doesn't help because with LTO the warning context shifts to the
test
Quoted 3 lines
Quoted 3 lines
file where the inlined code is instantiated.
Fix by sizing all buffers passed to soring acquire/dequeue
functions
Quoted 1 line
Quoted 1 line
for the worst-case element size (16 bytes = 4 *
sizeof(uint32_t)).Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
This satisfies the static analyzer without changing runtime
behavior.
Quoted 2 lines
Using wildly oversized buffers doesn't seem like a recommendable
solution.
Quoted 1 line
If the ring library is ever updated to support cache size
elements
Quoted 6 lines
Quoted 3 lines
(64 byte), the buffers would have to be oversize by factor 16.
The analysis (from AI) is that compiler is getting confused.
That would be my analysis too.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Since there is no good
way other than turning of LTO for the test to tell the compilerThere is another way to tell the compiler:
__rte_assume()Tried that but it doesn't work because doesn't get propagated deep enough to impact here.
Quoted 8 lines
Does this fix generally imply that when using LTO, using an SORING with elements smaller than 16 bytes requires oversize buffers?
That's not good. :-(The SORING is still experimental.
Maybe the element size and metadata size need to be passed as parameters to the SORING functions, like the RING functions take element size as parameter (except the functions that are hardcoded for using pointers as element size).
Quoted 6 lines
Personally, I am not a big fan of such idea...
Wonder is that possible just to disable LTO for soring.o?
Another thought - if all the problems come from 128 bit version of enque/dequeue, would usingmemcpy()instead of specific functions help to mitigate the problem?
I did some more experiments using pragmas, and attributes. The good news is it works for some versions of Gcc,
the bad news is that pragmas and optimization changes on function basis seem to crash old compilers, and be disabled in Gcc 16 and get:
../app/test/test_soring.c:154:1: warning: bad option ‘-fno-lto’ to attribute ‘optimize’ [-Wattributes]
Re: [PATCH v3 1/6] test/soring: fix buffer overflow warnings with LTO
In reply to Konstantin AnanyevQuoted 75 lines · On Tue, 20 Jan 2026 15:40:21 +0000 Konstantin Ananyev…
Quoted 66 lines
Quoted 58 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, 20 January 2026 15.34Quoted 9 lines · On Tue, 20 Jan 2026 09:49:44 +0100 Morten Brørup <[email protected]>…
Quoted 9 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, 19 January 2026 23.48Quoted 3 lines · On Fri, 16 Jan 2026 10:32:52 +0100 Morten Brørup <[email protected]>…
Quoted 3 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Friday, 16 January 2026 07.46Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
When building with LTO (Link Time Optimization), GCC performs aggressive cross-compilation-unit inlining. This causes the
compiler
Quoted 1 line
Quoted 1 line
to analyze all code paths in
__rte_ring_do_dequeue_elems(),including
Quoted 1 line
Quoted 1 line
the 16-byte element path (
__rte_ring_dequeue_elems_128), evenwhen
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
the runtime element size is only 4 bytes.
The static analyzer sees that the 16-byte path would copy 32 elements * 16 bytes = 512 bytes into a 128-byte buffer (uint32_t[32]),
triggering -Wstringop-overflow warnings.The element size is not an inline function parameter, but fetched
from the "esize" field in the
rte_soringstructure, so the compiler cannot see that the element size is 4 bytes. And thus it needs to consider all possible element sizes.Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Quoted 3 lines
The existing #pragma GCC diagnostic suppression in
rte_ring_elem_pvt.hQuoted 1 line
Quoted 1 line
doesn't help because with LTO the warning context shifts to the
test
Quoted 3 lines
Quoted 3 lines
file where the inlined code is instantiated.
Fix by sizing all buffers passed to soring acquire/dequeue
functions
Quoted 1 line
Quoted 1 line
for the worst-case element size (16 bytes = 4 *
sizeof(uint32_t)).Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
This satisfies the static analyzer without changing runtime
behavior.
Quoted 2 lines
Using wildly oversized buffers doesn't seem like a recommendable
solution.
Quoted 1 line
If the ring library is ever updated to support cache size
elements
Quoted 6 lines
Quoted 3 lines
(64 byte), the buffers would have to be oversize by factor 16.
The analysis (from AI) is that compiler is getting confused.
That would be my analysis too.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Since there is no good
way other than turning of LTO for the test to tell the compilerThere is another way to tell the compiler:
__rte_assume()Tried that but it doesn't work because doesn't get propagated deep enough to impact here.
Quoted 8 lines
Does this fix generally imply that when using LTO, using an SORING with elements smaller than 16 bytes requires oversize buffers?
That's not good. :-(The SORING is still experimental.
Maybe the element size and metadata size need to be passed as parameters to the SORING functions, like the RING functions take element size as parameter (except the functions that are hardcoded for using pointers as element size).
Quoted 6 lines
Personally, I am not a big fan of such idea...
Wonder is that possible just to disable LTO for soring.o?
Another thought - if all the problems come from 128 bit version of enque/dequeue, would usingmemcpy()instead of specific functions help to mitigate the problem?
A much simpler and clear solution is to just get rid of __rte_always_inline and use inline instead. The compiler still inlines a lot but it can make its own decision.
The attribute always_inline is not always faster, in fact in real world applications it can make things slower because real applications get i-cache misses and lots of inline expansion makes it worse.
RE: [PATCH v3 1/6] test/soring: fix buffer overflow warnings with LTO
Quoted 114 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, 20 January 2026 20.27Quoted 6 lines · On Tue, 20 Jan 2026 15:40:21 +0000 Konstantin Ananyev…
Quoted 6 lines
Quoted 6 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, 20 January 2026 15.34On Tue, 20 Jan 2026 09:49:44 +0100
Morten Brørup <[email protected]> wrote:Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, 19 January 2026 23.48Quoted 1 line · On Fri, 16 Jan 2026 10:32:52 +0100 Morten Brørup <[email protected]>…
Quoted 1 line
From: Stephen Hemminger
[mailto:[email protected]]
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Sent: Friday, 16 January 2026 07.46
When building with LTO (Link Time Optimization), GCC
performs
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
aggressive cross-compilation-unit inlining. This causes
the
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
compiler
Quoted 1 line
Quoted 1 line
to analyze all code paths in
__rte_ring_do_dequeue_elems(),Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
including
Quoted 1 line
Quoted 1 line
the 16-byte element path (
__rte_ring_dequeue_elems_128),even
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
when
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
the runtime element size is only 4 bytes.
The static analyzer sees that the 16-byte path would copy 32 elements * 16 bytes = 512 bytes into a 128-byte buffer (uint32_t[32]),
triggering -Wstringop-overflow warnings.The element size is not an inline function parameter, but
fetched
Quoted 1 line
Quoted 1 line
Quoted 1 line
from the "esize" field in the
rte_soringstructure, so thecompiler
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
cannot see that the element size is 4 bytes. And thus it needs to consider all possible element sizes.
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
The existing #pragma GCC diagnostic suppression in
rte_ring_elem_pvt.hQuoted 1 line
Quoted 1 line
doesn't help because with LTO the warning context shifts
to the
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
test
Quoted 3 lines
Quoted 3 lines
file where the inlined code is instantiated.
Fix by sizing all buffers passed to soring
acquire/dequeue
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
functions
Quoted 1 line
Quoted 1 line
for the worst-case element size (16 bytes = 4 *
sizeof(uint32_t)).Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
This satisfies the static analyzer without changing
runtime
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
behavior.
Quoted 2 lines
Using wildly oversized buffers doesn't seem like a
recommendable
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
solution.
Quoted 1 line
If the ring library is ever updated to support cache size
elements
Quoted 1 line
Quoted 1 line
(64 byte), the buffers would have to be oversize by factor
16.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
The analysis (from AI) is that compiler is getting confused.
That would be my analysis too.
Quoted 2 lines
Since there is no good
way other than turning of LTO for the test to tell thecompiler
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
There is another way to tell the compiler:
__rte_assume()Tried that but it doesn't work because doesn't get propagated
deep
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
enough to impact here.
Does this fix generally imply that when using LTO, using an SORING
with elements
Quoted 5 lines
Quoted 5 lines
smaller than 16 bytes requires oversize buffers?
That's not good. :-(The SORING is still experimental.
Maybe the element size and metadata size need to be passed asparameters to
Quoted 1 line
Quoted 1 line
the SORING functions, like the RING functions take element size as
parameter
Quoted 1 line
Quoted 1 line
(except the functions that are hardcoded for using pointers as
element size).
Quoted 4 lines
Personally, I am not a big fan of such idea...
Wonder is that possible just to disable LTO for soring.o? Another thought - if all the problems come from 128 bit version ofenque/dequeue,
Quoted 1 line
would using
memcpy()instead of specific functions help to mitigatethe problem?
Quoted 2 lines
A much simpler and clear solution is to just get rid of
__rte_always_inline
and use inline instead. The compiler still inlines a lot but it can make its
own decision.
Quoted 4 lines
The attribute
always_inlineis not always faster, in fact in real world applications it can make things slower because real applications get i- cache
misses and lots of inline expansion makes it worse.
Here's another (untested) idea...
Maybe it would help moving the inlining around.
The SORING way of inlining differs from the RING way of inlining.
In RING inlining starts at the outermost layer.
*rte_ring.h:*
static __rte_always_inline unsigned int rte_ring_dequeue_bulk(struct rte_ring *r, void **obj_table, unsigned int n,
unsigned int *available)
{
return rte_ring_dequeue_bulk_elem(r, obj_table, sizeof(void *),
n, available);In SORING, the outermost layer is a normal function.
*rte_soring.h:*__rte_experimentaluint32_t
rte_soring_dequeue_bulk(struct rte_soring *r, void *objs,
uint32_t num, uint32_t *available);
*soring.c:* RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_soring_dequeue_bulk, 25.03) uint32_t
rte_soring_dequeue_bulk(struct rte_soring *r, void *objs, uint32_t num,
uint32_t *available)
{
return soring_dequeue(r, objs, NULL, num, RTE_RING_QUEUE_FIXED,
available);
}Note that for RING, the element size is determined at the outermost layer and passed as a parameter to the underlying functions.
I'm not sure that modifying SORING to the same style of inlining solves anything. The element size is build time constant for RING, but SORING would have to pass r->esize as element size parameter, and that is not build time constant. With such a change, my suggestion of adding __rte_assume(r->esize == sizeof(uint32_t)) at the application might work.
In my experience, __rte_assume() needs to be very close to the code using it, or it has no effect.
It would be an ABI change, but not an API change.
RE: [PATCH v3 1/6] test/soring: fix buffer overflow warnings with LTO
In reply to Stephen HemmingerQuoted 90 lines
Quoted 61 lines · On Tue, 20 Jan 2026 15:40:21 +0000 Konstantin Ananyev…
Quoted 61 lines
Quoted 61 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, 20 January 2026 15.34Quoted 9 lines · On Tue, 20 Jan 2026 09:49:44 +0100 Morten Brørup <[email protected]>…
Quoted 9 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, 19 January 2026 23.48Quoted 3 lines · On Fri, 16 Jan 2026 10:32:52 +0100 Morten Brørup <[email protected]>…
Quoted 3 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Friday, 16 January 2026 07.46Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
When building with LTO (Link Time Optimization), GCC performs aggressive cross-compilation-unit inlining. This causes the
compiler
Quoted 1 line
Quoted 1 line
to analyze all code paths in
__rte_ring_do_dequeue_elems(),including
Quoted 1 line
Quoted 1 line
the 16-byte element path (
__rte_ring_dequeue_elems_128), evenwhen
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
the runtime element size is only 4 bytes.
The static analyzer sees that the 16-byte path would copy 32 elements * 16 bytes = 512 bytes into a 128-byte buffer (uint32_t[32]),
triggering -Wstringop-overflow warnings.The element size is not an inline function parameter, but fetched
from the "esize" field in the
rte_soringstructure, so the compiler cannot see that the element size is 4 bytes. And thus it needs to consider all possible element sizes.Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Quoted 3 lines
The existing #pragma GCC diagnostic suppression in
rte_ring_elem_pvt.hQuoted 1 line
Quoted 1 line
doesn't help because with LTO the warning context shifts to the
test
Quoted 3 lines
Quoted 3 lines
file where the inlined code is instantiated.
Fix by sizing all buffers passed to soring acquire/dequeue
functions
Quoted 1 line
Quoted 1 line
for the worst-case element size (16 bytes = 4 *
sizeof(uint32_t)).Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
This satisfies the static analyzer without changing runtime
behavior.
Quoted 2 lines
Using wildly oversized buffers doesn't seem like a recommendable
solution.
Quoted 1 line
If the ring library is ever updated to support cache size
elements
Quoted 9 lines
Quoted 3 lines
(64 byte), the buffers would have to be oversize by factor 16.
The analysis (from AI) is that compiler is getting confused.
That would be my analysis too.
Quoted 2 lines
Since there is no good
way other than turning of LTO for the test to tell the compilerQuoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
There is another way to tell the compiler:
__rte_assume()Tried that but it doesn't work because doesn't get propagated deep enough to impact here.
Does this fix generally imply that when using LTO, using an SORING with
elements
Quoted 5 lines
Quoted 5 lines
smaller than 16 bytes requires oversize buffers?
That's not good. :-(The SORING is still experimental.
Maybe the element size and metadata size need to be passed as parametersto
Quoted 1 line
Quoted 1 line
the SORING functions, like the RING functions take element size as
parameter
Quoted 5 lines
Quoted 1 line
(except the functions that are hardcoded for using pointers as element size).
Personally, I am not a big fan of such idea...
Wonder is that possible just to disable LTO for soring.o? Another thought - if all the problems come from 128 bit version ofenque/dequeue,
Quoted 1 line
would using
memcpy()instead of specific functions help to mitigate theproblem?
Quoted 2 lines
Quoted 6 lines
A much simpler and clear solution is to just get rid of
__rte_always_inlineand use inline instead. The compiler still inlines a lot but it can make its own decision.
The attributealways_inlineis not always faster, in fact in real world applications it can make things slower because real applications get i-cache misses and lots of inline expansion makes it worse.
Sounds like a clean and safe fix.
I also don't expect any perf degradations with such approach, but will run some perf tests with it to confirm. Thanks
Re: [PATCH v3 1/6] test/soring: fix buffer overflow warnings with LTO
Quoted 11 lines · On Wed, 21 Jan 2026 12:56:25 +0000 Konstantin Ananyev…
Quoted 6 lines
A much simpler and clear solution is to just get rid of
__rte_always_inlineand use inline instead. The compiler still inlines a lot but it can make its own decision.
The attributealways_inlineis not always faster, in fact in real world applications it can make things slower because real applications get i-cache misses and lots of inline expansion makes it worse.Sounds like a clean and safe fix.
I also don't expect any perf degradations with such approach, but will run some perf tests with it to confirm. Thanks
Only enqueue/dequeue functions needed the change.
PATCH v3 2/6 common/cnxk: replace variable length state array
In reply to Stephen HemmingerThe cipher function is always called with in_len = 16 and there is an existing define for that.
--- drivers/common/cnxk/roc_aes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/common/cnxk/roc_aes.c +2 -1
@@ -157,9 +157,10 @@ static void cipher(uint8_t *in, uint8_t *out, uint32_t *ks, uint32_t key_rounds, uint8_t in_len) {uint8_t data_word_len = in_len /sizeof (uint32_t ); -uint32_t state[data_word_len]; +uint32_t state[AES_HASH_KEY_LEN /sizeof (uint32_t )];unsigned int i, round; +RTE_ASSERT (in_len <=AES_HASH_KEY_LEN );memcpy (state, in,sizeof (state));/* AddRoundKey(state, w[0, Nb-1]) // See Sec. 5.1.4 */
Signature · 1 line
2.51.0
PATCH v3 3/6 common/cnxk: replace variable length array
In reply to Stephen HemmingerThis fixes errors when compiled with LTO about large VLA.../drivers/common/cnxk/roc_platform.c: In function ‘irq_init’:../drivers/common/cnxk/roc_platform.c:92:14: warning: argument to variable-length array is too large [-Wvla-larger-than=]
92 | char irq_set_buf[MSIX_IRQ_SET_BUF_LEN];
| ^
Since the number of IRQ is limited by EAL max interrupt vectors use that define that already exists rather than a function call hidden in a macro.
--- drivers/common/cnxk/roc_platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/common/cnxk/roc_platform.c +2 -2
@@ -17,8 +17,8 @@#include <sys/ioctl.h> #include <unistd.h> -#define MSIX_IRQ_SET_BUF_LEN \ - (sizeof(struct vfio_irq_set) + sizeof(int) * (plt_intr_max_intr_get(intr_handle))) +#define MSIX_IRQ_SET_BUF_LEN \ + (sizeof(struct vfio_irq_set) + sizeof(int) * PLT_MAX_RXTX_INTR_VEC_ID)static int irq_get_info (struct plt_intr_handle *intr_handle)
Signature · 1 line
2.51.0
PATCH v3 4/6 common/cnxk: re-enable vla warnings
In reply to Stephen HemmingerThe code in common/cnxk no longer uses VLAs.
--- drivers/common/cnxk/meson.build | 2 -- 1 file changed, 2 deletions(-)
drivers/common/cnxk/meson.build +0 -2
@@ -94,8 +94,6 @@ sources += files('cnxk_telemetry_bphy.c', 'cnxk_telemetry_sso.c', ) -cflags += no_wvla_cflag - if meson.is_cross_build() soc_type = meson.get_external_property('platform', '') else
Signature · 1 line
2.51.0
PATCH v3 5/6 common/cnxk: fix buffer overflow in reassembly SA setup
In reply to Stephen HemmingerThe nix_inl_reass_inb_sa_tbl_setup() function initializes inb_sa_sz to 1 byte, then allocates a buffer of that size. However, the buffer is subsequently passed to roc_ow_reass_inb_sa_init() which performs:
memset(sa, 0, sizeof(struct roc_ow_ipsec_inb_sa));
This writes 808 bytes into a 1-byte allocation, causing heap corruption.
This bug was detected by GCC's -Wstringop-overflow warning when building with LTO, which enables cross-compilation-unit inlining and allows the compiler to track the allocation size through to the memset call.
Fix by initializing inb_sa_sz to ROC_NIX_INL_OW_IPSEC_INB_SA_SZ, which is the standard macro used elsewhere in this file for OW (Sobek) inbound SA allocations.
--- drivers/common/cnxk/roc_nix_inl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/common/cnxk/roc_nix_inl.c +1 -1
@@ -583,7 +583,7 @@ nix_inl_reass_inb_sa_tbl_setup(struct roc_nix *roc_nix)uint64_t sa_idx_w, lenm1_max;uint64_t res_addr_offset =0 ;uint64_t def_cptq =0 ; -size_t inb_sa_sz =1 ; +size_t inb_sa_sz =ROC_NIX_INL_OW_IPSEC_INB_SA_SZ ;uint8_t profile_id;struct mbox *mbox;void *sa;
Signature · 1 line
2.51.0
PATCH v3 6/6 net/mlx5/hws: fix LTO false positive stringop-overflow warning
In reply to Stephen HemmingerWhen compiling with LTO (Link Time Optimization) enabled, GCC's interprocedural analysis produces false positive warnings about potential buffer overflow in mlx5dr_action_prepare_decap_l3_data():
In function 'mlx5dr_action_prepare_decap_l3_data',
inlined from 'mlx5dr_action_handle_tunnel_l3_to_l2', inlined from 'mlx5dr_action_create_reformat_hws':
warning: writing 4 bytes into a region of size 0 [-Wstringop-overflow=]
memcpy(dst, e_src, MLX5DR_ACTION_INLINE_DATA_SIZE);
note: at offset [140, 524248] into destination object 'mh_data' of size 64
With LTO, the function chain is fully inlined, giving GCC visibility into the 64-byte stack buffer 'mh_data'. However, GCC's static analysis cannot determine that num_of_actions is constrained to either DECAP_L3_NUM_ACTIONS_W_NO_VLAN (6) or DECAP_L3_NUM_ACTIONS_W_VLAN (7) by the callers. It assumes worst-case bounds that greatly exceed the buffer size.
Fix this by adding an explicit bounds check at function entry. The valid values for num_of_actions are 6 (no VLAN) or 7 (with VLAN), which produce maximum buffer usage well under 64 bytes:
- offset 12 + (num_of_actions-3) * 8 + 2 = max 46 bytes for 7 actions
This provides GCC with the proof it needs that subsequent memcpy operations are safe.
This is not a data path function - it executes only during flow rule creation, so the additional check has no performance impact.
--- drivers/net/mlx5/hws/mlx5dr_action.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/net/mlx5/hws/mlx5dr_action.c +14 -0
@@ -3620,6 +3620,20 @@ mlx5dr_action_prepare_decap_l3_data(uint8_t *src, uint8_t *dst,uint8_t *e_src;int i; +/* +* Bounds check to help GCC LTO static analysis. +* +* When LTO inlines this into mlx5dr_action_handle_tunnel_l3_to_l2(), +* GCC sees the 64-byte mh_data buffer but cannot prove num_of_actions +* is bounded, causing false -Wstringop-overflow warnings. +* +* Valid num_of_actions values are DECAP_L3_NUM_ACTIONS_W_NO_VLAN (6) +* or DECAP_L3_NUM_ACTIONS_W_VLAN (7). This check gives GCC the proof +* it needs that the loop iterations stay within buffer bounds. +*/ +if (unlikely (num_of_actions >DECAP_L3_NUM_ACTIONS_W_VLAN )) +return ; +/* num_of_actions = remove l3l2 + 4/5 inserts + remove extra 2 bytes * copy from end of src to the start of dst. * move to the end, 2 is the leftover from 14B or 18B
Signature · 1 line
2.51.0
v4 cover fix build failures with LTO enabled
In reply to Stephen HemmingerThis series addresses build failures and warnings that occur when compiling DPDK with Link Time Optimization (LTO) enabled. LTO performs aggressive cross-compilation-unit inlining, which allows GCC's static analyzer to detect both real bugs and generate false positive warnings that are not visible without LTO.
The series fixes:
- Real bugs: buffer overflow in cnxk reassembly SA setup (heap corruption)
- Variable-length arrays that trigger warnings with LTO
- False positive warnings where compiler cannot prove bounds safety
v4
- add Fixes tags where appropriate
- Bugzilla ID's for existing bugs
The cnxk patches (1-4) should be applied together as they eliminate all VLAs from common/cnxk and re-enable VLA warnings. The remaining patches (5-6) address warnings in other subsystems.
Stephen Hemminger (6):
common/cnxk: replace variable length state array common/cnxk: replace variable length array common/cnxk: re-enable vla warnings
common/cnxk: fix buffer overflow in reassembly SA setup net/mlx5: fix LTO false positive stringop-overflow warning test/soring: fix stringop-overflow warning with LTO
app/test/test_soring.c | 18 ++++++++++++------ drivers/common/cnxk/meson.build | 2 -- drivers/common/cnxk/roc_aes.c | 3 ++- drivers/common/cnxk/roc_nix_inl.c | 2 +- drivers/common/cnxk/roc_platform.c | 4 ++-- drivers/net/mlx5/hws/mlx5dr_action.c | 14 ++++++++++++++ 6 files changed, 31 insertions(+), 12 deletions(-)
Signature · 1 line
2.51.0
PATCH v4 1/6 common/cnxk: replace variable length state array
The cipher function is always called with in_len = 16 and there is an existing define for that.
--- drivers/common/cnxk/roc_aes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/common/cnxk/roc_aes.c +2 -1
@@ -157,9 +157,10 @@ static void cipher(uint8_t *in, uint8_t *out, uint32_t *ks, uint32_t key_rounds, uint8_t in_len) {uint8_t data_word_len = in_len /sizeof (uint32_t ); -uint32_t state[data_word_len]; +uint32_t state[AES_HASH_KEY_LEN /sizeof (uint32_t )];unsigned int i, round; +PLT_ASSERT (in_len <=AES_HASH_KEY_LEN );memcpy (state, in,sizeof (state));/* AddRoundKey(state, w[0, Nb-1]) // See Sec. 5.1.4 */
Signature · 1 line
2.51.0
PATCH v4 2/6 common/cnxk: replace variable length array
In reply to Stephen HemmingerThis fixes errors when compiled with LTO about large VLA.../drivers/common/cnxk/roc_platform.c: In function ‘irq_init’:../drivers/common/cnxk/roc_platform.c:92:14: warning: argument to variable-length array is too large [-Wvla-larger-than=]
92 | char irq_set_buf[MSIX_IRQ_SET_BUF_LEN];
| ^
Since the number of IRQ is limited by EAL max interrupt vectors use that define that already exists rather than a function call hidden in a macro.
Bugzilla ID: 1863
--- drivers/common/cnxk/roc_platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/common/cnxk/roc_platform.c +2 -2
@@ -17,8 +17,8 @@#include <sys/ioctl.h> #include <unistd.h> -#define MSIX_IRQ_SET_BUF_LEN \ - (sizeof(struct vfio_irq_set) + sizeof(int) * (plt_intr_max_intr_get(intr_handle))) +#define MSIX_IRQ_SET_BUF_LEN \ + (sizeof(struct vfio_irq_set) + sizeof(int) * PLT_MAX_RXTX_INTR_VEC_ID)static int irq_get_info (struct plt_intr_handle *intr_handle)
Signature · 1 line
2.51.0
PATCH v4 3/6 common/cnxk: re-enable vla warnings
In reply to Stephen HemmingerThe code in common/cnxk no longer uses VLAs.
--- drivers/common/cnxk/meson.build | 2 -- 1 file changed, 2 deletions(-)
drivers/common/cnxk/meson.build +0 -2
@@ -94,8 +94,6 @@ sources += files('cnxk_telemetry_bphy.c', 'cnxk_telemetry_sso.c', ) -cflags += no_wvla_cflag - if meson.is_cross_build() soc_type = meson.get_external_property('platform', '') else
Signature · 1 line
2.51.0
PATCH v4 4/6 common/cnxk: fix buffer overflow in reassembly SA setup
In reply to Stephen HemmingerThe nix_inl_reass_inb_sa_tbl_setup() function initializes inb_sa_sz to 1 byte, then allocates a buffer of that size. However, the buffer is subsequently passed to roc_ow_reass_inb_sa_init() which performs:
memset(sa, 0, sizeof(struct roc_ow_ipsec_inb_sa));
This writes 808 bytes into a 1-byte allocation, causing heap corruption.
This bug was detected by GCC's -Wstringop-overflow warning when building with LTO, which enables cross-compilation-unit inlining and allows the compiler to track the allocation size through to the memset call.
Fix by initializing inb_sa_sz to ROC_NIX_INL_OW_IPSEC_INB_SA_SZ, which is the standard macro used elsewhere in this file for OW (Sobek) inbound SA allocations.
Bugzilla ID: 1513
--- drivers/common/cnxk/roc_nix_inl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/common/cnxk/roc_nix_inl.c +1 -1
@@ -583,7 +583,7 @@ nix_inl_reass_inb_sa_tbl_setup(struct roc_nix *roc_nix)uint64_t sa_idx_w, lenm1_max;uint64_t res_addr_offset =0 ;uint64_t def_cptq =0 ; -size_t inb_sa_sz =1 ; +size_t inb_sa_sz =ROC_NIX_INL_OW_IPSEC_INB_SA_SZ ;uint8_t profile_id;struct mbox *mbox;void *sa;
Signature · 1 line
2.51.0
PATCH v4 5/6 net/mlx5: fix LTO false positive stringop-overflow warning
In reply to Stephen HemmingerWhen compiling with LTO (Link Time Optimization) enabled, GCC's interprocedural analysis produces false positive warnings about potential buffer overflow in mlx5dr_action_prepare_decap_l3_data():
In function 'mlx5dr_action_prepare_decap_l3_data',
inlined from 'mlx5dr_action_handle_tunnel_l3_to_l2', inlined from 'mlx5dr_action_create_reformat_hws':
warning: writing 4 bytes into a region of size 0 [-Wstringop-overflow=]
memcpy(dst, e_src, MLX5DR_ACTION_INLINE_DATA_SIZE);
note: at offset [140, 524248] into destination object 'mh_data' of size 64
With LTO, the function chain is fully inlined, giving GCC visibility into the 64-byte stack buffer 'mh_data'. However, GCC's static analysis cannot determine that num_of_actions is constrained to either DECAP_L3_NUM_ACTIONS_W_NO_VLAN (6) or DECAP_L3_NUM_ACTIONS_W_VLAN (7) by the callers. It assumes worst-case bounds that greatly exceed the buffer size.
Fix this by adding an explicit bounds check at function entry. The valid values for num_of_actions are 6 (no VLAN) or 7 (with VLAN), which produce maximum buffer usage well under 64 bytes:
- offset 12 + (num_of_actions-3) * 8 + 2 = max 46 bytes for 7 actions
This provides GCC with the proof it needs that subsequent memcpy operations are safe.
This is not a data path function - it executes only during flow rule creation, so the additional check has no performance impact.
Bugzilla ID: 1710
--- drivers/net/mlx5/hws/mlx5dr_action.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/net/mlx5/hws/mlx5dr_action.c +14 -0
@@ -3620,6 +3620,20 @@ mlx5dr_action_prepare_decap_l3_data(uint8_t *src, uint8_t *dst,uint8_t *e_src;int i; +/* +* Bounds check to help GCC LTO static analysis. +* +* When LTO inlines this into mlx5dr_action_handle_tunnel_l3_to_l2(), +* GCC sees the 64-byte mh_data buffer but cannot prove num_of_actions +* is bounded, causing false -Wstringop-overflow warnings. +* +* Valid num_of_actions values are DECAP_L3_NUM_ACTIONS_W_NO_VLAN (6) +* or DECAP_L3_NUM_ACTIONS_W_VLAN (7). This check gives GCC the proof +* it needs that the loop iterations stay within buffer bounds. +*/ +if (unlikely (num_of_actions >DECAP_L3_NUM_ACTIONS_W_VLAN )) +return ; +/* num_of_actions = remove l3l2 + 4/5 inserts + remove extra 2 bytes * copy from end of src to the start of dst. * move to the end, 2 is the leftover from 14B or 18B
Signature · 1 line
2.51.0
PATCH v4 6/6 test/soring: fix stringop-overflow warning with LTO
In reply to Stephen HemmingerWhen LTO is enabled, GCC inlines through the soring dequeue path into __rte_ring_dequeue_elems_128(), which copies 32 bytes per element for 128-bit ring elements. The compiler cannot prove at compile time that this code path is unreachable when elem_size is 4 bytes, resulting in warnings like:
warning: writing 32 bytes into a region of size 0 [-Wstringop-overflow=]
note: at offset 128 into destination object 'dequeued_objs' of size 128
The test allocates uint32_t arrays of 32 elements (128 bytes), which is correct for 32 elements of 4 bytes each. However, the 128-bit path would require 512 bytes for 32 elements.
Using __rte_assume or RTE_ASSERT in this case is not enough to resolve the problem because the condition does not propogate through the compiler inlining so the compiler still can't prove the 128-bit path won't be taken.
Increase the array sizes in test_soring_stages() to 128 uint32_t elements (512 bytes) to accommodate the worst-case 128-bit element path that the compiler cannot eliminate.
Bugzilla ID: 1726
--- app/test/test_soring.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
app/test/test_soring.c +12 -6
@@ -149,12 +149,18 @@ test_soring_stages(void) {struct rte_soring *sor =NULL ;struct rte_soring_param prm; -uint32_t objs[32 ]; -uint32_t rcs[32 ]; -uint32_t acquired_objs[32 ]; -uint32_t acquired_rcs[32 ]; -uint32_t dequeued_rcs[32 ]; -uint32_t dequeued_objs[32 ]; +/* +* The soring/ring code has paths for 4/8/16-byte elements. +* With LTO, GCC cannot eliminate the 16-byte path and warns +* about potential buffer overflow. Size arrays for worst case: +* 32 elements * 16 bytes = 512 bytes = 128 uint32_t. +*/ +uint32_t objs[128 ]; +uint32_t rcs[128 ]; +uint32_t acquired_objs[128 ]; +uint32_t acquired_rcs[128 ]; +uint32_t dequeued_rcs[128 ]; +uint32_t dequeued_objs[128 ];size_t ssz;uint32_t stage, enqueued, dequeued, acquired;uint32_t i, ftoken;
Signature · 1 line
2.51.0
cover Fix LTO compilation warnings
In reply to Stephen HemmingerTLDR; fixes LTO build
Full explaination from AI...
This patch series addresses multiple compilation warnings and one buffer overflow bug that are revealed when with Link Time Optimization (LTO) enabled.
LTO enables cross-compilation-unit analysis and inlining, which allows GCC to detect issues that would otherwise be hidden. The patches fall into three categories:
1. Variable Length Array (VLA) fixes in common/cnxk [patches 1-3]
- Replace VLAs with fixed-size arrays and appropriate bounds checking
- Re-enable VLA warnings after fixes are complete
2. Actual bug fix in common/cnxk [patch 4]
- Fixes buffer overflow in IPsec inbound SA initialization
- Detected by GCC's -Wstringop-overflow with LTO enabled
3. False positive warning fixes [patches 5-6]
- Add explicit bounds checks to help GCC's static analysis
- Adjust inline attributes to prevent spurious warnings
All patches have been tested with LTO enabled and resolve the respective compilation warnings.
Stephen Hemminger (6):
common/cnxk: replace variable length state array common/cnxk: replace variable length array common/cnxk: re-enable vla warnings common/cnxk: fix buffer overflow in SA setup net/mlx5: fix LTO stringop-overflow warning
ring: use inline instead of always inline in soring
drivers/common/cnxk/meson.build | 1 - drivers/common/cnxk/roc_aes.c | 3 ++- drivers/common/cnxk/roc_nix_inl.c | 2 +- drivers/common/cnxk/roc_platform.c | 4 ++-- drivers/net/mlx5/hws/mlx5dr_action.c | 14 ++++++++++++++ lib/ring/soring.c | 4 ++-- 6 files changed, 21 insertions(+), 7 deletions(-)
Signature · 1 line
2.51.0
PATCH v5 1/6 common/cnxk: replace variable length state array
The cipher function is always called with in_len = 16 and there is an existing define for that.
--- drivers/common/cnxk/roc_aes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/common/cnxk/roc_aes.c +2 -1
@@ -157,9 +157,10 @@ static void cipher(uint8_t *in, uint8_t *out, uint32_t *ks, uint32_t key_rounds, uint8_t in_len) {uint8_t data_word_len = in_len /sizeof (uint32_t ); -uint32_t state[data_word_len]; +uint32_t state[AES_HASH_KEY_LEN /sizeof (uint32_t )];unsigned int i, round; +PLT_ASSERT (in_len <=AES_HASH_KEY_LEN );memcpy (state, in,sizeof (state));/* AddRoundKey(state, w[0, Nb-1]) // See Sec. 5.1.4 */
Signature · 1 line
2.51.0
PATCH v5 2/6 common/cnxk: replace variable length array
In reply to Stephen HemmingerThis fixes errors when compiled with LTO about large VLA.../drivers/common/cnxk/roc_platform.c: In function ‘irq_init’:../drivers/common/cnxk/roc_platform.c:92:14: warning: argument to variable-length array is too large [-Wvla-larger-than=]
92 | char irq_set_buf[MSIX_IRQ_SET_BUF_LEN];
| ^
Since the number of IRQ is limited by EAL max interrupt vectors use that define that already exists rather than a function call hidden in a macro.
Bugzilla ID: 1863
--- drivers/common/cnxk/roc_platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/common/cnxk/roc_platform.c +2 -2
@@ -17,8 +17,8 @@#include <sys/ioctl.h> #include <unistd.h> -#define MSIX_IRQ_SET_BUF_LEN \ - (sizeof(struct vfio_irq_set) + sizeof(int) * (plt_intr_max_intr_get(intr_handle))) +#define MSIX_IRQ_SET_BUF_LEN \ + (sizeof(struct vfio_irq_set) + sizeof(int) * PLT_MAX_RXTX_INTR_VEC_ID)static int irq_get_info (struct plt_intr_handle *intr_handle)
Signature · 1 line
2.51.0
PATCH v5 3/6 common/cnxk: re-enable vla warnings
In reply to Stephen HemmingerThe code in common/cnxk no longer uses VLAs.
--- drivers/common/cnxk/meson.build | 1 - 1 file changed, 1 deletion(-)
drivers/common/cnxk/meson.build +0 -1
@@ -94,7 +94,6 @@ sources += files('cnxk_telemetry_bphy.c', 'cnxk_telemetry_sso.c', ) -cflags += no_wvla_cflag cflags += no_shadow_cflag if meson.is_cross_build()
Signature · 1 line
2.51.0
PATCH v5 4/6 common/cnxk: fix buffer overflow in SA setup
In reply to Stephen HemmingerThe nix_inl_reass_inb_sa_tbl_setup() function initializes inb_sa_sz to 1 byte, then allocates a buffer of that size. However, the buffer is subsequently passed to roc_ow_reass_inb_sa_init() which performs:
memset(sa, 0, sizeof(struct roc_ow_ipsec_inb_sa));
This writes 808 bytes into a 1-byte allocation, causing heap corruption.
This bug was detected by GCC's -Wstringop-overflow warning when building with LTO, which enables cross-compilation-unit inlining and allows the compiler to track the allocation size through to the memset call.
Fix by initializing inb_sa_sz to ROC_NIX_INL_OW_IPSEC_INB_SA_SZ, which is the standard macro used elsewhere in this file for OW (Sobek) inbound SA allocations.
Bugzilla ID: 1513
--- drivers/common/cnxk/roc_nix_inl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/common/cnxk/roc_nix_inl.c +1 -1
@@ -583,7 +583,7 @@ nix_inl_reass_inb_sa_tbl_setup(struct roc_nix *roc_nix)uint64_t sa_idx_w, lenm1_max;uint64_t res_addr_offset =0 ;uint64_t def_cptq =0 ; -size_t inb_sa_sz =1 ; +size_t inb_sa_sz =ROC_NIX_INL_OW_IPSEC_INB_SA_SZ ;uint8_t profile_id;struct mbox *mbox;void *sa;
Signature · 1 line
2.51.0
PATCH v5 5/6 net/mlx5: fix LTO stringop-overflow warning
In reply to Stephen HemmingerWhen compiling with LTO (Link Time Optimization) enabled, GCC's interprocedural analysis produces false positive warnings about potential buffer overflow in mlx5dr_action_prepare_decap_l3_data():
In function 'mlx5dr_action_prepare_decap_l3_data',
inlined from 'mlx5dr_action_handle_tunnel_l3_to_l2', inlined from 'mlx5dr_action_create_reformat_hws':
warning: writing 4 bytes into a region of size 0 [-Wstringop-overflow=]
memcpy(dst, e_src, MLX5DR_ACTION_INLINE_DATA_SIZE);
note: at offset [140, 524248] into destination object 'mh_data' of size 64
With LTO, the function chain is fully inlined, giving GCC visibility into the 64-byte stack buffer 'mh_data'. However, GCC's static analysis cannot determine that num_of_actions is constrained to either DECAP_L3_NUM_ACTIONS_W_NO_VLAN (6) or DECAP_L3_NUM_ACTIONS_W_VLAN (7) by the callers. It assumes worst-case bounds that greatly exceed the buffer size.
Fix this by adding an explicit bounds check at function entry. The valid values for num_of_actions are 6 (no VLAN) or 7 (with VLAN), which produce maximum buffer usage well under 64 bytes:
- offset 12 + (num_of_actions-3) * 8 + 2 = max 46 bytes for 7 actions
This provides GCC with the proof it needs that subsequent memcpy operations are safe.
This is not a data path function - it executes only during flow rule creation, so the additional check has no performance impact.
Bugzilla ID: 1710
--- drivers/net/mlx5/hws/mlx5dr_action.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/net/mlx5/hws/mlx5dr_action.c +14 -0
@@ -3620,6 +3620,20 @@ mlx5dr_action_prepare_decap_l3_data(uint8_t *src, uint8_t *dst,uint8_t *e_src;int i; +/* +* Bounds check to help GCC LTO static analysis. +* +* When LTO inlines this into mlx5dr_action_handle_tunnel_l3_to_l2(), +* GCC sees the 64-byte mh_data buffer but cannot prove num_of_actions +* is bounded, causing false -Wstringop-overflow warnings. +* +* Valid num_of_actions values are DECAP_L3_NUM_ACTIONS_W_NO_VLAN (6) +* or DECAP_L3_NUM_ACTIONS_W_VLAN (7). This check gives GCC the proof +* it needs that the loop iterations stay within buffer bounds. +*/ +if (unlikely (num_of_actions >DECAP_L3_NUM_ACTIONS_W_VLAN )) +return ; +/* num_of_actions = remove l3l2 + 4/5 inserts + remove extra 2 bytes * copy from end of src to the start of dst. * move to the end, 2 is the leftover from 14B or 18B
Signature · 1 line
2.51.0
Re: [PATCH v5 5/6] net/mlx5: fix LTO stringop-overflow warning
Quoted 49 lines · Stephen Hemminger
When compiling with LTO (Link Time Optimization) enabled, GCC's interprocedural analysis produces false positive warnings about potential buffer overflow in
mlx5dr_action_prepare_decap_l3_data():In function '
mlx5dr_action_prepare_decap_l3_data',
inlined from 'mlx5dr_action_handle_tunnel_l3_to_l2', inlined from 'mlx5dr_action_create_reformat_hws':
warning: writing 4 bytes into a region of size 0 [-Wstringop-overflow=]memcpy(dst, e_src, MLX5DR_ACTION_INLINE_DATA_SIZE);note: at offset [140, 524248] into destination object '
mh_data' of size 64With LTO, the function chain is fully inlined, giving GCC visibility into the 64-byte stack buffer '
mh_data'. However, GCC's static analysis cannot determine thatnum_of_actionsis constrained to eitherDECAP_L3_NUM_ACTIONS_W_NO_VLAN(6) orDECAP_L3_NUM_ACTIONS_W_VLAN(7) by the callers. It assumes worst-case bounds that greatly exceed the buffer size.Fix this by adding an explicit bounds check at function entry. The valid values for
num_of_actionsare 6 (no VLAN) or 7 (with VLAN), which produce maximum buffer usage well under 64 bytes:
- offset 12 + (num_of_actions-3) * 8 + 2 = max 46 bytes for 7 actionsThis provides GCC with the proof it needs that subsequent memcpy operations are safe.
This is not a data path function - it executes only during flow rule creation, so the additional check has no performance impact.
Bugzilla ID: 1710
Fixes f8c8a6d8440d ("net/mlx5/hws: add action object")Signed-off-by Stephen Hemminger <[email protected]>--- drivers/net/mlx5/hws/mlx5dr_action.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)drivers/net/mlx5/hws/mlx5dr_action.c +3
-0@@ -3620,6 +3620,20 @@ mlx5dr_action_prepare_decap_l3_data(uint8_t *src, uint8_t *dst,uint8_t *e_src;int i; +/* +* Bounds check to help GCC LTO static analysis. +*
drivers/net/mlx5/hws/mlx5dr_action.c mlx5dr_action_prepare_decap_l3_data(uint8_t *src, uint8_t *dst, · line 3635
Quoted 10 lines
drivers/net/mlx5/hws/mlx5dr_action.c +10
-0+* When LTO inlines this into mlx5dr_action_handle_tunnel_l3_to_l2(), +* GCC sees the 64-byte mh_data buffer but cannot prove num_of_actions +* is bounded, causing false -Wstringop-overflow warnings. +* +* Valid num_of_actions values are DECAP_L3_NUM_ACTIONS_W_NO_VLAN (6) +* or DECAP_L3_NUM_ACTIONS_W_VLAN (7). This check gives GCC the proof +* it needs that the loop iterations stay within buffer bounds. +*/ +if (unlikely (num_of_actions >DECAP_L3_NUM_ACTIONS_W_VLAN )) +return ;
This function can be executed as part of fast path in async flow creation, so if possible
I would avoid adding such a condition.
I tested locally with GCC 14.2.0 and it looks like if this condition is changed to equivalent __rte_assume(), then this condition is removed from generated code
(https://godbolt.org/z/afx8jjr6Y as an example, code generated by LTO also optimizes the relevant code). __rte_assume() also fixes the LTO warning.
Could you please change the condition to equivalent __rte_assume()?
Quoted 7 lines
drivers/net/mlx5/hws/mlx5dr_action.c +1
-0+/* num_of_actions = remove l3l2 + 4/5 inserts + remove extra 2 bytes * copy from end of src to the start of dst. * move to the end, 2 is the leftover from 14B or 18B Signature · 1 line
2.51.0
Re: [PATCH v5 5/6] net/mlx5: fix LTO stringop-overflow warning
Quoted 65 lines · On Thu, 5 Feb 2026 14:43:35 +0100 Dariusz Sosnowski <[email protected]>…
Quoted 49 lines · Stephen Hemminger
When compiling with LTO (Link Time Optimization) enabled, GCC's interprocedural analysis produces false positive warnings about potential buffer overflow in
mlx5dr_action_prepare_decap_l3_data():In function '
mlx5dr_action_prepare_decap_l3_data',
inlined from 'mlx5dr_action_handle_tunnel_l3_to_l2', inlined from 'mlx5dr_action_create_reformat_hws':
warning: writing 4 bytes into a region of size 0 [-Wstringop-overflow=]memcpy(dst, e_src, MLX5DR_ACTION_INLINE_DATA_SIZE);note: at offset [140, 524248] into destination object '
mh_data' of size 64With LTO, the function chain is fully inlined, giving GCC visibility into the 64-byte stack buffer '
mh_data'. However, GCC's static analysis cannot determine thatnum_of_actionsis constrained to eitherDECAP_L3_NUM_ACTIONS_W_NO_VLAN(6) orDECAP_L3_NUM_ACTIONS_W_VLAN(7) by the callers. It assumes worst-case bounds that greatly exceed the buffer size.Fix this by adding an explicit bounds check at function entry. The valid values for
num_of_actionsare 6 (no VLAN) or 7 (with VLAN), which produce maximum buffer usage well under 64 bytes:
- offset 12 + (num_of_actions-3) * 8 + 2 = max 46 bytes for 7 actionsThis provides GCC with the proof it needs that subsequent memcpy operations are safe.
This is not a data path function - it executes only during flow rule creation, so the additional check has no performance impact.
Bugzilla ID: 1710
Fixes f8c8a6d8440d ("net/mlx5/hws: add action object")Signed-off-by Stephen Hemminger <[email protected]>--- drivers/net/mlx5/hws/mlx5dr_action.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)drivers/net/mlx5/hws/mlx5dr_action.c +3
-0@@ -3620,6 +3620,20 @@ mlx5dr_action_prepare_decap_l3_data(uint8_t *src, uint8_t *dst,uint8_t *e_src;int i; +/* +* Bounds check to help GCC LTO static analysis. +* drivers/net/mlx5/hws/mlx5dr_action.c mlx5dr_action_prepare_decap_l3_data(uint8_t *src, uint8_t *dst, · line 3635
Quoted 10 lines
drivers/net/mlx5/hws/mlx5dr_action.c +10
-0+* When LTO inlines this into mlx5dr_action_handle_tunnel_l3_to_l2(), +* GCC sees the 64-byte mh_data buffer but cannot prove num_of_actions +* is bounded, causing false -Wstringop-overflow warnings. +* +* Valid num_of_actions values are DECAP_L3_NUM_ACTIONS_W_NO_VLAN (6) +* or DECAP_L3_NUM_ACTIONS_W_VLAN (7). This check gives GCC the proof +* it needs that the loop iterations stay within buffer bounds. +*/ +if (unlikely (num_of_actions >DECAP_L3_NUM_ACTIONS_W_VLAN )) +return ;This function can be executed as part of fast path in async flow creation, so if possible
I would avoid adding such a condition.
Quoted 16 lines
I tested locally with GCC 14.2.0 and it looks like if this condition is changed to equivalent
__rte_assume(), then this condition is removed from generated code
(https://godbolt.org/z/afx8jjr6Y as an example, code generated by LTO also optimizes the relevant code).__rte_assume()also fixes the LTO warning.Could you please change the condition to equivalent
__rte_assume()?Quoted 7 lines
drivers/net/mlx5/hws/mlx5dr_action.c +1
-0+/* num_of_actions = remove l3l2 + 4/5 inserts + remove extra 2 bytes * copy from end of src to the start of dst. * move to the end, 2 is the leftover from 14B or 18B Signature · 1 line
2.51.0
Yes rte_assume works will resend
PATCH v5 6/6 ring: use inline instead of always inline in soring
In reply to Stephen HemmingerWhen LTO is enabled, GCC inlines through the entire soring call chain from test code into the ring element copy functions. With always_inline, the compiler is forced to inline __rte_ring_dequeue_elems_128() which copies 32 bytes per element. GCC's static analysis then warns about potential buffer overflow because it cannot prove the 128-bit element path is unreachable when the ring is configured for 4-byte elements:
warning: writing 32 bytes into a region of size 0 [-Wstringop-overflow=]
By using plain inline instead of always_inline on the soring enqueue and dequeue functions, the compiler regains discretion over inlining decisions. This introduces an analysis boundary that prevents GCC from connecting the test's buffer sizes to the unreachable 128-bit code path, eliminating the false positive warning.
Performance impact is expected to be negligible. At -O2/-O3, the compiler will still inline these small, hot functions based on its own heuristics. The difference only matters in debug builds or with -Os, where slightly less aggressive inlining is acceptable.
--- lib/ring/soring.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/ring/soring.c +2 -2
@@ -249,7 +249,7 @@ __rte_soring_stage_move_head(struct soring_stage_headtail *d,return n; } -static __rte_always_inline uint32_t +static inline uint32_t soring_enqueue (struct rte_soring *r,const void *objs,const void *meta,uint32_t n,enum rte_ring_queue_behavior behavior,uint32_t *free_space)
@@ -278,7 +278,7 @@ soring_enqueue(struct rte_soring *r, const void *objs,return n; } -static __rte_always_inline uint32_t +static inline uint32_t soring_dequeue (struct rte_soring *r,void *objs,void *meta,uint32_t num,enum rte_ring_queue_behavior behavior,uint32_t *available)
Signature · 1 line
2.51.0
RE: [PATCH v5 6/6] ring: use inline instead of always inline in soring
Quoted 43 lines
When LTO is enabled, GCC inlines through the entire soring call chain from test code into the ring element copy functions. With
always_inline, the compiler is forced to inline__rte_ring_dequeue_elems_128()which copies 32 bytes per element. GCC's static analysis then warns about potential buffer overflow because it cannot prove the 128-bit element path is unreachable when the ring is configured for 4-byte elements:warning: writing 32 bytes into a region of size 0 [-Wstringop-overflow=]
By using plain inline instead of
always_inlineon the soring enqueue and dequeue functions, the compiler regains discretion over inlining decisions. This introduces an analysis boundary that prevents GCC from connecting the test's buffer sizes to the unreachable 128-bit code path, eliminating the false positive warning.Performance impact is expected to be negligible. At -O2/-O3, the compiler will still inline these small, hot functions based on its own heuristics. The difference only matters in debug builds or with -Os, where slightly less aggressive inlining is acceptable.
Signed-off-by Stephen Hemminger <[email protected]>--- lib/ring/soring.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)lib/ring/soring.c +1
-1@@ -249,7 +249,7 @@ __rte_soring_stage_move_head(structsoring_stage_headtail *d, return n; } -static __rte_always_inline uint32_t +static inline uint32_t soring_enqueue(struct rte_soring *r, const void *objs, const void *meta, uint32_t n, enum rte_ring_queue_behavior behavior,lib/ring/soring.c +0
-0uint32_t *free_space)
lib/ring/soring.c soring_enqueue(struct rte_soring *r, const void *objs,
Quoted 9 lines
lib/ring/soring.c +1
-2@@ -278,7 +278,7 @@ soring_enqueue(struct rte_soring *r, const void *objs,return n; } -static __rte_always_inline uint32_t +static inline uint32_t soring_dequeue (struct rte_soring *r,void *objs,void *meta,uint32_t num,enum rte_ring_queue_behavior behavior,uint32_t *available) --
Run quick test, no perf degradation noticed.
Quoted 1 line
2.51.0
Morten Brørup
Acked-byRE: [PATCH v5 6/6] ring: use inline instead of always inline in soring
Quoted 57 lines
Quoted 2 lines
When LTO is enabled, GCC inlines through the entire soring call chain from test code into the ring element copy functions. With
always_inline,Quoted 6 lines
the compiler is forced to inline
__rte_ring_dequeue_elems_128()which copies 32 bytes per element. GCC's static analysis then warns about potential buffer overflow because it cannot prove the 128-bit element path is unreachable when the ring is configured for 4-byte elements:warning: writing 32 bytes into a region of size 0 [-Wstringop-
overflow=]
Quoted 4 lines
By using plain inline instead of
always_inlineon the soring enqueue and dequeue functions, the compiler regains discretion over inlining decisions. This introduces an analysis boundary that prevents GCCfrom
Quoted 1 line
connecting the test's buffer sizes to the unreachable 128-bit code
path,
Quoted 17 lines
eliminating the false positive warning.
Performance impact is expected to be negligible. At -O2/-O3, the compiler will still inline these small, hot functions based on its own heuristics. The difference only matters in debug builds or with -Os, where slightly less aggressive inlining is acceptable.
Signed-off-by Stephen Hemminger <[email protected]>--- lib/ring/soring.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)lib/ring/soring.c +0
-0lib/ring/soring.c __rte_soring_stage_move_head(struct · line 255
Quoted 8 lines
lib/ring/soring.c +1
-1@@ -249,7 +249,7 @@ __rte_soring_stage_move_head(structsoring_stage_headtail *d, return n; } -static __rte_always_inline uint32_t +static inline uint32_t soring_enqueue (struct rte_soring *r,const void *objs, const void *meta, uint32_t n, enum rte_ring_queue_behaviorbehavior,
lib/ring/soring.c soring_enqueue(struct rte_soring *r, const void
Quoted 2 lines
lib/ring/soring.c +0
-0uint32_t *free_space)@@ -278,7 +278,7 @@ soring_enqueue(struct rte_soring *r, const void*objs,
lib/ring/soring.c soring_enqueue(struct rte_soring *r, const void *objs,
Quoted 9 lines
lib/ring/soring.c +1
-2return n; } -static __rte_always_inline uint32_t +static inline uint32_t soring_dequeue (struct rte_soring *r,void *objs,void *meta,uint32_t num,enum rte_ring_queue_behavior behavior,uint32_t *available) --Run quick test, no perf degradation noticed.
Quoted 2 lines
Tested-by Konstantin Ananyev <[email protected]>
We want LTO to work, and the alternatives discussed in another thread [1] are not popular.
v6 cover Fix LTO compilation warnings
In reply to Stephen HemmingerThis series fixes compilation warnings and one buffer overflow bug exposed when building DPDK with Link Time Optimization (LTO) enabled.
v6:
- net/mlx5: use __rte_assume() instead of runtime bounds check per Dariusz Sosnowski's review, avoiding any overhead on the flow creation fast path
Stephen Hemminger (6):
common/cnxk: replace variable length state array common/cnxk: replace variable length array common/cnxk: re-enable vla warnings common/cnxk: fix buffer overflow in SA setup
ring: use inline instead of always inline in soring net/mlx5: fix LTO stringop-overflow warning
drivers/common/cnxk/meson.build | 1 - drivers/common/cnxk/roc_aes.c | 3 ++- drivers/common/cnxk/roc_nix_inl.c | 2 +- drivers/common/cnxk/roc_platform.c | 4 ++-- drivers/net/mlx5/hws/mlx5dr_action.c | 11 +++++++++++ lib/ring/soring.c | 4 ++-- 6 files changed, 18 insertions(+), 7 deletions(-)
Signature · 1 line
2.51.0
PATCH v6 1/6 common/cnxk: replace variable length state array
The cipher function is always called with in_len = 16 and there is an existing define for that.
--- drivers/common/cnxk/roc_aes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/common/cnxk/roc_aes.c +2 -1
@@ -157,9 +157,10 @@ static void cipher(uint8_t *in, uint8_t *out, uint32_t *ks, uint32_t key_rounds, uint8_t in_len) {uint8_t data_word_len = in_len /sizeof (uint32_t ); -uint32_t state[data_word_len]; +uint32_t state[AES_HASH_KEY_LEN /sizeof (uint32_t )];unsigned int i, round; +PLT_ASSERT (in_len <=AES_HASH_KEY_LEN );memcpy (state, in,sizeof (state));/* AddRoundKey(state, w[0, Nb-1]) // See Sec. 5.1.4 */
Signature · 1 line
2.51.0
RE: [EXTERNAL] [PATCH v6 1/6] common/cnxk: replace variable length state array
Hi Stephen,
Minor nit inline. With that
Quoted 25 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Thursday, February 5, 2026 11:26 PM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; Nithin Kumar Dabilpuram <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; Sunil Kumar Kori <[email protected]>; Satha Koteswara Rao Kottidi <[email protected]>; Harman Kalra <[email protected]>
Subject: [EXTERNAL] [PATCH v6 1/6] common/cnxk: replace variable length state arrayThe cipher function is always called with
in_len= 16 and there is an existing define for that.Signed-off-by Stephen Hemminger <[email protected]>--- drivers/common/cnxk/roc_aes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/common/cnxk/roc_aes.c +0
-0
drivers/common/cnxk/roc_aes.c static void · line 161
Quoted 6 lines
drivers/common/cnxk/roc_aes.c +1
-1@@ -157,9 +157,10 @@ static void cipher(uint8_t *in, uint8_t *out, uint32_t *ks, uint32_t key_rounds, uint8_t in_len) {uint8_t data_word_len = in_len /sizeof (uint32_t ); -uint32_t state[data_word_len]; +uint32_t state[AES_HASH_KEY_LEN /sizeof (uint32_t )];
[Tejasree] This line needs to be moved up to maintain reverse xmas tree.
Quoted 8 lines
drivers/common/cnxk/roc_aes.c +1
-0unsigned int i, round; +PLT_ASSERT (in_len <=AES_HASH_KEY_LEN );memcpy (state, in,sizeof (state));/*
AddRoundKey(state, w[0, Nb-1])// See Sec. 5.1.4 */
--
2.51.0
Re: [EXTERNAL] [PATCH v6 1/6] common/cnxk: replace variable length state array
Quoted 4 lines · On Mon, 2 Mar 2026 19:06:19 +0000 Tejasree Kondoj <[email protected]> wrote:
Quoted 4 lines
drivers/common/cnxk/roc_aes.c +0
-0
Quoted 8 lines
drivers/common/cnxk/roc_aes.c static void · line 161
Quoted 7 lines
drivers/common/cnxk/roc_aes.c +1
-1@@ -157,9 +157,10 @@ static void cipher(uint8_t *in, uint8_t *out, uint32_t *ks, uint32_t key_rounds, uint8_t in_len) {uint8_t data_word_len = in_len /sizeof (uint32_t ); -uint32_t state[data_word_len]; +uint32_t state[AES_HASH_KEY_LEN /sizeof (uint32_t )];[Tejasree] This line needs to be moved up to maintain reverse xmas tree.
That is a Linux netdev thing, DPDK doesn't care about that.
PATCH v6 2/6 common/cnxk: replace variable length array
In reply to Stephen HemmingerThis fixes errors when compiled with LTO about large VLA.../drivers/common/cnxk/roc_platform.c: In function ‘irq_init’:../drivers/common/cnxk/roc_platform.c:92:14: warning: argument to variable-length array is too large [-Wvla-larger-than=]
92 | char irq_set_buf[MSIX_IRQ_SET_BUF_LEN];
| ^
Since the number of IRQ is limited by EAL max interrupt vectors use that define that already exists rather than a function call hidden in a macro.
Bugzilla ID: 1863
--- drivers/common/cnxk/roc_platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/common/cnxk/roc_platform.c +2 -2
@@ -17,8 +17,8 @@#include <sys/ioctl.h> #include <unistd.h> -#define MSIX_IRQ_SET_BUF_LEN \ - (sizeof(struct vfio_irq_set) + sizeof(int) * (plt_intr_max_intr_get(intr_handle))) +#define MSIX_IRQ_SET_BUF_LEN \ + (sizeof(struct vfio_irq_set) + sizeof(int) * PLT_MAX_RXTX_INTR_VEC_ID)static int irq_get_info (struct plt_intr_handle *intr_handle)
Signature · 1 line
2.51.0
RE: [EXTERNAL] [PATCH v6 2/6] common/cnxk: replace variable length array
From: Stephen Hemminger <[email protected]>
Sent: Thursday, February 5, 2026 11:26 PM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; Satha Koteswara Rao Kottidi <[email protected]>; [email protected]; Nithin Kumar Dabilpuram <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; Sunil Kumar Kori <[email protected]>; Harman Kalra <[email protected]>
Subject: [EXTERNAL] [PATCH v6 2/6] common/cnxk: replace variable length array
This fixes errors when compiled with LTO about large VLA. .. /drivers/common/cnxk/roc_platform. c: In function ‘irq_init’: .. /drivers/common/cnxk/roc_platform. c: 92: 14: warning: argument to variable-length array is too large [-Wvla-larger-than=] ZjQcmQRYFpfptBannerStart
Prioritize security for external emails:
Confirm sender and content safety before clicking links or opening attachments
Report Suspicious <https://us-phishalarm-ewt.proofpoint.com/EWT/v1/CRVmXkqW!tq3Z1f8UYnWa9K-cWX26ztpYTgkipucwksIFWb6OAmEPh_V3Ac4-BrjxCsV7Xh7swUxc2cswohoNMT7ip8nHpaVjKY9y6l7leDPcyhU$>
ZjQcmQRYFpfptBannerEnd
This fixes errors when compiled with LTO about large VLA.
../drivers/common/cnxk/roc_platform.c: In function ‘irq_init’:
../drivers/common/cnxk/roc_platform.c:92:14: warning: argument to variable-length array is too large [-Wvla-larger-than=]
92 | char irq_set_buf[MSIX_IRQ_SET_BUF_LEN];
| ^
Since the number of IRQ is limited by EAL max interrupt vectors
use that define that already exists rather than a function call
hidden in a macro.
Bugzilla ID: 1863
---
drivers/common/cnxk/roc_platform.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
drivers/common/cnxk/roc_platform.c +0 -0
index e13cb42285..1fdbf8f051 100644
--- a/drivers/common/cnxk/roc_platform.c
+++ b/drivers/common/cnxk/roc_platform.c
@@ -17,8 +17,8 @@
#include <sys/ioctl.h>
#include <unistd.h>
-#define MSIX_IRQ_SET_BUF_LEN \
- (sizeof(struct vfio_irq_set) + sizeof(int) * (plt_intr_max_intr_get(intr_handle)))
+#define MSIX_IRQ_SET_BUF_LEN \
+ (sizeof(struct vfio_irq_set) + sizeof(int) * PLT_MAX_RXTX_INTR_VEC_ID)
static int
irq_get_info(struct plt_intr_handle *intr_handle)
--
2.51.0
PATCH v6 3/6 common/cnxk: re-enable vla warnings
In reply to Stephen HemmingerThe code in common/cnxk no longer uses VLAs.
--- drivers/common/cnxk/meson.build | 1 - 1 file changed, 1 deletion(-)
drivers/common/cnxk/meson.build +0 -1
@@ -94,7 +94,6 @@ sources += files('cnxk_telemetry_bphy.c', 'cnxk_telemetry_sso.c', ) -cflags += no_wvla_cflag cflags += no_shadow_cflag if meson.is_cross_build()
Signature · 1 line
2.51.0
Re: [PATCH v6 3/6] common/cnxk: re-enable vla warnings
Quoted 23 lines · Stephen Hemminger
The code in common/cnxk no longer uses VLAs.
Signed-off-by Stephen Hemminger <[email protected]>--- drivers/common/cnxk/meson.build | 1 - 1 file changed, 1 deletion(-)drivers/common/cnxk/meson.build +0
-2@@ -94,7 +94,6 @@ sources += files('cnxk_telemetry_bphy.c', 'cnxk_telemetry_sso.c', ) -cflags += no_wvla_cflag cflags += no_shadow_cflag if meson.is_cross_build() --2.51.0
PATCH v6 4/6 common/cnxk: fix buffer overflow in SA setup
In reply to Stephen HemmingerThe nix_inl_reass_inb_sa_tbl_setup() function initializes inb_sa_sz to 1 byte, then allocates a buffer of that size. However, the buffer is subsequently passed to roc_ow_reass_inb_sa_init() which performs:
memset(sa, 0, sizeof(struct roc_ow_ipsec_inb_sa));
This writes 808 bytes into a 1-byte allocation, causing heap corruption.
This bug was detected by GCC's -Wstringop-overflow warning when building with LTO, which enables cross-compilation-unit inlining and allows the compiler to track the allocation size through to the memset call.
Fix by initializing inb_sa_sz to ROC_NIX_INL_OW_IPSEC_INB_SA_SZ, which is the standard macro used elsewhere in this file for OW (Sobek) inbound SA allocations.
Bugzilla ID: 1513
--- drivers/common/cnxk/roc_nix_inl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/common/cnxk/roc_nix_inl.c +1 -1
@@ -583,7 +583,7 @@ nix_inl_reass_inb_sa_tbl_setup(struct roc_nix *roc_nix)uint64_t sa_idx_w, lenm1_max;uint64_t res_addr_offset =0 ;uint64_t def_cptq =0 ; -size_t inb_sa_sz =1 ; +size_t inb_sa_sz =ROC_NIX_INL_OW_IPSEC_INB_SA_SZ ;uint8_t profile_id;struct mbox *mbox;void *sa;
Signature · 1 line
2.51.0
Re: [PATCH v6 4/6] common/cnxk: fix buffer overflow in SA setup
Quoted 44 lines · Stephen Hemminger
The
nix_inl_reass_inb_sa_tbl_setup()function initializesinb_sa_szto 1 byte, then allocates a buffer of that size. However, the buffer is subsequently passed toroc_ow_reass_inb_sa_init()which performs:memset(sa, 0, sizeof(struct roc_ow_ipsec_inb_sa));This writes 808 bytes into a 1-byte allocation, causing heap corruption.
This bug was detected by GCC's -Wstringop-overflow warning when building with LTO, which enables cross-compilation-unit inlining and allows the compiler to track the allocation size through to the memset call.
Fix by initializing
inb_sa_sztoROC_NIX_INL_OW_IPSEC_INB_SA_SZ, which is the standard macro used elsewhere in this file for OW (Sobek) inbound SA allocations.Bugzilla ID: 1513
Fixes fc9a711b5c8f ("common/cnxk: add NIX inline reassembly profile config")Signed-off-by Stephen Hemminger <[email protected]>--- drivers/common/cnxk/roc_nix_inl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/common/cnxk/roc_nix_inl.c +1
-2@@ -583,7 +583,7 @@ nix_inl_reass_inb_sa_tbl_setup(struct roc_nix *roc_nix)uint64_t sa_idx_w, lenm1_max;uint64_t res_addr_offset =0 ;uint64_t def_cptq =0 ; -size_t inb_sa_sz =1 ; +size_t inb_sa_sz =ROC_NIX_INL_OW_IPSEC_INB_SA_SZ ;uint8_t profile_id;struct mbox *mbox;void *sa; --2.51.0
PATCH v6 5/6 ring: use inline instead of always inline in soring
In reply to Stephen HemmingerWith LTO enabled, always_inline forces GCC to inline the full soring call chain, triggering a false -Wstringop-overflow warning. GCC cannot prove the 128-bit element copy path is unreachable when the ring uses 4-byte elements.
Use plain inline instead, giving the compiler discretion over inlining. At -O2/-O3 these small hot functions are still inlined by the compiler's own heuristics.
--- lib/ring/soring.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/ring/soring.c +2 -2
@@ -249,7 +249,7 @@ __rte_soring_stage_move_head(struct soring_stage_headtail *d,return n; } -static __rte_always_inline uint32_t +static inline uint32_t soring_enqueue (struct rte_soring *r,const void *objs,const void *meta,uint32_t n,enum rte_ring_queue_behavior behavior,uint32_t *free_space)
@@ -278,7 +278,7 @@ soring_enqueue(struct rte_soring *r, const void *objs,return n; } -static __rte_always_inline uint32_t +static inline uint32_t soring_dequeue (struct rte_soring *r,void *objs,void *meta,uint32_t num,enum rte_ring_queue_behavior behavior,uint32_t *available)
Signature · 1 line
2.51.0
PATCH v6 6/6 net/mlx5: fix LTO stringop-overflow warning
In reply to Stephen HemmingerWhen LTO inlines mlx5dr_action_prepare_decap_l3_data() into its callers, GCC sees the 64-byte stack buffer 'mh_data' but cannot prove num_of_actions is bounded, producing a false -Wstringop-overflow warning.
Add __rte_assume(num_of_actions <= DECAP_L3_NUM_ACTIONS_W_VLAN) so GCC can verify the loop stays within buffer bounds.
Bugzilla ID: 1710
--- drivers/net/mlx5/hws/mlx5dr_action.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/net/mlx5/hws/mlx5dr_action.c +11 -0
@@ -3620,6 +3620,17 @@ mlx5dr_action_prepare_decap_l3_data(uint8_t *src, uint8_t *dst,uint8_t *e_src;int i; +/* +* When LTO inlines this into mlx5dr_action_handle_tunnel_l3_to_l2(), +* GCC sees the 64-byte mh_data buffer but cannot prove num_of_actions +* is bounded, causing false -Wstringop-overflow warnings. +* +* Valid num_of_actions values are DECAP_L3_NUM_ACTIONS_W_NO_VLAN (6) +* or DECAP_L3_NUM_ACTIONS_W_VLAN (7). This check gives GCC the proof +* it needs that the loop iterations stay within buffer bounds. +*/ +__rte_assume (num_of_actions <=DECAP_L3_NUM_ACTIONS_W_VLAN ); +/* num_of_actions = remove l3l2 + 4/5 inserts + remove extra 2 bytes * copy from end of src to the start of dst. * move to the end, 2 is the leftover from 14B or 18B
Signature · 1 line
2.51.0
Re: [PATCH v6 6/6] net/mlx5: fix LTO stringop-overflow warning
Quoted 5 lines · Stephen Hemminger
When LTO inlines
mlx5dr_action_prepare_decap_l3_data()into its callers, GCC sees the 64-byte stack buffer 'mh_data' but cannot provenum_of_actionsis bounded, producing a false -Wstringop-overflow warning.
Quoted 8 lines
Add
__rte_assume(num_of_actions <= DECAP_L3_NUM_ACTIONS_W_VLAN)so GCC can verify the loop stays within buffer bounds.Bugzilla ID: 1710
Fixes f8c8a6d8440d ("net/mlx5/hws: add action object")Signed-off-by Stephen Hemminger <[email protected]>
Re: [PATCH v6 0/6] Fix LTO compilation warnings
In reply to Stephen HemmingerHi Marvell guys,
Quoted 17 lines · Stephen Hemminger
This series fixes compilation warnings and one buffer overflow bug exposed when building DPDK with Link Time Optimization (LTO) enabled.
v6:
- net/mlx5: use__rte_assume()instead of runtime bounds check per Dariusz Sosnowski's review, avoiding any overhead on the flow creation fast pathStephen Hemminger (6):
common/cnxk: replace variable length state array common/cnxk: replace variable length array common/cnxk: re-enable vla warnings common/cnxk: fix buffer overflow in SA setup
ring: use inline instead of always inline in soring net/mlx5: fix LTO stringop-overflow warning
Quoted 7 lines
drivers/common/cnxk/meson.build | 1 - drivers/common/cnxk/roc_aes.c | 3 ++- drivers/common/cnxk/roc_nix_inl.c | 2 +- drivers/common/cnxk/roc_platform.c | 4 ++-- drivers/net/mlx5/hws/mlx5dr_action.c | 11 +++++++++++ lib/ring/soring.c | 4 ++-- 6 files changed, 18 insertions(+), 7 deletions(-)
Could you look at those common/cnxk patches please?
Signature · 1 line
David Marchand
Re: [PATCH v6 0/6] Fix LTO compilation warnings
In reply to Stephen HemmingerQuoted 17 lines · Stephen Hemminger
This series fixes compilation warnings and one buffer overflow bug exposed when building DPDK with Link Time Optimization (LTO) enabled.
v6:
- net/mlx5: use__rte_assume()instead of runtime bounds check per Dariusz Sosnowski's review, avoiding any overhead on the flow creation fast pathStephen Hemminger (6):
common/cnxk: replace variable length state array common/cnxk: replace variable length array common/cnxk: re-enable vla warnings common/cnxk: fix buffer overflow in SA setup
ring: use inline instead of always inline in soring net/mlx5: fix LTO stringop-overflow warning
Quoted 7 lines
drivers/common/cnxk/meson.build | 1 - drivers/common/cnxk/roc_aes.c | 3 ++- drivers/common/cnxk/roc_nix_inl.c | 2 +- drivers/common/cnxk/roc_platform.c | 4 ++-- drivers/net/mlx5/hws/mlx5dr_action.c | 11 +++++++++++ lib/ring/soring.c | 4 ++-- 6 files changed, 18 insertions(+), 7 deletions(-)
Series applied, thanks.
Signature · 1 line
David Marchand