Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CBC2C433EF for ; Thu, 9 Jun 2022 07:27:03 +0000 (UTC) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3BAAD40689; Thu, 9 Jun 2022 09:27:02 +0200 (CEST) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id 6DEE340220 for ; Thu, 9 Jun 2022 09:27:00 +0200 (CEST) Content-class: urn:content-classes:message Subject: RE: [RFC] eal/x86: disable array bounds checks in rte_memcpy_generic with gcc-12 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Date: Thu, 9 Jun 2022 09:26:57 +0200 Message-ID: <98CBD80474FA8B44BF855DF32C47DC35D87102@smartserver.smartshare.dk> X-MimeOLE: Produced By Microsoft Exchange V6.5 In-Reply-To: <20220608224928.457440-1-stephen@networkplumber.org> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [RFC] eal/x86: disable array bounds checks in rte_memcpy_generic with gcc-12 Thread-Index: Adh7igc+2IIRRAgyRribyDgNEC1ewAAR935A References: <20220608224928.457440-1-stephen@networkplumber.org> From: =?iso-8859-1?Q?Morten_Br=F8rup?= To: "Stephen Hemminger" , X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org > From: Stephen Hemminger [mailto:stephen@networkplumber.org] > Sent: Thursday, 9 June 2022 00.49 >=20 > Gcc 12 adds more array bounds checking (good); but it is not smart > enough to realize that for small fixed sizes, the bigger move options > are not used. >=20 > An example is using rte_memcpy() on a RSS key of 40 bytes may trigger > rte_memcpy complaints from rte_mov128 reading past end of input. >=20 > In order to keep some of the checks add special case for calls > to rte_memcpy() with fixed size arguments to use the compiler > builtin instead. Don't want to give all the checking for > code that uses rte_memcpy() everywhere. >=20 > Signed-off-by: Stephen Hemminger > --- > lib/eal/x86/include/rte_memcpy.h | 16 +++++++++++----- > 1 file changed, 11 insertions(+), 5 deletions(-) >=20 > diff --git a/lib/eal/x86/include/rte_memcpy.h > b/lib/eal/x86/include/rte_memcpy.h > index 18aa4e43a743..b90cdd8d7326 100644 > --- a/lib/eal/x86/include/rte_memcpy.h > +++ b/lib/eal/x86/include/rte_memcpy.h > @@ -27,6 +27,10 @@ extern "C" { > #pragma GCC diagnostic ignored "-Wstringop-overflow" > #endif >=20 > +#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >=3D 120000) > +#pragma GCC diagnostic ignored "-Warray-bounds" > +#endif > + > /** > * Copy bytes from one location to another. The locations must not > overlap. > * > @@ -842,19 +846,21 @@ rte_memcpy_aligned(void *dst, const void *src, > size_t n) > return ret; > } >=20 > +#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >=3D 100000) > +#pragma GCC diagnostic pop > +#endif > + > static __rte_always_inline void * > rte_memcpy(void *dst, const void *src, size_t n) > { > - if (!(((uintptr_t)dst | (uintptr_t)src) & ALIGNMENT_MASK)) > + if (__builtin_constant_p(n)) > + return __builtin_memcpy(dst, src, n); > + else if (!(((uintptr_t)dst | (uintptr_t)src) & ALIGNMENT_MASK)) > return rte_memcpy_aligned(dst, src, n); > else > return rte_memcpy_generic(dst, src, n); > } >=20 > -#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >=3D 100000) > -#pragma GCC diagnostic pop > -#endif > - > #ifdef __cplusplus > } > #endif > -- > 2.35.1 >=20 Very good. Reviewed-by: Morten Br=F8rup While you are at it, would you consider concealing the definition of = ALIGNMENT_MASK too? It seems to be leaking out from this header file.