* [PATCH dpdk] mbuf: fix strict aliasing error in allocator
@ 2024-09-25 14:00 Robin Jarry
2024-09-25 15:21 ` Morten Brørup
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Robin Jarry @ 2024-09-25 14:00 UTC (permalink / raw)
To: dev
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.
Signed-off-by: Robin Jarry <rjarry@redhat.com>
---
lib/mbuf/rte_mbuf.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/mbuf/rte_mbuf.h b/lib/mbuf/rte_mbuf.h
index babe16c72ccb..bab1fb94d41d 100644
--- a/lib/mbuf/rte_mbuf.h
+++ b/lib/mbuf/rte_mbuf.h
@@ -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;
--
2.46.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [PATCH dpdk] mbuf: fix strict aliasing error in allocator
2024-09-25 14:00 [PATCH dpdk] mbuf: fix strict aliasing error in allocator Robin Jarry
@ 2024-09-25 15:21 ` Morten Brørup
2024-09-25 15:23 ` Stephen Hemminger
2024-09-25 15:40 ` [PATCH dpdk v2] " Robin Jarry
2024-09-26 16:38 ` [PATCH dpdk] " Patrick Robb
2 siblings, 1 reply; 9+ messages in thread
From: Morten Brørup @ 2024-09-25 15:21 UTC (permalink / raw)
To: Robin Jarry, dev
> From: Robin Jarry [mailto:rjarry@redhat.com]
> Sent: Wednesday, 25 September 2024 10.00
>
> 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.
>
> Signed-off-by: Robin Jarry <rjarry@redhat.com>
> ---
> lib/mbuf/rte_mbuf.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/mbuf/rte_mbuf.h b/lib/mbuf/rte_mbuf.h
> index babe16c72ccb..bab1fb94d41d 100644
> --- a/lib/mbuf/rte_mbuf.h
> +++ b/lib/mbuf/rte_mbuf.h
> @@ -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;
Suggest:
__rte_mbuf_raw_sanity_check((struct rte_mbuf *)m);
return (struct rte_mbuf *)m;
> --
> 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:
Acked-by: Morten Brørup <mb@smartsharesystems.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH dpdk] mbuf: fix strict aliasing error in allocator
2024-09-25 15:21 ` Morten Brørup
@ 2024-09-25 15:23 ` Stephen Hemminger
2024-09-25 15:24 ` Robin Jarry
0 siblings, 1 reply; 9+ messages in thread
From: Stephen Hemminger @ 2024-09-25 15:23 UTC (permalink / raw)
To: Morten Brørup; +Cc: Robin Jarry, dev
On Wed, 25 Sep 2024 17:21:12 +0200
Morten Brørup <mb@smartsharesystems.com> wrote:
> From: Morten Brørup <mb@smartsharesystems.com>
> To: "Robin Jarry" <rjarry@redhat.com>, <dev@dpdk.org>
> Subject: RE: [PATCH dpdk] mbuf: fix strict aliasing error in allocator
> Date: Wed, 25 Sep 2024 17:21:12 +0200
>
> > From: Robin Jarry [mailto:rjarry@redhat.com]
> > Sent: Wednesday, 25 September 2024 10.00
> >
> > 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.
> >
> > Signed-off-by: Robin Jarry <rjarry@redhat.com>
> > ---
> > lib/mbuf/rte_mbuf.h | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/lib/mbuf/rte_mbuf.h b/lib/mbuf/rte_mbuf.h
> > index babe16c72ccb..bab1fb94d41d 100644
> > --- a/lib/mbuf/rte_mbuf.h
> > +++ b/lib/mbuf/rte_mbuf.h
> > @@ -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;
>
> Suggest:
> __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?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH dpdk] mbuf: fix strict aliasing error in allocator
2024-09-25 15:23 ` Stephen Hemminger
@ 2024-09-25 15:24 ` Robin Jarry
0 siblings, 0 replies; 9+ messages in thread
From: Robin Jarry @ 2024-09-25 15:24 UTC (permalink / raw)
To: Stephen Hemminger, Morten Brørup; +Cc: dev
Stephen Hemminger, Sep 25, 2024 at 11:23:
> On Wed, 25 Sep 2024 17:21:12 +0200
> Morten Brørup <mb@smartsharesystems.com> wrote:
>
> > From: Morten Brørup <mb@smartsharesystems.com>
> > To: "Robin Jarry" <rjarry@redhat.com>, <dev@dpdk.org>
> > Subject: RE: [PATCH dpdk] mbuf: fix strict aliasing error in allocator
> > Date: Wed, 25 Sep 2024 17:21:12 +0200
> >
> > > From: Robin Jarry [mailto:rjarry@redhat.com]
> > > Sent: Wednesday, 25 September 2024 10.00
> > >
> > > 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.
> > >
> > > Signed-off-by: Robin Jarry <rjarry@redhat.com>
> > > ---
> > > lib/mbuf/rte_mbuf.h | 4 ++--
> > > 1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/lib/mbuf/rte_mbuf.h b/lib/mbuf/rte_mbuf.h
> > > index babe16c72ccb..bab1fb94d41d 100644
> > > --- a/lib/mbuf/rte_mbuf.h
> > > +++ b/lib/mbuf/rte_mbuf.h
> > > @@ -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;
> >
> > Suggest:
> > __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?
I can use an inline union, it will be less code.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH dpdk v2] mbuf: fix strict aliasing error in allocator
2024-09-25 14:00 [PATCH dpdk] mbuf: fix strict aliasing error in allocator Robin Jarry
2024-09-25 15:21 ` Morten Brørup
@ 2024-09-25 15:40 ` Robin Jarry
2024-09-25 15:47 ` Stephen Hemminger
2024-10-17 14:17 ` Ali Alnubani
2024-09-26 16:38 ` [PATCH dpdk] " Patrick Robb
2 siblings, 2 replies; 9+ messages in thread
From: Robin Jarry @ 2024-09-25 15:40 UTC (permalink / raw)
To: dev
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 using an inline union variable.
Signed-off-by: Robin Jarry <rjarry@redhat.com>
---
Notes:
v2: use inline union to fix -Wincompatible-pointer-types
lib/mbuf/rte_mbuf.h | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/lib/mbuf/rte_mbuf.h b/lib/mbuf/rte_mbuf.h
index babe16c72ccb..0d2e0e64b3ce 100644
--- a/lib/mbuf/rte_mbuf.h
+++ b/lib/mbuf/rte_mbuf.h
@@ -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;
}
/**
--
2.46.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH dpdk v2] mbuf: fix strict aliasing error in allocator
2024-09-25 15:40 ` [PATCH dpdk v2] " Robin Jarry
@ 2024-09-25 15:47 ` Stephen Hemminger
2024-10-17 19:44 ` Thomas Monjalon
2024-10-17 14:17 ` Ali Alnubani
1 sibling, 1 reply; 9+ messages in thread
From: Stephen Hemminger @ 2024-09-25 15:47 UTC (permalink / raw)
To: Robin Jarry; +Cc: dev
On Wed, 25 Sep 2024 11:40:54 -0400
Robin Jarry <rjarry@redhat.com> wrote:
> From: Robin Jarry <rjarry@redhat.com>
> To: dev@dpdk.org
> Subject: [PATCH dpdk v2] mbuf: fix strict aliasing error in allocator
> Date: Wed, 25 Sep 2024 11:40:54 -0400
>
> 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 using an inline union variable.
>
> Signed-off-by: Robin Jarry <rjarry@redhat.com>
Thanks, union is safer than cast.
Reviewed-by: Stephen Hemminger <stephen@networkplumber.org>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH dpdk] mbuf: fix strict aliasing error in allocator
2024-09-25 14:00 [PATCH dpdk] mbuf: fix strict aliasing error in allocator Robin Jarry
2024-09-25 15:21 ` Morten Brørup
2024-09-25 15:40 ` [PATCH dpdk v2] " Robin Jarry
@ 2024-09-26 16:38 ` Patrick Robb
2 siblings, 0 replies; 9+ messages in thread
From: Patrick Robb @ 2024-09-26 16:38 UTC (permalink / raw)
To: Robin Jarry; +Cc: dev
[-- Attachment #1: Type: text/plain, Size: 227 bytes --]
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.
[-- Attachment #2: Type: text/html, Size: 274 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [PATCH dpdk v2] mbuf: fix strict aliasing error in allocator
2024-09-25 15:40 ` [PATCH dpdk v2] " Robin Jarry
2024-09-25 15:47 ` Stephen Hemminger
@ 2024-10-17 14:17 ` Ali Alnubani
1 sibling, 0 replies; 9+ messages in thread
From: Ali Alnubani @ 2024-10-17 14:17 UTC (permalink / raw)
To: Robin Jarry, dev; +Cc: NBU-Contact-Thomas Monjalon (EXTERNAL)
> -----Original Message-----
> From: Robin Jarry <rjarry@redhat.com>
> Sent: Wednesday, September 25, 2024 6:41 PM
> To: dev@dpdk.org
> Subject: [PATCH dpdk v2] 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 using an inline union variable.
>
> Signed-off-by: Robin Jarry <rjarry@redhat.com>
> ---
>
> Notes:
> v2: use inline union to fix -Wincompatible-pointer-types
>
> lib/mbuf/rte_mbuf.h | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/lib/mbuf/rte_mbuf.h b/lib/mbuf/rte_mbuf.h
> index babe16c72ccb..0d2e0e64b3ce 100644
> --- a/lib/mbuf/rte_mbuf.h
> +++ b/lib/mbuf/rte_mbuf.h
> @@ -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;
> }
>
> /**
> --
> 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.
Tested-by: Ali Alnubani <alialnu@nvidia.com>
Regards,
Ali
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH dpdk v2] mbuf: fix strict aliasing error in allocator
2024-09-25 15:47 ` Stephen Hemminger
@ 2024-10-17 19:44 ` Thomas Monjalon
0 siblings, 0 replies; 9+ messages in thread
From: Thomas Monjalon @ 2024-10-17 19:44 UTC (permalink / raw)
To: Robin Jarry; +Cc: dev, Stephen Hemminger
25/09/2024 17:47, Stephen Hemminger:
> On Wed, 25 Sep 2024 11:40:54 -0400
> Robin Jarry <rjarry@redhat.com> wrote:
>
> > From: Robin Jarry <rjarry@redhat.com>
> > To: dev@dpdk.org
> > Subject: [PATCH dpdk v2] mbuf: fix strict aliasing error in allocator
> > Date: Wed, 25 Sep 2024 11:40:54 -0400
> >
> > 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 using an inline union variable.
> >
> > Signed-off-by: Robin Jarry <rjarry@redhat.com>
>
> Thanks, union is safer than cast.
>
> Reviewed-by: Stephen Hemminger <stephen@networkplumber.org>
Applied, thanks.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-10-17 19:44 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-25 14:00 [PATCH dpdk] mbuf: fix strict aliasing error in allocator Robin Jarry
2024-09-25 15:21 ` Morten Brørup
2024-09-25 15:23 ` Stephen Hemminger
2024-09-25 15:24 ` Robin Jarry
2024-09-25 15:40 ` [PATCH dpdk v2] " Robin Jarry
2024-09-25 15:47 ` Stephen Hemminger
2024-10-17 19:44 ` Thomas Monjalon
2024-10-17 14:17 ` Ali Alnubani
2024-09-26 16:38 ` [PATCH dpdk] " Patrick Robb
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).