[PATCH v6] ethdev: fix strict aliasing lead to link cannot be up
Morten Brørup
mb at smartsharesystems.com
Mon Apr 15 15:15:18 CEST 2024
> @@ -1701,12 +1696,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);
> }
rte_eth_linkstatus_get() may be called by rte_eth_link_get():
https://elixir.bootlin.com/dpdk/v24.03/source/lib/ethdev/rte_ethdev.c#L2986
The application may call rte_eth_link_get() with the "link" parameter pointing to memory shared by other threads.
So link->val64 must be stored atomically:
rte_atomic_store_explicit(&link->val64,
rte_atomic_load_explicit(&dev->data->dev_link.val64,
rte_memory_order_seq_cst),
rte_memory_order_seq_cst);
With the above modification,
Acked-by: Morten Brørup <mb at smartsharesystems.com>
More information about the dev
mailing list