Skip to contentSkip to conversation

eal: add nonnull and access function attributes

PATCH Superseded Morten Brørup 15 participants 77 messages Dec 2, 2022 – Mar 13, 2024 1 message not in the archive Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eal: add nonnull and access function attributes

Add "nonnull" function attribute to help the compiler detect a NULL pointer being passed to a function not accepting NULL pointers as an argument at build time.

Add "access" function attribute to tell the optimizer how a function accesses its pointer arguments.

Add these attributes to the rte_memcpy() function, as the first in hopefully many to come.

---
 lib/eal/arm/include/rte_memcpy_32.h  |  6 ++++++
 lib/eal/arm/include/rte_memcpy_64.h  |  6 ++++++
 lib/eal/include/generic/rte_memcpy.h |  5 +++++
 lib/eal/include/rte_common.h         | 26 ++++++++++++++++++++++++++
 lib/eal/ppc/include/rte_memcpy.h     |  3 +++
 lib/eal/x86/include/rte_memcpy.h     |  6 ++++++
 6 files changed, 52 insertions(+)
lib/eal/arm/include/rte_memcpy_32.h +6 -0
index fb3245b59c..ba4f050a5d 100644
@@ -125,6 +125,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src)
 	memcpy((dst), (src), (n)) :          \
 	rte_memcpy_func((dst), (src), (n)); })
 
+__rte_nonnull(1, 2)
+__rte_access(write_only, 1, 3)
+__rte_access(read_only, 2, 3)
 static inline void *
 rte_memcpy_func(void *dst, const void *src, size_t n)
 {
@@ -290,6 +293,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src)
 	memcpy(dst, src, 256);
 }
 
+__rte_nonnull(1, 2)
+__rte_access(write_only, 1, 3)
+__rte_access(read_only, 2, 3)
 static inline void *
 rte_memcpy(void *dst, const void *src, size_t n)
 {
lib/eal/arm/include/rte_memcpy_64.h +6 -0
index 85ad587bd3..5403e30db5 100644
@@ -282,6 +282,9 @@ void rte_memcpy_ge64(uint8_t *dst, const uint8_t *src, size_t n)
 }
 
 #if RTE_CACHE_LINE_SIZE >= 128
+__rte_nonnull(1, 2)
+__rte_access(write_only, 1, 3)
+__rte_access(read_only, 2, 3)
 static __rte_always_inline
 void *rte_memcpy(void *dst, const void *src, size_t n)
 {
@@ -303,6 +306,9 @@ void *rte_memcpy(void *dst, const void *src, size_t n)
 }
 
 #else
+__rte_nonnull(1, 2)
+__rte_access(write_only, 1, 3)
+__rte_access(read_only, 2, 3)
 static __rte_always_inline
 void *rte_memcpy(void *dst, const void *src, size_t n)
 {
lib/eal/include/generic/rte_memcpy.h +5 -0
index e7f0f8eaa9..86fd20884c 100644
@@ -11,6 +11,8 @@
  * Functions for vectorised implementation of memcpy().
  */
 
+#include <rte_common.h>
+
 /**
  * Copy 16 bytes from one location to another using optimised
  * instructions. The locations should not overlap.
@@ -108,6 +110,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src);
  * @return
  *   Pointer to the destination data.
  */
+__rte_nonnull(1, 2)
+__rte_access(write_only, 1, 3)
+__rte_access(read_only, 2, 3)
 static void *
 rte_memcpy(void *dst, const void *src, size_t n);
 
lib/eal/include/rte_common.h +26 -0
index 15765b408d..c2bd6074b1 100644
@@ -149,6 +149,32 @@ typedef uint16_t unaligned_uint16_t;
 	__attribute__((format(printf, format_index, first_arg)))
 #endif
 
+/**
+ * Check pointer arguments at compile-time.
+ *
+ * @param ...
+ *    Comma separated list of parameter indexes of pointer arguments.
+ */
+#define __rte_nonnull(...) \
+	__attribute__((nonnull(__VA_ARGS__)))
+
+/**
+ * Tells compiler about the access mode of a pointer argument.
+ *
+ * @param access_mode
+ *    Access mode: read_only, read_write, write_only, or none.
+ * @param ref_index
+ *    Parameter index of pointer argument.
+ * @param size_index (optional)
+ *    Parameter index of size argument.
+ */
+#if defined(RTE_CC_IS_GNU) && (GCC_VERSION >= 100400)
+#define __rte_access(access_mode, ...) \
+	__attribute__((access(access_mode, __VA_ARGS__)))
+#else
+#define __rte_access(access_mode, ...)
+#endif
+
 /**
  * Tells compiler that the function returns a value that points to
  * memory, where the size is given by the one or two arguments.
lib/eal/ppc/include/rte_memcpy.h +3 -0
index 6f388c0234..d2c3234d5d 100644
@@ -84,6 +84,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src)
 	memcpy((dst), (src), (n)) :          \
 	rte_memcpy_func((dst), (src), (n)); })
 
+__rte_nonnull(1, 2)
+__rte_access(write_only, 1, 3)
+__rte_access(read_only, 2, 3)
 static inline void *
 rte_memcpy_func(void *dst, const void *src, size_t n)
 {
lib/eal/x86/include/rte_memcpy.h +6 -0
index d4d7a5cfc8..397461115b 100644
@@ -42,6 +42,9 @@ extern "C" {
  * @return
  *   Pointer to the destination data.
  */
+__rte_nonnull(1, 2)
+__rte_access(write_only, 1, 3)
+__rte_access(read_only, 2, 3)
 static __rte_always_inline void *
 rte_memcpy(void *dst, const void *src, size_t n);
 
@@ -859,6 +862,9 @@ rte_memcpy_aligned(void *dst, const void *src, size_t n)
 	return ret;
 }
 
+__rte_nonnull(1, 2)
+__rte_access(write_only, 1, 3)
+__rte_access(read_only, 2, 3)
 static __rte_always_inline void *
 rte_memcpy(void *dst, const void *src, size_t n)
 {
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Morten Brørup

Add "nonnull" function attribute to help the compiler detect a NULL pointer being passed to a function not accepting NULL pointers as an argument at build time.

Quoted 8 lines

Add "access" function attribute to tell the optimizer how a function accesses its pointer arguments.

Add these attributes to the rte_memcpy() function, as the first in hopefully many to come.

---

thanks for providing the non-gcc expansion to empty.

#2 lore raw

PATCH v2 1/1 eal: add nonnull and access function attributes

In reply to Morten Brørup

Add "nonnull" function attribute to help the compiler detect a NULL pointer being passed to a function not accepting NULL pointers as an argument at build time.

Add "access" function attribute to tell the compiler how a function accesses its pointer arguments.

Add these attributes to the rte_memcpy() function, as the first in hopefully many to come.

v2:
* Only define "nonnull" for GCC and CLANG.
* Append _param/_params to prepare for possible future attributes attached directly to the individual parameters, like __rte_unused.
* Use RTE_TOOLCHAIN_GCC instead of RTE_CC_GCC, to fix complaints about GCC_VERSION being undefined.
* Try to fix Doxygen compliants.

---
 lib/eal/arm/include/rte_memcpy_32.h |  8 ++++++++
 lib/eal/arm/include/rte_memcpy_64.h |  6 ++++++
 lib/eal/include/rte_common.h        | 29 +++++++++++++++++++++++++++++
 lib/eal/ppc/include/rte_memcpy.h    |  3 +++
 lib/eal/x86/include/rte_memcpy.h    |  6 ++++++
 5 files changed, 52 insertions(+)
lib/eal/arm/include/rte_memcpy_32.h +8 -0
index fb3245b59c..f454c06eca 100644
@@ -14,6 +14,8 @@ extern "C" {
 
 #include "generic/rte_memcpy.h"
 
+#include <rte_common.h>
+
 #ifdef RTE_ARCH_ARM_NEON_MEMCPY
 
 #ifndef __ARM_NEON
@@ -125,6 +127,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src)
 	memcpy((dst), (src), (n)) :          \
 	rte_memcpy_func((dst), (src), (n)); })
 
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static inline void *
 rte_memcpy_func(void *dst, const void *src, size_t n)
 {
@@ -290,6 +295,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src)
 	memcpy(dst, src, 256);
 }
 
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static inline void *
 rte_memcpy(void *dst, const void *src, size_t n)
 {
lib/eal/arm/include/rte_memcpy_64.h +6 -0
index 85ad587bd3..55cbe07733 100644
@@ -282,6 +282,9 @@ void rte_memcpy_ge64(uint8_t *dst, const uint8_t *src, size_t n)
 }
 
 #if RTE_CACHE_LINE_SIZE >= 128
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static __rte_always_inline
 void *rte_memcpy(void *dst, const void *src, size_t n)
 {
@@ -303,6 +306,9 @@ void *rte_memcpy(void *dst, const void *src, size_t n)
 }
 
 #else
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static __rte_always_inline
 void *rte_memcpy(void *dst, const void *src, size_t n)
 {
lib/eal/include/rte_common.h +29 -0
index 15765b408d..6e4011aa85 100644
@@ -149,6 +149,35 @@ typedef uint16_t unaligned_uint16_t;
 	__attribute__((format(printf, format_index, first_arg)))
 #endif
 
+/**
+ * Check pointer arguments at compile-time.
+ *
+ * @param ...
+ *    Comma separated list of parameter indexes of pointer arguments.
+ */
+#if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG)
+#define __rte_nonnull_params(...) \
+	__attribute__((nonnull(__VA_ARGS__)))
+#else
+#define __rte_nonnull_params(...)
+#endif
+
+/**
+ * Tells compiler about the access mode of a pointer argument.
+ *
+ * @param access_mode
+ *    Access mode: read_only, read_write, write_only, or none.
+ * @param ...
+ *    Parameter index of pointer argument.
+ *    Optionally followeded by comma and parameter index of size argument.
+ */
+#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >= 100400)
+#define __rte_access_param(access_mode, ...) \
+	__attribute__((access(access_mode, __VA_ARGS__)))
+#else
+#define __rte_access_param(access_mode, ...)
+#endif
+
 /**
  * Tells compiler that the function returns a value that points to
  * memory, where the size is given by the one or two arguments.
lib/eal/ppc/include/rte_memcpy.h +3 -0
index 6f388c0234..59a5d86948 100644
@@ -84,6 +84,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src)
 	memcpy((dst), (src), (n)) :          \
 	rte_memcpy_func((dst), (src), (n)); })
 
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static inline void *
 rte_memcpy_func(void *dst, const void *src, size_t n)
 {
lib/eal/x86/include/rte_memcpy.h +6 -0
index d4d7a5cfc8..2e7161e4e7 100644
@@ -42,6 +42,9 @@ extern "C" {
  * @return
  *   Pointer to the destination data.
  */
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static __rte_always_inline void *
 rte_memcpy(void *dst, const void *src, size_t n);
 
@@ -859,6 +862,9 @@ rte_memcpy_aligned(void *dst, const void *src, size_t n)
 	return ret;
 }
 
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static __rte_always_inline void *
 rte_memcpy(void *dst, const void *src, size_t n)
 {
Signature · 1 line
2.17.1
Reviewed-by on v2 1/1
#3 lore raw
Quoted 27 lines

-----Original Message-----
From: Morten Brørup <[email protected]>
Sent: Saturday, December 3, 2022 10:23 PM
To: [email protected]; [email protected]
Cc: Ruifeng Wang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Morten Brørup <[email protected]>
Subject: [PATCH v2] eal: add nonnull and access function attributes

Add "nonnull" function attribute to help the compiler detect a NULL pointer being passed to a function not accepting NULL pointers as an argument at build time.

Add "access" function attribute to tell the compiler how a function accesses its pointer arguments.

Add these attributes to the rte_memcpy() function, as the first in hopefully many to come.

v2:
* Only define "nonnull" for GCC and CLANG.
* Append _param/_params to prepare for possible future attributes attached directly to the individual parameters, like __rte_unused.
* Use RTE_TOOLCHAIN_GCC instead of RTE_CC_GCC, to fix complaints about GCC_VERSION being undefined.
* Try to fix Doxygen compliants.

Quoted 8 lines

---
lib/eal/arm/include/rte_memcpy_32.h | 8 ++++++++ lib/eal/arm/include/rte_memcpy_64.h |
6 ++++++

 lib/eal/include/rte_common.h        | 29 +++++++++++++++++++++++++++++
 lib/eal/ppc/include/rte_memcpy.h    |  3 +++
 lib/eal/x86/include/rte_memcpy.h    |  6 ++++++
 5 files changed, 52 insertions(+)

Thanks and regards.

#4 lore raw
In reply to Morten Brørup
Quoted 7 lines

From: Morten Brørup [mailto:[email protected]]
Sent: Saturday, 3 December 2022 15.23

Add "nonnull" function attribute to help the compiler detect a NULL pointer being passed to a function not accepting NULL pointers as an argument at build time.

Quoted 5 lines

Add "access" function attribute to tell the compiler how a function accesses its pointer arguments.

Add these attributes to the rte_memcpy() function, as the first in hopefully many to come.

Notes about Warnings/Errors reported in Patchwork [1]:

* The checkpatch warning is about the attributes being defined. This is the purpose of the patch, and I don't know how to do it without getting a checkpatch warning.

* The errors are previously uncaught bugs elsewhere, now being caught by GCC versions >= 10.4.0 due to these new attributes. I have reported these as [Bug 1146]. It shows some actual usefulness of the attributes in this patch, and provides a good example of why we should decorate many more functions with them.

[1]: https://patchwork.dpdk.org/project/dpdk/patch/[email protected]/
[Bug 1146]: https://bugs.dpdk.org/show_bug.cgi?id=1146

Example of previously uncaught bug:

../drivers/net/bnx2x/bnx2x_vfpf.c: In function ‘bnx2x_check_bull’:
../drivers/net/bnx2x/bnx2x_vfpf.c:57:17: error: ‘rte_memcpy’ writing 4 bytes into a region of size 2 overflows the destination [-Werror=stringop-overflow=]

   57 |                 rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, RTE_VLAN_HLEN);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../drivers/net/bnx2x/bnx2x.h:29,
                 from ../drivers/net/bnx2x/bnx2x_vfpf.c:8:

../drivers/net/bnx2x/bnx2x_vfpf.h:297:18: note: destination object ‘vlan’ of size 2
297 | uint16_t vlan;
| ^~~~
../drivers/net/bnx2x/bnx2x_vfpf.c:57:17: error: ‘rte_memcpy’ reading 4 bytes from a region of size 2 [-Werror=stringop-overread]

   57 |                 rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, RTE_VLAN_HLEN);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../drivers/net/bnx2x/bnx2x_vfpf.h:297:18: note: source object ‘vlan’ of size 2
297 | uint16_t vlan;
| ^~~~
In file included from ../lib/mempool/rte_mempool.h:48,

                 from ../lib/mbuf/rte_mbuf.h:38,
                 from ../lib/net/rte_ether.h:22,
                 from ../lib/ethdev/rte_eth_ctrl.h:10,
                 from ../lib/ethdev/rte_ethdev.h:1419,
                 from ../lib/ethdev/ethdev_driver.h:24,
                 from ../drivers/net/bnx2x/bnx2x_ethdev.h:34,
                 from ../drivers/net/bnx2x/bnx2x.h:23:
../lib/eal/x86/include/rte_memcpy.h:869:1: note: in a call to function ‘rte_memcpy’ declared with attribute ‘access (read_only, 2, 3)’
  869 | rte_memcpy(void *dst, const void *src, size_t n)
      | ^~~~~~~~~~
#5 lore raw

PATCH v3 1/2 eal: add nonnull and access function attributes

In reply to Morten Brørup

Add "nonnull" function attribute to help the compiler detect a NULL pointer being passed to a function not accepting NULL pointers as an argument at build time.

Add "access" function attribute to tell the compiler how a function accesses its pointer arguments.

Add these attributes to the rte_memcpy() function, as the first in hopefully many to come.

v3:
* No changes.
v2:
* Only define "nonnull" for GCC and CLANG.
* Append _param/_params to prepare for possible future attributes attached directly to the individual parameters, like __rte_unused.
* Use RTE_TOOLCHAIN_GCC instead of RTE_CC_GCC, to fix complaints about GCC_VERSION being undefined.
* Try to fix Doxygen compliants.

---
 lib/eal/arm/include/rte_memcpy_32.h |  8 ++++++++
 lib/eal/arm/include/rte_memcpy_64.h |  6 ++++++
 lib/eal/include/rte_common.h        | 29 +++++++++++++++++++++++++++++
 lib/eal/ppc/include/rte_memcpy.h    |  3 +++
 lib/eal/x86/include/rte_memcpy.h    |  6 ++++++
 5 files changed, 52 insertions(+)
lib/eal/arm/include/rte_memcpy_32.h +8 -0
index fb3245b59c..f454c06eca 100644
@@ -14,6 +14,8 @@ extern "C" {
 
 #include "generic/rte_memcpy.h"
 
+#include <rte_common.h>
+
 #ifdef RTE_ARCH_ARM_NEON_MEMCPY
 
 #ifndef __ARM_NEON
@@ -125,6 +127,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src)
 	memcpy((dst), (src), (n)) :          \
 	rte_memcpy_func((dst), (src), (n)); })
 
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static inline void *
 rte_memcpy_func(void *dst, const void *src, size_t n)
 {
@@ -290,6 +295,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src)
 	memcpy(dst, src, 256);
 }
 
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static inline void *
 rte_memcpy(void *dst, const void *src, size_t n)
 {
lib/eal/arm/include/rte_memcpy_64.h +6 -0
index 85ad587bd3..55cbe07733 100644
@@ -282,6 +282,9 @@ void rte_memcpy_ge64(uint8_t *dst, const uint8_t *src, size_t n)
 }
 
 #if RTE_CACHE_LINE_SIZE >= 128
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static __rte_always_inline
 void *rte_memcpy(void *dst, const void *src, size_t n)
 {
@@ -303,6 +306,9 @@ void *rte_memcpy(void *dst, const void *src, size_t n)
 }
 
 #else
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static __rte_always_inline
 void *rte_memcpy(void *dst, const void *src, size_t n)
 {
lib/eal/include/rte_common.h +29 -0
index 15765b408d..6e4011aa85 100644
@@ -149,6 +149,35 @@ typedef uint16_t unaligned_uint16_t;
 	__attribute__((format(printf, format_index, first_arg)))
 #endif
 
+/**
+ * Check pointer arguments at compile-time.
+ *
+ * @param ...
+ *    Comma separated list of parameter indexes of pointer arguments.
+ */
+#if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG)
+#define __rte_nonnull_params(...) \
+	__attribute__((nonnull(__VA_ARGS__)))
+#else
+#define __rte_nonnull_params(...)
+#endif
+
+/**
+ * Tells compiler about the access mode of a pointer argument.
+ *
+ * @param access_mode
+ *    Access mode: read_only, read_write, write_only, or none.
+ * @param ...
+ *    Parameter index of pointer argument.
+ *    Optionally followeded by comma and parameter index of size argument.
+ */
+#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >= 100400)
+#define __rte_access_param(access_mode, ...) \
+	__attribute__((access(access_mode, __VA_ARGS__)))
+#else
+#define __rte_access_param(access_mode, ...)
+#endif
+
 /**
  * Tells compiler that the function returns a value that points to
  * memory, where the size is given by the one or two arguments.
lib/eal/ppc/include/rte_memcpy.h +3 -0
index 6f388c0234..59a5d86948 100644
@@ -84,6 +84,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src)
 	memcpy((dst), (src), (n)) :          \
 	rte_memcpy_func((dst), (src), (n)); })
 
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static inline void *
 rte_memcpy_func(void *dst, const void *src, size_t n)
 {
lib/eal/x86/include/rte_memcpy.h +6 -0
index d4d7a5cfc8..2e7161e4e7 100644
@@ -42,6 +42,9 @@ extern "C" {
  * @return
  *   Pointer to the destination data.
  */
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static __rte_always_inline void *
 rte_memcpy(void *dst, const void *src, size_t n);
 
@@ -859,6 +862,9 @@ rte_memcpy_aligned(void *dst, const void *src, size_t n)
 	return ret;
 }
 
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static __rte_always_inline void *
 rte_memcpy(void *dst, const void *src, size_t n)
 {
Signature · 1 line
2.17.1
#6 lore raw

PATCH v3 2/2 net/bnx2x: fix warnings about rte_memcopy lengths

Bugfix: The vlan in the bulletin does not contain a VLAN header, only the VLAN ID, so only copy 2 byte, not 4. The target structure has padding after the field, so copying 2 byte too many is effectively harmless. There is no need to backport this patch.

Added type casts where copying arrays to the offset of a first field in a structure holding multiple fields, to avoid compiler warnings.

Bugzilla ID: 1146

v3:
* First patch in series.

---
 drivers/net/bnx2x/bnx2x_stats.c | 6 +++---
 drivers/net/bnx2x/bnx2x_vfpf.c  | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/net/bnx2x/bnx2x_stats.c +3 -3
index c07b01510a..a5a7aa3b40 100644
@@ -819,7 +819,7 @@ bnx2x_hw_stats_update(struct bnx2x_softc *sc)
 
     rte_memcpy(old, new, sizeof(struct nig_stats));
 
-    rte_memcpy(&(estats->rx_stat_ifhcinbadoctets_hi), &(pstats->mac_stx[1]),
+    rte_memcpy((struct mac_stx *)&(estats->rx_stat_ifhcinbadoctets_hi), &(pstats->mac_stx[1]),
 	   sizeof(struct mac_stx));
     estats->brb_drop_hi = pstats->brb_drop_hi;
     estats->brb_drop_lo = pstats->brb_drop_lo;
@@ -1492,9 +1492,9 @@ bnx2x_stats_init(struct bnx2x_softc *sc)
 		REG_RD(sc, NIG_REG_STAT0_BRB_TRUNCATE + port*0x38);
 	if (!CHIP_IS_E3(sc)) {
 		REG_RD_DMAE(sc, NIG_REG_STAT0_EGRESS_MAC_PKT0 + port*0x50,
-				&(sc->port.old_nig_stats.egress_mac_pkt0_lo), 2);
+				(uint32_t *)&(sc->port.old_nig_stats.egress_mac_pkt0_lo), 2);
 		REG_RD_DMAE(sc, NIG_REG_STAT0_EGRESS_MAC_PKT1 + port*0x50,
-				&(sc->port.old_nig_stats.egress_mac_pkt1_lo), 2);
+				(uint32_t *)&(sc->port.old_nig_stats.egress_mac_pkt1_lo), 2);
 	}
 
 	/* function stats */
drivers/net/bnx2x/bnx2x_vfpf.c +1 -1
index 63953c2979..87631c76ca 100644
@@ -54,7 +54,7 @@ bnx2x_check_bull(struct bnx2x_softc *sc)
 	if (valid_bitmap & (1 << MAC_ADDR_VALID) && memcmp(bull->mac, sc->old_bulletin.mac, ETH_ALEN))
 		rte_memcpy(&sc->link_params.mac_addr, bull->mac, ETH_ALEN);
 	if (valid_bitmap & (1 << VLAN_VALID))
-		rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, RTE_VLAN_HLEN);
+		rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, sizeof(bull->vlan));
 
 	sc->old_bulletin = *bull;
 
Signature · 1 line
2.17.1
#7 lore raw

PATCH v4 1/2 eal: add nonnull and access function attributes

In reply to Morten Brørup

Add "nonnull" function attribute to help the compiler detect a NULL pointer being passed to a function not accepting NULL pointers as an argument at build time.

Add "access" function attribute to tell the compiler how a function accesses its pointer arguments.

Add these attributes to the rte_memcpy() function, as the first in hopefully many to come.

v4:
* No changes.
v3:
* No changes.
v2:
* Only define "nonnull" for GCC and CLANG.
* Append _param/_params to prepare for possible future attributes attached directly to the individual parameters, like __rte_unused.
* Use RTE_TOOLCHAIN_GCC instead of RTE_CC_GCC, to fix complaints about GCC_VERSION being undefined.
* Try to fix Doxygen compliants.

---
 lib/eal/arm/include/rte_memcpy_32.h |  8 ++++++++
 lib/eal/arm/include/rte_memcpy_64.h |  6 ++++++
 lib/eal/include/rte_common.h        | 29 +++++++++++++++++++++++++++++
 lib/eal/ppc/include/rte_memcpy.h    |  3 +++
 lib/eal/x86/include/rte_memcpy.h    |  6 ++++++
 5 files changed, 52 insertions(+)
lib/eal/arm/include/rte_memcpy_32.h +8 -0
index fb3245b59c..f454c06eca 100644
@@ -14,6 +14,8 @@ extern "C" {
 
 #include "generic/rte_memcpy.h"
 
+#include <rte_common.h>
+
 #ifdef RTE_ARCH_ARM_NEON_MEMCPY
 
 #ifndef __ARM_NEON
@@ -125,6 +127,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src)
 	memcpy((dst), (src), (n)) :          \
 	rte_memcpy_func((dst), (src), (n)); })
 
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static inline void *
 rte_memcpy_func(void *dst, const void *src, size_t n)
 {
@@ -290,6 +295,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src)
 	memcpy(dst, src, 256);
 }
 
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static inline void *
 rte_memcpy(void *dst, const void *src, size_t n)
 {
lib/eal/arm/include/rte_memcpy_64.h +6 -0
index 85ad587bd3..55cbe07733 100644
@@ -282,6 +282,9 @@ void rte_memcpy_ge64(uint8_t *dst, const uint8_t *src, size_t n)
 }
 
 #if RTE_CACHE_LINE_SIZE >= 128
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static __rte_always_inline
 void *rte_memcpy(void *dst, const void *src, size_t n)
 {
@@ -303,6 +306,9 @@ void *rte_memcpy(void *dst, const void *src, size_t n)
 }
 
 #else
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static __rte_always_inline
 void *rte_memcpy(void *dst, const void *src, size_t n)
 {
lib/eal/include/rte_common.h +29 -0
index 15765b408d..6e4011aa85 100644
@@ -149,6 +149,35 @@ typedef uint16_t unaligned_uint16_t;
 	__attribute__((format(printf, format_index, first_arg)))
 #endif
 
+/**
+ * Check pointer arguments at compile-time.
+ *
+ * @param ...
+ *    Comma separated list of parameter indexes of pointer arguments.
+ */
+#if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG)
+#define __rte_nonnull_params(...) \
+	__attribute__((nonnull(__VA_ARGS__)))
+#else
+#define __rte_nonnull_params(...)
+#endif
+
+/**
+ * Tells compiler about the access mode of a pointer argument.
+ *
+ * @param access_mode
+ *    Access mode: read_only, read_write, write_only, or none.
+ * @param ...
+ *    Parameter index of pointer argument.
+ *    Optionally followeded by comma and parameter index of size argument.
+ */
+#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >= 100400)
+#define __rte_access_param(access_mode, ...) \
+	__attribute__((access(access_mode, __VA_ARGS__)))
+#else
+#define __rte_access_param(access_mode, ...)
+#endif
+
 /**
  * Tells compiler that the function returns a value that points to
  * memory, where the size is given by the one or two arguments.
lib/eal/ppc/include/rte_memcpy.h +3 -0
index 6f388c0234..59a5d86948 100644
@@ -84,6 +84,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src)
 	memcpy((dst), (src), (n)) :          \
 	rte_memcpy_func((dst), (src), (n)); })
 
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static inline void *
 rte_memcpy_func(void *dst, const void *src, size_t n)
 {
lib/eal/x86/include/rte_memcpy.h +6 -0
index d4d7a5cfc8..2e7161e4e7 100644
@@ -42,6 +42,9 @@ extern "C" {
  * @return
  *   Pointer to the destination data.
  */
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static __rte_always_inline void *
 rte_memcpy(void *dst, const void *src, size_t n);
 
@@ -859,6 +862,9 @@ rte_memcpy_aligned(void *dst, const void *src, size_t n)
 	return ret;
 }
 
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static __rte_always_inline void *
 rte_memcpy(void *dst, const void *src, size_t n)
 {
Signature · 1 line
2.17.1
#8 lore raw

PATCH v4 2/2 net/bnx2x: fix warnings about rte_memcpy lengths

Bugfix: The vlan in the bulletin does not contain a VLAN header, only the VLAN ID, so only copy 2 byte, not 4. The target structure has padding after the field, so copying 2 byte too many is effectively harmless. There is no need to backport this patch.

Added type casts where copying arrays to the offset of a first field in a structure holding multiple fields, to avoid compiler warnings.

Bugzilla ID: 1146

v4:
* Type casting did not fix the warnings, so use RTE_PTR_ADD instead. v3:
* First patch in series.

---
 drivers/net/bnx2x/bnx2x_stats.c | 11 +++++++----
 drivers/net/bnx2x/bnx2x_vfpf.c  |  2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/net/bnx2x/bnx2x_stats.c +7 -4
index c07b01510a..1c44504663 100644
@@ -819,8 +819,9 @@ bnx2x_hw_stats_update(struct bnx2x_softc *sc)
 
     rte_memcpy(old, new, sizeof(struct nig_stats));
 
-    rte_memcpy(&(estats->rx_stat_ifhcinbadoctets_hi), &(pstats->mac_stx[1]),
-	   sizeof(struct mac_stx));
+    rte_memcpy(RTE_PTR_ADD(estats,
+	   offsetof(struct bnx2x_eth_stats, rx_stat_ifhcinbadoctets_hi)),
+	   &(pstats->mac_stx[1]), sizeof(struct mac_stx));
     estats->brb_drop_hi = pstats->brb_drop_hi;
     estats->brb_drop_lo = pstats->brb_drop_lo;
 
@@ -1492,9 +1493,11 @@ bnx2x_stats_init(struct bnx2x_softc *sc)
 		REG_RD(sc, NIG_REG_STAT0_BRB_TRUNCATE + port*0x38);
 	if (!CHIP_IS_E3(sc)) {
 		REG_RD_DMAE(sc, NIG_REG_STAT0_EGRESS_MAC_PKT0 + port*0x50,
-				&(sc->port.old_nig_stats.egress_mac_pkt0_lo), 2);
+				RTE_PTR_ADD(&(sc->port.old_nig_stats),
+				offsetof(struct nig_stats, egress_mac_pkt0_lo)), 2);
 		REG_RD_DMAE(sc, NIG_REG_STAT0_EGRESS_MAC_PKT1 + port*0x50,
-				&(sc->port.old_nig_stats.egress_mac_pkt1_lo), 2);
+				RTE_PTR_ADD(&(sc->port.old_nig_stats),
+				offsetof(struct nig_stats, egress_mac_pkt1_lo)), 2);
 	}
 
 	/* function stats */
drivers/net/bnx2x/bnx2x_vfpf.c +1 -1
index 63953c2979..87631c76ca 100644
@@ -54,7 +54,7 @@ bnx2x_check_bull(struct bnx2x_softc *sc)
 	if (valid_bitmap & (1 << MAC_ADDR_VALID) && memcmp(bull->mac, sc->old_bulletin.mac, ETH_ALEN))
 		rte_memcpy(&sc->link_params.mac_addr, bull->mac, ETH_ALEN);
 	if (valid_bitmap & (1 << VLAN_VALID))
-		rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, RTE_VLAN_HLEN);
+		rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, sizeof(bull->vlan));
 
 	sc->old_bulletin = *bull;
 
Signature · 1 line
2.17.1
#9 lore raw

PATCH v5 1/4 eal: add nonnull and access function attributes

In reply to Morten Brørup

Add "nonnull" function attribute to help the compiler detect a NULL pointer being passed to a function not accepting NULL pointers as an argument at build time.

Add "access" function attribute to tell the compiler how a function accesses its pointer arguments.

Add these attributes to the rte_memcpy() function, as the first in hopefully many to come.

v5:
* No changes.
v4:
* No changes.
v3:
* No changes.
v2:
* Only define "nonnull" for GCC and CLANG.
* Append _param/_params to prepare for possible future attributes attached directly to the individual parameters, like __rte_unused.
* Use RTE_TOOLCHAIN_GCC instead of RTE_CC_GCC, to fix complaints about GCC_VERSION being undefined.
* Try to fix Doxygen compliants.

---
 lib/eal/arm/include/rte_memcpy_32.h |  8 ++++++++
 lib/eal/arm/include/rte_memcpy_64.h |  6 ++++++
 lib/eal/include/rte_common.h        | 29 +++++++++++++++++++++++++++++
 lib/eal/ppc/include/rte_memcpy.h    |  3 +++
 lib/eal/x86/include/rte_memcpy.h    |  6 ++++++
 5 files changed, 52 insertions(+)
lib/eal/arm/include/rte_memcpy_32.h +8 -0
index fb3245b59c..f454c06eca 100644
@@ -14,6 +14,8 @@ extern "C" {
 
 #include "generic/rte_memcpy.h"
 
+#include <rte_common.h>
+
 #ifdef RTE_ARCH_ARM_NEON_MEMCPY
 
 #ifndef __ARM_NEON
@@ -125,6 +127,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src)
 	memcpy((dst), (src), (n)) :          \
 	rte_memcpy_func((dst), (src), (n)); })
 
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static inline void *
 rte_memcpy_func(void *dst, const void *src, size_t n)
 {
@@ -290,6 +295,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src)
 	memcpy(dst, src, 256);
 }
 
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static inline void *
 rte_memcpy(void *dst, const void *src, size_t n)
 {
lib/eal/arm/include/rte_memcpy_64.h +6 -0
index 85ad587bd3..55cbe07733 100644
@@ -282,6 +282,9 @@ void rte_memcpy_ge64(uint8_t *dst, const uint8_t *src, size_t n)
 }
 
 #if RTE_CACHE_LINE_SIZE >= 128
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static __rte_always_inline
 void *rte_memcpy(void *dst, const void *src, size_t n)
 {
@@ -303,6 +306,9 @@ void *rte_memcpy(void *dst, const void *src, size_t n)
 }
 
 #else
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static __rte_always_inline
 void *rte_memcpy(void *dst, const void *src, size_t n)
 {
lib/eal/include/rte_common.h +29 -0
index 15765b408d..6e4011aa85 100644
@@ -149,6 +149,35 @@ typedef uint16_t unaligned_uint16_t;
 	__attribute__((format(printf, format_index, first_arg)))
 #endif
 
+/**
+ * Check pointer arguments at compile-time.
+ *
+ * @param ...
+ *    Comma separated list of parameter indexes of pointer arguments.
+ */
+#if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG)
+#define __rte_nonnull_params(...) \
+	__attribute__((nonnull(__VA_ARGS__)))
+#else
+#define __rte_nonnull_params(...)
+#endif
+
+/**
+ * Tells compiler about the access mode of a pointer argument.
+ *
+ * @param access_mode
+ *    Access mode: read_only, read_write, write_only, or none.
+ * @param ...
+ *    Parameter index of pointer argument.
+ *    Optionally followeded by comma and parameter index of size argument.
+ */
+#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >= 100400)
+#define __rte_access_param(access_mode, ...) \
+	__attribute__((access(access_mode, __VA_ARGS__)))
+#else
+#define __rte_access_param(access_mode, ...)
+#endif
+
 /**
  * Tells compiler that the function returns a value that points to
  * memory, where the size is given by the one or two arguments.
lib/eal/ppc/include/rte_memcpy.h +3 -0
index 6f388c0234..59a5d86948 100644
@@ -84,6 +84,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src)
 	memcpy((dst), (src), (n)) :          \
 	rte_memcpy_func((dst), (src), (n)); })
 
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static inline void *
 rte_memcpy_func(void *dst, const void *src, size_t n)
 {
lib/eal/x86/include/rte_memcpy.h +6 -0
index d4d7a5cfc8..2e7161e4e7 100644
@@ -42,6 +42,9 @@ extern "C" {
  * @return
  *   Pointer to the destination data.
  */
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static __rte_always_inline void *
 rte_memcpy(void *dst, const void *src, size_t n);
 
@@ -859,6 +862,9 @@ rte_memcpy_aligned(void *dst, const void *src, size_t n)
 	return ret;
 }
 
+__rte_nonnull_params(1, 2)
+__rte_access_param(write_only, 1, 3)
+__rte_access_param(read_only, 2, 3)
 static __rte_always_inline void *
 rte_memcpy(void *dst, const void *src, size_t n)
 {
Signature · 1 line
2.17.1
#10 lore raw

PATCH v5 2/4 net/bnx2x: fix warnings about rte_memcpy lengths

Bugfix: The vlan in the bulletin does not contain a VLAN header, only the VLAN ID, so only copy 2 byte, not 4. The target structure has padding after the field, so copying 2 byte too many is effectively harmless. There is no need to backport this patch.

Use RTE_PTR_ADD where copying arrays to the offset of a first field in a structure holding multiple fields, to avoid compiler warnings.

Bugzilla ID: 1146

v5:
* No changes.
v4:
* Type casting did not fix the warnings, so use RTE_PTR_ADD instead. v3:
* First patch in series.

---
 drivers/net/bnx2x/bnx2x_stats.c | 11 +++++++----
 drivers/net/bnx2x/bnx2x_vfpf.c  |  2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/net/bnx2x/bnx2x_stats.c +7 -4
index c07b01510a..1c44504663 100644
@@ -819,8 +819,9 @@ bnx2x_hw_stats_update(struct bnx2x_softc *sc)
 
     rte_memcpy(old, new, sizeof(struct nig_stats));
 
-    rte_memcpy(&(estats->rx_stat_ifhcinbadoctets_hi), &(pstats->mac_stx[1]),
-	   sizeof(struct mac_stx));
+    rte_memcpy(RTE_PTR_ADD(estats,
+	   offsetof(struct bnx2x_eth_stats, rx_stat_ifhcinbadoctets_hi)),
+	   &(pstats->mac_stx[1]), sizeof(struct mac_stx));
     estats->brb_drop_hi = pstats->brb_drop_hi;
     estats->brb_drop_lo = pstats->brb_drop_lo;
 
@@ -1492,9 +1493,11 @@ bnx2x_stats_init(struct bnx2x_softc *sc)
 		REG_RD(sc, NIG_REG_STAT0_BRB_TRUNCATE + port*0x38);
 	if (!CHIP_IS_E3(sc)) {
 		REG_RD_DMAE(sc, NIG_REG_STAT0_EGRESS_MAC_PKT0 + port*0x50,
-				&(sc->port.old_nig_stats.egress_mac_pkt0_lo), 2);
+				RTE_PTR_ADD(&(sc->port.old_nig_stats),
+				offsetof(struct nig_stats, egress_mac_pkt0_lo)), 2);
 		REG_RD_DMAE(sc, NIG_REG_STAT0_EGRESS_MAC_PKT1 + port*0x50,
-				&(sc->port.old_nig_stats.egress_mac_pkt1_lo), 2);
+				RTE_PTR_ADD(&(sc->port.old_nig_stats),
+				offsetof(struct nig_stats, egress_mac_pkt1_lo)), 2);
 	}
 
 	/* function stats */
drivers/net/bnx2x/bnx2x_vfpf.c +1 -1
index 63953c2979..87631c76ca 100644
@@ -54,7 +54,7 @@ bnx2x_check_bull(struct bnx2x_softc *sc)
 	if (valid_bitmap & (1 << MAC_ADDR_VALID) && memcmp(bull->mac, sc->old_bulletin.mac, ETH_ALEN))
 		rte_memcpy(&sc->link_params.mac_addr, bull->mac, ETH_ALEN);
 	if (valid_bitmap & (1 << VLAN_VALID))
-		rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, RTE_VLAN_HLEN);
+		rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, sizeof(bull->vlan));
 
 	sc->old_bulletin = *bull;
 
Signature · 1 line
2.17.1
#11 lore raw

Re: [PATCH v5 2/4] net/bnx2x: fix warnings about rte_memcpy lengths

Quoted 4 lines · On Wed, Dec 28, 2022, 16:10 Morten Brørup <[email protected]> wrote:

Bugfix: The vlan in the bulletin does not contain a VLAN header, only the VLAN ID, so only copy 2 byte, not 4. The target structure has padding after the field, so copying 2 byte too many is effectively harmless.

It is a small nitpick but why use rte_memcpy for a 2 byte / half-word copy? Shouldn't assignment with casts be enough?

Quoted 77 lines

There is no need to backport this patch.

Use RTE_PTR_ADD where copying arrays to the offset of a first field in a structure holding multiple fields, to avoid compiler warnings.

Bugzilla ID: 1146

v5:
* No changes.
v4:
* Type casting did not fix the warnings, so use RTE_PTR_ADD instead. v3:
* First patch in series.

---
 drivers/net/bnx2x/bnx2x_stats.c | 11 +++++++----
 drivers/net/bnx2x/bnx2x_vfpf.c  |  2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/net/bnx2x/bnx2x_stats.c +7 -4
index c07b01510a..1c44504663 100644
@@ -819,8 +819,9 @@ bnx2x_hw_stats_update(struct bnx2x_softc *sc)
 
     rte_memcpy(old, new, sizeof(struct nig_stats));
 
-    rte_memcpy(&(estats->rx_stat_ifhcinbadoctets_hi),
 &(pstats->mac_stx[1]),
-          sizeof(struct mac_stx));
+    rte_memcpy(RTE_PTR_ADD(estats,
+          offsetof(struct bnx2x_eth_stats, rx_stat_ifhcinbadoctets_hi)),
+          &(pstats->mac_stx[1]), sizeof(struct mac_stx));
     estats->brb_drop_hi = pstats->brb_drop_hi;
     estats->brb_drop_lo = pstats->brb_drop_lo;
@@ -1492,9 +1493,11 @@ bnx2x_stats_init(struct bnx2x_softc *sc)
                REG_RD(sc, NIG_REG_STAT0_BRB_TRUNCATE + port*0x38);
        if (!CHIP_IS_E3(sc)) {
                REG_RD_DMAE(sc, NIG_REG_STAT0_EGRESS_MAC_PKT0 + port*0x50,
-
 &(sc->port.old_nig_stats.egress_mac_pkt0_lo), 2);
+                               RTE_PTR_ADD(&(sc->port.old_nig_stats),
+                               offsetof(struct nig_stats,
 egress_mac_pkt0_lo)), 2);
                REG_RD_DMAE(sc, NIG_REG_STAT0_EGRESS_MAC_PKT1 + port*0x50,
-
 &(sc->port.old_nig_stats.egress_mac_pkt1_lo), 2);
+                               RTE_PTR_ADD(&(sc->port.old_nig_stats),
+                               offsetof(struct nig_stats,
egress_mac_pkt1_lo)), 2);
        }

        /* function stats */
drivers/net/bnx2x/bnx2x_vfpf.c +1 -1
index 63953c2979..87631c76ca 100644
@@ -54,7 +54,7 @@ bnx2x_check_bull(struct bnx2x_softc *sc)
        if (valid_bitmap & (1 << MAC_ADDR_VALID) && memcmp(bull->mac,
 sc->old_bulletin.mac, ETH_ALEN))
                rte_memcpy(&sc->link_params.mac_addr, bull->mac, ETH_ALEN);
        if (valid_bitmap & (1 << VLAN_VALID))
-               rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan,
 RTE_VLAN_HLEN);
+               rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan,
 sizeof(bull->vlan));
        sc->old_bulletin = *bull;

--
2.17.1

#12 lore raw

RE: [PATCH v5 2/4] net/bnx2x: fix warnings about rte_memcpy lengths

From: Stanisław Kardach [mailto:[email protected]]
Sent: Wednesday, 28 December 2022 17.14

Quoted 5 lines · On Wed, Dec 28, 2022, 16:10 Morten Brørup <[email protected]> wrote:
Quoted 3 lines

Bugfix: The vlan in the bulletin does not contain a VLAN header, only the VLAN ID, so only copy 2 byte, not 4. The target structure has padding after the field, so copying 2 byte too many is effectively harmless.

It is a small nitpick but why use rte_memcpy for a 2 byte / half-word copy? Shouldn't assignment with casts be enough?

Absolutely. It would also have prevented the bug to begin with. But in order to keep the changes minimal, I kept the rte_memcpy().

Quoted 49 lines
Quoted 49 lines

There is no need to backport this patch.

Use RTE_PTR_ADD where copying arrays to the offset of a first field in a structure holding multiple fields, to avoid compiler warnings.

Bugzilla ID: 1146

v5:
* No changes.
v4:
* Type casting did not fix the warnings, so use RTE_PTR_ADD instead. v3:
* First patch in series.

---
 drivers/net/bnx2x/bnx2x_stats.c | 11 +++++++----
 drivers/net/bnx2x/bnx2x_vfpf.c  |  2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/net/bnx2x/bnx2x_stats.c +7 -4
index c07b01510a..1c44504663 100644
@@ -819,8 +819,9 @@ bnx2x_hw_stats_update(struct bnx2x_softc *sc)
 
     rte_memcpy(old, new, sizeof(struct nig_stats));
 
-    rte_memcpy(&(estats->rx_stat_ifhcinbadoctets_hi), &(pstats->mac_stx[1]),
-          sizeof(struct mac_stx));
+    rte_memcpy(RTE_PTR_ADD(estats,
+          offsetof(struct bnx2x_eth_stats, rx_stat_ifhcinbadoctets_hi)),
+          &(pstats->mac_stx[1]), sizeof(struct mac_stx));
     estats->brb_drop_hi = pstats->brb_drop_hi;
     estats->brb_drop_lo = pstats->brb_drop_lo;
 
@@ -1492,9 +1493,11 @@ bnx2x_stats_init(struct bnx2x_softc *sc)
                REG_RD(sc, NIG_REG_STAT0_BRB_TRUNCATE + port*0x38);
        if (!CHIP_IS_E3(sc)) {
                REG_RD_DMAE(sc, NIG_REG_STAT0_EGRESS_MAC_PKT0 + port*0x50,
-                               &(sc->port.old_nig_stats.egress_mac_pkt0_lo), 2);
+                               RTE_PTR_ADD(&(sc->port.old_nig_stats),
+                               offsetof(struct nig_stats, egress_mac_pkt0_lo)), 2);
                REG_RD_DMAE(sc, NIG_REG_STAT0_EGRESS_MAC_PKT1 + port*0x50,
-                               &(sc->port.old_nig_stats.egress_mac_pkt1_lo), 2);
+                               RTE_PTR_ADD(&(sc->port.old_nig_stats),
+                               offsetof(struct nig_stats, egress_mac_pkt1_lo)), 2);
        }
 
Quoted 11 lines

drivers/net/bnx2x/bnx2x_vfpf.c bnx2x_check_bull(struct bnx2x_softc *sc) · line 57

Quoted 11 lines
drivers/net/bnx2x/bnx2x_stats.c +0 -0
        /* function stats */
drivers/net/bnx2x/bnx2x_vfpf.c +1 -1
index 63953c2979..87631c76ca 100644
@@ -54,7 +54,7 @@ bnx2x_check_bull(struct bnx2x_softc *sc)
        if (valid_bitmap & (1 << MAC_ADDR_VALID) && memcmp(bull->mac, sc->old_bulletin.mac, ETH_ALEN))
                rte_memcpy(&sc->link_params.mac_addr, bull->mac, ETH_ALEN);
        if (valid_bitmap & (1 << VLAN_VALID))
-               rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, RTE_VLAN_HLEN);
+               rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, sizeof(bull->vlan));

As Stanisław mentioned, this might as well be:

        if (valid_bitmap & (1 << VLAN_VALID))

- rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, RTE_VLAN_HLEN);
+ bull->vlan = sc->old_bulletin.vlan;

Quoted 5 lines
Quoted 5 lines
drivers/net/bnx2x/bnx2x_vfpf.c +0 -0
        sc->old_bulletin = *bull;
 
Signature · 1 line
2.17.1
#13 lore raw

Re: [PATCH v5 2/4] net/bnx2x: fix warnings about rte_memcpy lengths

Quoted 10 lines · On Wed, 28 Dec 2022 17:38:56 +0100 Morten Brørup <[email protected]>…

From: Stanisław Kardach [mailto:[email protected]]
Sent: Wednesday, 28 December 2022 17.14

Quoted 5 lines · On Wed, Dec 28, 2022, 16:10 Morten Brørup <[email protected]> wrote:
Quoted 3 lines

Bugfix: The vlan in the bulletin does not contain a VLAN header, only the VLAN ID, so only copy 2 byte, not 4. The target structure has padding after the field, so copying 2 byte too many is effectively harmless.

It is a small nitpick but why use rte_memcpy for a 2 byte / half-word copy? Shouldn't assignment with casts be enough?

Absolutely. It would also have prevented the bug to begin with. But in order to keep the changes minimal, I kept the rte_memcpy().

For small fixed values compiler can optimize memcpy into one instruction. Not so with current rte_memcpy

#14 lore raw

RE: [PATCH v5 2/4] net/bnx2x: fix warnings about rte_memcpy lengths

Quoted 17 lines

From: Stephen Hemminger [mailto:[email protected]]
Sent: Wednesday, 28 December 2022 18.03

Quoted 3 lines · On Wed, 28 Dec 2022 17:38:56 +0100 Morten Brørup <[email protected]>…

From: Stanisław Kardach [mailto:[email protected]]
Sent: Wednesday, 28 December 2022 17.14

Quoted 1 line

On Wed, Dec 28, 2022, 16:10 Morten Brørup

Quoted 1 line · <[email protected]> wrote:
Quoted 1 line
Quoted 1 line

Bugfix: The vlan in the bulletin does not contain a VLAN header,

only the

Quoted 1 line
Quoted 1 line
Quoted 1 line

VLAN ID, so only copy 2 byte, not 4. The target structure has

padding

Quoted 1 line
Quoted 1 line
Quoted 1 line

after the field, so copying 2 byte too many is effectively

harmless.

Quoted 1 line
Quoted 1 line

It is a small nitpick but why use rte_memcpy for a 2 byte / half-

Quoted 8 lines

word copy? Shouldn't assignment with casts be enough?

Quoted 3 lines

Absolutely. It would also have prevented the bug to begin with. But in order to keep the changes minimal, I kept the rte_memcpy().

For small fixed values compiler can optimize memcpy into one instruction.
Not so with current rte_memcpy

Good point, Stephen.

I took another look at it, and the two byte rte_memcpy() is only used in a slow path function, so no need to optimize further.

If the maintainers disagree, and want to optimize anyway, here's a proposal:

/* check the mac address and VLAN and allocate memory if valid */ if (valid_bitmap & (1 << MAC_ADDR_VALID) && !rte_is_same_ether_addr(

		(const struct rte_ether_addr *)&bull->mac,
		(const struct rte_ether_addr *)&sc->old_bulletin.mac))
	rte_ether_addr_copy((const struct rte_ether_addr *)&bull->mac,
			(struct rte_ether_addr *)&sc->link_params.mac_addr);
if (valid_bitmap & (1 << VLAN_VALID))
	bull->vlan = sc->old_bulletin.vlan;
#15 lore raw

Re: [PATCH v5 2/4] net/bnx2x: fix warnings about rte_memcpy lengths

Hello bnx2x maintainers,

Quoted 33 lines · Morten Brørup
Quoted 18 lines

From: Stephen Hemminger [mailto:[email protected]]
Sent: Wednesday, 28 December 2022 18.03

Quoted 3 lines · On Wed, 28 Dec 2022 17:38:56 +0100 Morten Brørup <[email protected]>…

From: Stanisław Kardach [mailto:[email protected]]
Sent: Wednesday, 28 December 2022 17.14

Quoted 1 line

On Wed, Dec 28, 2022, 16:10 Morten Brørup

Quoted 1 line · <[email protected]> wrote:
Quoted 1 line
Quoted 1 line

Bugfix: The vlan in the bulletin does not contain a VLAN header,

only the

Quoted 1 line
Quoted 1 line
Quoted 1 line

VLAN ID, so only copy 2 byte, not 4. The target structure has

padding

Quoted 1 line
Quoted 1 line
Quoted 1 line

after the field, so copying 2 byte too many is effectively

harmless.

Quoted 1 line
Quoted 1 line

It is a small nitpick but why use rte_memcpy for a 2 byte / half-

Quoted 8 lines

word copy? Shouldn't assignment with casts be enough?

Quoted 3 lines

Absolutely. It would also have prevented the bug to begin with. But in order to keep the changes minimal, I kept the rte_memcpy().

For small fixed values compiler can optimize memcpy into one instruction.
Not so with current rte_memcpy

Good point, Stephen.

I took another look at it, and the two byte rte_memcpy() is only used in a slow path function, so no need to optimize further.

If the maintainers disagree, and want to optimize anyway, here's a proposal:

Quoted 9 lines

/* check the mac address and VLAN and allocate memory if valid */ if (valid_bitmap & (1 << MAC_ADDR_VALID) && !rte_is_same_ether_addr(

                (const struct rte_ether_addr *)&bull->mac,
                (const struct rte_ether_addr *)&sc->old_bulletin.mac))
        rte_ether_addr_copy((const struct rte_ether_addr *)&bull->mac,
                        (struct rte_ether_addr *)&sc->link_params.mac_addr);
if (valid_bitmap & (1 << VLAN_VALID))
        bull->vlan = sc->old_bulletin.vlan;

Please review/advise.
Thanks.

Signature · 1 line
David Marchand
#16 lore raw

PATCH v5 3/4 event/dlb2: remove superfluous rte_memcpy

In reply to Morten Brørup

Copying with the same src and dst address has no effect; removed to avoid compiler warning.

v5:
* First patch in series.

---
 drivers/event/dlb2/dlb2.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/event/dlb2/dlb2.c +0 -3
index 60c5cd4804..03d32c779f 100644
@@ -215,7 +215,6 @@ static int
 dlb2_hw_query_resources(struct dlb2_eventdev *dlb2)
 {
 	struct dlb2_hw_dev *handle = &dlb2->qm_instance;
-	struct dlb2_hw_resource_info *dlb2_info = &handle->info;
 	int num_ldb_ports;
 	int ret;
 
@@ -277,8 +276,6 @@ dlb2_hw_query_resources(struct dlb2_eventdev *dlb2)
 	handle->info.hw_rsrc_max.reorder_window_size =
 		dlb2->hw_rsrc_query_results.num_hist_list_entries;
 
-	rte_memcpy(dlb2_info, &handle->info.hw_rsrc_max, sizeof(*dlb2_info));
-
 	return 0;
 }
 
Signature · 1 line
2.17.1
Acked-by on v5 3/4
#17 lore raw

Re: [PATCH v5 3/4] event/dlb2: remove superfluous rte_memcpy

Quoted 24 lines · On Wed, 28 Dec 2022 16:10:18 +0100 Morten Brørup <[email protected]>…

Copying with the same src and dst address has no effect; removed to avoid compiler warning.

v5:
* First patch in series.

---
 drivers/event/dlb2/dlb2.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/event/dlb2/dlb2.c +0 -1
index 60c5cd4804..03d32c779f 100644
@@ -215,7 +215,6 @@ static int
 dlb2_hw_query_resources(struct dlb2_eventdev *dlb2)
 {
 	struct dlb2_hw_dev *handle = &dlb2->qm_instance;
-	struct dlb2_hw_resource_info *dlb2_info = &handle->info;
 	int num_ldb_ports;
 	int ret;
 

drivers/event/dlb2/dlb2.c dlb2_hw_query_resources(struct dlb2_eventdev *dlb2) · line 280

Quoted 7 lines
drivers/event/dlb2/dlb2.c +0 -2
@@ -277,8 +276,6 @@ dlb2_hw_query_resources(struct dlb2_eventdev *dlb2)
 	handle->info.hw_rsrc_max.reorder_window_size =
 		dlb2->hw_rsrc_query_results.num_hist_list_entries;
 
-	rte_memcpy(dlb2_info, &handle->info.hw_rsrc_max, sizeof(*dlb2_info));
-
 	return 0;
 }

Please add Fixes and CC author.

Fixes e7c9971a857a ("event/dlb2: add probe-time hardware init")
#18 lore raw

PATCH v5 4/4 net/mlx5: fix warning about rte_memcpy length

In reply to Morten Brørup

Use RTE_PTR_ADD where copying to the offset of a field in a structure holding multiple fields, to avoid compiler warnings.

v5:
* First patch in series.

---
 drivers/net/mlx5/mlx5_flow_dv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow_dv.c +1 -1
index 62c38b87a1..dd9f5fda1a 100644
@@ -5662,7 +5662,7 @@ flow_dv_modify_create_cb(void *tool_ctx, void *cb_ctx)
 				   "cannot allocate resource memory");
 		return NULL;
 	}
-	rte_memcpy(&entry->ft_type,
+	rte_memcpy(RTE_PTR_ADD(entry, offsetof(typeof(*entry), ft_type)),
 		   RTE_PTR_ADD(ref, offsetof(typeof(*ref), ft_type)),
 		   key_len + data_len);
 	if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
Signature · 1 line
2.17.1
#19 lore raw
In reply to Morten Brørup

28/12/2022 16:10, Morten Brørup:

Quoted 6 lines

Add "nonnull" function attribute to help the compiler detect a NULL pointer being passed to a function not accepting NULL pointers as an argument at build time.

Add "access" function attribute to tell the compiler how a function accesses its pointer arguments.

Why access specification is needed?
Isn't it enough to have the const keyword?
I'm afraid we are going to make the code ugly to read with such attribute.

#20 lore raw
Quoted 8 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Monday, 9 January 2023 12.09

28/12/2022 16:10, Morten Brørup:

Quoted 4 lines

Add "nonnull" function attribute to help the compiler detect a NULL pointer being passed to a function not accepting NULL pointers as an argument at build time.

Quoted 5 lines
Quoted 2 lines

Add "access" function attribute to tell the compiler how a function accesses its pointer arguments.

Why access specification is needed?
Isn't it enough to have the const keyword?

No, it the const keyword is not enough. The read_only access attribute implies a stronger guarantee than the const qualifier which, when cast away from a pointer, does not prevent the pointed-to object from being modified [1].

[1]: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html

These attributes help finding bugs at build time (which I consider rather important). Proof: The other patches in the series are bugs revealed by using this attribute - bugs that were completely undetected without these attributes.

I guess they might also somehow help the optimizer, similar to "const" and "restrict". I noticed that we define __rte_weak, but not __rte_pure, so perhaps I should add that too?

Quoted 2 lines

I'm afraid we are going to make the code ugly to read with such attribute.

The same can be said about ASAN. Ugly, but helpful.

In the extreme, the same could be said about the "const" and "restrict" keywords... The more decoration on the functions, the uglier the code. :-)

If you prefer, I could split the __rte_access_param(access_mode, ...) up into one macro per access mode, so this:

+__rte_nonnull_params(1, 2) +__rte_access_param(write_only, 1, 3) +__rte_access_param(read_only, 2, 3)
static inline void *
rte_memcpy_func(void *dst, const void *src, size_t n)

would be shortened to this instead:

+__rte_params_nonnull(1, 2) +__rte_param_writeonly(1, 3) +__rte_param_readonly(2, 3)
static inline void *
rte_memcpy_func(void *dst, const void *src, size_t n)

or something else.

But I don't think it's the improvement you are hoping for. In essence, it is only a change of the names of the macros.

Please note: I prefer keeping the word "params" in the _nonnull macro, so we are prepared for defining an __rte_nonnull macro (without parameters) to be used with function parameters like the C22 NonNull keyword. Keeping "param" in the name(s) of the access macro(s) would ensure similar future proofing. That, and the similarity with the __rte_nonnull_params() name was the reason for the access macro name to include "param".

#21 lore raw
In reply to Morten Brørup
Quoted 11 lines · Morten Brørup

Add "nonnull" function attribute to help the compiler detect a NULL pointer being passed to a function not accepting NULL pointers as an argument at build time.

Add "access" function attribute to tell the compiler how a function accesses its pointer arguments.

Add these attributes to the rte_memcpy() function, as the first in hopefully many to come.

Compilation is broken starting first patch, so patches must be reordered to have the fixes first.

Quoted 5 lines

v5:
* No changes.
v4:
* No changes.
v3:

Quoted 8 lines

* No changes.
v2:
* Only define "nonnull" for GCC and CLANG.
* Append _param/_params to prepare for possible future attributes attached directly to the individual parameters, like __rte_unused.
* Use RTE_TOOLCHAIN_GCC instead of RTE_CC_GCC, to fix complaints about GCC_VERSION being undefined.
* Try to fix Doxygen compliants.

Patch history should be put as annotations (i.e. after --- but before patch content).

Quoted 4 lines

[snip]

Quoted 27 lines
lib/eal/include/rte_common.h +19 -0
index 15765b408d..6e4011aa85 100644
@@ -149,6 +149,35 @@ typedef uint16_t unaligned_uint16_t;
        __attribute__((format(printf, format_index, first_arg)))
 #endif
 
+/**
+ * Check pointer arguments at compile-time.
+ *
+ * @param ...
+ *    Comma separated list of parameter indexes of pointer arguments.
+ */
+#if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG)
+#define __rte_nonnull_params(...) \
+       __attribute__((nonnull(__VA_ARGS__)))
+#else
+#define __rte_nonnull_params(...)
+#endif
+
+/**
+ * Tells compiler about the access mode of a pointer argument.
+ *
+ * @param access_mode
+ *    Access mode: read_only, read_write, write_only, or none.
+ * @param ...

lib/eal/include/rte_common.h typedef uint16_t unaligned_uint16_t; · line 180

Quoted 10 lines
lib/eal/include/rte_common.h +10 -0
+ *    Parameter index of pointer argument.
+ *    Optionally followeded by comma and parameter index of size argument.
+ */
+#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >= 100400)
+#define __rte_access_param(access_mode, ...) \
+       __attribute__((access(access_mode, __VA_ARGS__)))
+#else
+#define __rte_access_param(access_mode, ...)
+#endif
+

This is tightly bound to gcc syntax.
With dedicated macros (which I find easier to read too), we can hope to adapt to other compilers if some of them add support for this kind of code cookies.
__rte_read_only_params(indexes...) __rte_write_only_params(indexes...) __rte_no_access_params(indexes...)

Signature · 1 line
David Marchand
#22 lore raw
Quoted 14 lines

From: David Marchand [mailto:[email protected]]
Sent: Monday, 9 January 2023 12.22
attributes

Quoted 8 lines · Morten Brørup

Add "nonnull" function attribute to help the compiler detect a NULL pointer being passed to a function not accepting NULL pointers as an argument at build time.

Add "access" function attribute to tell the compiler how a function accesses its pointer arguments.

Quoted 6 lines
Quoted 3 lines

Add these attributes to the rte_memcpy() function, as the first in hopefully many to come.

Compilation is broken starting first patch, so patches must be reordered to have the fixes first.

Will do.

Quoted 13 lines
Quoted 13 lines

v5:
* No changes.
v4:
* No changes.
v3:
* No changes.
v2:
* Only define "nonnull" for GCC and CLANG.
* Append _param/_params to prepare for possible future attributes attached directly to the individual parameters, like __rte_unused.
* Use RTE_TOOLCHAIN_GCC instead of RTE_CC_GCC, to fix complaints

Quoted 6 lines

about

Quoted 2 lines

GCC_VERSION being undefined.
* Try to fix Doxygen compliants.

Patch history should be put as annotations (i.e. after --- but before patch content).

Will do.

[...]

Quoted 7 lines

This is tightly bound to gcc syntax.
With dedicated macros (which I find easier to read too), we can hope to adapt to other compilers if some of them add support for this kind of code cookies.
__rte_read_only_params(indexes...) __rte_write_only_params(indexes...) __rte_no_access_params(indexes...)

I agree. Splitting the generic access macro up into dedicated access macros is probably better.

#23 lore raw
In reply to David Marchand
Quoted 60 lines

From: Morten Brørup
Sent: Monday, 9 January 2023 13.28

Quoted 9 lines

From: David Marchand [mailto:[email protected]]
Sent: Monday, 9 January 2023 12.22
attributes

Quoted 3 lines · Morten Brørup

Add "nonnull" function attribute to help the compiler detect a NULL pointer being passed to a function not accepting NULL pointers as

an

Quoted 11 lines
Quoted 8 lines

argument at build time.

Add "access" function attribute to tell the compiler how a function accesses its pointer arguments.

Add these attributes to the rte_memcpy() function, as the first in hopefully many to come.

Compilation is broken starting first patch, so patches must be reordered to have the fixes first.

Will do.

Quoted 12 lines
Quoted 12 lines

v5:
* No changes.
v4:
* No changes.
v3:
* No changes.
v2:
* Only define "nonnull" for GCC and CLANG.
* Append _param/_params to prepare for possible future attributes attached directly to the individual parameters, like

__rte_unused.

Quoted 7 lines
Quoted 1 line

* Use RTE_TOOLCHAIN_GCC instead of RTE_CC_GCC, to fix complaints

about

Quoted 2 lines

GCC_VERSION being undefined.
* Try to fix Doxygen compliants.

Patch history should be put as annotations (i.e. after --- but before patch content).

Will do.

[...]

Quoted 7 lines

This is tightly bound to gcc syntax.
With dedicated macros (which I find easier to read too), we can hope to adapt to other compilers if some of them add support for this kind of code cookies.
__rte_read_only_params(indexes...) __rte_write_only_params(indexes...) __rte_no_access_params(indexes...)

Quoted 2 lines

I agree. Splitting the generic access macro up into dedicated access macros is probably better.

Version 6 of this patch series is here:
https://patchwork.dpdk.org/project/dpdk/list/?series=26560

Please ignore the name of the series.

-Morten

#24 lore raw

PATCH v6 1/4 net/bnx2x: fix warnings about rte_memcpy lengths

In reply to Morten Brørup

Bugfix: The vlan in the bulletin does not contain a VLAN header, only the VLAN ID, so only copy 2 byte, not 4. The target structure has padding after the field, so copying 2 byte too many is effectively harmless. There is no need to backport this patch.

Use RTE_PTR_ADD where copying arrays to the offset of a first field in a structure holding multiple fields, to avoid compiler warnings with decorated rte_memcpy.

Bugzilla ID: 1146

Fixes 540a211084a7695a1c7bc43068934c140d6989be ("bnx2x: driver core")

---
v6:
* Add Fixes to patch description.
* Fix checkpatch warnings.
v5:
* No changes.
v4:
* Type casting did not fix the warnings, so use RTE_PTR_ADD instead. v3:
* First patch in series.

---
 drivers/net/bnx2x/bnx2x_stats.c | 11 +++++++----
 drivers/net/bnx2x/bnx2x_vfpf.c  |  2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/net/bnx2x/bnx2x_stats.c +7 -4
index c07b01510a..bc4a8b8e71 100644
@@ -819,8 +819,9 @@ bnx2x_hw_stats_update(struct bnx2x_softc *sc)
 
     rte_memcpy(old, new, sizeof(struct nig_stats));
 
-    rte_memcpy(&(estats->rx_stat_ifhcinbadoctets_hi), &(pstats->mac_stx[1]),
-	   sizeof(struct mac_stx));
+	rte_memcpy(RTE_PTR_ADD(estats,
+			offsetof(struct bnx2x_eth_stats, rx_stat_ifhcinbadoctets_hi)),
+			&pstats->mac_stx[1], sizeof(struct mac_stx));
     estats->brb_drop_hi = pstats->brb_drop_hi;
     estats->brb_drop_lo = pstats->brb_drop_lo;
 
@@ -1492,9 +1493,11 @@ bnx2x_stats_init(struct bnx2x_softc *sc)
 		REG_RD(sc, NIG_REG_STAT0_BRB_TRUNCATE + port*0x38);
 	if (!CHIP_IS_E3(sc)) {
 		REG_RD_DMAE(sc, NIG_REG_STAT0_EGRESS_MAC_PKT0 + port*0x50,
-				&(sc->port.old_nig_stats.egress_mac_pkt0_lo), 2);
+				RTE_PTR_ADD(&sc->port.old_nig_stats,
+				offsetof(struct nig_stats, egress_mac_pkt0_lo)), 2);
 		REG_RD_DMAE(sc, NIG_REG_STAT0_EGRESS_MAC_PKT1 + port*0x50,
-				&(sc->port.old_nig_stats.egress_mac_pkt1_lo), 2);
+				RTE_PTR_ADD(&sc->port.old_nig_stats,
+				offsetof(struct nig_stats, egress_mac_pkt1_lo)), 2);
 	}
 
 	/* function stats */
drivers/net/bnx2x/bnx2x_vfpf.c +1 -1
index 63953c2979..87631c76ca 100644
@@ -54,7 +54,7 @@ bnx2x_check_bull(struct bnx2x_softc *sc)
 	if (valid_bitmap & (1 << MAC_ADDR_VALID) && memcmp(bull->mac, sc->old_bulletin.mac, ETH_ALEN))
 		rte_memcpy(&sc->link_params.mac_addr, bull->mac, ETH_ALEN);
 	if (valid_bitmap & (1 << VLAN_VALID))
-		rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, RTE_VLAN_HLEN);
+		rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, sizeof(bull->vlan));
 
 	sc->old_bulletin = *bull;
 
Signature · 1 line
2.17.1
#25 lore raw

PATCH v6 2/4 event/dlb2: remove superfluous rte_memcpy

Copying with the same src and dst address has no effect; removed to avoid compiler warning with decorated rte_memcpy.

Fixes e7c9971a857a ("event/dlb2: add probe-time hardware init")

---
v6:
* Add Fixes to patch description. (Stephen)
v5:
* First patch in series.

---
 drivers/event/dlb2/dlb2.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/event/dlb2/dlb2.c +0 -3
index 60c5cd4804..03d32c779f 100644
@@ -215,7 +215,6 @@ static int
 dlb2_hw_query_resources(struct dlb2_eventdev *dlb2)
 {
 	struct dlb2_hw_dev *handle = &dlb2->qm_instance;
-	struct dlb2_hw_resource_info *dlb2_info = &handle->info;
 	int num_ldb_ports;
 	int ret;
 
@@ -277,8 +276,6 @@ dlb2_hw_query_resources(struct dlb2_eventdev *dlb2)
 	handle->info.hw_rsrc_max.reorder_window_size =
 		dlb2->hw_rsrc_query_results.num_hist_list_entries;
 
-	rte_memcpy(dlb2_info, &handle->info.hw_rsrc_max, sizeof(*dlb2_info));
-
 	return 0;
 }
 
Signature · 1 line
2.17.1
#26 lore raw

PATCH v6 3/4 net/mlx5: fix warning about rte_memcpy length

In reply to Morten Brørup

Use RTE_PTR_ADD where copying to the offset of a field in a structure holding multiple fields, to avoid compiler warnings with decorated rte_memcpy.

Fixes 16a7dbc4f69006cc1c96ca2a2c6d3e3c51a2ff50 ("net/mlx5: make flow modify action list thread safe")

---
v6:
* Add Fixes to patch description.
v5:
* First patch in series.

---
 drivers/net/mlx5/mlx5_flow_dv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow_dv.c +1 -1
index 62c38b87a1..dd9f5fda1a 100644
@@ -5662,7 +5662,7 @@ flow_dv_modify_create_cb(void *tool_ctx, void *cb_ctx)
 				   "cannot allocate resource memory");
 		return NULL;
 	}
-	rte_memcpy(&entry->ft_type,
+	rte_memcpy(RTE_PTR_ADD(entry, offsetof(typeof(*entry), ft_type)),
 		   RTE_PTR_ADD(ref, offsetof(typeof(*ref), ft_type)),
 		   key_len + data_len);
 	if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
Signature · 1 line
2.17.1
#27 lore raw

PATCH v6 4/4 eal: add nonnull and access function attributes

In reply to Morten Brørup

Add nonnull function attribute to help the compiler detect a NULL pointer being passed to a function not accepting NULL pointers as an argument at build time.

Add access function attributes to tell the compiler how a function accesses memory pointed to by its pointer arguments.

Add these attributes to the rte_memcpy() function, as the first in hopefully many to come.

---
v6:
* Make this the last patch in the series, putting the fixes first. (David)
* Split the generic access macro into dedicated macros per access mode. (David)
v5:
* No changes.
v4:
* No changes.
v3:
* No changes.
v2:
* Only define "nonnull" for GCC and CLANG.
* Append _param/_params to prepare for possible future attributes attached directly to the individual parameters, like __rte_unused.
* Use RTE_TOOLCHAIN_GCC instead of RTE_CC_GCC, to fix complaints about GCC_VERSION being undefined.
* Try to fix Doxygen compliants.

---
 lib/eal/arm/include/rte_memcpy_32.h |  8 +++
 lib/eal/arm/include/rte_memcpy_64.h |  6 +++
 lib/eal/include/rte_common.h        | 76 +++++++++++++++++++++++++++++
 lib/eal/ppc/include/rte_memcpy.h    |  3 ++
 lib/eal/x86/include/rte_memcpy.h    |  6 +++
 5 files changed, 99 insertions(+)
lib/eal/arm/include/rte_memcpy_32.h +8 -0
index fb3245b59c..a625a91951 100644
@@ -14,6 +14,8 @@ extern "C" {
 
 #include "generic/rte_memcpy.h"
 
+#include <rte_common.h>
+
 #ifdef RTE_ARCH_ARM_NEON_MEMCPY
 
 #ifndef __ARM_NEON
@@ -125,6 +127,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src)
 	memcpy((dst), (src), (n)) :          \
 	rte_memcpy_func((dst), (src), (n)); })
 
+__rte_nonnull_params(1, 2)
+__rte_write_only_param(1, 3)
+__rte_read_only_param(2, 3)
 static inline void *
 rte_memcpy_func(void *dst, const void *src, size_t n)
 {
@@ -290,6 +295,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src)
 	memcpy(dst, src, 256);
 }
 
+__rte_nonnull_params(1, 2)
+__rte_write_only_param(1, 3)
+__rte_read_only_param(2, 3)
 static inline void *
 rte_memcpy(void *dst, const void *src, size_t n)
 {
lib/eal/arm/include/rte_memcpy_64.h +6 -0
index 85ad587bd3..0c86237cc9 100644
@@ -282,6 +282,9 @@ void rte_memcpy_ge64(uint8_t *dst, const uint8_t *src, size_t n)
 }
 
 #if RTE_CACHE_LINE_SIZE >= 128
+__rte_nonnull_params(1, 2)
+__rte_write_only_param(1, 3)
+__rte_read_only_param(2, 3)
 static __rte_always_inline
 void *rte_memcpy(void *dst, const void *src, size_t n)
 {
@@ -303,6 +306,9 @@ void *rte_memcpy(void *dst, const void *src, size_t n)
 }
 
 #else
+__rte_nonnull_params(1, 2)
+__rte_write_only_param(1, 3)
+__rte_read_only_param(2, 3)
 static __rte_always_inline
 void *rte_memcpy(void *dst, const void *src, size_t n)
 {
lib/eal/include/rte_common.h +76 -0

82 lines not on this page · raw message

lib/eal/ppc/include/rte_memcpy.h +3 -0
index 6f388c0234..c36869a414 100644
@@ -84,6 +84,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src)
 	memcpy((dst), (src), (n)) :          \
 	rte_memcpy_func((dst), (src), (n)); })
 
+__rte_nonnull_params(1, 2)
+__rte_write_only_param(1, 3)
+__rte_read_only_param(2, 3)
 static inline void *
 rte_memcpy_func(void *dst, const void *src, size_t n)
 {
lib/eal/x86/include/rte_memcpy.h +6 -0
index d4d7a5cfc8..ee543aa37d 100644
@@ -42,6 +42,9 @@ extern "C" {
  * @return
  *   Pointer to the destination data.
  */
+__rte_nonnull_params(1, 2)
+__rte_write_only_param(1, 3)
+__rte_read_only_param(2, 3)
 static __rte_always_inline void *
 rte_memcpy(void *dst, const void *src, size_t n);
 
@@ -859,6 +862,9 @@ rte_memcpy_aligned(void *dst, const void *src, size_t n)
 	return ret;
 }
 
+__rte_nonnull_params(1, 2)
+__rte_write_only_param(1, 3)
+__rte_read_only_param(2, 3)
 static __rte_always_inline void *
 rte_memcpy(void *dst, const void *src, size_t n)
 {
Signature · 1 line
2.17.1
#28 lore raw

PATCH v7 1/4 net/bnx2x: fix warnings about rte_memcpy lengths

In reply to Morten Brørup

Bugfix: The vlan in the bulletin does not contain a VLAN header, only the VLAN ID, so only copy 2 byte, not 4. The target structure has padding after the field, so copying 2 byte too many is effectively harmless. There is no need to backport this patch.

Use RTE_PTR_ADD where copying arrays to the offset of a first field in a structure holding multiple fields, to avoid compiler warnings with decorated rte_memcpy.

Bugzilla ID: 1146

Fixes 540a211084a7695a1c7bc43068934c140d6989be ("bnx2x: driver core")

---
v7:
* No changes.
v6:
* Add Fixes to patch description.
* Fix checkpatch warnings.
v5:
* No changes.
v4:
* Type casting did not fix the warnings, so use RTE_PTR_ADD instead. v3:
* First patch in series.

---
 drivers/net/bnx2x/bnx2x_stats.c | 11 +++++++----
 drivers/net/bnx2x/bnx2x_vfpf.c  |  2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/net/bnx2x/bnx2x_stats.c +7 -4
index c07b01510a..bc4a8b8e71 100644
@@ -819,8 +819,9 @@ bnx2x_hw_stats_update(struct bnx2x_softc *sc)
 
     rte_memcpy(old, new, sizeof(struct nig_stats));
 
-    rte_memcpy(&(estats->rx_stat_ifhcinbadoctets_hi), &(pstats->mac_stx[1]),
-	   sizeof(struct mac_stx));
+	rte_memcpy(RTE_PTR_ADD(estats,
+			offsetof(struct bnx2x_eth_stats, rx_stat_ifhcinbadoctets_hi)),
+			&pstats->mac_stx[1], sizeof(struct mac_stx));
     estats->brb_drop_hi = pstats->brb_drop_hi;
     estats->brb_drop_lo = pstats->brb_drop_lo;
 
@@ -1492,9 +1493,11 @@ bnx2x_stats_init(struct bnx2x_softc *sc)
 		REG_RD(sc, NIG_REG_STAT0_BRB_TRUNCATE + port*0x38);
 	if (!CHIP_IS_E3(sc)) {
 		REG_RD_DMAE(sc, NIG_REG_STAT0_EGRESS_MAC_PKT0 + port*0x50,
-				&(sc->port.old_nig_stats.egress_mac_pkt0_lo), 2);
+				RTE_PTR_ADD(&sc->port.old_nig_stats,
+				offsetof(struct nig_stats, egress_mac_pkt0_lo)), 2);
 		REG_RD_DMAE(sc, NIG_REG_STAT0_EGRESS_MAC_PKT1 + port*0x50,
-				&(sc->port.old_nig_stats.egress_mac_pkt1_lo), 2);
+				RTE_PTR_ADD(&sc->port.old_nig_stats,
+				offsetof(struct nig_stats, egress_mac_pkt1_lo)), 2);
 	}
 
 	/* function stats */
drivers/net/bnx2x/bnx2x_vfpf.c +1 -1
index 63953c2979..87631c76ca 100644
@@ -54,7 +54,7 @@ bnx2x_check_bull(struct bnx2x_softc *sc)
 	if (valid_bitmap & (1 << MAC_ADDR_VALID) && memcmp(bull->mac, sc->old_bulletin.mac, ETH_ALEN))
 		rte_memcpy(&sc->link_params.mac_addr, bull->mac, ETH_ALEN);
 	if (valid_bitmap & (1 << VLAN_VALID))
-		rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, RTE_VLAN_HLEN);
+		rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, sizeof(bull->vlan));
 
 	sc->old_bulletin = *bull;
 
Signature · 1 line
2.17.1
#29 lore raw

PATCH v7 2/4 event/dlb2: remove superfluous rte_memcpy

Copying with the same src and dst address has no effect; removed to avoid compiler warning with decorated rte_memcpy.

Fixes e7c9971a857a ("event/dlb2: add probe-time hardware init")

---
v7:
* No changes.
v6:
* Add Fixes to patch description. (Stephen)
v5:
* First patch in series.

---
 drivers/event/dlb2/dlb2.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/event/dlb2/dlb2.c +0 -3
index 60c5cd4804..03d32c779f 100644
@@ -215,7 +215,6 @@ static int
 dlb2_hw_query_resources(struct dlb2_eventdev *dlb2)
 {
 	struct dlb2_hw_dev *handle = &dlb2->qm_instance;
-	struct dlb2_hw_resource_info *dlb2_info = &handle->info;
 	int num_ldb_ports;
 	int ret;
 
@@ -277,8 +276,6 @@ dlb2_hw_query_resources(struct dlb2_eventdev *dlb2)
 	handle->info.hw_rsrc_max.reorder_window_size =
 		dlb2->hw_rsrc_query_results.num_hist_list_entries;
 
-	rte_memcpy(dlb2_info, &handle->info.hw_rsrc_max, sizeof(*dlb2_info));
-
 	return 0;
 }
 
Signature · 1 line
2.17.1
#30 lore raw

RE: [PATCH v7 2/4] event/dlb2: remove superfluous rte_memcpy

PING dlb2 maintainers. Care to review this, so it can be included in 23.03?

Quoted 46 lines

From: Morten Brørup [mailto:[email protected]]
Sent: Monday, 16 January 2023 14.07

Copying with the same src and dst address has no effect; removed to avoid compiler warning with decorated rte_memcpy.

Fixes e7c9971a857a ("event/dlb2: add probe-time hardware init")

---
v7:
* No changes.
v6:
* Add Fixes to patch description. (Stephen)
v5:
* First patch in series.

---
 drivers/event/dlb2/dlb2.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/event/dlb2/dlb2.c +0 -4
index 60c5cd4804..03d32c779f 100644
@@ -215,7 +215,6 @@ static int
 dlb2_hw_query_resources(struct dlb2_eventdev *dlb2)
 {
 	struct dlb2_hw_dev *handle = &dlb2->qm_instance;
-	struct dlb2_hw_resource_info *dlb2_info = &handle->info;
 	int num_ldb_ports;
 	int ret;
 
@@ -277,8 +276,6 @@ dlb2_hw_query_resources(struct dlb2_eventdev *dlb2)
 	handle->info.hw_rsrc_max.reorder_window_size =
 		dlb2->hw_rsrc_query_results.num_hist_list_entries;
 
-	rte_memcpy(dlb2_info, &handle->info.hw_rsrc_max,
 sizeof(*dlb2_info));
-
 	return 0;
 }
 
--

2.17.1

#31 lore raw

RE: [PATCH v7 2/4] event/dlb2: remove superfluous rte_memcpy

Acked: by [email protected]

-----Original Message-----
From: Morten Brørup <[email protected]>
Sent: Thursday, February 9, 2023 8:51 AM
To: [email protected]; [email protected]; [email protected]; McDaniel, Timothy <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Richardson, Bruce <[email protected]>; [email protected]
Subject: RE: [PATCH v7 2/4] event/dlb2: remove superfluous rte_memcpy

PING dlb2 maintainers. Care to review this, so it can be included in 23.03?

Quoted 45 lines

From: Morten Brørup [mailto:[email protected]]
Sent: Monday, 16 January 2023 14.07

Copying with the same src and dst address has no effect; removed to avoid compiler warning with decorated rte_memcpy.

Fixes e7c9971a857a ("event/dlb2: add probe-time hardware init")

---
v7:
* No changes.
v6:
* Add Fixes to patch description. (Stephen)
v5:
* First patch in series.

---
 drivers/event/dlb2/dlb2.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/event/dlb2/dlb2.c +0 -4
index 60c5cd4804..03d32c779f 100644
@@ -215,7 +215,6 @@ static int
 dlb2_hw_query_resources(struct dlb2_eventdev *dlb2)  {
 	struct dlb2_hw_dev *handle = &dlb2->qm_instance;
-	struct dlb2_hw_resource_info *dlb2_info = &handle->info;
 	int num_ldb_ports;
 	int ret;
 
@@ -277,8 +276,6 @@ dlb2_hw_query_resources(struct dlb2_eventdev *dlb2)
 	handle->info.hw_rsrc_max.reorder_window_size =
 		dlb2->hw_rsrc_query_results.num_hist_list_entries;
 
-	rte_memcpy(dlb2_info, &handle->info.hw_rsrc_max,
 sizeof(*dlb2_info));
-
 	return 0;
 }
 
--

2.17.1

author Acked-by Abdullah Sevincer
#32 lore raw

RE: [PATCH v7 2/4] event/dlb2: remove superfluous rte_memcpy

Quoted 4 lines

From: Sevincer, Abdullah [mailto:[email protected]]
Sent: Thursday, 9 February 2023 19.50

Acked: by [email protected]

Thanks.

Patchwork didn't catch it due to formatting, but the point is obvious:

Quoted 61 lines

-----Original Message-----
From: Morten Brørup <[email protected]>
Sent: Thursday, February 9, 2023 8:51 AM
To: [email protected]; [email protected]; [email protected]; McDaniel, Timothy <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Richardson, Bruce <[email protected]>; [email protected]
Subject: RE: [PATCH v7 2/4] event/dlb2: remove superfluous rte_memcpy

PING dlb2 maintainers. Care to review this, so it can be included in 23.03?

drivers/event/dlb2/dlb2.c dlb2_hw_query_resources(struct dlb2_eventdev

Quoted 34 lines

From: Morten Brørup [mailto:[email protected]]
Sent: Monday, 16 January 2023 14.07

Copying with the same src and dst address has no effect; removed to avoid compiler warning with decorated rte_memcpy.

Fixes e7c9971a857a ("event/dlb2: add probe-time hardware init")

---
v7:
* No changes.
v6:
* Add Fixes to patch description. (Stephen)
v5:
* First patch in series.

---
 drivers/event/dlb2/dlb2.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/event/dlb2/dlb2.c +0 -1
index 60c5cd4804..03d32c779f 100644
@@ -215,7 +215,6 @@ static int
 dlb2_hw_query_resources(struct dlb2_eventdev *dlb2)  {
 	struct dlb2_hw_dev *handle = &dlb2->qm_instance;
-	struct dlb2_hw_resource_info *dlb2_info = &handle->info;
 	int num_ldb_ports;
 	int ret;
 
@@ -277,8 +276,6 @@ dlb2_hw_query_resources(struct dlb2_eventdev

*dlb2)

Quoted 11 lines
drivers/event/dlb2/dlb2.c +0 -3
 	handle->info.hw_rsrc_max.reorder_window_size =
 		dlb2->hw_rsrc_query_results.num_hist_list_entries;
 
-	rte_memcpy(dlb2_info, &handle->info.hw_rsrc_max,
 sizeof(*dlb2_info));
-
 	return 0;
 }
 
--

2.17.1

#34 lore raw

PATCH v8 1/1 net/bnx2x: fix warnings about rte_memcpy lengths

Bugfix: The vlan in the bulletin does not contain a VLAN header, only the VLAN ID, so only copy 2 byte, not 4. The target structure has padding after the field, so copying 2 byte too many is effectively harmless. There is no need to backport this patch.

Use RTE_PTR_ADD where copying arrays to the offset of a first field in a structure holding multiple fields, to avoid compiler warnings with decorated rte_memcpy.

Bugzilla ID: 1146

Fixes 540a211084a7695a1c7bc43068934c140d6989be ("bnx2x: driver core")

---
v8:
* Use memcpy instead of rte_memcpy in slow path. (Stephen Hemminger) v7:
* No changes.
v6:
* Add Fixes to patch description.
* Fix checkpatch warnings.
v5:
* No changes.
v4:
* Type casting did not fix the warnings, so use RTE_PTR_ADD instead. v3:
* First patch in series.

---
 drivers/net/bnx2x/bnx2x_stats.c | 14 ++++++++------
 drivers/net/bnx2x/bnx2x_vfpf.c  | 14 +++++++-------
 2 files changed, 15 insertions(+), 13 deletions(-)
drivers/net/bnx2x/bnx2x_stats.c +8 -6
index c07b01510a..8105375d44 100644
@@ -114,7 +114,7 @@ bnx2x_hw_stats_post(struct bnx2x_softc *sc)
 
 	/* Update MCP's statistics if possible */
 	if (sc->func_stx) {
-		rte_memcpy(BNX2X_SP(sc, func_stats), &sc->func_stats,
+		memcpy(BNX2X_SP(sc, func_stats), &sc->func_stats,
 				sizeof(sc->func_stats));
 	}
 
@@ -817,10 +817,10 @@ bnx2x_hw_stats_update(struct bnx2x_softc *sc)
 			  etherstatspktsover1522octets);
     }
 
-    rte_memcpy(old, new, sizeof(struct nig_stats));
+    memcpy(old, new, sizeof(struct nig_stats));
 
-    rte_memcpy(&(estats->rx_stat_ifhcinbadoctets_hi), &(pstats->mac_stx[1]),
-	   sizeof(struct mac_stx));
+	memcpy(RTE_PTR_ADD(estats, offsetof(struct bnx2x_eth_stats, rx_stat_ifhcinbadoctets_hi)),
+			&pstats->mac_stx[1], sizeof(struct mac_stx));
     estats->brb_drop_hi = pstats->brb_drop_hi;
     estats->brb_drop_lo = pstats->brb_drop_lo;
 
@@ -1492,9 +1492,11 @@ bnx2x_stats_init(struct bnx2x_softc *sc)
 		REG_RD(sc, NIG_REG_STAT0_BRB_TRUNCATE + port*0x38);
 	if (!CHIP_IS_E3(sc)) {
 		REG_RD_DMAE(sc, NIG_REG_STAT0_EGRESS_MAC_PKT0 + port*0x50,
-				&(sc->port.old_nig_stats.egress_mac_pkt0_lo), 2);
+				RTE_PTR_ADD(&sc->port.old_nig_stats,
+				offsetof(struct nig_stats, egress_mac_pkt0_lo)), 2);
 		REG_RD_DMAE(sc, NIG_REG_STAT0_EGRESS_MAC_PKT1 + port*0x50,
-				&(sc->port.old_nig_stats.egress_mac_pkt1_lo), 2);
+				RTE_PTR_ADD(&sc->port.old_nig_stats,
+				offsetof(struct nig_stats, egress_mac_pkt1_lo)), 2);
 	}
 
 	/* function stats */
drivers/net/bnx2x/bnx2x_vfpf.c +7 -7
index 63953c2979..5411df3a38 100644
@@ -52,9 +52,9 @@ bnx2x_check_bull(struct bnx2x_softc *sc)
 
 	/* check the mac address and VLAN and allocate memory if valid */
 	if (valid_bitmap & (1 << MAC_ADDR_VALID) && memcmp(bull->mac, sc->old_bulletin.mac, ETH_ALEN))
-		rte_memcpy(&sc->link_params.mac_addr, bull->mac, ETH_ALEN);
+		memcpy(&sc->link_params.mac_addr, bull->mac, ETH_ALEN);
 	if (valid_bitmap & (1 << VLAN_VALID))
-		rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, RTE_VLAN_HLEN);
+		memcpy(&bull->vlan, &sc->old_bulletin.vlan, sizeof(bull->vlan));
 
 	sc->old_bulletin = *bull;
 
@@ -569,7 +569,7 @@ bnx2x_vf_set_mac(struct bnx2x_softc *sc, int set)
 
 	bnx2x_check_bull(sc);
 
-	rte_memcpy(query->filters[0].mac, sc->link_params.mac_addr, ETH_ALEN);
+	memcpy(query->filters[0].mac, sc->link_params.mac_addr, ETH_ALEN);
 
 	bnx2x_add_tlv(sc, query, query->first_tlv.tl.length,
 		      BNX2X_VF_TLV_LIST_END,
@@ -583,9 +583,9 @@ bnx2x_vf_set_mac(struct bnx2x_softc *sc, int set)
 	while (BNX2X_VF_STATUS_FAILURE == reply->status &&
 			bnx2x_check_bull(sc)) {
 		/* A new mac was configured by PF for us */
-		rte_memcpy(sc->link_params.mac_addr, sc->pf2vf_bulletin->mac,
+		memcpy(sc->link_params.mac_addr, sc->pf2vf_bulletin->mac,
 				ETH_ALEN);
-		rte_memcpy(query->filters[0].mac, sc->pf2vf_bulletin->mac,
+		memcpy(query->filters[0].mac, sc->pf2vf_bulletin->mac,
 				ETH_ALEN);
 
 		rc = bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
@@ -622,10 +622,10 @@ bnx2x_vf_config_rss(struct bnx2x_softc *sc,
 		      BNX2X_VF_TLV_LIST_END,
 		      sizeof(struct channel_list_end_tlv));
 
-	rte_memcpy(query->rss_key, params->rss_key, sizeof(params->rss_key));
+	memcpy(query->rss_key, params->rss_key, sizeof(params->rss_key));
 	query->rss_key_size = T_ETH_RSS_KEY;
 
-	rte_memcpy(query->ind_table, params->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
+	memcpy(query->ind_table, params->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
 	query->ind_table_size = T_ETH_INDIRECTION_TABLE_SIZE;
 
 	query->rss_result_mask = params->rss_result_mask;
Signature · 1 line
2.17.1
#35 lore raw

PATCH v9 1/1 net/bnx2x: fix warnings about rte_memcpy lengths

In reply to Jerin Jacob

Bugfix: The vlan in the bulletin does not contain a VLAN header, only the VLAN ID, so only copy 2 byte, not 4. The target structure has padding after the field, so copying 2 byte too many is effectively harmless. There is no need to backport this patch.

Use RTE_PTR_ADD where copying arrays to the offset of a first field in a structure holding multiple fields, to avoid compiler warnings with decorated rte_memcpy.

Bugzilla ID: 1146

Fixes 540a211084a7695a1c7bc43068934c140d6989be ("bnx2x: driver core")

---
v9:
* Fix checkpatch warning about spaces.
v8:
* Use memcpy instead of rte_memcpy in slow path. (Stephen Hemminger) v7:
* No changes.
v6:
* Add Fixes to patch description.
* Fix checkpatch warnings.
v5:
* No changes.
v4:
* Type casting did not fix the warnings, so use RTE_PTR_ADD instead. v3:
* First patch in series.

---
 drivers/net/bnx2x/bnx2x_stats.c | 14 ++++++++------
 drivers/net/bnx2x/bnx2x_vfpf.c  | 14 +++++++-------
 2 files changed, 15 insertions(+), 13 deletions(-)
drivers/net/bnx2x/bnx2x_stats.c +8 -6
index c07b01510a..8105375d44 100644
@@ -114,7 +114,7 @@ bnx2x_hw_stats_post(struct bnx2x_softc *sc)
 
 	/* Update MCP's statistics if possible */
 	if (sc->func_stx) {
-		rte_memcpy(BNX2X_SP(sc, func_stats), &sc->func_stats,
+		memcpy(BNX2X_SP(sc, func_stats), &sc->func_stats,
 				sizeof(sc->func_stats));
 	}
 
@@ -817,10 +817,10 @@ bnx2x_hw_stats_update(struct bnx2x_softc *sc)
 			  etherstatspktsover1522octets);
     }
 
-    rte_memcpy(old, new, sizeof(struct nig_stats));
+	memcpy(old, new, sizeof(struct nig_stats));
 
-    rte_memcpy(&(estats->rx_stat_ifhcinbadoctets_hi), &(pstats->mac_stx[1]),
-	   sizeof(struct mac_stx));
+	memcpy(RTE_PTR_ADD(estats, offsetof(struct bnx2x_eth_stats, rx_stat_ifhcinbadoctets_hi)),
+			&pstats->mac_stx[1], sizeof(struct mac_stx));
     estats->brb_drop_hi = pstats->brb_drop_hi;
     estats->brb_drop_lo = pstats->brb_drop_lo;
 
@@ -1492,9 +1492,11 @@ bnx2x_stats_init(struct bnx2x_softc *sc)
 		REG_RD(sc, NIG_REG_STAT0_BRB_TRUNCATE + port*0x38);
 	if (!CHIP_IS_E3(sc)) {
 		REG_RD_DMAE(sc, NIG_REG_STAT0_EGRESS_MAC_PKT0 + port*0x50,
-				&(sc->port.old_nig_stats.egress_mac_pkt0_lo), 2);
+				RTE_PTR_ADD(&sc->port.old_nig_stats,
+				offsetof(struct nig_stats, egress_mac_pkt0_lo)), 2);
 		REG_RD_DMAE(sc, NIG_REG_STAT0_EGRESS_MAC_PKT1 + port*0x50,
-				&(sc->port.old_nig_stats.egress_mac_pkt1_lo), 2);
+				RTE_PTR_ADD(&sc->port.old_nig_stats,
+				offsetof(struct nig_stats, egress_mac_pkt1_lo)), 2);
 	}
 
 	/* function stats */
drivers/net/bnx2x/bnx2x_vfpf.c +7 -7
index 63953c2979..5411df3a38 100644
@@ -52,9 +52,9 @@ bnx2x_check_bull(struct bnx2x_softc *sc)
 
 	/* check the mac address and VLAN and allocate memory if valid */
 	if (valid_bitmap & (1 << MAC_ADDR_VALID) && memcmp(bull->mac, sc->old_bulletin.mac, ETH_ALEN))
-		rte_memcpy(&sc->link_params.mac_addr, bull->mac, ETH_ALEN);
+		memcpy(&sc->link_params.mac_addr, bull->mac, ETH_ALEN);
 	if (valid_bitmap & (1 << VLAN_VALID))
-		rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, RTE_VLAN_HLEN);
+		memcpy(&bull->vlan, &sc->old_bulletin.vlan, sizeof(bull->vlan));
 
 	sc->old_bulletin = *bull;
 
@@ -569,7 +569,7 @@ bnx2x_vf_set_mac(struct bnx2x_softc *sc, int set)
 
 	bnx2x_check_bull(sc);
 
-	rte_memcpy(query->filters[0].mac, sc->link_params.mac_addr, ETH_ALEN);
+	memcpy(query->filters[0].mac, sc->link_params.mac_addr, ETH_ALEN);
 
 	bnx2x_add_tlv(sc, query, query->first_tlv.tl.length,
 		      BNX2X_VF_TLV_LIST_END,
@@ -583,9 +583,9 @@ bnx2x_vf_set_mac(struct bnx2x_softc *sc, int set)
 	while (BNX2X_VF_STATUS_FAILURE == reply->status &&
 			bnx2x_check_bull(sc)) {
 		/* A new mac was configured by PF for us */
-		rte_memcpy(sc->link_params.mac_addr, sc->pf2vf_bulletin->mac,
+		memcpy(sc->link_params.mac_addr, sc->pf2vf_bulletin->mac,
 				ETH_ALEN);
-		rte_memcpy(query->filters[0].mac, sc->pf2vf_bulletin->mac,
+		memcpy(query->filters[0].mac, sc->pf2vf_bulletin->mac,
 				ETH_ALEN);
 
 		rc = bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
@@ -622,10 +622,10 @@ bnx2x_vf_config_rss(struct bnx2x_softc *sc,
 		      BNX2X_VF_TLV_LIST_END,
 		      sizeof(struct channel_list_end_tlv));
 
-	rte_memcpy(query->rss_key, params->rss_key, sizeof(params->rss_key));
+	memcpy(query->rss_key, params->rss_key, sizeof(params->rss_key));
 	query->rss_key_size = T_ETH_RSS_KEY;
 
-	rte_memcpy(query->ind_table, params->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
+	memcpy(query->ind_table, params->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
 	query->ind_table_size = T_ETH_INDIRECTION_TABLE_SIZE;
 
 	query->rss_result_mask = params->rss_result_mask;
Signature · 1 line
2.17.1
Acked-by Devendra Singh Rawat on v9 1/1
#36 lore raw

Re: [PATCH v9] net/bnx2x: fix warnings about rte_memcpy lengths

Quoted 18 lines · Morten Brørup

Bugfix: The vlan in the bulletin does not contain a VLAN header, only the VLAN ID, so only copy 2 byte, not 4. The target structure has padding after the field, so copying 2 byte too many is effectively harmless. There is no need to backport this patch.

Use RTE_PTR_ADD where copying arrays to the offset of a first field in a structure holding multiple fields, to avoid compiler warnings with decorated rte_memcpy.

Bugzilla ID: 1146

Fixes 540a211084a7695a1c7bc43068934c140d6989be ("bnx2x: driver core")
Quoted 5 lines

---
v9:
* Fix checkpatch warning about spaces.

Fixed the following issues[1] and updated the git commit as follows and applied to dpdk-next-net-mrvl/for-main. Thanks

net/bnx2x: fix warnings about memcpy lengths

The vlan in the bulletin does not contain a VLAN header, only the VLAN ID, so only copy 2 byte, not 4. The target structure has padding after the field, so copying 2 byte too many is effectively harmless. Fix it by using generic memcpy version instead of specialized rte version as it not used in fast path.

Also, Use RTE_PTR_ADD where copying arrays to the offset of a first field in a structure holding multiple fields, to avoid compiler warnings with decorated memcpy.

Bugzilla ID: 1146

Fixes 540a211084a7 ("bnx2x: driver core")

[1]
Wrong headline format:
net/bnx2x: fix warnings about rte_memcpy lengths
Wrong tag:
Bugfix: The vlan in the bulletin does not contain a VLAN
header, only the
Is it candidate for Cc: [email protected] backport?
net/bnx2x: fix warnings about rte_memcpy lengths

Invalid patch(es) found - checked 1 patch
check-git-log failed

### [PATCH] net/bnx2x: fix warnings about rte_memcpy lengths

WARNING:BAD_FIXES_TAG: Please use correct Fixes: style 'Fixes: <12 chars of sha1> ("<title line>")' - ie: 'Fixes: 540a211084a7 ("bnx2x:
driver core")'
#20:

Fixes 540a211084a7695a1c7bc43068934c140d6989be ("bnx2x: driver core")

total: 0 errors, 1 warnings, 0 checks, 76 lines checked

0/1 valid patch
checkpatch failed

#37 lore raw

RE: [PATCH v9] net/bnx2x: fix warnings about rte_memcpy lengths

Quoted 25 lines

From: Jerin Jacob [mailto:[email protected]]
Sent: Monday, 26 February 2024 09.34

Quoted 2 lines · Morten Brørup

Bugfix: The vlan in the bulletin does not contain a VLAN header, only

the

Quoted 5 lines

VLAN ID, so only copy 2 byte, not 4. The target structure has padding after the field, so copying 2 byte too many is effectively harmless. There is no need to backport this patch.

Use RTE_PTR_ADD where copying arrays to the offset of a first field in

a

Quoted 11 lines

structure holding multiple fields, to avoid compiler warnings with decorated rte_memcpy.

Bugzilla ID: 1146

Fixes 540a211084a7695a1c7bc43068934c140d6989be ("bnx2x: driver core")
Quoted 8 lines
Quoted 5 lines

---
v9:
* Fix checkpatch warning about spaces.

Fixed the following issues[1] and updated the git commit as follows and applied to dpdk-next-net-mrvl/for-main. Thanks

Thank you, Jerin.

[...]

Quoted 1 line

Is it candidate for Cc: [email protected] backport?

No, I don't think so:
1. The extra 2 byte copy is effectively harmless due to padding, as mentioned in the commit message.
2. The decorated rte_memcpy (if work on that patch series is ever resumed) is an improvement, not a bug fix, and will not be backported. So the memcpy parts of this patch are irrelevant for the stable versions.

#38 lore raw

Re: [PATCH v9] net/bnx2x: fix warnings about rte_memcpy lengths

Quoted 37 lines · Morten Brørup
Quoted 26 lines

From: Jerin Jacob [mailto:[email protected]]
Sent: Monday, 26 February 2024 09.34

Quoted 2 lines · Morten Brørup

Bugfix: The vlan in the bulletin does not contain a VLAN header, only

the

Quoted 5 lines

VLAN ID, so only copy 2 byte, not 4. The target structure has padding after the field, so copying 2 byte too many is effectively harmless. There is no need to backport this patch.

Use RTE_PTR_ADD where copying arrays to the offset of a first field in

a

Quoted 11 lines

structure holding multiple fields, to avoid compiler warnings with decorated rte_memcpy.

Bugzilla ID: 1146

Fixes 540a211084a7695a1c7bc43068934c140d6989be ("bnx2x: driver core")
Quoted 8 lines
Quoted 5 lines

---
v9:
* Fix checkpatch warning about spaces.

Fixed the following issues[1] and updated the git commit as follows and applied to dpdk-next-net-mrvl/for-main. Thanks

Thank you, Jerin.

Quoted 7 lines

[...]

Quoted 1 line

Is it candidate for Cc: [email protected] backport?

No, I don't think so:
1. The extra 2 byte copy is effectively harmless due to padding, as mentioned in the commit message.
2. The decorated rte_memcpy (if work on that patch series is ever resumed) is an improvement, not a bug fix, and will not be backported. So the memcpy parts of this patch are irrelevant for the stable versions.

Shall remove Fixes: tag then?. Since the patch has a Fixes tag, I thought good to merge to stable as it is fixing.

Also, could you comment on @Stephen Hemminger latest comments, Should I wait for new version? or new changes can go as separate patches.

Quoted 1 line
#39 lore raw

RE: [PATCH v9] net/bnx2x: fix warnings about rte_memcpy lengths

+To: Raslan, regarding MLX5 patch

Quoted 48 lines

From: Jerin Jacob [mailto:[email protected]]
Sent: Tuesday, 27 February 2024 12.01

Quoted 35 lines · Morten Brørup
Quoted 26 lines

From: Jerin Jacob [mailto:[email protected]]
Sent: Monday, 26 February 2024 09.34

Quoted 2 lines · Morten Brørup

Bugfix: The vlan in the bulletin does not contain a VLAN header, only

the

Quoted 5 lines

VLAN ID, so only copy 2 byte, not 4. The target structure has padding after the field, so copying 2 byte too many is effectively harmless. There is no need to backport this patch.

Use RTE_PTR_ADD where copying arrays to the offset of a first field in

a

Quoted 11 lines

structure holding multiple fields, to avoid compiler warnings with decorated rte_memcpy.

Bugzilla ID: 1146

Fixes 540a211084a7695a1c7bc43068934c140d6989be ("bnx2x: driver core")
Quoted 8 lines
Quoted 5 lines

---
v9:
* Fix checkpatch warning about spaces.

Fixed the following issues[1] and updated the git commit as follows and applied to dpdk-next-net-mrvl/for-main. Thanks

Quoted 8 lines

Thank you, Jerin.

[...]

Quoted 1 line

Is it candidate for Cc: [email protected] backport?

No, I don't think so:
1. The extra 2 byte copy is effectively harmless due to padding, as

Quoted 8 lines

mentioned in the commit message.

Quoted 1 line

2. The decorated rte_memcpy (if work on that patch series is ever resumed)

is an improvement, not a bug fix, and will not be backported. So the memcpy parts of this patch are irrelevant for the stable versions.

Shall remove Fixes: tag then?. Since the patch has a Fixes tag, I thought good to merge to stable as it is fixing.

Although the patch formally fixes a bug, the bug is harmless, so I don't think it is worth the effort backporting. I don't know the policy for Fixes: tags in such cases. However you proceed with it is perfectly fine with me.

Quoted 3 lines

Also, could you comment on @Stephen Hemminger latest comments, Should I wait for new version? or new changes can go as separate patches.

I'm not providing a new version of this patch.

This patch was part of a series, where its rte_memcpy changes were required for the primary patch in the series [1]. The purpose of the primary patch was to tighten rte_memcpy's parameter requirements by adding access-mode attributes.

[1]: https://patchwork.dpdk.org/project/dpdk/patch/[email protected]/

It was not really my intention to fix other things in the drivers I submitted patches for. That was only a positive side effect. ;-)

@Raslan: Also, the patch for the mlx5 driver [2] has seen no progress for a year, so I'm going to abandon it. I will resume it if I start working on the decorated rte_memcpy again. Should I change it's state to Not Applicable or something else?

[2]: https://patchwork.dpdk.org/project/dpdk/patch/[email protected]/

#40 lore raw

Re: [PATCH v9] net/bnx2x: fix warnings about rte_memcpy lengths

Quoted 5 lines · On Tue, 27 Feb 2024 12:27:31 +0100 Morten Brørup <[email protected]>…
Quoted 5 lines
Quoted 1 line

1. The extra 2 byte copy is effectively harmless due to padding, as

mentioned in the commit message.

Quoted 1 line

2. The decorated rte_memcpy (if work on that patch series is ever resumed)

is an improvement, not a bug fix, and will not be backported. So the memcpy parts of this patch are irrelevant for the stable versions.

The function rte_memcpy only exists because glibc and gcc version of memcpy is not optimized enough. Would love to see it go away in future.

#41 lore raw

Re: [PATCH v9] net/bnx2x: fix warnings about rte_memcpy lengths

Quoted 11 lines · Stephen Hemminger
Quoted 5 lines · On Tue, 27 Feb 2024 12:27:31 +0100 Morten Brørup <[email protected]>…
Quoted 5 lines
Quoted 1 line

1. The extra 2 byte copy is effectively harmless due to padding, as

mentioned in the commit message.

Quoted 1 line

2. The decorated rte_memcpy (if work on that patch series is ever resumed)

is an improvement, not a bug fix, and will not be backported. So the memcpy parts of this patch are irrelevant for the stable versions.

The function rte_memcpy only exists because glibc and gcc version of memcpy is not optimized enough. Would love to see it go away in future.

Definite +1.

#42 lore raw

RE: [PATCH v9] net/bnx2x: fix warnings about rte_memcpy lengths

In reply to Morten Brørup

Hi,

Quoted 100 lines

-----Original Message-----
From: Morten Brørup <[email protected]>
Sent: Tuesday, February 27, 2024 1:28 PM
To: Jerin Jacob <[email protected]>; Raslan Darawsheh <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH v9] net/bnx2x: fix warnings about rte_memcpy lengths

+To: Raslan, regarding MLX5 patch

Quoted 19 lines

From: Jerin Jacob [mailto:[email protected]]
Sent: Tuesday, 27 February 2024 12.01

Quoted 13 lines · Morten Brørup
Quoted 13 lines

From: Jerin Jacob [mailto:[email protected]]
Sent: Monday, 26 February 2024 09.34

Quoted 3 lines · Morten Brørup

Bugfix: The vlan in the bulletin does not contain a VLAN header, only

the

Quoted 2 lines

VLAN ID, so only copy 2 byte, not 4. The target structure has padding after the field, so copying 2 byte too many is effectively

harmless.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines

There is no need to backport this patch.

Use RTE_PTR_ADD where copying arrays to the offset of a first field in

a

Quoted 6 lines

structure holding multiple fields, to avoid compiler warnings with decorated rte_memcpy.

Bugzilla ID: 1146

Fixes 540a211084a7695a1c7bc43068934c140d6989be ("bnx2x:

driver

Quoted 24 lines
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines

core")
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

Quoted 8 lines
Quoted 5 lines

---
v9:
* Fix checkpatch warning about spaces.

Fixed the following issues[1] and updated the git commit as follows and applied to dpdk-next-net-mrvl/for-main. Thanks

Quoted 8 lines

Thank you, Jerin.

[...]

Quoted 1 line

Is it candidate for Cc: [email protected] backport?

No, I don't think so:
1. The extra 2 byte copy is effectively harmless due to padding, as

mentioned in the commit message.

Quoted 8 lines
Quoted 2 lines

2. The decorated rte_memcpy (if work on that patch series is ever resumed)

is an improvement, not a bug fix, and will not be backported. So the memcpy parts of this patch are irrelevant for the stable versions.

Shall remove Fixes: tag then?. Since the patch has a Fixes tag, I thought good to merge to stable as it is fixing.

Although the patch formally fixes a bug, the bug is harmless, so I don't think it is worth the effort backporting.
I don't know the policy for Fixes: tags in such cases. However you proceed with it is perfectly fine with me.

Quoted 2 lines

Also, could you comment on @Stephen Hemminger latest comments,

Should

Quoted 1 line

I wait for new version? or new changes can go as separate patches.

I'm not providing a new version of this patch.

This patch was part of a series, where its rte_memcpy changes were required for the primary patch in the series [1]. The purpose of the primary patch was to tighten rte_memcpy's parameter requirements by adding access-mode attributes.

[1]:
https://patchwork.dpdk.org/project/dpdk/patch/20230116130724.50277-
[email protected]/

It was not really my intention to fix other things in the drivers I submitted patches for. That was only a positive side effect. ;-)

Quoted 8 lines

@Raslan: Also, the patch for the mlx5 driver [2] has seen no progress for a year, so I'm going to abandon it. I will resume it if I start working on the decorated rte_memcpy again. Should I change it's state to Not Applicable or something else?

[2]:
https://patchwork.dpdk.org/project/dpdk/patch/20230116130724.50277-
[email protected]/

I think I might have forgotten it for some reason,
I can pick it still as I can see it's still applicable I will take it to next-net-mlx directly,

Kindest regards
Raslan Darawsheh

#43 lore raw

Re: [PATCH v9] net/bnx2x: fix warnings about rte_memcpy lengths

In reply to Morten Brørup

drivers/net/bnx2x/bnx2x_stats.c

Quoted 44 lines · On Fri, 23 Feb 2024 15:00:56 +0100 Morten Brørup <[email protected]>…

Bugfix: The vlan in the bulletin does not contain a VLAN header, only the VLAN ID, so only copy 2 byte, not 4. The target structure has padding after the field, so copying 2 byte too many is effectively harmless. There is no need to backport this patch.

Use RTE_PTR_ADD where copying arrays to the offset of a first field in a structure holding multiple fields, to avoid compiler warnings with decorated rte_memcpy.

Bugzilla ID: 1146

Fixes 540a211084a7695a1c7bc43068934c140d6989be ("bnx2x: driver core")

---
v9:
* Fix checkpatch warning about spaces.
v8:
* Use memcpy instead of rte_memcpy in slow path. (Stephen Hemminger) v7:
* No changes.
v6:
* Add Fixes to patch description.
* Fix checkpatch warnings.
v5:
* No changes.
v4:
* Type casting did not fix the warnings, so use RTE_PTR_ADD instead. v3:
* First patch in series.

---
 drivers/net/bnx2x/bnx2x_stats.c | 14 ++++++++------
 drivers/net/bnx2x/bnx2x_vfpf.c  | 14 +++++++-------
 2 files changed, 15 insertions(+), 13 deletions(-)
drivers/net/bnx2x/bnx2x_stats.c +0 -0
index c07b01510a..8105375d44 100644
	}

drivers/net/bnx2x/bnx2x_stats.c bnx2x_hw_stats_update(struct bnx2x_softc *sc) · line 820

Quoted 7 lines
drivers/net/bnx2x/bnx2x_stats.c +1 -1
@@ -817,10 +817,10 @@ bnx2x_hw_stats_update(struct bnx2x_softc *sc)
 			  etherstatspktsover1522octets);
     }
 
-    rte_memcpy(old, new, sizeof(struct nig_stats));
+	memcpy(old, new, sizeof(struct nig_stats));

This could just be structure assignment which is type safe.

	*new = *old;
Quoted 62 lines
drivers/net/bnx2x/bnx2x_stats.c +6 -4
-    rte_memcpy(&(estats->rx_stat_ifhcinbadoctets_hi), &(pstats->mac_stx[1]),
-	   sizeof(struct mac_stx));
+	memcpy(RTE_PTR_ADD(estats, offsetof(struct bnx2x_eth_stats, rx_stat_ifhcinbadoctets_hi)),
+			&pstats->mac_stx[1], sizeof(struct mac_stx));
     estats->brb_drop_hi = pstats->brb_drop_hi;
     estats->brb_drop_lo = pstats->brb_drop_lo;
 
@@ -1492,9 +1492,11 @@ bnx2x_stats_init(struct bnx2x_softc *sc)
 		REG_RD(sc, NIG_REG_STAT0_BRB_TRUNCATE + port*0x38);
 	if (!CHIP_IS_E3(sc)) {
 		REG_RD_DMAE(sc, NIG_REG_STAT0_EGRESS_MAC_PKT0 + port*0x50,
-				&(sc->port.old_nig_stats.egress_mac_pkt0_lo), 2);
+				RTE_PTR_ADD(&sc->port.old_nig_stats,
+				offsetof(struct nig_stats, egress_mac_pkt0_lo)), 2);
 		REG_RD_DMAE(sc, NIG_REG_STAT0_EGRESS_MAC_PKT1 + port*0x50,
-				&(sc->port.old_nig_stats.egress_mac_pkt1_lo), 2);
+				RTE_PTR_ADD(&sc->port.old_nig_stats,
+				offsetof(struct nig_stats, egress_mac_pkt1_lo)), 2);
 	}
 
 	/* function stats */
drivers/net/bnx2x/bnx2x_vfpf.c +5 -5
index 63953c2979..5411df3a38 100644
@@ -52,9 +52,9 @@ bnx2x_check_bull(struct bnx2x_softc *sc)
 
 	/* check the mac address and VLAN and allocate memory if valid */
 	if (valid_bitmap & (1 << MAC_ADDR_VALID) && memcmp(bull->mac, sc->old_bulletin.mac, ETH_ALEN))
-		rte_memcpy(&sc->link_params.mac_addr, bull->mac, ETH_ALEN);
+		memcpy(&sc->link_params.mac_addr, bull->mac, ETH_ALEN);
 	if (valid_bitmap & (1 << VLAN_VALID))
-		rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, RTE_VLAN_HLEN);
+		memcpy(&bull->vlan, &sc->old_bulletin.vlan, sizeof(bull->vlan));
 
 	sc->old_bulletin = *bull;
 
@@ -569,7 +569,7 @@ bnx2x_vf_set_mac(struct bnx2x_softc *sc, int set)
 
 	bnx2x_check_bull(sc);
 
-	rte_memcpy(query->filters[0].mac, sc->link_params.mac_addr, ETH_ALEN);
+	memcpy(query->filters[0].mac, sc->link_params.mac_addr, ETH_ALEN);
 
 	bnx2x_add_tlv(sc, query, query->first_tlv.tl.length,
 		      BNX2X_VF_TLV_LIST_END,
@@ -583,9 +583,9 @@ bnx2x_vf_set_mac(struct bnx2x_softc *sc, int set)
 	while (BNX2X_VF_STATUS_FAILURE == reply->status &&
 			bnx2x_check_bull(sc)) {
 		/* A new mac was configured by PF for us */
-		rte_memcpy(sc->link_params.mac_addr, sc->pf2vf_bulletin->mac,
+		memcpy(sc->link_params.mac_addr, sc->pf2vf_bulletin->mac,
 				ETH_ALEN);
-		rte_memcpy(query->filters[0].mac, sc->pf2vf_bulletin->mac,
+		memcpy(query->filters[0].mac, sc->pf2vf_bulletin->mac,
 				ETH_ALEN);
 
 		rc = bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
@@ -622,10 +622,10 @@ bnx2x_vf_config_rss(struct bnx2x_softc *sc,
 		      BNX2X_VF_TLV_LIST_END,
 		      sizeof(struct channel_list_end_tlv));

drivers/net/bnx2x/bnx2x_vfpf.c bnx2x_vf_config_rss(struct bnx2x_softc *sc, · line 631

Quoted 10 lines
drivers/net/bnx2x/bnx2x_vfpf.c +2 -2
 
-	rte_memcpy(query->rss_key, params->rss_key, sizeof(params->rss_key));
+	memcpy(query->rss_key, params->rss_key, sizeof(params->rss_key));
 	query->rss_key_size = T_ETH_RSS_KEY;
 
-	rte_memcpy(query->ind_table, params->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
+	memcpy(query->ind_table, params->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
 	query->ind_table_size = T_ETH_INDIRECTION_TABLE_SIZE;
 
 	query->rss_result_mask = params->rss_result_mask;

The driver is also using rte_memcpy for 2 byte values in bnx2x.c.

Another issue is the driver is using one element array as a flexible array. A good static checker should catch this and report out of bounds access.

union bnx2x_stats_show_data {
    uint32_t op; /* ioctl sub-command */

    struct {
	uint32_t num; /* return number of stats */
	uint32_t len; /* length of each string item */
    } desc;

    /* variable length... */
    char str[1]; /* holds names of desc.num stats, each desc.len in length */

    /* variable length... */
    uint64_t stats[1]; /* holds all stats */
};
#44 lore raw

PATCH v7 3/4 net/mlx5: fix warning about rte_memcpy length

In reply to Morten Brørup

Use RTE_PTR_ADD where copying to the offset of a field in a structure holding multiple fields, to avoid compiler warnings with decorated rte_memcpy.

Fixes 16a7dbc4f69006cc1c96ca2a2c6d3e3c51a2ff50 ("net/mlx5: make flow modify action list thread safe")

---
v7:
* No changes.
v6:
* Add Fixes to patch description.
v5:
* First patch in series.

---
 drivers/net/mlx5/mlx5_flow_dv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow_dv.c +1 -1
index 62c38b87a1..dd9f5fda1a 100644
@@ -5662,7 +5662,7 @@ flow_dv_modify_create_cb(void *tool_ctx, void *cb_ctx)
 				   "cannot allocate resource memory");
 		return NULL;
 	}
-	rte_memcpy(&entry->ft_type,
+	rte_memcpy(RTE_PTR_ADD(entry, offsetof(typeof(*entry), ft_type)),
 		   RTE_PTR_ADD(ref, offsetof(typeof(*ref), ft_type)),
 		   key_len + data_len);
 	if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
Signature · 1 line
2.17.1
#45 lore raw

RE: [PATCH v7 3/4] net/mlx5: fix warning about rte_memcpy length

PING mlx5 maintainers. Care to review this minor improvement, so it can be included in 23.03?

Quoted 42 lines

From: Morten Brørup [mailto:[email protected]]
Sent: Monday, 16 January 2023 14.07

Use RTE_PTR_ADD where copying to the offset of a field in a structure holding multiple fields, to avoid compiler warnings with decorated rte_memcpy.

Fixes 16a7dbc4f69006cc1c96ca2a2c6d3e3c51a2ff50 ("net/mlx5: make flow

modify action list thread safe")
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
v7:
* No changes.
v6:
* Add Fixes to patch description.
v5:
* First patch in series.

---
 drivers/net/mlx5/mlx5_flow_dv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mlx5/mlx5_flow_dv.c +1 -1
index 62c38b87a1..dd9f5fda1a 100644
@@ -5662,7 +5662,7 @@ flow_dv_modify_create_cb(void *tool_ctx, void
 *cb_ctx)
 				   "cannot allocate resource memory");
 		return NULL;
 	}
-	rte_memcpy(&entry->ft_type,
+	rte_memcpy(RTE_PTR_ADD(entry, offsetof(typeof(*entry), ft_type)),
 		   RTE_PTR_ADD(ref, offsetof(typeof(*ref), ft_type)),
 		   key_len + data_len);

if (entry->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)
--
2.17.1

#46 lore raw

RE: [PATCH v7 3/4] net/mlx5: fix warning about rte_memcpy length

Quoted 11 lines

-----Original Message-----
From: Morten Brørup <[email protected]>
Sent: Thursday, February 9, 2023 6:54 PM
To: [email protected]; Matan Azrad <[email protected]>; Slava Ovsiienko <[email protected]>; Xueming(Steven) Li <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH v7 3/4] net/mlx5: fix warning about rte_memcpy length

Quoted 17 lines

PING mlx5 maintainers. Care to review this minor improvement, so it can be included in 23.03?

Quoted 14 lines

From: Morten Brørup [mailto:[email protected]]
Sent: Monday, 16 January 2023 14.07

Use RTE_PTR_ADD where copying to the offset of a field in a structure holding multiple fields, to avoid compiler warnings with decorated rte_memcpy.

Fixes 16a7dbc4f69006cc1c96ca2a2c6d3e3c51a2ff50 ("net/mlx5: make flow

modify action list thread safe")
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

#47 lore raw

RE: [PATCH v7 3/4] net/mlx5: fix warning about rte_memcpy length

In reply to Morten Brørup

Hi,

Quoted 15 lines

-----Original Message-----
From: Morten Brørup <[email protected]>
Sent: Monday, January 16, 2023 3:07 PM
To: [email protected]; [email protected]; [email protected]; [email protected]; Matan Azrad <[email protected]>; Slava Ovsiienko <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Morten Brørup <[email protected]>; Xueming(Steven) Li <[email protected]>
Subject: [PATCH v7 3/4] net/mlx5: fix warning about rte_memcpy length

Use RTE_PTR_ADD where copying to the offset of a field in a structure holding multiple fields, to avoid compiler warnings with decorated rte_memcpy.

Quoted 7 lines
Fixes 16a7dbc4f69006cc1c96ca2a2c6d3e3c51a2ff50 ("net/mlx5: make flow

modify action list thread safe")
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

Patch applied to next-net-mlx,

Kindest regards
Raslan Darawsheh

#48 lore raw

PATCH v7 4/4 eal: add nonnull and access function attributes

In reply to Morten Brørup

Add nonnull function attribute to help the compiler detect a NULL pointer being passed to a function not accepting NULL pointers as an argument at build time.

Add access function attributes to tell the compiler how a function accesses memory pointed to by its pointer arguments.

Add these attributes to the rte_memcpy() function, as the first in hopefully many to come.

---
v7:
* Fix indentation. (checkpatch)
v6:
* Make this the last patch in the series, putting the fixes first. (David)
* Split the generic access macro into dedicated macros per access mode. (David)
v5:
* No changes.
v4:
* No changes.
v3:
* No changes.
v2:
* Only define "nonnull" for GCC and CLANG.
* Append _param/_params to prepare for possible future attributes attached directly to the individual parameters, like __rte_unused.
* Use RTE_TOOLCHAIN_GCC instead of RTE_CC_GCC, to fix complaints about GCC_VERSION being undefined.
* Try to fix Doxygen compliants.

---
 lib/eal/arm/include/rte_memcpy_32.h |  8 +++
 lib/eal/arm/include/rte_memcpy_64.h |  6 +++
 lib/eal/include/rte_common.h        | 76 +++++++++++++++++++++++++++++
 lib/eal/ppc/include/rte_memcpy.h    |  3 ++
 lib/eal/x86/include/rte_memcpy.h    |  6 +++
 5 files changed, 99 insertions(+)
lib/eal/arm/include/rte_memcpy_32.h +8 -0
index fb3245b59c..a625a91951 100644
@@ -14,6 +14,8 @@ extern "C" {
 
 #include "generic/rte_memcpy.h"
 
+#include <rte_common.h>
+
 #ifdef RTE_ARCH_ARM_NEON_MEMCPY
 
 #ifndef __ARM_NEON
@@ -125,6 +127,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src)
 	memcpy((dst), (src), (n)) :          \
 	rte_memcpy_func((dst), (src), (n)); })
 
+__rte_nonnull_params(1, 2)
+__rte_write_only_param(1, 3)
+__rte_read_only_param(2, 3)
 static inline void *
 rte_memcpy_func(void *dst, const void *src, size_t n)
 {
@@ -290,6 +295,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src)
 	memcpy(dst, src, 256);
 }
 
+__rte_nonnull_params(1, 2)
+__rte_write_only_param(1, 3)
+__rte_read_only_param(2, 3)
 static inline void *
 rte_memcpy(void *dst, const void *src, size_t n)
 {
lib/eal/arm/include/rte_memcpy_64.h +6 -0
index 85ad587bd3..0c86237cc9 100644
@@ -282,6 +282,9 @@ void rte_memcpy_ge64(uint8_t *dst, const uint8_t *src, size_t n)
 }
 
 #if RTE_CACHE_LINE_SIZE >= 128
+__rte_nonnull_params(1, 2)
+__rte_write_only_param(1, 3)
+__rte_read_only_param(2, 3)
 static __rte_always_inline
 void *rte_memcpy(void *dst, const void *src, size_t n)
 {
@@ -303,6 +306,9 @@ void *rte_memcpy(void *dst, const void *src, size_t n)
 }
 
 #else
+__rte_nonnull_params(1, 2)
+__rte_write_only_param(1, 3)
+__rte_read_only_param(2, 3)
 static __rte_always_inline
 void *rte_memcpy(void *dst, const void *src, size_t n)
 {
lib/eal/include/rte_common.h +76 -0

82 lines not on this page · raw message

lib/eal/ppc/include/rte_memcpy.h +3 -0
index 6f388c0234..c36869a414 100644
@@ -84,6 +84,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src)
 	memcpy((dst), (src), (n)) :          \
 	rte_memcpy_func((dst), (src), (n)); })
 
+__rte_nonnull_params(1, 2)
+__rte_write_only_param(1, 3)
+__rte_read_only_param(2, 3)
 static inline void *
 rte_memcpy_func(void *dst, const void *src, size_t n)
 {
lib/eal/x86/include/rte_memcpy.h +6 -0
index d4d7a5cfc8..ee543aa37d 100644
@@ -42,6 +42,9 @@ extern "C" {
  * @return
  *   Pointer to the destination data.
  */
+__rte_nonnull_params(1, 2)
+__rte_write_only_param(1, 3)
+__rte_read_only_param(2, 3)
 static __rte_always_inline void *
 rte_memcpy(void *dst, const void *src, size_t n);
 
@@ -859,6 +862,9 @@ rte_memcpy_aligned(void *dst, const void *src, size_t n)
 	return ret;
 }
 
+__rte_nonnull_params(1, 2)
+__rte_write_only_param(1, 3)
+__rte_read_only_param(2, 3)
 static __rte_always_inline void *
 rte_memcpy(void *dst, const void *src, size_t n)
 {
Signature · 1 line
2.17.1
#49 lore raw
Quoted 110 lines · Morten Brørup

Add nonnull function attribute to help the compiler detect a NULL pointer being passed to a function not accepting NULL pointers as an argument at build time.

Add access function attributes to tell the compiler how a function accesses memory pointed to by its pointer arguments.

Add these attributes to the rte_memcpy() function, as the first in hopefully many to come.

---
v7:
* Fix indentation. (checkpatch)
v6:
* Make this the last patch in the series, putting the fixes first. (David)
* Split the generic access macro into dedicated macros per access mode. (David)
v5:
* No changes.
v4:
* No changes.
v3:
* No changes.
v2:
* Only define "nonnull" for GCC and CLANG.
* Append _param/_params to prepare for possible future attributes attached directly to the individual parameters, like __rte_unused.
* Use RTE_TOOLCHAIN_GCC instead of RTE_CC_GCC, to fix complaints about GCC_VERSION being undefined.
* Try to fix Doxygen compliants.

---
 lib/eal/arm/include/rte_memcpy_32.h |  8 +++
 lib/eal/arm/include/rte_memcpy_64.h |  6 +++
 lib/eal/include/rte_common.h        | 76 +++++++++++++++++++++++++++++
 lib/eal/ppc/include/rte_memcpy.h    |  3 ++
 lib/eal/x86/include/rte_memcpy.h    |  6 +++
 5 files changed, 99 insertions(+)
lib/eal/arm/include/rte_memcpy_32.h +8 -0
index fb3245b59c..a625a91951 100644
@@ -14,6 +14,8 @@ extern "C" {
 
 #include "generic/rte_memcpy.h"
 
+#include <rte_common.h>
+
 #ifdef RTE_ARCH_ARM_NEON_MEMCPY
 
 #ifndef __ARM_NEON
@@ -125,6 +127,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src)
 	memcpy((dst), (src), (n)) :          \
 	rte_memcpy_func((dst), (src), (n)); })
 
+__rte_nonnull_params(1, 2)
+__rte_write_only_param(1, 3)
+__rte_read_only_param(2, 3)
 static inline void *
 rte_memcpy_func(void *dst, const void *src, size_t n)
 {
@@ -290,6 +295,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src)
 	memcpy(dst, src, 256);
 }
 
+__rte_nonnull_params(1, 2)
+__rte_write_only_param(1, 3)
+__rte_read_only_param(2, 3)
 static inline void *
 rte_memcpy(void *dst, const void *src, size_t n)
 {
lib/eal/arm/include/rte_memcpy_64.h +6 -0
index 85ad587bd3..0c86237cc9 100644
@@ -282,6 +282,9 @@ void rte_memcpy_ge64(uint8_t *dst, const uint8_t *src, size_t n)
 }
 
 #if RTE_CACHE_LINE_SIZE >= 128
+__rte_nonnull_params(1, 2)
+__rte_write_only_param(1, 3)
+__rte_read_only_param(2, 3)
 static __rte_always_inline
 void *rte_memcpy(void *dst, const void *src, size_t n)
 {
@@ -303,6 +306,9 @@ void *rte_memcpy(void *dst, const void *src, size_t n)
 }
 
 #else
+__rte_nonnull_params(1, 2)
+__rte_write_only_param(1, 3)
+__rte_read_only_param(2, 3)
 static __rte_always_inline
 void *rte_memcpy(void *dst, const void *src, size_t n)
 {
lib/eal/include/rte_common.h +3 -0
index 15765b408d..c9cd2c7496 100644
@@ -149,6 +149,82 @@ typedef uint16_t unaligned_uint16_t;
 	__attribute__((format(printf, format_index, first_arg)))
 #endif
 
+/**
+ * Tells compiler that the pointer arguments must be non-null.
+ *

lib/eal/include/rte_common.h typedef uint16_t unaligned_uint16_t; · line 164

Quoted 10 lines
lib/eal/include/rte_common.h +10 -0
+ * @param ...
+ *    Comma separated list of parameter indexes of pointer arguments.
+ */
+#if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG)
+#define __rte_nonnull_params(...) \
+	__attribute__((nonnull(__VA_ARGS__)))
+#else
+#define __rte_nonnull_params(...)
+#endif
+

What do you think to have a namespace for macros like '__rte_param_xxx', so name macros as:
__rte_param_nonull
__rte_param_read_only
__rte_param_write_only

No strong opinion, it just feels tidier this way

lib/eal/include/rte_common.h typedef uint16_t unaligned_uint16_t; · line 172

Quoted 8 lines
lib/eal/include/rte_common.h +8 -0
+/**
+ * Tells compiler that the memory pointed to by a pointer argument
+ * is only read, not written to, by the function.
+ * It might not be accessed at all.
+ *
+ * @param ...
+ *    Parameter index of pointer argument.
+ *    Optionally followeded by comma and parameter index of size argument.

s/followeded/followed/

multiple occurrences below

Quoted 19 lines
lib/eal/include/rte_common.h +19 -0
+ */
+#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >= 100400)
+#define __rte_read_only_param(...) \
+	__attribute__((access(read_only, __VA_ARGS__)))
+#else
+#define __rte_read_only_param(...)
+#endif
+
+/**
+ * Tells compiler that the memory pointed to by a pointer argument
+ * is only written to, not read, by the function.
+ * It might not be accessed at all.
+ *
+ * @param ...
+ *    Parameter index of pointer argument.
+ *    Optionally followeded by comma and parameter index of size argument.
+ */
+#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >= 100400)
+#define __rte_write_only_param(...) \

lib/eal/include/rte_common.h typedef uint16_t unaligned_uint16_t; · line 201

Quoted 10 lines
lib/eal/include/rte_common.h +10 -0
+	__attribute__((access(write_only, __VA_ARGS__)))
+#else
+#define __rte_write_only_param(...)
+#endif
+
+/**
+ * Tells compiler that the memory pointed to by a pointer argument
+ * is both read and written to by the function.
+ * It might not be read, written to, or accessed at all.
+ *

What I understand is difference between 'read_write' access mode and 'nonnull' attribute is,
'read_write' access mode additionally checks that variable is initialized before used in this function.
Should we document this detail, although it is gcc manual I think it helps to clarify here.

Quoted 67 lines
lib/eal/include/rte_common.h +26 -0
+ * @param ...
+ *    Parameter index of pointer argument.
+ *    Optionally followeded by comma and parameter index of size argument.
+ */
+#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >= 100400)
+#define __rte_read_write_param(...) \
+	__attribute__((access(read_write, __VA_ARGS__)))
+#else
+#define __rte_read_write_param(...)
+#endif
+
+/**
+ * Tells compiler that the memory pointed to by a pointer argument
+ * is not accessed by the function.
+ *
+ * @param ...
+ *    Parameter index of pointer argument.
+ *    Optionally followeded by comma and parameter index of size argument.
+ */
+#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >= 100400)
+#define __rte_no_access_param(...) \
+	__attribute__((access(none, __VA_ARGS__)))
+#else
+#define __rte_no_access_param(...)
+#endif
+
 /**
  * Tells compiler that the function returns a value that points to
  * memory, where the size is given by the one or two arguments.
lib/eal/ppc/include/rte_memcpy.h +3 -0
index 6f388c0234..c36869a414 100644
@@ -84,6 +84,9 @@ rte_mov256(uint8_t *dst, const uint8_t *src)
 	memcpy((dst), (src), (n)) :          \
 	rte_memcpy_func((dst), (src), (n)); })
 
+__rte_nonnull_params(1, 2)
+__rte_write_only_param(1, 3)
+__rte_read_only_param(2, 3)
 static inline void *
 rte_memcpy_func(void *dst, const void *src, size_t n)
 {
lib/eal/x86/include/rte_memcpy.h +6 -0
index d4d7a5cfc8..ee543aa37d 100644
@@ -42,6 +42,9 @@ extern "C" {
  * @return
  *   Pointer to the destination data.
  */
+__rte_nonnull_params(1, 2)
+__rte_write_only_param(1, 3)
+__rte_read_only_param(2, 3)
 static __rte_always_inline void *
 rte_memcpy(void *dst, const void *src, size_t n);
 
@@ -859,6 +862,9 @@ rte_memcpy_aligned(void *dst, const void *src, size_t n)
 	return ret;
 }
 
+__rte_nonnull_params(1, 2)
+__rte_write_only_param(1, 3)
+__rte_read_only_param(2, 3)
 static __rte_always_inline void *
 rte_memcpy(void *dst, const void *src, size_t n)
 {
#50 lore raw
Quoted 18 lines

From: Ferruh Yigit [mailto:[email protected]]
Sent: Monday, 16 January 2023 18.02

Quoted 14 lines · Morten Brørup

Add nonnull function attribute to help the compiler detect a NULL pointer being passed to a function not accepting NULL pointers as an argument at build time.

Add access function attributes to tell the compiler how a function accesses memory pointed to by its pointer arguments.

Add these attributes to the rte_memcpy() function, as the first in hopefully many to come.

---

[...]

Quoted 22 lines
Quoted 5 lines

+/**
+ * Tells compiler that the pointer arguments must be non-null.
+ *
+ * @param ...
+ * Comma separated list of parameter indexes of pointer

arguments.

lib/eal/include/rte_common.h typedef uint16_t unaligned_uint16_t; · line 164

Quoted 8 lines

+ */

lib/eal/include/rte_common.h +7 -0
+#if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG)
+#define __rte_nonnull_params(...) \
+	__attribute__((nonnull(__VA_ARGS__)))
+#else
+#define __rte_nonnull_params(...)
+#endif
+

What do you think to have a namespace for macros like '__rte_param_xxx',
so name macros as:
__rte_param_nonull
__rte_param_read_only
__rte_param_write_only

Quoted 1 line

No strong opinion, it just feels tidier this way

Being a proponent of the world_country_city naming scheme myself, I would usually agree with this proposal.

However, in the future, we might add macros without _param for use along with the function parameters, e.g.:

int foo(int bar __rte_nonnull __rte_read_only);

So I decided for this order in the names (treating nonnull/access_mode as "country" and param/params as "city"), also somewhat looking at the __rte_deprecated and __rte_deprecated_msg(msg) macros.

I have no strong preference either, so if anyone does, please speak up.

Slightly related, also note this:

The nonnull macro is plural (_params), because it can take multiple pointer parameter indexes.
The access mode macros are singular (_param), because they only take one pointer parameter index, and the optional size parameter index.

I considered splitting up the access mode macros even more, making two variants of each, e.g. __rte_read_only_param(ptr_index) and __rte_read_only_param_size(ptr_index, size_index), but concluded that it would be excruciatingly verbose. The only purpose would be to reduce the risk of using them incorrectly. I decided against it, thinking that any developer clever enough to use these macros is also clever enough to understand how to use them (or at least read their parameter descriptions to learn how).

Quoted 9 lines
Quoted 9 lines

+/**
+ * Tells compiler that the memory pointed to by a pointer argument
+ * is only read, not written to, by the function.
+ * It might not be accessed at all.
+ *
+ * @param ...
+ * Parameter index of pointer argument.
+ * Optionally followeded by comma and parameter index of size

Quoted 5 lines

argument.

s/followeded/followed/

multiple occurrences below

Good catch. Will fix this repeated typo in the next version.

Quoted 30 lines
Quoted 7 lines

+ */

lib/eal/include/rte_common.h +5 -0
+#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >= 100400)
+#define __rte_read_only_param(...) \
+	__attribute__((access(read_only, __VA_ARGS__)))
+#else
+#define __rte_read_only_param(...)

lib/eal/include/rte_common.h typedef uint16_t unaligned_uint16_t;

Quoted 10 lines
lib/eal/include/rte_common.h +10 -0
+#endif
+
+/**
+ * Tells compiler that the memory pointed to by a pointer argument
+ * is only written to, not read, by the function.
+ * It might not be accessed at all.
+ *
+ * @param ...
+ *    Parameter index of pointer argument.
+ *    Optionally followeded by comma and parameter index of size

argument.

Quoted 12 lines

+ */

lib/eal/include/rte_common.h +11 -0
+#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >= 100400)
+#define __rte_write_only_param(...) \
+	__attribute__((access(write_only, __VA_ARGS__)))
+#else
+#define __rte_write_only_param(...)
+#endif
+
+/**
+ * Tells compiler that the memory pointed to by a pointer argument
+ * is both read and written to by the function.
+ * It might not be read, written to, or accessed at all.
Quoted 8 lines
Quoted 1 line

+ *

What I understand is difference between 'read_write' access mode and 'nonnull' attribute is,
'read_write' access mode additionally checks that variable is initialized before used in this function.
Should we document this detail, although it is gcc manual I think it helps to clarify here.

This specific behavior might be compiler dependent, so I prefer not to add it to the description.

In the same context, I added "It might not be accessed at all." (and similar) to the macro descriptions for clarification. This leaves some flexibility for the compiler. It also reflects the behavior of GCC, which inspired me to add it. Just like __attribute__((__unused__)) only means that a variable might be unused, it does not mean that it is definitely unused.

Quoted 29 lines
Quoted 4 lines

+ * @param ...
+ * Parameter index of pointer argument.
+ * Optionally followeded by comma and parameter index of size

argument.

Quoted 5 lines

+ */

lib/eal/include/rte_common.h +4 -0
+#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >= 100400)
+#define __rte_read_write_param(...) \
+	__attribute__((access(read_write, __VA_ARGS__)))
+#else

lib/eal/include/rte_common.h typedef uint16_t unaligned_uint16_t;

Quoted 10 lines
lib/eal/include/rte_common.h +10 -0
+#define __rte_read_write_param(...)
+#endif
+
+/**
+ * Tells compiler that the memory pointed to by a pointer argument
+ * is not accessed by the function.
+ *
+ * @param ...
+ *    Parameter index of pointer argument.
+ *    Optionally followeded by comma and parameter index of size

argument.

Quoted 8 lines

+ */

lib/eal/include/rte_common.h +7 -0
+#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >= 100400)
+#define __rte_no_access_param(...) \
+	__attribute__((access(none, __VA_ARGS__)))
+#else
+#define __rte_no_access_param(...)
+#endif
+
#51 lore raw
Quoted 53 lines · Morten Brørup
Quoted 18 lines

From: Ferruh Yigit [mailto:[email protected]]
Sent: Monday, 16 January 2023 18.02

Quoted 14 lines · Morten Brørup

Add nonnull function attribute to help the compiler detect a NULL pointer being passed to a function not accepting NULL pointers as an argument at build time.

Add access function attributes to tell the compiler how a function accesses memory pointed to by its pointer arguments.

Add these attributes to the rte_memcpy() function, as the first in hopefully many to come.

---

[...]

Quoted 22 lines
Quoted 5 lines

+/**
+ * Tells compiler that the pointer arguments must be non-null.
+ *
+ * @param ...
+ * Comma separated list of parameter indexes of pointer

arguments.

lib/eal/include/rte_common.h typedef uint16_t unaligned_uint16_t; · line 164

Quoted 8 lines

+ */

lib/eal/include/rte_common.h +7 -0
+#if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG)
+#define __rte_nonnull_params(...) \
+	__attribute__((nonnull(__VA_ARGS__)))
+#else
+#define __rte_nonnull_params(...)
+#endif
+

What do you think to have a namespace for macros like '__rte_param_xxx',
so name macros as:
__rte_param_nonull
__rte_param_read_only
__rte_param_write_only

Quoted 1 line

No strong opinion, it just feels tidier this way

Being a proponent of the world_country_city naming scheme myself, I would usually agree with this proposal.

However, in the future, we might add macros without _param for use along with the function parameters, e.g.:

int foo(int bar __rte_nonnull __rte_read_only);

So I decided for this order in the names (treating nonnull/access_mode as "country" and param/params as "city"), also somewhat looking at the __rte_deprecated and __rte_deprecated_msg(msg) macros.

Quoted 9 lines

I have no strong preference either, so if anyone does, please speak up.

Slightly related, also note this:

The nonnull macro is plural (_params), because it can take multiple pointer parameter indexes.
The access mode macros are singular (_param), because they only take one pointer parameter index, and the optional size parameter index.

I considered splitting up the access mode macros even more, making two variants of each, e.g. __rte_read_only_param(ptr_index) and __rte_read_only_param_size(ptr_index, size_index), but concluded that it would be excruciatingly verbose. The only purpose would be to reduce the risk of using them incorrectly. I decided against it, thinking that any developer clever enough to use these macros is also clever enough to understand how to use them (or at least read their parameter descriptions to learn how).

microsoft also has a tool & annotation vehicle for this type of stuff. this discussion has caused me to wonder what happens if we would like to add additional annotations for other tools. just load on the annotations and expand them empty conditionally?

https://learn.microsoft.com/en-us/cpp/code-quality/using-sal-annotations-to-reduce-c-cpp-code-defects?view=msvc-170

anyway, just a thought. no serious response required here.

#52 lore raw

+To: Thomas & David, you probably have some opinions on this too!

Quoted 92 lines

From: Tyler Retzlaff [mailto:[email protected]]
Sent: Tuesday, 17 January 2023 22.17

Quoted 6 lines · Morten Brørup
Quoted 6 lines

From: Ferruh Yigit [mailto:[email protected]]
Sent: Monday, 16 January 2023 18.02

Quoted 2 lines · Morten Brørup

Add nonnull function attribute to help the compiler detect a NULL pointer being passed to a function not accepting NULL pointers as

an

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

argument at build time.

Add access function attributes to tell the compiler how a

function

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

accesses memory pointed to by its pointer arguments.

Add these attributes to the rte_memcpy() function, as the first

in

Quoted 31 lines
Quoted 6 lines
Quoted 6 lines

hopefully many to come.

---

[...]

Quoted 22 lines
Quoted 5 lines

+/**
+ * Tells compiler that the pointer arguments must be non-null.
+ *
+ * @param ...
+ * Comma separated list of parameter indexes of pointer

arguments.

lib/eal/include/rte_common.h typedef uint16_t unaligned_uint16_t; · line 164

Quoted 8 lines

+ */

lib/eal/include/rte_common.h +7 -0
+#if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG)
+#define __rte_nonnull_params(...) \
+	__attribute__((nonnull(__VA_ARGS__)))
+#else
+#define __rte_nonnull_params(...)
+#endif
+

What do you think to have a namespace for macros like '__rte_param_xxx',
so name macros as:
__rte_param_nonull
__rte_param_read_only
__rte_param_write_only

Quoted 3 lines
Quoted 1 line

No strong opinion, it just feels tidier this way

Being a proponent of the world_country_city naming scheme myself, I

would usually agree with this proposal.

Quoted 2 lines

However, in the future, we might add macros without _param for use

along with the function parameters, e.g.:

Quoted 4 lines

int foo(int bar __rte_nonnull __rte_read_only);

So I decided for this order in the names (treating

nonnull/access_mode as "country" and param/params as "city"), also somewhat looking at the __rte_deprecated and __rte_deprecated_msg(msg) macros.

Quoted 2 lines

I have no strong preference either, so if anyone does, please speak

up.

Quoted 4 lines

Slightly related, also note this:

The nonnull macro is plural (_params), because it can take multiple

pointer parameter indexes.

Quoted 1 line

The access mode macros are singular (_param), because they only take

one pointer parameter index, and the optional size parameter index.

Quoted 2 lines

I considered splitting up the access mode macros even more, making

two variants of each, e.g. __rte_read_only_param(ptr_index) and __rte_read_only_param_size(ptr_index, size_index), but concluded that it would be excruciatingly verbose. The only purpose would be to reduce the risk of using them incorrectly. I decided against it, thinking that any developer clever enough to use these macros is also clever enough to understand how to use them (or at least read their parameter descriptions to learn how).

Quoted 1 line

microsoft also has a tool & annotation vehicle for this type of stuff. this discussion has caused me to wonder what happens if we would like to
add additional annotations for other tools. just load on the annotations
and expand them empty conditionally?

Quoted 4 lines

https://learn.microsoft.com/en-us/cpp/code-quality/using-sal-
annotations-to-reduce-c-cpp-code-defects?view=msvc-170

anyway, just a thought. no serious response required here.

Excellent input, Tyler!

If we want DPDK to be considered truly cross-platform, and not treat non-Linux/non-GCC as second class citizens, we need to discuss this.

Microsoft's Source Code Annotation Language (SAL) seems very good, based on its finer granularity than GCC's attributes (which in comparison seem added as an afterthought, not cleanly structured like SAL). I have only skimmed the documentation, but that is my immediate impression of it.

SAL uses a completely different syntax than GCC attributes, and Microsoft happens to also use memcpy() as an example in the documentation referred to:

void * memcpy(
_Out_writes_bytes_all_(count) void *dest,
_In_reads_bytes_(count) const void *src,
size_t count
);

Going back to how we can handle this in DPDK, we can either:

1. Not annotate the functions at all, and miss out on finding the errors for us.

2. Invent our own language (or find something existing) for function headers, and use a parser to convert them to compiler specific C/C++ headers when building the code.

3a. Keep loading on attributes, with empty macros for unsupported compilers.

3b. Keep loading on attributes, with empty macros for unsupported compilers. But limit ourselves to GCC/Clang style attributes.

3c. Keep loading on attributes, with empty macros for unsupported compilers. But limit ourselves to Microsoft SAL style attributes.

3d. Keep loading on attributes, with empty macros for unsupported compilers. But limit ourselves to the most relevant attributes, using performance and/or bug detection as criteria when considering relevance.

I am strongly against both 1 and 2.

If bug detection is the primary driver, we could stick with either 3b or 3c (i.e. only target one specific build environment) and rely on the DPDK CI for detecting bugs. But then application developers would not benefit, because they don't run their code through the DPDK CI. So I am also against this.

I think 3d (keep loading on attributes, but only the most relevant ones) is the best choice.

GCC/Clang style attributes are already supported as macros prefixed by __rte, so let's not change the way we do that.

Regarding the Microsoft SAL, I suppose Microsoft already chose annotation names to avoid collisions, so we could consider using those exact names (i.e. without __rte prefix), and define empty macros for non-Microsoft compilers. This would allow using Microsoft SAL annotations directly in the DPDK code.

#53 lore raw
Quoted 67 lines · On Wed, 18 Jan 2023 09:31:42 +0100 Morten Brørup <[email protected]>…
Quoted 32 lines
Quoted 1 line

So I decided for this order in the names (treating

nonnull/access_mode as "country" and param/params as "city"), also somewhat looking at the __rte_deprecated and __rte_deprecated_msg(msg) macros.

Quoted 2 lines

I have no strong preference either, so if anyone does, please speak

up.

Quoted 4 lines

Slightly related, also note this:

The nonnull macro is plural (_params), because it can take multiple

pointer parameter indexes.

Quoted 1 line

The access mode macros are singular (_param), because they only take

one pointer parameter index, and the optional size parameter index.

Quoted 2 lines

I considered splitting up the access mode macros even more, making

two variants of each, e.g. __rte_read_only_param(ptr_index) and __rte_read_only_param_size(ptr_index, size_index), but concluded that it would be excruciatingly verbose. The only purpose would be to reduce the risk of using them incorrectly. I decided against it, thinking that any developer clever enough to use these macros is also clever enough to understand how to use them (or at least read their parameter descriptions to learn how).

Quoted 1 line

microsoft also has a tool & annotation vehicle for this type of stuff. this discussion has caused me to wonder what happens if we would like to
add additional annotations for other tools. just load on the annotations
and expand them empty conditionally?

Quoted 4 lines

https://learn.microsoft.com/en-us/cpp/code-quality/using-sal-
annotations-to-reduce-c-cpp-code-defects?view=msvc-170

anyway, just a thought. no serious response required here.

Excellent input, Tyler!

If we want DPDK to be considered truly cross-platform, and not treat non-Linux/non-GCC as second class citizens, we need to discuss this.

Microsoft's Source Code Annotation Language (SAL) seems very good, based on its finer granularity than GCC's attributes (which in comparison seem added as an afterthought, not cleanly structured like SAL). I have only skimmed the documentation, but that is my immediate impression of it.

SAL uses a completely different syntax than GCC attributes, and Microsoft happens to also use memcpy() as an example in the documentation referred to:

void * memcpy(
_Out_writes_bytes_all_(count) void *dest,
_In_reads_bytes_(count) const void *src,
size_t count
);

Going back to how we can handle this in DPDK, we can either:

1. Not annotate the functions at all, and miss out on finding the errors for us.

2. Invent our own language (or find something existing) for function headers, and use a parser to convert them to compiler specific C/C++ headers when building the code.

3a. Keep loading on attributes, with empty macros for unsupported compilers.

3b. Keep loading on attributes, with empty macros for unsupported compilers. But limit ourselves to GCC/Clang style attributes.

3c. Keep loading on attributes, with empty macros for unsupported compilers. But limit ourselves to Microsoft SAL style attributes.

3d. Keep loading on attributes, with empty macros for unsupported compilers. But limit ourselves to the most relevant attributes, using performance and/or bug detection as criteria when considering relevance.

I am strongly against both 1 and 2.

Quoted 7 lines

If bug detection is the primary driver, we could stick with either 3b or 3c (i.e. only target one specific build environment) and rely on the DPDK CI for detecting bugs. But then application developers would not benefit, because they don't run their code through the DPDK CI. So I am also against this.

I think 3d (keep loading on attributes, but only the most relevant ones) is the best choice.

GCC/Clang style attributes are already supported as macros prefixed by __rte, so let's not change the way we do that.

Regarding the Microsoft SAL, I suppose Microsoft already chose annotation names to avoid collisions, so we could consider using those exact names (i.e. without __rte prefix), and define empty macros for non-Microsoft compilers. This would allow using Microsoft SAL annotations directly in the DPDK code.

Looks like SAL was developed outside of all the other compilers, and probably pre-dates it. Having had to deal with it, my impression was it that it became a nuisance on a large code base. The value starts to drop off fast. And any annotation is only as good as the automated tooling that supports it. Doing more annotation than the CI system uses is worthless.

It would be good if there was a common set support by VS, Gcc, and Clang with DPDK macros for that. We already have annotations for format and allocations.

#54 lore raw
In reply to Morten Brørup
Quoted 114 lines · Morten Brørup

+To: Thomas & David, you probably have some opinions on this too!

Quoted 92 lines

From: Tyler Retzlaff [mailto:[email protected]]
Sent: Tuesday, 17 January 2023 22.17

Quoted 6 lines · Morten Brørup
Quoted 6 lines

From: Ferruh Yigit [mailto:[email protected]]
Sent: Monday, 16 January 2023 18.02

Quoted 2 lines · Morten Brørup

Add nonnull function attribute to help the compiler detect a NULL pointer being passed to a function not accepting NULL pointers as

an

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

argument at build time.

Add access function attributes to tell the compiler how a

function

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

accesses memory pointed to by its pointer arguments.

Add these attributes to the rte_memcpy() function, as the first

in

Quoted 31 lines
Quoted 6 lines
Quoted 6 lines

hopefully many to come.

---

[...]

Quoted 22 lines
Quoted 5 lines

+/**
+ * Tells compiler that the pointer arguments must be non-null.
+ *
+ * @param ...
+ * Comma separated list of parameter indexes of pointer

arguments.

lib/eal/include/rte_common.h typedef uint16_t unaligned_uint16_t; · line 164

Quoted 8 lines

+ */

lib/eal/include/rte_common.h +7 -0
+#if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG)
+#define __rte_nonnull_params(...) \
+       __attribute__((nonnull(__VA_ARGS__)))
+#else
+#define __rte_nonnull_params(...)
+#endif
+

What do you think to have a namespace for macros like '__rte_param_xxx',
so name macros as:
__rte_param_nonull
__rte_param_read_only
__rte_param_write_only

Quoted 3 lines
Quoted 1 line

No strong opinion, it just feels tidier this way

Being a proponent of the world_country_city naming scheme myself, I

would usually agree with this proposal.

Quoted 2 lines

However, in the future, we might add macros without _param for use

along with the function parameters, e.g.:

Quoted 4 lines

int foo(int bar __rte_nonnull __rte_read_only);

So I decided for this order in the names (treating

nonnull/access_mode as "country" and param/params as "city"), also somewhat looking at the __rte_deprecated and __rte_deprecated_msg(msg) macros.

Quoted 2 lines

I have no strong preference either, so if anyone does, please speak

up.

Quoted 4 lines

Slightly related, also note this:

The nonnull macro is plural (_params), because it can take multiple

pointer parameter indexes.

Quoted 1 line

The access mode macros are singular (_param), because they only take

one pointer parameter index, and the optional size parameter index.

Quoted 2 lines

I considered splitting up the access mode macros even more, making

two variants of each, e.g. __rte_read_only_param(ptr_index) and __rte_read_only_param_size(ptr_index, size_index), but concluded that it would be excruciatingly verbose. The only purpose would be to reduce the risk of using them incorrectly. I decided against it, thinking that any developer clever enough to use these macros is also clever enough to understand how to use them (or at least read their parameter descriptions to learn how).

Quoted 1 line

microsoft also has a tool & annotation vehicle for this type of stuff. this discussion has caused me to wonder what happens if we would like to
add additional annotations for other tools. just load on the annotations
and expand them empty conditionally?

Quoted 4 lines

https://learn.microsoft.com/en-us/cpp/code-quality/using-sal-
annotations-to-reduce-c-cpp-code-defects?view=msvc-170

anyway, just a thought. no serious response required here.

Excellent input, Tyler!

If we want DPDK to be considered truly cross-platform, and not treat non-Linux/non-GCC as second class citizens, we need to discuss this.

Microsoft's Source Code Annotation Language (SAL) seems very good, based on its finer granularity than GCC's attributes (which in comparison seem added as an afterthought, not cleanly structured like SAL). I have only skimmed the documentation, but that is my immediate impression of it.

SAL uses a completely different syntax than GCC attributes, and Microsoft happens to also use memcpy() as an example in the documentation referred to:

void * memcpy(
_Out_writes_bytes_all_(count) void *dest,
_In_reads_bytes_(count) const void *src,
size_t count
);

Quoted 3 lines

Going back to how we can handle this in DPDK, we can either:

1. Not annotate the functions at all, and miss out on finding the errors for us.

Seeing how clang safety checks helped me catch bugs, that would be a pity.

Quoted 2 lines

2. Invent our own language (or find something existing) for function headers, and use a parser to convert them to compiler specific C/C++ headers when building the code.

Argh, no.

Quoted 11 lines

3a. Keep loading on attributes, with empty macros for unsupported compilers.

3b. Keep loading on attributes, with empty macros for unsupported compilers. But limit ourselves to GCC/Clang style attributes.

3c. Keep loading on attributes, with empty macros for unsupported compilers. But limit ourselves to Microsoft SAL style attributes.

3d. Keep loading on attributes, with empty macros for unsupported compilers. But limit ourselves to the most relevant attributes, using performance and/or bug detection as criteria when considering relevance.

I am strongly against both 1 and 2.

Quoted 8 lines

If bug detection is the primary driver, we could stick with either 3b or 3c (i.e. only target one specific build environment) and rely on the DPDK CI for detecting bugs. But then application developers would not benefit, because they don't run their code through the DPDK CI. So I am also against this.

I think 3d (keep loading on attributes, but only the most relevant ones) is the best choice.

GCC/Clang style attributes are already supported as macros prefixed by __rte, so let's not change the way we do that.

Regarding the Microsoft SAL, I suppose Microsoft already chose annotation names to avoid collisions, so we could consider using those exact names (i.e. without __rte prefix), and define empty macros for non-Microsoft compilers. This would allow using Microsoft SAL annotations directly in the DPDK code.

I have a bit of trouble understanding the difference between 3a and 3d.. 3a would be about accepting any annotation?

3d is the best option as it is not changing anything to what we were doing so far: we evaluate the pros and cons of each annotations/tools, case per case.

Signature · 1 line
David Marchand
#55 lore raw
Quoted 128 lines

From: David Marchand [mailto:[email protected]]
Sent: Tuesday, 31 January 2023 12.15

Quoted 12 lines · Morten Brørup

+To: Thomas & David, you probably have some opinions on this too!

Quoted 9 lines

From: Tyler Retzlaff [mailto:[email protected]]
Sent: Tuesday, 17 January 2023 22.17

Quoted 5 lines · Morten Brørup
Quoted 5 lines

From: Ferruh Yigit [mailto:[email protected]]
Sent: Monday, 16 January 2023 18.02

Quoted 1 line · Morten Brørup

Add nonnull function attribute to help the compiler detect a

NULL

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

pointer being passed to a function not accepting NULL

pointers as

Quoted 8 lines
Quoted 8 lines

an

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

argument at build time.

Add access function attributes to tell the compiler how a

function

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

accesses memory pointed to by its pointer arguments.

Add these attributes to the rte_memcpy() function, as the

first

Quoted 8 lines
Quoted 8 lines

in

Quoted 7 lines
Quoted 6 lines
Quoted 6 lines

hopefully many to come.

---

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

[...]

Quoted 2 lines
Quoted 2 lines

+/**
+ * Tells compiler that the pointer arguments must be non-

null.

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 3 lines

+ *
+ * @param ...
+ * Comma separated list of parameter indexes of pointer

arguments.

lib/eal/include/rte_common.h typedef uint16_t unaligned_uint16_t; · line 164

Quoted 8 lines

+ */

lib/eal/include/rte_common.h +7 -0
+#if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG)
+#define __rte_nonnull_params(...) \
+       __attribute__((nonnull(__VA_ARGS__)))
+#else
+#define __rte_nonnull_params(...)
+#endif
+

What do you think to have a namespace for macros like '__rte_param_xxx',
so name macros as:
__rte_param_nonull
__rte_param_read_only
__rte_param_write_only

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

No strong opinion, it just feels tidier this way

Being a proponent of the world_country_city naming scheme myself,

I

Quoted 3 lines
Quoted 3 lines

would usually agree with this proposal.

Quoted 2 lines

However, in the future, we might add macros without _param for

use

Quoted 7 lines
Quoted 7 lines

along with the function parameters, e.g.:

Quoted 4 lines

int foo(int bar __rte_nonnull __rte_read_only);

So I decided for this order in the names (treating

nonnull/access_mode as "country" and param/params as "city"), also somewhat looking at the __rte_deprecated and

__rte_deprecated_msg(msg)

Quoted 3 lines
Quoted 3 lines

macros.

Quoted 2 lines

I have no strong preference either, so if anyone does, please

speak

Quoted 5 lines
Quoted 5 lines

up.

Quoted 4 lines

Slightly related, also note this:

The nonnull macro is plural (_params), because it can take

multiple

Quoted 2 lines
Quoted 2 lines

pointer parameter indexes.

Quoted 1 line

The access mode macros are singular (_param), because they only

take

Quoted 3 lines
Quoted 3 lines

one pointer parameter index, and the optional size parameter index.

Quoted 2 lines

I considered splitting up the access mode macros even more,

making

Quoted 2 lines
Quoted 2 lines

two variants of each, e.g. __rte_read_only_param(ptr_index) and __rte_read_only_param_size(ptr_index, size_index), but concluded

that

Quoted 1 line
Quoted 1 line

it would be excruciatingly verbose. The only purpose would be to

reduce

Quoted 1 line
Quoted 1 line

the risk of using them incorrectly. I decided against it, thinking

that

Quoted 1 line
Quoted 1 line

any developer clever enough to use these macros is also clever

enough

Quoted 5 lines
Quoted 5 lines

to understand how to use them (or at least read their parameter descriptions to learn how).

Quoted 1 line

microsoft also has a tool & annotation vehicle for this type of

stuff.

Quoted 1 line
Quoted 1 line

this discussion has caused me to wonder what happens if we would

like

Quoted 5 lines
Quoted 5 lines

to
add additional annotations for other tools. just load on the annotations
and expand them empty conditionally?

Quoted 8 lines
Quoted 4 lines

https://learn.microsoft.com/en-us/cpp/code-quality/using-sal-
annotations-to-reduce-c-cpp-code-defects?view=msvc-170

anyway, just a thought. no serious response required here.

Excellent input, Tyler!

If we want DPDK to be considered truly cross-platform, and not treat

non-Linux/non-GCC as second class citizens, we need to discuss this.

Quoted 2 lines

Microsoft's Source Code Annotation Language (SAL) seems very good,

Quoted 14 lines

based on its finer granularity than GCC's attributes (which in comparison seem added as an afterthought, not cleanly structured like SAL). I have only skimmed the documentation, but that is my immediate impression of it.

Quoted 2 lines

SAL uses a completely different syntax than GCC attributes, and

Microsoft happens to also use memcpy() as an example in the documentation referred to:

Quoted 6 lines

void * memcpy(
_Out_writes_bytes_all_(count) void *dest,
_In_reads_bytes_(count) const void *src,
size_t count
);

Stephen had bad experiences with SAL, so let's just consider the SAL memcpy() example a reference only, showing how the syntax of annotations can differ very much between build systems.

Quoted 46 lines
Quoted 4 lines

Going back to how we can handle this in DPDK, we can either:

1. Not annotate the functions at all, and miss out on finding the

errors for us.

Seeing how clang safety checks helped me catch bugs, that would be a pity.

Quoted 2 lines

2. Invent our own language (or find something existing) for function

headers, and use a parser to convert them to compiler specific C/C++ headers when building the code.

Argh, no.

Quoted 2 lines

3a. Keep loading on attributes, with empty macros for unsupported

compilers.

Quoted 2 lines

3b. Keep loading on attributes, with empty macros for unsupported

compilers. But limit ourselves to GCC/Clang style attributes.

Quoted 2 lines

3c. Keep loading on attributes, with empty macros for unsupported

compilers. But limit ourselves to Microsoft SAL style attributes.

Quoted 2 lines

3d. Keep loading on attributes, with empty macros for unsupported

compilers. But limit ourselves to the most relevant attributes, using performance and/or bug detection as criteria when considering relevance.

Quoted 4 lines

I am strongly against both 1 and 2.

If bug detection is the primary driver, we could stick with either 3b

or 3c (i.e. only target one specific build environment) and rely on the DPDK CI for detecting bugs. But then application developers would not benefit, because they don't run their code through the DPDK CI. So I am also against this.

Quoted 2 lines

I think 3d (keep loading on attributes, but only the most relevant

ones) is the best choice.

Quoted 2 lines

GCC/Clang style attributes are already supported as macros prefixed

by __rte, so let's not change the way we do that.

Quoted 2 lines

Regarding the Microsoft SAL, I suppose Microsoft already chose

Quoted 8 lines

annotation names to avoid collisions, so we could consider using those exact names (i.e. without __rte prefix), and define empty macros for non-Microsoft compilers. This would allow using Microsoft SAL annotations directly in the DPDK code.

Quoted 1 line

I have a bit of trouble understanding the difference between 3a and 3d.. 3a would be about accepting any annotation?

Correct.

Quoted 4 lines

3d is the best option as it is not changing anything to what we were doing so far: we evaluate the pros and cons of each annotations/tools, case per case.

Agree!

#56 lore raw
Quoted 137 lines · Morten Brørup
Quoted 137 lines

From: David Marchand [mailto:[email protected]]
Sent: Tuesday, 31 January 2023 12.15

Quoted 12 lines · Morten Brørup

+To: Thomas & David, you probably have some opinions on this too!

Quoted 9 lines

From: Tyler Retzlaff [mailto:[email protected]]
Sent: Tuesday, 17 January 2023 22.17

Quoted 5 lines · Morten Brørup
Quoted 5 lines

From: Ferruh Yigit [mailto:[email protected]]
Sent: Monday, 16 January 2023 18.02

Quoted 1 line · Morten Brørup

Add nonnull function attribute to help the compiler detect a

NULL

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

pointer being passed to a function not accepting NULL

pointers as

Quoted 8 lines
Quoted 8 lines

an

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

argument at build time.

Add access function attributes to tell the compiler how a

function

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

accesses memory pointed to by its pointer arguments.

Add these attributes to the rte_memcpy() function, as the

first

Quoted 8 lines
Quoted 8 lines

in

Quoted 7 lines
Quoted 6 lines
Quoted 6 lines

hopefully many to come.

---

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

[...]

Quoted 2 lines
Quoted 2 lines

+/**
+ * Tells compiler that the pointer arguments must be non-

null.

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 3 lines

+ *
+ * @param ...
+ * Comma separated list of parameter indexes of pointer

arguments.

Review

Quoted 8 lines

+ */

(quoted diff) +7 -0
+#if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG)
+#define __rte_nonnull_params(...) \
+       __attribute__((nonnull(__VA_ARGS__)))
+#else
+#define __rte_nonnull_params(...)
+#endif
+

What do you think to have a namespace for macros like '__rte_param_xxx',
so name macros as:
__rte_param_nonull
__rte_param_read_only
__rte_param_write_only

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

No strong opinion, it just feels tidier this way

Being a proponent of the world_country_city naming scheme myself,

I

Quoted 3 lines
Quoted 3 lines

would usually agree with this proposal.

Quoted 2 lines

However, in the future, we might add macros without _param for

use

Quoted 7 lines
Quoted 7 lines

along with the function parameters, e.g.:

Quoted 4 lines

int foo(int bar __rte_nonnull __rte_read_only);

So I decided for this order in the names (treating

nonnull/access_mode as "country" and param/params as "city"), also somewhat looking at the __rte_deprecated and

__rte_deprecated_msg(msg)

Quoted 3 lines
Quoted 3 lines

macros.

Quoted 2 lines

I have no strong preference either, so if anyone does, please

speak

Quoted 5 lines
Quoted 5 lines

up.

Quoted 4 lines

Slightly related, also note this:

The nonnull macro is plural (_params), because it can take

multiple

Quoted 2 lines
Quoted 2 lines

pointer parameter indexes.

Quoted 1 line

The access mode macros are singular (_param), because they only

take

Quoted 3 lines
Quoted 3 lines

one pointer parameter index, and the optional size parameter index.

Quoted 2 lines

I considered splitting up the access mode macros even more,

making

Quoted 2 lines
Quoted 2 lines

two variants of each, e.g. __rte_read_only_param(ptr_index) and __rte_read_only_param_size(ptr_index, size_index), but concluded

that

Quoted 1 line
Quoted 1 line

it would be excruciatingly verbose. The only purpose would be to

reduce

Quoted 1 line
Quoted 1 line

the risk of using them incorrectly. I decided against it, thinking

that

Quoted 1 line
Quoted 1 line

any developer clever enough to use these macros is also clever

enough

Quoted 5 lines
Quoted 5 lines

to understand how to use them (or at least read their parameter descriptions to learn how).

Quoted 1 line

microsoft also has a tool & annotation vehicle for this type of

stuff.

Quoted 1 line
Quoted 1 line

this discussion has caused me to wonder what happens if we would

like

Quoted 5 lines
Quoted 5 lines

to
add additional annotations for other tools. just load on the annotations
and expand them empty conditionally?

Quoted 8 lines
Quoted 4 lines

https://learn.microsoft.com/en-us/cpp/code-quality/using-sal-
annotations-to-reduce-c-cpp-code-defects?view=msvc-170

anyway, just a thought. no serious response required here.

Excellent input, Tyler!

If we want DPDK to be considered truly cross-platform, and not treat

non-Linux/non-GCC as second class citizens, we need to discuss this.

Quoted 2 lines

Microsoft's Source Code Annotation Language (SAL) seems very good,

based on its finer granularity than GCC's attributes (which in comparison seem added as an afterthought, not cleanly structured like SAL). I have only skimmed the documentation, but that is my immediate impression of it.

Quoted 2 lines

SAL uses a completely different syntax than GCC attributes, and

Microsoft happens to also use memcpy() as an example in the documentation referred to:

Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines

void * memcpy(
_Out_writes_bytes_all_(count) void *dest,
_In_reads_bytes_(count) const void *src,
size_t count
);

Stephen had bad experiences with SAL, so let's just consider the SAL memcpy() example a reference only, showing how the syntax of annotations can differ very much between build systems.

yes, if we are in a position to use annotations today that work with clang/gcc then let's do that even if they aren't compatible with SAL. so long as they expand empty when not using clang/gcc we can defer discussion about other tools like SAL.

Quoted 65 lines
Quoted 47 lines
Quoted 5 lines

Going back to how we can handle this in DPDK, we can either:

1. Not annotate the functions at all, and miss out on finding the

errors for us.

Seeing how clang safety checks helped me catch bugs, that would be a pity.

Quoted 2 lines

2. Invent our own language (or find something existing) for function

headers, and use a parser to convert them to compiler specific C/C++ headers when building the code.

Argh, no.

Quoted 2 lines

3a. Keep loading on attributes, with empty macros for unsupported

compilers.

Quoted 2 lines

3b. Keep loading on attributes, with empty macros for unsupported

compilers. But limit ourselves to GCC/Clang style attributes.

Quoted 2 lines

3c. Keep loading on attributes, with empty macros for unsupported

compilers. But limit ourselves to Microsoft SAL style attributes.

Quoted 2 lines

3d. Keep loading on attributes, with empty macros for unsupported

compilers. But limit ourselves to the most relevant attributes, using performance and/or bug detection as criteria when considering relevance.

Quoted 4 lines

I am strongly against both 1 and 2.

If bug detection is the primary driver, we could stick with either 3b

or 3c (i.e. only target one specific build environment) and rely on the DPDK CI for detecting bugs. But then application developers would not benefit, because they don't run their code through the DPDK CI. So I am also against this.

Quoted 2 lines

I think 3d (keep loading on attributes, but only the most relevant

ones) is the best choice.

Quoted 2 lines

GCC/Clang style attributes are already supported as macros prefixed

by __rte, so let's not change the way we do that.

Quoted 2 lines

Regarding the Microsoft SAL, I suppose Microsoft already chose

Quoted 8 lines

annotation names to avoid collisions, so we could consider using those exact names (i.e. without __rte prefix), and define empty macros for non-Microsoft compilers. This would allow using Microsoft SAL annotations directly in the DPDK code.

Quoted 1 line

I have a bit of trouble understanding the difference between 3a and 3d.. 3a would be about accepting any annotation?

Correct.

Quoted 4 lines

3d is the best option as it is not changing anything to what we were doing so far: we evaluate the pros and cons of each annotations/tools, case per case.

Agree!

#57 lore raw

31/01/2023 19:26, Tyler Retzlaff:

Quoted 63 lines · Morten Brørup
Quoted 62 lines
Quoted 62 lines

From: David Marchand [mailto:[email protected]]
Sent: Tuesday, 31 January 2023 12.15

Quoted 12 lines · Morten Brørup

+To: Thomas & David, you probably have some opinions on this too!

Quoted 9 lines

From: Tyler Retzlaff [mailto:[email protected]]
Sent: Tuesday, 17 January 2023 22.17

Quoted 5 lines · Morten Brørup
Quoted 5 lines

From: Ferruh Yigit [mailto:[email protected]]
Sent: Monday, 16 January 2023 18.02

Quoted 1 line · Morten Brørup

Add nonnull function attribute to help the compiler detect a

NULL

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

pointer being passed to a function not accepting NULL

pointers as

Quoted 8 lines
Quoted 8 lines

an

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

argument at build time.

Add access function attributes to tell the compiler how a

function

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

accesses memory pointed to by its pointer arguments.

Add these attributes to the rte_memcpy() function, as the

first

Quoted 8 lines
Quoted 8 lines

in

Quoted 7 lines
Quoted 6 lines
Quoted 6 lines

hopefully many to come.

---

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

[...]

Quoted 2 lines
Quoted 2 lines

+/**
+ * Tells compiler that the pointer arguments must be non-

null.

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 3 lines

+ *
+ * @param ...
+ * Comma separated list of parameter indexes of pointer

arguments.

Review

Quoted 8 lines

+ */

(quoted diff) +7 -0
+#if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG)
+#define __rte_nonnull_params(...) \
+       __attribute__((nonnull(__VA_ARGS__)))
+#else
+#define __rte_nonnull_params(...)
+#endif
+

What do you think to have a namespace for macros like '__rte_param_xxx',
so name macros as:
__rte_param_nonull
__rte_param_read_only
__rte_param_write_only

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

No strong opinion, it just feels tidier this way

I tend to prefer this kind of namespace as well.
Let's compare different naming proposals,
taking into account what we already have for some annotations, and what is proposed to be added in this patch and David's patch for lock annotations.

Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

Being a proponent of the world_country_city naming scheme myself,

I

Quoted 3 lines
Quoted 3 lines

would usually agree with this proposal.

Quoted 2 lines

However, in the future, we might add macros without _param for

use

Quoted 7 lines
Quoted 7 lines

along with the function parameters, e.g.:

Quoted 4 lines

int foo(int bar __rte_nonnull __rte_read_only);

So I decided for this order in the names (treating

nonnull/access_mode as "country" and param/params as "city"), also somewhat looking at the __rte_deprecated and

__rte_deprecated_msg(msg)

Quoted 3 lines
Quoted 3 lines

macros.

Quoted 2 lines

I have no strong preference either, so if anyone does, please

speak

Quoted 5 lines
Quoted 5 lines

up.

Quoted 4 lines

Slightly related, also note this:

The nonnull macro is plural (_params), because it can take

multiple

Quoted 2 lines
Quoted 2 lines

pointer parameter indexes.

Quoted 1 line

The access mode macros are singular (_param), because they only

take

Quoted 3 lines
Quoted 3 lines

one pointer parameter index, and the optional size parameter index.

Quoted 2 lines

I considered splitting up the access mode macros even more,

making

Quoted 2 lines
Quoted 2 lines

two variants of each, e.g. __rte_read_only_param(ptr_index) and __rte_read_only_param_size(ptr_index, size_index), but concluded

that

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line

it would be excruciatingly verbose. The only purpose would be to

reduce

Quoted 1 line
Quoted 1 line

the risk of using them incorrectly. I decided against it, thinking

that

Quoted 1 line
Quoted 1 line

any developer clever enough to use these macros is also clever

enough

Quoted 2 lines
Quoted 2 lines

to understand how to use them (or at least read their parameter descriptions to learn how).

Longer macro names may be better for code readers.

Quoted 35 lines
Quoted 35 lines
Quoted 34 lines
Quoted 1 line
Quoted 1 line

microsoft also has a tool & annotation vehicle for this type of

stuff.

Quoted 1 line
Quoted 1 line

this discussion has caused me to wonder what happens if we would

like

Quoted 5 lines
Quoted 5 lines

to
add additional annotations for other tools. just load on the annotations
and expand them empty conditionally?

Quoted 8 lines
Quoted 4 lines

https://learn.microsoft.com/en-us/cpp/code-quality/using-sal-
annotations-to-reduce-c-cpp-code-defects?view=msvc-170

anyway, just a thought. no serious response required here.

Excellent input, Tyler!

If we want DPDK to be considered truly cross-platform, and not treat

non-Linux/non-GCC as second class citizens, we need to discuss this.

Quoted 2 lines

Microsoft's Source Code Annotation Language (SAL) seems very good,

based on its finer granularity than GCC's attributes (which in comparison seem added as an afterthought, not cleanly structured like SAL). I have only skimmed the documentation, but that is my immediate impression of it.

Quoted 2 lines

SAL uses a completely different syntax than GCC attributes, and

Microsoft happens to also use memcpy() as an example in the documentation referred to:

Quoted 6 lines

void * memcpy(
_Out_writes_bytes_all_(count) void *dest,
_In_reads_bytes_(count) const void *src,
size_t count
);

Quoted 6 lines
Quoted 1 line

Stephen had bad experiences with SAL, so let's just consider the SAL memcpy() example a reference only, showing how the syntax of annotations can differ very much between build systems.

yes, if we are in a position to use annotations today that work with clang/gcc then let's do that even if they aren't compatible with SAL. so long as they expand empty when not using clang/gcc we can defer discussion about other tools like SAL.

Yes of course it must expand empty for compilers not supporting the annotation. Anyway I don't think we need to support all compilers with annotation. The main goal of annotation is to do more checks in the CI,
so supporting one compiler should be enough.

Quoted 54 lines
Quoted 54 lines
Quoted 53 lines
Quoted 3 lines

Going back to how we can handle this in DPDK, we can either:

1. Not annotate the functions at all, and miss out on finding the

errors for us.

Seeing how clang safety checks helped me catch bugs, that would be a pity.

Quoted 2 lines

2. Invent our own language (or find something existing) for function

headers, and use a parser to convert them to compiler specific C/C++ headers when building the code.

Argh, no.

Quoted 2 lines

3a. Keep loading on attributes, with empty macros for unsupported

compilers.

Quoted 2 lines

3b. Keep loading on attributes, with empty macros for unsupported

compilers. But limit ourselves to GCC/Clang style attributes.

Quoted 2 lines

3c. Keep loading on attributes, with empty macros for unsupported

compilers. But limit ourselves to Microsoft SAL style attributes.

Quoted 2 lines

3d. Keep loading on attributes, with empty macros for unsupported

compilers. But limit ourselves to the most relevant attributes, using performance and/or bug detection as criteria when considering relevance.

Quoted 4 lines

I am strongly against both 1 and 2.

If bug detection is the primary driver, we could stick with either 3b

or 3c (i.e. only target one specific build environment) and rely on the DPDK CI for detecting bugs. But then application developers would not benefit, because they don't run their code through the DPDK CI. So I am also against this.

Quoted 2 lines

I think 3d (keep loading on attributes, but only the most relevant

ones) is the best choice.

Quoted 2 lines

GCC/Clang style attributes are already supported as macros prefixed

by __rte, so let's not change the way we do that.

Quoted 2 lines

Regarding the Microsoft SAL, I suppose Microsoft already chose

annotation names to avoid collisions, so we could consider using those exact names (i.e. without __rte prefix), and define empty macros for non-Microsoft compilers. This would allow using Microsoft SAL annotations directly in the DPDK code.

Quoted 1 line

I have a bit of trouble understanding the difference between 3a and 3d.. 3a would be about accepting any annotation?

Quoted 8 lines
Quoted 8 lines

Correct.

Quoted 4 lines

3d is the best option as it is not changing anything to what we were doing so far: we evaluate the pros and cons of each annotations/tools, case per case.

Agree!

I am for 3d as well.
We should focus on clang for using compilation checks.

Another question about annotations is how much we want to use them. I think we should use such check for critical code only. Adding annotations everywhere is not always worth making the code uglier.

#58 lore raw
Quoted 74 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Tuesday, 31 January 2023 23.52

31/01/2023 19:26, Tyler Retzlaff:

Quoted 8 lines · Morten Brørup
Quoted 7 lines
Quoted 7 lines

From: David Marchand [mailto:[email protected]]
Sent: Tuesday, 31 January 2023 12.15

Quoted 2 lines · Morten Brørup

+To: Thomas & David, you probably have some opinions on this

too!

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

From: Tyler Retzlaff [mailto:[email protected]]
Sent: Tuesday, 17 January 2023 22.17

On Tue, Jan 17, 2023 at 09:19:22AM +0100, Morten Brørup

Quoted 5 lines · wrote:
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

From: Ferruh Yigit [mailto:[email protected]]
Sent: Monday, 16 January 2023 18.02

Quoted 1 line · Morten Brørup

Add nonnull function attribute to help the compiler

detect a

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

NULL

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

pointer being passed to a function not accepting NULL

pointers as

Quoted 4 lines
Quoted 4 lines

an

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

argument at build time.

Add access function attributes to tell the compiler how

a

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

function

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

accesses memory pointed to by its pointer arguments.

Add these attributes to the rte_memcpy() function, as

the

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

first

Quoted 8 lines
Quoted 8 lines

in

Quoted 7 lines
Quoted 6 lines
Quoted 6 lines

hopefully many to come.

---

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

[...]

Quoted 2 lines
Quoted 2 lines

+/**
+ * Tells compiler that the pointer arguments must be

non-

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

null.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

+ *
+ * @param ...
+ * Comma separated list of parameter indexes of

pointer

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines

arguments.

Review

Quoted 8 lines

+ */

(quoted diff) +7 -0
+#if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG)
+#define __rte_nonnull_params(...) \
+       __attribute__((nonnull(__VA_ARGS__)))
+#else
+#define __rte_nonnull_params(...)
+#endif
+

What do you think to have a namespace for macros like '__rte_param_xxx',
so name macros as:
__rte_param_nonull
__rte_param_read_only
__rte_param_write_only

Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

No strong opinion, it just feels tidier this way

I tend to prefer this kind of namespace as well.
Let's compare different naming proposals,
taking into account what we already have for some annotations, and what is proposed to be added in this patch and David's patch for lock annotations.

David's lock annotations don't use a dedicated naming convention, but simply replaces __attribute__(name(params)) with __rte_name(params), e.g.:

#define __rte_guarded_by(...) \
	__attribute__((guarded_by(__VA_ARGS__)))
#define __rte_exclusive_locks_required(...) \
	__attribute__((exclusive_locks_required(__VA_ARGS__)))
#define __rte_assert_exclusive_lock(...) \
	__attribute__((assert_exclusive_lock(__VA_ARGS__)))

This follows the existing convention in rte_common.h, which is easily readable, because they directly translate to GCC attribute names, e.g.:

#define __rte_warn_unused_result __attribute__((warn_unused_result)) #define __rte_always_inline inline __attribute__((always_inline)) #define __rte_noinline __attribute__((noinline))
#define __rte_hot __attribute__((hot))
#define __rte_cold __attribute__((cold))

I could follow this convention too, e.g.:

#define __rte_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))

#define __rte_access_read_only(...) \
	__attribute__((access(read_only, __VA_ARGS__)))
#define __rte_access_write_only(...) \
	__attribute__((access(write_only, __VA_ARGS__)))
Quoted 49 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Being a proponent of the world_country_city naming scheme

myself,

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

I

Quoted 3 lines
Quoted 3 lines

would usually agree with this proposal.

Quoted 2 lines

However, in the future, we might add macros without _param

for

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

use

Quoted 6 lines
Quoted 6 lines

along with the function parameters, e.g.:

Quoted 4 lines

int foo(int bar __rte_nonnull __rte_read_only);

So I decided for this order in the names (treating

nonnull/access_mode as "country" and param/params as "city"),

also

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line

somewhat looking at the __rte_deprecated and

__rte_deprecated_msg(msg)

Quoted 3 lines
Quoted 3 lines

macros.

Quoted 2 lines

I have no strong preference either, so if anyone does,

please

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

speak

Quoted 5 lines
Quoted 5 lines

up.

Quoted 4 lines

Slightly related, also note this:

The nonnull macro is plural (_params), because it can take

multiple

Quoted 2 lines
Quoted 2 lines

pointer parameter indexes.

Quoted 1 line

The access mode macros are singular (_param), because they

only

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

take

Quoted 1 line
Quoted 1 line

one pointer parameter index, and the optional size parameter

index.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

I considered splitting up the access mode macros even more,

making

Quoted 1 line
Quoted 1 line

two variants of each, e.g. __rte_read_only_param(ptr_index)

and

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

__rte_read_only_param_size(ptr_index, size_index), but

concluded

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

that

Quoted 1 line
Quoted 1 line

it would be excruciatingly verbose. The only purpose would be

to

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

reduce

Quoted 1 line
Quoted 1 line

the risk of using them incorrectly. I decided against it,

thinking

Quoted 1 line
Quoted 1 line
Quoted 1 line

that

Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

any developer clever enough to use these macros is also

clever

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

enough

Quoted 1 line
Quoted 1 line

to understand how to use them (or at least read their

parameter

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

descriptions to learn how).

Longer macro names may be better for code readers.

You have a good point here, Thomas. It will also prevent using the access mode attribute macros incorrectly.

Let's proceed with two macros (without and with size parameter) instead of the combined macros (with optional size parameter).

Referring to the existing convention in rte_common.h, what do you think about naming the new macros as follows?

__rte_access_read_only(ptr_index) __rte_access_read_only_size(ptr_index, size_index)

Or just:

__rte_read_only(ptr_index)
__rte_read_only_size(ptr_index, size_index)

Quoted 51 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

microsoft also has a tool & annotation vehicle for this type

of

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

stuff.

Quoted 1 line
Quoted 1 line

this discussion has caused me to wonder what happens if we

would

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

like

Quoted 5 lines
Quoted 5 lines

to
add additional annotations for other tools. just load on the annotations
and expand them empty conditionally?

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

https://learn.microsoft.com/en-us/cpp/code-quality/using-sal-
annotations-to-reduce-c-cpp-code-defects?view=msvc-170

anyway, just a thought. no serious response required here.

Excellent input, Tyler!

If we want DPDK to be considered truly cross-platform, and not

treat

Quoted 1 line
Quoted 1 line
Quoted 1 line

non-Linux/non-GCC as second class citizens, we need to discuss

this.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Microsoft's Source Code Annotation Language (SAL) seems very

good,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

based on its finer granularity than GCC's attributes (which in comparison seem added as an afterthought, not cleanly structured

like

Quoted 1 line
Quoted 1 line
Quoted 1 line

SAL). I have only skimmed the documentation, but that is my

immediate

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

impression of it.

Quoted 2 lines

SAL uses a completely different syntax than GCC attributes, and

Microsoft happens to also use memcpy() as an example in the documentation referred to:

Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines

void * memcpy(
_Out_writes_bytes_all_(count) void *dest,
_In_reads_bytes_(count) const void *src,
size_t count
);

Stephen had bad experiences with SAL, so let's just consider the

SAL memcpy() example a reference only, showing how the syntax of annotations can differ very much between build systems.

Quoted 4 lines

yes, if we are in a position to use annotations today that work with clang/gcc then let's do that even if they aren't compatible with SAL. so long as they expand empty when not using clang/gcc we can defer

Quoted 8 lines

discussion

Quoted 1 line

about other tools like SAL.

Yes of course it must expand empty for compilers not supporting the annotation.
Anyway I don't think we need to support all compilers with annotation. The main goal of annotation is to do more checks in the CI, so supporting one compiler should be enough.

There is also a secondary goal of increased performance. When the compiler knows more about a function's behavior, it can optimize more around it. E.g. knowing that a function doesn't modify something already held in a register (or other local memory) allows the compiler to reuse the local copy (in the register) without fetching the original again.

Quoted 79 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Going back to how we can handle this in DPDK, we can either:

1. Not annotate the functions at all, and miss out on finding

the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

errors for us.

Seeing how clang safety checks helped me catch bugs, that would

be a

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

pity.

Quoted 2 lines

2. Invent our own language (or find something existing) for

function

Quoted 1 line
Quoted 1 line
Quoted 1 line

headers, and use a parser to convert them to compiler specific

C/C++

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

headers when building the code.

Argh, no.

Quoted 2 lines

3a. Keep loading on attributes, with empty macros for

unsupported

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

compilers.

Quoted 2 lines

3b. Keep loading on attributes, with empty macros for

unsupported

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

compilers. But limit ourselves to GCC/Clang style attributes.

Quoted 2 lines

3c. Keep loading on attributes, with empty macros for

unsupported

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

compilers. But limit ourselves to Microsoft SAL style attributes.

Quoted 2 lines

3d. Keep loading on attributes, with empty macros for

unsupported

Quoted 1 line
Quoted 1 line
Quoted 1 line

compilers. But limit ourselves to the most relevant attributes,

using

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

performance and/or bug detection as criteria when considering relevance.

Quoted 4 lines

I am strongly against both 1 and 2.

If bug detection is the primary driver, we could stick with

either 3b

Quoted 1 line
Quoted 1 line
Quoted 1 line

or 3c (i.e. only target one specific build environment) and rely

on the

Quoted 1 line
Quoted 1 line
Quoted 1 line

DPDK CI for detecting bugs. But then application developers would

not

Quoted 1 line
Quoted 1 line
Quoted 1 line

benefit, because they don't run their code through the DPDK CI.

So I am

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

also against this.

Quoted 2 lines

I think 3d (keep loading on attributes, but only the most

relevant

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

ones) is the best choice.

Quoted 2 lines

GCC/Clang style attributes are already supported as macros

prefixed

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

by __rte, so let's not change the way we do that.

Quoted 2 lines

Regarding the Microsoft SAL, I suppose Microsoft already chose

annotation names to avoid collisions, so we could consider using

those

Quoted 1 line
Quoted 1 line
Quoted 1 line

exact names (i.e. without __rte prefix), and define empty macros

for

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

non-Microsoft compilers. This would allow using Microsoft SAL annotations directly in the DPDK code.

Quoted 1 line

I have a bit of trouble understanding the difference between 3a

and

Quoted 6 lines
Quoted 6 lines
Quoted 1 line

3d.. 3a would be about accepting any annotation?

Correct.

Quoted 2 lines

3d is the best option as it is not changing anything to what we

were

Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

doing so far: we evaluate the pros and cons of each

annotations/tools,

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

case per case.

Agree!

I am for 3d as well.
We should focus on clang for using compilation checks.

Clang doesn't support the access mode attribute (yet?). It is only supported by GCC.

The CI also uses GCC, so let's not limit ourselves to what clang can do. Using the access mode attribute with GCC is still useful for the CI to reveal bugs.

I agree with you on the principle: We don't need to add the same bug-finding attributes to all compiler environments; adding them to one CI supported compiler environment should suffice.

However, performance-enhancing attributes would be useful to support in multiple compiler environments.

Quoted 4 lines

Another question about annotations is how much we want to use them. I think we should use such check for critical code only.

Agree. And this includes some fast path code, where they might benefit performance.

Quoted 2 lines

Adding annotations everywhere is not always worth making the code uglier.

I agree. I suppose Stephen stressed the same point when referring his experience working with SAL.

It will be impossible to define a criteria for when to use or not use such attributes, but we can probably agree on this: When adding new functions to DPDK, adding such attributes is not a requirement. This should make it up to the contributor to decide if she wants to add them or not, which can be discussed on a case by case basis if the maintainer disagrees.

This principle should limit the big discussions to which attributes we want to allow into rte_common.h; like these and the ones in David's lock annotation patch.

#59 lore raw

01/02/2023 13:50, Morten Brørup:

Quoted 58 lines

From: Thomas Monjalon [mailto:[email protected]]

Quoted 23 lines

31/01/2023 19:26, Tyler Retzlaff:

Quoted 22 lines · Morten Brørup
Quoted 21 lines
Quoted 21 lines

From: David Marchand [mailto:[email protected]]

Quoted 18 lines · Morten Brørup
Quoted 18 lines

From: Tyler Retzlaff [mailto:[email protected]] On Tue, Jan 17, 2023 at 09:19:22AM +0100, Morten Brørup

Quoted 16 lines
Quoted 16 lines

Review

Quoted 8 lines

+ */

(quoted diff) +7 -0
+#if defined(RTE_CC_GCC) || defined(RTE_CC_CLANG)
+#define __rte_nonnull_params(...) \
+       __attribute__((nonnull(__VA_ARGS__)))
+#else
+#define __rte_nonnull_params(...)
+#endif
+

What do you think to have a namespace for macros like '__rte_param_xxx',
so name macros as:
__rte_param_nonull
__rte_param_read_only
__rte_param_write_only

Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

No strong opinion, it just feels tidier this way

I tend to prefer this kind of namespace as well.
Let's compare different naming proposals,
taking into account what we already have for some annotations, and what is proposed to be added in this patch and David's patch for lock annotations.

David's lock annotations don't use a dedicated naming convention, but simply replaces __attribute__(name(params)) with __rte_name(params), e.g.:

#define __rte_guarded_by(...) \
	__attribute__((guarded_by(__VA_ARGS__)))
#define __rte_exclusive_locks_required(...) \
	__attribute__((exclusive_locks_required(__VA_ARGS__)))
#define __rte_assert_exclusive_lock(...) \
	__attribute__((assert_exclusive_lock(__VA_ARGS__)))

This follows the existing convention in rte_common.h, which is easily readable, because they directly translate to GCC attribute names, e.g.:

#define __rte_warn_unused_result __attribute__((warn_unused_result)) #define __rte_always_inline inline __attribute__((always_inline)) #define __rte_noinline __attribute__((noinline))
#define __rte_hot __attribute__((hot))
#define __rte_cold __attribute__((cold))

I could follow this convention too, e.g.:

#define __rte_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))

#define __rte_access_read_only(...) \
	__attribute__((access(read_only, __VA_ARGS__)))
#define __rte_access_write_only(...) \
	__attribute__((access(write_only, __VA_ARGS__)))

[...]

Quoted 8 lines
Quoted 1 line

Longer macro names may be better for code readers.

You have a good point here, Thomas. It will also prevent using the access mode attribute macros incorrectly.

Let's proceed with two macros (without and with size parameter) instead of the combined macros (with optional size parameter).

Referring to the existing convention in rte_common.h, what do you think about naming the new macros as follows?

Quoted 7 lines

__rte_access_read_only(ptr_index) __rte_access_read_only_size(ptr_index, size_index)

Or just:

__rte_read_only(ptr_index)
__rte_read_only_size(ptr_index, size_index)

I think we don't need the word "access", so I prefer the second form.

What about the proposal of having "param" in the name? We could also have "function" is some macro names. Does it bring a benefit?

Please let's have a naming discussion with many opinions.

Quoted 52 lines
Quoted 52 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

microsoft also has a tool & annotation vehicle for this type

of

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

stuff.

Quoted 1 line
Quoted 1 line

this discussion has caused me to wonder what happens if we

would

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

like

Quoted 5 lines
Quoted 5 lines

to
add additional annotations for other tools. just load on the annotations
and expand them empty conditionally?

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

https://learn.microsoft.com/en-us/cpp/code-quality/using-sal-
annotations-to-reduce-c-cpp-code-defects?view=msvc-170

anyway, just a thought. no serious response required here.

Excellent input, Tyler!

If we want DPDK to be considered truly cross-platform, and not

treat

Quoted 1 line
Quoted 1 line
Quoted 1 line

non-Linux/non-GCC as second class citizens, we need to discuss

this.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Microsoft's Source Code Annotation Language (SAL) seems very

good,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

based on its finer granularity than GCC's attributes (which in comparison seem added as an afterthought, not cleanly structured

like

Quoted 1 line
Quoted 1 line
Quoted 1 line

SAL). I have only skimmed the documentation, but that is my

immediate

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

impression of it.

Quoted 2 lines

SAL uses a completely different syntax than GCC attributes, and

Microsoft happens to also use memcpy() as an example in the documentation referred to:

Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines

void * memcpy(
_Out_writes_bytes_all_(count) void *dest,
_In_reads_bytes_(count) const void *src,
size_t count
);

Stephen had bad experiences with SAL, so let's just consider the

SAL memcpy() example a reference only, showing how the syntax of annotations can differ very much between build systems.

Quoted 4 lines

yes, if we are in a position to use annotations today that work with clang/gcc then let's do that even if they aren't compatible with SAL. so long as they expand empty when not using clang/gcc we can defer

discussion

Quoted 1 line

about other tools like SAL.

Quoted 7 lines
Quoted 5 lines

Yes of course it must expand empty for compilers not supporting the annotation.
Anyway I don't think we need to support all compilers with annotation. The main goal of annotation is to do more checks in the CI, so supporting one compiler should be enough.

There is also a secondary goal of increased performance. When the compiler knows more about a function's behavior, it can optimize more around it. E.g. knowing that a function doesn't modify something already held in a register (or other local memory) allows the compiler to reuse the local copy (in the register) without fetching the original again.

If we want to enable such performance optimizations with all compilers, we may have issues to find a common syntax.
In general I am OK to try (best effort)
but we should be reasonnable in case things are getting complex.

[...]

Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

3d is the best option as it is not changing anything to what we

were

Quoted 1 line
Quoted 1 line
Quoted 1 line

doing so far: we evaluate the pros and cons of each

annotations/tools,

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

case per case.

Agree!

I am for 3d as well.
We should focus on clang for using compilation checks.

Clang doesn't support the access mode attribute (yet?). It is only supported by GCC.

OK

Quoted 9 lines

The CI also uses GCC, so let's not limit ourselves to what clang can do. Using the access mode attribute with GCC is still useful for the CI to reveal bugs.

I agree with you on the principle: We don't need to add the same bug-finding attributes to all compiler environments; adding them to one CI supported compiler environment should suffice.

However, performance-enhancing attributes would be useful to support in multiple compiler environments.

Quoted 2 lines

Another question about annotations is how much we want to use them. I think we should use such check for critical code only.

Quoted 8 lines

Agree. And this includes some fast path code, where they might benefit performance.

Quoted 2 lines

Adding annotations everywhere is not always worth making the code uglier.

I agree. I suppose Stephen stressed the same point when referring his experience working with SAL.

It will be impossible to define a criteria for when to use or not use such attributes, but we can probably agree on this: When adding new functions to DPDK, adding such attributes is not a requirement. This should make it up to the contributor to decide if she wants to add them or not, which can be discussed on a case by case basis if the maintainer disagrees.

Yes

Quoted 1 line

This principle should limit the big discussions to which attributes we want to allow into rte_common.h; like these and the ones in David's lock annotation patch.

OK

#60 lore raw
Quoted 49 lines · Thomas Monjalon
Quoted 32 lines
Quoted 5 lines

I tend to prefer this kind of namespace as well.
Let's compare different naming proposals,
taking into account what we already have for some annotations, and what is proposed to be added in this patch and David's patch for lock annotations.

David's lock annotations don't use a dedicated naming convention, but simply replaces __attribute__(name(params)) with __rte_name(params), e.g.:

#define __rte_guarded_by(...) \
      __attribute__((guarded_by(__VA_ARGS__)))
#define __rte_exclusive_locks_required(...) \
      __attribute__((exclusive_locks_required(__VA_ARGS__)))
#define __rte_assert_exclusive_lock(...) \
      __attribute__((assert_exclusive_lock(__VA_ARGS__)))

This follows the existing convention in rte_common.h, which is easily readable, because they directly translate to GCC attribute names, e.g.:

#define __rte_warn_unused_result __attribute__((warn_unused_result)) #define __rte_always_inline inline __attribute__((always_inline)) #define __rte_noinline __attribute__((noinline))
#define __rte_hot __attribute__((hot))
#define __rte_cold __attribute__((cold))

I could follow this convention too, e.g.:

#define __rte_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))

#define __rte_access_read_only(...) \
      __attribute__((access(read_only, __VA_ARGS__)))
#define __rte_access_write_only(...) \
      __attribute__((access(write_only, __VA_ARGS__)))

[...]

Quoted 8 lines
Quoted 1 line

Longer macro names may be better for code readers.

You have a good point here, Thomas. It will also prevent using the access mode attribute macros incorrectly.

Let's proceed with two macros (without and with size parameter) instead of the combined macros (with optional size parameter).

Referring to the existing convention in rte_common.h, what do you think about naming the new macros as follows?

Quoted 7 lines

__rte_access_read_only(ptr_index) __rte_access_read_only_size(ptr_index, size_index)

Or just:

__rte_read_only(ptr_index)
__rte_read_only_size(ptr_index, size_index)

Quoted 7 lines

I think we don't need the word "access", so I prefer the second form.

What about the proposal of having "param" in the name? We could also have "function" is some macro names. Does it bring a benefit?

Please let's have a naming discussion with many opinions.

Thomas, I think naming convention/discussion is the most likely to never conclude.

Just copying my previous suggestion.
__rte_read_only_params(indexes...)
__rte_write_only_params(indexes...)
__rte_no_access_params(indexes...)

So if we are not going with the existing (kind of) convention to just prefix with __rte_, I prefer Morten second form too and I have no better idea.

As for the lock annotations series, if you are not confident with the form I went with, I don't mind deferring to a later release. Though it adds more work on my pile like rebasing the vhost library. Additionnally, we lose the opportunity to catch introduction of new lock issues in the dpdk tree.

Signature · 1 line
David Marchand
#61 lore raw
Quoted 45 lines

From: David Marchand [mailto:[email protected]]
Sent: Monday, 6 February 2023 17.11

Quoted 7 lines · Thomas Monjalon
Quoted 7 lines
Quoted 5 lines

I tend to prefer this kind of namespace as well.
Let's compare different naming proposals,
taking into account what we already have for some annotations, and what is proposed to be added in this patch and David's patch for lock annotations.

David's lock annotations don't use a dedicated naming convention,

but simply replaces __attribute__(name(params)) with __rte_name(params), e.g.:

Quoted 9 lines
Quoted 9 lines
#define __rte_guarded_by(...) \
      __attribute__((guarded_by(__VA_ARGS__)))
#define __rte_exclusive_locks_required(...) \
      __attribute__((exclusive_locks_required(__VA_ARGS__)))
#define __rte_assert_exclusive_lock(...) \
      __attribute__((assert_exclusive_lock(__VA_ARGS__)))

This follows the existing convention in rte_common.h, which is

easily readable, because they directly translate to GCC attribute names, e.g.:

Quoted 2 lines
Quoted 2 lines

#define __rte_warn_unused_result

__attribute__((warn_unused_result))

Quoted 17 lines
Quoted 14 lines

#define __rte_always_inline inline __attribute__((always_inline)) #define __rte_noinline __attribute__((noinline)) #define __rte_hot __attribute__((hot))
#define __rte_cold __attribute__((cold))

I could follow this convention too, e.g.:

#define __rte_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))

#define __rte_access_read_only(...) \
      __attribute__((access(read_only, __VA_ARGS__)))
#define __rte_access_write_only(...) \
      __attribute__((access(write_only, __VA_ARGS__)))

[...]

Quoted 2 lines
Quoted 1 line

Longer macro names may be better for code readers.

Quoted 22 lines
Quoted 1 line
Quoted 1 line

You have a good point here, Thomas. It will also prevent using the

access mode attribute macros incorrectly.

Quoted 2 lines
Quoted 2 lines

Let's proceed with two macros (without and with size parameter)

instead of the combined macros (with optional size parameter).

Quoted 2 lines
Quoted 2 lines

Referring to the existing convention in rte_common.h, what do you

think about naming the new macros as follows?

Quoted 14 lines
Quoted 8 lines

__rte_access_read_only(ptr_index) __rte_access_read_only_size(ptr_index, size_index)

Or just:

__rte_read_only(ptr_index)
__rte_read_only_size(ptr_index, size_index)

I think we don't need the word "access", so I prefer the second form.

What about the proposal of having "param" in the name? We could also have "function" is some macro names. Does it bring a benefit?

The existing __rte_format_printf macro also follows the simple convention, and does not add "param" or "function" in the name:

#define __rte_format_printf(format_index, first_arg) \
__attribute__((format(printf, format_index, first_arg)))

Quoted 5 lines
Quoted 2 lines

Please let's have a naming discussion with many opinions.

Thomas, I think naming convention/discussion is the most likely to never conclude.

No one else seem to have strong enough opinions to join the discussion. So let's try to conclude the discussion.

Quoted 9 lines

Just copying my previous suggestion.
__rte_read_only_params(indexes...)
__rte_write_only_params(indexes...)
__rte_no_access_params(indexes...)

So if we are not going with the existing (kind of) convention to just prefix with __rte_, I prefer Morten second form too and I have no better idea.

I'm leaning towards following the existing convention in rte_common.h, and embrace Thomas' argument to make them more verbose in order to reduce the risk of wrong use. In other words, define these:

__rte_nonnull(...)
__rte_read_only(ptr_index)
__rte_read_only_size(ptr_index, size_index)
__rte_write_only(ptr_index)
__rte_write_only_size(ptr_index, size_index)
__rte_read_write(ptr_index)
__rte_read_write_size(ptr_index, size_index)
__rte_no_access(ptr_index)
__rte_no_access_size(ptr_index, size_index)

Quoted 4 lines

As for the lock annotations series, if you are not confident with the form I went with, I don't mind deferring to a later release.

The form follows the existing convention in rte_common.h, and I think we should stick with it.

Quoted 3 lines

Though it adds more work on my pile like rebasing the vhost library. Additionnally, we lose the opportunity to catch introduction of new lock issues in the dpdk tree.

Conclusion:

The names I listed in this email, and what David already has in his lock annotation patch, are both in line with an existing convention already established in rte_common.h. So unless someone objects very soon, let's go for that.

#62 lore raw
Quoted 74 lines · Morten Brørup
Quoted 45 lines

From: David Marchand [mailto:[email protected]]
Sent: Monday, 6 February 2023 17.11

Quoted 7 lines · Thomas Monjalon
Quoted 7 lines
Quoted 5 lines

I tend to prefer this kind of namespace as well.
Let's compare different naming proposals,
taking into account what we already have for some annotations, and what is proposed to be added in this patch and David's patch for lock annotations.

David's lock annotations don't use a dedicated naming convention,

but simply replaces __attribute__(name(params)) with __rte_name(params), e.g.:

Quoted 9 lines
Quoted 9 lines
#define __rte_guarded_by(...) \
      __attribute__((guarded_by(__VA_ARGS__)))
#define __rte_exclusive_locks_required(...) \
      __attribute__((exclusive_locks_required(__VA_ARGS__)))
#define __rte_assert_exclusive_lock(...) \
      __attribute__((assert_exclusive_lock(__VA_ARGS__)))

This follows the existing convention in rte_common.h, which is

easily readable, because they directly translate to GCC attribute names, e.g.:

Quoted 2 lines
Quoted 2 lines

#define __rte_warn_unused_result

__attribute__((warn_unused_result))

Quoted 17 lines
Quoted 14 lines

#define __rte_always_inline inline __attribute__((always_inline)) #define __rte_noinline __attribute__((noinline)) #define __rte_hot __attribute__((hot))
#define __rte_cold __attribute__((cold))

I could follow this convention too, e.g.:

#define __rte_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))

#define __rte_access_read_only(...) \
      __attribute__((access(read_only, __VA_ARGS__)))
#define __rte_access_write_only(...) \
      __attribute__((access(write_only, __VA_ARGS__)))

[...]

Quoted 2 lines
Quoted 1 line

Longer macro names may be better for code readers.

Quoted 22 lines
Quoted 1 line
Quoted 1 line

You have a good point here, Thomas. It will also prevent using the

access mode attribute macros incorrectly.

Quoted 2 lines
Quoted 2 lines

Let's proceed with two macros (without and with size parameter)

instead of the combined macros (with optional size parameter).

Quoted 2 lines
Quoted 2 lines

Referring to the existing convention in rte_common.h, what do you

think about naming the new macros as follows?

Quoted 14 lines
Quoted 8 lines

__rte_access_read_only(ptr_index) __rte_access_read_only_size(ptr_index, size_index)

Or just:

__rte_read_only(ptr_index)
__rte_read_only_size(ptr_index, size_index)

I think we don't need the word "access", so I prefer the second form.

What about the proposal of having "param" in the name? We could also have "function" is some macro names. Does it bring a benefit?

The existing __rte_format_printf macro also follows the simple convention, and does not add "param" or "function" in the name:

#define __rte_format_printf(format_index, first_arg) \
__attribute__((format(printf, format_index, first_arg)))

Quoted 1 line
Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Please let's have a naming discussion with many opinions.

Thomas, I think naming convention/discussion is the most likely to never conclude.

No one else seem to have strong enough opinions to join the discussion. So let's try to conclude the discussion.

+1 the value of getting this in with ~whatever names outweighs a prolonged discussion about naming. my view is this isn't part of the dpdk stable public api and it is incidental that the headers introduce the names. if applications choose to consume them, we document that they change from time to time without notice.

i also think if naming is of high importance it can be done post-merge. slightly related it would be nice to establish a more streamlined contribution process for non-semantic changes. it's painful to review changes filled with gratuitous style refactors mixed amongst functional change or code move / rename etc.. it's much easier to spot errors when such changes are in separate series, so let's make integrating them a fast path.

Quoted 38 lines
Quoted 10 lines

Just copying my previous suggestion.
__rte_read_only_params(indexes...)
__rte_write_only_params(indexes...)
__rte_no_access_params(indexes...)

So if we are not going with the existing (kind of) convention to just prefix with __rte_, I prefer Morten second form too and I have no better idea.

I'm leaning towards following the existing convention in rte_common.h, and embrace Thomas' argument to make them more verbose in order to reduce the risk of wrong use. In other words, define these:

__rte_nonnull(...)
__rte_read_only(ptr_index)
__rte_read_only_size(ptr_index, size_index)
__rte_write_only(ptr_index)
__rte_write_only_size(ptr_index, size_index)
__rte_read_write(ptr_index)
__rte_read_write_size(ptr_index, size_index)
__rte_no_access(ptr_index)
__rte_no_access_size(ptr_index, size_index)

Quoted 4 lines

As for the lock annotations series, if you are not confident with the form I went with, I don't mind deferring to a later release.

The form follows the existing convention in rte_common.h, and I think we should stick with it.

Quoted 3 lines

Though it adds more work on my pile like rebasing the vhost library. Additionnally, we lose the opportunity to catch introduction of new lock issues in the dpdk tree.

Conclusion:

The names I listed in this email, and what David already has in his lock annotation patch, are both in line with an existing convention already established in rte_common.h. So unless someone objects very soon, let's go for that.

#63 lore raw
Quoted 9 lines

From: Tyler Retzlaff [mailto:[email protected]]
Sent: Monday, 6 February 2023 18.29

Quoted 5 lines · Morten Brørup
Quoted 5 lines

From: David Marchand [mailto:[email protected]]
Sent: Monday, 6 February 2023 17.11

On Wed, Feb 1, 2023 at 2:16 PM Thomas Monjalon <[email protected]> wrote:

[...]

Quoted 27 lines
Quoted 2 lines

I'm leaning towards following the existing convention in rte_common.h, and

embrace Thomas' argument to make them more verbose in order to reduce the risk of wrong use. In other words, define these:

Quoted 13 lines

__rte_nonnull(...)
__rte_read_only(ptr_index)
__rte_read_only_size(ptr_index, size_index)
__rte_write_only(ptr_index)
__rte_write_only_size(ptr_index, size_index)
__rte_read_write(ptr_index)
__rte_read_write_size(ptr_index, size_index)
__rte_no_access(ptr_index)
__rte_no_access_size(ptr_index, size_index)

Quoted 2 lines
Quoted 4 lines
Quoted 2 lines

As for the lock annotations series, if you are not confident with the form I went with, I don't mind deferring to a later release.

The form follows the existing convention in rte_common.h, and I think we

should stick with it.

Quoted 5 lines
Quoted 4 lines

Though it adds more work on my pile like rebasing the vhost library. Additionnally, we lose the opportunity to catch introduction of new lock issues in the dpdk tree.

Quoted 6 lines
Quoted 3 lines

Conclusion:

The names I listed in this email, and what David already has in his lock

annotation patch, are both in line with an existing convention already established in rte_common.h. So unless someone objects very soon, let's go for that.

David, Thomas,

FYI:

I am deferring a new version this patch until a later DPDK release, so it doesn't get too much in the way of Tyler's MSVC patches.

Stretch goal: I'm considering if these new attributes could somehow also support MSVC, but let's not discuss that now!

PS: The other patches in the series are independent of this patch, and can be considered individually.

-Morten

#64 lore raw

David,

As mentioned below, the first 3 patches in this series [26561] can be considered as individual driver patches.

I guess this request was somehow missed. Should I delegate these 3 patches to the respective maintainers for the net-next-xxx trees in Patchwork, or how should I proceed?

Patches 1 and 2 are still valid as is (compared to the main branch). Patch 3 is a one-line modification where the modified line has moved further down.

[26561]: https://patchwork.dpdk.org/project/dpdk/list/?series=26561

Med venlig hilsen / Kind regards,
-Morten Brørup

Quoted 72 lines

From: Morten Brørup [mailto:[email protected]]
Sent: Monday, 8 May 2023 14.33

Quoted 8 lines

From: Tyler Retzlaff [mailto:[email protected]]
Sent: Monday, 6 February 2023 18.29

Quoted 4 lines · Morten Brørup
Quoted 4 lines

From: David Marchand [mailto:[email protected]]
Sent: Monday, 6 February 2023 17.11

On Wed, Feb 1, 2023 at 2:16 PM Thomas Monjalon

<[email protected]>

Quoted 1 line
Quoted 1 line
Quoted 1 line

wrote:

[...]

Quoted 2 lines
Quoted 2 lines

I'm leaning towards following the existing convention in

rte_common.h, and

Quoted 1 line

embrace Thomas' argument to make them more verbose in order to reduce

the risk

Quoted 15 lines

of wrong use. In other words, define these:

Quoted 14 lines

__rte_nonnull(...)
__rte_read_only(ptr_index)
__rte_read_only_size(ptr_index, size_index)
__rte_write_only(ptr_index)
__rte_write_only_size(ptr_index, size_index)
__rte_read_write(ptr_index)
__rte_read_write_size(ptr_index, size_index)
__rte_no_access(ptr_index)
__rte_no_access_size(ptr_index, size_index)

Quoted 3 lines

As for the lock annotations series, if you are not confident with

the

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

form I went with, I don't mind deferring to a later release.

The form follows the existing convention in rte_common.h, and I

think we

Quoted 3 lines

should stick with it.

Quoted 2 lines
Quoted 2 lines

Though it adds more work on my pile like rebasing the vhost

library.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Additionnally, we lose the opportunity to catch introduction of

new

Quoted 5 lines
Quoted 5 lines
Quoted 1 line

lock issues in the dpdk tree.

Conclusion:

The names I listed in this email, and what David already has in his

lock

Quoted 2 lines

annotation patch, are both in line with an existing convention already established in rte_common.h. So unless someone objects very soon,

let's go for

Quoted 1 line

that.

David, Thomas,

FYI:

I am deferring a new version this patch until a later DPDK release, so it doesn't get too much in the way of Tyler's MSVC patches.

Stretch goal: I'm considering if these new attributes could somehow also support MSVC, but let's not discuss that now!

PS: The other patches in the series are independent of this patch, and can be considered individually.

-Morten

#65 lore raw
In reply to Morten Brørup
Quoted 10 lines

From: Morten Brørup [mailto:[email protected]]
Sent: Monday, 16 January 2023 14.07

Add nonnull function attribute to help the compiler detect a NULL pointer being passed to a function not accepting NULL pointers as an argument at build time.

Add access function attributes to tell the compiler how a function accesses memory pointed to by its pointer arguments.

Quoted 7 lines

Add these attributes to the rte_memcpy() function, as the first in hopefully many to come.

---

David,

Patch parts 1, 2 and 3 are essentially individual stand-alone patches, and can be merged as such.

I only made them part of this series because they were required for the primary patch 4.

When I have some time to spare, I will send a new patch, adding the nonnull and access attributes, based on the received feedback.

PS: This patch series got the wrong name by mistake.

#66 lore raw

Hello Morten,

Quoted 10 lines · Morten Brørup
Quoted 10 lines

Add nonnull function attribute to help the compiler detect a NULL pointer being passed to a function not accepting NULL pointers as an argument at build time.

Add access function attributes to tell the compiler how a function accesses memory pointed to by its pointer arguments.

Add these attributes to the rte_memcpy() function, as the first in hopefully many to come.

Quoted 8 lines
Quoted 4 lines

---

David,

Patch parts 1, 2 and 3 are essentially individual stand-alone patches, and can be merged as such.

I am aware of them.

Btw, those were marked as "awaiting upstream", so I suspect someone (you maybe?) changed their state manually.
This state is something used between subtree maintainers and main repository.

I fixed their state as NEW in patchwork yesterday so they can be considered for merge.

Quoted 4 lines

I only made them part of this series because they were required for the primary patch 4.

When I have some time to spare, I will send a new patch, adding the nonnull and access attributes, based on the received feedback.

Ok.

Signature · 1 line
David Marchand
#67 lore raw
Quoted 23 lines

From: David Marchand [mailto:[email protected]]
Sent: Tuesday, 4 April 2023 15.51

Hello Morten,

Quoted 17 lines · Morten Brørup
Quoted 7 lines

Add nonnull function attribute to help the compiler detect a NULL pointer being passed to a function not accepting NULL pointers as an argument at build time.

Add access function attributes to tell the compiler how a function accesses memory pointed to by its pointer arguments.

Quoted 7 lines

Add these attributes to the rte_memcpy() function, as the first in hopefully many to come.

---

David,

Quoted 8 lines
Quoted 1 line

Patch parts 1, 2 and 3 are essentially individual stand-alone patches, and

can be merged as such.

I am aware of them.

Btw, those were marked as "awaiting upstream", so I suspect someone (you maybe?) changed their state manually.
This state is something used between subtree maintainers and main repository.

Yes, I changed their state, trying to help... Seems I was wrong. Thank you for informing me of the usage.

Do you know where I can find guidance to using DPDK Patchwork as a contributor? Or can I look for Linux Patchwork and assume it generally is used the same way?

Quoted 3 lines

I fixed their state as NEW in patchwork yesterday so they can be considered for merge.

Great, thanks.

Quoted 13 lines
Quoted 3 lines

I only made them part of this series because they were required for the

primary patch 4.

Quoted 2 lines

When I have some time to spare, I will send a new patch, adding the nonnull

and access attributes, based on the received feedback.

Ok.

--
David Marchand

#68 lore raw
Quoted 7 lines · Morten Brørup
Quoted 3 lines

Btw, those were marked as "awaiting upstream", so I suspect someone (you maybe?) changed their state manually.
This state is something used between subtree maintainers and main repository.

Yes, I changed their state, trying to help... Seems I was wrong. Thank you for informing me of the usage.

Do you know where I can find guidance to using DPDK Patchwork as a contributor? Or can I look for Linux Patchwork and assume it generally is used the same way?

In my experience, patchwork states are only touched by maintainers of a project. I don't know if there is one globally accepted policy for patches states in pw.

In DPDK, we ask, in the contributors guide, that submitters update their series with the "superseded" state.
The other states are manipulated by maintainers to sync (mainly the "awaiting upstream") or to hide older patches (like the "archived" state for resolved, as in accepted or rejected, patches sent in previous releases).
I know some maintainers do set the "Under review" state, but this is not done by everyone.

Signature · 1 line
David Marchand
#69 lore raw

RE: [PATCH v7 1/4] net/bnx2x: fix warnings about rte_memcpy lengths

In reply to Morten Brørup

PING bnx2x maintainers. Care to review this bugfix, so it can be included in 23.03?

Quoted 95 lines

From: Morten Brørup [mailto:[email protected]]
Sent: Monday, 16 January 2023 14.07

Bugfix: The vlan in the bulletin does not contain a VLAN header, only the
VLAN ID, so only copy 2 byte, not 4. The target structure has padding after the field, so copying 2 byte too many is effectively harmless. There is no need to backport this patch.

Use RTE_PTR_ADD where copying arrays to the offset of a first field in a
structure holding multiple fields, to avoid compiler warnings with decorated rte_memcpy.

Bugzilla ID: 1146

Fixes 540a211084a7695a1c7bc43068934c140d6989be ("bnx2x: driver core")

---
v7:
* No changes.
v6:
* Add Fixes to patch description.
* Fix checkpatch warnings.
v5:
* No changes.
v4:
* Type casting did not fix the warnings, so use RTE_PTR_ADD instead. v3:
* First patch in series.

---
 drivers/net/bnx2x/bnx2x_stats.c | 11 +++++++----
 drivers/net/bnx2x/bnx2x_vfpf.c  |  2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/net/bnx2x/bnx2x_stats.c +3 -2
index c07b01510a..bc4a8b8e71 100644
@@ -819,8 +819,9 @@ bnx2x_hw_stats_update(struct bnx2x_softc *sc)
 
     rte_memcpy(old, new, sizeof(struct nig_stats));
 
-    rte_memcpy(&(estats->rx_stat_ifhcinbadoctets_hi), &(pstats-
 >mac_stx[1]),
-	   sizeof(struct mac_stx));
+	rte_memcpy(RTE_PTR_ADD(estats,
+			offsetof(struct bnx2x_eth_stats,
 rx_stat_ifhcinbadoctets_hi)),
+			&pstats->mac_stx[1], sizeof(struct mac_stx));
     estats->brb_drop_hi = pstats->brb_drop_hi;
     estats->brb_drop_lo = pstats->brb_drop_lo;
drivers/net/bnx2x/bnx2x_stats.c +4 -2
@@ -1492,9 +1493,11 @@ bnx2x_stats_init(struct bnx2x_softc *sc)
 		REG_RD(sc, NIG_REG_STAT0_BRB_TRUNCATE + port*0x38);
 	if (!CHIP_IS_E3(sc)) {
 		REG_RD_DMAE(sc, NIG_REG_STAT0_EGRESS_MAC_PKT0 + port*0x50,
-				&(sc->port.old_nig_stats.egress_mac_pkt0_lo),
 2);
+				RTE_PTR_ADD(&sc->port.old_nig_stats,
+				offsetof(struct nig_stats,
 egress_mac_pkt0_lo)), 2);
 		REG_RD_DMAE(sc, NIG_REG_STAT0_EGRESS_MAC_PKT1 + port*0x50,
-				&(sc->port.old_nig_stats.egress_mac_pkt1_lo),
 2);
+				RTE_PTR_ADD(&sc->port.old_nig_stats,
+				offsetof(struct nig_stats,

egress_mac_pkt1_lo)), 2);

drivers/net/bnx2x/bnx2x_stats.c +0 -0
 	}
 
 	/* function stats */
drivers/net/bnx2x/bnx2x_vfpf.c +1 -1
index 63953c2979..87631c76ca 100644
@@ -54,7 +54,7 @@ bnx2x_check_bull(struct bnx2x_softc *sc)
 	if (valid_bitmap & (1 << MAC_ADDR_VALID) && memcmp(bull->mac, sc-
 >old_bulletin.mac, ETH_ALEN))
 		rte_memcpy(&sc->link_params.mac_addr, bull->mac, ETH_ALEN);
 	if (valid_bitmap & (1 << VLAN_VALID))
-		rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan,
 RTE_VLAN_HLEN);
+		rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan,
 sizeof(bull->vlan));

sc->old_bulletin = *bull;

--
2.17.1

#70 lore raw

Marvell QLogic bnx2x PMD support status

Marvell bnx2x PMD maintainers are silent. Is the PMD not maintained anymore?

Quoted 32 lines

From: Morten Brørup [mailto:[email protected]]
Sent: Thursday, 9 February 2023 17.50
To: [email protected]; [email protected]; [...]
Cc: [email protected]; [...]
Subject: RE: [PATCH v7 1/4] net/bnx2x: fix warnings about rte_memcpy lengths

PING bnx2x maintainers. Care to review this bugfix, so it can be included in 23.03?

Quoted 22 lines

From: Morten Brørup [mailto:[email protected]]
Sent: Monday, 16 January 2023 14.07

Bugfix: The vlan in the bulletin does not contain a VLAN header, only the
VLAN ID, so only copy 2 byte, not 4. The target structure has padding after the field, so copying 2 byte too many is effectively harmless. There is no need to backport this patch.

Use RTE_PTR_ADD where copying arrays to the offset of a first field in a
structure holding multiple fields, to avoid compiler warnings with decorated rte_memcpy.

Bugzilla ID: 1146

Fixes 540a211084a7695a1c7bc43068934c140d6989be ("bnx2x: driver core")
#71 lore raw

Re: [PATCH v7 1/4] net/bnx2x: fix warnings about rte_memcpy lengths

In reply to Morten Brørup
Quoted 3 lines · Morten Brørup

PING bnx2x maintainers. Care to review this bugfix, so it can be included in 23.03?

Still no luck in getting attention from bnx2x maintainers. One option is to declare this driver as UNMAINTAINED and disable its compilation when the memcpy annotations are finalised and merged in a next release.

Signature · 1 line
David Marchand
#72 lore raw

Re: [PATCH v7 1/4] net/bnx2x: fix warnings about rte_memcpy lengths

09/03/2023 11:25, David Marchand:

Quoted 9 lines · Morten Brørup
Quoted 3 lines

PING bnx2x maintainers. Care to review this bugfix, so it can be included in 23.03?

Still no luck in getting attention from bnx2x maintainers. One option is to declare this driver as UNMAINTAINED and disable its compilation when the memcpy annotations are finalised and merged in a next release.

Yes that's an option.
Jerin, what is your opinion?

#73 lore raw

RE: [EXT] Re: [PATCH v7 1/4] net/bnx2x: fix warnings about rte_memcpy lengths

++Alok Prasad

Quoted 16 lines

09/03/2023 11:25, David Marchand:

Quoted 1 line

On Thu, Feb 9, 2023 at 5:49 PM Morten Brørup

Quoted 2 lines · <[email protected]> wrote:
Quoted 2 lines

PING bnx2x maintainers. Care to review this bugfix, so it can be included in

23.03?

Quoted 6 lines
Quoted 1 line

Still no luck in getting attention from bnx2x maintainers. One option is to declare this driver as UNMAINTAINED and disable its compilation when the memcpy annotations are finalised and merged in a next release.

Yes that's an option.
Jerin, what is your opinion?

A message that is not in the archive (sent off-list or not yet received): SJ0PR18MB390039A8C34E485F8D2D518EA1B59@SJ0PR18MB3900.namprd18.prod.outlook.com

#75 lore raw

Re: [PATCH v7 1/4] net/bnx2x: fix warnings about rte_memcpy lengths

-----Original Message-----
From: Akhil Goyal <[email protected]>
Sent: 09 March 2023 21:41
To: Thomas Monjalon <[email protected]>; David Marchand <[email protected]>; Jerin Jacob Kollanukkaran <[email protected]>
Cc: Morten Brørup <[email protected]>; Rasesh Mody <[email protected]>; Shahed Shaikh <[email protected]>; [email protected]; Alok Prasad <[email protected]>
Subject: RE: [EXT] Re: [PATCH v7 1/4] net/bnx2x: fix warnings about rte_memcpy lengths

++Alok Prasad

Quoted 9 lines

09/03/2023 11:25, David Marchand:

Quoted 1 line

On Thu, Feb 9, 2023 at 5:49 PM Morten Brørup

Quoted 3 lines · <[email protected]> wrote:
Quoted 3 lines

PING bnx2x maintainers. Care to review this bugfix, so it can be included in

23.03?

Quoted 2 lines
Quoted 1 line
Quoted 8 lines
Quoted 4 lines

Still no luck in getting attention from bnx2x maintainers. One option is to declare this driver as UNMAINTAINED and disable its compilation when the memcpy annotations are finalised and merged in a next release.

Yes that's an option.
Jerin, what is your opinion?

Both the maintainers for bnx2x PMD have left Marvell, We are in process of finalizing new maintainers for this PMD. Meanwhile I have reviewed the patch and I am Acking it.

#76 lore raw

Re: [PATCH v7 1/4] net/bnx2x: fix warnings about rte_memcpy lengths

In reply to Morten Brørup
Quoted 9 lines · On Thu, 9 Feb 2023 17:49:31 +0100 Morten Brørup <[email protected]>…

drivers/net/bnx2x/bnx2x_stats.c bnx2x_hw_stats_update(struct bnx2x_softc *sc) · line 824

Quoted 9 lines
     rte_memcpy(old, new, sizeof(struct nig_stats));

- rte_memcpy(&(estats->rx_stat_ifhcinbadoctets_hi), &(pstats-

Quoted 1 line

mac_stx[1]),

drivers/net/bnx2x/bnx2x_stats.c +2 -1
-	   sizeof(struct mac_stx));
+	rte_memcpy(RTE_PTR_ADD(estats,
+			offsetof(struct bnx2x_eth_stats,

rx_stat_ifhcinbadoctets_hi)),

drivers/net/bnx2x/bnx2x_stats.c +1 -0
+			&pstats->mac_stx[1], sizeof(struct mac_stx));

Stop using rte_memcpy() in slow path like this.
memcpy() is just as fast, compiler can optimize, and the checking tools are better with it.

#77 lore raw

Re: [PATCH v7 1/4] net/bnx2x: fix warnings about rte_memcpy lengths

Quoted 14 lines · Stephen Hemminger
Quoted 9 lines · On Thu, 9 Feb 2023 17:49:31 +0100 Morten Brørup <[email protected]>…
Quoted 9 lines
     rte_memcpy(old, new, sizeof(struct nig_stats));

- rte_memcpy(&(estats->rx_stat_ifhcinbadoctets_hi), &(pstats-

Quoted 1 line

mac_stx[1]),

drivers/net/bnx2x/bnx2x_stats.c +2 -1
-      sizeof(struct mac_stx));
+   rte_memcpy(RTE_PTR_ADD(estats,
+                   offsetof(struct bnx2x_eth_stats,

rx_stat_ifhcinbadoctets_hi)),
+ &pstats->mac_stx[1], sizeof(struct mac_stx));

Quoted 3 lines

Stop using rte_memcpy() in slow path like this.
memcpy() is just as fast, compiler can optimize, and the checking tools are better with it.

+1

@Morten Brørup Could you send the next version? I am marking as Change requested.