Add __attribute__((may_alias)) to the CN20K-specific NPA structures (npa_cn20k_aura_s, npa_cn20k_pool_s, and npa_cn20k_halo_s) to allow safe type punning when casting between these structures and their base types (npa_aura_s and npa_pool_s).
This attribute tells the compiler that these structures may alias with other types, which is necessary when casting pointers between compatible hardware register structures that share the same memory layout. Without this attribute, such casts violate strict aliasing rules and can lead to incorrect compiler optimizations. Signed-off-by: Nawal Kishor <[email protected]> --- v2: * Fixed commit message typo drivers/common/cnxk/hw/npa.h | 8 +++++--- drivers/common/cnxk/roc_platform.h | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/common/cnxk/hw/npa.h b/drivers/common/cnxk/hw/npa.h index 8d6b6bbe8b..aea24b69da 100644 --- a/drivers/common/cnxk/hw/npa.h +++ b/drivers/common/cnxk/hw/npa.h @@ -5,6 +5,8 @@ #ifndef __NPA_HW_H__ #define __NPA_HW_H__ +#include "roc_platform.h" + /* Register offsets */ #define NPA_AF_BLK_RST (0x0ull) @@ -389,7 +391,7 @@ struct npa_cn20k_aura_s { uint64_t stream_ctx : 1; uint64_t unified_ctx : 1; uint64_t rsvd_511_448 : 64; /* W7 */ -}; +} __plt_may_alias; /* NPA pool context structure [CN20K] */ struct npa_cn20k_pool_s { @@ -465,7 +467,7 @@ struct npa_cn20k_pool_s { uint64_t rsvd_895_832 : 64; /* W13 */ uint64_t rsvd_959_896 : 64; /* W14 */ uint64_t rsvd_1023_960 : 64; /* W15 */ -}; +} __plt_may_alias; /* NPA halo context structure [CN20K] */ struct npa_cn20k_halo_s { @@ -545,7 +547,7 @@ struct npa_cn20k_halo_s { uint64_t reserved_895_832 : 64; /* W13 */ uint64_t reserved_959_896 : 64; /* W14 */ uint64_t reserved_1023_960 : 64; /* W15 */ -}; +} __plt_may_alias; /* NPA queue interrupt context hardware structure */ struct npa_qint_hw_s { diff --git a/drivers/common/cnxk/roc_platform.h b/drivers/common/cnxk/roc_platform.h index e22a50d47a..73cc12e567 100644 --- a/drivers/common/cnxk/roc_platform.h +++ b/drivers/common/cnxk/roc_platform.h @@ -100,6 +100,7 @@ #define __plt_packed_begin __rte_packed_begin #define __plt_packed_end __rte_packed_end #define __plt_unused __rte_unused +#define __plt_may_alias __rte_may_alias #define __roc_api __rte_internal #define plt_iova_t rte_iova_t -- 2.48.1

