[v6,17/30] drivers/vdpa: replace packed attributes

Message ID 1732668761-5556-18-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/vdpa/ifc/base/ifcvf.h | 4 ++--
 drivers/vdpa/mlx5/mlx5_vdpa.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
  

Comments

Tyler Retzlaff Dec. 5, 2024, 12:54 a.m. UTC | #1
On Tue, Nov 26, 2024 at 04:52:28PM -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/vdpa/ifc/base/ifcvf.h b/drivers/vdpa/ifc/base/ifcvf.h
index 04c81c8196..7be1596556 100644
--- a/drivers/vdpa/ifc/base/ifcvf.h
+++ b/drivers/vdpa/ifc/base/ifcvf.h
@@ -115,11 +115,11 @@  struct ifcvf_pci_common_cfg {
 	u32 queue_used_hi;
 };
 
-struct ifcvf_net_config {
+__rte_packed_begin struct ifcvf_net_config {
 	u8    mac[6];
 	u16   status;
 	u16   max_virtqueue_pairs;
-} __rte_packed;
+} __rte_packed_end;
 
 struct ifcvf_pci_mem_resource {
 	u64      phys_addr; /**< Physical address, 0 if not resource. */
diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.h b/drivers/vdpa/mlx5/mlx5_vdpa.h
index e156520172..6f25eea641 100644
--- a/drivers/vdpa/mlx5/mlx5_vdpa.h
+++ b/drivers/vdpa/mlx5/mlx5_vdpa.h
@@ -90,13 +90,13 @@  enum mlx5_vdpa_task_type {
 };
 
 /* Generic task information and size must be multiple of 4B. */
-struct __rte_aligned(4) mlx5_vdpa_task {
+__rte_packed_begin struct __rte_aligned(4) mlx5_vdpa_task {
 	struct mlx5_vdpa_priv *priv;
 	enum mlx5_vdpa_task_type type;
 	RTE_ATOMIC(uint32_t) *remaining_cnt;
 	RTE_ATOMIC(uint32_t) *err_cnt;
 	uint32_t idx;
-} __rte_packed;
+} __rte_packed_end;
 
 /* Generic mlx5_vdpa_c_thread information. */
 struct mlx5_vdpa_c_thread {