ethdev: fix strict aliasing lead to link cannot be 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.
[1] Strict aliasing problem with rte_eth_linkstatus_set()
https://marc.info/?l=dpdk-dev&m=171274148514777&w=3
Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
(cherry picked from commit 776b3090fb193bc8abe55d7a0ea19e44601b7607)
This commit is contained in:
parent
2898b1760a
commit
74977784f5
@ -0,0 +1,98 @@
|
||||
From 784ba0a03ddd16a54b9d23757d587b67b832e2b7 Mon Sep 17 00:00:00 2001
|
||||
From: Chengwen Feng <fengchengwen@huawei.com>
|
||||
Date: Thu, 11 Apr 2024 12:04:08 +0000
|
||||
Subject: [PATCH] ethdev: fix strict aliasing lead to link cannot be 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.
|
||||
|
||||
[1] Strict aliasing problem with rte_eth_linkstatus_set()
|
||||
https://marc.info/?l=dpdk-dev&m=171274148514777&w=3
|
||||
|
||||
Cc: stable@dpdk.org
|
||||
|
||||
Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
|
||||
Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
|
||||
---
|
||||
lib/ethdev/ethdev_driver.h | 23 +++++++----------------
|
||||
lib/ethdev/rte_ethdev.h | 16 ++++++++++------
|
||||
2 files changed, 17 insertions(+), 22 deletions(-)
|
||||
|
||||
diff --git a/lib/ethdev/ethdev_driver.h b/lib/ethdev/ethdev_driver.h
|
||||
index b482cd1..12a7bfc 100644
|
||||
--- a/lib/ethdev/ethdev_driver.h
|
||||
+++ b/lib/ethdev/ethdev_driver.h
|
||||
@@ -1655,18 +1655,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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1682,12 +1677,8 @@ 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));
|
||||
-
|
||||
- *dst = rte_atomic_load_explicit(src, rte_memory_order_seq_cst);
|
||||
+ link->val64 = rte_atomic_load_explicit(&dev->data->dev_link.val64,
|
||||
+ rte_memory_order_seq_cst);
|
||||
}
|
||||
|
||||
/**
|
||||
diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h
|
||||
index 57a9a55..b4b0357 100644
|
||||
--- a/lib/ethdev/rte_ethdev.h
|
||||
+++ b/lib/ethdev/rte_ethdev.h
|
||||
@@ -331,13 +331,17 @@ struct rte_eth_stats {
|
||||
/**
|
||||
* A structure used to retrieve link-level information of an Ethernet port.
|
||||
*/
|
||||
-__extension__
|
||||
struct rte_eth_link {
|
||||
- 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] */
|
||||
-} __rte_aligned(8); /**< aligned for atomic64 read/write */
|
||||
+ union {
|
||||
+ RTE_ATOMIC(uint64_t) val64; /**< used for atomic64 read/write */
|
||||
+ 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
|
||||
* Constants used in link management.
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
|
||||
Name: dpdk
|
||||
Version: 23.11
|
||||
Release: 8
|
||||
Release: 9
|
||||
URL: http://dpdk.org
|
||||
Source: https://fast.dpdk.org/rel/dpdk-%{version}.tar.xz
|
||||
|
||||
@ -51,6 +51,8 @@ Patch6030: 0030-app-testpmd-fix-crash-in-multi-process-forwarding.patch
|
||||
|
||||
Patch9013: 0031-add-rte_eth_bond_link_monitoring_get-in-map.patch
|
||||
|
||||
Patch9032: 0032-ethdev-fix-strict-aliasing-lead-to-link-cannot-be-up.patch
|
||||
|
||||
BuildRequires: meson
|
||||
BuildRequires: python3-pyelftools
|
||||
BuildRequires: diffutils
|
||||
@ -217,6 +219,9 @@ strip -g $RPM_BUILD_ROOT/lib/modules/%{kern_devel_ver}/extra/dpdk/igb_uio.ko
|
||||
%endif
|
||||
|
||||
%changelog
|
||||
* Fri Apr 12 2024 huangdengdui <huangdengui@huawei.com> - 23.11-9
|
||||
fix strict aliasing lead to link cannot be up
|
||||
|
||||
* Mon Apr 08 2024 jiangheng <jiangheng14@huawei.com> - 23.11-8
|
||||
move patch0031 to self developed patch
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user