DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: David Marchand <david.marchand@redhat.com>
Cc: dev@dpdk.org, Tyler Retzlaff <roretzla@linux.microsoft.com>,
	Anatoly Burakov <anatoly.burakov@intel.com>
Subject: Re: [PATCH 01/16] eal: add function attributes for allocation functions
Date: Fri, 27 Sep 2024 16:10:35 -0700	[thread overview]
Message-ID: <20240927161035.5a72dba0@hermes.local> (raw)
In-Reply-To: <CAJFAV8wm_PCtPiY+LWF33nx20it8dM++bzcfbShSuPEdX0ZFWg@mail.gmail.com>

On Fri, 27 Sep 2024 18:09:22 -0400
David Marchand <david.marchand@redhat.com> wrote:

> On Fri, Sep 27, 2024 at 4:48 PM Stephen Hemminger
> <stephen@networkplumber.org> wrote:
> >
> > The allocation functions take a alignment argument that
> > can be useful to hint the compiler optimizer.
> >
> > This is supported by Gcc and Clang but only useful with
> > Gcc because Clang gives warning if alignment is 0.
> >
> > Recent versions of GCC have a malloc attribute that can
> > be used to find mismatches between allocation and free;
> > the typical problem caught is a pointer allocated with
> > rte_malloc() that is then incorrectly freed using free().  
> 
> Interesting tool.
> 
> >
> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> > ---
> >  lib/eal/include/rte_common.h | 30 ++++++++++++++++++++++++++++++
> >  lib/eal/include/rte_malloc.h | 24 ++++++++++++++++--------
> >  2 files changed, 46 insertions(+), 8 deletions(-)
> >
> > diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h
> > index eec0400dad..1b3781274d 100644
> > --- a/lib/eal/include/rte_common.h
> > +++ b/lib/eal/include/rte_common.h
> > @@ -228,6 +228,36 @@ typedef uint16_t unaligned_uint16_t;
> >  #define __rte_alloc_size(...)
> >  #endif
> >
> > +/**
> > + * Tells the compiler that the function returns a value that points to
> > + * memory aligned by a function argument.
> > + * Not enabled on clang because it warns if align argument is zero.
> > + */
> > +#if defined(RTE_CC_GCC)
> > +#define __rte_alloc_align(align_arg) \
> > +       __attribute__((alloc_align(align_arg)))
> > +#else
> > +#define __rte_alloc_align(...)
> > +#endif
> > +
> > +/**
> > + * Tells the compiler this is a function like malloc and that the pointer
> > + * returned cannot alias any other pointer (ie new memory).
> > + *
> > + * Also, with recent GCC versions also able to track that proper
> > + * dealloctor function is used for this pointer.
> > + */
> > +#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >= 110000)  
> 
> Even though it is probably equivalent, GCC_VERSION is set with RTE_CC_GCC.
> 
> > +#define __rte_alloc_func(free_func) \
> > +       __attribute__((malloc, malloc(free_func)))  
> 
> I read that this malloc attribute can also make use of the arg index
> to assume the pointer is freed.
> 
> Did you try this feature?

Yes, but all DPDK functions use first arg, so not really that relevant

  reply	other threads:[~2024-09-27 23:10 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-27 20:45 [PATCH 00/16] Fix allocation issues and add hardening Stephen Hemminger
2024-09-27 20:45 ` [PATCH 01/16] eal: add function attributes for allocation functions Stephen Hemminger
2024-09-27 22:09   ` David Marchand
2024-09-27 23:10     ` Stephen Hemminger [this message]
2024-09-27 20:45 ` [PATCH 02/16] memzone: fix use after free in tracing Stephen Hemminger
2024-09-27 20:45 ` [PATCH 03/16] cryptodev/bcmfs: fix mis-matched free Stephen Hemminger
2024-09-27 20:45 ` [PATCH 04/16] dma/ixd: fix incorrect free function in cleanup Stephen Hemminger
2024-09-27 20:45 ` [PATCH 05/16] event/cnxk: fix pointer mismatch " Stephen Hemminger
2024-09-27 20:45 ` [PATCH 06/16] examples/vhost: fix free function mismatch Stephen Hemminger
2024-09-27 20:45 ` [PATCH 07/16] net/cnxk: fix use-after-free Stephen Hemminger
2024-09-27 20:45 ` [PATCH 08/16] bpf: fix free mismatch if convert fails Stephen Hemminger
2024-09-27 20:45 ` [PATCH 09/16] net/e1000: fix use-after-free Stephen Hemminger
2024-09-27 20:45 ` [PATCH 10/16] net/sfc: fix use-after-free warning messages Stephen Hemminger
2024-09-27 20:45 ` [PATCH 11/16] net/cpfl: fix free of nonheap object Stephen Hemminger
2024-09-27 20:45 ` [PATCH 12/16] raw/ifpga/base: fix use after free Stephen Hemminger
2024-09-27 20:45 ` [PATCH 13/16] common/qat: " Stephen Hemminger
2024-09-27 20:45 ` [PATCH 14/16] drivers/ifpga: fix free function mismatch Stephen Hemminger
2024-09-27 20:45 ` [PATCH 15/16] eal: add alloc_function attribute to rte_malloc Stephen Hemminger
2024-09-27 20:45 ` [PATCH 16/16] mempool: annotate mempool create Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240927161035.5a72dba0@hermes.local \
    --to=stephen@networkplumber.org \
    --cc=anatoly.burakov@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=roretzla@linux.microsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).