[02/15] eal: pack structures when building with MSVC

Message ID 1710968771-16435-3-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series fix packing of structs when building with MSVC |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Tyler Retzlaff March 20, 2024, 9:05 p.m. UTC
  Add __rte_msvc_pack to all __rte_packed structs to cause packing
when building with MSVC.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 lib/eal/common/eal_private.h      | 1 +
 lib/eal/include/rte_memory.h      | 1 +
 lib/eal/include/rte_memzone.h     | 1 +
 lib/eal/include/rte_trace_point.h | 1 +
 lib/eal/x86/include/rte_memcpy.h  | 3 +++
 5 files changed, 7 insertions(+)
  

Comments

Bruce Richardson March 21, 2024, 4:02 p.m. UTC | #1
On Wed, Mar 20, 2024 at 02:05:58PM -0700, Tyler Retzlaff wrote:
> Add __rte_msvc_pack to all __rte_packed structs to cause packing
> when building with MSVC.
> 
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> ---
>  lib/eal/common/eal_private.h      | 1 +
>  lib/eal/include/rte_memory.h      | 1 +
>  lib/eal/include/rte_memzone.h     | 1 +
>  lib/eal/include/rte_trace_point.h | 1 +
>  lib/eal/x86/include/rte_memcpy.h  | 3 +++
>  5 files changed, 7 insertions(+)
> 
> diff --git a/lib/eal/common/eal_private.h b/lib/eal/common/eal_private.h
> index 71523cf..21ace2a 100644
> --- a/lib/eal/common/eal_private.h
> +++ b/lib/eal/common/eal_private.h
> @@ -43,6 +43,7 @@ struct lcore_config {
>  /**
>   * The global RTE configuration structure.
>   */
> +__rte_msvc_pack
>  struct rte_config {
>  	uint32_t main_lcore;         /**< Id of the main lcore */
>  	uint32_t lcore_count;        /**< Number of available logical cores. */

This struct almost certainly doesn't need to be packed - since it's in a
private header, I would imagine removing packing wouldn't be an ABI
break.
Also, removing rte_packed doesn't change the size for me for a 64-bit x86
build. Looking at the struct, I don't see why it would change on a 32-bit
build either.

> diff --git a/lib/eal/include/rte_memory.h b/lib/eal/include/rte_memory.h
> index 842362d..73bb00d 100644
> --- a/lib/eal/include/rte_memory.h
> +++ b/lib/eal/include/rte_memory.h
> @@ -46,6 +46,7 @@
>  /**
>   * Physical memory segment descriptor.
>   */
> +__rte_msvc_pack
>  struct rte_memseg {
>  	rte_iova_t iova;            /**< Start IO address. */
>  	union {
> diff --git a/lib/eal/include/rte_memzone.h b/lib/eal/include/rte_memzone.h
> index 931497f..ca312c0 100644
> --- a/lib/eal/include/rte_memzone.h
> +++ b/lib/eal/include/rte_memzone.h
> @@ -45,6 +45,7 @@
>   * A structure describing a memzone, which is a contiguous portion of
>   * physical memory identified by a name.
>   */
> +__rte_msvc_pack
>  struct rte_memzone {
> 

This also doesn't look like it should be packed. It is a public header
though so we may need to be more careful. Checking a 64-bit x86 build shows
no size change when removing the "packed" attribute, though. For 32-bit, I
think the "size_t" field in the middle would be followed by padding on
32-bit if we removed the "packed" attribute, so it may be a no-go for now.
:-(

>  #define RTE_MEMZONE_NAMESIZE 32       /**< Maximum length of memory zone name.*/
> diff --git a/lib/eal/include/rte_trace_point.h b/lib/eal/include/rte_trace_point.h
> index 41e2a7f..63f333c 100644
> --- a/lib/eal/include/rte_trace_point.h
> +++ b/lib/eal/include/rte_trace_point.h
> @@ -292,6 +292,7 @@ int __rte_trace_point_register(rte_trace_point_t *trace, const char *name,
>  #define __RTE_TRACE_FIELD_ENABLE_MASK (1ULL << 63)
>  #define __RTE_TRACE_FIELD_ENABLE_DISCARD (1ULL << 62)
>  
> +__rte_msvc_pack
>  struct __rte_trace_stream_header {
>  	uint32_t magic;
>  	rte_uuid_t uuid;

From code review, this doesn't look like "packed" has any impact, since all
fields should naturally be aligned on both 32-bit and 64-bit builds.

/Bruce
  

Patch

diff --git a/lib/eal/common/eal_private.h b/lib/eal/common/eal_private.h
index 71523cf..21ace2a 100644
--- a/lib/eal/common/eal_private.h
+++ b/lib/eal/common/eal_private.h
@@ -43,6 +43,7 @@  struct lcore_config {
 /**
  * The global RTE configuration structure.
  */
+__rte_msvc_pack
 struct rte_config {
 	uint32_t main_lcore;         /**< Id of the main lcore */
 	uint32_t lcore_count;        /**< Number of available logical cores. */
diff --git a/lib/eal/include/rte_memory.h b/lib/eal/include/rte_memory.h
index 842362d..73bb00d 100644
--- a/lib/eal/include/rte_memory.h
+++ b/lib/eal/include/rte_memory.h
@@ -46,6 +46,7 @@ 
 /**
  * Physical memory segment descriptor.
  */
+__rte_msvc_pack
 struct rte_memseg {
 	rte_iova_t iova;            /**< Start IO address. */
 	union {
diff --git a/lib/eal/include/rte_memzone.h b/lib/eal/include/rte_memzone.h
index 931497f..ca312c0 100644
--- a/lib/eal/include/rte_memzone.h
+++ b/lib/eal/include/rte_memzone.h
@@ -45,6 +45,7 @@ 
  * A structure describing a memzone, which is a contiguous portion of
  * physical memory identified by a name.
  */
+__rte_msvc_pack
 struct rte_memzone {
 
 #define RTE_MEMZONE_NAMESIZE 32       /**< Maximum length of memory zone name.*/
diff --git a/lib/eal/include/rte_trace_point.h b/lib/eal/include/rte_trace_point.h
index 41e2a7f..63f333c 100644
--- a/lib/eal/include/rte_trace_point.h
+++ b/lib/eal/include/rte_trace_point.h
@@ -292,6 +292,7 @@  int __rte_trace_point_register(rte_trace_point_t *trace, const char *name,
 #define __RTE_TRACE_FIELD_ENABLE_MASK (1ULL << 63)
 #define __RTE_TRACE_FIELD_ENABLE_DISCARD (1ULL << 62)
 
+__rte_msvc_pack
 struct __rte_trace_stream_header {
 	uint32_t magic;
 	rte_uuid_t uuid;
diff --git a/lib/eal/x86/include/rte_memcpy.h b/lib/eal/x86/include/rte_memcpy.h
index 72a9229..fdc5df0 100644
--- a/lib/eal/x86/include/rte_memcpy.h
+++ b/lib/eal/x86/include/rte_memcpy.h
@@ -57,12 +57,15 @@ 
 	 * Use the following structs to avoid violating C standard
 	 * alignment requirements and to avoid strict aliasing bugs
 	 */
+	__rte_msvc_pack
 	struct rte_uint64_alias {
 		uint64_t val;
 	} __rte_packed __rte_may_alias;
+	__rte_msvc_pack
 	struct rte_uint32_alias {
 		uint32_t val;
 	} __rte_packed __rte_may_alias;
+	__rte_msvc_pack
 	struct rte_uint16_alias {
 		uint16_t val;
 	} __rte_packed __rte_may_alias;