mbuf: fix strict aliasing error in allocator
PATCH 1/1 mbuf: fix strict aliasing error in allocator
When building an application with -fstrict-aliasing -Wstrict-aliasing=2, we get errors triggered by rte_mbuf_raw_alloc() which is called inline from rte_pktmbuf_alloc().
../dpdk/lib/mbuf/rte_mbuf.h: In function ‘rte_mbuf_raw_alloc’:
../dpdk/lib/mbuf/rte_mbuf.h:600:42: error: dereferencing type-punned pointer might break strict-aliasing rules [-Werror=strict-aliasing]
600 | if (rte_mempool_get(mp, (void **)&m) < 0)
| ^~
Avoid incorrect casting by changing the type of the returned variable.
--- lib/mbuf/rte_mbuf.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/mbuf/rte_mbuf.h +2 -2
@@ -595,9 +595,9 @@ __rte_mbuf_raw_sanity_check(__rte_unused const struct rte_mbuf *m)*/ static inline struct rte_mbuf *rte_mbuf_raw_alloc (struct rte_mempool *mp) { -struct rte_mbuf *m; +void *m; -if (rte_mempool_get (mp, (void **)&m) <0 ) +if (rte_mempool_get (mp, &m) <0 )return NULL ;__rte_mbuf_raw_sanity_check (m);return m;
Signature · 1 line
2.46.1
Quoted 37 lines
From: Robin Jarry [mailto:[email protected]]
Sent: Wednesday, 25 September 2024 10.00When building an application with -fstrict-aliasing -Wstrict- aliasing=2,
we get errors triggered byrte_mbuf_raw_alloc()which is called inline fromrte_pktmbuf_alloc().
../dpdk/lib/mbuf/rte_mbuf.h: In function ‘rte_mbuf_raw_alloc’:
../dpdk/lib/mbuf/rte_mbuf.h:600:42: error: dereferencing type-punned pointer might break strict-aliasing rules [-Werror=strict-aliasing]
600 | if (rte_mempool_get(mp, (void **)&m)< 0)
| ^~Avoid incorrect casting by changing the type of the returned variable.
Signed-off-by Robin Jarry <[email protected]>--- lib/mbuf/rte_mbuf.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)lib/mbuf/rte_mbuf.h +2
-2@@ -595,9 +595,9 @@ __rte_mbuf_raw_sanity_check(__rte_unused conststruct rte_mbuf *m) */ static inline struct rte_mbuf *rte_mbuf_raw_alloc (struct rte_mempool *mp) { -struct rte_mbuf *m; +void *m; -if (rte_mempool_get (mp, (void **)&m) <0 ) +if (rte_mempool_get (mp, &m) <0 )return NULL ;
lib/mbuf/rte_mbuf.h __rte_mbuf_raw_sanity_check(__rte_unused const struct rte_mbuf *m) · line 603
Quoted 2 lines
lib/mbuf/rte_mbuf.h +0
-0__rte_mbuf_raw_sanity_check (m);return m;
Suggest:
__rte_mbuf_raw_sanity_check((struct rte_mbuf *)m); return (struct rte_mbuf *)m;
Quoted 2 lines
--
2.46.1
Please confirm that this builds with RTE_LIBRTE_MBUF_DEBUG and RTE_ENABLE_ASSERT set in config/rte_config.h. When confirmed, you may add:
Quoted 46 lines · On Wed, 25 Sep 2024 17:21:12 +0200 Morten Brørup <[email protected]>…
From: Morten Brørup <[email protected]>
To: "Robin Jarry" <[email protected]>, <[email protected]>
Subject: RE: [PATCH dpdk] mbuf: fix strict aliasing error in allocator
Date: Wed, 25 Sep 2024 17:21:12 +0200Quoted 37 lines
From: Robin Jarry [mailto:[email protected]]
Sent: Wednesday, 25 September 2024 10.00When building an application with -fstrict-aliasing -Wstrict- aliasing=2,
we get errors triggered byrte_mbuf_raw_alloc()which is called inline fromrte_pktmbuf_alloc().
../dpdk/lib/mbuf/rte_mbuf.h: In function ‘rte_mbuf_raw_alloc’:
../dpdk/lib/mbuf/rte_mbuf.h:600:42: error: dereferencing type-punned pointer might break strict-aliasing rules [-Werror=strict-aliasing]
600 | if (rte_mempool_get(mp, (void **)&m)< 0)
| ^~Avoid incorrect casting by changing the type of the returned variable.
Signed-off-by Robin Jarry <[email protected]>--- lib/mbuf/rte_mbuf.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)lib/mbuf/rte_mbuf.h +2
-2@@ -595,9 +595,9 @@ __rte_mbuf_raw_sanity_check(__rte_unused conststruct rte_mbuf *m) */ static inline struct rte_mbuf *rte_mbuf_raw_alloc (struct rte_mempool *mp) { -struct rte_mbuf *m; +void *m; -if (rte_mempool_get (mp, (void **)&m) <0 ) +if (rte_mempool_get (mp, &m) <0 )return NULL ;lib/mbuf/rte_mbuf.h __rte_mbuf_raw_sanity_check(__rte_unused const struct rte_mbuf *m) · line 603
Quoted 2 lines
lib/mbuf/rte_mbuf.h +0
-0__rte_mbuf_raw_sanity_check (m);return m;Suggest:
Quoted 2 lines
__rte_mbuf_raw_sanity_check((struct rte_mbuf *)m); return (struct rte_mbuf *)m;
Another way to avoid the warning would be to use a union?
Stephen Hemminger, Sep 25, 2024 at 11:23:
Quoted 52 lines
Quoted 46 lines · On Wed, 25 Sep 2024 17:21:12 +0200 Morten Brørup <[email protected]>…
From: Morten Brørup <[email protected]>
To: "Robin Jarry" <[email protected]>, <[email protected]>
Subject: RE: [PATCH dpdk] mbuf: fix strict aliasing error in allocator
Date: Wed, 25 Sep 2024 17:21:12 +0200Quoted 37 lines
From: Robin Jarry [mailto:[email protected]]
Sent: Wednesday, 25 September 2024 10.00When building an application with -fstrict-aliasing -Wstrict- aliasing=2,
we get errors triggered byrte_mbuf_raw_alloc()which is called inline fromrte_pktmbuf_alloc().
../dpdk/lib/mbuf/rte_mbuf.h: In function ‘rte_mbuf_raw_alloc’:
../dpdk/lib/mbuf/rte_mbuf.h:600:42: error: dereferencing type-punned pointer might break strict-aliasing rules [-Werror=strict-aliasing]
600 | if (rte_mempool_get(mp, (void **)&m)< 0)
| ^~Avoid incorrect casting by changing the type of the returned variable.
Signed-off-by Robin Jarry <[email protected]>--- lib/mbuf/rte_mbuf.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)lib/mbuf/rte_mbuf.h +2
-2@@ -595,9 +595,9 @@ __rte_mbuf_raw_sanity_check(__rte_unused conststruct rte_mbuf *m) */ static inline struct rte_mbuf *rte_mbuf_raw_alloc (struct rte_mempool *mp) { -struct rte_mbuf *m; +void *m; -if (rte_mempool_get (mp, (void **)&m) <0 ) +if (rte_mempool_get (mp, &m) <0 )return NULL ;lib/mbuf/rte_mbuf.h __rte_mbuf_raw_sanity_check(__rte_unused const struct rte_mbuf *m) · line 603
Quoted 2 lines
lib/mbuf/rte_mbuf.h +0
-0__rte_mbuf_raw_sanity_check (m);return m;Suggest:
Quoted 2 lines
__rte_mbuf_raw_sanity_check((struct rte_mbuf *)m); return (struct rte_mbuf *)m;
Quoted 1 line
Another way to avoid the warning would be to use a union?
I can use an inline union, it will be less code.
PATCH v2 1/1 mbuf: fix strict aliasing error in allocator
In reply to Robin JarryWhen building an application with -fstrict-aliasing -Wstrict-aliasing=2, we get errors triggered by rte_mbuf_raw_alloc() which is called inline from rte_pktmbuf_alloc().
../dpdk/lib/mbuf/rte_mbuf.h: In function ‘rte_mbuf_raw_alloc’:
../dpdk/lib/mbuf/rte_mbuf.h:600:42: error: dereferencing type-punned pointer might break strict-aliasing rules [-Werror=strict-aliasing]
600 | if (rte_mempool_get(mp, (void **)&m) < 0)
| ^~
Avoid incorrect casting by using an inline union variable.
---
Notes:
v2: use inline union to fix -Wincompatible-pointer-types
lib/mbuf/rte_mbuf.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
lib/mbuf/rte_mbuf.h +7 -4
@@ -595,12 +595,15 @@ __rte_mbuf_raw_sanity_check(__rte_unused const struct rte_mbuf *m)*/ static inline struct rte_mbuf *rte_mbuf_raw_alloc (struct rte_mempool *mp) { -struct rte_mbuf *m; +union { +void *ptr; +struct rte_mbuf *m; + } ret; -if (rte_mempool_get (mp, (void **)&m) <0 ) +if (rte_mempool_get (mp, &ret.ptr) <0 )return NULL ; -__rte_mbuf_raw_sanity_check (m); -return m; +__rte_mbuf_raw_sanity_check (ret.m); +return ret.m; }/**
Signature · 1 line
2.46.1
Quoted 15 lines · On Wed, 25 Sep 2024 11:40:54 -0400 Robin Jarry <[email protected]> wrote:
From: Robin Jarry <[email protected]>
To: [email protected]
Subject: [PATCH dpdk v2] mbuf: fix strict aliasing error in allocator
Date: Wed, 25 Sep 2024 11:40:54 -0400When building an application with -fstrict-aliasing -Wstrict-aliasing=2, we get errors triggered by
rte_mbuf_raw_alloc()which is called inline fromrte_pktmbuf_alloc().
../dpdk/lib/mbuf/rte_mbuf.h: In function ‘rte_mbuf_raw_alloc’:
../dpdk/lib/mbuf/rte_mbuf.h:600:42: error: dereferencing type-punned pointer might break strict-aliasing rules [-Werror=strict-aliasing]
600 | if (rte_mempool_get(mp, (void **)&m)< 0)
| ^~
Quoted 3 lines
Avoid incorrect casting by using an inline union variable.
Signed-off-by Robin Jarry <[email protected]>
Thanks, union is safer than cast.
Thomas Monjalon
Applied25/09/2024 17:47, Stephen Hemminger:
Quoted 18 lines
Quoted 15 lines · On Wed, 25 Sep 2024 11:40:54 -0400 Robin Jarry <[email protected]> wrote:
From: Robin Jarry <[email protected]>
To: [email protected]
Subject: [PATCH dpdk v2] mbuf: fix strict aliasing error in allocator
Date: Wed, 25 Sep 2024 11:40:54 -0400When building an application with -fstrict-aliasing -Wstrict-aliasing=2, we get errors triggered by
rte_mbuf_raw_alloc()which is called inline fromrte_pktmbuf_alloc().
../dpdk/lib/mbuf/rte_mbuf.h: In function ‘rte_mbuf_raw_alloc’:
../dpdk/lib/mbuf/rte_mbuf.h:600:42: error: dereferencing type-punned pointer might break strict-aliasing rules [-Werror=strict-aliasing]
600 | if (rte_mempool_get(mp, (void **)&m)< 0)
| ^~
Quoted 7 lines
Quoted 3 lines
Avoid incorrect casting by using an inline union variable.
Signed-off-by Robin Jarry <[email protected]>Thanks, union is safer than cast.
Reviewed-by Stephen Hemminger <[email protected]>
Applied, thanks.
Quoted 51 lines
-----Original Message-----
From: Robin Jarry <[email protected]>
Sent: Wednesday, September 25, 2024 6:41 PM
To: [email protected]
Subject: [PATCH dpdk v2] mbuf: fix strict aliasing error in allocatorWhen building an application with -fstrict-aliasing -Wstrict-aliasing=2, we get errors triggered by
rte_mbuf_raw_alloc()which is called inline fromrte_pktmbuf_alloc().
../dpdk/lib/mbuf/rte_mbuf.h: In function ‘rte_mbuf_raw_alloc’:
../dpdk/lib/mbuf/rte_mbuf.h:600:42: error: dereferencing type-punned pointer might break strict-aliasing rules [-Werror=strict-aliasing]
600 | if (rte_mempool_get(mp, (void **)&m)< 0)
| ^~Avoid incorrect casting by using an inline union variable.
Signed-off-by Robin Jarry <[email protected]>---
Notes:
v2: use inline union to fix -Wincompatible-pointer-typeslib/mbuf/rte_mbuf.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)lib/mbuf/rte_mbuf.h +7
-4@@ -595,12 +595,15 @@ __rte_mbuf_raw_sanity_check(__rte_unused conststruct rte_mbuf *m) */ static inline struct rte_mbuf *rte_mbuf_raw_alloc (struct rte_mempool *mp) { -struct rte_mbuf *m; +union { +void *ptr; +struct rte_mbuf *m; + } ret; -if (rte_mempool_get (mp, (void **)&m) <0 ) +if (rte_mempool_get (mp, &ret.ptr) <0 )return NULL ; -__rte_mbuf_raw_sanity_check (m); -return m; +__rte_mbuf_raw_sanity_check (ret.m); +return ret.m; }
Quoted 3 lines
/**
--
2.46.1
Hello,
We noticed the failure in ci/iol-mellanox-Performance and ran a few performance test cases on NVIDIA hardware and found no regressions. Additionally ran build and functional test cases that also passed.
Regards,
Ali
Recheck-request: iol-mellanox-Performance
When I enabled this test on Monday I accidentally set the delta threshold to 1.5% instead of 5%. So the accepted results window was too small and led to this false positive test fail.