net/ena: revert redefining memcpy

Message ID 20240812153417.65225-1-stephen@networkplumber.org (mailing list archive)
State Accepted
Delegated to: Ferruh Yigit
Headers
Series net/ena: revert redefining memcpy |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/Intel-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/intel-Functional success Functional PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS

Commit Message

Stephen Hemminger Aug. 12, 2024, 3:34 p.m. UTC
Redefining memcpy as rte_memcpy has no performance gain on
current compilers, and introduced bugs like this one where
rte_memcpy() will be detected as referencing past the destination.

Bugzilla ID: 1510
Fixes: 142778b3702a ("net/ena: switch memcpy to optimized version")

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/ena/base/ena_plat_dpdk.h | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
  

Comments

Wathsala Wathawana Vithanage Aug. 12, 2024, 8:53 p.m. UTC | #1
> Subject: [PATCH] net/ena: revert redefining memcpy
> 
> Redefining memcpy as rte_memcpy has no performance gain on current
> compilers, and introduced bugs like this one where
> rte_memcpy() will be detected as referencing past the destination.
> 
> Bugzilla ID: 1510
> Fixes: 142778b3702a ("net/ena: switch memcpy to optimized version")

Similar observations in Arm when RTE_ARCH_ARM64_MEMCPY flag is on.

Acked-by: Wathsala Vithanage <wathsala.vithanage@arm.com>

> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  drivers/net/ena/base/ena_plat_dpdk.h | 9 +--------
>  1 file changed, 1 insertion(+), 8 deletions(-)
> 
> diff --git a/drivers/net/ena/base/ena_plat_dpdk.h
> b/drivers/net/ena/base/ena_plat_dpdk.h
> index 21b96113c7..291db6cabe 100644
> --- a/drivers/net/ena/base/ena_plat_dpdk.h
> +++ b/drivers/net/ena/base/ena_plat_dpdk.h
> @@ -26,7 +26,6 @@
>  #include <rte_spinlock.h>
> 
>  #include <sys/time.h>
> -#include <rte_memcpy.h>
> 
>  typedef uint64_t u64;
>  typedef uint32_t u32;
> @@ -70,13 +69,7 @@ typedef uint64_t dma_addr_t;  #define
> ENA_UDELAY(x) rte_delay_us_block(x)
> 
>  #define ENA_TOUCH(x) ((void)(x))
> -/* Redefine memcpy with caution: rte_memcpy can be simply aliased to
> memcpy, so
> - * make the redefinition only if it's safe (and beneficial) to do so.
> - */
> -#if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64_MEMCPY) ||
> defined(RTE_ARCH_ARM_NEON_MEMCPY) -#undef memcpy -#define
> memcpy rte_memcpy -#endif
> +
>  #define wmb rte_wmb
>  #define rmb rte_rmb
>  #define mb rte_mb
> --
> 2.43.0
  
Morten Brørup Aug. 13, 2024, 8:57 a.m. UTC | #2
> From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> 
> Redefining memcpy as rte_memcpy has no performance gain on
> current compilers, and introduced bugs like this one where
> rte_memcpy() will be detected as referencing past the destination.
> 
> Bugzilla ID: 1510
> Fixes: 142778b3702a ("net/ena: switch memcpy to optimized version")
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---

Acked-by: Morten Brørup <mb@smartsharesystems.com>
  
Tyler Retzlaff Sept. 12, 2024, 5:12 a.m. UTC | #3
On Mon, Aug 12, 2024 at 08:34:17AM -0700, Stephen Hemminger wrote:
> Redefining memcpy as rte_memcpy has no performance gain on
> current compilers, and introduced bugs like this one where
> rte_memcpy() will be detected as referencing past the destination.
> 
> Bugzilla ID: 1510
> Fixes: 142778b3702a ("net/ena: switch memcpy to optimized version")
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---

Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
  
Ferruh Yigit Sept. 12, 2024, 8:19 a.m. UTC | #4
On 9/12/2024 6:12 AM, Tyler Retzlaff wrote:
> On Mon, Aug 12, 2024 at 08:34:17AM -0700, Stephen Hemminger wrote:
>> Redefining memcpy as rte_memcpy has no performance gain on
>> current compilers, and introduced bugs like this one where
>> rte_memcpy() will be detected as referencing past the destination.
>>
>> Bugzilla ID: 1510
>> Fixes: 142778b3702a ("net/ena: switch memcpy to optimized version")
>>
>> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
>> ---
> 
> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> 

Hi Shai,

Did you have any chance to check/test this patch?
  
Brandes, Shai Sept. 12, 2024, 2:53 p.m. UTC | #5
> -----Original Message-----
> From: Ferruh Yigit <ferruh.yigit@amd.com>
> Sent: Thursday, September 12, 2024 11:20 AM
> To: Tyler Retzlaff <roretzla@linux.microsoft.com>; Stephen Hemminger
> <stephen@networkplumber.org>; Brandes, Shai <shaibran@amazon.com>
> Cc: dev@dpdk.org; Schmeilin, Evgeny <evgenys@amazon.com>; Beider, Ron
> <rbeider@amazon.com>; Bernstein, Amit <amitbern@amazon.com>;
> Atrash, Wajeeh <atrwajee@amazon.com>; Chauskin, Igor
> <igorch@amazon.com>; Michal Krawczyk <mk@semihalf.com>; Artur Rojek
> <ar@semihalf.com>
> Subject: RE: [EXTERNAL] [PATCH] net/ena: revert redefining memcpy
> 
> CAUTION: This email originated from outside of the organization. Do not click
> links or open attachments unless you can confirm the sender and know the
> content is safe.
> 
> 
> 
> On 9/12/2024 6:12 AM, Tyler Retzlaff wrote:
> > On Mon, Aug 12, 2024 at 08:34:17AM -0700, Stephen Hemminger wrote:
> >> Redefining memcpy as rte_memcpy has no performance gain on current
> >> compilers, and introduced bugs like this one where
> >> rte_memcpy() will be detected as referencing past the destination.
> >>
> >> Bugzilla ID: 1510
> >> Fixes: 142778b3702a ("net/ena: switch memcpy to optimized version")
> >>
> >> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> >> ---
> >
> > Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> >
> 
> Hi Shai,
> 
> Did you have any chance to check/test this patch?
[Brandes, Shai] sorry, I missed this. The change will be tested by the upcoming Monday is this is fine.
  
Brandes, Shai Sept. 16, 2024, 6:33 a.m. UTC | #6
> -----Original Message-----
> From: Ferruh Yigit <ferruh.yigit@amd.com>
> Sent: Thursday, September 12, 2024 11:20 AM
> To: Tyler Retzlaff <roretzla@linux.microsoft.com>; Stephen Hemminger
> <stephen@networkplumber.org>; Brandes, Shai <shaibran@amazon.com>
> Cc: dev@dpdk.org; Schmeilin, Evgeny <evgenys@amazon.com>; Beider, Ron
> <rbeider@amazon.com>; Bernstein, Amit <amitbern@amazon.com>;
> Atrash, Wajeeh <atrwajee@amazon.com>; Chauskin, Igor
> <igorch@amazon.com>; Michal Krawczyk <mk@semihalf.com>; Artur Rojek
> <ar@semihalf.com>
> Subject: RE: [EXTERNAL] [PATCH] net/ena: revert redefining memcpy
> 
> CAUTION: This email originated from outside of the organization. Do not click
> links or open attachments unless you can confirm the sender and know the
> content is safe.
> 
> 
> 
> On 9/12/2024 6:12 AM, Tyler Retzlaff wrote:
> > On Mon, Aug 12, 2024 at 08:34:17AM -0700, Stephen Hemminger wrote:
> >> Redefining memcpy as rte_memcpy has no performance gain on current
> >> compilers, and introduced bugs like this one where
> >> rte_memcpy() will be detected as referencing past the destination.
> >>
> >> Bugzilla ID: 1510
> >> Fixes: 142778b3702a ("net/ena: switch memcpy to optimized version")
> >>
> >> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> >> ---
> >
> > Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> >
> 
> Hi Shai,
> 
> Did you have any chance to check/test this patch?
[Brandes, Shai] We are currently conducting tests and will provide an update shortly. In the meantime, could you advise whether it is recommended to entirely avoid using rte_memcpy in our driver, considering we have direct calls to it?
  
Stephen Hemminger Sept. 16, 2024, 3:11 p.m. UTC | #7
On Mon, 16 Sep 2024 06:33:26 +0000
"Brandes, Shai" <shaibran@amazon.com> wrote:

> > Did you have any chance to check/test this patch?  
> [Brandes, Shai] We are currently conducting tests and will provide an update shortly. In the meantime, could you advise whether it is recommended to entirely avoid using rte_memcpy in our driver, considering we have direct calls to it?

There is a long term goal to remove rte_memcpy(). It exists only as workaround for
cases where older compilers do not produce optimium code. 

When rte_memcpy() is used the checks done by fortify, gcc, coverity etc are
less and there is higher probability of bugs going undetected.

My current recommendation is to only use rte_memcpy() in the data path and for
variable size data items.
  
Brandes, Shai Sept. 16, 2024, 4:06 p.m. UTC | #8
Thanks for the clarification.
We are okay to move forward with the revert.

בתאריך 16 בספט׳ 2024 18:12,‏ Stephen Hemminger <stephen@networkplumber.org> כתב:
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.



On Mon, 16 Sep 2024 06:33:26 +0000
"Brandes, Shai" <shaibran@amazon.com> wrote:

> > Did you have any chance to check/test this patch?
> [Brandes, Shai] We are currently conducting tests and will provide an update shortly. In the meantime, could you advise whether it is recommended to entirely avoid using rte_memcpy in our driver, considering we have direct calls to it?

There is a long term goal to remove rte_memcpy(). It exists only as workaround for
cases where older compilers do not produce optimium code.

When rte_memcpy() is used the checks done by fortify, gcc, coverity etc are
less and there is higher probability of bugs going undetected.

My current recommendation is to only use rte_memcpy() in the data path and for
variable size data items.
  
Ferruh Yigit Sept. 22, 2024, 4:08 a.m. UTC | #9
On 9/12/2024 6:12 AM, Tyler Retzlaff wrote:
> On Mon, Aug 12, 2024 at 08:34:17AM -0700, Stephen Hemminger wrote:
>> Redefining memcpy as rte_memcpy has no performance gain on
>> current compilers, and introduced bugs like this one where
>> rte_memcpy() will be detected as referencing past the destination.
>>
>> Bugzilla ID: 1510
>> Fixes: 142778b3702a ("net/ena: switch memcpy to optimized version")
>>
>> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
>> ---
> 
> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> 

Acked-by: Shai Brandes <shaibran@amazon.com>

Applied to dpdk-next-net/main, thanks.
  

Patch

diff --git a/drivers/net/ena/base/ena_plat_dpdk.h b/drivers/net/ena/base/ena_plat_dpdk.h
index 21b96113c7..291db6cabe 100644
--- a/drivers/net/ena/base/ena_plat_dpdk.h
+++ b/drivers/net/ena/base/ena_plat_dpdk.h
@@ -26,7 +26,6 @@ 
 #include <rte_spinlock.h>
 
 #include <sys/time.h>
-#include <rte_memcpy.h>
 
 typedef uint64_t u64;
 typedef uint32_t u32;
@@ -70,13 +69,7 @@  typedef uint64_t dma_addr_t;
 #define ENA_UDELAY(x) rte_delay_us_block(x)
 
 #define ENA_TOUCH(x) ((void)(x))
-/* Redefine memcpy with caution: rte_memcpy can be simply aliased to memcpy, so
- * make the redefinition only if it's safe (and beneficial) to do so.
- */
-#if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64_MEMCPY) || defined(RTE_ARCH_ARM_NEON_MEMCPY)
-#undef memcpy
-#define memcpy rte_memcpy
-#endif
+
 #define wmb rte_wmb
 #define rmb rte_rmb
 #define mb rte_mb