app/test: use memcpy in ipsec test
PATCH 1/1 app/test: use memcpy in ipsec test
This test has tables of data that get copied with rte_memcpy. But when compiled without always inline the compiler gets confused by the inlining of rte_memcpy and thinks that it is possible for AVX code to reference past the input data.
Workaround is to use memcpy() which is better for this test anyway since regular memcpy has more static checking from compiler and analyzers.
--- app/test/test_ipsec.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
app/test/test_ipsec.c +6 -7
@@ -10,7 +10,6 @@#include <rte_hexdump.h> #include <rte_mbuf.h> #include <rte_malloc.h> -#include <rte_memcpy.h> #include <rte_cycles.h> #include <rte_bus_vdev.h> #include <rte_ip.h>
@@ -559,7 +558,7 @@ setup_test_string(struct rte_mempool *mpool, const char *string,return NULL ; }if (string !=NULL ) -rte_memcpy (dst, string, t_len); +memcpy (dst, string, t_len);else memset (dst,0 , t_len); }
@@ -604,22 +603,22 @@ setup_test_string_tunneled(struct rte_mempool *mpool, const char *string,/* copy outer IP and ESP header */ ipv4_outer.total_length =rte_cpu_to_be_16 (t_len); ipv4_outer.packet_id =rte_cpu_to_be_16 (seq); -rte_memcpy (dst, &ipv4_outer,sizeof (ipv4_outer)); +memcpy (dst, &ipv4_outer,sizeof (ipv4_outer)); dst +=sizeof (ipv4_outer); m->l3_len =sizeof (ipv4_outer); -rte_memcpy (dst, &esph,sizeof (esph)); +memcpy (dst, &esph,sizeof (esph)); dst +=sizeof (esph);if (string !=NULL ) {/* copy payload */ -rte_memcpy (dst, string, len); +memcpy (dst, string, len); dst += len;/* copy pad bytes */ -rte_memcpy (dst, esp_pad_bytes,RTE_MIN (padlen, +memcpy (dst, esp_pad_bytes,RTE_MIN (padlen,sizeof (esp_pad_bytes))); dst += padlen;/* copy ESP tail header */ -rte_memcpy (dst, &espt,sizeof (espt)); +memcpy (dst, &espt,sizeof (espt)); }else memset (dst,0 , t_len);
Signature · 1 line
2.53.0
Quoted 59 lines
This test has tables of data that get copied with
rte_memcpy. But when compiled without always inline the compiler gets confused by the inlining ofrte_memcpyand thinks that it is possible for AVX code to reference past the input data.Workaround is to use
memcpy()which is better for this test anyway since regular memcpy has more static checking from compiler and analyzers.Signed-off-by Stephen Hemminger <[email protected]>--- app/test/test_ipsec.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)app/test/test_ipsec.c +1
-2@@ -10,7 +10,6 @@#include <rte_hexdump.h> #include <rte_mbuf.h> #include <rte_malloc.h> -#include <rte_memcpy.h> #include <rte_cycles.h> #include <rte_bus_vdev.h> #include <rte_ip.h> @@ -559,7 +558,7 @@ setup_test_string(struct rte_mempool *mpool, constchar *string, return NULL; }if (string !=NULL ) -rte_memcpy (dst, string, t_len); +memcpy (dst, string, t_len);else memset (dst,0 , t_len);app/test/test_ipsec.c +3
-4}@@ -604,22 +603,22 @@ setup_test_string_tunneled(struct rte_mempool *mpool, const char *string,/* copy outer IP and ESP header */ ipv4_outer.total_length =rte_cpu_to_be_16 (t_len); ipv4_outer.packet_id =rte_cpu_to_be_16 (seq); -rte_memcpy (dst, &ipv4_outer,sizeof (ipv4_outer)); +memcpy (dst, &ipv4_outer,sizeof (ipv4_outer)); dst +=sizeof (ipv4_outer); m->l3_len =sizeof (ipv4_outer); -rte_memcpy (dst, &esph,sizeof (esph)); +memcpy (dst, &esph,sizeof (esph)); dst +=sizeof (esph);if (string !=NULL ) {/* copy payload */ -rte_memcpy (dst, string, len); +memcpy (dst, string, len); dst += len;/* copy pad bytes */ - rte_memcpy(dst, esp_pad_bytes, RTE_MIN(padlen,
app/test/test_ipsec.c setup_test_string_tunneled(struct rte_mempool
Quoted 10 lines
app/test/test_ipsec.c +2
-2+memcpy (dst, esp_pad_bytes,RTE_MIN (padlen,sizeof (esp_pad_bytes))); dst += padlen;/* copy ESP tail header */ -rte_memcpy (dst, &espt,sizeof (espt)); +memcpy (dst, &espt,sizeof (espt)); }else memset (dst,0 , t_len); --
Quoted 1 line
2.53.0
Morten Brørup
Acked-byQuoted 28 lines
app/test/test_ipsec.c setup_test_string(struct rte_mempool *mpool,
Quoted 27 lines
This test has tables of data that get copied with
rte_memcpy. But when compiled without always inline the compiler gets confused by the inlining ofrte_memcpyand thinks that it is possible for AVX code to reference past the input data.Workaround is to use
memcpy()which is better for this test anyway since regular memcpy has more static checking from compiler and analyzers.Signed-off-by Stephen Hemminger <[email protected]>--- app/test/test_ipsec.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)app/test/test_ipsec.c +0
-1@@ -10,7 +10,6 @@#include <rte_hexdump.h> #include <rte_mbuf.h> #include <rte_malloc.h> -#include <rte_memcpy.h> #include <rte_cycles.h> #include <rte_bus_vdev.h> #include <rte_ip.h> @@ -559,7 +558,7 @@ setup_test_string(struct rte_mempool *mpool,const
Quoted 16 lines
Quoted 10 lines
app/test/test_ipsec.c +1
-1char *string, return NULL; }if (string !=NULL ) -rte_memcpy (dst, string, t_len); +memcpy (dst, string, t_len);else memset (dst,0 , t_len);app/test/test_ipsec.c +0
-0}app/test/test_ipsec.c setup_test_string_tunneled(struct rte_mempool · line 607
Quoted 6 lines
app/test/test_ipsec.c +1
-1@@ -604,22 +603,22 @@ setup_test_string_tunneled(struct rte_mempool *mpool, const char *string,/* copy outer IP and ESP header */ ipv4_outer.total_length =rte_cpu_to_be_16 (t_len); ipv4_outer.packet_id =rte_cpu_to_be_16 (seq); -rte_memcpy (dst, &ipv4_outer,sizeof (ipv4_outer)); +memcpy (dst, &ipv4_outer,sizeof (ipv4_outer));
How about:
*dst = ipv4_outer;
Don't know if it applies here.
Quoted 6 lines
Quoted 6 lines
app/test/test_ipsec.c +1
-1dst +=sizeof (ipv4_outer); m->l3_len =sizeof (ipv4_outer); -rte_memcpy (dst, &esph,sizeof (esph)); +memcpy (dst, &esph,sizeof (esph)); dst +=sizeof (esph);
Quoted 13 lines
app/test/test_ipsec.c setup_test_string_tunneled(struct rte_mempool *mpool, const char *string, · line 621
Quoted 13 lines
app/test/test_ipsec.c +3
-3if (string !=NULL ) {/* copy payload */ -rte_memcpy (dst, string, len); +memcpy (dst, string, len); dst += len;/* copy pad bytes */ -rte_memcpy (dst, esp_pad_bytes,RTE_MIN (padlen, +memcpy (dst, esp_pad_bytes,RTE_MIN (padlen,sizeof (esp_pad_bytes))); dst += padlen;/* copy ESP tail header */ -rte_memcpy (dst, &espt,sizeof (espt)); +memcpy (dst, &espt,sizeof (espt));
Also here:
*dst = espt;
Also don't know if it applies here.
Quoted 8 lines
app/test/test_ipsec.c setup_test_string_tunneled(struct rte_mempool *mpool, const char *string,
Quoted 4 lines
app/test/test_ipsec.c +0
-1}else memset (dst,0 , t_len); --Quoted 1 line
2.53.0
With or without suggested changes:
If you are curious too...
Does the compiler still get confused about AVX rte_memcpy (without this patch), if applying the rte_memcpy patch?
https://patchwork.dpdk.org/project/dpdk/patch/[email protected]/
Quoted 11 lines · On Fri, 29 May 2026 22:45:00 +0200 Morten Brørup <[email protected]>…
Quoted 7 lines
app/test/test_ipsec.c setup_test_string_tunneled(struct rte_mempool · line 607
Quoted 7 lines
app/test/test_ipsec.c +1
-1@@ -604,22 +603,22 @@ setup_test_string_tunneled(struct rte_mempool *mpool, const char *string,/* copy outer IP and ESP header */ ipv4_outer.total_length =rte_cpu_to_be_16 (t_len); ipv4_outer.packet_id =rte_cpu_to_be_16 (seq); -rte_memcpy (dst, &ipv4_outer,sizeof (ipv4_outer)); +memcpy (dst, &ipv4_outer,sizeof (ipv4_outer));How about:
*dst =ipv4_outer;
Quoted 1 line
Don't know if it applies here.
Good idea but dst is char *.
I suppose could use a cast but at that point the good properties of assignment disappear.
Didn't want to go changing other code.
Quoted 18 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Saturday, 30 May 2026 00.53Quoted 1 line · On Fri, 29 May 2026 22:45:00 +0200 Morten Brørup <[email protected]>…
Quoted 1 line
Review setup_test_string_tunneled(struct
Quoted 1 line
(quoted diff) +0
-0@@ -604,22 +603,22 @@ setup_test_string_tunneled(struct
rte_mempoolQuoted 10 lines
Quoted 6 lines
app/test/test_ipsec.c setup_test_string_tunneled(struct rte_mempool *mpool, const char *string, · line 606
Quoted 6 lines
app/test/test_ipsec.c +1
-1*mpool, const char *string,/* copy outer IP and ESP header */ ipv4_outer.total_length =rte_cpu_to_be_16 (t_len); ipv4_outer.packet_id =rte_cpu_to_be_16 (seq); -rte_memcpy (dst, &ipv4_outer,sizeof (ipv4_outer)); +memcpy (dst, &ipv4_outer,sizeof (ipv4_outer));How about:
*dst =ipv4_outer;
Quoted 7 lines
Quoted 1 line
Don't know if it applies here.
Good idea but dst is char *.
I suppose could use a cast but at that point the good properties of assignment disappear.Didn't want to go changing other code.
Agree. Better stick with memcpy() than type cast.
Quoted 3 lines · On Fri, 29 May 2026 22:45:00 +0200 Morten Brørup <[email protected]>…
If you are curious too...
Does the compiler still get confused about AVXrte_memcpy(without this patch), if applying therte_memcpypatch?
https://patchwork.dpdk.org/project/dpdk/patch/[email protected]/
No still fails.
This is if __rte_always_inline is defined as just inline as an experiment. Compiler gets confused in virtio_net because of matching conditions doing initialization in virtio_net.
Also, has issue with rte_memcpy.
ninja: Entering directory `build'
[2352/3763] Compiling C object lib/librte_vhost.a.p/vhost_virtio_net.c.o ../lib/vhost/virtio_net.c: In function ‘desc_to_mbuf’:../lib/vhost/virtio_net.c:3025:34: warning: ‘pkts_info’ may be used uninitialized [-Wmaybe-uninitialized]
3025 | pkts_info[slot_idx].nethdr = *hdr;
| ^../lib/vhost/virtio_net.c:2915:37: note: ‘pkts_info’ was declared here
2915 | struct async_inflight_info *pkts_info;
| ^~~~~~~~~
[3487/3763] Compiling C object app/dpdk-test.p/test_test_ipsec.c.o
In file included from /usr/lib/gcc/x86_64-linux-gnu/15/include/immintrin.h:43,
from ../lib/eal/x86/include/rte_rtm.h:8,
from ../lib/eal/x86/include/rte_spinlock.h:9,
from ../lib/mempool/rte_mempool.h:44,
from ../lib/mbuf/rte_mbuf.h:39,
from ../app/test/test_ipsec.c:11:
In function ‘_mm256_loadu_si256’,
inlined from ‘rte_mov32’ at ../lib/eal/x86/include/rte_memcpy.h:119:9,
inlined from ‘rte_mov64’ at ../lib/eal/x86/include/rte_memcpy.h:158:2,
inlined from ‘rte_mov128’ at ../lib/eal/x86/include/rte_memcpy.h:170:2,
inlined from ‘rte_memcpy_generic_more_than_64’ at ../lib/eal/x86/include/rte_memcpy.h:389:4,
inlined from ‘rte_memcpy’ at ../lib/eal/x86/include/rte_memcpy.h:715:10,
inlined from ‘setup_test_string_tunneled.constprop’ at ../app/test/test_ipsec.c:615:3:
/usr/lib/gcc/x86_64-linux-gnu/15/include/avxintrin.h:873:10: warning: array subscript ‘__m256i_u[3]’ is partly outside array bounds of ‘const char[108]’ [-Warray-bounds=]
873 | return *__P;
| ^~~~
../app/test/test_ipsec.c: In function ‘setup_test_string_tunneled.constprop’:
../app/test/test_ipsec.c:527:12: note: at offset 96 into object ‘null_plain_data’ of size 108
527 | const char null_plain_data[] =
| ^~~~~~~~~~~~~~~[3763/3763] Linking target app/dpdk-test
Quoted 59 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Saturday, 30 May 2026 00.59Quoted 2 lines · On Fri, 29 May 2026 22:45:00 +0200 Morten Brørup <[email protected]>…
If you are curious too...
Does the compiler still get confused about AVXrte_memcpy(withoutthis patch), if applying the
rte_memcpypatch?No still fails.
This is if
__rte_always_inlineis defined as just inline as an experiment.
Compiler gets confused invirtio_netbecause of matching conditions doing
initialization invirtio_net.Also, has issue with
rte_memcpy.ninja: Entering directory `build'
[2352/3763] Compiling C objectlib/librte_vhost.a.p/vhost_virtio_net.c.o../lib/vhost/virtio_net.c: In function ‘desc_to_mbuf’:../lib/vhost/virtio_net.c:3025:34: warning: ‘pkts_info’ may be used uninitialized [-Wmaybe-uninitialized]
3025 | pkts_info[slot_idx].nethdr = *hdr;
| ^../lib/vhost/virtio_net.c:2915:37: note: ‘pkts_info’ was declared here
2915 | structasync_inflight_info*pkts_info;
| ^~~~~~~~~
[3487/3763] Compiling C objectapp/dpdk-test.p/test_test_ipsec.c.oIn file included from/usr/lib/gcc/x86_64-linux-gnu/15/include/immintrin.h:43,from ../lib/eal/x86/include/rte_rtm.h:8, from ../lib/eal/x86/include/rte_spinlock.h:9, from ../lib/mempool/rte_mempool.h:44, from ../lib/mbuf/rte_mbuf.h:39, from ../app/test/test_ipsec.c:11:In function ‘_mm256_loadu_si256’,
inlined from ‘rte_mov32’ at../lib/eal/x86/include/rte_memcpy.h:119:9,
inlined from ‘rte_mov64’ at../lib/eal/x86/include/rte_memcpy.h:158:2,
inlined from ‘rte_mov128’ at../lib/eal/x86/include/rte_memcpy.h:170:2,
inlined from ‘rte_memcpy_generic_more_than_64’ at../lib/eal/x86/include/rte_memcpy.h:389:4,
inlined from ‘rte_memcpy’ at../lib/eal/x86/include/rte_memcpy.h:715:10,
inlined from ‘setup_test_string_tunneled.constprop’ at../app/test/test_ipsec.c:615:3:/usr/lib/gcc/x86_64-linux-gnu/15/include/avxintrin.h:873:10: warning:
array subscript ‘__m256i_u[3]’ is partly outside array bounds of ‘const char[108]’ [-Warray-bounds=]873 | return *__P; | ^~~~
Quoted 7 lines
../app/test/test_ipsec.c: In function ‘setup_test_string_tunneled.constprop’:../app/test/test_ipsec.c:527:12: note: at offset 96 into object ‘null_plain_data’ of size 108
527 | const char null_plain_data[] =| ^~~~~~~~~~~~~~~[3763/3763] Linking target app/dpdk-test
Interesting experiment. Thanks for sharing.
Akhil Goyal
AppliedQuoted 10 lines
This test has tables of data that get copied with
rte_memcpy. But when compiled without always inline the compiler gets confused by the inlining ofrte_memcpyand thinks that it is possible for AVX code to reference past the input data.Workaround is to use
memcpy()which is better for this test anyway since regular memcpy has more static checking from compiler and analyzers.Signed-off-by Stephen Hemminger <[email protected]>
Applied to dpdk-next-crypto
Thanks.