[v6,15/30] drivers/raw: replace packed attributes

Message ID 1732668761-5556-16-git-send-email-andremue@linux.microsoft.com (mailing list archive)
State Superseded
Delegated to: David Marchand
Headers
Series fix packing of structs when building with MSVC |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Andre Muezerie Nov. 27, 2024, 12:52 a.m. UTC
MSVC struct packing is not compatible with GCC. Replace macro
__rte_packed with __rte_packed_begin to push existing pack value
and set packing to 1-byte and macro __rte_packed_end to restore
the pack value prior to the push.

Macro __rte_packed_end is deliberately utilized to trigger a
MSVC compiler warning if no existing packing has been pushed allowing
easy identification of locations where the __rte_packed_begin is
missing.

Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
---
 drivers/raw/ifpga/afu_pmd_n3000.h    | 8 ++++----
 drivers/raw/ifpga/base/opae_hw_api.h | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)
  

Comments

Tyler Retzlaff Dec. 5, 2024, 12:51 a.m. UTC | #1
On Tue, Nov 26, 2024 at 04:52:26PM -0800, Andre Muezerie wrote:
> MSVC struct packing is not compatible with GCC. Replace macro
> __rte_packed with __rte_packed_begin to push existing pack value
> and set packing to 1-byte and macro __rte_packed_end to restore
> the pack value prior to the push.
> 
> Macro __rte_packed_end is deliberately utilized to trigger a
> MSVC compiler warning if no existing packing has been pushed allowing
> easy identification of locations where the __rte_packed_begin is
> missing.
> 
> Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
> ---

Reviewed-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
  

Patch

diff --git a/drivers/raw/ifpga/afu_pmd_n3000.h b/drivers/raw/ifpga/afu_pmd_n3000.h
index f6b6e07c6b..a74025cb3c 100644
--- a/drivers/raw/ifpga/afu_pmd_n3000.h
+++ b/drivers/raw/ifpga/afu_pmd_n3000.h
@@ -211,7 +211,7 @@  typedef union {
 	};
 } msgdma_desc_ctrl;
 
-typedef struct __rte_packed {
+typedef __rte_packed_begin struct {
 	uint32_t rd_address;
 	uint32_t wr_address;
 	uint32_t len;
@@ -223,7 +223,7 @@  typedef struct __rte_packed {
 	uint32_t rd_address_ext;
 	uint32_t wr_address_ext;
 	msgdma_desc_ctrl control;
-} msgdma_ext_desc;
+} __rte_packed_end msgdma_ext_desc;
 
 typedef union {
 	uint32_t csr;
@@ -279,13 +279,13 @@  typedef union {
 	};
 } msgdma_seq_num;
 
-typedef struct __rte_packed {
+typedef __rte_packed_begin struct {
 	msgdma_status status;
 	msgdma_ctrl ctrl;
 	msgdma_fill_level fill_level;
 	msgdma_rsp_level rsp;
 	msgdma_seq_num seq_num;
-} msgdma_csr;
+} __rte_packed_end msgdma_csr;
 
 #define CSR_STATUS(csr)   (&(((msgdma_csr *)(csr))->status))
 #define CSR_CONTROL(csr)  (&(((msgdma_csr *)(csr))->ctrl))
diff --git a/drivers/raw/ifpga/base/opae_hw_api.h b/drivers/raw/ifpga/base/opae_hw_api.h
index 613563a0b4..5957f67417 100644
--- a/drivers/raw/ifpga/base/opae_hw_api.h
+++ b/drivers/raw/ifpga/base/opae_hw_api.h
@@ -343,9 +343,9 @@  static inline void opae_adapter_remove_acc(struct opae_adapter *adapter,
 /* OPAE vBNG network datastruct */
 #define OPAE_ETHER_ADDR_LEN 6
 
-struct opae_ether_addr {
+__rte_packed_begin struct opae_ether_addr {
 	unsigned char addr_bytes[OPAE_ETHER_ADDR_LEN];
-} __rte_packed;
+} __rte_packed_end;
 
 /* OPAE vBNG network API*/
 int opae_manager_read_mac_rom(struct opae_manager *mgr, int port,