eal/x86: disable array bounds checks in rte_memcpy_generic with gcc-12
RFC 1/1 eal/x86: disable array bounds checks in rte_memcpy_generic with gcc-12
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.
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.
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.
--- lib/eal/x86/include/rte_memcpy.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
lib/eal/x86/include/rte_memcpy.h +11 -5
@@ -27,6 +27,10 @@ extern "C" {#pragma GCC diagnostic ignored "-Wstringop-overflow"#endif +#if defined(RTE_TOOLCHAIN_GCC ) && (GCC_VERSION >=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; } +#if defined(RTE_TOOLCHAIN_GCC ) && (GCC_VERSION >=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); } -#if defined(RTE_TOOLCHAIN_GCC ) && (GCC_VERSION >=100000 ) -#pragma GCC diagnostic pop -#endif - #ifdef __cplusplus }#endif
Signature · 1 line
2.35.1
Quoted 64 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Thursday, 9 June 2022 00.49Gcc 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.
An example is using
rte_memcpy()on a RSS key of 40 bytes may triggerrte_memcpycomplaints fromrte_mov128reading past end of input.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 usesrte_memcpy()everywhere.Signed-off-by Stephen Hemminger <[email protected]>--- lib/eal/x86/include/rte_memcpy.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)lib/eal/x86/include/rte_memcpy.h +4
-0@@ -27,6 +27,10 @@ extern "C" {#pragma GCC diagnostic ignored "-Wstringop-overflow"#endif +#if defined(RTE_TOOLCHAIN_GCC ) && (GCC_VERSION >=120000 ) +#pragma GCC diagnostic ignored "-Warray-bounds" +#endif +/** * Copy bytes from one location to another. The locations must not overlap.
*lib/eal/x86/include/rte_memcpy.h +7
-5@@ -842,19 +846,21 @@ rte_memcpy_aligned(void *dst, const void *src, size_t n)return ret; } +#if defined(RTE_TOOLCHAIN_GCC ) && (GCC_VERSION >=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); } -#if defined(RTE_TOOLCHAIN_GCC ) && (GCC_VERSION >=100000 ) -#pragma GCC diagnostic pop -#endif - #ifdef __cplusplus }
Quoted 4 lines
#endif
--
2.35.1
Very good.
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.
08/06/2022 23:49, Stephen Hemminger пишет:
Quoted 49 lines
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.
An example is using
rte_memcpy()on a RSS key of 40 bytes may triggerrte_memcpycomplaints fromrte_mov128reading past end of input.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 usesrte_memcpy()everywhere.Signed-off-by Stephen Hemminger <[email protected]>--- lib/eal/x86/include/rte_memcpy.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)lib/eal/x86/include/rte_memcpy.h +11
-1@@ -27,6 +27,10 @@ extern "C" {#pragma GCC diagnostic ignored "-Wstringop-overflow"#endif +#if defined(RTE_TOOLCHAIN_GCC ) && (GCC_VERSION >=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; } +#if defined(RTE_TOOLCHAIN_GCC ) && (GCC_VERSION >=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
lib/eal/x86/include/rte_memcpy.h rte_memcpy_aligned(void *dst, const void *src, size_t n) · line 866
Quoted 10 lines
lib/eal/x86/include/rte_memcpy.h +0
-4return rte_memcpy_generic (dst, src, n); } -#if defined(RTE_TOOLCHAIN_GCC ) && (GCC_VERSION >=100000 ) -#pragma GCC diagnostic pop -#endif - #ifdef __cplusplus }#endif
Quoted 37 lines · Stephen Hemminger
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.
An example is using
rte_memcpy()on a RSS key of 40 bytes may triggerrte_memcpycomplaints fromrte_mov128reading past end of input.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 usesrte_memcpy()everywhere.Signed-off-by Stephen Hemminger <[email protected]>--- lib/eal/x86/include/rte_memcpy.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)lib/eal/x86/include/rte_memcpy.h +5
-0@@ -27,6 +27,10 @@ extern "C" {#pragma GCC diagnostic ignored "-Wstringop-overflow"#endif +#if defined(RTE_TOOLCHAIN_GCC ) && (GCC_VERSION >=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; } +#if defined(RTE_TOOLCHAIN_GCC ) && (GCC_VERSION >=100000 )
lib/eal/x86/include/rte_memcpy.h rte_memcpy_aligned(void *dst, const void *src, size_t n) · line 858
Quoted 10 lines
lib/eal/x86/include/rte_memcpy.h +6
-1+#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 ))
This patch does two things,
1. Disable "-Warray-bounds" with above pragma to silence compiler warnings.
2. Use compiler builtin for some cases.
Second can impact the performance and not really needed for the build error, what do you think to split the patch in two, since 1. is simple change but 2. may require more testing before accepting.
Quoted 57 lines
From: Ferruh Yigit [mailto:[email protected]]
Sent: Friday, 10 June 2022 12.13Quoted 12 lines · Stephen Hemminger
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.
An example is using
rte_memcpy()on a RSS key of 40 bytes may triggerrte_memcpycomplaints fromrte_mov128reading past end of input.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 usesrte_memcpy()everywhere.Review
Quoted 6 lines
Signed-off-by Stephen Hemminger <[email protected]>--- lib/eal/x86/include/rte_memcpy.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)(quoted diff) +0
-0
b/lib/eal/x86/include/rte_memcpy.hlib/eal/x86/include/rte_memcpy.h extern "C" { · line 35
Quoted 13 lines
index
18aa4e43a743..b90cdd8d7326100644lib/eal/x86/include/rte_memcpy.h +4
-0@@ -27,6 +27,10 @@ extern "C" {#pragma GCC diagnostic ignored "-Wstringop-overflow"#endif +#if defined(RTE_TOOLCHAIN_GCC ) && (GCC_VERSION >=120000 ) +#pragma GCC diagnostic ignored "-Warray-bounds" +#endif +/** * Copy bytes from one location to another. The locations must not overlap.
lib/eal/x86/include/rte_memcpy.h rte_memcpy_aligned(void *dst, const void *src,
Quoted 2 lines
lib/eal/x86/include/rte_memcpy.h +0
-0* @@ -842,19 +846,21 @@ rte_memcpy_aligned(void *dst, const void *src,
size_tn)Quoted 4 lines
lib/eal/x86/include/rte_memcpy.h +1
-0return ret; } +#if defined(RTE_TOOLCHAIN_GCC ) && (GCC_VERSION >=100000 )lib/eal/x86/include/rte_memcpy.h rte_memcpy_aligned(void *dst, const void *src, size_t n) · line 858
Quoted 10 lines
lib/eal/x86/include/rte_memcpy.h +6
-1+#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 ))This patch does two things,
Quoted 8 lines
1. Disable "-Warray-bounds" with above pragma to silence compiler warnings.
2. Use compiler builtin for some cases.
Second can impact the performance and not really needed for the build error, what do you think to split the patch in two, since 1. is simple change but 2. may require more testing before accepting.
Any such testing will be highly compiler dependent.
Do you have any specific compilers in mind, where you see a risk for lower performance?
Quoted 65 lines · Morten Brørup
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
Quoted 62 lines
From: Ferruh Yigit [mailto:[email protected]]
Sent: Friday, 10 June 2022 12.13Quoted 12 lines · Stephen Hemminger
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.
An example is using
rte_memcpy()on a RSS key of 40 bytes may triggerrte_memcpycomplaints fromrte_mov128reading past end of input.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 usesrte_memcpy()everywhere.Review
Quoted 6 lines
Signed-off-by Stephen Hemminger <[email protected]>--- lib/eal/x86/include/rte_memcpy.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)(quoted diff) +0
-0
b/lib/eal/x86/include/rte_memcpy.hlib/eal/x86/include/rte_memcpy.h extern "C" { · line 35
Quoted 13 lines
index
18aa4e43a743..b90cdd8d7326100644lib/eal/x86/include/rte_memcpy.h +4
-0@@ -27,6 +27,10 @@ extern "C" {#pragma GCC diagnostic ignored "-Wstringop-overflow"#endif +#if defined(RTE_TOOLCHAIN_GCC ) && (GCC_VERSION >=120000 ) +#pragma GCC diagnostic ignored "-Warray-bounds" +#endif +/** * Copy bytes from one location to another. The locations must not overlap.
lib/eal/x86/include/rte_memcpy.h rte_memcpy_aligned(void *dst, const void *src,
Quoted 2 lines
lib/eal/x86/include/rte_memcpy.h +0
-0* @@ -842,19 +846,21 @@ rte_memcpy_aligned(void *dst, const void *src,
size_tn)Quoted 4 lines
lib/eal/x86/include/rte_memcpy.h +1
-0return ret; } +#if defined(RTE_TOOLCHAIN_GCC ) && (GCC_VERSION >=100000 )lib/eal/x86/include/rte_memcpy.h rte_memcpy_aligned(void *dst, const void *src, size_t n) · line 858
Quoted 10 lines
lib/eal/x86/include/rte_memcpy.h +6
-1+#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 ))This patch does two things,
1. Disable "-Warray-bounds" with above pragma to silence compiler warnings.
2. Use compiler builtin for some cases.
Quoted 8 lines
Quoted 3 lines
Second can impact the performance and not really needed for the build error, what do you think to split the patch in two, since 1. is simple change but 2. may require more testing before accepting.
Any such testing will be highly compiler dependent.
Do you have any specific compilers in mind, where you see a risk for lower performance?
Hi Morten,
My point is possible performance impact, not about any possible risk or specific compiler version.
The possible performance impact part can be separated to its own patch and these can be discussed there, independent from gcc12 build error.