diff options
| author | Chengwen Feng <[email protected]> | 2024-04-22 06:38:13 +0000 |
|---|---|---|
| committer | Ferruh Yigit <[email protected]> | 2024-04-22 10:02:16 +0200 |
| commit | b9a87346b05c562dd6005ee025eca67a1a80bea8 (patch) | |
| tree | 23486f97a4231a5696efd90c0429e5e557a348b6 /lib/ethdev | |
| parent | e94c20c34cfd7140b4199ab3c1059520c0605318 (diff) | |
ethdev: fix strict aliasing in link up
Fix a problem introduced by a compiler upgrade (from gcc10 to gcc12.3),
which will lead the hns3 NIC can't link up. The root cause is strict
aliasing violation in rte_eth_linkstatus_set() with hns3 driver, see
[1] for more details.
This commit use union to avoid such aliasing violation. Also the
impacted components (cxgbe and qos_sched) have been adapted to the
struct change.
[1] https://inbox.dpdk.org/dev/[email protected]/
Cc: [email protected]
Signed-off-by: Chengwen Feng <[email protected]>
Signed-off-by: Dengdui Huang <[email protected]>
Acked-by: Morten Brørup <[email protected]>
Acked-by: Ferruh Yigit <[email protected]>
Diffstat (limited to 'lib/ethdev')
| -rw-r--r-- | lib/ethdev/ethdev_driver.h | 24 | ||||
| -rw-r--r-- | lib/ethdev/rte_ethdev.h | 17 |
2 files changed, 20 insertions, 21 deletions
diff --git a/lib/ethdev/ethdev_driver.h b/lib/ethdev/ethdev_driver.h index 0dbf2dd6a2..883e59a927 100644 --- a/lib/ethdev/ethdev_driver.h +++ b/lib/ethdev/ethdev_driver.h @@ -1674,18 +1674,13 @@ static inline int rte_eth_linkstatus_set(struct rte_eth_dev *dev, const struct rte_eth_link *new_link) { - RTE_ATOMIC(uint64_t) *dev_link = (uint64_t __rte_atomic *)&(dev->data->dev_link); - union { - uint64_t val64; - struct rte_eth_link link; - } orig; - - RTE_BUILD_BUG_ON(sizeof(*new_link) != sizeof(uint64_t)); + struct rte_eth_link old_link; - orig.val64 = rte_atomic_exchange_explicit(dev_link, *(const uint64_t *)new_link, - rte_memory_order_seq_cst); + old_link.val64 = rte_atomic_exchange_explicit(&dev->data->dev_link.val64, + new_link->val64, + rte_memory_order_seq_cst); - return (orig.link.link_status == new_link->link_status) ? -1 : 0; + return (old_link.link_status == new_link->link_status) ? -1 : 0; } /** @@ -1701,12 +1696,11 @@ static inline void rte_eth_linkstatus_get(const struct rte_eth_dev *dev, struct rte_eth_link *link) { - RTE_ATOMIC(uint64_t) *src = (uint64_t __rte_atomic *)&(dev->data->dev_link); - uint64_t *dst = (uint64_t *)link; - - RTE_BUILD_BUG_ON(sizeof(*link) != sizeof(uint64_t)); + struct rte_eth_link curr_link; - *dst = rte_atomic_load_explicit(src, rte_memory_order_seq_cst); + curr_link.val64 = rte_atomic_load_explicit(&dev->data->dev_link.val64, + rte_memory_order_seq_cst); + rte_atomic_store_explicit(&link->val64, curr_link.val64, rte_memory_order_seq_cst); } /** diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h index 147257d6a2..548fada1c7 100644 --- a/lib/ethdev/rte_ethdev.h +++ b/lib/ethdev/rte_ethdev.h @@ -332,12 +332,17 @@ struct rte_eth_stats { /** * A structure used to retrieve link-level information of an Ethernet port. */ -__extension__ -struct __rte_aligned(8) rte_eth_link { /**< aligned for atomic64 read/write */ - uint32_t link_speed; /**< RTE_ETH_SPEED_NUM_ */ - uint16_t link_duplex : 1; /**< RTE_ETH_LINK_[HALF/FULL]_DUPLEX */ - uint16_t link_autoneg : 1; /**< RTE_ETH_LINK_[AUTONEG/FIXED] */ - uint16_t link_status : 1; /**< RTE_ETH_LINK_[DOWN/UP] */ +struct rte_eth_link { + union { + RTE_ATOMIC(uint64_t) val64; /**< used for atomic64 read/write */ + __extension__ + struct { + uint32_t link_speed; /**< RTE_ETH_SPEED_NUM_ */ + uint16_t link_duplex : 1; /**< RTE_ETH_LINK_[HALF/FULL]_DUPLEX */ + uint16_t link_autoneg : 1; /**< RTE_ETH_LINK_[AUTONEG/FIXED] */ + uint16_t link_status : 1; /**< RTE_ETH_LINK_[DOWN/UP] */ + }; + }; }; /**@{@name Link negotiation |
